The class handles system messages which are shown to the user. You can add messages from anywhere in the application. Usage: Message::addError('Please enter your name'); Message::addConfirm('The data has been stored'); Message::addInfo('You can upload only two files'); Message::addNew('There are two new messages');
コード例 #1
0
ファイル: BackendIndex.php プロジェクト: contao/core-bundle
 /**
  * Run the controller and parse the login template
  *
  * @return Response
  */
 public function run()
 {
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_login');
     $strHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['loginTo'], \Config::get('websiteTitle'));
     $objTemplate->theme = \Backend::getTheme();
     $objTemplate->messages = \Message::generate();
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->languages = \System::getLanguages(true);
     $objTemplate->title = \StringUtil::specialchars($strHeadline);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->userLanguage = $GLOBALS['TL_LANG']['tl_user']['language'][0];
     $objTemplate->headline = $strHeadline;
     $objTemplate->curLanguage = \Input::post('language') ?: str_replace('-', '_', $GLOBALS['TL_LANGUAGE']);
     $objTemplate->curUsername = \Input::post('username') ?: '';
     $objTemplate->uClass = $_POST && empty($_POST['username']) ? ' class="login_error"' : '';
     $objTemplate->pClass = $_POST && empty($_POST['password']) ? ' class="login_error"' : '';
     $objTemplate->loginButton = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['loginBT']);
     $objTemplate->username = $GLOBALS['TL_LANG']['tl_user']['username'][0];
     $objTemplate->password = $GLOBALS['TL_LANG']['MSC']['password'][0];
     $objTemplate->feLink = $GLOBALS['TL_LANG']['MSC']['feLink'];
     $objTemplate->default = $GLOBALS['TL_LANG']['MSC']['default'];
     $objTemplate->jsDisabled = $GLOBALS['TL_LANG']['MSC']['jsDisabled'];
     return $objTemplate->getResponse();
 }
コード例 #2
0
ファイル: PurgeData.php プロジェクト: contao/core-bundle
 /**
  * Generate the module
  *
  * @return string
  */
 public function run()
 {
     $arrJobs = array();
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_purge_data');
     $objTemplate->isActive = $this->isActive();
     $objTemplate->message = \Message::generateUnwrapped();
     // Run the jobs
     if (\Input::post('FORM_SUBMIT') == 'tl_purge') {
         $purge = \Input::post('purge');
         if (!empty($purge) && is_array($purge)) {
             foreach ($purge as $group => $jobs) {
                 foreach ($jobs as $job) {
                     list($class, $method) = $GLOBALS['TL_PURGE'][$group][$job]['callback'];
                     $this->import($class);
                     $this->{$class}->{$method}();
                 }
             }
         }
         \Message::addConfirmation($GLOBALS['TL_LANG']['tl_maintenance']['cacheCleared']);
         $this->reload();
     }
     // Tables
     foreach ($GLOBALS['TL_PURGE']['tables'] as $key => $config) {
         $arrJobs[$key] = array('id' => 'purge_' . $key, 'title' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][0], 'description' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][1], 'group' => 'tables', 'affected' => '');
         // Get the current table size
         foreach ($config['affected'] as $table) {
             $objCount = $this->Database->execute("SELECT COUNT(*) AS count FROM " . $table);
             $arrJobs[$key]['affected'] .= '<br>' . $table . ': <span>' . sprintf($GLOBALS['TL_LANG']['MSC']['entries'], $objCount->count) . ', ' . $this->getReadableSize($this->Database->getSizeOf($table), 0) . '</span>';
         }
     }
     $strCachePath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', \System::getContainer()->getParameter('kernel.cache_dir'));
     // Folders
     foreach ($GLOBALS['TL_PURGE']['folders'] as $key => $config) {
         $arrJobs[$key] = array('id' => 'purge_' . $key, 'title' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][0], 'description' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][1], 'group' => 'folders', 'affected' => '');
         // Get the current folder size
         foreach ($config['affected'] as $folder) {
             $total = 0;
             $folder = sprintf($folder, $strCachePath);
             // Only check existing folders
             if (is_dir(TL_ROOT . '/' . $folder)) {
                 $objFiles = Finder::create()->in(TL_ROOT . '/' . $folder)->files();
                 $total = iterator_count($objFiles);
             }
             $arrJobs[$key]['affected'] .= '<br>' . $folder . ': <span>' . sprintf($GLOBALS['TL_LANG']['MSC']['files'], $total) . '</span>';
         }
     }
     // Custom
     foreach ($GLOBALS['TL_PURGE']['custom'] as $key => $job) {
         $arrJobs[$key] = array('id' => 'purge_' . $key, 'title' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][0], 'description' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][1], 'group' => 'custom');
     }
     $objTemplate->jobs = $arrJobs;
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->headline = $GLOBALS['TL_LANG']['tl_maintenance']['clearCache'];
     $objTemplate->job = $GLOBALS['TL_LANG']['tl_maintenance']['job'];
     $objTemplate->description = $GLOBALS['TL_LANG']['tl_maintenance']['description'];
     $objTemplate->submit = \StringUtil::specialchars($GLOBALS['TL_LANG']['tl_maintenance']['clearCache']);
     $objTemplate->help = \Config::get('showHelp') && $GLOBALS['TL_LANG']['tl_maintenance']['cacheTables'][1] != '' ? $GLOBALS['TL_LANG']['tl_maintenance']['cacheTables'][1] : '';
     return $objTemplate->parse();
 }
コード例 #3
0
 /**
  * Run the controller and parse the password template
  *
  * @return Response
  */
 public function run()
 {
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_password');
     if (\Input::post('FORM_SUBMIT') == 'tl_password') {
         $pw = \Input::postUnsafeRaw('password');
         $cnf = \Input::postUnsafeRaw('confirm');
         // The passwords do not match
         if ($pw != $cnf) {
             \Message::addError($GLOBALS['TL_LANG']['ERR']['passwordMatch']);
         } elseif (Utf8::strlen($pw) < \Config::get('minPasswordLength')) {
             \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['passwordLength'], \Config::get('minPasswordLength')));
         } elseif ($pw == $this->User->username) {
             \Message::addError($GLOBALS['TL_LANG']['ERR']['passwordName']);
         } else {
             // Make sure the password has been changed
             if (\Encryption::verify($pw, $this->User->password)) {
                 \Message::addError($GLOBALS['TL_LANG']['MSC']['pw_change']);
             } else {
                 $this->loadDataContainer('tl_user');
                 // Trigger the save_callback
                 if (is_array($GLOBALS['TL_DCA']['tl_user']['fields']['password']['save_callback'])) {
                     foreach ($GLOBALS['TL_DCA']['tl_user']['fields']['password']['save_callback'] as $callback) {
                         if (is_array($callback)) {
                             $this->import($callback[0]);
                             $pw = $this->{$callback[0]}->{$callback[1]}($pw);
                         } elseif (is_callable($callback)) {
                             $pw = $callback($pw);
                         }
                     }
                 }
                 $objUser = \UserModel::findByPk($this->User->id);
                 $objUser->pwChange = '';
                 $objUser->password = \Encryption::hash($pw);
                 $objUser->save();
                 \Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['pw_changed']);
                 $this->redirect('contao/main.php');
             }
         }
         $this->reload();
     }
     $objTemplate->theme = \Backend::getTheme();
     $objTemplate->messages = \Message::generate();
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['pw_new']);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->headline = $GLOBALS['TL_LANG']['MSC']['pw_change'];
     $objTemplate->submitButton = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['continue']);
     $objTemplate->password = $GLOBALS['TL_LANG']['MSC']['password'][0];
     $objTemplate->confirm = $GLOBALS['TL_LANG']['MSC']['confirm'][0];
     return $objTemplate->getResponse();
 }
コード例 #4
0
ファイル: BackendAlerts.php プロジェクト: contao/core-bundle
 /**
  * Run the controller and parse the template
  *
  * @return Response
  */
 public function run()
 {
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_alerts');
     $objTemplate->theme = \Backend::getTheme();
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['systemMessages']);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->messages = \Message::generateUnwrapped() . \Backend::getSystemMessages();
     return $objTemplate->getResponse();
 }
コード例 #5
0
 /**
  * Rebuild Vimeo cache
  *
  * @param DataContainer $dc
  */
 public function rebuildVimeoCache(DataContainer $dc)
 {
     $rebuilder = new Rebuilder();
     try {
         $result = $rebuilder->rebuildElementCache(ContentModel::findByPk($dc->id));
     } catch (\InvalidArgumentException $e) {
         return;
     } catch (\RuntimeException $e) {
         System::log(sprintf('Unable to rebuild Vimeo cache of element ID %s: %s', $dc->id, $e->getMessage()), __METHOD__, TL_ERROR);
         $result = false;
     }
     if ($result === true) {
         Message::addConfirmation($GLOBALS['TL_LANG']['tl_content']['vimeo_cacheConfirm']);
     } elseif ($result === false) {
         Message::addError($GLOBALS['TL_LANG']['tl_content']['vimeo_cacheError']);
     }
 }
コード例 #6
0
ファイル: Frontend.php プロジェクト: bytehead/core-bundle
 /**
  * Check whether there is a cached version of the page and return a response object
  *
  * @return Response|null
  */
 public static function getResponseFromCache()
 {
     // Build the page if a user is (potentially) logged in or there is POST data
     if (!empty($_POST) || \Input::cookie('BE_USER_AUTH') || \Input::cookie('FE_USER_AUTH') || \Input::cookie('FE_AUTO_LOGIN') || $_SESSION['DISABLE_CACHE'] || isset($_SESSION['LOGIN_ERROR']) || \Message::hasMessages() || \Config::get('debugMode')) {
         return null;
     }
     $strCacheDir = \System::getContainer()->getParameter('kernel.cache_dir');
     // Try to map the empty request
     if (\Environment::get('relativeRequest') == '') {
         // Return if the language is added to the URL and the empty domain will be redirected
         if (\Config::get('addLanguageToUrl') && !\Config::get('doNotRedirectEmpty')) {
             return null;
         }
         $strCacheKey = null;
         $arrLanguage = \Environment::get('httpAcceptLanguage');
         $strMappingFile = $strCacheDir . '/contao/config/mapping.php';
         // Try to get the cache key from the mapper array
         if (file_exists($strMappingFile)) {
             $arrMapper = (include $strMappingFile);
             $arrPaths = array(\Environment::get('host'), '*');
             // Try the language specific keys
             foreach ($arrLanguage as $strLanguage) {
                 foreach ($arrPaths as $strPath) {
                     $strKey = $strPath . '/empty.' . $strLanguage;
                     if (isset($arrMapper[$strKey])) {
                         $strCacheKey = $arrMapper[$strKey];
                         break;
                     }
                 }
             }
             // Try the fallback key
             if ($strCacheKey === null) {
                 foreach ($arrPaths as $strPath) {
                     $strKey = $strPath . '/empty.fallback';
                     if (isset($arrMapper[$strKey])) {
                         $strCacheKey = $arrMapper[$strKey];
                         break;
                     }
                 }
             }
         }
         // Fall back to the first accepted language
         if ($strCacheKey === null) {
             $strCacheKey = \Environment::get('host') . '/empty.' . $arrLanguage[0];
         }
     } else {
         $strCacheKey = \Environment::get('host') . '/' . \Environment::get('relativeRequest');
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getCacheKey']) && is_array($GLOBALS['TL_HOOKS']['getCacheKey'])) {
         foreach ($GLOBALS['TL_HOOKS']['getCacheKey'] as $callback) {
             $strCacheKey = \System::importStatic($callback[0])->{$callback[1]}($strCacheKey);
         }
     }
     $blnFound = false;
     $strCacheFile = null;
     // Check for a mobile layout
     if (\Input::cookie('TL_VIEW') == 'mobile' || \Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop') {
         $strMd5CacheKey = md5($strCacheKey . '.mobile');
         $strCacheFile = $strCacheDir . '/contao/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html';
         if (file_exists($strCacheFile)) {
             $blnFound = true;
         }
     } else {
         $strMd5CacheKey = md5($strCacheKey . '.desktop');
         $strCacheFile = $strCacheDir . '/contao/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html';
         if (file_exists($strCacheFile)) {
             $blnFound = true;
         }
     }
     // Check for a regular layout
     if (!$blnFound) {
         $strMd5CacheKey = md5($strCacheKey);
         $strCacheFile = $strCacheDir . '/contao/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html';
         if (file_exists($strCacheFile)) {
             $blnFound = true;
         }
     }
     // Return if the file does not exist
     if (!$blnFound) {
         return null;
     }
     $expire = null;
     $content = null;
     $type = null;
     $files = null;
     $assets = null;
     // Include the file
     ob_start();
     require_once $strCacheFile;
     // The file has expired
     if ($expire < time()) {
         ob_end_clean();
         return null;
     }
     // Define the static URL constants (see #7914)
     define('TL_FILES_URL', $files);
     define('TL_ASSETS_URL', $assets);
     // Read the buffer
     $strBuffer = ob_get_clean();
     /** @var AttributeBagInterface $session */
     $session = \System::getContainer()->get('session')->getBag('contao_frontend');
     // Session required to determine the referer
     $data = $session->all();
     // Set the new referer
     if (!isset($_GET['pdf']) && !isset($_GET['file']) && !isset($_GET['id']) && $data['referer']['current'] != \Environment::get('requestUri')) {
         $data['referer']['last'] = $data['referer']['current'];
         $data['referer']['current'] = substr(\Environment::get('requestUri'), strlen(\Environment::get('path')) + 1);
     }
     // Store the session data
     $session->replace($data);
     // Load the default language file (see #2644)
     \System::loadLanguageFile('default');
     // Replace the insert tags and then re-replace the request_token tag in case a form element has been loaded via insert tag
     $strBuffer = \Controller::replaceInsertTags($strBuffer, false);
     $strBuffer = str_replace(array('{{request_token}}', '[{]', '[}]'), array(REQUEST_TOKEN, '{{', '}}'), $strBuffer);
     // HOOK: allow to modify the compiled markup (see #4291 and #7457)
     if (isset($GLOBALS['TL_HOOKS']['modifyFrontendPage']) && is_array($GLOBALS['TL_HOOKS']['modifyFrontendPage'])) {
         foreach ($GLOBALS['TL_HOOKS']['modifyFrontendPage'] as $callback) {
             $strBuffer = \System::importStatic($callback[0])->{$callback[1]}($strBuffer, null);
         }
     }
     // Content type
     if (!$content) {
         $content = 'text/html';
     }
     $response = new Response($strBuffer);
     // Send the status header (see #6585)
     if ($type == 'error_403') {
         $response->setStatusCode(Response::HTTP_FORBIDDEN);
     } elseif ($type == 'error_404') {
         $response->setStatusCode(Response::HTTP_NOT_FOUND);
     }
     $response->headers->set('Vary', 'User-Agent', false);
     $response->headers->set('Content-Type', $content . '; charset=' . \Config::get('characterSet'));
     // Send the cache headers
     if ($expire !== null && (\Config::get('cacheMode') == 'both' || \Config::get('cacheMode') == 'browser')) {
         $response->headers->set('Cache-Control', 'public, max-age=' . ($expire - time()));
         $response->headers->set('Pragma', 'public');
         $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', time()) . ' GMT');
         $response->headers->set('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
     } else {
         $response->headers->set('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
         $response->headers->set('Pragma', 'no-cache');
         $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
         $response->headers->set('Expires', 'Fri, 06 Jun 1975 15:10:00 GMT');
     }
     return $response;
 }
コード例 #7
0
ファイル: Newsletter.php プロジェクト: burguin/test02
    /**
     * Return a form to choose a CSV file and import it
     *
     * @return string
     */
    public function importRecipients()
    {
        if (\Input::get('key') != 'import') {
            return '';
        }
        $this->import('BackendUser', 'User');
        $class = $this->User->uploader;
        // See #4086 and #7046
        if (!class_exists($class) || $class == 'DropZone') {
            $class = 'FileUpload';
        }
        /** @var FileUpload $objUploader */
        $objUploader = new $class();
        // Import recipients
        if (\Input::post('FORM_SUBMIT') == 'tl_recipients_import') {
            $arrUploaded = $objUploader->uploadTo('system/tmp');
            if (empty($arrUploaded)) {
                \Message::addError($GLOBALS['TL_LANG']['ERR']['all_fields']);
                $this->reload();
            }
            $time = time();
            $intTotal = 0;
            $intInvalid = 0;
            foreach ($arrUploaded as $strCsvFile) {
                $objFile = new \File($strCsvFile);
                if ($objFile->extension != 'csv') {
                    \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $objFile->extension));
                    continue;
                }
                // Get separator
                switch (\Input::post('separator')) {
                    case 'semicolon':
                        $strSeparator = ';';
                        break;
                    case 'tabulator':
                        $strSeparator = "\t";
                        break;
                    case 'linebreak':
                        $strSeparator = "\n";
                        break;
                    default:
                        $strSeparator = ',';
                        break;
                }
                $arrRecipients = array();
                $resFile = $objFile->handle;
                while (($arrRow = @fgetcsv($resFile, null, $strSeparator)) !== false) {
                    $arrRecipients = array_merge($arrRecipients, $arrRow);
                }
                $arrRecipients = array_filter(array_unique($arrRecipients));
                foreach ($arrRecipients as $strRecipient) {
                    // Skip invalid entries
                    if (!\Validator::isEmail($strRecipient)) {
                        $this->log('Recipient address "' . $strRecipient . '" seems to be invalid and was not imported', __METHOD__, TL_ERROR);
                        ++$intInvalid;
                        continue;
                    }
                    // Check whether the e-mail address exists
                    $objRecipient = $this->Database->prepare("SELECT COUNT(*) AS count FROM tl_newsletter_recipients WHERE pid=? AND email=?")->execute(\Input::get('id'), $strRecipient);
                    if ($objRecipient->count > 0) {
                        continue;
                    }
                    // Check whether the e-mail address has been blacklisted
                    $objBlacklist = $this->Database->prepare("SELECT COUNT(*) AS count FROM tl_newsletter_blacklist WHERE pid=? AND hash=?")->execute(\Input::get('id'), md5($strRecipient));
                    if ($objBlacklist->count > 0) {
                        $this->log('Recipient address "' . $strRecipient . '" has been unsubscribed and was not imported', __METHOD__, TL_ERROR);
                        continue;
                    }
                    $this->Database->prepare("INSERT INTO tl_newsletter_recipients SET pid=?, tstamp={$time}, email=?, active=1")->execute(\Input::get('id'), $strRecipient);
                    ++$intTotal;
                }
            }
            \Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_newsletter_recipients']['confirm'], $intTotal));
            if ($intInvalid > 0) {
                \Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_newsletter_recipients']['invalid'], $intInvalid));
            }
            \System::setCookie('BE_PAGE_OFFSET', 0, 0);
            $this->reload();
        }
        // Return form
        return '
<div id="tl_buttons">
<a href="' . ampersand(str_replace('&key=import', '', \Environment::get('request'))) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>
' . \Message::generate() . '
<form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_recipients_import" class="tl_form" method="post" enctype="multipart/form-data">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_recipients_import">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">
<input type="hidden" name="MAX_FILE_SIZE" value="' . \Config::get('maxFileSize') . '">

<div class="tl_tbox">
  <h3><label for="separator">' . $GLOBALS['TL_LANG']['MSC']['separator'][0] . '</label></h3>
  <select name="separator" id="separator" class="tl_select" onfocus="Backend.getScrollOffset()">
    <option value="comma">' . $GLOBALS['TL_LANG']['MSC']['comma'] . '</option>
    <option value="semicolon">' . $GLOBALS['TL_LANG']['MSC']['semicolon'] . '</option>
    <option value="tabulator">' . $GLOBALS['TL_LANG']['MSC']['tabulator'] . '</option>
    <option value="linebreak">' . $GLOBALS['TL_LANG']['MSC']['linebreak'] . '</option>
  </select>' . ($GLOBALS['TL_LANG']['MSC']['separator'][1] != '' ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['MSC']['separator'][1] . '</p>' : '') . '
  <h3>' . $GLOBALS['TL_LANG']['MSC']['source'][0] . '</h3>' . $objUploader->generateMarkup() . (isset($GLOBALS['TL_LANG']['MSC']['source'][1]) ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['MSC']['source'][1] . '</p>' : '') . '
</div>

</div>

<div class="tl_formbody_submit">

<div class="tl_submit_container">
  <button type="submit" name="save" id="save" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['tl_newsletter_recipients']['import'][0] . '</button>
</div>

</div>
</form>';
    }
コード例 #8
0
 /**
  * Compares the current host to the phpbb Cookie Domain
  * and adds Warning Msg if they differ
  */
 public function testCookieDomain()
 {
     $result = $this->compareCookieDomains();
     if ($result === false) {
         Message::addError('WARNING: The current Host (' . Environment::get('host') . ') differs from the cookie_domain configured in phpbb. Please make sure the used frontend domain is the same to: ' . System::getContainer()->get('phpbb_bridge.connector')->getDbConfig('cookie_domain'));
     }
 }
コード例 #9
0
ファイル: DC_Folder.php プロジェクト: Mozan/core-bundle
    /**
     * Synchronize the file system with the database
     *
     * @return string
     *
     * @throws AccessDeniedException
     */
    public function sync()
    {
        if (!$this->blnIsDbAssisted) {
            return '';
        }
        $this->import('BackendUser', 'User');
        $this->loadLanguageFile('tl_files');
        // Check the permission to synchronize
        if (!$this->User->hasAccess('f6', 'fop')) {
            throw new AccessDeniedException('Not enough permissions to synchronize the file system.');
        }
        // Synchronize
        $strLog = \Dbafs::syncFiles();
        // Show the results
        $arrMessages = array();
        $arrCounts = array('Added' => 0, 'Changed' => 0, 'Unchanged' => 0, 'Moved' => 0, 'Deleted' => 0);
        // Read the log file
        $fh = fopen(TL_ROOT . '/' . $strLog, 'rb');
        while (($buffer = fgets($fh)) !== false) {
            list($type, $file) = explode('] ', trim(substr($buffer, 1)), 2);
            // Add a message depending on the type
            switch ($type) {
                case 'Added':
                    $arrMessages[] = '<p class="tl_new">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncAdded'], specialchars($file)) . '</p>';
                    break;
                case 'Changed':
                    $arrMessages[] = '<p class="tl_info">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncChanged'], specialchars($file)) . '</p>';
                    break;
                case 'Unchanged':
                    $arrMessages[] = '<p class="tl_confirm hidden">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncUnchanged'], specialchars($file)) . '</p>';
                    break;
                case 'Moved':
                    list($source, $target) = explode(' to ', $file, 2);
                    $arrMessages[] = '<p class="tl_info">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncMoved'], specialchars($source), specialchars($target)) . '</p>';
                    break;
                case 'Deleted':
                    $arrMessages[] = '<p class="tl_error">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncDeleted'], specialchars($file)) . '</p>';
                    break;
            }
            ++$arrCounts[$type];
        }
        // Close the log file
        unset($buffer);
        fclose($fh);
        // Confirm
        \Message::addConfirmation($GLOBALS['TL_LANG']['tl_files']['syncComplete']);
        $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>
' . \Message::generate() . '
<div id="sync-results">
  <p class="left">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncResult'], \System::getFormattedNumber($arrCounts['Added'], 0), \System::getFormattedNumber($arrCounts['Changed'], 0), \System::getFormattedNumber($arrCounts['Unchanged'], 0), \System::getFormattedNumber($arrCounts['Moved'], 0), \System::getFormattedNumber($arrCounts['Deleted'], 0)) . '</p>
  <p class="right"><input type="checkbox" id="show-hidden" class="tl_checkbox" onclick="Backend.toggleUnchanged()"> <label for="show-hidden">' . $GLOBALS['TL_LANG']['tl_files']['syncShowUnchanged'] . '</label></p>
  <div class="clear"></div>
</div>
<div class="tl_message nobg" id="result-list" style="margin-bottom:2em">';
        // Add the messages
        foreach ($arrMessages as $strMessage) {
            $return .= "\n  " . $strMessage;
        }
        $return .= '
</div>

<div class="tl_submit_container">
  <a href="' . $this->getReferer(true) . '" class="tl_submit" style="display:inline-block">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</a>
</div>
';
        return $return;
    }
コード例 #10
0
ファイル: tl_page.php プロジェクト: postyou/contao-deep-login
 public function generate403Page($dc)
 {
     // Return if there is no active record (override all)
     if (!$dc->activeRecord || $dc->activeRecord->tstamp > 0 || $dc->activeRecord->type != 'login') {
         return;
     }
     $new_records = $this->Session->get('new_records');
     // Not a new page
     if (!$new_records || is_array($new_records[$dc->table]) && !in_array($dc->id, $new_records[$dc->table])) {
         return;
     }
     // Check whether there are articles (e.g. on copied pages)
     $objTotal = $this->Database->prepare("SELECT COUNT(*) AS count FROM tl_page WHERE type='error_403'")->execute($dc->id);
     if ($objTotal->count > 0) {
         return;
     } else {
         $arrSet['pid'] = $dc->activeRecord->pid;
         $arrSet['sorting'] = 0;
         $arrSet['tstamp'] = time();
         $arrSet['type'] = "error_403";
         $arrSet['title'] = "403 Zugriff verweigert";
         $arrSet['alias'] = "403-zugriff-verweigert";
         // see #5168
         $arrSet['published'] = "1";
         $this->Database->prepare("INSERT INTO tl_page %s")->set($arrSet)->execute();
         \Contao\Message::addInfo("Created 403-error page.");
     }
 }
