[24677] | 1 | <?php |
---|
| 2 | /*********************************************** |
---|
| 3 | * File : maintain.inc.php |
---|
| 4 | * Project : piwigo-openstreetmap |
---|
| 5 | * Descr : Install / Uninstall method |
---|
| 6 | * |
---|
| 7 | * Created : 28.05.2013 |
---|
| 8 | * |
---|
| 9 | * Copyright 2013 <xbgmsharp@gmail.com> |
---|
| 10 | * |
---|
| 11 | * This program is free software: you can redistribute it and/or modify |
---|
| 12 | * it under the terms of the GNU General Public License as published by |
---|
| 13 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 14 | * (at your option) any later version. |
---|
| 15 | * |
---|
| 16 | * This program is distributed in the hope that it will be useful, |
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 19 | * GNU General Public License for more details. |
---|
| 20 | * |
---|
| 21 | * You should have received a copy of the GNU General Public License |
---|
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 23 | * |
---|
| 24 | ************************************************/ |
---|
| 25 | |
---|
| 26 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 27 | |
---|
| 28 | function plugin_install() |
---|
| 29 | { |
---|
| 30 | // Remove unused files from 0.4 to 0.5 |
---|
| 31 | $toremove = array("admin.tpl", "admin.php", "admin_boot.php"); |
---|
| 32 | foreach ($toremove as $file) |
---|
| 33 | { |
---|
| 34 | if (is_file(VIDEOJS_PATH.$file)) |
---|
| 35 | { |
---|
| 36 | @unlink(VIDEOJS_PATH.$file); |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | /* Modify images table if require */ |
---|
| 41 | $q = 'SELECT COUNT(*) as nb FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "'.IMAGES_TABLE.'" AND COLUMN_NAME = "lat" OR COLUMN_NAME = "lon"'; |
---|
| 42 | $result = pwg_db_fetch_array( pwg_query($q) ); |
---|
| 43 | if($result['nb'] != 2) |
---|
| 44 | { |
---|
| 45 | $q = 'ALTER TABLE '.IMAGES_TABLE.' ADD COLUMN `lat` DOUBLE(10,8) COMMENT "latitude used by the piwigo-openstreetmap plugin"'; |
---|
| 46 | pwg_query($q); |
---|
| 47 | $q = 'ALTER TABLE '.IMAGES_TABLE.' ADD INDEX images_lat(`lat`)'; |
---|
| 48 | pwg_query($q); |
---|
| 49 | $q = 'ALTER TABLE '.IMAGES_TABLE.' ADD COLUMN `lon` DOUBLE(11,8) COMMENT "longitude used by the piwigo-openstreetmap plugin"'; |
---|
| 50 | pwg_query($q); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | $default_config = array( |
---|
| 54 | 'right_panel' => array( |
---|
| 55 | 'enabled' => true, |
---|
| 56 | 'add_before' => 'Average', |
---|
| 57 | 'height' => '200', |
---|
| 58 | 'zoom' => 12, |
---|
| 59 | 'link' => 'Location', |
---|
| 60 | 'linkcss' => null, |
---|
| 61 | 'showosm' => true, |
---|
| 62 | ), |
---|
| 63 | 'left_menu' => array( |
---|
| 64 | 'enabled' => true, |
---|
| 65 | 'link' => 'OS World Map', |
---|
| 66 | 'popup' => 0, |
---|
| 67 | 'popupinfo_name' => true, |
---|
| 68 | 'popupinfo_img' => true, |
---|
| 69 | 'popupinfo_link' => true, |
---|
| 70 | 'popupinfo_comment' => true, |
---|
| 71 | 'popupinfo_author' => true, |
---|
| 72 | ), |
---|
| 73 | 'map' => array( |
---|
| 74 | 'baselayer' => 'mapnik', |
---|
| 75 | 'custombaselayer' => null, |
---|
| 76 | 'custombaselayerurl' => null, |
---|
| 77 | 'noworldwarp' => false, |
---|
| 78 | 'attrleaflet' => true, |
---|
| 79 | 'attrimagery' => true, |
---|
| 80 | 'attrplugin' => true, |
---|
| 81 | ), |
---|
| 82 | 'auto_sync' => false, |
---|
| 83 | 'batch_manager' => false, |
---|
| 84 | ); |
---|
| 85 | /* Add configuration to the config table */ |
---|
| 86 | $conf['osm_conf'] = serialize($default_config); |
---|
| 87 | conf_update_param('osm_conf', $conf['osm_conf']); |
---|
| 88 | |
---|
| 89 | $q = 'UPDATE '.CONFIG_TABLE.' SET `comment` = "Configuration settings for piwigo-openstreetmap plugin" WHERE `param` = "osm_conf";'; |
---|
| 90 | pwg_query( $q ); |
---|
| 91 | |
---|
| 92 | // Create world map link |
---|
| 93 | $dir_name = basename( dirname(__FILE__) ); |
---|
| 94 | $c = <<<EOF |
---|
| 95 | <?php |
---|
| 96 | define('PHPWG_ROOT_PATH','./'); |
---|
| 97 | include_once( PHPWG_ROOT_PATH. 'plugins/$dir_name/osmmap.php'); |
---|
| 98 | ?> |
---|
| 99 | EOF; |
---|
| 100 | $fp = fopen( PHPWG_ROOT_PATH.'osmmap.php', 'w' ); |
---|
| 101 | fwrite( $fp, $c); |
---|
| 102 | fclose( $fp ); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | function plugin_uninstall() |
---|
| 106 | { |
---|
| 107 | /* Delete all files */ |
---|
| 108 | /* Don't remove myself on restore settings |
---|
| 109 | if (is_dir(OSM_PATH)) |
---|
| 110 | { |
---|
| 111 | deltree(OSM_PATH); |
---|
| 112 | } |
---|
| 113 | */ |
---|
| 114 | // Remove world map link |
---|
| 115 | @unlink(PHPWG_ROOT_PATH.'osmmap.php'); |
---|
| 116 | |
---|
| 117 | /* Remove configuration from the config table */ |
---|
| 118 | $q = 'DELETE FROM '.CONFIG_TABLE.' WHERE param = "osm_conf" LIMIT 1;'; |
---|
| 119 | pwg_query( $q ); |
---|
| 120 | |
---|
| 121 | /* Remove geotag from images table */ |
---|
| 122 | /* |
---|
| 123 | $q = 'ALTER TABLE '.IMAGES_TABLE.' DROP COLUMN `lat`'; |
---|
| 124 | pwg_query( $q ); |
---|
| 125 | $q = 'ALTER TABLE '.IMAGES_TABLE.' DROP COLUMN `lon`'; |
---|
| 126 | pwg_query( $q ); |
---|
| 127 | $q = 'ALTER TABLE '.IMAGES_TABLE.' DROP INDEX `images_lat`'; |
---|
| 128 | pwg_query( $q ); |
---|
| 129 | */ |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | function plugin_activate() |
---|
| 133 | { |
---|
| 134 | global $conf; |
---|
| 135 | |
---|
| 136 | if ( (!isset($conf['osm_conf'])) |
---|
| 137 | or (count($conf['osm_conf'], COUNT_RECURSIVE) != 27)) |
---|
| 138 | { |
---|
| 139 | plugin_install(); |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | function deltree($path) |
---|
| 144 | { |
---|
| 145 | if (is_dir($path)) |
---|
| 146 | { |
---|
| 147 | $fh = opendir($path); |
---|
| 148 | while ($file = readdir($fh)) |
---|
| 149 | { |
---|
| 150 | if ($file != '.' and $file != '..') |
---|
| 151 | { |
---|
| 152 | $pathfile = $path . '/' . $file; |
---|
| 153 | if (is_dir($pathfile)) |
---|
| 154 | { |
---|
| 155 | deltree($pathfile); |
---|
| 156 | } |
---|
| 157 | else |
---|
| 158 | { |
---|
| 159 | @unlink($pathfile); |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | closedir($fh); |
---|
| 164 | return @rmdir($path); |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | ?> |
---|