Skip to content

Commit

Permalink
Sync with 1.3 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnrDaemon committed Feb 24, 2019
1 parent a16b36c commit 079240e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 64 deletions.
35 changes: 15 additions & 20 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
------------------------------------------------------------------------
r761 | anrdaemon | 2018-03-12 18:31:02 +0300 (Mon, 12 Mar 2018) | 2 lines
r987 | anrdaemon | 2019-02-24 22:38:16 +0300 (Sun, 24 Feb 2019) | 2 lines

* Fix default parameters for Gallery::getUrl().
* Unnecessary whitespace changes.

------------------------------------------------------------------------
r760 | anrdaemon | 2018-03-12 09:01:38 +0300 (Mon, 12 Mar 2018) | 2 lines
r986 | anrdaemon | 2019-02-24 22:37:38 +0300 (Sun, 24 Feb 2019) | 3 lines

* Correctly set HTTP response code.
* Sorted out usage of iterators' classes.
* Implement \IteratorAggregate instead of direct \Iterator.

------------------------------------------------------------------------
r759 | anrdaemon | 2018-03-12 08:34:55 +0300 (Mon, 12 Mar 2018) | 2 lines
r985 | anrdaemon | 2019-02-24 22:35:43 +0300 (Sun, 24 Feb 2019) | 2 lines

+ index.sample: Added index link to show image pages.
+ Explicitly list extensions used in the project.

------------------------------------------------------------------------
r758 | anrdaemon | 2018-03-12 08:01:19 +0300 (Mon, 12 Mar 2018) | 2 lines
r984 | anrdaemon | 2019-02-24 22:26:12 +0300 (Sun, 24 Feb 2019) | 2 lines

+ Added example PHAR stub and compilation instructions.
* Include correct configuration file regardless if running in PHP or PHAR mode.

------------------------------------------------------------------------
r757 | anrdaemon | 2018-03-12 07:55:31 +0300 (Mon, 12 Mar 2018) | 2 lines
r983 | anrdaemon | 2019-02-24 22:24:45 +0300 (Sun, 24 Feb 2019) | 2 lines

* index.sample: Tweak built-in config activation case.
+ Improve stub.php handling in Makefile.

------------------------------------------------------------------------
r756 | anrdaemon | 2018-03-12 07:46:20 +0300 (Mon, 12 Mar 2018) | 2 lines
r982 | anrdaemon | 2019-02-24 21:59:40 +0300 (Sun, 24 Feb 2019) | 2 lines

* config.sample: More comments and better defaults.
+ Sanitize config defaults.

------------------------------------------------------------------------
r755 | anrdaemon | 2018-03-12 06:51:49 +0300 (Mon, 12 Mar 2018) | 4 lines
r766 | anrdaemon | 2018-03-17 15:40:36 +0300 (Sat, 17 Mar 2018) | 2 lines

* index.sample: Make index appropriate for use in PHAr as is.
* index.sample: Tweak show image page CSS to combat text overlap.

------------------------------------------------------------------------
r692 | anrdaemon | 2017-10-27 20:48:50 +0300 (Fri, 27 Oct 2017) | 2 lines

* Update dev-master alias.
+ Release building makefile.

------------------------------------------------------------------------
63 changes: 23 additions & 40 deletions Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*
* A simple drop-in file-based HTML gallery.
*
* $Id: Gallery.php 761 2018-03-12 15:31:02Z anrdaemon $
* $Id: Gallery.php 987 2019-02-24 19:38:16Z anrdaemon $
*/

namespace AnrDaemon\MyLittleGallery;

