source: extensions/download_permissions/main.inc.php @ 30769

Last change on this file since 30769 was 30490, checked in by plg, 10 years ago

compatible with Piwigo 2.7

File size: 2.1 KB
Line 
1<?php 
2/*
3Plugin Name: Download Permissions
4Version: auto
5Description: Manage download permissions, filter by album.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
7Author: plg
8Author URI: http://le-gall.net/pierrick
9*/
10
11defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
12
13global $prefixeTable;
14define('DLPERMS_PATH',    PHPWG_PLUGINS_PATH . 'download_permissions/');
15define('DLPERMS_ADMIN',   get_root_url() . 'admin.php?page=plugin-download_permissions');
16define('DLPERMS_VERSION', 'auto');
17
18add_event_handler('init', 'dlperms_init');
19add_event_handler('loc_begin_picture', 'dlperms_begin_picture');
20 
21if (defined('IN_ADMIN'))
22{
23  add_event_handler('tabsheet_before_select', 'dlperms_tab', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
24}
25
26/**
27 * initialization
28 */
29function 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 */
45function 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
60function 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
70function 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 = '
76SELECT
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}
Note: See TracBrowser for help on using the repository browser.