Beispiel #1
0
 /**
  * Load a set of DCA files
  *
  * @param boolean $blnNoCache If true, the cache will be bypassed
  */
 public function load($blnNoCache = false)
 {
     // Return if the data has been loaded already
     if (isset($GLOBALS['loadDataContainer'][$this->strTable]) && !$blnNoCache) {
         return;
     }
     $GLOBALS['loadDataContainer'][$this->strTable] = true;
     // see #6145
     $strCacheFile = 'system/cache/dca/' . $this->strTable . '.php';
     // Try to load from cache
     if (!\Config::get('bypassCache') && file_exists(TL_ROOT . '/' . $strCacheFile)) {
         include TL_ROOT . '/' . $strCacheFile;
     } else {
         foreach (\ModuleLoader::getActive() as $strModule) {
             $strFile = 'system/modules/' . $strModule . '/dca/' . $this->strTable . '.php';
             if (file_exists(TL_ROOT . '/' . $strFile)) {
                 include TL_ROOT . '/' . $strFile;
             }
         }
     }
     // HOOK: allow to load custom settings
     if (isset($GLOBALS['TL_HOOKS']['loadDataContainer']) && is_array($GLOBALS['TL_HOOKS']['loadDataContainer'])) {
         foreach ($GLOBALS['TL_HOOKS']['loadDataContainer'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($this->strTable);
         }
     }
     // Local configuration file
     if (file_exists(TL_ROOT . '/system/config/dcaconfig.php')) {
         include TL_ROOT . '/system/config/dcaconfig.php';
     }
 }
Beispiel #2
0
 /**
  * Return all excluded fields as HTML drop down menu
  *
  * @return array
  */
 public function getExcludedFields()
 {
     $included = array();
     foreach (ModuleLoader::getActive() as $strModule) {
         $strDir = 'system/modules/' . $strModule . '/dca';
         if (!is_dir(TL_ROOT . '/' . $strDir)) {
             continue;
         }
         foreach (scan(TL_ROOT . '/' . $strDir) as $strFile) {
             // Ignore non PHP files and files which have been included before
             if (substr($strFile, -4) != '.php' || in_array($strFile, $included)) {
                 continue;
             }
             $included[] = $strFile;
             $strTable = substr($strFile, 0, -4);
             System::loadLanguageFile($strTable);
             $this->loadDataContainer($strTable);
         }
     }
     $arrReturn = array();
     // Get all excluded fields
     foreach ($GLOBALS['TL_DCA'] as $k => $v) {
         if (is_array($v['fields'])) {
             foreach ($v['fields'] as $kk => $vv) {
                 if ($vv['exclude'] || $vv['orig_exclude']) {
                     $arrReturn[$k][specialchars($k . '::' . $kk)] = $vv['label'][0] ?: $kk;
                 }
             }
         }
     }
     ksort($arrReturn);
     return $arrReturn;
 }
 /**
  * Send a registration e-mail
  * @param integer
  * @param array
  * @param object
  */
 public function sendRegistrationEmail($intId, $arrData, &$objModule)
 {
     if (!$objModule->nc_notification) {
         return;
     }
     $arrTokens = array();
     $arrTokens['admin_email'] = $GLOBALS['TL_ADMIN_EMAIL'];
     $arrTokens['domain'] = \Environment::get('host');
     $arrTokens['link'] = \Environment::get('base') . \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $arrData['activation'];
     // Support newsletters
     if (in_array('newsletter', \ModuleLoader::getActive())) {
         if (!is_array($arrData['newsletter'])) {
             if ($arrData['newsletter'] != '') {
                 $objChannels = \Database::getInstance()->execute("SELECT title FROM tl_newsletter_channel WHERE id IN(" . implode(',', array_map('intval', (array) $arrData['newsletter'])) . ")");
                 $arrTokens['member_newsletter'] = implode("\n", $objChannels->fetchEach('title'));
             } else {
                 $arrTokens['member_newsletter'] = '';
             }
         }
     }
     // translate/format values
     foreach ($arrData as $strFieldName => $strFieldValue) {
         $arrTokens['member_' . $strFieldName] = \Haste\Util\Format::dcaValue('tl_member', $strFieldName, $strFieldValue);
     }
     $objNotification = \NotificationCenter\Model\Notification::findByPk($objModule->nc_notification);
     if ($objNotification !== null) {
         $objNotification->send($arrTokens);
         // Disable the email to admin because no core notification has been sent
         $objModule->reg_activate = true;
     }
 }
 protected function afterSubmitCallback(\DataContainer $dc)
 {
     // remove previously created locks
     if (in_array('entity_lock', \ModuleLoader::getActive()) && $this->addEntityLock) {
         \HeimrichHannot\EntityLock\EntityLockModel::deleteLocks($this->formHybridDataContainer, $this->intId);
     }
 }
 protected function buildFileDir($objEntity = null)
 {
     if ($this->fileDir && ($objFolder = \FilesModel::findByUuid($this->fileDir))) {
         $objMember = \FrontendUser::getInstance();
         $strDir = $objFolder->path;
         if ($this->useHomeDir && FE_USER_LOGGED_IN && $objMember->assignDir && $objMember->homeDir) {
             $strDir = Files::getPathFromUuid($objMember->homeDir);
         }
         if (in_array('protected_homedirs', \ModuleLoader::getActive())) {
             if ($this->useProtectedHomeDir && $objMember->assignProtectedDir && $objMember->protectedHomeDir) {
                 $strDir = Files::getPathFromUuid($objMember->protectedHomeDir);
             }
         }
         if ($this->fileSubDirName) {
             $strDir .= '/' . $this->fileSubDirName;
         }
         if (isset($GLOBALS['TL_HOOKS']['exporter_modifyFileDir']) && is_array($GLOBALS['TL_HOOKS']['exporter_modifyFileDir'])) {
             foreach ($GLOBALS['TL_HOOKS']['exporter_modifyFileDir'] as $callback) {
                 $objCallback = \System::importStatic($callback[0]);
                 $strFixedDir = $objCallback->{$callback}[1]($strDir, $this);
                 $strDir = $strFixedDir ?: $strDir;
             }
         }
         return $strDir;
     }
     throw new \Exception('No exporter fileDir defined!');
 }
Beispiel #6
0
 /**
  * Check permissions to edit table tl_faq
  */
 public function checkPermission()
 {
     // HOOK: comments extension required
     if (!in_array('comments', ModuleLoader::getActive())) {
         $key = array_search('allowComments', $GLOBALS['TL_DCA']['tl_faq']['list']['sorting']['headerFields']);
         unset($GLOBALS['TL_DCA']['tl_faq']['list']['sorting']['headerFields'][$key]);
     }
 }
 /**
  * Return true if the notification_center is installed and can be supported
  *
  * @param bool $checkOptions Enable to check for available form notifications
  *
  * @return bool
  */
 public static function available($checkOptions = false)
 {
     $result = in_array('notification_center', \ModuleLoader::getActive());
     if ($result && $checkOptions && \NotificationCenter\Model\Notification::countBy('type', 'core_form') === 0) {
         $result = false;
     }
     return $result;
 }
 /**
  * Disable inactive modules.
  *
  * @return void
  */
 private function disableInactiveModules()
 {
     $disabled = deserialize(\Config::get('inactiveModules'), true);
     $active = \ModuleLoader::getActive();
     foreach ($disabled as $module) {
         if (in_array($module, $active)) {
             new \File(sprintf('system/modules/%s/.skip', $module));
         }
     }
 }
 public function modifyDC(&$arrDca = null)
 {
     foreach ($this->arrEditable as $strField) {
         if (in_array('bootstrapper', \ModuleLoader::getActive())) {
             $arrDca['fields'][$strField]['eval']['invisible'] = true;
         } else {
             $arrDca['fields'][$strField]['inputType'] = 'hidden';
         }
     }
 }
 protected function runAfterSaving(&$objItem, $objTypoItem)
 {
     $objItem->alias = $this->generateAlias($objItem->alias ? $objItem->alias : $objItem->headline, $objItem);
     $objItem->source = 'default';
     $objItem->floating = 'above';
     $this->createContentElements($objItem);
     $this->createEnclosures($objItem);
     // news_categories module support
     if (in_array('news_categories', \ModuleLoader::getActive())) {
         $this->setCategories($objItem, $objTypoItem);
     }
     //		$objItem->teaser = "<p>" . strip_tags($objItem->teaser) . "</p>";
     $objItem->save();
 }
 /**
  * Export data
  *
  * @access		public
  * @param		string
  * @return		void
  */
 public static function run($dc = null, $strName = 'formsubmissions', $blnHeaders = true)
 {
     if (!in_array('!composer', \ModuleLoader::getActive())) {
         \Message::addError($GLOBALS['TL_LANG']['ERR']['exportExcelNoComposer']);
         \System::redirect(str_ireplace('&key=exportExcel', '', \Environment::get('request')));
         return;
     }
     if (!is_file(TL_ROOT . '/composer/vendor/phpoffice/phpexcel/Classes/PHPExcel.php')) {
         \Message::addError($GLOBALS['TL_LANG']['ERR']['exportExcelNoPHPExcel']);
         \System::redirect(str_ireplace('&key=exportExcel', '', \Environment::get('request')));
         return;
     }
     parent::run($dc, $strName, $blnHeaders);
 }
 public function modifyPalette()
 {
     $objModule = \ModuleModel::findByPk(\Input::get('id'));
     $arrDc =& $GLOBALS['TL_DCA']['tl_module'];
     // submission -> already done in formhybrid
     // confirmation
     $arrFieldsToHide = array('formHybridConfirmationMailSender', 'formHybridConfirmationMailSubject', 'formHybridConfirmationMailText', 'formHybridConfirmationMailTemplate', 'formHybridConfirmationMailAttachment');
     if (in_array('avisota-core', \ModuleLoader::getActive()) && $objModule->reg_activate_plus && $objModule->formHybridConfirmationAvisotaMessage) {
         $arrDc['subpalettes']['reg_activate_plus'] = str_replace($arrFieldsToHide, array_map(function () {
             return '';
         }, $arrFieldsToHide), $arrDc['subpalettes']['reg_activate_plus']);
         $arrDc['subpalettes']['reg_activate_plus'] = str_replace('formHybridConfirmationAvisotaMessage', 'formHybridConfirmationAvisotaMessage,formHybridConfirmationAvisotaSalutationGroup', $arrDc['subpalettes']['reg_activate_plus']);
     }
 }
 /**
  * Instantiate the object (Factory)
  *
  * @return \Files The files object
  */
 public static function getInstance()
 {
     if (self::$objInstance === null) {
         // Use FTP to modify files
         if (\Config::get('useFTP')) {
             self::$objInstance = new \Files\Ftp();
         } elseif (\Config::get('useSmhExtended') && in_array('smhextended', \ModuleLoader::getActive())) {
             self::$objInstance = new \SMHExtended();
         } else {
             self::$objInstance = new \Files\Php();
         }
     }
     return self::$objInstance;
 }
Beispiel #14
0
 /**
  * Load all data containers
  */
 protected function loadDataContainers()
 {
     foreach (\ModuleLoader::getActive() as $module) {
         $dir = 'system/modules/' . $module . '/dca';
         if (!is_dir(TL_ROOT . '/' . $dir)) {
             continue;
         }
         foreach (scan(TL_ROOT . '/' . $dir) as $file) {
             if (substr($file, -4) != '.php') {
                 continue;
             }
             \Controller::loadDataContainer(substr($file, 0, -4));
         }
     }
 }
 public function addTokens($objMessage, &$arrTokens, $strLanguage, $objGatewayModel)
 {
     if (!isset($arrTokens['salutation_user'])) {
         $arrTokens['salutation_user'] = static::createSalutation($strLanguage, \FrontendUser::getInstance());
     }
     if (!isset($arrTokens['salutation_form'])) {
         $arrTokens['salutation_form'] = static::createSalutation($strLanguage, array('gender' => $arrTokens['form_value_gender'], 'title' => $arrTokens['form_title'] ?: $arrTokens['form_academicTitle'], 'lastname' => $arrTokens['form_lastname']));
     }
     if (in_array('isotope', \ModuleLoader::getActive())) {
         if (!isset($arrTokens['billing_address_form'])) {
             $arrTokens['salutation_billing_address'] = static::createSalutation($strLanguage, array('gender' => $arrTokens['billing_address_gender'], 'title' => $arrTokens['billing_address_title'], 'lastname' => $arrTokens['billing_address_lastname']));
         }
     }
     $this->addContextTokens($objMessage, $arrTokens, $strLanguage);
     return true;
 }
 public function languageLabels($row, $label, $dc = null, $imageAttribute = '', $blnReturnImage = false, $blnProtected = false)
 {
     // generate the default label
     $objDcaClass = null;
     if (in_array('cacheicon', ModuleLoader::getActive())) {
         $objDcaClass = new tl_page_cacheicon();
     } elseif (in_array('Avisota', ModuleLoader::getActive())) {
         $objDcaClass = new tl_page_avisota();
     } else {
         $objDcaClass = new tl_page();
     }
     $label = $objDcaClass->addIcon($row, $label, $dc, $imageAttribute, $blnReturnImage, $blnProtected);
     // return the label for root or folder page
     if ($row['type'] == 'root' || $row['type'] == 'folder') {
         return $label;
     }
     // load the current page
     $objPage = PageModel::findWithDetails($row['id']);
     // prepare alternate pages
     $objAlternates = null;
     if ($objPage->languageMain) {
         // get all pages referencing the same fallback page
         $t = \PageModel::getTable();
         $objAlternates = PageModel::findBy(array("{$t}.languageMain = ? OR {$t}.id = ?"), array($objPage->languageMain, $objPage->languageMain));
     } else {
         // get all pages referencing the current page as its fallback
         $objAlternates = PageModel::findByLanguageMain($objPage->id);
     }
     // check if alternates were found
     if ($objAlternates !== null) {
         $label .= '<ul class="tl_page_language_alternates">';
         // go through each page and add link
         while ($objAlternates->next()) {
             if ($objAlternates->id == $objPage->id) {
                 continue;
             }
             $objAlternates->current()->loadDetails();
             $label .= '<li><a href="contao/main.php?do=page&amp;node=' . $objAlternates->id . '&amp;ref=' . TL_REFERER_ID . '">' . $objAlternates->language . '</a></li>';
         }
         $label .= '</ul>';
     }
     return $label;
 }
 public function modifyFieldPalette()
 {
     if (($objFieldPalette = \HeimrichHannot\FieldPalette\FieldPaletteModel::findByPk(\Input::get('id'))) === null) {
         return;
     }
     $objModule = \ModuleModel::findByPk($objFieldPalette->pid);
     $arrDca =& $GLOBALS['TL_DCA']['tl_fieldpalette'];
     switch ($objModule->type) {
         case 'iso_direct_checkout':
             if (in_array('isotope_plus', \ModuleLoader::getActive())) {
                 $arrDca['subpalettes']['iso_addSubscription'] = str_replace('iso_subscriptionArchive', 'iso_subscriptionArchive,iso_addSubscriptionCheckbox', $arrDca['subpalettes']['iso_addSubscription']);
             }
             // no break!
         // no break!
         case 'iso_checkout':
             if ($objFieldPalette->iso_addActivation) {
                 $arrDca['subpalettes']['iso_addSubscription'] = str_replace('iso_addActivation', 'iso_addActivation,iso_activationNotification,iso_activationJumpTo', $arrDca['subpalettes']['iso_addSubscription']);
             }
             break;
     }
 }
Beispiel #18
0
 /**
  * Return all template files of a particular group as array.
  *
  * @param string  $prefix  The string prefix to use.
  *
  * @param integer $themeId The theme in which to search.
  *
  * @return array
  */
 public static function getTemplateGroup($prefix, $themeId = 0)
 {
     $folders = array();
     // Add the templates root directory
     $folders['/templates'] = TL_ROOT . '/templates';
     // Add the theme templates folder
     if ($themeId > 0) {
         $resultSet = Database::getInstance()->prepare('SELECT templates FROM tl_theme WHERE id=?')->limit(1)->execute($themeId);
         if ($resultSet->numRows > 0 && $resultSet->templates != '') {
             $folders[$resultSet->title] = TL_ROOT . '/' . $resultSet->templates;
         }
     }
     // Add the module templates folders if they exist
     $activeModules = \ModuleLoader::getActive();
     foreach ($activeModules as $module) {
         $folder = TL_ROOT . '/system/modules/' . $module . '/templates';
         if (is_dir($folder)) {
             $folders['system/modules/' . $module] = $folder;
         }
     }
     return static::getTemplateGroupInFolders($prefix, $folders);
 }
 protected function generateFields($objItem)
 {
     $arrItem = parent::generateFields($objItem);
     if (in_array('member_content_archives', \ModuleLoader::getActive())) {
         $arrFilterTags = deserialize($this->memberContentArchiveTags, true);
         $arrItem['fields']['memberContent'] = '';
         if (($objMemberContentArchives = \HeimrichHannot\MemberContentArchives\MemberContentArchiveModel::findBy(array('mid=?', 'published=?'), array($objItem->memberId ?: $objItem->id, true))) !== null) {
             while ($objMemberContentArchives->next()) {
                 if (in_array($objMemberContentArchives->tag, $arrFilterTags)) {
                     $arrItem['fields']['memberContentId'] = $objMemberContentArchives->id;
                     $objElement = \ContentModel::findPublishedByPidAndTable($objMemberContentArchives->id, 'tl_member_content_archive');
                     if ($objElement !== null) {
                         while ($objElement->next()) {
                             $arrItem['fields']['memberContent'] .= \Controller::getContentElement($objElement->current());
                         }
                     }
                 }
             }
             if ($objMemberContentArchives->tag == $this->memberContentArchiveTeaserTag) {
                 $arrItem['fields']['memberContentTitle'] = $objMemberContentArchives->title;
                 $arrItem['fields']['memberContentTeaser'] = $objMemberContentArchives->teaser;
             }
             // override member fields
             $arrOverridableMemberFields = deserialize(\Config::get('overridableMemberFields'));
             if (!empty($arrOverridableMemberFields)) {
                 foreach ($arrOverridableMemberFields as $strField) {
                     $strFieldOverride = 'member' . ucfirst($strField);
                     if ($objMemberContentArchives->{$strFieldOverride}) {
                         if (\Validator::isUuid($objMemberContentArchives->{$strFieldOverride})) {
                             $objMemberContentArchives->{$strFieldOverride} = Files::getPathFromUuid($objMemberContentArchives->{$strFieldOverride});
                         }
                         $arrItem['fields'][$strField] = $objMemberContentArchives->{$strFieldOverride};
                     }
                 }
             }
         }
     }
     return $arrItem;
 }
 protected function parseItem($objItem, $strClass = '', $intCount = 0)
 {
     if (in_array('member_content_archives', \ModuleLoader::getActive())) {
         $arrFilterTags = deserialize($this->memberContentArchiveTags, true);
         $objItem->memberContent = '';
         if (($objMemberContentArchives = \HeimrichHannot\MemberContentArchives\MemberContentArchiveModel::findBy('mid', $objItem->memberId ?: $objItem->id)) !== null) {
             while ($objMemberContentArchives->next()) {
                 if (in_array($objMemberContentArchives->tag, $arrFilterTags)) {
                     $objItem->memberContentId = $objMemberContentArchives->id;
                     $objElement = \ContentModel::findPublishedByPidAndTable($objMemberContentArchives->id, 'tl_member_content_archive');
                     if ($objElement !== null) {
                         while ($objElement->next()) {
                             $objItem->memberContent .= \Controller::getContentElement($objElement->current());
                         }
                     }
                 }
             }
             if ($objMemberContentArchives->tag == $this->memberContentArchiveTeaserTag) {
                 $objItem->memberContentTitle = $objMemberContentArchives->title;
                 $objItem->memberContentTeaser = $objMemberContentArchives->teaser;
             }
             // override member fields
             $arrOverridableMemberFields = deserialize(\Config::get('overridableMemberFields'));
             if (!empty($arrOverridableMemberFields)) {
                 foreach ($arrOverridableMemberFields as $strField) {
                     $strFieldOverride = 'member' . ucfirst($strField);
                     if ($objMemberContentArchives->{$strFieldOverride}) {
                         if (\Validator::isUuid($objMemberContentArchives->{$strFieldOverride})) {
                             $objMemberContentArchives->{$strFieldOverride} = Files::getPathFromUuid($objMemberContentArchives->{$strFieldOverride});
                         }
                         $objItem->{$strField} = $objMemberContentArchives->{$strFieldOverride};
                     }
                 }
             }
         }
     }
     return parent::parseItem($objItem, $strClass, $intCount);
 }
 /**
  * getPageIdFromUrl Hook
  * checks if the URL fragment is a news alias and sets the page alias and auto item accordingly
  * @param array the URL fragments
  */
 public function getPageIdFromUrl($arrFragments)
 {
     // extract alias from fragments
     $alias = null;
     // handle special case with i18nl10n (see #4)
     if (in_array('i18nl10n', \ModuleLoader::getActive()) && count($arrFragments) == 3) {
         if ($arrFragments[0] == null && $arrFragments[1] == 'language') {
             $alias = $arrFragments[2];
         }
     } elseif (count($arrFragments) == 1) {
         $alias = $arrFragments[0];
     }
     // check if an alias was extracted
     if ($alias) {
         // check if news item exists
         if (($objNews = \NewsModel::findByAlias($alias)) !== null) {
             // check if jumpTo page exists
             if (($objTarget = \PageModel::findWithDetails($objNews->getRelated('pid')->jumpTo)) !== null) {
                 // check if target page is in the right language
                 if (\Config::get('addLanguageToUrl') && $objTarget->rootLanguage != \Input::get('language')) {
                     // return fragments without change
                     return $arrFragments;
                 }
                 // check if target page is in the right domain
                 if ($objTarget->domain && stripos(\Environment::get('host'), $objTarget->domain) === false) {
                     // return fragments without change
                     return $arrFragments;
                 }
                 // return changed fragments
                 return array($objTarget->alias, 'auto_item', $objNews->alias);
             }
         }
     }
     // return fragments without change
     return $arrFragments;
 }
    /**
     * Create a new template
     *
     * @return string
     */
    public function addNewTemplate()
    {
        $strError = '';
        // Copy an existing template
        if (Input::post('FORM_SUBMIT') == 'tl_create_template') {
            $strOriginal = Input::post('original');
            if (Validator::isInsecurePath($strOriginal)) {
                throw new RuntimeException('Invalid path ' . $strOriginal);
            }
            $strTarget = Input::post('target');
            if (Validator::isInsecurePath($strTarget)) {
                throw new RuntimeException('Invalid path ' . $strTarget);
            }
            // Validate the source path
            if (strncmp($strOriginal, 'system/modules/', 15) !== 0 || !file_exists(TL_ROOT . '/' . $strOriginal)) {
                $strError = sprintf($GLOBALS['TL_LANG']['tl_templates']['invalid'], $strOriginal);
            } else {
                // Validate the target path
                if (strncmp($strTarget, 'templates', 9) !== 0 || !is_dir(TL_ROOT . '/' . $strTarget)) {
                    $strError = sprintf($GLOBALS['TL_LANG']['tl_templates']['invalid'], $strTarget);
                } else {
                    $strTarget .= '/' . basename($strOriginal);
                    // Check whether the target file exists
                    if (file_exists(TL_ROOT . '/' . $strTarget)) {
                        $strError = sprintf($GLOBALS['TL_LANG']['tl_templates']['exists'], $strTarget);
                    } else {
                        $this->import('Files');
                        $this->Files->copy($strOriginal, $strTarget);
                        $this->redirect($this->getReferer());
                    }
                }
            }
        }
        $arrAllTemplates = array();
        $arrAllowed = trimsplit(',', Config::get('templateFiles'));
        // Get all templates
        foreach (ModuleLoader::getActive() as $strModule) {
            // Continue if there is no templates folder
            if ($strModule == 'repository' || !is_dir(TL_ROOT . '/system/modules/' . $strModule . '/templates')) {
                continue;
            }
            /** @var \SplFileInfo[] $objFiles */
            $objFiles = new SortedIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(TL_ROOT . '/system/modules/' . $strModule . '/templates', FilesystemIterator::UNIX_PATHS | FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::SKIP_DOTS)));
            foreach ($objFiles as $objFile) {
                $strExtension = pathinfo($objFile->getFilename(), PATHINFO_EXTENSION);
                if (in_array($strExtension, $arrAllowed)) {
                    $strRelpath = str_replace(TL_ROOT . '/', '', $objFile->getPathname());
                    $arrAllTemplates[$strModule][basename($strRelpath)] = $strRelpath;
                }
            }
        }
        $strAllTemplates = '';
        // Group the templates by module
        foreach ($arrAllTemplates as $k => $v) {
            $strAllTemplates .= '<optgroup label="' . $k . '">';
            foreach ($v as $kk => $vv) {
                $strAllTemplates .= sprintf('<option value="%s"%s>%s</option>', $vv, Input::post('original') == $vv ? ' selected="selected"' : '', $kk);
            }
            $strAllTemplates .= '</optgroup>';
        }
        // Show form
        return '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>' . ($strError != '' ? '

<div class="tl_message">
<p class="tl_error">' . $strError . '</p>
</div>' : '') . '

<form action="' . ampersand(Environment::get('request')) . '" id="tl_create_template" class="tl_form" method="post">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_create_template">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">
<div class="tl_tbox">
<div>
  <h3><label for="ctrl_original">' . $GLOBALS['TL_LANG']['tl_templates']['original'][0] . '</label></h3>
  <select name="original" id="ctrl_original" class="tl_select tl_chosen" onfocus="Backend.getScrollOffset()">' . $strAllTemplates . '</select>' . ($GLOBALS['TL_LANG']['tl_templates']['original'][1] && Config::get('showHelp') ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_templates']['original'][1] . '</p>' : '') . '
