Verified Commit f88fc894 authored by David Libeau's avatar David Libeau
Browse files

Add opt-out

parent 07322b2d
<?php
$logEnabled=true;
$logMode="verbose";
$serverEnv="dev";
if($serverEnv!="dev"){
......@@ -26,6 +27,7 @@ if($logEnabled){
foreach ($headers as $header => $value) {
$echolog.="$header: $value\n";
}
$echolog.="Accept: ".$_SERVER["HTTP_ACCEPT"]."\n";
file_put_contents("log/".date("d-m-Y").".txt",date("h:i:sa")." : ".$_SERVER["REQUEST_URI"]."\r".$echolog."\r",FILE_USE_INCLUDE_PATH | FILE_APPEND);
}
......
......@@ -36,7 +36,7 @@ class Core{
}
}
}
if(glob("static/".$staticQuery)){
if(glob("static/".$staticQuery)){ //file_exists ?
$fileToRender="static/".$staticQuery;
}else{
$allFiles=glob("static/".$staticQuery.".*");
......@@ -60,35 +60,47 @@ class Core{
}else{//user
$username=$query[0];
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;
$optoutdb=file_get_contents("optoutdb.txt");
$inoptoutdb=false;
foreach(preg_split("/((\r?\n)|(\r\n?))/", $optoutdb) as $line){
$dbuser=explode(";", $line);
if($dbuser[0]==$username){
$inoptoutdb=true;
}
}
if($inoptoutdb){
exit("This user opted out from this service.");
}else{
error_reporting(E_ERROR | E_PARSE);
$dom = new \PHPHtmlParser\Dom();
$dom->loadFromUrl("http://twitter.com/".$username);
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);
$avatarSrc=$dom->find(".ProfileAvatar-image")[0]->getAttribute("src");
$headerSrc=$dom->find(".ProfileCanopy-headerBg img")[0]->getAttribute("src");
$name=str_replace("&nbsp;","",$dom->find(".ProfileHeaderCard-nameLink")[0]->text(true));
$description=str_replace("&nbsp;","",$dom->find(".ProfileHeaderCard-bio")[0]->text(true));
error_reporting(E_ALL);
//store to json
$json=json_encode(array(
"username" => $username,
"name" => $name,
"description" => $description,
"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"){
if(strpos($_SERVER["HTTP_ACCEPT"], "application/activity+json")!==false || strpos($_SERVER["HTTP_ACCEPT"], "application/json")!==false || strpos($_SERVER["HTTP_ACCEPT"], "application/ld+json")!==false){
$query[1]="json";
}
......@@ -96,10 +108,6 @@ class Core{
ob_start();
include "views/account.php";
echo(ob_get_clean()); //render PHP
/*echo("<h1>".$name."</h1>");
echo("<img src=\"".$username."/avatar.jpg\"/>");
echo("<p><a href=\"https://twitter.com/".$username."\">See @".$username." on Twitter.com</a></p>");$*/
}elseif(sizeof($query)==2){
switch($query[1]){
case "json" :
......@@ -109,7 +117,7 @@ class Core{
"https://w3id.org/security/v1",
),
"id" => "https://".$this->subdomain.".activitypub.actor/".$username,
"type" => "Person",
"type" => "Service",
"following" => "https://".$this->subdomain.".activitypub.actor/".$username."/following",
"followers" => "https://".$this->subdomain.".activitypub.actor/".$username."/followers",
"inbox" => "https://".$this->subdomain.".activitypub.actor/".$username."/inbox",
......@@ -124,6 +132,11 @@ class Core{
"owner" => "https://".$this->subdomain.".activitypub.actor/".$username,
"publicKeyPem" => "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyJAjDVrhKSGRQaG8Z59E\nHB7Q7c58pYOGmEpzV2Vrboi9A0EOOH7qrmVsnuncPOoxd31z3cwAQyCz+WkXVsG5\npUbvG3XjzUQKXSwOUemg8jCJ7/JHrqCpaSX5f4i028F+eNX8yjuYlj208COk37qz\nR96p2Nvzm+3RSodcYIf0qEi2d0x+cmoDSMSf3K/AdkgKIi5IA02kStOAt1bXnpeA\nhw0bdMGjq+z6B083zfZKi4Ya6s51fh/kV/dB/K4VxNsKaMXUhwk/558x5v43OiuO\ntBP4bbJwJm8txCt2eG3WxoDxbZvRbenp4DK4P6F0JLi42oVRWnGTcTKzt0F3KK4d\njQIDAQAB\n-----END PUBLIC KEY-----\n",
),
"manuallyApprovesFollowers"=>true,
"attachment"=> array(array(
"type"=>"PropertyValue",
"name"=>"Direct link",
"value"=>"<a href=\"https://twitter.com/".$username."\" rel=\"noopener noreferrer\" >https://twitter.com/".$username."</a>")),
"icon" => array(
"type" => "Image",
"mediaType" => "image/jpeg",
......@@ -138,43 +151,8 @@ class Core{
"sharedInbox" => "https://".$this->subdomain.".activitypub.actor/".$username."/inbox",
),
);
/*$activityjson=array(
"@context" => array(
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
),
"id" => "https://".$this->subdomain.".activitypub.actor/".$username,
"type" => "Person",
/*"following" => "https://".$this->subdomain.".activitypub.actor/".$username."/following",
"followers" => "https://".$this->subdomain.".activitypub.actor/".$username."/followers",
"outbox" => "https://".$this->subdomain.".activitypub.actor/".$username."/outbox",
"inbox" => "https://".$this->subdomain.".activitypub.actor/".$username."/inbox",
"preferredUsername" => "".$username,
"name" => "".$name,
"summary" => "<p>".$description."</p>",
"manuallyApprovesFollowers" => true,
"url" => "https://".$this->subdomain.".activitypub.actor/".$username,
"publicKey" => array(
"id" => "https://".$this->subdomain.".activitypub.actor/".$username."#main-key",
"owner" => "https://".$this->subdomain.".activitypub.actor/".$username,
"publicKeyPem" => "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyJAjDVrhKSGRQaG8Z59E\nHB7Q7c58pYOGmEpzV2Vrboi9A0EOOH7qrmVsnuncPOoxd31z3cwAQyCz+WkXVsG5\npUbvG3XjzUQKXSwOUemg8jCJ7/JHrqCpaSX5f4i028F+eNX8yjuYlj208COk37qz\nR96p2Nvzm+3RSodcYIf0qEi2d0x+cmoDSMSf3K/AdkgKIi5IA02kStOAt1bXnpeA\nhw0bdMGjq+z6B083zfZKi4Ya6s51fh/kV/dB/K4VxNsKaMXUhwk/558x5v43OiuO\ntBP4bbJwJm8txCt2eG3WxoDxbZvRbenp4DK4P6F0JLi42oVRWnGTcTKzt0F3KK4d\njQIDAQAB\n-----END PUBLIC KEY-----\n",
),
"icon" => array(
"type" => "Image",
"mediaType" => "image/jpeg",
"url" => "https://".$this->subdomain.".activitypub.actor/".$username."/avatar.jpg",
),
"image" => array(
"type" => "Image",
"mediaType" => "image/jpeg",
"url" => "https://".$this->subdomain.".activitypub.actor/".$username."/header.jpg",
),
/*"endpoints" => array(
"sharedInbox" => "https://".$this->subdomain.".activitypub.actor/".$username."/inbox",
),
);*/
header('Content-type: application/activity+json');
echo(json_encode($activityjson));
$this->echoWithLog(json_encode($activityjson,JSON_UNESCAPED_SLASHES));
break;
case "avatar.jpg" :
if(file_exists("cache/avatar/".$username.".jpg")){
......@@ -219,7 +197,7 @@ class Core{
"totalItems" => 0,
);
header('Content-type: application/activity+json');
echo(json_encode($activityjson));
$this->echoWithLog(json_encode($activityjson,JSON_UNESCAPED_SLASHES));
break;
}
}
......@@ -265,7 +243,7 @@ class Core{
$domain=$account[1];
if($domain==$this->subdomain.".activitypub.actor"){
header("Content-type: application/json;charset=utf-8");
echo(json_encode(array(
$this->echoWithLog(json_encode(array(
"subject" => join(":", $query),
"links" => array(array(
"rel" => "self",
......@@ -274,12 +252,17 @@ class Core{
)),
"aliases" => array(
"https://".$this->subdomain.".activitypub.actor/".$username,
"https://".$this->subdomain.".activitypub.actor/".$username."/json"
),
)));
),JSON_UNESCAPED_SLASHES));
}else{
$this->error("404");
}
}
}
public function echoWithLog($string){
echo($string);
file_put_contents("log/".date("d-m-Y").".txt",date("h:i:sa")." : ".$_SERVER["REQUEST_URI"]."\r".$string."\r",FILE_USE_INCLUDE_PATH | FILE_APPEND);
}
}
\ No newline at end of file
body{
font-family: sans-serif;
background-color: #fcfcfc;
}
.content{
width: 80vw;
margin: auto;
}
img{
max-width: 100%;
}
header{
header {
margin-top: 20px;
line-height: 0;
border: 1px solid #eaeaea;
border-radius: 3vw;
border-radius: 2.5vw;
overflow: hidden;
-webkit-box-shadow: 0 10px 40px -5px rgba(0,0,0,0.05);
box-shadow: 0 10px 40px -5px rgba(0,0,0,0.05);
-webkit-box-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.05);
box-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.05);
}
/*header:focus{
-webkit-box-shadow: 0 10px 40px -5px rgba(0,0,0,0.1);
box-shadow: 0 10px 40px -5px rgba(0,0,0,0.1);
}*/
header>.footer{
header > .footer {
position: relative;
background-color: white;
padding: 20px;
padding-left: calc(6vw + 15vw);
padding-top: 2vw;
line-height: normal;
}
.banner{
.banner {
min-height: 12vw;
background-color: #1da1f2;
}
.avatar{
.avatar {
position: absolute;
left: 3vw;
top: calc(-8.9vw - 5px);
width: 15vw;
height: 15vw;
border-radius: 100%;
-webkit-box-shadow: 0 0 20px 0 rgba(0,0,0,0.1);
box-shadow: 0 0 20px 0 rgba(0,0,0,0.1);
-webkit-box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
border: 5px solid white;
background-color: #fcfcfc;
}
header h1, header h2{
header h1,
header h2 {
margin: 10px 0;
}
header h1{
header h1 {
font-size: 2.5em;
}
header h2{
color:#8e8e8e;
header h2 {
color: #8e8e8e;
}
header>div>.externallink{
header > div > .externallink {
position: absolute;
right: 3vw;
top: 3vw;
top: 2vw;
padding: 10px 15px;
color: white;
text-decoration: none;
......@@ -68,7 +66,8 @@ header>div>.externallink{
border: 1px solid #6b6b6b;
border-radius: 4px;
}
header>div>.externallink:hover{
header > div > .externallink:hover {
color: #eaeaea;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
......@@ -76,46 +75,116 @@ header>div>.externallink:hover{
-o-transition: all 0.2s ease;
transition: all 0.2s ease;
}
header>div>.externallink:focus{
transform: translate(0,1px);
header > div > .externallink:focus {
transform: translate(0, 1px);
}
header>div>.externallink>.fa-external-link{
header > div > .externallink > .fa-external-link {
top: 3px;
position: relative;
margin-left: 3px;
font-size: 1.2em;
}
@media only screen and (max-width: 1000px) {
.content{
width: 95vw;
}
}
@media only screen and (max-width: 700px) {
header>.footer{
padding-top: 8vw!important;
header > .footer {
padding-top: 8vw !important;
padding-left: 3vw;
padding-bottom: 3vw;
padding-right: 3vw;
}
header>div>.externallink{
header > div > .externallink {
display: block;
position: relative;
right: 0;
top: 0;
margin: 5px 0;
}
header>div>.externallink>.fa-external-link{
header > div > .externallink > .fa-external-link {
float: right;
}
}
header .optionmenu{
#optionmenu {
position: absolute;
right: 1.5vw;
top: 3vw;
top: 2vw;
padding: 10px 0;
font-size: 2em;
color: #8e8e8e;
cursor: pointer;
}
#optionmenu:hover {
color: black;
}
#optionmenu:active {
color: #8e8e8e;
}
#optionmenu > input {
display: none;
}
#optionmenu > ul {
display: none;
position: absolute;
top: 0;
right: 20px;
min-width: 100px;
width: 12vw;
margin: 0;
padding: 0;
list-style: none;
font-size: 16px;
background-color: white;
border: 1px solid #eaeaea;
border-radius: 3px;
overflow: hidden;
-webkit-box-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.05);
box-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.05);
}
#optionmenu > ul:before {
content: "";
position: absolute;
left: 100%;
top: 26px;
width: 0;
height: 0;
border-top: 8px solid transparent;
border-right: 10px solid white;
border-bottom: 8px solid transparent;
}
#optionmenu > ul > li {
padding: 5px;
}
#optionmenu > input:checked + ul {
display: block;
}
main {
color: #8e8e8e;
font-style: italic;
}
main a {
color: #6a6a6a;
text-decoration: none;
}
main a:hover {
text-decoration: underline;
}
main a:focus {
text-decoration: none;
}
main .code {
background-color: #8e8e8e;
}
\ No newline at end of file
body{
font-family: sans-serif;
background-color: #fcfcfc;
}
.content{
width: 80vw;
margin: auto;
}
img{
max-width: 100%;
}
@media only screen and (max-width: 1000px) {
.content{
width: 95vw;
}
}
main {
padding: 2vw;
}
a{
text-decoration: none;
color: #8e8e8e;
}
a:hover{
text-decoration: underline;
}
a:focus{
text-decoration: none;
}
.code {
background-color: #454545;
border: 1px solid #eaeaea;
border-radius: 5px;
color: white;
font-style: normal;
}
span.code {
display: inline-block;
font-weight: bold;
padding: 5px;
}
pre.code{
padding: 15px;
}
input[type="text"] {
padding: 7px;
font-size: 0.8em;
border-radius: 5px;
border: 1px solid #eaeaea;
}
button, [type="submit"] {
padding: 7px;
font-size: 0.8em;
border-radius: 5px;
border: 1px solid white;
background-color: #eaeaea;
cursor: pointer;
}
button:hover, [type="submit"]:hover{
border: 1px solid #454545;
}
button:focus, [type="submit"]:focus{
border: 1px solid #eaeaea;
}
\ No newline at end of file
header{
margin-top: 20px;
line-height: 0;
border: 1px solid #eaeaea;
border-radius: 2.5vw;
overflow: hidden;
-webkit-box-shadow: 0 10px 40px -5px rgba(0,0,0,0.05);
box-shadow: 0 10px 40px -5px rgba(0,0,0,0.05);
padding: 5vw;
background-color: white;
text-align: center;
}
header>p{
color: #8e8e8e;
margin: 2vw 0;
}
header>h1:last-child{
color: #1da1f2;
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="fr">
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Activitypub.actor</title>
<title>ActivityPub.Actor</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="theme-color" content="#0070C0">
<meta name="theme-color" content="#1da1f2">
<meta property="og:title" content="Activitypub.actor" />
<link rel="stylesheet" href="https://dav.li/forkawesome/1.0.11/css/fork-awesome.min.css"/>
<link rel="stylesheet" href="/general.css" type="text/css"/>
<link rel="stylesheet" href="/index.css" type="text/css"/>
</head>
<body>
<h1>Hello, world</h1>
<p>WIP.</p>
<div class="content">
<header>
<h1>ActivityPub.Actor</h1>
<p><i class="fa fa-heart" aria-hidden="true"></i></p>
<h1>Twitter.com</h1>
</header>
<main>
<p>WIP (beta) - <a href="https://framagit.org/DavidLibeau/activitypubactor" target="_blank">Open source</a> - <a href="https://mastodon.xyz/@David" target="_blank">Dev contact</a></p>
</main>
</div>
</body>
</html>
header {
margin-top: 20px;
padding: 5vw;
background-color: white;
text-align: center;
border-radius: 2.5vw;
border: 1px solid #eaeaea;
-webkit-box-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.05);
box-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.05);
overflow: hidden;
}
header > p {
color: #8e8e8e;
margin-top: 40px;
}
#services {
position: relative;
display: grid;
grid-template-columns: repeat(auto-fill, calc(33% - 7.5px));
grid-gap: 15px;
justify-content: space-between;
list-style: none;
margin: 0 -2vw;
padding: 0;
z-index: 9;
}
@media only screen and (max-width: 850px) {
#services {
grid-template-columns: repeat(auto-fill, calc(50% - 7.5px));
}
}
@media only screen and (max-width: 550px) {
#services {
grid-template-columns: repeat(auto-fill, 100%);
}
}
#services > li {
display: inline-block;
position: relative;
background-color: white;
border-radius: 1vw;
border: 1px solid #eaeaea;
-webkit-box-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.05);
box-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.05);
text-overflow: ellipsis;
overflow: hidden;
}