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 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | |
---|
13 | define('COPYRIGHTS_PATH', |
---|
14 | PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)) . '/'); // The plugin path |
---|
15 | define('COPYRIGHTS_WEB_PATH', get_root_url().'admin.php?page=plugin-copyrights'); |
---|
16 | |
---|
17 | global $prefixeTable; |
---|
18 | define('COPYRIGHTS_ADMIN', $prefixeTable.'copyrights_admin'); // The db |
---|
19 | define('COPYRIGHTS_MEDIA', $prefixeTable.'copyrights_media'); // The db |
---|
20 | |
---|
21 | include_once(COPYRIGHTS_PATH . 'include/functions.inc.php'); |
---|
22 | |
---|
23 | /* Plugin admin */ |
---|
24 | add_event_handler('get_admin_plugin_menu_links', 'copyrights_admin_menu'); |
---|
25 | function copyrights_admin_menu($menu) { |
---|
26 | array_push( |
---|
27 | $menu, |
---|
28 | array( |
---|
29 | 'NAME' => 'Copyrights', |
---|
30 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php' |
---|
31 | ) |
---|
32 | ); |
---|
33 | return $menu; |
---|
34 | } |
---|
35 | |
---|
36 | // Add copyrights drop down menu to the batch manager |
---|
37 | add_event_handler('loc_end_element_set_global', 'copyrights_batch'); |
---|
38 | // Add handler to the submit event of the batch manager |
---|
39 | add_event_handler('element_set_global_action', 'copyrights_batch_submit', 50, 2); |
---|
40 | |
---|
41 | function copyrights_batch() |
---|
42 | { |
---|
43 | global $template; |
---|
44 | |
---|
45 | //load_language('plugin.lang', dirname(__FILE__).'/'); // Engels is voorlopig goed zat |
---|
46 | |
---|
47 | // Assign the template for batch management |
---|
48 | $template->set_filename('batch', dirname(__FILE__).'/batch.tpl'); |
---|
49 | |
---|
50 | // Fetch all the copyrights and assign them to the template |
---|
51 | $query = ' |
---|
52 | SELECT `cr_id`,`name` |
---|
53 | FROM '.COPYRIGHTS_ADMIN.' |
---|
54 | WHERE `visible`<>0 |
---|
55 | ;'; |
---|
56 | $result = pwg_query($query); |
---|
57 | $CRoptions = array(); |
---|
58 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
59 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
60 | } |
---|
61 | $template->assign('CRoptions', $CRoptions); |
---|
62 | |
---|
63 | |
---|
64 | // Goed, ik weet dus echt niet waarom dit hieronder gedaan wordt... |
---|
65 | // AHA!!!! - dit is er zodat de "choose action" optie deze plugin gebruikt.... |
---|
66 | $template->append('element_set_global_plugins_actions', array( |
---|
67 | 'ID' => 'copyrights', // ID of the batch manager action |
---|
68 | 'NAME' => 'Edit copyrights', // Description of the batch manager action |
---|
69 | 'CONTENT' => $template->parse('batch', true) |
---|
70 | ) |
---|
71 | ); |
---|
72 | } |
---|
73 | |
---|
74 | // * Deze functie wordt een keer aangeroepen, nadat de gebruiker submit. |
---|
75 | // * Fietst met een foreach loop over de geselecteerde fotos |
---|
76 | // * Rammelt alle toevoegingen in 1x met mass_updates naar de db. |
---|
77 | function copyrights_batch_submit($action, $collection) |
---|
78 | { |
---|
79 | if ($action == 'copyrights') |
---|
80 | { |
---|
81 | $crID = $_POST['copyrightID']; |
---|
82 | |
---|
83 | if (count($collection) > 0) { |
---|
84 | $query = ' |
---|
85 | DELETE |
---|
86 | FROM '.COPYRIGHTS_MEDIA.' |
---|
87 | WHERE media_id IN ('.implode(',', $collection).') |
---|
88 | ;'; |
---|
89 | pwg_query($query); |
---|
90 | } |
---|
91 | |
---|
92 | $edits = array(); |
---|
93 | foreach ($collection as $image_id) |
---|
94 | { |
---|
95 | array_push( |
---|
96 | $edits, |
---|
97 | array( |
---|
98 | 'media_id' => $image_id, |
---|
99 | 'cr_id' => $crID, |
---|
100 | ) |
---|
101 | ); |
---|
102 | } |
---|
103 | |
---|
104 | mass_inserts( |
---|
105 | COPYRIGHTS_MEDIA, // Table name |
---|
106 | array_keys($edits[0]), //Columns |
---|
107 | $edits // Data |
---|
108 | ); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | ?> |
---|