Пример #1
0
 static function DrawData($rec)
 {
     $ret = $rec['content'];
     while (utopia::MergeVars($ret)) {
     }
     return $ret;
 }
Пример #2
0
 public function MergeFields(&$string, $row)
 {
     $fields = $this->fields;
     if (preg_match_all('/{([a-z]+)\\.([^{]+)}/Ui', $string, $matches, PREG_PATTERN_ORDER)) {
         $searchArr = $matches[0];
         $typeArr = isset($matches[1]) ? $matches[1] : false;
         $varsArr = isset($matches[2]) ? $matches[2] : false;
         $row['_module_url'] = $this->GetURL($row[$this->GetPrimaryKey()]);
         foreach ($searchArr as $k => $search) {
             $field = $varsArr[$k];
             $qs = null;
             if (strpos($field, '?') !== FALSE) {
                 list($field, $qs) = explode('?', $field, 2);
             }
             if (!array_key_exists($field, $row)) {
                 continue;
             }
             if ($qs) {
                 parse_str(html_entity_decode($qs), $qs);
                 $this->FieldStyles_Add($field, $qs);
             }
             switch ($typeArr[$k]) {
                 case 'urlencode':
                     $replace = $this->PreProcess($field, $row[$field], $row);
                     $replace = rawurlencode($replace);
                     $string = str_replace($search, $replace, $string);
                     break;
                 case 'd':
                     $replace = $this->GetCell($field, $row);
                     $string = str_replace($search, $replace, $string);
                     break;
                 case 'field':
                     $replace = $this->PreProcess($field, $row[$field], $row);
                     $string = str_replace($search, $replace, $string);
                     break;
                 default:
             }
         }
     }
     $this->fields = $fields;
     while (utopia::MergeVars($string)) {
     }
 }
Пример #3
0
 static function DrawData($rec)
 {
     if (!$rec['module'] || !class_exists($rec['module'])) {
         return $rec['no_rows'];
     }
     if (!($instance = utopia::GetInstance($rec['module'], false))) {
         return 'Could not load Data Source';
     }
     $instance->_SetupParents();
     $instance->_SetupFields();
     // clear filters
     $rec['clear_filter'] = (array) utopia::jsonTryDecode($rec['clear_filter']);
     foreach ($rec['clear_filter'] as $uid) {
         $instance->RemoveFilter($uid);
     }
     // add filters
     utopia::MergeVars($rec['filter']);
     if ($rec['filter']) {
         $instance->AddFilter($rec['filter'], ctCUSTOM);
     }
     // add Order
     utopia::MergeVars($rec['order']);
     if ($rec['order']) {
         $instance->ordering = NULL;
         $instance->AddOrderBy($rec['order']);
     }
     $dataset = $instance->GetDataset();
     // init limit
     utopia::MergeVars($rec['limit']);
     $rec['limit'] = trim($rec['limit']);
     $instance->GetLimit($limit, $page);
     // page is governed by a different query arg for widgets, below
     $page = stripos($rec['content'], '{pagination}') !== FALSE && isset($_GET['_p_' . $rec['block_id']]) ? $_GET['_p_' . $rec['block_id']] : 0;
     $offset = $limit * $page;
     if ($rec['limit']) {
         if (strpos($rec['limit'], ',') === FALSE) {
             $limit = $rec['limit'];
             $offset = $limit * $page;
         } else {
             list($offset, $limit) = explode(',', $rec['limit']);
             $offset = trim($offset);
             $limit = trim($limit);
         }
     }
     if (!($total = $dataset->CountRecords())) {
         return $rec['no_rows'];
     }
     // get rows
     if ($offset > $total) {
         return $rec['no_rows'];
     }
     // get content
     $content = $append = $prepend = '';
     $html = str_get_html($rec['content'], true, true, DEFAULT_TARGET_CHARSET, false);
     $ele = '';
     if ($html) {
         $ele = $html->find('._ri', 0);
         if ($ele) {
             $ele = $ele->innertext;
         } else {
             $ele = $html->find('._r', 0);
             if ($ele) {
                 $ele = $ele->outertext;
             } else {
                 $ele = '';
             }
         }
     } else {
         $html = $rec['content'];
     }
     $repeatable = $html;
     if ($ele) {
         // found a repeatable element
         // split content at this element. prepare for apend and prepend.
         list($append, $prepend) = explode($ele, $repeatable);
         $repeatable = $ele;
     }
     $dataset->GetOffset($offset, $limit);
     while ($row = $dataset->fetch()) {
         $c = $repeatable;
         $instance->MergeFields($c, $row);
         $content .= $c;
     }
     $ret = $append . $content . $prepend;
     // process full doc
     $ret = str_ireplace('{total}', $total, $ret);
     if ($page !== NULL && is_numeric($limit)) {
         $pages = max(ceil($total / $limit), 1);
         ob_start();
         $cPage = utopia::OutputPagination($pages, '_p_' . $rec['block_id']);
         $ret = str_ireplace('{pagination}', ob_get_clean(), $ret);
         $ret = str_ireplace('{pages}', $pages, $ret);
         $ret = str_ireplace('{current_page}', $cPage, $ret);
     }
     while (utopia::MergeVars($ret)) {
     }
     return $ret;
 }
Пример #4
0
 static function MergeFields(&$string, $row)
 {
     if (preg_match_all('/{([a-z]+)\\.([^{]+)}/Ui', $string, $matches, PREG_PATTERN_ORDER)) {
         $searchArr = $matches[0];
         $typeArr = isset($matches[1]) ? $matches[1] : false;
         $varsArr = isset($matches[2]) ? $matches[2] : false;
         foreach ($searchArr as $k => $search) {
             $field = $varsArr[$k];
             switch ($typeArr[$k]) {
                 case 'urlencode':
                     $replace = $row[$field];
                     $replace = rawurlencode($replace);
                     $string = str_replace($search, $replace, $string);
                     break;
                 case 'field':
                     $replace = $row[$field];
                     $string = str_replace($search, $replace, $string);
                     break;
                 default:
             }
         }
     }
     while (utopia::MergeVars($string)) {
     }
 }
Пример #5
0
 public static function getEditor($id = '')
 {
     $thisObj = utopia::GetInstance(__CLASS__);
     $canEdit = uEvents::TriggerEvent('CanAccessModule', $thisObj) !== FALSE;
     // get content
     $rec = uCMS_View::findPage();
     if (!$rec) {
         return;
     }
     // page not found
     $content = $rec['content_published'];
     if ($rec['content_time'] == 0) {
         $content = $rec['content'];
     }
     if ($canEdit && (isset($_GET['edit']) || isset($_GET['preview']))) {
         $content = $rec['content'];
     }
     $content = utopia::jsonTryDecode($content);
     if (!is_array($content)) {
         $content = array('' => $content);
     }
     if (!isset($content[$id])) {
         $content[$id] = '';
     }
     if ($canEdit && isset($_GET['edit'])) {
         $rec['content:' . $id] = $content[$id];
         return $thisObj->GetCell('content:' . $id, $rec);
     }
     $content = $content[$id];
     $content = $thisObj->PreProcess('content', $content, $rec);
     utopia::MergeVars($content);
     return $content;
 }