diff --git a/app/controllers/TagController.php b/app/controllers/TagController.php new file mode 100644 index 000000000..4707b4b00 --- /dev/null +++ b/app/controllers/TagController.php @@ -0,0 +1,11 @@ +session_only = false; + } + + function dispatch() { + $this->page->setTitle(__('page.tag')); + } +} diff --git a/app/models/postn/Postn.php b/app/models/postn/Postn.php index 286676290..73791f899 100644 --- a/app/models/postn/Postn.php +++ b/app/models/postn/Postn.php @@ -24,7 +24,6 @@ class Postn extends Model { public $updated; // public $delay; // - public $tags; // Store the tags public $picture; // Tell if the post contain embeded pictures public $lat; @@ -80,8 +79,6 @@ class Postn extends Model { {"type":"text" }, "picture" : {"type":"int", "size":4 }, - "tags" : - {"type":"text" }, "hash" : {"type":"string", "size":128 } }'; @@ -186,19 +183,24 @@ class Postn extends Model { // Tags parsing if($entry->entry->category) { - $this->tags = array(); + $td = new \Modl\TagDAO; if($entry->entry->category->count() == 1 - && isset($entry->entry->category->attributes()->term)) - array_push($this->tags, (string)$entry->entry->category->attributes()->term); - else - foreach($entry->entry->category as $cat) - array_push($this->tags, (string)$cat->attributes()->term); + && isset($entry->entry->category->attributes()->term)) { + $tag = new \Modl\Tag; + $tag->nodeid = $this->__get('nodeid'); + $tag->tag = (string)$entry->entry->category->attributes()->term; + $td->set($tag); + } else { + foreach($entry->entry->category as $cat) { + $tag = new \Modl\Tag; + $tag->nodeid = $this->__get('nodeid'); + $tag->tag = (string)$cat->attributes()->term; + $td->set($tag); + } + } } - if(!empty($this->tags)) - $this->__set('tags', serialize($this->tags)); - if($contentimg != '') $content .= '
'.$contentimg; @@ -366,6 +368,21 @@ class Postn extends Model { } } + public function getTags() + { + $td = new \Modl\TagDAO; + $tags = $td->getTags($this->nodeid); + return array_map(function($tag) { return $tag->tag; }, $tags); + } + + public function getTagsImploded() + { + $tags = $this->getTags(); + if(is_array($tags)) { + return implode(', ', $tags); + } + } + public function isPublic() { if(isset($this->privacy) && $this->privacy) { return true; diff --git a/app/models/postn/PostnDAO.php b/app/models/postn/PostnDAO.php index 5d5f244ae..7ac38f481 100644 --- a/app/models/postn/PostnDAO.php +++ b/app/models/postn/PostnDAO.php @@ -26,7 +26,6 @@ class PostnDAO extends SQL { links = :links, picture = :picture, - tags = :tags, hash = :hash @@ -57,7 +56,6 @@ class PostnDAO extends SQL { 'links' => $post->links, 'picture' => $post->picture, - 'tags' => $post->tags, 'hash' => $post->hash, @@ -97,7 +95,6 @@ class PostnDAO extends SQL { links, picture, - tags, hash) values( @@ -125,7 +122,6 @@ class PostnDAO extends SQL { :links, :picture, - :tags, :hash )'; @@ -153,7 +149,6 @@ class PostnDAO extends SQL { 'links' => $post->links, 'picture' => $post->picture, - 'tags' => $post->tags, 'hash' => $post->hash, @@ -210,8 +205,8 @@ class PostnDAO extends SQL { and postn.node != \'urn:xmpp:microblog:0\' order by postn.published desc'; - if($limitr) - $this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf; + if($limitr !== false) + $this->_sql = $this->_sql.' limit '.(int)$limitr.' offset '.(int)$limitf; $this->prepare( 'Postn', @@ -225,6 +220,28 @@ class PostnDAO extends SQL { return $this->run('ContactPostn'); } + function getPublicTag($tag, $limitf = false, $limitr = false) { + $this->_sql = ' + select *, postn.aid, privacy.value as privacy from postn + left outer join contact on postn.aid = contact.jid + left outer join privacy on postn.nodeid = privacy.pkey + where nodeid in (select nodeid from tag where tag = :title) + and privacy.value = 1 + order by postn.published desc'; + + if($limitr !== false) + $this->_sql = $this->_sql.' limit '.(int)$limitr.' offset '.(int)$limitf; + + $this->prepare( + 'Postn', + array( + 'title' => $tag # Hack + ) + ); + + return $this->run('ContactPostn'); + } + function getNodeUnfiltered($from, $node, $limitf = false, $limitr = false) { $this->_sql = ' select *, postn.aid, privacy.value as privacy from postn diff --git a/app/models/tag/Tag.php b/app/models/tag/Tag.php new file mode 100644 index 000000000..a78515c40 --- /dev/null +++ b/app/models/tag/Tag.php @@ -0,0 +1,20 @@ +_struct = ' + { + "tag" : + {"type":"string", "size":64, "mandatory":true, "key":true }, + "nodeid" : + {"type":"string", "size":96, "mandatory":true, "key":true } + }'; + + parent::__construct(); + } +} diff --git a/app/models/tag/TagDAO.php b/app/models/tag/TagDAO.php new file mode 100644 index 000000000..06b470018 --- /dev/null +++ b/app/models/tag/TagDAO.php @@ -0,0 +1,56 @@ +_sql = ' + update tag + set nodeid = :nodeid, + tag = :tag + where nodeid = :nodeid + and tag = :tag'; + + $this->prepare( + 'Tag', + array( + 'nodeid' => $t->nodeid, + 'tag' => $t->tag + ) + ); + + $this->run('Tag'); + + if(!$this->_effective) { + $this->_sql = ' + insert into tag + (nodeid, tag) + values (:nodeid, :tag)'; + + $this->prepare( + 'Tag', + array( + 'nodeid' => $t->nodeid, + 'tag' => $t->tag + ) + ); + + $this->run('Tag'); + } + } + + function getTags($nodeid) { + $this->_sql = ' + select * from tag + where nodeid = :nodeid'; + + $this->prepare( + 'Tag', + array( + 'nodeid' => $nodeid + ) + ); + + return $this->run('Tag'); + } +} diff --git a/app/views/tag.tpl b/app/views/tag.tpl new file mode 100644 index 000000000..0250f152c --- /dev/null +++ b/app/views/tag.tpl @@ -0,0 +1,7 @@ +
+
+
+ widget('Blog');?> +
+
+
diff --git a/app/widgets/Blog/Blog.php b/app/widgets/Blog/Blog.php index 26d0baafd..ba81bba8a 100644 --- a/app/widgets/Blog/Blog.php +++ b/app/widgets/Blog/Blog.php @@ -13,6 +13,7 @@ class Blog extends WidgetBase { private $_messages; private $_page; private $_mode; + private $_tag; function load() { @@ -27,6 +28,10 @@ class Blog extends WidgetBase { $this->_mode = 'group'; $this->url = Route::urlize('node', array($this->_from, $this->_node)); + } elseif($this->_view == 'tag' && $this->validateTag($this->get('t'))) { + $this->_mode = 'tag'; + $this->_tag = $this->get('t'); + $this->title = '#'.$this->_tag; } else { $this->_from = $this->get('f'); @@ -46,7 +51,11 @@ class Blog extends WidgetBase { if($this->_id = $this->get('i')) { if(Validator::int()->between(0, 100)->validate($this->_id)) { - $this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, $this->_id * $this->_paging, $this->_paging + 1); + if(isset($this->_tag)) { + $this->_messages = $pd->getPublicTag($this->get('t'), $this->_id * $this->_paging, $this->_paging + 1); + } else { + $this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, $this->_id * $this->_paging, $this->_paging + 1); + } $this->_page = $this->_id + 1; } elseif(Validator::string()->length(5, 100)->validate($this->_id)) { $this->_messages = $pd->getPublicItem($this->_from, $this->_node, $this->_id); @@ -73,7 +82,11 @@ class Blog extends WidgetBase { } } else { $this->_page = 1; - $this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, 0, $this->_paging + 1); + if(isset($this->_tag)) { + $this->_messages = $pd->getPublicTag($this->get('t'), 0, $this->_paging + 1); + } else { + $this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, 0, $this->_paging + 1); + } } if(count($this->_messages) == $this->_paging + 1) { @@ -91,6 +104,8 @@ class Blog extends WidgetBase { $this->view->assign('mode', $this->_mode); $this->view->assign('more', $this->_page); $this->view->assign('posts', $this->_messages); + + $this->view->assign('tag', $this->_tag); } private function validateServerNode($server, $node) @@ -104,6 +119,11 @@ class Blog extends WidgetBase { else return true; } + private function validateTag($tag) + { + return Validator::string()->notEmpty()->alnum()->validate($tag); + } + function getComments($post) { $pd = new \Modl\PostnDAO(); diff --git a/app/widgets/Blog/blog.tpl b/app/widgets/Blog/blog.tpl index 604b15782..f4acbcbac 100644 --- a/app/widgets/Blog/blog.tpl +++ b/app/widgets/Blog/blog.tpl @@ -31,6 +31,17 @@

{$contact->description}

{/if} + {elseif="$mode == 'tag'"} +
  • + + + +

    + + #{$tag} + +

    +
  • {else}
  • @@ -132,6 +143,19 @@