コード例 #1
0
ファイル: Twig.php プロジェクト: haobojunsun/d3
 public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $config = \Yaf_Registry::get('configarr');
     $dispatcher = Yaf_Dispatcher::getInstance();
     $twig = '';
     // view 放在module 目录里
     if ($request->module == $config['application']['dispatcher']['defaultModule']) {
         $twig = new \Core_Twig(APP_PATH . 'views', $config['twig']);
     } else {
         $twig = new \Core_Twig(APP_PATH . 'modules/' . $request->module . '/views', $config['twig']);
     }
     // url generate
     $twig->twig->addFunction("url", new Twig_Function_Function("Tools_help::url"));
     // 语言对应
     $twig->twig->addFunction("lang", new Twig_Function_Function("Tools_help::lang"));
     // 图片路径
     $twig->twig->addFunction("fbu", new Twig_Function_Function("Tools_help::fbu"));
     // 数字验证
     $twig->twig->addFunction("is_numeric", new Twig_Function_Function("is_numeric"));
     // 处理错误提醒
     $session_key = array('ErrorMessageStop', 'ErrorMessage', 'Message');
     foreach ($session_key as $value) {
         $twig->assign($value, Tools_help::getSession($value));
         Tools_help::setSession($value, '');
     }
     $dispatcher->setView($twig);
 }
 protected function doDisplay(array $context, array $blocks = array())
 {
     // line 1
     echo "前台\n<a href=\"";
     // line 2
     echo twig_escape_filter($this->env, Tools_help::url("index/test", array("id" => "1", "name" => "codejm")), "html", null, true);
     echo "\" >测试</a>\n";
 }
コード例 #3
0
ファイル: Members.php プロジェクト: xujunjiepk/yaf_base
 /**
  * 记住用户
  *
  *
  */
 public function reMemberMe($data, $isWriteCookie = false)
 {
     $temp = array('uid' => $data['uid'], 'username' => $data['username'], 'password' => $data['password'], 'role_type' => $data['role_type']);
     Tools_help::setSession('admin', $temp);
     // rememberme 记住密码
     if ($isWriteCookie) {
         Tools_help::setCookie('admin', $temp, 24 * 60 * 60 * 7);
     }
 }
コード例 #4
0
ファイル: BackendCtl.php プロジェクト: xujunjiepk/yaf_base
 public function init()
 {
     parent::init();
     // ---------------- 判断登录 --------------------------------------
     $admin = '';
     $relogin = false;
     // 判断session
     $admin = Tools_help::getSession('admin');
     if (empty($admin)) {
         // 判断cookie
         $admin = Tools_help::getCookie('admin');
         if (empty($admin)) {
             $this->redirect('/backend/Login/index');
         } else {
             $relogin = true;
         }
     }
     // cookie重新验证
     if ($admin && $relogin) {
         $adminModel = new AdminModel();
         $data = $adminModel->getAdminById($admin['id']);
         if (empty($data) || $data['roleid'] != 1 || $data['password'] != $admin['password']) {
             $this->redirect('/backend/Login/index');
         }
         $adminModel->reMemberMe($data);
         $admin = $data;
     }
     // E
     $this->_view->assign("curr_admin", $admin);
     // 用户权限判断
     /*$checkTitle = strtolower($this->moduleName.'_'.$this->controllerName.'_'.$this->actionName);
       $pid = Rbac_Core::getPermissions()->returnId($checkTitle);
       if($pid) {
           if($admin['id']!=1){
               if(!Rbac_Core::getInstance()->check($pid, $admin['id'])) {
                   exit('您没有权限访问该网页1!<a href="javascript:window.history.back();">返回</a> ');
               }
           }
       } else {
           Rbac_Core::getPermissions()->add($checkTitle, $checkTitle);
           //exit('您没有权限访问该网页2!<a href="javascript:window.history.back();">返回</a> ');
       }*/
     $purview = null;
     // 后台菜单数组 S
     $backendMenu = new \Core_CBackendMenu(ConstDefine::$backendMenu, $this->controllerName, $this->actionName, $purview);
     $menustr = $backendMenu->get();
     $this->_view->assign('backendMenu', $menustr);
     // E
 }
