> ------------------------------------------------------------------------------ This is the default class for the Gally themes interfaces managment --------------------------------------------------------------------------- */ include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); include_once('Conf.class.inc.php'); load_language('theme.lang', PHPWG_THEMES_PATH.'gally-default/'); class GallyDefault { const THEME_VERSION = '1.4.0'; private $directories=Array( 'templates.parent' => '', 'templates.local' => '', 'conf.parent' => '', 'conf.local' => '' ); private $pageLink; private $authorizedValues=Array(); protected $config; protected $tabsheet; protected $themeProperties = Array( 'name' => 'Gally/Default', 'version' => self::THEME_VERSION ); /** * function used to activate a theme * * @param String $themeId : theme's id (for example 'gally-lapis-lazulis') * @param String $themeVersion : theme's release (not gally-default release) * @param String $gallyDefaultNeeded : gally-default release needed * @param &Array $errors : array of error messages */ static public function activate($themeId, $themeVersion, $gallyDefaultNeeded, $errors) { if(strnatcmp(self::THEME_VERSION, $gallyDefaultNeeded)<0) { if(!is_array($errors)) { if($errors!='') { $errors=array($errors); } else { $errors=array(); } } $errors[]=sprintf(l10n('This theme needs Gally-default theme v%s; actually, Gally-default version is %s.'), $gallyDefaultNeeded, self::THEME_VERSION); } else { Conf::init($themeId); } return($errors); } /** * function used to deactivate a theme * */ static public function deactivate() { } /** * * @param String $themeName : the name of the theme * @param String $templateDirectory : directory for the admin.tpl template * file ; if no directory is given, assume * to use the gally/default admin.tpl file * @param String $confDirectory : directory for the conf files * if no directory is given, assume to use * the gally/default conf files * @param Boolean $manage : if true, manage display interface when * the class is instancied */ public function __construct($themeName, $templateDirectory="", $confDirectory="", $manage=true) { $this->setDirectoryPrivate('templates.parent', dirname(__FILE__)); $this->setDirectoryPrivate('templates.local', $templateDirectory); $this->setDirectoryPrivate('conf.parent', dirname(dirname(__FILE__)).'/conf'); $this->setDirectoryPrivate('conf.local', $confDirectory); if($themeName!="") { $this->themeProperties['name']=$themeName; } $this->pageLink="admin.php?page=theme&theme=".$_REQUEST['theme']; $this->authorizedValues['fGally_tabsheet']=Array('img_interface', 'img_high_res', 'img_other'); $this->loadConfig(); $this->initTabSheet(); if($manage) { $this->manage(); } } public function __destruct() { unset($this->tabsheet); unset($this->config); unset($this->directories); unset($this->authorizedValues); unset($this->themeProperties); } /** * */ public function loadConfig() { $this->config = new Conf(); $this->config->setFileName($this->directories['conf.parent']."/default.conf"); $this->config->read(); $this->config->setFileName($this->directories['conf.local']."/default.conf"); $this->config->read(false); $this->config->setFileName(PHPWG_ROOT_PATH."local/themes/".basename(dirname($this->directories['conf.local']))."/conf/local.conf"); $this->config->read(false); } /** * */ public function initTabSheet() { $this->tabsheet = new tabsheet(); $this->tabsheet->add('img_interface', l10n('gally_img_interface'), $this->getAdminThemeLink().'&fGally_tabsheet=img_interface'); $this->tabsheet->add('img_high_res', l10n('gally_img_high_res'), $this->getAdminThemeLink().'&fGally_tabsheet=img_high_res'); $this->tabsheet->add('img_other', l10n('gally_img_other'), $this->getAdminThemeLink().'&fGally_tabsheet=img_other'); } /** * manage the display of the admin theme interface * */ public function manage() { global $template; $template->set_filenames(array( 'theme_admin_content' => $this->getFile('templates', 'admin.tpl'))); $this->initRequest(); $this->manageConfig(); $this->tabsheet->select($_REQUEST['fGally_tabsheet']); $this->tabsheet->assign(); $file=$this->getFile('templates', 'gally_'.$_REQUEST['fGally_tabsheet'].'.tpl'); if($file!==false) { $template->set_filename('body_page', $file); $template->assign('options', $this->config->getConf()); $template->assign_var_from_handle('GALLY_BODY_PAGE', 'body_page'); $template->assign('gally', $this->themeProperties); $template->assign_var_from_handle('ADMIN_CONTENT', 'theme_admin_content'); } } /** * @return String : the url of the theme admin page */ public function getAdminThemeLink() { return($this->pageLink); } /** * */ public function getDirectory($type) { if($type=='templates.local' or $type=='templates.parent' or $type=='conf.local' or $type=='conf.parent') { return($this->directories[$type]); } else { return(false); } } /** * */ public function setDirectory($type, $directory) { if($type=='templates.local' or $type=='conf.local') { $this->setDirectoryPrivate($type, $directory); } return($this->directories[$type]); } /** * */ private function setDirectoryPrivate($type, $directory) { if(substr($directory, -1)=="/") $directory=substr($directory, 0, -1); if(file_exists($directory)) $this->directories[$type]=$directory; return($this->directories[$type]); } /** * * */ public function getFile($type, $fileName) { if(@file_exists($this->directories[$type.'.local'].'/'.$fileName)) { return($this->directories[$type.'.local'].'/'.$fileName); } elseif(@file_exists($this->directories[$type.'.parent'].'/'.$fileName)) { return($this->directories[$type.'.parent'].'/'.$fileName); } return(false); } /** * check and initialize all needed properties in the $_REQUEST var */ protected function initRequest() { //initialise $REQUEST values if not defined if(!array_key_exists('fGally_tabsheet', $_REQUEST)) { $_REQUEST['fGally_tabsheet']='img_interface'; } if(!$this->isAuthorizedValues('fGally_tabsheet', $_REQUEST['fGally_tabsheet'])) { $_REQUEST['fGally_tabsheet']='img_interface'; } } protected function manageConfig() { $config=$this->config->getConf(); if(isset($_POST['submit_gally'])) { foreach($config as $key => $val) { if(isset($_POST['f_'.$key])) { $config[$key] = stripslashes($_REQUEST['f_'.$key]); } } $this->config->setConf($config, false); $this->displayResult(l10n("gally_save_local_conf"), $this->config->write()); } } protected function displayResult($action_msg, $result) { global $page; if($result) { array_push($page['infos'], $action_msg); array_push($page['infos'], l10n("gally_action_ok")); } else { array_push($page['errors'], $action_msg); array_push($page['errors'], l10n("gally_action_ko")); } } protected function isAuthorizedValues($key, $value) { if(array_key_exists($key, $this->authorizedValues)) { if(in_array($value, $this->authorizedValues[$key])) { return(true); } } return(false); } protected function addAuthorizedValue($key, $value) { if(array_key_exists($key, $this->authorizedValues)) { if(!in_array($value, $this->authorizedValues[$key])) { $this->authorizedValues[$key][]=$value; } } else { $this->authorizedValues[$key]=Array($value); } } protected function removeAuthorizedValue($key, $value) { if(array_key_exists($key, $this->authorizedValues)) { $key2=array_search($value, $this->authorizedValues[$key]); if($key2!==false) { unset($this->authorizedValues[$key][$key2]); } } } } ?>