--- /dev/null
+<?php
+namespace imagestore;
+
+class Controller_Api_ImageBase extends Controller_Base
+{
+ protected function getBaseUrl()
+ {
+ if (isset($_SERVER['HTTPS'])) {
+ } else {
+ $protocol = 'http';
+ }
+ return $protocol . '://' . $_SERVER['HTTP_HOST'] . '/';
+ }
+
+ protected function getFirstImage(\SplFileInfo $dirInfo)
+ {
+ $it = $this->getImageIterator($dirInfo);
+ $it->rewind();
+ return $it->current();
+ }
+
+ protected function getImageIterator(\SplFileInfo $dirInfo)
+ {
+ $it = new \AppendIterator();
+ $it->append(
+ new \GlobIterator($dirInfo->getPathName() . '/*.jpg')
+ );
+ $it->append(
+ new \GlobIterator($dirInfo->getPathName() . '/*.JPG')
+ );
+ return $it;
+ }
+
+ protected function getImageUrl($path)
+ {
+ return $this->getBaseUrl()
+ . 'image?path=' . urlencode($this->getRelPath($path));
+ }
+
+ protected function getRelPath($path)
+ {
+ return substr($path, strlen($GLOBALS['imagestore']['basedir']));
+ }
+}
+?>