コード例 #5
0
ファイル: CBackendMenu.php プロジェクト: xujunjiepk/yaf_base
 public function get()
 {
     $menustr = '<ul class="nav nav-list">';
     foreach ($this->menuArr as $menu) {
         if (is_array($menu['controller'])) {
             foreach ($menu['controller'] as $controller) {
                 if (strtolower($controller) == strtolower($this->controllerName)) {
                     $active = ' class="active"';
                     break;
                 } else {
                     $active = '';
                 }
             }
         } else {
             $active = strtolower($menu['controller']) == strtolower($this->controllerName) ? ' class="active"' : '';
         }
         if (isset($menu['sub']) && !empty($menu['sub'])) {
             // 权限判断
             if (!$this->isShowController($menu['controller'])) {
                 continue;
             }
             // 组菜单
             $menustr .= '<li' . $active . '> <a href="#" class="dropdown-toggle"> <i class="menu-icon fa fa-desktop"></i> <span class="menu-text"> ' . $menu['name'] . '</span> <b class="arrow fa fa-angle-down"></b> </a> <b class="arrow"></b><ul class="submenu">';
             foreach ($menu['sub'] as $submenu) {
                 // 权限判断
                 if (!$this->isShowAction($submenu)) {
                     continue;
                 }
                 // 组菜单
                 $active = '';
                 if (stripos($submenu['url'], $this->url) !== false) {
                     $active = ' class="active"';
                 }
                 $menustr .= '<li' . $active . '> <a href="' . Tools_help::url($submenu['url']) . '"> <i class="menu-icon fa fa-caret-right"></i> ' . $submenu['name'] . '</a> <b class="arrow"></b> </li>';
             }
             $menustr .= '</ul> </li>';
         } else {
             // 权限判断
             if (!$this->isShowController($menu['controller'])) {
                 continue;
             }
             // 组数组
             $menustr .= '<li' . $active . '><a href="' . Tools_help::url($menu['url']) . '"><i class="menu-icon fa fa-tachometer"></i><span class="menu-text"> ' . $menu['name'] . '</span></a><b class="arrow"></b></li>';
         }
     }
     $menustr .= '</ul>';
     return $menustr;
 }
コード例 #6
0
ファイル: BackendCtl.php プロジェクト: huzhaer/yaf_base
 public function init()
 {
     parent::init();
     // ---------------- 判断登录 --------------------------------------
     $admin = '';
     $relogin = false;
     // 判断session
     $admin = Tools_help::getSession('admin');
     if (empty($admin)) {
         // 判断cookie
         $admin = Tools_help::getCookie('admin');
         if (empty($admin)) {
             $this->redirect('/backend/Login/index');
         } else {
             $relogin = true;
         }
     }
     // cookie重新验证
     if ($admin && $relogin) {
         $adminModel = new AdminModel();
         $data = $adminModel->getAdminById($admin['id']);
         if (empty($data) || $data['roleid'] != 1 || $data['password'] != $admin['password']) {
             $this->redirect('/backend/Login/index');
         }
         $adminModel->reMemberMe($data);
         $admin = $data;
     }
     // E
     $this->_view->assign("curr_admin", $admin);
     $this->admin = $admin;
     $rbac = new Rbac_Core();
     if ($admin['rid']) {
         $checkTitle = strtolower($this->moduleName . '/' . $this->controllerName . '/' . $this->actionName);
         $pid = $rbac->check($admin['rid'], $checkTitle);
         if (empty($pid)) {
             exit('您没有权限访问该网页!<a href="javascript:window.history.back();">返回</a> ');
         }
     }
     $menu = $rbac->getMenu($admin['rid'], false);
     // 后台菜单数组 S
     $menustr = new \Core_CBackendMenu($menu, $this->controllerName, $this->actionName);
     $this->_view->assign('backendMenu', $menustr);
     // E
 }
コード例 #7
0
ファイル: Upload.php プロジェクト: huzhaer/yaf_base
 /**
  * 删除文件处理
  *
  */
 public function uploadAction()
 {
     $dir = $this->getg('dir');
     $dirs = array('members', 'album', 'default');
     if (empty($dir) || !in_array($dir, $dirs)) {
         $dir = 'default';
     }
     $fileName = $this->getp('filename');
     if (!empty($fileName)) {
         $_FILES['image']['name'] = $fileName;
     }
     // 处理图片等特殊数据
     $imageInfo = Tools_help::upload('image', $dir);
     $data = array();
     if (!empty($imageInfo)) {
         $data['url'] = Tools_help::fbu($imageInfo);
     }
     echo json_encode($data);
     $this->_exit();
 }
