From 3d28c5a88b5874b20d35b85635329aa30b2750ce Mon Sep 17 00:00:00 2001 From: e107steved Date: Fri, 20 Nov 2009 22:23:02 +0000 Subject: [PATCH] Support backticks in db checking, comments in db definition files, other minor tweaks --- e107_admin/db_verify.php | 46 +++++++++++-------- e107_admin/update_routines.php | 19 ++++---- e107_handlers/db_table_admin_class.php | 40 +++++++++------- e107_handlers/mail.php | 16 +------ e107_handlers/shortcode_handler.php | 29 ++++++++++-- .../English/admin/lan_log_messages.php | 4 +- e107_languages/English/admin/lan_mailout.php | 10 ++-- 7 files changed, 95 insertions(+), 69 deletions(-) diff --git a/e107_admin/db_verify.php b/e107_admin/db_verify.php index 3b7e1645e..8ee166a0c 100644 --- a/e107_admin/db_verify.php +++ b/e107_admin/db_verify.php @@ -9,9 +9,9 @@ * Administration - DB Verify * * $Source: /cvs_backup/e107_0.8/e107_admin/db_verify.php,v $ - * $Revision: 1.9 $ - * $Date: 2009-11-18 01:04:25 $ - * $Author: e107coders $ + * $Revision: 1.10 $ + * $Date: 2009-11-20 22:23:02 $ + * $Author: e107steved $ * */ require_once("../class2.php"); @@ -40,7 +40,7 @@ if (!$sql_data) exit(DBLAN_1); } -$tables["core"] = $sql_data; +$tables['core'] = preg_replace("#\/\*.*?\*\/#mis", '', $sql_data); // Strip any comments as we copy if (!getperms("0")) { @@ -51,11 +51,13 @@ if (!getperms("0")) //Get any plugin _sql.php files foreach($pref['e_sql_list'] as $path => $file) { - $filename = e_PLUGIN.$path."/".$file.".php"; + $filename = e_PLUGIN.$path.'/'.$file.'.php'; if(is_readable($filename)) { - $id = str_replace("_sql","",$file); - $tables[$id] = file_get_contents($filename); + $id = str_replace('_sql','',$file); + $temp = file_get_contents($filename); + $tables[$id] = preg_replace("#\/\*.*?\*\/#mis", '', $temp); // Strip comments as we copy + unset($temp); } else { @@ -183,29 +185,36 @@ function check_tables($what) if ($current_tab) { - $lines = split("\n", $current_tab); // Create one element of $lines per field or other line of info + $lines = split("\n", $current_tab); // Actual table - create one element of $lines per field or other line of info $fieldnum = 0; foreach($tablines[$k] as $x) { // $x is a line of the DB definition from the *_sql.php file $x = str_replace(' ',' ',$x); // Remove double spaces $fieldnum++; - $ffound = 0; - list($fname, $fparams) = explode(" ", $x, 2); - if ($fname == "UNIQUE" || $fname == 'FULLTEXT') + $ffound = 0; + list($fname, $fparams) = explode(' ', $x, 2); // Pull out first word of definition + if ($fname == 'UNIQUE' || $fname == 'FULLTEXT') { - list($key, $key1, $keyname, $keyparms) = split(" ", $x, 4); + list($key, $key1, $keyname, $keyparms) = split(' ', $x, 4); $fname = $key." ".$key1." ".$keyname; $fparams = $keyparms; } - elseif ($fname == "KEY") + elseif ($fname == 'KEY') { - list($key, $keyname, $keyparms) = split(" ", $x, 3); + list($key, $keyname, $keyparms) = split(' ', $x, 3); $fname = $key." ".$keyname; $fparams = $keyparms; } + elseif ($fname == 'PRIMARY') + { // Nothing to do ATM + } + else + { // Must be a field name + $fname = str_replace('`','',$fname); // Just remove back ticks if present + } $fields[$fname] = 1; $fparams = ltrim(rtrim($fparams)); - $fparams = preg_replace("/\r?\n$|\r[^\n]$|,$/", "", $fparams); + $fparams = preg_replace("/\r?\n$|\r[^\n]$|,$/", '', $fparams); if(stristr($k, "lan_") !== FALSE && $cur != 1) @@ -219,13 +228,12 @@ function check_tables($what) {$fname} "; - if (strpos($fparams, "KEY") !== FALSE) + if (strpos($fparams, 'KEY') !== FALSE) { - $head_txt .= " $fparams aa"; + $head_txt .= " {$fparams} aa"; } - $head_txt .= " - + $head_txt .= " "; $xfieldnum = -1; diff --git a/e107_admin/update_routines.php b/e107_admin/update_routines.php index c13b01003..e509aa1a7 100644 --- a/e107_admin/update_routines.php +++ b/e107_admin/update_routines.php @@ -11,9 +11,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/update_routines.php,v $ -| $Revision: 1.63 $ -| $Date: 2009-11-20 05:01:30 $ -| $Author: e107coders $ +| $Revision: 1.64 $ +| $Date: 2009-11-20 22:23:02 $ +| $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -321,7 +321,7 @@ function update_706_to_800($type='') $db_parser = new db_table_admin; // Class to read table defs and process them $do_save = FALSE; // Set TRUE to update prefs when update complete - $updateMessages = array(); + $updateMessages = array(); // Used to log actions for the admin log $just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing whether an update is needed @@ -707,7 +707,7 @@ function update_706_to_800($type='') $mes = e107::getMessage(); foreach ($ttc as $ct) { - $sqlDefs = e_PLUGIN.$plugName.'/'.$plugName.'_sql.php'; // Filename containing definitions + $sqlDefs = e_PLUGIN.$plugName.'/'.str_replace('_menu','',$plugName).'_sql.php'; // Filename containing definitions // echo "Looking at file: {$sqlDefs}, table {$ct}
"; $req_defs = $db_parser->get_table_def($ct,$sqlDefs); if (!is_array($req_defs)) @@ -764,10 +764,10 @@ function update_706_to_800($type='') } // This has to be done after the table is upgraded - if($sql->db_Select("plugin", "plugin_category", "plugin_category = ''")) + if($sql->db_Select('plugin', 'plugin_category', "plugin_category = ''")) { - if ($just_check) return update_needed(); - require_once(e_HANDLER."plugin_class.php"); + if ($just_check) return update_needed('Update plugin table'); + require_once(e_HANDLER.'plugin_class.php'); $ep = new e107plugin; $ep -> update_plugins_table(); // $_pdateMessages[] = LAN_UPDATE_XX24; @@ -828,7 +828,8 @@ function update_706_to_800($type='') if ($do_save) { save_prefs(); - $updateMessages[] = LAN_UPDATE_50.implode(', ',$accum); // FIXME + $mes->add(LAN_UPDATE_50); + $updateMessages[] = LAN_UPDATE_50.implode(', ',$accum); // Note for admin log } //FIXME grab message-stack from $mes for the log. diff --git a/e107_handlers/db_table_admin_class.php b/e107_handlers/db_table_admin_class.php index eac1430c6..506da4dfb 100644 --- a/e107_handlers/db_table_admin_class.php +++ b/e107_handlers/db_table_admin_class.php @@ -9,9 +9,9 @@ * Database utilities * * $Source: /cvs_backup/e107_0.8/e107_handlers/db_table_admin_class.php,v $ - * $Revision: 1.12 $ - * $Date: 2009-11-18 01:04:43 $ - * $Author: e107coders $ + * $Revision: 1.13 $ + * $Date: 2009-11-20 22:23:02 $ + * $Author: e107steved $ */ /* @@ -61,19 +61,23 @@ class db_table_admin return $matches; } - // Routine to do first-level parse of table structure - //--------------------------------------------------- - // Given the name of a file, returns an array, with each element being a table creation definition. - // Tracks the last file read - only reads it once - // If the file name is an empty string, uses a previously read/set buffer - // If a table name is given, returns only that table's info; otherwise returns a list of all tables - // The table name must include a prefix where appropriate (although not required with standard E107 table definition files) - // Each element is itself an array: - // [0] - The complete string which creates a table (unless a prefix needs adding to the table name), including terminating ';' - // [1] - The table name. Any backticks are stripped - // [2] - Field definitions, with the surrounding (...) stripped - // [3] - The 'TYPE' field ('TYPE=' is stripped) and any AUTO-INCREMENT definition or other text. - // function get_table_def($table_name='',$file_name = e_ADMIN."sql/core_sql.php") + /** + * Routine to do first-level parse of table structure + *--------------------------------------------------- + * Given the name of a file, returns an array, with each element being a table creation definition. + * Tracks the last file read - only reads it once + * If the file name is an empty string, uses a previously read/set buffer + * + * @param string $table_name - If specified, returns only that table's info; otherwise returns a list of all tables + * The table name must include a prefix where appropriate (although not required with standard E107 table definition files) + * @return string|array + * - if error, returns a brief text message + * - if successful, returns an array of table definitions, each of which is itself an array: + * [0] - The complete string which creates a table (unless a prefix needs adding to the table name), including terminating ';' + * [1] - The table name. Any backticks are stripped + * [2] - Field definitions, with the surrounding (...) stripped + * [3] - The 'TYPE' field ('TYPE=' is stripped) and any AUTO-INCREMENT definition or other text. + */ function get_table_def($table_name = '', $file_name = "") { if ($file_name != '') @@ -86,7 +90,9 @@ class db_table_admin } $temp = file_get_contents($file_name); // Strip any php header - $this->file_buffer = preg_replace("#\<\?php.*?\?\>#mis", '', $temp); + $temp = preg_replace("#\<\?php.*?\?\>#mis", '', $temp); + // Strip any comments (only /*...*/ supported + $this->file_buffer = preg_replace("#\/\*.*?\*\/#mis", '', $temp); $this->last_file = $file_name; } } diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index 4335282f6..c63986ac2 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -9,31 +9,19 @@ * e107 Main * * $Source: /cvs_backup/e107_0.8/e107_handlers/mail.php,v $ - * $Revision: 1.19 $ - * $Date: 2009-11-19 20:24:21 $ + * $Revision: 1.20 $ + * $Date: 2009-11-20 22:23:02 $ * $Author: e107steved $ */ /* -This is a work in progress, upgrading the mailout routines to use the PHP5-compatible PHPMailer classes in a class-based structure - -A further class extension will add features for mass-mailouts - - -Three main scenarios to handle: - - Individual email to a number of recipients (analagous to 'manual' email sending). May be called multiple times in a run - - One email send individually to a number of recipients (probably based on array of senders) - - Personalised mailshots - template email modified to personalise for each recipient (based on DB list) - TODO: -2. Bulk mailing - look at using the batching constants with SMTPKeepAlive to reset the connection every so often 3. mail (PHP method) - note that it has parameters for additional headers and other parameters 4. Check that language support works - PHPMailer defaults to English if other files not available - PHPMailer expects a 2-letter code - $this->SetLanguage(CORE_LC) - e.g. 'en', 'br' 5. Logging: - Use rolling log for errors - error string(s) available - sort out entry - Look at support of some other logging options - - Debug option to just log, not send emails (variables in place, and supported by current bulk mailer) 9. Make sure SMTPDebug can be set (TRUE/FALSE) 12. Check support for port number - ATM we just override for SSL. Looks as if phpmailer can take it from end of server link. 13. Possibly strip bbcode from plain text mailings - best done by caller? diff --git a/e107_handlers/shortcode_handler.php b/e107_handlers/shortcode_handler.php index 36963d027..a975e9bc3 100644 --- a/e107_handlers/shortcode_handler.php +++ b/e107_handlers/shortcode_handler.php @@ -9,9 +9,9 @@ * e107 Shortcode handler * * $Source: /cvs_backup/e107_0.8/e107_handlers/shortcode_handler.php,v $ - * $Revision: 1.36 $ - * $Date: 2009-11-18 01:04:43 $ - * $Author: e107coders $ + * $Revision: 1.37 $ + * $Date: 2009-11-20 22:23:02 $ + * $Author: e107steved $ */ if (!defined('e107_INIT')) { exit; } @@ -101,6 +101,29 @@ function setScVar($className, $scVarName, $value) } } + +/** + * Call function on an already registered SC object + * + * @param string $className + * @param string $scFuncName + * @param mixed $param - passed to function + * + * @return mixed|boolean - FALSE if class doesn't exist; otherwise whatever the function returns. + */ +function callScFunc($className, $scFuncName, $param= '') +{ + $sc = e107::getScParser(); + if(isset($sc->scClasses[$className])) + { + return call_user_func(array($sc->scClasses[$className],$scFuncName), $param); + } + else + { + return FALSE; + } +} + /** * Create shortcode object * diff --git a/e107_languages/English/admin/lan_log_messages.php b/e107_languages/English/admin/lan_log_messages.php index 49242958b..c6e71b1dc 100644 --- a/e107_languages/English/admin/lan_log_messages.php +++ b/e107_languages/English/admin/lan_log_messages.php @@ -1,6 +1,6 @@