상속: extends craft\BasePlugin
예제 #1
0
 /**
  * Executes a shell command
  * 
  * @param $command
  */
 public function executeOptimize($command, $file = '')
 {
     $command = escapeshellcmd($command);
     $r = shell_exec($command);
     if ($this->getSetting('logOptimizations')) {
         ImagerPlugin::log("Optimized image {$file} \n\n" . $r, LogLevel::Info, true);
     }
 }
예제 #2
0
 /**
  * Method that triggers any pending tasks immediately.
  */
 private function _triggerTasksNow()
 {
     $url = UrlHelper::getActionUrl('tasks/runPendingTasks');
     if (function_exists('curl_init')) {
         $ch = curl_init($url);
         $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => false, CURLOPT_NOSIGNAL => true);
         if (defined('CURLOPT_TIMEOUT_MS')) {
             $options[CURLOPT_TIMEOUT_MS] = 500;
         } else {
             $options[CURLOPT_TIMEOUT] = 1;
         }
         curl_setopt_array($ch, $options);
         curl_exec($ch);
         $curlErrorNo = curl_errno($ch);
         $curlError = curl_error($ch);
         $httpStatus = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
         curl_close($ch);
         if ($curlErrorNo !== 0) {
             ImagerPlugin::log("Request for running tasks immediately failed with error number {$curlErrorNo} and error message: {$curlError}", LogLevel::Error);
         }
         if ($httpStatus !== 200) {
             ImagerPlugin::log("Request for running tasks immediately failed with http status {$httpStatus}", LogLevel::Error);
         }
     }
 }
예제 #3
0
 /**
  * ---- AWS -----------------------------------------------------------------------------------------------------------
  */
 public function uploadToAWS($filePath)
 {
     if (is_null($this->s3)) {
         $this->s3 = new \S3($this->getSetting('awsAccessKey'), $this->getSetting('awsSecretAccessKey'));
         $this->s3->setExceptions(true);
     }
     $file = $this->s3->inputFile($filePath);
     $headers = $this->getSetting('awsRequestHeaders');
     if (!isset($headers['Cache-Control'])) {
         $headers['Cache-Control'] = 'max-age=' . $this->getSetting('awsCacheDuration') . ', must-revalidate';
     }
     if (!$this->s3->putObject($file, $this->getSetting('awsBucket'), ImagerService::fixSlashes($this->getSetting('awsFolder') . '/' . str_replace($this->getSetting('imagerSystemPath'), '', $filePath), true, true), \S3::ACL_PUBLIC_READ, array(), $headers, $this->_getAWSStorageClass())) {
         ImagerPlugin::log("Upload to AWS failed for {$filePath} in ImagerService", LogLevel::Error);
     }
 }