[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 | CStat_root : common classe for admin and public classes |
---|
| 13 | |
---|
| 14 | --------------------------------------------------------------------------- */ |
---|
| 15 | include_once('cstat_colorstat.class.inc.php'); |
---|
| 16 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php'); |
---|
| 17 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCCss.class.inc.php'); |
---|
| 18 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
| 19 | |
---|
| 20 | class CStat_root extends CommonPlugin |
---|
| 21 | { |
---|
| 22 | protected $css; //the css object |
---|
| 23 | protected $colorTableSize=Array('small' => Array(30,20), 'large' => Array(10,10)); |
---|
| 24 | |
---|
| 25 | public function __construct($prefixeTable, $filelocation) |
---|
| 26 | { |
---|
| 27 | $this->setPluginName('ColorStat'); |
---|
| 28 | $this->setPluginNameFiles("cstat"); |
---|
| 29 | parent::__construct($prefixeTable, $filelocation); |
---|
| 30 | $this->section_name=$this->getPluginNameFiles(); |
---|
| 31 | |
---|
| 32 | $this->setTablesList(array('images', 'color_table', 'images_colors')); |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css"); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | public function __destruct() |
---|
| 39 | { |
---|
| 40 | unset($this->css); |
---|
| 41 | parent::__destruct(); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | public function initEvents() |
---|
| 45 | { |
---|
| 46 | parent::initEvents(); |
---|
| 47 | add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') ); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | /* |
---|
| 51 | menu block management |
---|
| 52 | */ |
---|
| 53 | public function register_blocks() |
---|
| 54 | { |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /* |
---|
| 58 | intialize default values |
---|
| 59 | */ |
---|
| 60 | public function initConfig() |
---|
| 61 | { |
---|
| 62 | //global $user; |
---|
| 63 | $this->config=array( |
---|
| 64 | 'newInstall' => 'n', |
---|
| 65 | 'analyze.maxTime' => 0.1, |
---|
| 66 | 'analyze.colorTable' => 'small', |
---|
| 67 | 'analyze.pps' => 0, |
---|
| 68 | 'analyze.itemPerRequest' => 10, |
---|
| 69 | 'display.stat.orderType' => 'img', |
---|
| 70 | ); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * return HTML code for a given colorTable |
---|
| 76 | * |
---|
| 77 | * @param Array $colorTable : a color table, typically made with the |
---|
| 78 | * ColorStat::getColorTable() function |
---|
| 79 | * @param Int $size : size for colorbox in the HTML table |
---|
| 80 | * @return String : HTML code |
---|
| 81 | */ |
---|
| 82 | public function htmlColorTable($colorTable, $size=5, $id="", $class="") |
---|
| 83 | { |
---|
| 84 | global $template; |
---|
| 85 | |
---|
| 86 | $template->set_filename('color_table_page', |
---|
| 87 | dirname($this->getFileLocation()).'/templates/cstat_color_table.tpl'); |
---|
| 88 | |
---|
| 89 | $nbHue=count($colorTable); |
---|
| 90 | $nbStep=count($colorTable[0]); |
---|
| 91 | $colors=Array(); |
---|
| 92 | for($step=0;$step<$nbStep;$step++) |
---|
| 93 | { |
---|
| 94 | $row=Array(); |
---|
| 95 | for($hue=0;$hue<$nbHue;$hue++) |
---|
| 96 | { |
---|
| 97 | |
---|
| 98 | if($colorTable[$hue][$step] instanceof HSV) |
---|
| 99 | { |
---|
| 100 | $row[]=Array('color' => $colorTable[$hue][$step]->getRGB()->getHexString(), 'pct' => "", 'num' => ""); |
---|
| 101 | } |
---|
| 102 | elseif(is_array($colorTable[$hue][$step])) |
---|
| 103 | { |
---|
| 104 | $row[]=Array( |
---|
| 105 | 'color' => (array_key_exists('color', $colorTable[$hue][$step]))?$colorTable[$hue][$step]['color']:"", |
---|
| 106 | 'pct' => (array_key_exists('pct', $colorTable[$hue][$step]))?$colorTable[$hue][$step]['pct']:"", |
---|
| 107 | 'num' => (array_key_exists('num', $colorTable[$hue][$step]))?$colorTable[$hue][$step]['num']:"", |
---|
| 108 | ); |
---|
| 109 | } |
---|
| 110 | else |
---|
| 111 | { |
---|
| 112 | $row[]=Array('color' => $colorTable[$hue][$step], 'pct' => "", 'num' => ""); |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | $colors[]=$row; |
---|
| 116 | unset($row); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | $data=array( |
---|
| 120 | 'colorTable' => $colors, |
---|
| 121 | 'size' => $size, |
---|
| 122 | 'id' => $id, |
---|
| 123 | 'class' => $class |
---|
| 124 | ); |
---|
| 125 | |
---|
| 126 | $template->assign('data', $data); |
---|
| 127 | unset($data); |
---|
| 128 | |
---|
| 129 | return($template->parse('color_table_page', true)); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | * return HTML code for a given colors list |
---|
| 134 | * |
---|
| 135 | * @param Array $colors : list of colors |
---|
| 136 | * @param Int $size : size for colorbox in the HTML table |
---|
| 137 | * @return String : HTML code |
---|
| 138 | */ |
---|
| 139 | public function htmlColorList($colorList, $split=8, $size=5, $id="", $class="") |
---|
| 140 | { |
---|
| 141 | global $template; |
---|
| 142 | |
---|
| 143 | $template->set_filename('color_table_page', |
---|
| 144 | dirname($this->getFileLocation()).'/templates/cstat_color_table.tpl'); |
---|
| 145 | |
---|
| 146 | $colors=Array(); |
---|
| 147 | |
---|
| 148 | $row=0; |
---|
| 149 | $num=0; |
---|
| 150 | foreach($colorList as $key => $val) |
---|
| 151 | { |
---|
| 152 | $colors[$row][]=Array('color' => $key, 'pct' => $val['pct'], 'num' => ""); |
---|
| 153 | $num++; |
---|
| 154 | if($num==$split) |
---|
| 155 | { |
---|
| 156 | $num=0; |
---|
| 157 | $row++; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | $data=array( |
---|
| 162 | 'colorTable' => $colors, |
---|
| 163 | 'size' => $size, |
---|
| 164 | 'id' => $id, |
---|
| 165 | 'class' => $class |
---|
| 166 | ); |
---|
| 167 | |
---|
| 168 | $template->assign('data', $data); |
---|
| 169 | unset($data); |
---|
| 170 | |
---|
| 171 | return($template->parse('color_table_page', true)); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | protected function displayResult($action_msg, $result) |
---|
| 178 | { |
---|
| 179 | global $page; |
---|
| 180 | |
---|
| 181 | if($result) |
---|
| 182 | { |
---|
| 183 | array_push($page['infos'], $action_msg); |
---|
| 184 | } |
---|
| 185 | else |
---|
| 186 | { |
---|
| 187 | array_push($page['errors'], $action_msg); |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | /* --------------------------------------------------------------------------- |
---|
| 193 | ajax functions |
---|
| 194 | --------------------------------------------------------------------------- */ |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | } //class |
---|
| 198 | |
---|
| 199 | ?> |
---|