source: extensions/batch_manager_added_by/main.inc.php @ 29530

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

compatibility Piwigo 2.7

File size: 3.1 KB
Line 
1<?php
2/*
3Plugin Name: Batch Manager, Added By
4Version: auto
5Description: Add filter "Added by" in Batch Manager
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
7Author: plg
8Author URI: http://le-gall.net/pierrick
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13add_event_handler('loc_end_element_set_global', 'bmab_add_filter');
14function bmab_add_filter()
15{
16  global $conf, $template;
17
18  $query = '
19SELECT
20    u.'.$conf['user_fields']['username'].' AS username,
21    i.added_by,
22    COUNT(*) AS counter
23  FROM '.USERS_TABLE.' AS u
24    INNER JOIN '.IMAGES_TABLE.' AS i ON u.'.$conf['user_fields']['id'].' = i.added_by
25  GROUP BY i.added_by
26  ORDER BY u.'.$conf['user_fields']['username'].' ASC
27;';
28  $result = pwg_query($query);
29 
30  $added_by_options = array();
31  while ($row = pwg_db_fetch_assoc($result))
32  {
33    $added_by_options[$row['added_by']] = $row['username'].' ('.l10n_dec('%d photo', '%d photos', $row['counter']).')';
34  }
35  $template->assign('added_by_options', $added_by_options);
36
37  $template->assign(
38    'added_by_selected',
39    isset($_SESSION['bulk_manager_filter']['added_by']) ? $_SESSION['bulk_manager_filter']['added_by'] : ''
40    );
41
42  $template->set_prefilter('batch_manager_global', 'bmab_add_filter_prefilter');
43}
44
45function bmab_add_filter_prefilter($content, &$smarty)
46{
47  // first we add the (hidden by default) block to select the user
48  $pattern = '#</ul>\s*<p class="actionButtons">#ms';
49  $replacement = '
50      <li id="filter_added_by" {if !isset($filter.added_by)}style="display:none"{/if}>
51        <a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a>
52        <input type="checkbox" name="filter_added_by_use" class="useFilterCheckbox" {if isset($filter.added_by)}checked="checked"{/if}>
53        {\'Added by %s\'|@translate|sprintf:""}
54        <select name="filter_added_by">
55          {html_options options=$added_by_options selected=$added_by_selected}
56        </select>
57      </li>
58    </ul>
59
60    <p class="actionButtons">
61';
62  $content = preg_replace($pattern, $replacement, $content);
63
64  // then we add the "Added by" in the filter selector
65  $pattern = '#</select>\s*<a id="removeFilters"#ms';
66  $replacement = '
67<option value="filter_added_by" {if isset($filter.added_by)}disabled="disabled"{/if}>{\'Added by %s\'|@translate|sprintf:""}</option>
68      </select>
69      <a id="removeFilters"
70';
71  $content = preg_replace($pattern, $replacement, $content);
72
73  return $content;
74}
75
76add_event_handler('batch_manager_register_filters', 'bmab_register_filter', 50, 2);
77function bmab_register_filter()
78{
79  global $page;
80
81  if (isset($_POST['filter_added_by_use']))
82  {
83    check_input_parameter('filter_added_by', $_POST, false, PATTERN_ID);
84    $_SESSION['bulk_manager_filter']['added_by'] = $_POST['filter_added_by'];
85  }
86}
87
88add_event_handler('batch_manager_perform_filters', 'bmab_perform_filter');
89function bmab_perform_filter($filter_sets)
90{
91  if (isset($_SESSION['bulk_manager_filter']['added_by']))
92  {
93    $query = '
94SELECT
95    id
96  FROM '.IMAGES_TABLE.'
97  WHERE added_by = '.$_SESSION['bulk_manager_filter']['added_by'].'
98;';
99    $filter_sets[] = array_from_query($query, 'id');
100  }
101
102  return $filter_sets;
103}
104?>
Note: See TracBrowser for help on using the repository browser.