Пример #1
0
 /**
  * Generate an XML files and save them to the root directory
  *
  * @param array $arrFeed
  */
 protected function generateFiles($arrFeed)
 {
     $arrArchives = deserialize($arrFeed['archives']);
     if (!is_array($arrArchives) || empty($arrArchives)) {
         return;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     // Get the items
     if ($arrFeed['maxItems'] > 0) {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']);
     } else {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives);
     }
     // Parse the items
     if ($objArticle !== null) {
         $arrUrls = array();
         while ($objArticle->next()) {
             /** @var \PageModel $objPage */
             $objPage = $objArticle->getRelated('pid');
             $jumpTo = $objPage->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] = $objParent->getFrontendUrl(\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/items/%s');
                 }
             }
             // Skip the event if it requires a jumpTo URL but there is none
             if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') {
                 continue;
             }
             $strUrl = $arrUrls[$jumpTo];
             $objItem = new \FeedItem();
             $objItem->title = $objArticle->headline;
             $objItem->link = $this->getLink($objArticle, $strUrl, $strLink);
             $objItem->published = $objArticle->date;
             $objItem->author = $objArticle->authorName;
             // Prepare the description
             if ($arrFeed['source'] == 'source_text') {
                 $strDescription = '';
                 $objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news');
                 if ($objElement !== null) {
                     // Overwrite the request (see #7756)
                     $strRequest = \Environment::get('request');
                     \Environment::set('request', $objItem->link);
                     while ($objElement->next()) {
                         $strDescription .= $this->getContentElement($objElement->current());
                     }
                     \Environment::set('request', $strRequest);
                 }
             } else {
                 $strDescription = $objArticle->teaser;
             }
             $strDescription = $this->replaceInsertTags($strDescription, false);
             $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
             // Add the article image as enclosure
             if ($objArticle->addImage) {
                 $objFile = \FilesModel::findByUuid($objArticle->singleSRC);
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path, $strLink);
                 }
             }
             // Enclosures
             if ($objArticle->addEnclosure) {
                 $arrEnclosure = deserialize($objArticle->enclosure, true);
                 if (is_array($arrEnclosure)) {
                     $objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
                     if ($objFile !== null) {
                         while ($objFile->next()) {
                             $objItem->addEnclosure($objFile->path, $strLink);
                         }
                     }
                 }
             }
             $objFeed->addItem($objItem);
         }
     }
     // Create the file
     \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
Пример #2
0
 /**
  * Generate an XML file and save it to the root directory
  * @param array
  */
 protected function generateFiles($arrArchive)
 {
     $time = time();
     $this->arrEvents = array();
     $strType = $arrArchive['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrArchive['feedBase'] != '' ? $arrArchive['feedBase'] : $this->Environment->base;
     $strFile = $arrArchive['feedName'];
     $objFeed = new Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrArchive['title'];
     $objFeed->description = $arrArchive['description'];
     $objFeed->language = $arrArchive['language'];
     $objFeed->published = $arrArchive['tstamp'];
     // Get upcoming events using endTime instead of startTime (see #3917)
     $objArticleStmt = $this->Database->prepare("SELECT *, (SELECT name FROM tl_user u WHERE u.id=e.author) AS authorName FROM tl_calendar_events e WHERE pid=? AND (endTime>={$time} OR (recurring=1 AND (recurrences=0 OR repeatEnd>={$time}))) AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time}) AND published=1 ORDER BY startTime");
     if ($arrArchive['maxItems'] > 0) {
         $objArticleStmt->limit($arrArchive['maxItems']);
     }
     $objArticle = $objArticleStmt->execute($arrArchive['id']);
     // Get the default URL
     $objParent = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")->limit(1)->execute($arrArchive['jumpTo']);
     if ($objParent->numRows < 1) {
         return;
     }
     $objParent = $this->getPageDetails($objParent->id);
     $strUrl = $strLink . $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/events/%s', $objParent->language);
     // Parse items
     while ($objArticle->next()) {
         $this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl, $strLink);
         // Recurring events
         if ($objArticle->recurring) {
             $count = 0;
             $arrRepeat = deserialize($objArticle->repeatEach);
             // Do not include more than 20 recurrences
             while ($count++ < 20) {
                 if ($objArticle->recurrences > 0 && $count >= $objArticle->recurrences) {
                     break;
                 }
                 $arg = $arrRepeat['value'];
                 $unit = $arrRepeat['unit'];
                 $strtotime = '+ ' . $arg . ' ' . $unit;
                 $objArticle->startTime = strtotime($strtotime, $objArticle->startTime);
                 $objArticle->endTime = strtotime($strtotime, $objArticle->endTime);
                 if ($objArticle->startTime >= $time) {
                     $this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl, $strLink);
                 }
             }
         }
     }
     $count = 0;
     ksort($this->arrEvents);
     // Add feed items
     foreach ($this->arrEvents as $days) {
         foreach ($days as $events) {
             foreach ($events as $event) {
                 if ($arrArchive['maxItems'] > 0 && $count++ >= $arrArchive['maxItems']) {
                     break 3;
                 }
                 $objItem = new FeedItem();
                 $objItem->title = $event['title'];
                 $objItem->link = $event['link'];
                 $objItem->published = $event['published'];
                 $objItem->start = $event['start'];
                 $objItem->end = $event['end'];
                 $objItem->author = $event['authorName'];
                 // Prepare the description
                 $strDescription = $arrArchive['source'] == 'source_text' ? $event['description'] : $event['teaser'];
                 $strDescription = $this->replaceInsertTags($strDescription);
                 $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
                 if (is_array($event['enclosure'])) {
                     foreach ($event['enclosure'] as $enclosure) {
                         $objItem->addEnclosure($enclosure);
                     }
                 }
                 $objFeed->addItem($objItem);
             }
         }
     }
     // Create file
     $objRss = new File($strFile . '.xml');
     $objRss->write($this->replaceInsertTags($objFeed->{$strType}()));
     $objRss->close();
 }
Пример #3
0
 /**
  * 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;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     $arrCategories = deserialize($arrFeed['categories']);
     // Filter by categories
     if (is_array($arrCategories) && !empty($arrCategories)) {
         $GLOBALS['NEWS_FILTER_CATEGORIES'] = true;
         $GLOBALS['NEWS_FILTER_DEFAULT'] = $arrCategories;
     } else {
         $GLOBALS['NEWS_FILTER_CATEGORIES'] = false;
     }
     // Get the items
     if ($arrFeed['maxItems'] > 0) {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']);
     } else {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives);
     }
     // Parse the items
     if ($objArticle !== null) {
         $arrUrls = array();
         while ($objArticle->next()) {
             $jumpTo = $objArticle->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 && $objArticle->source == 'default') {
                 continue;
             }
             // Get the categories
             if ($arrFeed['categories_show']) {
                 $arrCategories = array();
                 if (($objCategories = NewsCategoryModel::findPublishedByIds(deserialize($objArticle->categories, true))) !== null) {
                     $arrCategories = $objCategories->fetchEach('title');
                 }
             }
             $strUrl = $arrUrls[$jumpTo];
             $objItem = new \FeedItem();
             // Add the categories to the title
             if ($arrFeed['categories_show'] == 'title') {
                 $objItem->title = sprintf('[%s] %s', implode(', ', $arrCategories), $objArticle->headline);
             } else {
                 $objItem->title = $objArticle->headline;
             }
             $objItem->link = $this->getLink($objArticle, $strUrl, $strLink);
             $objItem->published = $objArticle->date;
             $objItem->author = $objArticle->authorName;
             // Prepare the description
             if ($arrFeed['source'] == 'source_text') {
                 $strDescription = '';
                 $objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news');
                 if ($objElement !== null) {
                     while ($objElement->next()) {
                         $strDescription .= $this->getContentElement($objElement->id);
                     }
                 }
             } else {
                 $strDescription = $objArticle->teaser;
             }
             // Add the categories to the description
             if ($arrFeed['categories_show'] == 'text_before' || $arrFeed['categories_show'] == 'text_after') {
                 $strCategories = '<p>' . $GLOBALS['TL_LANG']['MSC']['newsCategories'] . ' ' . implode(', ', $arrCategories) . '</p>';
                 if ($arrFeed['categories_show'] == 'text_before') {
                     $strDescription = $strCategories . $strDescription;
                 } else {
                     $strDescription .= $strCategories;
                 }
             }
             $strDescription = $this->replaceInsertTags($strDescription, false);
             $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
             // Add the article image as enclosure
             if ($objArticle->addImage) {
                 $objFile = \FilesModel::findByUuid($objArticle->singleSRC);
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path);
                 }
             }
             // Enclosures
             if ($objArticle->addEnclosure) {
                 $arrEnclosure = deserialize($objArticle->enclosure, true);
                 if (is_array($arrEnclosure)) {
                     $objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
                     if ($objFile !== null) {
                         while ($objFile->next()) {
                             $objItem->addEnclosure($objFile->path);
                         }
                     }
                 }
             }
             $objFeed->addItem($objItem);
         }
     }
     // Create the file
     \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
    $dateadded = mysql_result($result, $currentrecord, "dateadded");
    $filesize = mysql_result($result, $currentrecord, "filesize");
    // Parse apart the date into its component parts.
    list($date, $time) = explode(" ", $dateadded);
    list($year, $month, $day) = explode("-", $date);
    list($hour, $minute, $second) = explode(":", $time);
    $date_number = mktime($hour, $minute, $second, $month, $day, $year);
    // Add a channel item to the RSS feed.
    $item = new FeedItem();
    $item->title = $heading . " Building Permit Summary";
    $item->link = "http://www.city.charlottetown.pe.ca/" . $url;
    $item->description = "<a href=\"http://www.city.charlottetown.pe.ca/{$url}\">{$heading} Building Permit Summary</a>";
    $item->date = strftime("%Y-%m-%dT%H:%M:%S%z", $date_number);
    $item->source = "http://www.city.charlottetown.pe.ca/residents/application_fees.cfm";
    $item->guid = "http://www.city.charlottetown.pe.ca/" . $url;
    $item->addEnclosure("http://www.city.charlottetown.pe.ca/" . $url, $filesize, "text/pdf");
    $item->author = "peter@rukavina.net (Peter Rukavina)";
    $rss->addItem($item);
    $currentrecord++;
}
// Save the RSS feed.  This should be a web-accessible location.
$rss->saveFeed("RSS2.0", $rssfile, FALSE);
/**
 * Parse apart the part of the filename that contains the date, and make it standard.
 * There is inconsistency in the date format used in URLs.  Examples of formats used:
 * 
 * May 28 05
 * August 27 2005
 * Feb 4 2006
 *
 * The format is always Month - space - day - space - year, but the month can 
Пример #5
0
 /**
  * Generate an XML file and save it to the root directory
  *
  * @param array $arrFeed
  */
 protected function generateFiles($arrFeed)
 {
     $arrCalendars = deserialize($arrFeed['calendars']);
     if (!is_array($arrCalendars) || empty($arrCalendars)) {
         return;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     $arrUrls = array();
     $this->arrEvents = array();
     $time = time();
     // Get the upcoming events
     $objArticle = \CalendarEventsModel::findUpcomingByPids($arrCalendars, $arrFeed['maxItems']);
     // Parse the items
     if ($objArticle !== null) {
         while ($objArticle->next()) {
             $jumpTo = $objArticle->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(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/events/%s', $objParent->language);
                 }
             }
             // Skip the event if it requires a jumpTo URL but there is none
             if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') {
                 continue;
             }
             $strUrl = $arrUrls[$jumpTo];
             $this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl, $strLink);
             // Recurring events
             if ($objArticle->recurring) {
                 $arrRepeat = deserialize($objArticle->repeatEach);
                 if ($arrRepeat['value'] < 1) {
                     continue;
                 }
                 $count = 0;
                 $intStartTime = $objArticle->startTime;
                 $intEndTime = $objArticle->endTime;
                 $strtotime = '+ ' . $arrRepeat['value'] . ' ' . $arrRepeat['unit'];
                 // Do not include more than 20 recurrences
                 while ($count++ < 20) {
                     if ($objArticle->recurrences > 0 && $count >= $objArticle->recurrences) {
                         break;
                     }
                     $intStartTime = strtotime($strtotime, $intStartTime);
                     $intEndTime = strtotime($strtotime, $intEndTime);
                     if ($intStartTime >= $time) {
                         $this->addEvent($objArticle, $intStartTime, $intEndTime, $strUrl, $strLink);
                     }
                 }
             }
         }
     }
     $count = 0;
     ksort($this->arrEvents);
     // Add the feed items
     foreach ($this->arrEvents as $days) {
         foreach ($days as $events) {
             foreach ($events as $event) {
                 if ($arrFeed['maxItems'] > 0 && $count++ >= $arrFeed['maxItems']) {
                     break 3;
                 }
                 $objItem = new \FeedItem();
                 $objItem->title = $event['title'];
                 $objItem->link = $event['link'];
                 $objItem->published = $event['tstamp'];
                 $objItem->begin = $event['begin'];
                 $objItem->end = $event['end'];
                 $objItem->author = $event['authorName'];
                 // Prepare the description
                 if ($arrFeed['source'] == 'source_text') {
                     $strDescription = '';
                     $objElement = \ContentModel::findPublishedByPidAndTable($event['id'], 'tl_calendar_events');
                     if ($objElement !== null) {
                         // Overwrite the request (see #7756)
                         $strRequest = \Environment::get('request');
                         \Environment::set('request', $objItem->link);
                         while ($objElement->next()) {
                             $strDescription .= $this->getContentElement($objElement->current());
                         }
                         \Environment::set('request', $strRequest);
                     }
                 } else {
                     $strDescription = $event['teaser'];
                 }
                 $strDescription = $this->replaceInsertTags($strDescription, false);
                 $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
                 if (is_array($event['enclosure'])) {
                     foreach ($event['enclosure'] as $enclosure) {
                         $objItem->addEnclosure($enclosure);
                     }
                 }
                 $objFeed->addItem($objItem);
             }
         }
     }
     // Create the file
     \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
