From 1c75486642f7fb66b34548a8d9c8373a496a4eb1 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Sun, 28 Jan 2018 05:59:51 -0600 Subject: [PATCH 1/5] Permissive numeric field validation in db_verify db_verify::diffStructurePermissive() now checks for all MySQL/MariaDB numeric types and permissively allows the expected and actual default values to be strings rather than numerical. Fixes: #3011 Related: #2998 --- e107_handlers/db_verify_class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 e107_handlers/db_verify_class.php diff --git a/e107_handlers/db_verify_class.php b/e107_handlers/db_verify_class.php old mode 100644 new mode 100755 index a90a8cb3a..6418be6bc --- a/e107_handlers/db_verify_class.php +++ b/e107_handlers/db_verify_class.php @@ -147,11 +147,11 @@ class db_verify $expected['default'] = $actual['default']; } - // Loosely typed default value for int-like types - if(1 === preg_match('/[A-Z]*INT/i', $expected['type'])) + // Loosely typed default value for numeric types + if(1 === preg_match('/([A-Z]*INT|NUMERIC|DEC|FIXED|FLOAT|REAL|DOUBLE)/i', $expected['type'])) { - $expected['default'] = preg_replace("/DEFAULT '(\d+)'/i", 'DEFAULT $1', $expected['default']); - $actual['default'] = preg_replace("/DEFAULT '(\d+)'/i", 'DEFAULT $1', $actual['default'] ); + $expected['default'] = preg_replace("/DEFAULT '(\d*\.?\d*)'/i", 'DEFAULT $1', $expected['default']); + $actual['default'] = preg_replace("/DEFAULT '(\d*\.?\d*)'/i", 'DEFAULT $1', $actual['default'] ); } return array_diff_assoc($expected, $actual); From 5b4f936d925c9369af78426ec52de5b050650ae2 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Sun, 28 Jan 2018 06:27:29 -0600 Subject: [PATCH 2/5] file_inspector::inspect() optional arguments file_inspector::inspect() now works in PHP 7 because pass-by-reference variables are optional now as they were intended. Fixes: #3013 --- e107_admin/fileinspector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 e107_admin/fileinspector.php diff --git a/e107_admin/fileinspector.php b/e107_admin/fileinspector.php old mode 100644 new mode 100755 index f2866719d..23bb95988 --- a/e107_admin/fileinspector.php +++ b/e107_admin/fileinspector.php @@ -569,7 +569,7 @@ class file_inspector { // $dir // &$tree_end // &$parent_expand - function inspect($list, $deprecated, $level, $dir, &$tree_end, &$parent_expand) + function inspect($list, $deprecated, $level, $dir, &$tree_end = null, &$parent_expand = null) { global $coredir; @@ -1707,4 +1707,4 @@ i.fa-folder-open-o, i.fa-times-circle-o { cursor:pointer } return $text; } -?> \ No newline at end of file +?> From 28d70da8e6685ba151c71325da51c4daf452b96d Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 28 Jan 2018 13:41:16 -0800 Subject: [PATCH 3/5] Revert #3016 --- e107_handlers/admin_ui.php | 93 +++++++++++++++++++----- e107_handlers/model_class.php | 130 +++++----------------------------- 2 files changed, 92 insertions(+), 131 deletions(-) mode change 100755 => 100644 e107_handlers/model_class.php diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index bc1e2965f..25eefb1b8 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -4209,8 +4209,8 @@ class e_admin_controller_ui extends e_admin_controller elseif($this->sortField && $this->sortParent && !deftrue('e_DEBUG_TREESORT')) // automated 'tree' sorting. { // $qry = "SELECT SQL_CALC_FOUND_ROWS a. *, CASE WHEN a.".$this->sortParent." = 0 THEN a.".$this->sortField." ELSE b.".$this->sortField." + (( a.".$this->sortField.")/1000) END AS treesort FROM `#".$this->table."` AS a LEFT JOIN `#".$this->table."` AS b ON a.".$this->sortParent." = b.".$this->pid; - $qry = $this->getParentChildQry(true); - //$this->listOrder = '_treesort '; // .$this->sortField; + $qry = $this->getParentChildQry(); + $this->listOrder = '_treesort '; // .$this->sortField; // $this->orderStep = ($this->orderStep === 1) ? 100 : $this->orderStep; } else @@ -4337,18 +4337,84 @@ class e_admin_controller_ui extends e_admin_controller /** * Return a Parent/Child SQL Query based on sortParent and sortField variables - * - * Note: Since 2018-01-28, the queries were replaced with pure PHP sorting. See: - * https://github.com/e107inc/e107/issues/3015 - * * @param bool|false $orderby - include 'ORDER BY' in the qry. * @return string */ public function getParentChildQry($orderby=false) { - return "SELECT SQL_CALC_FOUND_ROWS * FROM `#".$this->getTableName()."` "; - // Use the following return statement to break e107 native sorting but speed up tree creation by presorting for e_tree_model::arrayToTree() - #return "SELECT SQL_CALC_FOUND_ROWS * FROM `#".$this->getTableName()."` ORDER BY ".$this->getSortParent().", ".$this->getSortField(); + + $parent= $this->getSortParent(); + $table = $this->getTableName(); + $pid = $this->getPrimaryName(); + $order = $this->getSortField(); + + + + $sql = "DROP FUNCTION IF EXISTS `getDepth` ;"; + + e107::getDb()->gen($sql); + + + $sql = " + CREATE FUNCTION `getDepth` (project_id INT) RETURNS int + BEGIN + DECLARE depth INT; + SET depth=1; + + WHILE project_id > 0 DO + + SELECT IFNULL(".$parent.",-1) + INTO project_id + FROM ( SELECT ".$parent." FROM `#".$table."` WHERE ".$pid." = project_id) AS t; + + IF project_id > 0 THEN + SET depth = depth + 1; + END IF; + + END WHILE; + + RETURN depth; + + END + ; + "; + + + e107::getDb()->gen($sql); + + $sql = "DROP FUNCTION IF EXISTS `getTreeSort`;"; + + e107::getDb()->gen($sql); + $sql = " + CREATE FUNCTION getTreeSort(incid INT) + RETURNS CHAR(255) + BEGIN + SET @parentstr = CONVERT(incid, CHAR); + SET @parent = -1; + label1: WHILE @parent != 0 DO + SET @parent = (SELECT ".$parent." FROM `#".$table."` WHERE ".$pid." =incid); + SET @order = (SELECT ".$order." FROM `#".$table."` WHERE ".$pid." =incid); + SET @parentstr = CONCAT(if(@parent = 0,'',@parent), LPAD(@order,4,0), @parentstr); + SET incid = @parent; + END WHILE label1; + + RETURN @parentstr; + END + ; + + "; + + + e107::getDb()->gen($sql); + + $qry = "SELECT SQL_CALC_FOUND_ROWS *, getTreeSort(".$pid.") as _treesort, getDepth(".$pid.") as _depth FROM `#".$table."` "; + + if($orderby === true) + { + $qry .= " ORDER BY _treesort"; + } + + return $qry; } @@ -6190,14 +6256,7 @@ class e_admin_ui extends e_admin_controller_ui ->setFieldIdName($this->pid) ->setUrl($this->url) ->setMessageStackName('admin_ui_tree_'.$this->table) - ->setParams(array('model_class' => 'e_admin_model', - 'model_message_stack' => 'admin_ui_model_'.$this->table , - 'db_query' => $this->listQry, - // Information necessary for PHP-based tree sort - 'sort_parent' => $this->getSortParent(), - 'sort_field' => $this->getSortField(), - 'primary_field' => $this->getPrimaryName(), - )); + ->setParams(array('model_class' => 'e_admin_model', 'model_message_stack' => 'admin_ui_model_'.$this->table ,'db_query' => $this->listQry)); return $this; } diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php old mode 100755 new mode 100644 index 97a2399e1..1ef1cac0e --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -3310,6 +3310,7 @@ class e_tree_model extends e_front_model return $this; } + $class_name = $this->getParam('model_class', 'e_model'); // auto-load all if(!$this->getParam('db_query') && $this->getModelTable()) { @@ -3322,7 +3323,6 @@ class e_tree_model extends e_front_model ); } - $class_name = $this->getParam('model_class', 'e_model'); if($this->getParam('db_query') && $class_name && class_exists($class_name)) { $sql = e107::getDb($this->getParam('model_class', 'e_model')); @@ -3330,12 +3330,8 @@ class e_tree_model extends e_front_model if($sql->gen($this->getParam('db_query'), $this->getParam('db_debug') ? true : false)) { - $rows = self::flatTreeFromArray($sql->rows(), - $this->getParam('primary_field'), - $this->getParam('sort_parent'), - $this->getParam('sort_field') - ); - foreach($rows as $tmp) + $this->_total = is_integer($sql->total_results) ? $sql->total_results : false; //requires SQL_CALC_FOUND_ROWS in query - see db handler + while($tmp = $sql->db_Fetch()) { $tmp = new $class_name($tmp); if($this->getParam('model_message_stack')) @@ -3344,9 +3340,20 @@ class e_tree_model extends e_front_model } $this->_onLoad($tmp)->setNode($tmp->get($this->getFieldIdName()), $tmp); } - unset($tmp); - $this->countResults($sql); + if(false === $this->_total && $this->getModelTable() && !$this->getParam('nocount')) + { + //SQL_CALC_FOUND_ROWS not found in the query, do one more query + // $this->_total = e107::getDb()->db_Count($this->getModelTable()); // fails with specific listQry + + // Calculates correct total when using filters and search. //XXX Optimize. + $countQry = preg_replace('/(LIMIT ([\d,\s])*)$/', "", $this->getParam('db_query')); + + $this->_total = e107::getDb()->gen($countQry); + + } + + unset($tmp); } if($sql->getLastErrorNumber()) @@ -3365,111 +3372,6 @@ class e_tree_model extends e_front_model return $this; } - /** - * Depth-first sort a relational array with a parent field and a sort order field - * @param array $rows Relational array with a parent field and a sort order field - * @param string $primary_field The field name of the primary key (matches children to parents) - * @param string $sort_parent The field name whose value is the parent ID - * @param string $sort_field The field name whose value is the sort order in the current tree node - * @return array Input array sorted depth-first as if it were a tree - */ - private static function flatTreeFromArray($rows, $primary_field, $sort_parent, $sort_field) - { - $rows_tree = self::arrayToTree($rows, $primary_field, $sort_parent); - return self::flattenTree($rows_tree, $sort_field); - } - - /** - * Converts a relational array with a parent field and a sort order field to a tree - * @param array $rows Relational array with a parent field and a sort order field - * @param string $primary_field The field name of the primary key (matches children to parents) - * @param string $sort_parent The field name whose value is the parent ID - * @return array Multidimensional array with child nodes under the "_children" key - */ - private static function arrayToTree($rows, $primary_field, $sort_parent) - { - $nodes = array(); - $root = array($primary_field => 0); - $nodes[] = &$root; - - while(!empty($nodes)) - { - $node = &$nodes[0]; - array_shift($nodes); - foreach($rows as $key => $row) - { - $rowParentID = (int) $row[$sort_parent]; - $nodeID = (int) $node[$primary_field]; - if($rowParentID === $nodeID) - { - $node['_children'][] = &$row; - unset($rows[$key]); - $nodes[] = &$row; - unset($row); - } - } - } - - return array(0 => $root); - } - - /** - * Flattens a tree into a depth-first array, sorting each node by a field's values - * @param array $tree Tree with child nodes under the "_children" key - * @param string $sort_field The field name whose value is the sort order in the current tree node - * @param int $depth The depth that this level of recursion is entering - * @return array One-dimensional array in depth-first order with depth indicated by the "_depth" key - */ - private static function flattenTree($tree, $sort_field = null, $depth = 0) - { - $flat = array(); - - foreach($tree as $item) - { - $children = $item['_children']; - unset($item['_children']); - $item['_depth'] = $depth; - if($depth > 0) - $flat[] = $item; - if(is_array($children)) - { - uasort($children, function($node1, $node2) - { - if(intval($node1[$sort_field]) === intval($node2[$sort_field])) return 0; - return intval($node1[$sort_field]) < intval($node2[$sort_field]) ? -1 : 1; - }); - $flat = array_merge($flat, self::flattenTree($children, $sort_field, $depth+1)); - } - } - - return $flat; - } - - /** - * Resiliently counts the results from the last SQL query in the given resource - * - * Sets the count in $this->_total - * - * @param resource $sql SQL resource that executed a query - * @return int Number of results from the latest query - */ - private function countResults($sql) - { - $this->_total = is_integer($sql->total_results) ? $sql->total_results : false; //requires SQL_CALC_FOUND_ROWS in query - see db handler - if(false === $this->_total && $this->getModelTable() && !$this->getParam('nocount')) - { - //SQL_CALC_FOUND_ROWS not found in the query, do one more query - // $this->_total = e107::getDb()->db_Count($this->getModelTable()); // fails with specific listQry - - // Calculates correct total when using filters and search. //XXX Optimize. - $countQry = preg_replace('/(LIMIT ([\d,\s])*)$/', "", $this->getParam('db_query')); - - $this->_total = e107::getDb()->gen($countQry); - - } - return $this->_total; - } - /** * Get single model instance from the collection * @param integer $node_id From 3b049fefd5d7436d623a0f4d817ce1f1c98a0cf1 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 29 Jan 2018 12:03:15 -0800 Subject: [PATCH 4/5] Fixes #3009 new e_gsitemap addon. --- e107_handlers/plugin_class.php | 2 + e107_plugins/forum/e_gsitemap.php | 41 ++++++++++++++++ e107_plugins/gsitemap/admin_config.php | 67 ++++++++++---------------- 3 files changed, 68 insertions(+), 42 deletions(-) create mode 100644 e107_plugins/forum/e_gsitemap.php diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index 37849500e..4af32abcc 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -75,6 +75,7 @@ class e_plugin 'e_upload', 'e_user', 'e_library', // For third-party libraries are defined by plugins/themes. + 'e_gsitemap', ); @@ -1067,6 +1068,7 @@ class e107plugin 'e_upload', 'e_user', 'e_library', // For third-party libraries are defined by plugins/themes. + 'e_gsitemap', ); diff --git a/e107_plugins/forum/e_gsitemap.php b/e107_plugins/forum/e_gsitemap.php new file mode 100644 index 000000000..b82612b63 --- /dev/null +++ b/e107_plugins/forum/e_gsitemap.php @@ -0,0 +1,41 @@ +retrieve("forum", "*", "forum_parent!='0' ORDER BY forum_order ASC", true); + + foreach($data as $row) + { + $import[] = array( + 'name' => $row['forum_name'], + 'url' => e107::url('forum','forum',$row, array('mode'=>'full')), // ('forum/forum/view', $row['forum_id']), + 'type' => LAN_PLUGIN_FORUM_NAME + ); + + } + + return $import; + } + + + +} diff --git a/e107_plugins/gsitemap/admin_config.php b/e107_plugins/gsitemap/admin_config.php index 03193da0d..266cf2584 100644 --- a/e107_plugins/gsitemap/admin_config.php +++ b/e107_plugins/gsitemap/admin_config.php @@ -18,7 +18,7 @@ if(!getperms("P") || !e107::isInstalled('gsitemap')) require_once(e_ADMIN."auth.php"); require_once(e_HANDLER."userclass_class.php"); -e107::lan('gsitemap',e_LANGUAGE."_admin_gsitemap.php"); +e107::lan('gsitemap',true); $gsm = new gsitemap; @@ -381,44 +381,27 @@ class gsitemap - /* forums ... */ - if(e107::isInstalled('forum')) - { - $sql -> select("forum", "*", "forum_parent!='0' ORDER BY forum_order ASC"); - $nfArray = $sql -> db_getList(); - foreach($nfArray as $row) + /* Plugins.. - currently: forums ... */ + $addons = e107::getAddonConfig('e_gsitemap', null, 'import'); + + foreach($addons as $plug => $config) + { + + foreach($config as $row) { - if(!in_array($row['forum_name'], $existing)) + if(!in_array($row['name'], $existing)) { - $importArray[] = array('name' => $row['forum_name'], 'url' => e107::getUrl()->create('forum/forum/view', $row['forum_id']), 'type' => "Forum"); + $importArray[] = $row; } } + } - - /* DEPRECATED content pages ... - if(e107::isInstalled('content')) - { - $sql -> select("pcontent", "content_id, content_heading", "LEFT(content_parent,1) = '0' ORDER BY content_heading"); - $nfArray = $sql -> db_getList(); - foreach($nfArray as $row) - { - $sql2 -> select("pcontent", "content_id, content_heading", "content_parent = '".$row['content_id']."' AND content_refer != 'sa' ORDER BY content_heading"); - $nfArray2 = $sql2 -> db_getList(); - foreach($nfArray2 as $row2) - { - if(!$sql -> select("gsitemap", "*", "gsitemap_name='".$row2['content_heading']."' ")) - { - $importArray[] = array('name' => $row2['content_heading'], 'url' => $PLUGINS_DIRECTORY."content/content.php?content.".$row2['content_id'], 'type' => $row['content_heading']); - } - } - } - } - */ + $editArray = $_POST; $text = "
- +
@@ -427,21 +410,22 @@ class gsitemap - - - - + + + + "; - foreach($importArray as $ia) + foreach($importArray as $k=>$ia) { + $id = 'gs-'.$k; $text .= " - - + + @@ -451,17 +435,16 @@ class gsitemap $text .= "
".GSLAN_2."".LAN_TYPE."".LAN_NAME."".LAN_URL."".GSLAN_2."".LAN_TYPE."".LAN_NAME."".LAN_URL."
".$ia['type']." ".$ia['name']." ".str_replace(SITEURL,"",$ia['url'])."
-
".GSLAN_8."   ".GSLAN_9." : \n"; for ($i=0.1; $i<1.0; $i=$i+0.1) { $sel = (vartrue($editArray['gsitemap_priority']) == number_format($i,1))? "selected='selected'" : ""; $text .= "\n"; - }; + } $text.="   ".GSLAN_10." -

+ $text .= "

@@ -479,7 +462,7 @@ class gsitemap
". - $frm->admin_button('import_links',GSLAN_18,'submit')." + $frm->admin_button('import_links',GSLAN_18,'submit')."
"; From 0ab3485a84bd177d075dac551243830f68d87c2d Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 31 Jan 2018 14:10:41 -0800 Subject: [PATCH 5/5] Fix for [img] class in TinyMce. --- e107_handlers/bbcode_handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e107_handlers/bbcode_handler.php b/e107_handlers/bbcode_handler.php index 6a6a669c0..5ae2c6049 100644 --- a/e107_handlers/bbcode_handler.php +++ b/e107_handlers/bbcode_handler.php @@ -716,7 +716,7 @@ class e_bbcode $cls = array(); foreach($tmp as $v) { - if($v === 'img-rounded' || $v === 'rounded' || $v === 'bbcode' || $v === 'bbcode-img-news' || $v === 'bbcode-img') + if($v === 'img-rounded' || $v === 'rounded' || strpos($v,'bbcode') === 0 ) { continue; }