protected function compile()
 {
     global $objPage;
     $arrElements = array();
     $objCte = \ContentModel::findPublishedByPidAndTable($objPage->id, 'tl_page');
     if ($objCte !== null) {
         $intCount = 0;
         $intLast = $objCte->count() - 1;
         while ($objCte->next()) {
             $arrCss = array();
             /** @var \ContentModel $objRow */
             $objRow = $objCte->current();
             // Add the "first" and "last" classes (see #2583)
             if ($intCount == 0 || $intCount == $intLast) {
                 if ($intCount == 0) {
                     $arrCss[] = 'first';
                 }
                 if ($intCount == $intLast) {
                     $arrCss[] = 'last';
                 }
             }
             $objRow->classes = $arrCss;
             $arrElements[] = $this->getContentElement($objRow, $this->strColumn);
             ++$intCount;
         }
     }
     $this->Template->elements = $arrElements;
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['compileArticle']) && is_array($GLOBALS['TL_HOOKS']['compileArticle'])) {
         foreach ($GLOBALS['TL_HOOKS']['compileArticle'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($this->Template, $this->arrData, $this);
         }
     }
 }
示例#2
0
 protected function compile()
 {
     if ($this->objConfig->header) {
         $this->Template->showHeader = true;
     }
     $id = $this->id;
     $this->Template->body = function () use($id) {
         $strText = '';
         $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_modal');
         if ($objElement !== null) {
             while ($objElement->next()) {
                 $strContent = $this->getContentElement($objElement->current());
                 // HOOK: add custom logic
                 if (isset($GLOBALS['TL_HOOKS']['getModalContentElement']) && is_array($GLOBALS['TL_HOOKS']['getModalContentElement'])) {
                     foreach ($GLOBALS['TL_HOOKS']['getModalContentElement'] as $callback) {
                         $strContent = static::importStatic($callback[0])->{$callback[1]}($objElement->current(), $strContent, $this->Template, $this->objModel, $this->objConfig, $this);
                     }
                 }
                 $strText .= $strContent;
             }
         }
         return $strText;
     };
     $this->Template->hasBody = \ContentModel::countPublishedByPidAndTable($this->id, 'tl_modal') > 0;
     if ($this->objConfig->footer && $this->addFooter) {
         $this->Template->showFooter = true;
     }
 }
示例#3
0
 public static function getPlaceholder($placeholder)
 {
     $object = new self();
     $strContent = "";
     $addStmt = "";
     $db = \Database::getInstance();
     $placeholderId = is_numeric($placeholder) ? $placeholder : 0;
     $placeholderAlias = is_string($placeholder) ? $placeholder : 0;
     if (!BE_USER_LOGGED_IN) {
         $time = time();
         $addStmt = " AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time}) AND published=1";
     }
     // TODO: make a Placeholder Model!!
     $objPlaceholder = $db->prepare("SELECT * FROM tl_dps_placeholder WHERE (id=? OR alias=?)" . $addStmt)->limit(1)->execute($placeholderId, $placeholderAlias);
     if ($objPlaceholder->numRows > 0) {
         $objPlaceholder = $objPlaceholder->first();
         $id = $objPlaceholder->id;
         $objContent = \ContentModel::findPublishedByPidAndTable($id, "tl_dps_placeholder");
         if ($objContent && $objContent->count() > 0) {
             while ($objContent->next()) {
                 $strContent .= $object->replaceInsertTags($object->getContentElement($objContent->id));
             }
         }
     }
     return $strContent;
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     // Get ID
     $strAlias = \Input::get('auto_item') ? \Input::get('auto_item') : \Input::get('store');
     // Find published store from ID
     if (($objStore = AnyStoresModel::findPublishedByIdOrAlias($strAlias)) !== null) {
         // load all details
         $objStore->loadDetails();
         // generate description
         $objDescription = \ContentModel::findPublishedByPidAndTable($objStore->id, $objStore->getTable());
         if ($objDescription !== null) {
             while ($objDescription->next()) {
                 $objStore->description .= \Controller::getContentElement($objDescription->current());
             }
         }
         // Get referer for back button
         $objStore->referer = $this->getReferer();
         // generate google map if template and geodata is set
         if ($this->anystores_mapTpl != '' && is_numeric($objStore->latitude) && is_numeric($objStore->longitude)) {
             $objMapTemplate = new \FrontendTemplate($this->anystores_mapTpl);
             $objMapTemplate->setData($objStore->row());
             $objStore->gMap = $objMapTemplate->parse();
         }
         // Template
         $objDetailTemplate = new \FrontendTemplate($this->anystores_detailTpl);
         $objDetailTemplate->setData($objStore->row());
         $this->Template->store = $objDetailTemplate->parse();
     } else {
         $this->_redirect404();
     }
 }
    /**
     * Add the type of input field
     * @param array
     * @return string
     */
    public function listNewsletterArticles($arrRow)
    {
        $strStats = '';
        $strContents = '';
        $objContents = \ContentModel::findPublishedByPidAndTable($arrRow['id'], 'tl_newsletter');
        if (!is_null($objContents)) {
            foreach ($objContents as $objContent) {
                $strContents .= $this->getContentElement($objContent->id) . '<hr>';
            }
        }
        $intTotal = $arrRow['recipients'] + $arrRow['rejected'];
        //		$intTracked = NewsletterContent\Models\NewsletterTrackingModel::countTrackedByPid($arrRow['id']);
        $objTracked = NewsletterContent\Models\NewsletterTrackingModel::findTrackedInteractionsByPid($arrRow['id']);
        $intTracked = !is_null($objTracked) ? $objTracked->count() : 0;
        $intPercent = @round($intTracked / $intTotal * 100);
        $strStats = sprintf($GLOBALS['TL_LANG']['tl_newsletter']['sentTo'], $arrRow['recipients'], strval($intTotal), strval($intTracked), strval($intPercent));
        return '
<div class="cte_type ' . ($arrRow['sent'] && $arrRow['date'] ? 'published' : 'unpublished') . '"><strong>' . $arrRow['subject'] . '</strong> - ' . ($arrRow['sent'] && $arrRow['date'] ? sprintf($GLOBALS['TL_LANG']['tl_newsletter']['sentOn'], Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $arrRow['date'])) . '<br>' . $strStats : $GLOBALS['TL_LANG']['tl_newsletter']['notSent']) . '</div>
<div class="limit_height' . (!$GLOBALS['TL_CONFIG']['doNotCollapse'] ? ' h128' : '') . '">
' . (!$arrRow['sendText'] && strlen($strContents) ? '
' . $strContents : '') . '
' . nl2br_html5($arrRow['text']) . '
</div>' . "\n";
        return '<div class="tl_content_left">' . $arrRow['subject'] . ' <span style="color:#b3b3b3;padding-left:3px">[' . $arrRow['senderName'] . ' &lt;' . $arrRow['sender'] . '&gt;]</span></div>';
    }
 /**
  * Generate the module
  */
 protected function compile()
 {
     global $objPage;
     $this->Template->content = '';
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     if (TL_MODE == 'FE' && BE_USER_LOGGED_IN) {
         $objNewsletter = \NewsletterModel::findByIdOrAlias(\Input::get('items'));
     } else {
         $objNewsletter = \NewsletterModel::findSentByParentAndIdOrAlias(\Input::get('items'), $this->nl_channels);
     }
     if ($objNewsletter === null) {
         // Do not index or cache the page
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         // Send a 404 header
         header('HTTP/1.1 404 Not Found');
         $this->Template->content = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('items')) . '</p>';
         return;
     }
     // Overwrite the page title (see #2853 and #4955)
     if ($objNewsletter->subject != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($objNewsletter->subject));
     }
     // Add enclosure
     if ($objNewsletter->addFile) {
         $this->addEnclosuresToTemplate($this->Template, $objNewsletter->row(), 'files');
     }
     if (!$objNewsletter->sendText) {
         $nl2br = $objPage->outputFormat == 'xhtml' ? 'nl2br_xhtml' : 'nl2br_html5';
         $strContent = '';
         $objContentElements = \ContentModel::findPublishedByPidAndTable($objNewsletter->id, 'tl_newsletter');
         if ($objContentElements !== null) {
             if (!defined('NEWSLETTER_CONTENT_PREVIEW')) {
                 define('NEWSLETTER_CONTENT_PREVIEW', true);
             }
             foreach ($objContentElements as $objContentElement) {
                 $strContent .= $this->getContentElement($objContentElement->id);
             }
         }
         // Parse simple tokens and insert tags
         $strContent = $this->replaceInsertTags($strContent);
         $strContent = \String::parseSimpleTokens($strContent, array());
         // Encode e-mail addresses
         $strContent = \String::encodeEmail($strContent);
         $this->Template->content = $strContent;
     } else {
         $strContent = str_ireplace(' align="center"', '', $objNewsletter->content);
     }
     // Convert relative URLs
     $strContent = $this->convertRelativeUrls($strContent);
     // Parse simple tokens and insert tags
     $strContent = $this->replaceInsertTags($strContent);
     $strContent = \String::parseSimpleTokens($strContent, array());
     // Encode e-mail addresses
     $strContent = \String::encodeEmail($strContent);
     $this->Template->content = $strContent;
     $this->Template->subject = $objNewsletter->subject;
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->Template->content = '';
     if (($objElement = \ContentModel::findPublishedByPidAndTable($this->User->id, 'tl_member')) !== null) {
         while ($objElement->next()) {
             $this->Template->content .= $this->getContentElement($objElement->id);
         }
     }
 }
