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 | --------------------------------------------------------------------------- */ |
---|
13 | |
---|
14 | if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
15 | |
---|
16 | include_once('cstat_root.class.inc.php'); |
---|
17 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); |
---|
18 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
19 | |
---|
20 | class CStat_AIPInstall extends CStat_root |
---|
21 | { |
---|
22 | protected $tabsheet; |
---|
23 | |
---|
24 | public function __construct($prefixeTable, $filelocation) |
---|
25 | { |
---|
26 | parent::__construct($prefixeTable, $filelocation); |
---|
27 | $this->loadConfig(); |
---|
28 | $this->initEvents(); |
---|
29 | |
---|
30 | $this->tabsheet = new tabsheet(); |
---|
31 | $this->tabsheet->add('install', |
---|
32 | l10n('cstat_install'), |
---|
33 | $this->getAdminLink()."-install"); |
---|
34 | } |
---|
35 | |
---|
36 | public function __destruct() |
---|
37 | { |
---|
38 | unset($this->tabsheet); |
---|
39 | parent::__destruct(); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | public function loadCSS() |
---|
44 | { |
---|
45 | parent::loadCSS(); |
---|
46 | GPCCore::addUI('gpcCSS'); |
---|
47 | GPCCore::addHeaderCSS('cstat.css', 'plugins/'.$this->getDirectory().'/'.$this->getPluginNameFiles().".css"); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | /* |
---|
53 | display administration page |
---|
54 | */ |
---|
55 | public function manage() |
---|
56 | { |
---|
57 | global $template; |
---|
58 | |
---|
59 | $this->checkRequest(); |
---|
60 | $this->returnAjaxContent(); |
---|
61 | |
---|
62 | GPCCore::setTemplateToken(); |
---|
63 | |
---|
64 | $template->set_filename('plugin_admin_content', dirname($this->getFileLocation())."/admin/cstat_admin.tpl"); |
---|
65 | |
---|
66 | $this->displayInstallPage(); |
---|
67 | |
---|
68 | $this->tabsheet->select($_GET['tab']); |
---|
69 | $this->tabsheet->assign(); |
---|
70 | $selected_tab=$this->tabsheet->get_selected(); |
---|
71 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
72 | |
---|
73 | $template_plugin["CSTAT_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('cstat_release').CSTAT_VERSION; |
---|
74 | |
---|
75 | $template->assign('plugin', $template_plugin); |
---|
76 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | /* |
---|
81 | return ajax content |
---|
82 | */ |
---|
83 | protected function returnAjaxContent() |
---|
84 | { |
---|
85 | global $ajax, $template; |
---|
86 | |
---|
87 | if(isset($_REQUEST['ajaxfct'])) |
---|
88 | { |
---|
89 | //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']); |
---|
90 | $result="<p class='errors'>An error has occured</p>"; |
---|
91 | switch($_REQUEST['ajaxfct']) |
---|
92 | { |
---|
93 | case 'installProcess': |
---|
94 | $result=$this->ajax_installProcess($_REQUEST['tableSize']); |
---|
95 | break; |
---|
96 | } |
---|
97 | GPCAjax::returnResult($result); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * check the $_REQUEST values and set default values |
---|
103 | * |
---|
104 | */ |
---|
105 | protected function checkRequest() |
---|
106 | { |
---|
107 | $_GET['tab']='install'; |
---|
108 | |
---|
109 | if(isset($_REQUEST['ajaxfct'])) |
---|
110 | { |
---|
111 | if($_REQUEST['ajaxfct']=='installProcess') |
---|
112 | { |
---|
113 | if(!isset($_REQUEST['tableSize'])) $_REQUEST['tableSize']='small'; |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | /** |
---|
120 | * display config page |
---|
121 | */ |
---|
122 | protected function displayInstallPage() |
---|
123 | { |
---|
124 | global $template, $lang; |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | $template->set_filename('body_page', |
---|
129 | dirname($this->getFileLocation()).'/admin/cstat_install_page.tpl'); |
---|
130 | |
---|
131 | $smallColorTable=ColorStat::getColorTable(CStat_root::$colorTableSize['small'][0],CStat_root::$colorTableSize['small'][1]); |
---|
132 | $largeColorTable=ColorStat::getColorTable(CStat_root::$colorTableSize['large'][0],CStat_root::$colorTableSize['large'][1]); |
---|
133 | $template->assign('smallTableColor', CStat_functions::htmlColorTable($smallColorTable, 19, '', 'color0px')); |
---|
134 | $template->assign('largeTableColor', CStat_functions::htmlColorTable($largeColorTable, 10, '', 'color0px')); |
---|
135 | |
---|
136 | $template->assign( |
---|
137 | 'smallColorList1', |
---|
138 | CStat_functions::htmlColorList( |
---|
139 | ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample1.png', $smallColorTable, Array('quality' => 8, 'numColors' => 16)), |
---|
140 | 16, 18, '', 'colorListSample color0px' |
---|
141 | ) |
---|
142 | ); |
---|
143 | $pps=ColorStat::$fileColorsStat['pps']; |
---|
144 | |
---|
145 | $template->assign( |
---|
146 | 'largeColorList1', |
---|
147 | CStat_functions::htmlColorList( |
---|
148 | ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample1.png', $largeColorTable, Array('quality' => 8, 'numColors' => 16)), |
---|
149 | 16, 18, '', 'colorListSample color0px' |
---|
150 | ) |
---|
151 | ); |
---|
152 | $pps+=ColorStat::$fileColorsStat['pps']; |
---|
153 | |
---|
154 | $template->assign( |
---|
155 | 'smallColorList2', |
---|
156 | CStat_functions::htmlColorList( |
---|
157 | ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample2.png', $smallColorTable, Array('quality' => 8, 'numColors' => 16)), |
---|
158 | 16, 18, '', 'colorListSample color0px' |
---|
159 | ) |
---|
160 | ); |
---|
161 | $pps+=ColorStat::$fileColorsStat['pps']; |
---|
162 | |
---|
163 | $template->assign( |
---|
164 | 'largeColorList2', |
---|
165 | CStat_functions::htmlColorList( |
---|
166 | ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample2.png', $largeColorTable, Array('quality' => 8, 'numColors' => 16)), |
---|
167 | 16, 18, '', 'colorListSample color0px' |
---|
168 | ) |
---|
169 | ); |
---|
170 | $pps+=ColorStat::$fileColorsStat['pps']; |
---|
171 | |
---|
172 | unset($smallColorTable); |
---|
173 | unset($largeColorTable); |
---|
174 | |
---|
175 | $this->config['analyze_pps']=round($pps/4,0); |
---|
176 | $this->saveConfig(); |
---|
177 | |
---|
178 | $template->assign('urlRequest', $this->getAdminLink()); |
---|
179 | $template->assign('help', |
---|
180 | Array( |
---|
181 | 'SmallColorTable' => GPCCore::BBtoHTML(l10n('cstat_help_small_color_table')), |
---|
182 | 'LargeColorTable' => GPCCore::BBtoHTML(l10n('cstat_help_large_color_table')), |
---|
183 | 'Step1' => GPCCore::BBtoHTML(l10n('cstat_step_1_help')), |
---|
184 | |
---|
185 | ) |
---|
186 | ); |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | $template->assign_var_from_handle('CSTAT_BODY_PAGE', 'body_page'); |
---|
191 | } //displayInstallPage |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | /* --------------------------------------------------------------------------- |
---|
197 | function to manage database manipulation |
---|
198 | --------------------------------------------------------------------------- */ |
---|
199 | |
---|
200 | |
---|
201 | /* --------------------------------------------------------------------------- |
---|
202 | ajax functions |
---|
203 | --------------------------------------------------------------------------- */ |
---|
204 | protected function ajax_installProcess($tableSize) |
---|
205 | { |
---|
206 | $this->config['newInstall']='n'; |
---|
207 | $this->config['analyze_colorTable']=$tableSize; |
---|
208 | $this->saveConfig(); |
---|
209 | |
---|
210 | $colorTable=ColorStat::getColorTable(CStat_root::$colorTableSize[$tableSize][0],CStat_root::$colorTableSize[$tableSize][1]); |
---|
211 | |
---|
212 | foreach($colorTable as $key => $hue) |
---|
213 | { |
---|
214 | foreach($hue as $key2 => $saturation) |
---|
215 | { |
---|
216 | foreach($saturation as $key3=>$value) |
---|
217 | { |
---|
218 | $hsv=$value->get(); |
---|
219 | $sql.=(($sql=="")?"":", ")."('".$value->getRGB()->getHexString()."', |
---|
220 | '".$hsv['H']."', |
---|
221 | '".$hsv['S']."', |
---|
222 | '".$hsv['V']."', |
---|
223 | 0, 0)"; |
---|
224 | } |
---|
225 | } |
---|
226 | } |
---|
227 | $sql="REPLACE INTO ".$this->tables['color_table']." |
---|
228 | VALUES ".$sql; |
---|
229 | pwg_query($sql); |
---|
230 | return("OK"); |
---|
231 | } |
---|
232 | |
---|
233 | } //class |
---|
234 | |
---|
235 | |
---|
236 | ?> |
---|