Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

506 lines
18 KiB

  1. <?php
  2. function display_init(&$a) {
  3. if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
  4. return;
  5. }
  6. $nick = (($a->argc > 1) ? $a->argv[1] : '');
  7. $profiledata = array();
  8. // If there is only one parameter, then check if this parameter could be a guid
  9. if ($a->argc == 2) {
  10. $nick = "";
  11. $itemuid = 0;
  12. // Does the local user have this item?
  13. if (local_user()) {
  14. $r = q("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item`
  15. WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  16. AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
  17. if (count($r)) {
  18. $nick = $a->user["nickname"];
  19. $itemuid = local_user();
  20. }
  21. }
  22. // Or is it anywhere on the server?
  23. if ($nick == "") {
  24. $r = q("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`,
  25. `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`body`
  26. FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
  27. WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  28. AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
  29. AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
  30. AND `item`.`private` = 0 AND NOT `user`.`hidewall`
  31. AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
  32. // AND `item`.`private` = 0 AND `item`.`wall` = 1
  33. if (count($r)) {
  34. $nick = $r[0]["nickname"];
  35. $itemuid = $r[0]["uid"];
  36. }
  37. }
  38. // Is it an item with uid=0?
  39. if ($nick == "") {
  40. $r = q("SELECT `item`.`id`, `item`.`parent`, `item`.`author-name`,
  41. `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`body`
  42. FROM `item` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  43. AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
  44. AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
  45. AND `item`.`private` = 0 AND `item`.`uid` = 0
  46. AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
  47. // AND `item`.`private` = 0 AND `item`.`wall` = 1
  48. }
  49. if (count($r)) {
  50. if ($r[0]["id"] != $r[0]["parent"])
  51. $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item`
  52. WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  53. AND `id` = %d", $r[0]["parent"]);
  54. $profiledata = display_fetchauthor($a, $r[0]);
  55. if (strstr(normalise_link($profiledata["url"]), normalise_link($a->get_baseurl()))) {
  56. $nickname = str_replace(normalise_link($a->get_baseurl())."/profile/", "", normalise_link($profiledata["url"]));
  57. if (($nickname != $a->user["nickname"])) {
  58. $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
  59. INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
  60. WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
  61. dbesc($nickname)
  62. );
  63. if (count($r))
  64. $profiledata = $r[0];
  65. $profiledata["network"] = NETWORK_DFRN;
  66. } else
  67. $profiledata = array();
  68. }
  69. } else {
  70. $a->error = 404;
  71. notice( t('Item not found.') . EOL);
  72. return;
  73. }
  74. }
  75. profile_load($a, $nick, 0, $profiledata);
  76. }
  77. function display_fetchauthor($a, $item) {
  78. require_once("mod/proxy.php");
  79. require_once("include/bbcode.php");
  80. $profiledata = array();
  81. $profiledata["uid"] = -1;
  82. $profiledata["nickname"] = $item["author-name"];
  83. $profiledata["name"] = $item["author-name"];
  84. $profiledata["picdate"] = "";
  85. $profiledata["photo"] = proxy_url($item["author-avatar"]);
  86. $profiledata["url"] = $item["author-link"];
  87. $profiledata["network"] = $item["network"];
  88. // Check for a repeated message
  89. $skip = false;
  90. $body = trim($item["body"]);
  91. // Skip if it isn't a pure repeated messages
  92. // Does it start with a share?
  93. if (!$skip AND strpos($body, "[share") > 0)
  94. $skip = true;
  95. // Does it end with a share?
  96. if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
  97. $skip = true;
  98. if (!$skip) {
  99. $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
  100. // Skip if there is no shared message in there
  101. if ($body == $attributes)
  102. $skip = true;
  103. }
  104. if (!$skip) {
  105. $author = "";
  106. preg_match("/author='(.*?)'/ism", $attributes, $matches);
  107. if ($matches[1] != "")
  108. $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
  109. preg_match('/author="(.*?)"/ism', $attributes, $matches);
  110. if ($matches[1] != "")
  111. $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
  112. $profile = "";
  113. preg_match("/profile='(.*?)'/ism", $attributes, $matches);
  114. if ($matches[1] != "")
  115. $profiledata["url"] = $matches[1];
  116. preg_match('/profile="(.*?)"/ism', $attributes, $matches);
  117. if ($matches[1] != "")
  118. $profiledata["url"] = $matches[1];
  119. $avatar = "";
  120. preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
  121. if ($matches[1] != "")
  122. $profiledata["photo"] = $matches[1];
  123. preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
  124. if ($matches[1] != "")
  125. $profiledata["photo"] = $matches[1];
  126. $profiledata["nickname"] = $profiledata["name"];
  127. $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
  128. $profiledata["address"] = "";
  129. $profiledata["about"] = "";
  130. }
  131. // Fetching further contact data from the contact table
  132. $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s'",
  133. dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), dbesc($item["network"]));
  134. if (!count($r))
  135. $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
  136. dbesc(normalise_link($profiledata["url"])), intval($item["uid"]));
  137. if (!count($r))
  138. $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
  139. dbesc(normalise_link($profiledata["url"])));
  140. if (count($r)) {
  141. if ((($r[0]["uid"] != local_user()) OR !local_user()) AND ($profiledata["network"] == NETWORK_DIASPORA)) {
  142. $r[0]["location"] = "";
  143. $r[0]["about"] = "";
  144. }
  145. $profiledata["photo"] = proxy_url($r[0]["photo"]);
  146. $profiledata["address"] = bbcode($r[0]["location"]);
  147. $profiledata["about"] = bbcode($r[0]["about"]);
  148. if ($r[0]["nick"] != "")
  149. $profiledata["nickname"] = $r[0]["nick"];
  150. }
  151. // Fetching profile data from unique contacts
  152. $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($profiledata["url"])));
  153. if (count($r)) {
  154. if ($profiledata["photo"] == "")
  155. $profiledata["photo"] = proxy_url($r[0]["avatar"]);
  156. if (($profiledata["address"] == "") AND ($profiledata["network"] != NETWORK_DIASPORA))
  157. $profiledata["address"] = bbcode($r[0]["location"]);
  158. if (($profiledata["about"] == "") AND ($profiledata["network"] != NETWORK_DIASPORA))
  159. $profiledata["about"] = bbcode($r[0]["about"]);
  160. if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != ""))
  161. $profiledata["nickname"] = $r[0]["nick"];
  162. }
  163. if (local_user()) {
  164. if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
  165. $profiledata["remoteconnect"] = $a->get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
  166. } elseif ($profiledata["network"] == NETWORK_DFRN) {
  167. $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
  168. $profiledata["remoteconnect"] = $connect;
  169. }
  170. return($profiledata);
  171. }
  172. function display_content(&$a, $update = 0) {
  173. if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
  174. notice( t('Public access denied.') . EOL);
  175. return;
  176. }
  177. require_once("include/bbcode.php");
  178. require_once('include/security.php');
  179. require_once('include/conversation.php');
  180. require_once('include/acl_selectors.php');
  181. $o = '';
  182. $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
  183. if($update) {
  184. $nick = $_REQUEST['nick'];
  185. }
  186. else {
  187. $nick = (($a->argc > 1) ? $a->argv[1] : '');
  188. }
  189. if($update) {
  190. $item_id = $_REQUEST['item_id'];
  191. $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
  192. }
  193. else {
  194. $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
  195. if ($a->argc == 2) {
  196. $nick = "";
  197. if (local_user()) {
  198. $r = q("SELECT `id` FROM `item`
  199. WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  200. AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
  201. if (count($r)) {
  202. $item_id = $r[0]["id"];
  203. $nick = $a->user["nickname"];
  204. }
  205. }
  206. if ($nick == "") {
  207. $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
  208. WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  209. AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
  210. AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
  211. AND `item`.`private` = 0 AND NOT `user`.`hidewall`
  212. AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
  213. // AND `item`.`private` = 0 AND `item`.`wall` = 1
  214. if (count($r)) {
  215. $item_id = $r[0]["id"];
  216. $nick = $r[0]["nickname"];
  217. }
  218. }
  219. if ($nick == "") {
  220. $r = q("SELECT `item`.`id` FROM `item`
  221. WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  222. AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
  223. AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
  224. AND `item`.`private` = 0 AND `item`.`uid` = 0
  225. AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
  226. // AND `item`.`private` = 0 AND `item`.`wall` = 1
  227. if (count($r)) {
  228. $item_id = $r[0]["id"];
  229. }
  230. }
  231. }
  232. }
  233. if(! $item_id) {
  234. $a->error = 404;
  235. notice( t('Item not found.') . EOL);
  236. return;
  237. }
  238. $groups = array();
  239. $contact = null;
  240. $remote_contact = false;
  241. $contact_id = 0;
  242. if(is_array($_SESSION['remote'])) {
  243. foreach($_SESSION['remote'] as $v) {
  244. if($v['uid'] == $a->profile['uid']) {
  245. $contact_id = $v['cid'];
  246. break;
  247. }
  248. }
  249. }
  250. if($contact_id) {
  251. $groups = init_groups_visitor($contact_id);
  252. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  253. intval($contact_id),
  254. intval($a->profile['uid'])
  255. );
  256. if(count($r)) {
  257. $contact = $r[0];
  258. $remote_contact = true;
  259. }
  260. }
  261. if(! $remote_contact) {
  262. if(local_user()) {
  263. $contact_id = $_SESSION['cid'];
  264. $contact = $a->contact;
  265. }
  266. }
  267. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
  268. intval($a->profile['uid'])
  269. );
  270. if(count($r))
  271. $a->page_contact = $r[0];
  272. $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
  273. if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
  274. notice( t('Access to this profile has been restricted.') . EOL);
  275. return;
  276. }
  277. if ($is_owner) {
  278. $x = array(
  279. 'is_owner' => true,
  280. 'allow_location' => $a->user['allow_location'],
  281. 'default_location' => $a->user['default-location'],
  282. 'nickname' => $a->user['nickname'],
  283. 'lockstate' => ( (is_array($a->user)) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))) ? 'lock' : 'unlock'),
  284. 'acl' => populate_acl($a->user, true),
  285. 'bang' => '',
  286. 'visitor' => 'block',
  287. 'profile_uid' => local_user(),
  288. 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
  289. );
  290. $o .= status_editor($a,$x,0,true);
  291. }
  292. $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
  293. // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
  294. if($update) {
  295. $r = q("SELECT id FROM item WHERE item.uid = %d
  296. AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
  297. $sql_extra AND unseen = 1",
  298. intval($a->profile['uid']),
  299. dbesc($item_id),
  300. dbesc($item_id)
  301. );
  302. if(!$r)
  303. return '';
  304. }
  305. // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
  306. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
  307. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
  308. `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
  309. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  310. FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  311. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  312. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  313. and `item`.`moderated` = 0
  314. AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
  315. AND uid = %d)
  316. $sql_extra
  317. ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
  318. intval($a->profile['uid']),
  319. dbesc($item_id),
  320. dbesc($item_id),
  321. intval($a->profile['uid'])
  322. );
  323. if(!$r && local_user()) {
  324. // Check if this is another person's link to a post that we have
  325. $r = q("SELECT `item`.uri FROM `item`
  326. WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
  327. LIMIT 1",
  328. dbesc($item_id),
  329. dbesc($item_id)
  330. );
  331. if($r) {
  332. $item_uri = $r[0]['uri'];
  333. // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
  334. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
  335. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
  336. `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
  337. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  338. FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  339. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  340. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  341. and `item`.`moderated` = 0
  342. AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
  343. ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
  344. intval(local_user()),
  345. dbesc($item_uri),
  346. intval(local_user())
  347. );
  348. }
  349. }
  350. if($r) {
  351. if((local_user()) && (local_user() == $a->profile['uid'])) {
  352. q("UPDATE `item` SET `unseen` = 0
  353. WHERE `parent` = %d AND `unseen` = 1",
  354. intval($r[0]['parent'])
  355. );
  356. }
  357. $items = conv_sort($r,"`commented`");
  358. if(!$update)
  359. $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
  360. $o .= conversation($a,$items,'display', $update);
  361. // Preparing the meta header
  362. require_once('include/bbcode.php');
  363. require_once("include/html2plain.php");
  364. $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
  365. $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
  366. $author_name = $r[0]["author-name"];
  367. $image = "";
  368. if ($image == "")
  369. $image = $r[0]["thumb"];
  370. if ($title == "")
  371. $title = $author_name;
  372. $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
  373. $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
  374. $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
  375. //<meta name="keywords" content="">
  376. $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
  377. $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
  378. $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
  379. $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
  380. // Schema.org microdata
  381. $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
  382. $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
  383. $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
  384. $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
  385. // Twitter cards
  386. $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
  387. $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
  388. $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
  389. $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
  390. $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
  391. // Dublin Core
  392. $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
  393. $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
  394. // Open Graph
  395. $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
  396. $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
  397. $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
  398. $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
  399. $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
  400. $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
  401. // article:tag
  402. return $o;
  403. }
  404. $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
  405. dbesc($item_id),
  406. dbesc($item_id)
  407. );
  408. if($r) {
  409. if($r[0]['deleted']) {
  410. notice( t('Item has been removed.') . EOL );
  411. }
  412. else {
  413. notice( t('Permission denied.') . EOL );
  414. }
  415. }
  416. else {
  417. notice( t('Item not found.') . EOL );
  418. }
  419. return $o;
  420. }