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_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 | |
---|
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', |
---|
83 | `colors` char(111) NOT NULL default '', |
---|
84 | `colors_pct` char(111) NOT NULL default '', |
---|
85 | PRIMARY KEY (`image_id`), |
---|
86 | KEY `by_analyzed` (`analyzed`) |
---|
87 | )", |
---|
88 | ); |
---|
89 | |
---|
90 | $result=$this->tablef->create($tables_def); |
---|
91 | |
---|
92 | GPCCore::register($this->getPluginName(), CSTAT_VERSION, CSTAT_GPC_NEEDED); |
---|
93 | |
---|
94 | return($result); |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | /* |
---|
99 | function for uninstall process |
---|
100 | */ |
---|
101 | public function uninstall() |
---|
102 | { |
---|
103 | GPCCore::unregister($this->getPluginName()); |
---|
104 | |
---|
105 | $this->deleteConfig(); |
---|
106 | $this->tablef->drop(); |
---|
107 | return(''); |
---|
108 | } |
---|
109 | |
---|
110 | public function activate() |
---|
111 | { |
---|
112 | global $template; |
---|
113 | |
---|
114 | $this->initConfig(); |
---|
115 | $this->loadConfig(); |
---|
116 | $this->config['installed']=CSTAT_VERSION2; |
---|
117 | $this->saveConfig(); |
---|
118 | |
---|
119 | /* |
---|
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']." |
---|
131 | SELECT id, 'n', 0, 0, 0, 0, 0, 0, '', '' |
---|
132 | FROM ".IMAGES_TABLE." |
---|
133 | WHERE id NOT IN (SELECT image_id FROM ".$this->tables['images'].")"); |
---|
134 | */ |
---|
135 | |
---|
136 | GPCCore::register($this->getPluginName(), CSTAT_VERSION, CSTAT_GPC_NEEDED); |
---|
137 | GPCRequestBuilder::register($this->getPluginName(), dirname($this->getFileLocation()).'/cstat_rb_callback.class.inc.php'); |
---|
138 | |
---|
139 | return(''); |
---|
140 | } |
---|
141 | |
---|
142 | public function deactivate() |
---|
143 | { |
---|
144 | GPCRequestBuilder::unregister($this->getPluginName()); |
---|
145 | } |
---|
146 | |
---|
147 | } //class |
---|
148 | |
---|
149 | ?> |
---|