/** * render * * @since 2.6.0 * * @param string $directory * @param array $options * * @return string */ public static function render($directory = null, $options = null) { $output = null; $outputItem = null; /* html elements */ $imageElement = new Html\Element(); $imageElement->init('img', array('class' => self::$_config['className']['image'])); $linkElement = new Html\Element(); $linkElement->init('a'); $listElement = new Html\Element(); $listElement->init('ul', array('class' => self::$_config['className']['list'])); /* gallery directory */ $galleryDirectory = new Directory(); $galleryDirectory->init($directory, self::$_config['thumbDirectory']); $galleryDirectoryArray = $galleryDirectory->getArray(); /* adjust order */ if ($options['order'] === 'desc') { $galleryDirectoryArray = array_reverse($galleryDirectoryArray); } /* gallery data */ $galleryCounter = 0; $galleryTotal = count($galleryDirectoryArray); $galleryId = uniqid('gallery-'); /* remove thumbs */ if ($options['command'] === 'remove' || !$galleryTotal) { $galleryDirectory->remove(self::$_config['thumbDirectory']); } else { /* process directory */ foreach ($galleryDirectoryArray as $key => $value) { $imagePath = $directory . '/' . $value; $thumbPath = $directory . '/' . self::$_config['thumbDirectory'] . '/' . $value; /* create thumbs */ if ($options['command'] === 'create' || !is_file($thumbPath)) { self::_createThumb($value, $directory, $options); } /* image data */ $imageData = self::_getImageData($imagePath); /* collect item output */ $outputItem .= '<li>'; $outputItem .= $linkElement->copy()->attr(array('href' => $imagePath, 'data-counter' => ++$galleryCounter, 'data-total' => $galleryTotal, 'data-id' => $galleryId, 'data-artist' => array_key_exists('artist', $imageData) ? $imageData['artist'] : null, 'data-date' => array_key_exists('date', $imageData) ? $imageData['date'] : null, 'data-description' => array_key_exists('description', $imageData) ? $imageData['description'] : null))->html($imageElement->copy()->attr(array('src' => $thumbPath, 'alt' => array_key_exists('description', $imageData) ? $imageData['description'] : null))); $outputItem .= '</li>'; } $output = $listElement->attr('id', $galleryId)->html($outputItem); } return $output; }
/** * testRemove * * @since 2.1.0 * * @param array $path * @param array $expect * * @dataProvider providerRemove */ public function testRemove($path = array(), $expect = array()) { /* setup */ $directory = new Directory(); $directory->init(Stream::url($path[1])); $directory->remove($path[0]); /* actual */ $actual = scandir(Stream::url($path[2])); /* compare */ $this->assertEquals($expect, $actual); }
/** * testRemove * * @since 3.0.0 * * @param string $path * @param string $remove * @param array $expectArray * * @dataProvider providerRemove */ public function testRemove($path = null, $remove = null, $expectArray = []) { /* setup */ $directory = new Directory(); $directory->init(Stream::url($path)); $directory->remove($remove); /* actual */ $actualArray = scandir(Stream::url($path)); /* compare */ $this->assertEquals($expectArray, $actualArray); }
/** * tearDownAfterClass * * @since 3.0.0 */ public static function tearDownAfterClass() { $rootDirectory = new Directory(); $rootDirectory->init('.'); $rootDirectory->remove('.restore'); }
/** * removeThumb * * @since 3.0.0 * * @param string $directory */ protected static function _removeThumb($directory = null) { $galleryDirectory = new Directory(); $galleryDirectory->init($directory); $galleryDirectory->remove(self::$_configArray['thumbDirectory']); }