Example #1
0
 /**
  * Fast processing of MODX tags.
  *
  * @param string $content
  * @param bool $processUncacheable
  *
  * @return mixed
  */
 public function fastProcess($content, $processUncacheable = true)
 {
     $matches = array();
     $this->getParser()->collectElementTags($content, $matches);
     $unprocessed = $pl = $vl = array();
     foreach ($matches as $tag) {
         $tmp = $this->parser->processTag($tag, $processUncacheable);
         if ($tmp === $tag[0]) {
             $unprocessed[] = $tmp;
         } else {
             $pl[] = $tag[0];
             $vl[] = $tmp;
         }
     }
     $content = str_replace($pl, $vl, $content);
     $content = str_replace($unprocessed, '', $content);
     return $content;
 }
 /** {inheritDoc} */
 public function processElementTags($parentTag, &$content, $processUncacheable = false, $removeUnprocessed = false, $prefix = "[[", $suffix = "]]", $tokens = array(), $depth = 0)
 {
     $work = is_string($content) && empty($parentTag) && $processUncacheable && preg_match('#\\{(\\$|\\/|\\w+\\s)#', $content) && !empty($this->pdoTools->config['useFenomParser']) && !empty($this->pdoTools->config['useFenom']);
     $tag = htmlentities(trim($content), ENT_QUOTES, 'UTF-8');
     $hash = sha1($tag);
     $parse_time_start = microtime(true);
     $query_time_start = $this->modx->queryTime;
     $queries_start = $this->modx->executedQueries;
     $result = parent::processElementTags($parentTag, $content, $processUncacheable, $removeUnprocessed, $prefix, $suffix, $tokens, $depth);
     if ($work) {
         $parse_time = number_format(round(microtime(true) - $parse_time_start, 7), 7);
         $query_time = number_format(round($this->modx->queryTime - $query_time_start, 7), 7);
         $queries = $this->modx->executedQueries - $queries_start;
         if (isset($this->tags[$hash])) {
             $this->tags[$hash]['attempts']++;
             $this->tags[$hash]['queries'] += $queries;
             $this->tags[$hash]['queries_time'] += $query_time;
             $this->tags[$hash]['parse_time'] += $parse_time;
         } else {
             $this->tags[$hash] = array('tag' => $tag, 'attempts' => 1, 'queries' => $queries, 'queries_time' => $query_time, 'parse_time' => $parse_time);
         }
     }
     return $result;
 }