Пример #1
0
 /**
  * Find related elements of a start element
  *
  * @param Model $model
  * @param null $type
  *
  * @return Collection
  */
 public static function findRelatedElements(Model $model, $type = null)
 {
     if ($model->bootstrap_parentId == '' && $model->getType() != $model::TYPE_START) {
         return null;
     }
     $options = array('order' => 'sorting');
     if ($type === null) {
         $column = 'bootstrap_parentId';
         $values[] = $model->id;
     } else {
         $column = array('bootstrap_parentId=? ', 'type=?');
         $values[] = $model->id;
         $values[] = $model->getTypeName($type);
     }
     return \ContentModel::findBy($column, $values, $options);
 }
Пример #2
0
 public function getContentSliderCarousels(DataContainer $dc)
 {
     $arrOptions = array();
     $objSlider = \ContentModel::findBy('type', 'slick-content-start');
     if ($objSlider === null) {
         return $arrOptions;
     }
     while ($objSlider->next()) {
         $objArticle = \ArticleModel::findByPk($objSlider->pid);
         if ($objArticle === null) {
             continue;
         }
         $arrOptions[$objSlider->id] = sprintf($GLOBALS['TL_LANG']['tl_content']['contentSliderCarouselSelectOption'], $objArticle->title, $objArticle->id, $objSlider->id);
     }
     return $arrOptions;
 }
 /**
  * Parse the template
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         // create new backend template
         $objTemplate = new \BackendTemplate('be_include');
         // get all include elements
         $objElements = \ContentModel::findBy('module', $this->module, array('order' => 'id'));
         // prepare include breadcrumbs
         $includes = array();
         // go throuch each include element
         while ($objElements->next()) {
             // get the parent article
             $objArticle = \ArticleModel::findByPk($objElements->pid);
             if ($objArticle === null) {
                 continue;
             }
             // get the parent pages
             $objPages = \PageModel::findParentsById($objArticle->pid);
             if ($objPages === null) {
                 continue;
             }
             // get the page titles
             $arrPageTitles = array_reverse($objPages->fetchEach('title'));
             // css classes for list
             $classes = array();
             if ($objElements->id == $this->id) {
                 $classes[] = 'self';
             }
             if ($objElements->invisible) {
                 $classes[] = 'hidden';
             }
             // create breadcrumb
             $includes[] = array('crumbs' => implode(' » ', $arrPageTitles), 'article' => array('title' => $objArticle->title, 'link' => 'contao/main.php?do=article&table=tl_content&id=' . $objArticle->id . '&rt=' . REQUEST_TOKEN), 'class' => implode(' ', $classes));
         }
         // set include breadcrumbs
         if (count($includes) > 1) {
             $objTemplate->includes = $includes;
         }
         // add CSS
         $GLOBALS['TL_CSS'][] = \IncludeInfoHelper::BACKEND_CSS;
         // return info + content
         return $objTemplate->parse() . parent::generate();
     }
     // return content only
     return parent::generate();
 }
 public static function getIncludes($where, $includeId, $selfId = null)
 {
     // get all include elements
     $objElements = \ContentModel::findBy($where, $includeId, array('order' => 'id'));
     // check for result
     if ($objElements === null) {
         return array();
     }
     // prepare include breadcrumbs
     $includes = array();
     // go throuch each include element
     while ($objElements->next()) {
         // get the parent article
         $objArticle = \ArticleModel::findByPk($objElements->pid);
         if ($objArticle === null) {
             continue;
         }
         // get the parent pages
         $objPages = \PageModel::findParentsById($objArticle->pid);
         if ($objPages === null) {
             continue;
         }
         // get the page titles
         $arrPageTitles = array_reverse($objPages->fetchEach('title'));
         // css classes for list
         $classes = array();
         if ($objElements->id == $selfId) {
             $classes[] = 'self';
         }
         if ($objElements->invisible) {
             $classes[] = 'hidden';
         }
         // create breadcrumb
         $includes[] = array('crumbs' => implode(' » ', $arrPageTitles), 'article' => array('title' => $objArticle->title, 'link' => 'contao/main.php?do=article&table=tl_content&id=' . $objArticle->id . '&rt=' . REQUEST_TOKEN), 'class' => implode(' ', $classes));
     }
     // return the include elements
     return $includes;
 }
 /**
  * Update the Facebook albums
  */
 public function updateAlbums()
 {
     $contentModels = \ContentModel::findBy('type', 'facebook_album');
     if ($contentModels === null) {
         return;
     }
     $count = 0;
     /** @var \ContentModel $contentModel */
     foreach ($contentModels as $contentModel) {
         $accountModel = AccountModel::findByPk($contentModel->accountModel);
         if ($accountModel === null) {
             continue;
         }
         $facebookAlbum = new FacebookAlbum($accountModel);
         $facebookAlbum->setAlbumId($contentModel->facebook_album);
         if ($facebookAlbum->isOutdated()) {
             $facebookAlbum->fetchImages();
             $count++;
         }
     }
     if ($count > 0) {
         \System::log(sprintf('Facebook albums: %s have been updated', $count), __METHOD__, TL_CRON);
     }
 }
