Exemplo n.º 1
0
 /**
  * Generate a list of images that were generated from this image
  */
 private function getGeneratedImages()
 {
     $generatedImages = array();
     $cachedFiles = array();
     $folder = $this->ParentID ? $this->Parent()->Filename : ASSETS_DIR . '/';
     $cacheDir = Director::getAbsFile($folder . '_resampled/');
     if (is_dir($cacheDir)) {
         if ($handle = opendir($cacheDir)) {
             while (($file = readdir($handle)) !== false) {
                 // ignore all entries starting with a dot
                 if (substr($file, 0, 1) != '.' && is_file($cacheDir . $file)) {
                     $cachedFiles[] = $file;
                 }
             }
             closedir($handle);
         }
     }
     $pattern = $this->getFilenamePatterns($this->Name);
     foreach ($cachedFiles as $cfile) {
         if (preg_match($pattern['FullPattern'], $cfile, $matches)) {
             if (Director::fileExists($cacheDir . $cfile)) {
                 $subFilename = substr($cfile, 0, -1 * strlen($this->Name));
                 preg_match_all($pattern['GeneratorPattern'], $subFilename, $subMatches, PREG_SET_ORDER);
                 $generatorArray = array();
                 foreach ($subMatches as $singleMatch) {
                     $generatorArray[] = array('Generator' => $singleMatch['Generator'], 'Args' => Convert::base64url_decode($singleMatch['Args']));
                 }
                 // Using array_reverse is important, as a cached image will
                 // have the generators settings in the filename in reversed
                 // order: the last generator given in the filename is the
                 // first that was used. Later resizements are prepended
                 $generatedImages[] = array('FileName' => $cacheDir . $cfile, 'Generators' => array_reverse($generatorArray));
             }
         }
     }
     return $generatedImages;
 }
 /**
  * Tests {@link Convert::base64url_encode()} and {@link Convert::base64url_decode()}
  */
 public function testBase64url()
 {
     $data = 'Wëīrð characters ☺ such as ¤Ø¶÷╬';
     // This requires this test file to have UTF-8 character encoding
     $this->assertEquals($data, Convert::base64url_decode(Convert::base64url_encode($data)));
     $data = 654.423;
     $this->assertEquals($data, Convert::base64url_decode(Convert::base64url_encode($data)));
     $data = true;
     $this->assertEquals($data, Convert::base64url_decode(Convert::base64url_encode($data)));
     $data = array('simple', 'array', '¤Ø¶÷╬');
     $this->assertEquals($data, Convert::base64url_decode(Convert::base64url_encode($data)));
     $data = array('a' => 'associative', 4 => 'array', '☺' => '¤Ø¶÷╬');
     $this->assertEquals($data, Convert::base64url_decode(Convert::base64url_encode($data)));
 }
Exemplo n.º 3
0
 /**
  * Generate a list of images that were generated from this image
  *
  * @return array
  */
 protected function getGeneratedImages()
 {
     $generatedImages = array();
     $cachedFiles = array();
     $folder = $this->ParentID ? $this->Parent()->Filename : ASSETS_DIR . '/';
     $cacheDir = Director::getAbsFile($folder . '_resampled/');
     // Find all paths with the same filename as this Image (the path contains the transformation info)
     if (is_dir($cacheDir)) {
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cacheDir));
         foreach ($files as $path => $file) {
             if ($file->getFilename() == $this->Name) {
                 $cachedFiles[] = $path;
             }
         }
     }
     $pattern = $this->getFilenamePatterns($this->Name);
     // Reconstruct the image transformation(s) from the format-folder(s) in the path
     // (if chained, they contain the transformations in the correct order)
     foreach ($cachedFiles as $cf_path) {
         if (($pos = stripos($cf_path, '_resampled')) === false) {
             continue;
         }
         $cf_generated = substr($cf_path, $pos + strlen('_resampled'));
         preg_match_all($pattern['GeneratorPattern'], $cf_generated, $matches, PREG_SET_ORDER);
         $generatorArray = array();
         foreach ($matches as $singleMatch) {
             $generatorArray[] = array('Generator' => $singleMatch['Generator'], 'Args' => Convert::base64url_decode($singleMatch['Args']) ?: array());
         }
         $generatedImages[] = array('FileName' => $cf_path, 'Generators' => $generatorArray);
     }
     return $generatedImages;
 }