> ------------------------------------------------------------------------------ See main.inc.php for release information HGram_root : common classe for admin and public classes --------------------------------------------------------------------------- */ if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); include_once('hgram_histogram.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); class HGram_root extends CommonPlugin { const LOCAL_DIRECTORY='/local/plugins/Histogram/'; static public $pluginName='Histogram'; static public $pluginNameFile='hgram'; static public $pluginTables=array('histo'); public function __construct($prefixeTable, $filelocation) { $this->setPluginName(self::$pluginName); $this->setPluginNameFiles(self::$pluginNameFile); parent::__construct($prefixeTable, $filelocation); $this->section_name=$this->getPluginNameFiles(); $this->setTablesList(self::$pluginTables); } /** * initialize default values * */ public function initConfig() { $this->config=array( 'histo_width' => 256, 'histo_height' => 100, 'histo_method' => 'L', // L:luminance, A:average, M:max 'color_bg' => 0xffffff, 'color_v' => 0x606060, 'color_r' => 0xC00000, 'color_g' => 0x00C000, 'color_b' => 0x0000C0, 'mode_v' => 'surface', 'mode_r' => 'line', 'mode_g' => 'line', 'mode_b' => 'line' ); } /** * check if the given picture as histogram values * * @param Integer $id : piwigo image id * @return Bool : true if histogram exists */ public function checkHistogram($id) { $sql="SELECT COUNT(imageId) FROM ".$this->tables['histo']." WHERE imageId='$id';"; $result=pwg_query($sql); if($result) { $count=0; while($row=pwg_db_fetch_row($result)) { $count=$row[0]; } return($count>0); } return(false); } public function readHistogram($id) { $sql="SELECT path FROM ".IMAGES_TABLE." WHERE id='$id';"; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { $fileName=GPCCore::getPiwigoSystemPath().'/'.$row['path']; } if(file_exists($fileName)) { $values=Histogram::read($fileName); $sql="REPLACE INTO ".$this->tables['histo']." VALUES ('$id', '".implode(';',$values['L'])."', '".implode(';',$values['A'])."', '".implode(';',$values['M'])."', '".implode(';',$values['R'])."', '".implode(';',$values['G'])."', '".implode(';',$values['B'])."', '')"; $result=pwg_query($sql); } } } public function getHistogram($id) { $returned=array( 'L' => array(), 'A' => array(), 'M' => array(), 'R' => array(), 'G' => array(), 'B' => array() ); $sql="SELECT valueL AS L, valueA AS A, valueM AS M, valueR AS R, valueG AS G, valueB AS B FROM ".$this->tables['histo']." WHERE imageId='$id';"; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { $returned['L']=explode(';', $row['L']); $returned['A']=explode(';', $row['A']); $returned['M']=explode(';', $row['M']); $returned['R']=explode(';', $row['R']); $returned['G']=explode(';', $row['G']); $returned['B']=explode(';', $row['B']); } } return($returned); } public function getHistogramGraph($id, $read=false) { $sql="SELECT graphFile FROM ".$this->tables['histo']." WHERE imageId='$id';"; $result=pwg_query($sql); if($result) { $fileName=''; $exist=false; while($row=pwg_db_fetch_assoc($result)) { $fileName=$row['graphFile']; $exist=true; } if(!$exist) { if($read) { self::readHistogram($id); } else { return(''); } } if($fileName=='' or !file_exists(GPCCore::getPiwigoSystemPath().self::LOCAL_DIRECTORY.$fileName)) { $fileName=md5( sprintf("%s-%s", $id, implode('-', $this->config) ) ).".png"; $values=self::getHistogram($id); Histogram::build(GPCCore::getPiwigoSystemPath().self::LOCAL_DIRECTORY.$fileName, $values, $this->config); $sql="UPDATE ".$this->tables['histo']." SET graphFile='$fileName' WHERE imageId='$id';"; pwg_query($sql); } return($fileName); } return(''); } /** * get a valid token for an image (used to build histogram) * * @param Integer $imageId : image id * @return String : valid token */ public function getToken($imageId) { global $conf; return(hash_hmac('md5', "$imageId-".session_id(), $conf['secret_key'])); } /** * purge all histogram graph in directory cache */ public function purgeHistoCache() { $files=scandir(GPCCore::getPiwigoSystemPath().self::LOCAL_DIRECTORY); foreach($files as $fileName) { if(!is_dir($fileName)) unlink(GPCCore::getPiwigoSystemPath().self::LOCAL_DIRECTORY.'/'.$fileName); } $sql="UPDATE ".$this->tables['histo']." SET graphFile='';"; pwg_query($sql); } } //class ?>