Passed
Push — master ( 565d4a...492cc7 )
by Michael
07:40
created
class/Digest.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         global $myts;
68 68
 
69 69
         $clean = stripslashes($text);
70
-        $clean =& $myts->displayTarea($clean, 1, 0, 1);
70
+        $clean = & $myts->displayTarea($clean, 1, 0, 1);
71 71
         $clean = strip_tags($clean);
72 72
         $clean = htmlspecialchars($clean, ENT_QUOTES);
73 73
 
@@ -87,16 +87,16 @@  discard block
 block discarded – undo
87 87
             $linebreak = $isHtml ? '<br>' : "\n";
88 88
             for ($i = 0; $i < $digest_count; ++$i) {
89 89
                 if ($isHtml) {
90
-                    $content .= ($i + 1) . '. <a href=' . $this->items[$i]['link'] . '>' . $this->items[$i]['title'] . '</a>';
90
+                    $content .= ($i + 1).'. <a href='.$this->items[$i]['link'].'>'.$this->items[$i]['title'].'</a>';
91 91
                 } else {
92
-                    $content .= ($i + 1) . '. ' . $this->items[$i]['title'] . $linebreak . $this->items[$i]['link'];
92
+                    $content .= ($i + 1).'. '.$this->items[$i]['title'].$linebreak.$this->items[$i]['link'];
93 93
                 }
94 94
 
95
-                $content .= $linebreak . $this->items[$i]['author'];
95
+                $content .= $linebreak.$this->items[$i]['author'];
96 96
                 if ($isSummary) {
97
-                    $content .= $linebreak . $this->items[$i]['summary'];
97
+                    $content .= $linebreak.$this->items[$i]['summary'];
98 98
                 }
99
-                $content .= $linebreak . $linebreak;
99
+                $content .= $linebreak.$linebreak;
100 100
             }
101 101
         }
102 102
         $this->setVar('digest_content', $content);
Please login to merge, or discard this patch.
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -12,96 +12,96 @@
 block discarded – undo
12 12
 
13 13
 class Digest extends \XoopsObject
14 14
 {
15
-    public $digest_id;
16
-    public $digest_time;
17
-    public $digest_content;
15
+	public $digest_id;
16
+	public $digest_time;
17
+	public $digest_content;
18 18
 
19
-    public $items;
20
-    public $isHtml    = false;
21
-    public $isSummary = true;
19
+	public $items;
20
+	public $isHtml    = false;
21
+	public $isSummary = true;
22 22
 
23
-    /**
24
-     *
25
-     */
26
-    public function __construct()
27
-    {
28
-        parent::__construct();
29
-        $this->initVar('digest_id', XOBJ_DTYPE_INT);
30
-        $this->initVar('digest_time', XOBJ_DTYPE_INT);
31
-        $this->initVar('digest_content', XOBJ_DTYPE_TXTAREA);
32
-        $this->items = [];
33
-    }
23
+	/**
24
+	 *
25
+	 */
26
+	public function __construct()
27
+	{
28
+		parent::__construct();
29
+		$this->initVar('digest_id', XOBJ_DTYPE_INT);
30
+		$this->initVar('digest_time', XOBJ_DTYPE_INT);
31
+		$this->initVar('digest_content', XOBJ_DTYPE_TXTAREA);
32
+		$this->items = [];
33
+	}
34 34
 
35
-    public function setHtml()
36
-    {
37
-        $this->isHtml = true;
38
-    }
35
+	public function setHtml()
36
+	{
37
+		$this->isHtml = true;
38
+	}
39 39
 
40
-    public function setSummary()
41
-    {
42
-        $this->isSummary = true;
43
-    }
40
+	public function setSummary()
41
+	{
42
+		$this->isSummary = true;
43
+	}
44 44
 
45
-    /**
46
-     * @param        $title
47
-     * @param        $link
48
-     * @param        $author
49
-     * @param string $summary
50
-     */
51
-    public function addItem($title, $link, $author, $summary = '')
52
-    {
53
-        $title  = $this->cleanup($title);
54
-        $author = $this->cleanup($author);
55
-        if (!empty($summary)) {
56
-            $summary = $this->cleanup($summary);
57
-        }
58
-        $this->items[] = ['title' => $title, 'link' => $link, 'author' => $author, 'summary' => $summary];
59
-    }
45
+	/**
46
+	 * @param        $title
47
+	 * @param        $link
48
+	 * @param        $author
49
+	 * @param string $summary
50
+	 */
51
+	public function addItem($title, $link, $author, $summary = '')
52
+	{
53
+		$title  = $this->cleanup($title);
54
+		$author = $this->cleanup($author);
55
+		if (!empty($summary)) {
56
+			$summary = $this->cleanup($summary);
57
+		}
58
+		$this->items[] = ['title' => $title, 'link' => $link, 'author' => $author, 'summary' => $summary];
59
+	}
60 60
 
61
-    /**
62
-     * @param $text
63
-     * @return mixed|string
64
-     */
65
-    public function cleanup($text)
66
-    {
67
-        global $myts;
61
+	/**
62
+	 * @param $text
63
+	 * @return mixed|string
64
+	 */
65
+	public function cleanup($text)
66
+	{
67
+		global $myts;
68 68
 
69
-        $clean = stripslashes($text);
70
-        $clean =& $myts->displayTarea($clean, 1, 0, 1);
71
-        $clean = strip_tags($clean);
72
-        $clean = htmlspecialchars($clean, ENT_QUOTES);
69
+		$clean = stripslashes($text);
70
+		$clean =& $myts->displayTarea($clean, 1, 0, 1);
71
+		$clean = strip_tags($clean);
72
+		$clean = htmlspecialchars($clean, ENT_QUOTES);
73 73
 
74 74
 
75
-        return $clean;
76
-    }
75
+		return $clean;
76
+	}
77 77
 
78
-    /**
79
-     * @param  bool $isSummary
80
-     * @param  bool $isHtml
81
-     * @return bool
82
-     */
83
-    public function buildContent($isSummary = true, $isHtml = false)
84
-    {
85
-        $digest_count = count($this->items);
86
-        $content      = '';
87
-        if ($digest_count > 0) {
88
-            $linebreak = $isHtml ? '<br>' : "\n";
89
-            for ($i = 0; $i < $digest_count; ++$i) {
90
-                if ($isHtml) {
91
-                    $content .= ($i + 1) . '. <a href=' . $this->items[$i]['link'] . '>' . $this->items[$i]['title'] . '</a>';
92
-                } else {
93
-                    $content .= ($i + 1) . '. ' . $this->items[$i]['title'] . $linebreak . $this->items[$i]['link'];
94
-                }
78
+	/**
79
+	 * @param  bool $isSummary
80
+	 * @param  bool $isHtml
81
+	 * @return bool
82
+	 */
83
+	public function buildContent($isSummary = true, $isHtml = false)
84
+	{
85
+		$digest_count = count($this->items);
86
+		$content      = '';
87
+		if ($digest_count > 0) {
88
+			$linebreak = $isHtml ? '<br>' : "\n";
89
+			for ($i = 0; $i < $digest_count; ++$i) {
90
+				if ($isHtml) {
91
+					$content .= ($i + 1) . '. <a href=' . $this->items[$i]['link'] . '>' . $this->items[$i]['title'] . '</a>';
92
+				} else {
93
+					$content .= ($i + 1) . '. ' . $this->items[$i]['title'] . $linebreak . $this->items[$i]['link'];
94
+				}
95 95
 
96
-                $content .= $linebreak . $this->items[$i]['author'];
97
-                if ($isSummary) {
98
-                    $content .= $linebreak . $this->items[$i]['summary'];
99
-                }
100
-                $content .= $linebreak . $linebreak;
101
-            }
102
-        }
103
-        $this->setVar('digest_content', $content);
96
+				$content .= $linebreak . $this->items[$i]['author'];
97
+				if ($isSummary) {
98
+					$content .= $linebreak . $this->items[$i]['summary'];
99
+				}
100
+				$content .= $linebreak . $linebreak;
101
+			}
102
+		}
103
+		$this->setVar('digest_content', $content);
104 104
 
105
-        return true;
106
-    }
105
+		return true;
106
+	}
107 107
 }
Please login to merge, or discard this patch.
class/Utility.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     public function addField($field, $table)
66 66
     {
67 67
         global $xoopsDB;
68
-        $result = $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field");
68
+        $result = $xoopsDB->queryF('ALTER TABLE '.$table." ADD $field");
69 69
 
70 70
         return $result;
71 71
     }
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             if (!@mkdir($folder) && !is_dir($folder)) {
84 84
                 throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
85 85
             } else {
86
-                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
86
+                file_put_contents($folder.'/index.html', '<script>history.go(-1);</script>');
87 87
             }
88 88
         } catch (\Exception $e) {
89 89
             echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             return;
99 99
         }
100 100
         // for 2.5 systems, clear everything
101
-        require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
101
+        require_once XOOPS_ROOT_PATH.'/modules/system/class/maintenance.php';
102 102
         $maintenance = new \SystemMaintenance();
103 103
         $cacheList   = [
104 104
             3, // xoops_cache
Please login to merge, or discard this patch.
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -8,127 +8,127 @@
 block discarded – undo
8 8
  */
9 9
 class Utility
10 10
 {
11
-    use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits
12
-
13
-    use Common\ServerStats; // getServerStats Trait
14
-
15
-    use Common\FilesManagement; // Files Management Trait
16
-
17
-    //--------------- Custom module methods -----------------------------
18
-
19
-    /**
20
-     * Verify that a mysql table exists
21
-     *
22
-     * @package       News
23
-     * @author        Hervé Thouzard (http://www.herve-thouzard.com)
24
-     * @copyright (c) Hervé Thouzard
25
-     * @param $tablename
26
-     * @return bool
27
-     */
28
-    public function tableExists($tablename)
29
-    {
30
-        global $xoopsDB;
31
-        /** @var \XoopsMySQLDatabase $xoopsDB */
32
-        $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'");
33
-
34
-        return ($xoopsDB->getRowsNum($result) > 0);
35
-    }
36
-
37
-    /**
38
-     * Verify that a field exists inside a mysql table
39
-     *
40
-     * @package       News
41
-     * @author        Hervé Thouzard (http://www.herve-thouzard.com)
42
-     * @copyright (c) Hervé Thouzard
43
-     * @param $fieldname
44
-     * @param $table
45
-     * @return bool
46
-     */
47
-    public function fieldExists($fieldname, $table)
48
-    {
49
-        global $xoopsDB;
50
-        $result = $xoopsDB->queryF("SHOW COLUMNS FROM   $table LIKE '$fieldname'");
51
-
52
-        return ($xoopsDB->getRowsNum($result) > 0);
53
-    }
54
-
55
-    /**
56
-     * Add a field to a mysql table
57
-     *
58
-     * @package       News
59
-     * @author        Hervé Thouzard (http://www.herve-thouzard.com)
60
-     * @copyright (c) Hervé Thouzard
61
-     * @param $field
62
-     * @param $table
63
-     * @return bool|\mysqli_result
64
-     */
65
-    public function addField($field, $table)
66
-    {
67
-        global $xoopsDB;
68
-        $result = $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field");
69
-
70
-        return $result;
71
-    }
72
-
73
-    /**
74
-     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
75
-     *
76
-     * @param string $folder Le chemin complet du répertoire à vérifier
77
-     *
78
-     * @return void
79
-     */
80
-    public static function prepareFolder($folder)
81
-    {
82
-        try {
83
-            if (!@mkdir($folder) && !is_dir($folder)) {
84
-                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
85
-            } else {
86
-                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
87
-            }
88
-        } catch (\Exception $e) {
89
-            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
90
-        }
91
-    }
92
-
93
-    public static function cleanCache()
94
-    {
95
-        $cacheHelper = new \Xmf\Module\Helper\Cache('newbb');
96
-        if (method_exists($cacheHelper, 'clear')) {
97
-            $cacheHelper->clear();
98
-            return;
99
-        }
100
-        // for 2.5 systems, clear everything
101
-        require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
102
-        $maintenance = new \SystemMaintenance();
103
-        $cacheList   = [
104
-            3, // xoops_cache
105
-        ];
106
-        $maintenance->CleanCache($cacheList);
107
-        xoops_setActiveModules();
108
-    }
109
-
110
-    /**
111
-     * Checks if a user is admin of NewBB
112
-     *
113
-     * @return boolean
114
-     */
115
-    public static function userIsAdmin()
116
-    {
117
-        /** @var Newbb\Helper $helper */
118
-        $helper = Newbb\Helper::getInstance();
119
-
120
-        static $newbbIsAdmin;
121
-
122
-        if (isset($newbbIsAdmin)) {
123
-            return $newbbIsAdmin;
124
-        }
125
-
126
-        if (!$GLOBALS['xoopsUser']) {
127
-            $newbbIsAdmin = false;
128
-        } else {
129
-            $newbbIsAdmin = $GLOBALS['xoopsUser']->isAdmin($helper->getModule()->getVar('mid'));
130
-        }
131
-
132
-        return $newbbIsAdmin;
133
-    }
11
+	use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits
12
+
13
+	use Common\ServerStats; // getServerStats Trait
14
+
15
+	use Common\FilesManagement; // Files Management Trait
16
+
17
+	//--------------- Custom module methods -----------------------------
18
+
19
+	/**
20
+	 * Verify that a mysql table exists
21
+	 *
22
+	 * @package       News
23
+	 * @author        Hervé Thouzard (http://www.herve-thouzard.com)
24
+	 * @copyright (c) Hervé Thouzard
25
+	 * @param $tablename
26
+	 * @return bool
27
+	 */
28
+	public function tableExists($tablename)
29
+	{
30
+		global $xoopsDB;
31
+		/** @var \XoopsMySQLDatabase $xoopsDB */
32
+		$result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'");
33
+
34
+		return ($xoopsDB->getRowsNum($result) > 0);
35
+	}
36
+
37
+	/**
38
+	 * Verify that a field exists inside a mysql table
39
+	 *
40
+	 * @package       News
41
+	 * @author        Hervé Thouzard (http://www.herve-thouzard.com)
42
+	 * @copyright (c) Hervé Thouzard
43
+	 * @param $fieldname
44
+	 * @param $table
45
+	 * @return bool
46
+	 */
47
+	public function fieldExists($fieldname, $table)
48
+	{
49
+		global $xoopsDB;
50
+		$result = $xoopsDB->queryF("SHOW COLUMNS FROM   $table LIKE '$fieldname'");
51
+
52
+		return ($xoopsDB->getRowsNum($result) > 0);
53
+	}
54
+
55
+	/**
56
+	 * Add a field to a mysql table
57
+	 *
58
+	 * @package       News
59
+	 * @author        Hervé Thouzard (http://www.herve-thouzard.com)
60
+	 * @copyright (c) Hervé Thouzard
61
+	 * @param $field
62
+	 * @param $table
63
+	 * @return bool|\mysqli_result
64
+	 */
65
+	public function addField($field, $table)
66
+	{
67
+		global $xoopsDB;
68
+		$result = $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field");
69
+
70
+		return $result;
71
+	}
72
+
73
+	/**
74
+	 * Function responsible for checking if a directory exists, we can also write in and create an index.html file
75
+	 *
76
+	 * @param string $folder Le chemin complet du répertoire à vérifier
77
+	 *
78
+	 * @return void
79
+	 */
80
+	public static function prepareFolder($folder)
81
+	{
82
+		try {
83
+			if (!@mkdir($folder) && !is_dir($folder)) {
84
+				throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
85
+			} else {
86
+				file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
87
+			}
88
+		} catch (\Exception $e) {
89
+			echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
90
+		}
91
+	}
92
+
93
+	public static function cleanCache()
94
+	{
95
+		$cacheHelper = new \Xmf\Module\Helper\Cache('newbb');
96
+		if (method_exists($cacheHelper, 'clear')) {
97
+			$cacheHelper->clear();
98
+			return;
99
+		}
100
+		// for 2.5 systems, clear everything
101
+		require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
102
+		$maintenance = new \SystemMaintenance();
103
+		$cacheList   = [
104
+			3, // xoops_cache
105
+		];
106
+		$maintenance->CleanCache($cacheList);
107
+		xoops_setActiveModules();
108
+	}
109
+
110
+	/**
111
+	 * Checks if a user is admin of NewBB
112
+	 *
113
+	 * @return boolean
114
+	 */
115
+	public static function userIsAdmin()
116
+	{
117
+		/** @var Newbb\Helper $helper */
118
+		$helper = Newbb\Helper::getInstance();
119
+
120
+		static $newbbIsAdmin;
121
+
122
+		if (isset($newbbIsAdmin)) {
123
+			return $newbbIsAdmin;
124
+		}
125
+
126
+		if (!$GLOBALS['xoopsUser']) {
127
+			$newbbIsAdmin = false;
128
+		} else {
129
+			$newbbIsAdmin = $GLOBALS['xoopsUser']->isAdmin($helper->getModule()->getVar('mid'));
130
+		}
131
+
132
+		return $newbbIsAdmin;
133
+	}
134 134
 }
Please login to merge, or discard this patch.
class/ReadHandler.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     public function __construct(\XoopsDatabase $db, $type)
93 93
     {
94 94
         $type = ('forum' === $type) ? 'forum' : 'topic';
95
-        parent::__construct($db, 'newbb_reads_' . $type, Read::class . $type, 'read_id', 'post_id');
95
+        parent::__construct($db, 'newbb_reads_'.$type, Read::class.$type, 'read_id', 'post_id');
96 96
         $this->type  = $type;
97 97
         $newbbConfig = newbbLoadConfig();
98 98
         // irmtfan if read_expire = 0 dont clean
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
             return false;
114 114
         }
115 115
 
116
-        $sql = 'DELETE bb FROM ' . $this->table . ' AS bb' . ' LEFT JOIN ' . $this->table . ' AS aa ON bb.read_item = aa.read_item ' . ' WHERE aa.post_id > bb.post_id';
116
+        $sql = 'DELETE bb FROM '.$this->table.' AS bb'.' LEFT JOIN '.$this->table.' AS aa ON bb.read_item = aa.read_item '.' WHERE aa.post_id > bb.post_id';
117 117
         if (!$result = $this->db->queryF($sql)) {
118 118
             //xoops_error($this->db->error());
119 119
             return false;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         }
125 125
         // irmtfan move here and rephrase
126 126
         $expire = time() - (int)$this->lifetime;
127
-        $sql    = 'DELETE FROM ' . $this->table . ' WHERE read_time < ' . $expire;
127
+        $sql    = 'DELETE FROM '.$this->table.' WHERE read_time < '.$expire;
128 128
         if (!$result = $this->db->queryF($sql)) {
129 129
             //xoops_error($this->db->error());
130 130
             return false;
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
                 return false;
181 181
             }
182 182
         }
183
-        $sql = 'SELECT post_id ' . ' FROM ' . $this->table . ' WHERE read_item = ' . (int)$read_item . '     AND uid = ' . (int)$uid;
183
+        $sql = 'SELECT post_id '.' FROM '.$this->table.' WHERE read_item = '.(int)$read_item.'     AND uid = '.(int)$uid;
184 184
         if (!$result = $this->db->queryF($sql, 1)) {
185 185
             return null;
186 186
         }
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
             }
236 236
         }
237 237
 
238
-        $sql = 'UPDATE ' . $this->table . ' SET post_id = ' . (int)$post_id . ',' . '     read_time =' . time() . ' WHERE read_item = ' . (int)$read_item . '     AND uid = ' . (int)$uid;
238
+        $sql = 'UPDATE '.$this->table.' SET post_id = '.(int)$post_id.','.'     read_time ='.time().' WHERE read_item = '.(int)$read_item.'     AND uid = '.(int)$uid;
239 239
         if ($this->db->queryF($sql) && $this->db->getAffectedRows()) {
240 240
             return true;
241 241
         }
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
         }
308 308
 
309 309
         $criteria = new \CriteriaCompo(new \Criteria('uid', $uid));
310
-        $criteria->add(new \Criteria('read_item', '(' . implode(', ', array_map('intval', array_keys($items))) . ')', 'IN'));
310
+        $criteria->add(new \Criteria('read_item', '('.implode(', ', array_map('intval', array_keys($items))).')', 'IN'));
311 311
         $itemsObject = $this->getAll($criteria, ['read_item', 'post_id']);
312 312
 
313 313
         $items_list = [];
@@ -339,43 +339,43 @@  discard block
 block discarded – undo
339 339
         $sql = "SET sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''))";
340 340
         $this->db->queryF($sql);
341 341
 
342
-        $sql = 'CREATE TABLE ' . $this->table . '_duplicate LIKE ' . $this->table . '; ';
342
+        $sql = 'CREATE TABLE '.$this->table.'_duplicate LIKE '.$this->table.'; ';
343 343
         if (!$result = $this->db->queryF($sql)) {
344
-            xoops_error($this->db->error() . '<br>' . $sql);
344
+            xoops_error($this->db->error().'<br>'.$sql);
345 345
 
346 346
             return false;
347 347
         }
348
-        $sql = 'INSERT ' . $this->table . '_duplicate SELECT * FROM ' . $this->table . ' GROUP BY read_item, uid; ';
348
+        $sql = 'INSERT '.$this->table.'_duplicate SELECT * FROM '.$this->table.' GROUP BY read_item, uid; ';
349 349
         if (!$result = $this->db->queryF($sql)) {
350
-            xoops_error($this->db->error() . '<br>' . $sql);
350
+            xoops_error($this->db->error().'<br>'.$sql);
351 351
 
352 352
             return false;
353 353
         }
354
-        $sql = 'RENAME TABLE ' . $this->table . ' TO ' . $this->table . '_with_duplicate; ';
354
+        $sql = 'RENAME TABLE '.$this->table.' TO '.$this->table.'_with_duplicate; ';
355 355
         if (!$result = $this->db->queryF($sql)) {
356
-            xoops_error($this->db->error() . '<br>' . $sql);
356
+            xoops_error($this->db->error().'<br>'.$sql);
357 357
 
358 358
             return false;
359 359
         }
360
-        $sql = 'RENAME TABLE ' . $this->table . '_duplicate TO ' . $this->table . '; ';
360
+        $sql = 'RENAME TABLE '.$this->table.'_duplicate TO '.$this->table.'; ';
361 361
         if (!$result = $this->db->queryF($sql)) {
362
-            xoops_error($this->db->error() . '<br>' . $sql);
362
+            xoops_error($this->db->error().'<br>'.$sql);
363 363
 
364 364
             return false;
365 365
         }
366
-        $sql    = 'SHOW INDEX FROM ' . $this->table . " WHERE KEY_NAME = 'read_item_uid'";
366
+        $sql    = 'SHOW INDEX FROM '.$this->table." WHERE KEY_NAME = 'read_item_uid'";
367 367
         $result = $this->db->queryF($sql);
368 368
         if (empty($result)) {
369
-            $sql .= 'ALTER TABLE ' . $this->table . ' ADD INDEX read_item_uid ( read_item, uid ); ';
369
+            $sql .= 'ALTER TABLE '.$this->table.' ADD INDEX read_item_uid ( read_item, uid ); ';
370 370
             if (!$result = $this->db->queryF($sql)) {
371
-                xoops_error($this->db->error() . '<br>' . $sql);
371
+                xoops_error($this->db->error().'<br>'.$sql);
372 372
 
373 373
                 return false;
374 374
             }
375 375
         }
376
-        $sql = 'DROP TABLE ' . $this->table . '_with_duplicate; ';
376
+        $sql = 'DROP TABLE '.$this->table.'_with_duplicate; ';
377 377
         if (!$result = $this->db->queryF($sql)) {
378
-            xoops_error($this->db->error() . '<br>' . $sql);
378
+            xoops_error($this->db->error().'<br>'.$sql);
379 379
 
380 380
             return false;
381 381
         }
Please login to merge, or discard this patch.
Indentation   +336 added lines, -336 removed lines patch added patch discarded remove patch
@@ -48,340 +48,340 @@
 block discarded – undo
48 48
  */
49 49
 class ReadHandler extends \XoopsPersistableObjectHandler
