[phpMP-CVS] CVS: phpMP/includes Config_File.class.php,NONE,1.1 Smarty.class.php,NONE,1.1 Smarty_Comp
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2002-07-25 11:06:28
|
Update of /cvsroot/phpmp/phpMP/includes In directory usw-pr-cvs1:/tmp/cvs-serv25048/includes Modified Files: core.php Added Files: Config_File.class.php Smarty.class.php Smarty_Compiler.class.php template_ext.php Removed Files: template.php Log Message: Integrated Smarty Template Engine into phpMP. Removed old template engine and files no longer needed (but may be added back later). Note: Blocking does not yet work. Still a few kinks. --- NEW FILE: Config_File.class.php --- <?php /** * Config_File class. * * @version 2.2.0 * @author Andrei Zmievski <an...@ph...> * @access public * * Copyright: 2001,2002 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * You may contact the author of Config_File by e-mail at: * an...@ph... * * Or, write to: * Andrei Zmievski * Software Engineer, ispi * 237 S. 70th suite 220 * Lincoln, NE 68510 * * The latest version of Config_File can be obtained from: * http://www.phpinsider.com */ class Config_File { /* Options */ /** * Controls whether variables with the same name overwrite each other. * * @access public */ var $overwrite = true; /** * Controls whether config values of on/true/yes and off/false/no get * converted to boolean values automatically. * * @access public */ var $booleanize = true; /** * Controls whether hidden config sections/vars are read from the file. * * @access public */ var $read_hidden = true; /* Private variables */ var $_config_path = ""; var $_config_data = array(); var $_separator = ""; /** * Constructs a new config file class. * * @param $config_path string (optional) path to the config files * @access public */ function Config_File($config_path = NULL) { if (substr(PHP_OS, 0, 3) == "WIN" || substr(PHP_OS, 0, 4) == "OS/2") $this->_separator = "\\"; else $this->_separator = "/"; if (isset($config_path)) $this->set_path($config_path); } /** * Set the path where configuration files can be found. * * @param $config_path string path to the config files * @access public */ function set_path($config_path) { if (!empty($config_path)) { if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) { $this->_trigger_error_msg("Bad config file path '$config_path'"); return; } $this->_config_path = $config_path . $this->_separator; } } /** * Retrieves config info based on the file, section, and variable name. * * @access public * @param $file_name string config file to get info for * @param $section_name string (optional) section to get info for * @param $var_name string (optional) variable to get info for * @return mixed a value or array of values */ function &get($file_name, $section_name = NULL, $var_name = NULL) { if (empty($file_name)) { $this->_trigger_error_msg('Empty config file name'); return; } else { $file_name = $this->_config_path . $file_name; if (!isset($this->_config_data[$file_name])) $this->load_file($file_name, false); } if (!empty($var_name)) { if (empty($section_name)) { return $this->_config_data[$file_name]["vars"][$var_name]; } else return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]; } else { if (empty($section_name)) return (array)$this->_config_data[$file_name]["vars"]; else return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"]; } } /** * Retrieves config info based on the key. * * @access public * @param $file_name string config key (filename/section/var) * @return mixed a value or array of values */ function &get_key($config_key) { list($file_name, $section_name, $var_name) = explode('/', $config_key, 3); $result = &$this->get($file_name, $section_name, $var_name); return $result; } /** * Get all loaded config file names. * * @access public * @return array an array of loaded config file names */ function get_file_names() { return array_keys($this->_config_data); } /** * Get all section names from a loaded file. * * @access public * @param $file_name string config file to get section names from * @return array an array of section names from the specified file */ function get_section_names($file_name) { $file_name = $this->_config_path . $file_name; if (!isset($this->_config_data[$file_name])) { $this->_trigger_error_msg("Unknown config file '$file_name'"); return; } return array_keys($this->_config_data[$file_name]["sections"]); } /** * Get all global or section variable names. * * @access public * @param $file_name string config file to get info for * @param $section_name string (optional) section to get info for * @return array an array of variables names from the specified file/section */ function get_var_names($file_name, $section = NULL) { if (empty($file_name)) { $this->_trigger_error_msg('Empty config file name'); return; } else if (!isset($this->_config_data[$file_name])) { $this->_trigger_error_msg("Unknown config file '$file_name'"); return; } if (empty($section)) return array_keys($this->_config_data[$file_name]["vars"]); else return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]); } /** * Clear loaded config data for a certain file or all files. * * @access public * @param $file_name string file to clear config data for */ function clear($file_name = NULL) { if ($file_name === NULL) $this->_config_data = array(); else if (isset($this->_config_data[$file_name])) $this->_config_data[$file_name] = array(); } /** * Load a configuration file manually. * * @access public * @param $file_name string file name to load * @param $prepend_path boolean whether current config path should be prepended to the filename */ function load_file($file_name, $prepend_path = true) { if ($prepend_path && $this->_config_path != "") $config_file = $this->_config_path . $file_name; else $config_file = $file_name; ini_set('track_errors', true); $fp = @fopen($config_file, "r"); if (!is_resource($fp)) { $this->_trigger_error_msg("Could not open config file '$config_file'"); return; } $contents = fread($fp, filesize($config_file)); fclose($fp); $config_data = array(); /* Get global variables first. */ if (preg_match("/^(.*?)(\n\[|\Z)/s", $contents, $match)) $config_data["vars"] = $this->_parse_config_block($match[1]); /* Get section variables. */ $config_data["sections"] = array(); preg_match_all("/^\[(.*?)\]/m", $contents, $match); foreach ($match[1] as $section) { if ($section{0} == '.' && !$this->read_hidden) continue; if (preg_match("/\[".preg_quote($section)."\](.*?)(\n\[|\Z)/s", $contents, $match)) if ($section{0} == '.') $section = substr($section, 1); $config_data["sections"][$section]["vars"] = $this->_parse_config_block($match[1]); } $this->_config_data[$config_file] = $config_data; } function _parse_config_block($config_block) { $vars = array(); /* First we grab the multi-line values. */ if (preg_match_all("/^([^=\n]+)=\s*\"{3}(.*?)\"{3}\s*$/ms", $config_block, $match, PREG_SET_ORDER)) { for ($i = 0; $i < count($match); $i++) { $this->_set_config_var($vars, trim($match[$i][1]), $match[$i][2], false); } $config_block = preg_replace("/^[^=\n]+=\s*\"{3}.*?\"{3}\s*$/ms", "", $config_block); } $config_lines = preg_split("/\n+/", $config_block); foreach ($config_lines as $line) { if (preg_match("/^\s*(\.?\w+)\s*=(.*)/", $line, $match)) { $var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', trim($match[2])); $this->_set_config_var($vars, trim($match[1]), $var_value, $this->booleanize); } } return $vars; } function _set_config_var(&$container, $var_name, $var_value, $booleanize) { if ($var_name{0} == '.') { if (!$this->read_hidden) return; else $var_name = substr($var_name, 1); } if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) { $this->_trigger_error_msg("Bad variable name '$var_name'"); return; } if ($booleanize) { if (preg_match("/^(on|true|yes)$/i", $var_value)) $var_value = true; else if (preg_match("/^(off|false|no)$/i", $var_value)) $var_value = false; } if (!isset($container[$var_name]) || $this->overwrite) $container[$var_name] = $var_value; else { settype($container[$var_name], 'array'); $container[$var_name][] = $var_value; } } function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING) { trigger_error("Config_File error: $error_msg", $error_type); } } ?> --- NEW FILE: Smarty.class.php --- <?php /* * Project: Smarty: the PHP compiling template engine * File: Smarty.class.php * Author: Monte Ohrt <mo...@is...> * Andrei Zmievski <an...@ph...> * * Version: 2.2.0 * Copyright: 2001,2002 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. [...1933 lines suppressed...] // windows pathnames $_path_array = explode(';',$_ini_include_path); } else { $_path_array = explode(':',$_ini_include_path); } } foreach ($_path_array as $_include_path) { if (@file_exists($_include_path . DIR_SEP . $file_path)) { $new_file_path = $_include_path . DIR_SEP . $file_path; return true; } } return false; } } /* vim: set expandtab: */ ?> --- NEW FILE: Smarty_Compiler.class.php --- <?php /* * Project: Smarty: the PHP compiling template engine * File: Smarty_Compiler.class.php * Author: Monte Ohrt <mo...@is...> * Andrei Zmievski <an...@ph...> * * Version: 2.2.0 * Copyright: 2001,2002 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU [...1354 lines suppressed...] } } } } /*======================================================================*\ Function: _syntax_error Purpose: display Smarty syntax error \*======================================================================*/ function _syntax_error($error_msg, $error_type = E_USER_ERROR) { trigger_error("Smarty: [in " . $this->_current_file . " line " . $this->_current_line_no . "]: syntax error: $error_msg", $error_type); } } /* vim: set et: */ ?> --- NEW FILE: template_ext.php --- <? /****************************************************************************** ******************************************************************************* phpMP - The World's Greatest Modular Portal *********************************************** Are you MPowered? Copyright (C) 2002 phpMP Development Group All rights reserved. Lead Programmer: Brian Rose Lead Designer: Trevor Joynson Filename: /includes/template_ext.php Usage & Function: Contains Template-Smarty Class Create Date: July 25, 2002 $Id: template_ext.php,v 1.1 2002/07/25 11:06:25 heimidal Exp $ ******************************************************************************* ******************************************************************************* This software is provided under the GPL software license. A copy of the license should have been included with this software, located in the Docs folder. Feel free to redistribute and/or modify it according to the regulations stated in the license. ******************************************************************************* ******************************************************************************* Notes on this document: Database abstraction classes have been partially taken from jimmacr's phpusion project. Some source code has been modified, but most functions do exactly the same thing he intended them for. Most likely, this code will be mostly rewritten by project release. ******************************************************************************* ******************************************************************************/ class Template extends Smarty { var $TPLVars; function Template() { // Class Constructor. These automatically get set with each new instance. global $MPCONF; $this->template_dir = $MPCONF['GEN']['abs_path'] . '/templates/' . $MPCONF['TPL']['tpl_name']; $this->compile_dir = $MPCONF['GEN']['abs_path'] . '/templates/' . $MPCONF['TPL']['tpl_name'] . '/compile'; $this->config_dir = $MPCONF['GEN']['abs_path'] . '/templates/' . $MPCONF['TPL']['tpl_name'] . '/configs'; $this->cache_dir = ''; $this->force_compile = 1; $this->caching = false; //Hopefully we'll get caching working eventually. } function add_blocks($side) { global $MPCONF, $DBA; $sql = "SELECT * FROM " . $MPCONF['DB']['table_prefix'] . "blocking WHERE side='" . $side . "' ORDER BY weight"; $data = $DBA->query($sql); $i = 0; while($data_array = $DBA->fetch_array($data)) { $blockname = ""; $content = ""; $blockname = $data_array['blockname']; if($data_array['is_php'] == '1') { include($MPCONF['GEN']['abs_path'] . '/modules/' . $data_array['php_file']); } else { $content = $data_array['content']; } $this->TPLVars["$side"][$i]['name'] = $blockname; $this->TPLVars["$side"][$i]['content'] = $content; $i++; } } function assign_defaults() { global $MPCONF, $DBA; $this->assign( array( "abspath" => $MPCONF['GEN']['abs_path'], "mpuri" => $MPCONF['GEN']['uri'], "site_address" => $MPCONF['GEN']['address'], "date" => date('l, F jS, Y'), "tpl_name" => $MPCONF['TPL']['tpl_name'], "copyright" => $MPCONF['TPL']['copyright'], "site_name" => $MPCONF['TPL']['sitename'], "bullet_html" => $MPCONF['TPL']['bullet_html'], ) ); } function display_template($temp_name) { global $DBA, $Debug; $this->add_blocks('left'); $this->add_blocks('right'); $this->assign_defaults(); $Debug->endTimer(); $this->assign("debug_info","debug mode :: " . $DBA->stats['query_count'] . " queries executed :: executed in " . $Debug->totaltime . " seconds"); $this->assign( "blocking", $this->TPLVars ); $this->display($temp_name . ".tpl"); } } ?> Index: core.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/core.php,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -r1.14 -r1.15 *** core.php 25 Jul 2002 06:16:22 -0000 1.14 --- core.php 25 Jul 2002 11:06:25 -0000 1.15 *************** *** 40,44 **** ******************************************************************************/ ! class Debug { var $starttime; --- 40,44 ---- ******************************************************************************/ ! class Debug { //Taken from InvisionBoard and modified lightly. Will replace eventually. var $starttime; *************** *** 73,77 **** global $MPCONF; ! if($core_files!="") { $core_array = explode(',', "$core_files"); // Splits core_files. } --- 73,77 ---- global $MPCONF; ! if($core_files != "") { $core_array = explode(',', "$core_files"); // Splits core_files. } *************** *** 80,84 **** $core_array[] = 'functions'; $core_array[] = 'auth'; ! $core_array[] = 'template'; for($i=0; $i < count($core_array); $i++) { --- 80,85 ---- $core_array[] = 'functions'; $core_array[] = 'auth'; ! $core_array[] = 'Smarty.class'; ! $core_array[] = 'template_ext'; for($i=0; $i < count($core_array); $i++) { *************** *** 98,102 **** $Template = new Template(); ! if($var_files!="") { $var_array = explode(',', "$var_files"); // Splits var_files. } --- 99,103 ---- $Template = new Template(); ! if($var_files != "") { $var_array = explode(',', "$var_files"); // Splits var_files. } --- template.php DELETED --- |