function generateMenuItems($menuID, $parentID, $langIn, $isSelected, $selPage, $firstLayout) { global $db, $lang; $firstNum = NULL; $firstTmp = NULL; $query = $db->query('SELECT * FROM cms_menus_items WHERE menuID=' . $menuID . ' AND parentID="' . $parentID . '" AND status="N" AND selection!="4" ORDER BY orderID asc'); $int = $db->rows($query); if ($int > 0) { echo '<ul>'; while ($results = $db->fetch($query)) { $shown = ''; if ($isSelected && $selPage == $results['ID']) { $firstLayout = true; $firstNum = $results['ID']; $firstTmp = $results['template']; $shown = 'class="show"'; } else { if (!$isSelected && $firstLayout === false) { $firstLayout = true; $firstNum = $results['ID']; $firstTmp = $results['template']; $shown = 'class="show"'; } } if ($results['enabled'] == 1) { $ena = ''; } else { $ena = 'style="color:#ff0000;"'; } if ($results['showM'] == "Y") { $smenu = ''; } else { $smenu = '<span style="color:#ff0000 !important;">*</span>'; } if ($results['selection'] == 1) { echo '<li ' . $shown . '><div ' . $ena . ' class="S_RND" id="' . $results['ID'] . '#' . $menuID . '" onclick="sumo2.siteTree.RefreshLayout(' . $results['ID'] . ',' . $langIn . ',' . checkTemplate($results['template']) . ')">' . $results['title'] . ' ' . $smenu . '</div>'; } else { if ($results['selection'] == 2) { $nameResult = $db->get($db->query("SELECT * FROM cms_menus_items WHERE ID='" . $results['link'] . "' LIMIT 1")); echo '<li class="nosel"><div title="' . $lang->MOD_96 . '' . $nameResult['title'] . '" style="color:green;" id="' . $results['ID'] . '#' . $menuID . '" class="sumo2-tooltip S_RND">' . $results['title'] . ' ' . $smenu . '</div>'; } else { if ($results['selection'] == 3) { echo '<li class="nosel"><div title="' . $lang->MOD_97 . '' . $results['link'] . '" style="color:blue;" id="' . $results['ID'] . '#' . $menuID . '" class="sumo2-tooltip S_RND">' . $results['title'] . ' ' . $smenu . '</div>'; } } } $tmp = generateMenuItems($menuID, $results['ID'], $langIn, $isSelected, $selPage, $firstLayout); if ($tmp[0] != NULL) { $firstNum = $tmp[0]; $firstTmp = $tmp[1]; } } echo '</ul>'; } return array($firstNum, $firstTmp); }
/** * ParseTemplate * This is the master 'parsing' function. It reads in the template file and runs through all the parsing functions in order. * * @param String $name Template to be parsed * @param Boolean $return Toggles whether the parsed template code will be echo'ed out directly or returned by the function. * * @return Mixed Can be either void or a String * * @see LoadTemplateFile * @see ParseForeach * @see ParseSet * @see ParseIf * @see ParseVariables * @see TemplateData */ public function ParseTemplate($name = null, $return = false, $input = null) { static $cache_cutoff_time = false; if (!is_null($name)) { $name = strtolower($name); $name = checkTemplate($name, false); $this->SetTemplate($name); $templateFile = $this->GetTemplateFilename(); } else { $templateFile = false; } // Check that all the paths are set up correctly if (empty($this->CachePath) || is_null($this->CachePath)) { throw new InterspireTemplateException('Invalid cache path. A cache path must be specified before a template can be parsed.'); } if (empty($this->TemplatePath) || is_null($this->TemplatePath)) { throw new InterspireTemplateException('Invalid template path. A valid template path must be specified pointing to the directory of the template files.'); } // check the there is something to parse, either direct input or a template file. if (empty($input) && !$templateFile) { throw new InterspireTemplateException('Nothing to parse. Either direct input is required or a valid template file must be specified.'); return false; } // ----- Initialize any variables that should be available to the running template $tpl = $this; $this->Assign('IEM', self::IEM_DefaultVariables(), false); if ($name == 'header_popup') { $GLOBALS['UsingWYSIWYG'] = '0'; $user = IEM::getCurrentUser(); if ($user) { if ($user->Get('usewysiwyg') == 1) { $GLOBALS['UsingWYSIWYG'] = '1'; } } } if (!IEM::sessionGet('LicenseError')) { if (SENDSTUDIO_SEND_TEST_MODE) { $this->Assign('ShowTestModeWarning', true); $this->Assign('SendTestWarningMessage', GetLang('Header_Send_TestMode_WarningMessage_User'), false); $user = IEM::getCurrentUser(); if ($user && $user->Admin()) { $this->Assign('SendTestWarningMessage', GetLang('Header_Send_TestMode_WarningMessage_Admin'), false); } } } // ----- $parseTemplateFile = true; if (empty($input)) { $file_hash = md5($templateFile); $cacheFile = $this->CachePath . '/' . $this->TemplateFile . '_' . $file_hash . '_' . $this->TemplateFileExtension . '.php'; // ----- If cache doesn't exists or have been modified since cache last refreshed or the cache is 5 days old, then update cache. $parseTemplateFile = true; do { // File does not exists if (!file_exists($cacheFile)) { break; } $tempTemplateFileLastModified = filemtime($templateFile); $tempChacheFileLastModified = filemtime($cacheFile); // The template file is newer than the cache if ($tempTemplateFileLastModified > $tempChacheFileLastModified) { break; } // ----- Cache is older than 5 days if (empty($cache_cutoff_time)) { $cache_cutoff_time = time() - self::CACHE_LIFETIME; } if ($tempChacheFileLastModified < $cache_cutoff_time) { break; } // ----- // If none of the above conditions are met, then our cache is till good. // Do not re-parse the template file. $parseTemplateFile = false; } while (false); // ----- } else { $cacheFile = $this->CachePath . '/tmp' . rand(3000, 90000000) . '.html'; } if ($parseTemplateFile) { if ($this->EventBeforeUncachedTemplateParsed()) { if (empty($input)) { $this->LoadTemplateFile(); } else { $this->TemplateData = $input; } $this->StripTemplateComments(); // run through all the template parsing functions $this->TemplateData = $this->ParseForeach($this->TemplateData); // foreach is recursive, so we need to use this method of calling it $this->ParseIEM(); $this->ParseAlias(); $this->ParseCapture(); $this->ParseCycle(); $this->ParseIncludes(); $this->ParseSet(); $this->ParseIf(); $this->ParseConfig(); $this->ParseLanguageVariables(); $this->ParseHelpLanguageVariables(); $this->ParseVariables(); $this->ParseLegacy_Request(); $this->ParseLegacy_Global(); $this->ParseLegacy_LanguageHelp(); $this->ParseLegacy_Language(); if ($this->CleanWhiteSpace) { // this cleans up the code a bit, if there is a closing PHP tag and only whitespace between it and another opening PHP tag, // get rid of both of them and let the PHP 'continue' $this->TemplateData = preg_replace('#\\? >[\\n\\s\\t]*<\\?php#sm', '', $this->TemplateData); } } $this->EventAfterUncachedTemplateParsed(); if ($this->EventBeforeTemplateCached($cacheFile)) { file_put_contents($cacheFile, $this->TemplateData); @chmod($cacheFile, 0666); } $this->EventAfterTemplateCached($cacheFile); } ob_start(); if ($this->EventBeforeTemplateIncluded($cacheFile)) { include $cacheFile; } $this->EventAfterTemplateIncluded(); $this->TemplateData = ob_get_contents(); ob_end_clean(); $this->EventTemplateCaptured(); if (!empty($input)) { @unlink($cacheFile); } if ($return) { return $this->TemplateData; } else { echo $this->TemplateData; } }