[7054] | 1 | <?php |
---|
| 2 | /* ----------------------------------------------------------------------------- |
---|
| 3 | Plugin : GMaps |
---|
| 4 | Author : Grum |
---|
| 5 | email : grum@piwigo.org |
---|
| 6 | website : http://photos.grum.fr |
---|
| 7 | |
---|
| 8 | << May the Little SpaceFrog be with you ! >> |
---|
| 9 | ------------------------------------------------------------------------------ |
---|
| 10 | See main.inc.php for release information |
---|
| 11 | |
---|
| 12 | GMaps_Install : classe to manage plugin install |
---|
| 13 | |
---|
| 14 | --------------------------------------------------------------------------- */ |
---|
| 15 | |
---|
| 16 | include_once('gmaps_version.inc.php'); // => Don't forget to update this file !! |
---|
| 17 | include_once('gmaps_root.class.inc.php'); |
---|
| 18 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); |
---|
[7386] | 19 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); |
---|
[7054] | 20 | |
---|
| 21 | /* GMaps class for install process */ |
---|
| 22 | class GMaps_Install extends GMaps_root |
---|
| 23 | { |
---|
| 24 | private $tablef; |
---|
| 25 | |
---|
| 26 | public function __construct($prefixeTable, $filelocation) |
---|
| 27 | { |
---|
| 28 | parent::__construct($prefixeTable, $filelocation); |
---|
| 29 | $this->tablef= new GPCTables($this->tables); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | public function __destruct() |
---|
| 33 | { |
---|
| 34 | unset($this->tablef); |
---|
| 35 | parent::__destruct(); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | /* |
---|
| 39 | function for installation process |
---|
| 40 | return true if install process is ok, otherwise false |
---|
| 41 | */ |
---|
| 42 | public function install() |
---|
| 43 | { |
---|
[10915] | 44 | if(!file_exists(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY)) |
---|
[7308] | 45 | { |
---|
[10915] | 46 | mkdir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY, 0755, true); |
---|
[7308] | 47 | } |
---|
| 48 | |
---|
[7054] | 49 | $this->initConfig(); |
---|
| 50 | $this->loadConfig(); |
---|
| 51 | $this->config['installed']=GMAPS_VERSION2; |
---|
| 52 | $this->config['newInstall']='y'; |
---|
| 53 | $this->saveConfig(); |
---|
| 54 | |
---|
| 55 | $tables_def=array( |
---|
[7125] | 56 | "CREATE TABLE `".$this->tables['maps']."` ( |
---|
[7054] | 57 | `id` int(10) unsigned NOT NULL auto_increment, |
---|
| 58 | `name` varchar(80) NOT NULL, |
---|
[7125] | 59 | `displayType` char(2) NOT NULL, |
---|
| 60 | `sizeMode` char(1) NOT NULL, |
---|
[7054] | 61 | `width` int(10) unsigned NOT NULL default '470', |
---|
| 62 | `height` int(10) unsigned NOT NULL default '210', |
---|
| 63 | `zoomLevel` smallint(6) NOT NULL default '4', |
---|
| 64 | `mapType` varchar(9) NOT NULL default 'hybrid', |
---|
| 65 | `mapTypeControl` smallint(6) NOT NULL default '0', |
---|
| 66 | `navigationControl` smallint(6) NOT NULL default '0', |
---|
| 67 | `scaleControl` char(1) NOT NULL default 'y', |
---|
[7177] | 68 | `streetViewControl` char(1) NOT NULL default 'n', |
---|
[7054] | 69 | `style` varchar(512) NOT NULL, |
---|
[7308] | 70 | `zoomLevelMaxActivated` char(1) NOT NULL default 'n', |
---|
[7125] | 71 | PRIMARY KEY (`id`) |
---|
[7054] | 72 | )", |
---|
[7125] | 73 | "CREATE TABLE `".$this->tables['category_maps']."` ( |
---|
[7054] | 74 | `id` int(10) unsigned NOT NULL auto_increment, |
---|
[7125] | 75 | `categoryId` smallint(5) unsigned NOT NULL, |
---|
| 76 | `mapId` int(11) NOT NULL, |
---|
| 77 | `imgSort` smallint(5) unsigned NOT NULL default '0', |
---|
[7054] | 78 | `applySubCat` char(1) NOT NULL default 'y', |
---|
[7132] | 79 | `kmlFileId` int(10) unsigned NOT NULL default '0', |
---|
[7054] | 80 | `kmlFileUrl` varchar(255) NOT NULL, |
---|
[7125] | 81 | `icon` varchar(255) NOT NULL, |
---|
[7139] | 82 | `marker` varchar(255) NOT NULL, |
---|
[7125] | 83 | `title` varchar(200) NOT NULL, |
---|
[7479] | 84 | `forceDisplay` char(1) NOT NULL default 'n', |
---|
[7054] | 85 | PRIMARY KEY (`id`), |
---|
[7125] | 86 | KEY `byCategorie` (`categoryId`,`mapId`) |
---|
| 87 | )", |
---|
| 88 | "CREATE TABLE `".$this->tables['cache']."` ( |
---|
[7616] | 89 | `requestId` mediumint(8) UNSIGNED NOT NULL default '0', |
---|
[7125] | 90 | `imageId` mediumint(8) NOT NULL, |
---|
[7616] | 91 | `latitude` decimal(17,14) NOT NULL default '0', |
---|
| 92 | `longitude` decimal(17,14) NOT NULL default '0', |
---|
| 93 | PRIMARY KEY (`requestId`,`imageId`) |
---|
[7132] | 94 | )", |
---|
[7616] | 95 | "CREATE TABLE `".$this->tables['cache_id']."` ( |
---|
| 96 | `requestId` mediumint(8) UNSIGNED NOT NULL auto_increment, |
---|
| 97 | `userId` smallint(5) NOT NULL, |
---|
| 98 | `date` timestamp NOT NULL default '0000-00-00 00:00:00', |
---|
| 99 | PRIMARY KEY (`requestId`) |
---|
| 100 | )", |
---|
[7132] | 101 | "CREATE TABLE `".$this->tables['kmlfiles']."` ( |
---|
| 102 | `id` int(10) unsigned NOT NULL auto_increment, |
---|
| 103 | `file` varchar(255) NOT NULL, |
---|
| 104 | `name` varchar(255) NOT NULL, |
---|
| 105 | `fileDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, |
---|
| 106 | `fileSize` mediumint(8) unsigned NOT NULL, |
---|
| 107 | PRIMARY KEY (`id`) |
---|
[7054] | 108 | )" |
---|
| 109 | ); |
---|
| 110 | |
---|
| 111 | $tables_def = create_table_add_character_set($tables_def); |
---|
| 112 | $result=$this->tablef->create($tables_def); |
---|
| 113 | unset($tables_def); |
---|
| 114 | |
---|
| 115 | GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED); |
---|
| 116 | return($result); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | /* |
---|
| 121 | function for uninstall process |
---|
| 122 | */ |
---|
| 123 | public function uninstall() |
---|
| 124 | { |
---|
[10915] | 125 | GPCCore::rmDir(dirname(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY)); |
---|
[7054] | 126 | $this->deleteConfig(); |
---|
| 127 | $this->tablef->drop(); |
---|
| 128 | GPCCore::unregister($this->getPluginName()); |
---|
| 129 | return(''); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | public function activate() |
---|
| 133 | { |
---|
| 134 | $this->initConfig(); |
---|
| 135 | $this->loadConfig(); |
---|
| 136 | |
---|
| 137 | /* |
---|
| 138 | * migration code |
---|
| 139 | */ |
---|
| 140 | switch($this->config['installed']) |
---|
| 141 | { |
---|
[7479] | 142 | case '01.00.00': |
---|
[7308] | 143 | $this->updateFrom_010000(); |
---|
[7548] | 144 | case '01.01.00': |
---|
| 145 | $this->updateFrom_010100(); |
---|
[7616] | 146 | case '01.02.00': |
---|
| 147 | case '01.02.01': |
---|
| 148 | case '01.02.02': |
---|
| 149 | $this->updateFrom_010202(); |
---|
[7054] | 150 | default: |
---|
| 151 | // nothing to do... |
---|
| 152 | break; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | $this->config['installed']=GMAPS_VERSION2; |
---|
| 156 | $this->saveConfig(); |
---|
| 157 | |
---|
| 158 | GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED); |
---|
[7128] | 159 | GPCRequestBuilder::register($this->getPluginName(), dirname($this->getFileLocation()).'/gmaps_rb_callback.class.inc.php'); |
---|
[7054] | 160 | return(''); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | public function deactivate() |
---|
| 164 | { |
---|
| 165 | GPCRequestBuilder::unregister($this->getPluginName()); |
---|
| 166 | } |
---|
| 167 | |
---|
[7308] | 168 | |
---|
| 169 | /** |
---|
| 170 | * update from release 1.0.0 |
---|
| 171 | * |
---|
| 172 | * - create the /local/plugins/GMaps/kml directory |
---|
| 173 | * - move kml files from /plugins/GMaps/kml directory to the new directory |
---|
| 174 | * - remove the /plugins/GMaps/kml directory |
---|
| 175 | */ |
---|
| 176 | private function updateFrom_010000() |
---|
| 177 | { |
---|
[10915] | 178 | if(!file_exists(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY)) |
---|
| 179 | mkdir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY, 0755, true); |
---|
[7308] | 180 | |
---|
| 181 | $directory=scandir(GMAPS_PATH.'kml/'); |
---|
| 182 | foreach($directory as $file) |
---|
| 183 | { |
---|
| 184 | $ext=(pathinfo($file, PATHINFO_EXTENSION)); |
---|
| 185 | if(preg_match('/.*(?:\.kml|\.kmz)$/i', $file)) |
---|
| 186 | { |
---|
[10915] | 187 | rename(GMAPS_PATH.'kml/'.$file, GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY.$file); |
---|
[7308] | 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
[7386] | 191 | GPCCore::rmDir(GMAPS_PATH.'kml'); |
---|
[7308] | 192 | |
---|
| 193 | $tablesUpdate=array( |
---|
[7386] | 194 | $this->tables['maps'] => array( |
---|
[7308] | 195 | 'zoomLevelMaxActivated' => " ADD COLUMN `zoomLevelMaxActivated` CHAR(1) NOT NULL DEFAULT 'n' AFTER `style` ", |
---|
| 196 | ) |
---|
| 197 | ); |
---|
| 198 | |
---|
| 199 | $tablef=new GPCTables(array($this->tables['maps'])); |
---|
| 200 | $tablef->updateTablesFields($tablesUpdate); |
---|
| 201 | |
---|
| 202 | unset($tablesUpdate); |
---|
| 203 | } |
---|
| 204 | |
---|
[7479] | 205 | /** |
---|
[7548] | 206 | * update from release 1.1.0 |
---|
[7479] | 207 | * |
---|
| 208 | */ |
---|
[7548] | 209 | private function updateFrom_010100() |
---|
[7479] | 210 | { |
---|
| 211 | |
---|
| 212 | $tablesUpdate=array( |
---|
| 213 | $this->tables['category_maps'] => array( |
---|
| 214 | 'forceDisplay' => " ADD COLUMN `forceDisplay` CHAR(1) NOT NULL DEFAULT 'n' AFTER `title` ", |
---|
| 215 | ) |
---|
| 216 | ); |
---|
| 217 | |
---|
| 218 | $tablef=new GPCTables(array($this->tables['category_maps'])); |
---|
| 219 | $tablef->updateTablesFields($tablesUpdate); |
---|
| 220 | |
---|
| 221 | unset($tablesUpdate); |
---|
| 222 | } |
---|
| 223 | |
---|
[7616] | 224 | /** |
---|
| 225 | * update from release 1.2.2 |
---|
| 226 | * |
---|
| 227 | */ |
---|
| 228 | private function updateFrom_010202() |
---|
| 229 | { |
---|
| 230 | $sql="DROP TABLE ".$this->tables['cache']; |
---|
| 231 | pwg_query($sql); |
---|
[7479] | 232 | |
---|
[7616] | 233 | $tablesCreate=array( |
---|
| 234 | "CREATE TABLE `".$this->tables['cache']."` ( |
---|
[7619] | 235 | `requestId` mediumint(8) UNSIGNED NOT NULL default '0', |
---|
[7616] | 236 | `imageId` mediumint(8) NOT NULL, |
---|
| 237 | `latitude` decimal(17,14) NOT NULL default '0', |
---|
| 238 | `longitude` decimal(17,14) NOT NULL default '0', |
---|
| 239 | PRIMARY KEY (`requestId`,`imageId`) |
---|
[7619] | 240 | )", |
---|
[7616] | 241 | "CREATE TABLE `".$this->tables['cache_id']."` ( |
---|
| 242 | `requestId` mediumint(8) UNSIGNED NOT NULL auto_increment, |
---|
| 243 | `userId` smallint(5) NOT NULL, |
---|
[7619] | 244 | `date` timestamp NOT NULL default '0000-00-00 00:00:00', |
---|
[7616] | 245 | PRIMARY KEY (`requestId`) |
---|
| 246 | )" |
---|
| 247 | ); |
---|
[7479] | 248 | |
---|
[7616] | 249 | $tablesDef = create_table_add_character_set($tablesCreate); |
---|
| 250 | |
---|
| 251 | $tablef=new GPCTables(array($this->tables['cache'], $this->tables['cache_id'])); |
---|
| 252 | $tablef->create($tablesCreate); |
---|
| 253 | |
---|
| 254 | unset($tablesCreate); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | |
---|
[7054] | 258 | } //class |
---|
| 259 | |
---|
| 260 | ?> |
---|