コード例 #1
0
ファイル: Task.class.php プロジェクト: z445056647/phx-svns
 /**
  * 更改任务状态
  * @param int $status
  * @param int $id
  * @param string $msg	状态描述
  * @param int $send_time
  */
 public function UpdateStatus($status, $id, $msg = NULL, $send_time = 0)
 {
     $tableInfo = array('status' => $status, 'msg' => $msg, 'last_send' => time());
     if ($send_time) {
         $tableInfo['send_time'] = $send_time;
     }
     if ($status == Task::ERROR) {
         $item = $this->get($id);
         $tableInfo['retry_count'] = $item['retry_count'] + 1;
     }
     if ($status == Task::OK) {
         $item = $this->get($id);
         $type_arr = explode('|', $item['type']);
         $thirdAccount = new ThirdAccount();
         $third = $thirdAccount->getThird($item['uid'], $type_arr[0], $type_arr[1]);
         $tableInfo['url'] = $third['url'];
     }
     return $this->update($tableInfo, array('id' => $id));
 }
コード例 #2
0
ファイル: blog.php プロジェクト: z445056647/phx-svns
<?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);
コード例 #3
0
ファイル: task_exec.php プロジェクト: z445056647/phx-svns
include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
// test curl
$curl = curl_init();
curl_close($curl);
// 设置执行超时时间(秒)
set_time_limit(500);
// 更新脚本最后执行时间
$user = new User();
$user->update(array('last_exec' => time()), array());
$watch = new Stopwatch();
$watch->Start();
$task = new Task();
$tasks = $task->GetExecTasks();
$taskIds = array_keys($tasks);
$task->UpdateStatus(Task::EXECING, $taskIds);
$thirdAccount = new ThirdAccount();
foreach ($tasks as $id => $item) {
    $type_arr = explode('|', $item['type']);
    if (str_contains($item['msg'], '验证码') || str_contains($item['msg'], 'valCodeError') || $type_arr[0] == 'qzone_simula') {
        if (time() - $item['last_send'] < 10 * 60) {
            continue;
        }
    }
    if (str_contains($item['msg'], '重复发送') || str_contains($item['msg'], '用户调用次数超过限制')) {
        $task->update(array('retry_count' => Task::RETRY_COUNT), array('id' => $id));
        continue;
    }
    $third = $thirdAccount->getThird($item['uid'], $type_arr[0], $type_arr[1]);
    if ($third && $third['valid'] == 1) {
        $api = Factory::CreateAPI2($type_arr[0], $type_arr[1], $third);
        if ($item['cat'] == 'weibo') {
コード例 #4
0
ファイル: users.php プロジェクト: z445056647/phx-svns
$TEMPLATE['title'] = '用户管理';
$TEMPLATE['login_name'] = Passport::GetLoginName();
$TEMPLATE['nav']['users'] = 'current';
switch (strtolower($_GET['action'])) {
    case 'edit':
        $id = intval($_GET['id']);
        $TEMPLATE['data'] = $user->get($id);
        $TEMPLATE['data']['perms'] = unserialize($TEMPLATE['data']['perms']);
        if (Request::IsPost()) {
            $fields = $_POST['f'];
            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);
コード例 #5
0
ファイル: bind.php プロジェクト: z445056647/phx-svns
<?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'];
コード例 #6
0
ファイル: bind.php プロジェクト: z445056647/phx-svns
switch ($api->type) {
    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;
コード例 #7
0
ファイル: task.php プロジェクト: z445056647/phx-svns
 * 管理定时发送任务。立即发送、取消
 * @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']);
            }
            $TEMPLATE['report'] = array();
            $TEMPLATE['report'][$type] = array('id' => $id, 'status' => $ret === true, 'msg' => $ret === true ? '发送成功!<a href="' . $third['url'] . '" target="_blank">查看</a>' : '发送失败:' . $ret);
            $task->UpdateStatus($ret === true ? Task::OK : Task::ERROR, $id, $ret, time());