/** * * @param type $sMessage * @param JchPlatformSettings $params * @param type $sCategory */ public static function log($sMessage, JchPlatformSettings $params) { if ($params->get('log', 0)) { JchPlatformUtility::log($sMessage, 'ERROR', 'plg_jch_optimize.errors.php'); } }
/** * Constructor * * @param type $oParams Plugin parameters */ private function __construct($oParams) { loadJchOptimizeClass('JchPlatformSettings'); ini_set('pcre.backtrack_limit', 1000000); ini_set('pcre.recursion_limit', 100000); $this->params = JchPlatformSettings::getInstance($oParams); }
/** * Constructor * * @param type $oParams Plugin parameters */ private function __construct($oParams) { ini_set('pcre.backtrack_limit', 1000000); $this->params = JchPlatformSettings::getInstance($oParams); if (!defined('JCH_VERSION')) { define('JCH_VERSION', '4.1.1'); } }
/** * */ public static function getPluginParams() { $plugin = self::getPlugin(); $pluginParams = new JRegistry(); $pluginParams->loadString($plugin->params); if (!defined('JCH_DEBUG')) { define('JCH_DEBUG', $pluginParams->get('debug', 0) && JDEBUG); } return JchPlatformSettings::getInstance($pluginParams); }
/** * * @return boolean * @throws Exception */ public function onAfterRender() { if (JDEBUG && $this->params->get('debug', 0)) { global $_PROFILER; $_PROFILER->mark('beforeOnAfterRender plgSystem (JCH Optimize)'); } $app = JFactory::getApplication(); $config = JFactory::getConfig(); $user = JFactory::getUser(); if ($app->getName() != 'site' || JFactory::getDocument()->getType() != 'html' || $app->input->get('jchbackend', '', 'int') == 1 || $config->get('offline') && $user->guest || class_exists('JEditor', FALSE)) { return FALSE; } if ($this->params->get('log', 0)) { error_reporting(E_ALL & ~E_NOTICE); } if (version_compare(JVERSION, '3.2.3', '>=')) { $sHtml = $app->getBody(); } else { $sHtml = JResponse::getBody(); } if ($app->input->get('jchbackend') == '2') { echo $sHtml; while (@ob_end_flush()) { } exit; } try { loadJchOptimizeClass('JchOptimize'); $sOptimizedHtml = JchOptimize::optimize($this->params, $sHtml); } catch (Exception $ex) { JchOptimizeLogger::log($ex->getMessage(), JchPlatformSettings::getInstance($this->params)); $sOptimizedHtml = $sHtml; } if (version_compare(JVERSION, '3.2.3', '>=')) { $app->setBody($sOptimizedHtml); } else { JResponse::setBody($sOptimizedHtml); } if (JDEBUG && $this->params->get('debug', 0)) { $_PROFILER->mark('afterOnAfterRender plgSystem (JCH Optimize)'); } }
/** * * @return boolean * @throws Exception */ public function onAfterRender() { $app = JFactory::getApplication(); $config = JFactory::getConfig(); $user = JFactory::getUser(); if ($app->getName() != 'site' || JFactory::getDocument()->getType() != 'html' || $app->input->get('jchbackend', '', 'int') == 1 || $config->get('offline') && $user->guest || $this->isEditorLoaded()) { return FALSE; } if ($this->params->get('log', 0)) { error_reporting(E_ALL & ~E_NOTICE); } if (version_compare(JVERSION, '3.2.3', '>=')) { $sHtml = $app->getBody(); } else { $sHtml = JResponse::getBody(); } if ($app->input->get('jchbackend') == '2') { echo $sHtml; while (@ob_end_flush()) { } exit; } if (!defined('JCH_VERSION')) { define('JCH_VERSION', '4.2.4'); } try { loadJchOptimizeClass('JchOptimize'); $sOptimizedHtml = JchOptimize::optimize($this->params, $sHtml); } catch (Exception $ex) { JchOptimizeLogger::log($ex->getMessage(), JchPlatformSettings::getInstance($this->params)); $sOptimizedHtml = $sHtml; } if (version_compare(JVERSION, '3.2.3', '>=')) { $app->setBody($sOptimizedHtml); } else { JResponse::setBody($sOptimizedHtml); } }
/** * */ public function onAjaxGarbagecron() { return JchOptimizeAjax::garbageCron(JchPlatformSettings::getInstance($this->params)); }
/** * * @param type $sMessage * @param JchPlatformSettings $params * @param type $sCategory */ public static function log($sMessage, JchPlatformSettings $params, $sCategory = 'jch-optimize') { if ($params->get('log', 0)) { JchPlatformUtility::log($sMessage, $sCategory); } }
/** * Constructor * * @param type $oParams Plugin parameters */ private function __construct($oParams) { loadJchOptimizeClass('JchPlatformSettings'); ini_set('pcre.backtrack_limit', 1000000); ini_set('pcre.recursion_limit', 100000); if (version_compare(PHP_VERSION, '7', '>=')) { $this->jit = ini_get('pcre.jit'); ini_set('pcre.jit', 0); } $this->params = JchPlatformSettings::getInstance($oParams); }
/** * */ public function onAjaxOptimizeimages() { return JchOptimizeAjax::optimizeImages(JchPlatformSettings::getInstance($this->params)); }
/** * * @param JchPlatformSettings $params */ public static function clearHiddenValues(JchPlatformSettings $params) { $params->set('hidden_containsgf', ''); JchPlatformPlugin::saveSettings($params); }
/** * * @return type * @throws type */ public static function optimizeImages(JchPlatformSettings $params) { error_reporting(0); $root = JchPlatformPaths::rootPath(); set_time_limit(0); $dir = JchPlatformUtility::get('dir', '', 'string'); $current = JchPlatformUtility::get('current', '0', 'int'); $optimize = JchPlatformUtility::get('optimize', '0', 'int'); $dir = JchPlatformUtility::decrypt($dir); $arr = array('total' => 0, 'current' => $current, 'optimize' => $optimize, 'message' => ''); $files = array(); if (is_dir($root . $dir)) { //$files = glob($root . $dir . '*.{gif,jpg,png}', GLOB_BRACE); if ($dh = opendir($root . $dir)) { while (($file = readdir($dh)) !== false) { if (preg_match('#\\.(?:gif|jpe?g|png)$#i', $file)) { $files[] = $root . $dir . $file; } } closedir($dh); } $arr['total'] = count($files); } else { $files = array($dir); } // try // { // $smushitclass = 'JchOptimize\SmushIt'; // $smushit = new $smushitclass($files[$arr['current']], 0x02); // // $opfiles = $smushit->get(); // // if (copy($opfiles[0]->destination, $opfiles[0]->source)) // { // $arr['optimize'] ++; // $arr['message'] = $opfiles[0]->source . ':Optimized!'; // } // else // { // throw new Exception($opfiles[0]->source . ': Could not copy optimized image'); // } // } // catch (Exception $e) // { // $arr['message'] = $e->getMessage(); // } $kraken = new JchOptimize\Kraken($params->get('kraken_api_key'), $params->get('kraken_api_secret')); $options = array("file" => $files[$arr['current']], "wait" => true, "lossy" => $params->get('kraken_optimization_level', 0) ? TRUE : FALSE); if ($params->get('kraken_quality', 0)) { $options['quality'] = (int) $params->get('kraken_quality'); } try { $data = $kraken->upload($options); } catch (Exception $ex) { $data = array('success' => FALSE, 'error' => $ex->getMessage()); } $file = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $files[$arr['current']]); if (isset($data['success'])) { if ($data['success']) { if ($data['saved_bytes'] == 0) { $arr['message'] = $file . ': This image can not be optimized any further.'; } elseif (self::copy($data['kraked_url'], $file)) { $arr['optimize']++; $arr['message'] = $file . ': Optimized! You saved ' . $data['saved_bytes'] . ' bytes.'; } else { $arr['message'] = $file . ': Could not copy optimized file.' . ' ' . $msg; } } else { $arr['message'] = $file . ': ' . $data['error']; } } else { $arr['message'] = $file . ': Unrecognizable response from server'; } $arr['current']++; $arr['log_path'] = JchPlatformUtility::getLogsPath(); try { JchOptimizeLogger::logInfo($arr['message'], 'INFO'); } catch (Exception $e) { } return json_encode($arr); }
/** * * @param JchPlatformSettings $params */ public static function garbageCron(JchPlatformSettings $params) { $lifetime = (int) $params->get('cache_lifetime', '1') * 24 * 60 * 60; JchPlatformCache::gc($lifetime); }
function jch_ajax_garbage_cron() { JchOptimizeAjax::garbageCron(JchPlatformSettings::getInstance(get_option('jch_options'))); die; }
/** * * @return type */ public static function getPluginParams() { $options = get_option('jch_options'); return JchPlatformSettings::getInstance($options); }