> ------------------------------------------------------------------------------ See main.inc.php for release information CStat_root : common classe for admin and public classes --------------------------------------------------------------------------- */ if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); include_once('cstat_colorstat.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCCss.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); class CStat_root extends CommonPlugin { protected $css; //the css object protected $colorTableSize=Array('small' => Array(30,20), 'large' => Array(10,10)); public function __construct($prefixeTable, $filelocation) { $this->setPluginName('ColorStat'); $this->setPluginNameFiles("cstat"); parent::__construct($prefixeTable, $filelocation); $this->section_name=$this->getPluginNameFiles(); $this->setTablesList(array('images', 'color_table', 'images_colors')); $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css"); } public function __destruct() { unset($this->css); parent::__destruct(); } public function initEvents() { parent::initEvents(); add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') ); } /* menu block management */ public function register_blocks() { } /* intialize default values */ public function initConfig() { //global $user; $this->config=array( 'newInstall' => 'n', 'analyze_maxTime' => 0.1, 'analyze_colorTable' => 'small', 'analyze_pps' => 0, 'analyze_itemPerRequest' => 10, 'display_gallery_showColors' => 'n', 'display_stat_orderType' => 'img', 'stat_minPct' => 3.5, ); } /** * return HTML code for a given colorTable * * @param Array $colorTable : a color table, typically made with the * ColorStat::getColorTable() function * @param Int $size : size for colorbox in the HTML table * @return String : HTML code */ public function htmlColorTable($colorTable, $size=5, $id="", $class="") { global $template; $template->set_filename('color_table_page', dirname($this->getFileLocation()).'/templates/cstat_color_table.tpl'); $nbHue=count($colorTable); $nbStep=count($colorTable[0]); $colors=Array(); for($step=0;$step<$nbStep;$step++) { $row=Array(); for($hue=0;$hue<$nbHue;$hue++) { if($colorTable[$hue][$step] instanceof HSV) { $row[]=Array('color' => $colorTable[$hue][$step]->getRGB()->getHexString(), 'pct' => "", 'num' => ""); } elseif(is_array($colorTable[$hue][$step])) { $row[]=Array( 'color' => (array_key_exists('color', $colorTable[$hue][$step]))?$colorTable[$hue][$step]['color']:"", 'pct' => (array_key_exists('pct', $colorTable[$hue][$step]))?$colorTable[$hue][$step]['pct']:"", 'num' => (array_key_exists('num', $colorTable[$hue][$step]))?$colorTable[$hue][$step]['num']:"", ); } else { $row[]=Array('color' => $colorTable[$hue][$step], 'pct' => "", 'num' => ""); } } $colors[]=$row; unset($row); } $data=array( 'colorTable' => $colors, 'size' => $size, 'id' => $id, 'class' => $class ); $template->assign('data', $data); unset($data); return($template->parse('color_table_page', true)); } /** * return HTML code for a given colors list * * @param Array $colors : list of colors * @param Int $size : size for colorbox in the HTML table * @return String : HTML code */ public function htmlColorList($colorList, $split=8, $size=5, $id="", $class="", $br='
') { global $template; $template->set_filename('color_table_page', dirname($this->getFileLocation()).'/templates/cstat_color_table.tpl'); $colors=Array(); $row=0; $num=0; foreach($colorList as $key => $val) { $colors[$row][]=Array('color' => $key, 'pct' => $val['pct'], 'num' => ""); $num++; if($num==$split) { $num=0; $row++; } } $data=array( 'colorTable' => $colors, 'size' => $size, 'id' => $id, 'class' => $class, 'br' => $br, ); $template->assign('data', $data); unset($data); return($template->parse('color_table_page', true)); } /** * returns an array of colors & colors percent of an image * * @param Integer $imageId : id of the image * @return Array('colors' => Array(), 'colors_pct' => Array()) */ public function getImageColors($imageId) { $returned=Array( 'colors' => Array(), 'colors_pct' => Array(), ); $sql="SELECT colors, colors_pct FROM ".$this->tables['images']." WHERE image_id='".$imageId."'"; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { $returned['colors']=explode(',', $row['colors']); $returned['colors_pct']=explode(',', $row['colors_pct']); } } return($returned); } /** * return all HTML&JS code necessary to display a dialogbox to choose * colors */ protected function dialogBoxColor() { global $template; $template->set_filename('colors_choose', dirname($this->getFileLocation()).'/templates/cstat_dialog_colors_choose.tpl'); $colorTable=$this->getColorTableWithStat(); $datas=Array( 'colorTable' => $this->htmlColorTable( $colorTable, ($this->config['analyze_colorTable']=='small')?16:8, "", "color0px" ), //'urlRequest' => $this->getAdminLink(), ); $template->assign('datas', $datas); unset($data); return($template->parse('colors_choose', true)); } /** * return a color table with stat on color * * @return Array : a color table with statistics on colors */ protected function getColorTableWithStat() { $generalStats=$this->getGeneralStats(); $colors=Array(); $sql="SELECT color_id, num_images, num_pixels FROM ".$this->tables['color_table']." WHERE num_images > 0 ORDER BY color_id "; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { $colors[$row['color_id']]=Array('num_images' => $row['num_images'], 'num_pixels' => $row['num_pixels']); } } $colorTable=ColorStat::getColorTable( $this->colorTableSize[$this->config['analyze_colorTable']][0], $this->colorTableSize[$this->config['analyze_colorTable']][1] ); foreach($colorTable as $key=>$val) { foreach($val as $key2=>$val2) { $rgb=$val2->getRGB()->getHexString(); $colorTable[$key][$key2]=Array( 'color' => $rgb, 'pct' => '', //(array_key_exists($rgb, $colors))?sprintf("%.2f", round(100*$colors[$rgb]['num_pixels']/$generalStats['pixelsAnalyzedSum'],2)):"", 'num' => (array_key_exists($rgb, $colors))?$colors[$rgb]['num_images']:"", ); } } unset($colors); return($colorTable); } /* --------------------------------------------------------------------------- ajax functions --------------------------------------------------------------------------- */ } //class ?>