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