1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 12:48:26 +02:00

Code optimization and cleaning

This commit is contained in:
Cameron
2020-12-17 13:13:29 -08:00
parent 2cd0005b68
commit 0e90d4aa66
16 changed files with 34 additions and 33 deletions

View File

@@ -381,7 +381,7 @@ class usersettings_shortcodes extends e_shortcode
foreach($catList as $cat) 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']); $text = $this->sc_userextended_cat($cat['user_extended_struct_id']);
$ret .= $text; $ret .= $text;
$catName = vartrue($cat['user_extended_struct_text'], $cat['user_extended_struct_name']); $catName = vartrue($cat['user_extended_struct_text'], $cat['user_extended_struct_name']);
@@ -425,7 +425,7 @@ class usersettings_shortcodes extends e_shortcode
return ""; return "";
} }
$ret = ""; $ret = "";
$catInfo = getcachedvars("extendedcat_{$parm}"); $catInfo = e107::getRegistry("extendedcat_{$parm}");
if(!$catInfo) if(!$catInfo)
{ {
$qry = " $qry = "
@@ -456,7 +456,7 @@ class usersettings_shortcodes extends e_shortcode
$fieldList = $sql->db_getList(); $fieldList = $sql->db_getList();
foreach($fieldList as $field) 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(); //TODO use $this instead of parseTemplate();
$ret .= $this->sc_userextended_field($field['user_extended_struct_name']); $ret .= $this->sc_userextended_field($field['user_extended_struct_name']);
// $ret .= $tp->parseTemplate("{USEREXTENDED_FIELD={$field['user_extended_struct_name']}}", TRUE, $usersettings_shortcodes); // $ret .= $tp->parseTemplate("{USEREXTENDED_FIELD={$field['user_extended_struct_name']}}", TRUE, $usersettings_shortcodes);
@@ -509,7 +509,7 @@ class usersettings_shortcodes extends e_shortcode
$ret = ""; $ret = "";
$fInfo = getcachedvars("extendeddata_{$parm}"); $fInfo = e107::getRegistry("extendeddata_{$parm}");
if(!$fInfo) if(!$fInfo)
{ {

View File

@@ -584,7 +584,7 @@ function nextprev_shortcode($parm = '')
if($cached_parms = getcachedvars('nextprev')) if($cached_parms = e107::getRegistry('nextprev'))
{ {
$tmp = $cached_parms; $tmp = $cached_parms;
foreach($tmp as $key => $val) foreach($tmp as $key => $val)

View File

@@ -1423,7 +1423,7 @@ class comment
return null; return null;
} }
$data = getcachedvars('e_comment'); $data = e107::getRegistry('e_comment');
if ($data !== FALSE) if ($data !== FALSE)
{ {
return $data; return $data;

View File

@@ -53,7 +53,7 @@ class db_table_admin
} }
$row = $sql->db_Fetch('num'); $row = $sql->db_Fetch('num');
$tmp = str_replace("`", "", stripslashes($row[1])).';'; // Add semicolon to work with our parser $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) if ($count === FALSE)
{ {
return "Error occurred"; return "Error occurred";
@@ -112,7 +112,7 @@ class db_table_admin
$table_name = '\w+?'; $table_name = '\w+?';
} }
// Regex should be identical to that in get_current_table (apart from the source text variable name) // 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) if ($count === false)
{ {
return "Error occurred"; return "Error occurred";

View File

@@ -2383,7 +2383,7 @@ class e_db_pdo implements e_db
$row = $this->fetch('num'); $row = $this->fetch('num');
$qry = $row[1]; $qry = $row[1];
// $qry = str_replace($old, $new, $qry); // $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 else
{ {

View File

@@ -1061,7 +1061,7 @@ class e_parse extends e_parser
if ($utf8) if ($utf8)
{ {
// Pull out a piece of the maximum permissible length // 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 // Make any problems obvious for now
$value .= '[!<b>invalid utf-8: '.$sp.'<b>!]'; $value .= '[!<b>invalid utf-8: '.$sp.'<b>!]';

View File

@@ -346,7 +346,7 @@ class e_jshelper
* @param string $errextended * @param string $errextended
* @access public * @access public
*/ */
public function sendAjaxError($errcode, $errmessage, $errextended = '') public static function sendAjaxError($errcode, $errmessage, $errextended = '')
{ {
header('Content-type: text/html; charset='.CHARSET); header('Content-type: text/html; charset='.CHARSET);
header("HTTP/1.0 {$errcode} {$errmessage}"); header("HTTP/1.0 {$errcode} {$errmessage}");

View File

@@ -2159,7 +2159,7 @@ class e_db_mysql implements e_db
*/ */
public function resetTableList() public function resetTableList()
{ {
return $this->db_ResetTableList(); $this->db_ResetTableList();
} }
/** /**

View File

@@ -1180,11 +1180,12 @@ class themeHandler
if(isset($_POST['submit_adminstyle'])) if(isset($_POST['submit_adminstyle']))
{ {
$this->id = $this->curTheme; $this->id = $this->curTheme;
if($this->setAdminStyle()) $this->setAdminStyle(); // this redirects.
/*if($this->setAdminStyle())
{ {
eMessage::getInstance()->add(TPVLAN_43, E_MESSAGE_SUCCESS); eMessage::getInstance()->add(TPVLAN_43, E_MESSAGE_SUCCESS);
} }
e107::getConfig()->save(true); e107::getConfig()->save(true);*/
} }
if(isset($_POST['submit_style'])) if(isset($_POST['submit_style']))

View File

@@ -166,7 +166,7 @@ class alt_login
$newUser['data'] = $db_vals; $newUser['data'] = $db_vals;
validatorClass::addFieldTypes($userMethods->userVettingInfo,$newUser); validatorClass::addFieldTypes($userMethods->userVettingInfo,$newUser);
$newUser['WHERE'] = '`user_id`='.$row['user_id']; $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); 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) foreach ($xFields as $k => $v)
@@ -184,14 +184,14 @@ class alt_login
$ue->addFieldTypes($xArray); // Add in the data types for storage $ue->addFieldTypes($xArray); // Add in the data types for storage
$xArray['WHERE'] = '`user_extended_id`='.intval($row['user_id']); $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); 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 else
{ // Never been an extended user fields record for this user { // Never been an extended user fields record for this user
$xArray['data']['user_extended_id'] = $row['user_id']; $xArray['data']['user_extended_id'] = $row['user_id'];
$ue->addDefaultFields($xArray); // Add in the data types for storage, plus any default values $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); 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);
} }
} }
} }

View File

@@ -545,7 +545,7 @@ $columnInfo = array(
$foundSome = false; $foundSome = false;
foreach($files as $file) 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) { if (!$foundSome) {
// $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform"); // $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform");
$text .= '<form method="post" action="'.e_SELF.'?'.e_QUERY.'" id="myform"> $text .= '<form method="post" action="'.e_SELF.'?'.e_QUERY.'" id="myform">
@@ -816,7 +816,7 @@ $columnInfo = array(
$files = $efile->get_files(e_DOWNLOAD); $files = $efile->get_files(e_DOWNLOAD);
$foundSome = false; $foundSome = false;
foreach($files as $file) { 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) { if (!$foundSome) {
// $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform"); // $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform");
$text .= '<form method="post" action="'.e_SELF.'?'.e_QUERY.'" id="myform"> $text .= '<form method="post" action="'.e_SELF.'?'.e_QUERY.'" id="myform">
@@ -1877,7 +1877,7 @@ $columnInfo = array(
$updateArray = array_merge($dlInfo,$dlMirrors); $updateArray = array_merge($dlInfo,$dlMirrors);
$updateArray['WHERE'] = 'download_id='.intval($id); $updateArray['WHERE'] = 'download_id='.intval($id);
$mes->addAuto($sql->db_Update('download',$updateArray), 'update', DOWLAN_2." (<a href='".e_PLUGIN."download/download.php?view.".$id."'>".$_POST['download_name']."</a>)"); $mes->addAuto($sql->update('download',$updateArray), 'update', DOWLAN_2." (<a href='".e_PLUGIN."download/download.php?view.".$id."'>".$_POST['download_name']."</a>)");
$dlInfo['download_id'] = $id; $dlInfo['download_id'] = $id;
$this->downloadLog('DOWNL_06',$dlInfo,$dlMirrors); $this->downloadLog('DOWNL_06',$dlInfo,$dlMirrors);
@@ -1909,7 +1909,7 @@ $columnInfo = array(
if ($_POST['remove_upload']) 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 = "<br/>".$_POST['download_name']." ".DOWLAN_104; $mess = "<br/>".$_POST['download_name']." ".DOWLAN_104;
$mess .= "<br/><br/><a href='".e_ADMIN."upload.php'>".DOWLAN_105."</a>"; $mess .= "<br/><br/><a href='".e_ADMIN."upload.php'>".DOWLAN_105."</a>";
$this->show_message($mess); $this->show_message($mess);
@@ -1956,7 +1956,7 @@ $columnInfo = array(
if ($delete == "mirror") 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,''); e107::getLog()->add('DOWNL_14','ID: '.$del_id,E_LOG_INFORMATIVE,'');
} }
@@ -2107,12 +2107,12 @@ $columnInfo = array(
if (isset($_POST['id'])) 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,''); e107::getLog()->add('DOWNL_13','ID: '.intval($_POST['id']).'[!br!]'.$logString,E_LOG_INFORMATIVE,'');
} }
else 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,''); e107::getLog()->add('DOWNL_12',$logString,E_LOG_INFORMATIVE,'');
} }
} }

