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.
 
 
 
 
 
 

1278 lines
40 KiB

  1. <?php
  2. /**
  3. *
  4. * This is the POST destination for most all locally posted
  5. * text stuff. This function handles status, wall-to-wall status,
  6. * local comments, and remote coments that are posted on this site
  7. * (as opposed to being delivered in a feed).
  8. * Also processed here are posts and comments coming through the
  9. * statusnet/twitter API.
  10. * All of these become an "item" which is our basic unit of
  11. * information.
  12. * Posts that originate externally or do not fall into the above
  13. * posting categories go through item_store() instead of this function.
  14. *
  15. */
  16. require_once('include/crypto.php');
  17. require_once('include/enotify.php');
  18. require_once('include/email.php');
  19. require_once('include/tags.php');
  20. require_once('include/files.php');
  21. require_once('include/threads.php');
  22. require_once('include/text.php');
  23. require_once('include/items.php');
  24. require_once('include/Scrape.php');
  25. require_once('include/diaspora.php');
  26. require_once('include/Contact.php');
  27. function item_post(&$a) {
  28. if((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter')))
  29. return;
  30. require_once('include/security.php');
  31. $uid = local_user();
  32. if(x($_REQUEST,'dropitems')) {
  33. $arr_drop = explode(',',$_REQUEST['dropitems']);
  34. drop_items($arr_drop);
  35. $json = array('success' => 1);
  36. echo json_encode($json);
  37. killme();
  38. }
  39. call_hooks('post_local_start', $_REQUEST);
  40. // logger('postinput ' . file_get_contents('php://input'));
  41. logger('postvars ' . print_r($_REQUEST,true), LOGGER_DATA);
  42. $api_source = ((x($_REQUEST,'api_source') && $_REQUEST['api_source']) ? true : false);
  43. $message_id = ((x($_REQUEST,'message_id') && $api_source) ? strip_tags($_REQUEST['message_id']) : '');
  44. $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
  45. $preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0);
  46. // Check for doubly-submitted posts, and reject duplicates
  47. // Note that we have to ignore previews, otherwise nothing will post
  48. // after it's been previewed
  49. if(!$preview && x($_REQUEST['post_id_random'])) {
  50. if(x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) {
  51. logger("item post: duplicate post", LOGGER_DEBUG);
  52. item_post_return($a->get_baseurl(), $api_source, $return_path);
  53. }
  54. else
  55. $_SESSION['post-random'] = $_REQUEST['post_id_random'];
  56. }
  57. /**
  58. * Is this a reply to something?
  59. */
  60. $parent = ((x($_REQUEST,'parent')) ? intval($_REQUEST['parent']) : 0);
  61. $parent_uri = ((x($_REQUEST,'parent_uri')) ? trim($_REQUEST['parent_uri']) : '');
  62. $parent_item = null;
  63. $parent_contact = null;
  64. $thr_parent = '';
  65. $parid = 0;
  66. $r = false;
  67. $objecttype = null;
  68. if($parent || $parent_uri) {
  69. $objecttype = ACTIVITY_OBJ_COMMENT;
  70. if(! x($_REQUEST,'type'))
  71. $_REQUEST['type'] = 'net-comment';
  72. if($parent) {
  73. $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
  74. intval($parent)
  75. );
  76. } elseif($parent_uri && local_user()) {
  77. // This is coming from an API source, and we are logged in
  78. $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
  79. dbesc($parent_uri),
  80. intval(local_user())
  81. );
  82. }
  83. // if this isn't the real parent of the conversation, find it
  84. if($r !== false && count($r)) {
  85. $parid = $r[0]['parent'];
  86. $parent_uri = $r[0]['uri'];
  87. if($r[0]['id'] != $r[0]['parent']) {
  88. $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1",
  89. intval($parid)
  90. );
  91. }
  92. }
  93. if(($r === false) || (! count($r))) {
  94. notice( t('Unable to locate original post.') . EOL);
  95. if(x($_REQUEST,'return'))
  96. goaway($a->get_baseurl() . "/" . $return_path );
  97. killme();
  98. }
  99. $parent_item = $r[0];
  100. $parent = $r[0]['id'];
  101. // multi-level threading - preserve the info but re-parent to our single level threading
  102. //if(($parid) && ($parid != $parent))
  103. $thr_parent = $parent_uri;
  104. if($parent_item['contact-id'] && $uid) {
  105. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  106. intval($parent_item['contact-id']),
  107. intval($uid)
  108. );
  109. if(count($r))
  110. $parent_contact = $r[0];
  111. // If the contact id doesn't fit with the contact, then set the contact to null
  112. $thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent));
  113. if (count($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS)
  114. AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
  115. $parent_contact = null;
  116. $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
  117. dbesc(normalise_link($thrparent[0]["author-link"])));
  118. if (count($r)) {
  119. $parent_contact = $r[0];
  120. $parent_contact["thumb"] = $parent_contact["photo"];
  121. $parent_contact["micro"] = $parent_contact["photo"];
  122. unset($parent_contact["id"]);
  123. }
  124. if (!isset($parent_contact["nick"])) {
  125. require_once("include/Scrape.php");
  126. $probed_contact = probe_url($thrparent[0]["author-link"]);
  127. if ($probed_contact["network"] != NETWORK_FEED) {
  128. $parent_contact = $probed_contact;
  129. $parent_contact["nurl"] = normalise_link($probed_contact["url"]);
  130. $parent_contact["thumb"] = $probed_contact["photo"];
  131. $parent_contact["micro"] = $probed_contact["photo"];
  132. $parent_contact["addr"] = $probed_contact["addr"];
  133. }
  134. }
  135. logger('no contact found: '.print_r($thrparent, true), LOGGER_DEBUG);
  136. } else
  137. logger('parent contact: '.print_r($parent_contact, true), LOGGER_DEBUG);
  138. if ($parent_contact["nick"] == "")
  139. $parent_contact["nick"] = $parent_contact["name"];
  140. }
  141. }
  142. if($parent) logger('mod_item: item_post parent=' . $parent);
  143. $profile_uid = ((x($_REQUEST,'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0);
  144. $post_id = ((x($_REQUEST,'post_id')) ? intval($_REQUEST['post_id']) : 0);
  145. $app = ((x($_REQUEST,'source')) ? strip_tags($_REQUEST['source']) : '');
  146. $extid = ((x($_REQUEST,'extid')) ? strip_tags($_REQUEST['extid']) : '');
  147. $allow_moderated = false;
  148. // here is where we are going to check for permission to post a moderated comment.
  149. // First check that the parent exists and it is a wall item.
  150. if((x($_REQUEST,'commenter')) && ((! $parent) || (! $parent_item['wall']))) {
  151. notice( t('Permission denied.') . EOL) ;
  152. if(x($_REQUEST,'return'))
  153. goaway($a->get_baseurl() . "/" . $return_path );
  154. killme();
  155. }
  156. // Now check that it is a page_type of PAGE_BLOG, and that valid personal details
  157. // have been provided, and run any anti-spam plugins
  158. if((! can_write_wall($a,$profile_uid)) && (! $allow_moderated)) {
  159. notice( t('Permission denied.') . EOL) ;
  160. if(x($_REQUEST,'return'))
  161. goaway($a->get_baseurl() . "/" . $return_path );
  162. killme();
  163. }
  164. // is this an edited post?
  165. $orig_post = null;
  166. if($post_id) {
  167. $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
  168. intval($profile_uid),
  169. intval($post_id)
  170. );
  171. if(! count($i))
  172. killme();
  173. $orig_post = $i[0];
  174. }
  175. $user = null;
  176. $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
  177. intval($profile_uid)
  178. );
  179. if(count($r))
  180. $user = $r[0];
  181. if($orig_post) {
  182. $str_group_allow = $orig_post['allow_gid'];
  183. $str_contact_allow = $orig_post['allow_cid'];
  184. $str_group_deny = $orig_post['deny_gid'];
  185. $str_contact_deny = $orig_post['deny_cid'];
  186. $location = $orig_post['location'];
  187. $coord = $orig_post['coord'];
  188. $verb = $orig_post['verb'];
  189. $objecttype = $orig_post['object-type'];
  190. $emailcc = $orig_post['emailcc'];
  191. $app = $orig_post['app'];
  192. $categories = $orig_post['file'];
  193. $title = notags(trim($_REQUEST['title']));
  194. $body = escape_tags(trim($_REQUEST['body']));
  195. $private = $orig_post['private'];
  196. $pubmail_enable = $orig_post['pubmail'];
  197. $network = $orig_post['network'];
  198. $guid = $orig_post['guid'];
  199. $extid = $orig_post['extid'];
  200. } else {
  201. // if coming from the API and no privacy settings are set,
  202. // use the user default permissions - as they won't have
  203. // been supplied via a form.
  204. if(($api_source)
  205. && (! array_key_exists('contact_allow',$_REQUEST))
  206. && (! array_key_exists('group_allow',$_REQUEST))
  207. && (! array_key_exists('contact_deny',$_REQUEST))
  208. && (! array_key_exists('group_deny',$_REQUEST))) {
  209. $str_group_allow = $user['allow_gid'];
  210. $str_contact_allow = $user['allow_cid'];
  211. $str_group_deny = $user['deny_gid'];
  212. $str_contact_deny = $user['deny_cid'];
  213. }
  214. else {
  215. // use the posted permissions
  216. $str_group_allow = perms2str($_REQUEST['group_allow']);
  217. $str_contact_allow = perms2str($_REQUEST['contact_allow']);
  218. $str_group_deny = perms2str($_REQUEST['group_deny']);
  219. $str_contact_deny = perms2str($_REQUEST['contact_deny']);
  220. }
  221. $title = notags(trim($_REQUEST['title']));
  222. $location = notags(trim($_REQUEST['location']));
  223. $coord = notags(trim($_REQUEST['coord']));
  224. $verb = notags(trim($_REQUEST['verb']));
  225. $emailcc = notags(trim($_REQUEST['emailcc']));
  226. $body = escape_tags(trim($_REQUEST['body']));
  227. $network = notags(trim($_REQUEST['network']));
  228. $guid = get_guid(32);
  229. item_add_language_opt($_REQUEST);
  230. $postopts = $_REQUEST['postopts'] ? $_REQUEST['postopts'] : "";
  231. $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
  232. if($user['hidewall'])
  233. $private = 2;
  234. // If this is a comment, set the permissions from the parent.
  235. if($parent_item) {
  236. // for non native networks use the network of the original post as network of the item
  237. if (($parent_item['network'] != NETWORK_DIASPORA)
  238. AND ($parent_item['network'] != NETWORK_OSTATUS)
  239. AND ($network == ""))
  240. $network = $parent_item['network'];
  241. $str_contact_allow = $parent_item['allow_cid'];
  242. $str_group_allow = $parent_item['allow_gid'];
  243. $str_contact_deny = $parent_item['deny_cid'];
  244. $str_group_deny = $parent_item['deny_gid'];
  245. $private = $parent_item['private'];
  246. }
  247. $pubmail_enable = ((x($_REQUEST,'pubmail_enable') && intval($_REQUEST['pubmail_enable']) && (! $private)) ? 1 : 0);
  248. // if using the API, we won't see pubmail_enable - figure out if it should be set
  249. if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) {
  250. $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
  251. if(! $mail_disabled) {
  252. $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
  253. intval(local_user())
  254. );
  255. if(count($r) && intval($r[0]['pubmail']))
  256. $pubmail_enabled = true;
  257. }
  258. }
  259. if(! strlen($body)) {
  260. if($preview)
  261. killme();
  262. info( t('Empty post discarded.') . EOL );
  263. if(x($_REQUEST,'return'))
  264. goaway($a->get_baseurl() . "/" . $return_path );
  265. killme();
  266. }
  267. }
  268. if(strlen($categories)) {
  269. // get the "fileas" tags for this post
  270. $filedas = file_tag_file_to_list($categories, 'file');
  271. }
  272. // save old and new categories, so we can determine what needs to be deleted from pconfig
  273. $categories_old = $categories;
  274. $categories = file_tag_list_to_file(trim($_REQUEST['category']), 'category');
  275. $categories_new = $categories;
  276. if(strlen($filedas)) {
  277. // append the fileas stuff to the new categories list
  278. $categories .= file_tag_list_to_file($filedas, 'file');
  279. }
  280. // Work around doubled linefeeds in Tinymce 3.5b2
  281. // First figure out if it's a status post that would've been
  282. // created using tinymce. Otherwise leave it alone.
  283. /* $plaintext = (local_user() ? intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled($profile_uid,'richtext') : 0);
  284. if((! $parent) && (! $api_source) && (! $plaintext)) {
  285. $body = fix_mce_lf($body);
  286. }*/
  287. $plaintext = (local_user() ? !feature_enabled($profile_uid,'richtext') : 0);
  288. if((! $parent) && (! $api_source) && (! $plaintext)) {
  289. $body = fix_mce_lf($body);
  290. }
  291. // get contact info for poster
  292. $author = null;
  293. $self = false;
  294. $contact_id = 0;
  295. if((local_user()) && (local_user() == $profile_uid)) {
  296. $self = true;
  297. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
  298. intval($_SESSION['uid']));
  299. }
  300. elseif(remote_user()) {
  301. if(is_array($_SESSION['remote'])) {
  302. foreach($_SESSION['remote'] as $v) {
  303. if($v['uid'] == $profile_uid) {
  304. $contact_id = $v['cid'];
  305. break;
  306. }
  307. }
  308. }
  309. if($contact_id) {
  310. $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
  311. intval($contact_id)
  312. );
  313. }
  314. }
  315. if(count($r)) {
  316. $author = $r[0];
  317. $contact_id = $author['id'];
  318. }
  319. // get contact info for owner
  320. if($profile_uid == local_user()) {
  321. $contact_record = $author;
  322. }
  323. else {
  324. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
  325. intval($profile_uid)
  326. );
  327. if(count($r))
  328. $contact_record = $r[0];
  329. }
  330. $post_type = notags(trim($_REQUEST['type']));
  331. if($post_type === 'net-comment') {
  332. if($parent_item !== null) {
  333. if($parent_item['wall'] == 1)
  334. $post_type = 'wall-comment';
  335. else
  336. $post_type = 'remote-comment';
  337. }
  338. }
  339. /**
  340. *
  341. * When a photo was uploaded into the message using the (profile wall) ajax
  342. * uploader, The permissions are initially set to disallow anybody but the
  343. * owner from seeing it. This is because the permissions may not yet have been
  344. * set for the post. If it's private, the photo permissions should be set
  345. * appropriately. But we didn't know the final permissions on the post until
  346. * now. So now we'll look for links of uploaded messages that are in the
  347. * post and set them to the same permissions as the post itself.
  348. *
  349. */
  350. $match = null;
  351. if((! $preview) && preg_match_all("/\[img([\=0-9x]*?)\](.*?)\[\/img\]/",$body,$match)) {
  352. $images = $match[2];
  353. if(count($images)) {
  354. $objecttype = ACTIVITY_OBJ_IMAGE;
  355. foreach($images as $image) {
  356. if(! stristr($image,$a->get_baseurl() . '/photo/'))
  357. continue;
  358. $image_uri = substr($image,strrpos($image,'/') + 1);
  359. $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
  360. if(! strlen($image_uri))
  361. continue;
  362. $srch = '<' . intval($contact_id) . '>';
  363. $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''
  364. AND `resource-id` = '%s' AND `uid` = %d LIMIT 1",
  365. dbesc($srch),
  366. dbesc($image_uri),
  367. intval($profile_uid)
  368. );
  369. if(! count($r))
  370. continue;
  371. $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
  372. WHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ",
  373. dbesc($str_contact_allow),
  374. dbesc($str_group_allow),
  375. dbesc($str_contact_deny),
  376. dbesc($str_group_deny),
  377. dbesc($image_uri),
  378. intval($profile_uid),
  379. dbesc( t('Wall Photos'))
  380. );
  381. }
  382. }
  383. }
  384. /**
  385. * Next link in any attachment references we find in the post.
  386. */
  387. $match = false;
  388. if((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) {
  389. $attaches = $match[1];
  390. if(count($attaches)) {
  391. foreach($attaches as $attach) {
  392. $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
  393. intval($profile_uid),
  394. intval($attach)
  395. );
  396. if(count($r)) {
  397. $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
  398. WHERE `uid` = %d AND `id` = %d",
  399. dbesc($str_contact_allow),
  400. dbesc($str_group_allow),
  401. dbesc($str_contact_deny),
  402. dbesc($str_group_deny),
  403. intval($profile_uid),
  404. intval($attach)
  405. );
  406. }
  407. }
  408. }
  409. }
  410. // embedded bookmark or attachment in post? set bookmark flag
  411. $bookmark = 0;
  412. $data = get_attachment_data($body);
  413. if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) OR isset($data["type"])) {
  414. $objecttype = ACTIVITY_OBJ_BOOKMARK;
  415. $bookmark = 1;
  416. }
  417. $body = bb_translate_video($body);
  418. /**
  419. * Fold multi-line [code] sequences
  420. */
  421. $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body);
  422. $body = scale_external_images($body,false);
  423. // Setting the object type if not defined before
  424. if (!$objecttype) {
  425. $objecttype = ACTIVITY_OBJ_NOTE; // Default value
  426. require_once("include/plaintext.php");
  427. $objectdata = get_attached_data($body);
  428. if ($post["type"] == "link")
  429. $objecttype = ACTIVITY_OBJ_BOOKMARK;
  430. elseif ($post["type"] == "video")
  431. $objecttype = ACTIVITY_OBJ_VIDEO;
  432. elseif ($post["type"] == "photo")
  433. $objecttype = ACTIVITY_OBJ_IMAGE;
  434. }
  435. /**
  436. * Look for any tags and linkify them
  437. */
  438. $str_tags = '';
  439. $inform = '';
  440. $tags = get_tags($body);
  441. /**
  442. * add a statusnet style reply tag if the original post was from there
  443. * and we are replying, and there isn't one already
  444. */
  445. if($parent AND ($parent_contact['network'] === NETWORK_OSTATUS)) {
  446. if ($parent_contact['id'] != "")
  447. $contact = '@'.$parent_contact['nick'].'+'.$parent_contact['id'];
  448. else
  449. $contact = '@[url='.$parent_contact['url'].']'.$parent_contact['nick'].'[/url]';
  450. if (!in_array($contact,$tags)) {
  451. $body = $contact.' '.$body;
  452. $tags[] = $contact;
  453. }
  454. $toplevel_contact = "";
  455. $toplevel_parent = q("SELECT `contact`.* FROM `contact`
  456. INNER JOIN `item` ON `item`.`contact-id` = `contact`.`id` AND `contact`.`url` = `item`.`author-link`
  457. WHERE `item`.`id` = `item`.`parent` AND `item`.`parent` = %d", intval($parent));
  458. if ($toplevel_parent)
  459. $toplevel_contact = '@'.$toplevel_parent[0]['nick'].'+'.$toplevel_parent[0]['id'];
  460. else {
  461. $toplevel_parent = q("SELECT `author-link`, `author-name` FROM `item` WHERE `id` = `parent` AND `parent` = %d", intval($parent));
  462. $toplevel_contact = '@[url='.$toplevel_parent[0]['author-link'].']'.$toplevel_parent[0]['author-name'].'[/url]';
  463. }
  464. if (!in_array($toplevel_contact,$tags))
  465. $tags[] = $toplevel_contact;
  466. }
  467. $tagged = array();
  468. $private_forum = false;
  469. if(count($tags)) {
  470. foreach($tags as $tag) {
  471. if(strpos($tag,'#') === 0)
  472. continue;
  473. // If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
  474. // Robert Johnson should be first in the $tags array
  475. $fullnametagged = false;
  476. for($x = 0; $x < count($tagged); $x ++) {
  477. if(stristr($tagged[$x],$tag . ' ')) {
  478. $fullnametagged = true;
  479. break;
  480. }
  481. }
  482. if($fullnametagged)
  483. continue;
  484. $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network);
  485. if($success['replaced'])
  486. $tagged[] = $tag;
  487. if(is_array($success['contact']) && intval($success['contact']['prv'])) {
  488. $private_forum = true;
  489. $private_id = $success['contact']['id'];
  490. }
  491. }
  492. }
  493. if(($private_forum) && (! $parent) && (! $private)) {
  494. // we tagged a private forum in a top level post and the message was public.
  495. // Restrict it.
  496. $private = 1;
  497. $str_contact_allow = '<' . $private_id . '>';
  498. }
  499. $attachments = '';
  500. $match = false;
  501. if(preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
  502. foreach($match[2] as $mtch) {
  503. $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
  504. intval($profile_uid),
  505. intval($mtch)
  506. );
  507. if(count($r)) {
  508. if(strlen($attachments))
  509. $attachments .= ',';
  510. $attachments .= '[attach]href="' . $a->get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : '') . '"[/attach]';
  511. }
  512. $body = str_replace($match[1],'',$body);
  513. }
  514. }
  515. $wall = 0;
  516. if($post_type === 'wall' || $post_type === 'wall-comment')
  517. $wall = 1;
  518. if(! strlen($verb))
  519. $verb = ACTIVITY_POST ;
  520. if ($network == "")
  521. $network = NETWORK_DFRN;
  522. $gravity = (($parent) ? 6 : 0 );
  523. // even if the post arrived via API we are considering that it
  524. // originated on this site by default for determining relayability.
  525. $origin = ((x($_REQUEST,'origin')) ? intval($_REQUEST['origin']) : 1);
  526. $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
  527. $uri = (($message_id) ? $message_id : item_new_uri($a->get_hostname(),$profile_uid, $guid));
  528. // Fallback so that we alway have a thr-parent
  529. if(!$thr_parent)
  530. $thr_parent = $uri;
  531. $datarray = array();
  532. $datarray['uid'] = $profile_uid;
  533. $datarray['type'] = $post_type;
  534. $datarray['wall'] = $wall;
  535. $datarray['gravity'] = $gravity;
  536. $datarray['network'] = $network;
  537. $datarray['contact-id'] = $contact_id;
  538. $datarray['owner-name'] = $contact_record['name'];
  539. $datarray['owner-link'] = $contact_record['url'];
  540. $datarray['owner-avatar'] = $contact_record['thumb'];
  541. $datarray["owner-id"] = get_contact($datarray["owner-link"], 0);
  542. $datarray['author-name'] = $author['name'];
  543. $datarray['author-link'] = $author['url'];
  544. $datarray['author-avatar'] = $author['thumb'];
  545. $datarray["author-id"] = get_contact($datarray["author-link"], 0);
  546. $datarray['created'] = datetime_convert();
  547. $datarray['edited'] = datetime_convert();
  548. $datarray['commented'] = datetime_convert();
  549. $datarray['received'] = datetime_convert();
  550. $datarray['changed'] = datetime_convert();
  551. $datarray['extid'] = $extid;
  552. $datarray['guid'] = $guid;
  553. $datarray['uri'] = $uri;
  554. $datarray['title'] = $title;
  555. $datarray['body'] = $body;
  556. $datarray['app'] = $app;
  557. $datarray['location'] = $location;
  558. $datarray['coord'] = $coord;
  559. $datarray['tag'] = $str_tags;
  560. $datarray['file'] = $categories;
  561. $datarray['inform'] = $inform;
  562. $datarray['verb'] = $verb;
  563. $datarray['object-type'] = $objecttype;
  564. $datarray['allow_cid'] = $str_contact_allow;
  565. $datarray['allow_gid'] = $str_group_allow;
  566. $datarray['deny_cid'] = $str_contact_deny;
  567. $datarray['deny_gid'] = $str_group_deny;
  568. $datarray['private'] = $private;
  569. $datarray['pubmail'] = $pubmail_enable;
  570. $datarray['attach'] = $attachments;
  571. $datarray['bookmark'] = intval($bookmark);
  572. $datarray['thr-parent'] = $thr_parent;
  573. $datarray['postopts'] = $postopts;
  574. $datarray['origin'] = $origin;
  575. $datarray['moderated'] = $allow_moderated;
  576. $datarray['gcontact-id'] = get_gcontact_id(array("url" => $datarray['author-link'], "network" => $datarray['network'],
  577. "photo" => $datarray['author-avatar'], "name" => $datarray['author-name']));
  578. /**
  579. * These fields are for the convenience of plugins...
  580. * 'self' if true indicates the owner is posting on their own wall
  581. * If parent is 0 it is a top-level post.
  582. */
  583. $datarray['parent'] = $parent;
  584. $datarray['self'] = $self;
  585. // $datarray['prvnets'] = $user['prvnets'];
  586. $datarray['parent-uri'] = ($parent == 0) ? $uri : $parent_item['uri'];
  587. $datarray['plink'] = $a->get_baseurl().'/display/'.urlencode($datarray['guid']);
  588. $datarray['last-child'] = 1;
  589. $datarray['visible'] = 1;
  590. if($orig_post)
  591. $datarray['edit'] = true;
  592. // Search for hashtags
  593. item_body_set_hashtags($datarray);
  594. // preview mode - prepare the body for display and send it via json
  595. if($preview) {
  596. require_once('include/conversation.php');
  597. $o = conversation($a,array(array_merge($contact_record,$datarray)),'search', false, true);
  598. logger('preview: ' . $o);
  599. echo json_encode(array('preview' => $o));
  600. killme();
  601. }
  602. call_hooks('post_local',$datarray);
  603. if(x($datarray,'cancel')) {
  604. logger('mod_item: post cancelled by plugin.');
  605. if($return_path) {
  606. goaway($a->get_baseurl() . "/" . $return_path);
  607. }
  608. $json = array('cancel' => 1);
  609. if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload']))
  610. $json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload'];
  611. echo json_encode($json);
  612. killme();
  613. }
  614. // Fill the cache field
  615. put_item_in_cache($datarray);
  616. if($orig_post) {
  617. $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
  618. dbesc($datarray['title']),
  619. dbesc($datarray['body']),
  620. dbesc($datarray['tag']),
  621. dbesc($datarray['attach']),
  622. dbesc($datarray['file']),
  623. dbesc($datarray['rendered-html']),
  624. dbesc($datarray['rendered-hash']),
  625. dbesc(datetime_convert()),
  626. dbesc(datetime_convert()),
  627. intval($post_id),
  628. intval($profile_uid)
  629. );
  630. create_tags_from_item($post_id);
  631. create_files_from_item($post_id);
  632. update_thread($post_id);
  633. // update filetags in pconfig
  634. file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
  635. proc_run(PRIORITY_HIGH, "include/notifier.php", 'edit_post', $post_id);
  636. if((x($_REQUEST,'return')) && strlen($return_path)) {
  637. logger('return: ' . $return_path);
  638. goaway($a->get_baseurl() . "/" . $return_path );
  639. }
  640. killme();
  641. } else
  642. $post_id = 0;
  643. $r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`,
  644. `owner-name`,`owner-link`,`owner-avatar`, `owner-id`,
  645. `author-name`, `author-link`, `author-avatar`, `author-id`,
  646. `created`, `edited`, `commented`, `received`, `changed`,
  647. `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`,
  648. `tag`, `inform`, `verb`, `object-type`, `postopts`,
  649. `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`,
  650. `pubmail`, `attach`, `bookmark`,`origin`, `moderated`, `file`,
  651. `rendered-html`, `rendered-hash`,
  652. `parent`, `parent-uri`, `plink`, `last-child`, `visible`)
  653. VALUES('%s', '%s', %d, '%s', %d, %d, '%s', %d,
  654. '%s', '%s', '%s', %d,
  655. '%s', '%s', '%s', %d,
  656. '%s', '%s', '%s', '%s', '%s',
  657. '%s', '%s', '%s', '%s', '%s', '%s', '%s',
  658. '%s', '%s', '%s', '%s', '%s',
  659. '%s', '%s', '%s', '%s', %d,
  660. %d, '%s', %d, %d, %d, '%s',
  661. '%s', '%s',
  662. %d, '%s', '%s', %d, %d)",
  663. dbesc($datarray['guid']),
  664. dbesc($datarray['extid']),
  665. intval($datarray['uid']),
  666. dbesc($datarray['type']),
  667. intval($datarray['wall']),
  668. intval($datarray['gravity']),
  669. dbesc($datarray['network']),
  670. intval($datarray['contact-id']),
  671. dbesc($datarray['owner-name']),
  672. dbesc($datarray['owner-link']),
  673. dbesc($datarray['owner-avatar']),
  674. intval($datarray['owner-id']),
  675. dbesc($datarray['author-name']),
  676. dbesc($datarray['author-link']),
  677. dbesc($datarray['author-avatar']),
  678. intval($datarray['author-id']),
  679. dbesc($datarray['created']),
  680. dbesc($datarray['edited']),
  681. dbesc($datarray['commented']),
  682. dbesc($datarray['received']),
  683. dbesc($datarray['changed']),
  684. dbesc($datarray['uri']),
  685. dbesc($datarray['thr-parent']),
  686. dbesc($datarray['title']),
  687. dbesc($datarray['body']),
  688. dbesc($datarray['app']),
  689. dbesc($datarray['location']),
  690. dbesc($datarray['coord']),
  691. dbesc($datarray['tag']),
  692. dbesc($datarray['inform']),
  693. dbesc($datarray['verb']),
  694. dbesc($datarray['object-type']),
  695. dbesc($datarray['postopts']),
  696. dbesc($datarray['allow_cid']),
  697. dbesc($datarray['allow_gid']),
  698. dbesc($datarray['deny_cid']),
  699. dbesc($datarray['deny_gid']),
  700. intval($datarray['private']),
  701. intval($datarray['pubmail']),
  702. dbesc($datarray['attach']),
  703. intval($datarray['bookmark']),
  704. intval($datarray['origin']),
  705. intval($datarray['moderated']),
  706. dbesc($datarray['file']),
  707. dbesc($datarray['rendered-html']),
  708. dbesc($datarray['rendered-hash']),
  709. intval($datarray['parent']),
  710. dbesc($datarray['parent-uri']),
  711. dbesc($datarray['plink']),
  712. intval($datarray['last-child']),
  713. intval($datarray['visible'])
  714. );
  715. $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
  716. dbesc($datarray['uri']));
  717. if(!count($r)) {
  718. logger('mod_item: unable to retrieve post that was just stored.');
  719. notice( t('System error. Post not saved.') . EOL);
  720. goaway($a->get_baseurl() . "/" . $return_path );
  721. // NOTREACHED
  722. }
  723. $post_id = $r[0]['id'];
  724. logger('mod_item: saved item ' . $post_id);
  725. $datarray["id"] = $post_id;
  726. item_set_last_item($datarray);
  727. // update filetags in pconfig
  728. file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
  729. if($parent) {
  730. // This item is the last leaf and gets the comment box, clear any ancestors
  731. $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d AND `last-child` AND `id` != %d",
  732. dbesc(datetime_convert()),
  733. intval($parent),
  734. intval($post_id)
  735. );
  736. // update the commented timestamp on the parent
  737. q("UPDATE `item` SET `visible` = 1, `commented` = '%s', `changed` = '%s' WHERE `id` = %d",
  738. dbesc(datetime_convert()),
  739. dbesc(datetime_convert()),
  740. intval($parent)
  741. );
  742. if($contact_record != $author) {
  743. notification(array(
  744. 'type' => NOTIFY_COMMENT,
  745. 'notify_flags' => $user['notify-flags'],
  746. 'language' => $user['language'],
  747. 'to_name' => $user['username'],
  748. 'to_email' => $user['email'],
  749. 'uid' => $user['uid'],
  750. 'item' => $datarray,
  751. 'link' => $a->get_baseurl().'/display/'.urlencode($datarray['guid']),
  752. 'source_name' => $datarray['author-name'],
  753. 'source_link' => $datarray['author-link'],
  754. 'source_photo' => $datarray['author-avatar'],
  755. 'verb' => ACTIVITY_POST,
  756. 'otype' => 'item',
  757. 'parent' => $parent,
  758. 'parent_uri' => $parent_item['uri']
  759. ));
  760. }
  761. // Store the comment signature information in case we need to relay to Diaspora
  762. diaspora::store_comment_signature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id);
  763. } else {
  764. $parent = $post_id;
  765. $r = q("UPDATE `item` SET `parent` = %d WHERE `id` = %d",
  766. intval($parent),
  767. intval($post_id));
  768. if($contact_record != $author) {
  769. notification(array(
  770. 'type' => NOTIFY_WALL,
  771. 'notify_flags' => $user['notify-flags'],
  772. 'language' => $user['language'],
  773. 'to_name' => $user['username'],
  774. 'to_email' => $user['email'],
  775. 'uid' => $user['uid'],
  776. 'item' => $datarray,
  777. 'link' => $a->get_baseurl().'/display/'.urlencode($datarray['guid']),
  778. 'source_name' => $datarray['author-name'],
  779. 'source_link' => $datarray['author-link'],
  780. 'source_photo' => $datarray['author-avatar'],
  781. 'verb' => ACTIVITY_POST,
  782. 'otype' => 'item'
  783. ));
  784. }
  785. }
  786. call_hooks('post_local_end', $datarray);
  787. if(strlen($emailcc) && $profile_uid == local_user()) {
  788. $erecips = explode(',', $emailcc);
  789. if(count($erecips)) {
  790. foreach($erecips as $recip) {
  791. $addr = trim($recip);
  792. if(! strlen($addr))
  793. continue;
  794. $disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'),$a->user['username'])
  795. . '<br />';
  796. $disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
  797. $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
  798. if (!$datarray['title']=='') {
  799. $subject = email_header_encode($datarray['title'],'UTF-8');
  800. } else {
  801. $subject = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']),'UTF-8');
  802. }
  803. $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
  804. $html = prepare_body($datarray);
  805. $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
  806. include_once('include/html2plain.php');
  807. $params = array (
  808. 'fromName' => $a->user['username'],
  809. 'fromEmail' => $a->user['email'],
  810. 'toEmail' => $addr,
  811. 'replyTo' => $a->user['email'],
  812. 'messageSubject' => $subject,
  813. 'htmlVersion' => $message,
  814. 'textVersion' => html2plain($html.$disclaimer),
  815. );
  816. Emailer::send($params);
  817. }
  818. }
  819. }
  820. create_tags_from_item($post_id);
  821. create_files_from_item($post_id);
  822. if ($post_id == $parent)
  823. add_thread($post_id);
  824. else {
  825. update_thread($parent, true);
  826. // Insert an item entry for UID=0 for global entries
  827. // We have to remove or change some data before that,
  828. // so that the post appear like a regular received post.
  829. unset($datarray['self']);
  830. unset($datarray['wall']);
  831. unset($datarray['origin']);
  832. if (in_array($datarray['type'], array("net-comment", "wall-comment")))
  833. $datarray['type'] = 'remote-comment';
  834. elseif ($datarray['type'] == 'wall')
  835. $datarray['type'] = 'remote';
  836. add_shadow_entry($datarray);
  837. }
  838. // This is a real juggling act on shared hosting services which kill your processes
  839. // e.g. dreamhost. We used to start delivery to our native delivery agents in the background
  840. // and then run our plugin delivery from the foreground. We're now doing plugin delivery first,
  841. // because as soon as you start loading up a bunch of remote delivey processes, *this* page is
  842. // likely to get killed off. If you end up looking at an /item URL and a blank page,
  843. // it's very likely the delivery got killed before all your friends could be notified.
  844. // Currently the only realistic fixes are to use a reliable server - which precludes shared hosting,
  845. // or cut back on plugins which do remote deliveries.
  846. proc_run(PRIORITY_HIGH, "include/notifier.php", $notify_type, $post_id);
  847. logger('post_complete');
  848. item_post_return($a->get_baseurl(), $api_source, $return_path);
  849. // NOTREACHED
  850. }
  851. function item_post_return($baseurl, $api_source, $return_path) {
  852. // figure out how to return, depending on from whence we came
  853. if($api_source)
  854. return;
  855. if($return_path) {
  856. goaway($baseurl . "/" . $return_path);
  857. }
  858. $json = array('success' => 1);
  859. if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload']))
  860. $json['reload'] = $baseurl . '/' . $_REQUEST['jsreload'];
  861. logger('post_json: ' . print_r($json,true), LOGGER_DEBUG);
  862. echo json_encode($json);
  863. killme();
  864. }
  865. function item_content(&$a) {
  866. if((! local_user()) && (! remote_user()))
  867. return;
  868. require_once('include/security.php');
  869. $o = '';
  870. if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
  871. $o = drop_item($a->argv[2], !is_ajax());
  872. if (is_ajax()){
  873. // ajax return: [<item id>, 0 (no perm) | <owner id>]
  874. echo json_encode(array(intval($a->argv[2]), intval($o)));
  875. killme();
  876. }
  877. }
  878. return $o;
  879. }
  880. /**
  881. * This function removes the tag $tag from the text $body and replaces it with
  882. * the appropiate link.
  883. *
  884. * @param unknown_type $body the text to replace the tag in
  885. * @param string $inform a comma-seperated string containing everybody to inform
  886. * @param string $str_tags string to add the tag to
  887. * @param integer $profile_uid
  888. * @param string $tag the tag to replace
  889. * @param string $network The network of the post
  890. *
  891. * @return boolean true if replaced, false if not replaced
  892. */
  893. function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") {
  894. require_once("include/Scrape.php");
  895. require_once("include/socgraph.php");
  896. $replaced = false;
  897. $r = null;
  898. //is it a person tag?
  899. if(strpos($tag,'@') === 0) {
  900. //is it already replaced?
  901. if(strpos($tag,'[url=')) {
  902. //append tag to str_tags
  903. if(!stristr($str_tags,$tag)) {
  904. if(strlen($str_tags))
  905. $str_tags .= ',';
  906. $str_tags .= $tag;
  907. }
  908. // Checking for the alias that is used for OStatus
  909. $pattern = "/@\[url\=(.*?)\](.*?)\[\/url\]/ism";
  910. if (preg_match($pattern, $tag, $matches)) {
  911. $r = q("SELECT `alias`, `name` FROM `contact` WHERE `nurl` = '%s' AND `alias` != '' AND `uid` = 0",
  912. normalise_link($matches[1]));
  913. if (!$r)
  914. $r = q("SELECT `alias`, `name` FROM `gcontact` WHERE `nurl` = '%s' AND `alias` != ''",
  915. normalise_link($matches[1]));
  916. if ($r)
  917. $data = $r[0];
  918. else
  919. $data = probe_url($matches[1]);
  920. if ($data["alias"] != "") {
  921. $newtag = '@[url='.$data["alias"].']'.$data["name"].'[/url]';
  922. if(!stristr($str_tags,$newtag)) {
  923. if(strlen($str_tags))
  924. $str_tags .= ',';
  925. $str_tags .= $newtag;
  926. }
  927. }
  928. }
  929. return $replaced;
  930. }
  931. $stat = false;
  932. //get the person's name
  933. $name = substr($tag,1);
  934. // Sometimes the tag detection doesn't seem to work right
  935. // This is some workaround
  936. $nameparts = explode(" ", $name);
  937. $name = $nameparts[0];
  938. // Try to detect the contact in various ways
  939. if ((strpos($name,'@')) || (strpos($name,'http://'))) {
  940. // Is it in format @user@domain.tld or @http://domain.tld/...?
  941. // First check the contact table for the address
  942. $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `contact`
  943. WHERE `addr` = '%s' AND `uid` = %d AND
  944. (`network` != '%s' OR (`notify` != '' AND `alias` != ''))
  945. LIMIT 1",
  946. dbesc($name),
  947. intval($profile_uid),
  948. dbesc(NETWORK_OSTATUS)
  949. );
  950. // Then check in the contact table for the url
  951. if (!$r)
  952. $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `contact`
  953. WHERE `nurl` = '%s' AND `uid` = %d AND
  954. (`network` != '%s' OR (`notify` != '' AND `alias` != ''))
  955. LIMIT 1",
  956. dbesc(normalise_link($name)),
  957. intval($profile_uid),
  958. dbesc(NETWORK_OSTATUS)
  959. );
  960. // Then check in the global contacts for the address
  961. if (!$r)
  962. $r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact`
  963. WHERE `addr` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != ''))
  964. LIMIT 1",
  965. dbesc($name),
  966. dbesc(NETWORK_OSTATUS)
  967. );
  968. // Then check in the global contacts for the url
  969. if (!$r)
  970. $r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact`
  971. WHERE `nurl` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != ''))
  972. LIMIT 1",
  973. dbesc(normalise_link($name)),
  974. dbesc(NETWORK_OSTATUS)
  975. );
  976. if (!$r) {
  977. $probed = probe_url($name);
  978. if ($result['network'] != NETWORK_PHANTOM) {
  979. update_gcontact($probed);
  980. $r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
  981. dbesc(normalise_link($probed["url"])));
  982. }
  983. }
  984. } else {
  985. $r = false;
  986. if (strrpos($name,'+')) {
  987. // Is it in format @nick+number?
  988. $tagcid = intval(substr($name,strrpos($name,'+') + 1));
  989. $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  990. intval($tagcid),
  991. intval($profile_uid)
  992. );
  993. }
  994. //select someone by attag or nick and the name passed in the current network
  995. if(!$r AND ($network != ""))
  996. $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
  997. dbesc($name),
  998. dbesc($name),
  999. dbesc($network),
  1000. intval($profile_uid)
  1001. );
  1002. //select someone from this user's contacts by name in the current network
  1003. if (!$r AND ($network != ""))
  1004. $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1",
  1005. dbesc($name),
  1006. dbesc($network),
  1007. intval($profile_uid)
  1008. );
  1009. //select someone by attag or nick and the name passed in
  1010. if(!$r)
  1011. $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
  1012. dbesc($name),
  1013. dbesc($name),
  1014. intval($profile_uid)
  1015. );
  1016. //select someone from this user's contacts by name
  1017. if(!$r)
  1018. $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
  1019. dbesc($name),
  1020. intval($profile_uid)
  1021. );
  1022. }
  1023. if ($r) {
  1024. if(strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"])))
  1025. $inform .= ',';
  1026. if (isset($r[0]["id"]))
  1027. $inform .= 'cid:' . $r[0]["id"];
  1028. elseif (isset($r[0]["notify"]))
  1029. $inform .= $r[0]["notify"];
  1030. $profile = $r[0]["url"];
  1031. $alias = $r[0]["alias"];
  1032. $newname = $r[0]["nick"];
  1033. if (($newname == "") OR (($r[0]["network"] != NETWORK_OSTATUS) AND ($r[0]["network"] != NETWORK_TWITTER)
  1034. AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET)))
  1035. $newname = $r[0]["name"];
  1036. }
  1037. //if there is an url for this persons profile
  1038. if (isset($profile) AND ($newname != "")) {
  1039. $replaced = true;
  1040. //create profile link
  1041. $profile = str_replace(',','%2c',$profile);
  1042. $newtag = '@[url='.$profile.']'.$newname.'[/url]';
  1043. $body = str_replace('@'.$name, $newtag, $body);
  1044. //append tag to str_tags
  1045. if(! stristr($str_tags,$newtag)) {
  1046. if(strlen($str_tags))
  1047. $str_tags .= ',';
  1048. $str_tags .= $newtag;
  1049. }
  1050. // Status.Net seems to require the numeric ID URL in a mention if the person isn't
  1051. // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
  1052. if(strlen($alias)) {
  1053. $newtag = '@[url='.$alias.']'.$newname.'[/url]';
  1054. if(! stristr($str_tags,$newtag)) {
  1055. if(strlen($str_tags))
  1056. $str_tags .= ',';
  1057. $str_tags .= $newtag;
  1058. }
  1059. }
  1060. }
  1061. }
  1062. return array('replaced' => $replaced, 'contact' => $r[0]);
  1063. }