コード例 #11
0
ファイル: DC_Table.php プロジェクト: Mozan/core-bundle
    /**
     * List all records of the current table and return them as HTML string
     *
     * @return string
     */
    protected function listView()
    {
        $return = '';
        $table = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6 ? $this->ptable : $this->strTable;
        $orderBy = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['fields'];
        $firstOrderBy = preg_replace('/\\s+.*$/', '', $orderBy[0]);
        if (is_array($this->orderBy) && $this->orderBy[0] != '') {
            $orderBy = $this->orderBy;
            $firstOrderBy = $this->firstOrderBy;
        }
        $query = "SELECT * FROM " . $this->strTable;
        if (!empty($this->procedure)) {
            $query .= " WHERE " . implode(' AND ', $this->procedure);
        }
        if (!empty($this->root) && is_array($this->root)) {
            $query .= (!empty($this->procedure) ? " AND " : " WHERE ") . "id IN(" . implode(',', array_map('intval', $this->root)) . ")";
        }
        if (is_array($orderBy) && $orderBy[0] != '') {
            foreach ($orderBy as $k => $v) {
                list($key, $direction) = explode(' ', $v, 2);
                if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['eval']['findInSet']) {
                    if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options_callback'])) {
                        $strClass = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options_callback'][0];
                        $strMethod = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options_callback'][1];
                        $this->import($strClass);
                        $keys = $this->{$strClass}->{$strMethod}($this);
                    } elseif (is_callable($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options_callback'])) {
                        $keys = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options_callback']($this);
                    } else {
                        $keys = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options'];
                    }
                    if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['eval']['isAssociative'] || array_is_assoc($keys)) {
                        $keys = array_keys($keys);
                    }
                    $orderBy[$k] = $this->Database->findInSet($v, $keys);
                } elseif (in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['flag'], array(5, 6, 7, 8, 9, 10))) {
                    $orderBy[$k] = "CAST({$key} AS SIGNED)" . ($direction ? " {$direction}" : "");
                    // see #5503
                }
            }
            if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 3) {
                $firstOrderBy = 'pid';
                $showFields = $GLOBALS['TL_DCA'][$table]['list']['label']['fields'];
                $query .= " ORDER BY (SELECT " . $showFields[0] . " FROM " . $this->ptable . " WHERE " . $this->ptable . ".id=" . $this->strTable . ".pid), " . implode(', ', $orderBy);
                // Set the foreignKey so that the label is translated
                if ($GLOBALS['TL_DCA'][$table]['fields']['pid']['foreignKey'] == '') {
                    $GLOBALS['TL_DCA'][$table]['fields']['pid']['foreignKey'] = $this->ptable . '.' . $showFields[0];
                }
                // Remove the parent field from label fields
                array_shift($showFields);
                $GLOBALS['TL_DCA'][$table]['list']['label']['fields'] = $showFields;
            } else {
                $query .= " ORDER BY " . implode(', ', $orderBy);
            }
        }
        if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 1 && $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] % 2 == 0) {
            $query .= " DESC";
        }
        $objRowStmt = $this->Database->prepare($query);
        if ($this->limit != '') {
            $arrLimit = explode(',', $this->limit);
            $objRowStmt->limit($arrLimit[1], $arrLimit[0]);
        }
        $objRow = $objRowStmt->execute($this->values);
        $this->bid = $return != '' ? $this->bid : 'tl_buttons';
        // Display buttos
        if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] || !empty($GLOBALS['TL_DCA'][$this->strTable]['list']['global_operations'])) {
            $return .= '

<div id="' . $this->bid . '">' . (\Input::get('act') == 'select' || $this->ptable ? '
<a href="' . $this->getReferer(true, $this->ptable) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> ' : (isset($GLOBALS['TL_DCA'][$this->strTable]['config']['backlink']) ? '
<a href="contao/main.php?' . $GLOBALS['TL_DCA'][$this->strTable]['config']['backlink'] . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> ' : '')) . (\Input::get('act') != 'select' && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable'] ? '
<a href="' . ($this->ptable != '' ? $this->addToUrl('act=create' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] < 4 ? '&amp;mode=2' : '') . '&amp;pid=' . $this->intId) : $this->addToUrl('act=create')) . '" class="header_new" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['new'][1]) . '" accesskey="n" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG'][$this->strTable]['new'][0] . '</a> ' : '') . $this->generateGlobalButtons() . '
</div>' . \Message::generate(true);
        }
        // Return "no records found" message
        if ($objRow->numRows < 1) {
            $return .= '
<p class="tl_empty">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>';
        } else {
            $result = $objRow->fetchAllAssoc();
            $return .= (\Input::get('act') == 'select' ? '

<form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_select" class="tl_form' . (\Input::get('act') == 'select' ? ' unselectable' : '') . '" method="post" novalidate>
<div class="tl_formbody">
<input type="hidden" name="FORM_SUBMIT" value="tl_select">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' : '') . '

<div class="tl_listing_container list_view">' . (\Input::get('act') == 'select' ? '

<div class="tl_select_trigger">
<label for="tl_select_trigger" class="tl_select_label">' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</label> <input type="checkbox" id="tl_select_trigger" onclick="Backend.toggleCheckboxes(this)" class="tl_tree_checkbox">
</div>' : '') . '

<table class="tl_listing' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns'] ? ' showColumns' : '') . '">';
            // Automatically add the "order by" field as last column if we do not have group headers
            if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns']) {
                $blnFound = false;
                // Extract the real key and compare it to $firstOrderBy
                foreach ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'] as $f) {
                    if (strpos($f, ':') !== false) {
                        list($f) = explode(':', $f, 2);
                    }
                    if ($firstOrderBy == $f) {
                        $blnFound = true;
                        break;
                    }
                }
                if (!$blnFound) {
                    $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'][] = $firstOrderBy;
                }
            }
            // Generate the table header if the "show columns" option is active
            if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns']) {
                $return .= '
  <tr>';
                foreach ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'] as $f) {
                    if (strpos($f, ':') !== false) {
                        list($f) = explode(':', $f, 2);
                    }
                    $return .= '
    <th class="tl_folder_tlist col_' . $f . ($f == $firstOrderBy ? ' ordered_by' : '') . '">' . (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$f]['label']) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$f]['label'][0] : $GLOBALS['TL_DCA'][$this->strTable]['fields'][$f]['label']) . '</th>';
                }
                $return .= '
    <th class="tl_folder_tlist tl_right_nowrap">&nbsp;</th>
  </tr>';
            }
            // Process result and add label and buttons
            $remoteCur = false;
            $groupclass = 'tl_folder_tlist';
            $eoCount = -1;
            foreach ($result as $row) {
                $args = array();
                $this->current[] = $row['id'];
                $showFields = $GLOBALS['TL_DCA'][$table]['list']['label']['fields'];
                // Label
                foreach ($showFields as $k => $v) {
                    // Decrypt the value
                    if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['encrypt']) {
                        $row[$v] = \Encryption::decrypt(deserialize($row[$v]));
                    }
                    if (strpos($v, ':') !== false) {
                        list($strKey, $strTable) = explode(':', $v);
                        list($strTable, $strField) = explode('.', $strTable);
                        $objRef = $this->Database->prepare("SELECT " . $strField . " FROM " . $strTable . " WHERE id=?")->limit(1)->execute($row[$strKey]);
                        $args[$k] = $objRef->numRows ? $objRef->{$strField} : '';
                    } elseif (in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['flag'], array(5, 6, 7, 8, 9, 10))) {
                        if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'date') {
                            $args[$k] = $row[$v] ? \Date::parse(\Config::get('dateFormat'), $row[$v]) : '-';
                        } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'time') {
                            $args[$k] = $row[$v] ? \Date::parse(\Config::get('timeFormat'), $row[$v]) : '-';
                        } else {
                            $args[$k] = $row[$v] ? \Date::parse(\Config::get('datimFormat'), $row[$v]) : '-';
                        }
                    } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'checkbox' && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['multiple']) {
                        $args[$k] = $row[$v] != '' ? $GLOBALS['TL_DCA'][$table]['fields'][$v]['label'][0] : '';
                    } else {
                        $row_v = deserialize($row[$v]);
                        if (is_array($row_v)) {
                            $args_k = array();
                            foreach ($row_v as $option) {
                                $args_k[] = $GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$option] ?: $option;
                            }
                            $args[$k] = implode(', ', $args_k);
                        } elseif (isset($GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]])) {
                            $args[$k] = is_array($GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]]) ? $GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]][0] : $GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]];
                        } elseif (($GLOBALS['TL_DCA'][$table]['fields'][$v]['eval']['isAssociative'] || array_is_assoc($GLOBALS['TL_DCA'][$table]['fields'][$v]['options'])) && isset($GLOBALS['TL_DCA'][$table]['fields'][$v]['options'][$row[$v]])) {
                            $args[$k] = $GLOBALS['TL_DCA'][$table]['fields'][$v]['options'][$row[$v]];
                        } else {
                            $args[$k] = $row[$v];
                        }
                    }
                }
                // Shorten the label it if it is too long
                $label = vsprintf($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['format'] ?: '%s', $args);
                if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'] > 0 && $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'] < strlen(strip_tags($label))) {
                    $label = trim(\StringUtil::substrHtml($label, $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'])) . ' …';
                }
                // Remove empty brackets (), [], {}, <> and empty tags from the label
                $label = preg_replace('/\\( *\\) ?|\\[ *\\] ?|\\{ *\\} ?|< *> ?/', '', $label);
                $label = preg_replace('/<[^>]+>\\s*<\\/[^>]+>/', '', $label);
                // Build the sorting groups
                if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] > 0) {
                    $current = $row[$firstOrderBy];
                    $orderBy = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['fields'];
                    $sortingMode = count($orderBy) == 1 && $firstOrderBy == $orderBy[0] && $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] != '' && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['flag'] == '' ? $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] : $GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['flag'];
                    $remoteNew = $this->formatCurrentValue($firstOrderBy, $current, $sortingMode);
                    // Add the group header
                    if (!$GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns'] && !$GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['disableGrouping'] && ($remoteNew != $remoteCur || $remoteCur === false)) {
                        $eoCount = -1;
                        $group = $this->formatGroupHeader($firstOrderBy, $remoteNew, $sortingMode, $row);
                        $remoteCur = $remoteNew;
                        $return .= '
  <tr>
    <td colspan="2" class="' . $groupclass . '">' . $group . '</td>
  </tr>';
                        $groupclass = 'tl_folder_list';
                    }
                }
                $return .= '
  <tr class="' . (++$eoCount % 2 == 0 ? 'even' : 'odd') . ' click2edit toggle_select hover-row">
    ';
                $colspan = 1;
                // Call the label_callback ($row, $label, $this)
                if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback']) || is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) {
                    if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) {
                        $strClass = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'][0];
                        $strMethod = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'][1];
                        $this->import($strClass);
                        $args = $this->{$strClass}->{$strMethod}($row, $label, $this, $args);
                    } elseif (is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) {
                        $args = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback']($row, $label, $this, $args);
                    }
                    // Handle strings and arrays
                    if (!$GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns']) {
                        $label = is_array($args) ? implode(' ', $args) : $args;
                    } elseif (!is_array($args)) {
                        $args = array($args);
                        $colspan = count($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields']);
                    }
                }
                // Show columns
                if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns']) {
                    foreach ($args as $j => $arg) {
                        $return .= '<td colspan="' . $colspan . '" class="tl_file_list col_' . $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'][$j] . ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'][$j] == $firstOrderBy ? ' ordered_by' : '') . '">' . ($arg ?: '-') . '</td>';
                    }
                } else {
                    $return .= '<td class="tl_file_list">' . $label . '</td>';
                }
                // Buttons ($row, $table, $root, $blnCircularReference, $childs, $previous, $next)
                $return .= (\Input::get('act') == 'select' ? '
    <td class="tl_file_list tl_right_nowrap"><input type="checkbox" name="IDS[]" id="ids_' . $row['id'] . '" class="tl_tree_checkbox" value="' . $row['id'] . '"></td>' : '
    <td class="tl_file_list tl_right_nowrap">' . $this->generateButtons($row, $this->strTable, $this->root) . '</td>') . '
  </tr>';
            }
            // Close the table
            $return .= '
</table>

</div>';
            // Close the form
            if (\Input::get('act') == 'select') {
                // Submit buttons
                $arrButtons = array();
                if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notDeletable']) {
                    $arrButtons['delete'] = '<button type="submit" name="delete" id="delete" class="tl_submit" accesskey="d" onclick="return confirm(\'' . $GLOBALS['TL_LANG']['MSC']['delAllConfirm'] . '\')">' . $GLOBALS['TL_LANG']['MSC']['deleteSelected'] . '</button>';
                }
                if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) {
                    $arrButtons['copy'] = '<button type="submit" name="copy" id="copy" class="tl_submit" accesskey="c">' . $GLOBALS['TL_LANG']['MSC']['copySelected'] . '</button>';
                }
                if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) {
                    $arrButtons['override'] = '<button type="submit" name="override" id="override" class="tl_submit" accesskey="v">' . $GLOBALS['TL_LANG']['MSC']['overrideSelected'] . '</button>';
                    $arrButtons['edit'] = '<button type="submit" name="edit" id="edit" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['editSelected'] . '</button>';
                }
                // Call the buttons_callback (see #4691)
                if (is_array($GLOBALS['TL_DCA'][$this->strTable]['select']['buttons_callback'])) {
                    foreach ($GLOBALS['TL_DCA'][$this->strTable]['select']['buttons_callback'] as $callback) {
                        if (is_array($callback)) {
                            $this->import($callback[0]);
                            $arrButtons = $this->{$callback[0]}->{$callback[1]}($arrButtons, $this);
                        } elseif (is_callable($callback)) {
                            $arrButtons = $callback($arrButtons, $this);
                        }
                    }
                }
                $return .= '

<div class="tl_formbody_submit" style="text-align:right">

<div class="tl_submit_container">
  ' . implode(' ', $arrButtons) . '
</div>

</div>
</div>
</form>';
            }
        }
        return $return;
    }
コード例 #12
0
ファイル: Password.php プロジェクト: contao/core-bundle
 /**
  * Validate input and set value
  *
  * @param mixed $varInput
  *
  * @return string
  */
 protected function validator($varInput)
 {
     $this->blnSubmitInput = false;
     if (($varInput == '' || $varInput == '*****') && $this->varValue != '') {
         return '*****';
     }
     if (Utf8::strlen($varInput) < \Config::get('minPasswordLength')) {
         $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['passwordLength'], \Config::get('minPasswordLength')));
     }
     if ($varInput != $this->getPost($this->strName . '_confirm')) {
         $this->addError($GLOBALS['TL_LANG']['ERR']['passwordMatch']);
     }
     if ($varInput == $GLOBALS['TL_USERNAME']) {
         $this->addError($GLOBALS['TL_LANG']['ERR']['passwordName']);
     }
     $varInput = parent::validator($varInput);
     if (!$this->hasErrors()) {
         $this->blnSubmitInput = true;
         \Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['pw_changed']);
         return \Encryption::hash($varInput);
     }
     return '';
 }
コード例 #13
0
 /**
  * Add the template output to the cache and add the cache headers
  */
 protected function addToCache()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $intCache = 0;
     // Decide whether the page shall be cached
     if (!isset($_GET['file']) && !isset($_GET['token']) && empty($_POST) && !BE_USER_LOGGED_IN && !FE_USER_LOGGED_IN && !$_SESSION['DISABLE_CACHE'] && !isset($_SESSION['LOGIN_ERROR']) && !\Message::hasMessages() && intval($objPage->cache) > 0 && !$objPage->protected) {
         $intCache = time() + intval($objPage->cache);
     }
     // Server-side cache
     if ($intCache > 0 && (\Config::get('cacheMode') == 'both' || \Config::get('cacheMode') == 'server')) {
         // If the request string is empty, use a special cache tag which considers the page language
         if (\Environment::get('relativeRequest') == '') {
             $strCacheKey = \Environment::get('host') . '/empty.' . $objPage->language;
         } else {
             $strCacheKey = \Environment::get('host') . '/' . \Environment::get('relativeRequest');
         }
         // HOOK: add custom logic
         if (isset($GLOBALS['TL_HOOKS']['getCacheKey']) && is_array($GLOBALS['TL_HOOKS']['getCacheKey'])) {
             foreach ($GLOBALS['TL_HOOKS']['getCacheKey'] as $callback) {
                 $this->import($callback[0]);
                 $strCacheKey = $this->{$callback[0]}->{$callback[1]}($strCacheKey);
             }
         }
         // Add a suffix if there is a mobile layout (see #7826)
         if ($objPage->mobileLayout > 0) {
             if (\Input::cookie('TL_VIEW') == 'mobile' || \Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop') {
                 $strCacheKey .= '.mobile';
             } else {
                 $strCacheKey .= '.desktop';
             }
         }
         // Replace insert tags for caching
         $strBuffer = $this->replaceInsertTags($this->strBuffer);
         $strBuffer = $this->replaceDynamicScriptTags($strBuffer);
         // see #4203
         // Add the cache file header
         $strHeader = sprintf("<?php /* %s */ \$expire = %d; \$content = %s; \$type = %s; \$files = %s; \$assets = %s; ?>\n", $strCacheKey, (int) $intCache, var_export($this->strContentType, true), var_export($objPage->type, true), var_export(TL_FILES_URL, true), var_export(TL_ASSETS_URL, true));
         $strCachePath = str_replace(TL_ROOT . '/', '', \System::getContainer()->getParameter('kernel.cache_dir'));
         // Create the cache file
         $strMd5CacheKey = md5($strCacheKey);
         $objFile = new \File($strCachePath . '/contao/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html');
         $objFile->write($strHeader);
         $objFile->append($this->minifyHtml($strBuffer), '');
         $objFile->close();
     }
     // Client-side cache
     if (!headers_sent()) {
         if ($intCache > 0 && (\Config::get('cacheMode') == 'both' || \Config::get('cacheMode') == 'browser')) {
             header('Cache-Control: private, max-age=' . ($intCache - time()));
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
             header('Expires: ' . gmdate('D, d M Y H:i:s', $intCache) . ' GMT');
         } else {
             header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
             header('Expires: Fri, 06 Jun 1975 15:10:00 GMT');
         }
     }
 }
コード例 #14
0
 /**
  * Add the welcome screen
  *
  * @return string
  */
 protected function welcomeScreen()
 {
     \System::loadLanguageFile('explain');
     /** @var \BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_welcome');
     $objTemplate->messages = \Message::generateUnwrapped();
     // HOOK: add custom messages
     if (isset($GLOBALS['TL_HOOKS']['getSystemMessages']) && is_array($GLOBALS['TL_HOOKS']['getSystemMessages'])) {
         $arrMessages = array();
         foreach ($GLOBALS['TL_HOOKS']['getSystemMessages'] as $callback) {
             $this->import($callback[0]);
             $strBuffer = $this->{$callback}[0]->{$callback}[1]();
             if ($strBuffer != '') {
                 $arrMessages[] = $strBuffer;
             }
         }
         if (!empty($arrMessages)) {
             $objTemplate->messages .= "\n" . implode("\n", $arrMessages);
         }
     }
     // Add the versions overview
     \Versions::addToTemplate($objTemplate);
     $objTemplate->welcome = sprintf($GLOBALS['TL_LANG']['MSC']['welcomeTo'], \Config::get('websiteTitle'));
     $objTemplate->showDifferences = specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MSC']['showDifferences']));
     $objTemplate->systemMessages = $GLOBALS['TL_LANG']['MSC']['systemMessages'];
     $objTemplate->shortcuts = $GLOBALS['TL_LANG']['MSC']['shortcuts'][0];
     $objTemplate->shortcutsLink = $GLOBALS['TL_LANG']['MSC']['shortcuts'][1];
     $objTemplate->editElement = specialchars($GLOBALS['TL_LANG']['MSC']['editElement']);
     return $objTemplate->parse();
 }
 /**
  * Add a message to the contao message array in the session.
  *
  * @param AddMessageEvent $event The event.
  *
  * @return void
  */
 public function addMessage(AddMessageEvent $event)
 {
     Message::add($event->getContent(), 'TL_' . strtoupper($event->getType()));
 }
コード例 #16
0
 /**
  * Import files from selected folder
  *
  * @param string $strPath
  */
 protected function importFromPath($strPath)
 {
     $arrFiles = scan(TL_ROOT . '/' . $strPath);
     if (empty($arrFiles)) {
         Message::addError($GLOBALS['TL_LANG']['MSC']['noFilesInFolder']);
         Controller::reload();
     }
     $blnEmpty = true;
     $arrDelete = array();
     $objProducts = \Database::getInstance()->prepare("SELECT * FROM tl_iso_product WHERE pid=0")->execute();
     while ($objProducts->next()) {
         $arrImageNames = array();
         $arrImages = deserialize($objProducts->images);
         if (!is_array($arrImages)) {
             $arrImages = array();
         } else {
             foreach ($arrImages as $row) {
                 if ($row['src']) {
                     $arrImageNames[] = $row['src'];
                 }
             }
         }
         $arrPattern = array();
         $arrPattern[] = $objProducts->alias ? standardize($objProducts->alias) : null;
         $arrPattern[] = $objProducts->sku ? $objProducts->sku : null;
         $arrPattern[] = $objProducts->sku ? standardize($objProducts->sku) : null;
         $arrPattern[] = !empty($arrImageNames) ? implode('|', $arrImageNames) : null;
         // !HOOK: add custom import regex patterns
         if (isset($GLOBALS['ISO_HOOKS']['addAssetImportRegexp']) && is_array($GLOBALS['ISO_HOOKS']['addAssetImportRegexp'])) {
             foreach ($GLOBALS['ISO_HOOKS']['addAssetImportRegexp'] as $callback) {
                 $objCallback = System::importStatic($callback[0]);
                 $arrPattern = $objCallback->{$callback}[1]($arrPattern, $objProducts);
             }
         }
         $strPattern = '@^(' . implode('|', array_filter($arrPattern)) . ')@i';
         $arrMatches = preg_grep($strPattern, $arrFiles);
         if (!empty($arrMatches)) {
             $arrNewImages = array();
             foreach ($arrMatches as $file) {
                 if (is_dir(TL_ROOT . '/' . $strPath . '/' . $file)) {
                     $arrSubfiles = scan(TL_ROOT . '/' . $strPath . '/' . $file);
                     if (!empty($arrSubfiles)) {
                         foreach ($arrSubfiles as $subfile) {
                             if (is_file($strPath . '/' . $file . '/' . $subfile)) {
                                 $objFile = new File($strPath . '/' . $file . '/' . $subfile);
                                 if ($objFile->isGdImage) {
                                     $arrNewImages[] = $strPath . '/' . $file . '/' . $subfile;
                                 }
                             }
                         }
                     }
                 } elseif (is_file(TL_ROOT . '/' . $strPath . '/' . $file)) {
                     $objFile = new \File($strPath . '/' . $file);
                     if ($objFile->isGdImage) {
                         $arrNewImages[] = $strPath . '/' . $file;
                     }
                 }
             }
             if (!empty($arrNewImages)) {
                 foreach ($arrNewImages as $strFile) {
                     $pathinfo = pathinfo(TL_ROOT . '/' . $strFile);
                     // Will recursively create the folder
                     $objFolder = new \Folder('isotope/' . strtolower(substr($pathinfo['filename'], 0, 1)));
                     $strCacheName = $pathinfo['filename'] . '-' . substr(md5_file(TL_ROOT . '/' . $strFile), 0, 8) . '.' . $pathinfo['extension'];
                     \Files::getInstance()->copy($strFile, $objFolder->path . '/' . $strCacheName);
                     $arrImages[] = array('src' => $strCacheName);
                     $arrDelete[] = $strFile;
                     Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['MSC']['assetImportConfirmation'], $pathinfo['filename'] . '.' . $pathinfo['extension'], $objProducts->name));
                     $blnEmpty = false;
                 }
                 \Database::getInstance()->prepare("UPDATE tl_iso_product SET images=? WHERE id=?")->execute(serialize($arrImages), $objProducts->id);
             }
         }
     }
     if (!empty($arrDelete)) {
         $arrDelete = array_unique($arrDelete);
         foreach ($arrDelete as $file) {
             \Files::getInstance()->delete($file);
         }
     }
     if ($blnEmpty) {
         \Message::addInfo($GLOBALS['TL_LANG']['MSC']['assetImportNoFilesFound']);
     }
     \Controller::reload();
 }
