示例#1
0
	/**
	 * Transform HTML to text, using html2text library
	 *
	 * @param string $html The HTML string to transform
	 * @return string
	 */
	public static function html2Text($html) {
		lib::load('html2text');
		return html2text($html);
	}
示例#2
0
 /**
  * Load a class definition
  *
  * @param string $className The className to load
  * @return true If success
  * @throws nExecption If the file isn't find
  */
 public static function load($className)
 {
     if (!class_exists($className) && !in_array($className, self::$loadedClass)) {
         if (!array_key_exists($className, self::$loadFiles)) {
             if ($file = file::nyroExists(array('name' => $className))) {
                 require $file;
                 self::$loadFiles[$className] = array($file);
                 self::$saveCacheLoad = true;
                 self::$loadedClass[] = $className;
                 if (defined('RUNKIT_VERSION')) {
                     $filesExtend = file::nyroExists(array('name' => $className, 'type' => 'extend', 'rtl' => false, 'list' => true));
                     if (!empty($filesExtend)) {
                         self::$loadFiles[$className][1] = $filesExtend;
                         foreach ($filesExtend as $fe) {
                             runkit_import($fe);
                         }
                     }
                 }
             } else {
                 if (!lib::load($className)) {
                     if (self::$throwOnLoad) {
                         throw new nException('Factory - load: Unable to find the file for ' . $className . '.');
                     } else {
                         return false;
                     }
                 }
             }
         } else {
             require self::$loadFiles[$className][0];
             self::$loadedClass[] = $className;
             if (defined('RUNKIT_VERSION') && array_key_exists(1, self::$loadFiles[$className])) {
                 foreach (self::$loadFiles[$className][1] as $fe) {
                     runkit_import($fe);
                 }
             }
         }
     }
     return true;
 }
示例#3
0
	/**
	 * Compress the file requested, using MoxieCompressor library
	 *
	 * @param string $type File type (css or js)
	 * @param array $prm Files to compress
	 */
	protected function compress($type, $prm) {
		$resp = response::getInstance();
		
		if ($type == 'js') {
			$conf = $this->cfg->all;
			factory::mergeCfg($conf, $this->cfg->js);
		} else if ($type == 'css') {
			$conf = $this->cfg->all;
			factory::mergeCfg($conf, $this->cfg->css);
		}
		
		$key = $type.'--'.md5(serialize($prm)).'--'.md5(serialize($conf));
		$supportsGzip = false;
		if ($conf['compress']) {
			$encodings = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING']))) : array();
			if ($conf['gzip_compress'] && (in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('gzencode') && !ini_get('zlib.output_compression')) {
				$enc = in_array('x-gzip', $encodings) ? 'x-gzip' : 'gzip';
				$supportsGzip = true;
				$key = 'gzip-'.$key;
			}
		}
		$content = null;
		$cache = cache::getInstance($this->cfg->cache);
		$cacheDate = $cache->get($content, array('id'=>$key));
		
		if (!$conf['disk_cache'] || !$cacheDate) {
			foreach($prm as $file) {
				$f = file::nyroExists(array(
								'name'=>'module_'.nyro::getCfg()->compressModule.'_'.$type.'_'.$file,
								'type'=>'tpl',
								'tplExt'=>$type
							));
				if ($f) {
					if ($conf['php'])
						$content.= file::fetch($f);
					else
						$content.= file::read($f);
				}
			}
			
			if ($conf['compress']) {
				if ($type == 'js') {
					lib::load('jsMin');
					$content = JSMin::minify($content);
				} else if ($type == 'css') {
					lib::load('cssMin');
					$content = CssMin::minify($content, $conf['filters'], $conf['plugins']);
				}
				if ($supportsGzip)
					$content = gzencode($content, 9, FORCE_GZIP);
			}
			$cache->save();
		} else if ($cacheDate) {
			$resp->addHeader('Age', time() - $cacheDate);
		}
		
		/* @var $resp response_http */
		if ($conf['compress']) {
			$resp->setCompress(false);
			$resp->addHeader('Vary', 'Accept-Encoding'); // Handle proxies
			if ($conf['etags'] || preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT'])) {
				// We need to use etags on IE since it will otherwise always load the contents
				$resp->addHeader('ETag', md5($content));
			}
			$parseTime = $this->_parseTime($conf['expires_offset']);
			$resp->addHeader('Expires', gmdate('D, d M Y H:i:s', time() + $parseTime).' GMT');
			$resp->addHeader('Cache-Control', 'public, max-age='.$parseTime);
			
			if ($type == 'js') {
				// Output explorer workaround or compressed file
				if (!isset($_GET['gz']) && $supportsGzip && $conf['patch_ie'] && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
					// Build request URL
					$url = $_SERVER['REQUEST_URI'];

					if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'])
						$url.= '?'.$_SERVER['QUERY_STRING'].'&gz=1';
					else
						$url.= '?gz=1';

					// This script will ensure that the gzipped script gets loaded on IE versions with the Gzip request chunk bug
					echo 'var gz;try {gz = new XMLHttpRequest();} catch(gz) { try {gz = new ActiveXObject("Microsoft.XMLHTTP");}';
					echo 'catch (gz) {gz = new ActiveXObject("Msxml2.XMLHTTP");}}';
					echo 'gz.open("GET", "'.$url.'", false);gz.send(null);eval(gz.responseText);';
					die();
				}
			}
			
			if ($supportsGzip)
				$resp->addHeader('Content-Encoding', $enc);	
		}
		
		$resp->sendText($content);
	}