From dcc9cfdf49e48c907ba699f0e02d203867d7ad5f Mon Sep 17 00:00:00 2001 From: DariusIII Date: Thu, 23 Feb 2017 14:48:23 +0100 Subject: [PATCH] Continue refactoring --- nntmux/Category.php | 72 ++++++++++----------------------------------- nntmux/ColorCLI.php | 16 +++++----- 2 files changed, 23 insertions(+), 65 deletions(-) diff --git a/nntmux/Category.php b/nntmux/Category.php index aa4b67d45..04e5a9cc3 100755 --- a/nntmux/Category.php +++ b/nntmux/Category.php @@ -171,7 +171,7 @@ class Category break; // Multiple category constraints default: - $catsrch = " AND r.categories_id IN (" . implode(", ", $categories) . ") "; + $catsrch = ' AND r.categories_id IN (' . implode(', ', $categories) . ') '; break; } @@ -186,7 +186,7 @@ class Category */ public static function getCategoryOthersGroup() { - return implode(",", + return implode(',', [ self::BOOKS_UNKNOWN, self::GAME_OTHER, @@ -217,10 +217,10 @@ class Category public function isParent($cid) { $ret = $this->pdo->query( - sprintf("SELECT id FROM categories WHERE id = %d AND parentid IS NULL", $cid), + sprintf('SELECT id FROM categories WHERE id = %d AND parentid IS NULL', $cid), true, NN_CACHE_EXPIRY_LONG ); - return (isset($ret[0]['id'])); + return isset($ret[0]['id']); } /** @@ -232,9 +232,9 @@ class Category { $act = ""; if ($activeonly) { - $act = sprintf(" WHERE c.status = %d ", Category::STATUS_ACTIVE); + $act = sprintf(' WHERE c.status = %d ', Category::STATUS_ACTIVE); } - return $this->pdo->query("SELECT c.*, (SELECT title FROM categories WHERE id=c.parentid) AS parentName FROM categories c " . $act . " ORDER BY c.id"); + return $this->pdo->query('SELECT c.*, (SELECT title FROM categories WHERE id=c.parentid) AS parentName FROM categories c ' . $act . ' ORDER BY c.id'); } /** @@ -247,7 +247,7 @@ class Category public function getChildren($cid) { return $this->pdo->query( - sprintf("SELECT c.* FROM categories c WHERE parentid = %d", $cid), + sprintf('SELECT c.* FROM categories c WHERE parentid = %d', $cid), true, NN_CACHE_EXPIRY_LONG ); } @@ -259,7 +259,7 @@ class Category public function getEnabledParentNames() { return $this->pdo->query( - "SELECT title FROM categories WHERE parentid IS NULL AND status = 1", + 'SELECT title FROM categories WHERE parentid IS NULL AND status = 1', true, NN_CACHE_EXPIRY_LONG ); } @@ -272,7 +272,7 @@ class Category public function getDisabledIDs() { return $this->pdo->query( - "SELECT id FROM categories WHERE status = 2 OR parentid IN (SELECT id FROM categories WHERE status = 2 AND parentid IS NULL)", + 'SELECT id FROM categories WHERE status = 2 OR parentid IN (SELECT id FROM categories WHERE status = 2 AND parentid IS NULL)', true, NN_CACHE_EXPIRY_LONG ); } @@ -290,48 +290,6 @@ class Category return $this->pdo->queryOneRow(sprintf("SELECT c.disablepreview, c.id, c.description, c.minsizetoformrelease, c.maxsizetoformrelease, CONCAT(COALESCE(cp.title,'') , CASE WHEN cp.title IS NULL THEN '' ELSE ' > ' END , c.title) as title, c.status, c.parentid from categories c left outer join categories cp on cp.id = c.parentid where c.id = %d", $id)); } - public function getSizeRangeById($id) - { - $res = $this->pdo->queryOneRow(sprintf("SELECT c.minsizetoformrelease, c.maxsizetoformrelease, cp.minsizetoformrelease as p_minsizetoformrelease, cp.maxsizetoformrelease as p_maxsizetoformrelease" . - " from categories c left outer join categories cp on cp.id = c.parentid where c.id = %d", $id - ) - ); - if (!$res) - return null; - - $min = intval($res['minsizetoformrelease']); - $max = intval($res['maxsizetoformrelease']); - if ($min == 0 && $max == 0) { - # Size restriction disabled; now check parent - $min = intval($res['p_minsizetoformrelease']); - $max = intval($res['p_maxsizetoformrelease']); - if ($min == 0 && $max == 0) { - # no size restriction - return null; - } else if ($max > 0) { - $min = 0; - $max = intval($res['p_maxsizetoformrelease']); - } else { - $min = intval($res['p_minsizetoformrelease']); - $max = PHP_INT_MAX; - } - } else if ($max > 0) { - $min = 0; - $max = intval($res['maxsizetoformrelease']); - } else { - $min = intval($res['minsizetoformrelease']); - $max = PHP_INT_MAX; - } - - # If code reaches here, then content is enabled - return array('min' => $min, 'max' => $max); - } - - /* - * Return min/max size range (in array(min, max)) otherwise, none is returned - * if no size restrictions are set - */ - /** * Get multiple categories. * @@ -364,15 +322,15 @@ class Category public function getNameByID($ID) { $cat = $this->pdo->queryOneRow( - sprintf(" + sprintf(' SELECT c.title AS ctitle, cp.title AS ptitle FROM categories c INNER JOIN categories cp ON c.parentid = cp.id - WHERE c.id = %d", + WHERE c.id = %d', $ID ) ); - return $cat["ptitle"] . " -> " . $cat["ctitle"]; + return $cat['ptitle'] . ' -> ' . $cat['ctitle']; } /** @@ -389,7 +347,7 @@ class Category */ public function update($id, $status, $desc, $disablepreview, $minsize, $maxsize) { - return $this->pdo->queryExec(sprintf("UPDATE categories SET disablepreview = %d, status = %d, minsizetoformrelease = %d, maxsizetoformrelease = %d, description = %s WHERE id = %d", $disablepreview, $status, $minsize, $maxsize, $this->pdo->escapeString($desc), $id)); + return $this->pdo->queryExec(sprintf('UPDATE categories SET disablepreview = %d, status = %d, minsizetoformrelease = %d, maxsizetoformrelease = %d, description = %s WHERE id = %d', $disablepreview, $status, $minsize, $maxsize, $this->pdo->escapeString($desc), $id)); } /** @@ -463,11 +421,11 @@ class Category $temp_array = []; if ($blnIncludeNoneSelected) { - $temp_array[-1] = "--Please Select--"; + $temp_array[-1] = '--Please Select--'; } foreach ($categories as $category) - $temp_array[$category["id"]] = $category["title"]; + $temp_array[$category['id']] = $category['title']; return $temp_array; } diff --git a/nntmux/ColorCLI.php b/nntmux/ColorCLI.php index 71f609f60..ea81153ab 100755 --- a/nntmux/ColorCLI.php +++ b/nntmux/ColorCLI.php @@ -6,7 +6,7 @@ namespace nntmux; class ColorCLI { - static $foreground_colors = array( + static $foreground_colors = [ 'Black' => '30', 'Blue' => '34', 'Green' => '32', @@ -15,9 +15,9 @@ class ColorCLI 'Purple' => '35', 'Yellow' => '33', 'Gray' => '37', - ); + ]; // Feel free to add any other colors that you like here. - static $colors256 = array( + static $colors256 = [ 'Gray' => '008', 'Red' => '009', 'Green' => '010', 'Yellow' => '011', 'Blue' => '012', 'Purple' => '013', @@ -142,19 +142,19 @@ class ColorCLI 'Grey26' => '250', 'Grey27' => '251', 'Grey28' => '252', 'Grey29' => '253', 'Grey30' => '254', 'Grey31' => '255', - ); - static $background_colors = array( + ]; + static $background_colors = [ 'Black' => '40', 'Red' => '41', 'Green' => '42', 'Yellow' => '43', 'Blue' => '44', 'Purple' => '45', 'Cyan' => '46', 'White' => '47', - ); - static $options = array( + ]; + static $options = [ 'Norm' => '0', 'Bold' => '1', 'Dim' => '2', 'Uline' => '4', 'Blink' => '5', 'Rev' => '7', 'Hidden' => '8', 'Crossout' => '9', - ); + ]; public static function bell($count = 1) {