Copyright 2008- Samuli Järvelä Released under GPL License. License: http://www.mollify.org/license.php
Exemple #1
0
 /**
  * generate
  *
  */
 public function generate()
 {
     $this->out('Generate .cake ...');
     $d = new Dotcake(APP, App::paths(), CAKE_CORE_INCLUDE_PATH);
     $contents = json_encode($d->generate());
     if (array_key_exists('format', $this->params)) {
         $format = $this->params['format'];
         switch ($format) {
             case 'tab':
                 $formatter = new Formatter();
                 $contents = $formatter->reformat($contents);
                 break;
             case 'ws':
                 // no break
             // no break
             case 'whitespace':
                 // can use JSON_PRETTY_PRINT option since PHP5.4
                 $formatter = new Formatter('    ');
                 // 4 spaces
                 $contents = $formatter->reformat($contents);
                 break;
             default:
                 $this->out(__d('cake_console', "'{$format}' is invalid format option. You can use 'tab', 'ws' or 'whitespace' as option value."));
                 exit(0);
         }
     }
     $this->createFile(APP . '.cake', $contents);
 }
 /**
  * Affiche un block dans la commande
  * @param  string  $message       [description]
  * @param  [string]  $type          [description]
  * @param  [boolean] $force_display [description]
  * @return [type]                 [description]
  */
 protected function outputMessage($message, $type = 'info', $force_display = false)
 {
     if ($this->is_verbose || $force_display == true) {
         $messages = array($message);
         $formattedBlock = $this->formatter->formatBlock($messages, $type);
         $this->output->writeln($formattedBlock);
     }
     $this->log($message, $type);
 }
Exemple #3
0
 /**
  * Convert a date (number) to a database date representation (string).
  *
  * @param long dateTime The date (number)
  * @param boolean whether the returned string should be surrounted by quotes.
  * @return string
  */
 public static function convertDate($dateTime, $timeZone = 'GMT', $withQuotes = true)
 {
     if ($dateTime == null) {
         return $withQuotes ? "null" : null;
     }
     $format = new Formatter($timeZone);
     $sDate = $format->dateFormat($dateTime, "Y-m-d H:i:s");
     return $withQuotes ? "'{$sDate}'" : $sDate;
 }
 /**
  * Format the link.
  *
  * @param Link $link
  *
  * @return bool
  */
 public final function format(Link $link)
 {
     $formatted = $this->formatting($link);
     if (empty($formatted)) {
         // the link has not been formatted by this formatter, try next formatter
         if (!is_null($this->successor)) {
             $formatted = $this->successor->format($link);
         }
     }
     return $formatted;
 }