コード例 #17
0
ファイル: User.php プロジェクト: qzminski/contao-core-bundle
 /**
  * Check the account status and return true if it is active
  *
  * @return boolean True if the account is active
  */
 protected function checkAccountStatus()
 {
     $time = time();
     // Check whether the account is locked
     if ($this->locked + \Config::get('lockPeriod') > $time) {
         \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['accountLocked'], ceil(($this->locked + \Config::get('lockPeriod') - $time) / 60)));
         return false;
     } elseif ($this->disable) {
         \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
         $this->log('The account has been disabled', __METHOD__, TL_ACCESS);
         return false;
     } elseif ($this instanceof FrontendUser && !$this->login) {
         \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
         $this->log('User "' . $this->username . '" is not allowed to log in', __METHOD__, TL_ACCESS);
         return false;
     } elseif ($this->start != '' || $this->stop != '') {
         $time = \Date::floorToMinute($time);
         if ($this->start != '' && $this->start > $time) {
             \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
             $this->log('The account was not active yet (activation date: ' . \Date::parse(\Config::get('dateFormat'), $this->start) . ')', __METHOD__, TL_ACCESS);
             return false;
         }
         if ($this->stop != '' && $this->stop <= $time + 60) {
             \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
             $this->log('The account was not active anymore (deactivation date: ' . \Date::parse(\Config::get('dateFormat'), $this->stop) . ')', __METHOD__, TL_ACCESS);
             return false;
         }
     }
     return true;
 }
コード例 #18
0
ファイル: System.php プロジェクト: contao/core-bundle
 /**
  * Return all available message types
  *
  * @return array An array of message types
  *
  * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0.
  *             Use Message::getTypes() instead.
  */
 protected function getMessageTypes()
 {
     @trigger_error('Using System::getMessageTypes() has been deprecated and will no longer work in Contao 5.0. Use Message::getTypes() instead.', E_USER_DEPRECATED);
     return \Message::getTypes();
 }
コード例 #19
0
ファイル: DC_File.php プロジェクト: jamesdevine/core-bundle
    /**
     * Auto-generate a form to edit the local configuration file
     *
     * @return string
     */
    public function edit()
    {
        $return = '';
        $ajaxId = null;
        if (\Environment::get('isAjaxRequest')) {
            $ajaxId = func_get_arg(1);
        }
        // Build an array from boxes and rows
        $this->strPalette = $this->getPalette();
        $boxes = trimsplit(';', $this->strPalette);
        $legends = array();
        if (!empty($boxes)) {
            foreach ($boxes as $k => $v) {
                $boxes[$k] = trimsplit(',', $v);
                foreach ($boxes[$k] as $kk => $vv) {
                    if (preg_match('/^\\[.*\\]$/', $vv)) {
                        continue;
                    }
                    if (preg_match('/^\\{.*\\}$/', $vv)) {
                        $legends[$k] = substr($vv, 1, -1);
                        unset($boxes[$k][$kk]);
                    } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) {
                        unset($boxes[$k][$kk]);
                    }
                }
                // Unset a box if it does not contain any fields
                if (empty($boxes[$k])) {
                    unset($boxes[$k]);
                }
            }
            /** @var AttributeBagInterface $objSessionBag */
            $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
            // Render boxes
            $class = 'tl_tbox';
            $fs = $objSessionBag->get('fieldset_states');
            $blnIsFirst = true;
            foreach ($boxes as $k => $v) {
                $strAjax = '';
                $blnAjax = false;
                $key = '';
                $cls = '';
                $legend = '';
                if (isset($legends[$k])) {
                    list($key, $cls) = explode(':', $legends[$k]);
                    $legend = "\n" . '<legend onclick="AjaxRequest.toggleFieldset(this, \'' . $key . '\', \'' . $this->strTable . '\')">' . (isset($GLOBALS['TL_LANG'][$this->strTable][$key]) ? $GLOBALS['TL_LANG'][$this->strTable][$key] : $key) . '</legend>';
                }
                if (isset($fs[$this->strTable][$key])) {
                    $class .= $fs[$this->strTable][$key] ? '' : ' collapsed';
                } else {
                    $class .= $cls && $legend ? ' ' . $cls : '';
                }
                $return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend;
                // Build rows of the current box
                foreach ($v as $vv) {
                    if ($vv == '[EOF]') {
                        if ($blnAjax && \Environment::get('isAjaxRequest')) {
                            return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">';
                        }
                        $blnAjax = false;
                        $return .= "\n  " . '</div>';
                        continue;
                    }
                    if (preg_match('/^\\[.*\\]$/', $vv)) {
                        $thisId = 'sub_' . substr($vv, 1, -1);
                        $blnAjax = $ajaxId == $thisId && \Environment::get('isAjaxRequest') ? true : false;
                        $return .= "\n  " . '<div id="' . $thisId . '">';
                        continue;
                    }
                    $this->strField = $vv;
                    $this->strInputName = $vv;
                    $this->varValue = \Config::get($this->strField);
                    // Handle entities
                    if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text' || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'textarea') {
                        if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple']) {
                            $this->varValue = deserialize($this->varValue);
                        }
                        if (!is_array($this->varValue)) {
                            $this->varValue = htmlspecialchars($this->varValue);
                        } else {
                            foreach ($this->varValue as $k => $v) {
                                $this->varValue[$k] = htmlspecialchars($v);
                            }
                        }
                    }
                    // Autofocus the first field
                    if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') {
                        $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus';
                        $blnIsFirst = false;
                    }
                    // Call load_callback
                    if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) {
                        foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) {
                            if (is_array($callback)) {
                                $this->import($callback[0]);
                                $this->varValue = $this->{$callback}[0]->{$callback}[1]($this->varValue, $this);
                            } elseif (is_callable($callback)) {
                                $this->varValue = $callback($this->varValue, $this);
                            }
                        }
                    }
                    // Build row
                    $blnAjax ? $strAjax .= $this->row() : ($return .= $this->row());
                }
                $class = 'tl_box';
                $return .= "\n" . '</fieldset>';
            }
        }
        $this->import('Files');
        // Check whether the target file is writeable
        if (!$this->Files->is_writeable('system/config/localconfig.php')) {
            \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['notWriteable'], 'system/config/localconfig.php'));
        }
        // Submit buttons
        $arrButtons = array();
        $arrButtons['save'] = '<button type="submit" name="save" id="save" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['save'] . '</button>';
        $arrButtons['saveNclose'] = '<button type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c">' . $GLOBALS['TL_LANG']['MSC']['saveNclose'] . '</button>';
        // Call the buttons_callback (see #4691)
        if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) {
            foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) {
                if (is_array($callback)) {
                    $this->import($callback[0]);
                    $arrButtons = $this->{$callback}[0]->{$callback}[1]($arrButtons, $this);
                } elseif (is_callable($callback)) {
                    $arrButtons = $callback($arrButtons, $this);
                }
            }
        }
        // Add the buttons and end the form
        $return .= '
</div>

<div class="tl_formbody_submit">

<div class="tl_submit_container">
  ' . implode(' ', $arrButtons) . '
</div>

</div>
</form>

<script>
  window.addEvent(\'domready\', function() {
    Theme.focusInput("' . $this->strTable . '");
  });
</script>';
        // Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field)
        $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>
' . \Message::generate() . '
<form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '>

<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="' . $this->strTable . '">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">
<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">' . ($this->noReload ? '

<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return;
        // Reload the page to prevent _POST variables from being sent twice
        if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) {
            // Call onsubmit_callback
            if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) {
                foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) {
                    if (is_array($callback)) {
                        $this->import($callback[0]);
                        $this->{$callback}[0]->{$callback}[1]($this);
                    } elseif (is_callable($callback)) {
                        $callback($this);
                    }
                }
            }
            // Reload
            if (isset($_POST['saveNclose'])) {
                \Message::reset();
                \System::setCookie('BE_PAGE_OFFSET', 0, 0);
                $this->redirect($this->getReferer());
            }
            $this->reload();
        }
        // Set the focus if there is an error
        if ($this->noReload) {
            $return .= '

<script>
  window.addEvent(\'domready\', function() {
    Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20));
  });
</script>';
        }
        return $return;
    }
