コード例 #1
0
ファイル: item.php プロジェクト: firaga/operation
 public function post($update, $after = null, $post_style = 'default')
 {
     $file = Ko_Web_Request::AFile('file');
     $api = new KStorage_Api();
     if (!$api->bUpload2Storage($file, $image)) {
         throw new Exception('文件上传失败', 1);
     }
     $title = $file['name'];
     $loginApi = new KUser_loginApi();
     $uid = $loginApi->iGetLoginUid();
     $photoApi = new KPhoto_Api();
     switch ($post_style) {
         case 'album':
             $albumid = $update;
             break;
         default:
             $albumid = 0;
             break;
     }
     $photoid = $photoApi->addPhoto($albumid, $uid, $image, $title);
     $this->_sendSysmsg($uid, $albumid, $photoid);
     $data = array('key' => compact('uid', 'photoid'));
     if (is_array($after)) {
         switch ($after['style']) {
             default:
                 $data['after'] = $photoApi->getPhotoInfo($uid, $photoid);
                 $data['after']['image'] = $api->sGetUrl($image, $after['decorate']);
                 break;
         }
     }
     return $data;
 }
コード例 #2
0
ファイル: OAuthBase.php プロジェクト: AllenLyu/ko
 /**
  * 临时授权 / 用户授权 / token 接口 / 回调接口
  *
  * @return array
  */
 public function aGetPara()
 {
     if ('GET' === Ko_Web_Request::SRequestMethod()) {
         return $this->_aReq = Ko_Web_Request::AGet(false, 'UTF-8');
     }
     return $this->_aReq = Ko_Web_Request::APost(false, 'UTF-8');
 }
コード例 #3
0
ファイル: loginrefApi.php プロジェクト: firaga/operation
 public static function SGet()
 {
     $ref = Ko_Web_Request::SCookie(self::COOKIE_NAME);
     if ('' == $ref) {
         return 'http://' . MAIN_DOMAIN;
     }
     return $ref;
 }
コード例 #4
0
ファイル: Module.php プロジェクト: AllenLyu/ko
 /**
  * 获取脚本程序名称全路经
  *
  * @return string
  */
 public static function SGetScriptFullName()
 {
     $sScript = Ko_Web_Request::SScriptFilename();
     if ('/' != $sScript[0] && ':/' != substr($sScript, 1, 2)) {
         $sPath = realpath(dirname($sScript));
         $sScript = $sPath . '/' . $sScript;
     }
     return $sScript;
 }
コード例 #5
0
ファイル: Utils.php プロジェクト: AllenLyu/ko
 /**
  * 根据 uri 重新设置一些相关的环境变量
  */
 public static function VResetEnv($sUri)
 {
     list($sn, $qs, $pi) = self::AParseUri($sUri);
     parse_str($qs, $arr);
     $GLOBALS['_GET'] = $_GET = $arr;
     $GLOBALS['_REQUEST'] = $_REQUEST = $_REQUEST + $arr;
     $GLOBALS['_SERVER']['QUERY_STRING'] = $_SERVER['QUERY_STRING'] = $GLOBALS['_ENV']['QUERY_STRING'] = $_ENV['QUERY_STRING'] = $qs;
     $GLOBALS['_SERVER']['PHP_SELF'] = $_SERVER['PHP_SELF'] = $GLOBALS['_SERVER']['SCRIPT_NAME'] = $_SERVER['SCRIPT_NAME'] = $GLOBALS['_ENV']['PHP_SELF'] = $_ENV['PHP_SELF'] = $GLOBALS['_ENV']['SCRIPT_NAME'] = $_ENV['SCRIPT_NAME'] = $sn;
     $GLOBALS['_SERVER']['SCRIPT_FILENAME'] = $_SERVER['SCRIPT_FILENAME'] = $GLOBALS['_ENV']['SCRIPT_FILENAME'] = $_ENV['SCRIPT_FILENAME'] = Ko_Web_Request::SDocumentRoot() . $sn;
     $GLOBALS['_SERVER']['PATH_INFO'] = $_SERVER['PATH_INFO'] = $GLOBALS['_ENV']['PATH_INFO'] = $_ENV['PATH_INFO'] = $pi;
 }
