diff --git a/Changelog b/Changelog index c3b9330d3..ca6fbdf73 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-02-14 DariusIII + * Chg: Update ColorCLI class * Chg: Update API and RSS classes * Chg: Remove unused Settings use statement from api page * Fix: Fix moviesSearch $whereSql query diff --git a/app/Extensions/helper/helpers.php b/app/Extensions/helper/helpers.php index ba17a18f9..885145d46 100644 --- a/app/Extensions/helper/helpers.php +++ b/app/Extensions/helper/helpers.php @@ -1,5 +1,6 @@ =5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*", + "satooshi/php-coveralls": "1.0.*", + "squizlabs/php_codesniffer": "1.*" + }, + "type": "library", + "autoload": { + "psr-0": { + "Colors": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kevin Le Brun", + "email": "lebrun.k@gmail.com", + "homepage": "http://kevinlebrun.fr", + "role": "developer" + } + ], + "description": "Colors for PHP CLI scripts", + "homepage": "https://github.com/kevinlebrun/colors.php", + "keywords": [ + "cli", + "color", + "colors", + "console", + "shell" + ], + "time": "2016-04-12T20:58:34+00:00" + }, { "name": "kevinrob/guzzle-cache-middleware", "version": "v2.1.1", diff --git a/misc/testing/DB/change_USP_provider.php b/misc/testing/DB/change_USP_provider.php deleted file mode 100644 index d5b7d3a86..000000000 --- a/misc/testing/DB/change_USP_provider.php +++ /dev/null @@ -1,163 +0,0 @@ -log->setColor('Yellow')."This script is used when you have switched UseNet Providers(USP) so you can pickup where you left off, rather than resetting all the groups.\nOnly use this script after you have updated your config.php file with your new USP info!!\nMake sure you ".$pdo->log->setColor('Red', 'Bold').'DO NOT'.$pdo->log->setcolor('Yellow')." have any update or postprocess scripts running when running this script!\n\n".$pdo->log->setColor('Cyan')."Usage: php change_USP_provider true\n"); - exit(); -} - -$groups = $pdo->query('SELECT id, name, first_record_postdate, last_record_postdate FROM groups WHERE active = 1'); -$numofgroups = count($groups); -$guesstime = $numofgroups * 2; -$totalstart = microtime(true); - -echo "You have $numofgroups active, it takes about 2 minutes on average to processes each group.\n"; -foreach ($groups as $group) { - $starttime = microtime(true); - $nntp = new NNTP(['Settings' => $pdo]); - if ($nntp->doConnect() !== true) { - return; - } - //printf("Updating group ".$group['name']."..\n"); - $bfdays = daysOldstr($group['first_record_postdate']); - $currdays = daysOldstr($group['last_record_postdate']); - $bfartnum = daytopost($nntp, $group['name'], $bfdays, true, true); - echo 'Our Current backfill postdate was: '.$pdo->log->setColor('Yellow').date('r', strtotime($group['first_record_postdate'])).$pdo->log->rsetcolor()."\n"; - $currartnum = daytopost($nntp, $group['name'], $currdays, true, false); - echo 'Our Current current postdate was: '.$pdo->log->setColor('Yellow').date('r', strtotime($group['last_record_postdate'])).$pdo->log->rsetcolor().PHP_EOL; - $pdo->queryExec(sprintf('UPDATE groups SET first_record = %s, last_record = %s WHERE id = %d', $pdo->escapeString($bfartnum), $pdo->escapeString($currartnum), $group['id'])); - $endtime = microtime(true); - echo $pdo->log->setColor('Gray', 'Dim').'This group took '.gmdate('H:i:s', $endtime - $starttime).' to process.'.PHP_EOL; - $numofgroups--; - echo 'There are '.$numofgroups.' left to process.'.PHP_EOL.PHP_EOL.$pdo->log->rsetcolor().''; -} - -$totalend = microtime(true); -echo $pdo->log->header('Total time to update all groups '.gmdate('H:i:s', $totalend - $totalstart)); - -// Truncate tables to complete the change to the new USP. -$arr = ['parts', 'missed_parts', 'binaries', 'collections', 'multigroup_parts', 'multigroup_missed_parts', 'multigroup_binaries', 'multigroup_collections']; -foreach ($arr as &$value) { - $rel = $pdo->queryExec("TRUNCATE TABLE $value"); - if ($rel !== false) { - echo $pdo->log->header("Truncating $value completed."); - } -} -unset($value); - -function daysOldstr($timestamp) -{ - return round((time() - strtotime($timestamp)) / 86400, 5); -} - -function daysOld($timestamp) -{ - return round((time() - $timestamp) / 86400, 5); -} - -// This function taken from lib/backfill.php, and modified to fit our needs. -function daytopost($nntp, $group, $days, $debug = true, $bfcheck = true) -{ - global $pdo; - - $st = false; - if ($debug && $bfcheck) { - echo $pdo->log->primary('Finding start and end articles for '.$group.'.'); - } - - if (! isset($nntp)) { - $nntp = new NNTP(['Settings' => $pdo]); - if ($nntp->doConnect(false) !== true) { - return; - } - - $st = true; - } - - $binaries = new Binaries(['NNTP' => $nntp, 'Settings' => $pdo]); - - $data = $nntp->selectGroup($group); - if ($nntp->isError($data)) { - $data = $nntp->dataError($nntp, $group, false); - if ($data === false) { - return; - } - } - - // Goal timestamp. - $goaldate = date('U') - (86400 * $days); - $totalnumberofarticles = $data['last'] - $data['first']; - $upperbound = $data['last']; - $lowerbound = $data['first']; - - if ($debug && $bfcheck) { - echo $pdo->log->header('Total Articles: '.number_format($totalnumberofarticles).' Newest: '.number_format($upperbound).' Oldest: '.number_format($lowerbound)); - } - - if ($data['last'] == PHP_INT_MAX) { - exit($pdo->log->error("Group data is coming back as php's max value. You should not see this since we use a patched Net_NNTP that fixes this bug.")); - } - - $firstDate = $binaries->postdate($data['first'], $data); - $lastDate = $binaries->postdate($data['last'], $data); - - if ($goaldate < $firstDate && $bfcheck) { - if ($st === true) { - $nntp->doQuit(); - } - echo $pdo->log->warning("The oldest post indexed from $days day(s) ago is older than the first article stored on your news server.\nSetting to First available article of (date('r', $firstDate) or daysOld($firstDate) days)."); - - return $data['first']; - } elseif ($goaldate > $lastDate && $bfcheck) { - if ($st === true) { - $nntp->doQuit(); - } - echo $pdo->log->error("ERROR: The oldest post indexed from $days day(s) ago is newer than the last article stored on your news server.\nTo backfill this group you need to set Backfill Days to at least ceil(daysOld($lastDate)+1) days (date('r', $lastDate-86400)."); - - return ''; - } - - if ($debug && $bfcheck) { - echo $pdo->log->primary("Searching for postdates.\nGroup's Firstdate: ".$firstDate.' ('.(is_int($firstDate) ? date('r', $firstDate) : 'n/a').").\nGroup's Lastdate: ".$lastDate.' ('.date('r', $lastDate).').'); - } - - $interval = floor(($upperbound - $lowerbound) * 0.5); - $templowered = ''; - $dateofnextone = $lastDate; - // Match on days not timestamp to speed things up. - while (daysOld($dateofnextone) < $days) { - while (($tmpDate = $binaries->postdate(($upperbound - $interval), $data)) > $goaldate) { - $upperbound -= $interval; - } - - if (! $templowered) { - $interval = ceil($interval / 2); - } - $dateofnextone = $binaries->postdate($upperbound - 1, $data); - while (! $dateofnextone) { - $dateofnextone = $binaries->postdate($upperbound - 1, $data); - } - } - if ($st === true) { - $nntp->doQuit(); - } - if ($bfcheck) { - echo $pdo->log->header("\nBackfill article determined to be ".$upperbound.' '.$pdo->log->setColor('Yellow').'('.date('r', $dateofnextone).')'.$pdo->log->rsetcolor()); - } // which is '.daysOld($dateofnextone)." days old.\n"; - else { - echo $pdo->log->header('Current article determined to be '.$upperbound.' '.$pdo->log->setColor('Yellow').'('.date('r', $dateofnextone).')'.$pdo->log->rsetcolor()); - } // which is '.daysOld($dateofnextone)." days old.\n"; - return $upperbound; -} diff --git a/misc/testing/Various/find_password_hash_cost.php b/misc/testing/Various/find_password_hash_cost.php deleted file mode 100644 index 697a7a68d..000000000 --- a/misc/testing/Various/find_password_hash_cost.php +++ /dev/null @@ -1,28 +0,0 @@ - $cost]); - $end = microtime(true); -} while (($end - $start) < $timeTarget); - -echo 'Appropriate Cost Found: '.$cost.PHP_EOL; diff --git a/nntmux/Backfill.php b/nntmux/Backfill.php index 12b6b9b36..3b4cae724 100755 --- a/nntmux/Backfill.php +++ b/nntmux/Backfill.php @@ -277,8 +277,7 @@ class Backfill while ($done === false) { if ($this->_echoCLI) { ColorCLI::doEcho( - ColorCLI::set256('Yellow'). - PHP_EOL.'Getting '. + color('Getting '. number_format($last - $first + 1). ' articles from '. $groupName. @@ -286,10 +285,7 @@ class Backfill $left. ' group(s) left. ('. number_format($first - $targetpost). - ' articles in queue).'. - ColorCLI::rsetColor(), - true - ); + ' articles in queue')->fg('yellow'), true); } flush(); diff --git a/nntmux/ColorCLI.php b/nntmux/ColorCLI.php index 513214322..fff84dc07 100755 --- a/nntmux/ColorCLI.php +++ b/nntmux/ColorCLI.php @@ -7,211 +7,14 @@ namespace nntmux; class ColorCLI { - private static $foreground_colors = [ - 'Black' => '30', - 'Blue' => '34', - 'Green' => '32', - 'Cyan' => '36', - 'Red' => '31', - 'Purple' => '35', - 'Yellow' => '33', - 'Gray' => '37', - ]; - // Feel free to add any other colors that you like here. - private static $colors256 = [ - 'Gray' => '008', 'Red' => '009', - 'Green' => '010', 'Yellow' => '011', - 'Blue' => '012', 'Purple' => '013', - 'Cyan' => '014', 'White' => '015', - 'Grey1' => '016', 'NavyBlue' => '017', - 'DarkBlue' => '018', 'Blue2' => '019', - 'Blue3' => '020', 'Blue1' => '021', - 'DarkGreen' => '022', 'DeepSkyBlue5' => '023', - 'DeepSkyBlue6' => '024', 'DeepSkyBlue7' => '025', - 'DodgerBlue2' => '026', 'DodgerBlue1' => '027', - 'Green4' => '028', 'SpringGreen5' => '029', - 'Turquoise1' => '030', 'DeepSkyBlue2' => '031', - 'DeepSkyBlue3' => '032', 'DodgerBlue' => '033', - 'Green2' => '034', 'SpringGreen3' => '035', - 'DarkCyan' => '036', 'LightSeaGreen' => '037', - 'DeepSkyBlue1' => '038', 'DeepSkyBlue' => '039', - 'Green3' => '040', 'SpringGreen4' => '041', - 'SpringGreen1' => '042', 'Cyan3' => '043', - 'DarkTurquoise' => '044', 'Turquoise' => '045', - 'Green1' => '046', 'SpringGreen2' => '047', - 'SpringGreen' => '048', 'MediumSpringGreen' => '049', - 'Cyan2' => '050', 'Cyan1' => '051', - 'DarkRed' => '052', 'DeepPink5' => '053', - 'Purple4' => '054', 'Purple5' => '055', - 'Purple3' => '056', 'BlueViolet' => '057', - 'Orange2' => '058', 'Grey2' => '059', - 'MediumPurple6' => '060', 'SlateBlue1' => '061', - 'SlateBlue2' => '062', 'RoyalBlue1' => '063', - 'Chartreuse5' => '064', 'DarkSeaGreen7' => '065', - 'PaleTurquoise1' => '066', 'SteelBlue' => '067', - 'SteelBlue3' => '068', 'CornflowerBlue' => '069', - 'Chartreuse3' => '070', 'DarkSeaGreen8' => '071', - 'CadetBlue' => '072', 'CadetBlue1' => '073', - 'SkyBlue2' => '074', 'SteelBlue1' => '075', - 'Chartreuse4' => '076', 'PaleGreen2' => '077', - 'SeaGreen3' => '078', 'Aquamarine2' => '079', - 'MediumTurquoise' => '080', 'SteelBlue2' => '081', - 'Chartreuse1' => '082', 'SeaGreen2' => '083', - 'SeaGreen' => '084', 'SeaGreen1' => '085', - 'Aquamarine' => '086', 'DarkSlateGray1' => '087', - 'DarkRed1' => '088', 'DeepPink6' => '089', - 'DarkMagenta' => '090', 'DarkMagenta1' => '091', - 'DarkViolet' => '092', 'Purple1' => '093', - 'Orange3' => '094', 'LightPink2' => '095', - 'Plum3' => '096', 'MediumPurple4' => '097', - 'MediumPurple5' => '098', 'SlateBlue' => '099', - 'Yellow5' => '100', 'Wheat1' => '101', - 'Grey3' => '102', 'LightSlateGrey' => '103', - 'MediumPurple' => '104', 'LightSlateBlue' => '105', - 'Yellow6' => '106', 'DarkOliveGreen3' => '107', - 'DarkSeaGreen' => '108', 'LightSkyBlue1' => '109', - 'LightSkyBlue2' => '110', 'SkyBlue1' => '111', - 'Chartreuse2' => '112', 'DarkOliveGreen4' => '113', - 'PaleGreen3' => '114', 'DarkSeaGreen5' => '115', - 'DarkSlateGray2' => '116', 'SkyBlue' => '117', - 'Chartreuse' => '118', 'LightGreen' => '119', - 'LightGreen1' => '120', 'PaleGreen' => '121', - 'Aquamarine1' => '122', 'DarkSlateGray' => '123', - 'Red2' => '124', 'DeepPink7' => '125', - 'MediumVioletRed' => '126', 'Magenta4' => '127', - 'DarkViolet1' => '128', 'Purple2' => '129', - 'DarkOrange1' => '130', 'IndianRed' => '131', - 'HotPink3' => '132', 'MediumOrchid3' => '133', - 'MediumOrchid' => '134', 'MediumPurple2' => '135', - 'DarkGoldenrod' => '136', 'LightSalmon1' => '137', - 'RosyBrown' => '138', 'Grey4' => '139', - 'MediumPurple3' => '140', 'MediumPurple1' => '141', - 'Gold1' => '142', 'DarkKhaki' => '143', - 'NavajoWhite1' => '144', 'Grey5' => '145', - 'LightSteelBlue2' => '146', 'LightSteelBlue' => '147', - 'Yellow3' => '148', 'DarkOliveGreen5' => '149', - 'DarkSeaGreen6' => '150', 'DarkSeaGreen3' => '151', - 'LightCyan2' => '152', 'LightSkyBlue' => '153', - 'GreenYellow' => '154', 'DarkOliveGreen2' => '155', - 'PaleGreen1' => '156', 'DarkSeaGreen4' => '157', - 'DarkSeaGreen1' => '158', 'PaleTurquoise' => '159', - 'Red3' => '160', 'DeepPink3' => '161', - 'DeepPink4' => '162', 'Magenta5' => '163', - 'Magenta6' => '164', 'Magenta2' => '165', - 'DarkOrange2' => '166', 'IndianRed1' => '167', - 'HotPink4' => '168', 'HotPink2' => '169', - 'Orchid' => '170', 'MediumOrchid1' => '171', - 'Orange1' => '172', 'LightSalmon2' => '173', - 'LightPink1' => '174', 'Pink1' => '175', - 'Plum2' => '176', 'Violet' => '177', - 'Gold2' => '178', 'LightGoldenrod4' => '179', - 'Tan' => '180', 'MistyRose1' => '181', - 'Thistle1' => '182', 'Plum1' => '183', - 'Yellow4' => '184', 'Khaki1' => '185', - 'LightGoldenrod1' => '186', 'LightYellow' => '187', - 'Grey6' => '188', 'LightSteelBlue1' => '189', - 'Yellow2' => '190', 'DarkOliveGreen' => '191', - 'DarkOliveGreen1' => '192', 'DarkSeaGreen2' => '193', - 'Honeydew' => '194', 'LightCyan1' => '195', - 'Red1' => '196', 'DeepPink2' => '197', - 'DeepPink' => '198', 'DeepPink1' => '199', - 'Magenta3' => '200', 'Magenta1' => '201', - 'OrangeRed' => '202', 'IndianRed2' => '203', - 'IndianRed3' => '204', 'HotPink' => '205', - 'HotPink1' => '206', 'MediumOrchid2' => '207', - 'DarkOrange' => '208', 'Salmon' => '209', - 'LightCoral' => '210', 'PaleVioletRed' => '211', - 'Orchid2' => '212', 'Orchid1' => '213', - 'Orange' => '214', 'SandyBrown' => '215', - 'LightSalmon' => '216', 'LightPink' => '217', - 'Pink' => '218', 'Plum' => '219', - 'Gold' => '220', 'LightGoldenrod2' => '221', - 'LightGoldenrod3' => '222', 'NavajoWhite' => '223', - 'MistyRose' => '224', 'Thistle' => '225', - 'Yellow1' => '226', 'LightGoldenrod' => '227', - 'Khaki' => '228', 'Wheat' => '229', - 'Cornsilk' => '230', 'Grey7' => '231', - 'Grey8' => '232', 'Grey9' => '233', - 'Grey10' => '234', 'Grey11' => '235', - 'Grey12' => '236', 'Grey13' => '237', - 'Grey14' => '238', 'Grey15' => '239', - 'Grey16' => '240', 'Grey17' => '241', - 'Grey18' => '242', 'Grey19' => '243', - 'Grey20' => '244', 'Grey21' => '245', - 'Grey22' => '246', 'Grey23' => '247', - 'Grey24' => '248', 'Grey25' => '249', - 'Grey26' => '250', 'Grey27' => '251', - 'Grey28' => '252', 'Grey29' => '253', - 'Grey30' => '254', 'Grey31' => '255', - ]; - private static $background_colors = [ - 'Black' => '40', 'Red' => '41', - 'Green' => '42', 'Yellow' => '43', - 'Blue' => '44', 'Purple' => '45', - 'Cyan' => '46', 'White' => '47', - ]; - private static $options = [ - 'Norm' => '0', 'Bold' => '1', - 'Dim' => '2', 'Uline' => '4', - 'Blink' => '5', 'Rev' => '7', - 'Hidden' => '8', 'Crossout' => '9', - ]; - - /** - * @param int $count - */ - public static function bell($count = 1): void - { - echo str_repeat("\007", $count); - } - - /** - * @param $fg - * @param string $opt - * @param string $bg - * @return string - */ - public static function setColor($fg, $opt = 'None', $bg = 'None'): string - { - $colored_string = "\033[".self::$foreground_colors[$fg]; - if (isset(self::$options[$opt])) { - $colored_string .= ';'.self::$options[$opt]; - } - if (isset(self::$background_colors[$bg])) { - $colored_string .= ';'.self::$background_colors[$bg]; - } - $colored_string .= 'm'; - - return $colored_string; - } - - /** - * @param $fg - * @param string $opt - * @param string $bg - * @return string - */ - public static function set256($fg, $opt = 'None', $bg = 'None'): string - { - $colored_string = "\033[38;5;".self::$colors256[$fg]; - if ($opt !== 'Norm' && isset(self::$options[$opt])) { - $colored_string .= ';'.self::$options[$opt]; - } - if (isset(self::$background_colors[$bg])) { - $colored_string .= ';48;5;'.self::$colors256[$bg]; - } - $colored_string .= 'm'; - - return $colored_string; - } - /** * @param $str + * * @return string */ - public static function debug($str): string + public static function debug($str) { - return "\033[".self::$foreground_colors['Gray']."mDebug: $str\033[0m\n"; + return color('Debug: ' .$str)->light_gray() . PHP_EOL; } /** @@ -220,7 +23,7 @@ class ColorCLI */ public static function info($str): string { - return "\033[".self::$foreground_colors['Purple']."mInfo: $str\033[0m\n"; + return color('Info: ' .$str)->fg('magenta'); } /** @@ -229,7 +32,7 @@ class ColorCLI */ public static function notice($str): string { - return "\033[38;5;".self::$colors256['Blue']."mNotice: $str\033[0m\n"; + return color('Notice: ' .$str)->blue(); } /** @@ -238,7 +41,7 @@ class ColorCLI */ public static function warning($str): string { - return "\033[".self::$foreground_colors['Yellow']."mWarning: $str\033[0m\n"; + return color('Warning: ' .$str)->fg('yellow'); } /** @@ -247,7 +50,7 @@ class ColorCLI */ public static function error($str): string { - return "\033[".self::$foreground_colors['Red']."mError: $str\033[0m\n"; + return color('Error: ' . $str)->fg('red'); } /** @@ -256,7 +59,7 @@ class ColorCLI */ public static function primary($str): string { - return "\033[38;5;".self::$colors256['Green']."m$str\033[0m\n"; + return color($str)->green(); } /** @@ -265,7 +68,7 @@ class ColorCLI */ public static function header($str): string { - return "\033[38;5;".self::$colors256['Yellow']."m$str\033[0m\n"; + return color($str)->yellow(); } /** @@ -274,7 +77,7 @@ class ColorCLI */ public static function alternate($str): string { - return "\033[38;5;".self::$colors256['DeepPink1']."m$str\033[0m\n"; + return color($str)->magenta()->dark()->bold(); } /** @@ -283,7 +86,7 @@ class ColorCLI */ public static function tmuxOrange($str): string { - return "\033[38;5;".self::$colors256['Orange']."m$str\033[0m\n"; + return color($str)->yellow()->dark(); } /** @@ -292,7 +95,7 @@ class ColorCLI */ public static function primaryOver($str): string { - return "\033[38;5;".self::$colors256['Green']."m$str\033[0m"; + return color($str)->green(); } /** @@ -301,7 +104,7 @@ class ColorCLI */ public static function headerOver($str): string { - return "\033[38;5;".self::$colors256['Yellow']."m$str\033[0m"; + return color($str)->yellow(); } /** @@ -310,7 +113,7 @@ class ColorCLI */ public static function alternateOver($str): string { - return "\033[38;5;".self::$colors256['DeepPink1']."m$str\033[0m"; + return color($str)->magenta()->dark(); } /** @@ -319,15 +122,7 @@ class ColorCLI */ public static function warningOver($str): string { - return "\033[38;5;".self::$colors256['Red']."m$str\033[0m"; - } - - /** - * @return string - */ - public static function rsetColor(): string - { - return "\033[0m"; + return color($str)->red(); } /**