* @package Kernel * @version $Id: VCDPage.php 1066 2007-08-15 17:05:56Z konni $ * @since 0.90 */ ?> force_compile = false; $this->compile_check = false; if ($template !== 'page.error.tpl') { $this->mod_rewrite = VCDConfig::isUsingFriendlyUrls(); } $this->template = $template; $this->template_dir = VCDDB_BASE.DIRECTORY_SEPARATOR.'pages'.DIRECTORY_SEPARATOR; $this->compile_dir = VCDDB_BASE.DIRECTORY_SEPARATOR.CACHE_FOLDER; $this->cache_dir = VCDDB_BASE.DIRECTORY_SEPARATOR.CACHE_FOLDER; $this->debugging = $this->debug; $this->verifyTemplate(); if ($doTranslate == true) { $func = array('VCDPageTransform','translate'); $this->register_prefilter($func); } } /** * Verify that the template to be rendered with Smarty actually exists. * */ private function verifyTemplate() { $template = $this->template_dir.$this->template; if (!file_exists($template)) { throw new VCDProgramException('Template "' . $this->template . '" is missing.'); } } /** * Get a value from url parameter that is passed to the page. * If $param does not exists or is an emptry string, null is returned. * * @param string $param | The parameter name * @param boolean $isPost | Ids the parameter from _POST[] or _GET[] * @param string $defaultValue| Default value to use if $param is not found * @return string | The paramter value */ protected function getParam($param, $isPost=false, $defaultValue=null) { if ($isPost) { if (isset($_POST[$param]) && (!empty($_POST[$param]))) { return $_POST[$param]; } } else { if (isset($_GET[$param]) && (strcmp($_GET[$param],'')!=0)) { return $_GET[$param]; } } return $defaultValue; } /** * Render the current template to the internal pagebuffer. * if $template is NULL $this->template is used. * * @param string $template | The template to render. */ public function render($template=null) { $compile_id = VCDClassFactory::getInstance('VCDLanguage')->getPrimaryLanguageID(); if (is_null($template)) { $buffer = $this->fetch($this->template, 'vcddb', $compile_id); } else { $buffer = $this->fetch($template, 'vcddb', $compile_id); } $base = VCDConfig::getWebBaseDir(); self::$pageBuffer .= $this->rewriteRelative($buffer,$base); } public function renderPage() { if($this->mod_rewrite) { $this->rewriteShortUrls(); } if ($this->tidy && extension_loaded('tidy')) { // Specify configuration $config = array( 'indent' => true, 'output-xhtml' => true, 'wrap' => 200); // Tidy $tidy = new tidy; $tidy->parseString(self::$pageBuffer, $config, 'utf8'); $tidy->cleanRepair(); print $tidy; } else { print self::$pageBuffer; } } private function rewriteShortUrls() { $in = array( "'index.php\?page=cd&vcd_id=([0-9]*)'", "'\?page=cd&vcd_id=([0-9]*)'", "'\?page=category&category_id=([0-9]*)&batch=([0-9]*)&viewmode=(img|text)'", "'\?page=category&category_id=([0-9]*)&batch=([0-9]*)'", "'\?page=category&category_id=([0-9]*)'", "'index.php\?page=adultcategory&(category|studio)_id=([0-9]*)'", "'\?page=adultcategory&(category|studio)_id=([0-9]*)&batch=([0-9]*)&viewmode=(img|text)'", "'\?page=adultcategory&(category|studio)_id=([0-9]*)&batch=([0-9]*)'", "'\?page=adultcategory&(category|studio)_id=([0-9]*)'", "'\?page=pornstars&view=(all|active)&l=([a-zA-Z\\+]){1}&viewmode=(img|text)'", "'\?page=pornstars&view=(all|active)'", "'\?page=pornstar&pornstar_id=([0-9]*)'", "'index.php\?page=movies&do=([a-zA-Z\\-]*)&index=([0-9]*)'", "'index.php\?page=movies&do=([a-zA-Z\\-]*)'", "'\?page=movies&do=([a-zA-Z\\-]*)&index=([0-9]*)'", "'\?page=movies&do=([a-zA-Z\\-]*)'", "'\?page=file&(cover|pornstar)_id=([0-9]*)'", "'\?page=search&by=(actor|director)&searchstring=([^\<]*)'", "'index.php\?page=([a-zA-Z\\-]*)'", "'\?page=([a-zA-Z\\-]*)'" ); $out = array( 'movie/\\1', 'movie/\\1', 'category/\\1/\\2/\\3', 'category/\\1/\\2', 'category/\\1', 'xxx/\\1/\\2', 'xxx/\\1/\\2/\\3/\\4', 'xxx/\\1/\\2/\\3', 'xxx/\\1/\\2', 'pornstars/\\1/\\2/\\3', 'pornstars/\\1', 'pornstar/\\1', 'page/movies/\\1/\\2', 'page/movies/\\1', 'page/movies/\\1/\\2', 'page/movies/\\1', 'file/\\1/\\2', 'search/\\1/\\2', 'page/\\1', 'page/\\1' ); self::$pageBuffer = preg_replace($in, $out, &self::$pageBuffer); } /** * Rewrite all urls to they become absolute, needed when mod_rewrite is used. * * @param string $html | The html buffer to transform * @param string $base | The base directory where VCD-db resides * @return string | The transformed html buffer */ private function rewriteRelative($html, $base) { // generate server-only replacement for root-relative URLs $server = preg_replace('@^([^\:]*)://([^/*]*)(/|$).*@', '\1://\2/', $base); // replace root-relative URLs $html = preg_replace('@\<([^>]*) (href|src)="/([^"]*)"@i', '<\1 \2="' . $server . '\3"', $html); // replace base-relative URLs (rather kludgy, but I couldn't get ! to work) $html = preg_replace('@\<([^>]*) (href|src|archive)="(([^\:"])*|([^"]*:[^/"].*))"@i', '<\1 \2="' . $base . '\3"', $html); return $html; } } /** * This class handles all transformations of the pagebuffer before it's sent to browser. * */ class VCDPageTransform { /** * Find translation string based on the key * * @param string $key | The translation key * @return string | The translation value */ public static function trans($key) { return VCDLanguage::translate($key[1]); } /** * Convert all the {$translate.(.*?} smarty tags to translated values. * * @param string $tpl_source | The template's source * @param Smarty $smarty | Smarty instance * @return mixed */ public static function translate($tpl_source, &$smarty) { // We hook in here to list all the included modules. /* preg_match_all('/{include file=\'module.(.*?).tpl\'}/',$tpl_source,$modules,2); if (is_array($modules)) { $list = array(); for ($i=0;$i