Exemplo n.º 1
0
Arquivo: City.php Projeto: pancke/yyaf
 /**
  * 增加城市
  */
 public function addAction()
 {
     if ($this->_request->isPost()) {
         //修改密码验证
         $aCookie = Util_Cookie::get(Yaf_G::getConf('authkey', 'cookie'));
         $iAdminID = $aCookie['iAdminID'];
         $aUser = Model_Admin::getDetail($iAdminID);
         $pwd = $this->getParam('pwd');
         if (!isset($pwd) || $pwd == '') {
             return $this->showMsg('修改密码不可以为空', false);
         }
         if ($aUser['sEditPassword'] != md5($pwd)) {
             return $this->showMsg('修改密码不正确', false);
         }
         $aCity = $this->_checkData('add');
         if (empty($aCity)) {
             return null;
         }
         if (Model_City::getCityByName($aCity['sCityName'])) {
             return $this->showMsg('城市已经存在!', false);
         }
         if (Model_City::addData($aCity) > 0) {
             return $this->showMsg('城市增加成功!', true);
         } else {
             return $this->showMsg('城市增加失败!', false);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 上传视频
  *
  * @param
  *            $aConfig
  * @return array
  */
 public function uploadimg($aConfig)
 {
     $aReturn = array('state' => 'SUCCESS', 'url' => '', 'title' => '', 'original' => '', 'type' => '', 'size' => '');
     do {
         $sFileField = $aConfig['imageFieldName'];
         if (!isset($_FILES[$sFileField])) {
             $aReturn['state'] = '上传文件为空';
             break;
         }
         $sFromURL = $this->getRequest()->getHttpReferer();
         $oStorage = new File_Storage();
         $mResult = $oStorage->isAllowedDomain($sFromURL);
         if (!$mResult) {
             // 当前站点不允许上传到图片服务器
             $aReturn['state'] = '当前站点不允许上传到服务器';
             break;
         }
         $sIP = $this->getRequest()->getClientIP();
         $sDomain = Util_Uri::getDomain($sFromURL);
         $aFile = $_FILES[$sFileField];
         list($iError, $mResult) = $oStorage->saveFile($aFile['name'], $aFile['tmp_name'], $aFile['error'], $aFile['size'], $sIP, $sDomain);
         if ($iError !== 0) {
             $aReturn['state'] = $mResult;
             break;
         }
         $sCDNDomain = Yaf_G::getConf('file', 'domain');
         $aReturn['url'] = 'http://' . $sCDNDomain . '/view/' . $mResult['sKey'] . '.' . $mResult['sExt'];
         $aReturn['title'] = basename($aFile['name']);
         $aReturn['original'] = basename($aFile['name']);
         $aReturn['type'] = $mResult['sExt'];
         $aReturn['size'] = $mResult['iSize'];
     } while (false);
     return $aReturn;
 }
Exemplo n.º 3
0
 /**
  * @runInSeparateProcess
  */
 public function testCase02()
 {
     if (!defined('YAF_MODE')) {
         //@todo for some reason this need to b true to pass the test
         Yaf_G::iniSet('yaf.use_spl_autoload', true);
         Yaf_G::iniSet('yaf.lowcase_path', false);
     } else {
         ini_set('yaf.use_spl_autoload', false);
         ini_set('yaf.lowcase_path', false);
     }
     $this->assertEquals('CLI', $this->request->getMethod());
     $this->assertEquals('index', $this->request->getModuleName());
     $this->assertEquals('dummy', $this->request->getControllerName());
     $this->assertEquals('index', $this->request->getActionName());
     $this->assertFalse($this->request->isDispatched());
     $this->assertTrue($this->request->isRouted());
     $this->request->setParam('name', 'Laruence');
     $this->assertEquals('Laruence', $this->request->getParam('name'));
     $this->assertNull($this->request->getParam('non-exists'));
     $this->assertTrue($this->request->isCli());
     $app = new Yaf_Application(array("application" => array("directory" => dirname(__FILE__))));
     try {
         $app->getDispatcher()->dispatch($this->request);
         $this->fail('An Yaf_Exception_LoadFailed_Controller ' . 'exception was not throwed');
     } catch (Exception $e) {
         $this->assertEquals('Could not find controller script ' . dirname(__FILE__) . '/controllers/Dummy.php', $e->getMessage());
     }
 }
Exemplo n.º 4
0
 /**
  * 代理修改
  */
 public function editAction()
 {
     if ($this->_request->isPost()) {
         //修改密码验证
         $aCookie = Util_Cookie::get(Yaf_G::getConf('authkey', 'cookie'));
         $iAdminID = $aCookie['iAdminID'];
         $aUser = Model_Admin::getDetail($iAdminID);
         $pwd = $this->getParam('pwd');
         if (!isset($pwd) || $pwd == '') {
             return $this->showMsg('修改密码不可以为空', false);
         }
         if ($aUser['sEditPassword'] != md5($pwd)) {
             return $this->showMsg('修改密码不正确', false);
         }
         $aProxy = $this->_checkData('update');
         if (empty($aProxy)) {
             return null;
         }
         $aProxy['iProxyID'] = intval($this->getParam('iProxyID'));
         $aOldProxy = Model_CrawlProxy::getDetail($aProxy['iProxyID']);
         if (!$aOldProxy) {
             return $this->showMsg('代理信息更新失败!', false);
         }
         if (1 == Model_CrawlProxy::updData($aProxy)) {
             return $this->showMsg('代理信息更新成功!', true);
         } else {
             return $this->showMsg('代理信息更新失败!', false);
         }
     } else {
         $iProxyID = intval($this->getParam('id'));
         $aProxy = Model_CrawlProxy::getDetail($iProxyID);
         $this->assign('aProxy', $aProxy);
     }
 }
Exemplo n.º 5
0
Arquivo: Role.php Projeto: pancke/yyaf
 /**
  * 编辑角色
  * @return NULL|boolean
  */
 public function editAction()
 {
     if ($this->isPost()) {
         //修改密码验证
         $aCookie = Util_Cookie::get(Yaf_G::getConf('authkey', 'cookie'));
         $iAdminID = $aCookie['iAdminID'];
         $aUser = Model_Admin::getDetail($iAdminID);
         $pwd = $this->getParam('pwd');
         if (!isset($pwd) || $pwd == '') {
             return $this->showMsg('修改密码不可以为空', false);
         }
         if ($aUser['sEditPassword'] != md5($pwd)) {
             return $this->showMsg('修改密码不正确', false);
         }
         $aRole = $this->_checkData('update');
         if (empty($aRole)) {
             return null;
         }
         $aRole['iRoleID'] = intval($this->getParam('iRoleID'));
         if (1 == Model_Role::updData($aRole)) {
             return $this->showMsg('角色信息更新成功!', true);
         } else {
             return $this->showMsg('角色信息更新失败!', false);
         }
     } else {
         $iRoleID = intval($this->getParam('id'));
         $aRole = Model_Role::getDetail($iRoleID);
         $aRole['aPermission'] = explode(',', $aRole['sPermission']);
         $aRole['aModule'] = explode(',', $aRole['sModule']);
         $this->assign('aRole', $aRole);
         $this->assign('aPermissionList', Model_Permission::getAllPermissions());
         $this->assign('aMenuList', Model_Menu::getMenus());
     }
 }
Exemplo n.º 6
0
 public function __construct()
 {
     $app = self::app();
     if (!is_null($app)) {
         throw new Yaf_Exception('Only one application can be initialized');
     }
     Yaf_G::init();
     //这里主要是配置文件的加载
     // request initialization
     if (isset($_SERVER['REQUEST_METHOD'])) {
         //判断http请求还是cli请求
         $request = new Yaf_Request_Http();
         //获取请求的url路径和基础路径,以及请求方式
     } else {
         $request = new Yaf_Request_Cli();
     }
     if ($request == null) {
         throw new Yaf_Exception('Initialization of request failed');
     }
     // dispatcher
     $this->_dispatcher = Yaf_Dispatcher::getInstance();
     //将调度对象赋值给app对象的属性,并在调度对象的属性中添加路由对象,单例
     if ($this->_dispatcher == null || !$this->_dispatcher instanceof Yaf_Dispatcher) {
         throw new Yaf_Exception('Instantiation of dispatcher failed');
     }
     $this->_dispatcher->setRequest($request);
     //把请求对象赋值给调度对象的属性中
     self::$_app = $this;
 }
Exemplo n.º 7
0
 /**
  * Find a matching route to the current Request and inject
  * returning values to the Request object.
  *
  * @return bool if there is a valid route
  */
 public function route(Yaf_Request_Abstract $request)
 {
     $requestUri = $request->getRequestUri();
     //去掉根目录
     $baseuri = $request->getBaseUri();
     if ($requestUri != '' && $baseuri != '' && stripos($requestUri, $baseuri) === 0) {
         $path = substr($requestUri, strlen($baseuri));
     } else {
         $path = $requestUri;
     }
     //支持rewrite路由
     $matches = null;
     $rewrites = Yaf_G::getConf('rewrite', 'route');
     $rest = explode('?', $path, 2);
     $path = $rest[0];
     if (!empty($rewrites)) {
         foreach ($rewrites as $k => $v) {
             $matches = null;
             if (preg_match($k, $path, $matches)) {
                 $path = preg_replace($k, $v, $path);
                 break;
             }
         }
     }
     if (!empty($rest[1])) {
         $path .= '?' . $rest[1];
     }
     //取得Route
     $aRoute = Yaf_G::getRoute($path);
     $request->setModuleName($aRoute['module']);
     $request->setControllerName($aRoute['controller']);
     $request->setActionName($aRoute['action']);
     //解析参数
     parse_str($aRoute['query'], $params);
     /*
     $params = array();
     $rest = $aRoute['query'];
     $numSegs = count($rest);
     if ($numSegs > 0) {
         for ($i = 0; $i < $numSegs; $i = $i + 2) {
             $key = $rest[$i];
             $val = isset($rest[$i + 1]) ? $rest[$i + 1]: null;
             $params[$key] = (isset($params[$key]) ? (array_merge((array) $params[$key], array(
                 $val
             ))) : $val);
         }
     }
     */
     //rewrite参数解析
     if (!empty($matches)) {
         foreach ($matches as $k => $v) {
             if (!is_numeric($k)) {
                 $params[$k] = $v;
             }
         }
     }
     $request->setParam($params);
     return true;
 }
Exemplo n.º 8
0
 /**
  * 支付宝回调
  * @param unknown $aParams
  * @return Ambigous <验证结果, boolean>
  */
 public static function callback($aParams)
 {
     require_once LIB_PATH . '/Payment/Alipay/alipay_service.class.php';
     require_once LIB_PATH . '/Payment/Alipay/alipay_notify.class.php';
     $alipay_config = Yaf_G::getConf('aliapy_config', null, 'alipay');
     $alipayNotify = new AlipayNotify($alipay_config);
     return $alipayNotify->verifyNotify($aParams);
 }
Exemplo n.º 9
0
Arquivo: User.php Projeto: pancke/yyaf
 /**
  * 登录
  * @param unknown $aUser
  */
 public static function login($aUser)
 {
     $aCookie = array('iUserID' => $aUser['iUserID'], 'sEmail' => $aUser['sEmail'], 'sMobile' => $aUser['sMobile'], 'iType' => $aUser['iType'], 'sRealName' => $aUser['sRealName']);
     $sKey = Model_User::getUserType($aUser['iType']);
     $expire = Yaf_G::getConf('frontexpire', 'cookie');
     Util_Cookie::set(Yaf_G::getConf($sKey, 'cookie'), $aCookie, $expire);
     $sKey = Model_User::getUserType($aUser['iType'] == Model_User::TYPE_AD ? Model_User::TYPE_MEDIA : Model_User::TYPE_AD);
     Util_Cookie::delete(Yaf_G::getConf($sKey, 'cookie'));
     return $aCookie;
 }
Exemplo n.º 10
0
Arquivo: Menu.php Projeto: pancke/yyaf
 public static function getTree($iAdminID = 0)
 {
     $aWhere = array('iStatus' => 1);
     $aList = self::getAll(array('where' => $aWhere, 'order' => 'iMenuID ASC'));
     // 权限判断
     if ($iAdminID > 0) {
         $aMenuPermission = Model_Permission::getMenuPermissions($iAdminID);
     }
     // 是否查找当前菜单
     $bFind = 0;
     if ($iAdminID > 0) {
         $sUri = Yaf_G::getUrl();
     } else {
         $sUri = null;
     }
     // 排序及整理
     $aParentID = array();
     $aOrder = array();
     $aData = array();
     foreach ($aList as $aMenu) {
         if ($iAdminID > 0) {
             if ($aMenuPermission != -1 && !isset($aMenuPermission[$aMenu['iMenuID']])) {
                 continue;
             }
             $aMenu['iCurr'] = Yaf_G::getUrl($aMenu['sUrl']) == $sUri ? 1 : 0;
             if (!$bFind && $aMenu['iCurr'] == 1) {
                 $bFind = 1;
             }
         }
         $aParentID[] = $aMenu['iParentID'];
         $aOrder[] = $aMenu['iOrder'];
         unset($aMenu['iOrder'], $aMenu['iStatus'], $aMenu['iCreateTime'], $aMenu['iUpdateTime']);
         $aData[] = $aMenu;
     }
     unset($aList);
     array_multisort($aParentID, SORT_NUMERIC, SORT_ASC, $aOrder, SORT_NUMERIC, SORT_ASC, $aData);
     // 如果没有匹配的菜单,则从Cookie中获取
     if ($iAdminID > 0) {
         if (!$bFind) {
             $sUri = Util_Cookie::get('menu');
         } else {
             Util_Cookie::set('menu', $sUri);
         }
     }
     // 整理父节点
     $aParent = [];
     foreach ($aData as $aMenu) {
         if (!$bFind) {
             $aMenu['iCurr'] = Yaf_G::getUrl($aMenu['sUrl']) == $sUri ? 1 : 0;
         }
         $aParent[$aMenu['iParentID']][] = $aMenu;
     }
     unset($aMenu);
     return self::_buildTree($aParent, 0, 0, '');
 }
Exemplo n.º 11
0
 /**
  * 执行Action前执行
  * @see Yaf_Controller::actionBefore()
  */
 public function actionBefore()
 {
     $this->aCurrProject = Yaf_G::getConf('project');
     if ($this->bCheckLogin) {
     }
     $this->assign('sStaticRoot', 'http://' . Yaf_G::getConf('static', 'domain'));
     $this->assign('sRoot', 'http://' . Yaf_G::getConf('static', 'domain'));
     $this->assign('aMeta', array('title' => $this->aCurrProject['name']));
     //做个零时的
     $this->aCurrUser = ['iUsername' => 'admin', 'iUserID' => 1];
 }
Exemplo n.º 12
0
Arquivo: Base.php Projeto: pancke/yyaf
 /**
  * 执行Action前执行
  *
  * @see Yaf_Controller::actionBefore()
  */
 public function actionBefore()
 {
     Model_ActionLog::setType(Model_ActionLog::TYPE_FRONT);
     $this->_frame = 'frame.phtml';
     // 访问者的GUID
     $this->sVistorGuid = Util_Cookie::get('guid');
     if (empty($this->sVistorGuid)) {
         $this->sVistorGuid = Util_Guid::get('-');
         Util_Cookie::set('guid', $this->sVistorGuid, 86400 * 365);
     }
     $this->assign('sStaticRoot', 'http://' . Yaf_G::getConf('static', 'domain'));
 }
Exemplo n.º 13
0
 /**
  * 构造函数
  */
 private static function init()
 {
     self::$_bInit = true;
     self::$_aConfig = Yaf_G::getConf(null, 'logger');
     $sBaseDir = self::$_aConfig['sBaseDir'];
     unset(self::$_aConfig['sBaseDir']);
     foreach (self::$_aConfig as $sKey => $mConfig) {
         $sDir = isset(self::$_aConfig[$sKey]['sDir']) ? self::$_aConfig[$sKey]['sDir'] : $sKey;
         self::$_aConfig[$sKey]['sPath'] = $sBaseDir . DIRECTORY_SEPARATOR . $sDir . DIRECTORY_SEPARATOR;
         if (!is_dir(self::$_aConfig[$sKey]['sPath'])) {
             umask(00);
             if (false === mkdir(self::$_aConfig[$sKey]['sPath'], 0755, true)) {
                 throw new Exception(__CLASS__ . ': can not create path(' . self::$_aConfig[$sKey]['sPath'] . ').');
                 return false;
             }
         }
     }
 }
Exemplo n.º 14
0
Arquivo: Base.php Projeto: pancke/yyaf
  * 当前用户
  * 
  * @var unknown
  */
 protected $aCurrUser = null;
 /**
  * 当前城市
  * 
  * @var unknown
  */
 protected $iCurrCityID = null;
 protected $aCurrCity = null;
 /**
  * 执行Action前执行
  * 
  * @see Yaf_Controller::actionBefore()
  */
 public function actionBefore()
 {
     $this->_frame = 'admin.phtml';
Exemplo n.º 15
0
 /**
  * @runaInSeparateProcess
  */
 public function testCase027()
 {
     $globalDir = '/php/global/dir';
     if (!defined('YAF_MODE')) {
         Yaf_G::iniSet('yaf.library', $globalDir);
         Yaf_G::iniSet('yaf.use_spl_autoload', false);
     } else {
         ini_set('yaf.library', $globalDir);
         ini_set('yaf.use_spl_autoload', false);
     }
     $config = array("application" => array("directory" => TEST_APPLICATION_PATH . 'application/', "dispatcher" => array("catchException" => 0, "throwException" => 0)));
     $app = new Yaf_Application($config);
     include dirname(__FILE__) . '/Loader/testCase027.php';
     try {
         $app->execute('testCase027');
     } catch (PHPUnit_Framework_Error_Warning $e) {
         $this->assertContains('Could not find script ' . TEST_APPLICATION_PATH . 'application/controllers/NoExists.php', $e->getMessage());
     }
 }
Exemplo n.º 16
0
 /**
  * 基础配置修改
  */
 public function editAction()
 {
     if ($this->_request->isPost()) {
         //修改密码验证
         $aCookie = Util_Cookie::get(Yaf_G::getConf('authkey', 'cookie'));
         $iAdminID = $aCookie['iAdminID'];
         $aUser = Model_Admin::getDetail($iAdminID);
         $pwd = $this->getParam('pwd');
         if (!isset($pwd) || $pwd == '') {
             return $this->showMsg('修改密码不可以为空', false);
         }
         if ($aUser['sEditPassword'] != md5($pwd)) {
             return $this->showMsg('修改密码不正确', false);
         }
         $aDomain = $this->_checkData('update');
         if (empty($aDomain)) {
             return null;
         }
         $aDomain['iAutoID'] = intval($this->getParam('iAutoID'));
         $aOldDomain = Model_Domain::getDetail($aDomain['iAutoID']);
         if (empty($aOldDomain)) {
             return $this->showMsg('基础配置不存在!', false);
         }
         if ($aOldDomain['sName'] != $aDomain['sName']) {
             if (Model_Domain::getRow(array('where' => array('sName' => $aDomain['sName'], 'iType' => $aDomain['iType'], 'iStatus' => 1)))) {
                 return $this->showMsg('基础配置已经存在!', false);
             }
         }
         if (1 == Model_Domain::updData($aDomain)) {
             return $this->showMsg('基础配置信息更新成功!', true);
         } else {
             return $this->showMsg('基础配置信息更新失败!', false);
         }
     } else {
         $iAutoID = intval($this->getParam('id'));
         $aDomain = Model_Domain::getDetail($iAutoID);
         $this->assign('aDomain', $aDomain);
     }
     $this->assign('iType', Model_Domain::$iType);
 }
Exemplo n.º 17
0
Arquivo: Menu.php Projeto: pancke/yyaf
 /**
  * 编辑菜单
  */
 public function editAction()
 {
     if ($this->isPost()) {
         //修改密码验证
         $aCookie = Util_Cookie::get(Yaf_G::getConf('authkey', 'cookie'));
         $iAdminID = $aCookie['iAdminID'];
         $aUser = Model_Admin::getDetail($iAdminID);
         $pwd = $this->getParam('pwd');
         if (!isset($pwd) || $pwd == '') {
             return $this->showMsg('修改密码不可以为空', false);
         }
         if ($aUser['sEditPassword'] != md5($pwd)) {
             return $this->showMsg('修改密码不正确', false);
         }
         $aMenu = $this->_checkData('update');
         if (empty($aMenu)) {
             return null;
         }
         $aMenu['iMenuID'] = intval($this->getParam('iMenuID'));
         $aOldMenu = Model_Menu::getDetail($aMenu['iMenuID']);
         if (empty($aOldMenu)) {
             return $this->showMsg('菜单不存在!', false);
         }
         //更新排序,加在最后面
         if ($aOldMenu['iParentID'] != $aMenu['iParentID']) {
             $aMenu['iOrder'] = Model_Menu::getNextOrder($aMenu['iParentID']);
         }
         if (1 == Model_Menu::updData($aMenu)) {
             return $this->showMsg('菜单信息更新成功!', true);
         } else {
             return $this->showMsg('菜单信息更新失败!', false);
         }
     } else {
         $iMenuID = intval($this->getParam('id'));
         $aMenu = Model_Menu::getDetail($iMenuID);
         $aTree = Model_Menu::getMenus();
         $this->assign('aTree', $aTree);
         $this->assign('aMenu', $aMenu);
     }
 }
Exemplo n.º 18
0
 /**
  * 敏感词修改
  */
 public function editAction()
 {
     if ($this->_request->isPost()) {
         //修改密码验证
         $aCookie = Util_Cookie::get(Yaf_G::getConf('authkey', 'cookie'));
         $iAdminID = $aCookie['iAdminID'];
         $aUser = Model_Admin::getDetail($iAdminID);
         $pwd = $this->getParam('pwd');
         if (!isset($pwd) || $pwd == '') {
             return $this->showMsg('修改密码不可以为空', false);
         }
         if ($aUser['sEditPassword'] != md5($pwd)) {
             return $this->showMsg('修改密码不正确', false);
         }
         $aBadword = $this->_checkData('update');
         if (empty($aBadword)) {
             return null;
         }
         $aBadword['iAutoID'] = intval($this->getParam('iAutoID'));
         $aOldBadword = Model_Badword::getDetail($aBadword['iAutoID']);
         if (empty($aOldBadword)) {
             return $this->showMsg('敏感词不存在!', false);
         }
         if ($aOldBadword['sWord'] != $aBadword['sWord']) {
             if (Model_Badword::getBadwordByWord($aBadword['sWord'])) {
                 return $this->showMsg('敏感词已经存在!', false);
             }
         }
         if (1 == Model_Badword::updData($aBadword)) {
             return $this->showMsg('敏感词信息更新成功!', true);
         } else {
             return $this->showMsg('敏感词信息更新失败!', false);
         }
     } else {
         $iBadwordID = intval($this->getParam('id'));
         $aBadword = Model_Badword::getDetail($iBadwordID);
         $this->assign('aBadword', $aBadword);
     }
 }
Exemplo n.º 19
0
 public function __construct($method = null, $module = null, $controller = null, $action = null, $params = array())
 {
     if (!is_array($params)) {
         throw new Yaf_Exception_TypeError('Expects the params is an array');
     }
     if ($method == null) {
         if (isset($_SERVER['REQUEST_METHOD'])) {
             $method = $_SERVER['REQUEST_METHOD'];
         } else {
             $sapiType = php_sapi_name();
             if (strtolower($sapiType) == 'cli' || substr($sapiType, 0, 3) == 'cgi') {
                 $method = 'CLI';
             } else {
                 $method = 'unknown';
             }
         }
     }
     $this->method = $method;
     if ($module != null || $action != null || $controller != null) {
         $this->setActionName($action);
         $this->setControllerName($controller);
         $this->setModuleName($module);
         $this->setRouted(true);
     } else {
         if ($module == null) {
             $this->setModuleName(Yaf_G::get('default_module'));
         }
         if ($controller == null) {
             $this->setControllerName(Yaf_G::get('default_controller'));
         }
         if ($action == null) {
             $this->setActionName(Yaf_G::get('default_action'));
         }
     }
     if ($params) {
         $this->setParam($params);
     }
 }
Exemplo n.º 20
0
 public function __construct()
 {
     $app = self::app();
     if (!is_null($app)) {
         throw new Yaf_Exception('Only one application can be initialized');
     }
     Yaf_G::init();
     // request initialization
     if (isset($_SERVER['REQUEST_METHOD'])) {
         $request = new Yaf_Request_Http();
     } else {
         $request = new Yaf_Request_Cli();
     }
     if ($request == null) {
         throw new Yaf_Exception('Initialization of request failed');
     }
     // dispatcher
     $this->_dispatcher = Yaf_Dispatcher::getInstance();
     if ($this->_dispatcher == null || !$this->_dispatcher instanceof Yaf_Dispatcher) {
         throw new Yaf_Exception('Instantiation of dispatcher failed');
     }
     $this->_dispatcher->setRequest($request);
     self::$_app = $this;
 }
Exemplo n.º 21
0
 /**
  * 构造函数
  */
 private function __construct()
 {
     $this->_aConfig = Yaf_G::getConf(null, 'logger');
     $sBaseDir = $this->_aConfig['sBaseDir'];
     unset($this->_aConfig['sBaseDir']);
     $iTime = time();
     foreach ($this->_aConfig as $sKey => $mConfig) {
         //  设置日志级别
         if (isset($this->_aConfig[$sKey]['sLevelName'])) {
             $this->_aConfig[$sKey]['iLevel'] = $this->getLogLevelByName($this->_aConfig[$sKey]['sLevelName']);
         }
         $sDir = isset($this->_aConfig[$sKey]['sDir']) ? $this->_aConfig[$sKey]['sDir'] : $sKey;
         switch ($mConfig['sSplitType']) {
             case 'day':
                 $this->_aConfig[$sKey]['sFilename'] = $sBaseDir . DIRECTORY_SEPARATOR . $sDir . DIRECTORY_SEPARATOR . date('Ymd', $iTime) . '.log';
                 break;
             case 'week':
                 $this->_aConfig[$sKey]['sFilename'] = $sBaseDir . DIRECTORY_SEPARATOR . $sDir . DIRECTORY_SEPARATOR . date('YW', $iTime) . '.log';
                 break;
             case 'month':
                 $this->_aConfig[$sKey]['sFilename'] = $sBaseDir . DIRECTORY_SEPARATOR . $sDir . DIRECTORY_SEPARATOR . date('Ym', $iTime) . '.log';
                 break;
             case 'persistent':
                 $this->_aConfig[$sKey]['sFilename'] = $sBaseDir . DIRECTORY_SEPARATOR . $sDir . DIRECTORY_SEPARATOR . $this->_aConfig[$sKey]['sFile'];
                 break;
         }
         $sPath = dirname($this->_aConfig[$sKey]['sFilename']);
         if (!is_dir($sPath)) {
             umask(00);
             if (false === mkdir($sPath, 0755, true)) {
                 throw new Exception(__CLASS__ . ': can not create path(' . $sPath . ').');
                 return false;
             }
         }
     }
 }
Exemplo n.º 22
0
 /**
  * 请求数据检测
  *
  * @return mixed
  */
 public function _checkData($sType = 'add')
 {
     $iType = $this->getParam('iType');
     $sEmail = $this->getParam('sEmail');
     $sMobile = $this->getParam('sMobile');
     $sRealName = $this->getParam('sRealName');
     $sPassword = $this->getParam('sPassword');
     $sCoName = $this->getParam('sCoName');
     $iCoIndustry = $this->getParam('iCoIndustry');
     $sCoAddress = $this->getParam('sCoAddress');
     $sCoWebSite = $this->getParam('sCoWebSite');
     $sCoDesc = $this->getParam('sCoDesc');
     $sWeixin = $this->getParam('sWeixin');
     $sQQ = $this->getParam('sQQ');
     $iIncome = $this->getParam('iIncome');
     $iMoney = $this->getParam('iMoney');
     $iStatus = $this->getParam('iStatus');
     $iRate = $this->getParam('iRate');
     $iUpdateTime = time();
     if (!Util_Validate::isEmail($sEmail)) {
         return $this->showMsg('输入的邮箱地址不合法!', false);
     }
     if (($sType == 'add' || !empty($sPassword)) && !Util_Validate::isLength($sPassword, 6, 20)) {
         return $this->showMsg('登录密码长度范围为6到20字符!', false);
     }
     if (!Util_Validate::isMobile($sMobile)) {
         return $this->showMsg('输入的手机号码不合法!', false);
     }
     if (!Util_Validate::isLength($sRealName, 2, 20)) {
         return $this->showMsg('真实姓名长度范围为2到20字符!', false);
     }
     $aDomain = Model_Domain::getPairDomain(Model_Domain::TYPE_CO_INDUSTRY);
     if (!isset($aDomain[$iCoIndustry])) {
         return $this->showMsg('选择的行业不存在!', false);
     }
     $aRow = array('iType' => $iType, 'sEmail' => $sEmail, 'sMobile' => $sMobile, 'sRealName' => $sRealName, 'sCoName' => $sCoName, 'iCoIndustry' => $iCoIndustry, 'sCoAddress' => $sCoAddress, 'sCoWebSite' => $sCoWebSite, 'sCoDesc' => $sCoDesc, 'sWeixin' => $sWeixin, 'sQQ' => $sQQ, 'iIncome' => $iIncome, 'iMoney' => $iMoney, 'iStatus' => $iStatus, 'iUpdateTime' => $iUpdateTime, 'iRate' => $iRate);
     if (!empty($sPassword)) {
         $aRow['sPassword'] = md5(Yaf_G::getConf('cryptkey', 'cookie') . $sPassword);
     }
     return $aRow;
 }
Exemplo n.º 23
0
 /**
  * 财务修改
  */
 public function editAction()
 {
     if ($this->_request->isPost()) {
         //修改密码验证
         $aCookie = Util_Cookie::get(Yaf_G::getConf('authkey', 'cookie'));
         $iAdminID = $aCookie['iAdminID'];
         $aUser = Model_Admin::getDetail($iAdminID);
         $pwd = $this->getParam('pwd');
         if (!isset($pwd) || $pwd == '') {
             return $this->showMsg('修改密码不可以为空', false);
         }
         if ($aUser['sEditPassword'] != md5($pwd)) {
             return $this->showMsg('修改密码不正确', false);
         }
         $aFinance = $this->_checkData('update');
         if (empty($aFinance)) {
             return null;
         }
         $aFinance['iAutoID'] = intval($this->getParam('iAutoID'));
         $aOldFinance = Model_Finance::getDetail($aFinance['iAutoID']);
         if (empty($aOldFinance)) {
             return $this->showMsg('财务不存在!', false);
         }
         if (1 == Model_Finance::updData($aFinance)) {
             if ($aOldFinance['iPayStatus'] == 0 && $aFinance['iPayStatus'] == 1) {
                 // 邮件通知
                 $sTitle = Model_Kv::getValue('finance_forget_email_title');
                 $sContent = Model_Kv::getValue('finance_forget_email_content');
                 $aUser = Model_Finance::getDetail($aFinance['iAutoID']);
                 $time = date('Y-m-d H:i:s', $aUser['iUpdateTime']);
                 $email = Model_User::getDetail($aUser['iUserID']);
                 // 短信通知
                 //					$iTempID = Util_Common::getConf(1, 'aSmsTempID');
                 Util_Mail::send($email['sEmail'], $sTitle, $sContent, array($email['sEmail'], $time, $aUser['iPayMoney']));
                 //					Util_Sms::sendTemplateSms($email['sMobile'], array(
                 //						$aUser['sMediaName']
                 //					), $iTempID);
             }
             return $this->showMsg('财务更新成功!', true);
         } else {
             return $this->showMsg('财务更新失败!', false);
         }
     } else {
         $iFinanceID = intval($this->getParam('id'));
         $aFinance = Model_Finance::getDetail($iFinanceID);
         $aUser = Model_User::getDetail($aFinance['iUserID']);
         $this->assign('aUser', $aUser);
         $this->assign('aFinance', $aFinance);
     }
 }
Exemplo n.º 24
0
 /**
  * Parse application options
  *
  * @param  array $options
  * @throws Yaf_Exception When no bootstrap path is provided
  * @throws Yaf_Exception When invalid bootstrap information are provided
  * @return Yaf_Application
  */
 protected function parseOptions(array $options)
 {
     if (!is_array($options)) {
         throw new Yaf_Exception_TypeError('Expected an array of application configure');
     }
     $options = array_change_key_case($options, CASE_LOWER);
     if (!isset($options['application'])) {
         throw new Yaf_Exception_TypeError('Expected an array of application configure');
     }
     $options = $options['application'];
     if (!empty($options['directory'])) {
         Yaf_G::set('directory', preg_replace("/" . preg_quote(DIRECTORY_SEPARATOR, "/") . "\$/", "", $options['directory']));
     } else {
         throw new Yaf_Exception_StartupError('Expected a directory entry in application configures');
     }
     if (!empty($options['ext'])) {
         Yaf_G::set('ext', $options['ext']);
     }
     if (!empty($options['bootstrap']) && is_string($options['bootstrap'])) {
         $this->_options['bootstrap'] = $options['bootstrap'];
     }
     if (!empty($options['library'])) {
         if (is_string($options['library'])) {
             $this->_options['local_library'] = $options['library'];
         } elseif (is_array($options['library'])) {
             if (!empty($options['library']['directory']) && is_string($options['library']['directory'])) {
                 $this->_options['local_library'] = $options['library']['directory'];
             }
             if (!empty($options['library']['namespace']) && is_string($options['library']['namespace'])) {
                 $this->_options['local_namespace'] = $options['library']['namespace'];
             }
         }
     } else {
         $this->_options['local_library'] = Yaf_G::get('directory') . DIRECTORY_SEPARATOR . Yaf_Loader::YAF_LIBRARY_DIRECTORY_NAME;
     }
     if (!empty($options['view']) && is_array($options['view']) && !empty($options['view']['ext']) && is_string($options['view']['ext'])) {
         Yaf_G::set('view_ext', $options['view']['ext']);
     }
     if (!empty($options['baseUri']) && is_string($options['baseUri'])) {
         $this->_options['baseUri'] = $options['baseUri'];
     } else {
         $this->_options['baseUri'] = $_SERVER['PHP_SELF'];
     }
     if (!empty($options['dispatcher']) && is_array($options['dispatcher'])) {
         if (!empty($options['dispatcher']['defaultModule']) && is_string($options['dispatcher']['defaultModule'])) {
             Yaf_G::set('default_module', $options['dispatcher']['defaultModule']);
         } else {
             Yaf_G::set('default_module', Yaf_Router::YAF_ROUTER_DEFAULT_MODULE);
         }
         if (!empty($options['dispatcher']['defaultController']) && is_string($options['dispatcher']['defaultController'])) {
             Yaf_G::set('default_controller', $options['dispatcher']['defaultController']);
         } else {
             Yaf_G::set('default_controller', Yaf_Router::YAF_ROUTER_DEFAULT_CONTROLLER);
         }
         if (!empty($options['dispatcher']['defaultAction']) && is_string($options['dispatcher']['defaultAction'])) {
             Yaf_G::set('default_action', $options['dispatcher']['defaultAction']);
         } else {
             Yaf_G::set('default_action', Yaf_Router::YAF_ROUTER_DEFAULT_ACTION);
         }
         if (isset($options['dispatcher']['throwException'])) {
             Yaf_G::set('throwException', (bool) $options['dispatcher']['throwException']);
         }
         if (isset($options['dispatcher']['catchException'])) {
             Yaf_G::set('catchException', (bool) $options['dispatcher']['catchException']);
         }
         if (isset($options['dispatcher']['defaultRoute']) && is_array($options['dispatcher']['defaultRoute'])) {
             Yaf_G::set('default_route', $options['dispatcher']['defaultRoute']);
         }
     } else {
         Yaf_G::set('default_module', Yaf_Router::YAF_ROUTER_DEFAULT_MODULE);
         Yaf_G::set('default_controller', Yaf_Router::YAF_ROUTER_DEFAULT_CONTROLLER);
         Yaf_G::set('default_action', Yaf_Router::YAF_ROUTER_DEFAULT_ACTION);
         $this->_options['throwException'] = true;
         $this->_options['catchException'] = true;
     }
     if (!empty($options['modules']) && is_string($options['modules'])) {
         $modules = preg_split("/,/", $options['modules']);
         foreach ($modules as $module) {
             $this->_modules[] = trim($module);
         }
     }
     if (empty($this->_modules)) {
         $this->_modules[] = Yaf_G::get('default_module');
     }
     return true;
 }
Exemplo n.º 25
0
 /**
  * 检查是否为图片
  *
  * @param
  *            $p_sExtension
  */
 protected function isImage($p_sExtension)
 {
     $aImageType = Yaf_G::getConf('aImageType', 'file', 'file');
     $bImage = in_array($p_sExtension, $aImageType) ? true : false;
     return $bImage;
 }
Exemplo n.º 26
0
 /**
  * Get a route from an array
  *
  * @param  array $info
  * @return Yaf_Route_Interface
  */
 protected function _getRouteFromArray(array $info)
 {
     $useNamespace = Yaf_G::iniGet('yaf.use_namespace');
     if ($useNamespace) {
         $class = isset($info['type']) ? '\\Yaf\\Route\\' . ucfirst($info['type']) : '\\Yaf\\Route\\Static';
     } else {
         $class = isset($info['type']) ? 'Yaf_Route_' . ucfirst($info['type']) : 'Yaf_Route_Static';
     }
     try {
         $route = call_user_func(array($class, 'getInstance'), $info);
     } catch (Exception $e) {
         return null;
     }
     return $route;
 }
Exemplo n.º 27
0
 private function resolveClass($class)
 {
     // Autodiscover the path from the class name
     // Implementation is PHP namespace-aware, and based on
     // Framework Interop Group reference implementation:
     // http://groups.google.com/group/php-standards/web/psr-0-final-proposal
     $className = ltrim($class, '\\');
     $file = '';
     $namespace = '';
     if (($lastNsPos = strripos($className, '\\')) !== false) {
         $namespace = substr($className, 0, $lastNsPos);
         $className = substr($className, $lastNsPos + 1);
         $file = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
     }
     if (Yaf_G::iniGet('yaf.lowcase_path') == true) {
         $file = strtolower($file);
         $segments = explode('_', $className);
         foreach ($segments as $key => &$value) {
             if ($key != count($segments) - 1) {
                 $value = strtolower($value);
             }
         }
         $file .= implode(DIRECTORY_SEPARATOR, $segments) . '.' . Yaf_G::get('ext');
     } else {
         $file .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.' . Yaf_G::get('ext');
     }
     return $file;
 }
Exemplo n.º 28
0
 public function logoutAction()
 {
     Util_Cookie::delete(Yaf_G::getConf('authkey', 'cookie'));
     $this->redirect('/login');
 }
Exemplo n.º 29
0
 public static function getDefaultImg($type = 1)
 {
     $staticUrl = Yaf_G::getConf('static', 'domain');
     $imgUrl = null;
     switch ($type) {
         case 1:
             $imgUrl = 'http://' . $staticUrl . '/img/blistd.png';
             break;
         case 2:
             $imgUrl = 'http://' . $staticUrl . '/touchweb/Evaluation/image/nopic.png';
             break;
         case 3:
             $imgUrl = 'http://' . $staticUrl . '/img/bd.png';
             break;
         case 4:
             $imgUrl = 'http://' . $staticUrl . '/img/default.png';
             break;
         default:
             break;
     }
     return $imgUrl;
 }
Exemplo n.º 30
0
 private static function curl($sDomain, $sRoute, $aParam, $method, $iCacheTime)
 {
     if ($iCacheTime > 0) {
         $sCacheKey = md5($sDomain . $sRoute . serialize($aParam) . $method);
         $aRet = Util_Common::getCache()->get($sCacheKey);
         if (!empty($aRet)) {
             return $aRet;
         }
     }
     $time1 = microtime(true);
     $aParam['_time'] = time();
     $aParam['_sign'] = md5($aParam['_time'] . Yaf_G::getConf('signkey', 'sdk'));
     $sHost = Yaf_G::getConf($sDomain, 'sdkdomain');
     if (!$sHost) {
         throw new Exception('配置[sdkdomain][' . $sDomain . ']未找到!');
         return false;
     }
     $sRoute = trim($sRoute, '/?& ');
     $sUrl = 'http://' . $sHost . '/' . $sRoute;
     if (!self::$_hCurl) {
         self::$_hCurl = curl_init();
     }
     curl_setopt(self::$_hCurl, CURLOPT_DNS_USE_GLOBAL_CACHE, true);
     curl_setopt(self::$_hCurl, CURLOPT_HEADER, false);
     curl_setopt(self::$_hCurl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt(self::$_hCurl, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt(self::$_hCurl, CURLOPT_CONNECTTIMEOUT, 30);
     curl_setopt(self::$_hCurl, CURLOPT_TIMEOUT, 30);
     if ($method == 'post') {
         curl_setopt(self::$_hCurl, CURLOPT_POST, 1);
         curl_setopt(self::$_hCurl, CURLOPT_POSTFIELDS, http_build_query($aParam));
     } else {
         $sUrl .= strpos($sUrl, '?') === false ? '?' : '&';
         $sUrl .= http_build_query($aParam);
         $aParam = null;
     }
     $aCookie = array();
     if (Yaf_G::getEnv() == 'beta') {
         $aCookie[] = 'fjdp_version=beta';
     }
     if (Yaf_G::isDebug()) {
         $aCookie[] = 'debug=2k9j38h#4';
     }
     if (!empty($aCookie)) {
         curl_setopt(self::$_hCurl, CURLOPT_COOKIE, join('; ', $aCookie));
     }
     curl_setopt(self::$_hCurl, CURLOPT_URL, $sUrl);
     $sData = curl_exec(self::$_hCurl);
     $aRet = array('status' => false, 'data' => '数据请求失败,返回为空!');
     if (!empty($sData)) {
         $aData = json_decode($sData, true);
         if (isset($aData['code'])) {
             //兼容mapi没有status
             if ($aData['code'] === 0) {
                 $aData['status'] = true;
             } else {
                 $aData['status'] = false;
                 //unset($aData['msg']);
             }
             if (isset($aData['data'])) {
                 $aData['data']['msg'] = $aData['msg'];
             } else {
                 $aData['data'] = array('msg' => $aData['msg']);
             }
             unset($aData['msg']);
             unset($aData['code']);
         }
         if (isset($aData['status']) && isset($aData['data'])) {
             $aRet = $aData;
         } else {
             $aRet = array('status' => false, 'data' => '数据请求错误:' . $sData);
         }
     }
     $oDebug = Util_Common::getDebug();
     if ($oDebug) {
         $time2 = microtime(true);
         $use_time = round(($time2 - $time1) * 1000, 2);
         self::$_iOptCnt++;
         self::$_iUseTime += $use_time;
         $oDebug->groupCollapsed('Api: ' . $sUrl . ' ' . $use_time . '毫秒');
         if (!empty($aParam)) {
             $oDebug->debug($aParam);
         }
         $oDebug->debug($aRet['data']);
         if (isset($aRet['debug'])) {
             foreach ($aRet['debug'] as $v) {
                 if (is_array($v)) {
                     $oDebug->add($v[0], $v[1]);
                 } else {
                     $oDebug->groupCollapsed($v);
                 }
             }
             $oDebug->groupEnd();
             unset($aRet['debug']);
         }
         $oDebug->groupEnd();
     }
     if ($iCacheTime > 0 && $aRet['status']) {
         Util_Common::getCache()->set($sCacheKey, $aRet, $iCacheTime);
     }
     return $aRet;
 }