Created
April 25, 2012 14:36
-
-
Save litzinger/2490211 to your computer and use it in GitHub Desktop.
Example of an EE extension hook to replace an {exp:channel:entries} custom field variable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Replace any template tags as needed | |
*/ | |
function channel_entries_tagdata($tagdata, $row, &$channel) | |
{ | |
// has this hook already been called? | |
if (isset($this->EE->extensions->last_call) && $this->EE->extensions->last_call) | |
{ | |
$tagdata = $this->EE->extensions->last_call; | |
} | |
$values = array(); | |
$params = array(); | |
foreach ($this->EE->TMPL->tagparams as $param => $value) | |
{ | |
$values[] = is_array($value) ? implode('',$value) : $value; | |
$params[] = is_array($param) ? implode('',$param) : $param; | |
} | |
$key = 'uhura:tagdata::'. $this->site_id .':'. $row['entry_id'] .':'. implode(':', $params) .'|'. implode(':', $values) .':'. $this->lang_id .':'. $this->EE->uhura_helper->_get_display_status(); | |
if($title = $this->EE->uhura_helper->memcache_get($key, 'entry')) | |
{ | |
// No further processing, use $tagdata below... | |
} | |
else | |
{ | |
// Only switching {title} for now | |
$query = $this->EE->db->select('title') | |
->where('lang_id', $this->lang_id) | |
->where('entry_id', $row['entry_id']) | |
->where('site_id', $this->EE->config->item('site_id')) | |
->where('status', $this->EE->uhura_helper->_get_display_status()) | |
->get('uhura_data'); | |
if($query->num_rows() == 0 AND $this->setting['display_fallback']) | |
{ | |
$query = $this->EE->db->select('title') | |
->where('entry_id', $row['entry_id']) | |
->where('site_id', $this->EE->config->item('site_id')) | |
->get('channel_titles'); | |
$title = $query->row('title'); | |
} | |
else | |
{ | |
$title = $query->row('title'); | |
} | |
// Prevents array to string conversions. Was getting $row data back without entry_ids, no idea why. | |
$title = is_array($title) ? '' : $title; | |
$this->EE->uhura_helper->memcache_save($key, 'entry', $title); | |
} | |
$tagdata = $this->EE->TMPL->swap_var_single('title', $title, $tagdata); | |
return $tagdata; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment