<?php /** * 发送成功列表 * @author 潘洪学 panliu888@gmail.com * @create_date 2011-10 */ include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php'; Passport::RequireLogin(); $task = new Task(); switch (strtolower($_GET['action'])) { case 'del': $task->UpdateStatus(Task::DELETE_OK, intval($_GET['id']), '已取消'); break; case 'clear': $task->update(array('status' => Task::DELETE_OK, 'msg' => '被清空'), array('uid' => Passport::GetLoginUid(), 'status' => Task::OK)); redirect('?'); break; } $pager = new Pager($task->GetCount(Task::OK), 20); $TEMPLATE['list'] = $task->GetList(Task::OK, $pager->offset()); $TEMPLATE['pager'] = $pager->render(); $TEMPLATE['title'] = '已发送'; $TEMPLATE['login_name'] = Passport::GetLoginName(); $TEMPLATE['nav']['list_ok'] = 'current'; $smarty = new Template(); echo $smarty->r('list_ok');
/** * 按状态和分页获取任务列表 * @param int $status * @param string $limit */ public function GetList($status, $limit = NULL) { $cond = array('status' => $status); if (!Passport::IsAdmin()) { $user = new User(); $perms = $user->getPerms(Passport::GetLoginUid()); if (count($perms) > 0) { $cond['pid'] = array_keys($perms); } else { $cond['uid'] = Passport::GetLoginUid(); } } $list = $this->findBy($cond, $this->primary_key, $limit, null, 'send_time desc, id desc'); // 查询 username 字段 $uids = array(); foreach ($list as $item) { $uids[] = $item['uid']; } $uids = array_unique($uids); $user = new User(); $user_list = $user->gets($uids); foreach ($list as &$item) { $item['username'] = if_null($user_list[$item['uid']]['username'], 'uid: ' . $item['uid']); unset($item); } return $list; }
<?php /** * 发微博 * @author 潘洪学 panliu888@gmail.com * @create_date 2011-10 */ include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php'; Passport::RequireLogin(); $task = new Task(); $id = intval($_GET['id']); $TEMPLATE['data'] = $data = $task->get($id); if ($data['uid'] != Passport::GetLoginUid()) { echo '没有权限!'; exit; } switch ($_POST['action']) { case '修改': $TEMPLATE['data'] = array_merge($data, $_POST); if (!validate()) { } else { $tableInfo = array('title' => $_POST['title'], 'content' => $_POST['content']); if ($data['cat'] == 'weibo') { if ($_FILES['image']['tmp_name']) { @mkdir(UPLOAD_PATH, 0777, true); $save_file = $upload_file = UPLOAD_PATH . microtime(true) . '_' . Pinyin::get($_FILES['image']['name']); move_uploaded_file($_FILES['image']['tmp_name'], $save_file); $tableInfo['pic'] = $save_file; } } if ($_POST['time'] == 'on') {
case 'qzone': $code_key = 'oauth_vericode'; break; case 'renren': case 'sina': $code_key = 'code'; break; default: $code_key = 'oauth_verifier'; break; } $token = $api->getAccessToken($_GET[$code_key], $_GET['oauth_token']); if ($token['oauth_token']) { $api->openid = $token['openid']; $thirdAccount = new ThirdAccount(); $tableInfo = array('uid' => Passport::GetLoginUid(), 'pid' => $pid, 'type' => $api->type, 'token' => $token['oauth_token'], 'token_secret' => $token['oauth_token_secret'], 'openid' => $token['openid'], 'nick' => $api->getNick(), 'url' => $api->getUrl(), 'valid' => 1); Log::customLog('token_expires_error.txt', "绑定 Token,信息:" . print_r($tableInfo, true)); $user = new User(); $users = $user->getsAll(); foreach ($users as $uid => $item) { $tableInfo['uid'] = $uid; $thirdAccount->replace($tableInfo); } redirect($_GET['redir']); echo <<<HTML <script> opener.location=opener.location; window.close(); </script> HTML; } else {
$ids = array_keys($TEMPLATE['platform_list']); redirect('?id=' . $ids[0]); } if ($_GET['action'] == 'unbind' && $_GET['type']) { $third = $thirdAccount->getByType($_GET['type'], $pid); $api = Factory::CreateAPI2($_GET['type'], $pid, $third); if (method_exists($api, 'Logout')) { $api->Logout(); } $thirdAccount->delete(array('uid' => Passport::GetLoginUid(), 'type' => $_GET['type'], 'pid' => $pid)); redirect("?id={$pid}"); } if ($_POST['action'] == 'bind') { $fields = $_POST['f']; $fields['pid'] = $pid; $fields['uid'] = Passport::GetLoginUid(); $fields['nick'] = $fields['token']; $fields['valid'] = 1; if ($fields['token'] && $fields['token_secret']) { $api = Factory::CreateAPI2($fields['type'], $pid, $fields); $ret = $api->Login($_POST['verify_code']); if ($ret === true) { $fields['url'] = $api->getUrl(); $user = new User(); $users = $user->getsAll(); foreach ($users as $uid => $item) { $fields['uid'] = $uid; $thirdAccount->replace($fields); } } else { $TEMPLATE['error'] = array('type' => $fields['type'], 'msg' => $ret);
<?php /** * 管理定时发送任务。立即发送、取消 * @author 潘洪学 panliu888@gmail.com * @create_date 2011-10 */ include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php'; Passport::RequireLogin(); $user = new User(); $data = $user->get(Passport::GetLoginUid()); $last_exec = $data['last_exec']; if (time() - $last_exec > 60 * 60) { $TEMPLATE['last_exec'] = max($last_exec, 1); } $task = new Task(); switch ($_GET['action']) { case 'send': $thirdAccount = new ThirdAccount(); $id = intval($_GET['id']); $item = $task->get($id); if ($item) { $type = $item['type']; $arr = explode('|', $type); $third = $thirdAccount->getByType($arr[0], $arr[1], $item['uid']); $api = Factory::CreateAPI2($arr[0], $arr[1], $third); if ($item['cat'] == 'weibo') { $ret = $api->upload($item['content'], $item['pic']); } else { $ret = $api->publish($item['title'], $item['content']); }
/** * 获取Session物理文件名 */ private static function getSessionFile() { return LOG_PATH . Passport::GetLoginUid() . '.session'; }
/** * 按平台和权限获取博客列表 * @param int $pid * @param bool $perm */ public function getBlogList($pid = 0, $perm = TRUE) { if ($pid == 0) { return array(); } if ($perm) { $user = new User(); $perms = $user->getPerms(Passport::GetLoginUid()); if (!array_key_exists($pid, $perms)) { return array(); } } $list = Config::blog_list(); if ($pid > 0) { $set_list = $this->findBy(array('status' => 1, 'pid' => $pid), 'name'); $new_list = array(); foreach ($list as $key => $value) { if (array_key_exists($key, $set_list) || array_key_exists($key, Config::simula_list())) { $new_list[$key] = $list[$key]; } } $list = $new_list; } else { foreach ($list as $key => $value) { if ($key == 'qzone_simula') { // 只要设定任何一个 qzone APPKEY,qzone模拟登录就关闭 if ($this->fetchOne(array('status' => 1, 'name' => 'qzone'))) { unset($list[$key]); continue; } } if (array_key_exists($key, Config::open_list())) { unset($list[$key]); } } } return $list; }
/** * 获取登录账户绑定信息 * @param string $type 第三方平台类型 * @param int $pid 自建平台ID */ public function getByType($type, $pid = 0, $uid = NULL) { $uid = if_null($uid, Passport::GetLoginUid()); return $this->getThird($uid, $type, $pid); }
<?php /** * 修改个人信息(密码)页面 * @author 潘洪学 panliu888@gmail.com * @create_date 2011-10 */ include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php'; Passport::RequireLogin(); if (Request::IsPost()) { $fields = $_POST['f']; if (validate($fields)) { $user = new User(); $TEMPLATE['error'] = array(); $tableInfo = array('password' => md5($fields['password']), 'last_login' => time()); if ($user->update($tableInfo, array('id' => Passport::GetLoginUid()))) { $TEMPLATE['error']['username'] = '******'; } else { $TEMPLATE['error']['username'] = '******'; $TEMPLATE['data'] = $fields; } } else { // 保持填写的数据 $TEMPLATE['data'] = $fields; } } $TEMPLATE['title'] = '修改密码'; $TEMPLATE['login_name'] = Passport::GetLoginName(); $TEMPLATE['nav']['profile'] = 'current'; $smarty = new Template(); echo $smarty->r('profile');