</div>
<div>
  <h3><label for="ctrl_target">' . $GLOBALS['TL_LANG']['tl_templates']['target'][0] . '</label></h3>
  <select name="target" id="ctrl_target" class="tl_select" onfocus="Backend.getScrollOffset()"><option value="templates">templates</option>' . $this->getTargetFolders('templates') . '</select>' . ($GLOBALS['TL_LANG']['tl_templates']['target'][1] && Config::get('showHelp') ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_templates']['target'][1] . '</p>' : '') . '
</div>
</div>
</div>

<div class="tl_formbody_submit">
<div class="tl_submit_container">
  <input type="submit" name="create" id="create" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['tl_templates']['newTpl']) . '">
</div>
</div>
</form>';
    }
 /**
  * Check permissions to edit table tl_calendar_events
  */
 public function checkPermission()
 {
     // HOOK: comments extension required
     if (!in_array('comments', ModuleLoader::getActive())) {
         $key = array_search('allowComments', $GLOBALS['TL_DCA']['tl_calendar_events']['list']['sorting']['headerFields']);
         unset($GLOBALS['TL_DCA']['tl_calendar_events']['list']['sorting']['headerFields'][$key]);
     }
     if ($this->User->isAdmin) {
         return;
     }
     // Set root IDs
     if (!is_array($this->User->calendars) || empty($this->User->calendars)) {
         $root = array(0);
     } else {
         $root = $this->User->calendars;
     }
     $id = strlen(Input::get('id')) ? Input::get('id') : CURRENT_ID;
     // Check current action
     switch (Input::get('act')) {
         case 'paste':
             // Allow
             break;
         case 'create':
             if (!strlen(Input::get('pid')) || !in_array(Input::get('pid'), $root)) {
                 $this->log('Not enough permissions to create events in calendar ID "' . Input::get('pid') . '"', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             }
             break;
         case 'cut':
         case 'copy':
             if (!in_array(Input::get('pid'), $root)) {
                 $this->log('Not enough permissions to ' . Input::get('act') . ' event ID "' . $id . '" to calendar ID "' . Input::get('pid') . '"', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             }
             // NO BREAK STATEMENT HERE
         // NO BREAK STATEMENT HERE
         case 'edit':
         case 'show':
         case 'delete':
         case 'toggle':
             $objCalendar = $this->Database->prepare("SELECT pid FROM tl_calendar_events WHERE id=?")->limit(1)->execute($id);
             if ($objCalendar->numRows < 1) {
                 $this->log('Invalid event ID "' . $id . '"', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             }
             if (!in_array($objCalendar->pid, $root)) {
                 $this->log('Not enough permissions to ' . Input::get('act') . ' event ID "' . $id . '" of calendar ID "' . $objCalendar->pid . '"', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             }
             break;
         case 'select':
         case 'editAll':
         case 'deleteAll':
         case 'overrideAll':
         case 'cutAll':
         case 'copyAll':
             if (!in_array($id, $root)) {
                 $this->log('Not enough permissions to access calendar ID "' . $id . '"', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             }
             $objCalendar = $this->Database->prepare("SELECT id FROM tl_calendar_events WHERE pid=?")->execute($id);
             if ($objCalendar->numRows < 1) {
                 $this->log('Invalid calendar ID "' . $id . '"', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             }
             $session = $this->Session->getData();
             $session['CURRENT']['IDS'] = array_intersect($session['CURRENT']['IDS'], $objCalendar->fetchEach('id'));
             $this->Session->setData($session);
             break;
         default:
             if (strlen(Input::get('act'))) {
                 $this->log('Invalid command "' . Input::get('act') . '"', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             } elseif (!in_array($id, $root)) {
                 $this->log('Not enough permissions to access calendar ID "' . $id . '"', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             }
             break;
     }
 }
Beispiel #24
0
 /**
  * Return all active modules as array
  *
  * @return array An array of active modules
  *
  * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0.
  *             Use the container parameter "kernel.bundles" instead.
  */
 public function getActiveModules()
 {
     trigger_error('Using Config::getActiveModules() has been deprecated and will no longer work in Contao 5.0. Use the container parameter "kernel.bundles" instead.', E_USER_DEPRECATED);
     return \ModuleLoader::getActive();
 }
Beispiel #25
0
 /**
  * Return all active modules as array
  *
  * @return array An array of active modules
  */
 public function getActiveModules()
 {
     return \ModuleLoader::getActive();
 }
 /**
  * Checks whether the extension 'htaccess' is installed and active.
  * @return True, if the extension 'htaccess' is installed and active.
  */
 public static function isHtaccessEnabled()
 {
     return in_array('htaccess', \ModuleLoader::getActive());
 }
 /**
  * Check permissions to edit table tl_news_archive
  */
 public function checkPermission()
 {
     // HOOK: comments extension required
     if (!in_array('comments', ModuleLoader::getActive())) {
         unset($GLOBALS['TL_DCA']['tl_news_archive']['fields']['allowComments']);
     }
     if ($this->User->isAdmin) {
         return;
     }
     // Set root IDs
     if (!is_array($this->User->news) || empty($this->User->news)) {
         $root = array(0);
     } else {
         $root = $this->User->news;
     }
     $GLOBALS['TL_DCA']['tl_news_archive']['list']['sorting']['root'] = $root;
     // Check permissions to add archives
     if (!$this->User->hasAccess('create', 'newp')) {
         $GLOBALS['TL_DCA']['tl_news_archive']['config']['closed'] = true;
     }
     // Check current action
     switch (Input::get('act')) {
         case 'create':
         case 'select':
             // Allow
             break;
         case 'edit':
             // Dynamically add the record to the user profile
             if (!in_array(Input::get('id'), $root)) {
                 $arrNew = $this->Session->get('new_records');
                 if (is_array($arrNew['tl_news_archive']) && in_array(Input::get('id'), $arrNew['tl_news_archive'])) {
                     // Add permissions on user level
                     if ($this->User->inherit == 'custom' || !$this->User->groups[0]) {
                         $objUser = $this->Database->prepare("SELECT news, newp FROM tl_user WHERE id=?")->limit(1)->execute($this->User->id);
                         $arrNewp = deserialize($objUser->newp);
                         if (is_array($arrNewp) && in_array('create', $arrNewp)) {
                             $arrNews = deserialize($objUser->news);
                             $arrNews[] = Input::get('id');
                             $this->Database->prepare("UPDATE tl_user SET news=? WHERE id=?")->execute(serialize($arrNews), $this->User->id);
                         }
                     } elseif ($this->User->groups[0] > 0) {
                         $objGroup = $this->Database->prepare("SELECT news, newp FROM tl_user_group WHERE id=?")->limit(1)->execute($this->User->groups[0]);
                         $arrNewp = deserialize($objGroup->newp);
                         if (is_array($arrNewp) && in_array('create', $arrNewp)) {
                             $arrNews = deserialize($objGroup->news);
                             $arrNews[] = Input::get('id');
                             $this->Database->prepare("UPDATE tl_user_group SET news=? WHERE id=?")->execute(serialize($arrNews), $this->User->groups[0]);
                         }
                     }
                     // Add new element to the user object
                     $root[] = Input::get('id');
                     $this->User->news = $root;
                 }
             }
             // No break;
         // No break;
         case 'copy':
         case 'delete':
         case 'show':
             if (!in_array(Input::get('id'), $root) || Input::get('act') == 'delete' && !$this->User->hasAccess('delete', 'newp')) {
                 $this->log('Not enough permissions to ' . Input::get('act') . ' news archive ID "' . Input::get('id') . '"', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             }
             break;
         case 'editAll':
         case 'deleteAll':
         case 'overrideAll':
             $session = $this->Session->getData();
             if (Input::get('act') == 'deleteAll' && !$this->User->hasAccess('delete', 'newp')) {
                 $session['CURRENT']['IDS'] = array();
             } else {
                 $session['CURRENT']['IDS'] = array_intersect($session['CURRENT']['IDS'], $root);
             }
             $this->Session->setData($session);
             break;
         default:
             if (strlen(Input::get('act'))) {
                 $this->log('Not enough permissions to ' . Input::get('act') . ' news archives', __METHOD__, TL_ERROR);
                 $this->redirect('contao/main.php?act=error');
             }
             break;
     }
 }
 /**
  * @return bool true if dlh_googlemaps is available, otherwise false
  */
 private static function init()
 {
     if (!in_array('dlh_googlemaps', \ModuleLoader::getActive())) {
         return false;
     }
     \Controller::loadLanguageFile('tl_dlh_googlemaps');
     return true;
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $this->Template->articles = '';
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     // Get the news item
     $objArticle = \NewsModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->news_archives);
     if (null === $objArticle) {
         /** @var \PageError404 $objHandler */
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
     }
     $arrArticle = $this->parseArticle($objArticle);
     $this->Template->articles = $arrArticle;
     // Overwrite the page title (see #2853 and #4955)
     if ($objArticle->headline != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($objArticle->headline));
     }
     // Overwrite the page description
     if ($objArticle->teaser != '') {
         $objPage->description = $this->prepareMetaDescription($objArticle->teaser);
     }
     // HOOK: comments extension required
     if ($objArticle->noComments || !in_array('comments', \ModuleLoader::getActive())) {
         $this->Template->allowComments = false;
         return;
     }
     /** @var \NewsArchiveModel $objArchive */
     $objArchive = $objArticle->getRelated('pid');
     $this->Template->allowComments = $objArchive->allowComments;
     // Comments are not allowed
     if (!$objArchive->allowComments) {
         return;
     }
     // Adjust the comments headline level
     $intHl = min(intval(str_replace('h', '', $this->hl)), 5);
     $this->Template->hlc = 'h' . ($intHl + 1);
     $this->import('Comments');
     $arrNotifies = array();
     // Notify the system administrator
     if ($objArchive->notify != 'notify_author') {
         $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
     }
     // Notify the author
     if ($objArchive->notify != 'notify_admin') {
         /** @var \UserModel $objAuthor */
         if (($objAuthor = $objArticle->getRelated('author')) !== null && $objAuthor->email != '') {
             $arrNotifies[] = $objAuthor->email;
         }
     }
     $objConfig = new \stdClass();
     $objConfig->perPage = $objArchive->perPage;
     $objConfig->order = $objArchive->sortOrder;
     $objConfig->template = $this->com_template;
     $objConfig->requireLogin = $objArchive->requireLogin;
     $objConfig->disableCaptcha = $objArchive->disableCaptcha;
     $objConfig->bbcode = $objArchive->bbcode;
     $objConfig->moderate = $objArchive->moderate;
     $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_news', $objArticle->id, $arrNotifies);
 }
Beispiel #30
0
 /**
  * Load a set of language files
  *
  * @param string  $strName     The table name
  * @param boolean $strLanguage An optional language code
  * @param boolean $blnNoCache  If true, the cache will be bypassed
  */
 public static function loadLanguageFile($strName, $strLanguage = null, $blnNoCache = false)
 {
     if ($strLanguage === null) {
         $strLanguage = str_replace('-', '_', $GLOBALS['TL_LANGUAGE']);
     }
     // Fall back to English
     if ($strLanguage == '') {
         $strLanguage = 'en';
     }
     // Return if the language file has been loaded already
     if (isset(static::$arrLanguageFiles[$strName][$strLanguage]) && !$blnNoCache) {
         return;
     }
     $strCacheKey = $strLanguage;
     // Make sure the language exists
     if (!static::isInstalledLanguage($strLanguage)) {
         $strShortLang = substr($strLanguage, 0, 2);
         // Fall back to "de" if "de_DE" does not exist
         if ($strShortLang != $strLanguage && static::isInstalledLanguage($strShortLang)) {
             $strLanguage = $strShortLang;
         } else {
             $strLanguage = 'en';
         }
     }
     // Use a global cache variable to support nested calls
     static::$arrLanguageFiles[$strName][$strCacheKey] = $strLanguage;
     // Fall back to English
     $arrCreateLangs = $strLanguage == 'en' ? array('en') : array('en', $strLanguage);
     // Load the language(s)
     foreach ($arrCreateLangs as $strCreateLang) {
         $strCacheFile = 'system/cache/language/' . $strCreateLang . '/' . $strName . '.php';
         // Try to load from cache
         if (!\Config::get('bypassCache') && file_exists(TL_ROOT . '/' . $strCacheFile)) {
             include TL_ROOT . '/' . $strCacheFile;
         } else {
             foreach (\ModuleLoader::getActive() as $strModule) {
                 $strFile = 'system/modules/' . $strModule . '/languages/' . $strCreateLang . '/' . $strName;
                 if (file_exists(TL_ROOT . '/' . $strFile . '.xlf')) {
                     static::convertXlfToPhp($strFile . '.xlf', $strCreateLang, true);
                 } elseif (file_exists(TL_ROOT . '/' . $strFile . '.php')) {
                     include TL_ROOT . '/' . $strFile . '.php';
                 }
             }
         }
     }
     // HOOK: allow to load custom labels
     if (isset($GLOBALS['TL_HOOKS']['loadLanguageFile']) && is_array($GLOBALS['TL_HOOKS']['loadLanguageFile'])) {
         foreach ($GLOBALS['TL_HOOKS']['loadLanguageFile'] as $callback) {
             static::importStatic($callback[0])->{$callback}[1]($strName, $strLanguage, $strCacheKey);
         }
     }
     // Handle single quotes in the deleteConfirm message
     if ($strName == 'default') {
         $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] = str_replace("'", "\\'", $GLOBALS['TL_LANG']['MSC']['deleteConfirm']);
     }
     // Local configuration file
     if (file_exists(TL_ROOT . '/system/config/langconfig.php')) {
         include TL_ROOT . '/system/config/langconfig.php';
     }
 }