/** * 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; }
<?php use TMCms\Templates\VisualEdit; VisualEdit::getInstance()->init(); if (!VisualEdit::getInstance()->isEnabled()) { return; } if (!isset($_POST['content'], $_POST['component'], $_POST['page_id'])) { return; } q('UPDATE `cms_pages_components` SET `data` = "' . sql_prepare($_POST['content']) . '" WHERE `page_id` = "' . (int) $_POST['page_id'] . '" AND `component` = "' . sql_prepare($_POST['component']) . '" '); echo json_encode(['status' => true]);