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 @@
+
{$contact->description}
{/if} + {elseif="$mode == 'tag'"} +