123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- <?php
- //ini_set('display_errors', 1);
- //ini_set("log_errors", 1);
- //error_reporting(1);
- ini_set("error_log", "php-error.log");
- /* this file handles some actions that are most of the time requested
- by the javascript portion of the FE */
- /* since most of the time the file is loaded sandalonely, so we have to
- include the initializing files if they haven't been included already */
- require_once "vendor/simple_html_dom.php";
- require_once "settings.php";
- require_once "include/init.php";
- require_once "include/functions.php";
- $srv = $user_settings['instance'];
- if (isset($_POST['action']) && $_POST['action'] == "account"){
- if(!empty($_FILES["avatar"]["name"])){
- $ext = strtolower(end(explode('.', $_FILES["avatar"]['name'])));
- if(in_array($ext,array("jpg","jpeg","gif","png"))){
- $file_name = time().mt_rand(100,199).".".$ext;
- $file_tmp = $_FILES["avatar"]['tmp_name'];
- move_uploaded_file($file_tmp, $file_name);
- upload_profile($file_name,'avatar');
- unlink($file_name);
- } else {
- unlink($_FILES["avatar"]['tmp_name']);
- }
-
- $info = api_get("accounts/verify_credentials");
- $cookie[$index]['avatar'] = $info['avatar'];
- setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
-
- }
- if(!empty($_FILES["header"]["name"])){
- $ext = strtolower(end(explode('.', $_FILES["header"]['name'])));
- if(in_array($ext,array("jpg","jpeg","gif","png"))){
- $file_name = time().mt_rand(100,199).".".$ext;
- $file_tmp = $_FILES["header"]['tmp_name'];
- move_uploaded_file($file_tmp, $file_name);
- upload_profile($file_name,'header');
- unlink($file_name);
- } else {
- unlink($_FILES["header"]['tmp_name']);
- }
- }
-
- foreach($_POST as $key => $value){
- switch($key){
- case "username":
- api_patch("accounts/update_credentials",array('display_name'=>$value));
- break;
-
- case "bio":
- api_patch("accounts/update_credentials",array('note'=>$value));
- break;
- }
- }
- header("location: ./?page=settings");
- }
- if (isset($_POST['action']) && $_POST['action'] == "settings"){
- foreach($_POST as $key => $value){
- switch($key){
- case "explicit":
- $cookie[$index]['explicit'] = htmlentities($value);
- break;
-
- case "unrollcw":
- $cookie[$index]['unrollcw'] = htmlentities($value);
- break;
-
- /*
- case "emoji":
- $cookie[$index]['emoji'] = intval($value);
- break;
- */
-
- case "defscope":
- $cookie[$index]['defscope'] = intval($value);
- break;
-
- case "text":
- $cookie[$index]['text'] = ($value == "on" ? "on" : "off");
- break;
-
- case "attach":
- $cookie[$index]['attach'] = ($value == "on" ? "on" : "off");
- break;
-
- case "replies":
- $cookie[$index]['replies'] = ($value == "on" ? "on" : "off");
- break;
-
- case "theme":
- $cookie[$index]['theme'] = sanitize($value);
- break;
- case "notif":
- $cookie[$index]['notif'] = "";
- $cookie[$index]['notif'] .= (isset($value['fav']) ? "1" : "0");
- $cookie[$index]['notif'] .= (isset($value['rt']) ? "1" : "0");
- $cookie[$index]['notif'] .= (isset($value['mnt']) ? "1" : "0");
- $cookie[$index]['notif'] .= (isset($value['follow']) ? "1" : "0");
- break;
- case "videoloop":
- $cookie[$index]['videoloop'] = ($value == "on" ? "on" : "off");
- break;
-
- case "mute":
- $cookie[$index]['mute'] = ($value == "on" ? "on" : "off");
- break;
-
- case "embyt":
- $cookie[$index]['embyt'] = ($value == "on" ? "on" : "off");
- break;
-
- case "linkpv":
- $cookie[$index]['linkpv'] = ($value == "on" ? "on" : "off");
- break;
-
- case "invidious":
- $cookie[$index]['invidious'] = (empty($value) ? "" : sanitize($value));
- break;
-
- case "teddit":
- $cookie[$index]['teddit'] = (empty($value) ? "" : sanitize($value));
- break;
-
- case "nitter":
- $cookie[$index]['nitter'] = (empty($value) ? "" : sanitize($value));
- break;
-
- case "theme":
- $cookie[$index]['theme'] = sanitize($value);
- break;
-
- /*
- case "instance":
- if (!isset($_COOKIE['token'])){
- $cookie[$index]['instance'] = htmlentities($value);
- }
- break;
- */
-
- case "mtwords":
- $cookie[$index]['mtwords'] = array();
- $mtwords = explode("\n",$value);
- foreach ($mtwords as $word){
- $cookie[$index]['mtwords'][] = sanitize($word);
- }
- break;
-
- case "fhtags":
- $cookie[$index]['fhtags'] = array();
- $fhtags = explode("\n",$value);
- foreach ($fhtags as $word){
- $cookie[$index]['fhtags'][] = sanitize($word);
- }
- break;
-
- case "fg":
- $theme['fg'] = sanitize($value);
- break;
-
- case "bg":
- $theme['bg'] = sanitize($value);
- break;
-
- case "tx":
- $theme['tx'] = sanitize($value);
- break;
-
- case "lc":
- $theme['lc'] = sanitize($value);
- break;
- case "bc":
- $theme['bc'] = sanitize($value);
- break;
- case "br":
- $theme['br'] = sanitize($value);
- break;
- case "bw":
- $theme['bw'] = sanitize($value);
- break;
- case "dr":
- $theme['dr'] = sanitize($value);
- break;
- }
- }
-
- setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
- setrawcookie("theme",base64_encode(json_encode($theme)),time()+60*60*24*30,'/');
-
- header("location: ./?page=settings");
- }
- $thread = (isset($_GET['thread']) ? htmlentities($_GET['thread']) : false);
- $mode = (isset($_GET['mode']) ? htmlentities($_GET['mode']) : false);
- $ajax = (isset($_GET['a']) ? true : false);
- foreach($_GET as $key => $value){
- switch($key){
-
- case "info":
- echo json_encode(array($token,$user_settings['instance']));
- break;
-
- case "vote":
- $elem = array();
- $elem['poll'] = json_decode(vote($value,$_GET['choices']),true);
- //var_dump($_GET['choices']);
- echo renderPoll($elem);
- break;
-
- case "fav":
- $result = favourite($value,($mode === 'on' ? true : false));
- if ($ajax){
- echo $result;
- die();
- } else {
- header("Location: ?thread=".$value);
- }
- break;
-
- case "reblog":
- $result =reblog($value,($mode === 'on' ? true : false));
- if ($ajax){
- echo $result;
- die();
- } else {
- header("Location: ?thread=".$value);
- }
- break;
-
- case "mute":
- if($thread){
- $rel = api_post("statuses/".htmlentities($value)."/".($mode === 'true' ? "" : "un")."mute",array());
- echo (isset($rel[0]['muting']) ? "1" : "0" );
- } else {
- $rel = api_post("accounts/".htmlentities($value)."/".($mode === 'true' ? "" : "un")."mute",array());
- echo (isset($rel[0]['muting']) ? "1" : "0" );
- }
- die();
- break;
-
- case "softmute":
- if (!isset($user_settings['softmute'])){
- $user_settings['softmute'] = array();
- $cookie[$index]['softmute'] = array();
- }
-
- $user_settings['softmute'][] = sanitize($value);
- $cookie[$index]['softmute'] = $user_settings['softmute'];
- setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
- echo "1";
- die();
- break;
-
-
- case "list":
- if($mode === 'true'){
- $rel = api_post("lists/".htmlentities($value)."/accounts?account_ids[]=".$_GET['user'],array());
- var_dump($rel);
- } else {
- $rel = api_delete("lists/".htmlentities($value)."/accounts?account_ids[]=".$_GET['user'],array());
- var_dump($rel);
- }
- die();
- break;
-
- case "listdelete":
- $rel = api_delete("lists/".htmlentities($value),array());
- die();
- break;
-
- case "softmutedelete":
- $key = array_search(sanitize($value),$user_settings['softmute']);
- unset($user_settings['softmute'][$key]);
- unset($cookie[$index]['softmute'][$key]);
- setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
- die();
- break;
-
- case "listnew":
- $rel = api_post("lists/",array("title" => htmlentities($value)));
- die();
- break;
-
- case "block":
- $rel = api_post("accounts/".htmlentities($value)."/".($mode === 'true' ? "" : "un")."block",array());
- echo (isset($rel[0]['blocking']) ? "1" : "0" );
- die();
- break;
-
- case "bookmark":
- $status = api_get("statuses/".htmlentities($value));
- $rel = api_post("statuses/".htmlentities($value)."/".($status['bookmarked'] == 'true' ? "un" : "")."bookmark",array());
- die();
- break;
-
- case "notif":
-
- echo getnotif(intval($value),(isset($_GET['max']) ? true : false));
- die();
- break;
-
- case "delete":
- echo delpost(htmlentities($value));
- die();
- break;
-
- case "replies":
- $since = (isset($_GET['since']) ? htmlentities($_GET['since']) : false);
- foreach(getreplies(htmlentities($value),$since) as $elem){
- echo render_reply($elem['content']);
- }
- die();
- break;
-
- case "notes":
- $notes = getnotes($value);
- foreach ($notes as $note){
- echo "<div id='".$note[1]['id']."'>
- <a href='?user=".$note[1]['id']."' class='ldr' title='".$note[1]['acct']."'>
- <div class='nte' style='background-image:url(".$note[1]['avatar'].");'>
- <div class='nte_type' style='background-color:".($note[0] == "fav" ? "red" : "green")."'><span>".($note[0] == "fav" ? "" : "")."</span></div>
- </div>
- </a>
- </div>";
- }
- die();
- break;
-
- case "follow":
- $rel = api_post("accounts/".htmlentities($value)."/follow",array());
- echo ($rel['following'] == true || $rel['requested'] == true ? "1" : "0" );
- die();
- break;
-
- case "unfollow":
- $rel = api_post("accounts/".htmlentities($value)."/unfollow",array());
- echo ($rel['following'] == false ? "1" : "0" );
- die();
- break;
-
- case "nsfw":
- if(in_array($value,$user_settings['nsfw'])){
- $key = array_search($value, $user_settings['nsfw']);
- unset($user_settings['nsfw'][$key]);
- $cookie[$index]['nsfw'] = $user_settings['nsfw'];
- setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
- } else {
- $user_settings['nsfw'][] = htmlentities($value);
- $cookie[$index]['nsfw'] = $user_settings['nsfw'];
- setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
- }
- echo "1";
- die();
- break;
-
- case "hide":
- if(!isset($user_settings['hide'])|| !is_array($user_settings['hide'])){
- $user_settings['hide'] = array();
- }
- if(in_array($value,$user_settings['hide'])){
- $key = array_search($value, $user_settings['hide']);
- unset($user_settings['hide'][$key]);
- $cookie[$index]['hide'] = $user_settings['hide'];
- setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
- } else {
- $user_settings['hide'][] = htmlentities($value);
- $cookie[$index]['hide'] = $user_settings['hide'];
- setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
- }
- echo "1";
- die();
- break;
-
- case "userinfo":
- $info = api_get("accounts/".htmlentities($value));
- $rel = api_get("accounts/relationships?id=".htmlentities($value));
- /*
- $photos = api_get("accounts/".htmlentities($value)."/statuses?only_media=true&limit=5&exclude_reblogs=true");
- $photo = array();
- $c = 0;
- if (!empty($photos)){
- foreach ($photos as $elem){
- if ($elem['media_attachments'][0]['type'] == "image"){
- $photo[$c]['url'] = $elem['media_attachments'][0]['url'];
- if ($elem['sensitive'] == true){
- $photo[$c]['s'] = true;
- }
- $c++;
- }
- if ($c == 3){
- break;
- }
- }
- }
- */
-
- echo "<div class='userinfo_he' style='background-color:#".averageColor($info['avatar'])."; background-size:cover;" . (!empty($info['header']) ? "background-image:url(".$info['header'].");" : "") . "'>
- <span style='margin:5px; display:inline-block;'>
- <a href='".$info['url']."' target='_blank' class='external' style='font-weight:bold; font-size:13px; text-decoration:none; color: white; text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;'>".$info['acct']."</a>
- </span>
- </div>
- <div class='userinfo_co'>
- <div class='avatar' style='position: absolute; left:35%; top:-60px; display:inline-block; margin:0px; background-color:white; background-image:url(" . $info['avatar'] . "); text-align:center; border:3px solid white; border-radius:10px; clear:both;'></div>
- <div style='font-weight:bold; padding-top:30px; display:block;'><a href='?user=".$info['id']."' class='link ldr' style='font-size:15px;'>".emojify($info['display_name'],$info['emojis'],20)."</a></div><br>
- <div style='font-weight:normal; font-size:12px; line-height:12px;'>".emojify($info['note'],$info['emojis'],20)."</div><br>
- ".($rel[0]['followed_by'] ? "<p class='link' style='font-weight:normal; font-size:12px; line-height:12px;'><span class='fontello link'></span> Follows You</p>" : "")."
- <span style='width:290; height:30px; display:block; margin-top:10px;'>
- ".($logedin ? "<span id='".$info['id']."' class='profileButton ".(($rel[0]['following'] || $rel[0]['requested']) ? "unfollow" : "follow" )."'>".($rel[0]['following'] || $rel[0]['requested'] ? "Following" : "Follow" )."</span>" : "")."
- <span id='".$info['id']."' class='profileButton ".(in_array($info['id'],$user_settings['nsfw']) ? "unnsfw" : "nsfw" )."'>".(in_array($info['id'],$user_settings['nsfw']) ? "NSFW <span class='fontello'></span>" : "NSFW <span class='fontello'></span>" )."</span>
- ".($logedin ? "<span id='" . $info['id'] . "' class='profileButton " . ($rel[0]['muting'] ? "un" : "") . "mute'>" . ($rel[0]['muting'] ? " Unmute" : " Mute") . "</span>" : "")."<br>
- </span>
- <div style='display:flex; width:280px'>";
- /*
- foreach ($photo as $elem){
- echo "<div style='overflow:hidden; display:block; height:90px; flex:1; background-image:url(\"".$elem['url']."\"); ".(isset($elem['s']) ? "filter: blur(5px);" : "")." background-size:cover; margin:2px;'></div>";
- }
- */
- echo "</div>
- </div>
- ";
- die();
- break;
-
- case "previewpost":
- $post = api_get("statuses/".htmlentities($value));
- echo "<div class='notifContents' style='max-width:none;'>
- <div style='flex: 0 0 60px; background-size:cover; background-image:url(".$post['account']['avatar']."); border-radius:5px;'></div>
- <div style='flex: 1; padding-left:5px; padding-right:5px; word-break: break-all; overflow:hidden;'>
- <span><span style='font-size:12px; font-weight:bold;'><a class='link' style='font-size:12px;' href='?user=9hwsQhjN9oox1iSfK4'>".emojify($post['account']['display_name'],$post['account']['emojis'],20)."</a></span></span>
- <a style='text-decoration:none;' class='ldr' href='?thread=9nngbBWBRHvILwEoF6' target='_blank'><span style='display:block; opacity:1; font-size:10px; line-height:12px;'>".emojify(strip_tags($post['content'],'<br>'),$post['emojis'],20)."</span></a>
- </div>
- ".(!empty($post['media_attachments']) ? "<div style='flex: 0 0 60px; background-size:cover; background-image:url(".$post['media_attachments'][0]['url'].");'></div>" :"")."
- </div>";
- die();
- break;
-
-
- case "previewurl":
- $url = base64_decode($value);
- $graph = getOgTags(file_get_contents(trim($url),false));
- if (empty($graph)){
- echo "empty";
- die();
- }
-
- $desc = (isset($graph['description']) ? $graph['description'] : $graph['title']);
-
-
- echo "<div class='notifContents' style='max-width:none;'>
- <div style='flex: 0 0 60px; background-size:cover; background-image:url(".$graph['image']."); border-radius:5px;'></div>
- <div style='flex: 1; padding-left:5px; padding-right:5px; word-break: break-all; overflow:hidden;'>
- <a style='text-decoration:none;' class='ldr' href='".parse_url($url)."' target='_blank'><b><span style='display:block; opacity:1; font-size:10px; line-height:12px;'>".$graph['title']."</span></b></a><span style='font-size:12px !important; line-height:12px !important;'>".$graph['description']."</span>
- </div>
- </div>";
-
-
-
- //var_dump($graph);
- /*
- if (isset($graph['description'])){
- echo "<div style='display:flex;' class='flex'>
- <a href='$url' target='_blank'><div style='min-width:100px; min-height:100px; background-size:cover; background-image:url(".$graph['image'].");'></div></a>
- <div style='padding:10px;'>
- <span class='flex_title'><a href='$url' target='_blank'>".$graph['title']."</a></span>
- <span class='flex_host'>".parse_url($url)['host']."</span>
- <span class='flex_description'>".nl2br($graph['description'])."</span>
- </div>
- </div>
- ";
- }*/
- die();
- break;
- case "themefile":
- echo themes("get",$value);
- die();
- break;
-
- case "themename":
- echo $user_settings['theme'];
- die();
- break;
-
- case "emoji":
- echo emoji_list(sanitize($value));
- break;
- case "contact":
- echo contact_search(sanitize($value));
- break;
- }
- }
- if(isset($_POST['status'])){
-
- if(isset($_POST['scope'])){
- switch($_POST['scope']){
- case "1":
- $scope = "public";
- break;
-
- case "2":
- $scope = "unlisted";
- break;
-
- case "3":
- $scope = "private";
- break;
-
- case "4":
- $scope = "direct";
- break;
- }
- } else {
- if (isset($_POST['thread'])){
- $result = api_get("statuses/".htmlentities($_POST['thread']));
- $scope = $result['visibility'];
- } else {
- $scope = "public";
- }
- }
-
- $uploaded = (empty($_POST['uploaded']) ? array() : explode("|",$_POST['uploaded']));
- $reply = json_decode(sendpost(trim($_POST['status']),$uploaded,$_POST['thread'],false,$scope,(isset($_POST['sensitive']) ? $_POST['sensitive'] : false),(isset($_POST['spoiler']) && $_POST['spoiler'] != 'Title (optional)' ? $_POST['spoiler'] : false)),true);
- echo render_reply($reply);
- die();
- }
|