addon = new UniteCreatorAddon(); $this->objTemplate = new UniteCreatorTemplateEngine(); $this->processType = UniteCreatorParamsProcessor::PROCESS_TYPE_OUTPUT; } /** * set output type */ public function setProcessType($type){ UniteCreatorParamsProcessor::validateProcessType($type); $this->processType = $type; } /** * validate inited */ private function validateInited(){ if($this->isInited == false) UniteFunctionsUC::throwError("Output error: addon not inited"); } private function a___________INCLUDES_________(){} /** * cache include */ private function cacheInclude($url, $handle, $type){ if($type == "css"){ //cache css self::$arrUrlCacheCss[$url] = true; self::$arrHandleCacheCss[$handle] = true; }else{ //cache js self::$arrUrlCacheJs[$url] = true; self::$arrHandleCacheJs[$handle] = true; } } /** * check that the include located in cache */ private function isIncludeInCache($url, $handle, $type){ if(empty($url) || empty($handle)) return(false); if($type == "css"){ if(isset(self::$arrUrlCacheCss[$url])) return(true); if(isset(self::$arrHandleCacheCss[$handle])) return(true); }else{ //js if(isset(self::$arrUrlCacheJs[$url])) return(true); if(isset(self::$arrHandleCacheJs[$handle])) return(true); } return(false); } /** * check include condition * return true to include and false to not include */ private function checkIncludeCondition($condition){ if(empty($condition)) return(true); if(!is_array($condition)) return(true); $name = UniteFunctionsUC::getVal($condition, "name"); $value = UniteFunctionsUC::getVal($condition, "value"); if(empty($name)) return(true); if($name == "never_include") return(false); $params = $this->getAddonParams(); if(array_key_exists($name, $params) == false) return(true); $paramValue = $params[$name]; if($paramValue === $value) return(true); else return(false); } /** * process includes list, get array("url", type) */ private function processIncludesList($arrIncludes, $type){ $arrIncludesProcessed = array(); foreach($arrIncludes as $handle => $include){ $urlInclude = $include; if(is_array($include)){ $urlInclude = UniteFunctionsUC::getVal($include, "url"); $condition = UniteFunctionsUC::getVal($include, "condition"); $isIncludeByCondition = $this->checkIncludeCondition($condition); if($isIncludeByCondition == false) continue; } if(is_numeric($handle) || empty($handle)){ $addonName = $this->addon->getName(); $handle = HelperUC::getUrlHandle($urlInclude, $addonName); } $urlInclude = HelperUC::urlToSSLCheck($urlInclude); $arrIncludeNew = array(); $arrIncludeNew["url"] = $urlInclude; $arrIncludeNew["type"] = $type; if(!empty($handle)) $arrIncludeNew["handle"] = $handle; $arrIncludesProcessed[] = $arrIncludeNew; } return($arrIncludesProcessed); } /** * get processed includes list * includes type = js / css / all */ public function getProcessedIncludes($includeLibraries = false, $processProviderLibrary = false, $includesType = "all"){ $this->validateInited(); //get list of js and css $arrLibJs = array(); $arrLibCss = array(); if($includeLibraries == true){ //get all libraries without provider process $arrLibraries = $this->addon->getArrLibraryIncludesUrls($processProviderLibrary); } $arrIncludesJS = array(); $arrIncludesCss = array(); //get js if($includesType != "css"){ if($includeLibraries) $arrLibJs = $arrLibraries["js"]; $arrIncludesJS = $this->addon->getJSIncludes(); $arrIncludesJS = array_merge($arrLibJs, $arrIncludesJS); $arrIncludesJS = $this->processIncludesList($arrIncludesJS, "js"); } //get css if($includesType != "js"){ if($includeLibraries) $arrLibCss = $arrLibraries["css"]; $arrIncludesCss = $this->addon->getCSSIncludes(); $arrIncludesCss = array_merge($arrLibCss, $arrIncludesCss); $arrIncludesCss = $this->processIncludesList($arrIncludesCss, "css"); } $arrProcessedIncludes = array_merge($arrIncludesJS, $arrIncludesCss); return($arrProcessedIncludes); } /** * get includes html */ private function getHtmlIncludes($arrIncludes = null){ $this->validateInited(); if(empty($arrIncludes)) return(""); $addonName = $this->addon->getName(); $html = ""; foreach($arrIncludes as $include){ $type = $include["type"]; $url = $include["url"]; $handle = UniteFunctionsUC::getVal($include, "handle"); if(empty($handle)) $handle = HelperUC::getUrlHandle($url, $addonName); $isInCache = $this->isIncludeInCache($url, $handle, $type); if($isInCache == true) continue; $this->cacheInclude($url, $handle, $type); switch($type){ case "js": $html .= self::TAB2."".self::BR; break; case "css": $cssID = "{$handle}-css"; $html .= self::TAB2."".self::BR; break; default: UniteFunctionsUC::throwError("Wrong include type: {$type} "); break; } } return($html); } /** * process includes * includes type = "all,js,css" */ public function processIncludes($includesType = "all"){ $arrIncludes = $this->getProcessedIncludes(true, true, $includesType); $addonName = $this->addon->getName(); foreach($arrIncludes as $include){ $type = $include["type"]; $url = $include["url"]; $handle = UniteFunctionsUC::getVal($include, "handle"); if(empty($handle)) $handle = HelperUC::getUrlHandle($url, $addonName); $isInCache = $this->isIncludeInCache($url, $handle, $type); if($isInCache == true){ continue; } $this->cacheInclude($url, $handle, $type); switch($type){ case "js": UniteProviderFunctionsUC::addScript($handle, $url); break; case "css": UniteProviderFunctionsUC::addStyle($handle, $url); break; default: UniteFunctionsUC::throwError("Wrong include type: {$type} "); break; } } } private function a___________GENERAL_________(){} /** * process html before output, function for override */ protected function processHtml($html){ return($html); } /** * place output by shortcode */ public function getHtmlBody($scriptHardCoded = true, $putCssIncludes = false, $putCssInline = true){ $this->validateInited(); $title = $this->addon->getTitle(true); $html = $this->objTemplate->getRenderedHtml(self::TEMPLATE_HTML); $html = $this->processHtml($html); //make css $css = $this->objTemplate->getRenderedHtml(self::TEMPLATE_CSS); $js = $this->objTemplate->getRenderedHtml(self::TEMPLATE_JS); //get css includes if needed $arrCssIncludes = array(); if($putCssIncludes == true) $arrCssIncludes = $this->getProcessedIncludes(true, true, "css"); $output = ""; //add css includes if needed if(!empty($arrCssIncludes)){ $htmlIncludes = $this->getHtmlIncludes($arrCssIncludes); $output .= "\n".$htmlIncludes; } //add css if(!empty($css)){ if($putCssInline == true) $output .= "\n "; else HelperUC::putInlineStyle($css); } //add html $output .= "\n\n ".$html; //output js if(!empty($js)){ $title = $this->addon->getTitle(); if($scriptHardCoded == false) $js = "// $title scripts: \n".$js; if($scriptHardCoded == false) UniteProviderFunctionsUC::printCustomScript($js); else{ $output .= "\n\n "; } } $output .= "\n "; return($output); } /** * get addon preview html */ public function getPreviewHtml(){ $this->validateInited(); $outputs = ""; $title = $this->addon->getTitle(); $title .= " ". __("Preview",ADDONLIBRARY_TEXTDOMAIN); $title = htmlspecialchars($title); //get libraries, but not process provider $htmlBody = $this->getHtmlBody(); $arrIncludes = $this->getProcessedIncludes(true, false); $htmlInlcudes = $this->getHtmlIncludes($arrIncludes); //set options $options = $this->addon->getOptions(); $bgCol = $this->addon->getOption("preview_bgcol"); $previewSize = $this->addon->getOption("preview_size"); $previewWidth = "100%"; switch($previewSize){ case "column": $previewWidth = "300px"; break; case "custom": $previewWidth = $this->addon->getOption("preview_custom_width"); if(!empty($previewWidth)){ $previewWidth = (int)$previewWidth; $previewWidth .= "px"; } break; } $style = ""; $style .= "max-width:{$previewWidth};"; $style .= "background-color:{$bgCol};"; $urlPreviewCss = GlobalsUC::$urlPlugin."css/unitecreator_preview.css"; $html = ""; $htmlHead = ""; $htmlHead = "".self::BR; $htmlHead .= "".self::BR; //output head $htmlHead .= self::TAB."
".self::BR; $html .= $htmlHead; //get head html $htmlHead .= self::TAB2."