示例#1
0
 /**
  * compile wrapper element
  */
 protected function compile()
 {
     // get included elements
     if ($this->objWrapper->getType() == ContentWrapper\Model::TYPE_START) {
         $this->Template->count = ContentWrapper\Repository::countRelatedElements($this->objWrapper);
         $cssID = $this->cssID;
         if ($cssID[0] == '') {
             $cssID[0] = sprintf($this->strIdentifier, $this->id);
             $this->cssID = $cssID;
         }
     } else {
         $start = \ContentModel::findByPk($this->bootstrap_parentId);
         if ($start !== null) {
             $start = new Attributes($start);
             $start->registerNamespaceAttributes($this->arrBootstrapAttributes);
             $start->cssID = deserialize($start->cssID, true);
             $this->Template->start = $start;
             if ($start->cssID[0] == '') {
                 $cssID = $start->cssID;
                 $cssID[0] = sprintf($this->strIdentifier, $start->id);
                 $this->cssID = $cssID;
             } else {
                 $this->cssID = $start->cssID;
             }
         }
     }
     $this->Template->identifier = $this->cssID[0];
 }
 /**
  * Parse the template
  *
  * @return string
  */
 public function generate()
 {
     $objElement = \ContentModel::findByPk($this->cteAlias);
     if ($objElement === null) {
         return '';
     }
     $strClass = static::findClass($objElement->type);
     if (!class_exists($strClass)) {
         return '';
     }
     $objElement->origId = $objElement->id;
     $objElement->id = $this->id;
     $objElement->typePrefix = 'ce_';
     /** @var \ContentElement $objElement */
     $objElement = new $strClass($objElement);
     // create new cssID array
     $cssID = array();
     // set the ID
     $cssID[0] = $this->cssID[0] ?: $objElement->cssID[0];
     // merge the classes
     $arrElementClasses = explode(' ', $this->cssID[1]);
     $arrIncludeClasses = explode(' ', $objElement->cssID[1]);
     $cssID[1] = implode(' ', array_unique(array_merge($arrIncludeClasses, $arrElementClasses)));
     // Overwrite spacing and CSS ID
     $objElement->origSpace = $objElement->space;
     $objElement->space = $this->space;
     $objElement->origCssID = $objElement->cssID;
     $objElement->cssID = $cssID;
     return $objElement->generate();
 }
示例#3
0
 /**
  * Parse the template
  *
  * @return string
  */
 public function generate()
 {
     $objElement = \ContentModel::findByPk($this->cteAlias);
     if ($objElement === null) {
         return '';
     }
     $strClass = static::findClass($objElement->type);
     if (!class_exists($strClass)) {
         return '';
     }
     $objElement->origId = $objElement->id;
     $objElement->id = $this->id;
     $objElement->typePrefix = 'ce_';
     /** @var ContentElement $objElement */
     $objElement = new $strClass($objElement);
     $cssID = deserialize($objElement->cssID, true);
     // Override the CSS ID (see #305)
     if (!empty($this->cssID[0])) {
         $cssID[0] = $this->cssID[0];
     }
     // Merge the CSS classes (see #6011)
     if (!empty($this->cssID[1])) {
         $cssID[1] = trim($cssID[1] . ' ' . $this->cssID[1]);
     }
     $objElement->cssID = $cssID;
     return $objElement->generate();
 }
示例#4
0
 /**
  * compile wrapper element
  */
 protected function compile()
 {
     if ($this->wrapper->isTypeOf(Wrapper\Helper::TYPE_START)) {
         $cssID = $this->cssID;
         if ($cssID[0] == '') {
             $cssID[0] = sprintf($this->identifier, $this->id);
             $this->cssID = $cssID;
         }
         $attributes = new Attributes();
         $attributes->addClass('carousel')->addClass('slide')->setAttribute('id', $cssID[0]);
         if ($this->bootstrap_autostart) {
             $attributes->setAttribute('data-ride', 'carousel');
         }
         if ($this->bootstrap_interval > 0) {
             $attributes->setAttribute('data-interval', $this->bootstrap_interval);
         }
         $this->Template->attributes = $attributes;
         $this->Template->count = $this->wrapper->countRelatedElements();
     } else {
         $start = \ContentModel::findByPk($this->bootstrap_parentId);
         if ($start !== null) {
             $start->cssID = deserialize($start->cssID, true);
             $this->Template->start = $start;
             if ($start->cssID[0] == '') {
                 $cssID = $start->cssID;
                 $cssID[0] = sprintf($this->identifier, $start->id);
                 $this->cssID = $cssID;
             } else {
                 $this->cssID = $start->cssID;
             }
         }
     }
     $this->Template->identifier = $this->cssID[0];
     $this->Template->wrapper = $this->wrapper;
 }
 public function modifyPalette(DataContainer $dc)
 {
     $objElement = \ContentModel::findByPk($dc->id);
     if ($objElement === null || $objElement->type != 'linkteaser' || $objElement->source != 'modal') {
         return false;
     }
     $GLOBALS['TL_DCA']['tl_content']['fields']['jumpTo']['label'] =& $GLOBALS['TL_LANG']['tl_content']['modalJumpTo'];
     $GLOBALS['TL_DCA']['tl_content']['fields']['jumpTo']['eval']['mandatory'] = false;
     $GLOBALS['TL_DCA']['tl_content']['fields']['jumpTo']['eval']['tl_class'] = 'clr w50';
 }
 /**
  * Invoke the rendering.
  *
  * @param array $row The child as array.
  *
  * @return mixed|string
  */
 public function __invoke($row)
 {
     $buffer = call_user_func($this->callback, $row);
     if ($row['ptable'] === 'tl_content_node') {
         $parent = \ContentModel::findByPk($row['pid']);
         if ($this->registry->hasNodeType($parent->type)) {
             $node = $this->registry->getNode($parent->type);
             return $node->generateChildInBackendView($row, $buffer);
         }
     }
     return $buffer;
 }
示例#7
0
 /**
  * Modify the current datacontainer palette
  *
  * @param \DataContainer $dc
  *
  * @return bool
  */
 public function modifyPalette(\DataContainer $dc)
 {
     $id = strlen(\Input::get('id')) ? \Input::get('id') : CURRENT_ID;
     $objModel = \ContentModel::findByPk($id);
     if ($objModel === null || $objModel->type != 'linkteaser') {
         return false;
     }
     $dca =& $GLOBALS['TL_DCA']['tl_content'];
     // make text non mandatory
     $dca['fields']['text']['eval']['mandatory'] = false;
     $dca['fields']['target']['load_callback'][] = array(__CLASS__, 'setTargetFlags');
 }
 /**
  * Redirect to the content page when trying to access the content node.
  *
  * This fixes the edit links on the header.
  *
  * @return void
  */
 public function redirect()
 {
     if ($this->input->get('table') === 'tl_content_node') {
         $model = \ContentModel::findByPk($this->input->get('id'));
         if (!$model) {
             \Controller::log(sprintf('Content node "%s" not found', $this->input->get('id')), __METHOD__, TL_ERROR);
             \Controller::redirect('contao/main.php?act=error');
         }
         $nodes = $model->ptable === 'tl_content_node' ? '1' : '';
         $url = \Backend::addToUrl('table=tl_content&nodes=' . $nodes);
         \Controller::redirect($url);
     }
 }
示例#9
0
 /**
  * Parse the template
  * @return string
  */
 public function generate()
 {
     $objElement = \ContentModel::findByPk($this->cteAlias);
     if ($objElement === null) {
         return '';
     }
     $strClass = $this->findContentElement($objElement->type);
     if (!$this->classFileExists($strClass)) {
         return '';
     }
     $objElement->id = $this->id;
     $objElement->typePrefix = 'ce_';
     $objElement = new $strClass($objElement);
     // Overwrite spacing and CSS ID
     $objElement->space = $this->space;
     $objElement->cssID = $this->cssID;
     return $objElement->generate();
 }
示例#10
0
 /**
  * Count required tab separator elements.
  *
  * @param \Database\Result $model  Current row.
  * @param Helper           $helper Wrapper helper.
  *
  * @return int
  */
 public function countRequiredTabSeparators(\Database\Result $model, Helper $helper)
 {
     if (!$helper->isTypeOf(Helper::TYPE_START)) {
         $model = \ContentModel::findByPk($model->bootstrap_parentId);
     }
     $tabs = array();
     if ($model->bootstrap_tabs) {
         $tabs = deserialize($model->bootstrap_tabs, true);
     } elseif (\Input::post('bootstrap_tabs')) {
         $tabs = \Input::post('bootstrap_tabs');
     }
     $count = 0;
     foreach ($tabs as $tab) {
         if ($tab['type'] != 'dropdown') {
             $count++;
         }
     }
     return $count > 0 ? $count - 1 : 0;
 }
示例#11
0
 /**
  * count required tab separator elements
  *
  * @param ContentWrapper\Model $model
  *
  * @return int
  */
 public function countRequiredTabSeparators(ContentWrapper\Model $model)
 {
     if ($model->getType() != ContentWrapper\Model::TYPE_START) {
         $model = \ContentModel::findByPk($model->bootstrap_parentId);
     }
     $tabs = array();
     if ($model->bootstrap_tabs) {
         $tabs = deserialize($model->bootstrap_tabs, true);
     } elseif (\Input::post('bootstrap_tabs')) {
         $tabs = \Input::post('bootstrap_tabs');
     }
     $count = 0;
     foreach ($tabs as $tab) {
         if ($tab['type'] != 'dropdown') {
             $count++;
         }
     }
     return $count > 0 ? $count - 1 : 0;
 }
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $this->strTemplate = 'be_wildcard';
         $this->Template = new \BackendTemplate($this->strTemplate);
         $this->Template->title = $this->headline;
     }
     parent::generate();
     $objConfig = SlickConfigModel::findByPk($this->slickConfig);
     if ($objConfig === null) {
         return;
     }
     $objSlider = \ContentModel::findByPk($this->slickContentSlider);
     if ($objSlider === null) {
         return;
     }
     $this->Template->class .= ' slick-nav ' . SlickConfig::getCssClassFromModel($objConfig) . ' slick';
     $this->Template->syncTo = SlickConfig::getCssClassForContent($this->slickContentSlider);
     return $this->Template->parse();
 }
 /**
  * Parse the template
  *
  * @return string
  */
 public function generate()
 {
     $objElement = \ContentModel::findByPk($this->cteAlias);
     if ($objElement === null) {
         return '';
     }
     $strClass = static::findClass($objElement->type);
     if (!class_exists($strClass)) {
         return '';
     }
     $objElement->origId = $objElement->id;
     $objElement->id = $this->id;
     $objElement->typePrefix = 'ce_';
     /** @var \ContentElement $objElement */
     $objElement = new $strClass($objElement);
     // Overwrite spacing and CSS ID
     $objElement->origSpace = $objElement->space;
     $objElement->space = $this->space;
     $objElement->origCssID = $objElement->cssID;
     $objElement->cssID = $this->cssID;
     return $objElement->generate();
 }
 /**
  * Parse the template
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         // create new backend template
         $objTemplate = new \BackendTemplate('be_include');
         // get the element
         $objElement = \ContentModel::findByPk($this->cteAlias);
         if ($objElement === null) {
             return '';
         }
         // get the parent article
         $objArticle = \ArticleModel::findByPk($objElement->pid);
         if ($objArticle === null) {
             return parent::generate();
         }
         // get the parent pages
         $objPages = \PageModel::findParentsById($objArticle->pid);
         if ($objPages === null) {
             return parent::generate();
         }
         // get the page titles
         $arrPageTitles = array_reverse($objPages->fetchEach('title'));
         // set breadcrumb to original element
         $objTemplate->original = array('crumbs' => implode(' » ', $arrPageTitles), 'article' => array('title' => $objArticle->title, 'link' => 'contao/main.php?do=article&table=tl_content&id=' . $objArticle->id . '&rt=' . REQUEST_TOKEN));
         // get include breadcrumbs
         $includes = \IncludeInfoHelper::getIncludes('cteAlias', $this->cteAlias, $this->id);
         // 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();
 }
 /**
  * Show a hint if a JavaScript library needs to be included in the page layout
  *
  * @param object
  */
 public function showJsLibraryHint($dc)
 {
     if ($_POST || Input::get('act') != 'edit') {
         return;
     }
     // Return if the user cannot access the layout module (see #6190)
     if (!$this->User->hasAccess('themes', 'modules') || !$this->User->hasAccess('layout', 'themes')) {
         return;
     }
     $objCte = \ContentModel::findByPk($dc->id);
     if ($objCte === null) {
         return;
     }
     switch ($objCte->type) {
         case 'gallery':
             Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_content']['includeTemplates'], 'moo_mediabox', 'j_colorbox'));
             break;
         case 'sliderStart':
         case 'sliderStop':
             Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_content']['includeTemplates'], 'moo_slider', 'j_slider'));
             break;
         case 'accordionSingle':
         case 'accordionStart':
         case 'accordionStop':
             Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_content']['includeTemplates'], 'moo_accordion', 'j_accordion'));
             break;
         case 'player':
             Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_content']['includeTemplate'], 'j_mediaelement'));
             break;
         case 'table':
             if ($objCte->sortable) {
                 Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_content']['includeTemplates'], 'moo_tablesort', 'j_tablesort'));
             }
             break;
     }
 }
示例#16
0
 * @author wangaz. GbR <*****@*****.**>
 * @link https://wangaz.com
 * @license http://creativecommons.org/licenses/by-sa/4.0/ CC BY-SA 4.0
 */
/*
 * Config
 */
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = function ($dc) {
    if ($_POST || Input::get('act') != 'edit') {
        return;
    }
    $objUser = \BackendUser::getInstance();
    if (!$objUser->hasAccess('themes', 'modules') || !$objUser->hasAccess('layout', 'themes')) {
        return;
    }
    $objCte = ContentModel::findByPk($dc->id);
    if ($objCte === null) {
        return;
    }
    switch ($objCte->type) {
        case 'juiTabStart':
        case 'juiTabSeparator':
        case 'juiTabStop':
            Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_content']['includeTemplate'], 'j_ui_tabs'));
            break;
    }
};
/*
 * Palettes
 */
$GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][] = 'juiTabShowDropdown';
 public function getTitle(WatchlistItemModel $objItem)
 {
     $objFileModel = \FilesModel::findById($objItem->uuid);
     if ($objFileModel === null) {
         return;
     }
     $objFile = new \File($objFileModel->path, true);
     $objContent = \ContentModel::findByPk($objItem->cid);
     $linkTitle = specialchars($objFile->name);
     // use generate for download & downloads as well
     if ($objContent->type == 'download' && $objContent->linkTitle != '') {
         $linkTitle = $objContent->linkTitle;
     }
     $arrMeta = deserialize($objFileModel->meta);
     // Language support
     if (($arrLang = $arrMeta[$GLOBALS['TL_LANGUAGE']]) != '') {
         $linkTitle = $arrLang['title'] ? $arrLang['title'] : $linkTitle;
     }
     return $linkTitle;
 }
示例#18
0
 /**
  * Generate the header fields.
  *
  * @param array $fields The header fields.
  *
  * @return array
  */
 public function generateHeaderFields($fields)
 {
     $model = \ContentModel::findByPk(CURRENT_ID);
     if ($model instanceof \ContentModel && $this->registry->hasNodeType($model->type)) {
         return $this->registry->getNode($model->type)->generateHeaderFields($fields, $model);
     }
     return $fields;
 }
示例#19
0
 /**
  * handle content element deletion, called by ondelete_callback
  * @param $dc
  */
 public function delete($dc)
 {
     $model = \ContentModel::findByPk($dc->id);
     $this->objModel = new ContentWrapper\Model($model);
     // getType will throw an exception if type is not found. use it to detect non content wrapper elements
     try {
         $type = $this->objModel->getType();
     } catch (\Exception $e) {
         return;
     }
     if ($this->objModel->getType() == ContentWrapper\Model::TYPE_START) {
         $deleteTypes = array();
         if ($this->isTrigger($this->objModel->getType(), ContentWrapper\Model::TYPE_SEPARATOR, static::TRIGGER_DELETE)) {
             $deleteTypes[] = $this->objModel->getTypeName(ContentWrapper\Model::TYPE_SEPARATOR);
         }
         if ($this->isTrigger($this->objModel->getType(), ContentWrapper\Model::TYPE_STOP, static::TRIGGER_DELETE)) {
             $deleteTypes[] = $this->objModel->getTypeName(ContentWrapper\Model::TYPE_STOP);
         }
         if (!empty($deleteTypes)) {
             $this->Database->prepare(sprintf('DELETE FROM tl_content WHERE bootstrap_parentId=? AND type IN(\'%s\')', implode('\',\'', $deleteTypes)))->execute($this->objModel->id);
         }
     } elseif ($this->objModel->getType() == ContentWrapper\Model::TYPE_STOP) {
         if ($this->isTrigger($this->objModel->getType(), ContentWrapper\Model::TYPE_SEPARATOR, static::TRIGGER_DELETE)) {
             $this->Database->prepare('DELETE FROM tl_content WHERE bootstrap_parentId=? AND type=?')->execute($this->objModel->bootstrap_parentId, $this->objModel->getTypeName(ContentWrapper\Model::TYPE_SEPARATOR));
         }
         if ($this->isTrigger($this->objModel->getType(), ContentWrapper\Model::TYPE_START, static::TRIGGER_DELETE)) {
             $query = sprintf('DELETE FROM %s WHERE id=?', $this->objModel->getModel()->getTable());
             \Database::getInstance()->prepare($query)->execute($this->objModel->bootstrap_parentId);
         }
     } else {
         // todo: handle seperator delete actions
     }
 }
 /**
  * On load callback for tl_content
  *
  * @param \DataContainer $dc
  * @return void
  */
 public function contentOnloadCallback($dc)
 {
     if (!static::checkLicense()) {
         $this->removeProFields($dc->table, array('rsts_content_type', 'rsts_direction', 'rsts_centerContent'), array('rsts_carousel_legend'));
     }
     if (!$dc->id) {
         return;
     }
     $contentElement = \ContentModel::findByPk($dc->id);
     if (!$contentElement || !isset($contentElement->type)) {
         return;
     }
     if ($contentElement->type === 'rocksolid_slider') {
         $GLOBALS['TL_DCA'][$dc->table]['fields']['multiSRC']['eval']['isGallery'] = true;
         $GLOBALS['TL_DCA'][$dc->table]['fields']['multiSRC']['eval']['extensions'] = \Config::get('validImageTypes');
     }
 }