Пример #6
0
 /**
  * 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;
     }
     $strType = 'generateItunes';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new iTunesFeed($strFile);
     $objFeed->link = $strLink;
     $objFeed->podcastUrl = $strLink . 'share/' . $strFile . '.xml';
     $objFeed->title = $arrFeed['title'];
     $objFeed->subtitle = $arrFeed['subtitle'];
     $objFeed->description = $this->cleanHtml($arrFeed['description']);
     $objFeed->explicit = $arrFeed['explicit'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->author = $arrFeed['author'];
     $objFeed->owner = $arrFeed['owner'];
     $objFeed->email = $arrFeed['email'];
     $objFeed->category = $arrFeed['category'];
     $objFeed->published = $arrFeed['tstamp'];
     //Add Feed Image
     $objFile = \FilesModel::findByUuid($arrFeed['image']);
     if ($objFile !== null) {
         $objFeed->imageUrl = \Environment::get('base') . $objFile->path;
     }
     // Get the items
     if ($arrFeed['maxItems'] > 0) {
         $objPodcasts = \NewsPodcastsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']);
     } else {
         $objPodcasts = \NewsPodcastsModel::findPublishedByPids($arrArchives);
     }
     // Parse the items
     if ($objPodcasts !== null) {
         $arrUrls = array();
         while ($objPodcasts->next()) {
             $jumpTo = $objPodcasts->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 && $objPodcasts->source == 'default') {
                 continue;
             }
             $strUrl = $arrUrls[$jumpTo];
             $objItem = new \FeedItem();
             $objItem->headline = $this->cleanHtml($objPodcasts->headline);
             $objItem->subheadline = $this->cleanHtml($objPodcasts->subheadline !== null ? $objPodcasts->subheadline : $objPodcasts->description);
             $objItem->link = $strLink . sprintf($strUrl, $objPodcasts->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objPodcasts->alias : $objPodcasts->id);
             $objItem->published = $objPodcasts->date;
             $objAuthor = $objPodcasts->getRelated('author');
             $objItem->author = $objAuthor->name;
             $objItem->description = $this->cleanHtml($objPodcasts->teaser);
             $objItem->explicit = $objPodcasts->explicit;
             // Add the article image as enclosure
             $objItem->addEnclosure($objFeed->imageUrl);
             // Add the Audio File
             if ($objPodcasts->podcast) {
                 $objFile = \FilesModel::findByUuid($objPodcasts->podcast);
                 if ($objFile !== null) {
                     // Add statistics service
                     if (!empty($arrFeed['addStatistics'])) {
                         // If no trailing slash given, add one
                         $statisticsPrefix = rtrim($arrFeed['statisticsPrefix'], '/') . '/';
                         $podcastPath = $statisticsPrefix . \Environment::get('host') . '/' . preg_replace('(^https?://)', '', $objFile->path);
                     } else {
                         $podcastPath = \Environment::get('base') . \System::urlEncode($objFile->path);
                     }
                     $objItem->podcastUrl = $podcastPath;
                     // Prepare the duration / prefer linux tool mp3info
                     $mp3file = new GetMp3Duration(TL_ROOT . '/' . $objFile->path);
                     if ($this->checkMp3InfoInstalled()) {
                         $shell_command = 'mp3info -p "%S" ' . escapeshellarg(TL_ROOT . '/' . $objFile->path);
                         $duration = shell_exec($shell_command);
                     } else {
                         $duration = $mp3file->getDuration();
                     }
                     $objPodcastFile = new \File($objFile->path, true);
                     $objItem->length = $objPodcastFile->size;
                     $objItem->type = $objPodcastFile->mime;
                     $objItem->duration = $mp3file->formatTime($duration);
                 }
             }
             $objFeed->addItem($objItem);
         }
     }
     // Create the file
     \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
Пример #7
0
 /**
  * Generate an XML files and save them to the root directory
  * @param array
  */
 protected function generateFiles($arrArchive)
 {
     $time = time();
     $strType = $arrArchive['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrArchive['feedBase'] != '' ? $arrArchive['feedBase'] : $this->Environment->base;
     $strFile = $arrArchive['feedName'];
     $objFeed = new Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrArchive['title'];
     $objFeed->description = $arrArchive['description'];
     $objFeed->language = $arrArchive['language'];
     $objFeed->published = $arrArchive['tstamp'];
     // Get items
     $objArticleStmt = $this->Database->prepare("SELECT *, (SELECT name FROM tl_user u WHERE u.id=n.author) AS authorName\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM tl_news4ward_article n\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE pid=? AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time}) AND status='published'\n\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY start DESC");
     if ($arrArchive['maxItems'] > 0) {
         $objArticleStmt->limit($arrArchive['maxItems']);
     }
     $objArticle = $objArticleStmt->execute($arrArchive['id']);
     // Get the default URL
     $objParent = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")->limit(1)->execute($arrArchive['jumpTo']);
     if ($objParent->numRows < 1) {
         return;
     }
     $objParent = $this->getPageDetails($objParent->id);
     $strUrl = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/items/%s', $objParent->language);
     // Parse items
     while ($objArticle->next()) {
         $objItem = new FeedItem();
         $objItem->title = $objArticle->title;
         $objItem->link = $this->generateUrl($objArticle, $strUrl);
         $objItem->published = $objArticle->start;
         $objItem->author = $objArticle->authorName;
         // Prepare the description
         if ($arrArchive['source'] == 'source_text') {
             /* generate the content-elements */
             $objContentelements = $this->Database->prepare('SELECT id FROM tl_content WHERE pid=? AND do="news4ward" AND invisible="" ORDER BY sorting')->execute($objArticle->id);
             $strDescription = '';
             while ($objContentelements->next()) {
                 $strDescription .= $this->getContentElement($objContentelements->id);
             }
         } else {
             $strDescription = $objArticle->teaser;
         }
         $strDescription = $this->replaceInsertTags($strDescription);
         $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
         // Add the article image as enclosure
         if ($objArticle->addImage) {
             $objItem->addEnclosure($objArticle->singleSRC);
         }
         // Enclosure
         if ($objArticle->addEnclosure) {
             $arrEnclosure = deserialize($objArticle->enclosure, true);
             if (is_array($arrEnclosure)) {
                 foreach ($arrEnclosure as $strEnclosure) {
                     if (is_file(TL_ROOT . '/' . $strEnclosure)) {
                         $objItem->addEnclosure($strEnclosure);
                     }
                 }
             }
         }
         $objFeed->addItem($objItem);
     }
     // Create file
     $objRss = new File($strFile . '.xml');
     $objRss->write($this->replaceInsertTags($objFeed->{$strType}()));
     $objRss->close();
 }
Пример #8
0
 /**
  * Generate an XML files and save them to the root directory
  * @param array
  */
 protected function generateFiles($arrArchive)
 {
     $time = time();
     $strType = $arrArchive['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = strlen($arrArchive['feedBase']) ? $arrArchive['feedBase'] : $this->Environment->base;
     $strFile = $arrArchive['feedName'];
     $objFeed = new Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrArchive['title'];
     $objFeed->description = $arrArchive['description'];
     $objFeed->language = $arrArchive['language'];
     $objFeed->published = $arrArchive['tstamp'];
     // Get items
     $objArticleStmt = $this->Database->prepare("SELECT *, (SELECT name FROM tl_user u WHERE u.id=n.author) AS authorName FROM tl_news n WHERE pid=? AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time}) AND published=1 ORDER BY date DESC");
     if ($arrArchive['maxItems'] > 0) {
         $objArticleStmt->limit($arrArchive['maxItems']);
     }
     $objArticle = $objArticleStmt->execute($arrArchive['id']);
     // Get default URL
     $objParent = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")->limit(1)->execute($arrArchive['jumpTo']);
     $strUrl = $this->generateFrontendUrl($objParent->fetchAssoc(), '/items/%s');
     // Parse items
     while ($objArticle->next()) {
         $objItem = new FeedItem();
         $objItem->title = $objArticle->headline;
         $objItem->link = ($objArticle->source == 'external' ? '' : $strLink) . $this->getLink($objArticle, $strUrl);
         $objItem->published = $objArticle->date;
         $objItem->author = $objArticle->authorName;
         // Prepare the description
         $strDescription = $arrArchive['source'] == 'source_text' ? $objArticle->text : $objArticle->teaser;
         $strDescription = $this->replaceInsertTags($strDescription);
         $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
         // Add the article image as enclosure
         if ($objArticle->addImage) {
             $objItem->addEnclosure($objArticle->singleSRC);
         }
         // Enclosure
         if ($objArticle->addEnclosure) {
             $arrEnclosure = deserialize($objArticle->enclosure, true);
             if (is_array($arrEnclosure)) {
                 foreach ($arrEnclosure as $strEnclosure) {
                     if (is_file(TL_ROOT . '/' . $strEnclosure)) {
                         $objItem->addEnclosure($strEnclosure);
                     }
                 }
             }
         }
         $objFeed->addItem($objItem);
     }
     // Create file
     $objRss = new File($strFile . '.xml');
     $objRss->write($this->replaceInsertTags($objFeed->{$strType}()));
     $objRss->close();
 }
 /**
  * Generate the XML files and save them to the root directory
  * @param array
  */
 protected function generateFiles($arrFeed)
 {
     $arrConfigs = deserialize($arrFeed['configs']);
     if (!is_array($arrConfigs) || count($arrConfigs) < 1) {
         return;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     $objJumpTo = \PageModel::findByPk($arrFeed['jumpTo']);
     // find the source attributes
     $objDescriptionAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['descriptionField']);
     $objPublishedAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['publishedField']);
     $objTitleAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['titleField']);
     $objAuthorAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['authorField']);
     $objImageAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['imageField']);
     $arrFields = array('id', 'pid', 'tstamp', 'description' => $objDescriptionAttribute->alias, 'title' => $objTitleAttribute->alias, 'published' => $objPublishedAttribute->alias, 'author' => $objAuthorAttribute->alias, 'singleSRC' => $objImageAttribute->alias);
     foreach ($arrConfigs as $config_id) {
         $objCC = CustomCatalogFactory::findById($config_id);
         if ($objCC === null) {
             continue;
         }
         // set visibles to source attribute only
         $objCC->setVisibles(array_filter(array_values($arrFields)));
         if ($arrFeed['maxItems'] > 0) {
             $objCC->setLimit($arrFeed['maxItems']);
         }
         // fetch the entries
         $objEntries = $objCC->prepare();
         if ($objEntries->numRows < 1) {
             continue;
         }
         while ($objEntries->next()) {
             $objItem = new \FeedItem();
             $objItem->title = $objEntries->{$arrFields['title']};
             $objItem->link = $strLink . $objCC->generateDetailsUrl($objEntries, $objJumpTo);
             $objItem->published = $objEntries->{$arrFields['published']} ?: $objEntries->tstamp;
             $objItem->author = $objEntries->{$arrFields['author']} ?: '';
             $strDescription = $this->replaceInsertTags($objEntries->{$arrFields['description']}, false);
             $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
             if ($objEntries->{$arrFields['singleSRC']} && $objImageAttribute->published) {
                 $objFile = \FilesModel::findByUuid($objEntries->{$arrFields['singleSRC']});
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path);
                 }
             }
             // add feed item
             $objFeed->addItem($objItem);
         }
     }
     // create file
     \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