コード例 #20
0
 /**
  * @param null $dc
  */
 public function sendPasswordEmail($dc = null)
 {
     // Front end call
     if (!$dc instanceof DataContainer) {
         return;
     }
     if ($this->isDisabledAccountmail($dc)) {
         return;
     }
     // Return if there is no active record
     if (!$dc->activeRecord) {
         return;
     }
     // Send login data
     if ($dc->activeRecord->sendLoginData == 1) {
         // Set different passwords on overrideAll mode, when no password was given
         if (Input::get('act') == 'overrideAll' && $GLOBALS['ACCOUNTMAIL']['AUTO_PASSWORD'] === true) {
             $this->setPostPassword('', $dc->id);
         }
         if ($this->getPostPassword($dc->id) == '' || $this->getPostPassword($dc->id) == '*****') {
             // Set empty password
             $this->setPostPassword('', $dc->id);
             // Generate new password
             $this->setAutoPassword($dc);
         }
         if ($this->getPostPassword($dc->id) != '' && $this->getPostPassword($dc->id) != '*****') {
             $strType = $this->getType($dc);
             $arrParameters = $this->getParameters($dc);
             $strLanguage = $this->getAccountLanguage($dc);
             if (!strlen($strType)) {
                 return;
             }
             if ($this->sendEmail($dc->activeRecord->email, $strType, $arrParameters, $strLanguage)) {
                 // Disable sendLoginData field
                 $dc->activeRecord->sendLoginData = '';
                 // Disable sendLoginData field in the database
                 Database::getInstance()->prepare("UPDATE " . $dc->table . " SET sendLoginData='', loginDataAlreadySent='1' WHERE id=?")->execute($dc->activeRecord->id);
                 // Show success message
                 Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['login_data_send']);
             } else {
                 // Show error message
                 Message::addError($GLOBALS['TL_LANG']['MSC']['login_data_not_send']);
             }
         }
     }
 }
コード例 #21
0
ファイル: Theme.php プロジェクト: contao/core-bundle
 /**
  * Extract the theme files and write the data to the database
  *
  * @param array $arrFiles
  * @param array $arrDbFields
  */
 protected function extractThemeFiles($arrFiles, $arrDbFields)
 {
     foreach ($arrFiles as $strZipFile) {
         $xml = null;
         // Open the archive
         $objArchive = new \ZipReader($strZipFile);
         // Extract all files
         while ($objArchive->next()) {
             // Load the XML file
             if ($objArchive->file_name == 'theme.xml') {
                 $xml = new \DOMDocument();
                 $xml->preserveWhiteSpace = false;
                 $xml->loadXML($objArchive->unzip());
                 continue;
             }
             // Limit file operations to files and the templates directory
             if (strncmp($objArchive->file_name, 'files/', 6) !== 0 && strncmp($objArchive->file_name, 'tl_files/', 9) !== 0 && strncmp($objArchive->file_name, 'templates/', 10) !== 0) {
                 \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidFile'], $objArchive->file_name));
                 continue;
             }
             // Extract the files
             try {
                 \File::putContent($this->customizeUploadPath($objArchive->file_name), $objArchive->unzip());
             } catch (\Exception $e) {
                 \Message::addError($e->getMessage());
             }
         }
         // Continue if there is no XML file
         if (!$xml instanceof \DOMDocument) {
             \Message::addError(sprintf($GLOBALS['TL_LANG']['tl_theme']['missing_xml'], basename($strZipFile)));
             continue;
         }
         $arrMapper = array();
         $tables = $xml->getElementsByTagName('table');
         $arrNewFolders = array();
         // Extract the folder names from the XML file
         for ($i = 0; $i < $tables->length; $i++) {
             if ($tables->item($i)->getAttribute('name') == 'tl_theme') {
                 $fields = $tables->item($i)->childNodes->item(0)->childNodes;
                 for ($k = 0; $k < $fields->length; $k++) {
                     if ($fields->item($k)->getAttribute('name') == 'folders') {
                         $arrNewFolders = \StringUtil::deserialize($fields->item($k)->nodeValue);
                         break;
                     }
                 }
                 break;
             }
         }
         // Sync the new folder(s)
         if (!empty($arrNewFolders) && is_array($arrNewFolders)) {
             foreach ($arrNewFolders as $strFolder) {
                 $strCustomized = $this->customizeUploadPath($strFolder);
                 if (\Dbafs::shouldBeSynchronized($strCustomized)) {
                     \Dbafs::addResource($strCustomized);
                 }
             }
         }
         // Lock the tables
         $arrLocks = array('tl_files' => 'WRITE', 'tl_theme' => 'WRITE', 'tl_style_sheet' => 'WRITE', 'tl_style' => 'WRITE', 'tl_module' => 'WRITE', 'tl_layout' => 'WRITE', 'tl_image_size' => 'WRITE', 'tl_image_size_item' => 'WRITE');
         // Load the DCAs of the locked tables (see #7345)
         foreach (array_keys($arrLocks) as $table) {
             $this->loadDataContainer($table);
         }
         $this->Database->lockTables($arrLocks);
         // Get the current auto_increment values
         $tl_files = $this->Database->getNextId('tl_files');
         $tl_theme = $this->Database->getNextId('tl_theme');
         $tl_style_sheet = $this->Database->getNextId('tl_style_sheet');
         $tl_style = $this->Database->getNextId('tl_style');
         $tl_module = $this->Database->getNextId('tl_module');
         $tl_layout = $this->Database->getNextId('tl_layout');
         $tl_image_size = $this->Database->getNextId('tl_image_size');
         $tl_image_size_item = $this->Database->getNextId('tl_image_size_item');
         // Build the mapper data (see #8326)
         for ($i = 0; $i < $tables->length; $i++) {
             $rows = $tables->item($i)->childNodes;
             $table = $tables->item($i)->getAttribute('name');
             // Skip invalid tables
             if (!in_array($table, array_keys($arrLocks))) {
                 continue;
             }
             // Loop through the rows
             for ($j = 0; $j < $rows->length; $j++) {
                 $fields = $rows->item($j)->childNodes;
                 // Loop through the fields
                 for ($k = 0; $k < $fields->length; $k++) {
                     // Increment the ID
                     if ($fields->item($k)->getAttribute('name') == 'id') {
                         $arrMapper[$table][$fields->item($k)->nodeValue] = ${$table}++;
                         break;
                     }
                 }
             }
         }
         // Loop through the tables
         for ($i = 0; $i < $tables->length; $i++) {
             $rows = $tables->item($i)->childNodes;
             $table = $tables->item($i)->getAttribute('name');
             // Skip invalid tables
             if (!in_array($table, array_keys($arrLocks))) {
                 continue;
             }
             // Get the order fields
             $objDcaExtractor = \DcaExtractor::getInstance($table);
             $arrOrder = $objDcaExtractor->getOrderFields();
             // Loop through the rows
             for ($j = 0; $j < $rows->length; $j++) {
                 $set = array();
                 $fields = $rows->item($j)->childNodes;
                 // Loop through the fields
                 for ($k = 0; $k < $fields->length; $k++) {
                     $value = $fields->item($k)->nodeValue;
                     $name = $fields->item($k)->getAttribute('name');
                     // Skip NULL values
                     if ($value == 'NULL') {
                         continue;
                     } elseif ($name == 'id') {
                         $value = $arrMapper[$table][$value];
                     } elseif ($name == 'pid') {
                         if ($table == 'tl_style') {
                             $value = $arrMapper['tl_style_sheet'][$value];
                         } elseif ($table == 'tl_image_size_item') {
                             $value = $arrMapper['tl_image_size'][$value];
                         } else {
                             $value = $arrMapper['tl_theme'][$value];
                         }
                     } elseif ($name == 'fallback') {
                         $value = '';
                     } elseif ($table == 'tl_layout' && $name == 'stylesheet') {
                         $stylesheets = \StringUtil::deserialize($value);
                         if (is_array($stylesheets)) {
                             foreach (array_keys($stylesheets) as $key) {
                                 $stylesheets[$key] = $arrMapper['tl_style_sheet'][$stylesheets[$key]];
                             }
                             $value = serialize($stylesheets);
                         }
                     } elseif ($table == 'tl_layout' && $name == 'modules') {
                         $modules = \StringUtil::deserialize($value);
                         if (is_array($modules)) {
                             foreach ($modules as $key => $mod) {
                                 if ($mod['mod'] > 0) {
                                     $modules[$key]['mod'] = $arrMapper['tl_module'][$mod['mod']];
                                 }
                             }
                             $value = serialize($modules);
                         }
                     } elseif (($table == 'tl_theme' || $table == 'tl_style_sheet') && $name == 'name') {
                         $objCount = $this->Database->prepare("SELECT COUNT(*) AS count FROM " . $table . " WHERE name=?")->execute($value);
                         if ($objCount->count > 0) {
                             $value = preg_replace('/( |\\-)[0-9]+$/', '', $value);
                             $value .= ($table == 'tl_style_sheet' ? '-' : ' ') . ${$table};
                         }
                     } elseif (($table == 'tl_style_sheet' || $table == 'tl_style' || $table == 'tl_files' && $name == 'path') && strpos($value, 'files') !== false) {
                         $tmp = \StringUtil::deserialize($value);
                         if (is_array($tmp)) {
                             foreach ($tmp as $kk => $vv) {
                                 $tmp[$kk] = $this->customizeUploadPath($vv);
                             }
                             $value = serialize($tmp);
                         } else {
                             $value = $this->customizeUploadPath($value);
                         }
                     } elseif ($GLOBALS['TL_DCA'][$table]['fields'][$name]['inputType'] == 'fileTree' && !$GLOBALS['TL_DCA'][$table]['fields'][$name]['eval']['multiple']) {
                         if (!$value) {
                             $value = null;
                             // Contao >= 3.2
                         } else {
                             // Do not use the FilesModel here – tables are locked!
                             $objFile = $this->Database->prepare("SELECT uuid FROM tl_files WHERE path=?")->limit(1)->execute($this->customizeUploadPath($value));
                             $value = $objFile->uuid;
                         }
                     } elseif ($GLOBALS['TL_DCA'][$table]['fields'][$name]['inputType'] == 'fileTree' || in_array($name, $arrOrder)) {
                         $tmp = \StringUtil::deserialize($value);
                         if (is_array($tmp)) {
                             foreach ($tmp as $kk => $vv) {
                                 // Do not use the FilesModel here – tables are locked!
                                 $objFile = $this->Database->prepare("SELECT uuid FROM tl_files WHERE path=?")->limit(1)->execute($this->customizeUploadPath($vv));
                                 $tmp[$kk] = $objFile->uuid;
                             }
                             $value = serialize($tmp);
                         }
                     } elseif ($GLOBALS['TL_DCA'][$table]['fields'][$name]['inputType'] == 'imageSize') {
                         $imageSizes = \StringUtil::deserialize($value, true);
                         if (!empty($imageSizes)) {
                             if (is_numeric($imageSizes[2])) {
                                 $imageSizes[2] = $arrMapper['tl_image_size'][$imageSizes[2]];
                             }
                         }
                         $value = serialize($imageSizes);
                     }
                     $set[$name] = $value;
                 }
                 // Skip fields that are not in the database (e.g. because of missing extensions)
                 foreach ($set as $k => $v) {
                     if (!in_array($k, $arrDbFields[$table])) {
                         unset($set[$k]);
                     }
                 }
                 // Create the templates folder even if it is empty (see #4793)
                 if ($table == 'tl_theme' && isset($set['templates']) && strncmp($set['templates'], 'templates/', 10) === 0 && !is_dir(TL_ROOT . '/' . $set['templates'])) {
                     new \Folder($set['templates']);
                 }
                 // Update tl_files (entries have been created by the Dbafs class)
                 if ($table == 'tl_files') {
                     $this->Database->prepare("UPDATE {$table} %s WHERE path=?")->set($set)->execute($set['path']);
                 } else {
                     $this->Database->prepare("INSERT INTO {$table} %s")->set($set)->execute();
                 }
             }
         }
         // Unlock the tables
         $this->Database->unlockTables();
         // Update the style sheets
         $this->import('StyleSheets');
         $this->StyleSheets->updateStyleSheets();
         // Notify the user
         \Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_theme']['theme_imported'], basename($strZipFile)));
         // HOOK: add custom logic
         if (isset($GLOBALS['TL_HOOKS']['extractThemeFiles']) && is_array($GLOBALS['TL_HOOKS']['extractThemeFiles'])) {
             $intThemeId = empty($arrMapper['tl_theme']) ? null : reset($arrMapper['tl_theme']);
             foreach ($GLOBALS['TL_HOOKS']['extractThemeFiles'] as $callback) {
                 \System::importStatic($callback[0])->{$callback[1]}($xml, $objArchive, $intThemeId, $arrMapper);
             }
         }
         unset($tl_files, $tl_theme, $tl_style_sheet, $tl_style, $tl_module, $tl_layout, $tl_image_size, $tl_image_size_item);
     }
     \System::setCookie('BE_PAGE_OFFSET', 0, 0);
     /** @var SessionInterface $objSession */
     $objSession = \System::getContainer()->get('session');
     $objSession->remove('uploaded_themes');
     // Redirect
     $this->redirect(str_replace('&key=importTheme', '', \Environment::get('request')));
 }
