-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimage.php
More file actions
85 lines (69 loc) · 2.05 KB
/
image.php
File metadata and controls
85 lines (69 loc) · 2.05 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
// Add an event handler for a prefilter
add_event_handler('loc_end_picture', 'expd_loc_end_picture');
/**
* Add the prefilter to the template
*/
function expd_loc_end_picture()
{
global $template, $picture;
$template->set_prefilter('picture', 'expd_picture_prefilter');
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
if (!isset($picture['current']['expiry_date']) and !isset($picture['current']['expd_expired_on']))
{
return;
}
if (isset($picture['current']['expiry_date']))
{
$expiry_date = $picture['current']['expiry_date'];
$datetime1 = new DateTime($expiry_date);
$datetime2 = new DateTime($dbnow);
$interval = $datetime2->diff($datetime1);
$interval = $interval->format("%r%a");
$expiry_date = format_date($picture['current']['expiry_date']);
$template->assign(
array (
'expiry_date' => $expiry_date,
'expd_days' => $interval,
)
);
}
if (isset($picture['current']['expd_expired_on']) and !isset($picture['current']['expiry_date']))
{
$expired_on_date = format_date($picture['current']['expd_expired_on']);
$template->assign(
array (
'expired_on_date' => $expired_on_date,
)
);
}
}
/**
* Add expiry date to picture page
*/
function expd_picture_prefilter($content)
{
//TODO make compatible with modus, bootstrap and elegant
// Search for image info block
$search = '{if $display_info.rating_score';
//add expiry date to image info block or expire on date
$replace = '
{if isset($expiry_date)}
<div id="expd_expiry_date" class="imageInfo">
<dl class="row mb-0">
<dt class="col-sm-5">{\'Expiry date\'|translate}</dt>
<dd class="col-sm-7">{\'%s, in %s days\'|translate:$expiry_date:$expd_days}</dd>
</dl>
</div>
{/if}
{if isset($expired_on_date)}
<div id="expd_expired_on_date" class="imageInfo">
<dl class="row mb-0">
<dt class="col-sm-5">{\'expired on\'|@translate}</dt>
<dd class="col-sm-7">{$expired_on_date}</dd>
</dl>
</div>
{/if}
'.$search;
return str_replace($search, $replace, $content);
}