Skip to content

Commit

Permalink
Import 2018-03-12 Fixed default parameters for Gallery::getUrl().
Browse files Browse the repository at this point in the history
Fixed default parameters for Gallery::getUrl().

Added example PHAR stub and compilation instructions.

index.sample: Added index link to show image pages.
index.sample: Tweaked built-in config activation case.
index.sample: Make index appropriate for use in PHAr as is.
index.sample: Tweaked show-image page CSS to combat text overlap.
index.sample: Correctly set HTTP response code.

config.sample: More comments and better defaults.

Updated dev-master alias.
  • Loading branch information
AnrDaemon committed Mar 12, 2018
1 parent 21640f3 commit a16b36c
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 20 deletions.
38 changes: 29 additions & 9 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
------------------------------------------------------------------------
r684 | anrdaemon | 2017-10-10 07:41:44 +0300 (Вт, 10 окт 2017) | 3 lines
r761 | anrdaemon | 2018-03-12 18:31:02 +0300 (Mon, 12 Mar 2018) | 2 lines

- Fix using $this outside object context.
* Change base classes' resolution.
* Fix default parameters for Gallery::getUrl().

------------------------------------------------------------------------
r674 | anrdaemon | 2017-06-25 02:01:04 +0300 (Вс, 25 июн 2017) | 2 lines
r760 | anrdaemon | 2018-03-12 09:01:38 +0300 (Mon, 12 Mar 2018) | 2 lines

* ArrayIterator to store entries.
* Correctly set HTTP response code.

------------------------------------------------------------------------
r673 | anrdaemon | 2017-06-25 01:57:12 +0300 (Вс, 25 июн 2017) | 2 lines
r759 | anrdaemon | 2018-03-12 08:34:55 +0300 (Mon, 12 Mar 2018) | 2 lines

* Reformat initial assignment.
+ index.sample: Added index link to show image pages.

------------------------------------------------------------------------
r672 | anrdaemon | 2017-06-24 00:56:23 +0300 (Сб, 24 июн 2017) | 2 lines
r758 | anrdaemon | 2018-03-12 08:01:19 +0300 (Mon, 12 Mar 2018) | 2 lines

* Fix setters chaining.
+ Added example PHAR stub and compilation instructions.

------------------------------------------------------------------------
r757 | anrdaemon | 2018-03-12 07:55:31 +0300 (Mon, 12 Mar 2018) | 2 lines

* index.sample: Tweak built-in config activation case.

------------------------------------------------------------------------
r756 | anrdaemon | 2018-03-12 07:46:20 +0300 (Mon, 12 Mar 2018) | 2 lines

* config.sample: More comments and better defaults.

------------------------------------------------------------------------
r755 | anrdaemon | 2018-03-12 06:51:49 +0300 (Mon, 12 Mar 2018) | 4 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.

------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* A simple drop-in file-based HTML gallery.
*
* $Id: Gallery.php 684 2017-10-10 04:41:44Z anrdaemon $
* $Id: Gallery.php 761 2018-03-12 15:31:02Z anrdaemon $
*/

namespace AnrDaemon\MyLittleGallery;
Expand Down Expand Up @@ -265,7 +265,7 @@ public function getPath($name = null, $local = null)
return $path;
}

public function getUrl($prefix, $name)
public function getUrl($prefix, $name = '')
{
return $this->prefix[$prefix] . ($prefix === 'index' ? '/' : rawurlencode($name));
}
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ A PHP class and templates to create a quick drop-in HTML gallery.
### Unable to read files with non-ASCII names
#### PHP before 7.1
Check that encoding of `config.php` file itself matches value of GALLERY_FS_ENCODING constant.
#### PHP 7.1
#### PHP 7.1+
`config.php` MUST be in `UTF-8`.
For PHP 7.1 GALLERY_FS_ENCODING and `$fsEncoding` parameter of the constructor are ignored.
For PHP 7.1 and up GALLERY_FS_ENCODING and `$fsEncoding` parameter of the constructor are ignored.

Starting from PHP 7.1, [PHP uses internal_encoding to transcode file names](https://github.com/php/php-src/blob/e33ec61f9c1baa73bfe1b03b8c48a824ab2a867e/UPGRADING#L418).
Before that, file IO under Windows (notably) done using "default" (so-called "ANSI") character set (i.e. CP1251 for Russian cyrillic).

## Compiling single file archive

```
pharcommand.phar pack -f mlg.phar -s stub.php -c bzip2 index.php Gallery.php
```

Afterwards, the resulting `mlg.phar` can be used as index.php in your web gallery directory.
You may want to place config.php next to it to configure the gallery.
By default, it will list all recognized image files in current directory using UTF-8 encoding.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
"dev-trunk": "1.2.x-dev",
"dev-master": "1.2.x-dev"
}
},
"autoload": {
Expand Down
16 changes: 13 additions & 3 deletions config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,26 @@
//define('GALLERY_DESC_FILE', 'Files.bbs');
//define('GALLERY_DESC_FILE', 'Descript.ion');

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

/** Define general gallery layout
*/
define('GALLERY_PREVIEW_X', 160);
define('GALLERY_PREVIEW_Y', 120);
define('GALLERY_PREVIEW_WIDTH_FACTOR', 2);
define('GALLERY_COLUMNS', 3);

/** Allow X-SendFile/X-Accel-Redirect
* Uncomment one of the following defines
*
* Uncomment one of the following defines, if you know what you are doing.
*
* NB: SERVER CONFIGURATION IS REQUIRED BEFORE ACTIVATING THIS FEATURE!
*/
// Lighttpd, Apache mod_xsendfile
//define('GALLERY_SENDFILE_HEADER', 'X-SendFile');
Expand Down
14 changes: 11 additions & 3 deletions index.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
require_once __DIR__ . '/Gallery.php';
}

require_once __DIR__ . '/config.php';
if(!defined('GALLERY_BASE_DIR'))
{
require_once __DIR__ . '/config.php';
}

ini_set('default_charset', 'UTF-8');
setlocale(LC_ALL, 'C.' . GALLERY_FS_ENCODING);
Expand Down Expand Up @@ -36,8 +39,8 @@
501 => 'Not implemented',
);
$code = isset($map[$e->getCode()]) ? $e->getCode() : 500;
header("Status: $code", true, $code);
die("<!DOCTYPE html>
http_response_code($code);
exit("<!DOCTYPE html>
<html><head>
<title>{$code} {$map[$code]}</title>
</head><body><h1>{$map[$code]}</h1>
Expand Down Expand Up @@ -105,13 +108,18 @@
<html>
<head>
<title><?=htmlspecialchars($gallery[$name]['desc'])?> - My Little Gallery</title>
<link rel="INDEX UP" href="<?=htmlspecialchars($gallery->getUrl('index'))?>"/>
<?php if(isset($gallery[$name]['prev'])):?>
<link rel="PREVIOUS" href="<?=htmlspecialchars($gallery->getUrl('view', $gallery[$name]['prev']))?>"/>
<?php endif;
if(isset($gallery[$name]['next'])):?>
<link rel="NEXT" href="<?=htmlspecialchars($gallery->getUrl('view', $gallery[$name]['next']))?>"/>
<?php endif; ?>
<style type="text/css"><!--
h1 {
padding-top: 1ex;
}

h1, p {
text-align: center;
}
Expand Down
6 changes: 6 additions & 0 deletions stub.sample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

require_once __DIR__ . '/config.php';
require_once 'phar://' . __FILE__ . '/index.php';

__HALT_COMPILER();

0 comments on commit a16b36c

Please sign in to comment.