private function __probe($filename, $prettify) { // Start time $init = microtime(true); // Default options $options = '-loglevel quiet -show_format -show_streams -print_format json'; if ($prettify) { $options .= ' -pretty'; } // Avoid escapeshellarg() issues with UTF-8 filenames setlocale(LC_CTYPE, 'en_US.UTF-8'); //$command = sprintf('ffprobe %s %s ', $options, escapeshellarg($filename)); $command = sprintf('./ffprobe %s "%s" ', $options, $filename); // Run the ffprobe, save the JSON output then decode $json = json_decode(shell_exec($command), true); //if (!isset($json->format)) if (!isset($json['format'])) { //throw new Exception('Unsupported file type: '.$filename."\r\nCommand:\r\n".$command."\r\n"); $output = 'ffprobe: Unsupported file type: ' . $filename . "\r\nCommand:\r\n" . $command . "\r\n"; $colors = new Colors(); $colors->getColoredString($output, 'black', 'red'); //The command finished with an error. $error = R::dispense('error'); //$video->ownError = array($error); $error->raw_output = $output; $error->repaired = false; $id = R::store($error); } // Save parse time (milliseconds) $this->parse_time = round((microtime(true) - $init) * 1000); return $json; }
function color($str, $fg, $bg) { global $system; require_once $_dir['system_lib'] . 'colors.class.php'; $colors = new Colors(); return $colors->getColoredString($str, $fg, $bg); }
function display(&$feed1_title, &$feed1_pubdate, &$feed1_desc, &$totalfeedNews, $feed_rss, $feedFrom, $source) { $colors = new Colors(); $feed1_title = $colors->getColoredString($feed1_title, "yellow"); $feed1_desc = $colors->getColoredString($feed1_desc, "blue", "light_gray"); $source = strtoupper($source); $source = $colors->getColoredString($source, "white", "red"); print $feed1_title; print $feed1_pubdate->format('d-m-Y H:i A') . "\n"; print $feed1_desc; print "Source :" . $source . "\n"; }
function test_fd() { $colors = new Colors(); $exec = "./test_gnl 0 0 0"; $s1 = "-1"; $s2 = exec($exec); if (!strcmp($s1, $s2)) { echo $colors->getColoredString("OK\n", "green"); } else { echo $colors->getColoredString("FAIL\n", "red"); echo "Output should be: <", $s1, ">\nBut is: <", $s2, ">\n"; } }
/** * getInstance * Returns (or creates and returns) the single instance of Color * @static * @access public * @return Color */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Loops through the row and sets the maximum width for each column. * * @param array $row The table row. */ protected function checkRow(array $row) { foreach ($row as $column => $str) { $width = Colors::length($str); if (!isset($this->_width[$column]) || $width > $this->_width[$column]) { $this->_width[$column] = $width; } } return $row; }
function _recurse_output($OUTPUT, $depth = 0, $color = false) { if ($color) { require_once "helper_functions/colors.php"; $colors = new Colors(); } $i = 0; $keys = array_keys($OUTPUT); while ($i < count($OUTPUT)) { if (is_array($OUTPUT[$keys[$i]])) { $j = 0; while ($j < $depth) { echo " "; $j++; } if ($color) { echo $colors->getColoredString($keys[$i], "red") . ":\r\n"; } else { echo (string) $keys[$i] . ":\r\n"; } _recurse_output($OUTPUT[$keys[$i]], $depth + 1, $color); } else { $j = 0; while ($j < $depth) { echo " "; $j++; } if ($color) { $out = $colors->getColoredString((string) $keys[$i], "light_red"); $out .= ": "; $out .= $colors->getColoredString((string) $OUTPUT[$keys[$i]], "blue"); $out .= "\r\n"; echo $out; } else { echo (string) $keys[$i] . ": " . (string) $OUTPUT[$keys[$i]] . "\r\n"; } } $i++; } }
public function set($plantID, $colorArray) { $colors = Colors::all(); $colorArray = $this->filterArray($colorArray); $cleanColors = $this->cleanModelArray($colors); foreach ($colorArray as $color) { if (is_numeric(array_search($color, $cleanColors))) { $newColor = new PlantColor(); $newColor->plant_id = $plantID; $newColor->color_id = array_search($color, $cleanColors) + 1; $newColor->save(); } } }
/** * Outputs a $message to STDOUT and log file, color-coded depending on $case. * @param $message - the message to log * @param $case - the type of severity and reson to log, the message will be color-coded accordingly, the cases are: * userConnected, userDisconnected, addedItem, updatedItem, removedItem, clearedList, synced, error, warn */ function logMsg($message, $level = "default") { $colors = new Colors(); $fg = null; $bg = null; switch ($level) { case 'userConnected': $fg = null; $bg = "cyan"; break; case 'userDisconnected': $fg = "cyan"; $bg = "black"; break; case 'addedItem': $fg = "black"; $bg = "green"; break; case 'updatedItem': $fg = "light_gray"; $bg = "green"; break; case 'clearedList': $fg = "light_gray"; $bg = "black"; break; case 'removedItem': $fg = "yellow"; $bg = "black"; break; case 'error': $fg = "white"; $bg = "red"; break; case 'warn': $fg = "brown"; $bg = "magenta"; break; case 'sync': $fg = "light_green"; $bg = "blue"; break; default: break; } echo $colors->getColoredString($message, $fg, $bg) . "\n<br>"; echo GetCallingMethodName(); date_default_timezone_set('Europe/Stockholm'); file_put_contents("/var/www/shoppinglist/logs/logFile", date("{Y-m-d H:i:s}") . " " . $message . "\n", FILE_APPEND); }
/** * Outputs a $message to STDOUT and log file, color-coded depending on $case. * @param $message - the message to log * @param $case - the type of severity and reson to log, the message will be color-coded accordingly, the cases are: * userConnected, userDisconnected, addedItem, updatedItem, removedItem, clearedList, synced, error, warn */ function logMsg($message, $level = "default") { $colors = new Colors(); $fg = null; $bg = null; switch ($level) { case 'userConnected': $fg = null; $bg = "cyan"; break; case 'userDisconnected': $fg = "cyan"; $bg = "black"; break; case 'addedItem': $fg = "black"; $bg = "green"; break; case 'updatedItem': $fg = "light_gray"; $bg = "green"; break; case 'clearedList': $fg = "light_gray"; $bg = "black"; break; case 'removedItem': $fg = "yellow"; $bg = "black"; break; case 'error': $fg = "white"; $bg = "red"; break; case 'warn': $fg = "brown"; $bg = "magenta"; break; case 'sync': $fg = "light_green"; $bg = "blue"; break; default: break; } echo $colors->getColoredString($message, $fg, $bg) . "\n"; }
/** * Handles rendering strings. If extra scalar arguments are given after the `$msg` * the string will be rendered with `sprintf`. If the second argument is an `array` * then each key in the array will be the placeholder name. Placeholders are of the * format {:key}. * * @param string $msg The message to render. * @param mixed ... Either scalar arguments or a single array argument. * @return string The rendered string. */ public static function render($msg) { $args = func_get_args(); // No string replacement is needed if (count($args) == 1) { return Colors::colorize($msg); } // If the first argument is not an array just pass to sprintf if (!is_array($args[1])) { // Colorize the message first so sprintf doesn't bitch at us $args[0] = Colors::colorize($args[0]); return call_user_func_array('sprintf', $args); } // Here we do named replacement so formatting strings are more understandable foreach ($args[1] as $key => $value) { $msg = str_replace('{:' . $key . '}', $value, $msg); } return Colors::colorize($msg); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Colors the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Colors::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Show a nice list of statistics such as the amount of requirements, failed tests, etc. * * @author Yorick Peterse * @access Private * @static * @return Void */ private static function show_statistics() { $tests = Colors::blue("Tests: " . self::$statistics['tests']); $failed = Colors::red("Failed: " . self::$statistics['tests_failed']); $success = Colors::green("Success: " . (self::$statistics['tests'] - self::$statistics['tests_failed'])); $reqs = "Requirements: " . self::$statistics['requirements']; puts(PHP_EOL . "{$reqs} | {$tests} | {$success} | {$failed}"); }
/** * Formats $text according to the formater's options * * @param string $text */ public function format($text) { $lines = explode("\n", $text); foreach ($lines as &$line) { $line = (string) $this->quote . str_repeat(' ', $this->indent * $this->indentWidth) . $line; } return Colors::colorize(implode("\n", $lines), $this->fgColor, $this->bgColor); }
<?php /* * This file is part of the Nexylan packages. * * (c) Nexylan SAS <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ ini_set('memory_limit', '512M'); require_once __DIR__ . '/vendor/autoload.php'; // We are Gentoo users, we love color in bash shell :) $colors = new Colors(); // Detect more than 10000 consecutive characters on first line function detect_obfuscated($filecontent) { $weirdlength = 1000; //if (isset($filecontent[1]) && strlen($filecontent[1]) > $weirdlength && preg_match("/[A-Za-z0-9\\\]{$weirdlength}/",$filecontent[1])) { // If a line contains more than 10,000 characters, write it to stdout for ($line = 0; $line <= 1; ++$line) { if (isset($filecontent[$line]) && strlen($filecontent[$line]) > $weirdlength) { // If a line contains more than 10,000 characters, write it to stdout return true; } } return false; } // Detect eval functions on first line function detect_onelineshell($filecontent) { $lines = 3;
if (isset($this->background_colors[$background_color])) { $colored_string .= "[" . $this->background_colors[$background_color] . "m"; } // Add string and end coloring $colored_string .= $string . "[0m"; return $colored_string; } // Returns all foreground color names public function getForegroundColors() { return array_keys($this->foreground_colors); } // Returns all background color names public function getBackgroundColors() { return array_keys($this->background_colors); } } ?> <?php //Colors class basic usage examples // Create new Colors class $colors = new Colors(); // Test some basic printing with Colors class echo $colors->getColoredString("Testing Colors class, this is purple string on yellow background.", "purple", "yellow") . "\n"; echo $colors->getColoredString("Testing Colors class, this is blue string on light gray background.", "blue", "light_gray") . "\n"; echo $colors->getColoredString("Testing Colors class, this is red string on black background.", "red", "black") . "\n"; echo $colors->getColoredString("Testing Colors class, this is cyan string on green background.", "cyan", "green") . "\n"; echo $colors->getColoredString("Testing Colors class, this is cyan string on default background.", "cyan") . "\n"; echo $colors->getColoredString("Testing Colors class, this is default string on cyan background.", null, "cyan") . "\n";
/** * Colorizes a specific parts of a text, which are matched by search_regexp. * * @param string * @param string regexp * @param mixed|string|array * @param string $text * @param string $search_regexp * @param string $color */ public static function colorizePart($text, $search_regexp, $color) { $callback = function ($matches) use($color) { return Colors::write($matches[1], $color); }; $ansi_text = preg_replace_callback("/({$search_regexp})/", $callback, $text); return is_null($ansi_text) ? $text : $ansi_text; }
function cb_temp($temperature) { $temperature /= 10.0; static $temps = array(); static $times = array(); static $bingsBad = 0; static $bingsGood = 0; $temps[] = $temperature; $times[] = time(); if (count($temps) > 600) { array_shift($temps); array_shift($times); } $maxK = null; $maxV = 0; foreach ($temps as $k => $v) { if ($v > $maxV) { $maxK = $k; $maxV = $v; } } $temperature = floor($temperature); system('clear'); $trend = "▬"; if (count($temps) > 3) { $v = leastSquareFit(array_slice($temps, -30)); if ($v > 0) { $trend = "▲"; } if ($v <= 0) { $trend = "▼"; } } $t = " " . date("H:i:s") . ": " . str_pad($temperature, 5, " ", STR_PAD_LEFT) . " °C {$trend} "; $C = new Colors(); if ($temperature < 80) { echo $C->getColoredString($t, "white", "red"); if ($bingsBad < 3) { exec('play /usr/share/sounds/KDE-Sys-Log-Out.ogg > /dev/null 2>&1'); } $bingsGood = 0; $bingsBad++; } else { echo $C->getColoredString($t, "green", "black"); if ($bingsGood < 1) { exec('play /usr/share/sounds/KDE-Sys-App-Positive.ogg > /dev/null 2>&1'); } $bingsBad = 0; $bingsGood++; } echo "\n Max: " . date("H:i:s", $times[$maxK]) . ": " . $maxV . " °C"; }
static function ReplaceColors($_html, $_operator) { $primary = Communication::ReadParameter("ovlc", "#73be28"); $secondary = Communication::ReadParameter("ovlct", "#ffffff"); $textshadow = Communication::ReadParameter("ovlts", 1); //$textheader = Communication::ReadParameter("ovlch","#ffffff"); $_html = str_replace("<!--bgc-->", $primary, $_html); $_html = str_replace("<!--bgcm-->", Colors::TransformHEX($primary, 30), $_html); $_html = str_replace("<!--bgcd-->", Colors::TransformHEX($primary, 50), $_html); $_html = str_replace("<!--tc-->", $secondary, $_html); $_html = str_replace("<!--tch-->", $secondary, $_html); $_html = str_replace("<!--ts-->", $textshadow == 1 ? "text-shadow:1px 1px 0 #6b6b6b;" : "", $_html); return str_replace("<!--color-->", $_operator ? Colors::TransformHEX($secondary, 20) : "#000000", $_html); }
/** * Renders a row for output. * * @param array $row The table row. * @return string The formatted table row. */ protected function renderRow(array $row) { $render = '|'; foreach ($row as $column => $val) { $render .= ' ' . Colors::pad($val, $this->_width[$column]) . ' |'; } return $render; }
/** * An encoding-safe way of padding string length for display * * @param string $string The string to pad * @param int $length The length to pad it to * @return string */ function safe_str_pad($string, $length) { $cleaned_string = Colors::shouldColorize() ? Colors::decolorize($string) : $string; // Hebrew vowel characters $cleaned_string = preg_replace('#[\\x{591}-\\x{5C7}]+#u', '', $cleaned_string); if (function_exists('mb_strwidth') && function_exists('mb_detect_encoding')) { $real_length = mb_strwidth($cleaned_string, mb_detect_encoding($string)); } else { $real_length = safe_strlen($cleaned_string); } $diff = strlen($string) - $real_length; $length += $diff; return str_pad($string, $length); }
{ $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); // Uncomment one of the following alternatives // $bytes /= pow(1024, $pow); $bytes /= 1 << 10 * $pow; return round($bytes, $precision) . ' ' . $units[$pow]; } // Show progress declare (ticks=100000); $GStatusText = ''; $GStatusTextColor = 'light_green'; $GTimeTextColor = 'red'; $GColors = new Colors(); register_tick_function(function () { global $GStatusText; global $GStatusTextColor; global $GTimeTextColor; global $GColors; if (!$GStatusText) { return; } static $timer = null; if (!$timer) { $timer = new Timer(1); } static $lastTimePhaseChanged = 0; if (!$lastTimePhaseChanged) { $lastTimePhaseChanged = microtime(1);
{ $this->_colors = $arr; } public function fetch() { $color = each($this->_colors); if ($color) { return $color['value']; } else { reset($this->_colors); return false; } } } $arr = array("blue", "red", "green", "orange", "white"); $obj = new Colors($arr); while (($c = $obj->fetch()) != false) { echo $c . "<br/>"; } class Colors2 implements Iterator { private $_colors = array(); public function __construct($arr) { $this->_colors = $arr; $this->n = count($arr); } public function rewind() { $this->start = 0; }
/** * @param int $count * * @return string */ public static function generateSampleProducts($count = 10) { // Type $typeIds = Producttype::getIdsOrCreateDummy(); // category $categoryIds = Productcategory::getIdsOrCreateSampelData(); // unit berat $unitIds = Units::getIdsOrCreateSampleUnits(); // parent_id $parentId = 0; $fake = static::getFake(); // // Buat Product $catId = $fake->getFake()->randomElement($categoryIds); $typeId = $fake->getFake()->randomElement($typeIds); $unitWeightId = $fake->getFake()->randomElement($unitIds); $unitWidthId = $fake->getFake()->randomElement($unitIds); $supplierIds = Suppliers::getRecordIdsOrCreate(); $currencyIds = Currencies::getIdsOrCreateSample(); // color $colorIds = Colors::getIdsOrCreate(); // gradeIds $gradeIds = Fabricgrade::getIdsOrCreate(); $productIds = array(); for ($rec = 0; $rec < $count; $rec++) { $product = $fake->getProduct()->product($catId, $typeId, $unitWeightId, $unitWidthId, $parentId, '\\Emayk\\Ics\\Repo\\Productcategory\\Productcategory'); $record = static::createRecord($product); $productId = $record->id; $productIds[] = $productId; // Image/ Photo Product $imagesIds[] = Images::getIdsOrCreate($productId, '\\Emayk\\Ics\\Repo\\Products\\Products'); // Supplier Product // Product Supplier (Product dapat dari Supplier mana ?) $supplierId = $fake->getFake()->randomElement($supplierIds); $supplierProduct = Productsuppliers::create(array('master_product_id' => $productId, 'master_supplier_id' => $supplierId)); $supplierProductId = $supplierProduct->id; // Create Detail // Buat Product Detail $unitId = $fake->getFake()->randomElement($unitIds); $colorId = $fake->getFake()->randomElement($colorIds); $gradeId = $fake->getFake()->randomElement($gradeIds); $currSp = $fake->getFake()->randomElement($currencyIds); $currSpm = $fake->getFake()->randomElement($currencyIds); $detailIds[] = Productdetails::getIdOrCreate($productId, $colorId, $unitId, $gradeId, $currSp, $currSpm); //Buat Stock // Buat Stock $stockIds[] = Stockproducts::createStock($productId); } foreach ($stockIds as $stockId) { for ($history = 0; $history < 9; $history++) { // Buat Stock Detail/History277 if ($history % 2 == 0 || $history == 0) { $typeHistory = 'in'; } else { $typeHistory = 'out'; } $firstHistory = $history == 0; // $stockHistoryIds[] = Stockproducthistory::createHistoryStockSample($stockId, $typeHistory, $firstHistory); } } return "Sudah Generate sebanyak " . count($productIds) . " records"; return s($productIds, $supplierProductId, $imagesIds, $detailIds); }
public function logSeparator() { $colors = new Colors(); $message = $colors->getColoredString("\n\n------------------------------------------------------------", "white", "black") . ' '; $this->log($message); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { if (!$id) { return Redirect::route('colors.index')->with('error', 'Please provide color id'); } $color = Colors::find($id); if (empty($color)) { return Redirect::route('colors.index')->with('error', 'Colour not found'); } Colors::destroy($id); return Redirect::route('colors.index')->with('success', 'Colour deleted successfully'); }
$html = str_replace("<!--function_knowledgebase-->", To::BoolString(empty($_GET["hfk"]) && !empty(Server::$Configuration->File["gl_knba"])), $html); $html = str_replace("<!--hide_group_select_chat-->", To::BoolString(Communication::GetParameter("hcgs", 0, $nu, FILTER_VALIDATE_INT) == "1" || !empty($_GET[GET_EXTERN_DYNAMIC_GROUP])), $html); $html = str_replace("<!--hide_group_select_ticket-->", To::BoolString(Communication::GetParameter("htgs", 0, $nu, FILTER_VALIDATE_INT) == "1"), $html); $html = str_replace("<!--require_group_selection-->", To::BoolString(Communication::GetParameter("rgs", 0, $nu, FILTER_VALIDATE_INT) == "1"), $html); $html = str_replace("<!--offline_message_pop-->", To::BoolString(!empty(Server::$Configuration->File["gl_om_pop_up"]) || empty(Server::$Configuration->File["gl_om_mode"])), $html); $html = str_replace("<!--dynamic_group-->", !empty(VisitorChat::$DynamicGroup) ? base64_encode(Server::$Groups[VisitorChat::$DynamicGroup]->Descriptions["EN"]) : "", $html); } else { if ($_GET[GET_EXTERN_TEMPLATE] == "lz_chat_frame_lgin") { $html = IOStruct::GetFile(PATH_FRAMES . $_GET[GET_EXTERN_TEMPLATE] . ".tpl"); $html = isset(Server::$Configuration->File["gl_site_name"]) ? str_replace("<!--config_name-->", Server::$Configuration->File["gl_site_name"], $html) : str_replace("<!--config_name-->", "LiveZilla", $html); $html = getChatLoginInputs($html, MAX_INPUT_LENGTH); $html = str_replace("<!--alert-->", getAlertTemplate(), $html); $html = str_replace("<!--com_chats-->", getChatVoucherTemplate(), $html); $html = str_replace("<!--ssl_secured-->", Communication::GetScheme() == SCHEME_HTTP_SECURE && !empty(Server::$Configuration->File["gl_sssl"]) ? "" : "display:none;", $html); $html = str_replace("<!--bgc-->", $color = Communication::ReadParameter("epc", "#73be28"), $html); $html = str_replace("<!--color-->", Colors::TransformHEX($color, 30), $html); } else { if ($_GET[GET_EXTERN_TEMPLATE] == "lz_chat_frame_chat") { $html = IOStruct::GetFile(PATH_FRAMES . $_GET[GET_EXTERN_TEMPLATE] . ".tpl"); $html = str_replace("<!--alert-->", getAlertTemplate(), $html); $tlanguages = ""; if (strlen(Server::$Configuration->File["gl_otrs"]) > 1) { $mylang = LocalizationManager::GetBrowserLocalization(); $tlanguages = getLanguageSelects(LocalizationManager::GetBrowserLocalization()); } $html = str_replace("<!--languages-->", $tlanguages, $html); Server::InitDataBlock(array("GROUPS")); $groupid = $_POST["intgroup"]; if (!empty($groupid) && isset(Server::$Groups[$groupid])) { $html = str_replace("<!--SM_HIDDEN-->", empty(Server::$Groups[$groupid]->ChatFunctions[0]) ? "none" : "", $html); $html = str_replace("<!--SO_HIDDEN-->", empty(Server::$Groups[$groupid]->ChatFunctions[1]) ? "none" : "", $html);
public function printColorArray($color_ary) { $s = ''; $clr = new Colors(); foreach ($color_ary as $i => $ct) { foreach ($ct as $color => $text) { if (!empty($text)) { if ($color == 'gray') { $color = null; } $s .= $clr->getColoredString($text, $color, 'black'); } } } return $s; }
<?php include __DIR__ . '/clicolors.php'; $colors = new Colors(); $db = new PDO("pgsql:host=localhost;port=5432;dbname=dragonnet;user=moodle;password=helloworld"); var_dump($db); $filename = '/Users/Anthony/Desktop/Library Exports/Secondary All.csv'; $file = file_get_contents($filename); $lines = explode("\n", $file); $outputFilename = '/Users/Anthony/Desktop/Library Exports/Secondary All Wrong.csv'; $outputFile = fopen($outputFilename, "w+"); foreach ($lines as $lineNumber => $line) { $fields = explode(',', $line); foreach ($fields as &$field) { $field = trim($field, '"'); } if (stripos($fields[9], 'Student') === false) { continue; } if (substr($fields[0], 0, 2) !== 'P ') { $str = "\nInvalid barcode format: Line " . $lineNumber . " '" . $fields[0] . "'"; fwrite($outputFile, "\n" . $line); echo $colors->getColoredString($str, 'red'); continue; } $idnumber = substr($fields[0], 2); $q = $db->prepare('SELECT * FROM ssismdl_user WHERE idnumber = ?'); $q->execute(array($idnumber)); if ($user = $q->fetch(PDO::FETCH_OBJ)) { $str = "\nBarcode {$fields[0]} matches DragonNet user " . $user->username; echo $colors->getColoredString($str, 'green');
public static function debug($msg, $ns = "") { self::log(Colors::getInstance()->green('[DEBUG]'), $msg, $ns, null); }