示例#8
0
 /**
  * Add product items to the indexer
  * @param array
  * @param integer
  * @param boolean
  * @return array
  */
 public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false)
 {
     $arrRoot = array();
     if ($intRoot > 0) {
         $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page');
     }
     $time = time();
     $arrProcessed = array();
     // Get all catalog categories
     $objCatalog = \ProductCatalogModel::findByProtected('');
     // Walk through each archive
     if ($objCatalog !== null) {
         while ($objCatalog->next()) {
             // Skip catalog categories without target page
             if (!$objCatalog->jumpTo) {
                 continue;
             }
             // Skip catalog categories outside the root nodes
             if (!empty($arrRoot) && !in_array($objCatalog->jumpTo, $arrRoot)) {
                 continue;
             }
             // Get the URL of the jumpTo page
             if (!isset($arrProcessed[$objCatalog->jumpTo])) {
                 $objParent = \PageModel::findWithDetails($objCatalog->jumpTo);
                 // The target page does not exist
                 if ($objParent === null) {
                     continue;
                 }
                 // The target page has not been published (see #5520)
                 if (!$objParent->published || $objParent->start != '' && $objParent->start > $time || $objParent->stop != '' && $objParent->stop < $time) {
                     continue;
                 }
                 // The target page is exempt from the sitemap (see #6418)
                 if ($blnIsSitemap && $objParent->sitemap == 'map_never') {
                     continue;
                 }
                 // Set the domain (see #6421)
                 $domain = ($objParent->rootUseSSL ? 'https://' : 'http://') . ($objParent->domain ?: \Environment::get('host')) . TL_PATH . '/';
                 // Generate the URL
                 $arrProcessed[$objCatalog->jumpTo] = $domain . $this->generateFrontendUrl($objParent->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/items/%s', $objParent->language);
             }
             $strUrl = $arrProcessed[$objCatalog->jumpTo];
             // Get the items
             $objProduct = \ProductModel::findPublishedByPid($objCatalog->id);
             if ($objProduct !== null) {
                 while ($objProduct->next()) {
                     $objElement = \ContentModel::findPublishedByPidAndTable($objProduct->id, 'tl_product');
                     if ($objElement !== null) {
                         $arrPages[] = $this->getLink($objProduct, $strUrl);
                     }
                 }
             }
         }
     }
     return $arrPages;
 }
 protected function generateFields($objItem)
 {
     $arrItem = parent::generateFields($objItem);
     global $objPage;
     $arrItem['fields']['newsHeadline'] = $objItem->headline;
     $arrItem['fields']['subHeadline'] = $objItem->subheadline;
     $arrItem['fields']['hasSubHeadline'] = $objItem->subheadline ? true : false;
     $arrItem['fields']['linkHeadline'] = ModuleNews::generateLink($this, $objItem->headline, $objItem, false);
     $arrItem['fields']['more'] = ModuleNews::generateLink($this, $GLOBALS['TL_LANG']['MSC']['more'], $objItem, false, true);
     $arrItem['fields']['link'] = ModuleNews::generateNewsUrl($this, $objItem, false);
     $arrItem['fields']['text'] = '';
     // Clean the RTE output
     if ($objItem->teaser != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $arrItem['fields']['teaser'] = \StringUtil::toXhtml($objItem->teaser);
         } else {
             $arrItem['fields']['teaser'] = \StringUtil::toHtml5($objItem->teaser);
         }
         $arrItem['fields']['teaser'] = \StringUtil::encodeEmail($arrItem['fields']['teaser']);
     }
     // Display the "read more" button for external/article links
     if ($objItem->source != 'default') {
         $arrItem['fields']['text'] = true;
     } else {
         $objElement = \ContentModel::findPublishedByPidAndTable($objItem->id, 'tl_news');
         if ($objElement !== null) {
             while ($objElement->next()) {
                 $arrItem['fields']['text'] .= $this->getContentElement($objElement->current());
             }
         }
     }
     $arrMeta = ModuleNews::getMetaFields($this, $objItem);
     // Add the meta information
     $arrItem['fields']['date'] = $arrMeta['date'];
     $arrItem['fields']['hasMetaFields'] = !empty($arrMeta);
     $arrItem['fields']['numberOfComments'] = $arrMeta['ccount'];
     $arrItem['fields']['commentCount'] = $arrMeta['comments'];
     $arrItem['fields']['timestamp'] = $objItem->date;
     $arrItem['fields']['author'] = $arrMeta['author'];
     $arrItem['fields']['datetime'] = date('Y-m-d\\TH:i:sP', $objItem->date);
     $arrItem['fields']['addImage'] = false;
     // Add an image
     $this->addImage($objItem, 'singleSRC', $arrItem);
     // enclosures are added in runBeforeTemplateParsing
     return $arrItem;
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     // get content of article
     $objElements = \ContentModel::findPublishedByPidAndTable($this->dk_mmenuArticle, 'tl_article');
     if ($objElements !== null) {
         while ($objElements->next()) {
             $arrElements[] = $this->getContentElement($objElements->id);
         }
     }
     $this->Template->elements = $arrElements;
     // --- create FE template for javascript caller
     $objTemplateJs = new \FrontendTemplate($this->strTemplateJs);
     $objTemplateJs->id = $this->id;
     $objTemplateJs->cssIDonly = $this->cssID[0];
     $objMmenu = new Mmenu();
     $objMmenu->createTemplateData($this->Template, $objTemplateJs);
 }
 public function parseMember($objMember)
 {
     global $objPage;
     $objT = new \FrontendTemplate($this->mlTemplate);
     $objT->setData($objMember->row());
     $arrSkipFields = deserialize($this->mlFields, true);
     if ($this->mlSkipFields) {
         $this->dropFieldsFromTemplate($objT, $arrSkipFields);
     }
     $strUrl = $this->generateMemberUrl($objMember);
     $objT->hasContent = false;
     $objElement = \ContentModel::findPublishedByPidAndTable($objMember->id, 'tl_member');
     if ($objElement !== null) {
         $objT->hasContent = true;
         if ($this->mlLoadContent) {
             while ($objElement->next()) {
                 $objT->text .= $this->getContentElement($objElement->current());
             }
         }
     }
     $objT->addImage = false;
     if (!$this->mlDisableImages) {
         $this->addMemberImageToTemplate($objT, $objMember);
     }
     $objT->titleCombined = $this->getCombinedTitle($objMember, $arrSkipFields);
     $arrLocation = array_filter(array($objMember->postal, $objMember->city));
     $objT->locationCombined = empty($arrLocation) ? '' : implode(' ', $arrLocation);
     $objT->websiteLink = $objMember->website;
     $objT->websiteTitle = $GLOBALS['TL_LANG']['MSC']['memberlist']['websiteTitle'];
     // Add http:// to the website
     if ($objMember->website != '' && !preg_match('@^(https?://|ftp://|mailto:|#)@i', $objMember->website)) {
         $objT->websiteLink = 'http://' . $objMember->website;
     }
     if ($this->mlSource == 'external') {
         // Encode e-mail addresses
         if (substr($this->mlUrl, 0, 7) == 'mailto:') {
             $strUrl = \String::encodeEmail($this->mlUrl);
         } else {
             $strUrl = ampersand($this->mlUrl);
         }
     }
     $objT->link = $strUrl;
     $objT->linkTarget = $this->mlTarget ? $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"' : '';
     $objT->linkTitle = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['openMember'], $objT->titleCombined));
     return $objT->parse();
 }
 /**
  * Generate the content element
  */
 protected function compile()
 {
     $this->Template->image = \FilesModel::findByUuid($this->singleSRC);
     // for navigation: get list of content elements
     $nlContent = \ContentModel::findPublishedByPidAndTable($this->pid, "tl_newsletter");
     $content_items = array();
     $first = true;
     if ($nlContent) {
         foreach ($nlContent as $element) {
             if ($element->id != $this->id) {
                 if ($element->hoja_nl_headerlink_text) {
                     $content_items[] = array("id" => $element->id, "linktext" => $element->hoja_nl_headerlink_text);
                 }
             }
         }
     }
     $this->Template->nav_items = $content_items;
 }
 protected function compile()
 {
     parent::compile();
     $objNewsletter = \NewsletterModel::findSentByParentAndIdOrAlias(\Input::get('items'), $this->nl_channels);
     error_log("check");
     error_log($this->id);
     $html = '';
     $objContentElements = \ContentModel::findPublishedByPidAndTable($objNewsletter->id, 'tl_newsletter');
     error_log($objContentElements);
     if ($objContentElements !== null) {
         while ($objContentElements->next()) {
             $html .= $this->getContentElement($objContentElements->id);
         }
     }
     // Replace insert tags
     $html = $this->replaceInsertTags($html);
     $this->Template->htmlContent = $html;
 }
    /**
     * Add the type of input field
     * @param array
     * @return string
     */
    public function listNewsletterArticles($arrRow)
    {
        $strStats = '';
        $strContents = '';
        $objContents = \ContentModel::findPublishedByPidAndTable($arrRow['id'], 'tl_newsletter');
        if (!is_null($objContents)) {
            foreach ($objContents as $objContent) {
                $strContents .= $this->getContentElement($objContent->id) . '<hr>';
            }
        }
        $strStats = sprintf($GLOBALS['TL_LANG']['tl_newsletter']['hoja_status_string'], $arrRow['hoja_recipients'], $arrRow['hoja_rejected']);
        return '
<div class="cte_type ' . ($arrRow['sent'] && $arrRow['date'] ? 'published' : 'unpublished') . '"><strong>' . $arrRow['subject'] . '</strong> - ' . ($arrRow['sent'] && $arrRow['date'] ? sprintf($GLOBALS['TL_LANG']['tl_newsletter']['sentOn'], Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $arrRow['date'])) . '<br>' . $strStats : $GLOBALS['TL_LANG']['tl_newsletter']['notSent']) . '</div>
<div class="limit_height' . (!$GLOBALS['TL_CONFIG']['doNotCollapse'] ? ' h128' : '') . '">
' . (!$arrRow['sendText'] && strlen($strContents) ? '
' . $strContents : '') . '
' . nl2br_html5($arrRow['text']) . '
</div>' . "\n";
    }
 /**
  * Generate the content element
  */
 protected function compile()
 {
     $arrContent = array();
     $objBlock = BlockModuleModel::findByPk($this->block);
     if ($objBlock === null) {
         return;
     }
     $objElement = \ContentModel::findPublishedByPidAndTable($this->block, 'tl_block_module');
     if ($objElement !== null) {
         while ($objElement->next()) {
             $arrContent[] = \Controller::getContentElement($objElement->current());
         }
     }
     $strReturn = implode('', $arrContent);
     if ($objBlock->addWrapper) {
         $strReturn = ModuleBlock::createBlockWrapper($objBlock, $strReturn);
     }
     $this->Template->content = $strReturn;
 }
 protected function generateFields($objItem)
 {
     $arrItem = parent::generateFields($objItem);
     if (in_array('member_content_archives', \ModuleLoader::getActive())) {
         $arrFilterTags = deserialize($this->memberContentArchiveTags, true);
         $arrItem['fields']['memberContent'] = '';
         if (($objMemberContentArchives = \HeimrichHannot\MemberContentArchives\MemberContentArchiveModel::findBy(array('mid=?', 'published=?'), array($objItem->memberId ?: $objItem->id, true))) !== null) {
             while ($objMemberContentArchives->next()) {
                 if (in_array($objMemberContentArchives->tag, $arrFilterTags)) {
                     $arrItem['fields']['memberContentId'] = $objMemberContentArchives->id;
                     $objElement = \ContentModel::findPublishedByPidAndTable($objMemberContentArchives->id, 'tl_member_content_archive');
                     if ($objElement !== null) {
                         while ($objElement->next()) {
                             $arrItem['fields']['memberContent'] .= \Controller::getContentElement($objElement->current());
                         }
                     }
                 }
             }
             if ($objMemberContentArchives->tag == $this->memberContentArchiveTeaserTag) {
                 $arrItem['fields']['memberContentTitle'] = $objMemberContentArchives->title;
                 $arrItem['fields']['memberContentTeaser'] = $objMemberContentArchives->teaser;
             }
             // override member fields
             $arrOverridableMemberFields = deserialize(\Config::get('overridableMemberFields'));
             if (!empty($arrOverridableMemberFields)) {
                 foreach ($arrOverridableMemberFields as $strField) {
                     $strFieldOverride = 'member' . ucfirst($strField);
                     if ($objMemberContentArchives->{$strFieldOverride}) {
                         if (\Validator::isUuid($objMemberContentArchives->{$strFieldOverride})) {
                             $objMemberContentArchives->{$strFieldOverride} = Files::getPathFromUuid($objMemberContentArchives->{$strFieldOverride});
                         }
                         $arrItem['fields'][$strField] = $objMemberContentArchives->{$strFieldOverride};
                     }
                 }
             }
         }
     }
     return $arrItem;
 }
 protected function parseItem($objItem, $strClass = '', $intCount = 0)
 {
     if (in_array('member_content_archives', \ModuleLoader::getActive())) {
         $arrFilterTags = deserialize($this->memberContentArchiveTags, true);
         $objItem->memberContent = '';
         if (($objMemberContentArchives = \HeimrichHannot\MemberContentArchives\MemberContentArchiveModel::findBy('mid', $objItem->memberId ?: $objItem->id)) !== null) {
             while ($objMemberContentArchives->next()) {
                 if (in_array($objMemberContentArchives->tag, $arrFilterTags)) {
                     $objItem->memberContentId = $objMemberContentArchives->id;
                     $objElement = \ContentModel::findPublishedByPidAndTable($objMemberContentArchives->id, 'tl_member_content_archive');
                     if ($objElement !== null) {
                         while ($objElement->next()) {
                             $objItem->memberContent .= \Controller::getContentElement($objElement->current());
                         }
                     }
                 }
             }
             if ($objMemberContentArchives->tag == $this->memberContentArchiveTeaserTag) {
                 $objItem->memberContentTitle = $objMemberContentArchives->title;
                 $objItem->memberContentTeaser = $objMemberContentArchives->teaser;
             }
             // override member fields
             $arrOverridableMemberFields = deserialize(\Config::get('overridableMemberFields'));
             if (!empty($arrOverridableMemberFields)) {
                 foreach ($arrOverridableMemberFields as $strField) {
                     $strFieldOverride = 'member' . ucfirst($strField);
                     if ($objMemberContentArchives->{$strFieldOverride}) {
                         if (\Validator::isUuid($objMemberContentArchives->{$strFieldOverride})) {
                             $objMemberContentArchives->{$strFieldOverride} = Files::getPathFromUuid($objMemberContentArchives->{$strFieldOverride});
                         }
                         $objItem->{$strField} = $objMemberContentArchives->{$strFieldOverride};
                     }
                 }
             }
         }
     }
     return parent::parseItem($objItem, $strClass, $intCount);
 }