コード例 #8
0
ファイル: Bootstrap.php プロジェクト: huzhaer/yaf_base
 /**
  * 初始化多语言包,判断优先级:GET参数 > COOKIE > 浏览器ACCEPT_LANGUAGE > 默认zh_CN
  * @param Yaf_Dispatcher $dispatcher
  */
 public function _initI18n(Yaf_Dispatcher $dispatcher)
 {
     /*{{{*/
     if ($this->config['application']['site']['I18n']) {
         $lang_map = array('zh-cn' => 'zh_CN', 'zh-tw' => 'zh_TW', 'en-us' => 'en_US');
         //检查GET参数中的lang
         if (isset($_GET['lang']) && isset($lang_map[$_GET['lang']])) {
             $lang = $lang_map[$_GET['lang']];
             if (isset($_COOKIE['lang']) && $_GET['lang'] != $_COOKIE['lang'] || !isset($_COOKIE['lang'])) {
                 //若设置了lang,则写入cookie
                 Tools_help::setcookie('lang', $_GET['lang'], 86400 * 365);
             }
         }
         //若没有,检查COOKIE中的lang
         if (!isset($lang) && isset($_COOKIE['lang'])) {
             $lang = $lang_map[$_COOKIE['lang']];
         }
         //若没有,检查浏览器传的ACCEPT_LANGUAGE中首选
         if (!isset($lang) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
             //"zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3"
             $arr = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
             foreach ($arr as $item) {
                 $temp = explode(';', $item);
                 if (isset($temp[0]) && isset($lang_map[$temp[0]])) {
                     $lang = $lang_map[$temp[0]];
                 }
                 break;
             }
         }
         //没有则设置为zh_CN
         if (!isset($lang) || !in_array($lang, array_values($lang_map))) {
             $lang = $lang_map['zh-cn'];
         }
         // 加载对应语言包
         $lang_arr = (require APP_PATH . 'conf/lang/' . $lang . '.php');
         Yaf_Registry::set('lang_arr', $lang_arr);
         // 记录
         Yaf_Registry::set('lang', $lang);
     }
 }
コード例 #9
0
ファイル: Core.php プロジェクト: huzhaer/yaf_base
 /**
  * Run Opauth:
  * Parses request URI and perform defined authentication actions based based on it.
  */
 public function run()
 {
     if (!empty($this->strategyName)) {
         if (array_key_exists($this->strategyName, $this->strategyMap)) {
             // 当前oauth配置
             $strategy = $this->env['Strategy'][$this->strategyName];
             // 当前oauth执行方法
             if (!empty($this->strategyCallback)) {
                 $this->strategyCallback = strtolower($this->strategyName) . '_callback';
                 $this->env['params']['action'] = $this->strategyCallback;
             }
             // 调用对应oauth类
             $className = 'Oauth_Strategy_' . $this->strategyName;
             $safeEnv = $this->env;
             unset($safeEnv['Strategy']);
             $this->Strategy = new $className($strategy, $safeEnv);
             if (empty($this->env['params']['action'])) {
                 $this->env['params']['action'] = 'request';
                 // 记录来源 S
                 $referer = '';
                 if (isset($_GET['ref'])) {
                     $referer = addslashes($_GET['ref']);
                 } else {
                     if (isset($_SERVER["HTTP_REFERER"])) {
                         $referer = addslashes($_SERVER["HTTP_REFERER"]);
                     }
                 }
                 if (!empty($referer)) {
                     Tools_help::setSession('oauth_referer', $referer);
                 }
                 // 记录来源 E
             }
             // 调用oauth对应方法
             $this->Strategy->callAction($this->env['params']['action']);
         } else {
             trigger_error('未定义的Oauth - ' . $this->env['params']['strategy'], E_USER_ERROR);
         }
     }
 }
コード例 #10
0
ファイル: Captcha.php プロジェクト: huzhaer/yaf_base
 public static function simple($len, $width = 48, $height = 22)
 {
     $words = self::words($len);
     $session_key = 'captcha';
     //$_SESSION[$session_key] = strtolower($words);
     Tools_help::setSession($session_key, strtolower($words));
     $width = $len * 10 + 10 > $width ? $len * 10 + 10 : $width;
     $canvas = imagecreatetruecolor($width, $height);
     $r = array(225, 255, 255, 223);
     $g = array(225, 236, 237, 255);
     $b = array(225, 236, 166, 125);
     $key = mt_rand(0, 3);
     $back = imagecolorallocate($canvas, $r[$key], $g[$key], $b[$key]);
     $border = imagecolorallocate($canvas, 100, 100, 100);
     imagefilledrectangle($canvas, 0, 0, $width - 1, $height - 1, $back);
     imagerectangle($canvas, 0, 0, $width - 1, $height - 1, $border);
     $string = imagecolorallocate($canvas, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
     for ($i = 0; $i < 10; $i++) {
         imagearc($canvas, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 200), mt_rand(20, 200), 55, 44, $string);
     }
     for ($i = 0; $i < 25; $i++) {
         imagesetpixel($canvas, mt_rand(0, $width), mt_rand(0, $height), $string);
     }
     for ($i = 0; $i < $len; $i++) {
         imagestring($canvas, 5, $i * 10 + 5, mt_rand(1, 8), $words[$i], $string);
     }
     if ($canvas) {
         header("Cache-Control: no-cache, must-revalidate");
         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
         header("Pragma: no-cache");
         header("Cache-control: private");
         header('Content-Type: image/png');
         imagepng($canvas);
         imagedestroy($canvas);
     }
     exit;
 }
コード例 #11
0
ファイル: Log.php プロジェクト: xujunjiepk/yaf_base
 /**
  * 编辑
  *
  */
 public function editAction()
 {
     // 获取主键
     $id = $this->getg('id', 0);
     if (empty($id)) {
         $this->error('id 不能为空!');
     }
     // 实例化Model
     $log = new LogModel();
     // 处理Post
     if ($this->getRequest()->isPost()) {
         // 获取所有post数据
         $pdata = $this->getAllPost();
         // 处理图片等特殊数据
         // 验证
         $result = $log->validation->validate($pdata, 'edit');
         $log->parseAttributes($pdata);
         // 通过验证
         if ($result) {
             // 入库前数据处理
             // Model转换成数组
             $data = $log->toArray($pdata);
             $result = $log->update(array('id' => $id), $data);
             if ($result) {
                 // 提示信息并跳转到列表
                 Tools_help::setSession('Message', '修改成功!');
                 $this->redirect('/backend/log/index');
             } else {
                 // 出错
                 Tools_help::setSession('ErrorMessage', '修改失败, 请确定已修改了某项!');
                 $this->_view->assign("errors", $log->validation->getErrorSummary());
             }
             $log->id = $id;
         } else {
             // 验证失败
             Tools_help::setSession('ErrorMessage', '修改失败, 请检查错误项');
             $this->_view->assign("errors", $log->validation->getErrorSummary());
         }
     }
     // 如果Model数据为空,则获取
     if (!empty($id) && empty($log->id)) {
         $data = $log->select(array('where' => array('id' => $id)));
         $log->parseAttributes($data);
     }
     // 格式化表单数据
     // 模版分配数据
     $this->_view->assign("log", $log);
     $this->_view->assign("pageTitle", '修改');
 }
コード例 #12
0
ファイル: BaseCtl.php プロジェクト: huzhaer/yaf_base
 /**
  * request
  *
  */
 protected function getParam($name, $default = '')
 {
     $value = $this->getRequest()->getQuery($name, $default);
     $value = Tools_help::filter($value);
     return $value;
 }
コード例 #13
0
ファイル: Members.php プロジェクト: huzhaer/yaf_base
 /**
  * 编辑用户表
  *
  */
 public function editAction()
 {
     // 获取主键
     $uid = $this->getg('uid', 0);
     if (empty($uid)) {
         $this->error('uid 不能为空!');
     }
     // 实例化Model
     $members = new MembersModel();
     // 处理Post
     if ($this->getRequest()->isPost()) {
         // 获取所有post数据
         $pdata = $this->getAllPost();
         // 处理图片等特殊数据
         $imageInfo = Tools_help::upload('face', 'members');
         if (!empty($imageInfo)) {
             $pdata['face'] = $imageInfo;
         } else {
             unset($pdata['face']);
         }
         // 验证
         $result = $members->validation->validate($pdata, 'edit');
         $members->parseAttributes($pdata);
         // 用户名验证
         $data = $members->select(array('where' => array('username' => $members->username)));
         if ($data && $data['uid'] != $uid) {
             $result = false;
             $members->validation->errors['username'][] = '用户名 已经存在,请重新填写!';
         }
         // 通过验证
         if ($result) {
             // 入库前数据处理
             $pdata['regdate'] = Tools_help::htime($members->regdate);
             $pdata['password'] = Tools_help::hash($members->password);
             // Model转换成数组
             $data = $members->toArray($pdata);
             $result = $members->update(array('uid' => $uid), $data);
             if ($result) {
                 // 提示信息并跳转到列表
                 Tools_help::setSession('Message', '修改成功!');
                 $this->redirect('/backend/members/index');
             } else {
                 // 出错
                 Tools_help::setSession('ErrorMessage', '修改失败, 请确定已修改了某项!');
                 $this->_view->assign("errors", $members->validation->getErrorSummary());
             }
         } else {
             // 验证失败
             Tools_help::setSession('ErrorMessage', '修改失败, 请检查错误项');
             $this->_view->assign("errors", $members->validation->getErrorSummary());
         }
         $members->uid = $uid;
     }
     // 如果Model数据为空,则获取
     if (!empty($uid) && empty($members->uid)) {
         $data = $members->select(array('where' => array('uid' => $uid)));
         $members->parseAttributes($data);
     }
     // 图片处理
     if ($members->face) {
         $members->face = Tools_help::fbu($members->face);
     }
     // 模版分配数据
     $this->_view->assign("members", $members);
     $this->_view->assign("pageTitle", '修改用户表');
 }
コード例 #14
0
ファイル: Index.php プロジェクト: xujunjiepk/yaf_base
 public function testAction()
 {
     echo Tools_help::getCookie('key');
     exit;
 }
コード例 #15
0
ファイル: Roles.php プロジェクト: huzhaer/yaf_base
 /**
  * 编辑角色
  *
  */
 public function editAction()
 {
     // 获取主键
     $id = $this->getg('id', 0);
     if (empty($id)) {
         $this->error('id 不能为空!');
     }
     // 实例化Model
     $rbac = new Rbac_Core();
     // 处理Post
     if ($this->getRequest()->isPost()) {
         $name = $this->getp('name');
         $result = true;
         $errors = array();
         if (empty($name)) {
             $result = false;
             $errors['name'] = '角色名称不能为空!';
         } else {
             $data = $rbac->getRole($name);
             if ($data && $data['id'] != $id) {
                 $result = false;
                 $errors['name'] = '角色名称已经存在!';
             }
         }
         // 通过验证
         if ($result) {
             $result = $rbac->editRole($id, $name);
             if ($result) {
                 // 提示信息并跳转到列表
                 Tools_help::setSession('Message', '修改成功!');
                 $this->redirect('/backend/roles/index');
             } else {
                 // 验证失败
                 $this->_view->assign('ErrorMessage', '修改失败!');
             }
         } else {
             // 验证失败
             $this->_view->assign('ErrorMessage', '修改失败!');
             $this->_view->assign("errors", $errors);
         }
     }
     if (empty($name)) {
         $data = $rbac->getRole($id);
         if ($data) {
             $name = $data['name'];
         } else {
             // 提示信息并跳转到列表
             Tools_help::setSession('ErrorMessage', '没找到对应角色!');
             $this->redirect('/backend/roles/index');
         }
     }
     $this->_view->assign("name", $name);
     $this->_view->assign("id", $id);
     $this->_view->assign("pageTitle", '修改角色');
 }
コード例 #16
0
ファイル: Login.php プロジェクト: xujunjiepk/yaf_base
 /**
  * 管理员退出
  *
  */
 public function logoutAction()
 {
     Tools_help::setSession('member', '');
     Tools_help::setCookie('member', '', 0);
     $this->redirect('/backend/login/index');
 }
