'gally-default', 'icon_dir' => 'themes/gally-default/icon', 'mime_icon_dir' => 'themes/gally-default/icon/mimetypes/', 'activable' => false ); if(!defined('IN_ADMIN')) add_event_handler('init', 'initTemplateVar'); /** * GallyTpl class is used to initialise some templates variable and provide some * usefull function in template */ class GallyTpl { private $comment=array( 'id' => null ); public function __construct() { global $template, $themeconf; $this->loadConfDirectories(); $this->loadThemeJS(); $template->assign('gally', $this); } public function getToken() { return(get_pwg_token()); } public function getCommentKey($id) { if($this->loadComment($id)) { return(get_ephemeral_key(2, $this->comment['image_id'])); } return(''); } public function getCommentImage($id) { if($this->loadComment($id)) { return($this->comment['image_id']); } return(''); } public function getAlternateBannerContent() { global $template; return(html_entity_decode($template->smarty->get_config_vars('alternateBannerContent'))); } public function getRandomBox($value) { global $template; if(is_numeric($value)) return(rand(-$value, $value)); $v=$template->smarty->get_config_vars($value); return(rand(-$v, $v)); } /** * */ private function loadThemeJS() { global $template; $currentTheme=$template->get_template_vars('themeconf'); $file="themes/".$currentTheme['id']."/js/theme.js"; if(file_exists(dirname($_SERVER['SCRIPT_FILENAME']).'/'.$file)) { $template->scriptLoader->add($currentTheme['id'].'.theme.js', 'header', array('jquery'), $file, 0); } } /** * load conf directories in smarty variables * {$default_conf} * {$local_conf} */ private function loadConfDirectories() { global $template; $themes=$template->get_template_vars('themes'); foreach($themes as $theme) { $dir=dirname($_SERVER['SCRIPT_FILENAME'])."/themes/".$theme['id']."/conf/"; $dirlocal=dirname($_SERVER['SCRIPT_FILENAME'])."/".PWG_LOCAL_DIR."themes/".$theme['id']."/conf/"; if(file_exists($dir."local.conf")) $template->smarty->config_load($dir."default.conf"); if(file_exists($dirlocal."local.conf")) $template->smarty->config_load($dirlocal."local.conf"); } } /** * load comment properties * result is stored in $this->comment * * @param Integer $id: comment id */ private function loadComment($id) { if($id==null or $id=='') return(false); if($id==$this->comment['id']) return(true); $sql="SELECT image_id FROM ".COMMENTS_TABLE." WHERE id=$id"; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { $this->comment=array( 'id' => $id, 'image_id' => $row['image_id'] ); return(true); } } return(false); } } function initTemplateVar() { $gallyVar=new GallyTpl(); } ?>