/** * Includes the parsed chunk for the html-code */ function includeChunk() { if ($this->configIsSet() && $this->modx->documentObject['contentType'] == 'text/html') { $username = $this->loggedUserName(); // Check Webgroup if ($this->modx->isMemberOfWebGroup($this->options['piwikGroupTrack'])) { $trackUserName = $username; } if ($this->modx->isMemberOfWebGroup($this->options['piwikGroupExclude'])) { return ''; } // Check User if (in_array($username, $this->options['piwikUserTrack'])) { $trackUserName = $username; } if (in_array($username, $this->options['piwikUserExclude'])) { return ''; } // generate Chunk for the body $params = array(); if ($this->options['piwikTrackerPause'] != '') { $params[] = '_paq.push([ "setLinkTrackingTimer", ' . $this->options['piwikTrackerPause'] . ' ]);'; } if (!empty($this->options['piwikHostsAlias'])) { $params[] = '_paq.push([ "setDomains", ["' . implode(', ', $this->options['piwikHostsAlias']) . '"] ]);'; } if (!empty($this->options['piwikDownloadExtensions'])) { $params[] = '_paq.push([ "setDownloadExtensions", "' . implode('|', $this->options['piwikDownloadExtensions']) . '" ]);'; } if ($this->options['piwikInstallTracker'] == '') { $params[] = '_paq.push(["enableLinkTracking"]);'; } $this->chunkie->setPlaceholder('piwikURL', $this->options['piwikURL']); $this->chunkie->setPlaceholder('piwikSiteId', $this->options['piwikSiteId']); $this->chunkie->setPlaceholder('piwikJsName', $this->options['piwikJsName']); $this->chunkie->setPlaceholder('piwikDocumentTitle', $this->actionName()); $this->chunkie->setPlaceholder('piwikParams', implode("\r\n", $params)); $this->chunkie->setTpl($this->chunkie->getTemplateChunk('@FILE templates/chunk.template.html')); $this->chunkie->prepareTemplate(); $template = $this->chunkie->process(); return $template; } else { return 'nix'; } return; }
function displayMultiValue($tvOutput, $params) { // replace masked placeholder tags (for templates that are set directly set in snippet call by @CODE) $maskedTags = array('((' => '[+', '))' => '+]'); $params['outerTpl'] = str_replace(array_keys($maskedTags), array_values($maskedTags), $params['outerTpl']); $params['rowTpl'] = str_replace(array_keys($maskedTags), array_values($maskedTags), $params['rowTpl']); $countOutput = count($tvOutput); $firstEmpty = true; if ($countOutput) { // check for first item empty foreach (current($tvOutput) as $value) { if ($value != '') { $firstEmpty = false; } } } // stop if there is no output if (!$countOutput || $firstEmpty) { $noResults = ''; if ($params['noResults'] != '') { $parser = new newChunkie($this->modx); $noResults = $parser->getTemplateChunk($params['noResults']); } if ($params['emptyOutput']) { // output nothing return $noResults; } else { // output empty outer template $parser = new newChunkie($this->modx); $parser->setPlaceholder('wrapper', $noResults); $parser->setTpl($parser->getTemplateChunk($params['outerTpl'])); $parser->prepareTemplate(); return $parser->process(); } } // random or sort output if ($params['randomize']) { shuffle($tvOutput); } elseif ($params['reverse']) { $tvOutput = array_reverse($tvOutput); } elseif (!empty($params['sortBy'])) { $this->sort($tvOutput, trim($params['sortBy']), strtolower(trim($params['sortDir']))); } // check for display all regarding selected rows count and offset $countOutput = $params['rows'] === 'all' ? $countOutput : count($params['rows']); $display = $limit = $params['display'] !== 'all' ? intval($params['display']) : $countOutput; $display = $display + $params['offset'] < $countOutput ? $display : $countOutput - $params['offset']; $offset = $params['offset']; // output $wrapper = array(); $i = $iteration = 1; $classes = array($params['firstClass']); // rowTpl output foreach ($tvOutput as $value) { if ($display == 0) { break; } if ($params['rows'] !== 'all' && !in_array($i, $params['rows'])) { // output only selected rows $i++; continue; } if ($offset) { // don't show the offset rows $offset--; $i++; continue; } if (!$params['toJson']) { if ($display == 1) { $classes[] = $params['lastClass']; } if ($iteration % 2) { $classes[] = $params['oddClass']; } else { $classes[] = $params['evenClass']; } $parser = new newChunkie($this->modx); foreach ($value as $key => $fieldvalue) { $fieldname = is_int($key) ? $this->fieldnames[$key] : $key; $parser->setPlaceholder($fieldname, $fieldvalue); } $parser->setPlaceholder('iteration', $iteration); $parser->setPlaceholder('row', array('number' => $i, 'class' => implode(' ', $classes), 'total' => $countOutput)); $parser->setPlaceholder('docid', $params['docid']); $parser->setTpl($parser->getTemplateChunk($params['rowTpl'])); $parser->prepareTemplate(); $placeholder = $parser->process(); if ($params['toPlaceholder']) { $this->modx->setPlaceholder($params['toPlaceholder'] . '.' . $i, $placeholder); } $wrapper[] = $placeholder; $classes = array(); } else { $wrapper[] = $value; } $i++; $iteration++; $display--; } if ($params['emptyOutput'] && !count($wrapper)) { // output nothing $output = ''; } else { if (!$params['toJson']) { // wrap rowTpl output in outerTpl $parser = new newChunkie($this->modx); $parser->setPlaceholder('wrapper', implode($params['outputSeparator'], $wrapper)); $parser->setPlaceholder('rows', array('offset' => $params['offset'], 'total' => $countOutput)); $parser->setPlaceholder('docid', $params['docid']); if ($params['paginate']) { $pagination = new Pagination(array('per_page' => $limit, 'num_links' => 2, 'cur_page' => $params['offset'] / $limit + 1, 'total_rows' => $countOutput, 'page_query_string' => $params['offsetKey'], 'use_page_numbers' => true, 'first_link' => $this->language['paginate.first'], 'prev_link' => $this->language['paginate.prev'], 'next_link' => $this->language['paginate.next'], 'last_link' => $this->language['paginate.last'])); $parser->setPlaceholder('pagination', $pagination->create_links()); } $parser->setTpl($parser->getTemplateChunk($params['outerTpl'])); $parser->prepareTemplate(); $output = $parser->process(); } else { $output = json_encode($wrapper); } } if ($params['toPlaceholder']) { $this->modx->setPlaceholder($params['toPlaceholder'], $output); $output = ''; } return $output; }