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', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)) . '/'); // The plugin path |
---|
35 | define('COPYRIGHTS_WEB_PATH', get_root_url().'admin.php?page=plugin-copyrights'); |
---|
36 | // Whats the difference between "COPYRIGHTS_PATH" and "COPYRIGHTS_WEB_PATH" ??? |
---|
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 | |
---|
45 | /* +-----------------------------------------------------------------------+ |
---|
46 | * | Plugin admin | |
---|
47 | * +-----------------------------------------------------------------------+ */ |
---|
48 | |
---|
49 | |
---|
50 | add_event_handler('get_admin_plugin_menu_links', 'copyrights_admin_menu'); |
---|
51 | function copyrights_admin_menu($menu) { |
---|
52 | array_push( |
---|
53 | $menu, |
---|
54 | array( |
---|
55 | 'NAME' => 'Copyrights', |
---|
56 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php' |
---|
57 | ) |
---|
58 | ); |
---|
59 | return $menu; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /* +-----------------------------------------------------------------------+ |
---|
64 | * | Plugin image | |
---|
65 | * +-----------------------------------------------------------------------+ */ |
---|
66 | |
---|
67 | |
---|
68 | //if (script_basename() == 'picture') // Why should i want this here? |
---|
69 | include_once(dirname(__FILE__).'/image.php'); |
---|
70 | |
---|
71 | |
---|
72 | /* +-----------------------------------------------------------------------+ |
---|
73 | * | Plugin batchmanager | |
---|
74 | * +-----------------------------------------------------------------------+ */ |
---|
75 | |
---|
76 | |
---|
77 | // @Johan: Misschien een goed idee om dit ook in een apart php scriptje te zetten, voor de overzichtelijkheid. |
---|
78 | // En om deze reden (Citaat uit de piwigo docs http://piwigo.org/doc/doku.php?id=en:plugins): |
---|
79 | // Code size |
---|
80 | // When PWG loads the plugins, it will include every main.inc.php. |
---|
81 | // Don't put in your main.inc.php 3000 lines of code just to add a page on the administration menu. |
---|
82 | // Split you main.inc.php in several files and feel free to add include_once inside functions defined in main.inc.php as much as you want. |
---|
83 | |
---|
84 | |
---|
85 | // Add copyrights drop down menu to the batch manager |
---|
86 | add_event_handler('loc_end_element_set_global', 'copyrights_batch'); |
---|
87 | // Add handler to the submit event of the batch manager |
---|
88 | add_event_handler('element_set_global_action', 'copyrights_batch_submit', 50, 2); |
---|
89 | |
---|
90 | function copyrights_batch() |
---|
91 | { |
---|
92 | global $template; |
---|
93 | |
---|
94 | //load_language('plugin.lang', dirname(__FILE__).'/'); // Engels is voorlopig goed zat |
---|
95 | |
---|
96 | // Assign the template for batch management |
---|
97 | $template->set_filename('batch', dirname(__FILE__).'/batch.tpl'); |
---|
98 | |
---|
99 | // Fetch all the copyrights and assign them to the template |
---|
100 | $query = sprintf( |
---|
101 | 'SELECT `cr_id`,`name` |
---|
102 | FROM %s |
---|
103 | WHERE `visible`<>0 |
---|
104 | ;', |
---|
105 | COPYRIGHTS_ADMIN); |
---|
106 | $result = pwg_query($query); |
---|
107 | $CRoptions = array(); |
---|
108 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
109 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
110 | } |
---|
111 | $template->assign('CRoptions', $CRoptions); |
---|
112 | |
---|
113 | |
---|
114 | // Goed, ik weet dus echt niet waarom dit hieronder gedaan wordt... |
---|
115 | // AHA!!!! - dit is er zodat de "choose action" optie deze plugin gebruikt.... |
---|
116 | $template->append('element_set_global_plugins_actions', array( |
---|
117 | 'ID' => 'copyrights', // ID of the batch manager action |
---|
118 | 'NAME' => 'Edit copyrights', // Description of the batch manager action |
---|
119 | 'CONTENT' => $template->parse('batch', true) |
---|
120 | ) |
---|
121 | ); |
---|
122 | } |
---|
123 | |
---|
124 | // * Deze functie wordt een keer aangeroepen, nadat de gebruiker submit. |
---|
125 | // * Fietst met een foreach loop over de geselecteerde fotos |
---|
126 | // * Rammelt alle toevoegingen in 1x met mass_updates naar de db. |
---|
127 | function copyrights_batch_submit($action, $collection) |
---|
128 | { |
---|
129 | if ($action == 'copyrights') |
---|
130 | { |
---|
131 | $crID = pwg_db_real_escape_string($_POST['copyrightID']); |
---|
132 | |
---|
133 | if (count($collection) > 0) { |
---|
134 | $query = sprintf( |
---|
135 | 'DELETE |
---|
136 | FROM %s |
---|
137 | WHERE media_id IN (%s) |
---|
138 | ;', |
---|
139 | COPYRIGHTS_MEDIA, implode(',', $collection)); |
---|
140 | pwg_query($query); |
---|
141 | } |
---|
142 | |
---|
143 | $edits = array(); |
---|
144 | foreach ($collection as $image_id) |
---|
145 | { |
---|
146 | array_push( |
---|
147 | $edits, |
---|
148 | array( |
---|
149 | 'media_id' => $image_id, |
---|
150 | 'cr_id' => $crID, |
---|
151 | ) |
---|
152 | ); |
---|
153 | } |
---|
154 | |
---|
155 | mass_inserts( |
---|
156 | COPYRIGHTS_MEDIA, // Table name |
---|
157 | array_keys($edits[0]), //Columns |
---|
158 | $edits // Data |
---|
159 | ); |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | ?> |
---|