/si"; $repl[] = ''; $reg[] = "/<\/span>/si"; $repl[] = ''; $text = preg_replace( $reg, $repl, $text ); // Clean up variables unset($reg, $repl); return $text; } function _make_absolute($link) { if(substr($link,0, 7)!='http://'&&substr($link,0, 7)!='https://') { if(substr($link,0,1)=='/') { return $this->url.$link; } else { return $this->url.'/'.$link; } } return $link; } function _addscript($url) { // The method depends on event type. onAfterRender is complex and others are simple based on framework if ($this->event!='onAfterRender') $this->document->addScript($url); else { // Get header $reg = "/(]*>)(.*?)(<\/HEAD>)(.*)/si"; $count = preg_match_all($reg,$this->_text,$html); if ($count>0) { $head=$html[2][0]; } else { $head=''; } // clean browser if statements $reg = "//si"; $head = preg_replace($reg, '', $head); // define scripts regex $reg = '/]*[^<]*(<\/script>)?/i'; $found = false; $count = preg_match_all($reg,$head,$scripts,PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER); if ($count>0) foreach ($scripts[1] as $script) { if ($script[0]==$url) { $found = true; break; } } if (!$found) { $script = "\n\n"; if ($count==0) { // No scripts then just add it before $this->_text = preg_replace("/(.*?)<\/head>/is", "$2".$script."", $this->_text); } else { //add script after the last script // position last script and add length $pos = strpos($this->_text, trim($scripts[0][$count-1][0]))+strlen(trim($scripts[0][$count-1][0])); $this->_text = substr($this->_text,0, $pos).$script.substr($this->_text,$pos); } } // Clean up variables unset($reg, $count, $head, $found, $scripts, $script, $pos); } } function _addstylesheet($url) { // The method depends on event type. onAfterRender is complex and others are simple based on framework if ($this->event!='onAfterRender') $this->document->addStyleSheet($url); else { // Get header $reg = "/(]*>)(.*?)(<\/HEAD>)(.*)/si"; $count = preg_match_all($reg,$this->_text,$html); if ($count>0) { $head=$html[2][0]; } else { $head=''; } // clean browser if statements $reg = "//si"; $head = preg_replace($reg, '', $head); // define scripts regex $reg = '/]*[^<]*(<\/link>)?/i'; $found = false; $count = preg_match_all($reg,$head,$styles,PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER); if ($count>0) foreach ($styles[1] as $style) { if ($style[0]==$url) { $found = true; break; } } if (!$found) { $style = "\n\n"; if ($count==0) { // No styles then just add it before $this->_text = preg_replace("/(.*?)<\/head>/is", "$2".$style."", $this->_text); } else { //add style after the last style // position last style and add length $pos = strpos($this->_text, trim($styles[0][$count-1][0]))+strlen(trim($styles[0][$count-1][0])); $this->_text = substr($this->_text,0, $pos).$style.substr($this->_text,$pos); } } // Clean up variables unset($reg, $count, $head, $found, $styles, $style, $pos); } } function _addstyledeclaration($source) { // The method depends on event type. onAfterRender is complex and others are simple based on framework if ($this->event!='onAfterRender') $this->document->addStyleDeclaration($source); else { // Get header $reg = "/(]*>)(.*?)(<\/HEAD>)(.*)/si"; $count = preg_match_all($reg,$this->_text,$html); if ($count>0) { $head=$html[2][0]; } else { $head=''; } // clean browser if statements $reg = "//si"; $head = preg_replace($reg, '', $head); // define scripts regex $reg = '/]*>(.*?)<\/style>/si'; $found = false; $count = preg_match_all($reg,$head,$styles,PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER); if ($count>0) foreach ($styles[1] as $style) { if ($style[0]==$source) { $found = true; break; } } if (!$found) { $source = "\n\n"; if ($count==0) { // No styles then just add it before $this->_text = preg_replace("/(.*?)<\/head>/is", "$2".$source."", $this->_text); } else { //add style after the last style // position last style and add length $pos = strpos($this->_text, trim($styles[0][$count-1][0]))+strlen(trim($styles[0][$count-1][0])); $this->_text = substr($this->_text,0, $pos).$source.substr($this->_text,$pos); } } // Clean up variables unset($reg, $count, $head, $found, $styles, $style, $pos); } } function _is_utf8($string) { // v1.01 // define('_is_utf8_split',5000); // if (strlen($string) > _is_utf8_split) { if (strlen($string) > 5000) { // Based on: http://mobile-website.mobi/php-utf8-vs-iso-8859-1-59 for ($i=0,$s=_is_utf8_split,$j=ceil(strlen($string)/_is_utf8_split);$i < $j;$i++,$s+=_is_utf8_split) { if (is_utf8(substr($string,$s,_is_utf8_split))) return true; } return false; } else { // From http://w3.org/International/questions/qa-forms-utf-8.html return preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$%xs', $string); } } } ?>