コード例 #1
0
ファイル: default.php プロジェクト: noccy80/lepton-ng
 function upload()
 {
     if (request::isPost()) {
         $file = request::post('userfile');
         printf('<p>%s</p>', $file);
         $dest = APP_PATH . 'cache/image.jpg';
         printf('<p>%s</p>', $dest);
         if ($file->save($dest)) {
             print '<p><img src="/cache/image.jpg"></p>';
         } else {
             print '<p><b>Failed to save the image</b></p>';
         }
     }
     print '<form enctype="multipart/form-data" action="/default/upload" method="POST">';
     print 'Send this file: <input name="userfile" type="file">';
     print '<input type="submit" value="Send File">';
     print '</form>';
 }
コード例 #2
0
 /**
  * Indicate if the file uploaded is valid
  *
  * @return boolean
  */
 public function isValid()
 {
     $file = $this->getInfo();
     $tmp = !request::isPost() || $this->cfg->current || array_key_exists('error', $file) && $file['error'] === 0 && array_key_exists('size', $file) && $file['size'] > 0;
     $helperValid = $this->callHelper('valid', $file);
     return $tmp ? is_bool($helperValid) ? $helperValid : $helperValid : ($this->cfg->required ? 'required' : true);
 }
コード例 #3
0
ファイル: controller.class.php プロジェクト: nyroDev/nyroFwk
	protected function execIndex(array $prm = array()) {
		$this->prepare();
		
		$pattern = FILESROOT.$this->dir.DS.'*';
		$search = http_vars::getInstance()->get('search');
		if ($search) {
			$pattern.= strtolower($search).'*';
			$this->uri.= 'search='.$search.'&';
		}
		
		$delete = http_vars::getInstance()->get('delete');
		if ($delete) {
			$file = FILESROOT.urldecode($delete);
			if (file::exists($file)) {
				file::delete($file);
				file::multipleDelete(substr($file, 0, -strlen(file::getExt($file))-1).'_*');
				response::getInstance()->redirect($this->uri);
			}
		}
		
		$form = $this->getForm();
		
		if (request::isPost()) {
			$form->refill();
			if ($form->isValid())
				response::getInstance()->sendText('ok');
		}
		
		$files = array();
		foreach(file::search($pattern) as $f) {
			if (strpos($f, 'nyroBrowserThumb') === false) {
				$name = basename($f);
				if ($this->type == 'image' && strlen($name) > 15)
					$name = substr($name, 0, 15).'...'.file::getExt($f);
				$files[] = array(
					$f,
					request::uploadedUri(str_replace(FILESROOT, '', $f), $this->myCfg['uploadedUri']),
					$name,
					file::humanSize($f),
					utils::formatDate(filemtime($f)),
					$this->uri.'delete='.urlencode(str_replace(FILESROOT, '', $f)).'&'
				);
			}
		}
		
		$this->setViewVars(array(
			'uri'=>$this->uri,
			'form'=>$form,
			'config'=>$this->config,
			'type'=>$this->type,
			'files'=>$files,
			'searchButton'=>$this->myCfg['search'],
			'search'=>$search,
			'imgHelper'=>$this->myCfg['imgHelper'],
			'filesTitle'=>$this->myCfg['filesTitle'],
			'noFiles'=>$this->myCfg['noFiles'],
			'name'=>$this->myCfg['name'],
			'size'=>$this->myCfg['size'],
			'date'=>$this->myCfg['date'],
			'delete'=>$this->myCfg['delete'],
		));
	}
コード例 #4
0
ファイル: default.class.php プロジェクト: nyroDev/nyroFwk
	/**
	 * Login the current user
	 *
	 * @param mixed $prm
	 * @param null|string $page The page where to be redirected. If null, config will be used
	 * @param boolean $redirectIfLogged Enable the redirect when login is successful
	 * @return bool True if successful
	 */
	public function login($prm = null, $page = null, $redirectIfLogged = true) {
		$loginField = $this->cfg->getInArray('fields', 'login');
		$passField = $this->cfg->getInArray('fields', 'pass');

		$form = $this->getLoginForm();
		if (is_null($prm)) {
			if (request::isPost()) {
				$form->refill();
				$form->isValid();
				$prm = $form->getValues(true);
			}
		}

		if (is_array($prm)
			&& array_key_exists($loginField, $prm)
			&& array_key_exists($passField, $prm)) {
				$this->user = $this->table->find(array_merge(
					$this->cfg->where,
					$this->getWhereLogin($prm[$loginField], $prm[$passField])
				));
				
				if ($this->user) {
					$this->saveLogin(array_key_exists('stayConnected', $prm) && $prm['stayConnected']);
					$this->hook('login');
				} else
					$form->addCustomError($loginField, $this->cfg->errorMsg);
				if ($this->logged && $redirectIfLogged) {
					if (is_null($page)) {
						if ($this->session->pageFrom) {
							$page = $this->session->pageFrom;
							unset($this->session->pageFrom);
						} else
							$page = request::uri($this->getPage('logged'));
					} else
						$page = request::uri($page);
					response::getInstance()->redirect($page);
				}
		}
		return $this->logged;
	}
