protected function execTinyMce($prm=null) { $search = 'js/tiny_mce/'; $request = request::get('request'); $pos = strpos($request, $search); if ($pos === false) exit; $tmp = substr($request, $pos+strlen($search)); $file = file::nyroExists(array( 'name'=>'lib'.DS.'tinyMce'.DS.$tmp, 'realName'=>true, 'type'=>'other' )); if (strpos($file, '.php') !== false) { array_walk($_GET, create_function('&$v', '$v = urldecode($v);')); $path = str_replace($tmp, '', $file); ini_set('include_path', $path); define('TINYMCEPATH', substr($path, 0, -1)); define('TINYMCECACHEPATH', substr(TMPROOT, 0, -1)); if (ob_get_length()) ob_clean(); include($file); exit; } else response::getInstance()->showFile($file); }
/** * Find the init file for a library * ie: nyro/lib/$name/init.lib.php * * @param string $name The library name * @return false|string The file path or false if not found */ public static function initFile($name) { if (!array_key_exists($name, self::$libFiles)) { self::$libFiles[$name] = file::nyroExists(array( 'name'=>'lib_'.$name.'_init', 'type'=>'lib' )); } return self::$libFiles[$name]; }
/** * Returns the contents of the script file if it exists and removes the UTF-8 BOM header if it exists. * * @param String $file File to load. * @return String File contents or empty string if it doesn't exist. */ private function getFileContents($file) { /////////////////////////// Update for nyroFwk /////////////////////////// if (!file_exists($file)) { $file = file::nyroExists(array( 'realName'=>true, 'name'=>'lib/tinyMce/'.substr($file, strlen(TINYMCEPATH)+1), 'type'=>'other' )); if (!$file) return ''; } if (file_exists($file)) { $content = file_get_contents($file); // Remove UTF-8 BOM if (substr($content, 0, 3) === pack("CCC", 0xef, 0xbb, 0xbf)) $content = substr($content, 3); } else $content = ""; return $content; }
/** * Add an include file * * @param array $prm Same parameter as addCss or addJs, with adding: * - string type File type (js or css) (required) * @return bool True if addedor already added, False if not found * @throws nExecption if type or file not provided * @see addJs, addCss */ public function add(array $prm) { if (config::initTab($prm, array( 'type'=>null, 'file'=>null, 'dir'=>'nyro', 'media'=>'screen', 'condIE'=>false, 'verifExists'=>true ))) { $ret = false; $firstFile = $prm['file']; if (strpos($firstFile, 'jquery') === 0 && $firstFile != 'jquery') $this->addJS('jquery'); foreach($this->getDepend($prm['file'], $prm['type']) as $d) { if (is_array($d)) $this->add(array_merge($prm, $d)); else $this->add(array_merge($prm, array('file'=>$d))); } foreach($this->cfg->getInArray($prm['type'], 'alias') as $k=>$a) { if (strtolower($prm['file']) == strtolower($k)) $prm['file'] = $a; } $prmType = $this->cfg->get($prm['type']); $locDir = $prm['dir']; if (!array_key_exists($locDir, $this->incFiles[$prm['type']])) $locDir = 'nyro'; $fileExt = $prm['file'].'.'.$prm['type']; if ($prm['verifExists']) $fileExists = $locDir == 'web' ? file::webExists($prmType['dirWeb'].DS.$fileExt) : file::nyroExists(array( 'name'=>'module_'.nyro::getCfg()->compressModule.'_'.$prm['type'].'_'.$prm['file'], 'type'=>'tpl', 'tplExt'=>$prm['type'] )); else $fileExists = true; if ($fileExists) { if (!isset($this->incFiles[$prm['type']][$locDir][$prm['media']])) $this->incFiles[$prm['type']][$locDir][$prm['media']] = array(); $this->incFiles[$prm['type']][$locDir][$prm['media']][$prm['file']] = $prm; if ($prm['type'] == 'css') { $c = file::read($fileExists); preg_match_all('`@import (url\()?"(.+).css"\)?;`', $c, $matches); if (!empty($matches[2])) { $prefix = substr($prm['file'], 0, strpos($prm['file'], '_')+1); foreach($matches[2 ] as $m) $this->add(array_merge($prm, array('file'=>$prefix.$m))); } } $ret = true; } foreach($this->getDepend($firstFile, $prm['type'], true) as $d) { if (is_array($d)) $this->add(array_merge($prm, $d)); else $this->add(array_merge($prm, array('file'=>$d))); } return $ret; } else throw new nException('reponse::add: parameters file and/or type not provied'); }
/** * Check if a className is creable (ie if it's file exists) * * @return bool */ public static function isCreable($className) { return file::nyroExists(array('name' => $className)) !== false; }
/** * Find the template file * * @param array $prm Parameter used in file::nyroExists * @param array $name Template name * @return string|null The first template file path found or null */ protected function findTpl(array $prm, array $name) { foreach($name as $n) { if ($file = file::nyroExists(array_merge($prm, array('name'=>$n,'type'=>'tpl')))) return $file; } return null; }
/** * 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); }