/**
  * Return if there are no files
  *
  * @return string
  */
 public function generate()
 {
     // Use the home directory of the current user as file source
     if ($this->useHomeDir && FE_USER_LOGGED_IN) {
         $this->import('FrontendUser', 'User');
         if ($this->User->assignDir && $this->User->homeDir) {
             $this->multiSRC = array($this->User->homeDir);
         }
     } else {
         $this->multiSRC = deserialize($this->multiSRC);
     }
     // Return if there are no files
     if (!is_array($this->multiSRC) || empty($this->multiSRC)) {
         return '';
     }
     // Get the file entries from the database
     $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC);
     if ($this->objFiles === null) {
         if (!\Validator::isUuid($this->multiSRC[0])) {
             return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
         }
         return '';
     }
     $file = \Input::get('file', true);
     // Send the file to the browser and do not send a 404 header (see #4632)
     if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) {
         while ($this->objFiles->next()) {
             if ($file == $this->objFiles->path || dirname($file) == $this->objFiles->path) {
                 \Controller::sendFileToBrowser($file);
             }
         }
         $this->objFiles->reset();
     }
     return parent::generate();
 }
 public function __construct(\Model\Collection $objCss, $arrReturn = array(), $blnCache)
 {
     parent::__construct();
     $this->start = microtime(true);
     $this->cache = $blnCache;
     $this->loadDataContainer('tl_extcss');
     while ($objCss->next()) {
         $this->arrData[] = $objCss->row();
     }
     $this->variablesSrc = 'variables-' . $this->title . '.less';
     $this->mode = $this->cache ? 'none' : 'static';
     $this->arrReturn = $arrReturn;
     $this->objUserCssFile = new \File($this->getSrc($this->title . '.css'));
     // rewrite if group css is empty or created/updated recently
     if ($this->objUserCssFile->size == 0 || $this->lastUpdate > $this->objUserCssFile->mtime) {
         $this->rewrite = true;
         $this->rewriteBootstrap = true;
         $this->cache = false;
     }
     $this->uriRoot = (TL_ASSETS_URL ? TL_ASSETS_URL : \Environment::get('url')) . '/assets/css/';
     $this->arrLessOptions = array('compress' => !\Config::get('bypassCache'), 'cache_dir' => TL_ROOT . '/assets/css/lesscache');
     if (!$this->cache) {
         $this->objLess = new \Less_Parser($this->arrLessOptions);
         $this->addBootstrapVariables();
         $this->addFontAwesomeVariables();
         $this->addFontAwesomeCore();
         $this->addFontAwesomeMixins();
         $this->addFontAwesome();
         $this->addBootstrapMixins();
         $this->addBootstrapAlerts();
         $this->addBootstrap();
         $this->addBootstrapUtilities();
         $this->addBootstrapType();
         if ($this->addElegantIcons) {
             $this->addElegantIconsVariables();
             $this->addElegantIcons();
         }
         // HOOK: add custom assets
         if (isset($GLOBALS['TL_HOOKS']['addCustomAssets']) && is_array($GLOBALS['TL_HOOKS']['addCustomAssets'])) {
             foreach ($GLOBALS['TL_HOOKS']['addCustomAssets'] as $callback) {
                 $this->import($callback[0]);
                 $this->{$callback}[0]->{$callback}[1]($this->objLess, $this->arrData, $this);
             }
         }
         $this->addCustomLessFiles();
         $this->addCssFiles();
     } else {
         // remove custom less files as long as we can not provide mixins and variables in cache mode
         unset($GLOBALS['TL_USER_CSS']);
         // always add bootstrap
         $this->addBootstrap();
     }
 }
 /**
  * Add a model to a collection
  *
  * @param \Model                 $objModel
  * @param \Model\Collection|null $objCollection
  *
  * @return \Model\Collection|null
  */
 public static function addModelToCollection(\Model $objModel, \Model\Collection $objCollection = null)
 {
     $arrRegistered = array();
     if ($objCollection !== null) {
         while ($objCollection->next()) {
             if ($objCollection->getTable() !== $objModel->getTable) {
                 return $objCollection;
             }
             $intId = $objCollection->{$objModel::getPk()};
             $arrRegistered[$intId] = $objCollection->current();
         }
     }
     $arrRegistered[$objModel->{$objModel::getPk()}] = $objModel;
     return static::createCollection(array_filter(array_values($arrRegistered)), $objModel->getTable());
 }
 public static function parseCredits(\Model\Collection $objModels, array $arrPids = array(), $objModule)
 {
     $arrCredits = array();
     while ($objModels->next()) {
         if (($strReturn = static::parseCredit($objModels->current(), $arrPids, $objModule)) === null) {
             continue;
         }
         $arrCredits[] = $strReturn;
     }
     $arrCredits = static::sortCredits($arrCredits, $objModule->creditsSortBy);
     $arrCredits = static::groupCredits($arrCredits, $objModule->creditsGroupBy);
     $arrCredits = array_map(function ($value) use(&$arrCredit) {
         return $value['output'];
     }, $arrCredits);
     return $arrCredits;
 }
示例#5
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $intActive = null;
     $articles = array();
     $intCount = 1;
     while ($this->objArticles->next()) {
         /** @var \ArticleModel $objArticle */
         $objArticle = $this->objArticles->current();
         $strAlias = $objArticle->alias != '' && !\Config::get('disableAlias') ? $objArticle->alias : $objArticle->id;
         // Active article
         if (\Input::get('articles') == $strAlias) {
             $articles[] = array('isActive' => true, 'href' => $this->generateFrontendUrl($objPage->row(), '/articles/' . $strAlias), 'title' => specialchars($objArticle->title, true), 'link' => $intCount);
             $intActive = $intCount - 1;
         } else {
             $articles[] = array('isActive' => false, 'href' => $this->generateFrontendUrl($objPage->row(), '/articles/' . $strAlias), 'title' => specialchars($objArticle->title, true), 'link' => $intCount);
         }
         ++$intCount;
     }
     $this->Template->articles = $articles;
     $total = count($articles);
     // Link to first element
     if ($intActive > 1) {
         $this->Template->first = array('href' => $articles[0]['href'], 'title' => $articles[0]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['first']);
     }
     $key = $intActive - 1;
     // Link to previous element
     if ($intCount > 1 && $key >= 0) {
         $this->Template->previous = array('href' => $articles[$key]['href'], 'title' => $articles[$key]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['previous']);
     }
     $key = $intActive + 1;
     // Link to next element
     if ($intCount > 1 && $key < $total) {
         $this->Template->next = array('href' => $articles[$key]['href'], 'title' => $articles[$key]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['next']);
     }
     $key = $total - 1;
     // Link to last element
     if ($intCount > 1 && $intActive < $key - 1) {
         $this->Template->last = array('href' => $articles[$key]['href'], 'title' => $articles[$key]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['last']);
     }
 }
示例#6
0
 protected function buildOptions(\Model\Collection $collection)
 {
     while ($collection->next()) {
         $theme = \ThemeModel::findByPk($collection->pid);
         switch ($collection->type) {
             case 'code':
                 $label = $collection->code_snippet_title;
                 break;
             case 'url':
                 $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $collection->url);
                 break;
             case 'file':
                 if ($collection->filesource == $GLOBALS['TL_CONFIG']['uploadPath'] && version_compare(VERSION, '3', '>=')) {
                     $file = version_compare(VERSION, '3.2', '>=') ? \FilesModel::findByUuid($collection->file) : \FilesModel::findByPk($collection->file);
                     if ($file) {
                         $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $file->path);
                         break;
                     }
                 } else {
                     $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $collection->file);
                     break;
                 }
                 // no break
             // no break
             default:
                 $label = '?';
         }
         if (strlen($collection->cc)) {
             $label .= ' <span style="padding-left: 3px; color: #B3B3B3;">[' . $collection->cc . ']</span>';
         }
         $filterRules = File::renderFilterRules($collection->row());
         if ($filterRules) {
             $label .= ' <span style="padding-left: 3px; color: #B3B3B3;">' . $filterRules . '</span>';
         }
         $image = 'assets/theme-plus/images/' . $collection->type . '.png';
         $options[$theme->name][$collection->id] = ($image ? $this->generateImage($image, $label, 'style="vertical-align:-3px"') . ' ' : '') . $label;
     }
     return $options;
 }
    /**
     * Find active layers.
     *
     * @return Collection|null
     */
    public function findActiveLayers()
    {
        $query = <<<SQL
SELECT    l.*, c.mode as controlMode
FROM      tl_leaflet_layer l
LEFT JOIN tl_leaflet_control_layer
c ON      l.id = c.lid
WHERE     c.cid=? AND l.active=1
SQL;
        $result = \Database::getInstance()->prepare($query)->execute($this->id);
        if ($result->numRows < 1) {
            return null;
        }
        return Collection::createFromDbResult($result, 'tl_leaflet_layer');
    }
示例#8
0
    /**
     * Find all active layers.
     *
     * @return Collection|null
     */
    public function findActiveLayers()
    {
        $query = <<<SQL
SELECT    l.*
FROM      tl_leaflet_layer l
LEFT JOIN tl_leaflet_map_layer m
ON        l.id = m.lid
WHERE     m.mid=? AND l.active=1
SQL;
        $result = \Database::getInstance()->prepare($query)->execute($this->id);
        if ($result->numRows) {
            return Collection::createFromDbResult($result, 'tl_leaflet_layer');
        }
        return null;
    }
示例#9
0
 /**
  * Parse one or more items and return them as array
  *
  * @param \Model\Collection $objArticles
  * @param boolean           $blnAddArchive
  *
  * @return array
  */
 protected function parseArticles($objArticles, $blnAddArchive = false)
 {
     $limit = $objArticles->count();
     if ($limit < 1) {
         return array();
     }
     $count = 0;
     $arrArticles = array();
     while ($objArticles->next()) {
         /** @var \NewsModel $objArticle */
         $objArticle = $objArticles->current();
         $arrArticles[] = $this->parseArticle($objArticle, $blnAddArchive, (++$count == 1 ? ' first' : '') . ($count == $limit ? ' last' : '') . ($count % 2 == 0 ? ' odd' : ' even'), $count);
     }
     return $arrArticles;
 }
 public function add(array $attributes)
 {
     $tag = parent::add($attributes);
     $this->cache[$tag->getId()] = $tag;
     return $tag;
 }
示例#11
0
文件: Rule.php 项目: Aziz-JH/core
 /**
  * Fetch rules
  */
 protected static function findByConditions($arrProcedures, $arrValues = array(), $arrProducts = null, $blnIncludeVariants = false, $arrAttributeData = array())
 {
     // Only enabled rules
     $arrProcedures[] = "enabled='1'";
     // Date & Time restrictions
     $date = date('Y-m-d');
     $time = date('H:i:s');
     $arrProcedures[] = "(startDate='' OR startDate <= UNIX_TIMESTAMP('{$date}'))";
     $arrProcedures[] = "(endDate='' OR endDate >= UNIX_TIMESTAMP('{$date}'))";
     $arrProcedures[] = "(startTime='' OR startTime <= UNIX_TIMESTAMP('1970-01-01 {$time}'))";
     $arrProcedures[] = "(endTime='' OR endTime >= UNIX_TIMESTAMP('1970-01-01 {$time}'))";
     // Limits
     $arrProcedures[] = "(limitPerConfig=0 OR limitPerConfig>(SELECT COUNT(*) FROM tl_iso_rule_usage WHERE pid=r.id AND config_id=" . (int) Isotope::getConfig()->id . " AND order_id NOT IN (SELECT id FROM tl_iso_product_collection WHERE type='order' AND source_collection_id=" . (int) Isotope::getCart()->id . ")))";
     if (Isotope::getCart()->member > 0) {
         $arrProcedures[] = "(limitPerMember=0 OR limitPerMember>(SELECT COUNT(*) FROM tl_iso_rule_usage WHERE pid=r.id AND member_id=" . (int) \FrontendUser::getInstance()->id . " AND order_id NOT IN (SELECT id FROM tl_iso_product_collection WHERE type='order' AND source_collection_id=" . (int) Isotope::getCart()->id . ")))";
     }
     // Store config restrictions
     $arrProcedures[] = "(configRestrictions=''\n                            OR (configRestrictions='1' AND configCondition='1' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='configs' AND object_id=" . (int) Isotope::getConfig()->id . ")>0)\n                            OR (configRestrictions='1' AND configCondition='0' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='configs' AND object_id=" . (int) Isotope::getConfig()->id . ")=0))";
     // Member restrictions
     if (Isotope::getCart()->member > 0) {
         $arrGroups = array_map('intval', deserialize(\FrontendUser::getInstance()->groups, true));
         $arrProcedures[] = "(memberRestrictions='none'\n                                OR (memberRestrictions='guests' AND memberCondition='0')\n                                OR (memberRestrictions='members' AND memberCondition='1' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='members' AND object_id=" . (int) \FrontendUser::getInstance()->id . ")>0)\n                                OR (memberRestrictions='members' AND memberCondition='0' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='members' AND object_id=" . (int) \FrontendUser::getInstance()->id . ")=0)\n                                " . (!empty($arrGroups) ? "\n                                OR (memberRestrictions='groups' AND memberCondition='1' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='groups' AND object_id IN (" . implode(',', $arrGroups) . "))>0)\n                                OR (memberRestrictions='groups' AND memberCondition='0' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='groups' AND object_id IN (" . implode(',', $arrGroups) . "))=0)" : '') . ")";
     } else {
         $arrProcedures[] = "(memberRestrictions='none' OR (memberRestrictions='guests' AND memberCondition='1'))";
     }
     // Product restrictions
     if (!is_array($arrProducts)) {
         $arrProducts = Isotope::getCart()->getItems();
     }
     if (!empty($arrProducts)) {
         $arrProductIds = array(0);
         $arrVariantIds = array(0);
         $arrAttributes = array(0);
         $arrTypes = array(0);
         // Prepare product attribute condition
         $objAttributeRules = \Database::getInstance()->execute("SELECT * FROM " . static::$strTable . " WHERE enabled='1' AND productRestrictions='attribute' AND attributeName!='' GROUP BY attributeName, attributeCondition");
         while ($objAttributeRules->next()) {
             $arrAttributes[] = array('attribute' => $objAttributeRules->attributeName, 'condition' => $objAttributeRules->attributeCondition, 'values' => array());
         }
         foreach ($arrProducts as $objProduct) {
             if ($objProduct instanceof ProductCollectionItem) {
                 if (!$objProduct->hasProduct()) {
                     continue;
                 }
                 $objProduct = $objProduct->getProduct();
             }
             $arrProductIds[] = (int) $objProduct->getProductId();
             $arrVariantIds[] = (int) $objProduct->{$objProduct->getPk()};
             $arrTypes[] = (int) $objProduct->type;
             if ($objProduct->isVariant()) {
                 $arrVariantIds[] = (int) $objProduct->pid;
             }
             if ($blnIncludeVariants && $objProduct->hasVariants()) {
                 $arrVariantIds = array_merge($arrVariantIds, $objProduct->getVariantIds());
             }
             $arrOptions = $objProduct->getOptions();
             foreach ($arrAttributes as $k => $restriction) {
                 $varValue = null;
                 if (isset($arrAttributeData[$restriction['attribute']])) {
                     $varValue = $arrAttributeData[$restriction['attribute']];
                 } elseif (isset($arrOptions[$restriction['attribute']])) {
                     $varValue = $arrOptions[$restriction['attribute']];
                 } else {
                     $varValue = $objProduct->{$restriction['attribute']};
                 }
                 if (!is_null($varValue)) {
                     $arrAttributes[$k]['values'][] = is_array($varValue) ? serialize($varValue) : $varValue;
                 }
             }
         }
         $arrProductIds = array_unique($arrProductIds);
         $arrVariantIds = array_unique($arrVariantIds);
         $arrRestrictions = array("productRestrictions='none'");
         $arrRestrictions[] = "(productRestrictions='producttypes' AND productCondition='1' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='producttypes' AND object_id IN (" . implode(',', $arrTypes) . "))>0)";
         $arrRestrictions[] = "(productRestrictions='producttypes' AND productCondition='0' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='producttypes' AND object_id IN (" . implode(',', $arrTypes) . "))=0)";
         $arrRestrictions[] = "(productRestrictions='products' AND productCondition='1' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='products' AND object_id IN (" . implode(',', $arrProductIds) . "))>0)";
         $arrRestrictions[] = "(productRestrictions='products' AND productCondition='0' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='products' AND object_id IN (" . implode(',', $arrProductIds) . "))=0)";
         $arrRestrictions[] = "(productRestrictions='variants' AND productCondition='1' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='variants' AND object_id IN (" . implode(',', $arrVariantIds) . "))>0)";
         $arrRestrictions[] = "(productRestrictions='variants' AND productCondition='0' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='variants' AND object_id IN (" . implode(',', $arrVariantIds) . "))=0)";
         $arrRestrictions[] = "(productRestrictions='pages' AND productCondition='1' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='pages' AND object_id IN (SELECT page_id FROM " . \Isotope\Model\ProductCategory::getTable() . " WHERE pid IN (" . implode(',', $arrProductIds) . ")))>0)";
         $arrRestrictions[] = "(productRestrictions='pages' AND productCondition='0' AND (SELECT COUNT(*) FROM tl_iso_rule_restriction WHERE pid=r.id AND type='pages' AND object_id IN (SELECT page_id FROM " . \Isotope\Model\ProductCategory::getTable() . " WHERE pid IN (" . implode(',', $arrProductIds) . ")))=0)";
         foreach ($arrAttributes as $restriction) {
             if (empty($restriction['values'])) {
                 continue;
             }
             $strRestriction = "(productRestrictions='attribute' AND attributeName='" . $restriction['attribute'] . "' AND attributeCondition='" . $restriction['condition'] . "' AND ";
             switch ($restriction['condition']) {
                 case 'eq':
                 case 'neq':
                     $strRestriction .= "attributeValue" . ($restriction['condition'] == 'neq' ? " NOT" : '') . " IN ('" . implode("','", array_map('mysql_real_escape_string', $restriction['values'])) . "')";
                     break;
                 case 'lt':
                 case 'gt':
                 case 'elt':
                 case 'egt':
                     $arrOR = array();
                     foreach ($restriction['values'] as $value) {
                         $arrOR[] = "attributeValue" . ($restriction['condition'] == 'lt' || $restriction['condition'] == 'elt' ? '>' : '<') . ($restriction['condition'] == 'elt' || $restriction['condition'] == 'egt' ? '=' : '') . '?';
                         $arrValues[] = $value;
                     }
                     $strRestriction .= '(' . implode(' OR ', $arrOR) . ')';
                     break;
                 case 'starts':
                 case 'ends':
                 case 'contains':
                     $arrOR = array();
                     foreach ($restriction['values'] as $value) {
                         $arrOR[] = "? LIKE CONCAT(" . ($restriction['condition'] == 'ends' || $restriction['condition'] == 'contains' ? "'%', " : '') . "attributeValue" . ($restriction['condition'] == 'starts' || $restriction['condition'] == 'contains' ? ", '%'" : '') . ")";
                         $arrValues[] = $value;
                     }
                     $strRestriction .= '(' . implode(' OR ', $arrOR) . ')';
                     break;
                 default:
                     throw new \InvalidArgumentException('Unknown rule condition "' . $restriction['condition'] . '"');
             }
             $arrRestrictions[] = $strRestriction . ')';
         }
         $arrProcedures[] = '(' . implode(' OR ', $arrRestrictions) . ')';
     }
     $objResult = \Database::getInstance()->prepare("SELECT * FROM " . static::$strTable . " r WHERE " . implode(' AND ', $arrProcedures))->execute($arrValues);
     if ($objResult->numRows) {
         return \Model\Collection::createFromDbResult($objResult, static::$strTable);
     }
     return null;
 }
 public function __construct(Factory $factory, TagFactory $tagFactory)
 {
     parent::__construct($factory);
     $this->tagFactory = $tagFactory;
 }
 /**
  * Find published news categories by parent ID and IDs
  *
  * @param integer $intPid The parent ID
  * @param array   $arrIds An array of categories
  *
  * @return \Model|null The NewsModelCategpry or null if there are no categories
  */
 public static function findPublishedByPidAndIds($intPid, $arrIds)
 {
     if (!is_array($arrIds) || empty($arrIds)) {
         return null;
     }
     $objCategories = \Database::getInstance()->prepare("SELECT c1.*, (SELECT COUNT(*) FROM tl_news_category c2 WHERE c2.pid=c1.id AND c2.id IN (" . implode(',', array_map('intval', $arrIds)) . ")" . (!BE_USER_LOGGED_IN ? " AND c2.published=1" : "") . ") AS subcategories FROM tl_news_category c1 WHERE c1.pid=? AND c1.id IN (" . implode(',', array_map('intval', $arrIds)) . ")" . (!BE_USER_LOGGED_IN ? " AND c1.published=1" : "") . " ORDER BY c1.sorting")->execute($intPid);
     if ($objCategories->numRows < 1) {
         return null;
     }
     return \Model\Collection::createFromDbResult($objCategories, static::$strTable);
 }
 protected static function indexFiles(\Model\Collection $objFiles)
 {
     $blnCheck = true;
     while ($objFiles->next()) {
         $return = static::indexFile($objFiles->current());
         $blnCheck = !$blnCheck ?: $return;
     }
     return $blnCheck;
 }