コード例 #5
0
ファイル: filterTable.class.php プロジェクト: nyroDev/nyroFwk
 public function fillValues()
 {
     $defValues = $this->form->getValues();
     if (request::isPost() || request::getPrm($this->cfg->clearPrm)) {
         if (request::isPost()) {
             $this->form->refill();
         }
         $this->session->clear(true);
     } else {
         foreach ($this->form->getNames() as $name) {
             if ($this->session->check($name)) {
                 $this->form->setValue($name, $this->session->get($name));
             }
         }
         $this->form->setBound(false);
     }
     foreach ($this->form->getValues() as $k => $v) {
         if ($v != $defValues[$k]) {
             $this->hasValues = true;
         }
     }
 }
コード例 #6
0
ファイル: controller.class.php プロジェクト: nyroDev/nyroFwk
	protected function addEditForm($action, $id = null) {
		$uAction = ucfirst($action);
		$this->row = $id ? $this->table->find($id) : $this->table->getRow();
		if (!$this->row)
			response::getInstance()->redirect($this->indexPage);
		
		if ($action == 'duplic') {
			$tmp = $this->row;
			$this->row = $this->table->getRow();
			$this->row->setValues($tmp->getValues());
			$this->row->setValues($tmp->getValues('flat'));
			$action = 'add';
		}	
		
		$this->hook($action);

		$this->form = $this->row->getForm($this->getFields($action), array_merge(array('sectionName'=>tr::__('scaffold_'.$action)), $this->cfg->formOpts));
		$this->hook('formInit');
		$this->hook('formInit'.$uAction);

		if (request::isPost()) {
			$this->form->refill();
			$this->hook('formPost'.$uAction);
			if ($this->form->isValid()) {
				$this->row->setValues($this->form->getValues());
				$this->hook('before'.$uAction);
				if ($this->row->save()) {
					$this->hook('after'.$uAction);
					response::getInstance()->redirect($this->indexPage);
				}
			} else
				$this->setViewVar('errors', $this->form->getErrors());
		}

		$this->form->setSubmitText(tr::__('scaffold_'.$action));
		$this->form->setSubmitplus('<a href="'.$this->indexPage.'">'.tr::__('scaffold_back').'</a>');

		$this->hook('form'.$uAction);

		$this->setViewVars(array(
			'row'=>$this->row,
			'form'=>$this->form
		));
	}
コード例 #7
0
ファイル: nyro.class.php プロジェクト: nyroDev/nyroFwk
	/**
	 * Website main
	 */
	public static function main() {

		define('NYROVERSION', '0.2');
		
		$globalContent = null;
		$globalVars = null;
		$cacheInst = null;
		$cacheInstVars = null;

		try {
			self::init();

			$resp = response::getInstance();
			self::$cfg->overload(__CLASS__.'Response');
			
			if (self::$cfg->globalCache && !request::isPost() && count($_GET) == 0 && $resp->canGlobalCache()) {
				$prm = is_array(self::$cfg->globalCache) ? self::$cfg->globalCache : array();
				$cacheInst = cache::getInstance(array_merge(array('serialize'=>false), $prm));
				$id = str_replace('/', '._.', '/'.request::get('request')).(request::isAjax() ? '-ajax' : '');
				$cacheInst->get($globalContent, array(
					'id'=>$id
				));
				$cacheInstVars = cache::getInstance(array_merge(array('serialize'=>true), $prm));
				$cacheInstVars->get($globalVars, array(
					'id'=>$id.'-vars'
				));
			}
			if (is_null($globalContent)) {
				request::execModule();
				if (DEV) {
					debug::timer('nyroProcess');
					debug::timer('nyroRender');
				}
				$resp->setContent(request::publishModule());
			}
		} catch (module_exception $e) {
			session::setFlash('nyroError', 'MODULE or ACTION NOT FOUND<br />'.self::handleError($e));
			$resp->error(null, 404);
		} catch (nException $e) {
			session::setFlash('nyroError', self::handleError($e));
			$resp->error(null, 500);
		} catch (PDOException $e) {
			session::setFlash('nyroError', self::handleError($e));
			$resp->error(null, 500);
		} catch (Exception $e) {
			session::setFlash('nyroError', self::handleError($e));
			$resp->error(null, 500);
		}

		try {
			factory::saveCache();

			if ($cacheInst) {
				if ($globalContent) {
					$resp->setVarsFromGlobalCache($globalVars);
					echo $globalContent;
				} else {
					$globalVars = $resp->getVarsForGlobalCache();
					$globalContent = $resp->send();
					$cacheInst->save();
					$cacheInstVars->save();
					echo $globalContent;
				}
			} else {
				echo $resp->send();
			}
		} catch (Exception $e) {
			echo debug::trace($e);
		}
	}