/** * 构造函数 * @param int $pid 自建平台ID * @param string $oauth_token AccessToken 之后拿到的token * @param string $oauth_token_secret AccessToken 之后拿到的token_secret * @param int $openid openid,目前只有QQ空间日志开放平台用到 */ function __construct($pid, $oauth_token = NULL, $oauth_token_secret = NULL, $openid = NULL) { $wt_open = new WTOpen(); $app = $wt_open->getApp($pid, 'qzone'); $this->openid = $openid; $this->callback = $app['callback']; parent::__construct($app['app_key'], $app['app_secret'], $oauth_token, $oauth_token_secret); }
/** * 模板替换 * @param string $str * @param int $pid * @param string $type */ private function rep_platform($str, $pid, $type) { $wt = new WTOpen(); $ret = $wt->get($pid); $str = str_ireplace('{platform}', $ret['name'], $str); $str = str_ireplace('{weibo}', Config::get_name($type), $str); $str = str_ireplace('{pid}', $pid, $str); $str = str_ireplace('{type}', $type, $str); return $str; }
/** * 获取指定用户权限 * @param int $id 用户ID */ public function getPerms($id) { $info = $this->get($id); if ($info['type'] == 1) { $wt_open = new WTOpen(); $platform_list = $wt_open->getPlatformList(false); $perms = array(); foreach ($platform_list as $key => $item) { $perms[$key] = $item['name']; } } else { $perms = unserialize($info['perms']); } if (!is_array($perms)) { $perms = array(); } return $perms; }
/** * 列表页获取 平台-博客 名称 * @param string $type 类型 * @param string $cat 类别 weibo|blog */ function get_name($type, $cat = 'weibo') { global $platform_name_list; $arr = explode('|', $type); if (!isset($platform_name_list[$arr[1]])) { $wt_open = new WTOpen(); $platform = $wt_open->get($arr[1]); if ($platform) { $platform_name_list[$arr[1]] = $platform['name'] . ' - '; } } if ($cat != 'weibo') { $name = Config::get_blog_name($arr[0]); } else { $name = Config::get_weibo_name($arr[0]); } return $platform_name_list[$arr[1]] . $name; }
<?php /** * 发博客 * @author 潘洪学 panliu888@gmail.com * @create_date 2011-10 */ include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php'; Passport::RequireLogin(); $wt_open = new WTOpen(); $thirdAccount = new ThirdAccount(); if (Request::IsPost()) { if (!validate()) { $TEMPLATE['data'] = $_POST; } else { // 首先获取内容中包含的远程图片,并替换为本地图片 $content = save_remote_img($_POST['content']); $wbs = $_POST['target']; $task = new Task(); if ($_POST['time'] == 'on') { // 定时发送 foreach ($wbs as $type) { $task->AddTask($type, $content, $_POST['send_time'], NULL, Task::TASK, NULL, 'blog', $_POST['title']); } $TEMPLATE['report']['time'] = array('status' => true, 'msg' => '定时发送成功!<a href="task.php">查看</a>'); } else { $watch = new Stopwatch(); $watch->Start(); // 直接发送 foreach ($wbs as $type) { $type_arr = explode('|', $type);
if (validate($fields)) { if (!isset($fields['type'])) { $fields['type'] = 0; } // 按平台权限拷贝第一个管理员的Token $thirdAccount = new ThirdAccount(); $thirdAccount->copyToken($id, @array_keys($fields['perms'])); $fields['perms'] = serialize($fields['perms']); $user->update($fields, array('id' => $id)); redirect('?'); } else { $fields['username'] = $TEMPLATE['data']['username']; $TEMPLATE['data'] = $fields; } } $wt_open = new WTOpen(); $TEMPLATE['simula']['weibo_list'] = $wt_open->getWeiboList(0, false); $TEMPLATE['simula']['blog_list'] = $wt_open->getBlogList(0, false); $TEMPLATE['platform_list'] = $wt_open->getPlatformList(false); foreach ($TEMPLATE['platform_list'] as &$item) { $item['weibo_list'] = $wt_open->getWeiboList($item['id'], false); $item['blog_list'] = $wt_open->getBlogList($item['id'], false); unset($item); } if (!is_array($TEMPLATE['data']['perms'])) { $TEMPLATE['data']['perms'] = array(); } exit($smarty->r('users_edit')); break; } $TEMPLATE['list'] = $user->getsAll();
/** * 构造函数 * @param int $pid 自建平台ID * @param string $oauth_token AccessToken 之后拿到的token * @param string $oauth_token_secret AccessToken 之后拿到的token_secret */ function __construct($pid, $oauth_token = NULL, $oauth_token_secret = NULL) { $wt_open = new WTOpen(); $app = $wt_open->getApp($pid, 't_163'); parent::__construct($app['app_key'], $app['app_secret'], $oauth_token, $oauth_token_secret); }
<?php /** * 第三方账号绑定页面。 * @author 潘洪学 panliu888@gmail.com * @create_date 2011-10 */ include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php'; Passport::RequireLogin(); if (!Passport::IsAdmin()) { redirect('login.php'); } $wt_open = new WTOpen(); $thirdAccount = new ThirdAccount(); $TEMPLATE['platform_list'] = $wt_open->getPlatformList(); $pid = intval($_GET['id']); if ($pid == 0 && count($TEMPLATE['platform_list']) > 0) { $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'];
} if (Request::IsPost()) { $fields = $_POST['f']; if (validate($fields)) { $user = new User(); $ret = $user->getByName($fields['username']); $TEMPLATE['error'] = array(); if ($ret) { $TEMPLATE['error']['username'] = '******'; } else { $tableInfo = array('username' => $fields['username'], 'password' => md5($fields['password']), 'type' => $user->totals() == 0 ? 1 : 0, 'reg_date' => time(), 'last_login' => time()); $newid = $user->insertIgnore($tableInfo); if ($newid) { $ret = Passport::WriteCookie($newid, $tableInfo['username'], $tableInfo['type']); $return_url = get_returnurl('index.php'); $wt_open = new WTOpen(); $cbs = $wt_open->getCallbackList(); $scripts = ''; if (count($cbs) > 0) { $token = http_build_query($ret); foreach ($cbs as $value) { $url = get_absolute_url("login_api.php?{$token}", $value); $scripts .= "<script src=\"{$url}\"></script>\n"; } } echo <<<HTML {$scripts} <script> location.replace('{$return_url}'); </script> HTML;
<?php /** * 平台设定页面,新增、删除平台,APP KEY 设置 * @author 潘洪学 panliu888@gmail.com * @create_date 2011-10 */ include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php'; Passport::RequireLogin(); if (!Passport::IsAdmin()) { redirect('login.php'); } $wt_open = new WTOpen(); $pid = intval($_GET['id']); $TEMPLATE['error'] = array(); switch (strtolower($_REQUEST['action'])) { case 'add': $name = $_POST['name']; if ($name) { if ($wt_open->getByName($name)) { $TEMPLATE['error']['name'] = '名称已存在'; } else { $tableInfo = array('name' => $name, 'user' => Passport::GetLoginName()); $newid = $wt_open->insertIgnore($tableInfo); redirect("?id={$newid}"); } } else { $TEMPLATE['error']['name'] = '名称不能为空'; } $TEMPLATE['data'] = $_POST; break;