/** * Constructor - Sets the templateDir and compileDir for the Smarty files * @param <String> - $media Layout/Media name */ function __construct($media = '') { parent::__construct(); $THISDIR = dirname(__FILE__); $compileDir = ''; $templateDir = []; if (!empty($media)) { self::$currentLayout = $media; $customTemplatesDir = $THISDIR . '/../../custom/layouts/' . $media; $templateDir[] = $THISDIR . '/../../layouts/' . $media; $compileDir = $THISDIR . '/../../cache/templates_c/' . $media; } else { self::$currentLayout = Yeti_Layout::getActiveLayout(); $templateDir[] = $THISDIR . '/../../custom/layouts/' . self::$currentLayout; $templateDir[] = $THISDIR . '/../../layouts/' . self::$currentLayout; } $templateDir[] = $THISDIR . '/../../custom/layouts/' . self::getDefaultLayoutName(); $templateDir[] = $THISDIR . '/../../layouts/' . self::getDefaultLayoutName(); $compileDir = $THISDIR . '/../../cache/templates_c/' . self::getDefaultLayoutName(); if (!file_exists($compileDir)) { mkdir($compileDir, 0777, true); } $this->setTemplateDir($templateDir); $this->setCompileDir($compileDir); self::$debugViewer = AppConfig::debug('DEBUG_VIEWER'); // FOR SECURITY // Escape all {$variable} to overcome XSS // We need to use {$variable nofilter} to overcome double escaping // TODO: Until we review the use disabled. //$this->registerFilter('variable', array($this, 'safeHtmlFilter')); // FOR DEBUGGING: We need to have this only once. static $debugViewerURI = false; if (self::$debugViewer && $debugViewerURI === false) { $debugViewerURI = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); if (!empty($_POST)) { $debugViewerURI .= '?' . http_build_query($_POST); } else { $debugViewerURI = $_SERVER['REQUEST_URI']; } $this->log("URI: {$debugViewerURI}, TYPE: " . $_SERVER['REQUEST_METHOD']); } }
/** * Getting template name * @return string templateName */ public function getTemplateName($view, $moduleName) { $tpl = $view . $this->name . '.tpl'; $filename = 'layouts' . DIRECTORY_SEPARATOR . Yeti_Layout::getActiveLayout() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl; if (is_file($filename)) { return $tpl; } $filename = 'layouts' . DIRECTORY_SEPARATOR . Yeti_Layout::getActiveLayout() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'Vtiger' . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl; if (is_file($filename)) { return $tpl; } $filename = 'layouts' . DIRECTORY_SEPARATOR . Vtiger_Viewer::getDefaultLayoutName() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl; if (is_file($filename)) { return $tpl; } $filename = 'layouts' . DIRECTORY_SEPARATOR . Vtiger_Viewer::getDefaultLayoutName() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'Vtiger' . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl; if (is_file($filename)) { return $tpl; } return $view . 'Base' . '.tpl'; }
/** * Function returns the css files * @param <Array> $cssFileNames * @param <String> $fileExtension * @return <Array of Vtiger_CssScript_Model> * * First check if $cssFileName exists * if not, check under layout folder $cssFileName eg:layouts/basic/$cssFileName */ function checkAndConvertCssStyles($cssFileNames, $fileExtension = 'css') { $cssStyleInstances = []; foreach ($cssFileNames as $cssFileName) { $cssScriptModel = new Vtiger_CssScript_Model(); if (strpos($cssFileName, 'http://') === 0 || strpos($cssFileName, 'https://') === 0) { $cssStyleInstances[] = $cssScriptModel->set('href', $cssFileName); continue; } $completeFilePath = Vtiger_Loader::resolveNameToPath($cssFileName, $fileExtension); if (file_exists($completeFilePath)) { if (strpos($cssFileName, '~') === 0) { $filePath = ltrim(ltrim($cssFileName, '~'), '/'); } else { $filePath = str_replace('.', '/', $cssFileName) . '.' . $fileExtension; } $minFilePath = str_replace('.css', '.min.css', $filePath); if (Vtiger_Functions::getMinimizationOptions($fileExtension) && is_file(Vtiger_Loader::resolveNameToPath('~' . $minFilePath, $fileExtension))) { $filePath = $minFilePath; } $cssStyleInstances[$cssFileName] = $cssScriptModel->set('href', $filePath); continue; } else { $preLayoutPath = ''; if (strpos($cssFileName, '~') === 0) { $cssFile = ltrim(ltrim($cssFileName, '~'), '/'); $preLayoutPath = '~'; } else { $cssFile = $cssFileName; } // Checking if file exists in selected layout $layoutPath = 'layouts' . '/' . Yeti_Layout::getActiveLayout(); $fallBackFilePath = Vtiger_Loader::resolveNameToPath($preLayoutPath . $layoutPath . '/' . $cssFile, $fileExtension); if (is_file($fallBackFilePath)) { if (empty($preLayoutPath)) { $filePath = str_replace('.', '/', $cssFile) . '.css'; } $minFilePath = str_replace('.css', '.min.css', $filePath); if (Vtiger_Functions::getMinimizationOptions($fileExtension) && is_file(Vtiger_Loader::resolveNameToPath('~' . $layoutPath . '/' . $minFilePath, $fileExtension))) { $filePath = $minFilePath; } $cssStyleInstances[$cssFileName] = $cssScriptModel->set('href', $layoutPath . '/' . $filePath); continue; } // Checking if file exists in default layout $layoutPath = 'layouts' . '/' . Vtiger_Viewer::getDefaultLayoutName(); $fallBackFilePath = Vtiger_Loader::resolveNameToPath($preLayoutPath . $layoutPath . '/' . $cssFile, $fileExtension); if (is_file($fallBackFilePath)) { if (empty($preLayoutPath)) { $filePath = str_replace('.', '/', $cssFile) . '.css'; } $minFilePath = str_replace('.css', '.min.css', $filePath); if (Vtiger_Functions::getMinimizationOptions($fileExtension) && is_file(Vtiger_Loader::resolveNameToPath('~' . $layoutPath . '/' . $minFilePath, $fileExtension))) { $filePath = $minFilePath; } $cssStyleInstances[$cssFileName] = $cssScriptModel->set('href', $layoutPath . '/' . $filePath); continue; } } } return $cssStyleInstances; }
/** * Function to get the instance of Vtiger Link Model from a given Vtiger_Link object * @param Vtiger_Link $linkObj * @return Vtiger_Link_Model instance */ public static function getInstanceFromLinkObject(Vtiger_Link $linkObj) { $objectProperties = get_object_vars($linkObj); $linkModel = new self(); foreach ($objectProperties as $properName => $propertyValue) { $linkModel->{$properName} = $propertyValue; } // added support for multilayout if (strpos($linkModel->linkurl, '_layoutName_') !== false) { $filePath1 = str_replace('_layoutName_', Yeti_Layout::getActiveLayout(), $linkModel->linkurl); $filePath2 = str_replace('_layoutName_', Yeti_Layout::getActiveLayout(), $linkModel->linkurl); if (is_file(vglobal('root_directory') . $filePath1)) { $linkModel->linkurl = $filePath1; } else { if (is_file(vglobal('root_directory') . $filePath2)) { $linkModel->linkurl = $filePath2; } } } return $linkModel; }