Created
June 29, 2011 19:59
-
-
Save erikreagan/1054782 to your computer and use it in GitHub Desktop.
Parse global vars within entries in EE 1.x. (Probably could be cleaner, but it'll work for today.)
This file contains hidden or 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 if ( ! defined('EXT')) exit('Invalid file request'); | |
// ini_set('error_reporting',E_ALL); | |
/** | |
* Entry Global Vars | |
* | |
* Parse global variables used in your weblog entries. | |
* | |
* @package EntryGlobalVars | |
* @version 1.0.0 | |
* @author Erik Reagan http://focuslabllc.com | |
* @copyright Copyright (c) 2011 Focus Lab, LLC | |
*/ | |
class Entry_global_vars_ext { | |
private $settings = array(); | |
public $name = 'Entry Global Vars'; | |
public $version = '1.0.0'; | |
public $description = 'Parse global variables in weblog entries'; | |
public $settings_exist = 'n'; | |
public $docs_url = ''; | |
/** | |
* PHP4 Constructor | |
* | |
* @access public | |
* @see __construct() | |
*/ | |
public function Entry_global_vars_ext($settings='') | |
{ | |
$this->__construct($settings); | |
} | |
// End function Entry_global_vars_ext() | |
/** | |
* PHP 5 Constructor | |
* | |
* @access public | |
* @param array|string Extension settings associative array or an empty string | |
*/ | |
public function __construct($settings='') | |
{ | |
$this->settings = $settings; | |
} | |
// End function __construct() | |
/** | |
* Activates the extension | |
* | |
* @access public | |
* @return bool | |
*/ | |
public function activate_extension() | |
{ | |
global $DB; | |
$hooks = array( | |
// 'weblog_entries_query_result' => 'weblog_entries_query_result', | |
'weblog_entries_tagdata_end' => 'weblog_entries_tagdata_end' | |
); | |
foreach ($hooks as $hook => $method) | |
{ | |
$sql[] = $DB->insert_string('exp_extensions', | |
array( | |
'extension_id' => '', | |
'class' => __CLASS__, | |
'method' => $method, | |
'hook' => $hook, | |
'settings' => '', | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => "y" | |
) | |
); | |
} | |
// run all sql queries | |
foreach ($sql as $query) | |
{ | |
$DB->query($query); | |
} | |
return TRUE; | |
} | |
// End function activate_extension() | |
/** | |
* Update the extension | |
* | |
* @access public | |
* @param string | |
* @return bool | |
*/ | |
public function update_extension($current='') | |
{ | |
global $DB; | |
if ($current == '' OR $current == $this->version) | |
{ | |
return FALSE; | |
} | |
$DB->query("UPDATE exp_extensions SET version = '".$DB->escape_str($this->version)."' WHERE class = '".__CLASS__."'"); | |
} | |
// End function update_extension() | |
/** | |
* Disables the extension the extension and deletes settings from DB | |
* | |
* @access public | |
*/ | |
public function disable_extension() | |
{ | |
global $DB; | |
$DB->query("DELETE FROM exp_extensions WHERE class = '".__CLASS__."'"); | |
} | |
// End function disable_extension() | |
/** | |
* Manipulate query results | |
* | |
* NOTE: Note used. weblog_entries_tagdata_end benchmarked a little | |
* faster than this one so we opted for that. Code left in tact but | |
* commented out. | |
* | |
* @access public | |
* @return object | |
*/ | |
// public function weblog_entries_query_result($weblog, $query) | |
// { | |
// global $EXT, $IN; | |
// | |
// if($EXT->last_call !== FALSE) | |
// { | |
// $query = $EXT->last_call; | |
// } | |
// | |
// $globals = array(); | |
// foreach ($IN->global_vars as $var => $value) { | |
// $globals['/{'.$var.'}/'] = $value; | |
// } | |
// | |
// foreach ($query->result as $id => $entry) { | |
// foreach ($entry as $var => $value) { | |
// if (substr($var, 0, 9) == 'field_id_') | |
// { | |
// $query->result[$id][$var] = preg_replace(array_keys($globals),array_values($globals), $value); | |
// } | |
// } | |
// } | |
// | |
// return $query; | |
// | |
// } | |
// End function weblog_entries_query_result() | |
/** | |
* Manipulate tagdata results parsing global variables | |
* | |
* @access public | |
* @return object | |
*/ | |
public function weblog_entries_tagdata_end($tagdata, $row, $weblog) | |
{ | |
global $EXT, $IN; | |
if($EXT->last_call !== FALSE) | |
{ | |
$tagdata = $EXT->last_call; | |
} | |
$globals = array(); | |
foreach ($IN->global_vars as $var => $value) { | |
$globals['/{'.$var.'}/'] = $value; | |
} | |
return preg_replace(array_keys($globals),array_values($globals), $tagdata); | |
} | |
// End function weblog_entries_tagdata_end() | |
} | |
// END class | |
/* End of file ext.entry_global_vars_ext.php */ | |
/* Location: ./system/extensions/ext.entry_global_vars_ext.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment