예제 #1
0
파일: list.php 프로젝트: vanie3/appland
 public static function genericordering($sql, $chop = '30')
 {
     $db = MFactory::getDbo();
     $options = array();
     $db->setQuery($sql);
     $items = $db->loadObjectList();
     // Check for a database error.
     if ($db->getErrorNum()) {
         MError::raiseNotice(500, $db->getErrorMsg());
         return false;
     }
     if (empty($items)) {
         $options[] = MHtml::_('select.option', 1, MText::_('MOPTION_ORDER_FIRST'));
         return $options;
     }
     $options[] = MHtml::_('select.option', 0, '0 ' . MText::_('MOPTION_ORDER_FIRST'));
     for ($i = 0, $n = count($items); $i < $n; $i++) {
         $items[$i]->text = MText::_($items[$i]->text);
         if (MString::strlen($items[$i]->text) > $chop) {
             $text = MString::substr($items[$i]->text, 0, $chop) . "...";
         } else {
             $text = $items[$i]->text;
         }
         $options[] = MHtml::_('select.option', $items[$i]->value, $items[$i]->value . '. ' . $text);
     }
     $options[] = MHtml::_('select.option', $items[$i - 1]->value + 1, $items[$i - 1]->value + 1 . ' ' . MText::_('MOPTION_ORDER_LAST'));
     return $options;
 }
예제 #2
0
파일: string.php 프로젝트: vanie3/appland
 public static function abridge($text, $length = 50, $intro = 30)
 {
     // Abridge the item text if it is too long.
     if (MString::strlen($text) > $length) {
         // Determine the remaining text length.
         $remainder = $length - ($intro + 3);
         // Extract the beginning and ending text sections.
         $beg = MString::substr($text, 0, $intro);
         $end = MString::substr($text, MString::strlen($text) - $remainder);
         // Build the resulting string.
         $text = $beg . '...' . $end;
     }
     return $text;
 }
예제 #3
0
파일: cache.php 프로젝트: vanie3/appland
 public static function setWorkarounds($data, $options = array())
 {
     $loptions = array();
     $loptions['nopathway'] = 0;
     $loptions['nohead'] = 0;
     $loptions['nomodules'] = 0;
     $loptions['modulemode'] = 0;
     if (isset($options['nopathway'])) {
         $loptions['nopathway'] = $options['nopathway'];
     }
     if (isset($options['nohead'])) {
         $loptions['nohead'] = $options['nohead'];
     }
     if (isset($options['nomodules'])) {
         $loptions['nomodules'] = $options['nomodules'];
     }
     if (isset($options['modulemode'])) {
         $loptions['modulemode'] = $options['modulemode'];
     }
     $app = MFactory::getApplication();
     $document = MFactory::getDocument();
     $buffer1 = $document->getBuffer();
     if (!is_array($buffer1)) {
         $buffer1 = array();
     }
     if (!isset($buffer1['module']) || !is_array($buffer1['module'])) {
         $buffer1['module'] = array();
     }
     $cached['body'] = $data;
     if ($loptions['nohead'] != 1 && method_exists($document, 'getHeadData')) {
         if ($loptions['modulemode'] == 1) {
             $headnow = $document->getHeadData();
             $unset = array('title', 'description', 'link', 'links', 'metaTags');
             foreach ($unset as $un) {
                 unset($headnow[$un]);
                 unset($options['headerbefore'][$un]);
             }
             $cached['head'] = array();
             foreach ($headnow as $now => $value) {
                 if (isset($options['headerbefore'][$now])) {
                     $nowvalue = array_map('serialize', $headnow[$now]);
                     $beforevalue = array_map('serialize', $options['headerbefore'][$now]);
                     $newvalue = array_diff_assoc($nowvalue, $beforevalue);
                     $newvalue = array_map('unserialize', $newvalue);
                     if (($now == 'script' || $now == 'style') && is_array($newvalue) && is_array($options['headerbefore'][$now])) {
                         foreach ($newvalue as $type => $currentScriptStr) {
                             if (isset($options['headerbefore'][$now][strtolower($type)])) {
                                 $oldScriptStr = $options['headerbefore'][$now][strtolower($type)];
                                 if ($oldScriptStr != $currentScriptStr) {
                                     $newvalue[strtolower($type)] = MString::substr($currentScriptStr, MString::strlen($oldScriptStr));
                                 }
                             }
                         }
                     }
                 } else {
                     $newvalue = $headnow[$now];
                 }
                 if (!empty($newvalue)) {
                     $cached['head'][$now] = $newvalue;
                 }
             }
         } else {
             $cached['head'] = $document->getHeadData();
         }
     }
     if ($app->isSite() && $loptions['nopathway'] != 1) {
         $pathway = $app->getPathWay();
         $cached['pathway'] = isset($data['pathway']) ? $data['pathway'] : $pathway->getPathway();
     }
     if ($loptions['nomodules'] != 1) {
         $buffer2 = $document->getBuffer();
         if (!is_array($buffer2)) {
             $buffer2 = array();
         }
         if (!isset($buffer2['module']) || !is_array($buffer2['module'])) {
             $buffer2['module'] = array();
         }
         $cached['module'] = array_diff_assoc($buffer2['module'], $buffer1['module']);
     }
     return $cached;
 }