aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Tagger.php
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-04-18 20:38:38 -0700
committerredmatrix <git@macgirvin.com>2016-04-18 20:38:38 -0700
commit2a4e8972e0edfa3156d9ce54d68ce0e54c0ec289 (patch)
tree2376d950ba2bdc7753336a3e2b94865c95c238f2 /Zotlabs/Module/Tagger.php
parent2a61817bad96526994c0499f1fc0a843a9cc9405 (diff)
downloadvolse-hubzilla-2a4e8972e0edfa3156d9ce54d68ce0e54c0ec289.tar.gz
volse-hubzilla-2a4e8972e0edfa3156d9ce54d68ce0e54c0ec289.tar.bz2
volse-hubzilla-2a4e8972e0edfa3156d9ce54d68ce0e54c0ec289.zip
module updates
Diffstat (limited to 'Zotlabs/Module/Tagger.php')
-rw-r--r--Zotlabs/Module/Tagger.php140
1 files changed, 140 insertions, 0 deletions
diff --git a/Zotlabs/Module/Tagger.php b/Zotlabs/Module/Tagger.php
new file mode 100644
index 000000000..879cf3dbb
--- /dev/null
+++ b/Zotlabs/Module/Tagger.php
@@ -0,0 +1,140 @@
+<?php
+namespace Zotlabs\Module;
+
+require_once('include/security.php');
+require_once('include/bbcode.php');
+require_once('include/items.php');
+
+
+
+class Tagger extends \Zotlabs\Web\Controller {
+
+ function get() {
+
+ if(! local_channel() && ! remote_channel()) {
+ return;
+ }
+
+ $observer_hash = get_observer_hash();
+ //strip html-tags
+ $term = notags(trim($_GET['term']));
+ //check if empty
+ if(! $term)
+ return;
+
+ $item_id = ((argc() > 1) ? notags(trim(argv(1))) : 0);
+
+ logger('tagger: tag ' . $term . ' item ' . $item_id);
+
+
+ $r = q("SELECT * FROM item left join xchan on xchan_hash = author_xchan WHERE id = '%s' and uid = %d LIMIT 1",
+ dbesc($item_id),
+ intval(local_channel())
+ );
+
+ if((! $item_id) || (! $r)) {
+ logger('tagger: no item ' . $item_id);
+ return;
+ }
+
+ $item = $r[0];
+
+ $owner_uid = $item['uid'];
+
+ switch($item['resource_type']) {
+ case 'photo':
+ $targettype = ACTIVITY_OBJ_PHOTO;
+ $post_type = t('photo');
+ break;
+ case 'event':
+ $targgettype = ACTIVITY_OBJ_EVENT;
+ $post_type = t('event');
+ break;
+ default:
+ $targettype = ACTIVITY_OBJ_NOTE;
+ $post_type = t('post');
+ if($item['mid'] != $item['parent_mid'])
+ $post_type = t('comment');
+ break;
+ }
+
+
+ $links = array(array('rel' => 'alternate','type' => 'text/html',
+ 'href' => z_root() . '/display/' . $item['mid']));
+
+ $target = json_encode(array(
+ 'type' => $targettype,
+ 'id' => $item['mid'],
+ 'link' => $links,
+ 'title' => $item['title'],
+ 'content' => $item['body'],
+ 'created' => $item['created'],
+ 'edited' => $item['edited'],
+ 'author' => array(
+ 'name' => $item['xchan_name'],
+ 'address' => $item['xchan_addr'],
+ 'guid' => $item['xchan_guid'],
+ 'guid_sig' => $item['xchan_guid_sig'],
+ 'link' => array(
+ array('rel' => 'alternate', 'type' => 'text/html', 'href' => $item['xchan_url']),
+ array('rel' => 'photo', 'type' => $item['xchan_photo_mimetype'], 'href' => $item['xchan_photo_m'])),
+ ),
+ ));
+
+
+
+ $link = xmlify('<link rel="alternate" type="text/html" href="'
+ . z_root() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
+
+ $tagid = z_root() . '/search?tag=' . $term;
+ $objtype = ACTIVITY_OBJ_TAGTERM;
+
+ $obj = json_encode(array(
+ 'type' => $objtype,
+ 'id' => $tagid,
+ 'link' => array(array('rel' => 'alternate','type' => 'text/html', 'href' => $tagid)),
+ 'title' => $term,
+ 'content' => $term
+ ));
+
+ $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
+
+ // saving here for reference
+ // also check out x22d5 and x2317 and x0d6b and x0db8 and x24d0 and xff20 !!!
+
+ $termlink = html_entity_decode('&#x22d5;') . '[zrl=' . z_root() . '/search?tag=' . urlencode($term) . ']'. $term . '[/zrl]';
+
+ $channel = \App::get_channel();
+
+ $arr = array();
+
+ $arr['owner_xchan'] = $item['owner_xchan'];
+ $arr['author_xchan'] = $channel['channel_hash'];
+
+ $arr['item_origin'] = 1;
+ $arr['item_wall'] = ((intval($item['item_wall'])) ? 1 : 0);
+
+ $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]';
+ $alink = '[zrl=' . $item['xchan_url'] . ']' . $item['xchan_name'] . '[/zrl]';
+ $plink = '[zrl=' . $item['plink'] . ']' . $post_type . '[/zrl]';
+
+ $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
+
+ $arr['verb'] = ACTIVITY_TAG;
+ $arr['tgt_type'] = $targettype;
+ $arr['target'] = $target;
+ $arr['obj_type'] = $objtype;
+ $arr['object'] = $obj;
+ $arr['parent_mid'] = $item['mid'];
+
+ store_item_tag($item['uid'],$item['id'],TERM_OBJ_POST,TERM_COMMUNITYTAG,$term,$tagid);
+ $ret = post_activity_item($arr);
+
+ if($ret['success'])
+ proc_run('php','include/notifier.php','tag',$ret['activity']['id']);
+
+ killme();
+
+ }
+
+}