コード例 #6
0
ファイル: item.php プロジェクト: firaga/operation
 public function post($update, $after = null)
 {
     $file = Ko_Web_Request::AFile('file');
     $api = new KStorage_Api();
     if (!$api->bUpload2Storage($file, $sDest)) {
         throw new Exception('文件上传失败', 1);
     }
     $data = array('key' => $sDest);
     if (is_array($after)) {
         switch ($after['style']) {
             default:
                 $data['after'] = $api->sGetUrl($sDest, $after['decorate']);
                 break;
         }
     }
     return $data;
 }
コード例 #7
0
ファイル: Config.php プロジェクト: firaga/operation
 /**
  * @return self
  */
 private static function _OGetConfig($host)
 {
     if (is_null($host)) {
         $host = Ko_Web_Request::SHttpHost();
     }
     if (!isset(self::$s_aHostConfig[$host])) {
         self::$s_aHostConfig[$host] = new self();
         if (isset(self::$s_aConfig['global'][$host])) {
             $appname = self::$s_aConfig['global'][$host];
             self::$s_aHostConfig[$host]->_sAppName = $appname;
             if (isset(self::$s_aConfig['app_' . $appname])) {
                 self::$s_aHostConfig[$host]->_sDocumentRoot = strval(self::$s_aConfig['app_' . $appname]['documentroot']);
                 self::$s_aHostConfig[$host]->_sRewriteConf = strval(self::$s_aConfig['app_' . $appname]['rewriteconf']);
                 self::$s_aHostConfig[$host]->_sRewriteCache = strval(self::$s_aConfig['app_' . $appname]['rewritecache']);
             }
         }
     }
     return self::$s_aHostConfig[$host];
 }
コード例 #8
0
ファイル: Safe.php プロジェクト: AllenLyu/ko
 /**
  * 通过设置 POST 时允许的 ref 域名来保证基本的安全
  *
  * @param array $aPostAllowRefDomain 只允许ref为同样的域名 array(),
  *                                   允许ref为任意域名 array('*'),
  *                                   允许ref为指定某些域名 array('*.test.com', 'www.demo.com'),
  *                                   ref为空被视为可以访问不进行这些检查
  */
 public static function BCheckMethod($aPostAllowRefDomain = array())
 {
     if ('POST' === Ko_Web_Request::SRequestMethod()) {
         $referer = Ko_Web_Request::SHttpReferer();
         if (strlen($referer)) {
             $refinfo = parse_url(strtolower($referer));
             if (empty($aPostAllowRefDomain)) {
                 list($host, $port) = explode(':', Ko_Web_Request::SHttpHost(), 2);
                 if ($refinfo['host'] !== $host) {
                     return false;
                 }
             } else {
                 if (!self::_BCheckDomains($refinfo['host'], $aPostAllowRefDomain)) {
                     return false;
                 }
             }
         }
     }
     return true;
 }
コード例 #9
0
ファイル: loginApi.php プロジェクト: firaga/operation
 public function iGetLoginUid(&$exinfo = '')
 {
     static $s_iUid;
     if (is_null($s_iUid)) {
         $token = Ko_Web_Request::SCookie(self::SESSION_TOKEN_NAME);
         $s_iUid = $token ? $this->iCheckSessionToken($token, $exinfo, $iErrno) : 0;
         if (!$s_iUid) {
             $token = Ko_Web_Request::SCookie(self::PERSISTENT_TOKEN_NAME);
             $s_iUid = $token ? $this->iCheckPersistentToken($token, $newtoken, $iErrno) : 0;
             if ($s_iUid) {
                 Ko_Web_Response::VSetCookie(self::PERSISTENT_TOKEN_NAME, $newtoken, time() + 2592000, '/', '.' . MAIN_DOMAIN);
             }
         }
         if ($s_iUid) {
             $token = $s_iUid ? $this->sGetSessionToken($s_iUid, $exinfo) : '';
             Ko_Web_Response::VSetCookie(self::SESSION_TOKEN_NAME, $token, 0, '/', '.' . MAIN_DOMAIN);
         }
     }
     return $s_iUid;
 }
