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.

222 satır
5.9KB

  1. <?php
  2. require_once('include/security.php');
  3. require_once('include/bbcode.php');
  4. require_once('include/items.php');
  5. function tagger_content(App $a) {
  6. if(! local_user() && ! remote_user()) {
  7. return;
  8. }
  9. $term = notags(trim($_GET['term']));
  10. // no commas allowed
  11. $term = str_replace(array(',',' '),array('','_'),$term);
  12. if(! $term)
  13. return;
  14. $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
  15. logger('tagger: tag ' . $term . ' item ' . $item_id);
  16. $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
  17. dbesc($item_id)
  18. );
  19. if(! $item_id || (! dbm::is_result($r))) {
  20. logger('tagger: no item ' . $item_id);
  21. return;
  22. }
  23. $item = $r[0];
  24. $owner_uid = $item['uid'];
  25. $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
  26. intval($owner_uid)
  27. );
  28. if (dbm::is_result($r)) {
  29. $owner_nick = $r[0]['nickname'];
  30. $blocktags = $r[0]['blocktags'];
  31. }
  32. if(local_user() != $owner_uid)
  33. return;
  34. $r = q("select * from contact where self = 1 and uid = %d limit 1",
  35. intval(local_user())
  36. );
  37. if (dbm::is_result($r))
  38. $contact = $r[0];
  39. else {
  40. logger('tagger: no contact_id');
  41. return;
  42. }
  43. $uri = item_new_uri($a->get_hostname(),$owner_uid);
  44. $xterm = xmlify($term);
  45. $post_type = (($item['resource-id']) ? t('photo') : t('status'));
  46. $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
  47. $link = xmlify('<link rel="alternate" type="text/html" href="'
  48. . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
  49. $body = xmlify($item['body']);
  50. $target = <<< EOT
  51. <target>
  52. <type>$targettype</type>
  53. <local>1</local>
  54. <id>{$item['uri']}</id>
  55. <link>$link</link>
  56. <title></title>
  57. <content>$body</content>
  58. </target>
  59. EOT;
  60. $tagid = App::get_baseurl() . '/search?tag=' . $term;
  61. $objtype = ACTIVITY_OBJ_TAGTERM;
  62. $obj = <<< EOT
  63. <object>
  64. <type>$objtype</type>
  65. <local>1</local>
  66. <id>$tagid</id>
  67. <link>$tagid</link>
  68. <title>$xterm</title>
  69. <content>$xterm</content>
  70. </object>
  71. EOT;
  72. $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
  73. if (! isset($bodyverb)) {
  74. return;
  75. }
  76. $termlink = html_entity_decode('&#x2317;') . '[url=' . App::get_baseurl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
  77. $arr = array();
  78. $arr['guid'] = get_guid(32);
  79. $arr['uri'] = $uri;
  80. $arr['uid'] = $owner_uid;
  81. $arr['contact-id'] = $contact['id'];
  82. $arr['type'] = 'activity';
  83. $arr['wall'] = $item['wall'];
  84. $arr['gravity'] = GRAVITY_COMMENT;
  85. $arr['parent'] = $item['id'];
  86. $arr['parent-uri'] = $item['uri'];
  87. $arr['owner-name'] = $item['author-name'];
  88. $arr['owner-link'] = $item['author-link'];
  89. $arr['owner-avatar'] = $item['author-avatar'];
  90. $arr['author-name'] = $contact['name'];
  91. $arr['author-link'] = $contact['url'];
  92. $arr['author-avatar'] = $contact['thumb'];
  93. $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
  94. $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
  95. $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
  96. $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
  97. $arr['verb'] = ACTIVITY_TAG;
  98. $arr['target-type'] = $targettype;
  99. $arr['target'] = $target;
  100. $arr['object-type'] = $objtype;
  101. $arr['object'] = $obj;
  102. $arr['private'] = $item['private'];
  103. $arr['allow_cid'] = $item['allow_cid'];
  104. $arr['allow_gid'] = $item['allow_gid'];
  105. $arr['deny_cid'] = $item['deny_cid'];
  106. $arr['deny_gid'] = $item['deny_gid'];
  107. $arr['visible'] = 1;
  108. $arr['unseen'] = 1;
  109. $arr['last-child'] = 1;
  110. $arr['origin'] = 1;
  111. $post_id = item_store($arr);
  112. // q("UPDATE `item` set plink = '%s' where id = %d",
  113. // dbesc(App::get_baseurl() . '/display/' . $owner_nick . '/' . $post_id),
  114. // intval($post_id)
  115. // );
  116. if(! $item['visible']) {
  117. $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
  118. intval($item['id']),
  119. intval($owner_uid)
  120. );
  121. }
  122. $term_objtype = (($item['resource-id']) ? TERM_OBJ_PHOTO : TERM_OBJ_POST );
  123. $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
  124. intval($item['id']),
  125. dbesc($term)
  126. );
  127. if((! $blocktags) && $t[0]['tcount']==0 ) {
  128. /*q("update item set tag = '%s' where id = %d",
  129. dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . App::get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
  130. intval($item['id'])
  131. );*/
  132. q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
  133. intval($item['id']),
  134. $term_objtype,
  135. TERM_HASHTAG,
  136. dbesc($term),
  137. dbesc(App::get_baseurl() . '/search?tag=' . $term),
  138. intval($owner_uid)
  139. );
  140. }
  141. // if the original post is on this site, update it.
  142. $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
  143. dbesc($item['uri'])
  144. );
  145. if (dbm::is_result($r)) {
  146. $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
  147. intval($r[0]['uid'])
  148. );
  149. $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
  150. intval($r[0]['id']),
  151. dbesc($term)
  152. );
  153. if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
  154. q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
  155. intval($r[0]['id']),
  156. $term_objtype,
  157. TERM_HASHTAG,
  158. dbesc($term),
  159. dbesc(App::get_baseurl() . '/search?tag=' . $term),
  160. intval($owner_uid)
  161. );
  162. }
  163. /*if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
  164. q("update item set tag = '%s' where id = %d",
  165. dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . App::get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
  166. intval($r[0]['id'])
  167. );
  168. }*/
  169. }
  170. $arr['id'] = $post_id;
  171. call_hooks('post_local_end', $arr);
  172. proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $post_id);
  173. killme();
  174. return; // NOTREACHED
  175. }