Пример #1
0
 public function install($path)
 {
     $module = @(include path::decode($path . DS . 'module.php'));
     if (is_array($module)) {
         $module['path'] = $path;
         $module['url'] = $path;
         if (!isset($module['icon'])) {
             if (file::exists($path . '/icon.png')) {
                 $module['icon'] = $module['url'] . '/icon.png';
             }
         }
         $module['type'] = empty($module['type']) ? 'plugin' : $module['type'];
         $module['status'] = 0;
         $module['order'] = $this->max('order') + 1;
         $module['installtime'] = TIME;
         $module['updatetime'] = TIME;
         $insert = $this->insert($module);
     }
     if ($insert) {
         $driver = $this->db()->config('driver');
         $sqls = file::read($path . DS . 'install' . DS . $driver . '.sql');
         if ($sqls) {
             $this->db()->run($sqls);
         }
     }
     return true;
 }
Пример #2
0
 public function actionLicense($path)
 {
     $module = zotop::model('zotop.module');
     $modules = $module->getUnInstalled();
     if (empty($path) || !dir::exists($path)) {
         msg::error(array('content' => zotop::t('模块不存在,请确认是否已经上传该模块?'), 'description' => zotop::t("路径:{$path}")));
     }
     $licenseFile = $path . DS . 'license.txt';
     if (!file::exists($licenseFile)) {
         zotop::redirect('zotop/module/install', array('path' => url::encode($path)));
         exit;
     }
     $license = file::read($licenseFile);
     $page = new dialog();
     $page->set('title', '许可协议');
     $page->set('license', html::decode($license));
     $page->set('next', zotop::url('zotop/module/install', array('path' => url::encode($path))));
     $page->display();
 }
Пример #3
0
 public function onEdit($file)
 {
     if (form::isPostBack()) {
         $content = request::post('source');
         msg::success('保存测试', '测试,继续编辑或者返回' . zotop::dump($content, true), 'reload');
     }
     $source = file::read(ROOT . $file);
     $page['title'] = '文件编辑器';
     page::header($page);
     page::top();
     page::navbar($this->navbar());
     form::header(array('class' => 'sourceEditor'));
     form::field(array('type' => 'label', 'label' => zotop::t('文件名称'), 'name' => 'filename', 'value' => $file, 'valid' => '', 'description' => zotop::t('')));
     form::field(array('type' => 'source', 'label' => zotop::t('文件内容'), 'name' => 'source', 'value' => $source, 'valid' => 'required:true', 'description' => zotop::t('')));
     form::buttons(array('type' => 'submit', 'value' => '保存文件'), array('type' => 'back'));
     form::footer();
     page::bottom();
     page::footer();
 }
Пример #4
0
 public function licenseAction($id)
 {
     $module = zotop::model('zotop.module');
     $modules = $module->getUnInstalled();
     if (empty($id) || !isset($modules[$id])) {
         msg::error(zotop::t('ID为<b>{$id}</b>的模块不存在,请确认是否已经上传该模块?'));
     }
     $licenseFile = $modules[$id]['path'] . DS . 'license.txt';
     if (!file::exists($licenseFile)) {
         zotop::redirect('zotop/module/install', array('id' => $id));
         exit;
     }
     $license = file::read($licenseFile);
     $page = new dialog();
     $page->set('title', '许可协议');
     $page->set('license', html::decode($license));
     $page->set('next', zotop::url('zotop/module/install', array('id' => $id)));
     $page->display();
 }
Пример #5
0
 public function actionEditor($file = '')
 {
     $file = empty($file) ? zotop::get('file') : $file;
     $file = trim(url::decode($file), '/');
     $filepath = site::template($file);
     if (form::isPostBack()) {
         $filecontent = zotop::post('filecontent');
         if (file::write($filepath, $filecontent)) {
             msg::success('保存成功');
         }
         msg::error('保存失败');
     }
     $filecontent = file::read($filepath);
     $page = new dialog();
     $page->title = zotop::t('模板编辑器');
     $page->set('file', $file);
     $page->set('filepath', $filepath);
     $page->set('filecontent', $filecontent);
     $page->display();
 }
Пример #6
0
 static function family_name($real_name)
 {
     if (strlen($real_name) >= 6 && strlen($real_name) <= 15) {
         if (regexp::match($real_name, 'chinese')) {
             $first_name = substr($real_name, 0, 3);
             $odd_family_name = file::read('family_name', 1);
             $odd_data = str_split($odd_family_name[0], 3);
             if (in_array($first_name, $odd_data)) {
                 return true;
             }
             $first_name = substr($real_name, 0, 6);
             $even_family_name = file::read('family_name', 2);
             $even_data = explode(',', $even_family_name);
             if (in_array($first_name, $even_data)) {
                 return true;
             }
         }
     }
     return false;
 }