コード例 #10
0
ファイル: Api.php プロジェクト: firaga/operation
 public function run()
 {
     $uri = Ko_Web_Request::SGet('uri');
     $req_method = Ko_Web_Request::SRequestMethod(true);
     if ('POST' === $req_method) {
         $method = Ko_Web_Request::SPost('method');
         if ('PUT' === $method || 'DELETE' === $method) {
             $req_method = $method;
         }
     }
     $input = 'GET' === $req_method ? $_GET : $_POST;
     unset($input['uri']);
     unset($input['method']);
     if (isset($input['jsondata'])) {
         $input = json_decode($input['jsondata'], true);
     }
     $rest = new KRest_Api();
     $data = $rest->aCall($req_method, $uri, $input);
     $render = new KRender_json();
     $render->oSetData($data)->oSend();
 }
コード例 #11
0
ファイル: Rest.php プロジェクト: AllenLyu/ko
 public function run($ns = '')
 {
     $uri = Ko_Web_Request::SGet('uri');
     $req_method = Ko_Web_Request::SRequestMethod(true);
     if ('POST' === $req_method) {
         $method = Ko_Web_Request::SPost('method');
         if ('PUT' === $method || 'DELETE' === $method) {
             $req_method = $method;
         }
     }
     $input = 'GET' === $req_method ? $_GET : $_POST;
     unset($input['uri']);
     unset($input['method']);
     if (isset($input['jsondata'])) {
         $input = json_decode($input['jsondata'], true);
     }
     $uri = substr($ns, strlen(KO_APPS_NS) + 1) . '/' . $uri;
     $rest = new self();
     $data = $rest->aCall($req_method, $uri, $input);
     $render = new Ko_View_Render_JSON();
     $render->oSetData($data)->oSend();
 }
コード例 #12
0
ファイル: Config.php プロジェクト: AllenLyu/ko
 /**
  * @return self
  */
 private static function _OGetConfig($host, &$uri)
 {
     if (is_null($host)) {
         $host = Ko_Web_Request::SHttpHost();
     }
     if (is_null($uri)) {
         $uri = Ko_Web_Request::SRequestUri();
     }
     if (false === strpos($uri, '?')) {
         $path = $uri;
         $query = '';
     } else {
         list($path, $query) = explode('?', $uri, 2);
         $query = '?' . $query;
     }
     $key = $host . $path;
     if (!isset(self::$s_aConfigCache[$key])) {
         $path = rtrim($key, '/');
         $succ = false;
         while (false !== ($pos = strrpos($path, '/'))) {
             if ($succ = self::_BLoadConfig($key, $path, false)) {
                 break;
             }
             $path = rtrim(substr($path, 0, $pos), '/');
         }
         if (!$succ) {
             self::_BLoadConfig($key, $path, true);
         }
         $rewriteuri = substr($key, strlen($path));
         if (0 === strlen($rewriteuri)) {
             $rewriteuri = '/';
         }
         self::$s_aConfigCache[$key]->_sRewriteUri = $rewriteuri . $query;
     }
     $uri = self::$s_aConfigCache[$key]->_sRewriteUri;
     return self::$s_aConfigCache[$key];
 }
コード例 #13
0
ファイル: OAuth2Server.php プロジェクト: firaga/operation
 private function _bCheckClient($fnCheckClient_Callback)
 {
     //http://tools.ietf.org/html/rfc6749#section-2.3.1
     $client_id = urldecode(Ko_Web_Request::SPhpAuthUser());
     $client_secret = urldecode(Ko_Web_Request::SPhpAuthPw());
     if (0 === strlen($client_id) || 0 === strlen($client_secret)) {
         $client_id = $this->_aReq['client_id'];
         $client_secret = $this->_aReq['client_secret'];
     }
     if (0 === strlen($client_id) || 0 === strlen($client_secret)) {
         return false;
     }
     $info = $this->aGetClientInfo($client_id);
     if (empty($info)) {
         return false;
     }
     if (call_user_func_array($fnCheckClient_Callback, array($client_id, $client_secret))) {
         $this->_sClientId = $client_id;
         return true;
     }
     return false;
 }