Пример #6
0
 public function generateUrl($arrPages)
 {
     $arrPages = array();
     $News = \NewsModel::findAll();
     if (empty($News)) {
         return array();
     }
     $arrNews = array();
     while ($News->next()) {
         if (!empty($News)) {
             $arrNews[$News->pid][] = $this->generateNewsUrl($News);
         }
     }
     $InactiveArchives = \GlossarNewsArchiveModel::findByPidsAndInactiveGlossar(array_keys($arrNews));
     if (!empty($InactiveArchives)) {
         while ($InactiveArchives->next()) {
             unset($arrNews[$InactiveArchives->id]);
         }
     }
     if (empty($arrNews)) {
         return array();
     }
     $NewsReader = \ModuleModel::findByType('newsreader');
     if (empty($NewsReader)) {
         return array();
     }
     $arrReader = array();
     while ($NewsReader->next()) {
         $arrReader[$NewsReader->id] = deserialize($NewsReader->news_archives);
     }
     $Content = \ContentModel::findBy(array("module IN ('" . implode("','", array_keys($arrReader)) . "')"), array());
     if (empty($Content)) {
         return array();
     }
     $arrContent = array();
     while ($Content->next()) {
         $arrContent[$Content->module] = $Content->pid;
     }
     $Article = \ArticleModel::findBy(array("tl_article.id IN ('" . implode("','", $arrContent) . "')"), array());
     if (empty($Article)) {
         return array();
     }
     $finishedIDs = $arrPages = array();
     while ($Article->next()) {
         // $root = $this->getRootPage($Article->pid);
         $domain = \Environment::get('base');
         $strLanguage = 'de';
         $objPages = $Article->getRelated('pid');
         $ReaderId = false;
         foreach ($arrContent as $module => $mid) {
             if ($mid == $Article->id) {
                 $ReaderId = $module;
             }
         }
         foreach ($arrReader[$ReaderId] as $news_id) {
             if (in_array($news_id, $finishedIDs)) {
                 continue;
             }
             if (!empty($arrNews[$news_id])) {
                 foreach ($arrNews[$news_id] as $news_domain) {
                     $news_domain = str_replace('.html', '', $news_domain);
                     $arrPages['de'][] = $domain . static::generateFrontendUrl($objPages->row(), substr($news_domain, strpos($news_domain, '/')), $strLanguage);
                 }
             }
             $finishedIDs[] = $news_id;
         }
     }
     return $arrPages;
 }
 public static function hasContentElements($intId)
 {
     return \ContentModel::findBy(array('ptable=? AND pid=?'), array('tl_news', $intId)) !== null;
 }
