[31491] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | meta plugin for Piwigo | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008-2016 ddtddt http://temmii.com/piwigo/ | |
---|
| 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 8 | // | it under the terms of the GNU General Public License as published by | |
---|
| 9 | // | the Free Software Foundation | |
---|
| 10 | // | | |
---|
| 11 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 14 | // | General Public License for more details. | |
---|
| 15 | // | | |
---|
| 16 | // | You should have received a copy of the GNU General Public License | |
---|
| 17 | // | along with this program; if not, write to the Free Software | |
---|
| 18 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 19 | // | USA. | |
---|
| 20 | // +-----------------------------------------------------------------------+ |
---|
| 21 | |
---|
| 22 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 23 | |
---|
| 24 | class meta_maintain extends PluginMaintain |
---|
| 25 | { |
---|
| 26 | function install($plugin_version, &$errors=array()) |
---|
| 27 | { |
---|
| 28 | global $conf, $prefixeTable; |
---|
| 29 | $q = 'CREATE TABLE ' . $prefixeTable . 'meta( |
---|
| 30 | id SMALLINT( 5 ) UNSIGNED NOT NULL , |
---|
| 31 | metaname VARCHAR( 255 ) NOT NULL , |
---|
| 32 | metaval lONGTEXT NOT NULL , |
---|
| 33 | metatype VARCHAR( 255 ) NOT NULL , |
---|
| 34 | PRIMARY KEY (id))DEFAULT CHARSET=utf8;'; |
---|
| 35 | pwg_query($q); |
---|
| 36 | |
---|
| 37 | $q = ' |
---|
| 38 | INSERT INTO ' . $prefixeTable . 'meta(id,metaname,metaval,metatype)VALUES (1,"author","","name");'; |
---|
| 39 | pwg_query($q); |
---|
| 40 | |
---|
| 41 | $q = ' |
---|
| 42 | INSERT INTO ' . $prefixeTable . 'meta(id,metaname,metaval,metatype)VALUES (2,"keywords","","name");'; |
---|
| 43 | pwg_query($q); |
---|
| 44 | |
---|
| 45 | $q = ' |
---|
| 46 | INSERT INTO ' . $prefixeTable . 'meta(id,metaname,metaval,metatype)VALUES (3,"Description","","name");'; |
---|
| 47 | pwg_query($q); |
---|
| 48 | |
---|
| 49 | $q = ' |
---|
| 50 | INSERT INTO ' . $prefixeTable . 'meta(id,metaname,metaval,metatype)VALUES (4,"robots","follow","name");'; |
---|
| 51 | pwg_query($q); |
---|
| 52 | |
---|
| 53 | if (!defined('meta_img_TABLE')) |
---|
| 54 | define('meta_img_TABLE', $prefixeTable . 'meta_img'); |
---|
| 55 | $query = "CREATE TABLE IF NOT EXISTS " . meta_img_TABLE . " ( |
---|
| 56 | id SMALLINT( 5 ) UNSIGNED NOT NULL , |
---|
| 57 | metaKeyimg VARCHAR( 255 ) NOT NULL , |
---|
| 58 | metadesimg VARCHAR( 255 ) NOT NULL , |
---|
| 59 | PRIMARY KEY (id))DEFAULT CHARSET=utf8;"; |
---|
| 60 | $result = pwg_query($query); |
---|
| 61 | |
---|
| 62 | if (!defined('meta_cat_TABLE')) |
---|
| 63 | define('meta_cat_TABLE', $prefixeTable . 'meta_cat'); |
---|
| 64 | $query = "CREATE TABLE IF NOT EXISTS " . meta_cat_TABLE . " ( |
---|
| 65 | id SMALLINT( 5 ) UNSIGNED NOT NULL , |
---|
| 66 | metaKeycat VARCHAR( 255 ) NOT NULL , |
---|
| 67 | metadescat VARCHAR( 255 ) NOT NULL , |
---|
| 68 | PRIMARY KEY (id))DEFAULT CHARSET=utf8;"; |
---|
| 69 | $result = pwg_query($query); |
---|
| 70 | |
---|
| 71 | if (!defined('METAPERSO_TABLE')) |
---|
| 72 | define('METAPERSO_TABLE', $prefixeTable . 'metaperso'); |
---|
| 73 | $query = "CREATE TABLE IF NOT EXISTS " . METAPERSO_TABLE . " ( |
---|
| 74 | id SMALLINT( 5 ) UNSIGNED NOT NULL auto_increment, |
---|
| 75 | metaname VARCHAR( 255 ) NOT NULL , |
---|
| 76 | metaval lONGTEXT NOT NULL , |
---|
| 77 | metatype VARCHAR( 255 ) NOT NULL , |
---|
| 78 | PRIMARY KEY (id))DEFAULT CHARSET=utf8;"; |
---|
| 79 | $result = pwg_query($query); |
---|
| 80 | |
---|
| 81 | $majm1 = 'meta 2.0.5'; |
---|
| 82 | $query = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) VALUES ("' . $majm1 . '",1,"MAJ meta");'; |
---|
| 83 | pwg_query($query); |
---|
| 84 | |
---|
| 85 | $majm2 = 'meta 2.1.0'; |
---|
| 86 | $query = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) VALUES ("' . $majm2 . '",1,"MAJ meta");'; |
---|
| 87 | pwg_query($query); |
---|
| 88 | |
---|
| 89 | if (empty($conf['contactmeta'])) { |
---|
| 90 | conf_update_param('contactmeta', ''); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | if (!defined('META_AP_TABLE')) |
---|
| 94 | define('META_AP_TABLE', $prefixeTable . 'meta_ap'); |
---|
| 95 | $query = "CREATE TABLE IF NOT EXISTS " . META_AP_TABLE . " ( |
---|
| 96 | id SMALLINT( 5 ) UNSIGNED NOT NULL , |
---|
| 97 | metaKeyap VARCHAR( 255 ) NOT NULL , |
---|
| 98 | metadesap VARCHAR( 255 ) NOT NULL , |
---|
| 99 | PRIMARY KEY (id))DEFAULT CHARSET=utf8;"; |
---|
| 100 | $result = pwg_query($query); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | function update($old_version, $new_version, &$errors=array()) |
---|
| 104 | { |
---|
| 105 | global $prefixeTable, $template; |
---|
| 106 | define('METAPERSO_TABLE', $prefixeTable . 'metaperso'); |
---|
| 107 | |
---|
| 108 | $query = "CREATE TABLE IF NOT EXISTS " . METAPERSO_TABLE . " ( |
---|
| 109 | id SMALLINT( 5 ) UNSIGNED NOT NULL auto_increment, |
---|
| 110 | metaname VARCHAR( 255 ) NOT NULL , |
---|
| 111 | metaval lONGTEXT NOT NULL , |
---|
| 112 | metatype VARCHAR( 255 ) NOT NULL , |
---|
| 113 | PRIMARY KEY (id))DEFAULT CHARSET=utf8;"; |
---|
| 114 | $result = pwg_query($query); |
---|
| 115 | |
---|
| 116 | if (!isset($conf['contactmeta'])) { |
---|
| 117 | conf_update_param('contactmeta', ','); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | if (!defined('META_AP_TABLE')) |
---|
| 121 | define('META_AP_TABLE', $prefixeTable . 'meta_ap'); |
---|
| 122 | $query = "CREATE TABLE IF NOT EXISTS " . META_AP_TABLE . " ( |
---|
| 123 | id SMALLINT( 5 ) UNSIGNED NOT NULL , |
---|
| 124 | metaKeyap VARCHAR( 255 ) NOT NULL , |
---|
| 125 | metadesap VARCHAR( 255 ) NOT NULL , |
---|
| 126 | PRIMARY KEY (id))DEFAULT CHARSET=utf8;"; |
---|
| 127 | $result = pwg_query($query); |
---|
| 128 | |
---|
| 129 | //Gestion MAJ2 |
---|
| 130 | $majm2 = 'meta 2.1.0'; |
---|
| 131 | $query = ' |
---|
| 132 | select param,value |
---|
| 133 | FROM ' . CONFIG_TABLE . ' |
---|
| 134 | WHERE param = \'' . $majm2 . '\' |
---|
| 135 | ;'; |
---|
| 136 | $result = pwg_query($query); |
---|
| 137 | |
---|
| 138 | $row = pwg_db_fetch_assoc($result); |
---|
| 139 | $majparam2 = $row['param']; |
---|
| 140 | $majvalue2 = $row['value']; |
---|
| 141 | |
---|
| 142 | if (!$majvalue2 == 1) { |
---|
| 143 | |
---|
| 144 | //Gestion MAJ1 |
---|
| 145 | $majm1 = 'meta 2.0.5'; |
---|
| 146 | $query = ' |
---|
| 147 | select param,value |
---|
| 148 | FROM ' . CONFIG_TABLE . ' |
---|
| 149 | WHERE param = \'' . $majm1 . '\' |
---|
| 150 | ;'; |
---|
| 151 | $result = pwg_query($query); |
---|
| 152 | |
---|
| 153 | $row = pwg_db_fetch_assoc($result); |
---|
| 154 | $majparam1 = $row['param']; |
---|
| 155 | $majvalue1 = $row['value']; |
---|
| 156 | |
---|
| 157 | if (!$majvalue1 == 1) { |
---|
| 158 | if (!defined('meta_img_TABLE')) |
---|
| 159 | define('meta_img_TABLE', $prefixeTable . 'meta_img'); |
---|
| 160 | $query = "CREATE TABLE IF NOT EXISTS " . meta_img_TABLE . " ( |
---|
| 161 | id SMALLINT( 5 ) UNSIGNED NOT NULL , |
---|
| 162 | metaKeyimg VARCHAR( 255 ) NOT NULL , |
---|
| 163 | PRIMARY KEY (id))DEFAULT CHARSET=utf8;"; |
---|
| 164 | $result = pwg_query($query); |
---|
| 165 | |
---|
| 166 | if (!defined('meta_cat_TABLE')) |
---|
| 167 | define('meta_cat_TABLE', $prefixeTable . 'meta_cat'); |
---|
| 168 | $query = "CREATE TABLE IF NOT EXISTS " . meta_cat_TABLE . " ( |
---|
| 169 | id SMALLINT( 5 ) UNSIGNED NOT NULL , |
---|
| 170 | metaKeycat VARCHAR( 255 ) NOT NULL , |
---|
| 171 | PRIMARY KEY (id))DEFAULT CHARSET=utf8;"; |
---|
| 172 | $result = pwg_query($query); |
---|
| 173 | |
---|
| 174 | $query = ' |
---|
| 175 | select id |
---|
| 176 | FROM ' . CATEGORIES_TABLE . ' |
---|
| 177 | ORDER BY id DESC;'; |
---|
| 178 | $result = pwg_query($query); |
---|
| 179 | $row = pwg_db_fetch_assoc($result); |
---|
| 180 | |
---|
| 181 | $comp = $row['id'] + 1; |
---|
| 182 | $i = 1; |
---|
| 183 | |
---|
| 184 | while ($i < $comp) { |
---|
| 185 | $query = ' |
---|
| 186 | select id,metaKeywords |
---|
| 187 | FROM ' . CATEGORIES_TABLE . ' |
---|
| 188 | WHERE id = \'' . $i . '\''; |
---|
| 189 | $result = pwg_query($query); |
---|
| 190 | $row = pwg_db_fetch_assoc($result); |
---|
| 191 | |
---|
| 192 | if (!$row['id'] == 0 and ! $row['metaKeywords'] == 0) { |
---|
| 193 | $query = ' |
---|
| 194 | INSERT INTO ' . $prefixeTable . 'meta_cat(id,metaKeycat)VALUES (' . $row['id'] . ',"' . $row['metaKeywords'] . '");'; |
---|
| 195 | $result = pwg_query($query); |
---|
| 196 | } |
---|
| 197 | ++$i; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | $query = ' ALTER TABLE ' . CATEGORIES_TABLE . ' DROP COLUMN `metaKeywords`'; |
---|
| 201 | pwg_query($query); |
---|
| 202 | |
---|
| 203 | $query = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) VALUES ("' . $majm1 . '",1,"MAJ meta");'; |
---|
| 204 | pwg_query($query); |
---|
| 205 | $majvalue1 == 1; |
---|
| 206 | $maj = 0; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | $q = ' |
---|
| 210 | ALTER TABLE ' . meta_cat_TABLE . ' ADD COLUMN metadescat VARCHAR( 255 ) NOT NULL '; |
---|
| 211 | pwg_query($q); |
---|
| 212 | |
---|
| 213 | $q = ' |
---|
| 214 | ALTER TABLE ' . meta_img_TABLE . ' ADD COLUMN metadesimg VARCHAR( 255 ) NOT NULL '; |
---|
| 215 | pwg_query($q); |
---|
| 216 | |
---|
| 217 | $query = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) VALUES ("' . $majm2 . '",1,"MAJ meta");'; |
---|
| 218 | pwg_query($query); |
---|
| 219 | |
---|
| 220 | $template->delete_compiled_templates(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); |
---|
| 221 | |
---|
| 222 | $majvalue2 == 1; |
---|
| 223 | $maj = 0; |
---|
| 224 | } } |
---|
| 225 | |
---|
| 226 | function uninstall() |
---|
| 227 | { |
---|
| 228 | |
---|
| 229 | $majm1 = 'meta 2.0.5'; |
---|
| 230 | $majm2 = 'meta 2.1.0'; |
---|
| 231 | |
---|
| 232 | global $prefixeTable; |
---|
| 233 | |
---|
| 234 | $q = 'DROP TABLE ' . $prefixeTable . 'meta;'; |
---|
| 235 | pwg_query($q); |
---|
| 236 | |
---|
| 237 | $q = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE param="' . $majm1 . '" LIMIT 1;'; |
---|
| 238 | pwg_query($q); |
---|
| 239 | |
---|
| 240 | $q = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE param="' . $majm2 . '" LIMIT 1;'; |
---|
| 241 | pwg_query($q); |
---|
| 242 | |
---|
| 243 | $q = 'DROP TABLE ' . $prefixeTable . 'meta_img;'; |
---|
| 244 | pwg_query($q); |
---|
| 245 | |
---|
| 246 | $q = 'DROP TABLE ' . $prefixeTable . 'meta_cat;'; |
---|
| 247 | pwg_query($q); |
---|
| 248 | |
---|
| 249 | conf_delete_param('contactmeta'); |
---|
| 250 | } |
---|
| 251 | } |
---|