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

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

initial import

File size: 2.3 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 
33  include_once(DLPERMS_PATH.'maintain.inc.php');
34  $maintain = new download_permissions_maintain('download_permissions');
35  $maintain->autoUpdate(DLPERMS_VERSION, 'install');
36
37  // overwrite $user['enabled_high'] depending on the current album
38  if ('action' == script_basename() and isset($_GET['id']) and is_numeric($_GET['id']))
39  {
40    if (!dlperms_is_photo_downloadable($_GET['id']))
41    {
42      $user['enabled_high'] = false;
43    }
44  }
45}
46
47/**
48 * tab on albums properties page
49 */
50function dlperms_tab($sheets, $id)
51{
52  if ($id == 'cat_options')
53  {
54    load_language('plugin.lang', DLPERMS_PATH);
55   
56    $sheets['dlperms'] = array(
57      'caption' => l10n('Download'),
58      'url' => DLPERMS_ADMIN.'-cat_options',
59      );
60  }
61 
62  return $sheets;
63}
64
65function dlperms_begin_picture()
66{
67  global $user, $page;
68
69  if (!dlperms_is_photo_downloadable($page['image_id']))
70  {
71    $user['enabled_high'] = false;
72  }
73}
74
75function dlperms_is_photo_downloadable($image_id)
76{
77  // the photo is downloadable if it belongs at least to one album that is
78  // downloadable
79
80  $query = '
81SELECT
82    COUNT(*)
83  FROM '.IMAGE_CATEGORY_TABLE.'
84    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
85  WHERE image_id = '.$image_id.'
86    AND downloadable = \'true\'
87'.get_sql_condition_FandF
88  (
89    array
90      (
91        'forbidden_categories' => 'id',
92        'visible_categories' => 'id'
93      ),
94    'AND'
95  ).'
96;';
97  list($counter) = pwg_db_fetch_row(pwg_query($query));
98
99  if (0 == $counter)
100  {
101    return false;
102  }
103
104  return true;
105}
Note: See TracBrowser for help on using the repository browser.