app details (image list)
[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         } else {
10             $protocol = 'http';
11         }
12         return $protocol . '://' . $_SERVER['HTTP_HOST'] . '/';
13     }
14
15     protected function getFirstImage(\SplFileInfo $dirInfo)
16     {
17         $it = $this->getImageIterator($dirInfo);
18         $it->rewind();
19         return $it->current();
20     }
21
22     protected function getImageIterator(\SplFileInfo $dirInfo)
23     {
24         $it = new \AppendIterator();
25         $it->append(
26             new \GlobIterator($dirInfo->getPathName() . '/*.jpg')
27         );
28         $it->append(
29             new \GlobIterator($dirInfo->getPathName() . '/*.JPG')
30         );
31         return $it;
32     }
33
34     protected function getImageUrl($path)
35     {
36         return $this->getBaseUrl()
37             . 'image?path=' . urlencode($this->getRelPath($path));
38     }
39
40     protected function getRelPath($path)
41     {
42         return substr($path, strlen($GLOBALS['imagestore']['basedir']));
43     }
44 }
45 ?>