Exemple #5
0
function processor_folding($formatter, $value = "", $options = array())
{
    // unique id of the folding area
    $id = isset($GLOBALS['_folding_id_']) ? $GLOBALS['_folding_id_'] : 0;
    $id++;
    $GLOBALS['_folding_id_'] = $id;
    if ($value[0] == '#' and $value[1] == '!') {
        list($line, $value) = explode("\n", $value, 2);
    }
    $init_state = 'none';
    $title = _("More");
    $class = '';
    $opened = '';
    // parse args
    if (isset($line[0]) and ($p = strpos($line, ' ')) !== false) {
        $tag = substr($line, 0, $p);
        $args = substr($line, $p + 1);
        if (preg_match("/^(?:(open|\\+))?(?(1)[ ]*,[ ]*)?((?:(?:[a-zA-Z][a-z0-9_-]+)[ ]*)*)?(?(2)[ ]*,[ ]*)?/", $args, $matches)) {
            $class = isset($matches[2][0]) ? ' ' . $matches[2] : '';
            $tmp = substr($args, strlen($matches[0]));
            if (isset($tmp[0])) {
                $title = $tmp;
            }
            if ($matches[1] == 'open' or $matches[1] == '+') {
                $init_state = 'block';
                $opened = ' class="opened"';
            }
        }
    }
    // FIXME footnote prefix
    $fn_prefix = 'fn' . substr(md5(substr($value, 0, 32)), 0, 3);
    // allow wiki syntax in folding content
    ob_start();
    $params = array('notoc' => 1);
    $params['nosisters'] = 1;
    $f = new Formatter($formatter->page, $params);
    $f->foot_prefix = $fn_prefix;
    $f->get_javascripts();
    // trash default javascripts
    $f->pi['#linenum'] = 0;
    // do not use linenum
    $f->send_page($value, $params);
    $out = ob_get_contents();
    ob_end_clean();
    $onclick = " onclick=\"var f=document.getElementById('folding_{$id}');var s=f.style.display=='block';" . "f.style.display=s?'none':'block';this.className=s?'':'opened';\"";
    return <<<HERE
<div class="folding-area{$class}">
<dl class="folding">
<dt{$onclick}{$opened}>{$title}</dt>
<dd id="folding_{$id}" style="display:{$init_state};">{$out}</dd>
</dl>
</div>
HERE;
}
Exemple #6
0
function macro_WantedPages($formatter, $value = '')
{
    global $DBInfo;
    $pages = $DBInfo->getPageLists();
    $pagelinks = $formatter->pagelinks;
    // save
    $save = $formatter->sister_on;
    $formatter->sister_on = 0;
    $cache = new Cache_text("pagelinks");
    foreach ($pages as $page) {
        $dum = '';
        $p = new WikiPage($page);
        $f = new Formatter($p);
        $pi = $f->page->get_instructions($dum);
        if (in_array($pi['#format'], array('wiki', 'monimarkup'))) {
            continue;
        }
        $links = $f->get_pagelinks();
        if ($links) {
            $lns =& $links;
            foreach ($lns as $link) {
                if (!$link or $DBInfo->hasPage($link)) {
                    continue;
                }
                if ($link and !$wants[$link]) {
                    $wants[$link] = "[\"{$page}\"]";
                } else {
                    $wants[$link] .= " [\"" . $page . "\"]";
                }
            }
        }
    }
    $formatter->pagelinks = $pagelinks;
    // save
    $formatter->sister_on = $save;
    if (!count($wants)) {
        return '';
    }
    $pagelinks = $formatter->pagelinks;
    // save
    $formatter->sister_on = 0;
    asort($wants);
    $out = "<ul>\n";
    while (list($name, $owns) = each($wants)) {
        $owns = str_replace('<', '&lt;', $owns);
        $nowns = preg_replace_callback("/(" . $formatter->wordrule . ")/", array(&$formatter, 'link_repl'), $owns);
        $out .= "<li>" . $formatter->link_repl($name, htmlspecialchars($name)) . ": {$nowns}</li>";
    }
    $out .= "</ul>\n";
    $formatter->sister_on = $save;
    $formatter->pagelinks = $pagelinks;
    // save
    return $out;
}
 public function test_names()
 {
     $tests = array('smith' => 'Smith', 'sMith' => 'Smith', 'SMITH' => 'Smith', 'mr     extra   space' => 'Mr Extra Space', 'p smith' => 'P Smith', 'mr p smith' => 'Mr P Smith', 'mr. p. smith' => 'Mr. P. Smith', 'john smith' => 'John Smith', 'mcdonald' => 'McDonald', 'joy macdonald' => 'Joy Macdonald', 'robert MacDonald' => 'Robert MacDonald', 'Macon' => 'Macon', 'mcdoNald-SMYTHE' => 'McDonald-Smythe', 'smythe-Mcdonald' => 'Smythe-McDonald', 'von MacDonald iii' => 'von MacDonald III', "o'grady" => "O'Grady", "van o'grady" => "van O'Grady", "van o'grady jr." => "van O'Grady Jr.", 'de la rue' => 'de la Rue', 'de la rue 1st.' => 'de la Rue 1st.', 'ap DAVIs' => 'ap Davis', 'john ap davis' => 'John ap Davis', 'smythington-twistle' => 'Smythington-Twistle', 'smythington-twistle-de-groot' => 'Smythington-Twistle-De-Groot', 'mary-jo von syMington-mcDonald-twistle 3RD' => 'Mary-Jo von Symington-McDonald-Twistle 3rd', 'st john' => 'St John', 'st. john iV' => 'St. John IV');
     foreach ($tests as $input => $expected) {
         $this->assertEquals($expected, Formatter::name($input));
     }
 }
Exemple #8
0
 protected function getList()
 {
     $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_SETTINGS_DASHBOARD'), 'href' => $this->url->link('settings/dashboard')));
     $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_USERS_OVERVIEW')));
     // Initiate pagination
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     $data = array('start' => ($page - 1) * 25, 'limit' => 25);
     $user_total = $this->model_user_user->getTotalUsers();
     foreach ($this->model_user_user->getUsers($data) as $result) {
         $this->data['users'][] = array_merge($result, array('status' => $result['status'] ? Language::getVar('SUMO_NOUN_ENABLED') : Language::getVar('SUMO_NOUN_DISABLED'), 'date_added' => Formatter::date($result['date_added']), 'date_last_seen' => $result['date_last_seen'] != '0000-00-00 00:00:00' ? Formatter::date($result['date_last_seen']) : '&mdash;', 'edit' => $this->url->link('user/user/update', 'token=' . $this->session->data['token'] . '&user_id=' . $result['user_id'], 'SSL')));
     }
     $pagination = new Pagination();
     $pagination->total = $user_total;
     $pagination->page = $page;
     $pagination->limit = 25;
     $pagination->text = '';
     $pagination->url = $this->url->link('sale/return', 'token=' . $this->session->data['token'] . '&page={page}', 'SSL');
     $this->data = array_merge($this->data, array('pagination' => $pagination->renderAdmin(), 'insert' => $this->url->link('user/user/insert', 'token=' . $this->session->data['token'], 'SSL'), 'delete' => $this->url->link('user/user/delete', 'token=' . $this->session->data['token'], 'SSL'), 'u_users' => $this->url->link('user/user', 'token=' . $this->session->data['token'], 'SSL'), 'u_permissions' => $this->url->link('user/user_permission', 'token=' . $this->session->data['token'], 'SSL')));
     $this->template = 'user/user_list.tpl';
     $this->children = array('common/header', 'common/footer');
     $this->response->setOutput($this->render());
 }
 /**
  * Parses result of preg_match_all
  *
  * @return array
  */
 public function getPmaMatches()
 {
     $result['count'] = $this->pmaCount;
     $result['expr'] = Formatter::arrayToTree($this->pmaMatches[0]);
     $result['mtch'] = Formatter::arrayToTree($this->pmaMatches[1]);
     return $result;
 }
Exemple #10
0
 public function updateInvoice($invoiceID, $data)
 {
     // Delete invoice-lines and add 'em later again
     $this->query('DELETE FROM PREFIX_invoice_line WHERE invoice_id = :invoiceID', array('invoiceID' => $invoiceID));
     $this->query('DELETE FROM PREFIX_invoice_total WHERE invoice_id = :invoiceID', array('invoiceID' => $invoiceID));
     $totalTax = $total = 0;
     foreach ($data['amount'] as $line => $amount) {
         // Recalculate tax-amount based on the tax-percentage
         if ($data['tax_percentage'][$line] > 0) {
             $data['tax'][$line] = round($data['amount'][$line] * $data['quantity'][$line] * ($data['tax_percentage'][$line] / 100), 4);
             $totalTax += $data['tax'][$line];
         } else {
             $data['tax'][$line] = 0;
         }
         $total += $amount * $data['quantity'][$line];
         $this->query('INSERT INTO PREFIX_invoice_line (invoice_id, product_id, product, quantity, amount, tax_percentage, description) VALUES (
             :invoiceID,
             :productID,
             :product,
             :quantity,
             :amount,
             :taxPercentage,
             :description)', array('invoiceID' => $invoiceID, 'productID' => $data['product_id'][$line], 'product' => $data['product'][$line], 'quantity' => $data['quantity'][$line], 'amount' => $data['amount'][$line], 'taxPercentage' => $data['tax_percentage'][$line], 'description' => $data['description'][$line]));
     }
     foreach ($data['totals'] as $sortOrder => $productTotal) {
         $labelInject = isset($productTotal['label_inject']) ? $productTotal['label_inject'] : '';
         $this->query("INSERT INTO PREFIX_invoice_total\n                SET invoice_id        = :id,\n                    sort_order      = :sortOrder,\n                    label           = :label,\n                    label_inject    = :labelInject,\n                    value           = :value,\n                    value_hr        = :valueHR", array('id' => $invoiceID, 'sortOrder' => $sortOrder, 'label' => $productTotal['label'], 'labelInject' => $labelInject, 'value' => $productTotal['value'], 'valueHR' => Formatter::currency($productTotal['value'])));
     }
     // Totalamount is always the last line.
     $total = $productTotal['value'];
     $invoicePrefix = $this->config->get('invoice_prefix');
     // Customer country numeric? Change to plain text
     if (preg_match("/^\\d+\$/", $data['customer_country'])) {
         $countryData = $this->query("SELECT name FROM PREFIX_country WHERE country_id = :countryID", array('countryID' => $data['customer_country']))->fetch();
         $data['customer_country'] = !empty($countryData) ? $countryData['name'] : '-';
     }
     $this->query('UPDATE PREFIX_invoice SET
         invoice_no = :invoiceNO,
         customer_id = :customerID,
         customer_no = :customerNo,
         customer_name = :customerName,
         customer_address = :customerAddress,
         customer_postcode = :customerPostcode,
         customer_city = :customerCity,
         customer_country = :customerCountry,
         customer_email = :customerEmail,
         payment_amount = :paymentAmount,
         payment_tax_percentage = :paymentTax,
         shipping_amount = :shippingAmount,
         shipping_tax_percentage = :shippingTax,
         discount = :discount,
         total_amount = :amount,
         sent_date = :sentDate,
         notes = :notes,
         template = :template,
         term = :term,
         auto = :auto,
         reference = :reference
         WHERE invoice_id = :invoiceID', array('invoiceNO' => $invoicePrefix . str_pad($invoiceID, 5, 0, STR_PAD_LEFT), 'customerNo' => $customerNo, 'customerID' => $data['customer_id'], 'customerName' => $data['customer_name'], 'customerAddress' => $data['customer_address'], 'customerPostcode' => $data['customer_postcode'], 'customerCity' => $data['customer_city'], 'customerCountry' => $data['customer_country'], 'customerEmail' => $data['customer_email'], 'paymentAmount' => $data['payment_amount'], 'paymentTax' => $data['payment_tax'], 'shippingAmount' => $data['shipping_amount'], 'shippingTax' => $data['shipping_tax'], 'discount' => json_encode($data['discount']), 'amount' => $total, 'sentDate' => Formatter::dateReverse($data['sent_date']), 'notes' => $data['notes'], 'template' => $data['template'], 'term' => $data['term'], 'auto' => $data['auto'], 'reference' => $data['reference'], 'invoiceID' => $invoiceID));
 }
Exemple #11
0
 public function getReturns($data = array())
 {
     $values = array('language' => $this->config->get('language_id'));
     $sql = "SELECT *, CONCAT(r.firstname, ' ', r.lastname) AS customer, (\n                        SELECT rs.name\n                        FROM PREFIX_return_status AS rs\n                        WHERE rs.return_status_id = r.return_status_id AND rs.language_id = :language\n                    ) AS status\n                FROM PREFIX_return AS r";
     $implode = array();
     if (!empty($data['filter_return_id'])) {
         $implode[] = "r.return_id = :filter_return_id";
         $values['filter_return_id'] = $data['filter_return_id'];
     }
     if (!empty($data['filter_order_id'])) {
         $implode[] = "r.order_id = :filter_order_id";
         $values['filter_order_id'] = $data['filter_order_id'];
     }
     if (!empty($data['filter_customer'])) {
         $implode[] = "CONCAT(r.firstname, ' ', r.lastname) LIKE :filter_customer";
         $values['filter_customer'] = $data['filter_customer'] . '%';
     }
     if (!empty($data['filter_product'])) {
         $implode[] = "r.product = :filter_product";
         $values['filter_product'] = $data['filter_product'];
     }
     if (!empty($data['filter_model'])) {
         $implode[] = "r.model = :filter_model";
         $values['filter_model'] = $data['filter_model'];
     }
     if (!empty($data['filter_return_status_id'])) {
         $implode[] = "r.return_status_id = :filter_return_status_id";
         $values['filter_return_status_id'] = $data['filter_return_status_id'];
     }
     if (!empty($data['filter_date_added'])) {
         $implode[] = "DATE(r.date_added) = DATE('" . Formatter::dateRevers($data['filter_date_added']) . "')";
     }
     if (!empty($data['filter_date_modified'])) {
         $implode[] = "DATE(r.date_modified) = DATE('" . Formatter::dateRevers($data['filter_date_modified']) . "')";
     }
     if ($implode) {
         $sql .= " WHERE " . implode(" AND ", $implode);
     }
     $sort_data = array('r.return_id', 'r.order_id', 'customer', 'r.product', 'r.model', 'status', 'r.date_added', 'r.date_modified');
     if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
         $sql .= " ORDER BY " . $data['sort'];
     } else {
         $sql .= " ORDER BY r.return_id";
     }
     if (isset($data['order']) && $data['order'] == 'DESC') {
         $sql .= " DESC";
     } else {
         $sql .= " ASC";
     }
     if (isset($data['start']) || isset($data['limit'])) {
         if ($data['start'] < 0) {
             $data['start'] = 0;
         }
         if ($data['limit'] < 1) {
             $data['limit'] = 20;
         }
         $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit'];
     }
     return $this->fetchAll($sql, $values);
 }
Exemple #12
0
 /**
  * Recursively remove given directory
  *
  * @param string $dir            
  * @return boolean
  */
 public static function removeDir($dir)
 {
     if (!Formatter::endsWith($dir, DIRECTORY_SEPARATOR) && !Formatter::endsWith($dir, self::DIR_SEPARATOR)) {
         $dir .= self::DIR_SEPARATOR;
     }
     if (!is_dir($dir)) {
         return false;
     }
     if ($handle = opendir($dir)) {
         $dirsToVisit = array();
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 if (is_dir($dir . $file)) {
                     $dirsToVisit[] = $dir . $file;
                 } else {
                     if (is_file($dir . $file)) {
                         unlink($dir . $file);
                     }
                 }
             }
         }
         closedir($handle);
         foreach ($dirsToVisit as $i => $w) {
             self::removeDirectory($w);
         }
     }
     rmdir($dir);
     return true;
 }
Exemple #13
0
 /**
  * Ensure that yiiDateFormatToJQueryDateFormat correctly translates between format languages
  */
 public function testYiiDateFormatToJQueryDateFormat()
 {
     $formats = array('d MMM y' => 'd M yy', 'd/MMM/y' => 'd/M/yy', 'd/MM/y' => 'd/mm/yy', 'd/MM M/y' => 'd/mm m/yy', 'd/MM M/y MMM' => 'd/mm m/yy M');
     foreach ($formats as $fmt => $expected) {
         $newFormat = Formatter::yiiDateFormatToJQueryDateFormat($fmt);
         $this->assertEquals($expected, $newFormat);
     }
 }
 public function doValidate($ctx)
 {
     $formattedValue = $ctx->getRequest()->getString($this->getName(), null);
     // Validate only if there is a value
     if ($formattedValue === null || $formattedValue === '') {
         return true;
     }
     $format = new Formatter($ctx->getUser()->getTimezone(), $ctx->getUser()->getLocale());
     $value = $format->getNumber($formattedValue);
     if ($value === false) {
         $msg = sprintf(Application::getTranslator()->_('The field %1$s must be a valid number'), $this->getLabel());
         $this->addFieldError($ctx, $this->getName(), $msg);
         return false;
     }
     if ($this->minValue) {
         if ($this->minValue->isExclusive()) {
             if ($value <= $this->minValue->getValue()) {
                 $msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be greater than %2$s'), $this->getLabel(), $this->minValue->getValue());
                 $this->addFieldError($ctx, $this->getName(), $msg);
                 return false;
             }
         } else {
             if ($value < $this->minValue->getValue()) {
                 $msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be greater or equal to %2$s'), $this->getLabel(), $this->minValue->getValue());
                 $this->addFieldError($ctx, $this->getName(), $msg);
                 return false;
             }
         }
     }
     if ($this->maxValue) {
         if ($this->maxValue->isExclusive()) {
             if ($value >= $this->maxValue->getValue()) {
                 $msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be smaller than %2$s'), $this->getLabel(), $this->maxValue->getValue());
                 $this->addFieldError($ctx, $this->getName(), $msg);
                 return false;
             }
         } else {
             if ($value > $this->maxValue->getValue()) {
                 $msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be smaller or equal to %2$s'), $this->getLabel(), $this->maxValue->getValue());
                 $this->addFieldError($ctx, $this->getName(), $msg);
                 return false;
             }
         }
     }
     return true;
 }
 public function searchCustom($keyword, $pagesize = 10, $option = array())
 {
     $keyword = Formatter::clean($keyword);
     //$keyword = Apache_Solr_Service::phrase($keyword);
     $solr = $this->_getSolr();
     $params = array('group' => 'true', 'group.limit' => $pagesize, 'group.field' => 'type');
     $params['sort'] = "score desc, played_count desc";
     $rs = $solr->search($keyword, 0, $pagesize, $params);
     return $rs;
 }
Exemple #16
0
 /**
  * PhpGetBrowser constructor.
  *
  * @param bool $returnArray
  */
 public function __construct(bool $returnArray = false)
 {
     $options = self::KEY_LOWER | self::VALUE_BOOLEAN_TO_STRING | self::VALUE_REG_EXP_LOWER;
     if ($returnArray) {
         $options |= self::RETURN_ARRAY;
     } else {
         $options |= self::RETURN_OBJECT;
     }
     parent::__construct($options);
 }
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     $model = new AdminGUserModel();
     $userInfo = null;
     if (isset($_GET['AdminGUserModel'])) {
         $model->attributes = $_GET['AdminGUserModel'];
         $user_phone = Formatter::formatPhone($_GET['AdminGUserModel']['user_phone']);
         $userInfo = GUserModel::model()->findByAttributes(array('user_phone' => $user_phone));
     }
     $this->render('index', array('model' => $model, 'userInfo' => $userInfo));
 }
Exemple #18
0
 /**
  * Convert and array to a string representation in tree format
  *
  * @param string $array 
  * @return string
  */
 public static function arrayToTree($array)
 {
     $tree = "";
     foreach ($array as $key => $item) {
         if (is_array($item)) {
             $item = Formatter::arrayToTree($item);
         }
         $tree .= "[" . $key . "] " . self::sanitize($item) . PHP_EOL;
     }
     return $tree;
 }
Exemple #19
0
function do_new($formatter, $options)
{
    global $DBInfo;
    if (!$options['value']) {
        $title = _("Create a new page");
        $formatter->send_header("", $options);
        $formatter->send_title($title, "", $options);
        $url = $formatter->link_url($formatter->page->urlname);
        if ($DBInfo->hasPage('MyNewPage')) {
            $p = $DBInfo->getPage('MyNewPage');
            $f = new Formatter($p, $options);
            $f->use_rating = 0;
            $f->send_page('', $options);
        }
        $msg = _("Page Name");
        $fixname = _("Normalize this page name");
        $btn = _("Create a new page");
        print <<<FORM
<div class='addPage'>
<form method='get' action='{$url}'>
<table style='border:0'><tr><th class='addLabel'><labe>{$msg}: </label></th><td><input type='hidden' name='action' value='new' />
    <input name='value' size='30' /></td></tr>
<tr><th class='addLabel'><input type='checkbox' name='fixname' checked='checked' /></th><td>{$fixname}</td></tr>
<td></td><td><input type='submit' value='{$btn}' /></td>
</tr></table>
    </form>
</div>
FORM;
        $formatter->send_footer();
    } else {
        $pgname = $options['value'];
        if ($options['fixname']) {
            $pgname = normalize($pgname);
        }
        $options['page'] = $pgname;
        $page = new WikiPage($pgname);
        $f = new Formatter($page, $options);
        do_edit($f, $options);
        return true;
    }
}
 function test_Mixins()
 {
     foreach ($this->load_files('Mixins') as $item) {
         $out = str_replace('.css', '_out.css', $item);
         $original = file_get_contents($item);
         $expected = file_get_contents($out);
         $css = Mixins::parse($original);
         $css = Formatter::minify($css);
         $expected = Formatter::minify($expected);
         $this->assertEqual($expected, $css);
     }
 }
    public function testRootNode()
    {
        $snippet = <<<'END'
<?php
namespace Foo\Baz; class Blorg { public function __construct() {}}
END;
        $expected = <<<'END'
<?php
namespace Foo\Baz;

class Blorg
{
    public function __construct()
    {
    }
}
END;
        $doc = Parser::parseSource($snippet);
        $this->formatter->format($doc);
        $this->assertEquals($expected, $doc->getText());
    }
 public static function ArtistsByAlbum($id)
 {
     $artists = AlbumArtistModel::model()->getArtistsByAlbum($id);
     $i = 0;
     $html = "";
     foreach ($artists as $artist) {
         $html .= $i > 0 ? "<span>&nbsp;-&nbsp;</span>" : "";
         $html .= '<a href="' . URLHelper::buildFriendlyURL("artist", $artist->artist_id, Common::makeFriendlyUrl($artist->artist_name)) . '" title="' . $artist->artist_name . '">' . Formatter::substring($artist->artist_name, " ", 3, 15) . '</a>';
         $i++;
     }
     return $html;
 }
 /**
  * Constructor
  * 
  * @return  void
  */
 function NumberFormatter($arr_config)
 {
     parent::Formatter($arr_config);
     if ($this->arr_config['decimals'] == '') {
         $this->arr_config['decimals'] = 2;
     }
     if ($this->arr_config['dec_point'] == '') {
         $this->arr_config['dec_point'] = '.';
     }
     if ($this->arr_config['thousands_sep'] == '') {
         $this->arr_config['thousands_sep'] = ',';
     }
 }
 private function log()
 {
     $logDir = Config::getInstance()->getString('logging/logDir');
     $logFile = "{$logDir}/" . $this->logFileName;
     $this->ensureDirExists($logFile);
     $fDate = Formatter::dateTimeUTC($this->endTime);
     $diff = $this->endTime - $this->startTime;
     $text = $this->text ? $this->text : "-";
     // If text is empty, set it to '-'.
     $fd = fopen($logFile, "a");
     fwrite($fd, "{$fDate}\t{$text}\t{$diff}\n");
     fclose($fd);
 }
Exemple #25
0
 /**
  * @todo Implement testFileSize().
  */
 public function testFileSize()
 {
     $this->assertEquals('0 B', Formatter::fileSize(0));
     $this->assertEquals('1.00 KiB', Formatter::fileSize(1000));
     $this->assertEquals('1.02 KiB', Formatter::fileSize(1024));
     // Test fails due to floating point precision?
     //$this->assertEquals('1.03 KiB', Formatter::fileSize(1025));
     $this->assertEquals('1.03 KiB', Formatter::fileSize(1025.1));
     $this->assertEquals('1.00 MiB', Formatter::fileSize(1000000));
     $this->assertEquals('1.00 GiB', Formatter::fileSize(1000000000));
     $this->assertEquals('1.00 TiB', Formatter::fileSize(1000000000000));
     $this->assertEquals('1.00 PiB', Formatter::fileSize(1000000000000000));
 }
 public function formatData()
 {
     $array = Formatter::generateArrayFromData($this->getData());
     // CSV generation code adapted from
     // http://www.php.net/manual/en/function.fputcsv.php#74118
     $csv = fopen('php://temp/maxmemory:' . 5 * 1024 * 1024, 'r+');
     foreach ($array as $item) {
         fputcsv($csv, $item);
     }
     rewind($csv);
     $output = stream_get_contents($csv);
     return $output;
 }
