escape spaces in folders
[ouya-imagestore.git] / src / imagestore / Controller / Api / Apps.php
1 <?php
2 namespace imagestore;
3
4 class Controller_Api_Apps extends Controller_Api_ImageBase
5 {
6     public function handle($data)
7     {
8         $path = str_replace(
9             array('-.-', '+'), array('/', ' '), $data
10         );
11         $fullPath = $GLOBALS['imagestore']['basedir'] . $path;
12         if (!is_dir($fullPath)) {
13             return $this->error('404 Not Found', 'Path not found');
14         }
15
16         $dirInfo = new \SplFileInfo($fullPath);
17
18         $data = array(
19             'app' => array(
20                 'apkFileSize'   => 123456789,
21                 'contentRating' => 'Everyone',
22                 'description'   => 'Images from folder ' . $fullPath,
23                 'developer'     => 'Christian Weiske',
24                 'filepickerScreenshots' => $this->getScreenshots($dirInfo),
25                 'founder'       => false,
26                 'latestVersion' => '11111111-0000-1111-0000-111111111111',
27                 'likeCount'     => 1337,
28                 'mainImageFullUrl' => $this->getImageUrl($this->getFirstImage($dirInfo)),
29                 'overview'      => 'Images from a folder',
30                 'publishedAt'   => date('c', $dirInfo->getMTime()),
31                 'screenshots'   => array(),
32                 'supportEmailAddress' => 'cweiske+ouya@cweiske.de',
33                 'supportPhone'  => null,
34                 'title'         => $dirInfo->getBasename(),
35                 'uuid'          => $data,
36                 'versionNumber' => '0.0.1',
37                 'website'       => 'http://git.cweiske.de/ouya-imagestore.git/'
38             )
39         );
40
41         header('Content-Type: application/json');
42         echo json_encode($data, JSON_PRETTY_PRINT);
43     }
44
45     protected function getScreenshots(\SplFileInfo $dirInfo)
46     {
47         $lit = new \LimitIterator($this->getImageIterator($dirInfo), 0, 20);
48         $urls = array();
49         foreach ($lit as $file) {
50             $urls[] = $this->getImageUrl($file);
51         }
52         return $urls;
53     }
54 }
55 ?>