class Gallery
implements \ArrayAccess, \Countable, \Iterator
implements \ArrayAccess, \Countable, \IteratorAggregate
{
const previewTemplate =
'<div><a href="%1$s" target="_blank"><img src="%2$s" alt="%3$s"/></a><p><a href="%1$s" target="_blank">%3$s</a></p></div>';
Expand Down Expand Up @@ -52,7 +52,7 @@ protected function fromFileList(array $list)
if($meta === false || $meta[0] === 0 || $meta[1] === 0)
continue;

$this->params[$name] = new \ArrayIterator([
$this->params[$name] = new \ArrayObject([
'desc' => $name,
'path' => "{$this->path}/{$name}",
'width' => $meta[0],
Expand Down Expand Up @@ -96,7 +96,7 @@ public static function fromListfile(\SplFileInfo $target, $charset = 'CP866', $f
if($meta === false || $meta[0] === 0 || $meta[1] === 0)
continue;

$self->params[$name] = new \ArrayIterator([
$self->params[$name] = new \ArrayObject([
'desc' => $a['desc'],
'path' => "{$self->path}/{$name}",
'width' => $meta[0],
Expand Down Expand Up @@ -172,7 +172,7 @@ public function setNumberFormatter($locale = 'en_US.UTF-8', $style = \NumberForm
public function allowSendFile($prefix = null, $header = null)
{
$this->sfPrefix = $prefix;
$this->sfHeader = trim($header)?: 'X-SendFile';
$this->sfHeader = trim($header) ?: 'X-SendFile';

return $this;
}
Expand All @@ -182,18 +182,21 @@ public function sendFile($path)
if(!isset($this->sfPrefix))
return false;

header_register_callback(function(){
/*
Accept-Ranges
Cache-Control
Content-Disposition
Content-Type
Expires
Set-Cookie
*/
header_remove('Accept-Ranges');
header_remove('Content-Type');
});
header_register_callback(
function()
{
/*
Accept-Ranges
Cache-Control
Content-Disposition
Content-Type
Expires
Set-Cookie
*/
header_remove('Accept-Ranges');
header_remove('Content-Type');
}
);

header("{$this->sfHeader}: {$this->sfPrefix}" . urlencode("$path"));

Expand Down Expand Up @@ -433,30 +436,10 @@ public function count()
return count($this->params);
}

// Iterator

public function current()
{
return current($this->params);
}

public function key()
{
return key($this->params);
}

public function next()
{
return next($this->params);
}

public function rewind()
{
return reset($this->params);
}
// IteratorAggregate

public function valid()
public function getIterator()
{
return key($this->params) !== null;
return new \ArrayIterator($this->params);
}
}
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
SHELL := /bin/sh
.SHELLFLAGS := -ec
.ONESHELL:

PHAR_FILES := index.php config.php Gallery.php

clean:
-rm index.php config.php stub.php mlg.phar

release: release-phar

release-phar: mlg.phar

stub: stub.php

%.php: %.sample.php
cp "$<" "$@"

stub.php: config.sample.php
cp "config.sample.php" "stub.php"
printf "\n%s" \
"require_once 'phar://' . __FILE__ . '/index.php';" "" \
"__HALT_COMPILER(); ?>" >> "stub.php"

mlg.phar: stub.php $(PHAR_FILES)
phar pack -f "$@" -c bzip2 -s $^

.PHONY: clean stub release ;
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
}
],
"require": {
"php": "^5.3 || ^7.0"
"php": "^5.3 || ^7.0",
"ext-SPL": "*",
"ext-Phar": ">=2.0",
"ext-gd": "*"
},
"suggest": {
"ext-Imagick": "Better image handling."
},
"extra": {
"branch-alias": {
Expand Down
6 changes: 4 additions & 2 deletions config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

/** Specify gallery descriptions encoding.
*
* Only used with GALLERY_DESC_FILE
*
* CP866 for cyrillic descriptions is common.
* UTF-8 is a sane default suitable for drop-in gallery. (It's not used anyway then.)
* UTF-8 is a sane default suitable for drop-in gallery.
*/
//define('GALLERY_DESC_ENCODING', 'CP866');
define('GALLERY_DESC_ENCODING', 'UTF-8');
//define('GALLERY_DESC_ENCODING', 'UTF-8');

/** Define general gallery layout
*/
Expand Down
4 changes: 3 additions & 1 deletion index.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

if(!defined('GALLERY_BASE_DIR'))
{
require_once __DIR__ . '/config.php';
$confFile = dirname(\Phar::running(false) ?: __FILE__) . '/config.php';
if(file_exists($confFile))
require_once $confFile;
}

ini_set('default_charset', 'UTF-8');
Expand Down

0 comments on commit 079240e

Please sign in to comment.