Пример #7
0
 public function actionEdit($file = '')
 {
     $file = empty($file) ? zotop::get('file') : $file;
     $file = trim(url::decode($file), '/');
     $filepath = ZOTOP_PATH_ROOT . DS . str_replace('/', DS, $file);
     if (form::isPostBack()) {
         $content = request::post('source');
         $content = trim($content);
         if (empty($content)) {
             msg::error('内容为空,无法保存!');
         }
         file::write($filepath, trim($content));
         msg::success('内容保存成功!');
     }
     $filecontent = file::read($filepath);
     $page = new dialog();
     $page->title = '文件编辑器';
     $page->set('file', $file);
     $page->set('filepath', $filepath);
     $page->set('filecontent', $filecontent);
     $page->display();
 }
Пример #8
0
 public function actionEdit($file)
 {
     $filepath = realpath(ZOTOP_PATH_ROOT . DS . trim($file, '/'));
     if (empty($file)) {
         return false;
     }
     if (form::isPostBack()) {
         $content = request::post('source');
         $content = trim($content);
         if (empty($content)) {
             msg::error('内容为空,无法保存!');
         }
         file::write($filepath, trim($content));
         msg::success('内容保存成功!');
     }
     $content = file::read($filepath);
     $page = new dialog();
     $page->title = '文件编辑器';
     $page->set('file', $file);
     $page->set('filepath', $filepath);
     $page->set('content', $content);
     $page->display();
 }
Пример #9
0
 /**
  * Get the body content
  *
  * @param string|null $headers Header to edit or null to add the header in the email
  * @return string
  */
 protected function getBody(&$headers = null)
 {
     $body = null;
     //$text = $this->quotePrintable($this->cfg->text);
     $text = $this->cfg->text;
     if ($this->cfg->html) {
         if (empty($this->cfg->text)) {
             //$text = $this->quotePrintable(utils::html2Text($this->cfg->html));
             $text = utils::html2Text($this->cfg->html);
         }
         $boundary = '------------' . $this->getBoundary();
         if ($headers) {
             $headers .= $this->headerLine('Content-Type', 'multipart/alternative;' . $this->cfg->crlf . ' boundary="' . $boundary . '"');
             //$headers.= $this->textLine(' boundary="'.$boundary.'"');
         } else {
             $body .= $this->headerLine('Content-Type', 'multipart/alternative;' . $this->cfg->crlf . ' boundary="' . $boundary . '"');
             //$body.= $this->textLine(' boundary="'.$boundary.'"');
             $body .= $this->textLine('');
         }
         // Text part
         $body .= $this->textLine('This is a multi-part message in MIME format.');
         $body .= $this->textLine('--' . $boundary);
     }
     $body .= $this->headerLine('Content-Type', 'text/plain; charset=' . $this->cfg->charset);
     //$body.= $this->textLine(' charset="'.$this->cfg->charset.'"');
     $body .= $this->headerLine('Content-Transfer-Encoding', $this->cfg->encoding);
     //$body.= $this->headerLine('Content-Disposition', 'inline');
     $body .= $this->textLine(null);
     $body .= $this->textLine($this->encode($this->wrapText($text)));
     if ($this->cfg->html) {
         // HTML part
         $body .= $this->textLine('--' . $boundary);
         $html = $this->cfg->html;
         $inlineImages = false;
         if ($this->cfg->htmlInlineImage) {
             $rootUri = request::get('rootUri');
             preg_match_all('@src="(' . $rootUri . '|/)(.+)"@siU', $html, $matches);
             if (!empty($matches)) {
                 $images = array_unique($matches[2]);
                 $inlineImages = array();
                 $i = 1;
                 foreach ($images as $img) {
                     if (file::webExists($img)) {
                         $file = WEBROOT . str_replace('/', DS, $img);
                         $cid = 'part' . $i . '.' . $this->getBoundary(16) . '@' . $this->cfg->serverName;
                         $inlineImages[] = array('cid' => $cid, 'file' => $file, 'name' => file::name($file), 'type' => file::getType($file));
                         $i++;
                         $html = preg_replace('@src="(' . $rootUri . '|/)(' . $img . ')"@siU', 'src="cid:' . $cid . '"', $html);
                     }
                 }
             }
         }
         if (!empty($inlineImages)) {
             $boundaryRel = '------------' . $this->getBoundary();
             $body .= $this->headerLine('Content-Type', 'multipart/related;' . $this->cfg->crlf . ' boundary="' . $boundaryRel . '"');
             //$body.= $this->textLine(' boundary="'.$boundaryRel.'"');
             $body .= $this->textLine(null);
             $body .= $this->textLine(null);
             $body .= $this->textLine('--' . $boundaryRel);
         }
         $body .= $this->headerLine('Content-Type', 'text/html; charset=' . $this->cfg->charset . '');
         //$body.= $this->textLine(' charset="'.$this->cfg->charset.'"');
         $body .= $this->headerLine('Content-Transfer-Encoding', $this->cfg->encoding);
         //$body.= $this->headerLine('Content-Disposition', 'inline');
         $body .= $this->textLine(null);
         //$body.= $this->textLine($this->quotePrintable($html));
         $body .= $this->textLine($this->encode($this->wrapText($html)));
         if (!empty($inlineImages)) {
             foreach ($inlineImages as $img) {
                 $body .= $this->textLine('--' . $boundaryRel);
                 $body .= $this->headerLine('Content-Type', $img['type']);
                 //.'; name="'.$img['name'].'"');
                 $body .= $this->headerLine('Content-Transfer-Encoding', $this->cfg->fileEncoding);
                 $body .= $this->headerLine('Content-ID', '<' . $img['cid'] . '>');
                 //$body.= $this->headerLine('Content-Disposition', 'inline; filename="'.$img['name'].'"');
                 $body .= $this->textLine(null);
                 $body .= $this->encode(file::read($img['file']), $this->cfg->fileEncoding);
             }
             $body .= $this->textLine('--' . $boundaryRel . '--');
             $body .= $this->textLine(null);
         }
         $body .= '--' . $boundary . '--';
     }
     return $body;
 }