示例#15
0
文件: Slider.php 项目: GerqEV/cdemo2
    /**
     * Parse slides
     *
     * @param  \Model\Collection $objSlides slides retrieved from the database
     * @return array                        parsed slides
     */
    protected function parseSlides($objSlides)
    {
        global $objPage;
        $slides = array();
        $pids = array();
        $idIndexes = array();
        if (!$objSlides) {
            return $slides;
        }
        while ($objSlides->next()) {
            $slide = $objSlides->row();
            $slide['text'] = '';
            $pids[] = $slide['id'];
            $idIndexes[(int) $slide['id']] = count($slides);
            if (trim($slide['singleSRC']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['singleSRC']) : \FilesModel::findByUuid($slide['singleSRC'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) {
                $meta = $this->getMetaData($file->meta, $objPage->language);
                $slide['image'] = new \stdClass();
                $this->addImageToTemplate($slide['image'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'alt' => $meta['title'], 'imageUrl' => $meta['link'], 'caption' => $meta['caption'], 'size' => isset($this->imgSize) ? $this->imgSize : $this->size));
            }
            if ($slide['videoURL'] && empty($slide['image'])) {
                $slide['image'] = new \stdClass();
                if (preg_match('(^
						https?://  # http or https
						(?:
							www\\.youtube\\.com/(?:watch\\?v=|v/|embed/)  # Different URL formats
							| youtu\\.be/  # Short YouTube domain
						)
						([0-9a-z_\\-]{11})  # YouTube ID
						(?:$|&|/)  # End or separator
					)ix', html_entity_decode($slide['videoURL']), $matches)) {
                    $video = $matches[1];
                    $slide['image']->src = '//img.youtube.com/vi/' . $video . '/0.jpg';
                } else {
                    // Grey dummy image
                    $slide['image']->src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAJCAMAAAAM9FwAAAAAA1BMVEXGxsbd/8BlAAAAFUlEQVR42s3BAQEAAACAkP6vdiO6AgCZAAG/wrlvAAAAAElFTkSuQmCC';
                }
                $slide['image']->imgSize = '';
                $slide['image']->alt = '';
                if (version_compare(VERSION, '3.4', '>=')) {
                    $slide['image']->picture = array('img' => array('src' => $slide['image']->src, 'srcset' => $slide['image']->src), 'sources' => array());
                }
            }
            if ($slide['videos']) {
                $videoFiles = deserialize($slide['videos'], true);
                if (version_compare(VERSION, '3.2', '<')) {
                    $videoFiles = \FilesModel::findMultipleByIds($videoFiles);
                } else {
                    $videoFiles = \FilesModel::findMultipleByUuids($videoFiles);
                }
                $videos = array();
                foreach ($videoFiles as $file) {
                    $videos[] = $file;
                }
                $slide['videos'] = $videos;
            }
            if (trim($slide['backgroundImage']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['backgroundImage']) : \FilesModel::findByUuid($slide['backgroundImage'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) {
                $meta = $this->getMetaData($file->meta, $objPage->language);
                $slide['backgroundImage'] = new \stdClass();
                $this->addImageToTemplate($slide['backgroundImage'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'alt' => $meta['title'], 'imageUrl' => $meta['link'], 'caption' => $meta['caption'], 'size' => $slide['backgroundImageSize']));
            } else {
                $slide['backgroundImage'] = null;
            }
            if ($slide['backgroundVideos']) {
                $videoFiles = deserialize($slide['backgroundVideos'], true);
                if (version_compare(VERSION, '3.2', '<')) {
                    $videoFiles = \FilesModel::findMultipleByIds($videoFiles);
                } else {
                    $videoFiles = \FilesModel::findMultipleByUuids($videoFiles);
                }
                $videos = array();
                foreach ($videoFiles as $file) {
                    $videos[] = $file;
                }
                $slide['backgroundVideos'] = $videos;
            }
            if ($this->rsts_navType === 'thumbs') {
                $slide['thumb'] = new \stdClass();
                if (trim($slide['thumbImage']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['thumbImage']) : \FilesModel::findByUuid($slide['thumbImage'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) {
                    $this->addImageToTemplate($slide['thumb'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'size' => $this->rsts_thumbs_imgSize));
                } elseif (trim($slide['singleSRC']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['singleSRC']) : \FilesModel::findByUuid($slide['singleSRC'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) {
                    $this->addImageToTemplate($slide['thumb'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'size' => $this->rsts_thumbs_imgSize));
                } elseif (!empty($slide['image']->src)) {
                    $slide['thumb'] = clone $slide['image'];
                } elseif (!empty($slide['backgroundImage']->src)) {
                    $slide['thumb'] = clone $slide['backgroundImage'];
                }
            }
            $slides[] = $slide;
        }
        $slideContents = ContentModel::findPublishedByPidsAndTable($pids, SlideModel::getTable());
        if ($slideContents) {
            while ($slideContents->next()) {
                $slides[$idIndexes[(int) $slideContents->pid]]['text'] .= $this->getContentElement($slideContents->current());
            }
        }
        return $slides;
    }
示例#16
0
 /**
  * Create a new collection from a database result
  *
  * @param Database\Result $objResult The database result object
  * @param string          $strTable  The table name
  *
  * @return Model\Collection The model collection
  */
 protected static function createCollectionFromDbResult(Database\Result $objResult, $strTable)
 {
     return \Model\Collection::createFromDbResult($objResult, $strTable);
 }
 /**
  * Find published news categories by parent ID and IDs
  *
  * @param integer $intPid The parent ID
  * @param array   $arrIds An array of categories
  *
  * @return \Model|null The NewsModelCategpry or null if there are no categories
  */
 public static function findPublishedByPidAndIds($intPid, $arrIds)
 {
     if (!is_array($arrIds) || empty($arrIds)) {
         return null;
     }
     $arrLanguageFields = \MultilingualQueryBuilder::getMultilingualFields(static::$strTable);
     $strPid = \DC_Multilingual::getPidColumnForTable(static::$strTable);
     $strLang = \DC_Multilingual::getLanguageColumnForTable(static::$strTable);
     $objCategories = \Database::getInstance()->prepare("SELECT c1.*\n                " . (!empty($arrLanguageFields) ? ", " . implode(", ", \MultilingualQueryBuilder::generateFieldsSubquery($arrLanguageFields, 'c1', 'dcm2')) : "") . "\n                , (SELECT COUNT(*) FROM tl_news_category c2 WHERE c2.pid=c1.id AND c2.id IN (" . implode(',', array_map('intval', $arrIds)) . ")" . (!BE_USER_LOGGED_IN ? " AND c2.published=1" : "") . ") AS subcategories\n                FROM tl_news_category c1\n                " . (!empty($arrLanguageFields) ? " LEFT OUTER JOIN " . static::$strTable . " AS dcm2 ON (c1.id=dcm2." . $strPid . " AND dcm2.{$strLang}='" . $GLOBALS['TL_LANGUAGE'] . "')" : "") . "\n                WHERE c1.pid=? AND c1." . $strPid . "=0 AND c1.id IN (" . implode(',', array_map('intval', $arrIds)) . ")" . (!BE_USER_LOGGED_IN ? " AND c1.published=1" : "") . " ORDER BY c1.sorting")->execute($intPid);
     if ($objCategories->numRows < 1) {
         return null;
     }
     return \Model\Collection::createFromDbResult($objCategories, static::$strTable);
 }