1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Download Permissions |
---|
4 | Version: auto |
---|
5 | Description: Manage download permissions, filter by album. |
---|
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 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
12 | |
---|
13 | global $prefixeTable; |
---|
14 | define('DLPERMS_PATH', PHPWG_PLUGINS_PATH . 'download_permissions/'); |
---|
15 | define('DLPERMS_ADMIN', get_root_url() . 'admin.php?page=plugin-download_permissions'); |
---|
16 | define('DLPERMS_VERSION', 'auto'); |
---|
17 | |
---|
18 | add_event_handler('init', 'dlperms_init'); |
---|
19 | add_event_handler('loc_begin_picture', 'dlperms_begin_picture'); |
---|
20 | |
---|
21 | if (defined('IN_ADMIN')) |
---|
22 | { |
---|
23 | add_event_handler('tabsheet_before_select', 'dlperms_tab', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
24 | } |
---|
25 | |
---|
26 | /** |
---|
27 | * initialization |
---|
28 | */ |
---|
29 | function dlperms_init() |
---|
30 | { |
---|
31 | global $user; |
---|
32 | // overwrite $user['enabled_high'] depending on the current album |
---|
33 | if ('action' == script_basename() and isset($_GET['id']) and is_numeric($_GET['id'])) |
---|
34 | { |
---|
35 | if (!dlperms_is_photo_downloadable($_GET['id'])) |
---|
36 | { |
---|
37 | $user['enabled_high'] = false; |
---|
38 | } |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * tab on albums properties page |
---|
44 | */ |
---|
45 | function dlperms_tab($sheets, $id) |
---|
46 | { |
---|
47 | if ($id == 'cat_options') |
---|
48 | { |
---|
49 | load_language('plugin.lang', DLPERMS_PATH); |
---|
50 | |
---|
51 | $sheets['dlperms'] = array( |
---|
52 | 'caption' => l10n('Download'), |
---|
53 | 'url' => DLPERMS_ADMIN.'-cat_options', |
---|
54 | ); |
---|
55 | } |
---|
56 | |
---|
57 | return $sheets; |
---|
58 | } |
---|
59 | |
---|
60 | function dlperms_begin_picture() |
---|
61 | { |
---|
62 | global $user, $page; |
---|
63 | |
---|
64 | if (!dlperms_is_photo_downloadable($page['image_id'])) |
---|
65 | { |
---|
66 | $user['enabled_high'] = false; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | function dlperms_is_photo_downloadable($image_id) |
---|
71 | { |
---|
72 | // the photo is downloadable if it belongs at least to one album that is |
---|
73 | // downloadable |
---|
74 | |
---|
75 | $query = ' |
---|
76 | SELECT |
---|
77 | COUNT(*) |
---|
78 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
79 | INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id |
---|
80 | WHERE image_id = '.$image_id.' |
---|
81 | AND downloadable = \'true\' |
---|
82 | '.get_sql_condition_FandF |
---|
83 | ( |
---|
84 | array |
---|
85 | ( |
---|
86 | 'forbidden_categories' => 'id', |
---|
87 | 'visible_categories' => 'id' |
---|
88 | ), |
---|
89 | 'AND' |
---|
90 | ).' |
---|
91 | ;'; |
---|
92 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
---|
93 | |
---|
94 | if (0 == $counter) |
---|
95 | { |
---|
96 | return false; |
---|
97 | } |
---|
98 | |
---|
99 | return true; |
---|
100 | } |
---|