| 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'); |
|---|
| 19 | |
|---|
| 20 | /* GMaps class for install process */ |
|---|
| 21 | class GMaps_Install extends GMaps_root |
|---|
| 22 | { |
|---|
| 23 | private $tablef; |
|---|
| 24 | |
|---|
| 25 | public function __construct($prefixeTable, $filelocation) |
|---|
| 26 | { |
|---|
| 27 | parent::__construct($prefixeTable, $filelocation); |
|---|
| 28 | $this->tablef= new GPCTables($this->tables); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | public function __destruct() |
|---|
| 32 | { |
|---|
| 33 | unset($this->tablef); |
|---|
| 34 | parent::__destruct(); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | /* |
|---|
| 38 | function for installation process |
|---|
| 39 | return true if install process is ok, otherwise false |
|---|
| 40 | */ |
|---|
| 41 | public function install() |
|---|
| 42 | { |
|---|
| 43 | if(!file_exists(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY)) |
|---|
| 44 | { |
|---|
| 45 | mkdir(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY, 0755, true); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | $this->initConfig(); |
|---|
| 49 | $this->loadConfig(); |
|---|
| 50 | $this->config['installed']=GMAPS_VERSION2; |
|---|
| 51 | $this->config['newInstall']='y'; |
|---|
| 52 | $this->saveConfig(); |
|---|
| 53 | |
|---|
| 54 | $tables_def=array( |
|---|
| 55 | "CREATE TABLE `".$this->tables['maps']."` ( |
|---|
| 56 | `id` int(10) unsigned NOT NULL auto_increment, |
|---|
| 57 | `name` varchar(80) NOT NULL, |
|---|
| 58 | `displayType` char(2) NOT NULL, |
|---|
| 59 | `sizeMode` char(1) NOT NULL, |
|---|
| 60 | `width` int(10) unsigned NOT NULL default '470', |
|---|
| 61 | `height` int(10) unsigned NOT NULL default '210', |
|---|
| 62 | `zoomLevel` smallint(6) NOT NULL default '4', |
|---|
| 63 | `mapType` varchar(9) NOT NULL default 'hybrid', |
|---|
| 64 | `mapTypeControl` smallint(6) NOT NULL default '0', |
|---|
| 65 | `navigationControl` smallint(6) NOT NULL default '0', |
|---|
| 66 | `scaleControl` char(1) NOT NULL default 'y', |
|---|
| 67 | `streetViewControl` char(1) NOT NULL default 'n', |
|---|
| 68 | `style` varchar(512) NOT NULL, |
|---|
| 69 | `zoomLevelMaxActivated` char(1) NOT NULL default 'n', |
|---|
| 70 | PRIMARY KEY (`id`) |
|---|
| 71 | )", |
|---|
| 72 | "CREATE TABLE `".$this->tables['category_maps']."` ( |
|---|
| 73 | `id` int(10) unsigned NOT NULL auto_increment, |
|---|
| 74 | `categoryId` smallint(5) unsigned NOT NULL, |
|---|
| 75 | `mapId` int(11) NOT NULL, |
|---|
| 76 | `imgSort` smallint(5) unsigned NOT NULL default '0', |
|---|
| 77 | `applySubCat` char(1) NOT NULL default 'y', |
|---|
| 78 | `kmlFileId` int(10) unsigned NOT NULL default '0', |
|---|
| 79 | `kmlFileUrl` varchar(255) NOT NULL, |
|---|
| 80 | `icon` varchar(255) NOT NULL, |
|---|
| 81 | `marker` varchar(255) NOT NULL, |
|---|
| 82 | `title` varchar(200) NOT NULL, |
|---|
| 83 | PRIMARY KEY (`id`), |
|---|
| 84 | KEY `byCategorie` (`categoryId`,`mapId`) |
|---|
| 85 | )", |
|---|
| 86 | "CREATE TABLE `".$this->tables['cache']."` ( |
|---|
| 87 | `userId` smallint(5) NOT NULL, |
|---|
| 88 | `requestId` timestamp NOT NULL default '0000-00-00 00:00:00', |
|---|
| 89 | `imageId` mediumint(8) NOT NULL, |
|---|
| 90 | `latitude` decimal(20,17) NOT NULL default '0.00000000000000000', |
|---|
| 91 | `longitude` decimal(20,17) NOT NULL default '0.00000000000000000', |
|---|
| 92 | `imageName` varchar(255) NOT NULL, |
|---|
| 93 | `imageTnFile` varchar(255) NOT NULL, |
|---|
| 94 | `imageCatsId` varchar(255) NOT NULL, |
|---|
| 95 | `imageCatsNames` varchar(255) NOT NULL, |
|---|
| 96 | `imageCatsPLink` varchar(255) NOT NULL, |
|---|
| 97 | PRIMARY KEY USING BTREE (`userId`,`requestId`,`imageId`) |
|---|
| 98 | )", |
|---|
| 99 | "CREATE TABLE `".$this->tables['kmlfiles']."` ( |
|---|
| 100 | `id` int(10) unsigned NOT NULL auto_increment, |
|---|
| 101 | `file` varchar(255) NOT NULL, |
|---|
| 102 | `name` varchar(255) NOT NULL, |
|---|
| 103 | `fileDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, |
|---|
| 104 | `fileSize` mediumint(8) unsigned NOT NULL, |
|---|
| 105 | PRIMARY KEY (`id`) |
|---|
| 106 | )" |
|---|
| 107 | ); |
|---|
| 108 | |
|---|
| 109 | $tables_def = create_table_add_character_set($tables_def); |
|---|
| 110 | $result=$this->tablef->create($tables_def); |
|---|
| 111 | unset($tables_def); |
|---|
| 112 | |
|---|
| 113 | GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED); |
|---|
| 114 | return($result); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | /* |
|---|
| 119 | function for uninstall process |
|---|
| 120 | */ |
|---|
| 121 | public function uninstall() |
|---|
| 122 | { |
|---|
| 123 | $this->deleteConfig(); |
|---|
| 124 | $this->tablef->drop(); |
|---|
| 125 | GPCCore::unregister($this->getPluginName()); |
|---|
| 126 | return(''); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | public function activate() |
|---|
| 130 | { |
|---|
| 131 | $this->initConfig(); |
|---|
| 132 | $this->loadConfig(); |
|---|
| 133 | |
|---|
| 134 | /* |
|---|
| 135 | * migration code |
|---|
| 136 | */ |
|---|
| 137 | switch($this->config['installed']) |
|---|
| 138 | { |
|---|
| 139 | case '01.00.00'; |
|---|
| 140 | $this->updateFrom_010000(); |
|---|
| 141 | default: |
|---|
| 142 | // nothing to do... |
|---|
| 143 | break; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | $this->config['installed']=GMAPS_VERSION2; |
|---|
| 147 | $this->saveConfig(); |
|---|
| 148 | |
|---|
| 149 | GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED); |
|---|
| 150 | GPCRequestBuilder::register($this->getPluginName(), dirname($this->getFileLocation()).'/gmaps_rb_callback.class.inc.php'); |
|---|
| 151 | return(''); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | public function deactivate() |
|---|
| 155 | { |
|---|
| 156 | GPCRequestBuilder::unregister($this->getPluginName()); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | /** |
|---|
| 161 | * update from release 1.0.0 |
|---|
| 162 | * |
|---|
| 163 | * - create the /local/plugins/GMaps/kml directory |
|---|
| 164 | * - move kml files from /plugins/GMaps/kml directory to the new directory |
|---|
| 165 | * - remove the /plugins/GMaps/kml directory |
|---|
| 166 | */ |
|---|
| 167 | private function updateFrom_010000() |
|---|
| 168 | { |
|---|
| 169 | mkdir(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY, 0755, true); |
|---|
| 170 | |
|---|
| 171 | $directory=scandir(GMAPS_PATH.'kml/'); |
|---|
| 172 | foreach($directory as $file) |
|---|
| 173 | { |
|---|
| 174 | $ext=(pathinfo($file, PATHINFO_EXTENSION)); |
|---|
| 175 | if(preg_match('/.*(?:\.kml|\.kmz)$/i', $file)) |
|---|
| 176 | { |
|---|
| 177 | rename(GMAPS_PATH.'kml/'.$file, GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file); |
|---|
| 178 | } |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | mkdir(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY); |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | $tablesUpdate=array( |
|---|
| 185 | $this->tables['images_tags'] => array( |
|---|
| 186 | 'zoomLevelMaxActivated' => " ADD COLUMN `zoomLevelMaxActivated` CHAR(1) NOT NULL DEFAULT 'n' AFTER `style` ", |
|---|
| 187 | ) |
|---|
| 188 | ); |
|---|
| 189 | |
|---|
| 190 | $tablef=new GPCTables(array($this->tables['maps'])); |
|---|
| 191 | $tablef->updateTablesFields($tablesUpdate); |
|---|
| 192 | |
|---|
| 193 | unset($tablesUpdate); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | } //class |
|---|
| 197 | |
|---|
| 198 | ?> |
|---|