Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

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