protected function compile() { if (\Input::get('isAjax') == '1') { return; } $objFilter = new Articlefilter($this->getRootIdFromUrl(), $this->imgSize); $objFilter->selectedFilter = \Input::get('articlefilter_filter'); $objFilter->afstype = \Input::get('afstype'); $objFilter->sorting = $this->articlefilter_sorting; $objFilter->showAll = true; $objFilter->run(); /* search articles matching filter */ if ($objFilter->resultCount > 0) { $resultCount = $objFilter->resultCount; $results = $objFilter->results; if ($this->perPage > 0 && $resultCount > $this->perPage) { $objPagination = new \Pagination($resultCount, $this->perPage); $this->Template->pagination = $objPagination->generate(); $page = \Input::get('page'); if ($page == '' || $page < 1) { $page = 1; } $offset = ($page - 1) * $this->perPage; $results = array_slice($results, $offset, $this->perPage); } $this->Template->resultCount = $resultCount; $this->Template->results = $results; $this->Template->showFilter = $this->articlefilter_showfilter; $this->Template->selectedFilter = $objFilter->searchStrings; $this->Template->selectedFilterHeadline = sprintf($GLOBALS['TL_LANG']['articlefilter']['selectedFilterHeadline'], $resultCount); } else { $this->Template->no_filter = true; } }
/** * Generate content element */ protected function compile() { global $objPage; $this->import('String'); $arrDownloadFiles = array(); $time = time(); foreach ($this->arrDownloadfiles as $k => $archive) { $objArchive = \FelixPfeiffer\Downloadarchive\DownloadarchiveModel::findByPk($k); $strLightboxId = 'lightbox[' . substr(md5($objArchive->title . '_' . $objArchive->id), 0, 6) . ']'; foreach ($archive as $f => $arrFile) { #$objFile = \FilesModel::findByUuid($arrFile['singleSRC']); $objFile = new \File($f, true); // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $arrFile['description'] = \String::toXhtml($arrFile['description']); } else { $arrFile['description'] = \String::toHtml5($arrFile['description']); } $arrFile['description'] = \String::encodeEmail($arrFile['description']); $arrFile['css'] = $objArchive->class != "" ? $objArchive->class . ' ' : ''; $arrFile['ctime'] = $objFile->ctime; $arrFile['ctimeformated'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $objFile->ctime); $arrFile['mtime'] = $objFile->mtime; $arrFile['mtimeformated'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $objFile->mtime); $arrFile['atime'] = $objFile->mtime; $arrFile['atimeformated'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $objFile->atime); // Add an image if ($arrFile['addImage'] && $arrFile['imgSRC'] != '') { $objModel = \FilesModel::findByUuid($arrFile['imgSRC']); if (is_file(TL_ROOT . '/' . $objModel->path)) { $size = deserialize($arrFile['size']); $arrFile['imgSRC'] = $arrFile['imgSrc'] = \Image::get($objModel->path, $size[0], $size[1], $size[2]); // Image dimensions if (($imgSize = @getimagesize(TL_ROOT . '/' . rawurldecode($arrFile['imgSRC']))) !== false) { $arrFile['arrSize'] = $imgSize; $arrFile['imageSize'] = ' ' . $imgSize[3]; } $arrFile['imgHref'] = $objModel->path; $arrFile['alt'] = specialchars($arrFile['alt']); $arrFile['imagemargin'] = $this->generateMargin(deserialize($arrFile['imagemargin']), 'padding'); $arrFile['floating'] = in_array($arrFile['floating'], array('left', 'right')) ? sprintf(' float:%s;', $arrFile['floating']) : ''; $arrFile['addImage'] = true; $arrFile['lightbox'] = $objPage->outputFormat == 'xhtml' || VERSION < 2.11 ? ' rel="' . $strLightboxId . '"' : ' data-lightbox="' . substr($strLightboxId, 9, -1) . '"'; } } $arrFile['size'] = $this->getReadableSize($objFile->filesize); $src = TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon; if (($imgSize = @getimagesize(TL_ROOT . '/' . $src)) !== false) { $arrFile['iconSize'] = ' ' . $imgSize[3]; } $arrFile['icon'] = $src; $arrFile['href'] = $this->Environment->request . (stristr($this->Environment->request, '?') ? '&' : '?') . 'file=' . $this->urlEncode($f); $arrFile['archive'] = $objArchive->title; $strSorting = str_replace(array(' ASC', ' DESC'), '', $this->downloadSorting); $arrDownloadFiles[$arrFile[$strSorting]][] = $arrFile; } } if (stristr($this->downloadSorting, 'DESC')) { krsort($arrDownloadFiles); } else { ksort($arrDownloadFiles); } $arrFiles = array(); foreach ($arrDownloadFiles as $row) { foreach ($row as $file) { $arrFiles[] = $file; } } if ($this->downloadNumberOfItems > 0) { $arrFiles = array_slice($arrFiles, 0, $this->downloadNumberOfItems); } $i = 0; $length = count($arrFiles); if ($this->perPage > 0) { // Get the current page $page = $this->Input->get('page') ? $this->Input->get('page') : 1; if ($page > $length / $this->perPage) { $page = ceil($length / $this->perPage); } $offset = (($page > 1 ? $page : 1) - 1) * $this->perPage; $arrFiles = array_slice($arrFiles, $offset, $this->perPage); // Add pagination menu $objPagination = new Pagination($length, $this->perPage); $this->Template->pagination = $objPagination->generate("\n "); $length = count($arrFiles); } foreach ($arrFiles as $file) { $class = ""; if ($i++ == 0) { $class = "first "; } $class .= $i % 2 == 0 ? "even" : "odd"; if ($i == $length) { $class .= " last"; } $arrFiles[$i - 1]['css'] .= $class; } if (count($arrFiles) < 1) { $this->Template->arrFiles = $GLOBALS['TL_LANG']['MSC']['keinDownload']; } else { $this->Template->showMeta = $this->downloadShowMeta ? true : false; $this->Template->hideDate = $this->downloadHideDate ? true : false; $this->Template->arrFiles = $arrFiles; } }
/** * Add comments to a template * @param FrontendTemplate * @param stdClass * @param string * @param integer * @param array */ public function addCommentsToTemplate(FrontendTemplate $objTemplate, stdClass $objConfig, $strSource, $intParent, $arrNotifies) { global $objPage; $this->import('String'); $limit = null; $arrComments = array(); // Pagination if ($objConfig->perPage > 0) { // Get the total number of comments $objTotal = $this->Database->prepare("SELECT COUNT(*) AS count FROM tl_comments WHERE source=? AND parent=?" . (!BE_USER_LOGGED_IN ? " AND published=1" : ""))->execute($strSource, $intParent); $total = $objTotal->count; // Get the current page $page = $this->Input->get('page') ? $this->Input->get('page') : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $objConfig->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); $objTemplate->allowComments = false; $objTemplate->comments = array(); // see #4064 return; } // Set limit and offset $limit = $objConfig->perPage; $offset = ($page - 1) * $objConfig->perPage; // Initialize the pagination menu $objPagination = new Pagination($objTotal->count, $objConfig->perPage); $objTemplate->pagination = $objPagination->generate("\n "); } $objTemplate->allowComments = true; // Get all published comments $objCommentsStmt = $this->Database->prepare("SELECT c.*, u.name as authorName FROM tl_comments c LEFT JOIN tl_user u ON c.author=u.id WHERE c.source=? AND c.parent=?" . (!BE_USER_LOGGED_IN ? " AND c.published=1" : "") . " ORDER BY c.date" . ($objConfig->order == 'descending' ? " DESC" : "")); if ($limit) { $objCommentsStmt->limit($limit, $offset); } $objComments = $objCommentsStmt->execute($strSource, $intParent); $total = $objComments->numRows; if ($total > 0) { $count = 0; if ($objConfig->template == '') { $objConfig->template = 'com_default'; } $objPartial = new FrontendTemplate($objConfig->template); while ($objComments->next()) { $objPartial->setData($objComments->row()); // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $objComments->comment = $this->String->toXhtml($objComments->comment); } else { $objComments->comment = $this->String->toHtml5($objComments->comment); } $objPartial->comment = trim(str_replace(array('{{', '}}'), array('{{', '}}'), $objComments->comment)); $objPartial->datim = $this->parseDate($objPage->datimFormat, $objComments->date); $objPartial->date = $this->parseDate($objPage->dateFormat, $objComments->date); $objPartial->class = ($count < 1 ? ' first' : '') . ($count >= $total - 1 ? ' last' : '') . ($count % 2 == 0 ? ' even' : ' odd'); $objPartial->by = $GLOBALS['TL_LANG']['MSC']['comment_by']; $objPartial->id = 'c' . $objComments->id; $objPartial->timestamp = $objComments->date; $objPartial->datetime = date('Y-m-d\\TH:i:sP', $objComments->date); $objPartial->addReply = false; // Reply if ($objComments->addReply && $objComments->reply != '' && $objComments->authorName != '') { $objPartial->addReply = true; $objPartial->rby = $GLOBALS['TL_LANG']['MSC']['reply_by']; $objPartial->reply = $this->replaceInsertTags($objComments->reply); // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $objPartial->reply = $this->String->toXhtml($objPartial->reply); } else { $objPartial->reply = $this->String->toHtml5($objPartial->reply); } } $arrComments[] = $objPartial->parse(); ++$count; } } $objTemplate->comments = $arrComments; $objTemplate->addComment = $GLOBALS['TL_LANG']['MSC']['addComment']; $objTemplate->name = $GLOBALS['TL_LANG']['MSC']['com_name']; $objTemplate->email = $GLOBALS['TL_LANG']['MSC']['com_email']; $objTemplate->website = $GLOBALS['TL_LANG']['MSC']['com_website']; $objTemplate->commentsTotal = $limit ? $objTotal->count : $total; // Get the front end user object $this->import('FrontendUser', 'User'); // Access control if ($objConfig->requireLogin && !BE_USER_LOGGED_IN && !FE_USER_LOGGED_IN) { $objTemplate->requireLogin = true; return; } // Form fields $arrFields = array('name' => array('name' => 'name', 'label' => $GLOBALS['TL_LANG']['MSC']['com_name'], 'value' => trim($this->User->firstname . ' ' . $this->User->lastname), 'inputType' => 'text', 'eval' => array('mandatory' => true, 'maxlength' => 64)), 'email' => array('name' => 'email', 'label' => $GLOBALS['TL_LANG']['MSC']['com_email'], 'value' => $this->User->email, 'inputType' => 'text', 'eval' => array('rgxp' => 'email', 'mandatory' => true, 'maxlength' => 128, 'decodeEntities' => true)), 'website' => array('name' => 'website', 'label' => $GLOBALS['TL_LANG']['MSC']['com_website'], 'inputType' => 'text', 'eval' => array('rgxp' => 'url', 'maxlength' => 128, 'decodeEntities' => true))); // Captcha if (!$objConfig->disableCaptcha) { $arrFields['captcha'] = array('name' => 'captcha', 'inputType' => 'captcha', 'eval' => array('mandatory' => true)); } // Comment field $arrFields['comment'] = array('name' => 'comment', 'label' => $GLOBALS['TL_LANG']['MSC']['com_comment'], 'inputType' => 'textarea', 'eval' => array('mandatory' => true, 'rows' => 4, 'cols' => 40, 'preserveTags' => true)); $doNotSubmit = false; $arrWidgets = array(); $strFormId = 'com_' . $strSource . '_' . $intParent; // Initialize widgets foreach ($arrFields as $arrField) { $strClass = $GLOBALS['TL_FFL'][$arrField['inputType']]; // Continue if the class is not defined if (!$this->classFileExists($strClass)) { continue; } $arrField['eval']['required'] = $arrField['eval']['mandatory']; $objWidget = new $strClass($this->prepareForWidget($arrField, $arrField['name'], $arrField['value'])); // Validate the widget if ($this->Input->post('FORM_SUBMIT') == $strFormId) { $objWidget->validate(); if ($objWidget->hasErrors()) { $doNotSubmit = true; } } $arrWidgets[$arrField['name']] = $objWidget; } $objTemplate->fields = $arrWidgets; $objTemplate->submit = $GLOBALS['TL_LANG']['MSC']['com_submit']; $objTemplate->action = ampersand($this->Environment->request); $objTemplate->messages = ''; // Backwards compatibility $objTemplate->formId = $strFormId; $objTemplate->hasError = $doNotSubmit; // Do not index or cache the page with the confirmation message if ($_SESSION['TL_COMMENT_ADDED']) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; $objTemplate->confirm = $GLOBALS['TL_LANG']['MSC']['com_confirm']; $_SESSION['TL_COMMENT_ADDED'] = false; } // Add the comment if ($this->Input->post('FORM_SUBMIT') == $strFormId && !$doNotSubmit) { $this->import('String'); $strWebsite = $arrWidgets['website']->value; // Add http:// to the website if ($strWebsite != '' && !preg_match('@^(https?://|ftp://|mailto:|#)@i', $strWebsite)) { $strWebsite = 'http://' . $strWebsite; } // Do not parse any tags in the comment $strComment = htmlspecialchars(trim($arrWidgets['comment']->value)); $strComment = str_replace(array('&', '<', '>'), array('[&]', '[lt]', '[gt]'), $strComment); // Remove multiple line feeds $strComment = preg_replace('@\\n\\n+@', "\n\n", $strComment); // Parse BBCode if ($objConfig->bbcode) { $strComment = $this->parseBbCode($strComment); } // Prevent cross-site request forgeries $strComment = preg_replace('/(href|src|on[a-z]+)="[^"]*(contao\\/main\\.php|typolight\\/main\\.php|javascript|vbscri?pt|script|alert|document|cookie|window)[^"]*"+/i', '$1="#"', $strComment); $time = time(); // Prepare the record $arrSet = array('source' => $strSource, 'parent' => $intParent, 'tstamp' => $time, 'name' => $arrWidgets['name']->value, 'email' => $arrWidgets['email']->value, 'website' => $strWebsite, 'comment' => $this->convertLineFeeds($strComment), 'ip' => $this->anonymizeIp($this->Environment->ip), 'date' => $time, 'published' => $objConfig->moderate ? '' : 1); $insertId = $this->Database->prepare("INSERT INTO tl_comments %s")->set($arrSet)->execute()->insertId; // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['addComment']) && is_array($GLOBALS['TL_HOOKS']['addComment'])) { foreach ($GLOBALS['TL_HOOKS']['addComment'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($insertId, $arrSet, $this); } } // Notification $objEmail = new Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['com_subject'], $this->Environment->host); // Convert the comment to plain text $strComment = strip_tags($strComment); $strComment = $this->String->decodeEntities($strComment); $strComment = str_replace(array('[&]', '[lt]', '[gt]'), array('&', '<', '>'), $strComment); // Add comment details $objEmail->text = sprintf($GLOBALS['TL_LANG']['MSC']['com_message'], $arrSet['name'] . ' (' . $arrSet['email'] . ')', $strComment, $this->Environment->base . $this->Environment->request, $this->Environment->base . 'contao/main.php?do=comments&act=edit&id=' . $insertId); // Do not send notifications twice if (is_array($arrNotifies)) { $arrNotifies = array_unique($arrNotifies); } $objEmail->sendTo($arrNotifies); // Pending for approval if ($objConfig->moderate) { $_SESSION['TL_COMMENT_ADDED'] = true; } $this->reload(); } }
/** * Return a pagination menu to browse results * * @return string */ protected function paginationMenu() { $session = $this->Session->getData(); $filter = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4 ? $this->strTable . '_' . CURRENT_ID : $this->strTable; list($offset, $limit) = explode(',', $this->limit); // Set the limit filter based on the page number if (isset($_GET['lp'])) { $lp = intval(\Input::get('lp')) - 1; if ($lp >= 0 && $lp < ceil($this->total / $limit)) { $session['filter'][$filter]['limit'] = $lp * $limit . ',' . $limit; $this->Session->setData($session); } $this->redirect(preg_replace('/&(amp;)?lp=[^&]+/i', '', \Environment::get('request'))); } if ($limit) { \Input::setGet('lp', $offset / $limit + 1); } $objPagination = new \Pagination($this->total, $limit, 7, 'lp', new \BackendTemplate('be_pagination'), true); return $objPagination->generate(); }
/** * Generate the module */ protected function compile() { global $objPage; if ($this->rss_template != 'rss_default') { $this->strTemplate = $this->rss_template; $this->Template = new \FrontendTemplate($this->strTemplate); $this->Template->setData($this->arrData); } $this->Template->link = $this->objFeed->get_link(); $this->Template->title = $this->objFeed->get_title(); $this->Template->language = $this->objFeed->get_language(); $this->Template->description = $this->objFeed->get_description(); $this->Template->copyright = $this->objFeed->get_copyright(); // Add image if ($this->objFeed->get_image_url()) { $this->Template->image = true; $this->Template->src = $this->objFeed->get_image_url(); $this->Template->alt = $this->objFeed->get_image_title(); $this->Template->href = $this->objFeed->get_image_link(); $this->Template->height = $this->objFeed->get_image_height(); $this->Template->width = $this->objFeed->get_image_width(); } // Get items $arrItems = $this->objFeed->get_items(intval($this->skipFirst), intval($this->numberOfItems)); $limit = count($arrItems); $offset = 0; // Split pages if ($this->perPage > 0) { // Get the current page $id = 'page_r' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > ceil(count($arrItems) / $this->perPage)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); $this->Template->items = array(); return; } // Set limit and offset $offset = ($page - 1) * $this->perPage; $limit = $this->perPage + $offset; $objPagination = new \Pagination(count($arrItems), $this->perPage, 7, $id); $this->Template->pagination = $objPagination->generate("\n "); } $items = array(); $last = min($limit, count($arrItems)) - 1; for ($i = $offset; $i < $limit && $i < count($arrItems); $i++) { $items[$i] = array('link' => $arrItems[$i]->get_link(), 'title' => $arrItems[$i]->get_title(), 'permalink' => $arrItems[$i]->get_permalink(), 'description' => str_replace(array('<?', '?>'), array('<?', '?>'), $arrItems[$i]->get_description()), 'class' => ($i == 0 ? ' first' : '') . ($i == $last ? ' last' : '') . ($i % 2 == 0 ? ' even' : ' odd'), 'pubdate' => $this->parseDate($objPage->datimFormat, $arrItems[$i]->get_date('U')), 'category' => $arrItems[$i]->get_category(0)); // Add author if (($objAuthor = $arrItems[$i]->get_author(0)) != false) { $items[$i]['author'] = trim($objAuthor->name . ' ' . $objAuthor->email); } // Add enclosure if (($objEnclosure = $arrItems[$i]->get_enclosure(0)) != false) { $items[$i]['enclosure'] = $objEnclosure->get_link(); } } $this->Template->items = array_values($items); }
/** * Add a list of versions to a template * * @param \BackendTemplate|object $objTemplate */ public static function addToTemplate(\BackendTemplate $objTemplate) { $arrVersions = array(); $objUser = \BackendUser::getInstance(); $objDatabase = \Database::getInstance(); // Get the total number of versions $objTotal = $objDatabase->prepare("SELECT COUNT(*) AS count FROM tl_version WHERE version>1" . (!$objUser->isAdmin ? " AND userid=?" : ""))->execute($objUser->id); $intLast = ceil($objTotal->count / 30); $intPage = \Input::get('vp') !== null ? \Input::get('vp') : 1; $intOffset = ($intPage - 1) * 30; // Validate the page number if ($intPage < 1 || $intLast > 0 && $intPage > $intLast) { header('HTTP/1.1 404 Not Found'); } // Create the pagination menu $objPagination = new \Pagination($objTotal->count, 30, 7, 'vp', new \BackendTemplate('be_pagination')); $objTemplate->pagination = $objPagination->generate(); // Get the versions $objVersions = $objDatabase->prepare("SELECT pid, tstamp, version, fromTable, username, userid, description, editUrl, active FROM tl_version" . (!$objUser->isAdmin ? " WHERE userid=?" : "") . " ORDER BY tstamp DESC, pid, version DESC")->limit(30, $intOffset)->execute($objUser->id); while ($objVersions->next()) { $arrRow = $objVersions->row(); // Add some parameters $arrRow['from'] = max($objVersions->version - 1, 1); // see #4828 $arrRow['to'] = $objVersions->version; $arrRow['date'] = date(\Config::get('datimFormat'), $objVersions->tstamp); $arrRow['description'] = \String::substr($arrRow['description'], 32); $arrRow['shortTable'] = \String::substr($arrRow['fromTable'], 18); // see #5769 if ($arrRow['editUrl'] != '') { $arrRow['editUrl'] = preg_replace('/&(amp;)?rt=[a-f0-9]+/', '&rt=' . REQUEST_TOKEN, ampersand($arrRow['editUrl'])); } $arrVersions[] = $arrRow; } $intCount = -1; $arrVersions = array_values($arrVersions); // Add the "even" and "odd" classes foreach ($arrVersions as $k => $v) { $arrVersions[$k]['class'] = ++$intCount % 2 == 0 ? 'even' : 'odd'; try { // Mark deleted versions (see #4336) $objDeleted = $objDatabase->prepare("SELECT COUNT(*) AS count FROM " . $v['fromTable'] . " WHERE id=?")->execute($v['pid']); $arrVersions[$k]['deleted'] = $objDeleted->count < 1; } catch (\Exception $e) { // Probably a disabled module --$intCount; unset($arrVersions[$k]); } } $objTemplate->versions = $arrVersions; }
/** * Generate the content element */ protected function compile() { global $objPage; $images = array(); $auxDate = array(); $auxId = array(); $objFiles = $this->objFiles; // Get all images while ($objFiles->next()) { // Continue if the files has been processed or does not exist if (isset($images[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) { continue; } // Single files if ($objFiles->type == 'file') { $objFile = new \File($objFiles->path); if (!$objFile->isGdImage) { continue; } $arrMeta = $this->getMetaData($objFiles->meta, $objPage->language); // Use the file name as title if none is given if ($arrMeta['title'] == '') { $arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename))); } // Add the image $images[$objFiles->path] = array('id' => $objFiles->id, 'name' => $objFile->basename, 'singleSRC' => $objFiles->path, 'alt' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']); $auxDate[] = $objFile->mtime; $auxId[] = $objFiles->id; } else { $objSubfiles = \FilesModel::findByPid($objFiles->id); if ($objSubfiles === null) { continue; } while ($objSubfiles->next()) { // Skip subfolders if ($objSubfiles->type == 'folder') { continue; } $objFile = new \File($objSubfiles->path); if (!$objFile->isGdImage) { continue; } $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->language); // Use the file name as title if none is given if ($arrMeta['title'] == '') { $arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename))); } // Add the image $images[$objSubfiles->path] = array('id' => $objSubfiles->id, 'name' => $objFile->basename, 'singleSRC' => $objSubfiles->path, 'alt' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']); $auxDate[] = $objFile->mtime; $auxId[] = $objSubfiles->id; } } } // Sort array switch ($this->sortBy) { default: case 'name_asc': uksort($images, 'basename_natcasecmp'); break; case 'name_desc': uksort($images, 'basename_natcasercmp'); break; case 'date_asc': array_multisort($images, SORT_NUMERIC, $auxDate, SORT_ASC); break; case 'date_desc': array_multisort($images, SORT_NUMERIC, $auxDate, SORT_DESC); break; case 'meta': // Backwards compatibility // Backwards compatibility case 'custom': if ($this->orderSRC != '') { // Turn the order string into an array $arrOrder = array_flip(array_map('intval', explode(',', $this->orderSRC))); // Move the matching elements to their position in $arrOrder foreach ($images as $k => $v) { if (isset($arrOrder[$v['id']])) { $arrOrder[$v['id']] = $v; unset($images[$k]); } } // Append the left-over images at the end if (!empty($images)) { $arrOrder = array_merge($arrOrder, $images); } // Remove empty or numeric (not replaced) entries foreach ($arrOrder as $k => $v) { if ($v == '' || is_numeric($v)) { unset($arrOrder[$k]); } } $images = $arrOrder; unset($arrOrder); } break; case 'random': shuffle($images); break; } $images = array_values($images); // Limit the total number of items (see #2652) if ($this->numberOfItems > 0) { $images = array_slice($images, 0, $this->numberOfItems); } $offset = 0; $total = count($images); $limit = $total; // Pagination if ($this->perPage > 0) { // Get the current page $id = 'page_g' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } // Set limit and offset $offset = ($page - 1) * $this->perPage; $limit = min($this->perPage + $offset, $total); $objPagination = new \Pagination($total, $this->perPage, 7, $id); $this->Template->pagination = $objPagination->generate("\n "); } $rowcount = 0; $colwidth = floor(100 / $this->perRow); $intMaxWidth = TL_MODE == 'BE' ? floor(640 / $this->perRow) : floor($GLOBALS['TL_CONFIG']['maxImageWidth'] / $this->perRow); $strLightboxId = 'lightbox[lb' . $this->id . ']'; $body = array(); // Rows for ($i = $offset; $i < $limit; $i = $i + $this->perRow) { $class_tr = ''; if ($rowcount == 0) { $class_tr .= ' row_first'; } if ($i + $this->perRow >= $limit) { $class_tr .= ' row_last'; } $class_eo = $rowcount % 2 == 0 ? ' even' : ' odd'; // Columns for ($j = 0; $j < $this->perRow; $j++) { $class_td = ''; if ($j == 0) { $class_td = ' col_first'; } if ($j == $this->perRow - 1) { $class_td = ' col_last'; } $objCell = new \stdClass(); $key = 'row_' . $rowcount . $class_tr . $class_eo; // Empty cell if (!is_array($images[$i + $j]) || $j + $i >= $limit) { $objCell->class = 'col_' . $j . $class_td; } else { // Add size and margin $images[$i + $j]['size'] = $this->size; $images[$i + $j]['imagemargin'] = $this->imagemargin; $images[$i + $j]['fullsize'] = $this->fullsize; $this->addImageToTemplate($objCell, $images[$i + $j], $intMaxWidth, $strLightboxId); // Add column width and class $objCell->colWidth = $colwidth . '%'; $objCell->class = 'col_' . $j . $class_td; } $body[$key][$j] = $objCell; } ++$rowcount; } $strTemplate = 'gallery_default'; // Use a custom template if (TL_MODE == 'FE' && $this->galleryTpl != '') { $strTemplate = $this->galleryTpl; } $objTemplate = new \FrontendTemplate($strTemplate); $objTemplate->setData($this->arrData); $objTemplate->body = $body; $objTemplate->headline = $this->headline; // see #1603 $this->Template->images = $objTemplate->parse(); }
/** * Generate the content element */ protected function compile() { $images = $this->facebookAlbum->getImages($this->facebook_album_order, $GLOBALS['objPage']->language, $this->metaIgnore, $GLOBALS['objPage']->rootFallbackLanguage); if (empty($images)) { return; } $images = array_values($images); // Limit the total number of items if ($this->numberOfItems > 0) { $images = array_slice($images, 0, $this->numberOfItems); } $offset = 0; $total = count($images); $limit = $total; // Pagination if ($this->perPage > 0) { // Get the current page $id = 'page_g' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { /** @var \PageError404 $objHandler */ $handler = new $GLOBALS['TL_PTY']['error_404'](); $handler->generate($GLOBALS['objPage']->id); } // Set limit and offset $offset = ($page - 1) * $this->perPage; $limit = min($this->perPage + $offset, $total); $pagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $pagination->generate("\n "); } $this->Template->images = $this->generatePartial($images, $offset, $limit); // Add the album information if ($this->facebook_album_info) { $this->compileAlbumInfo($total); } }
/** * Generate the module */ protected function compile() { global $objPage; $blnClearInput = false; // Jump to the current period if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day'])) { switch ($this->cal_format) { case 'cal_year': \Input::setGet('year', date('Y')); break; case 'cal_month': \Input::setGet('month', date('Ym')); break; case 'cal_day': \Input::setGet('day', date('Ymd')); break; } $blnClearInput = true; } $blnDynamicFormat = !$this->cal_ignoreDynamic && in_array($this->cal_format, array('cal_day', 'cal_month', 'cal_year')); // Display year if ($blnDynamicFormat && \Input::get('year')) { $this->Date = new \Date(\Input::get('year'), 'Y'); $this->cal_format = 'cal_year'; $this->headline .= ' ' . date('Y', $this->Date->tstamp); } elseif ($blnDynamicFormat && \Input::get('month')) { $this->Date = new \Date(\Input::get('month'), 'Ym'); $this->cal_format = 'cal_month'; $this->headline .= ' ' . $this->parseDate('F Y', $this->Date->tstamp); } elseif ($blnDynamicFormat && \Input::get('day')) { $this->Date = new \Date(\Input::get('day'), 'Ymd'); $this->cal_format = 'cal_day'; $this->headline .= ' ' . $this->parseDate($objPage->dateFormat, $this->Date->tstamp); } else { $this->Date = new \Date(); } list($strBegin, $strEnd, $strEmpty) = $this->getDatesFromFormat($this->Date, $this->cal_format); // we have to check if we have to show recurrences and pass it to the getAllEventsExt function... $showRecurrences = $this->showRecurrences ? false : true; // Get all events $arrAllEvents = $this->getAllEventsExt($this->cal_holiday, $this->cal_calendar, $strBegin, $strEnd, $showRecurrences); $sort = $this->cal_order == 'descending' ? 'krsort' : 'ksort'; // Sort the days $sort($arrAllEvents); // Sort the events foreach (array_keys($arrAllEvents) as $key) { $sort($arrAllEvents[$key]); } $arrEvents = array(); $dateBegin = date('Ymd', $strBegin); $dateEnd = date('Ymd', $strEnd); // Remove events outside the scope foreach ($arrAllEvents as $key => $days) { if ($key < $dateBegin || $key > $dateEnd) { continue; } foreach ($days as $day => $events) { foreach ($events as $event) { $event['firstDay'] = $GLOBALS['TL_LANG']['DAYS'][date('w', $day)]; $event['firstDate'] = $this->parseDate($objPage->dateFormat, $day); $event['datetime'] = date('Y-m-d', $day); $event['pname'] = $this->calConf[$event['pid']]['calendar']; if ($this->calConf[$event['pid']]['background']) { $event['bgstyle'] = $this->calConf[$event['pid']]['background']; } if ($this->calConf[$event['pid']]['foreground']) { $event['fgstyle'] = $this->calConf[$event['pid']]['foreground']; } $arrEvents[] = $event; } } } unset($arrAllEvents, $days); $total = count($arrEvents); $limit = $total; $offset = 0; // Overall limit if ($this->cal_limit > 0) { $total = min($this->cal_limit, $total); $limit = $total; } // Pagination if ($this->perPage > 0) { $id = 'page_e' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } $offset = ($page - 1) * $this->perPage; $limit = min($this->perPage + $offset, $total); $objPagination = new \Pagination($total, $this->perPage, 7, $id); $this->Template->pagination = $objPagination->generate("\n "); } $strMonth = ''; $strDate = ''; $strEvents = ''; $dayCount = 0; $eventCount = 0; $headerCount = 0; $imgSize = false; // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0) { $imgSize = $this->imgSize; } } // Parse events for ($i = $offset; $i < $limit; $i++) { $event = $arrEvents[$i]; $blnIsLastEvent = false; // Last event on the current day if ($i + 1 == $limit || !isset($arrEvents[$i + 1]['firstDate']) || $event['firstDate'] != $arrEvents[$i + 1]['firstDate']) { $blnIsLastEvent = true; } $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData($event); // Month header if ($strMonth != $event['month']) { $objTemplate->newMonth = true; $strMonth = $event['month']; } // Day header if ($strDate != $event['firstDate']) { $headerCount = 0; $objTemplate->header = true; $objTemplate->classHeader = ($dayCount % 2 == 0 ? ' even' : ' odd') . ($dayCount == 0 ? ' first' : '') . ($event['firstDate'] == $arrEvents[$limit - 1]['firstDate'] ? ' last' : ''); $strDate = $event['firstDate']; ++$dayCount; } // Add template variables $objTemplate->classList = $event['class'] . ($headerCount % 2 == 0 ? ' even' : ' odd') . ($headerCount == 0 ? ' first' : '') . ($blnIsLastEvent ? ' last' : '') . ' cal_' . $event['parent']; $objTemplate->classUpcoming = $event['class'] . ($eventCount % 2 == 0 ? ' even' : ' odd') . ($eventCount == 0 ? ' first' : '') . ($offset + $eventCount + 1 >= $limit ? ' last' : '') . ' cal_' . $event['parent']; $objTemplate->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $event['title'])); $objTemplate->more = $GLOBALS['TL_LANG']['MSC']['more']; // Short view if ($this->cal_noSpan) { $objTemplate->day = $event['day']; $objTemplate->date = $event['date']; $objTemplate->span = $event['time'] == '' && $event['day'] == '' ? $event['date'] : ''; } else { $objTemplate->day = $event['firstDay']; $objTemplate->date = $event['firstDate']; $objTemplate->span = ''; } $objTemplate->addImage = false; // Add an image if ($event['addImage'] && $event['singleSRC'] != '') { if (!is_numeric($event['singleSRC'])) { $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } else { $objModel = \FilesModel::findByPk($event['singleSRC']); if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) { if ($imgSize) { $event['size'] = $imgSize; } $event['singleSRC'] = $objModel->path; $this->addImageToTemplate($objTemplate, $event); } } } $objTemplate->enclosure = array(); // Add enclosure if ($event['addEnclosure']) { $this->addEnclosuresToTemplate($objTemplate, $event); } $strEvents .= $objTemplate->parse(); ++$eventCount; ++$headerCount; } // No events found if ($strEvents == '') { $strEvents = "\n" . '<div class="empty">' . $strEmpty . '</div>' . "\n"; } // See #3672 $this->Template->headline = $this->headline; $this->Template->events = $strEvents; // Clear the $_GET array (see #2445) if ($blnClearInput) { \Input::setGet('year', null); \Input::setGet('month', null); \Input::setGet('day', null); } }
/** * Generate the module */ protected function compile() { $arrArchives = deserialize($this->videobox_archives, true); if (empty($arrArchives)) { return ''; } // basic template variables $this->Template->hasVideos = true; // prepare the sql $strSQL = ''; if ($this->videobox_sql) { $strSQL = ' ' . trim($this->videobox_sql); } $intTotal = (int) $this->Database->query('SELECT COUNT(id) AS total FROM tl_videobox WHERE pid IN (' . implode(',', $arrArchives) . ')' . $strSQL)->total; if ($intTotal == 0) { $this->Template->hasVideos = false; $this->Template->msg = $GLOBALS['TL_LANG']['VideoBox']['no_videos']; return; } $limit = $intTotal; $offset = 0; // Pagination if ($this->perPage > 0) { $page = $this->Input->get('page') ? $this->Input->get('page') : 1; $offset = ($page - 1) * $this->perPage; $limit = min($this->perPage + $offset, $intTotal); $objPagination = new Pagination($intTotal, $this->perPage); $this->Template->pagination = $objPagination->generate("\n "); } // videobox statement $objVideosStmt = $this->Database->prepare('SELECT id FROM tl_videobox WHERE pid IN (' . implode(',', $arrArchives) . ')' . $strSQL); // Limit the result if (isset($limit)) { $objVideosStmt->limit($limit, $offset); } $objVideos = $objVideosStmt->execute(); $arrVideos = array(); $count = 0; $this->import('VideoBoxHelpers', 'VBHelper'); while ($objVideos->next()) { $arrVideoData = $this->VBHelper->prepareVideoTemplateData($objVideos->id, $this->videobox_jumpTo); $arrVideos[$objVideos->id] = array_merge($arrVideoData, array('count' => ++$count, 'cssClass' => ($count == 1 ? ' first' : '') . ($count == $limit ? ' last' : '') . ($count % 2 == 0 ? ' odd' : ' even'))); } $this->Template->videos = $arrVideos; }
/** * Generate the module */ protected function compile() { $offset = intval($this->skipFirst); $limit = null; // Maximum number of items if ($this->numberOfItems > 0) { $limit = $this->numberOfItems; } // Maximum number of items if ($this->numberOfItems > 0) { $limit = $this->numberOfItems; } $this->Template->carpets = array(); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyCategory']; $intTotal = \CarpetModel::countPublishedByPids($this->carpet_categories, $this->carpet_status); if ($intTotal < 1) { return; } $total = $intTotal - $offset; // Split the results if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) { // Adjust the overall limit if (isset($limit)) { $total = min($limit, $total); } // Get the current page $id = 'page_n' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } // Set limit and offset $limit = $this->perPage; $offset += (max($page, 1) - 1) * $this->perPage; $skip = intval($this->skipFirst); // Overall limit if ($offset + $limit > $total + $skip) { $limit = $total + $skip - $offset; } // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } $arrOptions = array(); if ($this->carpet_sortBy) { switch ($this->carpet_sortBy) { case 'title_asc': $arrOptions['order'] = "title ASC"; break; case 'title_desc': $arrOptions['order'] = "title DESC"; break; case 'alias_asc': $arrOptions['order'] = "alias ASC"; break; case 'alias_desc': $arrOptions['order'] = "alias DESC"; break; case 'date_asc': $arrOptions['order'] = "date ASC"; break; case 'date_desc': $arrOptions['order'] = "date DESC"; break; case 'custom': $arrOptions['order'] = "sorting ASC"; break; } } // Get the items if (isset($limit)) { $objCarpets = \CarpetModel::findPublishedByPids($this->carpet_categories, $limit, $offset, $this->carpet_status, $arrOptions); } else { $objCarpets = \CarpetModel::findPublishedByPids($this->carpet_categories, 0, $offset, $this->carpet_status, $arrOptions); } // Add the Carpets if ($objCarpets !== null) { $this->Template->carpets = $this->parseCarpets($objCarpets); } $this->Template->gategories = $this->carpet_categories; }
/** * * @param int $id * @return Template */ public function loadEventData($id = 0) { $evt = $this->getEvent($id); $sub = $this->getEventSubscription($id); $num_sub = $this->countEventSubscription($id); // print_r($evt); $objTemplate = new BackendTemplate('mod_event_subscribe'); $objTemplate->back = $GLOBALS['TL_LANG']['MSC']['goBack']; $objTemplate->referer = 'javascript:history.go(-1)'; $objTemplate->wildcard = '### EVENT LIST ###'; $objTemplate->title = $evt['title']; $objTemplate->headline = $evt['teaser']; $objTemplate->id = $this->id; $objTemplate->date_from = date('d/m/Y', $evt['startDate']); $objTemplate->date_to = date('d/m/Y', $evt['endDate']); $objTemplate->calendar = 'test'; $objTemplate->link = 'link'; $objTemplate->entries = $evt; $objTemplate->num_sub = $num_sub; $objTemplate->sub = $sub; // $objTemplate->referer = 'typolight/main.php?do=tl_calendar_events_subscribe'; $objTemplate->href = 'typolight/main.php?do=modules&act=edit&id=' . $this->id; // Pagination if ($this->perPage > 0) { $limit = $this->perPage; // Get total number of events // $this->num_events = $this->countEvents(); // Add pagination menu $objPagination = new Pagination($num_sub, $this->perPage); $objTemplate->pagination = $objPagination->generate("\n "); } return $objTemplate->parse(); }
/** * Generate module */ protected function compile() { global $objPage; $blnExport = false; $blnCustomXlsExport = false; $strExportMode = 'csv'; $strSearchFormType = 'dropdown'; if ($this->efg_list_searchtype) { $strSearchFormType = $this->efg_list_searchtype; } $this->import('String'); $this->import('FrontendUser', 'Member'); $this->list_table = 'tl_formdata'; $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload'])); // get names of detail fields $objFF = $this->Database->prepare("SELECT ff.name, ff.label, ff.type, ff.rgxp FROM tl_form_field ff, tl_form f WHERE (ff.pid=f.id) AND ff.name != '' AND f.storeFormdata=?")->execute("1"); if ($objFF->numRows) { $this->arrFF = array(); $this->arrFFNames = array(); while ($objFF->next()) { $arrField = $objFF->row(); $this->arrFF[$arrField['name']] = $arrField; $this->arrFFNames[] = $arrField['name']; } } $this->strFormKey = ''; $this->strDcaKey = 'tl_formdata'; $this->strFormFilterKey = ''; $this->strFormFilterValue = ''; if (strlen($this->list_formdata)) { if ($this->list_formdata == 'feedback' || $this->list_formdata == 'fd_feedback' || $this->list_formdata == 'tl_formdata') { $this->strFormKey = ''; $this->strDcaKey = 'fd_feedback'; $this->strFormFilterKey = ''; $this->strFormFilterValue = ''; } else { $this->strFormKey = substr($this->list_formdata, 0, 3) == 'fd_' ? $this->list_formdata : 'fd_' . $this->list_formdata; $this->strDcaKey = substr($this->list_formdata, 0, 3) == 'fd_' ? $this->list_formdata : 'fd_' . $this->list_formdata; $this->strFormFilterKey = 'form'; $this->strFormFilterValue = $this->arrStoreForms[str_replace('fd_', '', $this->strFormKey)]['title']; $this->sqlFormFilter = ' AND ' . $this->strFormFilterKey . '=\'' . $this->strFormFilterValue . '\' '; } } // load dca-config into $GLOBALS['TL_DCA']['tl_formdata'] $this->loadDataContainer($this->strDcaKey); $this->loadLanguageFile('tl_formdata'); // Export if ($this->Input->get('act') == 'export') { $blnExport = true; $strExportMode = 'csv'; } elseif ($this->Input->get('act') == 'exportxls') { $blnExport = true; $strExportMode = 'xls'; } if ($blnExport) { $blnCustomXlsExport = false; $arrHookData = array(); $arrHookDataColumns = array(); $useFormValues = $this->FormData->arrStoreForms[substr($this->strFormKey, 3)]['useFormValues']; $useFieldNames = $this->FormData->arrStoreForms[substr($this->strFormKey, 3)]['useFieldNames']; $this->blnExportUTF8Decode = true; if (isset($GLOBALS['EFG']['exportUTF8Decode']) && $GLOBALS['EFG']['exportUTF8Decode'] == false) { $this->blnExportUTF8Decode = false; } if ($strExportMode == 'xls') { // check for HOOK efgExportXls if (array_key_exists('efgExportXls', $GLOBALS['TL_HOOKS']) && is_array($GLOBALS['TL_HOOKS']['efgExportXls'])) { $blnCustomXlsExport = true; } else { include TL_ROOT . '/plugins/xls_export/xls_export.php'; } } } else { $this->Template->textlink_details = $GLOBALS['TL_LANG']['tl_formdata']['fe_link_details']; $this->Template->textlink_edit = $GLOBALS['TL_LANG']['tl_formdata']['fe_link_edit']; $this->Template->textlink_delete = $GLOBALS['TL_LANG']['tl_formdata']['fe_link_delete']; $this->Template->text_confirmDelete = $GLOBALS['TL_LANG']['tl_formdata']['fe_deleteConfirm']; $this->Template->textlink_export = $GLOBALS['TL_LANG']['tl_formdata']['fe_link_export']; $this->Template->iconFolder = strlen($this->efg_iconfolder) ? $this->efg_iconfolder : 'system/modules/efg/html'; $this->Template->details = strlen($this->list_info) ? true : false; $this->Template->editable = false; if (strlen($this->efg_fe_edit_access)) { if ($this->efg_fe_edit_access == 'public') { $this->Template->editable = true; } elseif (($this->efg_fe_edit_access == 'member' || $this->efg_fe_edit_access == 'groupmembers') && intval($this->Member->id) > 0) { $this->Template->editable = true; } } $this->Template->deletable = false; if (strlen($this->efg_fe_delete_access)) { if ($this->efg_fe_delete_access == 'public') { $this->Template->deletable = true; } elseif (($this->efg_fe_delete_access == 'member' || $this->efg_fe_delete_access == 'groupmembers') && intval($this->Member->id) > 0) { $this->Template->deletable = true; } } $this->Template->exportable = false; if (strlen($this->efg_fe_export_access)) { if ($this->efg_fe_export_access == 'public') { $this->Template->exportable = true; } elseif (($this->efg_fe_export_access == 'member' || $this->efg_fe_export_access == 'groupmembers') && intval($this->Member->id) > 0) { $this->Template->exportable = true; } } } $this->arrBaseFields = $GLOBALS['TL_DCA']['tl_formdata']['tl_formdata']['baseFields']; $this->arrDetailFields = $GLOBALS['TL_DCA']['tl_formdata']['tl_formdata']['detailFields']; if (strlen($GLOBALS['TL_DCA']['tl_formdata']['tl_formdata']['formFilterKey'])) { $this->strFormFilterKey = $GLOBALS['TL_DCA']['tl_formdata']['tl_formdata']['formFilterKey']; } if (strlen($GLOBALS['TL_DCA']['tl_formdata']['tl_formdata']['formFilterValue'])) { $this->strFormFilterValue = $GLOBALS['TL_DCA']['tl_formdata']['tl_formdata']['formFilterValue']; } // List, edit or delete a single record if (strlen($this->Input->get($this->strDetailKey))) { // check details record $strQuery = "SELECT id FROM tl_formdata f"; $strWhere = " WHERE (id=? OR alias=?)"; if ($this->list_where) { $arrListWhere = array(); $arrListConds = preg_split('/(\\sAND\\s|\\sOR\\s)/si', $this->list_where, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($arrListConds as $strListCond) { if (preg_match('/\\sAND\\s|\\sOR\\s/si', $strListCond)) { $arrListWhere[] = $strListCond; } else { $arrListCond = preg_split('/([\\s!=><]+)/', $strListCond, -1, PREG_SPLIT_DELIM_CAPTURE); $strCondField = $arrListCond[0]; unset($arrListCond[0]); if (in_array($strCondField, $this->arrDetailFields)) { $arrListWhere[] = '(SELECT value FROM tl_formdata_details WHERE ff_name="' . $strCondField . '" AND pid=f.id ) ' . implode('', $arrListCond); } if (in_array($strCondField, $this->arrBaseFields)) { $arrListWhere[] = $strCondField . implode('', $arrListCond); } } } $strListWhere = count($arrListWhere) > 0 ? '(' . implode('', $arrListWhere) . ')' : ''; $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . $strListWhere; } if (strlen($this->strFormKey)) { $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . $this->strFormFilterKey . "='" . $this->strFormFilterValue . "'"; } // replace insert tags in where, e.g. {{user::id}} $strWhere = $this->replaceWhereTags($strWhere); $strWhere = $this->replaceInsertTags($strWhere); $strQuery .= $strWhere; $objCheck = $this->Database->prepare($strQuery)->execute($this->Input->get($this->strDetailKey), $this->Input->get($this->strDetailKey)); if ($objCheck->numRows == 1) { $this->intRecordId = intval($objCheck->id); } else { $this->log('Could not identify record by ID "' . $this->Input->get($this->strDetailKey) . '"', 'ModuleFormdataListing compile()', TL_GENERAL); $strUrl = preg_replace('/\\?.*$/', '', urldecode($this->Environment->request)); $strUrlParams = ''; $strUrlSuffix = $GLOBALS['TL_CONFIG']['urlSuffix']; $blnQuery = false; foreach (preg_split('/&(amp;)?/', urldecode($_SERVER['QUERY_STRING'])) as $fragment) { if (strlen($fragment)) { if (strncasecmp($fragment, 'file', 5) !== 0 && strncasecmp($fragment, $this->strDetailKey, strlen($this->strDetailKey)) !== 0 && strncasecmp($fragment, 'order_by', 8) !== 0 && strncasecmp($fragment, 'sort', 4) !== 0 && strncasecmp($fragment, 'page', 4) !== 0) { $strUrlParams .= (!$blnQuery ? '' : '&') . $fragment; $blnQuery = true; } } } $strRed = preg_replace(array('/\\/' . $this->strDetailKey . '\\/' . $this->Input->get($this->strDetailKey) . '/i', '/' . $this->strDetailKey . '=' . $this->Input->get($this->strDetailKey) . '/i'), array('', ''), $strUrl) . (strlen($strUrlParams) ? '?' . $strUrlParams : ''); $this->redirect($strRed); } if ($this->Input->get('act') == 'edit' && intval($this->intRecordId) > 0) { $this->editSingleRecord(); return; } elseif ($this->Input->get('act') == 'delete' && intval($this->intRecordId) > 0) { $this->deleteSingleRecord(); return; } elseif ($this->Input->get('act') == 'export' && intval($this->intRecordId) > 0) { $this->exportSingleRecord($strExportMode); return; } elseif (!is_null($this->intRecordId) && intval($this->intRecordId) > 0) { $this->listSingleRecord(); return; } } $page = $this->Input->get('page') ? $this->Input->get('page') : 1; $per_page = $this->Input->get('per_page') ? $this->Input->get('per_page') : $this->perPage; /** * Add search query */ $strWhere = ''; $varKeyword = ''; $strOptions = ''; if (count($this->arrAllowedOwnerIds) > 0) { $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . "fd_member IN (" . implode(',', $this->arrAllowedOwnerIds) . ")"; } if (!$blnExport) { $this->Template->searchable = false; } $arrSearchFields = trimsplit(',', $this->list_search); if ($strSearchFormType == 'none') { unset($arrSearchFields); } if (is_array($arrSearchFields) && count($arrSearchFields)) { if (!$blnExport) { $this->Template->searchable = true; $this->Template->search_form_type = $strSearchFormType; } switch ($strSearchFormType) { case 'singlefield': if (strlen($this->Input->get('search')) && strlen($this->Input->get('for'))) { $varKeyword = '%' . $this->Input->get('for') . '%'; $arrConds = array(); foreach (trimsplit(',', urldecode($this->Input->get('search'))) as $field) { if (in_array($field, $this->arrOwnerFields)) { if ($field == "fd_member") { $prop = 'arrMembers'; } elseif ($field == "fd_member_group") { $prop = 'arrMemberGroups'; } elseif ($field == "fd_user") { $prop = 'arrUsers'; } elseif ($field == "fd_user_group") { $prop = 'arrUserGroups'; } $arrMatches = $this->array_filter_like($this->{$prop}, $this->Input->get('for')); if (count($arrMatches)) { $arrConds[] = $field . " IN(" . implode(",", array_keys($arrMatches)) . ")"; } } elseif (in_array($field, $this->arrBaseFields)) { $arrConds[] = $field . " LIKE ?"; } else { $arrConds[] = '(SELECT value FROM tl_formdata_details WHERE ff_name="' . $field . '" AND pid=f.id ) LIKE ?'; } } if (count($arrConds) > 0) { $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . '(' . implode(" OR ", $arrConds) . ')'; $varKeyword = array_fill(0, count($arrConds), '%' . $this->Input->get('for') . '%'); } } $strOptions = implode(',', $arrSearchFields); break; case 'multiplefields': $arrOptions = array(); if (strlen($this->Input->get('search')) && is_array($this->Input->get('for'))) { $arrConds = array(); $arrKeywords = array(); foreach ($this->Input->get('for') as $field => $for) { if (in_array($field, $arrSearchFields) && strlen($for)) { if (in_array($field, $this->arrOwnerFields)) { if ($field == "fd_member") { $prop = 'arrMembers'; } elseif ($field == "fd_member_group") { $prop = 'arrMemberGroups'; } elseif ($field == "fd_user") { $prop = 'arrUsers'; } elseif ($field == "fd_user_group") { $prop = 'arrUserGroups'; } $arrMatches = $this->array_filter_like($this->{$prop}, urldecode($for)); if (count($arrMatches)) { $arrConds[] = $field . " IN(" . implode(",", array_keys($arrMatches)) . ")"; } } elseif (in_array($field, $this->arrBaseFields)) { $arrConds[] = $field . " LIKE ?"; $arrKeywords[] = '%' . urldecode($for) . '%'; } else { $arrConds[] = '(SELECT value FROM tl_formdata_details WHERE ff_name="' . $field . '" AND pid=f.id ) LIKE ?'; $arrKeywords[] = '%' . urldecode($for) . '%'; } } } if (count($arrConds) > 0) { $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . '(' . implode(" AND ", $arrConds) . ')'; $varKeyword = $arrKeywords; } } foreach (trimsplit(',', $this->list_search) as $field) { if (in_array($field, $this->arrBaseFields)) { if (strlen($this->strFormKey) && $field == 'form') { continue; } else { $arrOptions[] = array('name' => $field, 'label' => $GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['label'][0] ? htmlspecialchars($GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['label'][0]) : $field); } } elseif (is_array($this->arrDetailFields) && count($this->arrDetailFields) && in_array($field, $this->arrDetailFields)) { $arrOptions[] = array('name' => $field, 'label' => htmlspecialchars($GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['label'][0])); } } $strOptions = $this->list_search; $this->Template->search_searchfields = $arrOptions; unset($arrOptions); break; case 'dropdown': default: if (strlen($this->Input->get('search')) && strlen($this->Input->get('for'))) { $varKeyword = '%' . $this->Input->get('for') . '%'; if (in_array($this->Input->get('search'), $this->arrOwnerFields)) { $field = $this->Input->get('search'); if ($field == "fd_member") { $prop = 'arrMembers'; } elseif ($field == "fd_member_group") { $prop = 'arrMemberGroups'; } elseif ($field == "fd_user") { $prop = 'arrUsers'; } elseif ($field == "fd_user_group") { $prop = 'arrUserGroups'; } $arrMatches = $this->array_filter_like($this->{$prop}, $this->Input->get('for')); if (count($arrMatches)) { $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . $field . " IN(" . implode(",", array_keys($arrMatches)) . ")"; } } elseif (in_array($this->Input->get('search'), $this->arrBaseFields)) { $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . $this->Input->get('search') . " LIKE ?"; } else { $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . '(SELECT value FROM tl_formdata_details WHERE ff_name="' . $this->Input->get('search') . '" AND pid=f.id ) LIKE ?'; } } foreach (trimsplit(',', $this->list_search) as $field) { if (in_array($field, $this->arrBaseFields)) { if (strlen($this->strFormKey) && $field == 'form') { continue; } else { $strOptions .= ' <option value="' . $field . '"' . ($field == $this->Input->get('search') ? ' selected="selected"' : '') . '>' . htmlspecialchars($GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['label'][0]) . '</option>' . "\n"; } } elseif (is_array($this->arrDetailFields) && count($this->arrDetailFields) && in_array($field, $this->arrDetailFields)) { $strOptions .= ' <option value="' . $field . '"' . ($field == $this->Input->get('search') ? ' selected="selected"' : '') . '>' . ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['label'][0] ? htmlspecialchars($GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['label'][0]) : $field) . '</option>' . "\n"; } } break; } } if (!$blnExport) { $this->Template->search_fields = $strOptions; } /** * Get total number of records */ $strQuery = "SELECT COUNT(*) AS count FROM " . $this->list_table . " f"; if ($this->list_where) { $arrListWhere = array(); $arrListConds = preg_split('/(\\sAND\\s|\\sOR\\s)/si', $this->list_where, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($arrListConds as $strListCond) { if (preg_match('/\\sAND\\s|\\sOR\\s/si', $strListCond)) { $arrListWhere[] = $strListCond; } else { $arrListCond = preg_split('/([\\s!=><]+)/', $strListCond, -1, PREG_SPLIT_DELIM_CAPTURE); $strCondField = $arrListCond[0]; unset($arrListCond[0]); if (in_array($strCondField, $this->arrDetailFields)) { // handle numeric values if (isset($GLOBALS['TL_DCA']['tl_formdata']['fields'][$strCondField]['eval']['rgxp']) && $GLOBALS['TL_DCA']['tl_formdata']['fields'][$strCondField]['eval']['rgxp'] == 'digit') { $arrListWhere[] = '(SELECT value FROM tl_formdata_details WHERE ff_name="' . $strCondField . '" AND pid=f.id )+0.0 ' . implode('', $arrListCond); } else { $arrListWhere[] = '(SELECT value FROM tl_formdata_details WHERE ff_name="' . $strCondField . '" AND pid=f.id ) ' . implode('', $arrListCond); } } if (in_array($strCondField, $this->arrBaseFields)) { $arrListWhere[] = $strCondField . implode('', $arrListCond); } } } $strListWhere = count($arrListWhere) > 0 ? '(' . implode('', $arrListWhere) . ')' : ''; $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . $strListWhere; } if (strlen($this->strFormKey)) { $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . $this->strFormFilterKey . "='" . $this->strFormFilterValue . "'"; } // replace insert tags in where, e.g. {{user::id}} $strWhere = $this->replaceWhereTags($strWhere); $strWhere = $this->replaceInsertTags($strWhere); $strQuery .= $strWhere; $objTotal = $this->Database->prepare($strQuery)->execute($varKeyword); $rowTotalcount = $objTotal->row(); $intTotalcount = max(0, $rowTotalcount['count']); /** * Get the selected records */ $arrListFields = trimsplit(',', $this->list_fields); $intLastCol = -1; if ($this->Template->details || $this->Template->editable || $this->Template->deletable || $this->Template->exportable) { $intLastCol++; } $strListFields = ''; $strListFields .= 'id,alias'; if (count($arrListFields) > 0) { foreach ($arrListFields as $field) { // do not display field id if ($field == 'id') { continue; } $intLastCol++; if (in_array($field, $this->arrBaseFields)) { $strListFields .= ',' . $field; } if (is_array($this->arrDetailFields) && count($this->arrDetailFields) && in_array($field, $this->arrDetailFields)) { $strListFields .= ',(SELECT value FROM tl_formdata_details WHERE ff_name="' . $field . '" AND pid=f.id) AS `' . $field . '`'; } } } // member and user if (!in_array('fd_user', $arrListFields)) { $strListFields .= ',fd_user'; } if (!in_array('fd_member', $arrListFields)) { $strListFields .= ',fd_member'; } $strQuery = "SELECT " . $strListFields . " FROM " . $this->list_table . " f"; $strQuery .= $strWhere; // Order by if (strlen($this->Input->get('order_by'))) { if (in_array($this->Input->get('order_by'), $arrListFields) && (in_array($this->Input->get('order_by'), $this->arrBaseFields) || in_array($this->Input->get('order_by'), $this->arrDetailFields))) { if (isset($GLOBALS['TL_DCA']['tl_formdata']['fields'][$this->Input->get('order_by')]['eval']['rgxp']) && $GLOBALS['TL_DCA']['tl_formdata']['fields'][$this->Input->get('order_by')]['eval']['rgxp'] == 'digit') { $strQuery .= " ORDER BY CAST(`" . $this->Input->get('order_by') . '` AS DECIMAL) ' . $this->Input->get('sort'); } else { $strQuery .= " ORDER BY `" . $this->Input->get('order_by') . '` ' . $this->Input->get('sort'); } } } elseif ($this->list_sort) { $strListSort = $this->list_sort; $arrListSort = explode(',', $strListSort); $arrSort = array(); $arrSortSigned = array('digit', 'date', 'datim', 'time'); if (count($arrListSort)) { foreach ($arrListSort as $strSort) { $strSort = trim($strSort); preg_match_all('/^(.*?)(\\s|$)/i', $strSort, $arrMatch); if (!in_array($arrMatch[1][0], $arrListFields)) { if (in_array($GLOBALS['TL_DCA']['tl_formdata']['fields'][$arrMatch[1][0]]['eval']['rgxp'], $arrSortSigned)) { $arrSort[] = preg_replace('/\\b' . $arrMatch[1][0] . '\\b/i', 'CAST((SELECT value FROM tl_formdata_details WHERE ff_name="' . $arrMatch[1][0] . '" AND pid=f.id) AS DECIMAL)', $strSort); } else { $arrSort[] = preg_replace('/\\b' . $arrMatch[1][0] . '\\b/i', '(SELECT value FROM tl_formdata_details WHERE ff_name="' . $arrMatch[1][0] . '" AND pid=f.id)', $strSort); } } else { if (in_array($GLOBALS['TL_DCA']['tl_formdata']['fields'][$arrMatch[1][0]]['eval']['rgxp'], $arrSortSigned)) { $arrSort[] = preg_replace('/\\b' . $arrMatch[1][0] . '\\b/i', 'CAST(' . $arrMatch[1][0] . ' AS DECIMAL)', $strSort); } else { $arrSort[] = $strSort; } } } } if (count($arrSort) > 0) { $strListSort = 'ORDER BY ' . implode(',', $arrSort); } else { $strListSort = ''; } $strQuery .= $strListSort; } $objDataStmt = $this->Database->prepare($strQuery); // Limit if (!$blnExport) { if (intval($this->Input->get('per_page')) > 0) { $objDataStmt->limit($this->Input->get('per_page'), ($page - 1) * $per_page); } elseif (intval($this->perPage) > 0) { $objDataStmt->limit($this->perPage, ($page - 1) * $per_page); } } $objData = $objDataStmt->execute($varKeyword); /** * Prepare URL */ //$strUrl = preg_replace('/\?.*$/', '', urldecode($this->Environment->request)); $strUrl = $this->generateFrontendUrl($objPage->row()); if ($strUrl == '/' || $strUrl == '//') { $strUrl = ''; } $strUrlParams = ''; $strUrlSuffix = $GLOBALS['TL_CONFIG']['urlSuffix']; if (!$blnExport) { $this->Template->url = $strUrl; } $blnQuery = false; foreach (preg_split('/&(amp;)?/', urldecode($_SERVER['QUERY_STRING'])) as $fragment) { if (strlen($fragment)) { if (strncasecmp($fragment, 'file', 5) !== 0 && strncasecmp($fragment, 'act', 3) !== 0 && strncasecmp($fragment, 'order_by', 8) !== 0 && strncasecmp($fragment, 'sort', 4) !== 0 && strncasecmp($fragment, 'page', 4) !== 0) { $strUrlParams .= (!$blnQuery ? '' : '&') . $fragment; $blnQuery = true; } } } /** * Prepare data arrays */ $arrTh = array(); $arrTd = array(); $arrFields = $arrListFields; $intRowCounter = -1; $intColCounter = 0; $intRowCounter++; $ignoreFields = array('id', 'pid', 'sorting'); // THEAD if (!$blnExport) { for ($i = 0; $i < count($arrFields); $i++) { // do not display some special fields if (in_array($arrFields[$i], $ignoreFields) || $GLOBALS['TL_DCA'][$this->list_table]['fields'][$arrFields[$i]]['inputType'] == 'password') { continue; } $class = ''; $sort = 'asc'; $strField = strlen($label = $GLOBALS['TL_DCA'][$this->list_table]['fields'][$arrFields[$i]]['label'][0]) ? $label : $arrFields[$i]; if ($this->Input->get('order_by') == $arrFields[$i]) { $sort = $this->Input->get('sort') == 'asc' ? 'desc' : 'asc'; $class = ' sorted ' . $this->Input->get('sort'); } // add CSS class defined in form generator if (isset($GLOBALS['TL_DCA'][$this->list_table]['fields'][$arrFields[$i]]['ff_class']) && strlen($GLOBALS['TL_DCA'][$this->list_table]['fields'][$arrFields[$i]]['ff_class'])) { $class .= ' ' . $GLOBALS['TL_DCA'][$this->list_table]['fields'][$arrFields[$i]]['ff_class']; } $arrTh[] = array('link' => htmlspecialchars($strField), 'href' => $strUrl . (strlen($strUrlParams) ? '?' . $strUrlParams . '&' : '?') . 'order_by=' . $arrFields[$i] . '&sort=' . $sort, 'title' => htmlspecialchars(sprintf($GLOBALS['TL_LANG']['MSC']['list_orderBy'], $strField)), 'class' => $class . ($i == 0 ? ' col_first' : '')); } } else { $strExpEncl = '"'; $strExpSep = ''; if ($strExportMode == 'xls') { if (!$blnCustomXlsExport) { $xls = new xlsexport(); $strXlsSheet = "Export"; $xls->addworksheet($strXlsSheet); } } else { header('Content-Type: appplication/csv; charset=' . ($this->blnExportUTF8Decode ? 'CP1252' : 'utf-8')); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="export_' . $this->strFormKey . '_' . date("Ymd_His") . '.csv"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Expires: 0'); $strExpSep = ''; } $intColCounter = -1; for ($i = 0; $i < count($arrFields); $i++) { $v = $arrFields[$i]; if (in_array($v, $ignoreFields)) { continue; } $intColCounter++; if ($useFieldNames) { $strName = $v; } elseif (strlen($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['label'][0])) { $strName = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['label'][0]; } elseif (strlen($GLOBALS['TL_LANG']['tl_formdata'][$v][0])) { $strName = $GLOBALS['TL_LANG']['tl_formdata'][$v][0]; } else { $strName = strtoupper($v); } if (strlen($strName)) { $strName = $this->String->decodeEntities($strName); } if ($this->blnExportUTF8Decode || $strExportMode == 'xls' && !$blnCustomXlsExport) { $strName = $this->convertEncoding($strName, $GLOBALS['TL_CONFIG']['characterSet'], 'CP1252'); } if ($strExportMode == 'csv') { $strName = str_replace('"', '""', $strName); echo $strExpSep . $strExpEncl . $strName . $strExpEncl; $strExpSep = ";"; } if ($strExportMode == 'xls') { if (!$blnCustomXlsExport) { $xls->setcell(array("sheetname" => $strXlsSheet, "row" => $intRowCounter, "col" => $intColCounter, "data" => $strName, "fontweight" => XLSFONT_BOLD, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL)); $xls->setcolwidth($strXlsSheet, $intColCounter, 0x1aff); } else { $arrHookDataColumns[$v] = $strName; } } } $intRowCounter++; if ($strExportMode == 'csv') { echo "\n"; } } // Data result $arrRows = $objData->fetchAllAssoc(); if (!$blnExport) { // also store as list of items $arrListItems = array(); $arrEditAllowed = array(); $arrDeleteAllowed = array(); $arrExportAllowed = array(); // TBODY for ($i = 0; $i < count($arrRows); $i++) { $class = 'row_' . $i . ($i == 0 ? ' row_first' : '') . ($i + 1 == count($arrRows) ? ' row_last' : '') . ($i % 2 == 0 ? ' even' : ' odd'); // check edit access $blnEditAllowed = false; if ($this->efg_fe_edit_access == 'none') { $blnEditAllowed = false; } elseif ($this->efg_fe_edit_access == 'public') { $blnEditAllowed = true; } elseif (strlen($this->efg_fe_edit_access)) { if (in_array(intval($arrRows[$i]['fd_member']), $this->arrAllowedEditOwnerIds)) { $blnEditAllowed = true; } } // check delete access $blnDeleteAllowed = false; if ($this->efg_fe_delete_access == 'none') { $blnDeleteAllowed = false; } elseif ($this->efg_fe_delete_access == 'public') { $blnDeleteAllowed = true; } elseif (strlen($this->efg_fe_delete_access)) { if (in_array(intval($arrRows[$i]['fd_member']), $this->arrAllowedDeleteOwnerIds)) { $blnDeleteAllowed = true; } } // check export access $blnExportAllowed = false; if ($this->efg_fe_export_access == 'none') { $blnExportAllowed = false; } elseif ($this->efg_fe_export_access == 'public') { $blnExportAllowed = true; } elseif (strlen($this->efg_fe_export_access)) { if (in_array(intval($arrRows[$i]['fd_member']), $this->arrAllowedExportOwnerIds)) { $blnExportAllowed = true; } } $arrEditAllowed[$arrRows[$i]['id']] = $blnEditAllowed; $arrDeleteAllowed[$arrRows[$i]['id']] = $blnDeleteAllowed; $arrExportAllowed[$arrRows[$i]['id']] = $blnExportAllowed; $j = 0; foreach ($arrListFields as $intKey => $strVal) { $k = $strVal; $v = $arrRows[$i][$k]; // do not display some special fields if (in_array($k, $ignoreFields) || $GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['inputType'] == 'password') { continue; } $strLinkDetails = ''; if (strlen($arrRows[$i]['alias']) && !$GLOBALS['TL_CONFIG']['disableAlias']) { $strLinkDetails = str_replace($strUrlSuffix, '', $strUrl) . (strlen($strUrl) ? '/' : '') . $this->strDetailKey . '/' . $arrRows[$i]['alias'] . $strUrlSuffix . (strlen($strUrlParams) ? '?' . $strUrlParams : ''); } else { $strLinkDetails = $strUrl . '?' . $this->strDetailKey . '=' . $arrRows[$i]['id'] . (strlen($strUrlParams) ? '&' . $strUrlParams : ''); } $strLinkEdit = ''; if ($arrEditAllowed[$arrRows[$i]['id']]) { if (strlen($arrRows[$i]['alias']) && !$GLOBALS['TL_CONFIG']['disableAlias']) { $strLinkEdit = str_replace($strUrlSuffix, '', $strUrl) . (strlen($strUrl) ? '/' : '') . $this->strDetailKey . '/' . $arrRows[$i]['alias'] . $strUrlSuffix . '?act=edit' . (strlen($strUrlParams) ? '&' . $strUrlParams : ''); } else { $strLinkEdit = $strUrl . '?' . $this->strDetailKey . '=' . $arrRows[$i]['id'] . '&act=edit' . (strlen($strUrlParams) ? '&' . $strUrlParams : ''); } } $strLinkDelete = ''; if ($arrDeleteAllowed[$arrRows[$i]['id']]) { if (strlen($arrRows[$i]['alias']) && !$GLOBALS['TL_CONFIG']['disableAlias']) { $strLinkDelete = str_replace($strUrlSuffix, '', $strUrl) . (strlen($strUrl) ? '/' : '') . $this->strDetailKey . '/' . $arrRows[$i]['alias'] . $strUrlSuffix . '?act=delete' . (strlen($strUrlParams) ? '&' . $strUrlParams : ''); } else { $strLinkDelete = $strUrl . '?' . $this->strDetailKey . '=' . $arrRows[$i]['id'] . '&act=delete' . (strlen($strUrlParams) ? '&' . $strUrlParams : ''); } } $strLinkExport = ''; if ($arrExportAllowed[$arrRows[$i]['id']]) { if (strlen($arrRows[$i]['alias']) && !$GLOBALS['TL_CONFIG']['disableAlias']) { $strLinkExport = str_replace($strUrlSuffix, '', $strUrl) . (strlen($strUrl) ? '/' : '') . $this->strDetailKey . '/' . $arrRows[$i]['alias'] . $strUrlSuffix . '?act=export' . (strlen($strUrlParams) ? '&' . $strUrlParams : ''); } else { $strLinkExport = $strUrl . '?' . $this->strDetailKey . '=' . $arrRows[$i]['id'] . '&act=export' . (strlen($strUrlParams) ? '&' . $strUrlParams : ''); } } $value = $this->formatValue($k, $v); $v = $this->String->decodeEntities($v); if ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['inputType'] == 'fileTree' && $GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['multiple'] == true) { $v = is_string($v) && strpos($v, '|') !== false ? explode('|', $v) : deserialize($v); } // add CSS class defined in form generator $ff_class = ''; if (isset($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['ff_class']) && strlen($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['ff_class'])) { $ff_class = ' ' . $GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['ff_class']; } $arrTd[$class][] = array('id' => $arrRows[$i]['id'], 'alias' => $arrRows[$i]['alias'], 'content' => $value ? $value : ' ', 'raw' => $v, 'class' => 'col_' . $j . $ff_class . ($j == 0 ? ' col_first' : '') . ($j == $intLastCol ? ' col_last' : ''), 'link_details' => $strLinkDetails, 'link_edit' => $strLinkEdit, 'link_delete' => $strLinkDelete, 'link_export' => $strLinkExport); // store also as item $arrListItems[$i][$k] = array('id' => $arrRows[$i]['id'], 'alias' => $arrRows[$i]['alias'], 'name' => $k, 'label' => strlen($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['label'][0]) ? htmlspecialchars($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['label'][0]) : htmlspecialchars($k), 'content' => $value ? $value : ' ', 'raw' => $v, 'class' => 'field_' . $j . $ff_class . ($j == 0 ? ' field_first' : '') . ($j == $intLastCol - 1 ? ' field_last' : ''), 'record_class' => str_replace('row_', 'record_', $class), 'link_details' => $strLinkDetails, 'link_edit' => $strLinkEdit, 'link_delete' => $strLinkDelete, 'link_export' => $strLinkExport); if ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['inputType'] == 'fileTree') { $value = $arrListItems[$i][$k]['raw']; if (is_string($value) && strlen($value) && is_dir(TL_ROOT . '/' . $value)) { $arrTd[$class][count($arrTd[$class]) - 1]['content'] = ' '; $arrListItems[$i][$k]['content'] = ' '; } elseif (is_string($value) && strlen($value) && is_file(TL_ROOT . '/' . $value)) { $objFile = new File($value); if (!in_array($objFile->extension, $allowedDownload)) { $arrTd[$class][count($arrTd[$class]) - 1]['content'] = ' '; $arrListItems[$i][$k]['content'] = ' '; } else { $arrTd[$class][count($arrTd[$class]) - 1]['type'] = 'file'; $arrTd[$class][count($arrTd[$class]) - 1]['src'] = $this->urlEncode($value); $arrListItems[$i][$k]['type'] = 'file'; $arrListItems[$i][$k]['src'] = $this->urlEncode($value); if (substr($objFile->mime, 0, 6) == 'image/') { $arrTd[$class][count($arrTd[$class]) - 1]['display'] = 'image'; $arrListItems[$i][$k]['display'] = 'image'; } else { $size = ' (' . number_format($objFile->filesize / 1024, 1, $GLOBALS['TL_LANG']['MSC']['decimalSeparator'], $GLOBALS['TL_LANG']['MSC']['thousandsSeparator']) . ' kB)'; $href = preg_replace('@(\\?|&)download=.*?(&|$)@si', '', $this->Environment->request); $href .= (strpos($href, '?') >= 1 ? '&' : '?') . 'download=' . $arrRows[$i]['id'] . '.' . $k; $href = ampersand($href); $arrTd[$class][count($arrTd[$class]) - 1]['display'] = 'download'; $arrTd[$class][count($arrTd[$class]) - 1]['size'] = $size; $arrTd[$class][count($arrTd[$class]) - 1]['href'] = $href; $arrTd[$class][count($arrTd[$class]) - 1]['linkTitle'] = basename($objFile->basename); $arrTd[$class][count($arrTd[$class]) - 1]['icon'] = (strlen($this->efg_iconfolder) ? $this->efg_iconfolder . '/' : 'system/modules/efg/html/') . $objFile->icon; $arrListItems[$i][$k]['display'] = 'download'; $arrListItems[$i][$k]['size'] = $size; $arrListItems[$i][$k]['href'] = $href; $arrListItems[$i][$k]['linkTitle'] = basename($objFile->basename); $arrListItems[$i][$k]['icon'] = (strlen($this->efg_iconfolder) ? $this->efg_iconfolder . '/' : 'system/modules/efg/html/') . $objFile->icon; } } } elseif (is_array($value)) { $arrTemp = array(); $keyTemp = -1; $arrTd[$class][count($arrTd[$class]) - 1]['type'] = 'file'; $arrListItems[$i][$k]['type'] = 'file'; foreach ($value as $kF => $strFile) { if (strlen($strFile) && is_file(TL_ROOT . '/' . $strFile)) { $objFile = new File($strFile); if (!in_array($objFile->extension, $allowedDownload)) { unset($arrListItems[$i][$k]['raw'][$kF]); continue; } else { $keyTemp++; $arrTemp[$keyTemp]['src'] = $this->urlEncode($strFile); if (substr($objFile->mime, 0, 6) == 'image/') { $arrTemp[$keyTemp]['display'] = 'image'; } else { $size = ' (' . number_format($objFile->filesize / 1024, 1, $GLOBALS['TL_LANG']['MSC']['decimalSeparator'], $GLOBALS['TL_LANG']['MSC']['thousandsSeparator']) . ' kB)'; $href = preg_replace('@(\\?|&)download=.*?(&|$)@si', '', $this->Environment->request); $href .= (strpos($href, '?') >= 1 ? '&' : '?') . 'download=' . $arrRows[$i]['id'] . '.' . $k; $href = ampersand($href); $arrTemp[$keyTemp]['display'] = 'download'; $arrTemp[$keyTemp]['size'] = $size; $arrTemp[$keyTemp]['href'] = $href; $arrTemp[$keyTemp]['linkTitle'] = basename($objFile->basename); $arrTemp[$keyTemp]['icon'] = 'system/themes/' . $this->getTheme() . '/images/' . $objFile->icon; } } } } $arrTd[$class][count($arrTd[$class]) - 1]['content'] = $arrTemp; $arrListItems[$i][$k]['content'] = $arrTemp; $arrTd[$class][count($arrTd[$class]) - 1]['multiple'] = true; $arrTd[$class][count($arrTd[$class]) - 1]['number_of_items'] = count($arrTemp); $arrListItems[$i][$k]['multiple'] = true; $arrListItems[$i][$k]['number_of_items'] = count($arrTemp); unset($arrTemp); } } $j++; } } $strTotalNumberOfItems = number_format((int) $intTotalcount, 0, $GLOBALS['TL_LANG']['MSC']['decimalSeparator'], $GLOBALS['TL_LANG']['MSC']['thousandsSeparator']); $this->Template->totalNumberOfItems = array('raw' => (int) $intTotalcount, 'formatted' => $strTotalNumberOfItems, 'content' => sprintf($GLOBALS['TL_LANG']['MSC']['efgTotalNumberOfItems'], $strTotalNumberOfItems)); $this->Template->thead = $arrTh; $this->Template->tbody = $arrTd; $this->Template->listItems = $arrListItems; $this->Template->arrEditAllowed = $arrEditAllowed; $this->Template->arrDeleteAllowed = $arrDeleteAllowed; $this->Template->arrExportAllowed = $arrExportAllowed; /** * Pagination */ if (intval($per_page) > 0) { $objPagination = new Pagination($intTotalcount, $per_page); $this->Template->pagination = $objPagination->generate("\n "); } /** * Template variables */ $this->Template->action = ampersand(urldecode($this->Environment->request)); $this->Template->per_page_label = specialchars($GLOBALS['TL_LANG']['MSC']['list_perPage']); $this->Template->search_label = specialchars($GLOBALS['TL_LANG']['MSC']['search']); $this->Template->per_page = $this->Input->get('per_page'); if (intval($this->perPage) > 0) { $this->Template->list_perPage = $this->perPage; } $this->Template->search = $this->Input->get('search'); $this->Template->for = $this->Input->get('for'); $this->Template->order_by = $this->Input->get('order_by'); $this->Template->sort = $this->Input->get('sort'); //$this->Template->col_last = 'col_' . $j; $this->Template->col_last = 'col_' . $intLastCol; } else { $arrEditAllowed = array(); $arrDeleteAllowed = array(); $arrExportAllowed = array(); // Process result and format values foreach ($arrRows as $row) { $args = array(); $strExpEncl = '"'; $strExpSep = ''; $intColCounter = -1; // check export access $blnExportAllowed = false; if ($this->efg_fe_export_access == 'none') { $blnExportAllowed = false; } elseif ($this->efg_fe_export_access == 'public') { $blnExportAllowed = true; } elseif (strlen($this->efg_fe_export_access)) { if (in_array(intval($row['fd_member']), $this->arrAllowedExportOwnerIds)) { $blnExportAllowed = true; } } if ($blnExportAllowed == false) { continue; } // Prepare field value foreach ($arrFields as $k => $v) { if (in_array($v, $ignoreFields)) { continue; } $intColCounter++; $strVal = ''; $strVal = $row[$v]; if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'date') { $strVal = $row[$v] ? date($GLOBALS['TL_CONFIG']['dateFormat'], $row[$v]) : ''; } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'time') { $strVal = $row[$v] ? date($GLOBALS['TL_CONFIG']['timeFormat'], $row[$v]) : ''; } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'datim') { $strVal = $row[$v] ? date($GLOBALS['TL_CONFIG']['datimFormat'], $row[$v]) : ''; } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'checkbox' && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['multiple']) { if ($useFormValues == 1) { // single value checkboxes don't have options if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options']) && count($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options']) > 0) { $strVal = strlen($row[$v]) ? key($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options']) : ''; } else { $strVal = $row[$v]; } } else { $strVal = strlen($row[$v]) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['label'][0] : '-'; } } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'radio' || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'efgLookupRadio' || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'select' || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'efgLookupSelect' || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'checkbox' || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'efgLookupCheckbox') { // take the assigned value instead of the user readable output if ($useFormValues == 1) { if (strpos($row[$v], "|") === false && (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options']) && count($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options']) > 0)) { $options = array_flip($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options']); $strVal = $options[$row[$v]]; } else { if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options']) && count($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options']) > 0) { $options = array_flip($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options']); $tmparr = split("\\|", $row[$v]); $fieldvalues = array(); foreach ($tmparr as $valuedesc) { array_push($fieldvalues, $options[$valuedesc]); } $strVal = implode(",\n", $fieldvalues); } else { $strVal = strlen($row[$v]) ? str_replace('|', ",\n", $row[$v]) : ''; } } } else { $strVal = strlen($row[$v]) ? str_replace('|', ",\n", $row[$v]) : ''; } } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'fileTree') { if (is_string($row[$v]) && strpos($row[$v], '|') !== false) { $strVal = implode(",\n", explode('|', $row[$v])); } else { $strVal = implode(",\n", deserialize($row[$v], true)); } } else { $row_v = deserialize($row[$v]); if (is_array($row_v)) { $args_k = array(); foreach ($row_v as $option) { $args_k[] = strlen($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$option]) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$option] : $option; } $args[$k] = implode(",\n", $args_k); } elseif (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$row[$v]])) { $args[$k] = is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$row[$v]]) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$row[$v]][0] : $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$row[$v]]; } else { $args[$k] = $row[$v]; } $strVal = is_null($args[$k]) ? $args[$k] : vsprintf('%s', $args[$k]); } if (in_array($v, $this->arrBaseFields) || in_array($v, $this->arrOwnerFields)) { if ($v == 'fd_member') { $strVal = $this->arrMembers[intval($row[$v])]; } elseif ($v == 'fd_user') { $strVal = $this->arrUsers[intval($row[$v])]; } elseif ($v == 'fd_member_group') { $strVal = $this->arrMemberGroups[intval($row[$v])]; } elseif ($v == 'fd_user_group') { $strVal = $this->arrUserGroups[intval($row[$v])]; } } if (strlen($strVal)) { $strVal = $this->String->decodeEntities($strVal); $strVal = preg_replace(array('/<br.*\\/*>/si'), array("\n"), $strVal); if ($this->blnExportUTF8Decode || $strExportMode == 'xls' && !$blnCustomXlsExport) { $strVal = $this->convertEncoding($strVal, $GLOBALS['TL_CONFIG']['characterSet'], 'CP1252'); } } if ($strExportMode == 'csv') { $strVal = str_replace('"', '""', $strVal); echo $strExpSep . $strExpEncl . $strVal . $strExpEncl; $strExpSep = ";"; } if ($strExportMode == 'xls') { if (!$blnCustomXlsExport) { $xls->setcell(array("sheetname" => $strXlsSheet, "row" => $intRowCounter, "col" => $intColCounter, "data" => $strVal, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL)); } else { $arrHookData[$intRowCounter][$v] = $strVal; } } } $intRowCounter++; if ($strExportMode == 'csv') { $strExpSep = ''; echo "\n"; } } // foreach ($result as $row) if ($strExportMode == 'xls') { if (!$blnCustomXlsExport) { $xls->sendfile("export_" . $this->strFormKey . "_" . date("Ymd_His") . ".xls"); exit; } else { foreach ($GLOBALS['TL_HOOKS']['efgExportXls'] as $key => $callback) { $this->import($callback[0]); $res = $this->{$callback}[0]->{$callback}[1]($arrHookDataColumns, $arrHookData); } } } exit; } // $blnExport }
/** * Generate the module */ protected function compile() { // handle Ajax requests if (\Input::get('isAjaxRequest') && \Input::get('act') == 'toggleVisibility') { $this->handleAjax(); exit; } // add miscellaneous vars to the template $this->addTemplateVars(); // ***** RATED USER PROFILE ***** foreach ($this->ratedUser->row() as $k => $v) { if ($k == 'password') { continue; } $this->Template->ratedUser->{$k} = $v; } // get avatar of rated user $arrSize = deserialize($this->avatarSizeProfile); $title = $this->ratedUser->firstname . ' ' . $this->ratedUser->lastname; $this->ratedUser->avatar = $this->getAvatar($this->ratedUser->id, $arrSize, 'avatar', $title, 'avatar_large', $this); // get socialmedia links // socialmedia links $this->ratedUser->socialmediaLinks = $this->getSocialmediaLinks($this->ratedUser->id); $this->ratedUser->deleteSocialmediaLinkIcon = TL_FILES_URL . $this->getImageDir() . '/cancel_circle.png'; // get score and grade of rated user $this->ratedUser->score = $this->getScore($this->ratedUser->id); $this->ratedUser->averageRating = $this->getAverageRating($this->ratedUser->id); $this->ratedUser->ratingEnities = $this->getRatingEnities($this->ratedUser->id); $this->ratedUser->gradeLabel = $this->getGrade($this->ratedUser->id, 'label'); $this->ratedUser->gradeIcon = $this->getGrade($this->ratedUser->id, 'icon'); // add data to template $keys = array('firstname', 'lastname', 'avatar', 'socialmediaLinks', 'deleteSocialmediaLinkIcon', 'score', 'gradeLabel', 'gradeIcon'); foreach ($keys as $key) { $this->Template->{$key} = $this->ratedUser->{$key}; } if ($this->showTop3) { $this->Template->showTop3 = true; // ***** TOP 3 SECTION ***** $objRatings = $this->Database->prepare("SELECT * FROM tl_comments WHERE comment != '' AND source = ? AND parent = ? AND published = ? AND owner > 0 ORDER BY score DESC, dateOfCreation DESC")->limit(3)->execute('tl_member', $this->ratedUser->id, 1); $arrTop3 = array(); while ($row = $objRatings->fetchAssoc()) { $objMember = \MemberModel::findByPk($row['owner']); $row['time'] = \Date::parse(\Config::get('datimFormat'), $row['dateOfCreation']); if ($objMember !== null) { foreach (\MemberModel::findByPk($objMember->id)->row() as $k => $v) { if ($k == 'id' || $k == 'tstamp' || $k == 'password') { continue; } $row[$k] = $v; } // avatar $arrSize = deserialize($this->avatarSizeListing); $title = $objMember->firstname . ' ' . $objMember->lastname; $row['avatar'] = $this->getAvatar($objMember->id, $arrSize, 'avatar', $title, 'avatar_thumb', $this); } $arrTop3[] = $row; } $this->Template->top3 = count($arrTop3) > 2 ? $arrTop3 : false; } // ***** ALL RATINGS SECTION ***** if ($this->ratedUser->id == $this->loggedInUser->id) { $strSql = "SELECT * FROM tl_comments WHERE comment != '' AND source = ? AND parent = ? AND owner > 0 ORDER BY dateOfCreation DESC, score DESC"; } else { $strSql = "SELECT * FROM tl_comments WHERE comment != '' AND source = ? AND parent = ? AND published = '1' AND owner > 0 ORDER BY dateOfCreation DESC, score DESC"; } $objRatings = $this->Database->prepare($strSql)->execute('tl_member', $this->ratedUser->id); $arrAllRatings = array(); while ($row = $objRatings->fetchAssoc()) { $objMember = \MemberModel::findByPk($row['owner']); // Show only Members from a selected group if ($this->limitUsers) { $arrGroups = deserialize($this->listedGroups); if (count(array_intersect(deserialize($objMember->groups), $arrGroups)) < 1) { continue; } } $row['time'] = \Date::parse(\Config::get('datimFormat'), $row['dateOfCreation']); if ($objMember !== null) { foreach (\MemberModel::findByPk($objMember->id)->row() as $k => $v) { if ($k == 'id' || $k == 'tstamp' || $k == 'password') { continue; } $row[$k] = $v; } // avatar $arrSize = deserialize($this->avatarSizeListing); $title = $objMember->firstname . ' ' . $objMember->lastname; $row['avatar'] = $this->getAvatar($objMember->id, $arrSize, 'avatar', $title, 'avatar_thumb', $this); // toggle visibility icon $visibility = $row['published'] ? 'visible.png' : 'invisible.png'; $row['visibility_icon_src'] = TL_FILES_URL . sprintf($this->getImageDir() . '/%s', $visibility); } $arrAllRatings[] = $row; } // Pagination $total = count($arrAllRatings); $limit = $total; $offset = 0; if ($this->perPage > 0) { $id = 'page_e' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } $offset = ($page - 1) * $this->perPage; $limit = min($this->perPage + $offset, $total); $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } $arrRatings = array(); for ($i = $offset; $i < $limit; $i++) { $arrRatings[] = $arrAllRatings[$i]; } $this->Template->allRatings = count($arrRatings) ? $arrRatings : false; // generate forms if (FE_USER_LOGGED_IN) { if ($this->loggedInUser->id != $this->ratedUser->id) { $this->generateVotingForm(); } } }
/** * Generate the module */ protected function compile() { $offset = intval($this->skipFirst); $limit = null; $this->Template->recipes = array(); // Maximum number of items if ($this->numberOfItems > 0) { $limit = $this->numberOfItems; } // Get the total number of items $intTotal = \SimpleRecipesEntriesModel::countRecipesByOpen(); // Filter anwenden um die Gesamtanzahl zuermitteln if ($intTotal > 0) { $filterObj = \SimpleRecipesEntriesModel::findRecipes($intTotal, 0); $counter = 0; $idArr = array(); while ($filterObj->next()) { //wenn alle Filter stimmen -> Werte setzen $idArr[] = $filterObj->id; $counter++; } if ((int) $intTotal > $counter) { $intTotal = $counter; } } if ((int) $intTotal < 1) { $this->Template = new \FrontendTemplate('mod_simple_recipes_entries_empty'); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyBmList']; return; } $total = $intTotal - $offset; // Split the results if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) { // Adjust the overall limit if (isset($limit)) { $total = min($limit, $total); } // Get the current page $id = 'page_n' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; $objTarget = \PageModel::findByPk($objPage->id); if ($objTarget !== null) { $reloadUrl = ampersand($this->generateFrontendUrl($objTarget->row())); } $this->redirect($reloadUrl); } // Set limit and offset $limit = $this->perPage; $offset += (max($page, 1) - 1) * $this->perPage; $skip = intval($this->skipFirst); // Overall limit if ($offset + $limit > $total + $skip) { $limit = $total + $skip - $offset; } // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, $GLOBALS['TL_CONFIG']['maxPaginationLinks'], $id); $this->Template->pagination = $objPagination->generate("\n "); } // Get the items if (isset($limit)) { $recipesObj = \SimpleRecipesEntriesModel::findRecipes($limit, $offset, $idArr); } else { $recipesObj = \SimpleRecipesEntriesModel::findRecipes(0, $offset, $idArr); } // No items found if ($recipesObj === null) { $this->Template = new \FrontendTemplate('mod_simple_recipes_entries_empty'); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptySimpleRecipesList']; } else { $this->Template->recipes = $this->parseRecipes($recipesObj); } $this->Template->totalItems = $intTotal; }
/** * Generate the pagination * @param integer * @return integer */ protected function generatePagination($total) { // Add pagination if ($this->perPage > 0 && $total > 0) { $page = $this->Input->get('page') ? $this->Input->get('page') : 1; // Check the maximum page number if ($page > $total / $this->perPage) { $page = ceil($total / $this->perPage); } $offset = ($page - 1) * $this->perPage; $objPagination = new Pagination($total, $this->perPage); $this->Template->pagination = $objPagination->generate("\n "); return $offset; } return 0; }
/** * Generate the module */ protected function compile() { $offset = intval($this->skipFirst); $limit = null; $this->Template->libraries = array(); // Maximum number of items if ($this->numberOfItems > 0) { $limit = $this->numberOfItems; } $session = $this->Session->get('bmfilter') ?: array(); if (strlen($session['geo_lat']) > 0 && strlen($session['geo_lon']) > 0) { $geodata = array('lat' => $session['geo_lat'], 'lon' => $session['geo_lon']); } else { $geodata = $this->getGeoDataFromCurrentPosition(); } // Get the total number of items $intTotal = \BmStoresModel::countStoreEntries($geodata, $session['distance']); // Filter anwenden um die Gesamtanzahl zuermitteln if ($intTotal > 0) { $filterStoresObj = \BmStoresModel::findStores($intTotal, 0, $geodata, $session['distance']); $counter = 0; $idArr = array(); while ($filterStoresObj->next()) { // aktuell offen if ($session['only_open'] && $this->getCurrentOpenStatus($filterStoresObj) != 'open') { continue; } // gehoert einer bestimmten Kategorie an if (strlen($session['category']) > 0 && !$this->hasCategory($filterStoresObj)) { continue; } //wenn alle Filter stimmen -> Werte setzen $idArr[] = $filterStoresObj->id; $counter++; } if ((int) $intTotal > $counter) { $intTotal = $counter; } } if ((int) $intTotal < 1) { $this->Template = new \FrontendTemplate('mod_bm_entries_empty'); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyBmList']; return; } $total = $intTotal - $offset; // Split the results if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) { // Adjust the overall limit if (isset($limit)) { $total = min($limit, $total); } // Get the current page $id = 'page_n' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; $objTarget = \PageModel::findByPk($objPage->id); if ($objTarget !== null) { $reloadUrl = ampersand($this->generateFrontendUrl($objTarget->row())); } $this->redirect($reloadUrl); } // Set limit and offset $limit = $this->perPage; $offset += (max($page, 1) - 1) * $this->perPage; $skip = intval($this->skipFirst); // Overall limit if ($offset + $limit > $total + $skip) { $limit = $total + $skip - $offset; } // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, $GLOBALS['TL_CONFIG']['maxPaginationLinks'], $id); $this->Template->pagination = $objPagination->generate("\n "); } // Get the items if (isset($limit)) { $storesObj = \BmStoresModel::findStores($limit, $offset, $geodata, $session['distance'], $idArr); } else { $storesObj = \BmStoresModel::findStores(0, $offset, $geodata, $session['distance'], $idArr); } // No items found if ($storesObj === null) { $this->Template = new \FrontendTemplate('mod_bm_entries_empty'); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyBmList']; } else { $this->Template->stores = $this->parseStores($storesObj); } $GLOBALS['TL_JAVASCRIPT'][] = '.' . BM_PATH . '/assets/js/bm_fe.js'; $this->Template->isDistance = count($session) > 0 && strlen($session['plzcity']) > 0 ? true : false; $this->Template->filterActive = \Input::get('s') ? true : false; $this->Template->totalItems = $intTotal; }
/** * Generate the content element */ protected function compile() { $images = array(); $auxDate = array(); // Get all images foreach ($this->multiSRC as $file) { if (isset($images[$file]) || !file_exists(TL_ROOT . '/' . $file)) { continue; } // Single files if (is_file(TL_ROOT . '/' . $file)) { $objFile = new File($file); $this->parseMetaFile(dirname($file), true); $arrMeta = $this->arrMeta[$objFile->basename]; if ($arrMeta[0] == '') { $arrMeta[0] = str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)); } if ($objFile->isGdImage) { $images[$file] = array('name' => $objFile->basename, 'singleSRC' => $file, 'alt' => $arrMeta[0], 'imageUrl' => $arrMeta[1], 'caption' => $arrMeta[2]); $auxDate[] = $objFile->mtime; } continue; } $subfiles = scan(TL_ROOT . '/' . $file); $this->parseMetaFile($file); // Folders foreach ($subfiles as $subfile) { if (is_dir(TL_ROOT . '/' . $file . '/' . $subfile)) { continue; } $objFile = new File($file . '/' . $subfile); if ($objFile->isGdImage) { $arrMeta = $this->arrMeta[$subfile]; if ($arrMeta[0] == '') { $arrMeta[0] = str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)); } $images[$file . '/' . $subfile] = array('name' => $objFile->basename, 'singleSRC' => $file . '/' . $subfile, 'alt' => $arrMeta[0], 'imageUrl' => $arrMeta[1], 'caption' => $arrMeta[2]); $auxDate[] = $objFile->mtime; } } } // Sort array switch ($this->sortBy) { default: case 'name_asc': uksort($images, 'basename_natcasecmp'); break; case 'name_desc': uksort($images, 'basename_natcasercmp'); break; case 'date_asc': array_multisort($images, SORT_NUMERIC, $auxDate, SORT_ASC); break; case 'date_desc': array_multisort($images, SORT_NUMERIC, $auxDate, SORT_DESC); break; case 'meta': $arrImages = array(); foreach ($this->arrAux as $k) { if (strlen($k)) { $arrImages[] = $images[$k]; } } $images = $arrImages; break; case 'random': shuffle($images); break; } $images = array_values($images); // Limit the total number of items (see #2652) if ($this->numberOfItems > 0) { $images = array_slice($images, 0, $this->numberOfItems); } $total = count($images); $limit = $total; $offset = 0; // Pagination if ($this->perPage > 0) { // Get the current page $page = $this->Input->get('page') ? $this->Input->get('page') : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } // Set limit and offset $offset = ($page - 1) * $this->perPage; $limit = min($this->perPage + $offset, $total); $objPagination = new Pagination($total, $this->perPage); $this->Template->pagination = $objPagination->generate("\n "); } $rowcount = 0; $colwidth = floor(100 / $this->perRow); $intMaxWidth = TL_MODE == 'BE' ? floor(640 / $this->perRow) : floor($GLOBALS['TL_CONFIG']['maxImageWidth'] / $this->perRow); $strLightboxId = 'lightbox[lb' . $this->id . ']'; $body = array(); // Rows for ($i = $offset; $i < $limit; $i = $i + $this->perRow) { $class_tr = ''; if ($rowcount == 0) { $class_tr .= ' row_first'; } if ($i + $this->perRow >= $limit) { $class_tr .= ' row_last'; } $class_eo = $rowcount % 2 == 0 ? ' even' : ' odd'; // Columns for ($j = 0; $j < $this->perRow; $j++) { $class_td = ''; if ($j == 0) { $class_td = ' col_first'; } if ($j == $this->perRow - 1) { $class_td = ' col_last'; } $objCell = new stdClass(); $key = 'row_' . $rowcount . $class_tr . $class_eo; // Empty cell if (!is_array($images[$i + $j]) || $j + $i >= $limit) { $objCell->class = 'col_' . $j . $class_td; $body[$key][$j] = $objCell; continue; } // Add size and margin $images[$i + $j]['size'] = $this->size; $images[$i + $j]['imagemargin'] = $this->imagemargin; $images[$i + $j]['fullsize'] = $this->fullsize; $this->addImageToTemplate($objCell, $images[$i + $j], $intMaxWidth, $strLightboxId); // Add column width and class $objCell->colWidth = $colwidth . '%'; $objCell->class = 'col_' . $j . $class_td; $body[$key][$j] = $objCell; } ++$rowcount; } $strTemplate = 'gallery_default'; // Use a custom template if (TL_MODE == 'FE' && $this->galleryTpl != '') { $strTemplate = $this->galleryTpl; } $objTemplate = new FrontendTemplate($strTemplate); $objTemplate->setData($this->arrData); $objTemplate->body = $body; $objTemplate->headline = $this->headline; // see #1603 $this->Template->images = $objTemplate->parse(); }
public function addTestimonialsToTemplate(\FrontendTemplate $objTemplate, \stdClass $objConfig, $intParent, $arrNotifies) { global $objPage; $limit = 0; $offset = 0; $total = 0; $gtotal = 0; $arrTestimonials = array(); $objTemplate->testimonials = array(); // Pagination if ($objConfig->perPage > 0) { // Get the total number of testimonials $intTotal = \TestimonialsModel::countPublishedTestimonials($intParent); $total = $gtotal = $intTotal; // Get the current page $id = 'page_entry' . $intParent; // see #4141 $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $objConfig->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } // Set limit and offset $limit = $objConfig->perPage; $offset = ($page - 1) * $objConfig->perPage; // Initialize the pagination menu $objPagination = new \Pagination($total, $objConfig->perPage, 7, $id); $objTemplate->pagination = $objPagination->generate("\n "); } // Get all published testimonials if ($limit) { $objTestimonials = \TestimonialsModel::findPublishedTestimonials($intParent, $objConfig->order == 'descending', $limit, $offset); } else { $objTestimonials = \TestimonialsModel::findPublishedTestimonials($intParent, $objConfig->order == 'descending'); } // Parse the testimonials if ($objTestimonials !== null && ($total = $objTestimonials->count()) > 0) { $count = 0; if ($objConfig->template == '') { $objConfig->template = 'testimonial_entry'; } $objPartial = new \FrontendTemplate($objConfig->template); while ($objTestimonials->next()) { $objPartial->setData($objTestimonials->row()); // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $objTestimonials->testimonial = \StringUtil::toXhtml($objTestimonials->testimonial); } else { $objTestimonials->testimonial = \StringUtil::toHtml5($objTestimonials->testimonial); } $objPartial->testimonial = trim(str_replace(array('{{', '}}'), array('{{', '}}'), $objTestimonials->testimonial)); $objPartial->datim = $this->parseDate($objPage->datimFormat, $objTestimonials->date); $objPartial->date = $this->parseDate($objPage->dateFormat, $objTestimonials->date); $objPartial->class = ($count < 1 ? ' first' : '') . ($count >= $total - 1 ? ' last' : '') . ($count % 2 == 0 ? ' even' : ' odd'); $objPartial->by = $GLOBALS['TL_LANG']['MSC']['com_by']; $objPartial->id = 'entry_' . $objTestimonials->id; $objPartial->timestamp = $objTestimonials->date; $objPartial->datetime = date('Y-m-d\\TH:i:sP', $objTestimonials->date); $objPartial->avatar = $this->get_gravatar($objTestimonials->email, $objTestimonials->name, $objConfig->AvatarMode, $objConfig->AvatarSize, $objConfig->DefaultGravatar, $objConfig->DefaultGravatarRating, $objConfig->DefaultAvatar); $objPartial->titel = $objTestimonials->title; $objPartial->addVote = $objConfig->addVote; $objPartial->enableVoteField1 = $objConfig->enableVoteField1; $objPartial->enableVoteField2 = $objConfig->enableVoteField2; $objPartial->enableVoteField3 = $objConfig->enableVoteField3; $objPartial->enableVoteField4 = $objConfig->enableVoteField4; $objPartial->enableVoteField5 = $objConfig->enableVoteField5; $objPartial->enableVoteField6 = $objConfig->enableVoteField6; $objPartial->VoteField1Name = $objConfig->VoteField1Name; $objPartial->VoteField2Name = $objConfig->VoteField2Name; $objPartial->VoteField3Name = $objConfig->VoteField3Name; $objPartial->VoteField4Name = $objConfig->VoteField4Name; $objPartial->VoteField5Name = $objConfig->VoteField5Name; $objPartial->VoteField6Name = $objConfig->VoteField6Name; $objPartial->design = $objConfig->design; $arrTestimonials[] = $objPartial->parse(); ++$count; } } $objTemplate->testimonials = $arrTestimonials; $objTemplate->addVote = $objConfig->addVote; $objTemplate->name = $GLOBALS['TL_LANG']['MSC']['tm_name']; $objTemplate->email = $GLOBALS['TL_LANG']['MSC']['tm_email']; $objTemplate->url = $GLOBALS['TL_LANG']['MSC']['tm_website']; $objTemplate->company = $GLOBALS['TL_LANG']['MSC']['tm_company']; $objTemplate->title = $GLOBALS['TL_LANG']['MSC']['tm_title']; $objTemplate->TestimonialsTotal = $limit ? $gtotal : $total; // Add a form to create new testimonials $this->renderTestimonialForm($objTemplate, $objConfig, $intParent); }
/** * Generate the module */ protected function compile() { $time = time(); $offset = 0; $limit = null; $arrPolls = array(); $arrWhere = array(); // Maximum number of items if ($this->numberOfItems > 0) { $limit = $this->numberOfItems; } // Build the criteria if ($this->poll_visible == 'yes') { $arrWhere[] = "(showStart='' OR showStart<{$time}) AND (showStop='' OR showStop>{$time})"; } elseif ($this->poll_visible == 'no') { $arrWhere[] = "((showStart!='' AND showStart>={$time}) OR (showStop!='' AND showStop<={$time}))"; } if ($this->poll_active == 'yes') { $arrWhere[] = "closed='' AND (activeStart='' OR activeStart<{$time}) AND (activeStop='' OR activeStop>{$time})"; } elseif ($this->poll_active == 'no') { $arrWhere[] = "(closed=1 OR ((activeStart!='' AND activeStart>={$time}) OR (activeStop!='' AND activeStop<={$time})))"; } if ($this->poll_featured == 'yes') { $arrWhere[] = "featured=1"; } elseif ($this->poll_featured == 'no') { $arrWhere[] = "featured=''"; } if (!BE_USER_LOGGED_IN) { $arrWhere[] = "published=1"; } $total = $this->Database->execute("SELECT COUNT(*) AS total FROM tl_poll" . (!empty($arrWhere) ? " WHERE " . implode(" AND ", $arrWhere) : ""))->total; // Split the results if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) { // Adjust the overall limit if (isset($limit)) { $total = min($limit, $total); } // Get the current page $id = 'page_n' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } // Set limit and offset $limit = $this->perPage; $offset = (max($page, 1) - 1) * $this->perPage; // Overall limit if ($offset + $limit > $total) { $limit = $total - $offset; } // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, 7, $id); $this->Template->pagination = $objPagination->generate("\n "); } $objPollsStmt = $this->Database->prepare("SELECT * FROM tl_poll" . (!empty($arrWhere) ? " WHERE " . implode(" AND ", $arrWhere) : "") . " ORDER BY closed ASC, showStart DESC, activeStart DESC"); // Limit the result if (isset($limit)) { $objPollsStmt->limit($limit, $offset); } $objPolls = $objPollsStmt->execute(); // Generate the polls while ($objPolls->next()) { $objPoll = new \Poll($objPolls->id); $arrPolls[] = $objPoll->generate(); } $this->Template->polls = $arrPolls; }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; $blnClearInput = false; $intYear = \Input::get('year'); $intMonth = \Input::get('month'); $intDay = \Input::get('day'); // Jump to the current period if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day'])) { switch ($this->cal_format) { case 'cal_year': $intYear = date('Y'); break; case 'cal_month': $intMonth = date('Ym'); break; case 'cal_day': $intDay = date('Ymd'); break; } $blnClearInput = true; } $blnDynamicFormat = !$this->cal_ignoreDynamic && in_array($this->cal_format, array('cal_day', 'cal_month', 'cal_year')); // Create the date object try { if ($blnDynamicFormat && $intYear) { $this->Date = new \Date($intYear, 'Y'); $this->cal_format = 'cal_year'; $this->headline .= ' ' . date('Y', $this->Date->tstamp); } elseif ($blnDynamicFormat && $intMonth) { $this->Date = new \Date($intMonth, 'Ym'); $this->cal_format = 'cal_month'; $this->headline .= ' ' . \Date::parse('F Y', $this->Date->tstamp); } elseif ($blnDynamicFormat && $intDay) { $this->Date = new \Date($intDay, 'Ymd'); $this->cal_format = 'cal_day'; $this->headline .= ' ' . \Date::parse($objPage->dateFormat, $this->Date->tstamp); } else { $this->Date = new \Date(); } } catch (\OutOfBoundsException $e) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } list($strBegin, $strEnd, $strEmpty) = $this->getDatesFromFormat($this->Date, $this->cal_format); // Get all events $arrAllEvents = $this->getAllEvents($this->cal_calendar, $strBegin, $strEnd); $sort = $this->cal_order == 'descending' ? 'krsort' : 'ksort'; // Sort the days $sort($arrAllEvents); // Sort the events foreach (array_keys($arrAllEvents) as $key) { $sort($arrAllEvents[$key]); } $arrEvents = array(); $dateBegin = date('Ymd', $strBegin); $dateEnd = date('Ymd', $strEnd); // Remove events outside the scope foreach ($arrAllEvents as $key => $days) { if ($key < $dateBegin || $key > $dateEnd) { continue; } foreach ($days as $day => $events) { foreach ($events as $event) { $event['firstDay'] = $GLOBALS['TL_LANG']['DAYS'][date('w', $day)]; $event['firstDate'] = \Date::parse($objPage->dateFormat, $day); $event['datetime'] = date('Y-m-d', $day); $arrEvents[] = $event; } } } unset($arrAllEvents); $total = count($arrEvents); $limit = $total; $offset = 0; // Overall limit if ($this->cal_limit > 0) { $total = min($this->cal_limit, $total); $limit = $total; } // Pagination if ($this->perPage > 0) { $id = 'page_e' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } $offset = ($page - 1) * $this->perPage; $limit = min($this->perPage + $offset, $total); $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } $strMonth = ''; $strDate = ''; $strEvents = ''; $dayCount = 0; $eventCount = 0; $headerCount = 0; $imgSize = false; // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) { $imgSize = $this->imgSize; } } // Parse events for ($i = $offset; $i < $limit; $i++) { $event = $arrEvents[$i]; $blnIsLastEvent = false; // Last event on the current day if ($i + 1 == $limit || !isset($arrEvents[$i + 1]['firstDate']) || $event['firstDate'] != $arrEvents[$i + 1]['firstDate']) { $blnIsLastEvent = true; } /** @var \FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData($event); // Month header if ($strMonth != $event['month']) { $objTemplate->newMonth = true; $strMonth = $event['month']; } // Day header if ($strDate != $event['firstDate']) { $headerCount = 0; $objTemplate->header = true; $objTemplate->classHeader = ($dayCount % 2 == 0 ? ' even' : ' odd') . ($dayCount == 0 ? ' first' : '') . ($event['firstDate'] == $arrEvents[$limit - 1]['firstDate'] ? ' last' : ''); $strDate = $event['firstDate']; ++$dayCount; } // Show the teaser text of redirect events (see #6315) if (is_bool($event['details'])) { $objTemplate->hasDetails = false; } // Add the template variables $objTemplate->classList = $event['class'] . ($headerCount % 2 == 0 ? ' even' : ' odd') . ($headerCount == 0 ? ' first' : '') . ($blnIsLastEvent ? ' last' : '') . ' cal_' . $event['parent']; $objTemplate->classUpcoming = $event['class'] . ($eventCount % 2 == 0 ? ' even' : ' odd') . ($eventCount == 0 ? ' first' : '') . ($offset + $eventCount + 1 >= $limit ? ' last' : '') . ' cal_' . $event['parent']; $objTemplate->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $event['title'])); $objTemplate->more = $GLOBALS['TL_LANG']['MSC']['more']; $objTemplate->locationLabel = $GLOBALS['TL_LANG']['MSC']['location']; // Short view if ($this->cal_noSpan) { $objTemplate->day = $event['day']; $objTemplate->date = $event['date']; $objTemplate->span = $event['time'] == '' && $event['day'] == '' ? $event['date'] : ''; } else { $objTemplate->day = $event['firstDay']; $objTemplate->date = $event['firstDate']; $objTemplate->span = ''; } $objTemplate->addImage = false; // Add an image if ($event['addImage'] && $event['singleSRC'] != '') { $objModel = \FilesModel::findByUuid($event['singleSRC']); if ($objModel === null) { if (!\Validator::isUuid($event['singleSRC'])) { $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { if ($imgSize) { $event['size'] = $imgSize; } $event['singleSRC'] = $objModel->path; $this->addImageToTemplate($objTemplate, $event); } } $objTemplate->enclosure = array(); // Add enclosure if ($event['addEnclosure']) { $this->addEnclosuresToTemplate($objTemplate, $event); } $strEvents .= $objTemplate->parse(); ++$eventCount; ++$headerCount; } // No events found if ($strEvents == '') { $strEvents = "\n" . '<div class="empty">' . $strEmpty . '</div>' . "\n"; } // See #3672 $this->Template->headline = $this->headline; $this->Template->events = $strEvents; // Clear the $_GET array (see #2445) if ($blnClearInput) { \Input::setGet('year', null); \Input::setGet('month', null); \Input::setGet('day', null); } }
/** * Generate module */ protected function compile() { // use a private template if (TL_MODE == 'FE' && $this->gc_template != '') { $this->Template->style = count($this->arrStyle) ? implode(' ', $this->arrStyle) : ''; $this->Template->cssID = strlen($this->cssID[0]) ? ' id="' . $this->cssID[0] . '"' : ''; $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]); } // check for excluded albums in the module settings $arrExcludedAlbums = deserialize($this->gc_excludedAlbums); $strExcludedAlbums = is_array($arrExcludedAlbums) && !empty($arrExcludedAlbums) ? implode(',', $arrExcludedAlbums) : '0'; // redirect to the detailview if there is only 1 album if (!\Input::get('items') && $this->gc_redirectSingleAlb) { $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE published=? AND id NOT IN (' . $strExcludedAlbums . ')')->execute('1'); if ($objAlbum->numRows === 1) { \Input::setGet('items', $objAlbum->alias); } } if (\Input::get('items')) { $this->strAlbumalias = \Input::get('items'); // authenticate user if album is protected $this->authenticate($this->strAlbumalias); // get the album id from the album alias $objAlbum = $this->Database->prepare('SELECT id FROM tl_gallery_creator_albums WHERE alias=?')->execute($this->strAlbumalias); $this->intAlbumId = $objAlbum->id; } $switch = strlen(\Input::get('items')) ? 'detailview' : 'albumlisting'; $switch = strlen(\Input::get('jw_imagerotator')) ? 'jw_imagerotator' : $switch; switch ($switch) { case 'albumlisting': // get all published albums $arrAllowedAlbums = array(); if ($this->gc_hierarchicalOutput) { $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE published=? AND pid=? AND id NOT IN (' . $strExcludedAlbums . ')')->execute('1', '0'); } else { $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE published=? AND id NOT IN (' . $strExcludedAlbums . ')')->execute('1'); } while ($objAlbum->next()) { if (TL_MODE == 'FE' && $objAlbum->protected == true) { $this->import('FrontendUser', 'User'); // check if the frontend user is allowed if (FE_USER_LOGGED_IN && is_array(unserialize($this->User->allGroups))) { if (array_intersect(unserialize($this->User->allGroups), unserialize($objAlbum->groups))) { // user is allowed $arrAllowedAlbums[] = $objAlbum->id; } } continue; } // album is not protected $arrAllowedAlbums[] = $objAlbum->id; } // pagination settings $limit = $this->gc_AlbumsPerPage; if ($limit > 0) { $page = \Input::get('page') ? \Input::get('page') : 1; $offset = ($page - 1) * $limit; $itemsTotal = count($arrAllowedAlbums); // add pagination menu $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks; $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks); $this->Template->pagination = $objPagination->generate("\n "); } // get all published albums $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id IN(' . implode(",", $arrAllowedAlbums) . ') ORDER BY sorting ASC'); if ($limit > 0) { $objAlbum->limit($limit, $offset); } $objAlbum = $objAlbum->execute('1', '0'); // album array $arrAlbums = array(); while ($objAlbum->next()) { $arrAlbums[$objAlbum->id] = GcHelpers::getAlbumInformationArray($objAlbum->id, $this); } $this->Template->imagemargin = $this->generateMargin(unserialize($this->gc_imagemargin_albumlisting)); $this->Template->arrAlbums = $arrAlbums; $this->getAlbumTemplateVars($objAlbum->id); // Call gcGenerateFrontendTemplateHook $this->Template = $this->callGcGenerateFrontendTemplateHook($this); break; case 'detailview': $objAlbum = \GalleryCreatorAlbumsModel::findByPk($this->intAlbumId); $published = $objAlbum->published ? true : false; if ($published) { $published = in_array($this->intAlbumId, explode(',', $strExcludedAlbums)) ? false : true; } // for security reasons... if (!$published) { die("Gallery with alias " . \Input::get('items') . " is either not published or not available!!!"); } // generate the subalbum array if ($this->gc_hierarchicalOutput) { $arrSubalbums = GcHelpers::getSubalbumsInformationArray($this->intAlbumId, $this); $this->Template->subalbums = count($arrSubalbums) ? $arrSubalbums : null; } // pagination settings $limit = $this->gc_ThumbsPerPage; if ($limit > 0) { $page = \Input::get('page') ? \Input::get('page') : 1; $offset = ($page - 1) * $limit; // count albums $objTotal = $this->Database->prepare('SELECT COUNT(id) as itemsTotal FROM tl_gallery_creator_pictures WHERE published=? AND pid=?')->execute('1', $this->intAlbumId); $itemsTotal = $objTotal->itemsTotal; // add pagination menu $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks; $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks); $this->Template->pagination = $objPagination->generate("\n "); } $objPictures = $this->Database->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE published=? AND pid=? ORDER BY sorting'); if ($limit > 0) { $objPictures->limit($limit, $offset); } $objPictures = $objPictures->execute('1', $this->intAlbumId); $arrPictures = array(); while ($objPictures->next()) { // picture array $arrPictures[$objPictures->id] = GcHelpers::getPictureInformationArray($objPictures->id, $this); } // add picture array to the template $this->Template->arrPictures = $arrPictures; // add some other useful template vars $this->getAlbumTemplateVars($this->intAlbumId); // init the counter $this->initCounter($this->intAlbumId); // Call gcGenerateFrontendTemplateHook $this->Template = $this->callGcGenerateFrontendTemplateHook($this); break; case 'jw_imagerotator': header("content-type:text/xml;charset=utf-8"); echo $this->getJwImagerotatorXml($this->strAlbumalias); exit; break; } //end switch }
/** * Generate the module */ protected function compile() { $offset = intval($this->skipFirst); $limit = null; // Maximum number of items if ($this->numberOfItems > 0) { $limit = $this->numberOfItems; } // Handle featured news if ($this->photogallery_featured == 'featured') { $blnFeatured = true; } elseif ($this->photogallery_featured == 'unfeatured') { $blnFeatured = false; } else { $blnFeatured = null; } $this->Template->albums = array(); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyPhotogallery']; $intTotal = \PhotogalleryAlbumModel::countPublishedByPids($this->photogalleries); if ($intTotal < 1) { return; } $total = $intTotal - $offset; // Split the results if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) { // Adjust the overall limit if (isset($limit)) { $total = min($limit, $total); } // Get the current page $id = 'page_n' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } // Set limit and offset $limit = $this->perPage; $offset += (max($page, 1) - 1) * $this->perPage; $skip = intval($this->skipFirst); // Overall limit if ($offset + $limit > $total + $skip) { $limit = $total + $skip - $offset; } // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } // Get the items if (isset($limit)) { $objAlbums = \PhotogalleryAlbumModel::findPublishedByPids($this->photogalleries, $blnFeatured, $limit, $offset); } else { $objAlbums = \PhotogalleryAlbumModel::findPublishedByPids($this->photogalleries, $blnFeatured, 0, $offset); } // Add the albums if ($objAlbums !== null) { $this->Template->albums = $this->parseAlbums($objAlbums); } $this->Template->gategories = $this->photogalleries; }
/** * Generate module */ protected function compile() { $time = time(); /* build where */ $where = array(); // news archives $where[] = 'tl_news4ward_article.pid IN(' . implode(',', array_map('intval', $this->news_archives)) . ')'; // published if (!BE_USER_LOGGED_IN) { $where[] = "(tl_news4ward_article.start='' OR tl_news4ward_article.start<" . $time . ") AND (tl_news4ward_article.stop='' OR tl_news4ward_article.stop>" . $time . ") AND tl_news4ward_article.status='published'"; } // show only highlighted items? if ($this->news4ward_featured == 'featured') { $where[] = 'tl_news4ward_article.highlight="1"'; } elseif ($this->news4ward_featured == 'unfeatured') { $where[] = 'tl_news4ward_article.highlight<>"1"'; } // HOOK: add filter logic from other modules like tags if (isset($GLOBALS['TL_HOOKS']['News4wardListFilter']) && is_array($GLOBALS['TL_HOOKS']['News4wardListFilter'])) { foreach ($GLOBALS['TL_HOOKS']['News4wardListFilter'] as $callback) { $this->import($callback[0]); $tmp = $this->{$callback}[0]->{$callback}[1]($this); if (is_string($tmp) && !empty($tmp)) { $where[] = $tmp; } } } /* Ordering */ $ordering = array('tl_news4ward_article.sticky DESC'); switch ($this->news4ward_order) { case 'title ASC': $ordering[] = 'tl_news4ward_article.title'; break; case 'title DESC': $ordering[] = 'tl_news4ward_article.title DESC'; break; case 'start ASC': $ordering[] = 'tl_news4ward_article.start'; break; case 'start DESC': $ordering[] = 'tl_news4ward_article.start DESC'; break; } /* Pagination */ $skipFirst = intval($this->skipFirst); $offset = 0; $limit = null; // Maximum number of items if ($this->news4ward_numberOfItems > 0) { $limit = $this->news4ward_numberOfItems; } // Get the total number of items $objTotal = $this->Database->execute("SELECT COUNT(*) AS total FROM tl_news4ward_article WHERE " . implode(' AND ', $where)); $total = $objTotal->total - $skipFirst; // Split the results if ($this->perPage > 0 && (!isset($limit) || $this->news4ward_numberOfItems > $this->perPage)) { // Adjust the overall limit if (isset($limit)) { $total = min($limit, $total); } $page = $this->Input->get('page') ? $this->Input->get('page') : 1; // Check the maximum page number if ($page > $total / $this->perPage) { $page = ceil($total / $this->perPage); } // Limit and offset $limit = $this->perPage; $offset = (max($page, 1) - 1) * $this->perPage; // Overall limit if ($offset + $limit > $total) { $limit = $total - $offset; } // Add the pagination menu $objPagination = new Pagination($total, $this->perPage); $this->Template->pagination = $objPagination->generate("\n "); } /* get the items */ $objArticlesStmt = $this->Database->prepare("\n\t\t\tSELECT *, author AS authorId,\n\t\t\t\t(SELECT title FROM tl_news4ward WHERE tl_news4ward.id=tl_news4ward_article.pid) AS archive,\n\t\t\t\t(SELECT jumpTo FROM tl_news4ward WHERE tl_news4ward.id=tl_news4ward_article.pid) AS parentJumpTo,\n\t\t\t\t(SELECT name FROM tl_user WHERE id=author) AS author\n\t\t\tFROM tl_news4ward_article\n\t\t\tWHERE " . implode(' AND ', $where) . (count($ordering) ? ' ORDER BY ' . implode(',', $ordering) : '')); // Limit the result if (isset($limit)) { $objArticlesStmt->limit($limit, $offset + $skipFirst); } elseif ($skipFirst > 0) { $objArticlesStmt->limit(max($total, 1), $skipFirst); } $objArticles = $objArticlesStmt->execute(); $this->Template->articles = $this->parseArticles($objArticles); $this->Template->archives = $this->news_archives; $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyList']; // add newsfeeds to page $this->addNewsfeedsToLayout(); }
/** * Add comments to a template * * @param \FrontendTemplate|object $objTemplate * @param \stdClass $objConfig * @param string $strSource * @param integer $intParent * @param mixed $varNotifies */ public function addCommentsToTemplate(\FrontendTemplate $objTemplate, \stdClass $objConfig, $strSource, $intParent, $varNotifies) { /** @var \PageModel $objPage */ global $objPage; $limit = 0; $offset = 0; $total = 0; $gtotal = 0; $arrComments = array(); $objTemplate->comments = array(); // see #4064 // Pagination if ($objConfig->perPage > 0) { // Get the total number of comments $intTotal = \CommentsModel::countPublishedBySourceAndParent($strSource, $intParent); $total = $gtotal = $intTotal; // Calculate the key (e.g. tl_form_field becomes page_cff12) $key = ''; $chunks = explode('_', substr($strSource, strncmp($strSource, 'tl_', 3) === 0 ? 3 : 0)); foreach ($chunks as $chunk) { $key .= substr($chunk, 0, 1); } // Get the current page $id = 'page_c' . $key . $intParent; // see #4141 $page = \Input::get($id) !== null ? \Input::get($id) : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $objConfig->perPage), 1)) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } // Set limit and offset $limit = $objConfig->perPage; $offset = ($page - 1) * $objConfig->perPage; // Initialize the pagination menu $objPagination = new \Pagination($total, $objConfig->perPage, \Config::get('maxPaginationLinks'), $id); $objTemplate->pagination = $objPagination->generate("\n "); } $objTemplate->allowComments = true; // Get all published comments if ($limit) { $objComments = \CommentsModel::findPublishedBySourceAndParent($strSource, $intParent, $objConfig->order == 'descending', $limit, $offset); } else { $objComments = \CommentsModel::findPublishedBySourceAndParent($strSource, $intParent, $objConfig->order == 'descending'); } // Parse the comments if ($objComments !== null && ($total = $objComments->count()) > 0) { $count = 0; if ($objConfig->template == '') { $objConfig->template = 'com_default'; } /** @var \FrontendTemplate|object $objPartial */ $objPartial = new \FrontendTemplate($objConfig->template); while ($objComments->next()) { $objPartial->setData($objComments->row()); // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $objPartial->comment = \StringUtil::toXhtml($objComments->comment); } else { $objPartial->comment = \StringUtil::toHtml5($objComments->comment); } $objPartial->comment = trim(str_replace(array('{{', '}}'), array('{{', '}}'), $objPartial->comment)); $objPartial->datim = \Date::parse($objPage->datimFormat, $objComments->date); $objPartial->date = \Date::parse($objPage->dateFormat, $objComments->date); $objPartial->class = ($count < 1 ? ' first' : '') . ($count >= $total - 1 ? ' last' : '') . ($count % 2 == 0 ? ' even' : ' odd'); $objPartial->by = $GLOBALS['TL_LANG']['MSC']['com_by']; $objPartial->id = 'c' . $objComments->id; $objPartial->timestamp = $objComments->date; $objPartial->datetime = date('Y-m-d\\TH:i:sP', $objComments->date); $objPartial->addReply = false; // Reply if ($objComments->addReply && $objComments->reply != '') { if (($objAuthor = $objComments->getRelated('author')) !== null) { $objPartial->addReply = true; $objPartial->rby = $GLOBALS['TL_LANG']['MSC']['com_reply']; $objPartial->reply = $this->replaceInsertTags($objComments->reply); $objPartial->author = $objAuthor; // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $objPartial->reply = \StringUtil::toXhtml($objPartial->reply); } else { $objPartial->reply = \StringUtil::toHtml5($objPartial->reply); } } } $arrComments[] = $objPartial->parse(); ++$count; } } $objTemplate->comments = $arrComments; $objTemplate->addComment = $GLOBALS['TL_LANG']['MSC']['addComment']; $objTemplate->name = $GLOBALS['TL_LANG']['MSC']['com_name']; $objTemplate->email = $GLOBALS['TL_LANG']['MSC']['com_email']; $objTemplate->website = $GLOBALS['TL_LANG']['MSC']['com_website']; $objTemplate->commentsTotal = $limit ? $gtotal : $total; // Add a form to create new comments $this->renderCommentForm($objTemplate, $objConfig, $strSource, $intParent, $varNotifies); }
/** * Generate the module */ protected function compile() { \System::loadLanguageFile($this->list_table); $this->loadDataContainer($this->list_table); // List a single record if (\Input::get('show')) { $this->listSingleRecord(\Input::get('show')); return; } /** * Add the search menu */ $strWhere = ''; $varKeyword = ''; $strOptions = ''; $this->Template->searchable = false; $arrSearchFields = trimsplit(',', $this->list_search); if (!empty($arrSearchFields) && is_array($arrSearchFields)) { $this->Template->searchable = true; if (\Input::get('search') && \Input::get('for')) { $varKeyword = '%' . \Input::get('for') . '%'; $strWhere = (!$this->list_where ? " WHERE " : " AND ") . \Input::get('search') . " LIKE ?"; } foreach ($arrSearchFields as $field) { $strOptions .= ' <option value="' . $field . '"' . ($field == \Input::get('search') ? ' selected="selected"' : '') . '>' . (strlen($label = $GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['label'][0]) ? $label : $field) . '</option>' . "\n"; } } $this->Template->search_fields = $strOptions; /** * Get the total number of records */ $strQuery = "SELECT COUNT(*) AS count FROM " . $this->list_table; if ($this->list_where) { $strQuery .= " WHERE (" . $this->list_where . ")"; } $strQuery .= $strWhere; $objTotal = $this->Database->prepare($strQuery)->execute($varKeyword); /** * Validate the page count */ $id = 'page_l' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; $per_page = \Input::get('per_page') ?: $this->perPage; // Thanks to Hagen Klemp (see #4485) if ($per_page > 0 && ($page < 1 || $page > max(ceil($objTotal->count / $per_page), 1))) { /** @var \PageModel $objPage */ global $objPage; /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } /** * Get the selected records */ $strQuery = "SELECT " . $this->strPk . "," . $this->list_fields; if ($this->list_info_where) { $strQuery .= ", (SELECT COUNT(*) FROM " . $this->list_table . " t2 WHERE t2." . $this->strPk . "=t1." . $this->strPk . " AND " . $this->list_info_where . ") AS _details"; } $strQuery .= " FROM " . $this->list_table . " t1"; if ($this->list_where) { $strQuery .= " WHERE (" . $this->list_where . ")"; } $strQuery .= $strWhere; // Cast date fields to int (see #5609) $isInt = function ($field) { return $GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['eval']['rgxp'] == 'date' || $GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['eval']['rgxp'] == 'time' || $GLOBALS['TL_DCA'][$this->list_table]['fields'][$field]['eval']['rgxp'] == 'datim'; }; // Order by if (\Input::get('order_by')) { if ($isInt(\Input::get('order_by'))) { $strQuery .= " ORDER BY CAST(" . \Input::get('order_by') . " AS SIGNED) " . \Input::get('sort'); } else { $strQuery .= " ORDER BY " . \Input::get('order_by') . ' ' . \Input::get('sort'); } } elseif ($this->list_sort) { if ($isInt($this->list_sort)) { $strQuery .= " ORDER BY CAST(" . $this->list_sort . " AS SIGNED)"; } else { $strQuery .= " ORDER BY " . $this->list_sort; } } $objDataStmt = $this->Database->prepare($strQuery); // Limit if (\Input::get('per_page')) { $objDataStmt->limit(\Input::get('per_page'), ($page - 1) * $per_page); } elseif ($this->perPage) { $objDataStmt->limit($this->perPage, ($page - 1) * $per_page); } $objData = $objDataStmt->execute($varKeyword); /** * Prepare the URL */ $strUrl = preg_replace('/\\?.*$/', '', \Environment::get('request')); $blnQuery = false; foreach (preg_split('/&(amp;)?/', \Environment::get('queryString')) as $fragment) { if ($fragment != '' && strncasecmp($fragment, 'order_by', 8) !== 0 && strncasecmp($fragment, 'sort', 4) !== 0 && strncasecmp($fragment, $id, strlen($id)) !== 0) { $strUrl .= (!$blnQuery && !\Config::get('disableAlias') ? '?' : '&') . $fragment; $blnQuery = true; } } $this->Template->url = $strUrl; $strVarConnector = $blnQuery || \Config::get('disableAlias') ? '&' : '?'; /** * Prepare the data arrays */ $arrTh = array(); $arrTd = array(); $arrFields = trimsplit(',', $this->list_fields); // THEAD for ($i = 0, $c = count($arrFields); $i < $c; $i++) { // Never show passwords if ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$arrFields[$i]]['inputType'] == 'password') { continue; } $class = ''; $sort = 'asc'; $strField = strlen($label = $GLOBALS['TL_DCA'][$this->list_table]['fields'][$arrFields[$i]]['label'][0]) ? $label : $arrFields[$i]; // Add a CSS class to the order_by column if (\Input::get('order_by') == $arrFields[$i]) { $sort = \Input::get('sort') == 'asc' ? 'desc' : 'asc'; $class = ' sorted ' . \Input::get('sort'); } $arrTh[] = array('link' => $strField, 'href' => ampersand($strUrl) . $strVarConnector . 'order_by=' . $arrFields[$i] . '&sort=' . $sort, 'title' => specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['list_orderBy'], $strField)), 'class' => $class . ($i == 0 ? ' col_first' : '')); } $j = 0; $arrRows = $objData->fetchAllAssoc(); // TBODY for ($i = 0, $c = count($arrRows); $i < $c; $i++) { $j = 0; $class = 'row_' . $i . ($i == 0 ? ' row_first' : '') . ($i + 1 == count($arrRows) ? ' row_last' : '') . ($i % 2 == 0 ? ' even' : ' odd'); foreach ($arrRows[$i] as $k => $v) { // Skip the primary key if ($k == $this->strPk && !in_array($this->strPk, $arrFields)) { continue; } if ($k == '_details') { continue; } // Never show passwords if ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['inputType'] == 'password') { continue; } $value = $this->formatValue($k, $v); $arrTd[$class][$k] = array('raw' => $v, 'content' => $value ? $value : ' ', 'class' => 'col_' . $j . ($j++ == 0 ? ' col_first' : '') . ($this->list_info ? '' : ($j >= count($arrRows[$i]) - 1 ? ' col_last' : '')), 'id' => $arrRows[$i][$this->strPk], 'field' => $k, 'url' => $strUrl . $strVarConnector . 'show=' . $arrRows[$i][$this->strPk], 'details' => isset($arrRows[$i]['_details']) ? $arrRows[$i]['_details'] : 1); } } $this->Template->thead = $arrTh; $this->Template->tbody = $arrTd; /** * Pagination */ $objPagination = new \Pagination($objTotal->count, $per_page, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); $this->Template->per_page = $per_page; $this->Template->total = $objTotal->count; /** * Template variables */ $this->Template->action = \Environment::get('indexFreeRequest'); $this->Template->details = $this->list_info != '' ? true : false; $this->Template->search_label = specialchars($GLOBALS['TL_LANG']['MSC']['search']); $this->Template->per_page_label = specialchars($GLOBALS['TL_LANG']['MSC']['list_perPage']); $this->Template->fields_label = $GLOBALS['TL_LANG']['MSC']['all_fields'][0]; $this->Template->keywords_label = $GLOBALS['TL_LANG']['MSC']['keywords']; $this->Template->search = \Input::get('search'); $this->Template->for = \Input::get('for'); $this->Template->order_by = \Input::get('order_by'); $this->Template->sort = \Input::get('sort'); $this->Template->col_last = 'col_' . $j; }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; $limit = null; $offset = 0; $intBegin = 0; $intEnd = 0; $intYear = \Input::get('year'); $intMonth = \Input::get('month'); $intDay = \Input::get('day'); // Jump to the current period if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day']) && $this->news_jumpToCurrent != 'all_items') { switch ($this->news_format) { case 'news_year': $intYear = date('Y'); break; default: case 'news_month': $intMonth = date('Ym'); break; case 'news_day': $intDay = date('Ymd'); break; } } // Create the date object try { if ($intYear) { $strDate = $intYear; $objDate = new \Date($strDate, 'Y'); $intBegin = $objDate->yearBegin; $intEnd = $objDate->yearEnd; $this->headline .= ' ' . date('Y', $objDate->tstamp); } elseif ($intMonth) { $strDate = $intMonth; $objDate = new \Date($strDate, 'Ym'); $intBegin = $objDate->monthBegin; $intEnd = $objDate->monthEnd; $this->headline .= ' ' . \Date::parse('F Y', $objDate->tstamp); } elseif ($intDay) { $strDate = $intDay; $objDate = new \Date($strDate, 'Ymd'); $intBegin = $objDate->dayBegin; $intEnd = $objDate->dayEnd; $this->headline .= ' ' . \Date::parse($objPage->dateFormat, $objDate->tstamp); } elseif ($this->news_jumpToCurrent == 'all_items') { $intBegin = 0; $intEnd = time(); } } catch (\OutOfBoundsException $e) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } $this->Template->articles = array(); // Split the result if ($this->perPage > 0) { // Get the total number of items $intTotal = \NewsModel::countPublishedFromToByPids($intBegin, $intEnd, $this->news_archives); if ($intTotal > 0) { $total = $intTotal; // Get the current page $id = 'page_a' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } // Set limit and offset $limit = $this->perPage; $offset = (max($page, 1) - 1) * $this->perPage; // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } } // Get the news items if (isset($limit)) { $objArticles = \NewsModel::findPublishedFromToByPids($intBegin, $intEnd, $this->news_archives, $limit, $offset); } else { $objArticles = \NewsModel::findPublishedFromToByPids($intBegin, $intEnd, $this->news_archives); } // Add the articles if ($objArticles !== null) { $this->Template->articles = $this->parseArticles($objArticles); } $this->Template->headline = trim($this->headline); $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['empty']; }
/** * Generate module */ protected function compile() { if ($this->rss_template != 'rss_default') { $this->strTemplate = $this->rss_template; $this->Template = new FrontendTemplate($this->strTemplate); $this->Template->setData($this->arrData); } $this->Template->link = $this->objFeed->get_link(); $this->Template->title = $this->objFeed->get_title(); $this->Template->language = $this->objFeed->get_language(); $this->Template->description = $this->objFeed->get_description(); $this->Template->copyright = $this->objFeed->get_copyright(); // Add image if ($this->objFeed->get_image_url()) { $this->Template->image = true; $this->Template->src = $this->objFeed->get_image_url(); $this->Template->alt = $this->objFeed->get_image_title(); $this->Template->href = $this->objFeed->get_image_link(); $this->Template->height = $this->objFeed->get_image_height(); $this->Template->width = $this->objFeed->get_image_width(); } // Get items $arrItems = $this->objFeed->get_items(intval($this->skipFirst), $this->rss_numberOfItems); $limit = count($arrItems); $offset = 0; // Split pages if ($this->perPage > 0) { $page = $this->Input->get('page') ? $this->Input->get('page') : 1; $offset = ($page - 1) * $this->perPage; $limit = $this->perPage + $offset; $objPagination = new Pagination(count($arrItems), $this->perPage); $this->Template->pagination = $objPagination->generate("\n "); } $items = array(); $last = min($limit, count($arrItems)) - 1; for ($i = $offset; $i < $limit && $i < count($arrItems); $i++) { $items[$i] = array('link' => $arrItems[$i]->get_link(), 'title' => $arrItems[$i]->get_title(), 'permalink' => $arrItems[$i]->get_permalink(), 'description' => str_replace(array('<?', '?>'), array('<?', '?>'), $arrItems[$i]->get_description()), 'class' => ($i == 0 ? ' first' : ($i == $last ? ' last' : '')) . ($i % 2 == 0 ? ' even' : ' odd'), 'pubdate' => $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $arrItems[$i]->get_date('U')), 'category' => $arrItems[$i]->get_category(0)); // Add author if (($objAuthor = $arrItems[$i]->get_author(0)) != false) { $items[$i]['author'] = trim($objAuthor->name . ' ' . $objAuthor->email); } // Add enclosure if (($objEnclosure = $arrItems[$i]->get_enclosure(0)) != false) { $items[$i]['enclosure'] = $objEnclosure->get_link(); } } $this->Template->items = array_values($items); }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; if ($this->rss_template != 'rss_default') { $this->strTemplate = $this->rss_template; /** @var \FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->strTemplate); $this->Template = $objTemplate; $this->Template->setData($this->arrData); } $this->Template->link = $this->objFeed->get_link(); $this->Template->title = $this->objFeed->get_title(); $this->Template->language = $this->objFeed->get_language(); $this->Template->description = $this->objFeed->get_description(); $this->Template->copyright = $this->objFeed->get_copyright(); // Add image if ($this->objFeed->get_image_url()) { $this->Template->image = true; $this->Template->src = $this->objFeed->get_image_url(); $this->Template->alt = $this->objFeed->get_image_title(); $this->Template->href = $this->objFeed->get_image_link(); $this->Template->height = $this->objFeed->get_image_height(); $this->Template->width = $this->objFeed->get_image_width(); } // Get the items (see #6107) $arrItems = array_slice($this->objFeed->get_items(0, intval($this->numberOfItems) + intval($this->skipFirst)), intval($this->skipFirst), intval($this->numberOfItems) ?: null); $limit = count($arrItems); $offset = 0; // Split pages if ($this->perPage > 0) { // Get the current page $id = 'page_r' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil(count($arrItems) / $this->perPage), 1)) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } // Set limit and offset $offset = ($page - 1) * $this->perPage; $limit = $this->perPage + $offset; $objPagination = new \Pagination(count($arrItems), $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } $items = array(); $last = min($limit, count($arrItems)) - 1; /** @var \SimplePie_Item[] $arrItems */ for ($i = $offset, $c = count($arrItems); $i < $limit && $i < $c; $i++) { $items[$i] = array('link' => $arrItems[$i]->get_link(), 'title' => $arrItems[$i]->get_title(), 'permalink' => $arrItems[$i]->get_permalink(), 'description' => str_replace(array('<?', '?>'), array('<?', '?>'), $arrItems[$i]->get_description()), 'class' => ($i == 0 ? ' first' : '') . ($i == $last ? ' last' : '') . ($i % 2 == 0 ? ' even' : ' odd'), 'pubdate' => \Date::parse($objPage->datimFormat, $arrItems[$i]->get_date('U')), 'category' => $arrItems[$i]->get_category(0), 'object' => $arrItems[$i]); // Add author if (($objAuthor = $arrItems[$i]->get_author(0)) != false) { $items[$i]['author'] = trim($objAuthor->name . ' ' . $objAuthor->email); } // Add enclosure if (($objEnclosure = $arrItems[$i]->get_enclosure(0)) != false) { $items[$i]['enclosure'] = $objEnclosure->get_link(); } } $this->Template->items = array_values($items); }
/** * Generate the module */ protected function compile() { global $objPage; $blnClearInput = false; $intYear = \Input::get('year'); $intMonth = \Input::get('month'); $intDay = \Input::get('day'); // Jump to the current period if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day'])) { switch ($this->cal_format) { case 'cal_year': $intYear = date('Y'); break; case 'cal_month': $intMonth = date('Ym'); break; case 'cal_day': $intDay = date('Ymd'); break; } $blnClearInput = true; } $blnDynamicFormat = !$this->cal_ignoreDynamic && in_array($this->cal_format, array('cal_day', 'cal_month', 'cal_year')); // Display year if ($blnDynamicFormat && $intYear) { $this->Date = new \Date($intYear, 'Y'); $this->cal_format = 'cal_year'; $this->headline .= ' ' . date('Y', $this->Date->tstamp); } elseif ($blnDynamicFormat && $intMonth) { $this->Date = new \Date($intMonth, 'Ym'); $this->cal_format = 'cal_month'; $this->headline .= ' ' . \Date::parse('F Y', $this->Date->tstamp); } elseif ($blnDynamicFormat && $intDay) { $this->Date = new \Date($intDay, 'Ymd'); $this->cal_format = 'cal_day'; $this->headline .= ' ' . \Date::parse($objPage->dateFormat, $this->Date->tstamp); } else { $this->Date = new \Date(); } list($strBegin, $strEnd, $strEmpty) = $this->getDatesFromFormat($this->Date, $this->cal_format); $arrFilter = array(); $arrOptions = array(); $arrFilterConfig = array(); if ($this->cal_filterModule) { $objFilterModule = \ModuleModel::findByPk($this->cal_filterModule); if ($objFilterModule !== null) { $objFilterModule = $this->prepareFilterModel($objFilterModule); $arrFilter = $this->getFilter($objFilterModule); // $arrOptions = $this->getPossibleFilterOptions($objFilterModule); $arrFilterConfig['module'] = $objFilterModule->row(); $arrFilterConfig['combine_docents'] = $objFilterModule->cal_docent_combine; if (!empty($arrFilter)) { $strEmpty =& $GLOBALS['TL_LANG']['eventlist']['listEmptyFilter']; } } } // Get all events $arrAllEvents = $this->getAllEvents($this->cal_calendar, $strBegin, $strEnd, $arrFilter, $arrOptions, $arrFilterConfig); $isRelatedList = false; if (empty($arrAllEvents) && $objFilterModule->cal_filterRelatedOnEmpty) { $arrFilterConfig['show_related'] = true; $arrAllEvents = $this->getAllEvents($this->cal_calendar, $strBegin, $strEnd, $arrFilter, $arrOptions, $arrFilterConfig); $isRelatedList = true; } $sort = $this->cal_order == 'descending' ? 'krsort' : 'ksort'; // Sort the days $sort($arrAllEvents); // Sort the events foreach (array_keys($arrAllEvents) as $key) { $sort($arrAllEvents[$key]); } $arrEvents = array(); $arrEventIds = array(); $arrParentEvents = array(); $arrParentEventIds = array(); $arrSubEvents = array(); $dateBegin = date('Ymd', $strBegin); $dateEnd = date('Ymd', $strEnd); // Remove events outside the scope foreach ($arrAllEvents as $key => $days) { if ($key < $dateBegin || $key > $dateEnd) { continue; } foreach ($days as $day => $events) { foreach ($events as $event) { $event['firstDay'] = $GLOBALS['TL_LANG']['DAYS'][date('w', $day)]; $event['firstDate'] = \Date::parse($objPage->dateFormat, $day); $event['datetime'] = date('Y-m-d', $day); $event['dateday'] = $day; if (!$this->cal_ungroupSubevents) { // event is child event --> add parent event if (($intParentEvent = $event['parentEvent']) > 0) { // add parent event if (($arrParentEvent = $this->getParentEventDetails($intParentEvent, $event['pid'], $strBegin)) === null) { continue; } $arrParentEvent['firstDay'] = $GLOBALS['TL_LANG']['DAYS'][date('w', $day)]; $arrParentEvent['firstDate'] = \Date::parse($objPage->dateFormat, $day); $arrParentEvent['datetime'] = date('Y-m-d', $day); $arrParentEvent['dateday'] = $day; $arrParentEvents[$arrParentEvent['id']] = $arrParentEvent; $arrParentEventIds[] = $arrParentEvent['id']; // set parent event as href $event['href'] = $event['parentHref']; $arrSubEvents[$intParentEvent][$event['id']] = $event; continue; } else { $objChildEvents = CalendarPlusEventsModel::findPublishedSubEvents($event['id']); if ($objChildEvents !== null) { while ($objChildEvents->next()) { $arrSubEvents[$event['id']][$objChildEvents->id] = $this->addSingleEvent($objChildEvents, $strBegin); } } } } $arrEvents[] = $event; $arrEventIds[] = $event['id']; } } } // add parent events to $arrEvents if (!empty($arrParentEventIds)) { $arrEventIds = array_diff($arrParentEventIds, $arrEventIds); foreach ($arrParentEvents as $id => $event) { if (!in_array($id, $arrEventIds)) { continue; } $arrEvents[] = $event; } } unset($arrAllEvents); $total = count($arrEvents); $limit = $total; $offset = 0; // Overall limit if ($this->cal_limit > 0) { $total = min($this->cal_limit, $total); $limit = $total; } // Pagination if ($this->perPage > 0) { $id = 'page_e' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } $offset = ($page - 1) * $this->perPage; $limit = min($this->perPage + $offset, $total); // load specific pagination template if infiniteScroll is used // otherwise keep standard pagination $objT = $this->cal_useInfiniteScroll ? new \FrontendTemplate('infinite_pagination') : null; if (!is_null($objT)) { $objT->triggerText = $this->cal_changeTriggerText ? $this->cal_triggerText : $GLOBALS['TL_LANG']['eventlist']['loadMore']; } // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id, $objT); $this->Template->pagination = $objPagination->generate("\n "); } $strMonth = ''; $strDate = ''; $strEvents = ''; $monthCount = 0; $dayCount = 0; $eventCount = 0; $headerCount = 0; $headerMonthCount = 0; $imgSize = false; // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) { $imgSize = $this->imgSize; } } // Parse events for ($i = $offset; $i < $limit; $i++) { $event = $arrEvents[$i]; $blnIsLastEvent = false; // Last event on the current day if ($i + 1 == $limit || !isset($arrEvents[$i + 1]['firstDate']) || $event['firstDate'] != $arrEvents[$i + 1]['firstDate']) { $blnIsLastEvent = true; } $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData($event); $objTemplate->lastItem = $i + 1 == $limit || $arrEvents[$i + 1]['month'] != $event['month'] || $arrEvents[$i + 1]['firstDate'] != $event['firstDate']; // Month header if ($strMonth != $event['month']) { $headerMonthCount = 0; $objTemplate->newMonth = true; $objTemplate->classMonth = ($monthCount % 2 == 0 ? ' even' : ' odd') . ($monthCount == 0 ? ' first' : '') . ($event['firstDate'] == $arrEvents[$limit - 1]['firstDate'] ? ' last' : ''); $strMonth = $event['month']; ++$monthCount; } // Day header if ($strDate != $event['firstDate']) { $headerCount = 0; $objTemplate->header = true; $objTemplate->classHeader = ($dayCount % 2 == 0 ? ' even' : ' odd') . ($dayCount == 0 ? ' first' : '') . ($event['firstDate'] == $arrEvents[$limit - 1]['firstDate'] ? ' last' : ''); $objTemplate->firstHeader = $dayCount == 0; $strDate = $event['firstDate']; ++$dayCount; } if (isset($arrSubEvents[$event['id']]) && is_array($arrSubEvents[$event['id']])) { $strSubEvents = ''; foreach ($arrSubEvents[$event['id']] as $subID => $arrSubEvent) { $objSubEventTemplate = new \FrontendTemplate($this->cal_templateSubevent); $objSubEventTemplate->setData($arrSubEvent); $this->addEventDetailsToTemplate($objTemplate, $arrSubEvent, $headerCount, $eventCount, $imgSize); $strSubEvents .= $objSubEventTemplate->parse() . "\n"; } $objTemplate->subEvents = $strSubEvents; } $strClassList = $event['class'] . ($headerCount % 2 == 0 ? ' even' : ' odd') . ($headerCount == 0 ? ' first' : '') . ($blnIsLastEvent ? ' last' : '') . ' cal_' . $event['parent']; $strClassUpcoming = $event['class'] . ($eventCount % 2 == 0 ? ' even' : ' odd') . ($eventCount == 0 ? ' first' : '') . ($offset + $eventCount + 1 >= $limit ? ' last' : '') . ' cal_' . $event['parent']; $this->addEventDetailsToTemplate($objTemplate, $event, $strClassList, $strClassUpcoming, $imgSize); $strEvents .= $objTemplate->parse(); ++$eventCount; ++$headerCount; } $strEmpty = "\n" . '<div class="empty">' . $strEmpty . '</div>' . "\n"; $this->Template->emptyMessage = $strEmpty; // No events found if ($strEvents == '') { $strEvents = $strEmpty; $this->Template->empty = true; } // See #3672 $this->Template->headline = $this->headline; $this->Template->events = $strEvents; $this->Template->isRelated = $isRelatedList && !$this->Template->empty; // Clear the $_GET array (see #2445) if ($blnClearInput) { \Input::setGet('year', null); \Input::setGet('month', null); \Input::setGet('day', null); } }