> ------------------------------------------------------------------------------ See main.inc.php for release information GMaps_Install : classe to manage plugin install --------------------------------------------------------------------------- */ include_once('gmaps_version.inc.php'); // => Don't forget to update this file !! include_once('gmaps_root.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); /* GMaps class for install process */ class GMaps_Install extends GMaps_root { private $tablef; public function __construct($prefixeTable, $filelocation) { parent::__construct($prefixeTable, $filelocation); $this->tablef= new GPCTables($this->tables); } public function __destruct() { unset($this->tablef); parent::__destruct(); } /* function for installation process return true if install process is ok, otherwise false */ public function install() { if(!file_exists(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY)) { mkdir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY, 0755, true); } $this->initConfig(); $this->loadConfig(); $this->config['installed']=GMAPS_VERSION2; $this->config['newInstall']='y'; $this->saveConfig(); $tables_def=array( "CREATE TABLE `".$this->tables['maps']."` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(80) NOT NULL, `displayType` char(2) NOT NULL, `sizeMode` char(1) NOT NULL, `width` int(10) unsigned NOT NULL default '470', `height` int(10) unsigned NOT NULL default '210', `zoomLevel` smallint(6) NOT NULL default '4', `mapType` varchar(9) NOT NULL default 'hybrid', `mapTypeControl` smallint(6) NOT NULL default '0', `navigationControl` smallint(6) NOT NULL default '0', `scaleControl` char(1) NOT NULL default 'y', `streetViewControl` char(1) NOT NULL default 'n', `style` varchar(512) NOT NULL, `zoomLevelMaxActivated` char(1) NOT NULL default 'n', PRIMARY KEY (`id`) )", "CREATE TABLE `".$this->tables['category_maps']."` ( `id` int(10) unsigned NOT NULL auto_increment, `categoryId` smallint(5) unsigned NOT NULL, `mapId` int(11) NOT NULL, `imgSort` smallint(5) unsigned NOT NULL default '0', `applySubCat` char(1) NOT NULL default 'y', `kmlFileId` int(10) unsigned NOT NULL default '0', `kmlFileUrl` varchar(255) NOT NULL, `icon` varchar(255) NOT NULL, `marker` varchar(255) NOT NULL, `title` varchar(200) NOT NULL, `forceDisplay` char(1) NOT NULL default 'n', PRIMARY KEY (`id`), KEY `byCategorie` (`categoryId`,`mapId`) )", "CREATE TABLE `".$this->tables['cache']."` ( `requestId` mediumint(8) UNSIGNED NOT NULL default '0', `imageId` mediumint(8) NOT NULL, `latitude` decimal(17,14) NOT NULL default '0', `longitude` decimal(17,14) NOT NULL default '0', PRIMARY KEY (`requestId`,`imageId`) )", "CREATE TABLE `".$this->tables['cache_id']."` ( `requestId` mediumint(8) UNSIGNED NOT NULL auto_increment, `userId` smallint(5) NOT NULL, `date` timestamp NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`requestId`) )", "CREATE TABLE `".$this->tables['kmlfiles']."` ( `id` int(10) unsigned NOT NULL auto_increment, `file` varchar(255) NOT NULL, `name` varchar(255) NOT NULL, `fileDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `fileSize` mediumint(8) unsigned NOT NULL, PRIMARY KEY (`id`) )" ); $tables_def = create_table_add_character_set($tables_def); $result=$this->tablef->create($tables_def); unset($tables_def); GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED); return($result); } /* function for uninstall process */ public function uninstall() { GPCCore::rmDir(dirname(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY)); $this->deleteConfig(); $this->tablef->drop(); GPCCore::unregister($this->getPluginName()); return(''); } public function activate() { $this->initConfig(); $this->loadConfig(); /* * migration code */ switch($this->config['installed']) { case '01.00.00': $this->updateFrom_010000(); case '01.01.00': $this->updateFrom_010100(); case '01.02.00': case '01.02.01': case '01.02.02': $this->updateFrom_010202(); default: // nothing to do... break; } $this->config['installed']=GMAPS_VERSION2; $this->saveConfig(); GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED); GPCRequestBuilder::register($this->getPluginName(), dirname($this->getFileLocation()).'/gmaps_rb_callback.class.inc.php'); return(''); } public function deactivate() { GPCRequestBuilder::unregister($this->getPluginName()); } /** * update from release 1.0.0 * * - create the /local/plugins/GMaps/kml directory * - move kml files from /plugins/GMaps/kml directory to the new directory * - remove the /plugins/GMaps/kml directory */ private function updateFrom_010000() { if(!file_exists(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY)) mkdir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY, 0755, true); $directory=scandir(GMAPS_PATH.'kml/'); foreach($directory as $file) { $ext=(pathinfo($file, PATHINFO_EXTENSION)); if(preg_match('/.*(?:\.kml|\.kmz)$/i', $file)) { rename(GMAPS_PATH.'kml/'.$file, GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY.$file); } } GPCCore::rmDir(GMAPS_PATH.'kml'); $tablesUpdate=array( $this->tables['maps'] => array( 'zoomLevelMaxActivated' => " ADD COLUMN `zoomLevelMaxActivated` CHAR(1) NOT NULL DEFAULT 'n' AFTER `style` ", ) ); $tablef=new GPCTables(array($this->tables['maps'])); $tablef->updateTablesFields($tablesUpdate); unset($tablesUpdate); } /** * update from release 1.1.0 * */ private function updateFrom_010100() { $tablesUpdate=array( $this->tables['category_maps'] => array( 'forceDisplay' => " ADD COLUMN `forceDisplay` CHAR(1) NOT NULL DEFAULT 'n' AFTER `title` ", ) ); $tablef=new GPCTables(array($this->tables['category_maps'])); $tablef->updateTablesFields($tablesUpdate); unset($tablesUpdate); } /** * update from release 1.2.2 * */ private function updateFrom_010202() { $sql="DROP TABLE ".$this->tables['cache']; pwg_query($sql); $tablesCreate=array( "CREATE TABLE `".$this->tables['cache']."` ( `requestId` mediumint(8) UNSIGNED NOT NULL default '0', `imageId` mediumint(8) NOT NULL, `latitude` decimal(17,14) NOT NULL default '0', `longitude` decimal(17,14) NOT NULL default '0', PRIMARY KEY (`requestId`,`imageId`) )", "CREATE TABLE `".$this->tables['cache_id']."` ( `requestId` mediumint(8) UNSIGNED NOT NULL auto_increment, `userId` smallint(5) NOT NULL, `date` timestamp NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`requestId`) )" ); $tablesDef = create_table_add_character_set($tablesCreate); $tablef=new GPCTables(array($this->tables['cache'], $this->tables['cache_id'])); $tablef->create($tablesCreate); unset($tablesCreate); } } //class ?>