Пример #10
0
 /**
  * Try to get an output cached. If not found, information will be stored
  * and used with the next call from end.
  * The cache id is made with 5 kinds :
  *  - the $id passed to the function
  *  - the get, post, session or cookie variable if set
  *  - the class and function name where the cache is call
  *  - the tags if set
  *  - 'cache' is added (to differenciate from variable caching)
  *
  * @param array $prm Parameter for the cached variable:
  *  - int ttl: Time to live, in minutes, 0 for eternal (default: 60)
  *  - string id: Cache id (required)
  *  - array tags: Optionnal tags for the id
  *  - array request: Array for build the request ID (@see cache::idRequest)
  * @return bool True if cache found and content printed
  * @see end
  */
 public function start(array $prm)
 {
     if ($this->isEnabled() && config::initTab($prm, array('ttl' => $this->cfg->ttl, 'id' => null, 'tags' => $this->cfg->tags, 'request' => $this->cfg->request))) {
         $prm['file'] = $this->file(array_merge($prm, array('callFrom' => debug::callFrom(2), 'type' => 'cache')));
         if (file::exists($prm['file']) && ($prm['ttl'] == 0 || file::date($prm['file']) + $prm['ttl'] * 60 > time())) {
             echo file::read($prm['file']);
             return true;
         } else {
             $this->obSave = '';
             /*
             				if (ob_get_length()) {
             					$this->obSave = ob_get_contents();
             					ob_end_clean();
             				}
             				// */
             ob_start();
             $this->prmOut = $prm;
         }
     }
     return false;
 }
Пример #11
0
 public static function compile($file)
 {
     $content = file::read($file);
     $content = trim($content);
     //strip <?php
     $content = substr($content, 5);
     //strip <?php
     if (strtolower(substr($content, -2)) == '?>') {
         $content = substr($content, 0, -2);
     }
     return $content;
 }
Пример #12
0
	/**
	 * Show a file to the client
	 *
	 * @param string $file File Path
	 */
	public function showFile($file) {
		if (file::exists($file)) {
			$type = file::getType($file);
			if (strpos($type, 'audio') === 0 || strpos($type, 'video') === 0) {
				$this->mediaDownload($file);
			} else {
				$this->cfg->compress = false;
				$this->neverExpire();
				$this->addHeader('Last-Modified', gmdate('D, j M Y H:i:s', filemtime($file)).' GMT', true);
				$this->addHeader('Content-Type', $type, true);
				$this->addHeader('Cache-Control', 'public', false);
				$this->addHeader('Pragma', null, false);
				$this->addHeader('Content-length', file::size($file), true);
				$this->sendText(file::read($file));
			}
		}
	}
Пример #13
0
	/**
	 * 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');
	}
Пример #14
0
<?php

require_once "inc/class.file.php";
require_once "inc/class.gabarito.php";
$gaboficial = new file("gabaritos/gabaritooficial-1-a.dat");
$gabstr = $gaboficial->read();
$gabaritooficial = new gabarito();
$gabaritooficial->getFromStr($gabstr);
$lines = file('gabaritos/cobaia.dat');
// Percorre o array, mostrando o fonte HTML com numeração de linhas.
foreach ($lines as $line_num => $line) {
    $dados = substr($line, 0, 50);
    $gab = substr($line, 50, strlen($line) - 50);
    $gabarito = new gabarito();
    $gabarito->setDados($dados);
    $gabarito->getFromStr($gab);
    $gabarito->comparaComOficial($gabaritooficial);
    $html = $gabarito->getResultado();
    echo $html . "<br>";
    //echo "Linha #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
    /*
    echo "$gab<br>\n";
    echo "<pre>";
    var_dump($gabarito);
    echo "</pre>";
    */
}
Пример #15
0
function file_data($filename)
{
    $file = new file($filename);
    $data = $file->read();
    return $data;
}
Пример #16
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);
	}