Exemple #27
0
 public function index()
 {
     if (!$this->customer->isLogged()) {
         $this->session->data['redirect'] = $this->url->link('account/download', '', 'SSL');
         $this->redirect($this->url->link('account/login', '', 'SSL'));
     }
     $this->document->setTitle(Language::getVar('SUMO_DOWNLOAD_TITLE'));
     $this->data['breadcrumbs'] = array();
     $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_HOME'), 'href' => $this->url->link('common/home'), 'separator' => false);
     $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_ACCOUNT_TITLE'), 'href' => $this->url->link('account/account', '', 'SSL'));
     $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_DOWNLOAD_TITLE'), 'href' => $this->url->link('account/download', '', 'SSL'));
     $this->load->model('account/download');
     $totalDownloads = $this->model_account_download->getTotalDownloads();
     if ($totalDownloads) {
         if (isset($this->request->get['page'])) {
             $page = $this->request->get['page'];
         } else {
             $page = 1;
         }
         $this->data['downloads'] = array();
         $results = $this->model_account_download->getDownloads(($page - 1) * $this->config->get('catalog_limit'), $this->config->get('catalog_limit'));
         foreach ($results as $result) {
             if (file_exists(DIR_DOWNLOAD . $result['filename'])) {
                 $size = filesize(DIR_DOWNLOAD . $result['filename']);
                 $i = 0;
                 $suffix = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
                 while ($size / 1024 > 1) {
                     $size = $size / 1024;
                     $i++;
                 }
                 $this->data['downloads'][] = array('order_id' => str_pad($result['order_id'], 6, 0, STR_PAD_LEFT), 'date' => Formatter::date($result['order_date']), 'name' => $result['name'], 'remaining' => $result['remaining'], 'size' => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i], 'download' => $this->url->link('account/download/download', 'order_download_id=' . $result['order_download_id'], 'SSL'));
             }
         }
         $pagination = new Pagination();
         $pagination->total = $totalDownloads;
         $pagination->page = $page;
         $pagination->limit = $this->config->get('config_catalog_limit');
         $pagination->url = $this->url->link('account/download', 'page={page}', 'SSL');
         $this->data['pagination'] = $pagination->render();
         $this->data['continue'] = $this->url->link('account/account', '', 'SSL');
     } else {
         $this->data['downloads'] = $this->data['pagination'] = false;
     }
     $this->data['settings'] = $this->config->get('details_account_' . $this->config->get('template'));
     if (!is_array($this->data['settings']) || !count($this->data['settings'])) {
         $this->data['settings']['left'][] = $this->getChild('app/widgetsimplesidebar/', array('type' => 'accountTree', 'data' => array()));
     }
     $this->template = 'account/download.tpl';
     $this->children = array('common/footer', 'common/header');
     $this->response->setOutput($this->render());
 }
 public function getPendingGames($sport = 'NFL', $period = '')
 {
     $games = [];
     $url = "http://scores.nbcsports.com/ticker/data/gamesNEW.js.asp?jsonp=true&sport={$sport}&period={$period}";
     $jsonp = file_get_contents($url);
     $json_str = str_replace(');', '', str_replace('shsMSNBCTicker.loadGamesData(', '', $jsonp));
     $json_parsed = json_decode($json_str);
     foreach ($json_parsed->games as $game) {
         $game_xml = simplexml_load_string($game);
         $game_array = Formatter::make($game_xml, 'xml')->to_array();
         $games[$game_array['@attributes']['gamecode']] = $game_array;
     }
     return $games;
 }
 public function actionIndex()
 {
     $return = array('error' => 0, 'msg' => '');
     if (Yii::app()->request->isPostRequest) {
         $phone = Formatter::formatPhone($_POST['phone']);
         if (Formatter::isVinaphoneNumber($phone)) {
             if (!isset($_COOKIE["verifyWifiEvent"])) {
                 if (isset($_SESSION['countverifyWifiEvent'])) {
                     unset($_SESSION['countverifyWifiEvent']);
                 }
                 $_SESSION['countverifyWifiEvent'] = 1;
                 $_SESSION['phoneverifyWifiEvent'] = $phone;
                 setcookie("verifyWifiEvent", 1, time() + 600);
             } else {
                 $_SESSION['countverifyWifiEvent']++;
                 if ($_SESSION['countverifyWifiEvent'] > 3) {
                     $return['error'] = 1;
                     $return['msg'] = "Quí khách đã vượt quá số lần xác thực. Vui lòng thử lại sau ít phút.";
                 }
             }
             if ($return['error'] == 0) {
                 try {
                     $userVerify = UserVerifyModel::model()->findByAttributes(array('msisdn' => $phone, 'action' => 'register_event83'));
                     if (!empty($userVerify)) {
                         $verifyCode = $userVerify->verify_code;
                     } else {
                         $verifyCode = rand(1000, 9999);
                         $verifyModel = new UserVerifyModel();
                         $verifyModel->setAttribute('created_time', date("Y-m-d H:i:s"));
                         $verifyModel->setAttribute('msisdn', $phone);
                         $verifyModel->setAttribute('verify_code', $verifyCode);
                         $verifyModel->setAttribute('action', 'register_event83');
                         $verifyModel->save();
                     }
                     $sms = new SmsClient();
                     $content = "Ma xac thuc dang ky tren chacha la: " . $verifyCode;
                     $sms->sentMT("9234", $phone, 0, $content, 0, "", time(), 9234);
                     $this->redirect('/event/register/verifyWifi');
                 } catch (Exception $exc) {
                     echo $exc->getTraceAsString();
                 }
             }
         } else {
             $return['error'] = 2;
             $return['msg'] = "Số điện thoại của bạn không phải là thuê bao Vinaphone!";
         }
     }
     $this->render('index', array('return' => $return));
 }
 public function renderDate($field, array $htmlOptions = array())
 {
     $model = $this->owner;
     $fieldName = $field->fieldName;
     $oldDateVal = $model->{$fieldName};
     $model->{$fieldName} = Formatter::formatDate($model->{$fieldName}, 'medium');
     Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
     $pickerOptions = array('dateFormat' => Formatter::formatDatePicker(), 'changeMonth' => false, 'changeYear' => false);
     if (Yii::app()->getLanguage() === 'fr') {
         $pickerOptions['monthNamesShort'] = Formatter::getPlainAbbrMonthNames();
     }
     $input = Yii::app()->controller->widget('CJuiDateTimePicker', array('model' => $model, 'attribute' => $fieldName, 'mode' => 'date', 'options' => $pickerOptions, 'htmlOptions' => array_merge(array('title' => $field->attributeLabel, 'class' => 'x2-mobile-datepicker'), $htmlOptions), 'language' => Yii::app()->language == 'en' ? '' : Yii::app()->getLanguage()), true);
     $model->{$fieldName} = $oldDateVal;
     return $input;
 }