Example #1
0
 /**
  * Method for template_post_parse hook
  *
  * @param 	string	Parsed template string
  * @param 	bool	Whether is a sub-template or not
  * @param 	string	Site ID
  * @return 	string	Template string, possibly minified
  */
 public function template_post_parse($template, $sub, $site_id)
 {
     // play nice with others
     if (isset($this->EE->extensions->last_call) && $this->EE->extensions->last_call) {
         $template = $this->EE->extensions->last_call;
     }
     // do nothing if not final template
     if ($sub !== FALSE) {
         return $template;
     }
     // see if we need to post-render any plugin methods
     if (isset($this->cache['template_post_parse'])) {
         if (!class_exists('Minimee')) {
             include_once PATH_THIRD . 'minimee/pi.minimee.php';
         }
         // create a new instance of Minimee each time to guarantee defaults
         $m = new Minimee();
         // save our TMPL values to put back into place once finished
         $tagparams = $this->EE->TMPL->tagparams;
         // loop through & call each method
         foreach ($this->cache['template_post_parse'] as $needle => $tag) {
             Minimee_helper::log('Calling Minimee::display("' . $tag['method'] . '") during template_post_parse: ' . serialize($tag['tagparams']), 3);
             $this->EE->TMPL->tagparams = $tag['tagparams'];
             // our second parameter tells Minimee we are calling from template_post_parse
             $out = $m->display($tag['method'], TRUE);
             // replace our needle with output
             $template = str_replace(LD . $needle . RD, $out, $template);
             // reset Minimee for next loop
             $m->reset();
         }
         // put things back into place
         $this->EE->TMPL->tagparams = $tagparams;
     }
     // do nothing if not (likely) html!
     if (!preg_match('/webpage|static/i', $this->EE->TMPL->template_type)) {
         return $template;
     }
     // Are we configured to run through HTML minifier?
     if ($this->config->is_no('minify_html')) {
         Minimee_helper::log('HTML minification is disabled.', 3);
         return $template;
     }
     // is Minimee nonetheless disabled?
     if ($this->config->is_yes('disable')) {
         Minimee_helper::log('HTML minification aborted because Minimee has been disabled completely.', 3);
         return $template;
     }
     // we've made it this far, so...
     Minimee_helper::log('Running HTML minification.', 3);
     Minimee_helper::library('html');
     // run css & js minification?
     $opts = array();
     if ($this->config->is_yes('minify_css')) {
         $opts['cssMinifier'] = array('Minify_CSS', 'minify');
     }
     if ($this->config->is_yes('minify_js')) {
         $opts['jsMinifier'] = array('JSMin', 'minify');
     }
     return Minify_HTML::minify($template, $opts);
 }