[5961] | 1 | <?php |
---|
| 2 | /* ----------------------------------------------------------------------------- |
---|
| 3 | Plugin : ColorStat |
---|
| 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 | CStat_Install : classe to manage plugin install |
---|
| 13 | |
---|
| 14 | --------------------------------------------------------------------------- */ |
---|
| 15 | |
---|
[6107] | 16 | if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[5961] | 17 | |
---|
[6107] | 18 | include_once('cstat_root.class.inc.php'); |
---|
| 19 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); |
---|
| 20 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); |
---|
| 21 | |
---|
[5961] | 22 | /* CStat class for install process */ |
---|
| 23 | class CStat_Install extends CStat_root |
---|
| 24 | { |
---|
| 25 | private $tablef; |
---|
| 26 | |
---|
| 27 | public function __construct($prefixeTable, $filelocation) |
---|
| 28 | { |
---|
| 29 | parent::__construct($prefixeTable, $filelocation); |
---|
| 30 | $this->tablef= new GPCTables($this->tables); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | public function __destruct() |
---|
| 34 | { |
---|
| 35 | unset($this->tablef); |
---|
| 36 | parent::__destruct(); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | function for installation process |
---|
| 41 | return true if install process is ok, otherwise false |
---|
| 42 | */ |
---|
| 43 | public function install() |
---|
| 44 | { |
---|
| 45 | $this->initConfig(); |
---|
| 46 | $this->loadConfig(); |
---|
| 47 | $this->config['installed']=CSTAT_VERSION2; |
---|
| 48 | $this->config['newInstall']='y'; |
---|
| 49 | $this->saveConfig(); |
---|
| 50 | |
---|
| 51 | $tables_def=array( |
---|
| 52 | "CREATE TABLE `".$this->tables['color_table']."` ( |
---|
| 53 | `color_id` CHAR(6) NOT NULL DEFAULT 000000, |
---|
| 54 | `hue` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 55 | `saturation` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 56 | `value` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 57 | `num_images` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 58 | `num_pixels` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 59 | PRIMARY KEY (`color_id`), |
---|
| 60 | INDEX `hue`(`hue`) |
---|
| 61 | ) |
---|
| 62 | CHARACTER SET utf8 COLLATE utf8_general_ci", |
---|
| 63 | |
---|
| 64 | "CREATE TABLE `".$this->tables['images_colors']."` ( |
---|
| 65 | `image_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0, |
---|
| 66 | `color_id` CHAR(6) NOT NULL DEFAULT 000000, |
---|
| 67 | `pct` float unsigned NOT NULL default '0', |
---|
| 68 | `num_pixels` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 69 | PRIMARY KEY (`image_id`, `color_id`), |
---|
| 70 | KEY `by_color` (`pct`,`color_id`) |
---|
| 71 | ) |
---|
| 72 | CHARACTER SET utf8 COLLATE utf8_general_ci", |
---|
| 73 | |
---|
| 74 | "CREATE TABLE `".$this->tables['images']."` ( |
---|
| 75 | `image_id` mediumint(8) unsigned NOT NULL, |
---|
| 76 | `analyzed` char(1) NOT NULL default 'n', |
---|
| 77 | `num_colors` int(10) unsigned NOT NULL default '0', |
---|
| 78 | `num_pixels` int(10) unsigned NOT NULL default '0', |
---|
| 79 | `analyzed_pixels` int(10) unsigned NOT NULL default '0', |
---|
| 80 | `pps` int(10) unsigned NOT NULL default '0', |
---|
| 81 | `time` float unsigned NOT NULL default '0', |
---|
| 82 | `quality` tinyint(4) NOT NULL default '0', |
---|
[6107] | 83 | `colors` char(111) NOT NULL default '', |
---|
| 84 | `colors_pct` char(111) NOT NULL default '', |
---|
[5961] | 85 | PRIMARY KEY (`image_id`), |
---|
| 86 | KEY `by_analyzed` (`analyzed`) |
---|
| 87 | )", |
---|
| 88 | ); |
---|
| 89 | |
---|
| 90 | $result=$this->tablef->create($tables_def); |
---|
[6976] | 91 | |
---|
| 92 | GPCCore::register($this->getPluginName(), CSTAT_VERSION, CSTAT_GPC_NEEDED); |
---|
| 93 | |
---|
[5961] | 94 | return($result); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | /* |
---|
| 99 | function for uninstall process |
---|
| 100 | */ |
---|
| 101 | public function uninstall() |
---|
| 102 | { |
---|
[6976] | 103 | GPCCore::unregister($this->getPluginName()); |
---|
| 104 | |
---|
[5961] | 105 | $this->deleteConfig(); |
---|
| 106 | $this->tablef->drop(); |
---|
| 107 | return(''); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | public function activate() |
---|
| 111 | { |
---|
| 112 | global $template; |
---|
| 113 | |
---|
| 114 | $this->initConfig(); |
---|
[6976] | 115 | $this->loadConfig(); |
---|
[5961] | 116 | $this->config['installed']=CSTAT_VERSION2; |
---|
| 117 | $this->saveConfig(); |
---|
[8543] | 118 | |
---|
| 119 | /* |
---|
[5961] | 120 | pwg_query("DELETE FROM ".$this->tables['color_table']); |
---|
| 121 | pwg_query("DELETE FROM ".$this->tables['images_colors']); |
---|
| 122 | pwg_query("UPDATE ".$this->tables['images']." |
---|
| 123 | SET analyzed='n', |
---|
| 124 | num_colors=0, |
---|
| 125 | num_pixels=0, |
---|
| 126 | analyzed_pixels=0, |
---|
| 127 | pps=0, |
---|
| 128 | time=0, |
---|
| 129 | quality=0;"); |
---|
| 130 | pwg_query("INSERT INTO ".$this->tables['images']." |
---|
[6176] | 131 | SELECT id, 'n', 0, 0, 0, 0, 0, 0, '', '' |
---|
[5961] | 132 | FROM ".IMAGES_TABLE." |
---|
| 133 | WHERE id NOT IN (SELECT image_id FROM ".$this->tables['images'].")"); |
---|
[8544] | 134 | */ |
---|
[8543] | 135 | |
---|
[6976] | 136 | GPCCore::register($this->getPluginName(), CSTAT_VERSION, CSTAT_GPC_NEEDED); |
---|
| 137 | GPCRequestBuilder::register($this->getPluginName(), dirname($this->getFileLocation()).'/cstat_rb_callback.class.inc.php'); |
---|
[5961] | 138 | |
---|
| 139 | return(''); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | public function deactivate() |
---|
| 143 | { |
---|
[6976] | 144 | GPCRequestBuilder::unregister($this->getPluginName()); |
---|
[5961] | 145 | } |
---|
| 146 | |
---|
| 147 | } //class |
---|
| 148 | |
---|
| 149 | ?> |
---|