escape spaces in folders
[ouya-imagestore.git] / src / imagestore / Controller / Api / ImageBase.php
1 <?php
2 namespace imagestore;
3
4 class Controller_Api_ImageBase extends Controller_Base
5 {
6     protected function getBaseUrl()
7     {
8         if (isset($_SERVER['HTTPS'])) {
9             $protocol = 'https';
10         } else {
11             $protocol = 'http';
12         }
13         return $protocol . '://' . $_SERVER['HTTP_HOST'] . '/';
14     }
15
16     protected function getFirstImage(\SplFileInfo $dirInfo)
17     {
18         $it = $this->getImageIterator($dirInfo);
19         $it->rewind();
20         return $it->current();
21     }
22
23     protected function getImageIterator(\SplFileInfo $dirInfo)
24     {
25         $it = new \AppendIterator();
26         $it->append(
27             new \GlobIterator($dirInfo->getPathName() . '/*.jpg')
28         );
29         $it->append(
30             new \GlobIterator($dirInfo->getPathName() . '/*.JPG')
31         );
32         return $it;
33     }
34
35     protected function getImageUrl($path)
36     {
37         return $this->getBaseUrl()
38             . 'image?path=' . urlencode($this->getRelPath($path));
39     }
40
41     protected function getRelPath($path)
42     {
43         return substr($path, strlen($GLOBALS['imagestore']['basedir']));
44     }
45 }
46 ?>