From 183b96235ae40767a27ad1cfa7b7a0478a7dfdea Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 29 May 2019 11:18:34 -0700 Subject: [PATCH] Cleanup --- e107_admin/db.php | 532 ++-------------------------------------------- 1 file changed, 20 insertions(+), 512 deletions(-) diff --git a/e107_admin/db.php b/e107_admin/db.php index e145646cc6..5a928a793f 100644 --- a/e107_admin/db.php +++ b/e107_admin/db.php @@ -71,7 +71,7 @@ if(exportXmlFile($_POST['xml_prefs'],$_POST['xml_tables'],$_POST['xml_plugprefs'], $_POST['package_images'], false)) { $mes = e107::getMessage(); - $mes->add(LAN_SUCCESS, E_MESSAGE_SUCCESS); + $mes->add(LAN_CREATED, E_MESSAGE_SUCCESS); } } @@ -505,7 +505,12 @@ private function multiSiteProcess() } - + + /** + * @param object $sql + * @param $prefix + * @return bool + */ private function multiSiteCreateTables($sql, $prefix) { $mes = e107::getMessage(); @@ -519,7 +524,8 @@ private function multiSiteCreateTables($sql, $prefix) } preg_match_all("/create(.*?)(?:myisam|innodb);/si", $sql_data, $result ); - + + $sql->gen('SET NAMES `utf8`'); foreach ($result[0] as $sql_table) @@ -949,7 +955,7 @@ function getQueries($query) /** * Delete selected preferences. - * @return none + * @return null */ private function del_pref_val($mode='core') { @@ -1427,7 +1433,7 @@ private function pref_editor($type='core') /** * Preferences Editor - * @return none + * @return null */ private function scan_override() { @@ -1436,7 +1442,6 @@ private function scan_override() $f = e107::getFile(); $config = e107::getConfig(); - $scList = ''; $fList = $f->get_files(e_CORE.'override/shortcodes/single', '\.php$'); $scList = array(); @@ -1478,7 +1483,7 @@ private function scan_override() /** * Plugin Folder Scanner - * @return none + * @return null */ private function plugin_viewscan($mode = 'update') { @@ -1590,79 +1595,7 @@ private function plugin_viewscan($mode = 'update') } -/* - - $sql->select("plugin", "*", "plugin_id !='' order by plugin_path ASC"); // Must order by path to pick up duplicates. (plugin names may change). - $previous = ''; - while($row = $sql->fetch()) - { - e107::loadLanFiles($row['plugin_path'],'admin'); - e107::plugLan($row['plugin_path'],'global',true); - $text .= " - - ".$tp->toHTML($row['plugin_name'], FALSE, "defs,emotes_off")." - ".$row['plugin_path']." - "; - - if(trim($row['plugin_addons'])) - { - //XXX - $nl_code = ''; - OLD VAR? - foreach(explode(',', $row['plugin_addons']) as $this_addon) - { - $ret_code = 3; // Default to 'not checked - if((strpos($this_addon, 'e_') === 0) || (substr($this_addon, - 4, 4) == '_sql')) - { - $ret_code = $ep->checkAddon($row['plugin_path'], $this_addon); // See whether spaces before opening tag or after closing tag - } - elseif(strpos($this_addon, 'sc_') === 0) - { - $this_addon = substr($this_addon, 3). ' (sc)'; - } - - if(!is_numeric($ret_code)) - { - $errorMessage = $ret_code['msg']; - $ret_code = $error_type[$ret_code['type']]; - } - else - { - $errorMessage = $error_messages[$ret_code]; - } - - $text .= ""; - $text .= $error_glyph[$ret_code]." "; - - // $text .= "".$error_messages[$ret_code].""; - $text .= trim($this_addon); // $ret_code - 0=OK, 1=content error, 2=access error - $text .= "
"; - } - } - - $text .= " - - - "; - - if($previous == $row['plugin_path']) - { - $delid = $row['plugin_id']; - $delname = $row['plugin_name']; - //Admin delete button - $text .= $frm->admin_button("delplug[{$delid}]", DBLAN_52, 'delete', '', array('title' => LAN_CONFIRMDEL." ID:{$delid} [$delname]")); - //Or maybe image submit? - - //$text .= $frm->submit_image("delplug[{$delid}]", DBLAN_52, 'delete', LAN_CONFIRMDEL." ID:{$delid} [$delname]"); - } - else - { - $text .= ($row['plugin_installflag'] == 1) ? "".DBLAN_27."" : " "; // "Installed and not installed"; - } - $text .= " - - - "; - $previous = $row['plugin_path']; - }*/ $text .= " @@ -1672,6 +1605,8 @@ private function plugin_viewscan($mode = 'update') "; e107::getRender()->tablerender(DBLAN_10.SEP.DBLAN_22, $mes->render().$text); + + return null; } @@ -1685,6 +1620,7 @@ function db_adminmenu() //FIXME - has problems when navigation is on the LEFT in { global $st; + $var = array(); foreach($st->_options as $key=>$val) { @@ -1692,8 +1628,8 @@ function db_adminmenu() //FIXME - has problems when navigation is on the LEFT in $var[$key]['link'] = e_SELF."?mode=".$key; } - $icon = e107::getParser()->toIcon('e-database-24'); - $caption = $icon."".DBLAN_10.""; + $icon = e107::getParser()->toIcon('e-database-24'); + $caption = $icon."".DBLAN_10.""; e107::getNav()->admin($caption, $_GET['mode'], $var); } @@ -1704,7 +1640,7 @@ function db_adminmenu() //FIXME - has problems when navigation is on the LEFT in * @param object $prefs * @param object $tables * @param object $debug [optional] - * @return none + * @return bool|null */ function exportXmlFile($prefs,$tables=array(),$plugPrefs, $package=FALSE,$debug=FALSE) { @@ -1777,7 +1713,7 @@ function table_list() $exclude[] = "online"; $exclude[] = "upload"; $exclude[] = "user_extended_country"; - $exclude[] = "plugin"; +// $exclude[] = "plugin"; $coreTables = e107::getDb()->tables('nolan'); @@ -1800,433 +1736,5 @@ function table_list() -/* Still needed? - -function backup_core() -{ - global $pref, $sql; - $tmp = base64_encode((serialize($pref))); - if(!$sql->db_Insert("core", "'pref_backup', '{$tmp}' ")) - { - $sql->db_Update("core", "e107_value='{$tmp}' WHERE e107_name='pref_backup'"); - } -} - -*/ - -/* -function verify_sql_record() // deprecated by db_verify.php ( i think). -{ - global $e107; - - $sql = e107::getDb(); - $sql2 = e107::getDb('sql2'); - $sql3 = e107::getDb('sql3'); - $frm = e107::getForm(); - $tp = e107::getParser(); - $mes = e107::getMessage(); - - $tables = array(); - $tables[] = 'rate'; - $tables[] = 'comments'; - - if(isset($_POST['delete_verify_sql_record'])) - { - - if(!varset($_POST['del_dbrec'])) - { - $mes->add('Nothing to delete', E_MESSAGE_DEBUG); - } - else - { - $msg = "ok, so you want to delete some records? not a problem at all!
"; - $msg .= "but, since this is still an experimental procedure, i won't actually delete anything
"; - $msg .= "instead, i will show you the queries that would be performed
"; - $text .= "
"; - $mes->add($msg, E_MESSAGE_DEBUG); - - foreach($_POST['del_dbrec'] as $k => $v) - { - - if($k == 'rate') - { - - $keys = implode(", ", array_keys($v)); - $qry .= "DELETE * FROM rate WHERE rate_id IN (".$keys.")
"; - - } - elseif($k == 'comments') - { - - $keys = implode(", ", array_keys($v)); - $qry .= "DELETE * FROM comments WHERE comment_id IN (".$keys.")
"; - - } - - } - - $mes->add($qry, E_MESSAGE_DEBUG); - $mes->add("".LAN_BACK."", E_MESSAGE_DEBUG); - } - } - - //Nothing selected - if(isset($_POST['check_verify_sql_record']) && (!isset($_POST['table_rate']) && !isset($_POST['table_comments']))) - { - $_POST['check_verify_sql_record'] = ''; - unset($_POST['check_verify_sql_record']); - $mes->add(DBLAN_53, E_MESSAGE_WARNING); - } - - if(!isset($_POST['check_verify_sql_record'])) - { - //select table to verify - $text = " -
-
- ".DBLAN_39." - - - - - - - - - - - "; - foreach($tables as $t) - { - $text .= " - - - - "; - } - $text .= " - -
".DBLAN_37."
- ".$frm->checkbox('table_'.$t, $t).$frm->label($t, 'table_'.$t, $t)." -
-
- ".$frm->admin_button('check_verify_sql_record', DBLAN_38)." - ".$frm->admin_button('back', LAN_BACK, 'back')." -
-
-
- "; - - $ns->tablerender(DBLAN_10.SEP.DBLAN_39, $mes->render().$text); - } - else - { - - //function to sort the results - function verify_sql_record_cmp($a, $b) - { - - $orderby = array('type' => 'asc', 'itemid' => 'asc'); - - $result = 0; - foreach($orderby as $key => $value) - { - if($a[$key] == $b[$key]) - continue; - $result = ($a[$key] < $b[$key]) ? - 1 : 1; - if($value == 'desc') - $result = - $result; - break; - } - return $result; - } - - //function to display the results - //$err holds the error data - //$ctype holds the tablename - function verify_sql_record_displayresult($err, $ctype) - { - global $frm; - - usort($err, 'verify_sql_record_cmp'); - - $text = " - -
- ".DBLAN_40." ".$ctype." - - - - - - - - - - - - - - - - - "; - if(is_array($err) && !empty($err)) - { - - - foreach($err as $k => $v) - { - $delkey = $v['sqlid']; - $text .= " - - - - - - - "; - } - - } - else - { - $text .= " - - - - "; - } - $text .= " - -
".DBLAN_41."".LAN_ID."".DBLAN_43."".LAN_OPTIONS."
{$v['type']}{$v['itemid']}".($v['table_exist'] ? DBLAN_45 : DBLAN_46)." - ".$frm->checkbox('del_dbrec['.$ctype.']['.$delkey.'][]', '1').$frm->label(LAN_DELETE, 'del_dbrec['.$ctype.']['.$delkey.'][]', '1')." -
{$err}
-
- "; - - return $text; - } - - function verify_sql_record_gettables() - { - - $sql2 = e107::getDb('sql2'); - - //array which will hold all db tables - $dbtables = array(); - - //get all tables in the db - $sql2->gen("SHOW TABLES"); - while($row2 = $sql2->fetch()) - { - $dbtables[] = $row2[0]; - } - return $dbtables; - } - - $text = "
"; - - //validate rate table records - if(isset($_POST['table_rate'])) - { - - $query = " - SELECT r.* - FROM #rate AS r - WHERE r.rate_id!='' - ORDER BY r.rate_table, r.rate_itemid"; - $data = array('type' => 'rate', 'table' => 'rate_table', 'itemid' => 'rate_itemid', 'id' => 'rate_id'); - - if(!$sql->gen($query)) - { - $text .= verify_sql_record_displayresult(DBLAN_49, $data['type']); - } - else - { - //the master error array - $err = array(); - - //array which will hold all db tables - $dbtables = verify_sql_record_gettables(); - - while($row = $sql->fetch()) - { - - $ctype = $data['type']; - $cid = $row[$data['id']]; - $citemid = $row[$data['itemid']]; - $ctable = $row[$data['table']]; - - //if the rate_table is an existing table, we need to do more validation - //else if the rate_table is not an existing table, this is an invalid reference - //FIXME Steve: table is never found without MPREFIX; Multi-language tables? - if(in_array(MPREFIX.$ctable, $dbtables)) - { - - $sql3->gen("SHOW COLUMNS FROM ".MPREFIX.$ctable); - while($row3 = $sql3->fetch()) - { - //find the auto_increment field, since that's the most likely key used - if($row3['Extra'] == 'auto_increment') - { - $aif = $row3['Field']; - break; - } - } - - //we need to check if the itemid (still) exists in this table - //if the record is not found, this could well be an obsolete record - //if the record is found, we need to keep this record since it's a valid reference - if(!$sql2->db_Select("{$ctable}", "*", "{$aif}='{$citemid}' ORDER BY {$aif} ")) - { - $err[] = array('type' => $ctable, 'sqlid' => $cid, 'table' => $ctable, 'itemid' => $citemid, 'table_exist' => TRUE); - } - - } - else - { - $err[] = array('type' => $ctable, 'sqlid' => $cid, 'table' => $ctable, 'itemid' => $citemid, 'table_exist' => FALSE); - } - } - - $text .= verify_sql_record_displayresult(($err ? $err : DBLAN_54), $ctype); - } - } - - //validate comments table records - if(isset($_POST['table_comments'])) - { - - $query = " - SELECT c.* - FROM #comments AS c - WHERE c.comment_id!='' - ORDER BY c.comment_type, c.comment_item_id"; - $data = array('type' => 'comments', 'table' => 'comment_type', 'itemid' => 'comment_item_id', 'id' => 'comment_id'); - - if(!$sql->gen($query)) - { - $text .= verify_sql_record_displayresult(DBLAN_49, $data['type']); - } - else - { - - //the master error array - $err = array(); - - //array which will hold all db tables - $dbtables = verify_sql_record_gettables(); - - //get all e_comment files and variables - require_once (e_HANDLER."comment_class.php"); - $cobj = new comment(); - $e_comment = $cobj->get_e_comment(); - - while($row = $sql->fetch()) - { - - $ctype = $data['type']; - $cid = $row[$data['id']]; - $citemid = $row[$data['itemid']]; - $ctable = $row[$data['table']]; - - //for each comment we need to validate the referencing record exists - //we need to check if the itemid (still) exists in this table - //if the record is not found, this could well be an obsolete record - //if the record is found, we need to keep this record since it's a valid reference - - - // news - if($ctable == "0") - { - if(!$sql2->db_Select("news", "*", "news_id='{$citemid}' ")) - { - $err[] = array('type' => 'news', 'sqlid' => $cid, 'table' => $ctable, 'itemid' => $citemid, 'table_exist' => TRUE); - } - // article, review or content page - } - elseif($ctable == "1") - { - - // downloads - } - elseif($ctable == "2") - { - if(!$sql2->db_Select("download", "*", "download_id='{$citemid}' ")) - { - $err[] = array('type' => 'download', 'sqlid' => $cid, 'table' => $ctable, 'itemid' => $citemid, 'table_exist' => TRUE); - } - - // poll - } - elseif($ctable == "4") - { - if(!$sql2->db_Select("polls", "*", "poll_id='{$citemid}' ")) - { - $err[] = array('type' => 'polls', 'sqlid' => $cid, 'table' => $ctable, 'itemid' => $citemid, 'table_exist' => TRUE); - } - - // userprofile - } - elseif($ctable == "profile") - { - if(!$sql2->db_Select("user", "*", "user_id='{$citemid}' ")) - { - $err[] = array('type' => 'user', 'sqlid' => $cid, 'table' => $ctable, 'itemid' => $citemid, 'table_exist' => TRUE); - } - - //else if this is a plugin comment - } - elseif(isset($e_comment[$ctable]) && is_array($e_comment[$ctable])) - { - $var = $e_comment[$ctable]; - $qryp = ''; - //new method must use the 'qry' variable - if(isset($var) && $var['qry'] != '') - { - if($installed = $sql2->db_Select("plugin", "*", "plugin_path = '".$var['plugin_path']."' AND plugin_installflag = '1' ")) - { - $qryp = str_replace("{NID}", $citemid, $var['qry']); - if(!$sql2->gen($qryp)) - { - $err[] = array('type' => $ctable, 'sqlid' => $cid, 'table' => $ctable, 'itemid' => $citemid, 'table_exist' => TRUE); - } - } - //old method - } - else - { - if(!$sql2->db_Select($var['db_table'], $var['db_title'], $var['db_id']." = '{$citemid}' ")) - { - $err[] = array('type' => $ctable, 'sqlid' => $cid, 'table' => $ctable, 'itemid' => $citemid, 'table_exist' => TRUE); - } - } - //in all other cases - } - else - { - $err[] = array('type' => $ctable, 'sqlid' => $cid, 'table' => $ctable, 'itemid' => $citemid, 'table_exist' => FALSE); - } - - } - - $text .= verify_sql_record_displayresult(($err ? $err : DBLAN_54), $ctype); - } - } - - $text .= " -
- ".$frm->admin_button('delete_verify_sql_record', LAN_DELCHECKED, 'delete')." - ".$frm->admin_button('verify_sql_record', LAN_BACK, 'back')." - -
-
- "; - - $ns->tablerender(DBLAN_10.SEP.DBLAN_50, $mes->render().$text); - } -} -*/ -?> +?> \ No newline at end of file