Пример #10
0
 /**
  * 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}()));
 }
Пример #11
0
 /**
  * Generate an XML file and save it to the root directory
  * @param array
  */
 protected function generateFiles($arrFeed)
 {
     $arrCalendars = deserialize($arrFeed['calendars']);
     if (!is_array($arrCalendars) || empty($arrCalendars)) {
         return;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     $arrUrls = array();
     $this->arrEvents = array();
     $time = time();
     // Get the upcoming events
     $objArticle = \CalendarEventsModel::findUpcomingByPids($arrCalendars, $arrFeed['maxItems']);
     // Parse the items
     if ($objArticle !== null) {
         while ($objArticle->next()) {
             $jumpTo = $objArticle->getRelated('pid')->jumpTo;
             // No jumpTo page set (see #4784)
             if (!$jumpTo) {
                 continue;
             }
             // Get the jumpTo URL
             if (!isset($arrUrls[$jumpTo])) {
                 $objParent = $this->getPageDetails($jumpTo);
                 $arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/events/%s', $objParent->language);
             }
             $strUrl = $arrUrls[$jumpTo];
             $this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl, $strLink);
             // Recurring events
             if ($objArticle->recurring) {
                 $count = 0;
                 $arrRepeat = deserialize($objArticle->repeatEach);
                 // Do not include more than 20 recurrences
                 while ($count++ < 20) {
                     if ($objArticle->recurrences > 0 && $count >= $objArticle->recurrences) {
                         break;
                     }
                     $arg = $arrRepeat['value'];
                     $unit = $arrRepeat['unit'];
                     $strtotime = '+ ' . $arg . ' ' . $unit;
                     $objArticle->startTime = strtotime($strtotime, $objArticle->startTime);
                     $objArticle->endTime = strtotime($strtotime, $objArticle->endTime);
                     if ($objArticle->startTime >= $time) {
                         $this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl, $strLink);
                     }
                 }
             }
         }
     }
     $count = 0;
     ksort($this->arrEvents);
     // Add the feed items
     foreach ($this->arrEvents as $days) {
         foreach ($days as $events) {
             foreach ($events as $event) {
                 if ($arrFeed['maxItems'] > 0 && $count++ >= $arrFeed['maxItems']) {
                     break 3;
                 }
                 $objItem = new \FeedItem();
                 $objItem->title = $event['title'];
                 $objItem->link = $event['link'];
                 $objItem->published = $event['published'];
                 $objItem->start = $event['start'];
                 $objItem->end = $event['end'];
                 $objItem->author = $event['authorName'];
                 // Prepare the description
                 if ($arrFeed['source'] == 'source_text') {
                     $strDescription = '';
                     $objElement = \ContentModel::findPublishedByPidAndTable($event['id'], 'tl_calendar_events');
                     if ($objElement !== null) {
                         while ($objElement->next()) {
                             $strDescription .= $this->getContentElement($objElement->id);
                         }
                     }
                 } else {
                     $strDescription = $event['teaser'];
                 }
                 $strDescription = $this->replaceInsertTags($strDescription);
                 $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
                 if (is_array($event['enclosure'])) {
                     foreach ($event['enclosure'] as $enclosure) {
                         $objItem->addEnclosure($enclosure);
                     }
                 }
                 $objFeed->addItem($objItem);
             }
         }
     }
     // Create file
     $objRss = new \File('share/' . $strFile . '.xml');
     $objRss->write($this->replaceInsertTags($objFeed->{$strType}()));
     $objRss->close();
 }
