1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | function plugin_install($plugin_id, $plugin_version, &$errors) { |
---|
25 | global $conf, $prefixeTable; |
---|
26 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
27 | |
---|
28 | // Check if the copyrights plugin is there |
---|
29 | $query = ' |
---|
30 | SELECT `id` |
---|
31 | FROM '.$prefixeTable.'plugins |
---|
32 | WHERE id=\'Copyrights\' |
---|
33 | ;'; |
---|
34 | $result = pwg_query($query); |
---|
35 | // if not, cancel the install |
---|
36 | if (!pwg_db_fetch_assoc($result)) { |
---|
37 | $msg = l10n('To install this plugin, you need to install the <a href="http://piwigo.org/ext/extension_view.php?eid=537">Copyrights plugin</a> first.'); |
---|
38 | if(is_array($errors)) { |
---|
39 | array_push($errors, $msg); |
---|
40 | } else { |
---|
41 | $errors=Array($msg); |
---|
42 | } |
---|
43 | return false; |
---|
44 | } |
---|
45 | |
---|
46 | // Create the author table |
---|
47 | $query = ' |
---|
48 | CREATE TABLE IF NOT EXISTS '.$prefixeTable.'author_extended ( |
---|
49 | author_id int(11) NOT NULL AUTO_INCREMENT, |
---|
50 | name varchar(255) UNIQUE NOT NULL, |
---|
51 | url varchar(255), |
---|
52 | descr text DEFAULT NULL, |
---|
53 | copyright int(11) DEFAULT NULL, |
---|
54 | PRIMARY KEY (author_id) |
---|
55 | ) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 |
---|
56 | ;'; |
---|
57 | pwg_query($query); |
---|
58 | |
---|
59 | // Temporary disable the auto increment |
---|
60 | $query = ' |
---|
61 | ALTER TABLE '.$prefixeTable.'copyrights_admin |
---|
62 | MODIFY cr_id int(11) NOT NULL |
---|
63 | ;'; |
---|
64 | pwg_query($query); |
---|
65 | // Insert "author's default copyright" in the copyrights table. On duplicates, it does nothing. |
---|
66 | $query = ' |
---|
67 | INSERT INTO '.$prefixeTable.'copyrights_admin |
---|
68 | VALUES (-1, \'Author\'\'s default copyright\', \'\', \'This is the default copyright for an author.\', 1) |
---|
69 | ON DUPLICATE KEY UPDATE cr_id = -1 |
---|
70 | ;'; |
---|
71 | pwg_query($query); |
---|
72 | // Reenable the auto increment |
---|
73 | $query = ' |
---|
74 | ALTER TABLE '.$prefixeTable.'copyrights_admin |
---|
75 | MODIFY cr_id int(11) NOT NULL AUTO_INCREMENT |
---|
76 | ;'; |
---|
77 | pwg_query($query); |
---|
78 | } |
---|
79 | |
---|
80 | function plugin_uninstall() { |
---|
81 | global $prefixeTable; |
---|
82 | |
---|
83 | // Drop the author table |
---|
84 | $query = ' |
---|
85 | DROP TABLE '.$prefixeTable.'author_extended |
---|
86 | ;'; |
---|
87 | pwg_query($query); |
---|
88 | |
---|
89 | // Remove the default copyright from the admin table |
---|
90 | $query = ' |
---|
91 | DELETE |
---|
92 | FROM '.$prefixeTable.'copyrights_admin |
---|
93 | WHERE cr_id = -1 |
---|
94 | ;'; |
---|
95 | pwg_query($query); |
---|
96 | |
---|
97 | // And remove all default copyrights from the media table |
---|
98 | $query = ' |
---|
99 | DELETE |
---|
100 | FROM '.$prefixeTable.'copyrights_media |
---|
101 | WHERE cr_id = -1 |
---|
102 | ;'; |
---|
103 | pwg_query($query); |
---|
104 | } |
---|
105 | |
---|
106 | ?> |
---|