timeline.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?php
  2. /* this file will fetch and render the posts of a timeline based
  3. on the options of the user_settings cookie and the url query.
  4. a "timeline" may be something like TWKN or just a single post
  5. */
  6. $thread = timeline(array_merge($tl, $user_settings));
  7. /*
  8. if the timeline requested is the first part of an user profile it will render first
  9. the user profile header, i may move this to it's own place in the future but
  10. for now it's here.
  11. */
  12. if (isset($_GET['user']) && (!isset($_GET['next']) && !isset($_GET['since']))) {
  13. list($info, $rel) = user_info($_GET['user']);
  14. $template = themes("get","templates/profileheader.txt");
  15. $profile['mainColor'] = averageColor($info['avatar']);
  16. $profile['header'] = $info['header_static'];
  17. /* display user buttons (block, mute, list, etc) for loged in users only */
  18. $profile['top'] = ($logedin ? "<span id='" . $info['id'] . "' class='profileButton profileMenu' style='position:relative;'>&#xe811;
  19. <div class='menu' style='width:80px; position:absolute; background-color:yellow; top:25px; display:none;'>
  20. <div id='" . $info['id'] . "' class='profileButton " . ($rel[0]['muting'] ? "un" : "") . "mute' style='width:100%; border-radius:0px;'>" . ($rel[0]['muting'] ? "&#xe81a; Unmute" : "&#xe81b; Mute") . "</div>
  21. <div id='" . $info['id'] . "' class='profileButton " . ($rel[0]['blocking'] ? "un" : "") . "block' style='width:100%; border-radius:0px;'>" . ($rel[0]['blocking'] ? "&#xe80d Unblock" : "&#xe813; Block") . "</div>
  22. </div>
  23. </span>" : "");
  24. if ($logedin && $rel[0]['following']) {
  25. $profile['top'] .= "<span id='" . $info['id'] . "' class='profileButton listmenu' style='position:relative;'>Lists &#xe80b;
  26. <div class='menu' style='width:120px; position:absolute; background-color:yellow; top:25px; left:00px; display:none;'><ul>";
  27. $userlist = api_get("accounts/" . $info['id'] . "/lists");
  28. $listids = array();
  29. foreach ($userlist as $lst) {
  30. $listids[] = $lst['id'];
  31. }
  32. $lists = api_get("/lists");
  33. foreach ($lists as $list) {
  34. $profile['top'] .= "<a href='?action=addtolist&user=" . $info['id'] . "&list=" . $list['id'] . "' id='" . $info['id'] . "' list='" . $list['id'] . "' class='" . (in_array($list['id'], $listids) ? 'rutl' : 'autl') . "' onClick='return false;'><li>" . $list['title'] . "</li></a>";
  35. }
  36. $profile['top'] .= "<a href='?page=lists' class='ldr' onClick='return false;'><li>Manage Lists</li></a>";
  37. $profile['top'] .= "
  38. </ul></div>
  39. </span>";
  40. }
  41. if ($logedin) {
  42. if ($rel[0]['following']) {
  43. $label = "&#xe80c; Following";
  44. $class = "unfollow";
  45. }
  46. else {
  47. if ($info['locked']) {
  48. if ($rel[0]['requested']) {
  49. $label = "&#xe806; Follow Requested";
  50. $class = "unfollow";
  51. }
  52. else {
  53. $label = "&#xe806; Request Follow";
  54. $class = "follow";
  55. }
  56. }
  57. else {
  58. $label = "&#xf234; Follow";
  59. $class = "follow";
  60. }
  61. }
  62. $profile['top'] .= "<span id='" . $info['id'] . "' class='profileButton $class'>$label</span>";
  63. }
  64. /* The NSFW button is available even to non logged in users, the value is stored in a cookie */
  65. $profile['top'] .= "<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>";
  66. /* display some indicators (blocked, muting, etc) for loged in users only */
  67. if ($logedin) {
  68. $profile['bottom'] = "
  69. " . ($info['locked'] ? "<span class='profileButton' style='background-color: rgba(255,255,255,.5);'>&#xe819; Locked</span>" : "") . "
  70. " . ($rel[0]['followed_by'] ? "<span class='profileButton' style='background-color: rgba(255,255,255,.5);'>&#xe80c; Follows You</span>" : "") . "
  71. " . ($rel[0]['blocking'] ? "<span class='profileButton' style='background-color: rgba(255,255,255,.5);'>&#xe82c; Blocked</span>" : "") . "
  72. " . ($rel[0]['muting'] ? "<span class='profileButton' style='background-color: rgba(255,255,255,.5);'>&#xe813; Muted</span>" : "") . "
  73. ";
  74. }
  75. else {
  76. $profile['bottom'] = "";
  77. }
  78. /* some values are processed from the profile and stored in the $profile array*/
  79. $profile['avatar'] = $info['avatar'];
  80. $profile['name'] = emojify($info['display_name'], $info['emojis'], 40);
  81. $profile['acct'] = $info['acct'];
  82. $profile['url'] = $info['url'];
  83. $profile['note'] = emojify(trim($info['note']) , $info['emojis']);
  84. $profile['statuses'] = $info['statuses_count'];
  85. $profile['following'] = $info['following_count'];
  86. $profile['followers'] = $info['followers_count'];
  87. /* now we replace the text of the index of $profile array with the contents of the index
  88. in the fetched template */
  89. foreach ($profile as $key => $value) {
  90. $template = str_replace(":$key:", $value, $template);
  91. }
  92. echo $template;
  93. }
  94. elseif (!isset($_GET['next']) && !isset($_GET['since'])) {
  95. echo "<div class='element'></div>";
  96. }
  97. /*
  98. if the timeline array is empty or the content is not a post, we just display an error message.
  99. */
  100. if ((!isset($thread[0]['id']) && !empty($thread)) || !is_array($thread)) {
  101. echo "<div class='element'><div class='avatar'></div><span class='button error'> Error loading the timeline. " . json_encode($thread) . "</span></div>";
  102. } else {
  103. $e = 0;
  104. /* process all the posts on the timeline */
  105. foreach ($thread as $elem) {
  106. $post = array();
  107. /* pid is the ABSOLUTE id of a post, not linked to the relative id,
  108. a retweet has a different absolute id than the post that was retweeted */
  109. $post['pid'] = $elem['id'];
  110. $post['replyto'] = "";
  111. $post['rt'] = "";
  112. /* if the post is a retweet, we'll flag it as such and fetch the data of the post entity
  113. from the "reblog" key
  114. */
  115. if ($elem['reblog'] != null) {
  116. if ($user_settings['reblog'] == 'off'){
  117. continue;
  118. }
  119. $post['name'] = (empty($elem['reblog']['account']['display_name']) ? $elem['reblog']['account']['acct'] : emojify($elem['reblog']['account']['display_name'], $elem['reblog']['account']['emojis'], 20));
  120. $post['uid'] = $elem['reblog']['account']['id'];
  121. $post['acct'] = '';//$elem['reblog']['account']['acct'];
  122. $post['handle'] = explode("@",$elem['reblog']['account']['acct'])[0];
  123. $post['rter'] = $elem['account']['id'];
  124. $post['replyto'] = ($elem['reblog']['in_reply_to_id'] ? "<span> <a class='fontello link preview ldr' target='_blank' id='" . $elem['reblog']['in_reply_to_id'] . "' href='?thread=" . $elem['reblog']['in_reply_to_id'] . "'>&#xf112;</a></span>" : "");
  125. $post['rt'] = "<div style='display:inline-block; font-family:fontello, sans-serif; vertical-align:top;'>&#xe826; by <img src='" . $elem['account']['avatar'] . "' width=20 style='border-radius:5px; vertical-align:middle;'> <span class='user' id='" . $elem['account']['id'] . "'><a class='link ldr' style='font-size:12px;' id='" . $elem['account']['id'] . "' href='?user=" . $elem['account']['id'] . "'><span>@" . explode("@", $elem['account']['acct']) [0] . "</a></span></div>";
  126. $elem = $elem['reblog'];
  127. }
  128. else {
  129. $post['name'] = (empty($elem['account']['display_name']) ? $elem['account']['acct'] : emojify($elem['account']['display_name'], $elem['account']['emojis'], 20));
  130. $post['uid'] = $elem['account']['id'];
  131. $post['acct'] = "(@".$elem['account']['acct'].")";
  132. $post['handle'] = explode("@",$elem['account']['acct'])[0];
  133. $post['replyto'] = ($elem['in_reply_to_id'] ? "<span><a class='fontello link preview ldr' target='_blank' id='" . $elem['in_reply_to_id'] . "' href='?thread=" . $elem['in_reply_to_id'] . "'>&#xf112;</a></span>" : "");
  134. }
  135. /* We skip the post if it contains any of the muted words */
  136. foreach($user_settings['mtwords'] as $word){
  137. if(contains($elem['content'],trim($word))){
  138. continue 2;
  139. }
  140. }
  141. /* if the poster ID was flagged as NSFW by the user, the post is flagged
  142. as sensitive by default */
  143. if (in_array($elem["account"]['id'], $user_settings['nsfw'])) {
  144. $elem['sensitive'] = true;
  145. }
  146. if (in_array($post['rter'], $user_settings['softmute']) || in_array($elem['account']['id'], $user_settings['softmute'])) {
  147. if (!isset($_GET['user']) && !isset($_GET['thread'])){
  148. continue;
  149. }
  150. }
  151. /* if the settings say to avoid showing posts with NSFW content, we skip to the next post */
  152. if ($user_settings['explicit'] == "hide" && $elem['sensitive'] == true && $tl['mode'] != "thread") {
  153. continue;
  154. }
  155. /* if this thread has been hidden by the user, we skip to the next one
  156. note that the "conversation_id" post key is only available with pleroma servers
  157. */
  158. if (@in_array($elem["pleroma"]['conversation_id'], $user_settings['hide'])) {
  159. continue;
  160. }
  161. /* the $json array stores some data about the thread that is embedded inside the
  162. html of the post and is mostly used by the javascript portion of the FE. It stores
  163. the id of the post, the visibility and who was mentioned in the post.
  164. */
  165. $json['id'] = $elem['id'];
  166. $json['scope'] = $elem['visibility'];
  167. if ($logedin) {
  168. $pos['mentions'] = "";
  169. $array = $elem["mentions"];
  170. $json['mentions'] = ($user_settings['acct'] == $elem["account"]['acct'] ? "" : "@" . $elem["account"]['acct']) . " ";
  171. if (!empty($array)) {
  172. foreach ($array as $mnt) {
  173. if ($mnt['acct'] != $user_settings['acct'] && $mnt['acct'] != $elem['account']['acct']) {
  174. $json['mentions'] .= "@" . $mnt['acct'] . " ";
  175. }
  176. }
  177. }
  178. }
  179. $post['json'] = json_encode($json);
  180. /* the options menu of the post */
  181. $post['menu'] = "<ul>";
  182. if ($logedin) {
  183. $post['menu'] .= ($elem['account']['id'] == $user_settings['uid'] ? "<li><a href='?action=delete&thread=" . $elem['id'] . "' onClick='return false;' class='delete fontello' id=':id:'>&#xe80e; Delete Post</a></li>" : "");
  184. $post['menu'] .= "<li><a href='?action=compose&quote=" . $elem['id'] . "' onClick='return false;' class='quote fontello' id='" . $elem['id'] . "' style='background-color:transparent;'>&#xf10e; Quote Post</a></li>";
  185. $post['menu'] .= ($elem['account']['id'] != $user_settings['uid'] ? "<li><a href='?action=mute&user=" . $elem['account']['id'] . "' onClick='return false;' class='mute fontello' id='" . $elem['account']['id'] . "' style='background-color:transparent;'>&#xe81b; Mute User</a></li>" : "");
  186. $post['menu'] .= ($elem['account']['id'] != $user_settings['uid'] ? "<li><a href='?action=softmute&user=" . $elem['account']['id'] . "' onClick='return false;' class='softmute fontello' id='" . $elem['account']['id'] . "' style='background-color:transparent;'>&#xe81b; Soft Mute</a></li>" : "");
  187. $post['menu'] .= ($elem['account']['id'] != $user_settings['uid'] ? "<li><a href='?action=mute&thread=" . $elem['account']['id'] . "' onClick='return false;' class='muteconv fontello' id='" . $elem['id'] . "' style='background-color:transparent;'>&#xf1f7; Drop Thread</a></li>" : "");
  188. $post['menu'] .= (isset($user_settings['pleroma']) ? "<li><a href='?action=hide&thread=" . $elem['pleroma']['conversation_id'] . "' onClick='return false;' class='hide fontello' id='" . $elem['pleroma']['conversation_id'] . "' style='background-color:transparent;'>&#xf1f8; Hide Thread</a></li>" : "");
  189. $post['menu'] .= "<li><a href='?action=bookmark&thread=" . $elem['account']['id'] . "' onClick='return false;' class='" . ($elem['bookmarked'] == true ? "un" : "") . "bookmark fontello' id='" . $elem['id'] . "' style='background-color:transparent;'>&#xe81e; " . ($elem['bookmarked'] == true ? "Unb" : "B") . "ookmark</a></li>";
  190. $post['menu'] .= ($elem['account']['id'] != $user_settings['uid'] ? "<li><a href='?action=nsfw&user=" . $elem['account']['id'] . "' onClick='return false;' class='nsfw fontello' id='" . $elem['account']['id'] . "' style='background-color:transparent;'>&#xe829; User is NSFW</a></li>" : "");
  191. }
  192. $post['menu'] .= "<li><a target='_blank' href='" . $elem['url'] . "' class='original link fontello' style='background-color:transparent;'>&#xf14c; Original Note</a></li>";
  193. $post['menu'] .= "</ul>";
  194. $post['style'] = "";
  195. $post['id'] = $elem['id'];
  196. $post['avatar'] = $elem['account']['avatar'];
  197. $elem['content'] = (empty($user_settings['invidious']) ? $elem['content'] : str_replace("music.youtube.com",$user_settings['invidious'],$elem['content']));
  198. $elem['content'] = (empty($user_settings['invidious']) ? $elem['content'] : str_replace("youtube.com",$user_settings['invidious'],$elem['content']));
  199. $elem['content'] = (empty($user_settings['invidious']) ? $elem['content'] : str_replace("youtu.be",$user_settings['invidious'],$elem['content']));
  200. $elem['content'] = (empty($user_settings['nitter']) ? $elem['content'] : str_replace("twitter.com",$user_settings['nitter'],$elem['content']));
  201. $elem['content'] = (empty($user_settings['teddit']) ? $elem['content'] : str_replace("reddit.com",$user_settings['teddit'],$elem['content']));
  202. $post['text'] = processText($elem);
  203. if (!empty($elem['poll'])){
  204. $post['text'] .= "<div class='poll' id='".$elem['poll']['id']."' ".($elem['poll']['multiple'] ? "multiple" : "").">";
  205. $post['text'] .= renderPoll($elem);
  206. $post['text'] .= "</div>";
  207. }
  208. $post['spoiler'] = "";
  209. $post['hidden'] = "";
  210. if ($user_settings['unrollcw'] == 'off'){
  211. $post['spoiler'] = (empty($elem['spoiler_text']) ? "" : "<div class='spoiler' style='font-weight:bold;font-size:15px;'>" . emojify($elem['spoiler_text'], $elem['emojis'], 40) . "<a style='display:block;'>Click here to reveal</a></div>");
  212. $post['hidden'] = (empty($elem['spoiler_text']) ? "" : "hidden");
  213. } else {
  214. $post['spoiler'] = (empty($elem['spoiler_text']) ? "" : "<div style='font-weight:bold;font-size:15px;'>" . emojify($elem['spoiler_text'], $elem['emojis'], 40) . "</div>");
  215. }
  216. $post['media'] = "";
  217. $urls = array();
  218. $html = str_get_html($post['text']);
  219. if($html){
  220. foreach ($html->find('a.external') as $l){
  221. $urls[] = (string)$l->href;
  222. }
  223. }
  224. /* embed videos */
  225. if (!empty($urls)) {
  226. foreach ($urls as $url) {
  227. if(contains_any($url, array("jpg","jpeg","gif","png","webp","mp4","webm"))){
  228. continue;
  229. }
  230. if ($user_settings['embyt'] == 'on'){
  231. parse_str(parse_url($url, PHP_URL_QUERY) , $my_array_of_vars);
  232. if (isset($my_array_of_vars['v'])) {
  233. $post['media'] = "<div class='desktop'><embed width='620' height='415' src='https://".(empty($user_settings['invidious']) ? "youtube.com" : $user_settings['invidious'])."/embed/" . $my_array_of_vars['v'] . "'><br><a name='dock' class='cursor' onClick=\"dockvideo(this);\">Undock Video <span class='fontello'>&#xe836;</span></a></div>";
  234. }
  235. }
  236. }
  237. }
  238. /* embed the media attachments to the post... */
  239. if (!empty($elem['media_attachments'])) {
  240. /* ...only if there are attachments and the user hasn't turned off the attachments in the settings */
  241. if ($user_settings['attach'] != "off"){
  242. $images = count($elem['media_attachments']);
  243. $class = ($images === 1 ? "" : ($images > 4 ? "class='smaller'" : "class='small'"));
  244. $m = 1;
  245. foreach ($elem['media_attachments'] as $file) {
  246. $ext = explode(".", $file['url']);
  247. $ext = end($ext);
  248. $ext = explode("?", $ext) [0];
  249. if (in_array($ext,array('webm','mp4','ogv')) || $file['type'] == "video") {
  250. $post['media'] .= "<div style='overflow:hidden; float:left; margin:2px;' $class><video preload='metadata' style='text-align:center; max-width:100%; max-height:100%;' controls ".($user_settings['mute'] == "on" ? "muted" : "")." ".($user_settings['videoloop'] == "on" ? "loop" : "").">
  251. <source src='" . $file['url'] . "' type='video/".($ext == "ogv" ? "ogg" : $ext)."'>
  252. </video></div>
  253. ";
  254. }
  255. elseif (in_array($ext,array('mp3','ogg','oga','opus')) || $file['type'] == "audio") {
  256. $post['media'] .= "<div style='text-align:center; width:100%;'><audio controls>
  257. <source src='" . $file['url'] . "' type='audio/$ext'>
  258. Your browser does not support the audio tag.
  259. </audio> </div>";
  260. }
  261. elseif (in_array($ext,array('jpg','jpeg','png','gif','apng','svg','webp')) || $file['type'] == "image") {
  262. /* we'll either hide the attachment or assign a css class depending on the user's settings */
  263. /* if the post is marked as sensitive and nsfw hiding isn't turned off, we'll blur the image */
  264. if ($elem['sensitive'] == true && $user_settings['explicit'] != 'off') {
  265. //$post['media'] .= " <div style='overflow:hidden; float:left; margin:2px;background-color:#".(($class != "") || ($elem['sensitive'] == true && $user_settings['explicit'] != 'off') ? averageColor($file['url']) : "000")."!important; ".($images === 1 ? "width:100%;" : "max-width:100%; max-height:100%;")."' $class>
  266. $post['media'] .= " <div style='overflow:hidden; float:left; margin:2px;background-color:#".(($class != "") || ($elem['sensitive'] == true && $user_settings['explicit'] != 'off') ? "000" : "000")."!important; ".($images === 1 ? "width:100%;" : "max-width:100%; max-height:100%;")."' $class>
  267. <div class='toggleblur' style='height:25px;'>&#xe81b; Blur</div>
  268. <a target='_blank' href='" . $file['url'] . "' onClick='return false;' style='width:100%;' class='blur'>
  269. <noscript><img src='" . $file['url'] . "' style='width:100%;'></noscript>
  270. <img " . ($e < 2 ? "src='" . $file['url'] . "'" : "data-src='" . $file['url'] . "'") . " class='lazyload' style='".($images === 1 ? "width:100%;" : "max-width:100%; max-height:100%;")." vertical-align:middle;'>
  271. </a>
  272. <a target='_blank' href='" . $file['url'] . "' onClick='return false;' class='open-lightbox' style='display:none;'>
  273. <img src='" . $file['url'] . "' class='lazyload' style='width:100%;'>
  274. </a>
  275. </div>";
  276. }
  277. else {
  278. /* If the post was sensitive and wasn't caught by the nsfw filter and
  279. didn't got blurred, then the image will be shown normally */
  280. $post['media'] .= "<div style='margin:0px; ".($images == 3 && $m == 3 ? "width:100% !important;" : "")."background-color:#".($class != "" ? "000" : "000").";' $class><a target='_blank' href='" . $file['url'] . "' onClick='return false;' class='open-lightbox'><img " . ($e < 2 ? "src='" . $file['url'] . "'" : "data-src='" . $file['url'] . "'") . " class='lazyload' style='" . ($images === 1 ? "width:100%;" : "max-width:100%; max-height:100%;") . " vertical-align:middle;'><noscript><img src='" . $file['url'] . "' style='width:100%;'></noscript></a></div>";
  281. // $post['media'] .= "<div style='margin:0px; ".($images == 3 && $m == 3 ? "width:100% !important;" : "")."background-color:#".($class != "" ? averageColor($file['url']) : "000").";' $class><a target='_blank' href='" . $file['url'] . "' onClick='return false;' class='open-lightbox'><img " . ($e < 2 ? "src='" . $file['url'] . "'" : "data-src='" . $file['url'] . "'") . " class='lazyload' style='" . ($images === 1 ? "width:100%;" : "max-width:100%; max-height:100%;") . " vertical-align:middle;'><noscript><img src='" . $file['url'] . "' style='width:100%;'></noscript></a></div>";
  282. }
  283. } else {
  284. $post['media'] .= "<center><table><tr><td><a href='".$file['remote_url']."' download><img src='img/doc.png' width=40 border=0></a></td><td><a href='".$file['url']."' target='_blank'>".$file['description']."</a></td></tr></table></center>";
  285. }
  286. $m++;
  287. }
  288. } else {
  289. /* if the user turned off attachments we'll only show a link to it */
  290. $post['text'] .= "<br><br>\n";
  291. foreach ($elem['media_attachments'] as $file) {
  292. $post['text'] .= "<span class='fontello'>&#xe818;</span><a href='".$file['url']."' target='_blank' onClick='return false;' class='open-lightbox'>See attachment ".($elem['sensitive'] == true ? "(NSFW)" : "")."</a><br>\n";
  293. }
  294. }
  295. }
  296. $post['text'] .= $post['opengraph'];
  297. /* the code of the post footer (date, visibility and like/reblog buttons */
  298. $post['footer'] = "<div style='float:left;'>
  299. <a style='text-decoration:none;' class='ldr postAge' id='".strtotime($elem['created_at'])."' target='_blank' href='?thread=" . $elem['id'] . "' title='".gmdate("d/m/y H:i", strtotime($elem['created_at']))."'>" .time_elapsed_string($elem['created_at']) . "</a> - <span class='fontello ".$elem['visibility']."'></span> <span class='fontello ". ($elem['sensitive'] == true ? "sensitive" : "")."'> </span>
  300. </div>
  301. <div class='post_buttons' id='" . $elem['id'] . "'>
  302. " . ($logedin ? "<div class='felem'><a onClick='return false' class='replyform' href='?thread=" . $elem['id'] . "' style='font-family:fontello; vertical-align:middle;' alt='reply'>&#xf112;</a></div>" : "") . "
  303. <div class='felem'><a onClick='return false' " . ($logedin ? "class='" . ($elem['favourited'] == true ? "unfav" : "fav") . "' href='?action=true&mode=".($elem['favourited'] == true ? "off" : "true")."&fav=" . $elem['id'] . "'" : "class='notAllowed'") . " style='font-family:fontello; vertical-align:middle;'>&#xe802; <span>" . $elem['favourites_count'] . "</span></a></div>
  304. <div class='felem'><a onClick='return false' " . ($logedin && ($elem['visibility'] == "public" || $elem['visibility'] == "unlisted") ? "class='" . ($elem['reblogged'] == true ? "unreblog" : "reblog") . "' href='?action=true&mode=".($elem['reblogged'] == true ? "off" : "on")."&reblog=" . $elem['id'] . "'" : "class='notAllowed'") . " style='font-family:fontello; vertical-align:middle;'>&#xe83a; <span>" . $elem['reblogs_count'] . "</span></a></div>
  305. <div class='felem'><a class='replies' onClick='return false' href='?thread=" . $elem['id'] . "' style='font-family:fontello; vertical-align:middle;'>&#xe827; <span>" . $elem['replies_count'] . "</span></a></div>
  306. </div>";
  307. $post['form'] = ($tl['mode'] == 'thread' && $logedin ? str_replace(array(
  308. ":id:",
  309. ":content:"
  310. ) , array(
  311. $elem['id'],
  312. $json['mentions']
  313. ) , themes("get","templates/replyform.txt")) : "");
  314. $post['ancestors'] = " ";
  315. $post['descendants'] = " ";
  316. $post['notes'] = "";
  317. /* if the timeline is a single post, we'll fetch the replies and notes */
  318. if ($tl['mode'] == 'thread') {
  319. $replies = ($tl['mode'] == "thread" ? getreplies($tl['thread']) : false);
  320. $notes = ($tl['mode'] == "thread" ? getnotes($tl['thread']) : false);
  321. foreach ($replies as $e) {
  322. if ($e['mode'] == 'ancestor') {
  323. $post['ancestors'] .= render_reply($e['content']);
  324. }
  325. else {
  326. $post['descendants'] .= render_reply($e['content']);
  327. }
  328. }
  329. if ($notes) {
  330. foreach ($notes as $note) {
  331. $post['notes'] .= "<div id='" . $note[1]['id'] . "'>
  332. <a href='?user=" . $note[1]['id'] . "' class='ldr' title='" . $note[1]['acct'] . "'>
  333. <div class='nte' style='background-image:url(" . $note[1]['avatar'] . ");'>
  334. <div class='nte_type' style='background-color:" . ($note[0] == "fav" ? "red" : "green") . "'><span>" . ($note[0] == "fav" ? "&#xe802;" : "&#xe826;") . "</span></div>
  335. </div>
  336. </a>
  337. </div>";
  338. }
  339. }
  340. }
  341. if ((empty($elem['media_attachments']) && $post['media'] == "") || (!(empty($elem['media_attachments']) && $post['media'] == "") && $user_settings['attach'] == "off")) {
  342. $post['template'] = themes("get","templates/textpost.txt");
  343. }
  344. else {
  345. if ($logedin){
  346. $post['template'] = themes("get","templates/post.txt");
  347. } else {
  348. $post['template'] = themes("get","templates/post_logout.txt");
  349. }
  350. }
  351. foreach ($post as $key => $value) {
  352. $post['template'] = str_replace(":$key:", $value, $post['template']);
  353. }
  354. echo $post['template'];
  355. unset($post);
  356. $e++;
  357. $next = $elem['id'];
  358. }
  359. if ((!isset($_GET['next']) || (isset($_GET['next']) && !isset($_GET['ajax']))) && !isset($_GET['since']) && !isset($_GET['thread'])) {
  360. $query = http_build_query(array_filter(array(
  361. 'user' => (isset($tl['user']) ? $tl['user'] : false) ,
  362. 'mode' => $tl['mode']
  363. )));
  364. if ($tl['mode'] != "search"){
  365. echo "<div class='element'><div class='avatar' style='height:0px;'></div><div class='loadmore' style='display:table-cell; height:50px; line-height:50px;'><a class='link' onClick='return false;' style='margin:5px;' href='?next=$next&" . $query . "'>Load More Posts</a></div></div>";
  366. }
  367. }
  368. }
  369. ?>