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