Esempio n. 1
0
 /**
  * @param string $tpl
  * @param int $time
  *
  * @return string
  */
 public function getSource($tpl, &$time)
 {
     $content = '';
     if ($pos = strpos($tpl, '@')) {
         $propertySet = substr($tpl, $pos + 1);
         $tpl = substr($tpl, 0, $pos);
     }
     $c = is_numeric($tpl) && $tpl > 0 ? $tpl : array('name' => $tpl);
     /** @var modChunk $chunk */
     if ($element = $this->modx->getObject('modChunk', $c)) {
         $content = $element->getContent();
         $properties = array();
         if (!empty($propertySet)) {
             if ($tmp = $element->getPropertySet($propertySet)) {
                 $properties = $tmp;
             }
         } else {
             $properties = $element->getProperties();
         }
         if (!empty($content) && !empty($properties)) {
             $useFenom = $this->pdoTools->config['useFenom'];
             $this->pdoTools->config['useFenom'] = false;
             $content = $this->pdoTools->parseChunk('@INLINE ' . $content, $properties);
             $this->pdoTools->config['useFenom'] = $useFenom;
         }
     }
     return $content;
 }
Esempio n. 2
0
 /**
  * @param modX  $modx
  * @param array $config
  */
 function __construct(modX &$modx, array $config = array())
 {
     parent::__construct($modx, $config);
     $fqn = $modx->getOption('twiggy_class', null, 'twiggy.twiggy', true);
     $path = $modx->getOption('twiggy_class_path', null, MODX_CORE_PATH . 'components/twiggy/model/', true);
     if ($twiggyClass = $modx->loadClass($fqn, $path, false, true)) {
         $this->twiggy = new $twiggyClass($modx, $this->config);
     }
 }
Esempio n. 3
0
 /**
  * Recursive template of branch of menu
  *
  * @param array $row
  *
  * @return mixed|string
  */
 public function templateBranch($row = array())
 {
     $children = '';
     $row['level'] = $this->level;
     if (!empty($row['children']) && ($this->isHere($row['id']) || empty($this->pdoTools->config['hideSubMenus'])) && $this->checkResource($row['id'])) {
         $idx = 1;
         $this->level++;
         $count = count($row['children']);
         foreach ($row['children'] as $v) {
             $v['idx'] = $idx++;
             $v['last'] = (int) $v['idx'] == $count;
             $children .= $this->templateBranch($v);
         }
         $this->level--;
         $row['children'] = $count;
     } else {
         $row['children'] = isset($row['children']) ? count($row['children']) : 0;
     }
     if (!empty($this->pdoTools->config['countChildren'])) {
         if ($ids = $this->modx->getChildIds($row['id'])) {
             $tstart = microtime(true);
             $count = $this->modx->getCount('modResource', array('id:IN' => $ids, 'published' => true, 'deleted' => false));
             $this->modx->queryTime += microtime(true) - $tstart;
             $this->modx->executedQueries++;
             $this->pdoTools->addTime('Got the number of active children for resource "' . $row['id'] . '": ' . $count);
         } else {
             $count = 0;
         }
         $row['children'] = $count;
     }
     if (!empty($children)) {
         $pls = $this->addWayFinderPlaceholders(array('wrapper' => $children, 'classes' => ' class="' . $this->pdoTools->config['innerClass'] . '"', 'classNames' => $this->pdoTools->config['innerClass'], 'classnames' => $this->pdoTools->config['innerClass'], 'level' => $this->level));
         $row['wrapper'] = $this->pdoTools->parseChunk($this->pdoTools->config['tplInner'], $pls);
     } else {
         $row['wrapper'] = '';
     }
     if (empty($row['menutitle']) && !empty($row['pagetitle'])) {
         $row['menutitle'] = $row['pagetitle'];
     }
     $classes = $this->getClasses($row);
     if (!empty($classes)) {
         $row['classNames'] = $row['classnames'] = $classes;
         $row['classes'] = ' class="' . $classes . '"';
     } else {
         $row['classNames'] = $row['classnames'] = $row['classes'] = '';
     }
     if (!empty($this->pdoTools->config['useWeblinkUrl']) && $row['class_key'] == 'modWebLink') {
         $row['link'] = is_numeric(trim($row['content'], '[]~ ')) ? $this->modx->makeUrl(intval(trim($row['content'], '[]~ ')), '', '', $this->pdoTools->config['scheme']) : $row['content'];
     } else {
         $row['link'] = $this->modx->makeUrl($row['id'], $row['context_key'], '', $this->pdoTools->config['scheme']);
     }
     $row['title'] = !empty($this->pdoTools->config['titleOfLinks']) ? $row[$this->pdoTools->config['titleOfLinks']] : '';
     $tpl = $this->getTpl($row);
     $row = $this->addWayFinderPlaceholders($row);
     return $this->pdoTools->getChunk($tpl, $row, $this->pdoTools->config['fastMode']);
 }
