Exemplo n.º 1
0
 /**
  * Log method
  *
  * By default will pass message to log_message();
  * Also will log to template if rendering a PAGE.
  *
  * @access  public
  * @param   string      $message        The log entry message.
  * @param   int         $severity       The log entry 'level'.
  * @return  void
  */
 public static function log($message, $severity = 1)
 {
     // translate our severity number into text
     $severity = array_key_exists($severity, self::$_levels) ? self::$_levels[$severity] : self::$_levels[1];
     // save our log for EE Debug Toolbar
     self::$_log[] = array($severity, $message);
     if ($severity == 'ERROR') {
         self::$_log_has_error = TRUE;
     }
     // basic EE logging
     log_message($severity, MINIMEE_NAME . ": {$message}");
     // Can we also log our message to the template debugger?
     if (REQ == 'PAGE') {
         get_instance()->TMPL->log_item(MINIMEE_NAME . " [{$severity}]: {$message}");
     }
 }
Exemplo n.º 2
0
 /** 
  * Internal function for writing cache files
  * [Adapted from CodeIgniter Carabiner library]
  * 
  * @param	String of contents of the new file
  * @return	boolean	Returns true on successful cache, false on failure
  */
 protected function _write_cache($file_data)
 {
     if ($this->EE->extensions->active_hook('minimee_pre_write_cache')) {
         Minimee_helper::log('Hook `minimee_pre_write_cache` has been activated.', 3);
         // pass contents of file, and instance of self
         $file_data = $this->EE->extensions->call('minimee_pre_write_cache', $file_data, $this);
         if ($this->EE->extensions->end_script === TRUE) {
             return;
         }
     }
     $filepath = Minimee_helper::remove_double_slashes($this->config->cache_path . '/' . $this->cache_filename);
     $success = file_put_contents($filepath, $file_data);
     if ($success === FALSE) {
         throw new Exception('There was an error writing cache file ' . $this->cache_filename . ' to ' . $this->config->cache_path);
     }
     if ($success === 0) {
         Minimee_helper::log('The new cache file is empty.', 2);
     }
     // borrowed from /system/expressionengine/libraries/Template.php
     // FILE_READ_MODE is set in /system/expressionengine/config/constants.php
     @chmod($filepath, FILE_READ_MODE);
     Minimee_helper::log('Cache file `' . $this->cache_filename . '` was written to ' . $this->config->cache_path, 3);
     // creating the compressed file
     if ($this->config->is_yes('save_gz')) {
         $z_file = gzopen($filepath . '.gz', 'w9');
         gzwrite($z_file, $file_data);
         gzclose($z_file);
         @chmod($filepath . '.gz', FILE_READ_MODE);
         Minimee_helper::log('Gzipped file `' . $this->cache_filename . '.gz` was written to ' . $this->config->cache_path, 3);
     }
     // Do we need to clean up expired caches?
     if ($this->config->is_yes('cleanup')) {
         if ($handle = opendir($this->config->cache_path)) {
             while (false !== ($file = readdir($handle))) {
                 if ($file == '.' || $file == '..' || $file === $this->cache_filename) {
                     continue;
                 }
                 // matches should be deleted
                 if (strpos($file, $this->cache_filename_hash) === 0) {
                     @unlink($this->config->cache_path . '/' . $file);
                     Minimee_helper::log('Cache file `' . $this->cache_filename . '` has expired. File deleted.', 3);
                 }
             }
             closedir($handle);
         }
     }
     // free memory where possible
     unset($filepath, $z_file, $success);
 }
Exemplo n.º 3
0
 /**
  * See if person forgot to change config setup when upgrading from 1.x.
  */
 protected function _from_global_vars_legacy()
 {
     $settings = array();
     // loop through entire _global_vars array
     foreach ($this->EE->config->_global_vars as $key => $val) {
         if (strpos($key, 'minimee_') === 0) {
             $settings[substr($key, 8)] = $val;
         }
     }
     if (count($settings) > 0) {
         $this->location = 'global_vars';
         Minimee_helper::log(lang('config_settings_legacy_global_var_warning'), 2);
         Minimee_helper::log(lang('config_settings_from_legacy'), 3);
     } else {
         $settings = FALSE;
         Minimee_helper::log(lang('config_settings_legacy_not_found'), 3);
     }
     return $settings;
 }
Exemplo n.º 4
0
 /**
  * Reset class properties to their defaults
  * 
  * @return mixed string or empty
  */
 public function reset()
 {
     $defaults = Minimee_helper::minimee_class_vars();
     foreach ($defaults as $name => $default) {
         $this->{$name} = $default;
     }
     Minimee_helper::log('Public properties have been reset to their defaults.', 3);
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Update Extension
  *
  * @param 	string	String value of current version
  * @return 	mixed	void on update / false if none
  */
 public function update_extension($current = '')
 {
     /**
      * Up-to-date
      */
     if ($current == '' or $current == $this->version) {
         return FALSE;
     }
     /**
      * 2.0.0
      * 
      * - refactor to use new Minimee_config object
      */
     if (version_compare($current, '2.0.0', '<')) {
         $query = $this->EE->db->select('settings')->from('extensions')->where('class', __CLASS__)->limit(1)->get();
         if ($query->num_rows() > 0) {
             $settings = unserialize($query->row()->settings);
             // migrate combine
             if (array_key_exists('combine', $settings)) {
                 $settings['combine_css'] = $settings['combine'];
                 $settings['combine_js'] = $settings['combine'];
                 unset($settings['combine']);
             }
             // migrate minify
             if (array_key_exists('minify', $settings)) {
                 $settings['minify_css'] = $settings['minify'];
                 $settings['minify_js'] = $settings['minify'];
                 $settings['minify_html'] = $settings['minify'];
                 unset($settings['minify']);
             }
             // Sanitise & merge to get a complete up-to-date array of settings
             $settings = $this->config->sanitise_settings(array_merge($this->config->get_allowed(), $settings));
             // update db
             $this->EE->db->where('class', __CLASS__)->update('extensions', array('hook' => 'template_post_parse', 'method' => 'template_post_parse', 'settings' => serialize($settings)));
         }
         $query->free_result();
         Minimee_helper::log('Upgraded to 2.0.0', 3);
     }
     /**
      * 2.1.8
      * 
      * - Include debug panel via EE Debug Toolbar
      */
     if (version_compare($current, '2.1.8', '<')) {
         // grab a copy of our settings
         $query = $this->EE->db->select('settings')->from('extensions')->where('class', __CLASS__)->limit(1)->get();
         if ($query->num_rows() > 0) {
             $settings = $query->row()->settings;
         } else {
             $settings = serialize($this->config->factory()->to_array());
         }
         // add extension hook
         $this->EE->db->insert('extensions', array('class' => __CLASS__, 'hook' => 'ee_debug_toolbar_add_panel', 'method' => 'ee_debug_toolbar_add_panel', 'settings' => $settings, 'priority' => 10, 'version' => $this->version, 'enabled' => 'y'));
         $query->free_result();
         Minimee_helper::log('Upgraded to 2.1.8', 3);
     }
     // update table row with version
     $this->EE->db->where('class', __CLASS__);
     $this->EE->db->update('extensions', array('version' => $this->version));
     Minimee_helper::log('Upgrade complete. Now running ' . $this->version, 3);
 }