Update of /cvsroot/mxbb/phpbb2mxp/develop In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv12742/develop Added Files: README.html bbcode_conversion.php benchmark.php convert_avatars.php convert_bbcodeuid.php convert_conf.php convert_privmsgs.php convert_sigs.php convert_user_regdates.php convert_usernames.php dbinformer.php encoding_emails.php fix_files.sh fixfiles.sh insert_server_info.php most_users_update.php nuke-db.php revar_lang_files.php search_fill.php template_db_cache.php template_file_cache.php Log Message: upgrade to 2.0.24-beta1 --- NEW FILE: fix_files.sh --- #!/bin/bash # # Remove all those annoying ^M characters that Winblows editor's like to add # from all files in the current directory and all subdirectories. # # Written by: Jonathan Haase. # # UPDATE: 7/31/2001: fix so that it doesn't touch things in the images directory # find . > FILELIST.$$ grep -sv FILELIST FILELIST.$$ > FILELIST2.$$ grep -sv $(basename $0) FILELIST2.$$ > FILELIST.$$ grep -sv "^\.$" FILELIST.$$ > FILELIST2.$$ grep -sv "images" FILELIST2.$$ > FILELIST rm FILELIST2.$$ rm FILELIST.$$ for i in $(cat FILELIST); do if [ -f $i ]; then sed -e s/ //g $i > $i.tmp mv $i.tmp $i fi done rm FILELIST --- NEW FILE: dbinformer.php --- <?php /*************************************************************************** * dbinformer.php * ------------------- * begin : Saturday, May 05, 2002 * copyright : (C) 2002 The phpBB Group * email : n/a * * $Id: dbinformer.php,v 1.1 2008/12/31 01:43:48 orynider Exp $ * * Coded by AL, Techie-Micheal, Blade, and Black Fluffy Lion. * http://www.phpbb.com/phpBB/groupcp.php?g=7330 * ***************************************************************************/ /*************************************************************************** * * 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. * ***************************************************************************/ /* magic quotes, borrowed from install.php */ set_magic_quotes_runtime(0); if (!get_magic_quotes_gpc()) { if (is_array($HTTP_POST_VARS)) { while (list($k, $v) = each($HTTP_POST_VARS)) { if (is_array($HTTP_POST_VARS[$k])) { while (list($k2, $v2) = each($HTTP_POST_VARS[$k])) { $HTTP_POST_VARS[$k][$k2] = addslashes($v2); } @reset($HTTP_POST_VARS[$k]); } else { $HTTP_POST_VARS[$k] = addslashes($v); } } @reset($HTTP_POST_VARS); } } $all_connected = false; $error = false; $error_msg = ''; $select = false; $connect = false; function make_config($dbms, $dbhost, $dbname, $dbuser, $dbpasswd, $table_prefix) { $config_file = '<?php<br />' . "\n"; $config_file .= '<br />' . "\n"; $config_file .= '//<br />' . "\n"; $config_file .= '// phpBB 2.x auto-generated config file<br />' . "\n"; $config_file .= '// Do not change anything in this file!<br />' . "\n"; $config_file .= '//<br />' . "\n"; $config_file .= '<br />' . "\n"; $config_file .= '$dbms = \'' . $dbms . '\';<br /><br />' . "\n\n"; $config_file .= '$dbhost = \'' . $dbhost . '\';<br />' . "\n"; $config_file .= '$dbname = \'' . $dbname . '\';<br />' . "\n"; $config_file .= '$dbuser = \'' . $dbuser . '\';<br />' . "\n"; $config_file .= '$dbpasswd = \'' . $dbpasswd . '\';<br /><br />' . "\n\n"; $config_file .= '$table_prefix = \'' . $table_prefix . '\';<br /><br />' . "\n\n"; $config_file .= 'define(\'PHPBB_INSTALLED\', true);<br /><br />' . "\n\n"; $config_file .= '?>'; return $config_file; } function make_download($dbms, $dbhost, $dbname, $dbuser, $dbpasswd, $table_prefix) { $config_file = '<?php' . "\n\n"; $config_file .= '//' . "\n"; $config_file .= '// phpBB 2.x auto-generated config file' . "\n"; $config_file .= '// Do not change anything in this file!' . "\n"; $config_file .= '//' . "\n\n"; $config_file .= '$dbms = \'' . $dbms . '\';' . "\n\n"; $config_file .= '$dbhost = \'' . $dbhost . '\';' . "\n"; $config_file .= '$dbname = \'' . $dbname . '\';' . "\n"; $config_file .= '$dbuser = \'' . $dbuser . '\';' . "\n"; $config_file .= '$dbpasswd = \'' . $dbpasswd . '\';' . "\n\n"; $config_file .= '$table_prefix = \'' . $table_prefix . '\';' . "\n\n"; $config_file .= 'define(\'PHPBB_INSTALLED\', true);' . "\n\n"; $config_file .= '?>'; return $config_file; } /* make all the vars safe to display in form inputs and on the user's screen. Borrowed from usercp_register.php */ $check_var_list = array('dbms' => 'dbms', 'dbhost' => 'dbhost', 'dbname' => 'dbname', 'dbuser' => 'dbuser', 'dbpasswd' => 'dbpasswd', 'table_prefix' => 'table_prefix'); while (list($var, $param) = each($check_var_list)) { if (!empty($HTTP_POST_VARS[$param])) { $$var = stripslashes(htmlspecialchars(strip_tags($HTTP_POST_VARS[$param]))); } } $available_dbms = array( 'mysql' => 'MySQL 3.x', 'mysql4' => 'MySQL 4.x', 'postgres' => 'PostgreSQL 7.x', 'mssql' => 'MS SQL Server 7/2000', 'msaccess' => 'MS Access [ ODBC ]', 'mssql-odbc' => 'MS SQL Server [ OBDC ]', ); if (isset($HTTP_POST_VARS['download_config']) && $HTTP_POST_VARS['download_config'] == true && isset($HTTP_POST_VARS['submit_download_config']) && $HTTP_POST_VARS['submit_download_config'] == 'Download') { /* borrowed from install.php */ header('Content-Type: text/x-delimtext; name="config.php"'); header('Content-disposition: attachment; filename=config.php'); echo make_download($dbms, $dbhost, $dbname, $dbuser, $dbpasswd, $table_prefix); return; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>phpBB :: dbinformer.php</title> <link rel="stylesheet" href="../templates/subSilver/subSilver.css" type="text/css" /> <style type="text/css"> <!-- p,ul,td {font-size:10pt;} h3 {font-size:12pt;color:blue} //--> </style> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="10" align="center"> <tr> <td class="bodyline"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="../templates/subSilver/images/logo_phpBB.gif" border="0" alt="phpBB2 : Creating Communities" vspace="1" /></a></td> <td align="center" width="100%" valign="middle"><span class="maintitle">dbinformer.php</span> </td> </tr> </table> <br /><b><div align="center"> <a href="#what">What you entered</a> | <a href="#connect">Connection to database</a> | <a href="#tables">Tables in database</a> | <a href="#config">Config file</a> </b></div> <table width="100%" border="0" cellspacing="0" cellpadding="10" align="center"> <tr> <td align="center" width="100%" valign="middle"><span class="maintitle"></span></td> </tr> <tr> <td width="100%"> <table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline"> <tr> <th colspan="2">Database Configuration</th> </tr> <tr> <td class="row1" align="right"><span class="gen">Database type: </span></td> <td class="row2"> <form action="<?php echo htmlspecialchars($HTTP_SERVER_VARS['PHP_SELF']); ?>" method="post"> <select name="dbms"> <?php /* loop through the dbms, with the correct one selected (hopefully!) */ while (list($var, $param) = each($available_dbms)) { $selected = ($dbms == $var) ? ' selected="selected"' : ''; echo '<option value="' . $var . '"' . $selected . '>' . $param . '</option>'; } ?> </select></td> </tr> <tr> <td class="row1" align="right"><span class="gen">Database Server Hostname / DSN: </span></td> <td class="row2"><input type="text" name="dbhost" value="<?php echo @$dbhost; ?>" /></td> </tr> <tr> <td class="row1" align="right"><span class="gen">Your Database Name: </span></td> <td class="row2"><input type="text" name="dbname" value="<?php echo @$dbname; ?>" /></td> </tr> <tr> <td class="row1" align="right"><span class="gen">Database Username: </span></td> <td class="row2"><input type="text" name="dbuser" value="<?php echo @$dbuser; ?>" /></td> </tr> <tr> <td class="row1" align="right"><span class="gen">Database Password: </span></td> <td class="row2"><input type="password" name="dbpasswd" value="<?php echo @$dbpasswd; ?>" /></td> </tr> <tr> <td class="row1" align="right"><span class="gen">Chosen Prefix: </span></td> <td class="row2"><input type="text" name="table_prefix" value="<?php echo @$table_prefix; ?>" /></td> </tr> <tr> <td class="row1" align="right"><span class="gen">Generate a config file: </span></td> </td> <td class="row2"><input type="checkbox" name="generate_config" value="true" <?php $checked = (isset($HTTP_POST_VARS['generate_config']) && $HTTP_POST_VARS['generate_config'] == true) ? 'checked="checked"' : ''; echo $checked; ?> /></td> </tr> <tr> <td class="catbottom" align="center" colspan="2"> <input class="mainoption" type="submit" name="submit" value="Submit" /></td> </tr> </form></td> </tr> </table> <?php if (!isset($HTTP_POST_VARS['submit'])) { echo '<br />Please enter your data.<br />'; } else { /* dbal added by Techie-Micheal [and then obliterated by BFL]. weeeeeee! */ switch ($dbms) { case 'mysql': if (function_exists(@mysql_connect)) { $db = array( 'choice' => 'MySQL 3.x', 'connect' => @mysql_connect($dbhost, $dbuser, $dbpasswd), 'select' => @mysql_select_db($dbname), 'error' => @mysql_error(), 'list' => @mysql_list_tables($dbname), 'fetch' => @mysql_fetch_row, 'close' => @mysql_close() ); } else { $error = true; $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; } break; case 'mysql4': if (function_exists(@mysql_connect)) { $db = array( 'choice' => 'MySQL 4.x', 'connect' => @mysql_connect($dbhost, $dbuser, $dbpasswd), 'select' => @mysql_select_db($dbname), 'error' => @mysql_error(), 'list' => @mysql_list_tables($dbname), 'fetch' => @mysql_fetch_row, 'close' => @mysql_close() ); } else { $error = true; $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; } break; case 'msaccess': if (function_exists(@odbc_connect)) { $db = array( 'choice' => 'MS Access [ ODBC ]', 'connect' => @odbc_connect($dbhost, $dbuser, $dbpasswd), 'select' => 'na', 'error' => @odbc_errormsg(), 'list' => 'na', /* odbc_tables() */ 'fetch' => 'na', /* odbc_fetch_row(), odbc_result_all() */ 'close' => @odbc_close() ); } else { $error = true; $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; } break; case 'postgres': if (function_exists(@pg_connect)) { $db = array( 'choice' => 'PostgreSQL 7.x', 'connect' => @pg_connect('host=' . $dbhost . ' user=' . $dbuser . ' dbname=' . $dbname . ' password=' . $dbpasswd), 'select' => 'na', 'error' => @pg_last_error(), 'list' => @pg_exec("SELECT relname FROM pg_class WHERE relkind = 'r' AND relname NOT LIKE 'pg\_%'"), /* provided by SuGa */ 'fetch' => @pg_fetch_row, 'close' => @pg_close() ); } else { $error = true; $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; } break; case 'mssql': if (function_exists(@mssql_connect)) { $db = array( 'choice' => 'MS SQL Server 7/2000', 'connect' => @mssql_connect($dbhost, $dbuser, $dbpasswd), 'select' => @mssql_select_db($dbname), 'error' => @mssql_get_last_message(), 'list' => 'na', 'fetch' => 'na', /* mssql_fetch_row() */ 'close' => @mssql_close() ); } else { $error = true; $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; } break; case 'mssql-odbc': if (function_exists(@odbc_connect)) { $db = array( 'choice' => 'MS SQL Server [ ODBC ]', 'connect' => @odbc_connect($dbhost, $dbuser, $dbpasswd), 'select' => 'na', 'error' => @odbc_errormsg(), 'list' => 'na', /* odbc_tables() */ 'fetch' => 'na', /* odbc_fetch_row(), odbc_result_all() */ 'close' => @odbc_close() ); } else { $error = true; $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; } break; default: $error = true; $error_msg = 'Unrecognised DBMS.'; break; } if ($error == true && $error_msg != '') { echo '<br /><b>ERROR:</b> ' . $error_msg . '<br />'; } else { echo '<a name="what"><h3><u>What you entered</u></h3></a>'; echo 'Database Type: <b>' . $db['choice'] . '</b><br />'; echo 'Database Server Hostname / DSN: <b>' . $dbhost . '</b><br />'; echo 'Your Database Name: <b>' . $dbname . '</b><br />'; echo 'Database Username: <b>' . $dbuser . '</b><br />'; echo 'Database Password: <b>' . $dbpasswd . '</b><br />'; echo '<a name="connect"><h3><u>Connection to database</u></h3></a>'; if (!$db['connect']) { echo 'You have not established a connection to <b>' . $db['choice'] . '</b>.<br />'; echo '<b>ERROR:</b> <i>' . $db['error'] . '</i><br /><br />'; } else { echo 'You have established a connection to <b>' . $db['choice'] . '</b>.<br /><br />'; $connect = true; } if ($dbms == 'msaccess' || $dbms == 'postgres' || $dbms == 'mssql-odbc') { /* for dbmses which have no db select function */ $select = true; } else { if (!$db['select']) { echo 'Your database was not found.<br />'; echo '<b>ERROR:</b> <i>' . htmlspecialchars($db['error']) . '</i><br />'; } else { echo 'Your database was found.<br />'; $select = true; } } if ($connect == true && $select == true) { echo '<a name="tables"><h3><u>Tables in database</u></h3></a>'; if ($dbms == 'mysql' || $dbms == 'mysql4' || $dbms == 'postgres') { echo '<i>Tables with the table prefix you specified are in bold.</i>'; echo '<ul>'; while ($table = $db['fetch']($db['list'])) { /* Highlight tables with the table_prefix specified */ if (preg_match("/^$HTTP_POST_VARS[table_prefix]/i", $table[0])) { echo '<li><b>' . htmlspecialchars($table[0]) . '</b></li><br />'; } else { echo '<li>' . htmlspecialchars($table[0]) . '</li><br />'; } } echo '</ul>'; } else { echo 'Sorry, this feature isn\'t available with ' . $db['choice'] . '.'; } /* defined a var which is only there if successfully connected to the database and the database is found */ $all_connected = true; } /* Create a config file if checked and if the connection went OK */ if (isset($HTTP_POST_VARS['generate_config']) && $HTTP_POST_VARS['generate_config'] == true) { echo '<a name="config"><h3><u>Config file</u></h3></a>'; if ($all_connected != true) { echo 'The database has not been successfully connected to so no config file has been generated.<br />'; } else { echo 'Either copy the <b>19</b> lines below and save them as <u>config.php</u> or click on the <u>Download</u> button below. Then upload the file to your phpBB2 root directory (phpBB2/ by default). Make sure that there is nothing (this includes blank spaces) after the <u>?></u>.<br /><br />'; /* Create our config file */ echo '<form action="' . htmlspecialchars($HTTP_SERVER_VARS['PHP_SELF']) . '" method="post"><table cellspacing="1" cellpadding="3" border="0"><tr><td class="code">'; echo make_config($dbms, $dbhost, $dbname, $dbuser, $dbpasswd, $table_prefix); echo '</td></tr></table>'; echo '<input type="hidden" name="dbms" value="' . $dbms . '" />'; echo '<input type="hidden" name="dbhost" value="' . $dbhost . '" />'; echo '<input type="hidden" name="dbname" value="' . $dbname . '" />'; echo '<input type="hidden" name="dbuser" value="' . $dbuser . '" />'; echo '<input type="hidden" name="dbpasswd" value="' . $dbpasswd . '" />'; echo '<input type="hidden" name="table_prefix" value="' . $table_prefix . '" />'; echo '<input type="hidden" name="download_config" value="true" />'; echo '<br /><input type="submit" name="submit_download_config" value="Download" class="mainoption" /><br />'; } } /* close the connection */ if ($all_connected == true) { $db['close']; } } } /* And they all lived happily ever after... The End */ ?> <br /><a href="javascript:scrollTo('0','0');"><b>Return to top</b></a> </td> </tr> </table> <div align="center"><span class="copyright">© Copyright 2002 The <a href="http://www.phpbb.com/about.php" target="_phpbb" class="copyright">phpBB Group</a></span></div> </td> </tr> </table> </body> </html> --- NEW FILE: convert_avatars.php --- <?php // // Security message: // // This script is potentially dangerous. // Remove or comment the next line (die(".... ) to enable this script. // Do NOT FORGET to either remove this script or disable it after you have used it. // die("Please read the first lines of this script for instructions on how to enable it"); // // Do not change anything below this line. // $phpbb_root_path = "../"; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'config.'.$phpEx); include($phpbb_root_path . 'includes/constants.'.$phpEx); include($phpbb_root_path . 'includes/db.'.$phpEx); $sql = "ALTER TABLE " . USERS_TABLE . " ADD user_avatar_type TINYINT(4) DEFAULT '0' NOT NULL"; if( !$result = $db->sql_query($sql) ) { die("Couldn't alter users table"); } $sql = "SELECT user_id, user_avatar FROM " . USERS_TABLE; if( $result = $db->sql_query($sql) ) { $rowset = $db->sql_fetchrowset($result); for($i = 0; $i < count($rowset); $i++) { if( ereg("^http", $rowset[$i]['user_avatar'])) { $sql_type = USER_AVATAR_REMOTE; } else if( $rowset[$i]['user_avatar'] != "" ) { $sql_type = USER_AVATAR_UPLOAD; } else { $sql_type = USER_AVATAR_NONE; } $sql = "UPDATE " . USERS_TABLE . " SET user_avatar_type = $sql_type WHERE user_id = " . $rowset[$i]['user_id']; if( !$result = $db->sql_query($sql) ) { die("Couldn't update users table- " . $i); } } } echo "<BR><BR>COMPLETE<BR>"; ?> --- NEW FILE: template_db_cache.php --- <?php /*************************************************************************** * template.inc * ------------------- * begin : Saturday, Feb 13, 2001 * copyright : (C) 2001 The phpBB Group * email : su...@ph... * * $Id: template_db_cache.php,v 1.1 2008/12/31 01:43:48 orynider Exp $ * * ***************************************************************************/ /*************************************************************************** * * 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. * ***************************************************************************/ /** * Template class. By Nathan Codding of the phpBB group. * The interface was originally inspired by PHPLib templates, * and the template file formats are quite similar. * */ class Template { var $classname = "Template"; // variable that holds all the data we'll be substituting into // the compiled templates. // ... // This will end up being a multi-dimensional array like this: // $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(); // Hash of filenames for each template handle. var $files = array(); // Root template directory. var $root = ""; // this will hash handle names to the compiled code for that handle. var $compiled_code = array(); // This will hold the uncompiled code for that handle. var $uncompiled_code = array(); /** * Constructor. Simply sets the root dir. * */ function Template($root = '.') { global $db; $this->set_rootdir($root); $this->db = &$db; $this->pparse_order = array(); } /** * Destroys this template object. Should be called when you're done with it, in order * to clear out the template data so you can load/parse a new template set. */ function destroy() { $this->_tpldata = array(); } /** * Sets the template root directory for this Template object. */ function set_rootdir($dir) { if (!is_dir($dir)) { return false; } $this->root = $dir; return true; } /** * Sets the template filenames for handles. $filename_array * should be a hash of handle => filename pairs. */ function set_filenames($filename_array) { global $table_prefix; if ( !is_array($filename_array) ) { return false; } $template_names = ''; @reset($filename_array); while ( list($handle, $filename) = @each($filename_array) ) { $this->files[$handle] = $this->make_filename($filename); $template_names .= ( $template_names != '' ) ? ", '" . addslashes($this->files[$handle]) . "'" : "'" . addslashes($this->files[$handle]) . "'"; } $sql = "SELECT * FROM " . $table_prefix . "template_cache WHERE template_name IN ($template_names)"; if ( $result = $this->db->sql_query($sql) ) { while( $row = $this->db->sql_fetchrow($result) ) { if( $row['template_cached'] == filemtime($row['template_name']) ) { $this->compiled_code[$row['template_handle']] = $row['template_compile']; $this->echo_compiled[$row['template_handle']] = $row['template_echo']; } } } $this->db->sql_freeresult(); return true; } /** * Load the file for the handle, compile the file, * and run the compiled code. This will print out * the results of executing the template. */ function pparse($handle) { global $table_prefix; if( empty($this->compiled_code[$handle]) ) { if ( !$this->loadfile($handle) ) { die("Template->pparse(): Couldn't load template file for handle $handle"); } // // Actually compile the code now. // $this->echo_compiled[$handle] = 1; $this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]); $sql = "REPLACE INTO " . $table_prefix . "template_cache (template_name, template_handle, template_cached, template_compile) VALUES ('" . addslashes($this->files[$handle]) . "', '" . addslashes($handle) . "', " . filemtime($this->files[$handle]) . ", '" . addslashes($this->compiled_code[$handle]) . "')"; if ( !($result = $this->db->sql_query($sql)) ) { die("Couldn't insert template into cache!"); } } $_str = ""; eval($this->compiled_code[$handle]); if( $_str != "" ) { echo $_str; } return true; } /** * Inserts the uncompiled code for $handle as the * value of $varname in the root-level. This can be used * to effectively include a template in the middle of another * template. * Note that all desired assignments to the variables in $handle should be done * BEFORE calling this function. */ function assign_var_from_handle($varname, $handle) { global $table_prefix; if( empty($this->compiled_code[$handle]) ) { if ( !$this->loadfile($handle) ) { die("Template->pparse(): Couldn't load template file for handle $handle"); } $code = $this->compile($this->uncompiled_code[$handle], true, '_str'); $sql = "REPLACE INTO " . $table_prefix . "template_cache (template_name, template_handle, template_echo, template_cached, template_compile) VALUES ('" . addslashes($this->files[$handle]) . "', '" . addslashes($handle) . "', 0, " . filemtime($this->files[$handle]) . ", '" . addslashes($code) . "')"; if ( !($result = $this->db->sql_query($sql)) ) { die("Couldn't insert template into cache!"); } } else { $code = $this->compiled_code[$handle]; } // Compile It, With The "no Echo Statements" Option On. $_str = ""; // evaluate the variable assignment. eval($code); // assign the value of the generated variable to the given varname. $this->assign_var($varname, $_str); return true; } /** * Block-level variable assignment. Adds a new block iteration with the given * variable assignments. Note that this should only be called once per block * iteration. */ 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 .= '[\'' . $blocks[$i] . '.\']'; eval('$lastiteration = sizeof(' . $str . ') - 1;'); $str .= '[' . $lastiteration . ']'; } // 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;'; // Now we evaluate this assignment we've built up. eval($str); } else { // Top-level block. // Add a new iteration to this block with the variable assignments // we were given. $this->_tpldata[$blockname . '.'][] = $vararray; } return true; } /** * Root-level variable assignment. Adds to current assignments, overriding * any existing variable assignment with the same name. */ function assign_vars($vararray) { reset ($vararray); while (list($key, $val) = each($vararray)) { $this->_tpldata['.'][0][$key] = $val; } return true; } /** * Root-level variable assignment. Adds to current assignments, overriding * any existing variable assignment with the same name. */ function assign_var($varname, $varval) { $this->_tpldata['.'][0][$varname] = $varval; 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. if (substr($filename, 0, 1) != '/') { $filename = $this->root . '/' . $filename; } if (!file_exists($filename)) { die("Template->make_filename(): Error - file $filename does not exist"); } return $filename; } /** * If not already done, load the file for the given handle and populate * the uncompiled_code[] hash with its code. Do not compile. */ function loadfile($handle) { // 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])) { die("Template->loadfile(): No file specified for handle $handle"); } $filename = $this->files[$handle]; $str = implode("", @file($filename)); if (empty($str)) { die("Template->loadfile(): File $filename for handle $handle is empty"); } $this->uncompiled_code[$handle] = $str; return true; } /** * Compiles the given string of code, and returns * the result in a string. * If "do_not_echo" is true, the returned code will not be directly * executable, but can be used as part of a variable assignment * for use in assign_code_from_handle(). */ function compile($code, $do_not_echo = false, $retvar = '') { // replace \ with \\ and then ' with \'. $code = str_replace('\\', '\\\\', $code); $code = str_replace('\'', '\\\'', $code); // change template varrefs into PHP varrefs // This one will handle varrefs WITH namespaces $varrefs = array(); preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs); $varcount = sizeof($varrefs[1]); for ($i = 0; $i < $varcount; $i++) { $namespace = $varrefs[1][$i]; $varname = $varrefs[3][$i]; $new = $this->generate_block_varref($namespace, $varname); $code = str_replace($varrefs[0][$i], $new, $code); } // This will handle the remaining root-level varrefs $code = preg_replace('#\{([a-z0-9\-_]*?)\}#is', '\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \'', $code); // Break it up into lines. $code_lines = explode("\n", $code); $block_nesting_level = 0; $block_names = array(); $block_names[0] = "."; // Second: prepend echo ', append ' . "\n"; to each line. $line_count = sizeof($code_lines); for ($i = 0; $i < $line_count; $i++) { $code_lines[$i] = chop($code_lines[$i]); if (preg_match('#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m)) { $n[0] = $m[0]; $n[1] = $m[1]; // Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think. :) if ( preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $n) ) { $block_nesting_level++; $block_names[$block_nesting_level] = $m[1]; if ($block_nesting_level < 2) { // Block is not nested. $code_lines[$i] = '$_' . $a[1] . '_count = ( isset($this->_tpldata[\'' . $n[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $n[1] . '.\']) : 0;'; $code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)'; $code_lines[$i] .= "\n" . '{'; } else { // This block is nested. // Generate a namespace string for this block. $namespace = implode('.', $block_names); // strip leading period from root level.. $namespace = substr($namespace, 2); // 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. $code_lines[$i] = '$_' . $a[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;'; $code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)'; $code_lines[$i] .= "\n" . '{'; } // We have the end of a block. unset($block_names[$block_nesting_level]); $block_nesting_level--; $code_lines[$i] .= '} // END ' . $n[1]; $m[0] = $n[0]; $m[1] = $n[1]; } else { // We have the start of a block. $block_nesting_level++; $block_names[$block_nesting_level] = $m[1]; if ($block_nesting_level < 2) { // Block is not nested. $code_lines[$i] = '$_' . $m[1] . '_count = ( isset($this->_tpldata[\'' . $m[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $m[1] . '.\']) : 0;'; $code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)'; $code_lines[$i] .= "\n" . '{'; } else { // This block is nested. // Generate a namespace string for this block. $namespace = implode('.', $block_names); // strip leading period from root level.. $namespace = substr($namespace, 2); // 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. $code_lines[$i] = '$_' . $m[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;'; $code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)'; $code_lines[$i] .= "\n" . '{'; } } } else if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $m)) { // We have the end of a block. unset($block_names[$block_nesting_level]); $block_nesting_level--; $code_lines[$i] = '} // END ' . $m[1]; } else { // We have an ordinary line of code. if (!$do_not_echo) { $code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";'; } else { $code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";'; } } } // Bring it back into a single string of lines of code. $code = implode("\n", $code_lines); return $code ; } /** * 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 = '\' . ( ( isset(' . $varref . ') ) ? ' . $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] . '.\'][$_' . $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 .= '[$_' . $blocks[$blockcount] . '_i]'; } return $varref; } } ?> --- NEW FILE: convert_usernames.php --- <html> <body> <?php // // Security message: // // This script is potentially dangerous. // Remove or comment the next line (die(".... ) to enable this script. // Do NOT FORGET to either remove this script or disable it after you have used it. // die("Please read the first lines of this script for instructions on how to enable it"); // // Do not change anything below this line. // // // Convert 2.0.x Usernames to the new 2.0.5 Username format. // chdir("../"); define('IN_PHPBB', true); include('extension.inc'); include('config.'.$phpEx); include('includes/constants.'.$phpEx); include('includes/db.'.$phpEx); $sql = "SELECT user_id, username FROM " . USERS_TABLE; $result = $db->sql_query($sql); if(!$result) { die("Unable to get users"); } while ($row = $db->sql_fetchrow($result)) { if (!preg_match('#(>)|(<)|(")|(&)#', $row['username'])) { if ($row['username'] != htmlspecialchars($row['username'])) { flush(); $sql = "UPDATE " . USERS_TABLE . " SET username = '" . str_replace("'", "''", htmlspecialchars($row['username'])) . "' WHERE user_id = " . $row['user_id']; if (!$db->sql_query($sql)) { echo "ERROR: Unable to rename user " . htmlspecialchars($row['username']) . " with ID " . $row['user_id'] . "<br>"; echo "<pre>" . print_r($db->sql_error()) . "</pre><br />$sql"; } else { echo "Renamed User " . htmlspecialchars($row['username']) . " with ID " . $row['user_id'] . "<br>"; } } } } echo "<br>That's All Folks!"; ?> </body> </html> --- NEW FILE: search_fill.php --- <?php // // Security message: // // This script is potentially dangerous. // Remove or comment the next line (die(".... ) to enable this script. // Do NOT FORGET to either remove this script or disable it after you have used it. // // // Do not change anything below this line. // set_time_limit(0); $phpbb_root_path = "../"; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); include($phpbb_root_path . 'includes/search.'.$phpEx); $common_percent = 0.4; // Percentage of posts in which a word has to appear to be marked as common print "<html>\n<body>\n"; // // Try and load stopword and synonym files // // This needs fixing! Shouldn't be hardcoded to English files! $stopword_array = file($phpbb_root_path . "language/lang_english/search_stopwords.txt"); $synonym_array = file($phpbb_root_path . "language/lang_english/search_synonyms.txt"); // // Fetch a batch of posts_text entries // $sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id FROM ". POSTS_TEXT_TABLE; if ( !($result = $db->sql_query($sql)) ) { $error = $db->sql_error(); die("Couldn't get maximum post ID :: " . $sql . " :: " . $error['message']); } $max_post_id = $db->sql_fetchrow($result); $totalposts = $max_post_id['total']; $max_post_id = $max_post_id['max_post_id']; $postcounter = (!isset($HTTP_GET_VARS['batchstart'])) ? 0 : $HTTP_GET_VARS['batchstart']; $batchsize = 200; // Process this many posts per loop $batchcount = 0; for(;$postcounter <= $max_post_id; $postcounter += $batchsize) { $batchstart = $postcounter + 1; $batchend = $postcounter + $batchsize; $batchcount++; $sql = "SELECT * FROM " . POSTS_TEXT_TABLE . " WHERE post_id BETWEEN $batchstart AND $batchend"; if( !($result = $db->sql_query($sql)) ) { $error = $db->sql_error(); die("Couldn't get post_text :: " . $sql . " :: " . $error['message']); } $rowset = $db->sql_fetchrowset($result); $db->sql_freeresult($result); $post_rows = count($rowset); if( $post_rows ) { // $sql = "LOCK TABLES ".POST_TEXT_TABLE." WRITE"; // $result = $db->sql_query($sql); print "\n<p>\n<a href='$PHP_SELF?batchstart=$batchstart'>Restart from posting $batchstart</a><br>\n"; // For every post in the batch: for($post_nr = 0; $post_nr < $post_rows; $post_nr++ ) { print "."; flush(); $post_id = $rowset[$post_nr]['post_id']; $matches = array(); $matches['text'] = split_words(clean_words("post", $rowset[$post_nr]['post_text'], $stopword_array, $synonym_array)); $matches['title'] = split_words(clean_words("post", $rowset[$post_nr]['post_subject'], $stopword_array, $synonym_array)); while( list($match_type, $match_ary) = @each($matches) ) { $title_match = ( $match_type == 'title' ) ? 1 : 0; $num_matches = count($match_ary); if ( $num_matches < 1 ) { // Skip this post if no words where found continue; } // For all words in the posting $sql_in = ""; $sql_insert = ''; $sql_select = ''; $word = array(); $word_count = array(); for($j = 0; $j < $num_matches; $j++) { $this_word = strtolower(trim($match_ary[$j])); if ( $this_word != '' ) { $word_count[$this_word] = ( isset($word_count[$this_word]) ) ? $word_count[$this_word] + 1 : 0; $comma = ($sql_insert != '')? ', ': ''; $sql_insert .= "$comma('" . $this_word . "')"; $sql_select .= "$comma'" . $this_word . "'"; } } if ( $sql_insert == '' ) { die("no words found"); } $sql = 'INSERT IGNORE INTO ' . SEARCH_WORD_TABLE . " (word_text) VALUES $sql_insert"; if ( !$result = $db->sql_query($sql) ) { $error = $db->sql_error(); die("Couldn't INSERT words :: " . $sql . " :: " . $error['message']); } // Get the word_id's out of the DB (to see if they are already there) $sql = "SELECT word_id, word_text FROM " . SEARCH_WORD_TABLE . " WHERE word_text IN ($sql_select) GROUP BY word_text"; $result = $db->sql_query($sql); if ( !$result ) { $error = $db->sql_error(); die("Couldn't select words :: " . $sql . " :: " . $error['message']); } $sql_insert = array(); while( $row = $db->sql_fetchrow($result) ) { $sql_insert[] = "($post_id, " . $row['word_id'] . ", $title_match)"; } $db->sql_freeresult($result); $sql = "INSERT INTO " . SEARCH_MATCH_TABLE . " (post_id, word_id, title_match) VALUES " . implode(", ", $sql_insert); $result = $db->sql_query($sql); if ( !$result ) { $error = $db->sql_error(); die("Couldn't insert new word match :: " . $sql . " :: " . $error['message']); } } // All posts } // $sql = "UNLOCK TABLES"; // $result = $db->sql_query($sql); } // Remove common words after the first 2 batches and after every 4th batch after that. if( $batchcount % 4 == 3 ) { print "<br>Removing common words (words that appear in more than $common_percent of the posts)<br>\n"; flush(); print "Removed ". remove_common("global", $common_percent) ." words that where too common.<br>"; } } echo "<br>Done"; ?> </body> </html> --- NEW FILE: convert_privmsgs.php --- <?php // // Security message: // // This script is potentially dangerous. // Remove or comment the next line (die(".... ) to enable this script. // Do NOT FORGET to either remove this script or disable it after you have used it. // die("Please read the first lines of this script for instructions on how to enable it"); // // Do not change anything below this line. // $phpbb_root_path = "../"; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'config.'.$phpEx); include($phpbb_root_path . 'includes/constants.'.$phpEx); include($phpbb_root_path . 'includes/db.'.$phpEx); // // Alter table ... // echo "Alter tables ... "; echo $sql = "ALTER TABLE " . PRIVMSGS_TABLE . " ADD privmsgs_enable_bbcode TINYINT(1) DEFAULT '1' NOT NULL, ADD privmsgs_enable_html TINYINT(1) DEFAULT '0' NOT NULL, ADD privmsgs_enable_smilies TINYINT(1) DEFAULT '1' NOT NULL, ADD privmsgs_attach_sig TINYINT(1) DEFAULT '1' NOT NULL"; if( !$result = $db->sql_query($sql) ) { die("Couldn't alter privmsgs table"); } echo $sql = "ALTER TABLE " . PRIVMSGS_TEXT_TABLE . " ADD privmsgs_bbcode_uid CHAR(10) AFTER privmsgs_text_id"; if( !$result = $db->sql_query($sql) ) { die("Couldn't alter privmsgs text table"); } echo "COMPLETE<BR>"; // // Move bbcode ... // echo "Move bbcode uid's ... "; $sql = "SELECT privmsgs_id, privmsgs_bbcode_uid FROM " . PRIVMSGS_TABLE; if( $result = $db->sql_query($sql) ) { $rowset = $db->sql_fetchrowset($result); for($i = 0; $i < count($rowset); $i++) { $sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . " SET privmsgs_bbcode_uid = '" . $rowset[$i]['privmsgs_bbcode_uid'] . "' WHERE privmsgs_text_id = " . $rowset[$i]['privmsgs_id']; if( !$result = $db->sql_query($sql) ) { die("Couldn't update privmsgs text bbcode - " . $i); } } $sql = "ALTER TABLE " . PRIVMSGS_TABLE . " DROP privmsgs_bbcode_uid"; if( !$result = $db->sql_query($sql) ) { die("Couldn't alter privmsgs table - drop privmsgs_bbcode_uid"); } } echo "COMPLETE<BR>"; // // Stripslashes from titles // echo "Strip subject slashes ... "; $sql = "SELECT privmsgs_subject , privmsgs_id, privmsgs_to_userid, privmsgs_from_userid FROM " . PRIVMSGS_TABLE; if( $result = $db->sql_query($sql) ) { $rowset = $db->sql_fetchrowset($result); for($i = 0; $i < count($rowset); $i++) { $sql = "UPDATE " . PRIVMSGS_TABLE . " SET privmsgs_subject = '" . addslashes(stripslashes($rowset[$i]['privmsgs_subject'])) . "' WHERE privmsgs_id = " . $rowset[$i]['privmsgs_id']; if( !$result = $db->sql_query($sql) ) { die("Couldn't update subjects - $i"); } } } echo "COMPLETE<BR>"; // // Update sigs // echo "Remove [addsig], stripslashes and update privmsgs table sig enable ..."; $sql = "SELECT privmsgs_text_id , privmsgs_text FROM " . PRIVMSGS_TEXT_TABLE; if( $result = $db->sql_query($sql) ) { $rowset = $db->sql_fetchrowset($result); $attach_sql = ""; $non_attach_sql = ""; for($i = 0; $i < count($rowset); $i++) { if( ereg("\[addsig]$", $rowset[$i]['privmsgs_text'])) { if( $attach_sql != "" ) { $attach_sql .= ", "; } $attach_sql .= $rowset[$i]['privmsgs_text_id']; $sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . " SET privmsgs_text = '" . addslashes(preg_replace("/\[addsig\]/is", "", stripslashes($rowset[$i]['privmsgs_text']))) . "' WHERE privmsgs_text_id = " . $rowset[$i]['privmsgs_text_id']; if( !$result = $db->sql_query($sql) ) { die("Couldn't update privmsgs text - " . $i); } } else { $sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . " SET privmsgs_text = '" . addslashes(stripslashes($rowset[$i]['privmsgs_text'])) . "' WHERE privmsgs_text_id = " . $rowset[$i]['privmsgs_text_id']; if( !$result = $db->sql_query($sql) ) { die("Couldn't update privmsgs text - " . $i); } if( $non_attach_sql != "" ) { $non_attach_sql .= ", "; } $non_attach_sql .= $rowset[$i]['privmsgs_text_id']; } } if( $attach_sql != "" ) { $sql = "UPDATE " . PRIVMSGS_TABLE . " SET privmsgs_attach_sig = 1 WHERE privmsgs_id IN ($attach_sql)"; if( !$result = $db->sql_query($sql) ) { die("Couldn't update privmsgs table attach_sig - "); } } if( $non_attach_sql != "" ) { $sql = "UPDATE " . PRIVMSGS_TABLE . " SET privmsgs_attach_sig = 0 WHERE privmsgs_id IN ($non_attach_sql)"; if( !$result = $db->sql_query($sql) ) { die("Couldn't update privmsgs table non_attach_sig - "); } } } echo "COMPLETE<BR>"; $db->sql_close(); ?> --- NEW FILE: convert_sigs.php --- <?php // // Security message: // // This script is potentially dangerous. // Remove or comment the next line (die(".... ) to enable this script. // Do NOT FORGET to either remove this script or disable it after you have used it. // die("Please read the first lines of this script for instructions on how to enable it"); // // Do not change anything below this line. // $phpbb_root_path = "../"; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'config.'.$phpEx); include($phpbb_root_path . 'includes/constants.'.$phpEx); include($phpbb_root_path . 'includes/db.'.$phpEx); $sql = "SELECT post_id, post_text FROM " . POSTS_TEXT_TABLE; if( $result = $db->sql_query($sql) ) { $rowset = $db->sql_fetchrowset($result); $attach_sql = ""; $non_attach_sql = ""; for($i = 0; $i < count($rowset); $i++) { if( ereg("\[addsig]$", $rowset[$i]['post_text'])) { if( $attach_sql != "" ) { $attach_sql .= ", "; } $attach_sql .= $rowset[$i]['post_id']; $sql = "UPDATE " . POSTS_TEXT_TABLE . " SET post_text = '" . addslashes(preg_replace("/\[addsig\]/is", "", $rowset[$i]['post_text'])) . "' WHERE post_id = " . $rowset[$i]['post_id']; if( !$result = $db->sql_query($sql) ) { die("Couldn't update post_text - " . $i); } } else { if( $non_attach_sql != "" ) { $non_attach_sql .= ", "; } $non_attach_sql .= $rowset[$i]['post_id']; } } echo "<BR>"; if( $attach_sql != "" ) { echo $sql = "UPDATE " . POSTS_TABLE . " SET enable_sig = 1 WHERE post_id IN ($attach_sql)"; if( !$result = $db->sql_query($sql) ) { die("Couldn't update post table attach_sig - "); } } echo "<BR>"; if( $non_attach_sql != "" ) { echo $sql = "UPDATE " . POSTS_TABLE . " SET enable_sig = 0 WHERE post_id IN ($non_attach_sql)"; if( !$result = $db->sql_query($sql) ) { die("Couldn't update post table non_attach_sig - "); } } } $db->sql_close(); echo "<BR><BR>COMPLETE<BR>"; ?> --- NEW FILE: template_file_cache.php --- <?php /*************************************************************************** * template.php * ------------------- * begin : Saturday, Feb 13, 2001 * copyright : (C) 2001 The phpBB Group * email : su...@ph... * * $Id: template_file_cache.php,v 1.1 2008/12/31 01:43:48 orynider Exp $ * ***************************************************************************/ /*************************************************************************** * * 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. * ***************************************************************************/ /** * Template class. By Nathan Codding of the phpBB group. * The interface was originally inspired by PHPLib templates, * and the template file formats are quite similar. * * Updated 9th June 2003 - psoTFX * Backported various aspects of 2.2 template class * */ class Template { var $classname = 'Template'; // variable that holds all the data we'll be substituting into // the compiled templates. var $_tpldata = array(); // Hash of filenames for each template handle. var $files = array(); // Root template directories var $cache_root = 'cache/'; var $root = ''; // this will hash handle names to the compiled code for that handle. var $compiled_code = array(); // This will hold the uncompiled code for that handle. var $uncompiled_code = array(); /** * Constructor. Simply sets the root dir. * */ function Template($root = '.') { global $board_config, $db; $this->set_rootdir($root); $this->db = $db; } /** * Destroys this template object. Should be called when you're done with it, in order * to clear out the template data so you can load/parse a new template set. */ function destroy() { $this->_tpldata = array(); } /** * Sets the template root directory for this Template object. */ function set_rootdir($dir) { global $phpbb_root_path; if (is_file($dir) || is_link($dir)) { return false; } $this->root = phpbb_realpath($dir); $this->cachedir = phpbb_realpath($phpbb_root_path . $this->cache_root) . substr($dir, strrpos($dir, '/')) . '/'; if (!file_exists($this->cachedir . 'admin/')) { @umask(0); if (!file_exists($this->cachedir)) { mkdir($this->cachedir, 0777); } mkdir($this->cachedir . 'admin/', 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 = ''; @reset($filename_array); while (list($handle, $filename) = @each($filename_array)) { $this->filename[$handle] = $filename; $this->files[$handle] = $this->make_filename($filename); } return true; } /** * Load the file for the handle, compile the file, * and run the compiled code. This will print out * the results of executing the template. */ function pparse($handle) { global $phpEx; $cache_file = $this->cachedir . $this->filename[$handle] . '.' . $phpEx; if(@filemtime($cache_file) == @filemtime($this->files[$handle])) { $_str = ''; include($cache_file); if ($_str != '') { echo $_str; } } else { if (!$this->loadfile($handle)) { die("Template->pparse(): Couldn't load template file for handle $handle"); } // Actually compile the code now. $this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]); $fp = fopen($cache_file, 'w+'); fwrite ($fp, '<?php' . "\n" . $this->compiled_code[$handle] . "\n?" . '>'); fclose($fp); touch($cache_file, filemtime($this->files[$handle])); @chmod($cache_file, 0777); eval($this->compiled_code[$handle]); } return true; } /** * Inserts the uncompiled code for $handle as the * value of $varname in the root-level. This can be used * to effectively include a template in the middle of another * template. * Note that all desired assignments to the variables in $handle should be done * BEFORE calling this function. */ function assign_var_from_handle($varname, $handle) { global $phpEx; $cache_file = $this->cachedir . $this->filename[$handle] . '.' . $phpEx; if(@filemtime($cache_file) == @filemtime($this->files[$handle])) { $_str = ''; include($cache_file); } else { if (!$this->loadfile($handle)) { die("Template->pparse(): Couldn't load template file for handle $handle"); } $code = $this->compile($this->uncompiled_code[$handle], true, '_str'); $fp = fopen($cache_file, 'w+'); fwrite ($fp, '<?php' . "\n" . $code . "\n?" . '>'); fclose($fp); touch($cache_file, filemtime($this->files[$handle])); @chmod($cache_file, 0777); // Compile It, With The "no Echo Statements" Option On. $_str = ''; // evaluate the variable assignment. eval($code); } // assign the value of the generated variable to the given varname. $this->assign_var($varname, $_str); return true; } /** * Block-level variable assignment. Adds a new block iteration with the given * variable assignments. Note that this should only be called once per block * iteration. */ 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; } /** * Root-level variable assignment. Adds to current assignments, overriding * any existing variable assignment with the same name. */ function assign_vars($vararray) { reset ($vararray); while (list($key, $val) = each($vararray)) { $this->_tpldata['.'][0][$key] = $val; } return true; } /** * Root-level variable assignment. Adds to current assignments, overriding * any existing variable assignment with the same name. */ function assign_var($varname, $varval) { $this->_tpldata['.'][0][$varname] = $varval; 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. if (substr($filename, 0, 1) != '/') { $filename = phpbb_realpath($this->root . '/' . $filename); } if (!file_exists($filename)) { die("Template->make_filename(): Error - file $filename does not exist"); } return $filename; } /** * If not already done, load the file for the given handle and populate * the uncompiled_code[] hash with its code. Do not compile. */ function loadfile($handle) { // 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])) { die("Template->loadfile(): No file specified for handle $handle"); } $filename = $this->files[$handle]; $str = implode('', @file($filename)); if (empty($str)) { die("Template->loadfile(): File $filename for handle $handle is empty"); } $this->uncompiled_code[$handle] = $str; return true; } /** * Compiles the given string of code, and returns * the result in a string. * If "do_not_echo" is true, the returned code will not be directly * executable, but can be used as part of a variable assignment * for use in assign_code_from_handle(). */ function compile($code, $do_not_echo = false, $retvar = '') { $concat = (!$do_not_echo) ? ',' : '.'; // replace \ with \\ and then ' with \'. $code = str_replace('\\', '\\\\', $code); $code = str_replace('\'', '\\\'', $code); // change template varrefs into PHP varrefs // This one will handle varrefs WITH namespaces $varrefs = array(); preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs); $varcount = sizeof($varrefs[1]); for ($i = 0; $i < $varcount; $i++) { $namespace = $varrefs[1][$i]; $varname = $varrefs[3][$i]; $new = $this->generate_block_varref($namespace, $varname, $concat); $code = str_replace($varrefs[0][$i], $new, $code); } // This will handle the remaining root-level varrefs $code = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "' $concat ((isset(\$this->_tpldata['.'][0]['\\1'])) ? \$this->_tpldata['.'][0]['\\1'] : '') $concat '", $code); // Break it up into lines. $code_lines = explode("\n", $code); $block_nesting_level = 0; $block_names = array(); $block_names[0] = '.'; // Second: prepend echo ', append ' . "\n"; to each line. $line_count = sizeof($code_lines); for ($i = 0; $i < $line_count; $i++) { $code_lines[$i] = chop($code_lines[$i]); ... [truncated message content] |