]> git.mxchange.org Git - friendica.git/blobdiff - mod/tagger.php
Merge pull request #3047 from annando/1612-indexlength
[friendica.git] / mod / tagger.php
index 8ee499f5f30c0fcd42ec5dce684abe5956da738b..e53bc5eaf19d9da64a9c2182370e817d7512420e 100644 (file)
@@ -27,7 +27,7 @@ function tagger_content(&$a) {
                dbesc($item_id)
        );
 
-       if(! $item_id || (! count($r))) {
+       if(! $item_id || (! dbm::is_result($r))) {
                logger('tagger: no item ' . $item_id);
                return;
        }
@@ -39,7 +39,7 @@ function tagger_content(&$a) {
        $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
                intval($owner_uid)
        );
-       if(count($r)) {
+       if (dbm::is_result($r)) {
                $owner_nick = $r[0]['nickname'];
                $blocktags = $r[0]['blocktags'];
        }
@@ -47,18 +47,10 @@ function tagger_content(&$a) {
        if(local_user() != $owner_uid)
                return;
 
-       if(remote_user()) {
-               $r = q("select * from contact where id = %d AND `uid` = %d limit 1",
-                       intval(remote_user()),
-                       intval($item['uid'])
-               );
-       }
-       else {
-               $r = q("select * from contact where self = 1 and uid = %d limit 1",
-                       intval(local_user())
-               );
-       }
-       if(count($r))
+       $r = q("select * from contact where self = 1 and uid = %d limit 1",
+               intval(local_user())
+       );
+       if (dbm::is_result($r))
                        $contact = $r[0];
        else {
                logger('tagger: no contact_id');
@@ -66,14 +58,14 @@ function tagger_content(&$a) {
        }
 
        $uri = item_new_uri($a->get_hostname(),$owner_uid);
-
+       $xterm = xmlify($term);
        $post_type = (($item['resource-id']) ? t('photo') : t('status'));
-       $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); 
+       $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
 
-       $link = xmlify('<link rel="alternate" type="text/html" href="' 
-               . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
+       $link = xmlify('<link rel="alternate" type="text/html" href="'
+               . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
 
-       $body = $item['body'];
+       $body = xmlify($item['body']);
 
        $target = <<< EOT
        <target>
@@ -86,7 +78,7 @@ function tagger_content(&$a) {
        </target>
 EOT;
 
-       $tagid = $a->get_baseurl() . '/search?tag=' . $term;
+       $tagid = App::get_baseurl() . '/search?tag=' . $term;
        $objtype = ACTIVITY_OBJ_TAGTERM;
 
        $obj = <<< EOT
@@ -95,20 +87,22 @@ EOT;
                <local>1</local>
                <id>$tagid</id>
                <link>$tagid</link>
-               <title>$term</title>
-               <content>$term</content>
+               <title>$xterm</title>
+               <content>$xterm</content>
        </object>
 EOT;
 
        $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
 
-       if(! isset($bodyverb))
-                       return; 
+       if (! isset($bodyverb)) {
+               return;
+       }
 
-       $termlink = html_entity_decode('&#x2317;') . '[url=' . $a->get_baseurl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
+       $termlink = html_entity_decode('&#x2317;') . '[url=' . App::get_baseurl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
 
        $arr = array();
 
+       $arr['guid'] = get_guid(32);
        $arr['uri'] = $uri;
        $arr['uid'] = $owner_uid;
        $arr['contact-id'] = $contact['id'];
@@ -123,7 +117,7 @@ EOT;
        $arr['author-name'] = $contact['name'];
        $arr['author-link'] = $contact['url'];
        $arr['author-avatar'] = $contact['thumb'];
-       
+
        $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
        $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
        $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
@@ -144,25 +138,39 @@ EOT;
        $arr['last-child'] = 1;
        $arr['origin'] = 1;
 
-       $post_id = item_store($arr);    
+       $post_id = item_store($arr);
+
+//     q("UPDATE `item` set plink = '%s' where id = %d",
+//             dbesc(App::get_baseurl() . '/display/' . $owner_nick . '/' . $post_id),
+//             intval($post_id)
+//     );
 
-       q("UPDATE `item` set plink = '%s' where id = %d limit 1",
-               dbesc($a->get_baseurl() . '/display/' . $owner_nick . '/' . $post_id),
-               intval($post_id)
-       );
-               
 
        if(! $item['visible']) {
-               $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
+               $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
                        intval($item['id']),
                        intval($owner_uid)
                );
-       }                       
+       }
 
-       if((! $blocktags) && (! stristr($item['tag'], ']' . $term . '[' ))) {
-               q("update item set tag = '%s' where id = %d limit 1",
-                       dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
+       $term_objtype = (($item['resource-id']) ? TERM_OBJ_PHOTO : TERM_OBJ_POST );
+        $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
+                intval($item['id']),
+                dbesc($term)
+        );
+       if((! $blocktags) && $t[0]['tcount']==0 ) {
+               /*q("update item set tag = '%s' where id = %d",
+                       dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . App::get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
                        intval($item['id'])
+               );*/
+
+               q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
+                  intval($item['id']),
+                  $term_objtype,
+                  TERM_HASHTAG,
+                  dbesc($term),
+                  dbesc(App::get_baseurl() . '/search?tag=' . $term),
+                  intval($owner_uid)
                );
        }
 
@@ -171,29 +179,44 @@ EOT;
        $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
                dbesc($item['uri'])
        );
-       if(count($r)) {
+       if (dbm::is_result($r)) {
                $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
                        intval($r[0]['uid'])
                );
-               if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
-                       q("update item set tag = '%s' where id = %d limit 1",
-                               dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
+               $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
+                       intval($r[0]['id']),
+                       dbesc($term)
+               );
+               if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
+                       q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
+                          intval($r[0]['id']),
+                          $term_objtype,
+                          TERM_HASHTAG,
+                          dbesc($term),
+                          dbesc(App::get_baseurl() . '/search?tag=' . $term),
+                          intval($owner_uid)
+                       );
+               }
+
+               /*if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
+                       q("update item set tag = '%s' where id = %d",
+                               dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . App::get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
                                intval($r[0]['id'])
                        );
-               }
+               }*/
 
        }
-               
+
 
        $arr['id'] = $post_id;
 
        call_hooks('post_local_end', $arr);
 
-       proc_run('php',"include/notifier.php","tag","$post_id");
+       proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $post_id);
 
        killme();
 
        return; // NOTREACHED
 
 
-}
\ No newline at end of file
+}