From 0e90d4aa66bb75d0acc69baf00c005afbdc2909a Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 17 Dec 2020 13:13:29 -0800 Subject: [PATCH] Code optimization and cleaning --- .../shortcodes/batch/usersettings_shortcodes.php | 8 ++++---- e107_core/shortcodes/single/nextprev.php | 2 +- e107_handlers/comment_class.php | 2 +- e107_handlers/db_table_admin_class.php | 4 ++-- e107_handlers/e_db_pdo_class.php | 2 +- e107_handlers/e_parse_class.php | 2 +- e107_handlers/js_helper.php | 2 +- e107_handlers/mysql_class.php | 2 +- e107_handlers/theme_handler.php | 5 +++-- e107_plugins/alt_auth/alt_auth_login_class.php | 6 +++--- e107_plugins/download/includes/admin.php | 14 +++++++------- e107_plugins/faqs/faqs.php | 2 +- .../forum/shortcodes/batch/view_shortcodes.php | 4 ++-- e107_plugins/pm/pm_func.php | 2 +- e107_plugins/pm/pm_setup.php | 4 ++-- e107_plugins/tinymce4/admin_config.php | 6 +++--- 16 files changed, 34 insertions(+), 33 deletions(-) diff --git a/e107_core/shortcodes/batch/usersettings_shortcodes.php b/e107_core/shortcodes/batch/usersettings_shortcodes.php index 25d6d7095..44b60359d 100755 --- a/e107_core/shortcodes/batch/usersettings_shortcodes.php +++ b/e107_core/shortcodes/batch/usersettings_shortcodes.php @@ -381,7 +381,7 @@ class usersettings_shortcodes extends e_shortcode foreach($catList as $cat) { - cachevars("extendedcat_{$cat['user_extended_struct_id']}", $cat); + e107::setRegistry("extendedcat_{$cat['user_extended_struct_id']}", $cat); $text = $this->sc_userextended_cat($cat['user_extended_struct_id']); $ret .= $text; $catName = vartrue($cat['user_extended_struct_text'], $cat['user_extended_struct_name']); @@ -425,7 +425,7 @@ class usersettings_shortcodes extends e_shortcode return ""; } $ret = ""; - $catInfo = getcachedvars("extendedcat_{$parm}"); + $catInfo = e107::getRegistry("extendedcat_{$parm}"); if(!$catInfo) { $qry = " @@ -456,7 +456,7 @@ class usersettings_shortcodes extends e_shortcode $fieldList = $sql->db_getList(); foreach($fieldList as $field) { - cachevars("extendedfield_{$field['user_extended_struct_name']}", $field); + e107::setRegistry("extendedfield_{$field['user_extended_struct_name']}", $field); //TODO use $this instead of parseTemplate(); $ret .= $this->sc_userextended_field($field['user_extended_struct_name']); // $ret .= $tp->parseTemplate("{USEREXTENDED_FIELD={$field['user_extended_struct_name']}}", TRUE, $usersettings_shortcodes); @@ -509,7 +509,7 @@ class usersettings_shortcodes extends e_shortcode $ret = ""; - $fInfo = getcachedvars("extendeddata_{$parm}"); + $fInfo = e107::getRegistry("extendeddata_{$parm}"); if(!$fInfo) { diff --git a/e107_core/shortcodes/single/nextprev.php b/e107_core/shortcodes/single/nextprev.php index 613ba773a..6209b33db 100644 --- a/e107_core/shortcodes/single/nextprev.php +++ b/e107_core/shortcodes/single/nextprev.php @@ -584,7 +584,7 @@ function nextprev_shortcode($parm = '') - if($cached_parms = getcachedvars('nextprev')) + if($cached_parms = e107::getRegistry('nextprev')) { $tmp = $cached_parms; foreach($tmp as $key => $val) diff --git a/e107_handlers/comment_class.php b/e107_handlers/comment_class.php index 7e728de7a..b8cbe9b19 100644 --- a/e107_handlers/comment_class.php +++ b/e107_handlers/comment_class.php @@ -1423,7 +1423,7 @@ class comment return null; } - $data = getcachedvars('e_comment'); + $data = e107::getRegistry('e_comment'); if ($data !== FALSE) { return $data; diff --git a/e107_handlers/db_table_admin_class.php b/e107_handlers/db_table_admin_class.php index e18014abd..4c73f53a9 100644 --- a/e107_handlers/db_table_admin_class.php +++ b/e107_handlers/db_table_admin_class.php @@ -53,7 +53,7 @@ class db_table_admin } $row = $sql->db_Fetch('num'); $tmp = str_replace("`", "", stripslashes($row[1])).';'; // Add semicolon to work with our parser - $count = preg_match_all("#CREATE\s+?TABLE\s+?`{0,1}({$prefix}{$table_name})`{0,1}\s+?\((.*?)\)\s+?(?:TYPE|ENGINE)\s*\=\s*(.*?);#is", $tmp, $matches, PREG_SET_ORDER); + $count = preg_match_all("#CREATE\s+?TABLE\s+?`?({$prefix}{$table_name})`?\s+?\((.*?)\)\s+?(?:TYPE|ENGINE)\s*\=\s*(.*?);#is", $tmp, $matches, PREG_SET_ORDER); if ($count === FALSE) { return "Error occurred"; @@ -112,7 +112,7 @@ class db_table_admin $table_name = '\w+?'; } // Regex should be identical to that in get_current_table (apart from the source text variable name) - $count = preg_match_all("#CREATE\s+?TABLE\s+?`{0,1}({$table_name})`{0,1}\s+?\((.*?)\)\s+?(?:TYPE|ENGINE)\s*\=\s*(.*?);#is", $this->file_buffer, $matches, PREG_SET_ORDER); + $count = preg_match_all("#CREATE\s+?TABLE\s+?`?({$table_name})`?\s+?\((.*?)\)\s+?(?:TYPE|ENGINE)\s*\=\s*(.*?);#is", $this->file_buffer, $matches, PREG_SET_ORDER); if ($count === false) { return "Error occurred"; diff --git a/e107_handlers/e_db_pdo_class.php b/e107_handlers/e_db_pdo_class.php index 1dc6e545f..7d5b0ceeb 100644 --- a/e107_handlers/e_db_pdo_class.php +++ b/e107_handlers/e_db_pdo_class.php @@ -2383,7 +2383,7 @@ class e_db_pdo implements e_db $row = $this->fetch('num'); $qry = $row[1]; // $qry = str_replace($old, $new, $qry); - $qry = preg_replace("#CREATE\sTABLE\s`{0,1}".$old."`{0,1}\s#", "CREATE TABLE {$new} ", $qry, 1); // More selective search + $qry = preg_replace("#CREATE\sTABLE\s`?".$old."`?\s#", "CREATE TABLE {$new} ", $qry, 1); // More selective search } else { diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 7955432a0..6fe02f449 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -1061,7 +1061,7 @@ class e_parse extends e_parser if ($utf8) { // Pull out a piece of the maximum permissible length - if (preg_match('#^((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$width.'})(.{0,1}).*#s',$sp,$matches) == 0) + if (preg_match('#^((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$width.'})(.?).*#s',$sp,$matches) == 0) { // Make any problems obvious for now $value .= '[!invalid utf-8: '.$sp.'!]'; diff --git a/e107_handlers/js_helper.php b/e107_handlers/js_helper.php index fd5cc6827..f0b404ece 100644 --- a/e107_handlers/js_helper.php +++ b/e107_handlers/js_helper.php @@ -346,7 +346,7 @@ class e_jshelper * @param string $errextended * @access public */ - public function sendAjaxError($errcode, $errmessage, $errextended = '') + public static function sendAjaxError($errcode, $errmessage, $errextended = '') { header('Content-type: text/html; charset='.CHARSET); header("HTTP/1.0 {$errcode} {$errmessage}"); diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php index 876099885..e912ca72d 100644 --- a/e107_handlers/mysql_class.php +++ b/e107_handlers/mysql_class.php @@ -2159,7 +2159,7 @@ class e_db_mysql implements e_db */ public function resetTableList() { - return $this->db_ResetTableList(); + $this->db_ResetTableList(); } /** diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php index 5d0f47fea..ac7b12bc4 100644 --- a/e107_handlers/theme_handler.php +++ b/e107_handlers/theme_handler.php @@ -1180,11 +1180,12 @@ class themeHandler if(isset($_POST['submit_adminstyle'])) { $this->id = $this->curTheme; - if($this->setAdminStyle()) + $this->setAdminStyle(); // this redirects. + /*if($this->setAdminStyle()) { eMessage::getInstance()->add(TPVLAN_43, E_MESSAGE_SUCCESS); } - e107::getConfig()->save(true); + e107::getConfig()->save(true);*/ } if(isset($_POST['submit_style'])) diff --git a/e107_plugins/alt_auth/alt_auth_login_class.php b/e107_plugins/alt_auth/alt_auth_login_class.php index 1299876d9..1c554e3eb 100755 --- a/e107_plugins/alt_auth/alt_auth_login_class.php +++ b/e107_plugins/alt_auth/alt_auth_login_class.php @@ -166,7 +166,7 @@ class alt_login $newUser['data'] = $db_vals; validatorClass::addFieldTypes($userMethods->userVettingInfo,$newUser); $newUser['WHERE'] = '`user_id`='.$row['user_id']; - $aa_sql->db_Update('user',$newUser); + $aa_sql->update('user',$newUser); if (AA_DEBUG1) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User data update: ".print_r($newUser,TRUE),FALSE,LOG_TO_ROLLING); } foreach ($xFields as $k => $v) @@ -184,14 +184,14 @@ class alt_login $ue->addFieldTypes($xArray); // Add in the data types for storage $xArray['WHERE'] = '`user_extended_id`='.intval($row['user_id']); if (AA_DEBUG) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User xtnd update: ".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING); - $aa_sql->db_Update('user_extended',$xArray ); + $aa_sql->update('user_extended',$xArray ); } else { // Never been an extended user fields record for this user $xArray['data']['user_extended_id'] = $row['user_id']; $ue->addDefaultFields($xArray); // Add in the data types for storage, plus any default values if (AA_DEBUG) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","Write new extended record".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING); - $aa_sql->db_Insert('user_extended',$xArray); + $aa_sql->insert('user_extended',$xArray); } } } diff --git a/e107_plugins/download/includes/admin.php b/e107_plugins/download/includes/admin.php index 55c4227d0..5a25a3592 100644 --- a/e107_plugins/download/includes/admin.php +++ b/e107_plugins/download/includes/admin.php @@ -545,7 +545,7 @@ $columnInfo = array( $foundSome = false; foreach($files as $file) { - if (0 == $sql->db_Count('download', '(*)', " WHERE download_url='".$file['fname']."'")) { + if (0 == $sql->count('download', '(*)', " WHERE download_url='".$file['fname']."'")) { if (!$foundSome) { // $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform"); $text .= '
@@ -816,7 +816,7 @@ $columnInfo = array( $files = $efile->get_files(e_DOWNLOAD); $foundSome = false; foreach($files as $file) { - if (0 == $sql->db_Count('download', '(*)', " WHERE download_url='".$file['fname']."'")) { + if (0 == $sql->count('download', '(*)', " WHERE download_url='".$file['fname']."'")) { if (!$foundSome) { // $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform"); $text .= ' @@ -1877,7 +1877,7 @@ $columnInfo = array( $updateArray = array_merge($dlInfo,$dlMirrors); $updateArray['WHERE'] = 'download_id='.intval($id); - $mes->addAuto($sql->db_Update('download',$updateArray), 'update', DOWLAN_2." (".$_POST['download_name'].")"); + $mes->addAuto($sql->update('download',$updateArray), 'update', DOWLAN_2." (".$_POST['download_name'].")"); $dlInfo['download_id'] = $id; $this->downloadLog('DOWNL_06',$dlInfo,$dlMirrors); @@ -1909,7 +1909,7 @@ $columnInfo = array( if ($_POST['remove_upload']) { - $sql->db_Update("upload", "upload_active='1' WHERE upload_id='".$_POST['remove_id']."'"); + $sql->update("upload", "upload_active='1' WHERE upload_id='".$_POST['remove_id']."'"); $mess = "
".$_POST['download_name']." ".DOWLAN_104; $mess .= "

".DOWLAN_105.""; $this->show_message($mess); @@ -1956,7 +1956,7 @@ $columnInfo = array( if ($delete == "mirror") { - $mes->addAuto($sql -> db_Delete("download_mirror", "mirror_id=".$del_id), delete, DOWLAN_135); + $mes->addAuto($sql ->delete("download_mirror", "mirror_id=".$del_id), delete, DOWLAN_135); e107::getLog()->add('DOWNL_14','ID: '.$del_id,E_LOG_INFORMATIVE,''); } @@ -2107,12 +2107,12 @@ $columnInfo = array( if (isset($_POST['id'])) { - $mes->addAuto($sql -> db_Update("download_mirror", "mirror_name='{$name}', mirror_url='{$url}', mirror_image='".$tp->toDB($_POST['mirror_image'])."', mirror_location='{$location}', mirror_description='{$description}' WHERE mirror_id=".intval($_POST['id'])), 'update', DOWLAN_133); + $mes->addAuto($sql ->update("download_mirror", "mirror_name='{$name}', mirror_url='{$url}', mirror_image='".$tp->toDB($_POST['mirror_image'])."', mirror_location='{$location}', mirror_description='{$description}' WHERE mirror_id=".intval($_POST['id'])), 'update', DOWLAN_133); e107::getLog()->add('DOWNL_13','ID: '.intval($_POST['id']).'[!br!]'.$logString,E_LOG_INFORMATIVE,''); } else { - $mes->addAuto($sql -> db_Insert("download_mirror", "0, '{$name}', '{$url}', '".$tp->toDB($_POST['mirror_image'])."', '{$location}', '{$description}', 0"), 'insert', DOWLAN_134); + $mes->addAuto($sql ->insert("download_mirror", "0, '{$name}', '{$url}', '".$tp->toDB($_POST['mirror_image'])."', '{$location}', '{$description}', 0"), 'insert', DOWLAN_134); e107::getLog()->add('DOWNL_12',$logString,E_LOG_INFORMATIVE,''); } } diff --git a/e107_plugins/faqs/faqs.php b/e107_plugins/faqs/faqs.php index 75c460b00..7cddac573 100644 --- a/e107_plugins/faqs/faqs.php +++ b/e107_plugins/faqs/faqs.php @@ -82,7 +82,7 @@ if (isset($_POST['faq_submit'])) { $faq_question = $tp->toDB($_POST['faq_question']); $data = $tp->toDB($_POST['data']); - $count = ($sql->db_Count("faqs", "(*)", "WHERE faq_parent='".intval($_POST['faq_parent'])."' ") + 1); + $count = ($sql->count("faqs", "(*)", "WHERE faq_parent='".intval($_POST['faq_parent'])."' ") + 1); $sql->insert("faqs", " 0, '".$_POST['faq_parent']."', '$faq_question', '$data', '".filter_var($_POST['faq_comment'], FILTER_SANITIZE_STRING)."', '".time()."', '".USERID."', '".$count."' "); diff --git a/e107_plugins/forum/shortcodes/batch/view_shortcodes.php b/e107_plugins/forum/shortcodes/batch/view_shortcodes.php index 5a1f89bfc..814cffe3a 100644 --- a/e107_plugins/forum/shortcodes/batch/view_shortcodes.php +++ b/e107_plugins/forum/shortcodes/batch/view_shortcodes.php @@ -550,11 +550,11 @@ if($forum->prefs->get('sig_once')) { $_tmp = 'forum_sig_shown_' . $this->postInfo['post_user']; - if(getcachedvars($_tmp)) + if(e107::getRegistry($_tmp)) { return ''; } - cachevars($_tmp, 1); + e107::setRegistry($_tmp, 1); } if($parm == 'clean') diff --git a/e107_plugins/pm/pm_func.php b/e107_plugins/pm/pm_func.php index 84514b2d6..3749bb8cd 100755 --- a/e107_plugins/pm/pm_func.php +++ b/e107_plugins/pm/pm_func.php @@ -68,7 +68,7 @@ class pmbox_manager $pm_info[$which] = $this->pmDB->fetch(); if ($which == 'inbox' && ($this->pmPrefs['animate'] == 1 || $this->pmPrefs['popup'] == 1)) { - if($new = $this->pmDB->db_Count('private_msg', '(*)', "WHERE pm_sent > '".USERLV."' AND pm_read = 0 AND pm_to = '".USERID."' AND pm_read_del != 1")) + if($new = $this->pmDB->count('private_msg', '(*)', "WHERE pm_sent > '".USERLV."' AND pm_read = 0 AND pm_to = '".USERID."' AND pm_read_del != 1")) { $pm_info['inbox']['new'] = $new; } diff --git a/e107_plugins/pm/pm_setup.php b/e107_plugins/pm/pm_setup.php index 9919ed8b3..451ae2552 100644 --- a/e107_plugins/pm/pm_setup.php +++ b/e107_plugins/pm/pm_setup.php @@ -31,8 +31,8 @@ class pm_setup function uninstall_post() { $sql = e107::getDb(); - $sql->db_Delete('core', "e107_name = 'pm_prefs'"); - $sql->db_Delete('menus', "menu_name = 'private_msg_menu'"); + $sql->delete('core', "e107_name = 'pm_prefs'"); + $sql->delete('menus', "menu_name = 'private_msg_menu'"); } } diff --git a/e107_plugins/tinymce4/admin_config.php b/e107_plugins/tinymce4/admin_config.php index 146719de5..595c095e4 100644 --- a/e107_plugins/tinymce4/admin_config.php +++ b/e107_plugins/tinymce4/admin_config.php @@ -490,7 +490,7 @@ class tinymce if($id) { $insert_array['WHERE'] = $this->primary." = ".$id; - $status = $sql->db_Update($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; + $status = $sql->update($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; $message = LAN_UPDATED; @@ -499,7 +499,7 @@ class tinymce } else { - $status = $sql->db_Insert($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; + $status = $sql->insert($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; $message = LAN_CREATED; } @@ -518,7 +518,7 @@ class tinymce $sql = e107::getDb(); $query = $this->primary." = ".$id; - $status = $sql->db_Delete($this->table,$query) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; + $status = $sql->delete($this->table,$query) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; $message = LAN_DELETED; $emessage->add($message, $status); }