function do_minify($content) { global $config; $c = File::open(__DIR__ . DS . 'states' . DS . 'config.txt')->unserialize(); $url = $config->protocol . $config->host; // Minify HTML if (isset($c['html_minifier'])) { $config->html_minifier = true; Config::set('html_minifier', $config->html_minifier); $content = Converter::detractSkeleton($content); } // Minify URL if (isset($c['url_minifier']) && Text::check($content)->has('="' . $url)) { $content = str_replace(array('="' . $url . '"', '="' . $url . '/', '="' . $url . '?', '="' . $url . '#'), array('="/"', '="/', '="?', '="#'), $content); } // Minify Embedded CSS if (isset($c['css_minifier'])) { $content = preg_replace_callback('#<style(>| .*?>)([\\s\\S]*?)<\\/style>#i', function ($matches) use($config, $c, $url) { $css = Converter::detractShell($matches[2]); if (isset($c['url_minifier'])) { $css = preg_replace('#(?<=[\\s:])(src|url)\\(' . preg_quote($url, '/') . '#', '$1(', $css); } return '<style' . $matches[1] . $css . '</style>'; }, $content); } // Minify Embedded JavaScript if (isset($c['js_minifier'])) { $content = preg_replace_callback('#<script(>| .*?>)([\\s\\S]*?)<\\/script>#i', function ($matches) { $js = Converter::detractSword($matches[2]); return '<script' . $matches[1] . $js . '</script>'; }, $content); } return $content; }
public function testConvert() { $inputData = new \DOMDocument(); $inputData->load(__DIR__ . '/_files/api.xml'); $expectedResult = (require __DIR__ . '/_files/api.php'); $this->assertEquals($expectedResult, $this->_model->convert($inputData)); }
public function testConvert() { $document = new \DOMDocument(); $document->load(__DIR__ . '../../../_files/search_request.xml'); $result = $this->object->convert($document); $expected = (include __DIR__ . '/../../_files/search_request_config.php'); $this->assertEquals($expected, $result); }
/** * @inheritdoc */ public function toWindows() { $result = array(); foreach ($this->getInput() as $row) { $rowConverter = new Converter($row, $this->getBaseEncodings()); $result[] = $rowConverter->toWindows(); } return $result; }
/** * ========================================================== * DATE AGO CALCULATOR * ========================================================== * * -- CODE: ------------------------------------------------- * * $input = '2014-05-30 09:22:42'; * * var_dump(Date::ago($input)); * * ---------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------- | ----------------------------------- * $input | mixed | The date input * $output | string | Optional to output single data * $compact | boolean | Remove empty leading offset(s)? * --------- | ------- | ----------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function ago($input, $output = null, $compact = true) { $speak = Config::speak(); $date = new DateTime(); $date->setTimestamp((int) self::format($input, 'U')); $interval = $date->diff(new DateTime('now')); $time = $interval->format('%y.%m.%d.%h.%i.%s'); $time = explode('.', $time); $time = Converter::strEval($time); $data = array($speak->year . '|' . $speak->years => $time[0], $speak->month . '|' . $speak->months => $time[1], $speak->day . '|' . $speak->days => $time[2], $speak->hour . '|' . $speak->hours => $time[3], $speak->minute . '|' . $speak->minutes => $time[4], $speak->second . '|' . $speak->seconds => $time[5]); if ($compact) { foreach ($data as $k => $v) { if ($offset === 0) { unset($data[$k]); } else { break; } } } $results = array(); foreach ($data as $k => $v) { $text = explode('|', $k); $results[strtolower($text[0])] = $v . ' ' . ($v === 1 ? $text[0] : $text[1]); } unset($data); return !is_null($output) ? $results[$output] : $results; }
protected static function create($array, $indent = "", $FP = "", $i = 0) { $c_url = Config::get('url'); $c_url_current = Config::get('url_current'); $c_element = self::$config; $c_class = $c_element['classes']; $html = $indent . str_repeat(TAB, $i) . '<' . $c_element[$i === 0 ? 'trunk' : 'branch'] . ($i === 0 ? $c_class['trunk'] !== false ? ' class="' . $c_class['trunk'] . '"' : "" : ($c_class['branch'] !== false ? ' class="' . sprintf($c_class['branch'], $i / 2) . '"' : "")) . '>' . NL; foreach ($array as $key => $value) { if (!is_array($value)) { $url = Converter::url($value); $hole = $value === "" ? ' ' . $c_class['chink'] : ""; $current = $url === $c_url_current || $url !== $c_url && strpos($c_url_current . '/', $url . '/') === 0 ? ' ' . $c_class['current'] : ""; $c = trim(($c_class['twig'] !== false ? $c_class['twig'] : "") . $hole . $current); $twig = '<' . $c_element['twig'] . ($c ? ' class="' . $c . '"' : "") . '>'; if ($value !== "") { // List item without link: `array('foo')` if (is_int($key)) { $twig .= Filter::colon($FP . 'anchor', '<span class="a">' . $value . '</span>'); // List item without link: `array('foo' => null)` } else { if (is_null($value)) { $twig .= Filter::colon($FP . 'anchor', '<span class="a">' . $key . '</span>'); // List item with link: `array('foo' => '/')` } else { $url = Filter::colon($FP . 'url', $url); $twig .= Filter::colon($FP . 'anchor', '<a href="' . $url . '">' . $key . '</a>'); } } } $s = explode(' ', $c_element['twig']); $s = $s[0]; $html .= $indent . str_repeat(TAB, $i + 1) . Filter::colon($FP . 'twig', $twig . '</' . $s . '>', $i + 1) . NL; } else { // `text (path/to/url)` if (preg_match('#^\\s*(.*?)\\s*\\((.*?)\\)\\s*$#', $key, $match)) { $_key = $match[1]; $_value = trim($match[2]) !== "" ? Converter::url($match[2]) : '#'; } else { $_key = $key; $_value = null; } $url = Filter::colon($FP . 'url', $_value); $s = explode(' ', $c_element['branch']); $s = ' ' . $s[0]; $current = $url === $c_url_current || $url !== $c_url && strpos($c_url_current . '/', $url . '/') === 0 ? ' ' . $c_class['current'] : ""; $c = trim(($c_class['twig'] !== false ? $c_class['twig'] : "") . $current . $s); $twig = '<' . $c_element['twig'] . ($c ? ' class="' . $c . '"' : "") . '>'; $twig .= NL . $indent . str_repeat(TAB, $i + 2); $twig .= Filter::colon($FP . 'anchor', $_value !== null ? '<a href="' . $url . '">' . $_key . '</a>' : '<span class="a">' . $_key . '</span>'); $twig .= NL . self::create($value, $indent, $FP, $i + 2); $twig .= $indent . str_repeat(TAB, $i + 1); $s = explode(' ', $c_element['twig']); $s = $s[0]; $html .= $indent . str_repeat(TAB, $i + 1) . Filter::colon($FP . 'twig', $twig . '</' . $s . '>', $i + 1) . NL; } } $s = explode(' ', $c_element[$i === 0 ? 'trunk' : 'branch']); $s = $s[0]; return Filter::colon($FP . 'branch', rtrim($html, NL) . (!empty($array) ? NL . $indent . str_repeat(TAB, $i) : "") . '</' . $s . '>', $i) . NL; }
/** * ========================================================== * DATE AGO CALCULATOR * ========================================================== * * -- CODE: ------------------------------------------------- * * $input = '2014-05-30 09:22:42'; * * var_dump(Date::ago($input)); * * ---------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------- | ----------------------------------- * $input | mixed | The date input * $output | string | Optional to output single data * $compact | boolean | Remove empty leading offset(s)? * --------- | ------- | ----------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function ago($input, $output = null, $compact = true) { $speak = Config::speak(); $date = new DateTime(); $date->setTimestamp((int) self::format($input, 'U')); $interval = $date->diff(new DateTime('now')); $time = $interval->format('%y.%m.%d.%h.%i.%s'); $time = explode('.', $time); $time = Converter::strEval($time); $data = array('year' => $time[0], 'month' => $time[1], 'day' => $time[2], 'hour' => $time[3], 'minute' => $time[4], 'second' => $time[5]); if ($compact) { foreach ($data as $k => $v) { if ($v === 0) { unset($data[$k]); } else { break; } } } $results = array(); foreach ($data as $k => $v) { $text = array($speak->{$k}, $speak->{$k . 's'}); $results[$k] = $v . ' ' . ($v === 1 ? $text[0] : $text[1]); } unset($data); return !is_null($output) ? $results[$output] : $results; }
public function authenticate() { $db = $this->db; $session = new Zend_Session_Namespace("LeadsChat_Auth"); $username = $this->_request->getPost("username"); $password = $this->_request->getPost("password"); //authenticate using Zend Auth try { $this->_auth->setTableName("agents"); $this->_auth->setCredentialTreatment("MD5(?) AND active = 'Y'"); $authResult = $this->_auth->setCredential($password)->setIdentity($username)->authenticate(); $agent = $this->_auth->getResultRowObject(null, "password"); $agent = Converter::object_to_array($agent); if ($agent) { $session->agent_id = $agent["agent_id"]; $session->agent = $agent; //look for available agent availability $available_agent = $db->fetchRow($db->select()->from("available_agents", array("available_agent_id"))->where("agent_id = ?", $session->agent_id)); if ($available_agent) { $db->update("available_agents", array("available" => "Y", "currently_served" => 0, "updated" => date("Y-m-d h:i:s"))); } else { $db->insert("available_agents", array("available" => "Y", "currently_served" => 0, "updated" => date("Y-m-d h:i:s"), "agent_id" => $agent["agent_id"])); } return true; } else { return false; } } catch (Exception $e) { return false; } }
public function toHtml(array $data) { $html = "<div class='row'>"; // echo "<pre>"; // print_r($data); // die(); foreach ($data['columns'] as $column) { $html .= "<div class='col-md-" . $column['width'] . "'>"; $converter = new Converter(); $HTMLContent = $converter->toHtml(json_encode(array("data" => $column["blocks"]))); $html .= $HTMLContent; $html .= "</div>"; } $html .= "</div>"; return $html; }
public function authenticate() { $session = new Zend_Session_Namespace("LeadsChat_Owner_Auth"); $username = $this->_request->getPost("username"); $password = $this->_request->getPost("password"); $rememberMe = $this->_request->getPost("remember_me"); try { $this->_auth->setTableName("owners")->setIdentity($username)->setCredential($password)->setCredentialTreatment("MD5(?) AND activated = 'Y' AND approved = 'Y'"); $authResult = $this->_auth->authenticate(); if ($authResult->isValid()) { $owner = $this->_auth->getResultRowObject(null, "password"); $owner = Converter::object_to_array($owner); $session->owner_id = $owner["owner_id"]; $session->owner = $owner; $dataToLog["owner_name"] = $owner["first_name"] . " " . $owner["last_name"]; $dataToLog["owner_id"] = $owner["owner_id"]; Mongo_Logger::logEvent($dataToLog, Mongo_Logs_LogFactory::LoginOwner, Mongo_Interface::LOGS); if ($rememberMe) { $cookie = new Zend_Http_Cookie("userid", $sessionAgent->owner_id, $_SERVER["SERVER_NAME"]); } return true; } else { return false; } } catch (Exception $e) { return false; } }
public static function convertToMo($source, $destination) { Converter::admin_clear_cache(); $shellCmd = 'msgfmt -cv -o ' . $destination . ' ' . $source . ' 2>&1'; $result = shell_exec($shellCmd); CakeLog::write('debug', 'Translation : ' . $result . 'Path : ' . $destination); }
public function actionGetCurrentQuestion() { $customer_id = $this->getParam('customer_id'); $flag = $this->getParam('flag'); $current_id = array(); if ($flag == 'today') { $current_id = 2; } else { $current_id = 1; } $question = Converter::convertModelToArray(HiQuestion::model()->findByPk($current_id)); $answers = Converter::convertModelToArray(HiQuestionAnswer::model()->with('customer')->findAllByAttributes(array('customer_id' => $customer_id, 'question_id' => $current_id))); if ($flag == 'today') { $question['has_answered'] = 0; $year = date('Y'); foreach ($answers as $k => $v) { if (strpos('date' . $v['insert_date'], $year)) { $question['has_answered'] = 1; } } } else { $question['has_answered'] = 1; } $question['answers'] = $answers; EchoUtility::echoMsgTF($question, '获取问题', $question); }
public static function get($param = null, $fallback = false, $str_eval = true) { if (is_null($param)) { return $_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET) && !empty($_GET) ? $str_eval ? Converter::strEval($_GET, false) : $_GET : $fallback; } $output = Mecha::GVR($_GET, $param, $fallback); return $output === '0' || !empty($output) ? $str_eval ? Converter::strEval($output, false) : $output : $fallback; }
public function testCheckDigit() { $this->assertEquals(8, Converter::calculateCheckDigit(14080, 12712721)); $this->assertEquals(1, converter::calculateCheckDigit(10000, 81111111)); $this->assertEquals(9, converter::calculateCheckDigit(10000, 80000001)); $this->assertEquals(5, converter::calculateCheckDigit(16150, 12233411)); $this->assertEquals(7, converter::calculateCheckDigit(10001, 10001)); }
/** * Create a new commonmark converter instance. * * @param array $config * @param Environment|null $environment */ public function __construct(array $config = [], Environment $environment = null) { if ($environment === null) { $environment = Environment::createCommonMarkEnvironment(); } $environment->mergeConfig($config); parent::__construct(new DocParser($environment), new HtmlRenderer($environment)); }
/** * Run the application to convert files. * * @param bool $hack */ public function run($hack) { $converter = new Converter(); foreach ($this->getIterator() as $fileinfo) { $fileName = $fileinfo[0]; $file = new File($fileName); $converter->convert($file, $hack); if (0 === strpos($fileName, $this->sourceFolder)) { $path = substr($fileName, strlen($this->sourceFolder)); $destinationFile = $this->destinationFolder . $path; $destinationFolder = pathinfo($destinationFile, PATHINFO_DIRNAME); if (!file_exists($destinationFolder)) { mkdir($destinationFolder, 0777, true); } file_put_contents($destinationFile, $file->getCode()); } } }
/** * Add a component to this layout * * @param array */ public function addComponent(array $component) { // is this component a numeric or associative array? if (Converter::isAssociativeArray($component)) { $this->components[] = $component; } else { $this->components = array_merge($this->components, $component); } }
public function actionGetArticleById() { $article_id = $this->getParam('article_id'); $customer_id = $this->getParam('customer_id'); $article = Converter::convertModelToArray(HiPushArticle::model()->with('sections')->findByPk($article_id)); $c = new CDbCriteria(); $c->addCondition("article_ids LIKE '%\"" . (int) $article_id . "\"%' and customer_id = " . $customer_id); $article['is_favourite'] = HiPushArticleFavourite::model()->count($c); EchoUtility::echoMsgTF(1, '获取文章', $article); }
/** * * @param string $from_encoding * @param string $to_encoding * * @return EncodingConverter */ public static function create($from_encoding, $to_encoding) { $from_encoding = (string) $from_encoding; $to_encoding = (string) $to_encoding; if (strtolower($from_encoding) == strtolower($to_encoding)) { return Converter::identity(); } else { return new self($from_encoding, $to_encoding); } }
function do_shortcode_php($content) { if (strpos($content, '{{php}}') === false) { return $content; } global $config, $speak; return preg_replace_callback('#(?<!`)\\{\\{php\\}\\}(?!`)([\\s\\S]*?)(?<!`)\\{\\{\\/php\\}\\}(?!`)#', function ($matches) use($config, $speak) { return Converter::phpEval($matches[1], array('config' => $config, 'speak' => $speak)); }, $content); }
public static function content($data = "") { if ($data === false) { $data = ""; } // Restrict user(s) from inputting the `SEPARATOR` constant // to prevent mistake(s) in parsing the file content $data = Converter::ES($data); self::$bucket_alt = trim(self::$bucket_alt) !== "" && is_null(self::$open) ? trim(self::$bucket_alt) . (trim($data) !== "" ? "\n\n" . SEPARATOR . "\n\n" . $data : "") : $data; return new static(); }
public static function decode($text, $textType = "") { if (is_object($text)) { return $text; } $textType = Converter::initTextType($textType); if ($textType == Converter::HTML) { return $text; } return String::htmlDecode($text); }
/** * Displays the results in human readable format with pre tags, or returns the information. * @param boolean $return If true, information will be returned rather than printed. * @return mixed When the <i>return</i> parameter is true, this function will return a string. */ public function debug($return = false) { $data = array("Runtime" => $this->getTime() . " seconds", "MemoryStartUsage" => Converter::fromBytes($this->getMemoryStartUsage(), 2), "MemoryCurrentUsage" => Converter::fromBytes($this->getMemoryCurrentUsage(), 2), "MemoryPeakUsage" => Converter::fromBytes($this->getMemoryPeakUsage(), 2, "GB")); if ($return) { return print_r($data, true); } else { echo "<pre>"; print_r($data); echo "</pre>"; } }
public function convertFile($htmlFileName, $phpFileName = '') { $htmlContent = file_get_contents($htmlFileName); if ($htmlContent) { if (!$phpFileName) { $phpFileName = $this->_makeOutputFilename($htmlFileName, $htmlContent); } $result = $this->_converter->convert($htmlContent, $this->_makeTestName($htmlFileName), $this->_tplFile); file_put_contents($phpFileName, $result); print $phpFileName . "\n"; } }
public function search($params) { $category = new CategoryModel(); $result = $category->request($params); $output = ""; if (!empty($params["output"])) { $output = $params["output"]; } $html = Converter::generate($result, $output); Header::append($result["status"]["code"]); Header::append($output); echo $html; }
protected function _getData($file) { $configFilename = $file->getAbsolutePath(); $data = Tools::loadConfig($configFilename, 'xml'); $properties = $this->project->getProperties(); foreach ($properties as $key => &$value) { $value = $this->project->getProperty($key); } $phingData = Converter::ini2array($properties); Converter::normalizeForXml($phingData); $data['config']['phing'] = $phingData; $result = $data; return $result; }
public static function convert($method, $value) { switch ($method) { case 'lowercase': $value = self::tolower($value, 'UTF-8'); break; case 'uppercase': $value = self::toupper($value, 'UTF-8'); break; case 'capitalize': $value = self::ucfirst($value); break; case 'capitalize_words': $value = self::ucwords($value); break; case 'absolute': $value = abs($value); break; case 'remove_accents': $value = self::removeAccents($value); break; case 'remove_accents_lowercase': $value = self::tolower(Converter::removeAccents($value), 'UTF-8'); break; case 'remove_accents_uppercase': $value = self::toupper(Converter::removeAccents($value), 'UTF-8'); break; case 'remove_accents_capitalize': $value = self::ucfirst(Converter::removeAccents($value)); break; case 'remove_accents_capitalize_words': $value = self::ucwords(Converter::removeAccents($value)); break; case 'as_bool': $value = (bool) $value; break; case 'as_int': $value = (int) $value; break; case 'as_float': $value = (double) $value; break; case 'as_string': $value = (string) $value; break; default: break; } return $value; }
public function getRoutejson($_routeid) { require '/var/www/db-init-climb.php'; require 'Comment.class.php'; $comment = new Comment(); $stmt = $db->prepare("SELECT RouteId, Name, Grade, Description \n FROM Route \n WHERE RouteId=:routeid"); $stmt->execute([':routeid' => $_routeid]); $data = $stmt->fetch(PDO::FETCH_ASSOC); $data['Grade'] = preg_replace('/-/', '', parent::unConvert($data['Grade'])); $muuttuja = $comment->getComments($_routeid, 'route'); $muuttuja = $muuttuja->fetchAll(); $data['Image'] = $this->loadRoutePic($_routeid); $data['Comments'] = $muuttuja; echo json_encode($data); }
public static function Array2XML($data, &$xml_data) { foreach ($data as $key => $value) { if (is_array($value)) { if (is_numeric($key)) { $key = 'user'; //dealing with <0/>..<n/> issues } $subnode = $xml_data->addChild($key); Converter::Array2XML($value, $subnode); } else { $xml_data->addChild("{$key}", htmlspecialchars("{$value}")); } } }
function IFrameBox(&$root, $pipeline) { $this->InlineBlockBox(); // If NO src attribute specified, just return. if (!$root->has_attribute('src') || trim($root->get_attribute('src')) == '') { return; } // Determine the fullly qualified URL of the frame content $src = $root->get_attribute('src'); $url = $pipeline->guess_url($src); $data = $pipeline->fetch($url); /** * If framed page could not be fetched return immediately */ if (is_null($data)) { return; } /** * Render only iframes containing HTML only * * Note that content-type header may contain additional information after the ';' sign */ $content_type = $data->get_additional_data('Content-Type'); $content_type_array = explode(';', $content_type); if ($content_type_array[0] != "text/html") { return; } $html = $data->get_content(); // Remove control symbols if any $html = preg_replace('/[\\x00-\\x07]/', "", $html); $converter = Converter::create(); $html = $converter->to_utf8($html, $data->detect_encoding()); $html = html2xhtml($html); $tree = TreeBuilder::build($html); // Save current stylesheet, as each frame may load its own stylesheets // $pipeline->pushCSS(); $css =& $pipeline->getCurrentCSS(); $css->scan_styles($tree, $pipeline); $frame_root = traverse_dom_tree_pdf($tree); $box_child =& create_pdf_box($frame_root, $pipeline); $this->add_child($box_child); // Restore old stylesheet // $pipeline->popCSS(); $pipeline->pop_base_url(); }