1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Download by Size |
---|
4 | Version: auto |
---|
5 | Description: Select a photo size before download |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid= |
---|
7 | Author: plg |
---|
8 | Author URI: http://le-gall.net/pierrick |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) |
---|
12 | { |
---|
13 | die('Hacking attempt!'); |
---|
14 | } |
---|
15 | |
---|
16 | define('DLSIZE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
17 | |
---|
18 | add_event_handler('loc_end_picture', 'dlsize_picture'); |
---|
19 | function dlsize_picture() |
---|
20 | { |
---|
21 | global $conf, $template, $picture; |
---|
22 | |
---|
23 | $template->set_prefilter('picture', 'dlsize_picture_prefilter'); |
---|
24 | |
---|
25 | $params = array( |
---|
26 | 'id' => $picture['current']['id'], |
---|
27 | 'part' => 'e', |
---|
28 | 'download' => null, |
---|
29 | ); |
---|
30 | $base_dl_url = add_url_params(get_root_url().PHPWG_PLUGINS_PATH.'download_by_size/action.php', $params); |
---|
31 | |
---|
32 | $template->assign( |
---|
33 | array( |
---|
34 | 'DLSIZE_URL' => $base_dl_url.'&size=', |
---|
35 | ) |
---|
36 | ); |
---|
37 | |
---|
38 | if ($conf['picture_download_icon']) |
---|
39 | { |
---|
40 | // even if original can't be downloaded, we set U_DOWNLOAD so that |
---|
41 | // visitor can download smaller sizes |
---|
42 | $template->append('current', array('U_DOWNLOAD' => '#'), true); |
---|
43 | |
---|
44 | if (!empty($picture['current']['download_url'])) |
---|
45 | { |
---|
46 | $template->assign('DLSIZE_ORIGINAL', $picture['current']['download_url']); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | $template->set_filename('dlsize_picture', realpath(DLSIZE_PATH.'picture.tpl')); |
---|
51 | $template->parse('dlsize_picture'); |
---|
52 | } |
---|
53 | |
---|
54 | function dlsize_picture_prefilter($content, &$smarty) |
---|
55 | { |
---|
56 | $pattern = '#\{if isset\(\$current\.U_DOWNLOAD\)\}\s*<a #'; |
---|
57 | $replacement = '{if isset($current.U_DOWNLOAD)}<a id="downloadSizeLink" '; |
---|
58 | $content = preg_replace($pattern, $replacement, $content); |
---|
59 | |
---|
60 | return $content; |
---|
61 | } |
---|
62 | |
---|
63 | ?> |
---|