示例#18
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));
 }
示例#19
0
 /**
  * Parse an item and return it as string
  *
  * @param \NewsModel $objArticle
  * @param boolean    $blnAddArchive
  * @param string     $strClass
  * @param integer    $intCount
  *
  * @return string
  */
 protected function parseArticle($objArticle, $blnAddArchive = false, $strClass = '', $intCount = 0)
 {
     /** @var \PageModel $objPage */
     global $objPage;
     /** @var \FrontendTemplate|object $objTemplate */
     $objTemplate = new \FrontendTemplate($this->news_template);
     $objTemplate->setData($objArticle->row());
     $objTemplate->class = ($objArticle->cssClass != '' ? ' ' . $objArticle->cssClass : '') . $strClass;
     $objTemplate->newsHeadline = $objArticle->headline;
     $objTemplate->subHeadline = $objArticle->subheadline;
     $objTemplate->hasSubHeadline = $objArticle->subheadline ? true : false;
     $objTemplate->linkHeadline = $this->generateLink($objArticle->headline, $objArticle, $blnAddArchive);
     $objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objArticle, $blnAddArchive, true);
     $objTemplate->link = $this->generateNewsUrl($objArticle, $blnAddArchive);
     $objTemplate->archive = $objArticle->getRelated('pid');
     $objTemplate->count = $intCount;
     // see #5708
     $objTemplate->text = '';
     // Clean the RTE output
     if ($objArticle->teaser != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $objTemplate->teaser = \StringUtil::toXhtml($objArticle->teaser);
         } else {
             $objTemplate->teaser = \StringUtil::toHtml5($objArticle->teaser);
         }
         $objTemplate->teaser = \StringUtil::encodeEmail($objTemplate->teaser);
     }
     // Display the "read more" button for external/article links
     if ($objArticle->source != 'default') {
         $objTemplate->text = true;
     } else {
         $id = $objArticle->id;
         $objTemplate->text = function () use($id) {
             $strText = '';
             $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_news');
             if ($objElement !== null) {
                 while ($objElement->next()) {
                     $strText .= $this->getContentElement($objElement->current());
                 }
             }
             return $strText;
         };
     }
     $arrMeta = $this->getMetaFields($objArticle);
     // Add the meta information
     $objTemplate->date = $arrMeta['date'];
     $objTemplate->hasMetaFields = !empty($arrMeta);
     $objTemplate->numberOfComments = $arrMeta['ccount'];
     $objTemplate->commentCount = $arrMeta['comments'];
     $objTemplate->timestamp = $objArticle->date;
     $objTemplate->author = $arrMeta['author'];
     $objTemplate->datetime = date('Y-m-d\\TH:i:sP', $objArticle->date);
     $objTemplate->addImage = false;
     // Add an image
     if ($objArticle->addImage && $objArticle->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objArticle->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objArticle->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)
             $arrArticle = $objArticle->row();
             // Override the default image size
             if ($this->imgSize != '') {
                 $size = deserialize($this->imgSize);
                 if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
                     $arrArticle['size'] = $this->imgSize;
                 }
             }
             $arrArticle['singleSRC'] = $objModel->path;
             $this->addImageToTemplate($objTemplate, $arrArticle);
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures
     if ($objArticle->addEnclosure) {
         $this->addEnclosuresToTemplate($objTemplate, $objArticle->row());
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['parseArticles']) && is_array($GLOBALS['TL_HOOKS']['parseArticles'])) {
         foreach ($GLOBALS['TL_HOOKS']['parseArticles'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objTemplate, $objArticle->row(), $this);
         }
     }
     return $objTemplate->parse();
 }
 /**
  * Parse an item and return it as string
  * @param object
  * @param boolean
  * @param string
  * @param integer
  * @return string
  */
 protected function parseArticle($objArticle, $blnAddArchive = false, $strClass = '', $intCount = 0)
 {
     global $objPage;
     $arrCategories = deserialize($objArticle->categories, true);
     $objTemplate = new \FrontendTemplate($this->news_template);
     $objTemplate->setData($objArticle->row());
     $objTemplate->class = ($objArticle->cssClass != '' ? ' ' . $objArticle->cssClass : '') . $strClass;
     $objTemplate->newsHeadline = $objArticle->headline;
     $objTemplate->subHeadline = $objArticle->subheadline;
     $objTemplate->hasSubHeadline = $objArticle->subheadline ? true : false;
     $objTemplate->linkHeadline = $this->generateLink($objArticle->headline, $objArticle, $blnAddArchive);
     $objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objArticle, $blnAddArchive, true);
     $objTemplate->link = $this->generateNewsUrl($objArticle, $blnAddArchive);
     $objTemplate->linkTarget = $objArticle->target ? $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"' : '';
     $objTemplate->linkTitle = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->headline), true);
     $objTemplate->count = $intCount;
     // see #5708
     $objTemplate->text = '';
     $objTemplate->hasText = false;
     $objTemplate->hasTeaser = false;
     // print pdf
     if ($this->news_pdfJumpTo) {
         $objTemplate->showPdfButton = true;
         $pdfPage = \PageModel::findByPk($this->news_pdfJumpTo);
         $pdfArticle = \ArticleModel::findPublishedByPidAndColumn($this->news_pdfJumpTo, 'main');
         $options = deserialize($pdfArticle->printable);
         if (in_array('pdf', $options)) {
             $objTemplate->pdfArticleId = $pdfArticle->id;
         }
         $strUrl = \Controller::generateFrontendUrl($pdfPage->row());
         $objTemplate->pdfJumpTo = $strUrl;
     }
     $objArchive = \NewsArchiveModel::findByPk($objArticle->pid);
     $objTemplate->archive = $objArchive;
     $objTemplate->archive->title = $objTemplate->archive->displayTitle ? $objTemplate->archive->displayTitle : $objTemplate->archive->title;
     $objTemplate->archive->class = ModuleNewsListPlus::getArchiveClassFromTitle($objTemplate->archive->title, true);
     $objTemplate->archiveTitle = $objTemplate->archive->title;
     $arrCategoryTitles = array();
     if ($this->news_archiveTitleAppendCategories && !empty($arrCategories)) {
         $arrTitleCategories = array_intersect($arrCategories, deserialize($this->news_archiveTitleCategories, true));
         if (!empty($arrTitleCategories)) {
             $objTitleCategories = NewsCategoryModel::findPublishedByIds($arrTitleCategories);
             if ($objTitleCategories !== null) {
                 while ($objTitleCategories->next()) {
                     if ($objTitleCategories->frontendTitle) {
                         $arrCategoryTitles[$objTitleCategories->id] = $objTitleCategories->frontendTitle;
                         continue;
                     }
                     $arrCategoryTitles[$objTitleCategories->id] = $objTitleCategories->title;
                 }
                 $objTemplate->archiveTitle .= ' : ' . implode(' : ', $arrCategoryTitles);
             }
         }
     }
     // add tags
     $objTemplate->showTags = $this->news_showtags;
     if ($this->news_showtags && $this->news_template_modal && $this->Environment->isAjaxRequest) {
         $helper = new NewsPlusTagHelper();
         $tagsandlist = $helper->getTagsAndTaglistForIdAndTable($objArticle->id, 'tl_news', $this->tag_jumpTo);
         $tags = $tagsandlist['tags'];
         $taglist = $tagsandlist['taglist'];
         $objTemplate->showTagClass = $this->tag_named_class;
         $objTemplate->tags = $tags;
         $objTemplate->taglist = $taglist;
         $objTemplate->news = 'IN';
     }
     // nav
     $strUrl = '';
     $objArchive = \NewsArchiveModel::findByPk($objArticle->pid);
     if ($objArchive !== null && $objArchive->jumpTo && ($objTarget = $objArchive->getRelated('jumpTo')) !== null) {
         $strUrl = $this->generateFrontendUrl($objTarget->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/news/%s');
     }
     $objTemplate->nav = static::generateArrowNavigation($objArticle, $strUrl, $this->news_readerModule);
     // Clean the RTE output
     if ($objArticle->teaser != '') {
         $objTemplate->hasTeaser = true;
         if ($objPage->outputFormat == 'xhtml') {
             $objTemplate->teaser = \String::toXhtml($objArticle->teaser);
         } else {
             $objTemplate->teaser = \String::toHtml5($objArticle->teaser);
         }
         $objTemplate->teaser = \String::encodeEmail($objTemplate->teaser);
     }
     // Display the "read more" button for external/article links
     if ($objArticle->source != 'default') {
         $objTemplate->text = true;
         $objTemplate->hasText = true;
     } else {
         $id = $objArticle->id;
         $objTemplate->text = function () use($id) {
             $strText = '';
             $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_news');
             if ($objElement !== null) {
                 while ($objElement->next()) {
                     $strText .= $this->getContentElement($objElement->current());
                 }
             }
             return $strText;
         };
         $objTemplate->hasText = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news') !== null;
     }
     $arrMeta = $this->getMetaFields($objArticle);
     // Add the meta information
     $objTemplate->date = $arrMeta['date'];
     $objTemplate->hasMetaFields = !empty($arrMeta);
     $objTemplate->numberOfComments = $arrMeta['ccount'];
     $objTemplate->commentCount = $arrMeta['comments'];
     $objTemplate->timestamp = $objArticle->date;
     $objTemplate->author = $arrMeta['author'];
     $objTemplate->datetime = date('Y-m-d\\TH:i:sP', $objArticle->date);
     $objTemplate->addImage = false;
     // Add an image
     if ($objArticle->addImage && $objArticle->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objArticle->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objArticle->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)
             $arrArticle = $objArticle->row();
             // Override the default image size
             if ($this->imgSize != '') {
                 $size = deserialize($this->imgSize);
                 if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
                     $arrArticle['size'] = $this->imgSize;
                 }
             }
             $arrArticle['singleSRC'] = $objModel->path;
             $this->addImageToTemplate($objTemplate, $arrArticle);
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures
     if ($objArticle->addEnclosure) {
         $this->addEnclosuresToTemplate($objTemplate, $objArticle->row());
     }
     if (in_array('share', \ModuleLoader::getActive())) {
         $objArticle->title = $objArticle->headline;
         $objShare = new \HeimrichHannot\Share\Share($this->objModel, $objArticle);
         $objTemplate->share = $objShare->generate();
     }
     // Modal
     if ($this->news_showInModal && $objArticle->source == 'default' && $this->news_readerModule) {
         $objTemplate->modal = true;
         $objTemplate->modalTarget = '#' . NewsPlusHelper::getCSSModalID($this->news_readerModule);
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['parseArticles']) && is_array($GLOBALS['TL_HOOKS']['parseArticles'])) {
         foreach ($GLOBALS['TL_HOOKS']['parseArticles'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objTemplate, $objArticle->row(), $this);
         }
     }
     return $objTemplate->parse();
 }