コード例 #14
0
ファイル: Route.php プロジェクト: AllenLyu/ko
 public static function IDispatch(&$phpFilename)
 {
     $scriptFilename = Ko_Web_Request::SScriptFilename();
     $requestMethod = Ko_Web_Request::SRequestMethod(true);
     return self::_IDispatch($scriptFilename, $requestMethod, $phpFilename);
 }
コード例 #15
0
ファイル: XList.php プロジェクト: nuaazdh/ko
 public function vMain($aReq, $vAdmin = '')
 {
     if ($this->_bPageIsGb() != $this->_bIsGb()) {
         if ($this->_bIsGb()) {
             Ko_Tool_Str::VConvert2GB18030($aReq);
         } else {
             Ko_Tool_Str::VConvert2UTF8($aReq);
         }
     }
     if (!isset($aReq['sXSAction'])) {
         $aReq['sXSAction'] = '';
     }
     if (!isset($aReq['sXSOrder'])) {
         $aReq['sXSOrder'] = '';
     }
     if (!isset($aReq['iXSOrder'])) {
         $aReq['iXSOrder'] = 0;
     }
     if (!isset($aReq['iXSPage'])) {
         $aReq['iXSPage'] = 1;
     }
     $this->_vAdmin = $vAdmin;
     if (is_null($this->_oUI)) {
         $this->vAttachUI(new Ko_Mode_XIUI());
     }
     if (!$this->_bIsSingleDB()) {
         $cginame = $this->_sGetFieldCginame($this->_sGetSplitField_Item());
         if (isset($aReq[$cginame])) {
             $this->_sSplitValue = $aReq[$cginame];
         }
     }
     if ('POST' === Ko_Web_Request::SRequestMethod()) {
         $this->_vMain_Post($aReq);
     } else {
         $this->_vMain_Get($aReq);
     }
 }
