/** *Preparing contents from database to be rendered *with replacing of the template variables * *@author NT * */ public static function _templatePrepare($outputDB, $content = null, $lang = null, $pageInfo = null) { $db = Zend_Registry::get('db'); $title = Zend_Registry::get('pageTitle'); $langCode = self::$lang; $langCode = Zend_Registry::get('langCode'); if ($langCode == "") { //OVO MORA DA SE SKLONI!!!!! $langCode = "sr"; } $replaceThis = preg_match_all('/[{].+[}]/', $outputDB, $matches); foreach ($matches[0] as $part) { $parts = explode(":", $part); $Tvars[] = $parts; } if (count(@$Tvars)) { foreach ($Tvars as $Tvarss) { $i = 0; foreach ($Tvarss as $TV) { $module = trim($TV, "{}"); $build2[] = $module; $i++; } $build[] = $build2; $build2 = array(); } } //print_r($build); //print_r($matches); $count = 0; $cHI = 0; if (count(@$build)) { foreach ($build as $build_) { @($pattern = $matches[$count]); //TITLE OF THE PAGE //if (@preg_match("/{title}/", "{" . $build_[0] . "}" )) { if (@strstr("{" . $build_[0] . "}", "{title}")) { $output = $title; $outputDB = str_replace('{title}', $output, $outputDB); } //PAGE INFO HANDLE //if (@preg_match("/{searchform}/", "{" . $build_[0] . "}" )) { if (@strstr("{" . $build_[0] . "}", "{pageinfo}")) { $output = ViewController::pageInfo($pageInfo); $outputDB = str_replace('{pageinfo}', $output, $outputDB); } if (@strstr("{" . $build_[0] . "}", "{adminurl}")) { $outputDB = str_replace('{adminurl}', '<a href="' . NetActionController::$hostRW . NetActionController::$adminUrl . '" target="_blank">Admin (FF!/Safari/Chrome)</a>', $outputDB); } //SEARCH HANDLE //if (@preg_match("/{searchform}/", "{" . $build_[0] . "}" )) { if (@strstr("{" . $build_[0] . "}", "{searchform}")) { $output = SearchController::showSearchForm(); $outputDB = str_replace('{searchform}', $output, $outputDB); } //HTML PART HANDLE if (@strstr("{" . $build_[0], "{html")) { //$codeAll = $build_[1] . ":" . $build_[2]; //$countBuild = count($build_); $codeA = ""; foreach ($build_ as $countedB) { $codeA .= $countedB . ":"; } $codeA = ltrim($codeA, "html:"); $codeA = rtrim($codeA, ":"); $output = htmlspecialchars_decode($codeA); $output = str_replace('<br />', "", $output); $output = str_replace('<br>', "\n", $output); //$output = '<script type="text/javascript">document.write(' ."\n" . $output . ');</script>'; $outputDB = str_replace('{html:' . $codeA . '}', $output, $outputDB); //$outputDB = str_replace('{html' , $output, $outputDB); } //xHTML PART HANDLE - if this code block is to be xhtml purified if (@strstr("{" . $build_[0], "{x-html")) { $codeA = ""; foreach ($build_ as $countedB) { $codeA .= $countedB . ":"; } $codeA = ltrim($codeA, "x-html:"); $codeA = rtrim($codeA, ":"); $output = htmlspecialchars_decode($codeA); $output = str_replace('<br />', "", $output); $output = str_replace('<br>', "\n", $output); //$output = '<script type="text/javascript">document.write(' ."\n" . $output . ');</script>'; $outputDB = str_replace('{x-html:' . $codeA . '}', $output, $outputDB); //$outputDB = str_replace('{html' , $output, $outputDB); } //LANGUAGE chooser //if (@preg_match("/{language:flags}/", "{" . $build_[0] . ":flags}" )) { if (@strstr("{" . $build_[0] . ":flags}", "{language:flags}")) { $langsEnabled = NetActionController::getStaticEnabledLanguages(); /* $langQ = $db->fetchAll("SELECT * FROM languages WHERE enabled = '1'"); foreach ($langQ as $lang) { $langsEnabled[] = $lang['code']; } */ $output = ViewController::showLanguageChooser($langsEnabled); $outputDB = str_replace('{language:flags}', $output, $outputDB); } //MENU HANDLE //if (@preg_match("/menu:display/", "{" . $build_[0] . ":" . $build_[1])) { if (@strstr($build_[0] . ":" . $build_[1], "menu:display")) { $menuId = trim($build_[2], '""'); @($orientation = $build_[3]); //if ($orientation =! "slide") { //$menuQ = $db->fetchAll("SELECT *, url_en as url,name_en as name,description_en as description FROM menu_items WHERE menu_id = ?", array($menuId)); //} else { $menuQ = $db->fetchAll("SELECT *, menu_items.check_access as chkAccess, menu_items.content_id as cid, url_{$langCode} as url, name_{$langCode} as name, description_{$langCode} as description FROM menu_items LEFT JOIN pages_{$langCode} ON menu_items.content_id = pages_{$langCode}.id WHERE menu_id = ? AND pages_{$langCode}.published = '1' ORDER BY weight ASC", array($menuId)); //} //print_r($menuQ ); if (!empty($menuQ)) { $output = ViewController::displayMenu($menuQ, $orientation); if ($orientation == "") { $orient = ""; } elseif ($orientation == "vertical") { $orient = ":vertical"; } elseif ($orientation == "tree") { $orient = ":tree"; } elseif ($orientation == "slide") { $orient = ":slide"; } $outputDB = str_replace('{menu:display:' . $build_[2] . @$orient . '}', $output, $outputDB); } else { $outputDB = str_replace('{menu:display:' . $build_[2] . @$orient . '}', '<b style="color:red;">{menu:' . $build_[2] . '}Doesn\'t exist or it is empty!</b>', $outputDB); } } //CATEGORIES //if (@preg_match("/category:display/", "{" . $build_[0] . ":" . $build_[1])) { if (@strstr($build_[0] . ":" . $build_[1], "category:display")) { $catId = trim($build_[2], '""'); @($orientation = $build_[3]); $catQ = $db->fetchAll("SELECT id, title, alias, category, image, description, check_access FROM pages_{$langCode} WHERE category = ? AND pages_{$langCode}.published = '1'", array($catId)); //$catQ = $db->fetchAll("SELECT id, title, alias, category, image, description, check_access FROM pages_$langCode WHERE category = ? AND pages_$langCode.published = '1'", array($catId)); //$catQ = array(); $catItemsArray2 = $db->fetchAll("SELECT DISTINCT *, pages_{$langCode}.id as id, pages_{$langCode}.title as title, pages_{$langCode}.alias as alias, pages_{$langCode}.category as category, pages_{$langCode}.image, pages_{$langCode}.description, pages_{$langCode}.check_access as check_access FROM category_items LEFT JOIN pages_{$langCode} ON pages_{$langCode}.id = category_items.content_id WHERE category_items.category_id = ? AND pages_{$langCode}.published = '1' GROUP BY pages_{$langCode}.id DESC ", array($catId)); $catQ = array_merge($catQ, $catItemsArray2); //$catQ = $catQ + $catItemsArray2; //print_r($menuQ ); if (!empty($catQ)) { $output = ViewController::displayCategory($catQ, $orientation); if ($orientation == "") { $orient = ""; } elseif ($orientation == "oldest") { $orient = ":oldest"; } elseif ($orientation == "latest") { $orient = ":latest"; } elseif ($orientation == "desc") { $orient = ":desc"; } $outputDB = str_replace('{category:display:' . $build_[2] . @$orient . '}', $output, $outputDB); } else { $outputDB = str_replace('{category:display:' . $build_[2] . @$orient . '}', '<b style="color:red;">{category:' . $build_[2] . '}Doesn\'t exist or it is empty!</b>', $outputDB); } } //SLIDE cu3er if (@strstr("{" . $build_[0] . "}", "{cu3er}")) { $output = ViewController::slides(); $outputDB = str_replace('{cu3er}', $output, $outputDB); } //DISPLAY IMAGES //if (@preg_match("/images:display/", "{" . $build_[0] . ":" . $build_[1])) { if (@strstr($build_[0] . ":" . $build_[1], "images:display")) { $folder = trim($build_[2], '""'); $folder = trim($folder, "''"); @($image = trim($build_[3], "''")); //$menuQ = $db->fetchAll("SELECT *, url_en as url,name_en as name,description_en as description FROM menu_items WHERE menu_id = ?", array($menuId)); //print_r($menuQ ); if (!empty($folder)) { if (empty($image)) { $output = ViewController::displayImages($folder); $imageOut = ""; } else { $output = ViewController::displayImage($folder, $image); $imageOut = ":'" . $image . "'"; } $outputDB = str_replace('{images:display:' . $build_[2] . $imageOut . '}', $output, $outputDB); //$outputDB = str_replace('{images:display:' . $build_[2] . '}', "AAAAA", $outputDB); } else { $outputDB = str_replace('{images:display:' . $build_[2] . $imageOut . '}', '<b style="color:red;">{images:' . $build_[2] . '}Doesn\'t exist or it is empty!</b>', $outputDB); } } //EXTERN Joomla!! if (@preg_match("/extern:joomla/", "{" . $build_[0] . ":" . $build_[1])) { $folder = trim($build_[2], '""'); $folder = trim($folder, "''"); $type = trim($build_[2], '""'); //print_r($menuQ ); if (!empty($type)) { $output = ViewController::displayExternJoomla($type); $imageOut = ""; $outputDB = str_replace('{extern:joomla:' . $build_[2] . $imageOut . '}', $output, $outputDB); } else { $outputDB = str_replace('{extern:joomla:' . $build_[2] . $imageOut . '}', '<b style="color:red;">{images:' . $build_[2] . '}Doesn\'t exist or it is empty!</b>', $outputDB); } } //MODULE 'FORM' if (@preg_match("/module:forms/", "{" . $build_[0] . ":" . $build_[1])) { $contactFormName = trim($build_[2], "''"); $contactFormId = $db->fetchAll("SELECT *, mod_forms.name as formName FROM mod_forms LEFT JOIN mod_forms_fields ON mod_forms.id = mod_forms_fields.form_id WHERE enabled = '1' AND mod_forms.name = ?", array($contactFormName)); //print_r($contactFormId); if (!empty($contactFormId)) { $formId = $contactFormId; $output = FormsController::showForm($formId); $outputDB = str_replace('{module:forms:' . $build_[2] . '}', $output, $outputDB); } else { $outputDB = str_replace('{module:forms:' . $build_[2] . '}', '<b style="color:red;">{module:forms:' . $build_[2] . '}Doesn\'t exist!</b>', $outputDB); } } $outputString = ""; $count++; } } else { //$output = ViewController::setDefaultHeaderImage(); //$outputDB .= $output; } $outputDB = str_replace('{content}', $content, $outputDB); return $outputDB; }