Example #1
0
 /**
  * 用户授权管理:撤销 access token 授权
  */
 public function vRevokeToken($iUid, $iCid, $sToken)
 {
     $tokenApi = $this->_aConf['tokenApi'];
     $oOption = new Ko_Tool_SQL();
     $oOption->oWhere('uid = ? and cid = ?', $iUid, $iCid);
     $this->{$tokenApi}->iDelete($sToken, $oOption);
 }
Example #2
0
 public function aGetRoleList($iStart, $iLength, $flag = null)
 {
     $option = new Ko_Tool_SQL();
     $option->oOffset($iStart)->oLimit($iLength)->oCalcFoundRows(true);
     $option->oOrderBy('ctime desc');
     if (is_int($flag)) {
         $option->oWhere('flag = ?', $flag);
     }
     $aData = $this->aGetList($option);
     $aResult['total'] = $option->iGetFoundRows();
     $aResult['list'] = $aData;
     return $aResult;
 }
Example #3
0
 public function _vSyncAll_Callback($aInfo, $iNo)
 {
     $dbDao = $this->_aConf['db'] . 'Dao';
     $mcDao = $this->_aConf['mc'] . 'Dao';
     $key = $this->_sGetMCKey($aInfo);
     $mcinfo = intval($this->{$mcDao}->vGet($key));
     if ($mcinfo) {
         $update = array('mtime' => date('Y-m-d H:i:s'));
         $change = array('times' => $mcinfo);
         $oOption = new Ko_Tool_SQL();
         $oOption->oWhere('mtime = ?', $aInfo['mtime']);
         if ($this->{$dbDao}->iUpdate($aInfo, $update, $change, $oOption)) {
             $this->{$mcDao}->iDecrement($key, $mcinfo);
         }
     }
 }
Example #4
0
File: User.php Project: AllenLyu/ko
 private function _bUpdatePersistentToken($iUid, $sSeries, $sToken, &$sNewToken)
 {
     if ($this->_iGetPersistentStrict()) {
         // 每个 persistent_token 只能验证一次,如果重复验证可能是因为数据被重复提交,或者失窃
         $sNewToken = $this->_sGetNewSalt();
         $sMtime = date('Y-m-d H:i:s');
         $aUpdate = array('token' => $sNewToken, 'mtime' => $sMtime);
         $persistentDao = $this->_aConf['persistent'] . 'Dao';
         $key = array('uid' => $iUid, 'series' => $sSeries);
         $oOption = new Ko_Tool_SQL();
         $oOption->oWhere('token = ?', $sToken);
         return $this->{$persistentDao}->iUpdate($key, $aUpdate, array(), $oOption) ? true : false;
     } else {
         // 每次不更新 token,只做延期
         $sNewToken = $sToken;
         $sMtime = date('Y-m-d H:i:s');
         $aUpdate = array('mtime' => $sMtime);
         $persistentDao = $this->_aConf['persistent'] . 'Dao';
         $key = array('uid' => $iUid, 'series' => $sSeries);
         $oOption = new Ko_Tool_SQL();
         $oOption->oWhere('token = ?', $sToken);
         $this->{$persistentDao}->iUpdate($key, $aUpdate, array(), $oOption);
         return true;
     }
 }
Example #5
0
File: Tree.php Project: AllenLyu/ko
 private function _aGetChildList($aId)
 {
     $ret = array();
     if (!empty($aId)) {
         $treeApi = $this->_aConf['treeApi'];
         $option = new Ko_Tool_SQL();
         $list = $this->{$treeApi}->aGetList($option->oWhere('pid in (?)', $aId)->oForceMaster(true));
         foreach ($list as $v) {
             $ret[$v['pid']][$v['id']] = array();
         }
     }
     return $ret;
 }
Example #6
0
 private function _aGetReplyCids($iOid, $aIndexCid)
 {
     if (empty($aIndexCid)) {
         return array();
     }
     $replyDao = $this->_aConf['reply'] . 'Dao';
     $oOption = new Ko_Tool_SQL();
     $oOption->oWhere('thread_cid in (?)', $aIndexCid)->oOrderBy('cid desc')->oLimit(self::MAX_REPLY);
     $aReply = $this->{$replyDao}->aGetList($iOid, $oOption);
     return Ko_Tool_Utils::AObjs2ids($aReply, 'cid');
 }