コード例 #22
0
ファイル: BackendMain.php プロジェクト: bytehead/core-bundle
 /**
  * Add the welcome screen
  *
  * @return string
  */
 protected function welcomeScreen()
 {
     \System::loadLanguageFile('explain');
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_welcome');
     $objTemplate->messages = \Message::generateUnwrapped() . \Backend::getSystemMessages();
     $objTemplate->loginMsg = $GLOBALS['TL_LANG']['MSC']['firstLogin'];
     // Add the login message
     if ($this->User->lastLogin > 0) {
         $formatter = new DateTimeFormatter(\System::getContainer()->get('translator'));
         $diff = $formatter->formatDiff(new \DateTime(date('Y-m-d H:i:s', $this->User->lastLogin)), new \DateTime());
         $objTemplate->loginMsg = sprintf($GLOBALS['TL_LANG']['MSC']['lastLogin'][1], '<time title="' . \Date::parse(\Config::get('datimFormat'), $this->User->lastLogin) . '">' . $diff . '</time>');
     }
     // Add the versions overview
     \Versions::addToTemplate($objTemplate);
     $objTemplate->welcome = sprintf($GLOBALS['TL_LANG']['MSC']['welcomeTo'], \Config::get('websiteTitle'));
     $objTemplate->showDifferences = \StringUtil::specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MSC']['showDifferences']));
     $objTemplate->recordOfTable = \StringUtil::specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MSC']['recordOfTable']));
     $objTemplate->systemMessages = $GLOBALS['TL_LANG']['MSC']['systemMessages'];
     $objTemplate->shortcuts = $GLOBALS['TL_LANG']['MSC']['shortcuts'][0];
     $objTemplate->shortcutsLink = $GLOBALS['TL_LANG']['MSC']['shortcuts'][1];
     $objTemplate->editElement = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['editElement']);
     return $objTemplate->parse();
 }
コード例 #23
0
ファイル: RebuildIndex.php プロジェクト: contao/core-bundle
 /**
  * Generate the module
  *
  * @return string
  */
 public function run()
 {
     if (!\Config::get('enableSearch')) {
         return '';
     }
     $time = time();
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_rebuild_index');
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->indexHeadline = $GLOBALS['TL_LANG']['tl_maintenance']['searchIndex'];
     $objTemplate->isActive = $this->isActive();
     $objTemplate->message = \Message::generateUnwrapped();
     // Rebuild the index
     if (\Input::get('act') == 'index') {
         // Check the request token (see #4007)
         if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) {
             /** @var SessionInterface $objSession */
             $objSession = \System::getContainer()->get('session');
             $objSession->set('INVALID_TOKEN_URL', \Environment::get('request'));
             $this->redirect('contao/confirm.php');
         }
         $arrPages = $this->findSearchablePages();
         // HOOK: take additional pages
         if (isset($GLOBALS['TL_HOOKS']['getSearchablePages']) && is_array($GLOBALS['TL_HOOKS']['getSearchablePages'])) {
             foreach ($GLOBALS['TL_HOOKS']['getSearchablePages'] as $callback) {
                 $this->import($callback[0]);
                 $arrPages = $this->{$callback[0]}->{$callback[1]}($arrPages);
             }
         }
         // Return if there are no pages
         if (empty($arrPages)) {
             \Message::addError($GLOBALS['TL_LANG']['tl_maintenance']['noSearchable']);
             $this->redirect($this->getReferer());
         }
         // Truncate the search tables
         $this->import('Automator');
         $this->Automator->purgeSearchTables();
         // Hide unpublished elements
         $this->setCookie('FE_PREVIEW', 0, $time - 86400, null, null, \Environment::get('ssl'), true);
         // Calculate the hash
         $strHash = $this->getSessionHash('FE_USER_AUTH');
         // Remove old sessions
         $this->Database->prepare("DELETE FROM tl_session WHERE tstamp<? OR hash=?")->execute($time - \Config::get('sessionTimeout'), $strHash);
         // Log in the front end user
         if (is_numeric(\Input::get('user')) && \Input::get('user') > 0) {
             // Insert a new session
             $this->Database->prepare("INSERT INTO tl_session (pid, tstamp, name, sessionID, ip, hash) VALUES (?, ?, ?, ?, ?, ?)")->execute(\Input::get('user'), $time, 'FE_USER_AUTH', \System::getContainer()->get('session')->getId(), \Environment::get('ip'), $strHash);
             // Set the cookie
             $this->setCookie('FE_USER_AUTH', $strHash, $time + \Config::get('sessionTimeout'), null, null, \Environment::get('ssl'), true);
         } else {
             // Unset the cookies
             $this->setCookie('FE_USER_AUTH', $strHash, $time - 86400, null, null, \Environment::get('ssl'), true);
             $this->setCookie('FE_AUTO_LOGIN', \Input::cookie('FE_AUTO_LOGIN'), $time - 86400, null, null, \Environment::get('ssl'), true);
         }
         $strBuffer = '';
         $rand = rand();
         // Display the pages
         for ($i = 0, $c = count($arrPages); $i < $c; $i++) {
             $strBuffer .= '<span class="page_url" data-url="' . $arrPages[$i] . '#' . $rand . $i . '">' . \StringUtil::substr($arrPages[$i], 100) . '</span><br>';
             unset($arrPages[$i]);
             // see #5681
         }
         $objTemplate->content = $strBuffer;
         $objTemplate->note = $GLOBALS['TL_LANG']['tl_maintenance']['indexNote'];
         $objTemplate->loading = $GLOBALS['TL_LANG']['tl_maintenance']['indexLoading'];
         $objTemplate->complete = $GLOBALS['TL_LANG']['tl_maintenance']['indexComplete'];
         $objTemplate->indexContinue = $GLOBALS['TL_LANG']['MSC']['continue'];
         $objTemplate->theme = \Backend::getTheme();
         $objTemplate->isRunning = true;
         return $objTemplate->parse();
     }
     $arrUser = array('' => '-');
     // Get active front end users
     $objUser = $this->Database->execute("SELECT id, username FROM tl_member WHERE disable!='1' AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') ORDER BY username");
     while ($objUser->next()) {
         $arrUser[$objUser->id] = $objUser->username . ' (' . $objUser->id . ')';
     }
     // Default variables
     $objTemplate->user = $arrUser;
     $objTemplate->indexLabel = $GLOBALS['TL_LANG']['tl_maintenance']['frontendUser'][0];
     $objTemplate->indexHelp = \Config::get('showHelp') && strlen($GLOBALS['TL_LANG']['tl_maintenance']['frontendUser'][1]) ? $GLOBALS['TL_LANG']['tl_maintenance']['frontendUser'][1] : '';
     $objTemplate->indexSubmit = $GLOBALS['TL_LANG']['tl_maintenance']['indexSubmit'];
     return $objTemplate->parse();
 }