Пример #12
0
 /**
  * @param $arrFeed
  * @return null
  */
 protected function generateFiles($arrFeed)
 {
     $arrArchives = deserialize($arrFeed['wrappers']);
     if (!is_array($arrArchives) || empty($arrArchives)) {
         return null;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     if ($arrFeed['maxItems'] > 0) {
         $objArticle = $this->findPublishedByPids($arrArchives, $arrFeed['maxItems'], $arrFeed['fmodule'] . '_data');
     } else {
         $objArticle = $this->findPublishedByPids($arrArchives, 0, $arrFeed['fmodule'] . '_data');
     }
     if ($objArticle !== null) {
         $arrUrls = array();
         $strUrl = '';
         while ($objArticle->next()) {
             $pid = $objArticle->pid;
             $wrapperDB = $this->Database->prepare('SELECT * FROM ' . $arrFeed['fmodule'] . ' WHERE id = ?')->execute($pid)->row();
             if ($wrapperDB['addDetailPage'] == '1') {
                 $rootPage = $wrapperDB['rootPage'];
                 if (!isset($arrUrls[$rootPage])) {
                     $objParent = PageModel::findWithDetails($rootPage);
                     if ($objParent === null) {
                         $arrUrls[$rootPage] = false;
                     } else {
                         $arrUrls[$rootPage] = $this->generateFrontendUrl($objParent->row(), Config::get('useAutoItem') && !Config::get('disableAlias') ? '/%s' : '/items/%s', $objParent->language);
                     }
                 }
                 $strUrl = $arrUrls[$rootPage];
             }
             $authorName = '';
             if ($objArticle->author) {
                 $authorDB = $this->Database->prepare('SELECT * FROM tl_user WHERE id = ?')->execute($objArticle->author)->row();
                 $authorName = $authorDB['name'];
             }
             $objItem = new \FeedItem();
             $objItem->title = $objArticle->title;
             $objItem->link = HelperModel::getLink($objArticle, $strUrl, $strLink);
             $objItem->published = $objArticle->date ? $objArticle->date : $arrFeed['tstamp'];
             $objItem->author = $authorName;
             // Prepare the description
             if ($arrFeed['source'] == 'source_text') {
                 $strDescription = '';
                 $objElement = ContentModelExtend::findPublishedByPidAndTable($objArticle->id, $arrFeed['fmodule'] . '_data', array('fview' => 'detail'));
                 if ($objElement !== null) {
                     // Overwrite the request (see #7756)
                     $strRequest = Environment::get('request');
                     Environment::set('request', $objItem->link);
                     while ($objElement->next()) {
                         $strDescription .= $this->getContentElement($objElement->current());
                     }
                     Environment::set('request', $strRequest);
                 }
             } else {
                 $strDescription = '';
                 $objElement = ContentModelExtend::findPublishedByPidAndTable($objArticle->id, $arrFeed['fmodule'] . '_data', array('fview' => 'list'));
                 if ($objElement !== null) {
                     // Overwrite the request (see #7756)
                     $strRequest = Environment::get('request');
                     Environment::set('request', $objItem->link);
                     while ($objElement->next()) {
                         $strDescription .= $this->getContentElement($objElement->current());
                     }
                     Environment::set('request', $strRequest);
                 }
                 if (!$strDescription) {
                     $strDescription = $objArticle->description;
                 }
             }
             $strDescription = $this->replaceInsertTags($strDescription, false);
             $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
             // Add the article image as enclosure
             if ($objArticle->addImage) {
                 $objFile = \FilesModel::findByUuid($objArticle->singleSRC);
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path);
                 }
             }
             // Enclosures
             if ($objArticle->addEnclosure) {
                 $arrEnclosure = deserialize($objArticle->enclosure, true);
                 if (is_array($arrEnclosure)) {
                     $objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
                     if ($objFile !== null) {
                         while ($objFile->next()) {
                             $objItem->addEnclosure($objFile->path);
                         }
                     }
                 }
             }
             $objFeed->addItem($objItem);
         }
     }
     File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
Пример #13
0
 /**
  * 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;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     // Get the items
     if ($arrFeed['maxItems'] > 0) {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']);
     } else {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives);
     }
     // Parse the items
     if ($objArticle !== null) {
         $arrUrls = array();
         while ($objArticle->next()) {
             $jumpTo = $objArticle->getRelated('pid')->jumpTo;
             // No jumpTo page set (see #4784)
             if (!$jumpTo) {
                 continue;
             }
             // Get the jumpTo URL
             if (!isset($arrUrls[$jumpTo])) {
                 $objParent = $this->getPageDetails($jumpTo);
                 $arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/items/%s', $objParent->language);
             }
             $strUrl = $arrUrls[$jumpTo];
             $objItem = new \FeedItem();
             $objItem->title = $objArticle->headline;
             $objItem->link = $this->getLink($objArticle, $strUrl, $strLink);
             $objItem->published = $objArticle->date;
             $objItem->author = $objArticle->authorName;
             // Prepare the description
             if ($arrFeed['source'] == 'source_text') {
                 $strDescription = '';
                 $objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news');
                 if ($objElement !== null) {
                     while ($objElement->next()) {
                         $strDescription .= $this->getContentElement($objElement->id);
                     }
                 }
             } else {
                 $strDescription = $objArticle->teaser;
             }
             $strDescription = $this->replaceInsertTags($strDescription);
             $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
             // Add the article image as enclosure
             if ($objArticle->addImage) {
                 $objFile = \FilesModel::findByPk($objArticle->singleSRC);
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path);
                 }
             }
             // Enclosures
             if ($objArticle->addEnclosure) {
                 $arrEnclosure = deserialize($objArticle->enclosure, true);
                 if (is_array($arrEnclosure)) {
                     $objFile = \FilesModel::findMultipleByIds($arrEnclosure);
                     while ($objFile->next()) {
                         $objItem->addEnclosure($objFile->path);
                     }
                 }
             }
             $objFeed->addItem($objItem);
         }
     }
     // Create the file
     $objRss = new \File('share/' . $strFile . '.xml');
     $objRss->write($this->replaceInsertTags($objFeed->{$strType}()));
     $objRss->close();
 }
Пример #14
0
 /**
  * Generate an XML files and save them to the root directory
  * @param array
  */
 protected function generateFiles($arrArchive)
 {
     $this->import('Database');
     $time = time();
     $strType = $arrArchive['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrArchive['feedBase'] != '' ? $arrArchive['feedBase'] : $this->Environment->base;
     $strFile = $arrArchive['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrArchive['title'];
     $objFeed->description = $arrArchive['description'];
     $objFeed->language = $arrArchive['language'];
     $objFeed->published = $arrArchive['tstamp'];
     // Get items
     $objArticleStmt = $this->Database->prepare("SELECT *, (SELECT name FROM tl_user u WHERE u.id=p.author) AS authorName FROM tl_photoalbums2_album p WHERE pid=? AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time}) AND published=1 ORDER BY sorting ASC");
     if ($arrArchive['maxItems'] > 0) {
         $objArticleStmt->limit($arrArchive['maxItems']);
     }
     $objArticle = $objArticleStmt->execute($arrArchive['id']);
     // Get the default URL
     $objParent = \PageModel::findByPk($arrArchive['modulePage']);
     if ($objParent == null) {
         return;
     }
     $objParent = $this->getPageDetails($objParent->id);
     $strUrl = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/album/%s', $objParent->language);
     // Parse items
     if ($objArticle !== null) {
         while ($objArticle->next()) {
             // Deserialize image arrays
             $objArticle->images = deserialize($objArticle->images);
             $objArticle->imageSort = deserialize($objArticle->imageSort);
             // Sort images
             $objPa2ImageSorter = new \Pa2ImageSorter($objArticle->imageSortType, $objArticle->images, $objArticle->imageSort);
             $this->arrImages = $objPa2ImageSorter->getSortedUuids();
             $objItem = new \FeedItem();
             $objItem->title = $objArticle->title;
             $objItem->link = sprintf($strLink . $strUrl, $objArticle->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objArticle->alias : $objArticle->id);
             $objItem->published = $objArticle->startdate;
             $objItem->author = $objArticle->authorName;
             if (is_array($objArticle->arrImages) && count($objArticle->arrImages) > 0) {
                 foreach ($objArticle->arrImages as $image) {
                     if (is_file(TL_ROOT . '/' . $image)) {
                         $objItem->addEnclosure($image);
                     }
                 }
             }
             $objItem->description = $this->replaceInsertTags($objArticle->description);
             $objFeed->addItem($objItem);
         }
     }
     // Create file
     $objRss = new \file($strFile . '.xml');
     $objRss->write($this->replaceInsertTags($objFeed->{$strType}()));
     $objRss->close();
 }