/**
  * Generate the module
  */
 protected function compile()
 {
     $this->import('Sermoner');
     $offset = intval($this->skipFirst);
     $limit = null;
     $this->Template->sermons = array();
     // Maximum number of items
     if ($this->numberOfItems > 0) {
         $limit = $this->numberOfItems;
     }
     // Get the total number of items
     $intTotal = \SermonerItemsModel::countPublishedByPids($this->serm_sermonarchive);
     if ($intTotal < 1) {
         $this->Template = new \FrontendTemplate('mod_sermonlist_empty');
         $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyList'];
         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, $GLOBALS['TL_CONFIG']['maxPaginationLinks'], $id);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     //Configuration
     $objConfig = new \stdClass();
     $objConfig->feedHref = sprintf("%s/share/%s.xml", \Environment::get('path'), \SermonFeedModel::findByPk($this->linkedRssFeed)->alias);
     $objConfig->feedIcon = $this->iconSRC;
     $objConfig->template = $this->serm_template;
     // Get the items
     if (isset($limit)) {
         $objSermons = \SermonerItemsModel::findPublishedByPids($this->serm_sermonarchive, $limit, $offset);
     } else {
         $objSermons = \SermonerItemsModel::findPublishedByPids($this->serm_sermonarchive, 0, $offset);
     }
     // No items found
     if ($objSermons === null) {
         $this->Template = new \FrontendTemplate('mod_sermonlist_empty');
         $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyList'];
     } else {
         $this->Template->sermons = $this->Sermoner->parseSermons($objSermons, $objConfig);
     }
 }
Example #2
0
 /**
  * Parse an item and return it as string
  * @param object
  * @param boolean
  * @param string
  * @param integer
  * @param object
  * @return string
  */
 public function parseSermon($objSermon, $blnAddArchive = false, $strClass = '', $intCount = 0, $objConfig)
 {
     global $objPage;
     $objTemplate = new \FrontendTemplate($objConfig->template);
     $objTemplate->setData($objSermon->row());
     $objTemplate->sermonId = standardize(\String::restoreBasicEntities($objSermon->title));
     $objTemplate->class = ($objSermon->cssClass != '' ? ' ' . $objSermon->cssClass : '') . $strClass;
     $objTemplate->count = $intCount;
     // see #5708
     $objTemplate->date = \Date::parse($objPage->dateFormat, $objSermon->date);
     $objTemplate->subject = $objSermon->title;
     $objTemplate->speakerLabel = $GLOBALS['TL_LANG']['MSC']['preacher'];
     $objTemplate->moderatorLabel = $GLOBALS['TL_LANG']['MSC']['moderator'];
     $objTemplate->addImage = false;
     // Add an image
     if ($objSermon->addImage && $objSermon->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objSermon->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objSermon->singleSRC)) {
                 $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             // Do not override the field now that we have a model registry (see #6303)
             $arrSermon = $objSermon->row();
             $arrSermon['singleSRC'] = $objModel->path;
             $this->addImageToTemplate($objTemplate, $arrSermon);
         }
     }
     // Add the audio file
     if ($objSermon->audioSingleSRC != '') {
         /*$this->import('getid3');
         			$getID3 = new \getID3();
         
         			$ThisFileInfo = $getID3->analyze($objAudioModel = \FilesModel::findByUuid($objSermon->audioSingleSRC)->path);
         			print_r($ThisFileInfo['tags']['id3v2']);*/
         $objAudio = $objSermon;
         $objAudio->playerSRC = serialize(array($objSermon->audioSingleSRC));
         $contentPlayer = new \ContentMedia($objAudio);
         $objTemplate->player = $contentPlayer->generate();
     }
     if ($objSermon->getRelated('pid')->showRssFeed) {
         $linkedRssFeed = \SermonFeedModel::findByPk($objSermon->getRelated('pid')->linkedRssFeed);
         if ($linkedRssFeed) {
             $objTemplate->feedHref = sprintf("%s/share/%s.xml", \Environment::get('path'), $linkedRssFeed->alias);
         }
     }
     $objTemplate->addReference = false;
     // Add an Reference
     switch ($objSermon->addReference) {
         case 'none':
             $objTemplate->addReference = false;
             break;
         case 'file':
             $objTemplate->addReference = true;
             $objDownload = $objSermon;
             $objDownload->singleSRC = $objSermon->fileSingleSRC;
             $contentDownload = new \ContentDownload($objDownload);
             $objTemplate->reference = $contentDownload->generate();
             break;
         case 'link':
             $objTemplate->addReference = true;
             $contentHyperlink = new \ContentHyperlink($objSermon);
             $objTemplate->reference = $contentHyperlink->generate();
             break;
     }
     //Syndication Facebook
     $objRedirectPage = \PageModel::findByPk($objSermon->getRelated('pid')->jumpTo);
     //Download Predigt
     $objDownload = $objSermon;
     $objDownload->singleSRC = $objSermon->audioSingleSRC;
     $objDownload->linkTitle = '<img src="files/layout/icons/download.png" width="20" height="20" alt="">';
     $objDownload->titleText = $GLOBALS['TL_LANG']['sermoner']['downloadTitle'];
     $contentDownload = new \ContentDownload($objDownload);
     $objTemplate->sermonDownload = $contentDownload->generate();
     $objTemplate->encUrl = rawurlencode(\Environment::get('base') . ampersand($this->generateFrontendUrl($objRedirectPage->row(), ($GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objSermon->alias != '' ? $objSermon->alias : $objSermon->id))));
     $objTemplate->encTitle = rawurlencode($objSermon->title);
     return $objTemplate->parse();
 }