示例#21
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $id = 'article-' . $this->id;
     // Generate the CSS ID if it is not set
     if (empty($this->cssID[0])) {
         $this->cssID = array($id, $this->cssID[1]);
     }
     $this->Template->column = $this->inColumn;
     $this->Template->noMarkup = $this->blnNoMarkup;
     // Add the modification date
     $this->Template->timestamp = $this->tstamp;
     $this->Template->date = \Date::parse($objPage->datimFormat, $this->tstamp);
     // Clean the RTE output
     $this->teaser = \StringUtil::toHtml5($this->teaser);
     // Show the teaser only
     if ($this->multiMode && $this->showTeaser) {
         $this->cssID = array($id, '');
         $arrCss = \StringUtil::deserialize($this->teaserCssID);
         // Override the CSS ID and class
         if (is_array($arrCss) && count($arrCss) == 2) {
             if ($arrCss[0] == '') {
                 $arrCss[0] = $id;
             }
             $this->cssID = $arrCss;
         }
         $article = $this->alias ?: $this->id;
         $href = '/articles/' . ($this->inColumn != 'main' ? $this->inColumn . ':' : '') . $article;
         $this->Template->teaserOnly = true;
         $this->Template->headline = $this->headline;
         $this->Template->href = $objPage->getFrontendUrl($href);
         $this->Template->teaser = $this->teaser;
         $this->Template->readMore = \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $this->headline), true);
         $this->Template->more = $GLOBALS['TL_LANG']['MSC']['more'];
         return;
     }
     // Get section and article alias
     list($strSection, $strArticle) = explode(':', \Input::get('articles'));
     if ($strArticle === null) {
         $strArticle = $strSection;
     }
     // Overwrite the page title (see #2853 and #4955)
     if (!$this->blnNoMarkup && $strArticle != '' && ($strArticle == $this->id || $strArticle == $this->alias) && $this->title != '') {
         $objPage->pageTitle = strip_tags(\StringUtil::stripInsertTags($this->title));
         if ($this->teaser != '') {
             $objPage->description = $this->prepareMetaDescription($this->teaser);
         }
     }
     $this->Template->printable = false;
     $this->Template->backlink = false;
     // Back link
     if (!$this->multiMode && $strArticle != '' && ($strArticle == $this->id || $strArticle == $this->alias)) {
         $this->Template->backlink = 'javascript:history.go(-1)';
         // see #6955
         $this->Template->back = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goBack']);
     }
     $arrElements = array();
     $objCte = \ContentModel::findPublishedByPidAndTable($this->id, 'tl_article');
     if ($objCte !== null) {
         $intCount = 0;
         $intLast = $objCte->count() - 1;
         while ($objCte->next()) {
             $arrCss = array();
             /** @var ContentModel $objRow */
             $objRow = $objCte->current();
             // Add the "first" and "last" classes (see #2583)
             if ($intCount == 0 || $intCount == $intLast) {
                 if ($intCount == 0) {
                     $arrCss[] = 'first';
                 }
                 if ($intCount == $intLast) {
                     $arrCss[] = 'last';
                 }
             }
             $objRow->classes = $arrCss;
             $arrElements[] = $this->getContentElement($objRow, $this->strColumn);
             ++$intCount;
         }
     }
     $this->Template->teaser = $this->teaser;
     $this->Template->elements = $arrElements;
     if ($this->keywords != '') {
         $GLOBALS['TL_KEYWORDS'] .= ($GLOBALS['TL_KEYWORDS'] != '' ? ', ' : '') . $this->keywords;
     }
     // Deprecated since Contao 4.0, to be removed in Contao 5.0
     if ($this->printable == 1) {
         @trigger_error('Setting tl_article.printable to "1" has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
         $this->Template->printable = true;
         $this->Template->pdfButton = true;
     } elseif ($this->printable != '') {
         $options = \StringUtil::deserialize($this->printable);
         if (!empty($options) && is_array($options)) {
             $this->Template->printable = true;
             $this->Template->printButton = in_array('print', $options);
             $this->Template->pdfButton = in_array('pdf', $options);
             $this->Template->facebookButton = in_array('facebook', $options);
             $this->Template->twitterButton = in_array('twitter', $options);
             $this->Template->gplusButton = in_array('gplus', $options);
         }
     }
     // Add syndication variables
     if ($this->Template->printable) {
         $request = \Environment::get('indexFreeRequest');
         // URL encoding will be handled by the Symfony router, so do not apply rawurlencode() here anymore
         $this->Template->print = '#';
         $this->Template->encUrl = \Environment::get('base') . \Environment::get('request');
         $this->Template->encTitle = $objPage->pageTitle;
         $this->Template->href = $request . (strpos($request, '?') !== false ? '&amp;' : '?') . 'pdf=' . $this->id;
         $this->Template->printTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['printPage']);
         $this->Template->pdfTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['printAsPdf']);
         $this->Template->facebookTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['facebookShare']);
         $this->Template->twitterTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['twitterShare']);
         $this->Template->gplusTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['gplusShare']);
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['compileArticle']) && is_array($GLOBALS['TL_HOOKS']['compileArticle'])) {
         foreach ($GLOBALS['TL_HOOKS']['compileArticle'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback[0]}->{$callback[1]}($this->Template, $this->arrData, $this);
         }
     }
 }
