source: extensions/gally/gally-default/admin/GallyDefault.class.inc.php @ 7337

Last change on this file since 7337 was 7337, checked in by grum, 14 years ago

fix bug:1948

File size: 7.8 KB
RevLine 
[6109]1<?php
2/* -----------------------------------------------------------------------------
3  Theme      : Gally/default
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
11  This is the default class for the Gally themes interfaces managment
12
13  --------------------------------------------------------------------------- */
14
15include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
16include_once('Conf.class.inc.php');
17
18load_language('theme.lang', PHPWG_THEMES_PATH.'gally-default/');
19
20class GallyDefault
21{
22  private $directories=Array(
23    'templates.parent' => '',
24    'templates.local' => '',
25    'conf.parent' => '',
26    'conf.local' => ''
27  );
28  private $pageLink;
29  private $authorizedValues=Array();
30  protected $config;
31  protected $tabsheet;
32  protected $themeProperties = Array(
33      'name' => 'Gally/Default',
[6752]34      'version' => '1.3.1'
[6109]35    );
36
37  /**
38   *
39   * @param String $themeName : the name of the theme
40   * @param String $templateDirectory : directory for the admin.tpl template
41   *                                    file ; if no directory is given, assume
42   *                                    to use the gally/default admin.tpl file
43   * @param String $confDirectory     : directory for the conf files
44   *                                    if no directory is given, assume to use
45   *                                    the gally/default conf files
46   * @param Boolean $manage           : if true, manage display interface when
47   *                                    the class is instancied
48   */
49  public function __construct($themeName, $templateDirectory="", $confDirectory="", $manage=true)
50  {
51    $this->setDirectoryPrivate('templates.parent', dirname(__FILE__));
52    $this->setDirectoryPrivate('templates.local', $templateDirectory);
53
[7337]54
[6109]55    $this->setDirectoryPrivate('conf.parent', dirname(dirname(__FILE__)).'/conf');
56    $this->setDirectoryPrivate('conf.local', $confDirectory);
57
58    if($themeName!="")
59    {
60      $this->themeProperties['name']=$themeName;
61    }
62
63    $this->pageLink="admin.php?page=theme&amp;theme=".$_REQUEST['theme'];
64
65    $this->authorizedValues['fGally_tabsheet']=Array('img_interface', 'img_high_res', 'img_other');
66
67    $this->loadConfig();
68    $this->initTabSheet();
69
70    if($manage)
71    {
72      $this->manage();
73    }
74  }
75
76  public function __destruct()
77  {
78    unset($this->tabsheet);
79    unset($this->config);
80    unset($this->directories);
81    unset($this->authorizedValues);
82    unset($this->themeProperties);
83  }
84
85  /**
86   *
87   */
88  public function loadConfig()
89  {
90    $this->config = new Conf();
[6752]91    $this->config->setFileName($this->directories['conf.parent']."/default.conf");
[6109]92    $this->config->read();
[7337]93    $this->config->setFileName($this->directories['conf.local']."/default.conf");
94    $this->config->read();
[6109]95    $this->config->setFileName(PHPWG_ROOT_PATH."local/themes/".basename(dirname($this->directories['conf.local']))."/conf/local.conf");
96    $this->config->read(false);
97  }
98
99
100  /**
101   *
102   */
103  public function initTabSheet()
104  {
105    $this->tabsheet = new tabsheet();
106    $this->tabsheet->add('img_interface',
107                          l10n('gally_img_interface'),
108                          $this->getAdminThemeLink().'&amp;fGally_tabsheet=img_interface');
109    $this->tabsheet->add('img_high_res',
110                          l10n('gally_img_high_res'),
111                          $this->getAdminThemeLink().'&amp;fGally_tabsheet=img_high_res');
112    $this->tabsheet->add('img_other',
113                          l10n('gally_img_other'),
114                          $this->getAdminThemeLink().'&amp;fGally_tabsheet=img_other');
115  }
116
117  /**
118   * manage the display of the admin theme interface
119   *
120   */
121  public function manage()
122  {
123    global $template;
124
125    $template->set_filenames(array(
126        'theme_admin_content' => $this->getFile('templates', 'admin.tpl')));
127
128    $this->initRequest();
129    $this->manageConfig();
130
131    $this->tabsheet->select($_REQUEST['fGally_tabsheet']);
132    $this->tabsheet->assign();
133
134    $file=$this->getFile('templates', 'gally_'.$_REQUEST['fGally_tabsheet'].'.tpl');
135    if($file!==false)
136    {
137      $template->set_filename('body_page', $file);
138
139      $template->assign('options', $this->config->getConf());
140      $template->assign_var_from_handle('GALLY_BODY_PAGE', 'body_page');
141
142      $template->assign('gally', $this->themeProperties);
143      $template->assign_var_from_handle('ADMIN_CONTENT', 'theme_admin_content');
144    }
145  }
146
147
148  /**
149   * @return String : the url of the theme admin page
150   */
151  public function getAdminThemeLink()
152  {
153    return($this->pageLink);
154  }
155
156  /**
157   *
158   */
159  public function getDirectory($type)
160  {
161    if($type=='templates.local' or $type=='templates.parent' or
162       $type=='conf.local' or $type=='conf.parent')
163    {
164      return($this->directories[$type]);
165    }
166    else
167    {
168      return(false);
169    }
170  }
171
172  /**
173   *
174   */
175  public function setDirectory($type, $directory)
176  {
177    if($type=='templates.local' or $type=='conf.local')
178    {
179      $this->setDirectoryPrivate($type, $directory);
180    }
181    return($this->directories[$type]);
182  }
183
184  /**
185   *
186   */
187  private function setDirectoryPrivate($type, $directory)
188  {
189    if(substr($directory, -1)=="/") $directory=substr($directory, 0, -1);
190
191    if(file_exists($directory)) $this->directories[$type]=$directory;
192
193    return($this->directories[$type]);
194  }
195
196  /**
197   *
198   *
199   */
200  public function getFile($type, $fileName)
201  {
[6700]202    if(@file_exists($this->directories[$type.'.local'].'/'.$fileName))
[6109]203    {
204      return($this->directories[$type.'.local'].'/'.$fileName);
205    }
[6700]206    elseif(@file_exists($this->directories[$type.'.parent'].'/'.$fileName))
[6109]207    {
208      return($this->directories[$type.'.parent'].'/'.$fileName);
209    }
210    return(false);
211  }
212
213
214
215  /**
216   * check and initialize all needed properties in the $_REQUEST var
217   */
218  protected function initRequest()
219  {
220    //initialise $REQUEST values if not defined
221    if(!array_key_exists('fGally_tabsheet', $_REQUEST))
222    {
223      $_REQUEST['fGally_tabsheet']='img_interface';
224    }
225
226    if(!$this->isAuthorizedValues('fGally_tabsheet', $_REQUEST['fGally_tabsheet']))
227    {
228      $_REQUEST['fGally_tabsheet']='img_interface';
229    }
230  }
231
232
233  protected function manageConfig()
234  {
235    $config=$this->config->getConf();
236
237    if(isset($_POST['submit_gally']))
238    {
239      foreach($config as $key => $val)
240      {
241        if(isset($_POST['f_'.$key]))
242        {
243          $config[$key] = stripslashes($_REQUEST['f_'.$key]);
244        }
245      }
246      $this->config->setConf($config, false);
247      $this->displayResult(l10n("gally_save_local_conf"), $this->config->write());
248    }
249  }
250
251  protected function displayResult($action_msg, $result)
252  {
253    global $page;
254
255    if($result)
256    {
257      array_push($page['infos'], $action_msg);
258      array_push($page['infos'], l10n("gally_action_ok"));
259    }
260    else
261    {
262      array_push($page['errors'], $action_msg);
263      array_push($page['errors'], l10n("gally_action_ko"));
264    }
265  }
266
267  protected function isAuthorizedValues($key, $value)
268  {
269    if(array_key_exists($key, $this->authorizedValues))
270    {
271      if(in_array($value, $this->authorizedValues[$key]))
272      {
273        return(true);
274      }
275    }
276    return(false);
277  }
278
279  protected function addAuthorizedValue($key, $value)
280  {
281    if(array_key_exists($key, $this->authorizedValues))
282    {
283      if(!in_array($value, $this->authorizedValues[$key]))
284      {
285        $this->authorizedValues[$key][]=$value;
286      }
287    }
288    else
289    {
290      $this->authorizedValues[$key]=Array($value);
291    }
292  }
293
294  protected function removeAuthorizedValue($key, $value)
295  {
296    if(array_key_exists($key, $this->authorizedValues))
297    {
298      $key2=array_search($value, $this->authorizedValues[$key]);
299      if($key2!==false)
300      {
301        unset($this->authorizedValues[$key][$key2]);
302      }
303    }
304  }
305
306}
307
308
309?>
Note: See TracBrowser for help on using the repository browser.