示例#21
0
 /**
  * Generate a content element and return it as string
  * 
  * @param mixed $intId A content element ID or a Model object
  * 
  * @return string The content element HTML markup
  */
 protected function getContentElement($intId)
 {
     if (is_object($intId)) {
         $objRow = $intId;
     } else {
         if (!strlen($intId) || $intId < 1) {
             return '';
         }
         $objRow = \ContentModel::findByPk($intId);
         if ($objRow === null) {
             return '';
         }
     }
     // Show to guests only
     if ($objRow->guests && FE_USER_LOGGED_IN && !BE_USER_LOGGED_IN && !$objRow->protected) {
         return '';
     }
     // Protected the element
     if ($objRow->protected && !BE_USER_LOGGED_IN) {
         if (!FE_USER_LOGGED_IN) {
             return '';
         }
         $this->import('FrontendUser', 'User');
         $groups = deserialize($objRow->groups);
         if (!is_array($groups) || count($groups) < 1 || count(array_intersect($groups, $this->User->groups)) < 1) {
             return '';
         }
     }
     // Remove the spacing in the back end preview
     if (TL_MODE == 'BE') {
         $objRow->space = null;
     }
     $strClass = $this->findContentElement($objRow->type);
     // Return if the class does not exist
     if (!$this->classFileExists($strClass)) {
         $this->log('Content element class "' . $strClass . '" (content element "' . $objRow->type . '") does not exist', 'Controller getContentElement()', TL_ERROR);
         return '';
     }
     $objRow->typePrefix = 'ce_';
     $objElement = new $strClass($objRow);
     $strBuffer = $objElement->generate();
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getContentElement']) && is_array($GLOBALS['TL_HOOKS']['getContentElement'])) {
         foreach ($GLOBALS['TL_HOOKS']['getContentElement'] as $callback) {
             $this->import($callback[0]);
             $strBuffer = $this->{$callback}[0]->{$callback}[1]($objRow, $strBuffer);
         }
     }
     // Disable indexing if protected
     if ($objElement->protected && !preg_match('/^\\s*<!-- indexer::stop/i', $strBuffer)) {
         $strBuffer = "\n<!-- indexer::stop -->" . $strBuffer . "<!-- indexer::continue -->\n";
     }
     return $strBuffer;
 }
 /**
  * Inject the breadcrumb.
  *
  * @param string $buffer   The generated output.
  * @param string $template The template name.
  *
  * @return string
  */
 public function injectBreadcrumb($buffer, $template)
 {
     if (!$this->isBreadcrumbRequired($template)) {
         return $buffer;
     }
     $items = array();
     $model = \ContentModel::findByPk(CURRENT_ID);
     $current = $model;
     while ($model && $this->registry->hasNodeType($model->type)) {
         array_unshift($items, $model);
         if ($model->ptable !== 'tl_content_node') {
             break;
         }
         $model = \ContentModel::findByPk($model->pid);
     }
     if ($items) {
         $breadcrumb = new Breadcrumb();
         $this->addParentToBreadcrumb($model, $breadcrumb);
         foreach ($items as $item) {
             $this->registry->getNode($item->type)->buildBreadcrumb($breadcrumb, $item);
         }
         $replacement = $breadcrumb->generate() . '<div class="tl_listing_container node-' . $current->type;
         $buffer = str_replace('<div class="tl_listing_container', $replacement, $buffer);
     }
     return $buffer;
 }
 /**
  * Generate a content element and return it as string
  *
  * @param mixed  $intId     A content element ID or a Model object
  * @param string $strColumn The column the element is in
  *
  * @return string The content element HTML markup
  */
 public static function getContentElement($intId, $strColumn = 'main')
 {
     if (is_object($intId)) {
         $objRow = $intId;
     } else {
         if (!strlen($intId) || $intId < 1) {
             return '';
         }
         $objRow = \ContentModel::findByPk($intId);
         if ($objRow === null) {
             return '';
         }
     }
     // Check the visibility (see #6311)
     if (!static::isVisibleElement($objRow)) {
         return '';
     }
     // Remove the spacing in the back end preview
     if (TL_MODE == 'BE') {
         $objRow->space = null;
     }
     $strClass = \ContentElement::findClass($objRow->type);
     // Return if the class does not exist
     if (!class_exists($strClass)) {
         static::log('Content element class "' . $strClass . '" (content element "' . $objRow->type . '") does not exist', __METHOD__, TL_ERROR);
         return '';
     }
     $objRow->typePrefix = 'ce_';
     /** @var \ContentElement $objElement */
     $objElement = new $strClass($objRow, $strColumn);
     $strBuffer = $objElement->generate();
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getContentElement']) && is_array($GLOBALS['TL_HOOKS']['getContentElement'])) {
         foreach ($GLOBALS['TL_HOOKS']['getContentElement'] as $callback) {
             $strBuffer = static::importStatic($callback[0])->{$callback[1]}($objRow, $strBuffer, $objElement);
         }
     }
     // Disable indexing if protected
     if ($objElement->protected && !preg_match('/^\\s*<!-- indexer::stop/', $strBuffer)) {
         $strBuffer = "\n<!-- indexer::stop -->" . $strBuffer . "<!-- indexer::continue -->\n";
     }
     return $strBuffer;
 }
 /**
  * Generate the widget and return it as string
  * @return string
  */
 public function generate()
 {
     // create new include template
     $objTemplate = new \BackendTemplate('be_include');
     // get the active record
     $activeRecord = $this->arrConfiguration['activeRecord'];
     // get the type
     $type = $activeRecord->type;
     // get the table
     $table = $this->arrConfiguration['strTable'];
     // depending on type
     if ($type == 'alias') {
         // get the element
         $objElement = \ContentModel::findByPk($activeRecord->cteAlias);
         if ($objElement === null) {
             return '';
         }
         // get the parent article
         $objArticle = \ArticleModel::findByPk($objElement->pid);
         if ($objArticle === null) {
             return parent::generate();
         }
         // get the parent pages
         $objPages = \PageModel::findParentsById($objArticle->pid);
         if ($objPages === null) {
             return parent::generate();
         }
         // get the page titles
         $arrPageTitles = array_reverse($objPages->fetchEach('title'));
         // set breadcrumb to original element
         $objTemplate->original = array('crumbs' => implode(' &raquo; ', $arrPageTitles), 'article' => array('title' => $objArticle->title, 'link' => 'contao/main.php?do=article&amp;table=tl_content&amp;id=' . $objArticle->id . '&amp;rt=' . REQUEST_TOKEN));
         // get include breadcrumbs
         $includes = \IncludeInfoHelper::getIncludes('cteAlias', $activeRecord->cteAlias, $activeRecord->id);
         // set include breadcrumbs
         if (count($includes) > 1) {
             $objTemplate->includes = $includes;
         }
     } elseif ($type == 'article') {
         // get the article
         $objArticle = \ArticleModel::findByPk($activeRecord->articleAlias);
         if ($objArticle === null) {
             return parent::generate();
         }
         // get the parent pages
         $objPages = \PageModel::findParentsById($objArticle->pid);
         if ($objPages === null) {
             return parent::generate();
         }
         // get the page titles
         $arrPageTitles = array_reverse($objPages->fetchEach('title'));
         // set breadcrumb to original element
         $objTemplate->original = array('crumbs' => implode(' &raquo; ', $arrPageTitles), 'article' => array('title' => $objArticle->title, 'link' => 'contao/main.php?do=article&amp;table=tl_content&amp;id=' . $objArticle->id . '&amp;rt=' . REQUEST_TOKEN));
         // get include breadcrumbs
         $includes = \IncludeInfoHelper::getIncludes('articleAlias', $activeRecord->articleAlias, $activeRecord->id);
         // set include breadcrumbs
         if (count($includes) > 1) {
             $objTemplate->includes = $includes;
         }
     } elseif ($table == 'tl_content') {
         // get include breadcrumbs that reference this content element
         $includes = \IncludeInfoHelper::getIncludes(array("cteAlias = ? AND type = 'alias'"), array($activeRecord->id));
         // set include breadcrumbs
         if (count($includes) > 0) {
             $objTemplate->includes = $includes;
         }
     } elseif ($table == 'tl_article') {
         // get include breadcrumbs that reference this article
         $includes = \IncludeInfoHelper::getIncludes(array("articleAlias = ? AND type = 'article'"), array($activeRecord->id));
         // set include breadcrumbs
         if (count($includes) > 0) {
             $objTemplate->includes = $includes;
         }
     } elseif ($table == 'tl_module') {
         // get include breadcrumbs that reference this module
         $includes = \IncludeInfoHelper::getIncludes(array("module = ? AND type = 'module'"), array($activeRecord->id));
         // set include breadcrumbs
         if (count($includes) > 0) {
             $objTemplate->includes = $includes;
         }
     }
     // check for includes and add CSS
     if ($objTemplate->includes) {
         $GLOBALS['TL_CSS'][] = \IncludeInfoHelper::BACKEND_CSS;
     }
     // return template
     return $objTemplate->parse();
 }
 /**
  * Check if the node is a child of the parent id.
  *
  * @param array $row      The current row.
  * @param int   $parentId The id.
  *
  * @return bool
  */
 private function isChildOf($row, $parentId)
 {
     if ($row['pid'] == $parentId) {
         return true;
     }
     if ($row['ptable'] != 'tl_content_node') {
         return false;
     }
     $child = \ContentModel::findByPk($row['pid']);
     if ($child) {
         return $this->isChildOf($child->row(), $parentId);
     }
     return false;
 }
 /**
  * Generate a content element and return it as string
  *
  * @param mixed  $intId     A content element ID or a Model object
  * @param string $strColumn The column the element is in
  *
  * @return string The content element HTML markup
  */
 protected static function getContentElementAjax($intId, $strColumn = 'main')
 {
     if (is_object($intId)) {
         $objRow = $intId;
     } else {
         if (!strlen($intId) || $intId < 1) {
             return '';
         }
         $objRow = \ContentModel::findByPk($intId);
         if ($objRow === null) {
             return '';
         }
     }
     // Check the visibility (see #6311)
     if (!static::isVisibleElement($objRow)) {
         return '';
     }
     $strClass = \ContentElement::findClass($objRow->type);
     // Return if the class does not exist
     if (!class_exists($strClass)) {
         \System::log('Content element class "' . $strClass . '" (content element "' . $objRow->type . '") does not exist', __METHOD__, TL_ERROR);
         return '';
     }
     $objRow->typePrefix = 'ce_';
     $objElement = new $strClass($objRow, $strColumn);
     $strBuffer = AjaxInput::get('g') == '1' ? $objElement->generate() : $objElement->generateAjax();
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getContentElement']) && is_array($GLOBALS['TL_HOOKS']['getContentElement'])) {
         foreach ($GLOBALS['TL_HOOKS']['getContentElement'] as $callback) {
             $strBuffer = static::importStatic($callback[0])->{$callback}[1]($objRow, $strBuffer, $objElement);
         }
     }
     return $strBuffer;
 }
 public function createItem(CreateItemEvent $event)
 {
     $item = $event->getItem();
     if ($item->getType() == 'content') {
         $content = \ContentModel::findByPk($item->getName());
         if ($content && ($content->ptable == '' || $content->ptable == 'tl_article')) {
             $article = \ArticleModel::findByPk($content->pid);
             if ($article) {
                 $page = \PageModel::findByPk($article->pid);
                 if ($page) {
                     $headline = deserialize($content->headline, true);
                     $cssID = deserialize($content->cssID, true);
                     if (!empty($headline['value']) && !empty($headline['unit']) && !empty($cssID[0])) {
                         $item->setUri(\Frontend::generateFrontendUrl($page->row()) . '#' . $cssID[0]);
                         $item->setLabel($headline['value']);
                         $item->setExtras($content->row());
                     }
                 }
             }
         }
     }
 }
 /**
  * Return the demanded frontend module or content element parsed as html string
  *
  * Required GET data:
  * * action: "reload-element"
  * * element: "ce::id" or "mod::id" (replace 'id' with the element's id)
  * * page: "id" (optionally, replace 'id' with the current page's id)
  * * auto_item: (an optional auto_item which will be set before fetching the element)
  */
 public function getModuleOrContentElement()
 {
     if (!\Environment::get('isAjaxRequest') || Input::get('action') != 'reload-element') {
         return;
     }
     global $objPage;
     // Set page object as it may be needed for the language e.g.
     if (!$objPage && (int) Input::get('page')) {
         $objPage = \PageModel::findWithDetails((int) Input::get('page'));
     }
     $GLOBALS['TL_LANGUAGE'] = null !== $objPage ? $objPage->language : $GLOBALS['TL_LANGUAGE'];
     list($strElementType, $intElementId) = trimsplit('::', Input::get('element'));
     $strError = '';
     $return = '';
     // Authenticate front end user, e.g. for insert tags
     if (FE_USER_LOGGED_IN) {
         /** @noinspection PhpUndefinedMethodInspection */
         $this->import('FrontendUser', 'User');
         /** @var \FrontendUser $this ->User */
         $this->User->authenticate();
     }
     // Load default language file
     \System::loadLanguageFile('default');
     // Set a given auto_item to fetch the correct version of a module or content element
     if ($strAutoItem = Input::get('auto_item')) {
         Input::setGet('auto_item', $strAutoItem);
     }
     switch ($strElementType) {
         case 'mod':
             /** @type \Model $objModule */
             $objModule = \ModuleModel::findByPk($intElementId);
             if (null === $objModule) {
                 $strError = sprintf('Could not find module ID %s', $intElementId);
                 continue;
             }
             if (!$objModule->allowAjaxReload) {
                 $strError = sprintf('Module ID %u is not allowed to fetch', $intElementId);
                 continue;
             }
             $return = \Controller::getFrontendModule($objModule);
             break;
         case 'ce':
             /** @type \Model $objContent */
             $objContent = ContentModel::findByPk($intElementId);
             if (null === $objContent) {
                 $strError = sprintf('Could not find content element ID %s', $intElementId);
                 continue;
             }
             if (!$objContent->allowAjaxReload) {
                 $strError = sprintf('Content element ID %u is not allowed to fetch', $intElementId);
                 continue;
             }
             $return = \Controller::getContentElement($objContent);
             break;
         default:
             $strError = 'Could not determine whether the element is a module or content element';
             break;
     }
     $arrResponse = array();
     if ($strError) {
         $arrResponse['status'] = 'error';
         $arrResponse['error'] = $strError;
     } else {
         $arrResponse['status'] = 'ok';
         $arrResponse['html'] = $return;
     }
     $objResponse = new JsonResponse($arrResponse);
     $objResponse->send();
 }
