action.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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($_POST['action']) && $_POST['action'] == "settings"){
  16. if(!empty($_FILES["avatar"]["name"])){
  17. $ext = strtolower(end(explode('.', $_FILES["avatar"]['name'])));
  18. if(in_array($ext,array("jpg","jpeg","gif","png"))){
  19. $file_name = time().mt_rand(100,199).".".$ext;
  20. $file_tmp = $_FILES["avatar"]['tmp_name'];
  21. move_uploaded_file($file_tmp, $file_name);
  22. upload_profile($file_name,'avatar');
  23. unlink($file_name);
  24. } else {
  25. unlink($_FILES["avatar"]['tmp_name']);
  26. }
  27. }
  28. if(!empty($_FILES["header"]["name"])){
  29. $ext = strtolower(end(explode('.', $_FILES["header"]['name'])));
  30. if(in_array($ext,array("jpg","jpeg","gif","png"))){
  31. $file_name = time().mt_rand(100,199).".".$ext;
  32. $file_tmp = $_FILES["header"]['tmp_name'];
  33. move_uploaded_file($file_tmp, $file_name);
  34. upload_profile($file_name,'header');
  35. unlink($file_name);
  36. } else {
  37. unlink($_FILES["header"]['tmp_name']);
  38. }
  39. }
  40. foreach($_POST as $key => $value){
  41. switch($key){
  42. case "username":
  43. api_patch("accounts/update_credentials",array('display_name'=>$value));
  44. break;
  45. case "bio":
  46. api_patch("accounts/update_credentials",array('note'=>$value));
  47. break;
  48. case "explicit":
  49. $cookie[$index]['explicit'] = htmlentities($value);
  50. break;
  51. case "unrollcw":
  52. $cookie[$index]['unrollcw'] = htmlentities($value);
  53. break;
  54. case "emoji":
  55. $cookie[$index]['emoji'] = intval($value);
  56. break;
  57. case "defscope":
  58. $cookie[$index]['defscope'] = intval($value);
  59. break;
  60. case "text":
  61. $cookie[$index]['text'] = ($value == "on" ? "on" : "off");
  62. break;
  63. case "attach":
  64. $cookie[$index]['attach'] = ($value == "on" ? "on" : "off");
  65. break;
  66. case "replies":
  67. $cookie[$index]['replies'] = ($value == "on" ? "on" : "off");
  68. break;
  69. case "theme":
  70. $cookie[$index]['theme'] = sanitize($value);
  71. break;
  72. case "notif":
  73. $cookie[$index]['notif'] = "";
  74. $cookie[$index]['notif'] .= (isset($value['fav']) ? "1" : "0");
  75. $cookie[$index]['notif'] .= (isset($value['rt']) ? "1" : "0");
  76. $cookie[$index]['notif'] .= (isset($value['mnt']) ? "1" : "0");
  77. $cookie[$index]['notif'] .= (isset($value['follow']) ? "1" : "0");
  78. break;
  79. case "videoloop":
  80. $cookie[$index]['videoloop'] = ($value == "on" ? "on" : "off");
  81. break;
  82. case "theme":
  83. $cookie[$index]['theme'] = sanitize($value);
  84. break;
  85. case "instance":
  86. if (!isset($_COOKIE['token'])){
  87. $cookie[$index]['instance'] = htmlentities($value);
  88. }
  89. break;
  90. case "mtwords":
  91. $cookie[$index]['mtwords'] = array();
  92. $mtwords = explode("\n",$value);
  93. foreach ($mtwords as $word){
  94. $cookie[$index]['mtwords'][] = sanitize($word);
  95. }
  96. break;
  97. case "fhtags":
  98. $cookie[$index]['fhtags'] = array();
  99. $fhtags = explode("\n",$value);
  100. foreach ($fhtags as $word){
  101. $cookie[$index]['fhtags'][] = sanitize($word);
  102. }
  103. break;
  104. case "fg":
  105. $theme['fg'] = sanitize($value);
  106. break;
  107. case "bg":
  108. $theme['bg'] = sanitize($value);
  109. break;
  110. case "tx":
  111. $theme['tx'] = sanitize($value);
  112. break;
  113. case "lc":
  114. $theme['lc'] = sanitize($value);
  115. break;
  116. case "bc":
  117. $theme['bc'] = sanitize($value);
  118. break;
  119. case "br":
  120. $theme['br'] = sanitize($value);
  121. break;
  122. case "bw":
  123. $theme['bw'] = sanitize($value);
  124. break;
  125. case "dr":
  126. $theme['dr'] = sanitize($value);
  127. break;
  128. }
  129. }
  130. setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
  131. setrawcookie("theme",base64_encode(json_encode($theme)),time()+60*60*24*30,'/');
  132. header("location: ./?page=settings");
  133. }
  134. $thread = (isset($_GET['thread']) ? htmlentities($_GET['thread']) : false);
  135. $mode = (isset($_GET['mode']) ? htmlentities($_GET['mode']) : false);
  136. $ajax = (isset($_GET['a']) ? true : false);
  137. foreach($_GET as $key => $value){
  138. switch($key){
  139. case "vote":
  140. $elem = array();
  141. $elem['poll'] = json_decode(vote($value,$_GET['choices']),true);
  142. //var_dump($_GET['choices']);
  143. echo renderPoll($elem);
  144. break;
  145. case "fav":
  146. $result = favourite($value,($mode === 'on' ? true : false));
  147. if ($ajax){
  148. echo $result;
  149. die();
  150. } else {
  151. header("Location: ?thread=".$value);
  152. }
  153. break;
  154. case "reblog":
  155. $result =reblog($value,($mode === 'on' ? true : false));
  156. if ($ajax){
  157. echo $result;
  158. die();
  159. } else {
  160. header("Location: ?thread=".$value);
  161. }
  162. break;
  163. case "mute":
  164. if($thread){
  165. $rel = api_post("statuses/".htmlentities($value)."/".($mode === 'true' ? "" : "un")."mute",array());
  166. echo (isset($rel[0]['muting']) ? "1" : "0" );
  167. } else {
  168. $rel = api_post("accounts/".htmlentities($value)."/".($mode === 'true' ? "" : "un")."mute",array());
  169. echo (isset($rel[0]['muting']) ? "1" : "0" );
  170. }
  171. die();
  172. break;
  173. case "list":
  174. if($mode === 'true'){
  175. $rel = api_post("lists/".htmlentities($value)."/accounts?account_ids[]=".$_GET['user'],array());
  176. var_dump($rel);
  177. } else {
  178. $rel = api_delete("lists/".htmlentities($value)."/accounts?account_ids[]=".$_GET['user'],array());
  179. var_dump($rel);
  180. }
  181. die();
  182. break;
  183. case "listdelete":
  184. $rel = api_delete("lists/".htmlentities($value),array());
  185. die();
  186. break;
  187. case "listnew":
  188. $rel = api_post("lists/",array("title" => htmlentities($value)));
  189. die();
  190. break;
  191. case "block":
  192. $rel = api_post("accounts/".htmlentities($value)."/".($mode === 'true' ? "" : "un")."block",array());
  193. echo (isset($rel[0]['blocking']) ? "1" : "0" );
  194. die();
  195. break;
  196. case "bookmark":
  197. $status = api_get("statuses/".htmlentities($value));
  198. $rel = api_post("statuses/".htmlentities($value)."/".($status['bookmarked'] == 'true' ? "un" : "")."bookmark",array());
  199. die();
  200. break;
  201. case "notif":
  202. echo getnotif(intval($value),(isset($_GET['max']) ? true : false));
  203. die();
  204. break;
  205. case "delete":
  206. echo delpost(htmlentities($value));
  207. die();
  208. break;
  209. case "replies":
  210. $since = (isset($_GET['since']) ? htmlentities($_GET['since']) : false);
  211. foreach(getreplies(htmlentities($value),$since) as $elem){
  212. echo render_reply($elem['content']);
  213. }
  214. die();
  215. break;
  216. case "notes":
  217. $notes = getnotes($value);
  218. foreach ($notes as $note){
  219. echo "<div id='".$note[1]['id']."'>
  220. <a href='?user=".$note[1]['id']."' class='ldr' title='".$note[1]['acct']."'>
  221. <div class='nte' style='background-image:url(".$note[1]['avatar'].");'>
  222. <div class='nte_type' style='background-color:".($note[0] == "fav" ? "red" : "green")."'><span>".($note[0] == "fav" ? "&#xe802;" : "&#xe826;")."</span></div>
  223. </div>
  224. </a>
  225. </div>";
  226. }
  227. die();
  228. break;
  229. case "follow":
  230. $rel = api_post("accounts/".htmlentities($value)."/follow",array());
  231. echo ($rel['following'] == true || $rel['requested'] == true ? "1" : "0" );
  232. die();
  233. break;
  234. case "unfollow":
  235. $rel = api_post("accounts/".htmlentities($value)."/unfollow",array());
  236. echo ($rel['following'] == false ? "1" : "0" );
  237. die();
  238. break;
  239. case "nsfw":
  240. if(in_array($value,$user_settings['nsfw'])){
  241. $key = array_search($value, $user_settings['nsfw']);
  242. unset($user_settings['nsfw'][$key]);
  243. $cookie[$index]['nsfw'] = $user_settings['nsfw'];
  244. setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
  245. } else {
  246. $user_settings['nsfw'][] = htmlentities($value);
  247. $cookie[$index]['nsfw'] = $user_settings['nsfw'];
  248. setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
  249. }
  250. echo "1";
  251. die();
  252. break;
  253. case "hide":
  254. if(!isset($user_settings['hide'])|| !is_array($user_settings['hide'])){
  255. $user_settings['hide'] = array();
  256. }
  257. if(in_array($value,$user_settings['hide'])){
  258. $key = array_search($value, $user_settings['hide']);
  259. unset($user_settings['hide'][$key]);
  260. $cookie[$index]['hide'] = $user_settings['hide'];
  261. setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
  262. } else {
  263. $user_settings['hide'][] = htmlentities($value);
  264. $cookie[$index]['hide'] = $user_settings['hide'];
  265. setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
  266. }
  267. echo "1";
  268. die();
  269. break;
  270. case "userinfo":
  271. $info = api_get("accounts/".htmlentities($value));
  272. $rel = api_get("accounts/relationships?id=".htmlentities($value));
  273. /*
  274. $photos = api_get("accounts/".htmlentities($value)."/statuses?only_media=true&limit=5&exclude_reblogs=true");
  275. $photo = array();
  276. $c = 0;
  277. if (!empty($photos)){
  278. foreach ($photos as $elem){
  279. if ($elem['media_attachments'][0]['type'] == "image"){
  280. $photo[$c]['url'] = $elem['media_attachments'][0]['url'];
  281. if ($elem['sensitive'] == true){
  282. $photo[$c]['s'] = true;
  283. }
  284. $c++;
  285. }
  286. if ($c == 3){
  287. break;
  288. }
  289. }
  290. }
  291. */
  292. echo "<div class='userinfo_he' style='background-color:#".averageColor($info['avatar'])."; background-size:cover;" . (!empty($info['header']) ? "background-image:url(".$info['header'].");" : "") . "'>
  293. <span style='margin:5px; display:inline-block;'>
  294. <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>
  295. </span>
  296. </div>
  297. <div class='userinfo_co'>
  298. <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>
  299. <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>
  300. <div style='font-weight:normal; font-size:12px; line-height:12px;'>".emojify($info['note'],$info['emojis'],20)."</div><br>
  301. <span style='width:290; height:30px; display:block; margin-top:10px;'>
  302. ".($logedin ? "<span id='".$info['id']."' class='profileButton ".(($rel[0]['following'] || $rel[0]['requested']) ? "unfollow" : "follow" )."'>".($rel[0]['following'] || $rel[0]['requested'] ? "Following" : "Follow" )."</span>" : "")."
  303. <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>
  304. ".($logedin ? "<span id='" . $info['id'] . "' class='profileButton " . ($rel[0]['muting'] ? "un" : "") . "mute'>" . ($rel[0]['muting'] ? "&#xe81a; Unmute" : "&#xe81b; Mute") . "</span>" : "")."<br>
  305. </span>
  306. " . ($rel[0]['followed_by'] ? "<span class='profileButton' width:290; height:25px; display:inline-block; margin-top:5px; style='background-color: rgba(255,255,255,.5);'>&#xe80c; Follows You</span>" : "") . "
  307. <div style='display:flex; width:280px'>";
  308. /*
  309. foreach ($photo as $elem){
  310. 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>";
  311. }
  312. */
  313. echo "</div>
  314. </div>
  315. ";
  316. die();
  317. break;
  318. case "previewpost":
  319. $post = api_get("statuses/".htmlentities($value));
  320. echo "<div class='notifContents' style='max-width:none;'>
  321. <div style='flex: 0 0 60px; background-size:cover; background-image:url(".$post['account']['avatar']."); border-radius:5px;'></div>
  322. <div style='flex: 1; padding-left:5px; padding-right:5px; word-break: break-all; overflow:hidden;'>
  323. <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>
  324. <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>
  325. </div>
  326. ".(!empty($post['media_attachments']) ? "<div style='flex: 0 0 60px; background-size:cover; background-image:url(".$post['media_attachments'][0]['url'].");'></div>" :"")."
  327. </div>";
  328. die();
  329. break;
  330. case "themefile":
  331. echo themes("get",$value);
  332. die();
  333. break;
  334. case "themename":
  335. echo $user_settings['theme'];
  336. die();
  337. break;
  338. case "emoji":
  339. echo emoji_list(sanitize($value));
  340. break;
  341. case "contact":
  342. echo contact_search(sanitize($value));
  343. break;
  344. }
  345. }
  346. if(isset($_POST['status'])){
  347. if(isset($_POST['scope'])){
  348. switch($_POST['scope']){
  349. case "1":
  350. $scope = "public";
  351. break;
  352. case "2":
  353. $scope = "unlisted";
  354. break;
  355. case "3":
  356. $scope = "private";
  357. break;
  358. case "4":
  359. $scope = "direct";
  360. break;
  361. }
  362. } else {
  363. if (isset($_POST['thread'])){
  364. $result = api_get("statuses/".htmlentities($_POST['thread']));
  365. $scope = $result['visibility'];
  366. } else {
  367. $scope = "public";
  368. }
  369. }
  370. $uploaded = (empty($_POST['uploaded']) ? array() : explode("|",$_POST['uploaded']));
  371. $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);
  372. echo render_reply($reply);
  373. die();
  374. }