Esempio n. 4
0
 /**
  * @param array $where
  * @param array $options
  *
  * @return array|bool
  */
 public function getResources($where, array $options = array())
 {
     $output = false;
     $this->pdoTools->debugParserMethod('getResources', $where, $options);
     /** @var pdoFetch $pdoFetch */
     if ($pdoFetch = $this->modx->getService('pdoFetch')) {
         $output = $pdoFetch->getCollection('modResource', $where, $options);
     }
     $this->pdoTools->debugParserMethod('getResources', $where, $options);
     return $output;
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function setConfig(array $config = array(), $clean_timings = true)
 {
     parent::setConfig(array_merge(array('class' => 'modResource', 'limit' => 10, 'sortby' => '', 'sortdir' => '', 'groupby' => '', 'totalVar' => 'total', 'tpl' => '', 'return' => 'chunks', 'select' => '', 'leftJoin' => '', 'rightJoin' => '', 'innerJoin' => '', 'includeTVs' => '', 'tvPrefix' => '', 'tvsJoin' => array(), 'tvsSelect' => array(), 'tvFiltersAndDelimiter' => ',', 'tvFiltersOrDelimiter' => '||', 'additionalPlaceholders' => '', 'useWeblinkUrl' => false, 'scheme' => -1), $config), $clean_timings);
     if (empty($this->config['class'])) {
         $this->config['class'] = 'modResource';
     }
     $this->loadModels();
     $this->ancestry = $this->modx->getAncestry($this->config['class']);
     $pk = $this->modx->getPK($this->config['class']);
     $this->pk = is_array($pk) ? implode(',', $pk) : $pk;
     $this->idx = !empty($this->config['offset']) ? (int) $this->config['offset'] + 1 : 1;
 }
Esempio n. 6
0
 /**
  * @param string $tpl
  * @param int $time
  *
  * @return string
  */
 public function getSource($tpl, &$time)
 {
     $content = '';
     if ($pos = strpos($tpl, '@')) {
         $propertySet = substr($tpl, $pos + 1);
         $tpl = substr($tpl, 0, $pos);
     }
     /** @var modChunk $chunk */
     if ($element = $this->modx->getObject('modTemplate', array('templatename' => $tpl))) {
         $content = $element->getContent();
         $properties = array();
         if (!empty($propertySet)) {
             if ($tmp = $element->getPropertySet($propertySet)) {
                 $properties = $tmp;
             }
         } else {
             $properties = $element->getProperties();
         }
         if (!empty($content) && !empty($properties)) {
             $content = $this->pdoTools->parseChunk('@INLINE ' . $content, $properties);
         }
     }
     return $content;
 }
Esempio n. 7
0
 /**
  * Recursive template of branch of menu
  *
  * @param array $row
  *
  * @return mixed|string
  */
 public function templateBranch($row = array())
 {
     $children = '';
     $row['level'] = $this->level;
     if (!empty($row['children']) && ($this->isHere($row['id']) || empty($this->pdoTools->config['hideSubMenus'])) && $this->checkResource($row['id'])) {
         $idx = 1;
         $this->level++;
         $count = count($row['children']);
         foreach ($row['children'] as $v) {
             $v['idx'] = $idx++;
             $v['last'] = (int) $v['idx'] == $count;
             $children .= $this->templateBranch($v);
         }
         $this->level--;
         $row['children'] = $count;
     } else {
         $row['children'] = 0;
     }
     if (!empty($children)) {
         $pls = $this->addWayFinderPlaceholders(array('wrapper' => $children, 'classes' => ' class="' . $this->pdoTools->config['innerClass'] . '"', 'classNames' => $this->pdoTools->config['innerClass'], 'classnames' => $this->pdoTools->config['innerClass']));
         $row['wrapper'] = $this->pdoTools->parseChunk($this->pdoTools->config['tplInner'], $pls);
     } else {
         $row['wrapper'] = '';
     }
     if (empty($row['menutitle']) && !empty($row['pagetitle'])) {
         $row['menutitle'] = $row['pagetitle'];
     }
     $classes = $this->getClasses($row);
     if (!empty($classes)) {
         $row['classNames'] = $row['classnames'] = $classes;
         $row['classes'] = ' class="' . $classes . '"';
     } else {
         $row['classNames'] = $row['classnames'] = $row['classes'] = '';
     }
     if (!empty($this->pdoTools->config['useWeblinkUrl']) && $row['class_key'] == 'modWebLink') {
         $row['link'] = is_numeric(trim($row['content'], '[]~ ')) ? $this->modx->makeUrl(intval(trim($row['content'], '[]~ ')), $row['context_key'], '', $this->pdoTools->config['scheme']) : $row['content'];
     } else {
         $row['link'] = $this->modx->makeUrl($row['id'], $row['context_key'], '', $this->pdoTools->config['scheme']);
     }
     $row['title'] = !empty($this->pdoTools->config['titleOfLinks']) ? $row[$this->pdoTools->config['titleOfLinks']] : '';
     $tpl = $this->getTpl($row);
     $row = $this->addWayFinderPlaceholders($row);
     return $this->pdoTools->getChunk($tpl, $row, $this->pdoTools->config['fastMode']);
 }
Esempio n. 8
0
 /**
  * @param string $key
  * @param bool $string
  * @param string $tpl
  *
  * @return array|string
  */
 public function getInfo($key = '', $string = true, $tpl = '@INLINE {$key}: {$value}')
 {
     $totalTime = microtime(true) - $this->modx->startTime;
     $queryTime = sprintf("%2.4f s", $this->modx->queryTime);
     $totalTime = sprintf("%2.4f s", $totalTime);
     $phpTime = sprintf("%2.4f s", $totalTime - $queryTime);
     $queries = isset($this->modx->executedQueries) ? $this->modx->executedQueries : 0;
     $source = $this->modx->resourceGenerated ? 'database' : 'cache';
     $info = array('queries' => $queries, 'totalTime' => $totalTime, 'queryTime' => $queryTime, 'phpTime' => $phpTime, 'source' => $source);
     if (empty($key) && !empty($string)) {
         $output = array();
         foreach ($info as $key => $value) {
             $output[] = $this->pdoTools->parseChunk($tpl, array('key' => $key, 'value' => $value));
         }
         return implode("\n", $output);
     } else {
         return !empty($key) && isset($info[$key]) ? $info[$key] : $info;
     }
 }
 /**
  * Quickly processes a simple tag and returns the result.
  *
  * @param string $tag A full tag string parsed from content.
  * @param boolean $processUncacheable
  *
  * @return mixed The output of the processed element represented by the specified tag.
  */
 public function processTag($tag, $processUncacheable = true)
 {
     $outerTag = $tag[0];
     $innerTag = $tag[1];
     $processed = false;
     $output = $token = '';
     // Disabled tag
     if (empty($innerTag[0]) || $innerTag[0] == '-') {
         return '';
     } elseif ($innerTag[0] == '!' && !$processUncacheable) {
         $this->processElementTags($outerTag, $innerTag, $processUncacheable);
         $outerTag = '[[' . $innerTag . ']]';
         return $outerTag;
     } elseif (strpos($innerTag, '?') === false && preg_match('/^(?:!|)[-|%|~|+|*|#]+/', $innerTag, $matches)) {
         if (strpos($innerTag, '[[') !== false) {
             $this->processElementTags($outerTag, $innerTag, $processUncacheable);
             $outerTag = '[[' . $innerTag . ']]';
         }
         $innerTag = ltrim($this->realname($innerTag), '!');
         $token = $innerTag[0];
         $innerTag = substr($innerTag, 1);
         switch ($token) {
             // Lexicon tag
             case '%':
                 $tmp = $this->modx->lexicon($innerTag);
                 if ($tmp != $innerTag) {
                     $output = $tmp;
                     $processed = true;
                 }
                 break;
                 // Link tag
             // Link tag
             case '~':
                 if (is_numeric($innerTag)) {
                     if ($tmp = $this->modx->makeUrl($innerTag, '', '', $this->modx->getOption('link_tag_scheme', null, -1, true))) {
                         $output = $tmp;
                         $processed = true;
                     }
                 }
                 break;
                 // Usual placeholder
                 // and
                 // System setting
             // Usual placeholder
             // and
             // System setting
             case '+':
                 if (isset($this->modx->placeholders[$innerTag])) {
                     $output = $this->modx->placeholders[$innerTag];
                     $processed = true;
                 }
                 break;
                 // Resource tag and TVs
             // Resource tag and TVs
             case '*':
                 if (is_object($this->modx->resource) && $this->modx->resource instanceof modResource) {
                     if ($innerTag == 'content') {
                         $output = $this->modx->resource->getContent();
                     } elseif (is_array($this->modx->resource->_fieldMeta) && isset($this->modx->resource->_fieldMeta[$innerTag])) {
                         $output = $this->modx->resource->get($innerTag);
                     } else {
                         $output = $this->modx->resource->getTVValue($innerTag);
                     }
                     $processed = true;
                 }
                 break;
                 // FastField tag
                 // Thank to Argnist and Dimlight Studio (http://dimlight.ru) for the original idea
             // FastField tag
             // Thank to Argnist and Dimlight Studio (http://dimlight.ru) for the original idea
             case '#':
                 $tmp = array_map('trim', explode('.', $innerTag));
                 $length = count($tmp);
                 // Resource tag
                 if (is_numeric($tmp[0])) {
                     /** @var modResource $resource */
                     if (!($resource = $this->pdoTools->getStore($tmp[0], 'resource'))) {
                         $resource = $this->modx->getObject('modResource', $tmp[0]);
                         $this->pdoTools->setStore($tmp[0], $resource, 'resource');
                     }
                     $output = '';
                     if (!empty($resource)) {
                         // Field specified
                         if (!empty($tmp[1])) {
                             $tmp[1] = strtolower($tmp[1]);
                             if ($tmp[1] == 'content') {
                                 $output = $resource->getContent();
                             } elseif ($field = $resource->get($tmp[1])) {
                                 $output = $field;
                                 if (is_array($field)) {
                                     if ($length > 2) {
                                         foreach ($tmp as $k => $v) {
                                             if ($k === 0) {
                                                 continue;
                                             }
                                             if (isset($field[$v])) {
                                                 $output = $field[$v];
                                             }
                                         }
                                     }
                                 }
                             } elseif ($field === null) {
                                 unset($tmp[0]);
                                 $tmp = preg_replace('/^tv\\./', '', implode('.', $tmp));
                                 $output = $resource->getTVValue($tmp);
                             }
                         } else {
                             $output = $resource->toArray();
                         }
                     }
                 } else {
                     switch (strtolower($tmp[0])) {
                         case 'post':
                             $array = $_POST;
                             break;
                         case 'get':
                             $array = $_GET;
                             break;
                         case 'request':
                             $array = $_REQUEST;
                             break;
                         case 'server':
                             $array = $_SERVER;
                             break;
                         case 'files':
                             $array = $_FILES;
                             break;
                         case 'cookie':
                             $array = $_COOKIE;
                             break;
                         case 'session':
                             $array = $_SESSION;
                             break;
                         default:
                             $array = array();
                             break;
                     }
                     // Field specified
                     if (!empty($tmp[1])) {
                         $field = isset($array[$tmp[1]]) ? $array[$tmp[1]] : '';
                         $output = $field;
                         if (is_array($field)) {
                             if ($length > 2) {
                                 foreach ($tmp as $k => $v) {
                                     if ($k === 0) {
                                         continue;
                                     }
                                     if (isset($field[$v])) {
                                         $output = $field[$v];
                                     }
                                 }
                             }
                         }
                     } else {
                         $output = $array;
                     }
                     if (is_string($output)) {
                         $output = $this->modx->stripTags($output);
                     }
                 }
                 $processed = true;
                 break;
         }
     }
     // Processing output filters
     if ($processed) {
         if (strpos($outerTag, ':') !== false) {
             /** @var pdoTag $object */
             $tag = new pdoTag($this->modx);
             $tag->_content = $output;
             $tag->setTag($outerTag);
             $tag->setToken($token);
             $tag->setContent(ltrim(rtrim($outerTag, ']'), '[!' . $token));
             $tag->setCacheable(!$processUncacheable);
             $tag->process();
             $output = $tag->_output;
         }
         if ($this->modx->getDebug() === true) {
             $this->modx->log(xPDO::LOG_LEVEL_DEBUG, "Processing {$outerTag} as {$innerTag}:\n" . print_r($output, 1) . "\n\n");
         }
         // Print array
         if (is_array($output)) {
             $output = htmlentities(print_r($output, true), ENT_QUOTES, 'UTF-8');
         }
     } else {
         $output = parent::processTag($tag, $processUncacheable);
     }
     return $output;
 }
 /**
  * @param $entry
  */
 public function log($entry)
 {
     if ($this->pdoTools && empty($this->config['hideSearchLog'])) {
         $this->pdoTools->addTime('[mSearch2] ' . $entry);
     }
 }
Esempio n. 11
0
 /**
  * Modern pagination: 1,2,..,8,9,...,13,14
  *
  * @param int $page
  * @param int $pages
  * @param string $url
  *
  * @return string
  */
 public function buildModernPagination($page = 1, $pages = 5, $url = '')
 {
     $pageLimit = $this->pdoTools->config['pageLimit'];
     if ($pageLimit >= $pages || $pageLimit < 7) {
         return $this->buildClassicPagination($page, $pages, $url);
     } else {
         $tmp = (int) floor($pageLimit / 3);
         $left = $right = $tmp;
         $center = $pageLimit - $tmp * 2;
     }
     $pagination = array();
     // Left
     for ($i = 1; $i <= $left; $i++) {
         if ($page == $i && !empty($this->pdoTools->config['tplPageActive'])) {
             $tpl = $this->pdoTools->config['tplPageActive'];
         } elseif (!empty($this->pdoTools->config['tplPage'])) {
             $tpl = $this->pdoTools->config['tplPage'];
         }
         $pagination[$i] = !empty($tpl) ? $this->makePageLink($url, $i, $tpl) : '';
     }
     // Right
     for ($i = $pages - $right + 1; $i <= $pages; $i++) {
         if ($page == $i && !empty($this->pdoTools->config['tplPageActive'])) {
             $tpl = $this->pdoTools->config['tplPageActive'];
         } elseif (!empty($this->pdoTools->config['tplPage'])) {
             $tpl = $this->pdoTools->config['tplPage'];
         }
         $pagination[$i] = !empty($tpl) ? $this->makePageLink($url, $i, $tpl) : '';
     }
     // Center
     if ($page <= $left) {
         $i = $left + 1;
         while ($i <= $center + $left) {
             if ($i == $center + $left && !empty($this->pdoTools->config['tplPageSkip'])) {
                 $tpl = $this->pdoTools->config['tplPageSkip'];
             } else {
                 $tpl = $this->pdoTools->config['tplPage'];
             }
             $pagination[$i] = !empty($tpl) ? $this->makePageLink($url, $i, $tpl) : '';
             $i++;
         }
     } elseif ($page > $pages - $right) {
         $i = $pages - $right - $center + 1;
         while ($i <= $pages - $right) {
             if ($i == $pages - $right - $center + 1 && !empty($this->pdoTools->config['tplPageSkip'])) {
                 $tpl = $this->pdoTools->config['tplPageSkip'];
             } else {
                 $tpl = $this->pdoTools->config['tplPage'];
             }
             $pagination[$i] = !empty($tpl) ? $this->makePageLink($url, $i, $tpl) : '';
             $i++;
         }
     } else {
         if ($page - $center < $left) {
             $i = $left + 1;
             while ($i <= $center + $left) {
                 if ($page == $i && !empty($this->pdoTools->config['tplPageActive'])) {
                     $tpl = $this->pdoTools->config['tplPageActive'];
                 } elseif (!empty($this->pdoTools->config['tplPage'])) {
                     $tpl = $this->pdoTools->config['tplPage'];
                 }
                 $pagination[$i] = !empty($tpl) ? $this->makePageLink($url, $i, $tpl) : '';
                 $i++;
             }
             if (!empty($this->pdoTools->config['tplPageSkip'])) {
                 $key = $page + 1 == $left + $center ? $pages - $right + 1 : $left + $center;
                 $pagination[$key] = $this->pdoTools->getChunk($this->pdoTools->config['tplPageSkip']);
             }
         } elseif ($page + $center - 1 > $pages - $right) {
             $i = $pages - $right - $center + 1;
             while ($i <= $pages - $right) {
                 if ($page == $i && !empty($this->pdoTools->config['tplPageActive'])) {
                     $tpl = $this->pdoTools->config['tplPageActive'];
                 } elseif (!empty($this->pdoTools->config['tplPage'])) {
                     $tpl = $this->pdoTools->config['tplPage'];
                 }
                 $pagination[$i] = !empty($tpl) ? $this->makePageLink($url, $i, $tpl) : '';
                 $i++;
             }
             if (!empty($this->pdoTools->config['tplPageSkip'])) {
                 $key = $page - 1 == $pages - $right - $center + 1 ? $left : $pages - $right - $center + 1;
                 $pagination[$key] = $this->pdoTools->getChunk($this->pdoTools->config['tplPageSkip']);
             }
         } else {
             $tmp = (int) floor(($center - 1) / 2);
             $i = $page - $tmp;
             while ($i < $page - $tmp + $center) {
                 if ($page == $i && !empty($this->pdoTools->config['tplPageActive'])) {
                     $tpl = $this->pdoTools->config['tplPageActive'];
                 } elseif (!empty($this->pdoTools->config['tplPage'])) {
                     $tpl = $this->pdoTools->config['tplPage'];
                 }
                 $pagination[$i] = !empty($tpl) ? $this->makePageLink($url, $i, $tpl) : '';
                 $i++;
             }
             if (!empty($this->pdoTools->config['tplPageSkip'])) {
                 $pagination[$left] = $pagination[$pages - $right + 1] = $this->pdoTools->getChunk($this->pdoTools->config['tplPageSkip']);
             }
         }
     }
     ksort($pagination);
     return implode($pagination);
 }
Esempio n. 12
0
 /**
  * @param $name
  * @param array $properties
  *
  * @return mixed|string
  */
 public function getChunk($name, array $properties = array())
 {
     return $this->pdoTools ? $this->pdoTools->getChunk($name, $properties) : $this->modx->getChunk($name, $properties);
 }