Skip to content

Commit

Permalink
Merge pull request #38 from Devenet/v1.8.0
Browse files Browse the repository at this point in the history
v1.8.0
  • Loading branch information
Devenet authored Nov 30, 2023
2 parents 48eb15a + 761923a commit f9cf40d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ private/*.jpg
private/*.jpeg
private/*.png
private/*.gif
private/*.mp4
private/calendar.json
private/rss_cache.xml
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AdventCalendar

Advent Calendar is a light web application to show a picture and its legend per day before Christmas, or any other event.
It’s written in PHP, use last web technologies—and proud to not support obsolete versions of IE.
It’s written in PHP with modern web technologies.

[See a demo](https://www.devenet.eu/advent/demo).

Expand All @@ -25,6 +25,9 @@ Then edit the `settings.json` file to configure the application and set the year
To finish, just put your image files in the `private` folder; images named with the number of the day (such as `1.jpeg`, `2.jpg`, `3.png`).
Supported formats are: JPG/JPEG, PNG, GIF.

**NEW** You can now use a video file with MP4 format.
The video will be served by the PHP app, so I strongly recommand that you only use a lightweight video file.

***

## Installation
Expand All @@ -50,8 +53,8 @@ Copy the `settings.example.json` file on folder `private` to `settings.json` and
The minimum required configuration file must contains:
```json
{
"title": "Advent Calendar · 2021",
"year": 2021
"title": "Advent Calendar · 2023",
"year": 2023
}
```

Expand Down Expand Up @@ -86,16 +89,16 @@ _Feel free to use the online [settings file generator](https://www.devenet.eu/ad
| __`disqus_shortname`__ | string | Set a Disqus account to enable comments for day pages. |
| __`google_analytics`__ | object | Set a Google Analytics account with a child object containing the two properties `tracking_id` and `domain`. |
| __`piwik`__ | object | Set a Piwik account with a child object containing the two properties `piwik_url` and `site_id`. |
| __`plausible`__ | object | Set a Plausible account with a child object containing the property `domain` for _data-domain_, and if you use a CNAME custom domain the property `custom_src` with the full URL in the Plausible _src_ configuration. |
| __`plausible`__ | object | Set a Plausible account with a child object containing the property `domain` for _data-domain_. |
| __`copyright`__ | string | Set a copyright notice; not displayed if empty (default). |
| __`url_rewriting`__ | boolean | Set to `true` to enable rewriting URL and uncomment lines in the root `.htaccess` file. Default is `false`. |


This is an example with all options:
```json
{
"title": "Advent Calendar · 2020",
"year": 2020,
"title": "Advent Calendar · 2023",
"year": 2023,
"month": 12,
"first_day": 1,
"last_day": 24,
Expand All @@ -112,8 +115,7 @@ This is an example with all options:
"site_id": "12345"
},
"plausible": {
"domain": "domain.tld",
"custom_src": "https://cname.domain.tld/js/index.js"
"domain": "domain.tld"
},
"copyright": "All content is under Creative Commons BY-NC 3.0 licence.",
"url_rewriting": false
Expand All @@ -127,10 +129,10 @@ This is an example with all options:
Put your photos in the `private` folder, and name them with the number of the day you want to illustrate.
For example, for the 1st December, call your file `1.jpg` or `1.jpeg`.

Supported formats are: JPG/JPEG, PNG, GIF.
Supported formats are: JPG/JPEG, PNG, GIF for images, and MP4 for videos.

__Be sure that the access to `private` folder is forbidden when browsing it!__
For Apache configuration, be sure that a `.htaccess` file with the directive `Require all denied` is in and read.
For Apache configuration, be sure that a `.htaccess` file with the directive `Require all denied` is in.

### Customize legend and title

Expand Down Expand Up @@ -183,6 +185,6 @@ Let me know if you use Advent Calendar by sending me an e-mail, I will be happy


Special thanks to
❤️ Special thanks to
- [@fscholdei](https://github.com/fscholdei) for the German translation
- [@Thaoh](https://github.com/Thaoh) for the Norwegian translation and the URL custom background feature
2 changes: 1 addition & 1 deletion assets/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h1><i class="glyphicon glyphicon-tree-conifer"></i> Advent Calendar <small>/abo
<div class="col-md-8 col-md-offset-2">
<h2><i class="glyphicon glyphicon-search"></i> What is this?</h2>
<p><a href="https://github.com/Devenet/AdventCalendar" rel="external">Advent Calendar</a> is a very light web application to show a picture and its legend per day before Christmas, or any other event.</p>
<p>It’s written in PHP, use last web technologies—and proud to not support obsolete versions of <abbr title="Internet Explorer" class="tip">IE</abbr>.</p>
<p>It’s written in PHP with modern web technologies.</p>
</div>
</div>

Expand Down
25 changes: 18 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
error_reporting(0);

// constants to be used
define('VERSION', '1.7.0');
define('VERSION', '1.8.0');
define('ADVENT_CALENDAR', 'Advent Calendar');
define('URL_DAY', 'day');
define('URL_PHOTO', 'photo');
Expand Down Expand Up @@ -216,7 +216,7 @@ static function getInfo($day) {
if (Advent::acceptDay($day) && Advent::isActiveDay($day)) {
$result['url'] = Routes::route(URL_PHOTO, $day);

$extensions = ['jpg', 'jpeg', 'png', 'gif'];
$extensions = ['jpg', 'jpeg', 'png', 'gif', 'mp4'];
foreach ($extensions as $extension) {
$file = PRIVATE_FOLDER.'/'.$day.'.'.$extension;
if (file_exists($file)) {
Expand Down Expand Up @@ -246,6 +246,8 @@ static private function getMimeType($extension) {
return 'image/png';
case 'gif':
return 'image/gif';
case 'mp4':
return 'video/mp4';
default:
return NULL;
}
Expand Down Expand Up @@ -376,10 +378,14 @@ static function getDayHtml($day) {
// clearfix
$result .= '<div class="clearfix"></div>';

// display image
// display image or video
$result .= '<div class="text-center">';
if (!empty($link)) { $result .= '<a href="'. $link .'" rel="external">'; }
$result .= '<img src="'. Routes::route(URL_PHOTO, $day) .'" class="img-responsive img-thumbnail" alt="'. htmlspecialchars($title) .'" />';
if (Image::getInfo($day)['type'] == 'video/mp4') {
$result .= '<video controls preload="none" width="100%" class="img-responsive img-thumbnail"><source src="'. Routes::route(URL_PHOTO, $day) .'" type="video/mp4"></video>';
} else {
$result .= '<img src="'. Routes::route(URL_PHOTO, $day) .'" class="img-responsive img-thumbnail" alt="'. htmlspecialchars($title) .'">';
}
if (!empty($link)) { $result .= '</a>'; }

// do we have a legend?
Expand Down Expand Up @@ -483,9 +489,14 @@ static public function get() {
*/
if (defined('PASSKEY')) {
// for calendars on same server, set a different cookie name based on the script path
session_name(md5($_SERVER['SCRIPT_NAME']));
session_name('advent_'.md5($_SERVER['SCRIPT_NAME']));

session_start();
session_start([
'cookie_httponly' => true,
'cookie_samesite' => 'Lax',
'cookie_lifetime' => 24*3600, // 24 hours
'cookie_path' => dirname($_SERVER['SCRIPT_NAME']),
]);

// want to log out
if (isset($_GET[URL_LOGOUT])) {
Expand Down Expand Up @@ -669,7 +680,7 @@ static public function get() {
</script>
<?php endif; ?>
<?php if (AddOns::Found('plausible')): $plausible = AddOns::Get('plausible'); ?>
<script async defer data-domain="<?= $plausible['domain'] ?>" src="<?php echo isset($plausible['custom_src']) && !empty($plausible['custom_src']) ? $plausible['custom_src']: 'https://plausible.io/js/plausible.js'; ?>"></script>
<script async defer data-domain="<?= $plausible['domain'] ?>" src="https://plausible.io/js/plausible.js"></script>
<?php endif; ?>
</body>
</html>
3 changes: 2 additions & 1 deletion private/calendar.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"text": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
},
"2": {
"legend": "Berlin, March 2013"
"legend": "Berlin, March 2013",
"link": "https://www.berlin.de"
},
"6": {
"title": "Saint Nicholas Day"
Expand Down
4 changes: 2 additions & 2 deletions private/settings.example.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"title": "Advent Calendar · 2021",
"year": 2021
"title": "Advent Calendar · 2023",
"year": 2023
}

0 comments on commit f9cf40d

Please sign in to comment.