Exemplo n.º 1
0
 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);
             $third = $thirdAccount->getByType($type_arr[0], $type_arr[1]);
             $api = Factory::CreateAPI2($type_arr[0], $type_arr[1], $third);
             $ret = $api->publish($_POST['title'], $content);
             if ($ret !== true && str_contains($ret, '已过期')) {
                 $thirdAccount->fail($third, $ret);
             }
             $TEMPLATE['report'][$type] = array('status' => $ret === true, 'msg' => $ret === true ? '发送成功!' . ($third['url'] ? '<a href="' . $third['url'] . '" target="_blank">查看</a>' : '') : '发送失败:' . $ret . ' <a href="list_err.php">重新发送</a>');
             $task->AddTask($type, $content, time(), NULL, $ret === true ? Task::OK : Task::ERROR, $ret, 'blog', $_POST['title']);
         }
         $watch->Stop();
         $TEMPLATE['report']['watch'] = array('status' => true, 'msg' => "总耗时:{$watch->getElapsedSeconds()} 秒");
     }