Thread: [phpMP-CVS] CVS: phpMP/core admin.php,NONE,1.1 config.init.php,NONE,1.1 constants.php,NONE,1.1 core.
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2003-09-14 06:37:58
|
Update of /cvsroot/phpmp/phpMP/core In directory sc8-pr-cvs1:/tmp/cvs-serv9778/core Added Files: admin.php config.init.php constants.php core.php debug.php functions.php index.html language.php mpcode.php mpcode_arrays.php session.php template.php user.php Log Message: This should be fun. --- NEW FILE: admin.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: admin.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ class Admin { var $p_action; // Action desired by the user // Executes the given admin action // Author: Anthony White // Accepts: $action - actions as defined above, used in switch / case // Returns: none. function execute($action) { $this->p_action = $action; switch ($action) { case C_ACTION_SITE: $this->_show_site(); break; case C_ACTION_USER: $this->_show_user(); break; default: break; } } // Shows the general management form // Author: Anthony White // Accepts: none. // Returns: none. function _show_site() { // Print out a form for the user print "<form method=\"post\" action=\"main.php?parse=" . $this->p_action . "\">"; print "Site Name: <input type=\"text\" name=\"sname\" value=\"" . C_SITE_NAME . "\"><br>"; if (C_OVERRIDE_USR_TPL == 1) { $checked = "CHECKED"; } else { $checked = ""; } print "Default Template: <input type=\"text\" name=\"deftpl\" value=\"" . C_DEFAULT_TPL . "\">"; print " <input type=\"checkbox\" name=\"ovrtpl\" value=\"0\" " . $checked . "> Override User Template?<br>"; print "Default Language: <input type=\"text\" name=\"deflang\" value=\"" . C_DEFAULT_LANG . "\"> (french, english)<br>"; // Should / Will be a dropdown list print "Default Date Format: <input type=\"text\" name=\"defdate\" value=\"" . C_DEFAULT_DATE_FORMAT . "\"> (Example: " . date(C_DEFAULT_DATE_FORMAT) . ") [Same syntax as the PHP date function]<br>"; print "Account Activation Level: "; print "<select name=\"accact\">"; if (C_ENABLE_ACCOUNT_ACTIVATION == 0) { $sel0 = "SELECTED"; } if (C_ENABLE_ACCOUNT_ACTIVATION == 1) { $sel1 = "SELECTED"; } if (C_ENABLE_ACCOUNT_ACTIVATION == 2) { $sel2 = "SELECTED"; } print "<option value=\"0\" " . $sel0 . ">No Activation"; print "<option value=\"1\" " . $sel1 . ">User Activation"; print "<option value=\"2\" " . $sel2 . ">Admin Activation"; print "</select><br>"; print "System Timezone: "; print "<select name=\"systime\">"; print "<option value=\"" . GMT_MINUS_12 . "\">GMT -12 (International Dateline West)"; print "<option value=\"" . GMT_MINUS_11 . "\">GMT -11 (Midway Island, Simoa)"; print "<option value=\"" . GMT_MINUS_10 . "\">GMT -10 (Hawaii)"; print "<option value=\"" . GMT_MINUS_9 . "\">GMT -9 (Alaska)"; print "<option value=\"" . GMT_MINUS_8 . "\">GMT -8 (Pacific Time)"; print "<option value=\"" . GMT_MINUS_7 . "\">GMT -7 (Arizona, Mountain Time)"; print "<option value=\"" . GMT_MINUS_6 . "\">GMT -6 (Central Time)"; print "<option value=\"" . GMT_MINUS_5 . "\">GMT -5 (Eastern Time)"; print "<option value=\"" . GMT_MINUS_4 . "\">GMT -4 (Atlantic Time)"; print "<option value=\"" . GMT_MINUS_3_30 . "\">GMT -3.5 (Newfoundland)"; print "<option value=\"" . GMT_MINUS_3 . "\">GMT -3 (Greenland)"; print "<option value=\"" . GMT_MINUS_2 . "\">GMT -2 (Mid-Atlantic)"; print "<option value=\"" . GMT_MINUS_1 . "\">GMT -1 (Cape Verda Islands)"; print "<option value=\"" . GMT . "\">GMT (Greenwich Mean Time)"; print "<option value=\"" . GMT_PLUS_1 . "\">GMT +1 (Paris)"; print "<option value=\"" . GMT_PLUS_2 . "\">GMT +2 (Jerusalem)"; print "<option value=\"" . GMT_PLUS_3 . "\">GMT +3 (Moscow)"; print "<option value=\"" . GMT_PLUS_4 . "\">GMT +4 (Abu Dhabi)"; print "<option value=\"" . GMT_PLUS_4_30 . "\">GMT +4.5 (Kabul)"; print "<option value=\"" . GMT_PLUS_5 . "\">GMT +5 (Karachi)"; print "<option value=\"" . GMT_PLUS_5_30 . "\">GMT +5.5 (New Delhi)"; print "<option value=\"" . GMT_PLUS_5_45 . "\">GMT +5.75 (Kathmandu)"; print "<option value=\"" . GMT_PLUS_6 . "\">GMT +6 (Almaty)"; print "<option value=\"" . GMT_PLUS_6_30 . "\">GMT +6.5 (Rangoon)"; print "<option value=\"" . GMT_PLUS_7 . "\">GMT +7 (Bangkok)"; print "<option value=\"" . GMT_PLUS_8 . "\">GMT +8 (Beijing)"; print "<option value=\"" . GMT_PLUS_9 . "\">GMT +9 (Tokyo)"; print "<option value=\"" . GMT_PLUS_9_30 . "\">GMT +9.5 (Adelaide)"; print "<option value=\"" . GMT_PLUS_10 . "\">GMT +10 (Brisbane)"; print "<option value=\"" . GMT_PLUS_11 . "\">GMT +11 (Solomon Islands)"; print "<option value=\"" . GMT_PLUS_12 . "\">GMT +12 (Auckland)"; print "<option value=\"" . GMT_PLUS_13 . "\">GMT +13 (Nuku'alofa)"; print "</select> (Current: " . C_SYSTEM_TIMEZONE . ")<br>"; if (C_USE_PORTAL_PERMS == 1) { $checked = "CHECKED"; } else { $checked = ""; } print "<input type=\"checkbox\" name=\"portperms\" value=\"1\" " . $checked . "> Use Portal Permissions?<br>"; print "<input type=\"submit\" name=\"submit_general\" value=\"Submit Configuration\">"; print "</form>"; } // Parses the general management form // Author: Anthony White // Accepts: Form values from the site config form // Returns: none. function parse_site($sname, $ovrtpl, $deftpl, $deflang, $defdate, $accact, $systime, $portperms) { include_once( C_PHPMP_ROOT . 'dba/' . DB_TYPE . '.dba' ); $DB = new DB; if ($ovrtpl != 1) { $ovrtpl = 0; } if ($portperms != 1) { $portperms = 0; } // We now go through each config_value and update it accordingly // I dont know if this is the only way, but it works fine for me $DB->query("UPDATE " . DB_CONFIG_TABLE . " SET config_value='" . $sname . "' WHERE config_key='site_name'"); $DB->query("UPDATE " . DB_CONFIG_TABLE . " SET config_value='" . $ovrtpl . "' WHERE config_key='override_usr_tpl'"); $DB->query("UPDATE " . DB_CONFIG_TABLE . " SET config_value='" . $deftpl . "' WHERE config_key='default_tpl'"); $DB->query("UPDATE " . DB_CONFIG_TABLE . " SET config_value='" . $deflang . "' WHERE config_key='default_lang'"); $DB->query("UPDATE " . DB_CONFIG_TABLE . " SET config_value='" . $defdate . "' WHERE config_key='default_date_format'"); $DB->query("UPDATE " . DB_CONFIG_TABLE . " SET config_value='" . $accact . "' WHERE config_key='enable_account_activation'"); $DB->query("UPDATE " . DB_CONFIG_TABLE . " SET config_value='" . $systime . "' WHERE config_key='system_timezone'"); $DB->query("UPDATE " . DB_CONFIG_TABLE . " SET config_value='" . $portperms . "' WHERE config_key='use_portal_perms'"); } // Shows the user selection form // Author: Anthony White // Accepts: none. // Returns: none. function _show_user() { include_once( C_PHPMP_ROOT . 'dba/' . DB_TYPE . '.dba' ); $DB = new DB; print "<form method=\"post\" action=\"main.php?parse=" . $this->p_action . "\">"; print "Select user to edit: <select name=\"userid\">"; $query = $DB->query("SELECT * FROM " . DB_USERS_TABLE); while ($user = $DB->fetchArray($query)) { if ($user[userid] != 1) { print "<option value=\"" . $user[userid] . "\">" . $user[username]; } } print "</select><br>"; print "<input type=\"submit\" name=\"submit_user\" value=\"Edit User\">"; print "</form>"; } // Shows user management form // Author: Anthony White // Accepts: none. // Returns: none. function show_user($userid) { if (!$userid || $userid == 1) { print "Invalid User"; return; } include_once( C_PHPMP_ROOT . 'dba/' . DB_TYPE . '.dba' ); $DB = new DB; $query = $DB->query("SELECT * FROM " . DB_USERS_TABLE . " WHERE userid=" . $userid); $user = $DB->fetchArray($query); // Print out the form for management print "<form method=\"post\" action=\"main.php?parse=" . ($this->p_action + 1) . "\">"; print "Username: <input type=\"text\" name=\"username\" value=\"" . $user[username] . "\"><br>"; print "Password: <input type=\"password\" name=\"passwd\"> (Leave blank to not change)<br>"; print "Email: <input type=\"email\" name=\"email\" value=\"" . $user[email] . "\"><br>"; print "Authentication Level: <select name=\"auth_level\">"; switch ($user[auth_level]) { case AUTH_LVL_MEM: $sel1 = "SELECTED"; break; case AUTH_LVL_CONTRIB: $sel2 = "SELECTED"; break; case AUTH_LVL_MOD: $sel3 = "SELECTED"; break; case AUTH_LVL_ADMIN: $sel4 = "SELECTED"; break; default: break; } print "<option value=\"1\" " . $sel1 . ">Standard Member"; print "<option value=\"2\" " . $sel2 . ">Contributor"; print "<option value=\"3\" " . $sel3 . ">Moderator"; print "<option value=\"4\" " . $sel4 . ">Administrator"; print "</select><br>"; print "Date Format: <input type=\"text\" name=\"date_format\" value=\"" . $user[date_format] . "\"><br>"; print "Template: <input type=\"text\" name=\"template\" value=\"" . $user[template] . "\"><br>"; print "Signature:<br>"; print "<textarea name=\"signature\" rows=\"5\" cols=\"40\">" . $user[signature] . "</textarea><br>"; print "<input type=\"checkbox\" name=\"delete\" value=\"delete\"> Delete User? (WARNING: This deletes the user for good)<br>"; print "<input type=\"submit\" name=\"submit_user_parse\" value=\"Submit User Changes\">"; print "<input type=\"hidden\" name=\"userid\" value=\"" . $user[userid] . "\">"; print "</form>"; } // Parse the user management form // Author: Anthony White // Accepts: The form variables // Returns: none. function parse_user($userid, $username, $passwd, $email, $auth_level, $date_format, $template, $signature, $delete) { include_once( C_PHPMP_ROOT . 'dba/' . DB_TYPE . '.dba' ); $DB = new DB; if ($delete == "delete") { $DB->query("DELETE FROM " . DB_USERS_TABLE . " WHERE userid='" . $userid . "'"); return; } if ($passwd != "") { $DB->query("UPDATE " . DB_USERS_TABLE . " SET passwd='" . $passwd . "' WHERE userid='" . $userid . "'"); } $DB->query("UPDATE " . DB_USERS_TABLE . " SET username='" . $username . "', email='" . $email . "', auth_level='" . $auth_level . "', date_format='" . $date_format . "', template='" . $template . "', signature='" . $signature . "' WHERE userid='" . $userid . "'"); } } ?> --- NEW FILE: config.init.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: config.init.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ class Config { var $_cfgvars; /** * @return void * @desc Fetches Config vars. */ function Config() { global $DB; $result = $DB->query( "SELECT * FROM " . DB_CONFIG_TABLE ); // Loop through all config values from DB. // Define each key as its respective value. while( $row = $DB->fetch_array( $result ) ) { $this->_cfgvars[$row['config_key']] = $row['config_value']; } } /** * @return unknown * @param cfgkey unknown * @param cfgval unknown * @desc Inserts the value of a given key into the Config array. */ function set($cfgkey, $cfgval) { if( (!empty($cfgkey)) && (preg_match('/^[a-z][a-z0-9_-]+/', $cfgkey)) && (!empty($cfgval)) ) { $this->_cfgvars[$cfgkey] = $cfgval; return true; } else { return false; } } /** * @return unknown * @param cfgkey unknown * @desc Fetches config array values. */ function get($cfgkey) { if( !empty($this->_cfgvars[$cfgkey]) ) { return $this->_cfgvars[$cfgkey]; } else { return false; } } } ?> --- NEW FILE: constants.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: constants.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ define('ACTIVATE_DISABLED', 0); define('ACTIVATE_USER', 1); define('ACTIVATE_ADMIN', 2); define('ANONYMOUS', 1); define('AUTH_LVL_GUEST', 0); // Guest. define('AUTH_LVL_MEM', 1); // Standard Member define('AUTH_LVL_CONTRIB', 2); // Contributor define('AUTH_LVL_MOD', 3); // Moderator define('AUTH_LVL_ADMIN', 4); // Administrator define('SESS_LOC_COOKIE', 1); //Sessions stored in cookie. define('SESS_LOC_URL', 2); //Sessions stored in URL. // Timezones according to Windows. Probably wrong, but hey.. define('GMT_MINUS_12', -12); // International Date Line West. define('GMT_MINUS_11', -11); // Midway Island, Simoa. define('GMT_MINUS_10', -10); // Hawaii. define('GMT_MINUS_9', -9); // Alaska. define('GMT_MINUS_8', -8); // Pacific Time. define('GMT_MINUS_7', -7); // Arizona, Mountain Time. define('GMT_MINUS_6', -6); // Central Time. define('GMT_MINUS_5', -5); // Eastern Time. define('GMT_MINUS_4', -4); // Atlantic Time. define('GMT_MINUS_3_30', -3.5); // Newfoundland. define('GMT_MINUS_3', -3); // Greenland. define('GMT_MINUS_2', -2); // Mid-Atlantic. define('GMT_MINUS_1', -1); // Cape Verda Is. define('GMT', 0); // Greenwich Mean Time. define('GMT_PLUS_1', 1); // Paris. define('GMT_PLUS_2', 2); // Jerusalem. define('GMT_PLUS_3', 3); // Moscow. define('GMT_PLUS_4', 4); // Abu Dhabi. define('GMT_PLUS_4_30', 4.5); // Kabul. define('GMT_PLUS_5', 5); // Karachi. define('GMT_PLUS_5_30', 5.5); // New Delhi. define('GMT_PLUS_6', 6); // Almaty. define('GMT_PLUS_6_30', 6.5); // Rangoon. define('GMT_PLUS_7', 7); // Bangkok. define('GMT_PLUS_8', 8); // Beijing. define('GMT_PLUS_9', 9); // Tokyo. define('GMT_PLUS_19_30', 9.5); // Adelaide. define('GMT_PLUS_10', 10); // Brisbane. define('GMT_PLUS_11', 11); // Solomon Is. define('GMT_PLUS_12', 12); // Auckland. define('GMT_PLUS_13', 13); // Nuku'alofa. define('DEBUG_ON', 1); //define('DEBUG_ON', 0); ?> --- NEW FILE: core.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: core.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ class Core // Does, literally, everything. { /** * @return arr array * @param arr array * @desc Strips magic quotes from the * superglobal arrays. */ function strip_magic_quotes($arr) { foreach ($arr as $k => $v) { if (is_array($v)) { $arr[$k] = strip_magic_quotes($v); } else { $arr[$k] = stripslashes($v); } } return $arr; } /** * @return void * @param optional_files array * @desc Initiates all core components. */ function Core( $optional_files = array() ) { // The following code ensures that, no matter what, the dreaded // magic_quotes function will *never* mess with our data. // The addslashes() function *should* be used when necessary. // The stripslashes() function is worthless with these fixes in place. set_magic_quotes_runtime(0); if (get_magic_quotes_gpc()) { if (!empty($_GET)) { $_GET = $this->strip_magic_quotes($_GET); } if (!empty($_POST)) { $_POST = $this->strip_magic_quotes($_POST); } if (!empty($_COOKIE)) { $_COOKIE = $this->strip_magic_quotes($_COOKIE); } } error_reporting(E_ALL); //error_reporting(E_ERROR | E_WARNING | E_PARSE); $blah = include_once( C_PHPMP_ROOT . 'config.php' ); // Globalize all major class-containing variables. global $Config, $Debug, $DB, $User, $MPCode, $Template; include_once( C_PHPMP_ROOT . 'includes/debug.php' ); $Debug = new Debug(); include_once( C_PHPMP_ROOT . 'includes/dba/' . DB_TYPE . '.dba' ); $DB = new DB(); $DB->connect(); define('DB_CONFIG_TABLE', DB_NAME . '.' . DB_TABLE_PREFIX . 'config'); define('DB_USERS_TABLE', DB_NAME . '.' . DB_TABLE_PREFIX . 'users'); define('DB_SESSIONS_TABLE', DB_NAME . '.' . DB_TABLE_PREFIX . 'sessions'); define('DB_MODULES_TABLE', DB_NAME . '.' . DB_TABLE_PREFIX . 'modules'); define('DB_BLOCK_TABLE', DB_NAME . '.' . DB_TABLE_PREFIX . 'blocks'); define('DB_TEMPLATE_VARS_TABLE', DB_NAME . '.' . DB_TABLE_PREFIX . 'template_vars'); include_once(C_PHPMP_ROOT . 'includes/config.init.php'); $Config = new Config(); include_once(C_PHPMP_ROOT . 'includes/constants.php'); include_once(C_PHPMP_ROOT . 'includes/functions.php'); include_once(C_PHPMP_ROOT . 'includes/user.php'); $User = new User(); // Create an instance of User. create_vars(); include_once(C_PHPMP_ROOT . 'includes/session.php'); $Session = new Session(); $Session->start(); $Session->run(); include_once(C_PHPMP_ROOT . 'includes/language.php'); $Language = new Language(); include_once(C_PHPMP_ROOT . 'includes/mpcode.php'); // This while() statement will loop through the // $optional_files and include each file. if(count($optional_files) > 0) { $i = 0; while( $my_file = $optional_files[$i] ) { include_once(C_PHPMP_ROOT . 'includes/' . $my_file . '.php'); $i++; } } include_once(C_PHPMP_ROOT . 'includes/template.php'); $Template = new Template(); if( $User->get('template') == false ) { $Config->set('template', $Config->get('default_tpl')); } else { $Config->set('template', $User->get('template')); } $Template->set_template( $Config->get('template'), false, true ); $DB->close(); } } ?> --- NEW FILE: debug.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: debug.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ class Debug { /** * @return void * @desc Sets the error handler. */ function Debug() { @set_error_handler( array(&$this, 'msg_display') ); } /** * @return void * @param errno int * @param msg_text string * @param errfile string * @param errline int * @desc Error/message handler. Taken from phpBB2. I still don't quite understand it. :P */ function msg_display($errno, $msg_text, $errfile, $errline) { global $DB, $Config, $User, $Template; switch($errno) { case E_WARNING: break; case E_NOTICE: echo "PHP Notice on line <b>$errline</b> in <b>$errfile</b> :: <b>$msg_text</b><br />"; break; case E_USER_ERROR: if(isset($DB)) { $DB->close(); echo $msg_text; } break; case E_USER_NOTICE: echo "A User Notice has been issued. Please notify the <a href=\"mailto: " . $Config['site_contact'] . "\">board administrator</a>."; break; } } } ?> --- NEW FILE: functions.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: functions.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ /** * @return void * @desc Creates vars with no other place. Temporary. */ function create_vars() { global $Config, $User; ( $User->get('date_format') != '' ) ? ($Config->set('date_format', $User->get('date_format'))) : ($Config->set('date_format', $Config->get('default_date_format'))); $Config->set('time_now', date( $Config->get('date_format') ) ); // This is here...for now. } ?> --- NEW FILE: index.html --- <html> <head> <title>Sorry...</title> </head> <body> This directory is not directly accessible. </body> </html> --- NEW FILE: language.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: language.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ class Language { /** * @return void * @desc Discovers the user's language and creates the corresponding Local object. */ function Language() { global $Config, $User, $Local; $cfg_lang = $Config->get('default_lang'); $usr_lang = $User->get('language'); $lang = ''; (empty($usr_lang)) ? $lang = $cfg_lang : $lang = $usr_lang; $Config->set('language', $lang); $lang_file = C_PHPMP_ROOT . 'languages/' . $lang . '/lang_main.php'; if (!file_exists($lang_file)) { trigger_error("localization error - \"$lang_file\" does not exist.", E_USER_ERROR); } include_once( $lang_file ); } } ?> --- NEW FILE: mpcode.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: mpcode.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ // Content parsing functions to be developed here. // These work similarly to BBCode and the like. // Work here done by anthony. If you dont like it feel free to change it. // Deprecated. class mpcode { function parse_string($string) { if ($string == "") return; $split = explode(" ", $string); foreach ($split as $key => $code) { if ($key == count($split) - 1) $final .= $this->_replace($code); else $final .= $this->_replace($code) . " "; } return $final; } // This may not be the best way, but it works function _replace($string) { include (C_PHPMP_ROOT . "includes/mpcode_arrays.php"); foreach ($mpcode as $key => $code) { $string = str_replace($code, $html[$key], $string); } return $string; } } ?> --- NEW FILE: mpcode_arrays.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: mpcode_arrays.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ // Contains the mpcode and corresponding html arrays // Deprecated. $mpcode = array( "[b]", "[/b]", "[i]", "[/i]" ); $html = array( "<b>", "</b>", "<i>", "</i>" ); ?> --- NEW FILE: session.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: session.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ class Session // Creates and maintains sessions for all users. { var $started = false; var $session_data; var $session_key; var $do_login = false; var $is_logged_in = false; var $session_key_new = false; var $session_user_id; var $ip; var $page; /** * @return void * @desc Starts a session. Must be called implicitly. */ function start() { // We'll only start a session if // one hasn't already been started. if($this->started == false) { $this->get_session_data(); $this->started = true; } } /** * @return void * @desc Destroys sessions. Used for logging out. */ function destroy() { global $DB, $Config, $SID; $exp_time = time() + $Config->get('session_length'); $this->page = basename($_SERVER['REQUEST_URI']); // Sets the session as owned by an anonymous user. // Since there's no reason to use a different session key, we'll keep that. $sql = "UPDATE " . DB_SESSIONS_TABLE . " SET session_exp_time=" . $exp_time . " AND session_page='" . $this->page . "' AND session_user_id=" . ANONYMOUS . " WHERE session_key='" . $this->session_key . "'"; $DB->query($sql); $this->session_user_id = ANONYMOUS; setcookie($Config->get('cookie_name') . '_auto', '', time() - 31536000, $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure')); $cookie_data = urlencode( ANONYMOUS . ':' . $this->session_key ); (setcookie($Config->get('cookie_name') . '_data', $cookie_data, $cur_time + $Config->get('session_length'), $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure'))) ? ($SID = "?sid=") : ($SID = "?sid=" . $this->session_key); } /** * @return void * @desc Logs a user in. */ function login() { global $User, $DB, $Config; $this->do_login == true; // We are logging in. Set up variables. $username = addslashes($_POST['login_username']); $passwd_enc = md5($_POST['login_passwd']); $auto_login_set = $_POST['autologin']; $invisible_mode = $_POST['invisible_mode']; $sql = "SELECT * FROM " . DB_USERS_TABLE . " WHERE user_name='" . $username . "' AND user_passwd='" . $passwd_enc . "'"; $result = $DB->query($sql); $num_rows = $DB->num_rows($result); if( $num_rows == 1 ) // We have a user! { $User->set( $DB->fetch_assoc($result) ); $this->session_user_id = $User->get('user_id'); $this->is_logged_in = true; // We'll look into the invisible mode setting and ensure the user's wishes are met. ($invisible_mode == true) ? ( $User->set('invisible_mode', 1) ) : ( $User->set('invisible_mode', 0) ); // We'll set up an autologin cookie if the user wants us to. if( $auto_login_set == true ) { $auto_cookie_data = urlencode( $this->session_user_id . ':' . $passwd_enc . ':' . $User->get('invisible_mode') ); setcookie($Config->get('cookie_name') . '_auto', $auto_cookie_data, time() + 31536000, $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure')); } } else // Wrong login information. { die('Sorry. Your username and/or password are incorrect.'); } } /** * @return void * @desc Saves the session data to the database. */ function run() { global $User, $DB, $Config, $SID; if( isset($_POST['do_login']) && ($_POST['do_login'] == true) ) { $this->login(); } // Checks to see if a session has been started. // If not, we'll die because we want to explicitly declare sessions. if( $this->started == false ) { die('You must explicitly declare all $Session->start calls.'); } // Capture the page we're at. //$this->page = basename($_SERVER['REQUEST_URI']); $cur_time = time(); // Time as of right now. $exp_time = $cur_time + $Config->get('session_length'); // Time at which this session will become invalid. $this->ip = $User->get_ip_encoded(); // Gets the user's IP address. $session_exists = false; // We'll assume that no sessions exist yet. // If the ID is new, why bother querying to test for an old one? if( $this->session_key_new == false ) { // Gathers session data from the database. $sql = "SELECT * FROM " . DB_SESSIONS_TABLE . " WHERE session_key='" . $this->session_key . "' ORDER BY session_exp_time DESC"; $result = $DB->query($sql); $num_rows = $DB->num_rows($result); // Checks for a session in the database. ($num_rows >= 1) ? ($session_exists = true) : ($session_exists = false); // If the session is expired, we'll go ahead and create a new one regardless. // The old one *should* be cleaned out by our clean() function later. $this->session_data = $DB->fetch_assoc($result); if( $this->session_data['session_exp_time'] < $cur_time ) { $session_exists = false; } $this->session_user_id = $this->session_data['session_user_id']; } if( $session_exists == true ) // A session exists. Yay. { if( $this->is_logged_in == true ) // Swap out the anonymous user for our new user_id. { $sql = "UPDATE " . DB_SESSIONS_TABLE . " SET session_exp_time=" . $exp_time . ", session_page='" . addslashes($this->page) . "', session_user_id=" . $this->session_user_id . " WHERE session_key='" . $this->session_key . "'"; } else { $sql = "UPDATE " . DB_SESSIONS_TABLE . " SET session_exp_time=" . $exp_time . ", session_page='" . addslashes($this->page) . "' WHERE session_key='" . $this->session_key . "'"; } } else // A session does not exist. We'll create one. { if( $this->is_logged_in == false ) { $this->session_user_id = ANONYMOUS; } $sql = 'INSERT INTO ' . DB_SESSIONS_TABLE . ' (session_key, session_user_id, session_start_time, session_exp_time, session_page, session_ip) VALUES(\'' . $this->session_key . '\', ' . $this->session_user_id . ', ' . $cur_time . ', ' . $exp_time . ', \'' . addslashes($this->page) . '\', \'' . $this->ip . '\')'; } $DB->query($sql); if( $this->is_logged_in == false ) { $sql = 'SELECT * FROM ' . DB_USERS_TABLE . ' WHERE user_id=' . $this->session_user_id; $result = $DB->query($sql); $User->set( $DB->fetch_assoc($result) ); } $cookie_data = urlencode( $this->session_user_id . ':' . $this->session_key ); (setcookie($Config->get('cookie_name') . '_data', $cookie_data, $cur_time + $Config->get('session_length'), $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure'))) ? ($SID = "?sid=") : ($SID = "?sid=" . $this->session_key); $this->clean(); } /** * @return void * @param clean_all boolean * @desc Cleans out old session data. */ function clean($clean_all = false) { global $DB; $rand = rand(0,10); if(($rand <= 1) || ($clean_all == true)) // 1:10 chance of session cleanup. This may later become a setting. { $sql = "DELETE FROM " . DB_SESSIONS_TABLE . " WHERE session_exp_time<" . time(); $DB->query($sql); if((!empty($this->session_user_id)) && ($this->session_user_id != ANONYMOUS) && (!empty($this->session_key))) // Note that, if we reach this point, the following query will remove past sessions for this user which may not have expired. // This is good, but would be better if done for all users or if done during the creation of new sessions. { $sql = "DELETE FROM " . DB_SESSIONS_TABLE . " WHERE session_user_id=" . $this->session_user_id . " AND session_key!='" . $this->session_key . "'"; $DB->query($sql); } } } /** * @return void * @desc Grabs session data for the user. */ function get_session_data() { global $Config, $DB, $User; // Let's see if we have a standard cookie available. if(!empty($_COOKIE[$Config->get('cookie_name') . '_data'])) { $cookie_data = $_COOKIE[$Config->get('cookie_name') . '_data']; $cookie_array = explode(':', urldecode( $cookie_data ) ); // We have a cookie. Let's see if it's valid. if( ( !empty($cookie_array[0]) ) && ( strlen($cookie_array[1]) == 32 ) ) { // Our cookie is valid. Let's set a few vars. $this->session_user_id = $cookie_array[0]; $this->session_key = $cookie_array[1]; } } elseif(!empty($_GET['sid'])) { $this->session_key = $_GET['sid']; } if(empty($this->session_key)) // If we don't have a session key by now, there isn't one saved. { $this->session_key = md5( uniqid (microtime(), 1) ); $this->session_key_new = true; } // The user is currently anonymous, so let's check for auto-login. if( ($this->session_user_id == ANONYMOUS) || empty($this->session_user_id) ) { if( !empty( $_COOKIE[$Config->get('cookie_name') . '_auto'] ) ) // We have an autologin cookie set. { $auto_cookie_data = $_COOKIE[$Config->get('cookie_name') . '_auto']; $auto_cookie_array = explode(':', urldecode( $auto_cookie_data ) ); $sql = "SELECT * FROM " . DB_USERS_TABLE . " WHERE user_id=" . $auto_cookie_array[0] . " AND user_passwd='" . $auto_cookie_array[1] . "'"; $result = $DB->query($sql); $num_rows = $DB->num_rows($result); if( $num_rows == 1 ) // This cookie is valid. { $User->set( $DB->fetch_assoc($result) ); $User->set('invisible_mode', $auto_cookie_array[2]); $this->session_user_id = $auto_cookie_array[0]; $this->is_logged_in = true; } else // The autologin cookie was invalid. { // We'll unset the cookie and continue on like nothing ever happened. setcookie($Config->get('cookie_name') . '_auto', '', time() - 31536000, $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure')); return false; $this->session_user_id = ANONYMOUS; } } } } } ?> --- NEW FILE: template.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either vlersion 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: template.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ /* The following code was taken from or inspired by the guys over at phpBB. Any code resembling that of phpBB is probably their's and therefore they hold the legal rights to it. Since both phpBB and phpMP are released under the GPL, you must abide by said license. */ // Deprecated in favor of the (soon-to-be-started) Fission Template System. class Template { // variable that holds all the data we'll be substituting into // the compiled templates. Takes form: // --> $this->_tpldata[block.][iteration#][child.][iteration#][child2.][iteration#][variablename] == value // if it's a root-level variable, it'll be like this: // --> $this->_tpldata[.][0][varname] == value var $_tpldata = array(); // Root dir and hash of filenames for each template handle. var $root = ''; var $cache_root = 'cache/templates/'; var $files = array(); // this will hash handle names to the compiled/uncompiled code for that handle. var $compiled_code = array(); // Various counters and storage arrays var $block_names = array(); var $block_else_level = array(); var $block_nesting_level = 0; var $static_lang; var $force_recompile; function set_template($template = '', $static_lang = false, $force_recompile = false) { $this->root = C_PHPMP_ROOT . 'templates/' . $template; $this->cachedir = C_PHPMP_ROOT . $this->cache_root . $template . '/'; $this->static_lang = $static_lang; $this->force_recompile = $force_recompile; if (!file_exists($this->cachedir)) { @umask(0); mkdir($this->cachedir, 0777); } return true; } // Sets the template filenames for handles. $filename_array // should be a hash of handle => filename pairs. function set_filenames($filename_array) { if (!is_array($filename_array)) { return false; } $template_names = ''; foreach ($filename_array as $handle => $filename) { if (empty($filename)) { trigger_error("template error - Empty filename specified for $handle", E_USER_ERROR); } $this->filename[$handle] = $filename; $this->files[$handle] = $this->make_filename($filename); } return true; } // Generates a full path+filename for the given filename, which can either // be an absolute name, or a name relative to the rootdir for this Template // object. function make_filename($filename) { // Check if it's an absolute or relative path. return (substr($filename, 0, 1) != '/') ? $this->root . '/' . $filename : $filename; } // Destroy template data set function destroy() { $this->_tpldata = array(); } // Methods for loading and evaluating the templates function display($handle) { global $Config, $Local; if ($filename = $this->_tpl_load($handle)) { include($filename); } else { eval(' ?>' . $this->compiled_code[$handle] . '<?php '); } return true; } // Load a compiled template if possible, if not, recompile it function _tpl_load(&$handle) { global $Config, $user; $filename = $this->cachedir . $this->filename[$handle] . '.' . (($this->static_lang) ? $Config->get('language') . '.' : '') . 'php'; // Recompile page if the original template is newer, otherwise load the compiled version if (file_exists($filename) && !$this->force_recompile) { return $filename; } // If the file for this handle is already loaded and compiled, do nothing. if (!empty($this->uncompiled_code[$handle])) { return true; } // If we don't have a file assigned to this handle, die. if (!isset($this->files[$handle])) { trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR); } $str = ''; // Try and open template for read if (!($fp = @fopen($this->files[$handle], 'r'))) { trigger_error("template->_tpl_load(): File $filename does not exist or is empty", E_USER_ERROR); } $str = fread($fp, filesize($this->files[$handle])); @fclose($fp); // Actually compile the code now. $this->compiled_code[$handle] = $this->compile(trim($str)); $this->compile_write($handle, $this->compiled_code[$handle]); return false; } // Assign key variable pairs from an array function assign_vars($vararray) { foreach ($vararray as $key => $val) { $this->_tpldata['.'][0][$key] = $val; } return true; } // Assign a single variable to a single key function assign_var($varname, $varval) { $this->_tpldata['.'][0][$varname] = $varval; return true; } // Assign key variable pairs from an array to a specified block function assign_block_vars($blockname, $vararray) { if (strstr($blockname, '.')) { // Nested block. $blocks = explode('.', $blockname); $blockcount = sizeof($blocks) - 1; $str = &$this->_tpldata; for ($i = 0; $i < $blockcount; $i++) { $str = &$str[$blocks[$i]]; $str = &$str[sizeof($str) - 1]; } // Now we add the block that we're actually assigning to. // We're adding a new iteration to this block with the given // variable assignments. $str[$blocks[$blockcount]][] = $vararray; } else { // Top-level block. // Add a new iteration to this block with the variable assignments // we were given. $this->_tpldata[$blockname][] = $vararray; } return true; } // Include a seperate template function _tpl_include($filename, $include = true) { global $user, $Config, $Local; $handle = $filename; $this->filename[$handle] = $filename; $this->files[$handle] = $this->make_filename($filename); $filename = $this->_tpl_load($handle); if ($include) { // eval($this->compiled_code[$handle]); include($filename); } } // This next set of methods could be seperated off and included since // they deal exclusively with compilation ... which is done infrequently // and would save a fair few kb // The all seeing all doing compile method. Parts are inspired by or directly // from Smarty function compile($code, $no_echo = false, $echo_var = '') { global $Config; error_reporting(E_ERROR | E_WARNING | E_PARSE); // Remove any "loose" php ... we want to give admins the ability // to switch on/off PHP for a given template. Allowing unchecked // php is a no-no. There is a potential issue here in that non-php // content may be removed ... however designers should use entities // if they wish to display < and > $match_php_tags = array('#\<\?php .*?\?\>#is', '#\<\script language="php"\>.*?\<\/script\>#is', '#\<\?.*?\?\>#s', '#\<%.*?%\>#s'); $code = preg_replace($match_php_tags, '', $code); // Pull out all block/statement level elements and seperate // plain text preg_match_all('#<!-- PHP -->(.*?)<!-- ENDPHP -->#s', $code, $matches); $php_blocks = $matches[1]; $code = preg_replace('#<!-- PHP -->(.*?)<!-- ENDPHP -->#s', '<!-- PHP -->', $code); preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\.]+?) -->#', $code, $matches); $include_blocks = $matches[1]; $code = preg_replace('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\.]+?) -->#', '<!-- INCLUDE -->', $code); preg_match_all('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\.\\\\]+?) -->#', $code, $matches); $includephp_blocks = $matches[1]; $code = preg_replace('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\.]+?) -->#', '<!-- INCLUDEPHP -->', $code); preg_match_all('#<!-- (.*?) (.*?)?[ ]?-->#s', $code, $blocks); $text_blocks = preg_split('#<!-- (.*?) (.*?)?[ ]?-->#s', $code); for($i = 0; $i < count($text_blocks); $i++) { $this->compile_var_tags($text_blocks[$i]); } $compile_blocks = array(); /* for ($curr_tb = 0; $curr_tb < count($text_blocks); $curr_tb++) { switch ($blocks[1][$curr_tb]) { case 'BEGIN': $this->block_else_level[] = false; $compile_blocks[] = '<?php ' . $this->compile_tag_block($blocks[2][$curr_tb]) . ' ?>'; break; case 'BEGINELSE': $this->block_else_level[sizeof($this->block_else_level) - 1] = true; $compile_blocks[] = '<?php }} else { ?>'; break; case 'END': array_pop($this->block_names); $compile_blocks[] = '<?php ' . ((array_pop($this->block_else_level)) ? '}' : '}}') . ' ?>'; break; case 'IF': $compile_blocks[] = '<?php ' . $this->compile_tag_if($blocks[2][$curr_tb], false) . ' ?>'; break; case 'ELSE': $compile_blocks[] = '<?php } else { ?>'; break; case 'ELSEIF': $compile_blocks[] = '<?php ' . $this->compile_tag_if($blocks[2][$curr_tb], true) . ' ?>'; break; case 'ENDIF': $compile_blocks[] = '<?php } ?>'; break; case 'INCLUDE': $temp = ''; list(, $temp) = each($include_blocks); $compile_blocks[] = '<?php ' . $this->compile_tag_include($temp) . ' ?>'; $this->_tpl_include($temp, false); break; case 'INCLUDEPHP': if ($Config->get('tpl_php')) { $temp = ''; list(, $temp) = each($includephp_blocks); $compile_blocks[] = '<?php ' . $this->compile_tag_include_php($temp) . ' ?>'; } break; case 'PHP': if ($Config->get('tpl_php')) { $temp = ''; list(, $temp) = each($php_blocks); $compile_blocks[] = '<?php ' . $temp . ' ?>'; } break; default: $this->compile_var_tags($blocks[0][$curr_tb]); $trim_check = trim($blocks[0][$curr_tb]); $compile_blocks[] = (!$no_echo) ? ((!empty($trim_check)) ? $blocks[0][$curr_tb] : '') : ((!empty($trim_check)) ? $blocks[0][$curr_tb] : ''); break; } }*/ $template_php = ''; for ($i = 0; $i < count($text_blocks); $i++) { $trim_check_text = trim($text_blocks[$i]); // $trim_check_block = trim($compile_blocks[$i]); $template_php .= (!$no_echo) ? ((!empty($trim_check_text)) ? $text_blocks[$i] : '') . ((!empty($compile_blocks[$i])) ? $compile_blocks[$i] : '') : ((!empty($trim_check_text)) ? $text_blocks[$i] : '') . ((!empty($compile_blocks[$i])) ? $compile_blocks[$i] : ''); } // There will be a number of occassions where we switch into and out of // PHP mode instantaneously. Rather than "burden" the parser with this // we'll strip out such occurences, minimising such switching $template_php = str_replace(' ?><?php ', '', $template_php); return (!$no_echo) ? $template_php : "\$$echo_var .= '" . $template_php . "'"; } function compile_var_tags(&$text_blocks) { // change template varrefs into PHP varrefs $varrefs = array(); // This one will handle varrefs WITH namespaces preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $text_blocks, $varrefs); for ($j = 0; $j < sizeof($varrefs[1]); $j++) { $namespace = $varrefs[1][$j]; $varname = $varrefs[3][$j]; $new = $this->generate_block_varref($namespace, $varname); $text_blocks = str_replace($varrefs[0][$j], $new, $text_blocks); } // This will handle the remaining root-level varrefs if (!$this->static_lang) { global $Local; $text_blocks = preg_replace('#\{L_([a-z0-9\-_]*?)\}#is', "<?php echo ((isset(\$this->_tpldata['.'][0]['L_\\1'])) ? \$this->_tpldata['.'][0]['L_\\1'] : ((isset(\$Local->lang['\\1'])) ? \$Local->lang['\\1'] : '{ ' . ucfirst(strtolower(str_replace('_', ' ', '\\1'))) . ' }')); ?>", $text_blocks); } else { global $Local; $text_blocks = preg_replace('#\{L_([A-Z0-9\-_]*?)\}#e', "'<?php echo ((isset(\$this->_tpldata[\'.\'][0][\'L_\\1\'])) ? \$this->_tpldata[\'.\'][0][\'L_\\1\'] : \'' . ((isset(\$Local->lang['\\1'])) ? \$Local->lang['\\1'] : '') . '\'); ?>'" , $text_blocks); } $text_blocks = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "<?php echo \$this->_tpldata['.'][0]['\\1']; ?>", $text_blocks); return; } function compile_tag_block($tag_args) { $tag_template_php = ''; array_push($this->block_names, $tag_args); if (sizeof($this->block_names) < 2) { // Block is not nested. $tag_template_php = '$_' . $tag_args . "_count = (isset(\$this->_tpldata['$tag_args'])) ? sizeof(\$this->_tpldata['$tag_args']) : 0;"; } else { // This block is nested. // Generate a namespace string for this block. $namespace = implode('.', $this->block_names); // Get a reference to the data array for this block that depends on the // current indices of all parent blocks. $varref = $this->generate_block_data_ref($namespace, false); // Create the for loop code to iterate over this block. $tag_template_php = '$_' . $tag_args . '_count = (isset(' . $varref . ')) ? sizeof(' . $varref . ') : 0;'; } $tag_template_php .= 'if ($_' . $tag_args . '_count) {'; $tag_template_php .= 'for ($this->_' . $tag_args . '_i = 0; $this->_' . $tag_args . '_i < $_' . $tag_args . '_count; $this->_' . $tag_args . '_i++){'; return $tag_template_php; } // // Compile IF tags - much of this is from Smarty with // some adaptions for our block level methods // function compile_tag_if($tag_args, $elseif) { /* Tokenize args for 'if' tag. */ preg_match_all('/(?: "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" | \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' | [(),] | [^\s(),]+)/x', $tag_args, $match); $tokens = $match[0]; $is_arg_stack = array(); for ($i = 0; $i < count($tokens); $i++) { $token = &$tokens[$i]; switch (strtolower($token)) { case '!': case '%': case '!==': case '==': case '===': case '>': case '<': case '!=': case '<>': case '<<': case '>>': case '<=': case '>=': case '&&': case '||': case '|': case '^': case '&': case '~': case ')': case ',': case '+': case '-': case '*': case '/': case '@': break; case 'eq': $token = '=='; break; case 'ne': case 'neq': $token = '!='; break; case 'lt': $token = '<'; break; case 'le': case 'lte': $token = '<='; break; case 'gt': $token = '>'; break; case 'ge': case 'gte': $token = '>='; break; case 'and': $token = '&&'; break; case 'or': $token = '||'; break; case 'not': $token = '!'; break; case 'mod': $token = '%'; break; case '(': array_push($is_arg_stack, $i); break; case 'is': $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1; $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start)); $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1)); array_splice($tokens, $is_arg_start, count($tokens), $new_tokens); $i = $is_arg_start; default: if (preg_match('#^(([a-z0-9\-_]+?\.)+?)?([A-Z]+[A-Z0-9\-_]+?)$#s', $token, $varrefs)) { $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, strlen($varrefs[1]) - 1), true) . '[\'' . $varrefs[3] . '\']' : '$this->_tpldata[\'.\'][0][\'' . $varrefs[3] . '\']'; } break; } } return (($elseif) ? '} elseif (' : 'if (') . (implode(' ', $tokens) . ') { '); } function compile_tag_include($tag_args) { return "\$this->_tpl_include('$tag_args');"; } function compile_tag_include_php($tag_args) { return "include('" . $this->root . '/' . $tag_args . "');"; } // This is from Smarty function _parse_is_expr($is_arg, $tokens) { $expr_end = 0; $negate_expr = false; if (($first_token = array_shift($tokens)) == 'not') { $negate_expr = true; $expr_type = array_shift($tokens); } else { $expr_type = $first_token; } switch ($expr_type) { case 'even': if (@$tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; $expr = "!(($is_arg / $expr_arg) % $expr_arg)"; } else { $expr = "!($is_arg % 2)"; } break; case 'odd': if (@$tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; $expr = "(($is_arg / $expr_arg) % $expr_arg)"; } else { $expr = "($is_arg % 2)"; } break; case 'div': if (@$tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; $expr = "!($is_arg % $expr_arg)"; } break; default: break; } if ($negate_expr) { $expr = "!($expr)"; } array_splice($tokens, 0, $expr_end, $expr); return $tokens; } /** * Generates a reference to the given variable inside the given (possibly nested) * block namespace. This is a string of the form: * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . ' * It's ready to be inserted into an "echo" line in one of the templates. * NOTE: expects a trailing "." on the namespace. */ function generate_block_varref($namespace, $varname) { // Strip the trailing period. $namespace = substr($namespace, 0, strlen($namespace) - 1); // Get a reference to the data block for this namespace. $varref = $this->generate_block_data_ref($namespace, true); // Prepend the necessary code to stick this in an echo line. // Append the variable reference. $varref .= "['$varname']"; $varref = "<?php echo $varref; ?>"; return $varref; } /** * Generates a reference to the array of data values for the given * (possibly nested) block namespace. This is a string of the form: * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN'] * * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. * NOTE: does not expect a trailing "." on the blockname. */ function generate_block_data_ref($blockname, $include_last_iterator) { // Get an array of the blocks involved. $blocks = explode('.', $blockname); $blockcount = sizeof($blocks) - 1; $varref = '$this->_tpldata'; // Build up the string with everything but the last child. for ($i = 0; $i < $blockcount; $i++) { $varref .= "['" . $blocks[$i] . "'][\$this->_" . $blocks[$i] . '_i]'; } // Add the block reference for the last child. $varref .= "['" . $blocks[$blockcount] . "']"; // Add the iterator for the last child if requried. if ($include_last_iterator) { $varref .= '[$this->_' . $blocks[$blockcount] . '_i]'; } return $varref; } function compile_write(&$handle, $data) { global $user, $Config; $filename = $this->cachedir . $this->filename[$handle] . '.' . (($this->static_lang) ? $Config->get('language') . '.' : '') . 'php'; if ($fp = @fopen($filename, 'w+')) { @flock($fp, LOCK_EX); @fwrite ($fp, $data); @flock($fp, LOCK_UN); @fclose($fp); @umask(0); @chmod($filename, 0644); } return; } } ?> --- NEW FILE: user.php --- <?php /* * phpMP - The PHP Modular Portal System * Copyright (C) 2002-2003 Brian Rose and the phpMP group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: user.php,v 1.1 2003/09/14 06:37:52 heimidal Exp $ * */ class User { var $_data; /** * @return boolean * @param userkey mixed(string,array) * @param userval string optional * @desc Set a variable in userdata. */ function set($userkey, $userval = false) { if(is_array( $userkey )) { foreach( $userkey as $key => $val ) { if(preg_match('/^[a-z][a-z0-9_-]+/', $key)) { $this->_data[$key] = $val; } } } elseif( (!empty($userkey)) && (preg_match('/^[a-z][a-z0-9_-]+/', $userkey)) && (!empty($userval)) ) { $this->_data[$userkey] = $userval; return true; } else { return false; } } /** * @return string * @param userkey string * @desc Fetches us... [truncated message content] |