Add data cache

parent c7973e9b
<?php
if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
$logEnabled=true;
$serverEnv="dev";
if($serverEnv!="dev"){
if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
}
require("autoload.php");
if(isset($_GET["q"]) && $_GET["q"]!=""){
......
......@@ -60,15 +60,33 @@ class Core{
}else{//user
$username=$query[0];
error_reporting(E_ERROR | E_PARSE);
$dom = new \PHPHtmlParser\Dom();
$dom->loadFromUrl("http://twitter.com/".$username);
$avatarSrc=$dom->find(".ProfileAvatar-image")[0]->getAttribute("src");
$headerSrc=$dom->find(".ProfileCanopy-headerBg img")[0]->getAttribute("src");
$name=$dom->find(".ProfileHeaderCard-nameLink")[0]->text;
$description=$dom->find(".ProfileHeaderCard-bio")[0]->text;
error_reporting(E_ALL);
if(file_exists("cache/data/".$username.".json")){
$data = json_decode(file_get_contents("cache/data/".$username.".json"));
$avatarSrc=$data->avatarSrc;
$headerSrc=$data->headerSrc;
$name=$data->name;
$description=$data->description;
}else{
error_reporting(E_ERROR | E_PARSE);
$dom = new \PHPHtmlParser\Dom();
$dom->loadFromUrl("http://twitter.com/".$username);
$avatarSrc=$dom->find(".ProfileAvatar-image")[0]->getAttribute("src");
$headerSrc=$dom->find(".ProfileCanopy-headerBg img")[0]->getAttribute("src");
$name=$dom->find(".ProfileHeaderCard-nameLink")[0]->text;
$description=$dom->find(".ProfileHeaderCard-bio")[0]->text;
error_reporting(E_ALL);
//store to json
$json=json_encode(array(
"username" => $username,
"name" => $name,
"description" => $username,
"avatarSrc" => $avatarSrc,
"headerSrc" => $headerSrc,
));
file_put_contents("cache/data/".$username.".json",$json,FILE_USE_INCLUDE_PATH);
}
if($_SERVER["HTTP_ACCEPT"]=="application/activity+json" || $_SERVER["HTTP_ACCEPT"]=="application/json"){
$query[1]="json";
......@@ -155,7 +173,7 @@ class Core{
"sharedInbox" => "https://".$this->subdomain.".activitypub.actor/".$username."/inbox",
),
);*/
header("Content-Type: application/json");
header('Content-type: application/activity+json');
echo(json_encode($activityjson));
break;
case "avatar.jpg" :
......@@ -200,7 +218,7 @@ class Core{
"type" => "OrderedCollection",
"totalItems" => 0,
);
header("Content-Type: application/json");
header('Content-type: application/activity+json');
echo(json_encode($activityjson));
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment