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

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

for panoramic images, add possibility to simulate presence of a high resolution image

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