action.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. //ini_set('display_errors', 1);
  3. //ini_set("log_errors", 1);
  4. //error_reporting(1);
  5. ini_set("error_log", "php-error.log");
  6. /* this file handles some actions that are most of the time requested
  7. by the javascript portion of the FE */
  8. /* since most of the time the file is loaded sandalonely, so we have to
  9. include the initializing files if they haven't been included already */
  10. require_once "vendor/simple_html_dom.php";
  11. require_once "settings.php";
  12. require_once "include/init.php";
  13. require_once "include/functions.php";
  14. $srv = $user_settings['instance'];
  15. if (isset($_GET['action']) && $_GET['action'] == "settings"){
  16. //file_put_contents("settings.txt",var_export($_GET,true));
  17. foreach($_GET as $key => $value){
  18. switch($key){
  19. case "explicit":
  20. $user_settings['explicit'] = htmlentities($value);
  21. break;
  22. case "emoji":
  23. $user_settings['emoji'] = intval($value);
  24. break;
  25. case "text":
  26. $user_settings['text'] = ($value == "on" ? "on" : "off");
  27. break;
  28. case "attach":
  29. $user_settings['attach'] = ($value == "on" ? "on" : "off");
  30. break;
  31. case "replies":
  32. $user_settings['replies'] = ($value == "on" ? "on" : "off");
  33. break;
  34. case "setreblog":
  35. $user_settings['reblog'] = ($value == "on" ? "on" : "off");
  36. break;
  37. case "videoloop":
  38. $user_settings['videoloop'] = ($value == "on" ? "on" : "off");
  39. break;
  40. case "theme":
  41. $user_settings['theme'] = sanitize($value);
  42. break;
  43. case "instance":
  44. if (!isset($_COOKIE['token'])){
  45. $user_settings['instance'] = htmlentities($value);
  46. }
  47. break;
  48. case "fg":
  49. $theme['fg'] = sanitize($value);
  50. break;
  51. case "bg":
  52. $theme['bg'] = sanitize($value);
  53. break;
  54. case "tx":
  55. $theme['tx'] = sanitize($value);
  56. break;
  57. case "lc":
  58. $theme['lc'] = sanitize($value);
  59. break;
  60. case "bc":
  61. $theme['bc'] = sanitize($value);
  62. break;
  63. case "br":
  64. $theme['br'] = sanitize($value);
  65. break;
  66. case "bw":
  67. $theme['bw'] = sanitize($value);
  68. break;
  69. }
  70. }
  71. setrawcookie("user_settings",base64_encode(json_encode($user_settings)),time()+60*60*24*30,'/');
  72. setrawcookie("theme",base64_encode(json_encode($theme)),time()+60*60*24*30,'/');
  73. die();
  74. }
  75. $thread = (isset($_GET['thread']) ? htmlentities($_GET['thread']) : false);
  76. $mode = (isset($_GET['mode']) ? htmlentities($_GET['mode']) : false);
  77. $ajax = (isset($_GET['a']) ? true : false);
  78. foreach($_GET as $key => $value){
  79. switch($key){
  80. case "fav":
  81. $result = favourite($value,($mode === 'on' ? true : false));
  82. if ($ajax){
  83. echo $result;
  84. die();
  85. } else {
  86. header("Location: ?thread=".$value);
  87. }
  88. break;
  89. case "reblog":
  90. $result =reblog($value,($mode === 'on' ? true : false));
  91. if ($ajax){
  92. echo $result;
  93. die();
  94. } else {
  95. header("Location: ?thread=".$value);
  96. }
  97. break;
  98. case "mute":
  99. if($thread){
  100. $rel = api_post("statuses/".htmlentities($value)."/".($mode === 'true' ? "" : "un")."mute",array());
  101. echo (isset($rel[0]['muting']) ? "1" : "0" );
  102. } else {
  103. $rel = api_post("accounts/".htmlentities($value)."/".($mode === 'true' ? "" : "un")."mute",array());
  104. echo (isset($rel[0]['muting']) ? "1" : "0" );
  105. }
  106. die();
  107. break;
  108. case "list":
  109. if($mode === 'true'){
  110. $rel = api_post("lists/".htmlentities($value)."/accounts?account_ids[]=".$_GET['user'],array());
  111. var_dump($rel);
  112. } else {
  113. $rel = api_delete("lists/".htmlentities($value)."/accounts?account_ids[]=".$_GET['user'],array());
  114. var_dump($rel);
  115. }
  116. die();
  117. break;
  118. case "block":
  119. $rel = api_post("accounts/".htmlentities($value)."/".($mode === 'true' ? "" : "un")."block",array());
  120. echo (isset($rel[0]['blocking']) ? "1" : "0" );
  121. die();
  122. break;
  123. case "bookmark":
  124. $status = api_get("statuses/".htmlentities($value));
  125. $rel = api_post("statuses/".htmlentities($value)."/".($status['bookmarked'] == 'true' ? "un" : "")."bookmark",array());
  126. die();
  127. break;
  128. case "notif":
  129. echo getnotif(intval($value),(isset($_GET['max']) ? true : false));
  130. die();
  131. break;
  132. case "delete":
  133. echo delpost(htmlentities($value));
  134. die();
  135. break;
  136. case "replies":
  137. $since = (isset($_GET['since']) ? htmlentities($_GET['since']) : false);
  138. foreach(getreplies(htmlentities($value),$since) as $elem){
  139. echo render_reply($elem['content']);
  140. }
  141. die();
  142. break;
  143. case "notes":
  144. $notes = getnotes($value);
  145. foreach ($notes as $note){
  146. echo "<div id='".$note[1]['id']."'>
  147. <a href='?user=".$note[1]['id']."' class='ldr' title='".$note[1]['acct']."'>
  148. <div class='nte' style='background-image:url(".$note[1]['avatar'].");'>
  149. <div class='nte_type' style='background-color:".($note[0] == "fav" ? "red" : "green")."'><span>".($note[0] == "fav" ? "&#xe802;" : "&#xe826;")."</span></div>
  150. </div>
  151. </a>
  152. </div>";
  153. }
  154. die();
  155. break;
  156. case "follow":
  157. $rel = api_post("accounts/".htmlentities($value)."/follow",array());
  158. echo ($rel['following'] == true || $rel['requested'] == true ? "1" : "0" );
  159. die();
  160. break;
  161. case "unfollow":
  162. $rel = api_post("accounts/".htmlentities($value)."/unfollow",array());
  163. echo ($rel['following'] == false ? "1" : "0" );
  164. die();
  165. break;
  166. case "nsfw":
  167. if(in_array($value,$user_settings['nsfw'])){
  168. $key = array_search($value, $user_settings['nsfw']);
  169. unset($user_settings['nsfw'][$key]);
  170. setrawcookie("user_settings",base64_encode(json_encode($user_settings)),time()+60*60*24*30,'/');
  171. } else {
  172. $user_settings['nsfw'][] = htmlentities($value);
  173. setrawcookie("user_settings",base64_encode(json_encode($user_settings)),time()+60*60*24*30,'/');
  174. }
  175. echo "1";
  176. die();
  177. break;
  178. case "hide":
  179. if(!isset($user_settings['hide'])|| !is_array($user_settings['hide'])){
  180. $user_settings['hide'] = array();
  181. }
  182. if(in_array($value,$user_settings['hide'])){
  183. $key = array_search($value, $user_settings['hide']);
  184. unset($user_settings['hide'][$key]);
  185. setrawcookie("user_settings",base64_encode(json_encode($user_settings)),time()+60*60*24*30,'/');
  186. } else {
  187. $user_settings['hide'][] = htmlentities($value);
  188. setrawcookie("user_settings",base64_encode(json_encode($user_settings)),time()+60*60*24*30,'/');
  189. }
  190. echo "1";
  191. die();
  192. break;
  193. case "userinfo":
  194. $info = api_get("accounts/".htmlentities($value));
  195. $rel = api_get("accounts/relationships?id=".htmlentities($value));
  196. $image=imagecreatefromstring(file_get_contents($info['avatar']));
  197. $thumb=imagecreatetruecolor(1,1);
  198. imagecopyresampled($thumb,$image,0,0,0,0,1,1,imagesx($image),imagesy($image));
  199. $mainColor=strtoupper(dechex(imagecolorat($thumb,0,0)));
  200. echo "<div class='userinfo_he' style='background-color:#$mainColor; background-size:cover; background-image:url(" . $info['header_static'] . ");'>
  201. <span style='margin:5px; display:inline-block;'>
  202. <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>
  203. </span>
  204. </div>
  205. <div class='userinfo_co'>
  206. <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>
  207. <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>
  208. <div style='font-weight:normal; font-size:12px; line-height:12px;'>".emojify($info['note'],$info['emojis'],20)."</div><br>
  209. <span style='width:290; height:30px; display:block; margin-top:10px;'>
  210. ".($logedin ? "<span id='".$info['id']."' class='profileButton ".(($rel[0]['following'] || $rel[0]['requested']) ? "unfollow" : "follow" )."'>".($rel[0]['following'] || $rel[0]['requested'] ? "Following" : "Follow" )."</span>" : "")."
  211. <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'>&#xf205;</span>" : "NSFW <span class='fontello'>&#xf204;</span>" )."</span>
  212. </span>
  213. </div>
  214. ";
  215. die();
  216. break;
  217. case "previewpost":
  218. $post = api_get("statuses/".htmlentities($value));
  219. echo "<div class='notifContents' style='max-width:none;'>
  220. <div style='flex: 0 0 60px; background-size:cover; background-image:url(".$post['account']['avatar']."); border-radius:5px;'></div>
  221. <div style='flex: 1; padding-left:5px; padding-right:5px; word-break: break-all; overflow:hidden;'>
  222. <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>
  223. <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>
  224. </div>
  225. ".(!empty($post['media_attachments']) ? "<div style='flex: 0 0 60px; background-size:cover; background-image:url(".$post['media_attachments'][0]['url'].");'></div>" :"")."
  226. </div>";
  227. die();
  228. break;
  229. case "themefile":
  230. //echo $value;
  231. echo themes("get",$value);
  232. die();
  233. break;
  234. case "emoji":
  235. echo emoji_list(sanitize($value));
  236. //die();
  237. break;
  238. }
  239. }
  240. if(isset($_POST['status'])){
  241. if(isset($_POST['scope'])){
  242. switch($_POST['scope']){
  243. case "1":
  244. $scope = "public";
  245. break;
  246. case "2":
  247. $scope = "unlisted";
  248. break;
  249. case "3":
  250. $scope = "private";
  251. break;
  252. case "4":
  253. $scope = "direct";
  254. break;
  255. }
  256. } else {
  257. if (isset($_POST['thread'])){
  258. $result = api_get("statuses/".htmlentities($_POST['thread']));
  259. $scope = $result['visibility'];
  260. } else {
  261. $scope = "public";
  262. }
  263. }
  264. $uploaded = (empty($_POST['uploaded']) ? array() : explode("|",$_POST['uploaded']));
  265. $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);
  266. echo render_reply($reply);
  267. die();
  268. }