示例#22
0
文件: Calendar.php 项目: Jobu/core
 /**
  * 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));
 }
    /**
     * Renturn a form to choose an existing style sheet and import it
     * @param \DataContainer
     * @return string
     */
    public function send(\DataContainer $objDc)
    {
        if (TL_MODE == 'BE') {
            $GLOBALS['TL_CSS'][] = 'system/modules/newsletter_content/assets/css/style.css';
            if ($this->isFlexible) {
                $GLOBALS['TL_CSS'][] = 'system/modules/newsletter_content/assets/css/style-flexible.css';
            }
        }
        $objNewsletter = $this->Database->prepare("SELECT n.*, c.useSMTP, c.smtpHost, c.smtpPort, c.smtpUser, c.smtpPass FROM tl_newsletter n LEFT JOIN tl_newsletter_channel c ON n.pid=c.id WHERE n.id=?")->limit(1)->execute($objDc->id);
        // Return if there is no newsletter
        if ($objNewsletter->numRows < 1) {
            return '';
        }
        // Overwrite the SMTP configuration
        if ($objNewsletter->useSMTP) {
            $GLOBALS['TL_CONFIG']['useSMTP'] = true;
            $GLOBALS['TL_CONFIG']['smtpHost'] = $objNewsletter->smtpHost;
            $GLOBALS['TL_CONFIG']['smtpUser'] = $objNewsletter->smtpUser;
            $GLOBALS['TL_CONFIG']['smtpPass'] = $objNewsletter->smtpPass;
            $GLOBALS['TL_CONFIG']['smtpEnc'] = $objNewsletter->smtpEnc;
            $GLOBALS['TL_CONFIG']['smtpPort'] = $objNewsletter->smtpPort;
        }
        // Add default sender address
        if ($objNewsletter->sender == '') {
            list($objNewsletter->senderName, $objNewsletter->sender) = \String::splitFriendlyEmail($GLOBALS['TL_CONFIG']['adminEmail']);
        }
        $arrAttachments = array();
        $blnAttachmentsFormatError = false;
        // Add attachments
        if ($objNewsletter->addFile) {
            $files = deserialize($objNewsletter->files);
            if (!empty($files) && is_array($files)) {
                $objFiles = \FilesModel::findMultipleByUuids($files);
                if ($objFiles === null) {
                    if (!\Validator::isUuid($files[0])) {
                        $blnAttachmentsFormatError = true;
                        \Message::addError($GLOBALS['TL_LANG']['ERR']['version2format']);
                    }
                } else {
                    while ($objFiles->next()) {
                        if (is_file(TL_ROOT . '/' . $objFiles->path)) {
                            $arrAttachments[] = $objFiles->path;
                        }
                    }
                }
            }
        }
        // Get content
        $html = '';
        $objContentElements = \ContentModel::findPublishedByPidAndTable($objNewsletter->id, 'tl_newsletter');
        if ($objContentElements !== null) {
            if (!defined('NEWSLETTER_CONTENT_PREVIEW')) {
                define('NEWSLETTER_CONTENT_PREVIEW', true);
            }
            while ($objContentElements->next()) {
                $html .= $this->getContentElement($objContentElements->id);
            }
        }
        // Replace insert tags
        $text = $this->replaceInsertTags($objNewsletter->text);
        $html = $this->replaceInsertTags($html);
        // Convert relative URLs
        $html = $this->convertRelativeUrls($html);
        // Set back to object
        $objNewsletter->content = $html;
        // Send newsletter
        if (!$blnAttachmentsFormatError && \Input::get('token') != '' && \Input::get('token') == $this->Session->get('tl_newsletter_send')) {
            $referer = preg_replace('/&(amp;)?(start|mpc|token|recipient|preview)=[^&]*/', '', \Environment::get('request'));
            // Preview
            if (isset($_GET['preview'])) {
                // Check the e-mail address
                if (!\Validator::isEmail(\Input::get('recipient', true))) {
                    $_SESSION['TL_PREVIEW_MAIL_ERROR'] = true;
                    $this->redirect($referer);
                }
                // get preview recipient
                $arrRecipient = array();
                $strEmail = urldecode(\Input::get('recipient', true));
                $objRecipient = $this->Database->prepare("SELECT * FROM tl_member m WHERE email=? ORDER BY email")->limit(1)->execute($strEmail);
                if ($objRecipient->num_rows < 1) {
                    $arrRecipient['email'] = $strEmail;
                } else {
                    $arrRecipient = $objRecipient->row();
                }
                $arrRecipient = array_merge($arrRecipient, array('extra' => '&preview=1', 'tracker_png' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $strEmail . '&preview=1&t=png', 'tracker_gif' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $strEmail . '&preview=1&t=gif', 'tracker_css' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $strEmail . '&preview=1&t=css', 'tracker_js' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $strEmail . '&preview=1&t=js'));
                // Send
                $objEmail = $this->generateEmailObject($objNewsletter, $arrAttachments);
                $objNewsletter->email = $strEmail;
                $this->sendNewsletter($objEmail, $objNewsletter, $arrRecipient, $text, $html);
                // Redirect
                \Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_newsletter']['confirm'], 1));
                $this->redirect($referer);
            }
            // Get the total number of recipients
            $objTotal = $this->Database->prepare("SELECT COUNT(DISTINCT email) AS count FROM tl_newsletter_recipients WHERE pid=? AND active=1")->execute($objNewsletter->pid);
            // Return if there are no recipients
            if ($objTotal->count < 1) {
                $this->Session->set('tl_newsletter_send', null);
                \Message::addError($GLOBALS['TL_LANG']['tl_newsletter']['error']);
                $this->redirect($referer);
            }
            $intTotal = $objTotal->count;
            // Get page and timeout
            $intTimeout = \Input::get('timeout') > 0 ? \Input::get('timeout') : 1;
            $intStart = \Input::get('start') ? \Input::get('start') : 0;
            $intPages = \Input::get('mpc') ? \Input::get('mpc') : 10;
            // Get recipients
            $objRecipients = $this->Database->prepare("SELECT *, r.email FROM tl_newsletter_recipients r LEFT JOIN tl_member m ON(r.email=m.email) WHERE r.pid=? AND r.active=1 GROUP BY r.email ORDER BY r.email")->limit($intPages, $intStart)->execute($objNewsletter->pid);
            echo '<div style="font-family:Verdana,sans-serif;font-size:11px;line-height:16px;margin-bottom:12px">';
            // Send newsletter
            if ($objRecipients->numRows > 0) {
                // Update status
                if ($intStart == 0) {
                    $this->Database->prepare("UPDATE tl_newsletter SET sent=1, date=? WHERE id=?")->execute(time(), $objNewsletter->id);
                    $_SESSION['REJECTED_RECIPIENTS'] = array();
                }
                while ($objRecipients->next()) {
                    $objEmail = $this->generateEmailObject($objNewsletter, $arrAttachments);
                    $objNewsletter->email = $objRecipients->email;
                    $arrRecipient = array_merge($objRecipients->row(), array('tracker_png' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $objRecipients->email . '&t=png', 'tracker_gif' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $objRecipients->email . '&t=gif', 'tracker_css' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $objRecipients->email . '&t=css', 'tracker_js' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $objRecipients->email . '&t=js'));
                    $this->sendNewsletter($objEmail, $objNewsletter, $arrRecipient, $text, $html);
                    echo 'Sending newsletter to <strong>' . $objRecipients->email . '</strong><br>';
                }
            }
            echo '<div style="margin-top:12px">';
            // Redirect back home
            if ($objRecipients->numRows < 1 || $intStart + $intPages >= $intTotal) {
                $this->Session->set('tl_newsletter_send', null);
                // Deactivate rejected addresses
                if (!empty($_SESSION['REJECTED_RECIPIENTS'])) {
                    $intRejected = count($_SESSION['REJECTED_RECIPIENTS']);
                    \Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_newsletter']['rejected'], $intRejected));
                    $intTotal -= $intRejected;
                    foreach ($_SESSION['REJECTED_RECIPIENTS'] as $strRecipient) {
                        $this->Database->prepare("UPDATE tl_newsletter_recipients SET active='' WHERE email=?")->execute($strRecipient);
                        $this->log('Recipient address "' . $strRecipient . '" was rejected and has been deactivated', __METHOD__, TL_ERROR);
                    }
                }
                $this->Database->prepare("UPDATE tl_newsletter SET recipients=?, rejected=? WHERE id=?")->execute($intTotal, $intRejected, $objNewsletter->id);
                \Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_newsletter']['confirm'], $intTotal));
                echo '<script>setTimeout(\'window.location="' . \Environment::get('base') . $referer . '"\',1000)</script>';
                echo '<a href="' . \Environment::get('base') . $referer . '">Please click here to proceed if you are not using JavaScript</a>';
            } else {
                $url = preg_replace('/&(amp;)?(start|mpc|recipient)=[^&]*/', '', \Environment::get('request')) . '&start=' . ($intStart + $intPages) . '&mpc=' . $intPages;
                echo '<script>setTimeout(\'window.location="' . \Environment::get('base') . $url . '"\',' . $intTimeout * 1000 . ')</script>';
                echo '<a href="' . \Environment::get('base') . $url . '">Please click here to proceed if you are not using JavaScript</a>';
            }
            echo '</div></div>';
            exit;
        }
        $strToken = md5(uniqid(mt_rand(), true));
        $this->Session->set('tl_newsletter_send', $strToken);
        $sprintf = $objNewsletter->senderName != '' ? $objNewsletter->senderName . ' &lt;%s&gt;' : '%s';
        $this->import('BackendUser', 'User');
        // prepare preview
        $preview = $text;
        if (!$objNewsletter->sendText) {
            // Default template
            if ($objNewsletter->template == '') {
                $objNewsletter->template = 'mail_default';
            }
            // Load the mail template
            $objTemplate = new \BackendTemplate($objNewsletter->template);
            $objTemplate->setData($objNewsletter->row());
            $objTemplate->title = $objNewsletter->subject;
            $objTemplate->body = $html;
            $objTemplate->charset = $GLOBALS['TL_CONFIG']['characterSet'];
            $objTemplate->css = $css;
            // Backwards compatibility
            // Parse template
            $preview = $objTemplate->parse();
        }
        // Replace inserttags
        $arrName = explode(' ', $this->User->name);
        $preview = $this->replaceInsertTags($preview);
        $preview = $this->prepareLinkTracking($preview, $objNewsletter->id, $this->User->email, '&preview=1');
        $preview = $this->parseSimpleTokens($preview, array('firstname' => $arrName[0], 'lastname' => $arrName[sizeof($arrName) - 1], 'street' => 'Königsbrücker Str. 9', 'postal' => '01099', 'city' => 'Dresden', 'phone' => '0351 30966184', 'email' => $this->User->email, 'tracker_png' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $this->User->email . '&preview=1&t=png', 'tracker_gif' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $this->User->email . '&preview=1&t=gif', 'tracker_css' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $this->User->email . '&preview=1&t=css', 'tracker_js' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $this->User->email . '&preview=1&t=js'));
        // Create cache folder
        if (!file_exists(TL_ROOT . '/system/cache/newsletter')) {
            mkdir(TL_ROOT . '/system/cache/newsletter');
            file_put_contents(TL_ROOT . '/system/cache/newsletter/.htaccess', '<IfModule !mod_authz_core.c>
  Order allow,deny
  Allow from all
</IfModule>
<IfModule mod_authz_core.c>
  Require all granted
</IfModule>');
        }
        // Cache preview
        file_put_contents(TL_ROOT . '/system/cache/newsletter/' . $objNewsletter->alias . '.html', preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', $preview));
        // Preview newsletter
        $return = '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>

<h2 class="sub_headline">' . sprintf($GLOBALS['TL_LANG']['tl_newsletter']['send'][1], $objNewsletter->id) . '</h2>
' . \Message::generate() . '
<form action="' . ampersand(\Environment::get('script'), true) . '" id="tl_newsletter_send" class="tl_form" method="get">
<div class="tl_formbody_edit tl_newsletter_send">
<input type="hidden" name="do" value="' . \Input::get('do') . '">
<input type="hidden" name="table" value="' . \Input::get('table') . '">
<input type="hidden" name="key" value="' . \Input::get('key') . '">
<input type="hidden" name="id" value="' . \Input::get('id') . '">
<input type="hidden" name="token" value="' . $strToken . '">
<table class="prev_header">
  <tr class="row_0">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['from'] . '</td>
    <td class="col_1">' . sprintf($sprintf, $objNewsletter->sender) . '</td>
  </tr>
  <tr class="row_1">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['subject'][0] . '</td>
    <td class="col_1">' . $objNewsletter->subject . '</td>
  </tr>
  <tr class="row_2">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['template'][0] . '</td>
    <td class="col_1">' . $objNewsletter->template . '</td>
  </tr>' . (!empty($arrAttachments) && is_array($arrAttachments) ? '
  <tr class="row_3">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['attachments'] . '</td>
    <td class="col_1">' . implode(', ', $arrAttachments) . '</td>
  </tr>' : '') . '
</table>' . (!$objNewsletter->sendText ? '
<iframe class="preview_html" id="preview_html" seamless border="0" width="703px" height="503px" style="padding:0" src="system/cache/newsletter/' . $objNewsletter->alias . '.html"></iframe>
' : '') . '
<div class="preview_text">
' . nl2br_html5($text) . '
</div>

<div class="tl_tbox">
<div class="w50">
  <h3><label for="ctrl_mpc">' . $GLOBALS['TL_LANG']['tl_newsletter']['mailsPerCycle'][0] . '</label></h3>
  <input type="text" name="mpc" id="ctrl_mpc" value="10" class="tl_text" onfocus="Backend.getScrollOffset()">' . ($GLOBALS['TL_LANG']['tl_newsletter']['mailsPerCycle'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['mailsPerCycle'][1] . '</p>' : '') . '
</div>
<div class="w50">
  <h3><label for="ctrl_timeout">' . $GLOBALS['TL_LANG']['tl_newsletter']['timeout'][0] . '</label></h3>
  <input type="text" name="timeout" id="ctrl_timeout" value="1" class="tl_text" onfocus="Backend.getScrollOffset()">' . ($GLOBALS['TL_LANG']['tl_newsletter']['timeout'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['timeout'][1] . '</p>' : '') . '
</div>
<div class="w50">
  <h3><label for="ctrl_start">' . $GLOBALS['TL_LANG']['tl_newsletter']['start'][0] . '</label></h3>
  <input type="text" name="start" id="ctrl_start" value="0" class="tl_text" onfocus="Backend.getScrollOffset()">' . ($GLOBALS['TL_LANG']['tl_newsletter']['start'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['start'][1] . '</p>' : '') . '
</div>
<div class="w50">
  <h3><label for="ctrl_recipient">' . $GLOBALS['TL_LANG']['tl_newsletter']['sendPreviewTo'][0] . '</label></h3>
  <input type="text" name="recipient" id="ctrl_recipient" value="' . $this->User->email . '" class="tl_text" onfocus="Backend.getScrollOffset()">' . (isset($_SESSION['TL_PREVIEW_MAIL_ERROR']) ? '
  <div class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['email'] . '</div>' : ($GLOBALS['TL_LANG']['tl_newsletter']['sendPreviewTo'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['sendPreviewTo'][1] . '</p>' : '')) . '
</div>
<div class="clear"></div>
</div>
</div>';
        // Do not send the newsletter if there is an attachment format error
        if (!$blnAttachmentsFormatError) {
            $return .= '

<div class="tl_formbody_submit">
<div class="tl_submit_container">
<input type="submit" name="preview" class="tl_submit" accesskey="p" value="' . specialchars($GLOBALS['TL_LANG']['tl_newsletter']['preview']) . '">
<input type="submit" id="send" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['tl_newsletter']['send'][0]) . '" onclick="return confirm(\'' . str_replace("'", "\\'", $GLOBALS['TL_LANG']['tl_newsletter']['sendConfirm']) . '\')">
</div>
</div>';
        }
        $return .= '

</form>';
        unset($_SESSION['TL_PREVIEW_MAIL_ERROR']);
        return $return;
    }
示例#24
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $this->Template->event = '';
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     // Get the current event
     $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias(\Input::get('events'), $this->cal_calendar);
     if (null === $objEvent) {
         /** @var \PageError404 $objHandler */
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
     }
     // Overwrite the page title (see #2853 and #4955)
     if ($objEvent->title != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($objEvent->title));
     }
     // Overwrite the page description
     if ($objEvent->teaser != '') {
         $objPage->description = $this->prepareMetaDescription($objEvent->teaser);
     }
     $intStartTime = $objEvent->startTime;
     $intEndTime = $objEvent->endTime;
     $span = \Calendar::calculateSpan($intStartTime, $intEndTime);
     // Do not show dates in the past if the event is recurring (see #923)
     if ($objEvent->recurring) {
         $arrRange = deserialize($objEvent->repeatEach);
         if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) {
             while ($intStartTime < time() && $intEndTime < $objEvent->repeatEnd) {
                 $intStartTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intStartTime);
                 $intEndTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intEndTime);
             }
         }
     }
     $strDate = \Date::parse($objPage->dateFormat, $intStartTime);
     if ($span > 0) {
         $strDate = \Date::parse($objPage->dateFormat, $intStartTime) . ' – ' . \Date::parse($objPage->dateFormat, $intEndTime);
     }
     $strTime = '';
     if ($objEvent->addTime) {
         if ($span > 0) {
             $strDate = \Date::parse($objPage->datimFormat, $intStartTime) . ' – ' . \Date::parse($objPage->datimFormat, $intEndTime);
         } elseif ($intStartTime == $intEndTime) {
             $strTime = \Date::parse($objPage->timeFormat, $intStartTime);
         } else {
             $strTime = \Date::parse($objPage->timeFormat, $intStartTime) . ' – ' . \Date::parse($objPage->timeFormat, $intEndTime);
         }
     }
     $until = '';
     $recurring = '';
     // Recurring event
     if ($objEvent->recurring) {
         $arrRange = deserialize($objEvent->repeatEach);
         if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) {
             $strKey = 'cal_' . $arrRange['unit'];
             $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']);
             if ($objEvent->recurrences > 0) {
                 $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], \Date::parse($objPage->dateFormat, $objEvent->repeatEnd));
             }
         }
     }
     /** @var \FrontendTemplate|object $objTemplate */
     $objTemplate = new \FrontendTemplate($this->cal_template);
     $objTemplate->setData($objEvent->row());
     $objTemplate->date = $strDate;
     $objTemplate->time = $strTime;
     $objTemplate->datetime = $objEvent->addTime ? date('Y-m-d\\TH:i:sP', $intStartTime) : date('Y-m-d', $intStartTime);
     $objTemplate->begin = $intStartTime;
     $objTemplate->end = $intEndTime;
     $objTemplate->class = $objEvent->cssClass != '' ? ' ' . $objEvent->cssClass : '';
     $objTemplate->recurring = $recurring;
     $objTemplate->until = $until;
     $objTemplate->locationLabel = $GLOBALS['TL_LANG']['MSC']['location'];
     $objTemplate->details = '';
     $objTemplate->hasDetails = false;
     $objTemplate->hasTeaser = false;
     // Clean the RTE output
     if ($objEvent->teaser != '') {
         $objTemplate->hasTeaser = true;
         if ($objPage->outputFormat == 'xhtml') {
             $objTemplate->teaser = \StringUtil::toXhtml($objEvent->teaser);
         } else {
             $objTemplate->teaser = \StringUtil::toHtml5($objEvent->teaser);
         }
         $objTemplate->teaser = \StringUtil::encodeEmail($objTemplate->teaser);
     }
     // Display the "read more" button for external/article links
     if ($objEvent->source != 'default') {
         $objTemplate->details = true;
         $objTemplate->hasDetails = true;
     } else {
         $id = $objEvent->id;
         $objTemplate->details = function () use($id) {
             $strDetails = '';
             $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_calendar_events');
             if ($objElement !== null) {
                 while ($objElement->next()) {
                     $strDetails .= $this->getContentElement($objElement->current());
                 }
             }
             return $strDetails;
         };
         $objTemplate->hasDetails = \ContentModel::countPublishedByPidAndTable($id, 'tl_calendar_events') > 0;
     }
     $objTemplate->addImage = false;
     // Add an image
     if ($objEvent->addImage && $objEvent->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objEvent->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objEvent->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)
             $arrEvent = $objEvent->row();
             // Override the default image size
             if ($this->imgSize != '') {
                 $size = deserialize($this->imgSize);
                 if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
                     $arrEvent['size'] = $this->imgSize;
                 }
             }
             $arrEvent['singleSRC'] = $objModel->path;
             $this->addImageToTemplate($objTemplate, $arrEvent);
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures
     if ($objEvent->addEnclosure) {
         $this->addEnclosuresToTemplate($objTemplate, $objEvent->row());
     }
     $this->Template->event = $objTemplate->parse();
     // HOOK: comments extension required
     if ($objEvent->noComments || !in_array('comments', \ModuleLoader::getActive())) {
         $this->Template->allowComments = false;
         return;
     }
     /** @var \CalendarModel $objCalendar */
     $objCalendar = $objEvent->getRelated('pid');
     $this->Template->allowComments = $objCalendar->allowComments;
     // Comments are not allowed
     if (!$objCalendar->allowComments) {
         return;
     }
     // Adjust the comments headline level
     $intHl = min(intval(str_replace('h', '', $this->hl)), 5);
     $this->Template->hlc = 'h' . ($intHl + 1);
     $this->import('Comments');
     $arrNotifies = array();
     // Notify the system administrator
     if ($objCalendar->notify != 'notify_author') {
         $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
     }
     // Notify the author
     if ($objCalendar->notify != 'notify_admin') {
         /** @var \UserModel $objAuthor */
         if (($objAuthor = $objEvent->getRelated('author')) !== null && $objAuthor->email != '') {
             $arrNotifies[] = $objAuthor->email;
         }
     }
     $objConfig = new \stdClass();
     $objConfig->perPage = $objCalendar->perPage;
     $objConfig->order = $objCalendar->sortOrder;
     $objConfig->template = $this->com_template;
     $objConfig->requireLogin = $objCalendar->requireLogin;
     $objConfig->disableCaptcha = $objCalendar->disableCaptcha;
     $objConfig->bbcode = $objCalendar->bbcode;
     $objConfig->moderate = $objCalendar->moderate;
     $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_calendar_events', $objEvent->id, $arrNotifies);
 }