Example #7
0
 /**
  * 用户查看会话消息列表详情,根据最小id查询
  *
  * @return array
  */
 public function aGetMessageListByMinmid($iUid, $iThread, $iMinmid, $iNum, $bAutoRead = true)
 {
     if (isset($this->_aConf['userthread'])) {
         $userthreadDao = $this->_aConf['userthread'] . 'Dao';
         $info = $this->{$userthreadDao}->aGet(array('uid' => $iUid, 'mid' => $iThread));
         if (empty($info)) {
             return array();
         }
         if ($bAutoRead && $info['unread']) {
             $this->{$userthreadDao}->iUpdate(array('uid' => $iUid, 'mid' => $iThread), array('unread' => 0));
         }
     }
     $oOption = new Ko_Tool_SQL();
     if (isset($this->_aConf['userthread'])) {
         $oOption->oWhere('ctime >= ?', $info['jointime']);
     }
     $oOption->oAnd('mid > ?', $iMinmid)->oOrderBy('mid desc')->oLimit($iNum);
     return $this->_aGetMessageList($iUid, $iThread, $oOption);
 }
Example #8
0
File: XList.php Project: nuaazdh/ko
 private function _aGetAll_Exkey($aExkeyConf, $vHintId)
 {
     $exkeyDao = $aExkeyConf['dao'] . 'Dao';
     $oOption = new Ko_Tool_SQL();
     $oOption->oOrderBy($aExkeyConf['order']);
     if (!empty($aExkeyConf['option'])) {
         call_user_func_array(array($oOption, 'oAnd'), $aExkeyConf['option']);
     }
     if (strlen($this->{$exkeyDao}->sGetSplitField())) {
         return $this->{$exkeyDao}->aGetList($vHintId, $oOption);
     }
     return $this->{$exkeyDao}->aGetList($oOption);
 }
Example #9
0
 public function vDeleteByKind($uid, $kind)
 {
     $msgtypes = $this->_aKind2MsgTypes($kind);
     $userDao = $this->_aConf['user'] . 'Dao';
     $option = new Ko_Tool_SQL();
     $option->oWhere('msgtype in (?)', $msgtypes);
     $splitField = $this->{$userDao}->sGetSplitField();
     if (strlen($splitField)) {
         $this->{$userDao}->iDeleteByCond($uid, $option);
     } else {
         $option->oAnd('uid = ?', $uid);
         $this->{$userDao}->iDeleteByCond($option);
     }
 }
Example #10
0
 /**
  * 直接获取用户的授权信息
  *
  * @return array 返回用户授权信息 array(token, secret)
  */
 public function aGetUserTokenDirect($iCid, $iUid, $sScope = '')
 {
     $tokenApi = $this->_aConf['tokenApi'];
     $oOption = new Ko_Tool_SQL();
     $tokenInfo = $this->{$tokenApi}->aGetList($oOption->oWhere('uid = ? and cid = ?', $iUid, $iCid)->oLimit(1));
     if (!empty($tokenInfo)) {
         $aUpdate = array('scope' => $sScope, 'ctime' => date('Y-m-d H:i:s'));
         $this->{$tokenApi}->iUpdate($tokenInfo[0], $aUpdate);
         return array($tokenInfo[0]['token'], $tokenInfo[0]['secret']);
     }
     $sToken = Ko_Tool_OAuth::SGenKey();
     $sSecret = Ko_Tool_OAuth::SGenKey();
     $aData = array('cid' => $iCid, 'token' => $sToken, 'secret' => $sSecret, 'uid' => $iUid, 'scope' => $sScope, 'ctime' => date('Y-m-d H:i:s'));
     $this->{$tokenApi}->aInsert($aData);
     return array($sToken, $sSecret);
 }
Example #11
0
 private function _bUpdate($vObj, $sAction, $iMaxTimes, $iTimes)
 {
     $change = array('times' => $iTimes);
     $oOption = new Ko_Tool_SQL();
     $oOption->oWhere('times <= ?', $iMaxTimes - $iTimes);
     if ($this->_iUpdate($vObj, $sAction, array(), $change, $oOption)) {
         return true;
     }
     return false;
 }
