/**
	 * Read recursively path & sub-paths of xsl file
	 *
	 * @access private
	 * @param string $path the root path
	 * @param bool $searchTemplateName true if you want to recover templates names
	 * @param array &$arrayTemplateName reference array, it will contains templates names
	 * @param array &$arrayPath reference array, it will contains paths
	 * @param array &$arrayFilename reference array, it will contains filenames
	 * @since 1.0
	 */
	private function recursiveRead($path, $searchTemplateName=false, &$arrayTemplateName, &$arrayPath, &$arrayFilename)
	{ 
		if (substr($path, strlen($path)-1, 1) != "/")
			$path .= "/";
		if (@is_dir($path))
		{
			$handle = opendir($path);			
			while (false !== ($object = readdir($handle))) 
			{
				if (is_dir($path.$object) && substr($object, 0, 1) != ".") 
					$this->recursiveRead($path.$object, $searchTemplateName, $arrayTemplateName, $arrayPath, $arrayFilename);				
				if (substr($object, 0, 1) != "." && is_file($path.$object) && SLS_String::getFileExtension($object) == "xsl") 
				{
					if ($searchTemplateName)
					{
						$xslHandle = file_get_contents($path.$object);
						$boundContent = SLS_String::trimString(array_shift(SLS_String::getBoundContent($xslHandle, "<xsl:template", ">")));
						if (($stringName = stristr($boundContent, "name=")) === false)
						{
							array_push($arrayTemplateName, "");
						}
						else
						{
							$templateName = explode($stringName{5}, $stringName);
							array_push($arrayTemplateName, $templateName[1]);
						}
					}
					array_push($arrayPath, $path.$object);
					array_push($arrayFilename, $object);
				}		
			}
			closedir($handle);
		}
	}
Ejemplo n.º 2
0
	/**
	 * Parse final HTML with SLS_Dtd
	 * 
	 * @access public
	 * @param string $html the HTML content
	 * @return string the HTML content parsed
	 * @since 1.0.8
	 */
	public function parseHtml($html)
	{
		$delimiters = SLS_String::getBoundContent($html,"|||sls:","|||");
		$arraySearch = array();
		$arrayReplace = array();
		
		$dtd = new SLS_Dtd(null);
		
		// Foreach delimiters found, search if we can map a function of SLS_Dtd's class with this delimiter
		foreach($delimiters as $delimiter)
		{
			$dtd_mask = $delimiter;
			$delimiter = explode(":",$delimiter);
			$method = array_shift($delimiter);
			$args = $delimiter;			
			
			$ref = new ReflectionMethod($dtd,$method);			
			$nbRequiredParams = $ref->getNumberOfRequiredParameters();
			$nbMaxParams = $ref->getNumberOfParameters();
			
			if ($nbRequiredParams > count($args))			
				SLS_Tracing::addTrace(new Exception("Error: Specific SLS_Dtd function `".$method."` needs at least ".$nbRequiredParams." required parameters"),true);
			if ($nbMaxParams < count($args))
				SLS_Tracing::addTrace(new Exception("Warning: Specific SLS_Dtd function `".$method."` has only ".$nbMaxParams." parameters, you call it with ".count($args)." parameters"),true);
			
			if (method_exists($dtd,$method) && $nbRequiredParams <= count($args))
			{
				array_push($arraySearch,"|||sls:".$dtd_mask."|||");
				array_push($arrayReplace,$ref->invokeArgs($dtd,$args));
			}
			else
				SLS_Tracing::addTrace(new Exception("Warning: the delimiter |||sls:".$method."||| doesn't match with any function of class SLS_Dtd"));
		}
		return str_replace($arraySearch,$arrayReplace,$html);
	}