Permalink
Browse files

Added a site="" parameter to {exp:taggable:entries}

  • Loading branch information...
1 parent cb8e1fc commit cc49b8ae40f870f1530ac657ddb80ca347e17738 @jamierumbelow committed Mar 17, 2011
View
@@ -98,6 +98,9 @@ <h3 id="entries">&#x7B;exp:taggable:entries&#x7D;</h3>
<h4>Parameters</h4>
<dl>
+ <dt>site="not default_site"</dt>
+ <dd>A site name, or multiple tag names separated by a bar. Optionally 'not'</dd>
+
<dt>tag_id="not 1|5"</dt>
<dd>A tag ID, or multiple tag IDs separated by a bar. Optionally 'not'</dd>
@@ -1022,6 +1022,7 @@ public function install() {
$tags_entries = array(
'tag_id' => array('type' => 'INT'),
'entry_id' => array('type' => 'INT'),
+ 'site_id' => array('type' => 'INT'),
'template' => array('type' => 'VARCHAR', 'constraint' => 250, 'default' => 'tags')
);
@@ -155,17 +155,47 @@ public function url_name() {
* Template tag for getting tag entries. Not recommended; only for
* when you need to get from multiple channels. Use search: params instead.
*
- * {exp:taggable:entries tag_id="not 1|2" tag_url_name="not php|expressionengine" url_separator="-"}
+ * {exp:taggable:entries site="not site_a|site_b" tag_id="not 1|2" tag_url_name="not php|expressionengine" url_separator="-"}
* <h1>Posts tagged with {tag_name}</h1>
* {exp:channel:entries entry_id="{entries}"}
* <h1>{title}</h1>
* {/exp:channel:entries}
* {/exp:taggable:entries}
*/
public function entries() {
+ $site = $this->ee->TMPL->fetch_param('site');
$tag_id = $this->ee->TMPL->fetch_param('tag_id');
$tag_url_name = $this->ee->TMPL->fetch_param('tag_url_name');
$url_separator = ($this->ee->TMPL->fetch_param('url_separator')) ? $this->ee->TMPL->fetch_param('url_separator') : '-';
+ $site_where = FALSE;
+
+ // Get the site ID(s)
+ if ($site) {
+ // Handle not
+ if (substr($site, 0, 4) == 'not ') {
+ $site = substr($site, 4);
+ $site_not = TRUE;
+ } else {
+ $site_not = FALSE;
+ }
+
+ // Break up the site names
+ $sites = array_filter(explode('|', $site));
+
+ // Get the IDs
+ $result = $this->ee->db ->select('site_id')
+ ->where_in('site_name', $sites)
+ ->get('sites')
+ ->result();
+ $ids = array();
+
+ foreach ($result as $row) {
+ $ids[] = $row->site_id;
+ }
+
+ // Add a filer to the final result set
+ $site_where = $ids;
+ }
// Tag URL name?
if ($tag_url_name) {
@@ -222,6 +252,15 @@ public function entries() {
}
}
+ // Site where!
+ if ($site_where) {
+ if ($site_not) {
+ $this->ee->db->where_not_in('site_id', $site_where);
+ } else {
+ $this->ee->db->where_in('site_id', $site_where);
+ }
+ }
+
// Get the entry IDs and return
$this->ee->db->save_queries = TRUE;
$result = $this->ee->db->select('DISTINCT entry_id', FALSE)->get('taggable_tags_entries')->result();
@@ -51,7 +51,7 @@ public function install() {
);
$this->ee->db->insert('actions', $action);
-
+
// We're done!
return TRUE;
}
@@ -133,6 +133,12 @@ public function update($version = '') {
if ($version < 1.4) {
$this->ee->config->_update_config(array('taggable_default_theme' => 'taggable-tokens'));
}
+
+ // Update from 1.4 to 1.5
+ // - Add site_id column to taggable_tags_entries
+ if ($version < 1.5) {
+ $this->ee->dbforge->add_column('taggable_tags_entries', array('site_id' => array('type' => 'INT', 'default' => '1')));
+ }
return TRUE;
}

0 comments on commit cc49b8a

Please sign in to comment.