50 50
 {
51
-    /**
52
-     * Object type.
53
-     * <ul>
54
-     *  <li>forum</li>
55
-     *  <li>topic</li>
56
-     * </ul>
57
-     *
58
-     * @var string
59
-     */
60
-    public $type;
61
-
62
-    /**
63
-     * seconds records will persist.
64
-     * assigned from $GLOBALS['xoopsModuleConfig']["read_expire"]
65
-     * <ul>
66
-     *  <li>positive days = delete all read records exist in the tables before expire time // irmtfan add comment</li>
67
-     *  <li>0 = never expires // irmtfan change comment</li>
68
-     *  <li>-1 or any negative days = never records // irmtfan change comment</li>
69
-     * </ul>
70
-     *
71
-     * @var integer
72
-     */
73
-    public $lifetime;
74
-
75
-    /**
76
-     * storage mode for records.
77
-     * assigned from $GLOBALS['xoopsModuleConfig']["read_mode"]
78
-     * <ul>
79
-     *  <li>0 = never records</li>
80
-     *  <li>1 = uses cookie</li>
81
-     *  <li>2 = stores in database</li>
82
-     * </ul>
83
-     *
84
-     * @var integer
85
-     */
86
-    public $mode;
87
-
88
-    /**
89
-     * @param \XoopsDatabase     $db
90
-     * @param                    $type
91
-     */
92
-    public function __construct(\XoopsDatabase $db, $type)
93
-    {
94
-        $type = ('forum' === $type) ? 'forum' : 'topic';
95
-        parent::__construct($db, 'newbb_reads_' . $type, Read::class . $type, 'read_id', 'post_id');
96
-        $this->type  = $type;
97
-        $newbbConfig = newbbLoadConfig();
98
-        // irmtfan if read_expire = 0 dont clean
99
-        $this->lifetime = isset($newbbConfig['read_expire']) ? (int)$newbbConfig['read_expire'] * 24 * 3600 : 30 * 24 * 3600;
100
-        $this->mode     = isset($newbbConfig['read_mode']) ? $newbbConfig['read_mode'] : 2;
101
-    }
102
-
103
-    /**
104
-     * Clear garbage
105
-     *
106
-     * Delete all expired and duplicated records
107
-     */
108
-    // START irmtfan rephrase function to 1- add clearDuplicate and 2- dont clean when read_expire = 0
109
-    public function clearGarbage()
110
-    {
111
-        // irmtfan clear duplicaed rows
112
-        if (!$result = $this->clearDuplicate()) {
113
-            return false;
114
-        }
115
-
116
-        $sql = 'DELETE bb FROM ' . $this->table . ' AS bb' . ' LEFT JOIN ' . $this->table . ' AS aa ON bb.read_item = aa.read_item ' . ' WHERE aa.post_id > bb.post_id';
117
-        if (!$result = $this->db->queryF($sql)) {
118
-            //xoops_error($this->db->error());
119
-            return false;
120
-        }
121
-        // irmtfan if read_expire = 0 dont clean
122
-        if (empty($this->lifetime)) {
123
-            return true;
124
-        }
125
-        // irmtfan move here and rephrase
126
-        $expire = time() - (int)$this->lifetime;
127
-        $sql    = 'DELETE FROM ' . $this->table . ' WHERE read_time < ' . $expire;
128
-        if (!$result = $this->db->queryF($sql)) {
129
-            //xoops_error($this->db->error());
130
-            return false;
131
-        }
132
-
133
-        return true;
134
-    }
135
-
136
-    // END irmtfan rephrase function to 1- add clearDuplicate and 2- dont clean when read_expire = 0
137
-
138
-    /**
139
-     * @param                  $read_item
140
-     * @param  null            $uid
141
-     * @return bool|mixed|null
142
-     */
143
-    public function getRead($read_item, $uid = null)
144
-    {
145
-        if (empty($this->mode)) {
146
-            return null;
147
-        }
148
-        if (1 == $this->mode) {
149
-            return $this->getReadCookie($read_item);
150
-        }
151
-
152
-        return $this->getReadDb($read_item, $uid);
153
-    }
154
-
155
-    /**
156
-     * @param $item_id
157
-     * @return mixed
158
-     */
159
-    public function getReadCookie($item_id)
160
-    {
161
-        $cookie_name = ('forum' === $this->type) ? 'LF' : 'LT';
162
-        $cookie_var  = $item_id;
163
-        // irmtfan set true to return array
164
-        $lastview = newbbGetCookie($cookie_name, true);
165
-
166
-        return @$lastview[$cookie_var];
167
-    }
168
-
169
-    /**
170
-     * @param $read_item
171
-     * @param $uid
172
-     * @return bool|null
173
-     */
174
-    public function getReadDb($read_item, $uid)
175
-    {
176
-        if (empty($uid)) {
177
-            if (is_object($GLOBALS['xoopsUser'])) {
178
-                $uid = $GLOBALS['xoopsUser']->getVar('uid');
179
-            } else {
180
-                return false;
181
-            }
182
-        }
183
-        $sql = 'SELECT post_id ' . ' FROM ' . $this->table . ' WHERE read_item = ' . (int)$read_item . '     AND uid = ' . (int)$uid;
184
-        if (!$result = $this->db->queryF($sql, 1)) {
185
-            return null;
186
-        }
187
-        list($post_id) = $this->db->fetchRow($result);
188
-
189
-        return $post_id;
190
-    }
191
-
192
-    /**
193
-     * @param                  $read_item
194
-     * @param                  $post_id
195
-     * @param  null            $uid
196
-     * @return bool|mixed|void
197
-     */
198
-    public function setRead($read_item, $post_id, $uid = null)
199
-    {
200
-        if (empty($this->mode)) {
201
-            return true;
202
-        }
203
-
204
-        if (1 == $this->mode) {
205
-            return $this->setReadCookie($read_item, $post_id);
206
-        }
207
-
208
-        return $this->setReadDb($read_item, $post_id, $uid);
209
-    }
210
-
211
-    /**
212
-     * @param $read_item
213
-     * @param $post_id
214
-     */
215
-    public function setReadCookie($read_item, $post_id)
216
-    {
217
-        $cookie_name          = ('forum' === $this->type) ? 'LF' : 'LT';
218
-        $lastview             = newbbGetCookie($cookie_name, true);
219
-        $lastview[$read_item] = time();
220
-        newbbSetCookie($cookie_name, $lastview);
221
-    }
222
-
223
-    /**
224
-     * @param $read_item
225
-     * @param $post_id
226
-     * @param $uid
227
-     * @return bool|mixed
228
-     */
229
-    public function setReadDb($read_item, $post_id, $uid)
230
-    {
231
-        if (empty($uid)) {
232
-            if (is_object($GLOBALS['xoopsUser'])) {
233
-                $uid = $GLOBALS['xoopsUser']->getVar('uid');
234
-            } else {
235
-                return false;
236
-            }
237
-        }
238
-
239
-        $sql = 'UPDATE ' . $this->table . ' SET post_id = ' . (int)$post_id . ',' . '     read_time =' . time() . ' WHERE read_item = ' . (int)$read_item . '     AND uid = ' . (int)$uid;
240
-        if ($this->db->queryF($sql) && $this->db->getAffectedRows()) {
241
-            return true;
242
-        }
243
-        $object = $this->create();
244
-        $object->setVar('read_item', $read_item);
245
-        $object->setVar('post_id', $post_id);
246
-        $object->setVar('uid', $uid);
247
-        $object->setVar('read_time', time());
248
-
249
-        return parent::insert($object);
250
-    }
251
-
252
-    /**
253
-     * @param             $items
254
-     * @param  null       $uid
255
-     * @return array|null
256
-     */
257
-    public function isReadItems(&$items, $uid = null)
258
-    {
259
-        $ret = null;
260
-        if (empty($this->mode)) {
261
-            return $ret;
262
-        }
263
-
264
-        if (1 == $this->mode) {
265
-            $ret = $this->isReadItemsCookie($items);
266
-        } else {
267
-            $ret = $this->isReadItemsDb($items, $uid);
268
-        }
269
-
270
-        return $ret;
271
-    }
272
-
273
-    /**
274
-     * @param $items
275
-     * @return array
276
-     */
277
-    public function isReadItemsCookie(&$items)
278
-    {
279
-        $cookie_name = ('forum' === $this->type) ? 'LF' : 'LT';
280
-        $cookie_vars = newbbGetCookie($cookie_name, true);
281
-
282
-        $ret = [];
283
-        foreach ($items as $key => $last_update) {
284
-            $ret[$key] = (max(@$GLOBALS['last_visit'], @$cookie_vars[$key]) >= $last_update);
285
-        }
286
-
287
-        return $ret;
288
-    }
289
-
290
-    /**
291
-     * @param $items
292
-     * @param $uid
293
-     * @return array
294
-     */
295
-    public function isReadItemsDb(&$items, $uid)
296
-    {
297
-        $ret = [];
298
-        if (empty($items)) {
299
-            return $ret;
300
-        }
301
-
302
-        if (empty($uid)) {
303
-            if (is_object($GLOBALS['xoopsUser'])) {
304
-                $uid = $GLOBALS['xoopsUser']->getVar('uid');
305
-            } else {
306
-                return $ret;
307
-            }
308
-        }
309
-
310
-        $criteria = new \CriteriaCompo(new \Criteria('uid', $uid));
311
-        $criteria->add(new \Criteria('read_item', '(' . implode(', ', array_map('intval', array_keys($items))) . ')', 'IN'));
312
-        $itemsObject = $this->getAll($criteria, ['read_item', 'post_id']);
313
-
314
-        $items_list = [];
315
-        foreach (array_keys($itemsObject) as $key) {
316
-            $items_list[$itemsObject[$key]->getVar('read_item')] = $itemsObject[$key]->getVar('post_id');
317
-        }
318
-        unset($itemsObject);
319
-
320
-        foreach ($items as $key => $last_update) {
321
-            $ret[$key] = (@$items_list[$key] >= $last_update);
322
-        }
323
-
324
-        return $ret;
325
-    }
326
-
327
-    // START irmtfan add clear duplicated rows function
328
-
329
-    /**
330
-     * @return bool
331
-     */
332
-    public function clearDuplicate()
333
-    {
334
-        /**
335
-         * This is needed for the following query GROUP BY clauses to work in MySQL 5.7.
336
-         * This is a TEMPORARY fix. Needing this function is bad in the first place, but
337
-         * needing sloppy SQL to make it work is worse.
338
-         * @todo The schema itself should preclude the duplicates
339
-         */
340
-        $sql = "SET sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''))";
341
-        $this->db->queryF($sql);
342
-
343
-        $sql = 'CREATE TABLE ' . $this->table . '_duplicate LIKE ' . $this->table . '; ';
344
-        if (!$result = $this->db->queryF($sql)) {
345
-            xoops_error($this->db->error() . '<br>' . $sql);
346
-
347
-            return false;
348
-        }
349
-        $sql = 'INSERT ' . $this->table . '_duplicate SELECT * FROM ' . $this->table . ' GROUP BY read_item, uid; ';
350
-        if (!$result = $this->db->queryF($sql)) {
351
-            xoops_error($this->db->error() . '<br>' . $sql);
352
-
353
-            return false;
354
-        }
355
-        $sql = 'RENAME TABLE ' . $this->table . ' TO ' . $this->table . '_with_duplicate; ';
356
-        if (!$result = $this->db->queryF($sql)) {
357
-            xoops_error($this->db->error() . '<br>' . $sql);
358
-
359
-            return false;
360
-        }
361
-        $sql = 'RENAME TABLE ' . $this->table . '_duplicate TO ' . $this->table . '; ';
362
-        if (!$result = $this->db->queryF($sql)) {
363
-            xoops_error($this->db->error() . '<br>' . $sql);
364
-
365
-            return false;
366
-        }
367
-        $sql    = 'SHOW INDEX FROM ' . $this->table . " WHERE KEY_NAME = 'read_item_uid'";
368
-        $result = $this->db->queryF($sql);
369
-        if (empty($result)) {
370
-            $sql .= 'ALTER TABLE ' . $this->table . ' ADD INDEX read_item_uid ( read_item, uid ); ';
371
-            if (!$result = $this->db->queryF($sql)) {
372
-                xoops_error($this->db->error() . '<br>' . $sql);
373
-
374
-                return false;
375
-            }
376
-        }
377
-        $sql = 'DROP TABLE ' . $this->table . '_with_duplicate; ';
378
-        if (!$result = $this->db->queryF($sql)) {
379
-            xoops_error($this->db->error() . '<br>' . $sql);
380
-
381
-            return false;
382
-        }
383
-
384
-        return true;
385
-    }
386
-    // END irmtfan add clear duplicated rows function
51
+	/**
52
+	 * Object type.
53
+	 * <ul>
54
+	 *  <li>forum</li>
55
+	 *  <li>topic</li>
56
+	 * </ul>
57
+	 *
58
+	 * @var string
59
+	 */
60
+	public $type;
61
+
62
+	/**
63
+	 * seconds records will persist.
64
+	 * assigned from $GLOBALS['xoopsModuleConfig']["read_expire"]
65
+	 * <ul>
66
+	 *  <li>positive days = delete all read records exist in the tables before expire time // irmtfan add comment</li>
67
+	 *  <li>0 = never expires // irmtfan change comment</li>
68
+	 *  <li>-1 or any negative days = never records // irmtfan change comment</li>
69
+	 * </ul>
70
+	 *
71
+	 * @var integer
72
+	 */
73
+	public $lifetime;
74
+
75
+	/**
76
+	 * storage mode for records.
77
+	 * assigned from $GLOBALS['xoopsModuleConfig']["read_mode"]
78
+	 * <ul>
79
+	 *  <li>0 = never records</li>
80
+	 *  <li>1 = uses cookie</li>
81
+	 *  <li>2 = stores in database</li>
82
+	 * </ul>
83
+	 *
84
+	 * @var integer
85
+	 */
86
+	public $mode;
87
+
88
+	/**
89
+	 * @param \XoopsDatabase     $db
90
+	 * @param                    $type
91
+	 */
92
+	public function __construct(\XoopsDatabase $db, $type)
93
+	{
94
+		$type = ('forum' === $type) ? 'forum' : 'topic';
95
+		parent::__construct($db, 'newbb_reads_' . $type, Read::class . $type, 'read_id', 'post_id');
96
+		$this->type  = $type;
97
+		$newbbConfig = newbbLoadConfig();
98
+		// irmtfan if read_expire = 0 dont clean
99
+		$this->lifetime = isset($newbbConfig['read_expire']) ? (int)$newbbConfig['read_expire'] * 24 * 3600 : 30 * 24 * 3600;
100
+		$this->mode     = isset($newbbConfig['read_mode']) ? $newbbConfig['read_mode'] : 2;
101
+	}
102
+
103
+	/**
104
+	 * Clear garbage
105
+	 *
106
+	 * Delete all expired and duplicated records
107
+	 */
108
+	// START irmtfan rephrase function to 1- add clearDuplicate and 2- dont clean when read_expire = 0
109
+	public function clearGarbage()
110
+	{
111
+		// irmtfan clear duplicaed rows
112
+		if (!$result = $this->clearDuplicate()) {
113
+			return false;
114
+		}
115
+
116
+		$sql = 'DELETE bb FROM ' . $this->table . ' AS bb' . ' LEFT JOIN ' . $this->table . ' AS aa ON bb.read_item = aa.read_item ' . ' WHERE aa.post_id > bb.post_id';
117
+		if (!$result = $this->db->queryF($sql)) {
118
+			//xoops_error($this->db->error());
119
+			return false;
120
+		}
121
+		// irmtfan if read_expire = 0 dont clean
122
+		if (empty($this->lifetime)) {
123
+			return true;
124
+		}
125
+		// irmtfan move here and rephrase
126
+		$expire = time() - (int)$this->lifetime;
127
+		$sql    = 'DELETE FROM ' . $this->table . ' WHERE read_time < ' . $expire;
128
+		if (!$result = $this->db->queryF($sql)) {
129
+			//xoops_error($this->db->error());
130
+			return false;
131
+		}
132
+
133
+		return true;
134
+	}
135
+
136
+	// END irmtfan rephrase function to 1- add clearDuplicate and 2- dont clean when read_expire = 0
137
+
138
+	/**
139
+	 * @param                  $read_item
140
+	 * @param  null            $uid
141
+	 * @return bool|mixed|null
142
+	 */
143
+	public function getRead($read_item, $uid = null)
144
+	{
145
+		if (empty($this->mode)) {
146
+			return null;
147
+		}
148
+		if (1 == $this->mode) {
149
+			return $this->getReadCookie($read_item);
150
+		}
151
+
152
+		return $this->getReadDb($read_item, $uid);
153
+	}
154
+
155
+	/**
156
+	 * @param $item_id
157
+	 * @return mixed
158
+	 */
159
+	public function getReadCookie($item_id)
160
+	{
161
+		$cookie_name = ('forum' === $this->type) ? 'LF' : 'LT';
162
+		$cookie_var  = $item_id;
163
+		// irmtfan set true to return array
164
+		$lastview = newbbGetCookie($cookie_name, true);
165
+
166
+		return @$lastview[$cookie_var];
167
+	}
168
+
169
+	/**
170
+	 * @param $read_item
171
+	 * @param $uid
172
+	 * @return bool|null
173
+	 */
174
+	public function getReadDb($read_item, $uid)
175
+	{
176
+		if (empty($uid)) {
177
+			if (is_object($GLOBALS['xoopsUser'])) {
178
+				$uid = $GLOBALS['xoopsUser']->getVar('uid');
179
+			} else {
180
+				return false;
181
+			}
182
+		}
183
+		$sql = 'SELECT post_id ' . ' FROM ' . $this->table . ' WHERE read_item = ' . (int)$read_item . '     AND uid = ' . (int)$uid;
184
+		if (!$result = $this->db->queryF($sql, 1)) {
185
+			return null;
186
+		}
187
+		list($post_id) = $this->db->fetchRow($result);
188
+
189
+		return $post_id;
190
+	}
191
+
192
+	/**
193
+	 * @param                  $read_item
194
+	 * @param                  $post_id
195
+	 * @param  null            $uid
196
+	 * @return bool|mixed|void
197
+	 */
198
+	public function setRead($read_item, $post_id, $uid = null)
199
+	{
200
+		if (empty($this->mode)) {
201
+			return true;
202
+		}
203
+
204
+		if (1 == $this->mode) {
205
+			return $this->setReadCookie($read_item, $post_id);
206
+		}
207
+
208
+		return $this->setReadDb($read_item, $post_id, $uid);
209
+	}
210
+
211
+	/**
212
+	 * @param $read_item
213
+	 * @param $post_id
214
+	 */
215
+	public function setReadCookie($read_item, $post_id)
216
+	{
217
+		$cookie_name          = ('forum' === $this->type) ? 'LF' : 'LT';
218
+		$lastview             = newbbGetCookie($cookie_name, true);
219
+		$lastview[$read_item] = time();
220
+		newbbSetCookie($cookie_name, $lastview);
221
+	}
222
+
223
+	/**
224
+	 * @param $read_item
225
+	 * @param $post_id
226
+	 * @param $uid
227
+	 * @return bool|mixed
228
+	 */
229
+	public function setReadDb($read_item, $post_id, $uid)
230
+	{
231
+		if (empty($uid)) {
232
+			if (is_object($GLOBALS['xoopsUser'])) {
233
+				$uid = $GLOBALS['xoopsUser']->getVar('uid');
234
+			} else {
235
+				return false;
236
+			}
237
+		}
238
+
239
+		$sql = 'UPDATE ' . $this->table . ' SET post_id = ' . (int)$post_id . ',' . '     read_time =' . time() . ' WHERE read_item = ' . (int)$read_item . '     AND uid = ' . (int)$uid;
240
+		if ($this->db->queryF($sql) && $this->db->getAffectedRows()) {
241
+			return true;
242
+		}
243
+		$object = $this->create();
244
+		$object->setVar('read_item', $read_item);
245
+		$object->setVar('post_id', $post_id);
246
+		$object->setVar('uid', $uid);
247
+		$object->setVar('read_time', time());
248
+
249
+		return parent::insert($object);
250
+	}
251
+
252
+	/**
253
+	 * @param             $items
254
+	 * @param  null       $uid
255
+	 * @return array|null
256
+	 */
257
+	public function isReadItems(&$items, $uid = null)
258
+	{
259
+		$ret = null;
260
+		if (empty($this->mode)) {
261
+			return $ret;
262
+		}
263
+
264
+		if (1 == $this->mode) {
265
+			$ret = $this->isReadItemsCookie($items);
266
+		} else {
267
+			$ret = $this->isReadItemsDb($items, $uid);
268
+		}
269
+
270
+		return $ret;
271
+	}
272
+
273
+	/**
274
+	 * @param $items
275
+	 * @return array
276
+	 */
277
+	public function isReadItemsCookie(&$items)
278
+	{
279
+		$cookie_name = ('forum' === $this->type) ? 'LF' : 'LT';
280
+		$cookie_vars = newbbGetCookie($cookie_name, true);
281
+
282
+		$ret = [];
283
+		foreach ($items as $key => $last_update) {
284
+			$ret[$key] = (max(@$GLOBALS['last_visit'], @$cookie_vars[$key]) >= $last_update);
285
+		}
286
+
287
+		return $ret;
288
+	}
289
+
290
+	/**
291
+	 * @param $items
292
+	 * @param $uid
293
+	 * @return array
294
+	 */
295
+	public function isReadItemsDb(&$items, $uid)
296
+	{
297
+		$ret = [];
298
+		if (empty($items)) {
299
+			return $ret;
300
+		}
301
+
302
+		if (empty($uid)) {
303
+			if (is_object($GLOBALS['xoopsUser'])) {
304
+				$uid = $GLOBALS['xoopsUser']->getVar('uid');
305
+			} else {
306
+				return $ret;
307
+			}
308
+		}
309
+
310
+		$criteria = new \CriteriaCompo(new \Criteria('uid', $uid));
311
+		$criteria->add(new \Criteria('read_item', '(' . implode(', ', array_map('intval', array_keys($items))) . ')', 'IN'));
312
+		$itemsObject = $this->getAll($criteria, ['read_item', 'post_id']);
313
+
314
+		$items_list = [];
315
+		foreach (array_keys($itemsObject) as $key) {
316
+			$items_list[$itemsObject[$key]->getVar('read_item')] = $itemsObject[$key]->getVar('post_id');
317
+		}
318
+		unset($itemsObject);
319
+
320
+		foreach ($items as $key => $last_update) {
321
+			$ret[$key] = (@$items_list[$key] >= $last_update);
322
+		}
323
+
324
+		return $ret;
325
+	}
326
+
327
+	// START irmtfan add clear duplicated rows function
328
+
329
+	/**
330
+	 * @return bool
331
+	 */
332
+	public function clearDuplicate()
333
+	{
334
+		/**
335
+		 * This is needed for the following query GROUP BY clauses to work in MySQL 5.7.
336
+		 * This is a TEMPORARY fix. Needing this function is bad in the first place, but
337
+		 * needing sloppy SQL to make it work is worse.
338
+		 * @todo The schema itself should preclude the duplicates
339
+		 */
340
+		$sql = "SET sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''))";
341
+		$this->db->queryF($sql);
342
+
343
+		$sql = 'CREATE TABLE ' . $this->table . '_duplicate LIKE ' . $this->table . '; ';
344
+		if (!$result = $this->db->queryF($sql)) {
345
+			xoops_error($this->db->error() . '<br>' . $sql);
346
+
347
+			return false;
348
+		}
349
+		$sql = 'INSERT ' . $this->table . '_duplicate SELECT * FROM ' . $this->table . ' GROUP BY read_item, uid; ';
350
+		if (!$result = $this->db->queryF($sql)) {
351
+			xoops_error($this->db->error() . '<br>' . $sql);
352
+
353
+			return false;
354
+		}
355
+		$sql = 'RENAME TABLE ' . $this->table . ' TO ' . $this->table . '_with_duplicate; ';
356
+		if (!$result = $this->db->queryF($sql)) {
357
+			xoops_error($this->db->error() . '<br>' . $sql);
358
+
359
+			return false;
360
+		}
361
+		$sql = 'RENAME TABLE ' . $this->table . '_duplicate TO ' . $this->table . '; ';
362
+		if (!$result = $this->db->queryF($sql)) {
363
+			xoops_error($this->db->error() . '<br>' . $sql);
364
+
365
+			return false;
366
+		}
367
+		$sql    = 'SHOW INDEX FROM ' . $this->table . " WHERE KEY_NAME = 'read_item_uid'";
368
+		$result = $this->db->queryF($sql);
369
+		if (empty($result)) {
370
+			$sql .= 'ALTER TABLE ' . $this->table . ' ADD INDEX read_item_uid ( read_item, uid ); ';
371
+			if (!$result = $this->db->queryF($sql)) {
372
+				xoops_error($this->db->error() . '<br>' . $sql);
373
+
374
+				return false;
375
+			}
376
+		}
377
+		$sql = 'DROP TABLE ' . $this->table . '_with_duplicate; ';
378
+		if (!$result = $this->db->queryF($sql)) {
379
+			xoops_error($this->db->error() . '<br>' . $sql);
380
+
381
+			return false;
382
+		}
383
+
384
+		return true;
385
+	}
386
+	// END irmtfan add clear duplicated rows function
387 387
 }
Please login to merge, or discard this patch.
class/Xmlrss.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     {
86 86
         if (count($this->items) < $this->max_items) {
87 87
             if (!empty($label)) {
88
-                $label = '[' . $this->cleanup($label) . ']';
88
+                $label = '['.$this->cleanup($label).']';
89 89
             }
90 90
             if (!empty($description)) {
91 91
                 $description = $this->cleanup($description, $this->max_item_description);
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
                 //$description = $label;
95 95
             }
96 96
 
97
-            $title         = $this->cleanup($title) . ' ' . $label;
97
+            $title         = $this->cleanup($title).' '.$label;
98 98
             $pubdate       = $this->cleanup($pubdate);
99 99
             $this->items[] = [
100 100
                 'title'       => $title,
Please login to merge, or discard this patch.
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -24,105 +24,105 @@
 block discarded – undo
24 24
  */
25 25
 class Xmlrss
26 26
 {
27
-    public $xml_version;
28
-    public $rss_version;
29
-    public $xml_encoding;
27
+	public $xml_version;
28
+	public $rss_version;
29
+	public $xml_encoding;
30 30
 
31
-    public $channel_title;
32
-    public $channel_link;
33
-    public $channel_desc;
34
-    public $channel_lastbuild;
35
-    public $channel_webmaster;
36
-    public $channel_editor;
37
-    public $channel_category;
38
-    public $channel_generator;
39
-    public $channel_language;
31
+	public $channel_title;
32
+	public $channel_link;
33
+	public $channel_desc;
34
+	public $channel_lastbuild;
35
+	public $channel_webmaster;
36
+	public $channel_editor;
37
+	public $channel_category;
38
+	public $channel_generator;
39
+	public $channel_language;
40 40
 
41
-    public $image_title;
42
-    public $image_url;
43
-    public $image_link;
44
-    public $image_description;
45
-    public $image_height;
46
-    public $image_width;
41
+	public $image_title;
42
+	public $image_url;
43
+	public $image_link;
44
+	public $image_description;
45
+	public $image_height;
46
+	public $image_width;
47 47
 
48
-    public $max_items;
49
-    public $max_item_description;
50
-    public $items = [];
48
+	public $max_items;
49
+	public $max_item_description;
50
+	public $items = [];
51 51
 
52
-    /**
53
-     *
54
-     */
55
-    public function __construct()
56
-    {
57
-        $this->xml_version          = '1.0';
58
-        $this->xml_encoding         = empty($GLOBALS['xoopsModuleConfig']['rss_utf8']) ? _CHARSET : 'UTF-8';
59
-        $this->rss_version          = '2.0';
60
-        $this->image_height         = 31;
61
-        $this->image_width          = 88;
62
-        $this->max_items            = 10;
63
-        $this->max_item_description = 0;
64
-        $this->items                = [];
65
-    }
52
+	/**
53
+	 *
54
+	 */
55
+	public function __construct()
56
+	{
57
+		$this->xml_version          = '1.0';
58
+		$this->xml_encoding         = empty($GLOBALS['xoopsModuleConfig']['rss_utf8']) ? _CHARSET : 'UTF-8';
59
+		$this->rss_version          = '2.0';
60
+		$this->image_height         = 31;
61
+		$this->image_width          = 88;
62
+		$this->max_items            = 10;
63
+		$this->max_item_description = 0;
64
+		$this->items                = [];
65
+	}
66 66
 
67
-    /**
68
-     * @param $var
69
-     * @param $val
70
-     */
71
-    public function setVarRss($var, $val)
72
-    {
73
-        $this->$var = $this->cleanup($val);
74
-    }
67
+	/**
68
+	 * @param $var
69
+	 * @param $val
70
+	 */
71
+	public function setVarRss($var, $val)
72
+	{
73
+		$this->$var = $this->cleanup($val);
74
+	}
75 75
 
76
-    /**
77
-     * @param         $title
78
-     * @param         $link
79
-     * @param  string $description
80
-     * @param  string $label
81
-     * @param  int|string    $pubdate
82
-     * @return bool
83
-     */
84
-    public function addItem($title, $link, $description = '', $label = '', $pubdate = 0)
85
-    {
86
-        if (count($this->items) < $this->max_items) {
87
-            if (!empty($label)) {
88
-                $label = '[' . $this->cleanup($label) . ']';
89
-            }
90
-            if (!empty($description)) {
91
-                $description = $this->cleanup($description, $this->max_item_description);
92
-            //$description .= ' ' . $label;
93
-            } else {
94
-                //$description = $label;
95
-            }
76
+	/**
77
+	 * @param         $title
78
+	 * @param         $link
79
+	 * @param  string $description
80
+	 * @param  string $label
81
+	 * @param  int|string    $pubdate
82
+	 * @return bool
83
+	 */
84
+	public function addItem($title, $link, $description = '', $label = '', $pubdate = 0)
85
+	{
86
+		if (count($this->items) < $this->max_items) {
87
+			if (!empty($label)) {
88
+				$label = '[' . $this->cleanup($label) . ']';
89
+			}
90
+			if (!empty($description)) {
91
+				$description = $this->cleanup($description, $this->max_item_description);
92
+			//$description .= ' ' . $label;
93
+			} else {
94
+				//$description = $label;
95
+			}
96 96
 
97
-            $title         = $this->cleanup($title) . ' ' . $label;
98
-            $pubdate       = $this->cleanup($pubdate);
99
-            $this->items[] = [
100
-                'title'       => $title,
101
-                'link'        => $link,
102
-                'guid'        => $link,
103
-                'description' => $description,
104
-                'pubdate'     => $pubdate
105
-            ];
106
-        }
97
+			$title         = $this->cleanup($title) . ' ' . $label;
98
+			$pubdate       = $this->cleanup($pubdate);
99
+			$this->items[] = [
100
+				'title'       => $title,
101
+				'link'        => $link,
102
+				'guid'        => $link,
103
+				'description' => $description,
104
+				'pubdate'     => $pubdate
105
+			];
106
+		}
107 107
 
108
-        return true;
109
-    }
108
+		return true;
109
+	}
110 110
 
111
-    /**
112
-     * @param               $text
113
-     * @param  int          $trim
114
-     * @return mixed|string
115
-     */
116
-    public function cleanup($text, $trim = 0)
117
-    {
118
-        if ('utf-8' === strtolower($this->xml_encoding) && strncasecmp(_CHARSET, $this->xml_encoding, 5)) {
119
-            $text = \XoopsLocal::convert_encoding($text, 'utf-8');
120
-        }
121
-        if (!empty($trim)) {
122
-            $text = xoops_substr($text, 0, (int)$trim);
123
-        }
124
-        $text = htmlspecialchars($text, ENT_QUOTES);
111
+	/**
112
+	 * @param               $text
113
+	 * @param  int          $trim
114
+	 * @return mixed|string
115
+	 */
116
+	public function cleanup($text, $trim = 0)
117
+	{
118
+		if ('utf-8' === strtolower($this->xml_encoding) && strncasecmp(_CHARSET, $this->xml_encoding, 5)) {
119
+			$text = \XoopsLocal::convert_encoding($text, 'utf-8');
120
+		}
121
+		if (!empty($trim)) {
122
+			$text = xoops_substr($text, 0, (int)$trim);
123
+		}
124
+		$text = htmlspecialchars($text, ENT_QUOTES);
125 125
 
126
-        return $text;
127
-    }
126
+		return $text;
127
+	}
128 128
 }
Please login to merge, or discard this patch.
class/Tree.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@
 block discarded – undo
93 93
         }
94 94
 
95 95
         $newPostArray = [];
96
-        $prefix       .= $this->increment;
96
+        $prefix .= $this->increment;
97 97
         foreach ($this->postArray as $post) {
98 98
             if ($post->getVar('pid') == $pid) {
99 99
                 $postTree_array[] = [
Please login to merge, or discard this patch.
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -38,87 +38,87 @@
 block discarded – undo
38 38
  */
39 39
 class Tree extends \XoopsTree
40 40
 {
41
-    /** @var string */
42
-    private $prefix = '&nbsp;&nbsp;';
41
+	/** @var string */
42
+	private $prefix = '&nbsp;&nbsp;';
43 43
 
44
-    /** @var string */
45
-    private $increment = '&nbsp;&nbsp;';
44
+	/** @var string */
45
+	private $increment = '&nbsp;&nbsp;';
46 46
 
47
-    /** @var array */
48
-    private $postArray = [];
47
+	/** @var array */
48
+	private $postArray = [];
49 49
 
50
-    /**
51
-     * @param string $table_name
52
-     * @param string $id_name
53
-     * @param string $pid_name
54
-     */
55
-    public function __construct($table_name, $id_name = 'post_id', $pid_name = 'pid')
56
-    {
57
-        parent::__construct($table_name, $id_name, $pid_name);
58
-    }
50
+	/**
51
+	 * @param string $table_name
52
+	 * @param string $id_name
53
+	 * @param string $pid_name
54
+	 */
55
+	public function __construct($table_name, $id_name = 'post_id', $pid_name = 'pid')
56
+	{
57
+		parent::__construct($table_name, $id_name, $pid_name);
58
+	}
59 59
 
60
-    /**
61
-     * @param string $val
62
-     */
63
-    public function setPrefix($val = '')
64
-    {
65
-        $this->prefix    = $val;
66
-        $this->increment = $val;
67
-    }
60
+	/**
61
+	 * @param string $val
62
+	 */
63
+	public function setPrefix($val = '')
64
+	{
65
+		$this->prefix    = $val;
66
+		$this->increment = $val;
67
+	}
68 68
 
69
-    /**
70
-     * @param        $sel_id
71
-     * @param string $order
72
-     */
73
-    public function getAllPostArray($sel_id, $order = '')
74
-    {
75
-        $this->postArray = $this->getAllChild($sel_id, $order);
76
-    }
69
+	/**
70
+	 * @param        $sel_id
71
+	 * @param string $order
72
+	 */
73
+	public function getAllPostArray($sel_id, $order = '')
74
+	{
75
+		$this->postArray = $this->getAllChild($sel_id, $order);
76
+	}
77 77
 
78
-    /**
79
-     * @param $postArray
80
-     */
81
-    public function setPostArray($postArray)
82
-    {
83
-        $this->postArray = $postArray;
84
-    }
78
+	/**
79
+	 * @param $postArray
80
+	 */
81
+	public function setPostArray($postArray)
82
+	{
83
+		$this->postArray = $postArray;
84
+	}
85 85
 
86
-    // returns an array of first child objects for a given id($sel_id)
86
+	// returns an array of first child objects for a given id($sel_id)
87 87
 
88
-    /**
89
-     * @param         $postTree_array
90
-     * @param  int    $pid
91
-     * @param  string $prefix
92
-     * @return bool
93
-     */
94
-    public function getPostTree(&$postTree_array, $pid = 0, $prefix = '&nbsp;&nbsp;')
95
-    {
96
-        if (!is_array($postTree_array)) {
97
-            $postTree_array = [];
98
-        }
88
+	/**
89
+	 * @param         $postTree_array
90
+	 * @param  int    $pid
91
+	 * @param  string $prefix
92
+	 * @return bool
93
+	 */
94
+	public function getPostTree(&$postTree_array, $pid = 0, $prefix = '&nbsp;&nbsp;')
95
+	{
96
+		if (!is_array($postTree_array)) {
97
+			$postTree_array = [];
98
+		}
99 99
 
100
-        $newPostArray = [];
101
-        $prefix       .= $this->increment;
102
-        foreach ($this->postArray as $post) {
103
-            if ($post->getVar('pid') == $pid) {
104
-                $postTree_array[] = [
105
-                    'prefix'      => $prefix,
106
-                    'icon'        => $post->getVar('icon'),
107
-                    'post_time'   => $post->getVar('post_time'),
108
-                    'post_id'     => $post->getVar('post_id'),
109
-                    'forum_id'    => $post->getVar('forum_id'),
110
-                    'subject'     => $post->getVar('subject'),
111
-                    'poster_name' => $post->getVar('poster_name'),
112
-                    'uid'         => $post->getVar('uid')
113
-                ];
114
-                $this->getPostTree($postTree_array, $post->getVar('post_id'), $prefix);
115
-            } else {
116
-                $newPostArray[] = $post;
117
-            }
118
-        }
119
-        $this->postArray = $newPostArray;
120
-        unset($newPostArray);
100
+		$newPostArray = [];
101
+		$prefix       .= $this->increment;
102
+		foreach ($this->postArray as $post) {
103
+			if ($post->getVar('pid') == $pid) {
104
+				$postTree_array[] = [
105
+					'prefix'      => $prefix,
106
+					'icon'        => $post->getVar('icon'),
107
+					'post_time'   => $post->getVar('post_time'),
108
+					'post_id'     => $post->getVar('post_id'),
109
+					'forum_id'    => $post->getVar('forum_id'),
110
+					'subject'     => $post->getVar('subject'),
111
+					'poster_name' => $post->getVar('poster_name'),
112
+					'uid'         => $post->getVar('uid')
113
+				];
114
+				$this->getPostTree($postTree_array, $post->getVar('post_id'), $prefix);
115
+			} else {
116
+				$newPostArray[] = $post;
117
+			}
118
+		}
119
+		$this->postArray = $newPostArray;
120
+		unset($newPostArray);
121 121
 
122
-        return true;
123
-    }
122
+		return true;
123
+	}
124 124
 }
Please login to merge, or discard this patch.
class/ModerateHandler.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
     {
113 113
         $ips = [];
114 114
         if ($isUid) {
115
-            $criteria = 'uid =' . (int)$item;
115
+            $criteria = 'uid ='.(int)$item;
116 116
         } else {
117 117
             $ip_segs = explode('.', $item);
118 118
             $segs    = min(count($ip_segs), 4);
119 119
             for ($i = 1; $i <= $segs; ++$i) {
120 120
                 $ips[] = $this->db->quoteString(implode('.', array_slice($ip_segs, 0, $i)));
121 121
             }
122
-            $criteria = 'ip IN(' . implode(',', $ips) . ')';
122
+            $criteria = 'ip IN('.implode(',', $ips).')';
123 123
         }
124
-        $sql = 'SELECT MAX(mod_end) AS expire FROM ' . $this->db->prefix('newbb_moderates') . ' WHERE ' . $criteria;
124
+        $sql = 'SELECT MAX(mod_end) AS expire FROM '.$this->db->prefix('newbb_moderates').' WHERE '.$criteria;
125 125
         if (!$result = $this->db->query($sql)) {
126 126
             return -1;
127 127
         }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
142 142
     {
143
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE (forum_id >0 AND forum_id NOT IN ( SELECT DISTINCT forum_id FROM ' . $this->db->prefix('newbb_forums') . ') )';
143
+        $sql = 'DELETE FROM '.$this->table.' WHERE (forum_id >0 AND forum_id NOT IN ( SELECT DISTINCT forum_id FROM '.$this->db->prefix('newbb_forums').') )';
144 144
         if (!$result = $this->db->queryF($sql)) {
145 145
             //xoops_error($this->db->error());
146 146
             return false;
Please login to merge, or discard this patch.
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -19,133 +19,133 @@
 block discarded – undo
19 19
  */
20 20
 class ModerateHandler extends \XoopsPersistableObjectHandler
21 21
 {
22
-    /**
23
-     * @param null|\XoopsDatabase $db
24
-     */
25
-    public function __construct(\XoopsDatabase $db = null)
26
-    {
27
-        parent::__construct($db, 'newbb_moderates', Moderate::class, 'mod_id', 'uid');
28
-    }
29
-
30
-    /**
31
-     * Clear garbage
32
-     *
33
-     * Delete all moderation information that has expired
34
-     *
35
-     * @param int $expire Expiration time in UNIX, 0 for time()
36
-     */
37
-    public function clearGarbage($expire = 0)
38
-    {
39
-        $expire = time() - (int)$expire;
40
-        $sql    = sprintf('DELETE FROM `%s` WHERE mod_end < %u', $this->db->prefix('newbb_moderates'), $expire);
41
-        $this->db->queryF($sql);
42
-    }
43
-
44
-    /**
45
-     * Check if a user is moderated, according to his uid and ip
46
-     *
47
-     *
48
-     * @param  int    $uid user id
49
-     * @param  string|bool $ip  user ip
50
-     * @param  int    $forum
51
-     * @return bool true if IP is banned
52
-     */
53
-    public function verifyUser($uid = -1, $ip = '', $forum = 0)
54
-    {
55
-        error_reporting(E_ALL);
56
-        // if user is admin do not suspend
57
-        if (newbbIsAdmin($forum)) {
58
-            return true;
59
-        }
60
-
61
-        $uid = ($uid < 0) ? (is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0) : (int)$uid;
62
-
63
-        $criteria      = new \CriteriaCompo(new \Criteria('uid', (int)$uid));
64
-        $forumCriteria = new \CriteriaCompo(new \Criteria('forum_id', 0), 'OR');
65
-        if (!empty($forum)) {
66
-            $forumCriteria->add(new \Criteria('forum_id', (int)$forum), 'OR');
67
-        }
68
-        $criteria->add($forumCriteria);
69
-        $criteria->add(new \Criteria('mod_end', time(), '>'));
70
-
71
-        $matches = $this->getAll($criteria);
72
-
73
-        if (0 === count($matches)) {
74
-            return true; // no matches
75
-        }
76
-
77
-        if (count($matches) > 0 && $uid > 0) {
78
-            return false; // user is banned
79
-        }
80
-        // verify possible matches against IP address
81
-        $ip = empty($ip) ? IPAddress::fromRequest()->asReadable() : $ip;
82
-
83
-        foreach ($matches as $modMatch) {
84
-            $rawModIp = trim($modMatch->getVar('ip', 'n'));
85
-            if (empty($rawModIp)) {
86
-                return false; // banned without IP
87
-            }
88
-            $parts   = explode('/', $rawModIp);
89
-            $modIp   = $parts[0];
90
-            $checkIp = new IPAddress($modIp);
91
-            if (false !== $checkIp->asReadable()) {
92
-                $defaultMask = (6 === $checkIp->ipVersion()) ? 128 : 32;
93
-                $netMask     = isset($parts[1]) ? (int)$parts[1] : $defaultMask;
94
-                if ($checkIp->sameSubnet($ip, $netMask, $netMask)) {
95
-                    return false; // IP is banned
96
-                }
97
-            }
98
-        }
99
-
100
-        return true;
101
-    }
102
-
103
-    /**
104
-     * Get latest expiration for a user moderation
105
-     *
106
-     *
107
-     * @param  mixed  $item user id or ip
108
-     * @param  bool $isUid
109
-     * @return int
110
-     */
111
-    public function getLatest($item, $isUid = true)
112
-    {
113
-        $ips = [];
114
-        if ($isUid) {
115
-            $criteria = 'uid =' . (int)$item;
116
-        } else {
117
-            $ip_segs = explode('.', $item);
118
-            $segs    = min(count($ip_segs), 4);
119
-            for ($i = 1; $i <= $segs; ++$i) {
120
-                $ips[] = $this->db->quoteString(implode('.', array_slice($ip_segs, 0, $i)));
121
-            }
122
-            $criteria = 'ip IN(' . implode(',', $ips) . ')';
123
-        }
124
-        $sql = 'SELECT MAX(mod_end) AS expire FROM ' . $this->db->prefix('newbb_moderates') . ' WHERE ' . $criteria;
125
-        if (!$result = $this->db->query($sql)) {
126
-            return -1;
127
-        }
128
-        $row = $this->db->fetchArray($result);
129
-
130
-        return $row['expire'];
131
-    }
132
-
133
-    /**
134
-     * clean orphan items from database
135
-     *
136
-     * @param  string $table_link
137
-     * @param  string $field_link
138
-     * @param  string $field_object
139
-     * @return bool   true on success
140
-     */
141
-    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
142
-    {
143
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE (forum_id >0 AND forum_id NOT IN ( SELECT DISTINCT forum_id FROM ' . $this->db->prefix('newbb_forums') . ') )';
144
-        if (!$result = $this->db->queryF($sql)) {
145
-            //xoops_error($this->db->error());
146
-            return false;
147
-        }
148
-
149
-        return true;
150
-    }
22
+	/**
23
+	 * @param null|\XoopsDatabase $db
24
+	 */
25
+	public function __construct(\XoopsDatabase $db = null)
26
+	{
27
+		parent::__construct($db, 'newbb_moderates', Moderate::class, 'mod_id', 'uid');
28
+	}
29
+
30
+	/**
31
+	 * Clear garbage
32
+	 *
33
+	 * Delete all moderation information that has expired
34
+	 *
35
+	 * @param int $expire Expiration time in UNIX, 0 for time()
36
+	 */
37
+	public function clearGarbage($expire = 0)
38
+	{
39
+		$expire = time() - (int)$expire;
40
+		$sql    = sprintf('DELETE FROM `%s` WHERE mod_end < %u', $this->db->prefix('newbb_moderates'), $expire);
41
+		$this->db->queryF($sql);
42
+	}
43
+
44
+	/**
45
+	 * Check if a user is moderated, according to his uid and ip
46
+	 *
47
+	 *
48
+	 * @param  int    $uid user id
49
+	 * @param  string|bool $ip  user ip
50
+	 * @param  int    $forum
51
+	 * @return bool true if IP is banned
52
+	 */
53
+	public function verifyUser($uid = -1, $ip = '', $forum = 0)
54
+	{
55
+		error_reporting(E_ALL);
56
+		// if user is admin do not suspend
57
+		if (newbbIsAdmin($forum)) {
58
+			return true;
59
+		}
60
+
61
+		$uid = ($uid < 0) ? (is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0) : (int)$uid;
62
+
63
+		$criteria      = new \CriteriaCompo(new \Criteria('uid', (int)$uid));
64
+		$forumCriteria = new \CriteriaCompo(new \Criteria('forum_id', 0), 'OR');
65
+		if (!empty($forum)) {
66
+			$forumCriteria->add(new \Criteria('forum_id', (int)$forum), 'OR');
67
+		}
68
+		$criteria->add($forumCriteria);
69
+		$criteria->add(new \Criteria('mod_end', time(), '>'));
70
+
71
+		$matches = $this->getAll($criteria);
72
+
73
+		if (0 === count($matches)) {
74
+			return true; // no matches
75
+		}
76
+
77
+		if (count($matches) > 0 && $uid > 0) {
78
+			return false; // user is banned
79
+		}
80
+		// verify possible matches against IP address
81
+		$ip = empty($ip) ? IPAddress::fromRequest()->asReadable() : $ip;
82
+
83
+		foreach ($matches as $modMatch) {
84
+			$rawModIp = trim($modMatch->getVar('ip', 'n'));
85
+			if (empty($rawModIp)) {
86
+				return false; // banned without IP
87
+			}
88
+			$parts   = explode('/', $rawModIp);
89
+			$modIp   = $parts[0];
90
+			$checkIp = new IPAddress($modIp);
91
+			if (false !== $checkIp->asReadable()) {
92
+				$defaultMask = (6 === $checkIp->ipVersion()) ? 128 : 32;
93
+				$netMask     = isset($parts[1]) ? (int)$parts[1] : $defaultMask;
94
+				if ($checkIp->sameSubnet($ip, $netMask, $netMask)) {
95
+					return false; // IP is banned
96
+				}
97
+			}
98
+		}
99
+
100
+		return true;
101
+	}
102
+
103
+	/**
104
+	 * Get latest expiration for a user moderation
105
+	 *
106
+	 *
107
+	 * @param  mixed  $item user id or ip
108
+	 * @param  bool $isUid
109
+	 * @return int
110
+	 */
111
+	public function getLatest($item, $isUid = true)
112
+	{
113
+		$ips = [];
114
+		if ($isUid) {
115
+			$criteria = 'uid =' . (int)$item;
116
+		} else {
117
+			$ip_segs = explode('.', $item);
118
+			$segs    = min(count($ip_segs), 4);
119
+			for ($i = 1; $i <= $segs; ++$i) {
120
+				$ips[] = $this->db->quoteString(implode('.', array_slice($ip_segs, 0, $i)));
121
+			}
122
+			$criteria = 'ip IN(' . implode(',', $ips) . ')';
123
+		}
124
+		$sql = 'SELECT MAX(mod_end) AS expire FROM ' . $this->db->prefix('newbb_moderates') . ' WHERE ' . $criteria;
125
+		if (!$result = $this->db->query($sql)) {
126
+			return -1;
127
+		}
128
+		$row = $this->db->fetchArray($result);
129
+
130
+		return $row['expire'];
131
+	}
132
+
133
+	/**
134
+	 * clean orphan items from database
135
+	 *
136
+	 * @param  string $table_link
137
+	 * @param  string $field_link
138
+	 * @param  string $field_object
139
+	 * @return bool   true on success
140
+	 */
141
+	public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
142
+	{
143
+		$sql = 'DELETE FROM ' . $this->table . ' WHERE (forum_id >0 AND forum_id NOT IN ( SELECT DISTINCT forum_id FROM ' . $this->db->prefix('newbb_forums') . ') )';
144
+		if (!$result = $this->db->queryF($sql)) {
145
+			//xoops_error($this->db->error());
146
+			return false;
147
+		}
148
+
149
+		return true;
150
+	}
151 151
 }
Please login to merge, or discard this patch.
class/ObjectTree.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
                     $ret[$key]['forum_name'] = $this->tree[$key]['obj']->getVar('forum_name');
69 69
                 }
70 70
                 $ret[$key]['prefix'] = $prefix_curr;
71
-                $prefix_curr         .= $prefix_orig;
71
+                $prefix_curr .= $prefix_orig;
72 72
             }
73 73
             if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
74 74
                 foreach ($this->tree[$key]['child'] as $childkey) {
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
             $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
127 127
             trigger_error("makeSelBox() is deprecated since 2.5.9, please use makeSelectElement(), accessed from {$trace[0]['file']} line {$trace[0]['line']},");
128 128
 
129
-            $ret = '<select name=' . $name . '>';
129
+            $ret = '<select name='.$name.'>';
130 130
             if (!empty($addEmptyOption)) {
131
-                $ret .= '<option value="0">' . (is_string($EmptyOption) ? $EmptyOption : '') . '</option>';
131
+                $ret .= '<option value="0">'.(is_string($EmptyOption) ? $EmptyOption : '').'</option>';
132 132
             }
133 133
             $this->_makeSelBoxOptions('forum_name', $selected, $key, $ret, $prefix);
134 134
             $ret .= '</select>';
Please login to merge, or discard this patch.
Indentation   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -30,208 +30,208 @@  discard block
 block discarded – undo
30 30
 require_once $GLOBALS['xoops']->path('class/tree.php');
31 31
 
32 32
 if (!class_exists('ObjectTree')) {
33
-    /**
34
-     * Class ObjectTree
35
-     */
36
-    class ObjectTree extends \XoopsObjectTree
37
-    {
38
-        /**
39
-         * @param      $objectArr
40
-         * @param null $rootId
41
-         */
42
-        public function __construct(&$objectArr, $rootId = null)
43
-        {
44
-            parent::__construct($objectArr, 'forum_id', 'parent_forum', $rootId);
45
-        }
33
+	/**
34
+	 * Class ObjectTree
35
+	 */
36
+	class ObjectTree extends \XoopsObjectTree
37
+	{
38
+		/**
39
+		 * @param      $objectArr
40
+		 * @param null $rootId
41
+		 */
42
+		public function __construct(&$objectArr, $rootId = null)
43
+		{
44
+			parent::__construct($objectArr, 'forum_id', 'parent_forum', $rootId);
45
+		}
46 46
 
47
-        /**
48
-         * Make options for a select box from
49
-         *
50
-         * @param int        $key         ID of the object to display as the root of select options
51
-         * @param string     $ret         (reference to a string when called from outside) Result from previous recursions
52
-         * @param string     $prefix_orig String to indent items at deeper levels
53
-         * @param string     $prefix_curr String to indent the current item
54
-         * @param null|array $tags
55
-         * @internal  param string $fieldName Name of the member variable from the
56
-         *                                node objects that should be used as the title for the options.
57
-         * @internal  param string $selected Value to display as selected
58
-         * @access    private
59
-         */
60
-        protected function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
61
-        {
62
-            if ($key > 0) {
63
-                if (count($tags) > 0) {
64
-                    foreach ($tags as $tag) {
65
-                        $ret[$key][$tag] = $this->tree[$key]['obj']->getVar($tag);
66
-                    }
67
-                } else {
68
-                    $ret[$key]['forum_name'] = $this->tree[$key]['obj']->getVar('forum_name');
69
-                }
70
-                $ret[$key]['prefix'] = $prefix_curr;
71
-                $prefix_curr         .= $prefix_orig;
72
-            }
73
-            if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
74
-                foreach ($this->tree[$key]['child'] as $childkey) {
75
-                    $this->makeTreeItems($childkey, $ret, $prefix_orig, $prefix_curr, $tags);
76
-                }
77
-            }
78
-        }
47
+		/**
48
+		 * Make options for a select box from
49
+		 *
50
+		 * @param int        $key         ID of the object to display as the root of select options
51
+		 * @param string     $ret         (reference to a string when called from outside) Result from previous recursions
52
+		 * @param string     $prefix_orig String to indent items at deeper levels
53
+		 * @param string     $prefix_curr String to indent the current item
54
+		 * @param null|array $tags
55
+		 * @internal  param string $fieldName Name of the member variable from the
56
+		 *                                node objects that should be used as the title for the options.
57
+		 * @internal  param string $selected Value to display as selected
58
+		 * @access    private
59
+		 */
60
+		protected function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
61
+		{
62
+			if ($key > 0) {
63
+				if (count($tags) > 0) {
64
+					foreach ($tags as $tag) {
65
+						$ret[$key][$tag] = $this->tree[$key]['obj']->getVar($tag);
66
+					}
67
+				} else {
68
+					$ret[$key]['forum_name'] = $this->tree[$key]['obj']->getVar('forum_name');
69
+				}
70
+				$ret[$key]['prefix'] = $prefix_curr;
71
+				$prefix_curr         .= $prefix_orig;
72
+			}
73
+			if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
74
+				foreach ($this->tree[$key]['child'] as $childkey) {
75
+					$this->makeTreeItems($childkey, $ret, $prefix_orig, $prefix_curr, $tags);
76
+				}
77
+			}
78
+		}
79 79
 
80
-        /**
81
-         * Make a select box with options from the tree
82
-         *
83
-         * @param  string  $prefix         String to indent deeper levels
84
-         * @param  integer $key            ID of the object to display as the root of select options
85
-         * @param  null    $tags
86
-         * @return array|string  HTML select box
87
-         * @internal param string $name Name of the select box
88
-         * @internal param string $fieldName Name of the member variable from the
89
-         *                                 node objects that should be used as the title for the options.
90
-         * @internal param string $selected Value to display as selected
91
-         * @internal param bool $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy
92
-         */
93
-        public function &makeTree($prefix = '-', $key = 0, $tags = null)
94
-        {
95
-            $ret = [];
96
-            $this->makeTreeItems($key, $ret, $prefix, '', $tags);
80
+		/**
81
+		 * Make a select box with options from the tree
82
+		 *
83
+		 * @param  string  $prefix         String to indent deeper levels
84
+		 * @param  integer $key            ID of the object to display as the root of select options
85
+		 * @param  null    $tags
86
+		 * @return array|string  HTML select box
87
+		 * @internal param string $name Name of the select box
88
+		 * @internal param string $fieldName Name of the member variable from the
89
+		 *                                 node objects that should be used as the title for the options.
90
+		 * @internal param string $selected Value to display as selected
91
+		 * @internal param bool $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy
92
+		 */
93
+		public function &makeTree($prefix = '-', $key = 0, $tags = null)
94
+		{
95
+			$ret = [];
96
+			$this->makeTreeItems($key, $ret, $prefix, '', $tags);
97 97
 
98
-            return $ret;
99
-        }
98
+			return $ret;
99
+		}
100 100
 
101
-        /**
102
-         * Make a select box with options from the tree
103
-         *
104
-         * @param  string  $name           Name of the select box
105
-         * @param  string  $fieldName      Name of the member variable from the
106
-         *                                 node objects that should be used as the title for the options.
107
-         * @param  string  $prefix         String to indent deeper levels
108
-         * @param  string  $selected       Value to display as selected
109
-         * @param  bool    $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy
110
-         * @param  integer $key            ID of the object to display as the root of select options
111
-         * @param  string  $extra
112
-         * @return string  HTML select box
113
-         *
114
-         * @deprecated since 2.5.9, please use makeSelectElement()
115
-         */
116
-        public function makeSelBox(
117
-            $name,
118
-            $fieldName,
119
-            $prefix = '-',
120
-            $selected = '',
121
-            $addEmptyOption = false,
122
-            $key = 0,
123
-            $extra = ''
124
-        ) //makeSelBox($name, $prefix = '-', $selected = '', $EmptyOption = false, $key = 0)
125
-        {
126
-            $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
127
-            trigger_error("makeSelBox() is deprecated since 2.5.9, please use makeSelectElement(), accessed from {$trace[0]['file']} line {$trace[0]['line']},");
101
+		/**
102
+		 * Make a select box with options from the tree
103
+		 *
104
+		 * @param  string  $name           Name of the select box
105
+		 * @param  string  $fieldName      Name of the member variable from the
106
+		 *                                 node objects that should be used as the title for the options.
107
+		 * @param  string  $prefix         String to indent deeper levels
108
+		 * @param  string  $selected       Value to display as selected
109
+		 * @param  bool    $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy
110
+		 * @param  integer $key            ID of the object to display as the root of select options
111
+		 * @param  string  $extra
112
+		 * @return string  HTML select box
113
+		 *
114
+		 * @deprecated since 2.5.9, please use makeSelectElement()
115
+		 */
116
+		public function makeSelBox(
117
+			$name,
118
+			$fieldName,
119
+			$prefix = '-',
120
+			$selected = '',
121
+			$addEmptyOption = false,
122
+			$key = 0,
123
+			$extra = ''
124
+		) //makeSelBox($name, $prefix = '-', $selected = '', $EmptyOption = false, $key = 0)
125
+		{
126
+			$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
127
+			trigger_error("makeSelBox() is deprecated since 2.5.9, please use makeSelectElement(), accessed from {$trace[0]['file']} line {$trace[0]['line']},");
128 128
 
129
-            $ret = '<select name=' . $name . '>';
130
-            if (!empty($addEmptyOption)) {
131
-                $ret .= '<option value="0">' . (is_string($EmptyOption) ? $EmptyOption : '') . '</option>';
132
-            }
133
-            $this->_makeSelBoxOptions('forum_name', $selected, $key, $ret, $prefix);
134
-            $ret .= '</select>';
129
+			$ret = '<select name=' . $name . '>';
130
+			if (!empty($addEmptyOption)) {
131
+				$ret .= '<option value="0">' . (is_string($EmptyOption) ? $EmptyOption : '') . '</option>';
132
+			}
133
+			$this->_makeSelBoxOptions('forum_name', $selected, $key, $ret, $prefix);
134
+			$ret .= '</select>';
135 135
 
136
-            return $ret;
137
-        }
136
+			return $ret;
137
+		}
138 138
 
139
-        /**
140
-         * Make a tree for the array of a given category
141
-         *
142
-         * @param  string  $key   top key of the tree
143
-         * @param  array   $ret   the tree
144
-         * @param  integer $depth level of subcategories
145
-         * @return void
146
-         * @internal param array $tags fields to be used
147
-         */
148
-        public function getAllChildObject($key, &$ret, $depth = 0)
149
-        {
150
-            if (0 == --$depth) {
151
-                return;
152
-            }
139
+		/**
140
+		 * Make a tree for the array of a given category
141
+		 *
142
+		 * @param  string  $key   top key of the tree
143
+		 * @param  array   $ret   the tree
144
+		 * @param  integer $depth level of subcategories
145
+		 * @return void
146
+		 * @internal param array $tags fields to be used
147
+		 */
148
+		public function getAllChildObject($key, &$ret, $depth = 0)
149
+		{
150
+			if (0 == --$depth) {
151
+				return;
152
+			}
153 153
 
154
-            if (isset($this->tree[$key]['child'])) {
155
-                foreach ($this->tree[$key]['child'] as $childkey) {
156
-                    if (isset($this->tree[$childkey]['obj'])) {
157
-                        $ret['child'][$childkey] = $this->tree[$childkey]['obj'];
158
-                    }
159
-                    $this->getAllChild_object($childkey, $ret['child'][$childkey], $depth);
160
-                }
161
-            }
162
-        }
154
+			if (isset($this->tree[$key]['child'])) {
155
+				foreach ($this->tree[$key]['child'] as $childkey) {
156
+					if (isset($this->tree[$childkey]['obj'])) {
157
+						$ret['child'][$childkey] = $this->tree[$childkey]['obj'];
158
+					}
159
+					$this->getAllChild_object($childkey, $ret['child'][$childkey], $depth);
160
+				}
161
+			}
162
+		}
163 163
 
164
-        /**
165
-         * Make a tree for the array
166
-         *
167
-         * @param  int|string $key   top key of the tree
168
-         * @param  integer    $depth level of subcategories
169
-         * @return array
170
-         * @internal param array $tags fields to be used
171
-         */
172
-        public function &makeObjectTree($key = 0, $depth = 0)
173
-        {
174
-            $ret = [];
175
-            if ($depth > 0) {
176
-                ++$depth;
177
-            }
178
-            $this->getAllChild_object($key, $ret, $depth);
164
+		/**
165
+		 * Make a tree for the array
166
+		 *
167
+		 * @param  int|string $key   top key of the tree
168
+		 * @param  integer    $depth level of subcategories
169
+		 * @return array
170
+		 * @internal param array $tags fields to be used
171
+		 */
172
+		public function &makeObjectTree($key = 0, $depth = 0)
173
+		{
174
+			$ret = [];
175
+			if ($depth > 0) {
176
+				++$depth;
177
+			}
178
+			$this->getAllChild_object($key, $ret, $depth);
179 179
 
180
-            return $ret;
181
-        }
180
+			return $ret;
181
+		}
182 182
 
183
-        /**
184
-         * Make a tree for the array of a given category
185
-         *
186
-         * @param  string  $key   top key of the tree
187
-         * @param  array   $ret   the tree
188
-         * @param  array   $tags  fields to be used
189
-         * @param  integer $depth level of subcategories
190
-         * @return void
191
-         */
192
-        public function getAllChildArray($key, &$ret, array $tags = [], $depth = 0)
193
-        {
194
-            if (0 == --$depth) {
195
-                return;
196
-            }
183
+		/**
184
+		 * Make a tree for the array of a given category
185
+		 *
186
+		 * @param  string  $key   top key of the tree
187
+		 * @param  array   $ret   the tree
188
+		 * @param  array   $tags  fields to be used
189
+		 * @param  integer $depth level of subcategories
190
+		 * @return void
191
+		 */
192
+		public function getAllChildArray($key, &$ret, array $tags = [], $depth = 0)
193
+		{
194
+			if (0 == --$depth) {
195
+				return;
196
+			}
197 197
 
198
-            if (isset($this->tree[$key]['child'])) {
199
-                foreach ($this->tree[$key]['child'] as $childkey) {
200
-                    if (isset($this->tree[$childkey]['obj'])) {
201
-                        if (count($tags) > 0) {
202
-                            foreach ($tags as $tag) {
203
-                                $ret['child'][$childkey][$tag] = $this->tree[$childkey]['obj']->getVar($tag);
204
-                            }
205
-                        } else {
206
-                            $ret['child'][$childkey]['forum_name'] = $this->tree[$childkey]['obj']->getVar('forum_name');
207
-                        }
208
-                    }
198
+			if (isset($this->tree[$key]['child'])) {
199
+				foreach ($this->tree[$key]['child'] as $childkey) {
200
+					if (isset($this->tree[$childkey]['obj'])) {
201
+						if (count($tags) > 0) {
202
+							foreach ($tags as $tag) {
203
+								$ret['child'][$childkey][$tag] = $this->tree[$childkey]['obj']->getVar($tag);
204
+							}
205
+						} else {
206
+							$ret['child'][$childkey]['forum_name'] = $this->tree[$childkey]['obj']->getVar('forum_name');
207
+						}
208
+					}
209 209
 
210
-                    $this->getAllChildArray($childkey, $ret['child'][$childkey], $tags, $depth);
211
-                }
212
-            }
213
-        }
210
+					$this->getAllChildArray($childkey, $ret['child'][$childkey], $tags, $depth);
211
+				}
212
+			}
213
+		}
214 214
 
215
-        /**
216
-         * Make a tree for the array
217
-         *
218
-         * @param  int|string $key   top key of the tree
219
-         * @param  array      $tags  fields to be used
220
-         * @param  integer    $depth level of subcategories
221
-         * @return array
222
-         */
223
-        public function &makeArrayTree($key = 0, $tags = null, $depth = 0)
224
-        {
225
-            $ret = [];
226
-            if ($depth > 0) {
227
-                ++$depth;
228
-            }
229
-            $this->getAllChildArray($key, $ret, $tags, $depth);
215
+		/**
216
+		 * Make a tree for the array
217
+		 *
218
+		 * @param  int|string $key   top key of the tree
219
+		 * @param  array      $tags  fields to be used
220
+		 * @param  integer    $depth level of subcategories
221
+		 * @return array
222
+		 */
223
+		public function &makeArrayTree($key = 0, $tags = null, $depth = 0)
224
+		{
225
+			$ret = [];
226
+			if ($depth > 0) {
227
+				++$depth;
228
+			}
229
+			$this->getAllChildArray($key, $ret, $tags, $depth);
230 230
 
231
-            return $ret;
232
-        }
231
+			return $ret;
232
+		}
233 233
 
234
-        /**#@+
234
+		/**#@+
235 235
          * get all parent forums
236 236
          *
237 237
          * @param  string $key     ID of the child object
@@ -239,49 +239,49 @@  discard block
 block discarded – undo
239 239
          * @param  int    $uplevel (empty when called from outside) level of recursion
240 240
          * @return array  Array of parent nodes.
241 241
          */
242
-        public function &myGetParentForums($key, array $ret = [], $uplevel = 0)
243
-        {
244
-            if (isset($this->tree[$key]['parent']) && isset($this->tree[$this->tree[$key]['parent']]['obj'])) {
245
-                $ret[$uplevel] = $this->tree[$this->tree[$key]['parent']]['obj'];
246
-                if ($this->tree[$key]['parent'] !== $key) {
247
-                    //$parents = $this->getParentForums($this->tree[$key]['parent'], $ret, $uplevel+1);
248
-                    $parents = $this->getParentForums($this->tree[$key]['parent']);
249
-                    foreach (array_keys($parents) as $newkey) {
250
-                        $ret[$newkey] = $parents[$newkey];
251
-                    }
252
-                }
253
-            }
242
+		public function &myGetParentForums($key, array $ret = [], $uplevel = 0)
243
+		{
244
+			if (isset($this->tree[$key]['parent']) && isset($this->tree[$this->tree[$key]['parent']]['obj'])) {
245
+				$ret[$uplevel] = $this->tree[$this->tree[$key]['parent']]['obj'];
246
+				if ($this->tree[$key]['parent'] !== $key) {
247
+					//$parents = $this->getParentForums($this->tree[$key]['parent'], $ret, $uplevel+1);
248
+					$parents = $this->getParentForums($this->tree[$key]['parent']);
249
+					foreach (array_keys($parents) as $newkey) {
250
+						$ret[$newkey] = $parents[$newkey];
251
+					}
252
+				}
253
+			}
254 254
 
255
-            return $ret;
256
-        }
255
+			return $ret;
256
+		}
257 257
 
258
-        /**
259
-         * @param        $key
260
-         * @param  bool  $reverse
261
-         * @return array
262
-         */
263
-        public function &getParentForums($key, $reverse = true)
264
-        {
265
-            $ret  = [];
266
-            $pids = [];
267
-            if (isset($this->tree[$key]['parent']) && isset($this->tree[$this->tree[$key]['parent']]['obj'])) {
268
-                $pids[]  = $this->tree[$this->tree[$key]['parent']]['obj']->getVar($this->myId);
269
-                $parents = $this->myGetParentForums($this->tree[$key]['parent'], $ret);
270
-                foreach (array_keys($parents) as $newkey) {
271
-                    if (!is_object($newkey)) {
272
-                        continue;
273
-                    }
274
-                    $ret[] = $parents[$newkey]->getVar($this->myId);
275
-                }
276
-            }
277
-            if ($reverse) {
278
-                $pids = array_reverse($ret) + $pids;
279
-            } else {
280
-                $pids += $ret;
281
-            }
258
+		/**
259
+		 * @param        $key
260
+		 * @param  bool  $reverse
261
+		 * @return array
262
+		 */
263
+		public function &getParentForums($key, $reverse = true)
264
+		{
265
+			$ret  = [];
266
+			$pids = [];
267
+			if (isset($this->tree[$key]['parent']) && isset($this->tree[$this->tree[$key]['parent']]['obj'])) {
268
+				$pids[]  = $this->tree[$this->tree[$key]['parent']]['obj']->getVar($this->myId);
269
+				$parents = $this->myGetParentForums($this->tree[$key]['parent'], $ret);
270
+				foreach (array_keys($parents) as $newkey) {
271
+					if (!is_object($newkey)) {
272
+						continue;
273
+					}
274
+					$ret[] = $parents[$newkey]->getVar($this->myId);
275
+				}
276
+			}
277
+			if ($reverse) {
278
+				$pids = array_reverse($ret) + $pids;
279
+			} else {
280
+				$pids += $ret;
281
+			}
282 282
 
283
-            return $pids;
284
-        }
285
-        /**#@-*/
286
-    }
283
+			return $pids;
284
+		}
285
+		/**#@-*/
286
+	}
287 287
 }
Please login to merge, or discard this patch.
class/Plugin/userlog.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@
 block discarded – undo
66 66
             case 'viewtopic.php':
67 67
                 /** @var Newbb\TopicHandler $topicHandler */
68 68
                 $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
69
-                $post_id      = Request::getInt('post_id', 0);// !empty($_REQUEST["post_id"]) ? (int)($_REQUEST["post_id"]) : 0;
69
+                $post_id      = Request::getInt('post_id', 0); // !empty($_REQUEST["post_id"]) ? (int)($_REQUEST["post_id"]) : 0;
70 70
                 $move         = strtolower(Request::getString('move', '', 'GET')); // isset($_GET['move'])? strtolower($_GET['move']) : '';
71 71
                 $topic_id     = Request::getInt('topic_id', 0); // !empty($_REQUEST["topic_id"]) ? (int)($_REQUEST["topic_id"]) : 0;
72 72
                 if (!empty($post_id)) {
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -28,65 +28,65 @@
 block discarded – undo
28 28
 
29 29
 class Plugin extends Userlog\Plugin\PluginAbstract implements Userlog\Plugin\PluginInterface
30 30
 {
31
-    /**
32
-     * @param string $subscribe_from Name of the script
33
-     *
34
-     * 'name' => 'thread';
35
-     * 'title' => _MI_NEWBB_THREAD_NOTIFY;
36
-     * 'description' => _MI_NEWBB_THREAD_NOTIFYDSC;
37
-     * 'subscribe_from' => 'viewtopic.php';
38
-     * 'item_name' => 'topic_id';
39
-     * 'allow_bookmark' => 1;
40
-     *
41
-     * publisher:
42
-     * 'name' = 'category_item';
43
-     * 'title' = _MI_PUBLISHER_CATEGORY_ITEM_NOTIFY;
44
-     * 'description' = _MI_PUBLISHER_CATEGORY_ITEM_NOTIFY_DSC;
45
-     * 'subscribe_from' = array('index.php', 'category.php', 'item.php');
46
-     * 'item_name' = 'categoryid';
47
-     * 'allow_bookmark' = 1;
48
-     *
49
-     * empty($subscribe_from):
50
-     * @return bool|array $script_arr["item_name"] name of the item = array("subscribe_from1", "subscribe_from2") Name of the script
51
-     *
52
-     * !empty($subscribe_from):
53
-     * @return bool|array $item["item_name"] name of the item, $item["item_id"] id of the item
54
-     */
55
-    public function item($subscribe_from)
56
-    {
57
-        if (empty($subscribe_from)) {
58
-            $script_arr             = [];
59
-            $script_arr['topic_id'] = ['viewtopic.php'];
60
-            $script_arr['forum']    = ['viewforum.php'];
31
+	/**
32
+	 * @param string $subscribe_from Name of the script
33
+	 *
34
+	 * 'name' => 'thread';
35
+	 * 'title' => _MI_NEWBB_THREAD_NOTIFY;
36
+	 * 'description' => _MI_NEWBB_THREAD_NOTIFYDSC;
37
+	 * 'subscribe_from' => 'viewtopic.php';
38
+	 * 'item_name' => 'topic_id';
39
+	 * 'allow_bookmark' => 1;
40
+	 *
41
+	 * publisher:
42
+	 * 'name' = 'category_item';
43
+	 * 'title' = _MI_PUBLISHER_CATEGORY_ITEM_NOTIFY;
44
+	 * 'description' = _MI_PUBLISHER_CATEGORY_ITEM_NOTIFY_DSC;
45
+	 * 'subscribe_from' = array('index.php', 'category.php', 'item.php');
46
+	 * 'item_name' = 'categoryid';
47
+	 * 'allow_bookmark' = 1;
48
+	 *
49
+	 * empty($subscribe_from):
50
+	 * @return bool|array $script_arr["item_name"] name of the item = array("subscribe_from1", "subscribe_from2") Name of the script
51
+	 *
52
+	 * !empty($subscribe_from):
53
+	 * @return bool|array $item["item_name"] name of the item, $item["item_id"] id of the item
54
+	 */
55
+	public function item($subscribe_from)
56
+	{
57
+		if (empty($subscribe_from)) {
58
+			$script_arr             = [];
59
+			$script_arr['topic_id'] = ['viewtopic.php'];
60
+			$script_arr['forum']    = ['viewforum.php'];
61 61
 
62
-            return $script_arr;
63
-        }
62
+			return $script_arr;
63
+		}
64 64
 
65
-        switch ($subscribe_from) {
66
-            case 'viewtopic.php':
67
-                /** @var Newbb\TopicHandler $topicHandler */
68
-                $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
69
-                $post_id      = Request::getInt('post_id', 0);// !empty($_REQUEST["post_id"]) ? (int)($_REQUEST["post_id"]) : 0;
70
-                $move         = strtolower(Request::getString('move', '', 'GET')); // isset($_GET['move'])? strtolower($_GET['move']) : '';
71
-                $topic_id     = Request::getInt('topic_id', 0); // !empty($_REQUEST["topic_id"]) ? (int)($_REQUEST["topic_id"]) : 0;
72
-                if (!empty($post_id)) {
73
-                    $topicObject = $topicHandler->getByPost($post_id);
74
-                    $topic_id    = $topicObject->getVar('topic_id');
75
-                } elseif (!empty($move)) {
76
-                    $forum_id    = Request::getInt('forum_id', 0); //!empty($_REQUEST["forum_id"]) ? (int)($_REQUEST["forum_id"]) : 0;
77
-                    $topicObject = $topicHandler->getByMove($topic_id, ('prev' === $move) ? -1 : 1, $forum_id);
78
-                    $topic_id    = $topicObject->getVar('topic_id');
79
-                }
65
+		switch ($subscribe_from) {
66
+			case 'viewtopic.php':
67
+				/** @var Newbb\TopicHandler $topicHandler */
68
+				$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
69
+				$post_id      = Request::getInt('post_id', 0);// !empty($_REQUEST["post_id"]) ? (int)($_REQUEST["post_id"]) : 0;
70
+				$move         = strtolower(Request::getString('move', '', 'GET')); // isset($_GET['move'])? strtolower($_GET['move']) : '';
71
+				$topic_id     = Request::getInt('topic_id', 0); // !empty($_REQUEST["topic_id"]) ? (int)($_REQUEST["topic_id"]) : 0;
72
+				if (!empty($post_id)) {
73
+					$topicObject = $topicHandler->getByPost($post_id);
74
+					$topic_id    = $topicObject->getVar('topic_id');
75
+				} elseif (!empty($move)) {
76
+					$forum_id    = Request::getInt('forum_id', 0); //!empty($_REQUEST["forum_id"]) ? (int)($_REQUEST["forum_id"]) : 0;
77
+					$topicObject = $topicHandler->getByMove($topic_id, ('prev' === $move) ? -1 : 1, $forum_id);
78
+					$topic_id    = $topicObject->getVar('topic_id');
79
+				}
80 80
 
81
-                return ['item_name' => 'topic_id', 'item_id' => $topic_id];
82
-                break;
83
-            case 'viewforum.php':
84
-                $forum_id = Request::getInt('forum', 0); // !empty($_REQUEST["forum"]) ? (int)($_REQUEST["forum"]) : 0;
81
+				return ['item_name' => 'topic_id', 'item_id' => $topic_id];
82
+				break;
83
+			case 'viewforum.php':
84
+				$forum_id = Request::getInt('forum', 0); // !empty($_REQUEST["forum"]) ? (int)($_REQUEST["forum"]) : 0;
85 85
 
86
-                return ['item_name' => 'forum', 'item_id' => $forum_id];
87
-                break;
88
-        }
86
+				return ['item_name' => 'forum', 'item_id' => $forum_id];
87
+				break;
88
+		}
89 89
 
90
-        return false;
91
-    }
90
+		return false;
91
+	}
92 92
 }
Please login to merge, or discard this patch.
class/plugins/plugin.tag.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
     /** @var TopicHandler $itemHandler */
49 49
     $itemHandler = Newbb\Helper::getInstance()->getHandler('Topic');
50 50
     /** @var \XoopsObject $itemsObject */
51
-    $itemsObject = $itemHandler->getObjects(new \Criteria('topic_id', '(' . implode(', ', $items_id) . ')', 'IN'), true);
51
+    $itemsObject = $itemHandler->getObjects(new \Criteria('topic_id', '('.implode(', ', $items_id).')', 'IN'), true);
52 52
 
53 53
     foreach (array_keys($items) as $cat_id) {
54 54
         foreach (array_keys($items[$cat_id]) as $item_id) {
Please login to merge, or discard this patch.
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -32,43 +32,43 @@  discard block
 block discarded – undo
32 32
  */
33 33
 function newbb_tag_iteminfo(&$items)
34 34
 {
35
-    if (0 === count($items) || !is_array($items)) {
36
-        return false;
37
-    }
35
+	if (0 === count($items) || !is_array($items)) {
36
+		return false;
37
+	}
38 38
 
39
-    $items_id = [];
40
-    foreach (array_keys($items) as $cat_id) {
41
-        // Some handling here to build the link upon catid
42
-        // catid is not used in newbb, so just skip it
43
-        foreach (array_keys($items[$cat_id]) as $item_id) {
44
-            // In newbb, the item_id is "topic_id"
45
-            $items_id[] = (int)$item_id;
46
-        }
47
-    }
48
-    /** @var TopicHandler $itemHandler */
49
-    $itemHandler = Newbb\Helper::getInstance()->getHandler('Topic');
50
-    /** @var \XoopsObject $itemsObject */
51
-    $itemsObject = $itemHandler->getObjects(new \Criteria('topic_id', '(' . implode(', ', $items_id) . ')', 'IN'), true);
39
+	$items_id = [];
40
+	foreach (array_keys($items) as $cat_id) {
41
+		// Some handling here to build the link upon catid
42
+		// catid is not used in newbb, so just skip it
43
+		foreach (array_keys($items[$cat_id]) as $item_id) {
44
+			// In newbb, the item_id is "topic_id"
45
+			$items_id[] = (int)$item_id;
46
+		}
47
+	}
48
+	/** @var TopicHandler $itemHandler */
49
+	$itemHandler = Newbb\Helper::getInstance()->getHandler('Topic');
50
+	/** @var \XoopsObject $itemsObject */
51
+	$itemsObject = $itemHandler->getObjects(new \Criteria('topic_id', '(' . implode(', ', $items_id) . ')', 'IN'), true);
52 52
 
53
-    foreach (array_keys($items) as $cat_id) {
54
-        foreach (array_keys($items[$cat_id]) as $item_id) {
55
-            /** @var \XoopsObject $itemObject */
56
-            if (!$itemObject = $itemsObject[$item_id]) {
57
-                continue;
58
-            }
59
-            $items[$cat_id][$item_id] = [
60
-                'title'   => $itemObject->getVar('topic_title'),
61
-                'uid'     => $itemObject->getVar('topic_poster'),
62
-                'link'    => "viewtopic.php?topic_id={$item_id}",
63
-                'time'    => $itemObject->getVar('topic_time'),
64
-                'tags'    => tag_parse_tag($itemObject->getVar('topic_tags', 'n')),
65
-                'content' => ''
66
-            ];
67
-        }
68
-    }
69
-    unset($itemsObject);
53
+	foreach (array_keys($items) as $cat_id) {
54
+		foreach (array_keys($items[$cat_id]) as $item_id) {
55
+			/** @var \XoopsObject $itemObject */
56
+			if (!$itemObject = $itemsObject[$item_id]) {
57
+				continue;
58
+			}
59
+			$items[$cat_id][$item_id] = [
60
+				'title'   => $itemObject->getVar('topic_title'),
61
+				'uid'     => $itemObject->getVar('topic_poster'),
62
+				'link'    => "viewtopic.php?topic_id={$item_id}",
63
+				'time'    => $itemObject->getVar('topic_time'),
64
+				'tags'    => tag_parse_tag($itemObject->getVar('topic_tags', 'n')),
65
+				'content' => ''
66
+			];
67
+		}
68
+	}
69
+	unset($itemsObject);
70 70
 
71
-    return true;
71
+	return true;
72 72
 }
73 73
 
74 74
 /**
@@ -78,21 +78,21 @@  discard block
 block discarded – undo
78 78
  */
79 79
 function newbb_tag_synchronization($mid)
80 80
 {
81
-    /** @var TopicHandler $itemHandler */
82
-    $itemHandler = Newbb\Helper::getInstance()->getHandler('Topic');
83
-    /** @var \XoopsPersistableObjectHandler $linkHandler */
84
-    $linkHandler = Tag\Helper::getInstance()->getHandler('Link');
81
+	/** @var TopicHandler $itemHandler */
82
+	$itemHandler = Newbb\Helper::getInstance()->getHandler('Topic');
83
+	/** @var \XoopsPersistableObjectHandler $linkHandler */
84
+	$linkHandler = Tag\Helper::getInstance()->getHandler('Link');
85 85
 
86
-    /* clear tag-item links */
87
-    $sql = "    DELETE FROM {$linkHandler->table}"
88
-           . '    WHERE '
89
-           . "        tag_modid = {$mid}"
90
-           . '        AND '
91
-           . '        ( tag_itemid NOT IN '
92
-           . "            ( SELECT DISTINCT {$itemHandler->keyName} "
93
-           . "                FROM {$itemHandler->table} "
94
-           . "                WHERE {$itemHandler->table}.approved > 0"
95
-           . '            ) '
96
-           . '        )';
97
-    $linkHandler->db->queryF($sql);
86
+	/* clear tag-item links */
87
+	$sql = "    DELETE FROM {$linkHandler->table}"
88
+		   . '    WHERE '
89
+		   . "        tag_modid = {$mid}"
90
+		   . '        AND '
91
+		   . '        ( tag_itemid NOT IN '
92
+		   . "            ( SELECT DISTINCT {$itemHandler->keyName} "
93
+		   . "                FROM {$itemHandler->table} "
94
+		   . "                WHERE {$itemHandler->table}.approved > 0"
95
+		   . '            ) '
96
+		   . '        )';
97
+	$linkHandler->db->queryF($sql);
98 98
 }
Please login to merge, or discard this patch.