View File

@@ -82,7 +82,7 @@ if (isset($_POST['faq_submit']))
{ {
$faq_question = $tp->toDB($_POST['faq_question']); $faq_question = $tp->toDB($_POST['faq_question']);
$data = $tp->toDB($_POST['data']); $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."' "); $sql->insert("faqs", " 0, '".$_POST['faq_parent']."', '$faq_question', '$data', '".filter_var($_POST['faq_comment'], FILTER_SANITIZE_STRING)."', '".time()."', '".USERID."', '".$count."' ");

View File

@@ -550,11 +550,11 @@
if($forum->prefs->get('sig_once')) if($forum->prefs->get('sig_once'))
{ {
$_tmp = 'forum_sig_shown_' . $this->postInfo['post_user']; $_tmp = 'forum_sig_shown_' . $this->postInfo['post_user'];
if(getcachedvars($_tmp)) if(e107::getRegistry($_tmp))
{ {
return ''; return '';
} }
cachevars($_tmp, 1); e107::setRegistry($_tmp, 1);
} }
if($parm == 'clean') if($parm == 'clean')

View File

@@ -68,7 +68,7 @@ class pmbox_manager
$pm_info[$which] = $this->pmDB->fetch(); $pm_info[$which] = $this->pmDB->fetch();
if ($which == 'inbox' && ($this->pmPrefs['animate'] == 1 || $this->pmPrefs['popup'] == 1)) 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; $pm_info['inbox']['new'] = $new;
} }

View File

@@ -31,8 +31,8 @@ class pm_setup
function uninstall_post() function uninstall_post()
{ {
$sql = e107::getDb(); $sql = e107::getDb();
$sql->db_Delete('core', "e107_name = 'pm_prefs'"); $sql->delete('core', "e107_name = 'pm_prefs'");
$sql->db_Delete('menus', "menu_name = 'private_msg_menu'"); $sql->delete('menus', "menu_name = 'private_msg_menu'");
} }
} }

View File

@@ -490,7 +490,7 @@ class tinymce
if($id) if($id)
{ {
$insert_array['WHERE'] = $this->primary." = ".$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; $message = LAN_UPDATED;
@@ -499,7 +499,7 @@ class tinymce
} }
else 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; $message = LAN_CREATED;
} }
@@ -518,7 +518,7 @@ class tinymce
$sql = e107::getDb(); $sql = e107::getDb();
$query = $this->primary." = ".$id; $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; $message = LAN_DELETED;
$emessage->add($message, $status); $emessage->add($message, $status);
} }