]> git.mxchange.org Git - friendica.git/commitdiff
more tagging
authorFriendika <info@friendika.com>
Mon, 24 Oct 2011 11:17:46 +0000 (04:17 -0700)
committerFriendika <info@friendika.com>
Mon, 24 Oct 2011 11:17:46 +0000 (04:17 -0700)
include/items.php
mod/network.php
mod/tagger.php

index 82d351b28d2e902003252e619d0d9ab0d907c0e7..a12cdd911cfb91dd178c2546dfda3183ebd4bbaa 100644 (file)
@@ -1263,7 +1263,8 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                        $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
                        }
                        if($deleted && is_array($contact)) {
                                        $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
                        }
                        if($deleted && is_array($contact)) {
-                               $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
+                               $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.id` 
+                                       WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
                                        dbesc($uri),
                                        intval($importer['uid']),
                                        intval($contact['id'])
                                        dbesc($uri),
                                        intval($importer['uid']),
                                        intval($contact['id'])
@@ -1274,6 +1275,41 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                        if(! $item['deleted'])
                                                logger('consume_feed: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
 
                                        if(! $item['deleted'])
                                                logger('consume_feed: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
 
+                                       if(($item['verb'] === ACTIVITY_TAG) && ($item['object-type'] === ACTVITY_OBJ_TAGTERM)) {
+                                               $xo = parse_xml_string($item['object'],false);
+                                               $xt = parse_xml_string($item['target'],false);
+                                               if($xt->type === ACTIVITY_OBJ_NOTE) {
+                                                       $i = q("select * from `item` where uri = '%s' and uid = %d limit 1",
+                                                               dbesc($xt->id),
+                                                               intval($importer['importer_uid'])
+                                                       );
+                                                       if(count($i)) {
+
+                                                               // For tags, the owner cannot remove the tag on the author's copy of the post.
+
+                                                               $owner_remove = (($item['contact-id'] == $i[0]['contact-id']) ? true: false);
+                                                               $author_remove = (($item['origin'] && $item['self']) ? true : false);
+                                                               $author_copy = (($item['origin']) ? true : false);
+
+                                                               if($owner_remove && $author_copy)
+                                                                       continue;
+                                                               if($author_remove || $owner_remove) {
+                                                                       $tags = explode(',',$i[0]['tag']);
+                                                                       $newtags = array();
+                                                                       if(count($tags)) {
+                                                                               foreach($tags as $tag)
+                                                                                       if(trim($tag) !== trim($xo->body))
+                                                                                               $newtags[] = trim($tag);
+                                                                       }
+                                                                       q("update item set tag = '%s' where id = %d limit 1",
+                                                                               dbesc(implode(',',$newtags)),
+                                                                               intval($i[0]['id'])
+                                                                       );
+                                                               }
+                                                       }
+                                               }
+                                       }
+
                                        if($item['uri'] == $item['parent-uri']) {
                                                $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
                                                        `body` = '', `title` = ''
                                        if($item['uri'] == $item['parent-uri']) {
                                                $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
                                                        `body` = '', `title` = ''
@@ -1420,6 +1456,30 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                        $datarray['gravity'] = GRAVITY_LIKE;
                                }
 
                                        $datarray['gravity'] = GRAVITY_LIKE;
                                }
 
+                               if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
+                                       $xo = parse_xml_string($datarray['object'],false);
+                                       $xt = parse_xml_string($datarray['target'],false);
+
+                                       if($xt->type == ACTIVITY_OBJ_NOTE) {
+                                               $r = q("select * from item where `uri` = '%s' AND `uid` = %d limit 1",
+                                                       dbesc($xt->id),
+                                                       intval($importer['importer_uid'])
+                                               );
+                                               if(! count($r))
+                                                       continue;
+
+                                               // extract tag, if not duplicate, add to parent item
+                                               if($xo->content) {
+                                                       if(! (stristr($r[0]['tag'],trim($xo->content)))) {
+                                                               q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1",
+                                                                       dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'),
+                                                                       intval($r[0]['id'])
+                                                               );
+                                                       }
+                                               }
+                                       }
+                               }
+
                                $r = item_store($datarray,$force_parent);
                                continue;
                        }
                                $r = item_store($datarray,$force_parent);
                                continue;
                        }
@@ -1797,7 +1857,8 @@ function local_delivery($importer,$data) {
                        }
                        if($deleted) {
 
                        }
                        if($deleted) {
 
-                               $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
+                               $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join contact on `item`.`contact-id` = `contact`.`id`
+                                       WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
                                        dbesc($uri),
                                        intval($importer['importer_uid']),
                                        intval($importer['id'])
                                        dbesc($uri),
                                        intval($importer['importer_uid']),
                                        intval($importer['id'])
@@ -1815,22 +1876,33 @@ function local_delivery($importer,$data) {
                                                $xo = parse_xml_string($item['object'],false);
                                                $xt = parse_xml_string($item['target'],false);
                                                if($xt->type === ACTIVITY_OBJ_NOTE) {
                                                $xo = parse_xml_string($item['object'],false);
                                                $xt = parse_xml_string($item['target'],false);
                                                if($xt->type === ACTIVITY_OBJ_NOTE) {
-                                                       $i = q("select * from item where uri = '%s' and uid = %d limit 1",
+                                                       $i = q("select * from `item` where uri = '%s' and uid = %d limit 1",
                                                                dbesc($xt->id),
                                                                intval($importer['importer_uid'])
                                                        );
                                                        if(count($i)) {
                                                                dbesc($xt->id),
                                                                intval($importer['importer_uid'])
                                                        );
                                                        if(count($i)) {
-                                                               $tags = explode(',',$i['tag']);
-                                                               $newtags = array();
-                                                               if(count($tags)) {
-                                                                       foreach($tags as $tag)
-                                                                               if(trim($tag) !== trim($xo->body))
-                                                                                       $newtags[] = trim($tag);
+
+                                                               // For tags, the owner cannot remove the tag on the author's copy of the post.
+                                                               
+                                                               $owner_remove = (($item['contact-id'] == $i[0]['contact-id']) ? true: false);
+                                                               $author_remove = (($item['origin'] && $item['self']) ? true : false);
+                                                               $author_copy = (($item['origin']) ? true : false); 
+
+                                                               if($owner_remove && $author_copy)
+                                                                       continue;
+                                                               if($author_remove || $owner_remove) {                                                           
+                                                                       $tags = explode(',',$i[0]['tag']);
+                                                                       $newtags = array();
+                                                                       if(count($tags)) {
+                                                                               foreach($tags as $tag)
+                                                                                       if(trim($tag) !== trim($xo->body))
+                                                                                               $newtags[] = trim($tag);
+                                                                       }
+                                                                       q("update item set tag = '%s' where id = %d limit 1",
+                                                                               dbesc(implode(',',$newtags)),
+                                                                               intval($i[0]['id'])
+                                                                       );
                                                                }
                                                                }
-                                                               q("update item set tag = '%s' where id = %d limit 1",
-                                                                       dbesc(implode(',',$newtags)),
-                                                                       intval($i[0]['id'])
-                                                               );
                                                        }
                                                }
                                        }
                                                        }
                                                }
                                        }
index 04c2a1782b39afd82c6d7433143b720b59763edd..491603f354f2ef8b7e67f77f55cebbb48864fac9 100644 (file)
@@ -333,10 +333,14 @@ function network_content(&$a, $update = 0) {
 
        $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
 
 
        $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
 
-       if(x($_GET,'search'))
-               $sql_extra .= " AND `item`.`body` REGEXP '" . dbesc(escape_tags($_GET['search'])) . "' ";
+       if(x($_GET,'search')) {
+               $search = escape_tags($_GET['search']);
+               $sql_extra .= sprintf(" AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' ) ",
+                       dbesc($search),
+                       dbesc('\\]' . $search . '\\[')
+               );
+       }
 
 
-       
        $r = q("SELECT COUNT(*) AS `total`
                FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
        $r = q("SELECT COUNT(*) AS `total`
                FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
index c64184db77bd9f2c895bd37b38e7e03f1b113273..dd4b8ffea1d9783c10838eaeeaeeb655e4286d97 100644 (file)
@@ -21,7 +21,7 @@ function tagger_content(&$a) {
        logger('tagger: tag ' . $term . ' item ' . $item_id);
 
 
        logger('tagger: tag ' . $term . ' item ' . $item_id);
 
 
-       $r = q("SELECT * FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s') LIMIT 1",
+       $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
                dbesc($item_id),
                dbesc($item_id)
        );
                dbesc($item_id),
                dbesc($item_id)
        );
@@ -35,12 +35,13 @@ function tagger_content(&$a) {
 
        $owner_uid = $item['uid'];
 
 
        $owner_uid = $item['uid'];
 
-       $r = q("select `nickname` from user where uid = %d limit 1",
+       $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
                intval($owner_uid)
        );
                intval($owner_uid)
        );
-       if(count($r))
+       if(count($r)) {
                $owner_nick = $r[0]['nickname'];
                $owner_nick = $r[0]['nickname'];
-
+               $blocktags = $r[0]['blocktags'];
+       }
 
 //     if(local_user() != $owner_uid)
 //             return;
 
 //     if(local_user() != $owner_uid)
 //             return;
@@ -156,13 +157,37 @@ EOT;
                );
        }                       
 
                );
        }                       
 
+       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?search=' . $term . ']'. $term . '[/url]'),
+                       intval($item['id'])
+               );
+       }
+
+       // if the original post is on this site, update it.
 
 
+       $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
+               dbesc($item['uri'])
+       );
+       if(count($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?search=' . $term . ']'. $term . '[/url]'),
+                               intval($r[0]['id'])
+                       );
+               }
+
+       }
+               
 
        $arr['id'] = $post_id;
 
        call_hooks('post_local_end', $arr);
 
 
        $arr['id'] = $post_id;
 
        call_hooks('post_local_end', $arr);
 
-       proc_run('php',"include/notifier.php","like","$post_id");
+       proc_run('php',"include/notifier.php","tag","$post_id");
 
        return; // NOTREACHED
 
 
        return; // NOTREACHED