コード例 #17
0
ファイル: News.php プロジェクト: huzhaer/yaf_base
 /**
  * 编辑新闻
  *
  */
 public function editAction()
 {
     // 获取主键
     $id = $this->getg('id', 0);
     if (empty($id)) {
         $this->error('id 不能为空!');
     }
     // 实例化Model
     $news = new NewsModel();
     // 处理Post
     if ($this->getRequest()->isPost()) {
         // 获取所有post数据
         $pdata = $this->getAllPost();
         // 处理图片等特殊数据
         $imageInfo = Tools_help::upload('img', 'news');
         if (!empty($imageInfo)) {
             $pdata['img'] = $imageInfo;
         } else {
             unset($pdata['img']);
         }
         // 验证
         $result = $news->validation->validate($pdata, 'edit');
         $news->parseAttributes($pdata);
         // 通过验证
         if ($result) {
             // 入库前数据处理
             $pdata['dateline'] = Tools_help::htime($news->dateline);
             $pdata['updatetime'] = Tools_help::htime($news->updatetime);
             // Model转换成数组
             $data = $news->toArray($pdata);
             $result = $news->update(array('id' => $id), $data);
             if ($result) {
                 // 提示信息并跳转到列表
                 Tools_help::setSession('Message', '修改成功!');
                 $this->redirect('/backend/news/index');
             } else {
                 // 出错
                 Tools_help::setSession('ErrorMessage', '修改失败, 请确定已修改了某项!');
                 $this->_view->assign("errors", $news->validation->getErrorSummary());
             }
             $news->id = $id;
         } else {
             // 验证失败
             Tools_help::setSession('ErrorMessage', '修改失败, 请检查错误项');
             $this->_view->assign("errors", $news->validation->getErrorSummary());
         }
     }
     // 如果Model数据为空,则获取
     if (!empty($id) && empty($news->id)) {
         $data = $news->select(array('where' => array('id' => $id)));
         $news->parseAttributes($data);
     }
     // 格式化表单数据
     // 图片处理
     if ($news->img) {
         $news->img = Tools_help::fbu($news->img);
     }
     // 模版分配数据
     $this->_view->assign("news", $news);
     $this->_view->assign("pageTitle", '修改新闻');
 }
コード例 #18
0
ファイル: FileUpload.php プロジェクト: huzhaer/yaf_base
 public function save()
 {
     if (count($this->file_array) > 0) {
         $this->log('Capturing input %s', $this->input);
         if (array_key_exists($this->input, $this->file_array)) {
             // set original filename if not have a new name
             if (empty($this->filename)) {
                 $this->log('Using original filename %s', $this->file_array[$this->input]['name']);
                 $this->filename = $this->file_array[$this->input]['name'];
             }
             // 扩展名
             //$extension = preg_replace(
             //"/^[\p{L}\d\s\-\_\.\(\)]*\.([\d\w]+)$/iu",
             //'$1',
             //$this->file_array[$this->input]["name"]
             //);
             $extension = Tools_help::getFileExt($this->file_array[$this->input]['name']);
             $this->filename = sprintf($this->filename, $extension);
             // set file info
             $this->file['mime'] = $this->file_array[$this->input]['type'];
             $this->file['tmp'] = $this->file_array[$this->input]['tmp_name'];
             $this->file['original'] = $this->file_array[$this->input]['name'];
             $this->file['size'] = $this->file_array[$this->input]['size'];
             $this->file['sizeFormated'] = Tools_help::sizeFormat($this->file['size']);
             $this->file['destination'] = $this->destination_directory . $this->filename;
             $this->file['filename'] = $this->filename;
             $this->file['error'] = $this->file_array[$this->input]['error'];
             // Check if exists file
             if ($this->fileExists($this->destination_directory . $this->filename)) {
                 $this->log('%s file already exists', $this->filename);
                 // Check if overwrite file
                 if ($this->overwrite_file === false) {
                     $this->log('You don\'t allow overwriting. Show more about FileUpload::allowOverwriting');
                     return false;
                 }
                 $this->log('The %s file is overwritten', $this->filename);
             }
             // Execute input callback
             if (!empty($this->callbacks['input'])) {
                 $this->log('Running input callback');
                 call_user_func($this->callbacks['input'], (object) $this->file);
             }
             // Check mime type
             $this->log("Check mime type");
             if (!$this->checkMimeType($this->file['mime'])) {
                 $this->log('Mime type %s not allowed', $this->file['mime']);
                 return false;
             }
             $this->log('Mime type %s allowed', $this->file['mime']);
             // Check file size
             if ($this->max_file_size > 0) {
                 $this->log('Checking file size');
                 if ($this->max_file_size < $this->file["size"]) {
                     $this->log('The file exceeds the maximum size allowed(Max: %s; File: %s)', Tools_help::sizeFormat($this->max_file_size), Tools_help::sizeFormat($this->file["size"]));
                     return false;
                 }
             }
             // Copy tmp file to destination and change status
             $this->log('Copy tmp file to destination %s', $this->destination_directory);
             $this->log('Using upload function: %s', $this->upload_function);
             $this->file['status'] = call_user_func_array($this->upload_function, array($this->file_array[$this->input]['tmp_name'], $this->destination_directory . $this->filename));
             // Execute output callback
             if (!empty($this->callbacks['output'])) {
                 $this->log('Running output callback');
                 call_user_func($this->callbacks['output'], (object) $this->file);
             }
             return $this->file['status'];
         }
     }
 }