Example #12
0
 private function _vInsertIpRoles($sIp, $aConfig, $aUnknown)
 {
     foreach ($aConfig as $service => &$v) {
         foreach ($v as $pid => &$vv) {
             ksort($vv);
             foreach ($vv as $pname => &$vvv) {
                 sort($vvv);
             }
             unset($vvv);
         }
         unset($vv);
     }
     unset($v);
     foreach ($aConfig as $service => $v) {
         usort($v, array($this, '_iComIpRoles'));
         $config = array();
         foreach ($v as $pid => $vv) {
             foreach ($vv as $pname => $vvv) {
                 $config[$pid][] = array('pname' => $pname, 'localaddr' => implode(' ', $vvv));
             }
         }
         $this->_aInsertIpRole($sIp, $service, $config);
         echo date('Y-m-d H:i:s'), "\t", long2ip($sIp), "\t", $service, "\n";
     }
     $newroles = array_keys($aConfig);
     if (!empty($aUnknown)) {
         $newroles[] = 'unknown';
         $this->_aInsertIpRole($sIp, 'unknown', $aUnknown);
     }
     $iproleApi = $this->_aConf['iproleApi'];
     $option = new Ko_Tool_SQL();
     $this->{$iproleApi}->iDeleteByCond($option->oWhere('ip = ? and role not in (?)', $sIp, $newroles));
 }
Example #13
0
 private function _resetAlbumDigest($albumid)
 {
     $option = new Ko_Tool_SQL();
     $photolist = $this->photoDao->aGetList($option->oSelect('photoid')->oWhere('albumid = ?', $albumid)->oLimit(1000)->oOrderBy('sort desc, photoid desc'));
     $count = count($photolist);
     $step = max(1, floor($count / 50));
     $total = min($count, 50 * $step);
     $photoids = array();
     for ($i = 0; $i < $total; $i += $step) {
         $photoids[] = $photolist[$i]['photoid'];
     }
     $this->_setDigest($albumid, $photoids);
 }
Example #14
0
 private function _vSubTags($uid, $blogid, $tags)
 {
     foreach ($tags as $tag) {
         $taglistkey = compact('uid', 'tag', 'blogid');
         if ($this->taglistDao->iDelete($taglistkey)) {
             $taginfokey = compact('uid', 'tag');
             $option = new Ko_Tool_SQL();
             $this->taginfoDao->iUpdate($taginfokey, array(), array('bcount' => -1), $option->oWhere('bcount > ?', 0));
         }
     }
 }
Example #15
0
 protected function _aGetCurrentListFromDb()
 {
     $now = time();
     $stime = ceil($now / 3600.0) * 3600;
     $etime = floor($now / 3600.0) * 3600;
     $option = new Ko_Tool_SQL();
     $listApi = $this->_aConf['listApi'];
     $list = $this->{$listApi}->aGetList($option->oSelect('id, stime, etime, grp, regions, forbidregions, uids, priority')->oWhere('stime <= ? and etime >= ? and pub != 0', date('Y-m-d H:i:s', $stime), date('Y-m-d H:i:s', $etime)));
     foreach ($list as &$v) {
         $v['stime'] = strtotime($v['stime']);
         $v['etime'] = strtotime($v['etime']);
         $v['uids'] = preg_split('/;|,|\\s/', $v['uids']);
         $v['regions'] = $this->_aGetRegionArr($v['regions']);
         $v['forbidregions'] = $this->_aGetRegionArr($v['forbidregions']);
     }
     unset($v);
     return $list;
 }
Example #16
0
 private function _sGenToken($iUid, $sScope)
 {
     $tokenApi = $this->_aConf['tokenApi'];
     $oOption = new Ko_Tool_SQL();
     $tokenInfo = $this->{$tokenApi}->aGetList($oOption->oWhere('uid = ? and cid = ?', $iUid, $this->_sClientId)->oLimit(1));
     if (!empty($tokenInfo)) {
         $aUpdate = array('scope' => $sScope, 'ctime' => date('Y-m-d H:i:s'));
         $this->{$tokenApi}->iUpdate($tokenInfo[0], $aUpdate);
         return $tokenInfo[0]['token'];
     }
     $token = Ko_Tool_OAuth::SGenKey();
     $aData = array('cid' => $this->_sClientId, 'token' => $token, 'uid' => $iUid, 'scope' => $sScope, 'ctime' => date('Y-m-d H:i:s'));
     $this->{$tokenApi}->aInsert($aData);
     return $token;
 }
Example #17
0
 /**
  * 查询关注用户 B 的用户列表
  *
  * @return array
  */
 public function aGetFollowedListWithTotal($iUidb, $iStart, $iNum, &$iTotal)
 {
     $oOption = new Ko_Tool_SQL();
     $oOption->oOrderBy('sort desc')->oOffset($iStart)->oLimit($iNum)->oCalcFoundRows(true);
     $info = $this->_aGetFollowedList($iUidb, $oOption);
     $iTotal = $oOption->iGetFoundRows();
     return $info;
 }