1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Copyrights |
---|
4 | Version: Alpha |
---|
5 | Description: Create copyrights and assign them to your photos. |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=537 |
---|
7 | Author: Matty & Johan (dwo) |
---|
8 | Author URI: http://www.watergallery.nl/piwigo/plugins/copyrights/ |
---|
9 | */ |
---|
10 | // +-----------------------------------------------------------------------+ |
---|
11 | // | Piwigo - a PHP based picture gallery | |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
14 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
15 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
16 | // +-----------------------------------------------------------------------+ |
---|
17 | // | This program is free software; you can redistribute it and/or modify | |
---|
18 | // | it under the terms of the GNU General Public License as published by | |
---|
19 | // | the Free Software Foundation | |
---|
20 | // | | |
---|
21 | // | This program is distributed in the hope that it will be useful, but | |
---|
22 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
23 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
24 | // | General Public License for more details. | |
---|
25 | // | | |
---|
26 | // | You should have received a copy of the GNU General Public License | |
---|
27 | // | along with this program; if not, write to the Free Software | |
---|
28 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
29 | // | USA. | |
---|
30 | // +-----------------------------------------------------------------------+ |
---|
31 | |
---|
32 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
33 | |
---|
34 | define('COPYRIGHTS_PATH', |
---|
35 | PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)) . '/'); // The plugin path |
---|
36 | define('COPYRIGHTS_WEB_PATH', get_root_url().'admin.php?page=plugin-copyrights'); |
---|
37 | |
---|
38 | global $prefixeTable; |
---|
39 | define('COPYRIGHTS_ADMIN', $prefixeTable.'copyrights_admin'); // The db |
---|
40 | define('COPYRIGHTS_MEDIA', $prefixeTable.'copyrights_media'); // The db |
---|
41 | |
---|
42 | include_once(COPYRIGHTS_PATH . 'include/functions.inc.php'); |
---|
43 | |
---|
44 | /* Plugin admin */ |
---|
45 | add_event_handler('get_admin_plugin_menu_links', 'copyrights_admin_menu'); |
---|
46 | function copyrights_admin_menu($menu) { |
---|
47 | array_push( |
---|
48 | $menu, |
---|
49 | array( |
---|
50 | 'NAME' => 'Copyrights', |
---|
51 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php' |
---|
52 | ) |
---|
53 | ); |
---|
54 | return $menu; |
---|
55 | } |
---|
56 | |
---|
57 | // Add copyrights drop down menu to the batch manager |
---|
58 | add_event_handler('loc_end_element_set_global', 'copyrights_batch'); |
---|
59 | // Add handler to the submit event of the batch manager |
---|
60 | add_event_handler('element_set_global_action', 'copyrights_batch_submit', 50, 2); |
---|
61 | |
---|
62 | function copyrights_batch() |
---|
63 | { |
---|
64 | global $template; |
---|
65 | |
---|
66 | //load_language('plugin.lang', dirname(__FILE__).'/'); // Engels is voorlopig goed zat |
---|
67 | |
---|
68 | // Assign the template for batch management |
---|
69 | $template->set_filename('batch', dirname(__FILE__).'/batch.tpl'); |
---|
70 | |
---|
71 | // Fetch all the copyrights and assign them to the template |
---|
72 | $query = sprintf( |
---|
73 | 'SELECT `cr_id`,`name` |
---|
74 | FROM %s |
---|
75 | WHERE `visible`<>0 |
---|
76 | ;', |
---|
77 | COPYRIGHT_ADMIN); |
---|
78 | $result = pwg_query($query); |
---|
79 | $CRoptions = array(); |
---|
80 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
81 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
82 | } |
---|
83 | $template->assign('CRoptions', $CRoptions); |
---|
84 | |
---|
85 | |
---|
86 | // Goed, ik weet dus echt niet waarom dit hieronder gedaan wordt... |
---|
87 | // AHA!!!! - dit is er zodat de "choose action" optie deze plugin gebruikt.... |
---|
88 | $template->append('element_set_global_plugins_actions', array( |
---|
89 | 'ID' => 'copyrights', // ID of the batch manager action |
---|
90 | 'NAME' => 'Edit copyrights', // Description of the batch manager action |
---|
91 | 'CONTENT' => $template->parse('batch', true) |
---|
92 | ) |
---|
93 | ); |
---|
94 | } |
---|
95 | |
---|
96 | // * Deze functie wordt een keer aangeroepen, nadat de gebruiker submit. |
---|
97 | // * Fietst met een foreach loop over de geselecteerde fotos |
---|
98 | // * Rammelt alle toevoegingen in 1x met mass_updates naar de db. |
---|
99 | function copyrights_batch_submit($action, $collection) |
---|
100 | { |
---|
101 | if ($action == 'copyrights') |
---|
102 | { |
---|
103 | $crID = pwg_db_real_escape_string($_POST['copyrightID']); |
---|
104 | |
---|
105 | if (count($collection) > 0) { |
---|
106 | $query = sprintf( |
---|
107 | 'DELETE |
---|
108 | FROM %s |
---|
109 | WHERE media_id IN (%s) |
---|
110 | ;', |
---|
111 | COPYRIGHT_MEDIA, implode(',', $collection)); |
---|
112 | pwg_query($query); |
---|
113 | } |
---|
114 | |
---|
115 | $edits = array(); |
---|
116 | foreach ($collection as $image_id) |
---|
117 | { |
---|
118 | array_push( |
---|
119 | $edits, |
---|
120 | array( |
---|
121 | 'media_id' => $image_id, |
---|
122 | 'cr_id' => $crID, |
---|
123 | ) |
---|
124 | ); |
---|
125 | } |
---|
126 | |
---|
127 | mass_inserts( |
---|
128 | COPYRIGHTS_MEDIA, // Table name |
---|
129 | array_keys($edits[0]), //Columns |
---|
130 | $edits // Data |
---|
131 | ); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | ?> |
---|