Пример #8
0
 public function generateUrl($arrPages)
 {
     $arrPages = array();
     $Event = \CalendarEventsModel::findAll();
     if (empty($Event)) {
         return array();
     }
     $arrEvent = array();
     while ($Event->next()) {
         $objCalendar = \CalendarModel::findByPk($Event->pid);
         if ($objCalendar !== null && $objCalendar->jumpTo && ($objTarget = $objCalendar->getRelated('jumpTo')) !== null) {
             $arrEvent[$Event->pid][] = $this->generateEventUrl($Event, $this->generateFrontendUrl($objTarget->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/events/%s'));
         }
     }
     $InactiveArchives = \GlossarCalendarModel::findByPidsAndInactiveGlossar(array_keys($arrEvent));
     if (!empty($InactiveArchives)) {
         while ($InactiveArchives->next()) {
             unset($arrEvent[$InactiveArchives->id]);
         }
     }
     if (empty($arrEvent)) {
         return array();
     }
     $EventReader = \ModuleModel::findByType('eventreader');
     if (empty($EventReader)) {
         return array();
     }
     $arrReader = array();
     while ($EventReader->next()) {
         $arrReader[$EventReader->id] = deserialize($EventReader->cal_calendar);
     }
     $Content = \ContentModel::findBy(array("module IN ('" . implode("','", array_keys($arrReader)) . "')"), array());
     if (empty($Content)) {
         return array();
     }
     $arrContent = array();
     while ($Content->next()) {
         $arrContent[$Content->module] = $Content->pid;
     }
     $Article = \ArticleModel::findBy(array("tl_article.id IN ('" . implode("','", $arrContent) . "')"), array());
     if (empty($Article)) {
         return array();
     }
     $finishedIDs = $arrPages = array();
     while ($Article->next()) {
         // $root = $this->getRootPage($Article->pid);
         $domain = \Environment::get('base');
         $strLanguage = 'de';
         $objPages = $Article->getRelated('pid');
         $ReaderId = false;
         foreach ($arrContent as $module => $mid) {
             if ($mid == $Article->id) {
                 $ReaderId = $module;
             }
         }
         foreach ($arrReader[$ReaderId] as $event_id) {
             if (in_array($event_id, $finishedIDs)) {
                 continue;
             }
             if (!empty($arrEvent[$event_id])) {
                 foreach ($arrEvent[$event_id] as $event_domain) {
                     $event_domain = str_replace('.html', '', $event_domain);
                     $arrPages['de'][] = $domain . static::generateFrontendUrl($objPages->row(), substr($event_domain, strpos($event_domain, '/')), $strLanguage);
                 }
             }
             $finishedIDs[] = $event_id;
         }
     }
     return $arrPages;
 }
 public static function getTabControlTabs()
 {
     $arrOptions = array();
     if (($objContentElements = \ContentModel::findBy(array('tl_content.type = ?', 'tabType = ?'), array('tabcontrol', 'tabcontroltab'))) !== null) {
         while ($objContentElements->next()) {
             $arrTabs = deserialize($objContentElements->tab_tabs, true);
             $arrOptions[$objContentElements->id] = 'ID ' . $objContentElements->id . (count($arrTabs) > 0 ? ': ' . implode(', ', array_map(function ($arrTab) {
                 return $arrTab['tab_tabs_name'];
             }, $arrTabs)) : '');
         }
     }
     return $arrOptions;
 }
 public function templates($obj)
 {
     $template = $obj->getName();
     switch ($template) {
         case 'fe_page':
         case 'fe_page_multitoggle':
             //custom
             $obj->setName($template . '_gc');
             //gc = grid controll only
             $obj->__get("layout")->__set("gridCSS", (array) $this->getGridArr($obj->layout));
             break;
         case 'form':
             $obj->setName($template . '_' . \Config::get('co_grid_prefix'));
             break;
         default:
     }
     // `-,-´ ContentElements
     if ($obj->__get('typePrefix') == 'ce_' && strpos($template, 'ce_row_start') === FALSE) {
         $strClass = $this->findContentElement($obj->__get('type'));
         if ($strClass !== NULL && $strClass != '') {
             $objModel = \ContentModel::findBy('id', $obj->__get('id'));
             if ($objModel !== NULL) {
                 $objEl = new $strClass($objModel);
                 $objEl = $this->design_elements($objEl);
                 $obj->__set('ftc_classes', $objEl->ftc_classes);
                 $obj->__set('ftcID', $objEl->ftcID);
                 $obj->__set('data_attr', $this->splitArr($objEl->data_attr));
                 $obj->__set('class', $objEl->ftc_classes);
                 $obj->__set('cssID', $objEl->ftcID);
             }
         }
     }
     if (strpos($template, 'ce_row_start') !== FALSE) {
         $obj->__set('row_data_attr_ftc', $this->splitArr($obj->row_data_attr_ftc));
     }
     // `-,-´ Article
     if (strpos($template, 'mod_article') !== FALSE) {
         $objModel = \ArticleModel::findBy('id', $obj->__get('id'));
         if ($objModel !== NULL) {
             $objEl = new \ModuleArticle($objModel);
             $objEl = $this->design_articles($objEl);
             $obj->__set('class', '' . $objEl->ftc_classes);
             $obj->__set('cssID', $objEl->ftcID . ' ');
             //.$objEl->data_attr.' '
         }
     }
     // `-,-´ Module
     if ($obj->__get('typePrefix') == 'mod_') {
         $strClass = \Module::findClass($obj->__get('type'));
         if ($strClass !== NULL && $strClass != '') {
             $objModel = \ModuleModel::findBy('id', $obj->__get('id'));
             if ($objModel !== NULL) {
                 $objEl = new $strClass($objModel);
                 $co_grid = $this->design_modules($objEl);
                 $obj->__set('class', $co_grid['class'] . ' ' . $co_grid['co_grid_classes']);
                 // $obj->__set('cssID',$co_grid['ftcID'].' '.$co_grid['data_attr'].' ');
                 $obj->__set('ftc_classes', $co_grid['class'] . ' ' . $co_grid['co_grid_classes']);
                 $obj->__set('ftcID', $co_grid['ftcID'] . ' ');
                 $obj->__set('ftc_data_attr', $co_grid['data_attr']);
             }
         }
     }
 }
 /**
  * Generate the module
  *
  * @return string
  */
 public function run()
 {
     $objTemplate = new \BackendTemplate('be_rsce_convert');
     $objTemplate->isActive = $this->isActive();
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->indexHeadline = $GLOBALS['TL_LANG']['tl_maintenance']['searchIndex'];
     // Rebuild the index
     if (\Input::get('act') === 'rsce_convert') {
         // Check the request token
         if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) {
             $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request'));
             $this->redirect('contao/confirm.php');
         }
         $this->import('Database');
         $failedElements = array();
         $elementsCount = 0;
         $contentElements = \ContentModel::findBy(array(\ContentModel::getTable() . '.type LIKE ?'), 'rsce_%');
         while ($contentElements && $contentElements->next()) {
             $html = $this->getHtmlFromElement($contentElements);
             if (!$html) {
                 $failedElements[] = array('content', $contentElements->id, $contentElements->type);
             } else {
                 $this->createInitialVersion(\ContentModel::getTable(), $contentElements->id);
                 $this->Database->prepare('UPDATE ' . \ContentModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $contentElements->id);
                 $elementsCount++;
                 $this->createNewVersion(\ContentModel::getTable(), $contentElements->id);
                 $this->log('A new version of record "' . \ContentModel::getTable() . '.id=' . $contentElements->id . '" has been created', __METHOD__, TL_GENERAL);
             }
         }
         $moduleElements = \ModuleModel::findBy(array(\ModuleModel::getTable() . '.type LIKE ?'), 'rsce_%');
         while ($moduleElements && $moduleElements->next()) {
             $html = $this->getHtmlFromElement($moduleElements);
             if (!$html) {
                 $failedElements[] = array('module', $moduleElements->id, $moduleElements->type);
             } else {
                 $this->createInitialVersion(\ModuleModel::getTable(), $moduleElements->id);
                 $this->Database->prepare('UPDATE ' . \ModuleModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $moduleElements->id);
                 $elementsCount++;
                 $this->createNewVersion(\ModuleModel::getTable(), $moduleElements->id);
                 $this->log('A new version of record "' . \ModuleModel::getTable() . '.id=' . $moduleElements->id . '" has been created', __METHOD__, TL_GENERAL);
             }
         }
         $formElements = \FormFieldModel::findBy(array(\FormFieldModel::getTable() . '.type LIKE ?'), 'rsce_%');
         while ($formElements && $formElements->next()) {
             $html = $this->getHtmlFromElement($formElements);
             if (!$html) {
                 $failedElements[] = array('form', $formElements->id, $formElements->type);
             } else {
                 $this->createInitialVersion(\FormFieldModel::getTable(), $formElements->id);
                 $this->Database->prepare('UPDATE ' . \FormFieldModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $formElements->id);
                 $elementsCount++;
                 $this->createNewVersion(\FormFieldModel::getTable(), $formElements->id);
                 $this->log('A new version of record "' . \FormFieldModel::getTable() . '.id=' . $formElements->id . '" has been created', __METHOD__, TL_GENERAL);
             }
         }
         foreach ($failedElements as $element) {
             $this->log('Failed to convert ' . $element[0] . ' element ID ' . $element[1] . ' (' . $element[2] . ') to a standard HTML element', __METHOD__, TL_ERROR);
         }
         $this->log('Converted ' . $elementsCount . ' RockSolid Custom Elements to standard HTML elements', __METHOD__, TL_GENERAL);
         $objTemplate->elementsCount = $elementsCount;
         $objTemplate->failedElements = $failedElements;
     }
     $this->loadLanguageFile('rocksolid_custom_elements');
     return $objTemplate->parse();
 }
Пример #12
0
 /**
  * {@inheritDoc}
  */
 public function findChildren($nodeId)
 {
     $elements = \ContentModel::findBy(array('pid=?', 'ptable=?'), array($nodeId, 'tl_content_node'), array('order' => 'sorting'));
     if ($elements) {
         return $elements;
     }
     return array();
 }
Пример #13
0
 /**
  * Get parents for a specific item.
  *
  * @param \DataContainer $dataContainer The data container driver.
  *
  * @return array
  */
 public function getParents($dataContainer)
 {
     if ($dataContainer->id) {
         $row = \ContentModel::findByPk($dataContainer->id);
         if (!$row) {
             return array();
         }
         $helper = Helper::create($row);
         $start = Bootstrap::getConfigVar('wrappers.' . $helper->getGroup() . '.start.name');
         if ($start) {
             $table = \ContentModel::getTable();
             $result = \ContentModel::findBy(array($table . '.pid=?', $table . '.type=?', $table . '.sorting<?'), array($row->pid, $start, $row->sorting), array('order' => $table . '.sorting DESC'));
             if ($result) {
                 $values = array();
                 foreach ($result as $model) {
                     $headline = deserialize($model->headline, true);
                     $values[$model->id] = $headline['value'] ?: $model->type . ' ID: ' . $model->id;
                 }
                 return $values;
             }
         }
         return array();
     }
 }
Пример #14
0
 protected function checkIfIsLastElement($objRow)
 {
     $objElements = \ContentModel::findBy(array("invisible=?", "pid=?"), array("", $objRow->pid));
     if ($objElements) {
         $checkElement = false;
         $counter = 1;
         $max = $objElements->count();
         $columns = (int) $objRow->simple_columns;
         $currColumns = (int) $GLOBALS['DPS']['COLUMNS']['COUNT'] || 0;
         if (preg_match('/-/', $columns)) {
             $arrColumnParts = explode("-", $columns);
             $intColumnOffset = (int) ((int) $arrColumnParts[1] - 1);
             $columns = (int) $arrColumnParts[0];
             $GLOBALS['DPS']['COLUMNS']['COUNT'] = $GLOBALS['DPS']['COLUMNS']['COUNT'] + (int) $intColumnOffset;
             $currColumns = (int) $GLOBALS['DPS']['COLUMNS']['COUNT'];
         }
         $currColumns = intval($currColumns);
         while ($objElements->next()) {
             //				if( $checkElement )
             //				{
             //					$currColumns++;
             //
             //					break;
             //				}
             if ($objElements->id == $objRow->id) {
                 if ($counter == $max || $columns == $currColumns) {
                     //						echo "<pre>";
                     //						print_r( $counter);
                     //						echo " == ";
                     //						print_r($max);
                     //						echo "<br>";
                     //						print_r($columns);
                     //						echo " == ";
                     //						print_r($currColumns);
                     //						exit;
                     return true;
                 }
                 //					$checkElement = true;
             }
             $counter++;
         }
     }
     return false;
 }
 public function collectItems(CollectItemsEvent $event)
 {
     $item = $event->getParentItem();
     if ($item->getType() == 'article') {
         $t = \ContentModel::getTable();
         $arrColumns = array("{$t}.pid=?", "({$t}.ptable='' OR {$t}.ptable='tl_article')", "{$t}.cssID!=''");
         if (!BE_USER_LOGGED_IN) {
             $time = time();
             $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.invisible=''";
         }
         $contents = \ContentModel::findBy($arrColumns, array($item->getName()), array('order' => 'sorting'));
         if ($contents) {
             $factory = $event->getFactory();
             $reachedLevel = 7;
             foreach ($contents as $content) {
                 $headline = deserialize($content->headline, true);
                 $cssID = deserialize($content->cssID, true);
                 if (!empty($headline['value']) && !empty($headline['unit']) && !empty($cssID[0])) {
                     $elementLevel = (int) substr($headline['unit'], 1);
                     if ($elementLevel <= $reachedLevel) {
                         $factory->createItem('content', $content->id, $item);
                         $reachedLevel = $elementLevel;
                     }
                 }
             }
         }
     } else {
         if ($item->getType() == 'content') {
             $thisHeadline = deserialize($item->getExtra('headline'), true);
             if (!empty($thisHeadline['unit'])) {
                 $expectedLevel = intval(substr($thisHeadline['unit'], 1)) + 1;
                 $t = \ContentModel::getTable();
                 $arrColumns = array("{$t}.pid=?", "({$t}.ptable='' OR {$t}.ptable='tl_article')", "{$t}.cssID!=''", "{$t}.sorting > ?");
                 if (!BE_USER_LOGGED_IN) {
                     $time = time();
                     $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.invisible=''";
                 }
                 $contents = \ContentModel::findBy($arrColumns, array($item->getExtra('pid'), $item->getExtra('sorting')), array('order' => 'sorting'));
                 if ($contents) {
                     $factory = $event->getFactory();
                     $reachedLevel = 7;
                     foreach ($contents as $content) {
                         $headline = deserialize($content->headline, true);
                         $cssID = deserialize($content->cssID, true);
                         if (!empty($headline['value']) && !empty($headline['unit']) && !empty($cssID[0])) {
                             $elementLevel = (int) substr($headline['unit'], 1);
                             // level is one down
                             if ($elementLevel >= $expectedLevel && $elementLevel <= $reachedLevel) {
                                 $factory->createItem('content', $content->id, $item);
                                 $reachedLevel = $elementLevel;
                             } else {
                                 if ($elementLevel < $expectedLevel) {
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }