示例#1
0
 /**
  * 
  * @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');
         }
 }
示例#2
0
 /**
  * 
  * @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);
     }
 }
示例#3
0
文件: ajax.php 项目: grlf/eyedock
 /**
  * 
  * @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);
 }
示例#4
0
文件: ajax.php 项目: naka211/myloyal
 /**
  * 
  * @param JchPlatformSettings $params
  */
 public static function garbageCron(JchPlatformSettings $params)
 {
     $lifetime = (int) $params->get('cache_lifetime', '1') * 24 * 60 * 60;
     JchPlatformCache::gc($lifetime);
 }