Пример #1
0
		/**
		* ParseGL
		* Parse global and language vars from a template/panel/snippet
		*
		* @param string $TemplateData The string to parse for vars
		*
		* @return string The string with the vars replaced
		*/
		public function ParseGL($TemplateData)
		{
			// Parse out global and language variables from template data and
			// return it. This is used from the generic panel class for each panel
			$tplData = $TemplateData;

			// Design mode is only supported on the front end
			if(!$this->frontEnd) {
				$dmLangEditing = false;
			}
			// No design mode session was found
			else if(empty($_COOKIE['designModeToken']) && empty($_POST['designModeToken'])) {
				$dmLangEditing = false;
			}
			// Found and working with a valid design mode session
			else if(GetClass('ISC_ADMIN_AUTH')->isDesignModeAuthenticated()) {
				$dmLangEditing = true;
			}
			else {
				$dmLangEditing = false;
			}

			// Parse out the javascript language pack variables in the template file
			// Do this before any design mode stuff because it's not feasible to make js language variables clickable for editing as we can't predict where the string will end up being used (e.g., in an alert())
			preg_match_all("/(?siU)(%%LNG_JS_[a-zA-Z0-9]{1,}%%)/", $tplData, $matches);
			foreach ($matches[0] as $key => $k) {
				$pattern1 = $k;
				$pattern2 = str_replace("%", "", $pattern1);
				$pattern2 = str_replace("LNG_JS_", "", $pattern2);

				if (isset($GLOBALS['ISC_LANG'][$pattern2])) {
					$tplData = str_replace($pattern1,  Interspire_JavaScript::encode(GetLang($pattern2)), $tplData);
				}
			}

			// If design mode is on, we need to do a lot of cool string replacement stuff
			if($dmLangEditing) {
				$badMatches = array();
				$scriptStart = 0;
				do {
					$scriptStart = stripos($tplData, "<script", $scriptStart);
					if($scriptStart === false) {
						break;
					}
					$scriptEnd = stripos($tplData, "</script>", $scriptStart);
					if($scriptEnd === false) {
						break;
					}
					$badMatches[] = substr($tplData, $scriptStart, $scriptEnd-$scriptStart);
					$tplData = substr_replace($tplData, "%%DM_LANG_EDIT%%", $scriptStart, $scriptEnd-$scriptStart);
				}
				while($scriptStart !== false);
				$valueStart = 0;
				$badMatches2 = array();
				do {
					$valueStart = stripos($tplData, "value=\"", $valueStart);
					if($valueStart === false) {
						break;
					}
					$valueEnd = stripos($tplData, "\"", $valueStart+8);
					if($valueEnd === false) {
						break;
					}
					$badMatches2[] = substr($tplData, $valueStart, $valueEnd-$valueStart+1);
					$tplData = substr_replace($tplData, "%%DM2_LANG_EDIT%%", $valueStart, $valueEnd-$valueStart+1);
				}
				while($valueStart !== false);
			}

			// Parse out the language pack variables in the template file
			preg_match_all("/(?siU)(%%LNG_[a-zA-Z0-9_]{1,}%%)/", $tplData, $matches);
			foreach ($matches[0] as $key => $k) {
				$pattern1 = $k;
				$pattern2 = str_replace("%", "", $pattern1);
				$pattern2 = str_replace("LNG_", "", $pattern2);

				if($dmLangEditing == true) {
					if (isset($GLOBALS['ISC_LANG'][$pattern2])) {
						$lang_data = "<span id='lang_".$pattern2."' class='LNGString'>";
						$lang_data .= GetLang($pattern2)."</span>";
						$tplData = str_replace($pattern1, $lang_data, $tplData);
					}
				}
				else {
					if (isset($GLOBALS['ISC_LANG'][$pattern2])) {
						$tplData = str_replace($pattern1, GetLang($pattern2), $tplData);
					}
				}
			}

			if($dmLangEditing) {
				if(!empty($badMatches)) {
					foreach($badMatches as $match) {
						preg_match_all("/(?siU)(%%LNG_[a-zA-Z0-9]{1,}%%)/", $match, $matches);
						foreach ($matches[0] as $key => $k) {
							$pattern1 = $k;
							$pattern2 = str_replace("%", "", $pattern1);
							$pattern2 = str_replace("LNG_", "", $pattern2);
							if (isset($GLOBALS['ISC_LANG'][$pattern2])) {
								$match = str_replace($pattern1, GetLang($pattern2), $match);
							}
						}
						$startPos = strpos($tplData, "%%DM_LANG_EDIT%%");
						$length = strlen("%%DM_LANG_EDIT%%");
						$tplData = substr_replace($tplData, $match, $startPos, $length);
					}
				}
				if(!empty($badMatches2)) {
					foreach($badMatches2 as $match) {
						preg_match_all("/(?siU)(%%LNG_[a-zA-Z0-9]{1,}%%)/", $match, $matches);
						foreach ($matches[0] as $key => $k) {
							$pattern1 = $k;
							$pattern2 = str_replace("%", "", $pattern1);
							$pattern2 = str_replace("LNG_", "", $pattern2);
							if (isset($GLOBALS['ISC_LANG'][$pattern2])) {
								$match = str_replace($pattern1, GetLang($pattern2), $match);
							}
						}
						$startPos = strpos($tplData, "%%DM2_LANG_EDIT%%");
						$length = strlen("%%DM2_LANG_EDIT%%");
						$tplData = substr_replace($tplData, $match, $startPos, $length);
					}
				}

			}

			// This is kind of a hack to make sure that the template system has
			// the template variables it needs to parse this kind of template.
			if($this->frontEnd) {
				$tplData = str_replace('%%GLOBAL_template%%', $this->getActiveTemplateName(), $tplData);
				$tplData = str_replace('%%GLOBAL_SiteColor%%', $this->getActiveColorScheme(), $tplData);
				$tplData = str_replace('%%GLOBAL_IMG_PATH%%', $this->getImagePath(), $tplData);
			}

			$tplData = $this->Parse("GLOBAL_", $tplData, $GLOBALS);

			return $tplData;
		}
Пример #2
0
	/**
	* Filters a string to be safe for outputting to javascript embedded inside X/HTML. This is an 'escaper' filter; HTML escaping is bypassed.
	*
	* Escaped characters are:
	* \		literal backslash
	* \n	newline
	* \r	carriage return
	* "		double quote
	* '		single quote
	* &		for xhtml
	* <		for xhtml
	* >		for xhtml
	*
	* Twig Examples:
	* var foo = "{{ a_variable|js }}"; // double quotes are recommended as some old js engines have issues with escaping in single quote strings
	* var foo = '{{ a_variable|js }}';
	*
	* @param string $string Input string to filter
	* @return string Returns the input string with all appropriate control characters escaped for javascript usage
	*/
	public function jsFilter($string)
	{
		return Interspire_JavaScript::encode($string);
	}