コード例 #19
0
ファイル: Validation.php プロジェクト: huzhaer/yaf_base
 /**
  * 验证码验证
  */
 public static function captcha($input)
 {
     if (empty($input)) {
         return false;
     }
     $sys_captcha = Tools_help::getSession('captcha');
     if (strtolower($input) !== $sys_captcha) {
         return false;
     }
     return true;
 }
コード例 #20
0
ファイル: CMode.php プロジェクト: huzhaer/yaf_base
 /**
  * 单条查询
  *
  */
 public function select($params = array('where' => array()))
 {
     $query = "";
     if (isset($params['field']) && is_array($params['field']) && !empty($params['field'])) {
         $fieldstr = Tools_help::arraytofields($params['field']);
         $query .= 'select ' . $fieldstr . ' from ' . $this->_table;
     } else {
         $query .= 'select * from ' . $this->_table;
     }
     if (isset($params['where']) && is_array($params['where']) && !empty($params['where'])) {
         $query .= ' where 1=1 ';
         foreach ($params['where'] as $k => $v) {
             $islike = strstr($v, '%');
             if ($islike) {
                 $query .= ' and ' . $k . ' like ?';
             } else {
                 $query .= ' and ' . $k . '=?';
             }
         }
     }
     if (isset($params['order']) && !empty($params['order'])) {
         $query .= ' order by ' . $params['order'];
     }
     $query .= ' limit 1';
     $dbconn = $this->db->prepare($query);
     $dbconn->execute(array_values($params['where']));
     $result = $dbconn->fetch(PDO::FETCH_ASSOC);
     $dbconn->closeCursor();
     return isset($result) ? $result : false;
 }
コード例 #21
0
ファイル: Strategy.php プロジェクト: huzhaer/yaf_base
 /**
  * Send $data to callback_url using specified transport method
  *
  * @param array $data Data to be sent
  * @param string $transport Callback method, either 'get', 'post' or 'session'
  *        'session': Default. Works best unless callback_url is on a different domain than Opauth
  *        'post': Works cross-domain, but relies on availability of client-side JavaScript.
  *        'get': Works cross-domain, but may be limited or corrupted by browser URL length limit
  *               (eg. IE8/IE9 has 2083-char limit)
  *
  */
 private function shipToCallback($data, $transport = null)
 {
     if (empty($transport)) {
         $transport = $this->env['callback_transport'];
     }
     switch ($transport) {
         case 'get':
             $this->redirect($this->env['callback_url'] . '?' . http_build_query(array('opauth' => base64_encode(serialize($data))), '', '&'));
             break;
         case 'post':
             $this->clientPost($this->env['callback_url'], array('opauth' => base64_encode(serialize($data))));
             break;
         case 'session':
         default:
             Tools_help::setSession('oauth', $data);
             $this->redirect($this->env['callback_url']);
     }
 }
コード例 #22
0
ファイル: ImageManager.php プロジェクト: huzhaer/yaf_base
 /**
  * 验证上传文件的类型是否为图片及大小是否越界
  * @param $file
  * @param int $max_file_size
  * @return bool|string
  */
 public static function validateUpload($file, $max_file_size = 0)
 {
     if ((int) $max_file_size > 0 && $file['size'] > (int) $max_file_size) {
         return sprintf(Tools_help::displayError('Image is too large (%1$d kB). Maximum allowed: %2$d kB'), $file['size'] / 1024, $max_file_size / 1024);
     }
     if (!Files_ImageManager::isRealImage($file['tmp_name'], $file['type']) || !Files_ImageManager::isCorrectImageFileExt($file['name'])) {
         return 'Image format not recognized, allowed formats are: .gif, .jpg, .png';
     }
     if ($file['error']) {
         return sprintf(Tools_help::displayError('Error while uploading image; please change your server\'s settings. (Error code: %s)'), $file['error']);
     }
     return true;
 }