source: extensions/Extended_author/maintain.inc.php @ 27608

Last change on this file since 27608 was 12390, checked in by Mattias, 13 years ago

Small code cleanups - compatible with piwigo

File size: 3.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 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
24function 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          code varchar (4) UNIQUE NOT NULL,
52      url varchar(255),
53      descr text DEFAULT NULL,
54          copyright int(11) DEFAULT NULL,
55      PRIMARY KEY (author_id)
56    ) ENGINE=MyISAM DEFAULT CHARACTER SET utf8
57    ;';
58  pwg_query($query);
59 
60  // Temporary disable the auto increment
61  $query = '
62        ALTER TABLE '.$prefixeTable.'copyrights_admin
63        MODIFY cr_id int(11) NOT NULL
64    ;';
65  pwg_query($query);
66  // Insert "author's default copyright" in the copyrights table. On duplicates, it does nothing.
67  $query = '
68        INSERT INTO '.$prefixeTable.'copyrights_admin
69        VALUES (-1, \'Author\'\'s default copyright\', \'\', \'This is the default copyright for an author.\', 1)
70        ON DUPLICATE KEY UPDATE cr_id = -1
71    ;';
72  pwg_query($query);
73  // Reenable the auto increment
74  $query = '
75        ALTER TABLE '.$prefixeTable.'copyrights_admin
76        MODIFY cr_id int(11) NOT NULL AUTO_INCREMENT
77    ;';
78  pwg_query($query);
79}
80
81function plugin_uninstall() {
82  global $prefixeTable;
83 
84  // Drop the author table
85  $query = '
86    DROP TABLE '.$prefixeTable.'author_extended
87    ;';
88  pwg_query($query);
89 
90  // Remove the default copyright from the admin table
91  $query = '
92    DELETE
93    FROM '.$prefixeTable.'copyrights_admin
94    WHERE cr_id = -1
95    ;';
96  pwg_query($query);
97 
98  // And remove all default copyrights from the media table
99  $query = '
100    DELETE
101    FROM '.$prefixeTable.'copyrights_media
102    WHERE cr_id = -1
103    ;';
104  pwg_query($query); 
105}
106
107?>
Note: See TracBrowser for help on using the repository browser.