コード例 #16
0
ファイル: blog.php プロジェクト: firaga/operation
            exit;
        }
        $htmlrender->oSetData(KContent_Api::BLOG_TITLE, $blogid);
        $htmlrender->oSetData(KContent_Api::BLOG_CONTENT, $blogid);
    } else {
        $bloginfo = array();
        $htmlrender->oSetData(KContent_Api::DRAFT_CONTENT, $uid);
        $htmlrender->oSetData(KContent_Api::DRAFT_TITLE, $uid);
    }
    $render = new KRender_www();
    $render->oSetTemplate('www/blog/post.html')->oSetData('userinfo', $userinfo)->oSetData('bloginfo', $bloginfo)->oSetData('blogcontent', $htmlrender)->oSetData('taginfos', $taginfos)->oSend();
});
Ko_Web_Route::VGet('item', function () {
    $uid = Ko_Web_Request::IGet('uid');
    $blogid = Ko_Web_Request::IGet('blogid');
    $tag = Ko_Web_Request::SGet('tag');
    $userinfo = Ko_Tool_Adapter::VConv($uid, array('user_baseinfo', array('logo80')));
    $blogApi = new KBlog_Api();
    $taginfos = $blogApi->aGetAllTaginfo($uid);
    $bloginfo = $blogApi->aGet($uid, $blogid);
    if (empty($bloginfo) || in_array('回收站', $bloginfo['tags'])) {
        Ko_Web_Response::VSetRedirect('user?uid=' . $uid);
        Ko_Web_Response::VSend();
        exit;
    }
    if (0 == strlen($tag)) {
        $tag = $blogApi->sGetPriorTag($bloginfo['tags']);
    }
    $prevnextInfo = $blogApi->aGetPrevNextTitle($uid, $blogid, $tag);
    $contentApi = new KContent_Api();
    $htmlrender = new Ko_View_Render_HTML($contentApi);
コード例 #17
0
ファイル: photo.php プロジェクト: firaga/operation
        exit;
    }
    $userinfo = Ko_Tool_Adapter::VConv($uid, array('user_baseinfo', array('logo80')));
    $photolist = $photoApi->getPhotoListBySeq($uid, $albumid, '0_0_0', $num, $next, $next_boundary, 'imageView2/2/w/240');
    $render = new KRender_www();
    if ($loginuid == $uid) {
        $allalbumlist = $photoApi->getAllAlbumList($uid);
        $render->oSetData('allalbumlist', $allalbumlist);
    }
    $render->oSetTemplate('www/photo/album.html')->oSetData('userinfo', $userinfo)->oSetData('albuminfo', $albuminfo)->oSetData('photolist', $photolist)->oSetData('page', array('num' => $num, 'next' => $next, 'next_boundary' => $next_boundary))->oSend();
});
Ko_Web_Route::VGet('item', function () {
    $loginApi = new KUser_loginApi();
    $loginuid = $loginApi->iGetLoginUid();
    $uid = Ko_Web_Request::IGet('uid');
    $photoid = Ko_Web_Request::IGet('photoid');
    $storageApi = new KStorage_Api();
    $photoApi = new KPhoto_Api();
    $photoinfo = $photoApi->getPhotoInfo($uid, $photoid);
    if (empty($photoinfo)) {
        Ko_Web_Response::VSetRedirect('/');
        Ko_Web_Response::VSend();
        exit;
    }
    $photoinfo['image_src'] = $storageApi->sGetUrl($photoinfo['image'], '');
    $photoinfo['image_small'] = $storageApi->sGetUrl($photoinfo['image'], 'imageView2/1/w/60');
    $photoinfo['image_exif'] = $storageApi->aGetImageExif($photoinfo['image']);
    $agentinfo = KUser_agentApi::get();
    if ($agentinfo['screen']['height'] < 1000) {
        $photoinfo['image'] = $storageApi->sGetUrl($photoinfo['image'], 'imageView2/2/w/600/h/600');
        $photoinfo['imagesize'] = 600;
コード例 #18
0
ファイル: Rewrite.php プロジェクト: AllenLyu/ko
 private static function _AGet($sHost, $sUri)
 {
     self::_VLoadHostRules($sHost, $sUri);
     list($path, $query) = explode('?', $sUri, 2);
     $paths = self::_ASplitPath($path);
     $keys = array();
     if (is_null($matched = self::_VMatchPath($paths, self::$s_aRules, $keys))) {
         return array($sUri, 0);
     }
     $keys = array_reverse($keys);
     list($location, $httpCode) = explode(' ', $matched, 2);
     $slashmismatch = false;
     $keylen = count($keys);
     $pathlen = count($paths);
     if ($keylen === $pathlen + 1 && '' === $keys[$keylen - 1]) {
         //规则: /a/b/   URI: /a/b
         $slashmismatch = true;
         $paths[] = '';
     } elseif ($keylen + 1 === $pathlen && '' === $paths[$pathlen - 1]) {
         //规则: /a/b   URI: /a/b/
         $slashmismatch = true;
         array_pop($paths);
     }
     if ($slashmismatch && 'GET' === Ko_Web_Request::SRequestMethod()) {
         $location = '/' . implode('/', $paths);
         $httpCode = 301;
     } else {
         $matchedPattern = '/^\\/' . implode('\\/', $keys) . '/i';
         $uri = '/' . implode('/', $paths);
         if (!@preg_match($matchedPattern, $uri, $match) || false === ($location = @preg_replace($matchedPattern, $location, $match[0]))) {
             return array($sUri, 0);
         }
     }
     if (isset($query)) {
         $location .= false === strpos($location, '?') ? '?' : '&';
         $location .= $query;
     }
     return array($location, intval($httpCode));
 }
コード例 #19
0
ファイル: menu.php プロジェクト: firaga/operation
});
Ko_Web_Route::VPost('delpri', function () {
    $oPriApi = new KShequ_Menu_PrivacyApi();
    $oPriApi->vDeleteOneMenuPri($_POST['admin_uid'], $_POST['menu_id']);
    echo 1;
    exit;
});
Ko_Web_Route::VGet('suggest', function () {
    $sName = Ko_Web_Request::SInput("name");
    $suggest_result = KDuizhang_Tool::suggest($sName, "admin_user");
    Ko_Tool_Str::VConvert2UTF8($suggest_result);
    echo json_encode(array('ret' => 1, 'msg' => $suggest_result));
    exit;
});
Ko_Web_Route::VGet('suggestmenu', function () {
    $sName = Ko_Web_Request::SInput("name");
    $sName = Ko_Tool_Str::SConvert2GB18030(trim($sName));
    $suggest_result = KDuizhang_Tool::suggest($sName, "sq_menu", 'id', 'text');
    Ko_Tool_Str::VConvert2UTF8($suggest_result);
    $oApi = new KOperation_Menu_Api();
    $tree_api = new KOperation_Menu_TreeApi();
    $aList = $oApi->aGetAll();
    $result = array();
    if (!empty($suggest_result)) {
        foreach ($suggest_result as $v) {
            $relations = $tree_api->aGetParent($v['id'], 0);
            unset($relations[count($relations) - 1]);
            array_unshift($relations, $v['id']);
            if (!empty($relations)) {
                $relations = array_reverse($relations);
                $msg = '';
コード例 #20
0
ファイル: operation.php プロジェクト: firaga/operation
<?php

/**
 * Created by JetBrains PhpStorm.
 * User: Jichen Zhou
 * Date: 2015年12月22日
 * Time: 下午5:31
 */
Ko_Web_Event::On('ko.dispatch', 'before', function () {
    $uri = Ko_Web_Request::SRequestUri();
    $script = Ko_Web_Request::SScriptName();
    $userApi = new KUser_userApi();
    if ($uri == '/user/login/index') {
        echo "hook logout" . chr(10);
        //		$userApi->logoutAdminAuth();
    } elseif ($uri == '/rest/user/login/') {
    } else {
        if (!$userApi->checkLogin()) {
            $url = 'http://' . WWW_DOMAIN . '/user/login/index';
            header('Location:' . $url);
            exit;
        }
    }
});
コード例 #21
0
ファイル: agentApi.php プロジェクト: firaga/operation
 public static function get()
 {
     $str = Ko_Web_Request::SCookie(self::COOKIE_NAME);
     return json_decode($str, true);
 }
コード例 #22
0
ファイル: OAuthServer.php プロジェクト: AllenLyu/ko
 private function _sGetReqMethod()
 {
     return Ko_Web_Request::SRequestMethod();
 }
コード例 #23
0
ファイル: Safe.php プロジェクト: firaga/operation
 public static function BCheckRequestMethod($sAllowMethod = 'POST')
 {
     $method = Ko_Web_Request::SRequestMethod();
     return false !== strpos($sAllowMethod, $method);
 }
コード例 #24
0
ファイル: Ip.php プロジェクト: AllenLyu/ko
 /**
  * 从环境变量获取服务器Ip,如果获取不到有意义的ip,返回 unknown
  *
  * @return string
  */
 public static function SGetServerIp()
 {
     static $ip = null;
     if (is_null($ip)) {
         $ip = Ko_Web_Request::SServerAddr();
         if ($ip == '' || $ip == '127.0.0.1') {
             $ip = 'unknown';
         }
     }
     return $ip;
 }
コード例 #25
0
ファイル: entry.php プロジェクト: firaga/operation
            $loginuid = $loginApi->iGetLoginUid();
            if (empty($loginuid)) {
                Ko_Web_Response::VSetRedirect('http://' . PASSPORT_DOMAIN . '/user/login');
                Ko_Web_Response::VSend();
                exit;
            }
        }
    }
    $hooks = COMMON_CLASS_PATH . 'hooks/' . $appname . '.php';
    if (is_file($hooks)) {
        require_once $hooks;
    }
});
Ko_Web_Event::On('ko.error', '500', function ($errno, $errstr, $errfile, $errline, $errcontext) {
    Ko_Web_Error::V500($errno, $errstr, $errfile, $errline, $errcontext);
    exit;
});
Ko_Web_Event::On('ko.dispatch', 'before', function () {
    Ko_Tool_Adapter::VOn('user_baseinfo', array('KUser_baseinfoApi', 'AAdapter'));
    Ko_Tool_Adapter::VOn('image_baseinfo', array('KStorage_Api', 'AAdapter'));
    $uri = Ko_Web_Request::SRequestUri();
    $appname = Ko_Web_Config::SGetAppName();
    if ('zc' === $appname) {
        $_GET['uid'] = 20;
    }
});
Ko_Web_Event::On('ko.dispatch', '404', function () {
    Ko_Web_Route::V404();
    exit;
});
require_once KO_DIR . 'web/Bootstrap.php';