Created
May 6, 2012 12:07
-
-
Save airways/2621942 to your computer and use it in GitHub Desktop.
Proposed filter_extensions hook and example
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 | |
///////////////////////////////////////////// | |
// Added hook call to EE_Extensions: | |
///////////////////////////////////////////// | |
class EE_Extensions { | |
... | |
function __construct() | |
{ | |
$this->EE =& get_instance(); | |
if ($this->EE->config->item('allow_extensions') == 'y') | |
{ | |
$query = $this->EE->db->query("SELECT DISTINCT ee.* FROM exp_extensions ee WHERE enabled = 'y' ORDER BY hook, priority ASC, class"); | |
if ($query->num_rows() > 0) | |
{ | |
$this->extensions = array(); | |
foreach($query->result_array() as $row) | |
{ | |
$row['class'] = ucfirst(strtolower($row['class'])); | |
$this->extensions[$row['hook']][$row['priority']][$row['class']] = array($row['method'], $row['settings'], $row['version']); | |
$this->version_numbers[$row['class']] = $row['version']; | |
} | |
} | |
// Added - airways | |
if($this->active_hook('filter_extensions')) | |
{ | |
$this->extensions = $this->call('filter_extensions', $this->extensions); | |
} | |
// End Added - airways | |
} | |
} | |
... | |
} | |
///////////////////////////////////////////// | |
The extension: | |
///////////////////////////////////////////// | |
class Filter_extensions_ext { | |
public $settings = array(); | |
public $description = 'Allow specifying what extensions are enabled in a config file'; | |
public $docs_url = ''; | |
public $name = 'Filter Extensions'; | |
public $settings_exist = 'n'; | |
public $version = '1.0'; | |
public $EE; | |
public function __construct($settings = '') | |
{ | |
$this->EE =& get_instance(); | |
$this->settings = $settings; | |
} | |
public function activate_extension() | |
{ | |
// Setup custom settings in this array. | |
$this->settings = array(); | |
$data = array( | |
'class' => __CLASS__, | |
'method' => 'filter_extensions', | |
'hook' => 'filter_extensions', | |
'settings' => serialize($this->settings), | |
'version' => $this->version, | |
'enabled' => 'y' | |
); | |
$this->EE->db->insert('extensions', $data); | |
} | |
public function filter_extensions($extensions) | |
{ | |
$ext_config = $this->EE->config->item('filter_extensions'); | |
$disable = isset($ext_config['disable']) ? $ext_config['disable'] : array(); | |
foreach($extensions as $hook => $priority_list) | |
{ | |
foreach($priority_list as $priority => $class_list) | |
{ | |
foreach($class_list as $class => $call) | |
{ | |
if(!in_array($class, $disable)) | |
{ | |
$extensions_out[$hook][$priority][$class] = $call; | |
} | |
} | |
} | |
} | |
return $extensions_out; | |
} | |
function disable_extension() | |
{ | |
$this->EE->db->where('class', __CLASS__); | |
$this->EE->db->delete('extensions'); | |
} | |
function update_extension($current = '') | |
{ | |
if ($current == '' OR $current == $this->version) | |
{ | |
return FALSE; | |
} | |
} | |
} | |
/* End of file ext.filter_extensions.php */ | |
/* Location: /system/expressionengine/third_party/filter_extensions/ext.filter_extensions.php */ | |
///////////////////////////////////////////// | |
// The config.php settings: | |
///////////////////////////////////////////// | |
$config['filter_extensions'] = array( | |
'disable' => array('Safecracker_ext') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment