Created
August 10, 2012 08:32
-
-
Save ckimrie/3312619 to your computer and use it in GitHub Desktop.
Revisions
-
Christopher Imrie revised this gist
Aug 10, 2012 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,8 @@ * been used before in an EE addon. * * This has not been road tested and its side effects are unknown, so use this at your own risk. * * NB: Lines 74 and 75 will need to be modified by you before this extension will work. * * - Christopher Imrie * -
Christopher Imrie renamed this gist
Aug 10, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Christopher Imrie created this gist
Aug 10, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,158 @@ <?php /** * Modifying the final CP Output * * This extension demonstrates how you can access and modify the final ExpressionEngine * CP output. It is not a hack, but it is a new technique that to my knowledge has not * been used before in an EE addon. * * This has not been road tested and its side effects are unknown, so use this at your own risk. * * - Christopher Imrie * */ class Example_ext { var $EE; var $name = 'Example Extension'; var $version = '0.1a'; var $description = 'Allows access to the final ExpressionEngine CP output'; var $settings_exist = 'n'; var $docs_url = ''; var $settings = array(); /** * Constructor * * @param mixed Settings array or empty string if none exist. */ function __construct($settings = '') { $this->EE =& get_instance(); $this->settings = $settings; } /** * Initialize CI Hooks * * Using CI Hooks is the only way that we can ensure that our method is * LAST, after the EE CP Controller has finished. * * @param object $Session EE Session instance * @return null */ public function initialize_ci_hook($Session) { global $EXT; //If this request is a JS or AJAX call, dont bother to load initilise hooks. //We want legit CP page loads only if($this->EE->input->get("C") == "javascript"){ return; } //Enable CI Hooks $EXT->enabled = TRUE; //Create the post_controller hook array if needed if(!isset($EXT->hooks['post_controller'])){ $EXT->hooks['post_controller'] = array(); } //Add our hook $EXT->hooks['post_controller'][] = array( 'class' => __CLASS__, 'function' => 'modify_cp_output', 'filename' => THIS-FILENAME, // eg: ext.example.php 'filepath' => DIRECTORY-TO-THIS-FILE, // Relative to the system/expressionengine folder 'params' => array() ); } /** * Post EE Controller * * This method will be called after the EE Controller has finished. * * @return null */ public function modify_cp_output() { //Fetch the final CP Output $html = $this->EE->output->final_output; // // GO CRAZY CHANGING ALL THE THINGS ! // //Reset the final output to your modified version $this->EE->output->final_output = $html; } /** * Activate, Update and Delete */ function activate_extension() { $this->settings = array(); $data = array( 'class' => __CLASS__, 'method' => 'initialize_ci_hook', 'hook' => 'sessions_start', 'settings' => serialize($this->settings), 'priority' => 1, 'version' => $this->version, 'enabled' => 'y' ); $this->EE->db->insert('extensions', $data); } function update_extension($current = '') { if ($current == '' OR $current == $this->version) { return FALSE; } $this->EE->db->where('class', __CLASS__); $this->EE->db->update( 'extensions', array('version' => $this->version) ); } function disable_extension() { $this->EE->db->where('class', __CLASS__); $this->EE->db->delete('extensions'); } } // END CLASS