/**
  * Compress images
  *
  * @param boolean $arrFiles File array
  */
 public function processPostUpload($arrFiles)
 {
     if (is_array($arrFiles) && $GLOBALS['TL_CONFIG']['tinypng_api_key'] != '') {
         $strUrl = 'https://api.tinypng.com/shrink';
         $strKey = $GLOBALS['TL_CONFIG']['tinypng_api_key'];
         $strAuthorization = 'Basic ' . base64_encode("api:{$strKey}");
         foreach ($arrFiles as $file) {
             $objFile = FilesModel::findByPath($file);
             if (in_array($objFile->extension, array('png', 'jpg', 'jpeg'))) {
                 $strFile = TL_ROOT . '/' . $file;
                 $objRequest = new Request();
                 $objRequest->method = 'post';
                 $objRequest->data = file_get_contents($strFile);
                 $objRequest->setHeader('Content-type', 'image/png');
                 $objRequest->setHeader('Authorization', $strAuthorization);
                 $objRequest->send($strUrl);
                 $arrResponse = json_decode($objRequest->response);
                 if ($objRequest->code == 201) {
                     file_put_contents($strFile, fopen($arrResponse->output->url, "rb", false));
                     $objFile->tstamp = time();
                     $objFile->path = $file;
                     $objFile->hash = md5_file(TL_ROOT . '/' . $file);
                     $objFile->save();
                     System::log('Compression was successful. (File: ' . $file . ')', __METHOD__, TL_FILES);
                 } else {
                     System::log('Compression failed. (' . $arrResponse->message . ') (File: ' . $file . ')', __METHOD__, TL_FILES);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Check for new \Contao versions
  */
 public function checkForUpdates()
 {
     if (!is_numeric(BUILD)) {
         return;
     }
     // HOOK: proxy module
     if (Config::get('useProxy')) {
         $objRequest = new \ProxyRequest();
     } else {
         $objRequest = new \Request();
     }
     $objRequest->send(\Config::get('liveUpdateBase') . (LONG_TERM_SUPPORT ? 'lts-version.txt' : 'version.txt'));
     if (!$objRequest->hasError()) {
         \System::getContainer()->get('contao.cache')->save('latest-version', $objRequest->response);
     }
     // Add a log entry
     $this->log('Checked for Contao updates', __METHOD__, TL_CRON);
 }
 /**
  * Fetch the video image
  *
  * @param int $videoId
  * @param int $index
  *
  * @return null|string
  *
  * @throws \InvalidArgumentException
  */
 protected function fetchVideoImage($videoId, $index)
 {
     if ($index < 1) {
         throw new \InvalidArgumentException('The image index cannot be smaller than 1');
     }
     $videoId = (int) $videoId;
     // Return if the video could not be found
     if (($videoData = $this->getVideo($videoId)) === null) {
         return null;
     }
     $index = (int) $index - 1;
     // If the first image was requested then it should already be there
     if ($index === 0 && isset($videoData['pictures']['sizes'])) {
         $sizes = $videoData['pictures']['sizes'];
     } else {
         // Return if there are no video images
         if (($images = $this->getVideoImages($videoId)) === null) {
             return null;
         }
         $sizes = isset($images['data'][$index]['sizes']) ? $images['data'][$index]['sizes'] : $images['data'][0]['sizes'];
     }
     $picture = array_pop($sizes);
     $request = new Request();
     $request->send($picture['link']);
     if ($request->hasError()) {
         System::log(sprintf('Unable to download Vimeo video image "%s"', $picture['link']), __METHOD__, TL_ERROR);
         return null;
     }
     return $request->response;
 }