示例#25
0
 private function getGlossarElements($id)
 {
     $arrElements = array();
     $objCte = \ContentModel::findPublishedByPidAndTable($id, 'tl_sw_glossar');
     if ($objCte !== null) {
         $intCount = 0;
         $intLast = $objCte->count() - 1;
         while ($objCte->next()) {
             $arrCss = array();
             /** @var \ContentModel $objRow */
             $objRow = $objCte->current();
             // Add the "first" and "last" classes (see #2583)
             if ($intCount == 0 || $intCount == $intLast) {
                 if ($intCount == 0) {
                     $arrCss[] = 'first';
                 }
                 if ($intCount == $intLast) {
                     $arrCss[] = 'last';
                 }
             }
             $objRow->classes = $arrCss;
             $arrElements[] = $this->getContentElement($objRow, $this->strColumn);
             ++$intCount;
         }
     }
     return $arrElements;
 }
 /**
  * Parse an item and return it as string
  * @param object
  * @param boolean
  * @param string
  * @param integer
  * @return string
  */
 protected function parseProject($objProject, $blnAddCategory = false, $strClass = '', $intCount = 0)
 {
     global $objPage;
     $objTemplate = new \FrontendTemplate($this->project_template);
     $objTemplate->setData($objProject->row());
     $objTemplate->class = ($this->project_class != '' ? ' ' . $this->project_class : '') . $strClass;
     $objTemplate->project_class = $this->project_class;
     $objTemplate->link = $this->generateProjectUrl($objProject, $blnAddCategory);
     $objTemplate->category = $objProject->getRelated('pid');
     $objTemplate->count = $intCount;
     // see #5708
     $objTemplate->addImage = false;
     // Add an image
     if ($objProject->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($objProject->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($objProject->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)
             $arrProject = $objProject->row();
             // Override the default image size
             if ($this->project_imgSize != '') {
                 $size = deserialize($this->project_imgSize);
                 if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
                     $arrProject['size'] = $this->project_imgSize;
                 }
             }
             $arrProject['singleSRC'] = $objModel->path;
             $strLightboxId = 'lightbox[lb' . $objProject->id . ']';
             $arrProject['fullsize'] = $this->fullsize;
             $this->addImageToTemplate($objTemplate, $arrProject, null, $strLightboxId);
         }
     }
     $objElement = \ContentModel::findPublishedByPidAndTable($objProject->id, 'tl_portfolio_project');
     if ($objElement !== null) {
         while ($objElement->next()) {
             $objTemplate->text .= $this->getContentElement($objElement->current());
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures
     if ($objProject->addEnclosure) {
         $this->addEnclosuresToTemplate($objTemplate, $objProject->row());
     }
     return $objTemplate->parse();
 }
 public function getContentElements(\DataContainer $dc)
 {
     $result = "";
     $objContentElements = \ContentModel::findPublishedByPidAndTable($dc->id, 'tl_newsletter');
     if ($objContentElements !== null) {
         while ($objContentElements->next()) {
             ${$result} .= $this->getContentElement($objContentElements->id);
         }
     }
     return $result;
 }
示例#28
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));
 }
 protected function renderContent($objChild)
 {
     $strContent = '';
     $objElement = \ContentModel::findPublishedByPidAndTable($objChild->id, 'tl_block_module');
     if ($objElement !== null) {
         while ($objElement->next()) {
             if (!\Controller::isVisibleElement($objElement->current())) {
                 return '';
             }
             $strContent .= \Controller::getContentElement($objElement->current());
         }
     }
     return $strContent;
 }
 public static function hasTextOrTeaser($intId)
 {
     $objEvent = static::findByPk($intId);
     if ($objEvent !== null) {
         if ($objEvent->teaser) {
             return true;
         }
     }
     $objContent = \ContentModel::findPublishedByPidAndTable($intId, 'tl_calendar_events');
     return $objContent !== null;
 }