Пример #1
0
        }
        if ($parse["host"] !== "twitter.com") {
            throw new RuntimeException("Host is not twitter.com.", 400);
        }
        if (!isset($parse["path"])) {
            throw new RuntimeException("Path is empty.", 400);
        }
        preg_match("#/[a-zA-Z0-9_]{1,15}/status/([0-9]+)#", $parse["path"], $matches);
        if (!isset($matches[1])) {
            throw new RuntimeException("Please send in the 'https://twitter.com/{sn}/status/{id}' format.", 400);
        }
        $id = $matches[1];
    }
    $conf = config("twitter");
    $TwistOAuth = new TwistOAuth($conf["ck"], $conf["cs"], $conf["ot"], $conf["os"]);
    $SaveTweet = new SaveTweet(config("db"), $TwistOAuth);
    if ($SaveTweet->isRegistered($id)) {
        throw new RuntimeException("This ID is already registered.", 400);
    }
    $result = $SaveTweet->add($id);
    $json = ["status" => "OK.", "id" => $result["id"], "user" => $result["user"], "user_id" => $result["user_id"], "tweet_id" => $result["tweet_id"], "body" => $result["body"]];
} catch (PDOException $e) {
    http_response_code(500);
    $json = ["error" => ["message" => config("debug") ? $e->getMessage() : "DataBase Error.", "code" => 500]];
} catch (TwistException $e) {
    http_response_code(500);
    $json = ["error" => ["message" => config("debug") ? $e->getMessage() : "Twitter API Error.", "code" => 500]];
} catch (RuntimeException $e) {
    $json = ["error" => ["message" => $e->getMessage(), "code" => $e->getCode() === 0 ? 500 : $e->getCode()]];
    if ($e->getCode() !== 0) {
        http_response_code($e->getCode());
Пример #2
0
 /**
  * Test tweetsList()
  *
  * @return void
  */
 public function testTwList()
 {
     $this->assertInstanceOf(PDOStatement::class, $this->SaveTweet->tweetsList());
 }
Пример #3
0
<?php

require_once __DIR__ . "/bootstrap.php";
use HirotoK\SaveTweet\App\SaveTweet;
use HirotoK\SaveTweet\App\Cache;
if (config("https") && !is_https()) {
    header("location: https://" . config("url") . "/show.php");
    exit;
}
header("Content-Type: text/html; charset=utf-8", true);
try {
    $conf = config("twitter");
    $TwistOAuth = new TwistOAuth($conf["ck"], $conf["cs"], $conf["ot"], $conf["os"]);
    $SaveTweet = new SaveTweet(config("db"), $TwistOAuth);
    $Cache = new Cache($TwistOAuth);
    $filter = [];
    $user = filter_input(INPUT_GET, "user");
    if (!empty($user) && is_string($user)) {
        foreach (explode(",", $user) as $sn) {
            $filter[] = $sn;
        }
    }
    $user_ids = [];
    $names = [];
    $create_cache = [];
    foreach ($SaveTweet->tweetsList() as $row) {
        $user_ids[] = $row["user_id"];
    }
    if (count($user_ids) !== 0) {
        $statuses = $TwistOAuth->get("users/lookup", ["user_id" => implode(",", array_values(array_unique($user_ids)))]);
        foreach ($statuses as $status) {