Esempio n. 1
0
 /**
  * Show all columns in table
  * @param string $tbl - table name
  * @return array - list
  */
 public static function getFields($tbl)
 {
     if (Settings::isCacheEnabled()) {
         $cache_key = 'db_table_columns_' . $tbl;
         $cacher = Cacher::getInstance()->getDefaultCacher();
         if (!isset(self::$_cached_tbl_columns[$tbl])) {
             self::$_cached_tbl_columns[$tbl] = $cacher->get($cache_key);
         }
     }
     if (isset(self::$_cached_tbl_columns[$tbl])) {
         return self::$_cached_tbl_columns[$tbl];
     }
     $res = [];
     $sql = self::getInstance()->sql_query("SHOW COLUMNS FROM `{$tbl}`");
     while ($q = $sql->fetch(PDO::FETCH_NUM)) {
         $res[] = $q[0];
     }
     if (Settings::isCacheEnabled()) {
         $cacher->set($cache_key, $res, 86400);
     }
     return self::$_cached_tbl_columns[$tbl] = $res;
 }
 /**
  * Get Setting object
  * @param string $module
  * @param string $key
  * @return CustomSetting
  */
 public static function getCustomSetting($module, $key)
 {
     // Check cache
     if (Settings::isCacheEnabled()) {
         $cache_key = 'module_custom_settings_all';
         $cacher = Cacher::getInstance()->getDefaultCacher();
         if (!self::$cached_settings) {
             self::$cached_settings = $cacher->get($cache_key);
         }
     }
     if (!self::$cached_settings) {
         // To prevent more iterations
         self::$cached_settings['empty']['empty'] = '';
         $settings = new CustomSettingRepository();
         foreach ($settings->getAsArrayOfObjects() as $setting) {
             /** @var CustomSetting $setting */
             self::$cached_settings[$setting->getModule()][$setting->getKey()] = $setting;
         }
     }
     // Save cache
     if (Settings::isCacheEnabled()) {
         $cacher->set($cache_key, self::$cached_settings, 86400);
     }
     return isset(self::$cached_settings[$module][$key]) ? self::$cached_settings[$module][$key] : NULL;
 }
Esempio n. 3
0
 /**
  * Print processed page template with all data
  * @return string
  */
 public function __toString()
 {
     // If content is is rendered from cache
     if (Settings::isCacheEnabled() && $this->cached_page_html) {
         return $this->cached_page_html;
     }
     // Using clickmap script for client click tracking
     if (Settings::get('clickmap')) {
         // Show map on page
         if (isset($_GET['cms_view_clickmap'])) {
             // Load script to show clickmap container
             PageTail::getInstance()->addJsUrl('clickmap_frontend.js');
             PageHead::getInstance()->addJs('cms_page_id = ' . PAGE_ID);
         } else {
             // Just saving clicks - request scripts for registering clicks
             PageTail::getInstance()->addJsUrl('clickmap_register.js');
             PageHead::getInstance()->addJs('cms_page_id = ' . PAGE_ID);
         }
     }
     // Require js for Visual editor
     if (VisualEdit::getInstance()->isEnabled()) {
         PageHead::getInstance()->addJsUrl('visual_edit.js');
         PageHead::getInstance()->addJs('cms_page_id = "' . PAGE_ID . '"');
     }
     // Render HTML
     ob_start();
     // Static page from file
     if ($this->use_html_file_without_parse) {
         echo $this->html;
     } else {
         // Parse content
         // Hide e-mails from bots
         if (strpos($this->html, '@') !== false && preg_match_all('`\\<a([^>]+)href\\=\\"mailto\\:([^">]+)\\"([^>]*)\\>(.+)\\<\\/a\\>`ismU', $this->html, $matches)) {
             PageHead::getInstance()->addJsUrl('email_rewrite.js');
             $matches[5] = [];
             // Replace emails in content with script calls
             foreach ($matches[0] as $k => $v) {
                 // No email?
                 if (isset($matches[5][$v])) {
                     continue;
                 }
                 // No @ symbol?
                 $s = explode('@', $matches[2][$k]);
                 if (count($s) !== 2) {
                     continue;
                 }
                 // No zone?
                 $domain1 = explode('.', $s[1]);
                 $s = $s[0];
                 if (count($domain1) < 2) {
                     continue;
                 }
                 // Now can replace
                 $domain0 = array_pop($domain1);
                 $s = '<script>rewem2nortex("' . preg_replace('/\\sclass=\\"(.+)\\"/', '\\1', str_replace('"', '\'', $matches[3][$k])) . '","' . $s . '","' . implode('.', $domain1) . '","' . $domain0 . '"';
                 if ($matches[2][$k] !== $matches[4][$k]) {
                     $s .= ',"' . trim(str_replace(['@', '.'], ['"+"@"+"', '"+"."+"'], preg_replace('`\\<([a-z])`', '<"+"\\1', str_replace('"', '\\"', $matches[4][$k])))) . '"';
                 }
                 $s .= ');</script>';
                 $matches[5][$v] = $s;
             }
             $matches = $matches[5];
             // Replace found emails with scripts in content
             $this->html = str_replace(array_keys($matches), $matches, $this->html);
         }
         // For developers using git - site version from latest git commit, add to last meta tag
         if (function_exists('exec')) {
             $output = [];
             exec('git log -1 --pretty=format:\'%h (%ci)\' --abbrev-commit', $output);
             if ($output && isset($output[0])) {
                 PageHead::getInstance()->addMeta($output[0], 'X-Version');
             }
         }
         // Page with components itself
         $this->outputHead();
         // Put body tag if not found in template
         if (!strpos($this->html, '<body')) {
             // No trailing bracket ! may have class
             $classes = PageHead::getInstance()->getBodyCssClasses();
             echo '<body' . ($classes ? ' class="' . implode(' ', $classes) . '"' : '') . '>';
         }
         // Main page content
         $this->outputHtml();
         // Post-scripts
         $this->outputTail();
         // Put closing body tag if not found in template
         if (!strpos($this->html, '</body>')) {
             echo '</body>';
         }
         echo '</html>';
     }
     $html = ob_get_clean();
     // HTML optimization in rendered content
     if (Settings::get('optimize_html')) {
         $html = Optimize::HTML($html);
     }
     // Put in cache
     if (Settings::get('use_file_cache_for_all_pages') && Settings::isCacheEnabled()) {
         Cacher::getInstance()->getDefaultCacher()->set('html_' . PATH_INTERNAL_MD5, $html);
     }
     // Encode ff browser supports gzip
     if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
         $html = gzencode($html, 6);
         // 6 is ok with speed and compression rate
         header('Content-Encoding: gzip');
     }
     // Set cache headers for one hour
     if (Settings::isCacheEnabled() && !headers_sent()) {
         header("Cache-Control: max-age=2592000");
         header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 3600));
     }
     return $html;
 }
Esempio n. 4
0
 /**
  * Preload all data of plugins
  */
 private static function init()
 {
     if (!self::$data_initialized) {
         self::$data_initialized = true;
         $page_components_collection = new PageComponentRepository();
         $page_components_collection->setWherePageId(PAGE_ID);
         $page_components_collection->addWhereFieldIsLike('component', 'select_plugin');
         if (Settings::isCacheEnabled()) {
             $page_components_collection->enableUsingCache();
         }
         self::$data = $page_components_collection->getPairs('data', 'component');
     }
 }