示例#29
0
 public function createTemplateData(\Template $objTemplateHtml, \Template $objTemplateJs)
 {
     $objMasonry = \ContentModel::findByPk($objTemplateHtml->id);
     if ($objMasonry === null) {
         return;
     }
     $objTemplateJs->type = $objMasonry->type;
     switch ($objMasonry->dk_msryColumnWidthSelect) {
         case 'fixed':
             // Masonry option 'columnWidth': default value is width of the first element
             $columnWidth = unserialize($objMasonry->dk_msryColumnWidth);
             if (isset($columnWidth['value']) && $columnWidth['value'] != '') {
                 switch ($columnWidth['unit']) {
                     case 'px':
                         $objTemplateJs->columnWidth = 'columnWidth: ' . $columnWidth['value'];
                         break;
                 }
             }
             break;
         case 'class':
             if (isset($objMasonry->dk_msryColumnWidthClass) && $objMasonry->dk_msryColumnWidthClass != '') {
                 $objTemplateJs->columnWidthClass = $objMasonry->dk_msryColumnWidthClass;
                 $objTemplateJs->columnWidth = 'columnWidth: \'.' . $objMasonry->dk_msryColumnWidthClass . '\'';
             }
             break;
     }
     switch ($objMasonry->dk_msryGutterSelect) {
         case 'fixed':
             // Masonry option 'gutter': default value is '0'
             $gutter = unserialize($objMasonry->dk_msryGutter);
             if (isset($gutter['value']) && $gutter['value'] != '') {
                 switch ($gutter['unit']) {
                     case 'px':
                         $objTemplateJs->gutter = 'gutter: ' . $gutter['value'];
                         break;
                 }
             }
             break;
         case 'class':
             if (isset($objMasonry->dk_msryGutterClass) && $objMasonry->dk_msryGutterClass != '') {
                 $objTemplateJs->gutterClass = $objMasonry->dk_msryGutterClass;
                 $objTemplateJs->gutter = 'gutter: \'.' . $objMasonry->dk_msryGutterClass . '\'';
             }
             break;
     }
     // Masonry option 'isOriginLeft': default value is 'true'
     if ($objMasonry->dk_msryIsOriginLeft != 'left') {
         $objTemplateJs->isOriginLeft = 'isOriginLeft: false';
     }
     // Masonry option 'isOriginTop': default value is 'true'
     if ($objMasonry->dk_msryIsOriginTop != 'top') {
         $objTemplateJs->isOriginTop = 'isOriginTop: false';
     }
     // Masonry option 'isFitWidth': default value is 'false'
     if ($objMasonry->dk_msryIsFitWidth) {
         $objTemplateJs->isFitWidth = 'isFitWidth: true';
     }
     // Masonry option 'isResizeBound': default value is 'true'
     if (!$objMasonry->dk_msryIsResizeBound) {
         $objTemplateJs->isResizeBound = 'isResizeBound: false';
     }
     // Masonry option 'transitionDuration': default value is '400'
     if ($objMasonry->dk_msryTransitionDuration != '400') {
         $objTemplateJs->transitionDuration = 'transitionDuration: "' . $objMasonry->dk_msryTransitionDuration . 'ms"';
     }
     // ... global css file
     $GLOBALS['TL_CSS'][] = 'system/modules/dk_masonry/assets/css/masonry.css||static';
     // ... theme css file
     if (isset($objTemplateHtml->dk_msryThemeSelect) && $objTemplateHtml->dk_msryThemeSelect != '') {
         if ($objTemplateHtml->dk_msryThemeSelect == 'external') {
             $objFile = \FilesModel::findByPk($objTemplateHtml->dk_msryThemeSRC);
             if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) {
                 $GLOBALS['TL_CSS'][] = $objFile->path . '||static';
             }
         } else {
             $GLOBALS['TL_CSS'][] = 'system/modules/dk_masonry/assets/themes/' . $objTemplateHtml->dk_msryThemeSelect . '/css/' . $objTemplateHtml->dk_msryThemeSelect . '.css||static';
         }
     }
     // ... the masonry javascript itself
     $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/dk_masonry/assets/js/masonry.pkgd.min.js|static';
     // ... element dependent javascript caller
     $GLOBALS['TL_JQUERY'][] = $objTemplateJs->parse();
     // helper stuff:
     // ... images loaded javascript trigger mode
     $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/dk_masonry/assets/js/imagesloaded.pkgd.min.js|static';
 }
示例#30
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();
     }
 }