[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 | --------------------------------------------------------------------------- */ |
---|
| 13 | |
---|
[6107] | 14 | if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 15 | |
---|
[5961] | 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'), |
---|
[15344] | 33 | $this->getAdminLink()."-install"); |
---|
[5961] | 34 | } |
---|
| 35 | |
---|
| 36 | public function __destruct() |
---|
| 37 | { |
---|
| 38 | unset($this->tabsheet); |
---|
| 39 | parent::__destruct(); |
---|
| 40 | } |
---|
| 41 | |
---|
[16464] | 42 | |
---|
| 43 | public function loadCSS() |
---|
[5961] | 44 | { |
---|
[16464] | 45 | parent::loadCSS(); |
---|
| 46 | GPCCore::addUI('gpcCSS'); |
---|
| 47 | GPCCore::addHeaderCSS('cstat.css', 'plugins/'.$this->getDirectory().'/'.$this->getPluginNameFiles().".css"); |
---|
[5961] | 48 | } |
---|
| 49 | |
---|
[16464] | 50 | |
---|
| 51 | |
---|
[5961] | 52 | /* |
---|
| 53 | display administration page |
---|
| 54 | */ |
---|
| 55 | public function manage() |
---|
| 56 | { |
---|
| 57 | global $template; |
---|
| 58 | |
---|
| 59 | $this->checkRequest(); |
---|
| 60 | $this->returnAjaxContent(); |
---|
| 61 | |
---|
[16464] | 62 | GPCCore::setTemplateToken(); |
---|
| 63 | |
---|
[5961] | 64 | $template->set_filename('plugin_admin_content', dirname($this->getFileLocation())."/admin/cstat_admin.tpl"); |
---|
| 65 | |
---|
| 66 | $this->displayInstallPage(); |
---|
| 67 | |
---|
[15344] | 68 | $this->tabsheet->select($_GET['tab']); |
---|
[5961] | 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 | { |
---|
[15344] | 107 | $_GET['tab']='install'; |
---|
[5961] | 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 | |
---|
[6176] | 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')); |
---|
[5961] | 135 | |
---|
| 136 | $template->assign( |
---|
| 137 | 'smallColorList1', |
---|
[6176] | 138 | CStat_functions::htmlColorList( |
---|
[5961] | 139 | ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample1.png', $smallColorTable, Array('quality' => 8, 'numColors' => 16)), |
---|
[6107] | 140 | 16, 18, '', 'colorListSample color0px' |
---|
[5961] | 141 | ) |
---|
| 142 | ); |
---|
| 143 | $pps=ColorStat::$fileColorsStat['pps']; |
---|
| 144 | |
---|
| 145 | $template->assign( |
---|
| 146 | 'largeColorList1', |
---|
[6176] | 147 | CStat_functions::htmlColorList( |
---|
[5961] | 148 | ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample1.png', $largeColorTable, Array('quality' => 8, 'numColors' => 16)), |
---|
[6107] | 149 | 16, 18, '', 'colorListSample color0px' |
---|
[5961] | 150 | ) |
---|
| 151 | ); |
---|
| 152 | $pps+=ColorStat::$fileColorsStat['pps']; |
---|
| 153 | |
---|
| 154 | $template->assign( |
---|
| 155 | 'smallColorList2', |
---|
[6176] | 156 | CStat_functions::htmlColorList( |
---|
[5961] | 157 | ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample2.png', $smallColorTable, Array('quality' => 8, 'numColors' => 16)), |
---|
[6107] | 158 | 16, 18, '', 'colorListSample color0px' |
---|
[5961] | 159 | ) |
---|
| 160 | ); |
---|
| 161 | $pps+=ColorStat::$fileColorsStat['pps']; |
---|
| 162 | |
---|
| 163 | $template->assign( |
---|
| 164 | 'largeColorList2', |
---|
[6176] | 165 | CStat_functions::htmlColorList( |
---|
[5961] | 166 | ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample2.png', $largeColorTable, Array('quality' => 8, 'numColors' => 16)), |
---|
[6107] | 167 | 16, 18, '', 'colorListSample color0px' |
---|
[5961] | 168 | ) |
---|
| 169 | ); |
---|
| 170 | $pps+=ColorStat::$fileColorsStat['pps']; |
---|
| 171 | |
---|
| 172 | unset($smallColorTable); |
---|
| 173 | unset($largeColorTable); |
---|
| 174 | |
---|
[6107] | 175 | $this->config['analyze_pps']=round($pps/4,0); |
---|
[5961] | 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'; |
---|
[6107] | 207 | $this->config['analyze_colorTable']=$tableSize; |
---|
[5961] | 208 | $this->saveConfig(); |
---|
| 209 | |
---|
[6176] | 210 | $colorTable=ColorStat::getColorTable(CStat_root::$colorTableSize[$tableSize][0],CStat_root::$colorTableSize[$tableSize][1]); |
---|
[5961] | 211 | |
---|
[6176] | 212 | foreach($colorTable as $key => $hue) |
---|
[5961] | 213 | { |
---|
[6176] | 214 | foreach($hue as $key2 => $saturation) |
---|
[5961] | 215 | { |
---|
[6176] | 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 | } |
---|
[5961] | 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 | ?> |
---|