コード例 #1
0
 /**
  * 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);
     }
 }
コード例 #2
0
ファイル: Sermoner.php プロジェクト: samheer/contao-sermoner
 /**
  * Generate an XML files and save them to the root directory
  * @param array
  */
 protected function generateFiles($arrFeed)
 {
     $arrArchives = deserialize($arrFeed['archives']);
     if (!is_array($arrArchives) || empty($arrArchives)) {
         return;
     }
     switch ($arrFeed['format']) {
         case 'rss':
             $strType = 'generateRss';
             break;
         case 'atom':
             $strType = 'generateAtom';
             break;
         case 'podcast':
             $strType = 'generatePodcast';
             break;
     }
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new FeedPodcast($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     //Add Feed Image
     if ($arrFeed['format'] == 'podcast') {
         $objFile = \FilesModel::findByUuid($arrFeed['podcastSingleSRC']);
         if ($objFile !== null) {
             $objFeed->imageUrl = \Environment::get('base') . $objFile->path;
         }
     }
     // Get the items
     if ($arrFeed['maxItems'] > 0) {
         $objSermons = \SermonerItemsModel::findPublishedByPids($arrArchives, $arrFeed['maxItems']);
     } else {
         $objSermons = \SermonerItemsModel::findPublishedByPids($arrArchives);
     }
     // Parse the items
     if ($objSermons !== null) {
         $arrUrls = array();
         while ($objSermons->next()) {
             $jumpTo = $objSermons->getRelated('pid')->jumpTo;
             // No jumpTo page set (see #4784)
             if (!$jumpTo) {
                 continue;
             }
             // Get the jumpTo URL
             if (!isset($arrUrls[$jumpTo])) {
                 $objParent = \PageModel::findWithDetails($jumpTo);
                 // A jumpTo page is set but does no longer exist (see #5781)
                 if ($objParent === null) {
                     $arrUrls[$jumpTo] = false;
                 } else {
                     $arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/%s' : '/items/%s', $objParent->language);
                 }
             }
             // Skip the event if it requires a jumpTo URL but there is none
             if ($arrUrls[$jumpTo] === false && $objSermons->source == 'default') {
                 continue;
             }
             $strUrl = $arrUrls[$jumpTo];
             $objItem = new \FeedItem();
             $objItem->title = $objSermons->title;
             $objItem->link = $strLink . sprintf($strUrl, $objSermons->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objSermons->alias : $objSermons->id);
             $objItem->published = $objSermons->date;
             $objItem->author = $objSermons->speaker;
             // Prepare the description
             if ($arrFeed['format'] == 'podcast') {
                 $objItem->description = $this->replaceSermonInsertTags($arrFeed['podcastSubtitle'], $objSermons);
             }
             // Add the article image as enclosure
             if ($objSermons->addImage) {
                 $objFile = \FilesModel::findByUuid($objSermons->singleSRC);
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path);
                 }
             }
             // Add the Sermon Audio File
             if ($objSermons->audioSingleSRC) {
                 $objFile = \FilesModel::findByUuid($objSermons->audioSingleSRC);
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path);
                     //Prepare the duration if it's a podcast
                     if ($arrFeed['format'] == 'podcast') {
                         $this->import('getid3');
                         $getID3 = new \getID3();
                         $mp3FileInfo = $getID3->analyze(TL_ROOT . '/' . $objFile->path);
                         $objItem->duration = @$mp3FileInfo['playtime_string'];
                     }
                 }
             }
             $objFeed->addItem($objItem);
         }
     }
     // Create the file
     \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}()));
 }