1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 
<?php

/* --------------------------------------------------------------
   AbstractImagesApiV2Controller.inc.php 2016-01-27
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2016 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/

MainFactory::load_class('HttpApiV2Controller');

/**
 * Class AbstractImagesApiV2Controller
 *
 * Provides a listing of image files.
 *
 * @category System
 * @package  ApiV2Controllers
 */
abstract class AbstractImagesApiV2Controller extends HttpApiV2Controller
{
    /**
     * @var ProductWriteService|CategoryWriteService
     */
    protected $writeService;
    
    
    /**
     * Initializes API Controller
     */
    abstract protected function __initialize();
    
    
    /**
     * Returns the absolute path where the image files are located.
     *
     * @return string
     */
    abstract protected function _getImageFolderName();
    
    
    /**
     * Returns a list of all image files which exists on the server's filesystem.
     *
     * This function searches for image files ('gif', 'jpeg', 'jpg', 'png') in the path which is specified in the child
     * classes _getImageFolderName method.
     */
    public function get()
    {
        $allowedFileTypes = array('gif', 'jpeg', 'jpg', 'png');
        $response         = array();
        
        $files = glob($this->_getImageFolderName() . '*');
        {
            foreach($files as $file)
            {
                if(in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), $allowedFileTypes))
                {
                    $response[] = basename($file);
                }
            }
        }
        
        $this->_writeResponse($response);
    }
}