source: extensions/GrumPluginClasses/classes/GPCCore.class.inc.php @ 15373

Last change on this file since 15373 was 15373, checked in by grum, 12 years ago

feature:2634 - Compatibility with Piwigo 2.4
remove some unused functions

File size: 30.2 KB
Line 
1<?php
2
3/* -----------------------------------------------------------------------------
4  class name     : GPCCore
5  class version  : 1.4.1
6  plugin version : 3.5.2
7  date           : 2011-09-19
8  ------------------------------------------------------------------------------
9  author: grum at piwigo.org
10  << May the Little SpaceFrog be with you >>
11  ------------------------------------------------------------------------------
12
13  :: HISTORY
14
15| release | date       |
16| 1.0.0   | 2010/03/30 | * Update class & function names
17|         |            |
18| 1.1.0   | 2010/03/30 | * add the BBtoHTML function
19|         |            |
20| 1.2.0   | 2010/07/28 | * add the loadConfigFromFile function
21|         |            |
22| 1.3.0   | 2010/10/13 | * add the addHeaderCSS, addHeaderJS functions
23|         |            |
24| 1.3.1   | 2010/10/20 | * applyHeaderItems functions implemented with an
25|         |            |   higher priority on the 'loc_begin_page_header' event
26|         |            |
27|         |            | * implement the getUserLanguageDesc() function, using
28|         |            |   extended description function if present
29|         |            |
30|         |            | * implement the getPiwigoSystemPath() function
31|         |            |
32|         |            | * implement the rmDir() function
33|         |            |
34| 1.3.2   | 2011/01/28 | * implement the addUI() function
35|         |            |
36|         |            | * implement getMinified() & setMinifiedState() functions
37|         |            |
38| 1.3.3   | 2011/02/01 | * fix bug on loadConfig() function
39|         |            |
40|         |            | * update deleteConfig() function (allow to be used to
41|         |            |   delete the GPCCore config)
42|         |            |
43|         |            | * mantis bug:2167
44|         |            |
45| 1.3.4   | 2011/02/02 | * mantis bug:2170
46|         |            |   . File path for RBuilder registered plugins is corrupted
47|         |            |
48|         |            | * mantis bug:2178
49|         |            |   . RBuilder register function don't work
50|         |            |
51|         |            | * mantis bug:2179
52|         |            |   . JS file loaded in wrong order made incompatibility
53|         |            |     with Lightbox, GMaps & ASE plugins (and probably other)
54|         |            |
55| 1.4.0   | 2011/04/10 | * Updated for piwigo 2.2
56|         |            |
57| 1.4.1   | 2011/09/19 | * Add [var] and [form_mail] markup interpreter
58|         |            |
59|         | 2012/05/25 | * Add GPCUserAgent class
60|         |            |
61|         |            | * Compatibility with jquery 1.7.2 & jquery-ui 1.8.16
62|         |            |   . implement getMinified() & setMinifiedState() functions
63|         |            |        (let piwigo combined function manage the minified
64|         |            |         state)
65|         |            |   . add manually each component for ui functionnalities
66|         |            |
67|         |            | * Remove google translate connector (google has changed the useage
68|         |            |    and now an API key is needed)
69|         |            |
70
71  ------------------------------------------------------------------------------
72    no constructor, only static function are provided
73    - static function loadConfig
74    - static function loadConfigFromFile
75    - static function saveConfig
76    - static function deleteConfig
77    - static function getRegistered
78    - static function getModulesInfos
79    - static function register
80    - static function unregister
81    - static function BBtoHTML
82    - static function VarToHTML
83    - static function FormMailToHTML
84    - static function addHeaderCSS
85    - static function addHeaderJS
86    - static function addUI
87    - static function getUserLanguageDesc
88    - static function getPiwigoSystemPath
89    - static function formatOctet
90    - static function rmDir
91    - static function applyMarkups
92   ---------------------------------------------------------------------- */
93
94
95
96class GPCCore
97{
98  static private $piwigoSystemPath;
99
100  static public $pluginName = "GPCCore";
101  static protected $headerItems = array(
102    'css' => array(),
103    'js'  => array()
104  );
105
106  static public function init()
107  {
108    global $conf;
109
110    self::$piwigoSystemPath=dirname(dirname(dirname(dirname(__FILE__))));
111
112    if((isset($conf['gpc.markup.bb']) && $conf['gpc.markup.bb']) ||
113       (isset($conf['gpc.markup.var']) && $conf['gpc.markup.var']) ||
114       (isset($conf['gpc.markup.form']) && $conf['gpc.markup.form'])
115      )
116    {
117      add_event_handler('render_category_name', array('GPCCore', 'applyMarkups'), EVENT_HANDLER_PRIORITY_NEUTRAL+5);
118      add_event_handler('render_category_description', array('GPCCore', 'applyMarkups'), EVENT_HANDLER_PRIORITY_NEUTRAL+5, 2);
119      add_event_handler('render_element_description', array('GPCCore', 'applyMarkups'), EVENT_HANDLER_PRIORITY_NEUTRAL+5);
120      add_event_handler('AP_render_content', array('GPCCore', 'applyMarkups'), EVENT_HANDLER_PRIORITY_NEUTRAL+5);
121    }
122  }
123
124  /* ---------------------------------------------------------------------------
125   * grum plugin classes informations functions
126   * -------------------------------------------------------------------------*/
127  static public function getModulesInfos()
128  {
129    return(
130      Array(
131        Array('name' => "CommonPlugin", 'version' => "2.2.0"),
132        Array('name' => "GPCAjax", 'version' => "3.0.0"),
133        Array('name' => "GPCCategorySelector", 'version' => "1.0.1"),
134        Array('name' => "GPCCore", 'version' => "1.4.1"),
135        Array('name' => "GPCCss", 'version' => "3.1.0"),
136        Array('name' => "GPCPagesNavigation", 'version' => "2.0.0"),
137        Array('name' => "GPCPublicIntegration", 'version' => "2.0.0"),
138        Array('name' => "GPCRequestBuilder", 'version' => "1.1.2"),
139        Array('name' => "GPCTables", 'version' => "1.5.0"),
140        Array('name' => "GPCTabSheet", 'version' => "1.1.1"),
141        Array('name' => "GPCTranslate", 'version' => "2.1.1"),
142        Array('name' => "GPCUsersGroups", 'version' => "2.1.0"),
143        Array('name' => "GPCUserAgent", 'version' => "1.0.0")
144      )
145    );
146  }
147
148
149  /* ---------------------------------------------------------------------------
150   * register oriented functions
151   * -------------------------------------------------------------------------*/
152
153  /**
154   * register a plugin using GPC
155   *
156   * @param String $pluginName : the plugin name
157   * @param String $release : the plugin version like "2.0.0"
158   * @param String $GPCNeed : the minimal version of GPC needed by the plugin to
159   *                          work
160   * @return Boolean : true if registering is Ok, otherwise false
161   */
162  static public function register($plugin, $release, $GPCneeded)
163  {
164    $config=Array();
165    if(!self::loadConfig(self::$pluginName, $config))
166    {
167      $config['registered']=array();
168    }
169
170    $config['registered'][$plugin]=Array(
171      'name' => $plugin,
172      'release' => $release,
173      'needed' => $GPCneeded,
174      'date' => date("Y-m-d"),
175    );
176    return(self::saveConfig(self::$pluginName, $config));
177  }
178
179  /**
180   * unregister a plugin using GPC
181   *
182   * assume that if the plugin was not registerd before, unregistering returns
183   * a true value
184   *
185   * @param String $pluginName : the plugin name
186   * @return Boolean : true if registering is Ok, otherwise false
187   */
188  static public function unregister($plugin)
189  {
190    $config=Array();
191    if(self::loadConfig(self::$pluginName, $config))
192    {
193      if(array_key_exists('registered', $config))
194      {
195        if(array_key_exists($plugin, $config['registered']))
196        {
197          unset($config['registered'][$plugin]);
198          return(self::saveConfig(self::$pluginName, $config));
199        }
200      }
201    }
202    // assume if the plugin was not registered before, unregistering it is OK
203    return(true);
204  }
205
206  /**
207   * @return Array : list of registered plugins
208   */
209  static public function getRegistered()
210  {
211    $config=Array();
212    if(self::loadConfig(self::$pluginName, $config))
213    {
214      if(array_key_exists('registered', $config))
215      {
216        return($config['registered']);
217      }
218    }
219    return(Array());
220  }
221
222
223
224  /* ---------------------------------------------------------------------------
225   * config oriented functions
226   * -------------------------------------------------------------------------*/
227
228  /**
229   *  load config from CONFIG_TABLE into an array
230   *
231   * @param String $pluginName : the plugin name, must contain only alphanumerical
232   *                             character
233   * @param Array $config : array, initialized or not with default values ; the
234   *                        config values are loaded in this value
235   * @return Boolean : true if config is loaded, otherwise false
236   */
237  static public function loadConfig($pluginName, &$config=Array())
238  {
239    global $conf;
240
241    if(!isset($conf[$pluginName.'_config']))
242    {
243      return(false);
244    }
245
246    $configValues = unserialize($conf[$pluginName.'_config']);
247    reset($configValues);
248    while (list($key, $val) = each($configValues))
249    {
250      if(is_array($val))
251      {
252        foreach($val as $key2 => $val2)
253        {
254          $config[$key][$key2]=$val2;
255        }
256      }
257      else
258      {
259        $config[$key] =$val;
260      }
261    }
262
263    $conf[$pluginName.'_config']=serialize($config);
264
265    return(true);
266  }
267
268  /**
269   *  load config from a file into an array
270   *
271   *  note : the config file is a PHP file one var $conf used as an array,
272   *  like the piwigo $conf var
273   *
274   * @param String $fileName : the file name
275   * @param Array $config : array, initialized or not with default values ; the
276   *                        config values are loaded in this value
277   * @return Boolean : true if config is loaded, otherwise false
278   */
279  static public function loadConfigFromFile($fileName, &$config=Array())
280  {
281    $conf=array();
282
283    if(!is_array($config) or !file_exists($fileName))
284    {
285      return(false);
286    }
287
288    include_once($fileName);
289
290    foreach($conf as $key=>$val)
291    {
292      $config[$key]=$val;
293    }
294    return(true);
295  }
296
297
298  /**
299   * save var $my_config into CONFIG_TABLE
300   *
301   * @param String $pluginName : the plugin name, must contain only alphanumerical
302   *                             character
303   * @param Array $config : array of configuration values
304   * @return Boolean : true if config is saved, otherwise false
305   */
306  static public function saveConfig($pluginName, $config)
307  {
308    global $conf;
309
310    $sql="REPLACE INTO ".CONFIG_TABLE."
311           VALUES('".$pluginName."_config', '"
312           .pwg_db_real_escape_string(serialize($config))."', '')";
313    $result=pwg_query($sql);
314    if($result)
315    {
316      $conf[$pluginName.'_config']=serialize($config);
317      return true;
318    }
319    else
320    {
321      return false;
322    }
323  }
324
325  /**
326   * delete config from CONFIG_TABLE
327   *
328   * @param String $pluginName : the plugin name, must contain only alphanumerical
329   *                             character ; if empty, assume GPCCore config
330   * @return Boolean : true if config is deleted, otherwise false
331   */
332  static public function deleteConfig($pluginName='')
333  {
334    if($pluginName=='') $pluginName=self::$pluginName;
335    $sql="DELETE FROM ".CONFIG_TABLE."
336          WHERE param='".$pluginName."_config'";
337    $result=pwg_query($sql);
338    if($result)
339    { return true; }
340    else
341    { return false; }
342  }
343
344
345  /**
346   * convert (light) BB tag to HTML tag
347   *
348   * all BB codes are not recognized, only :
349   *  - [ul] [/ul]
350   *  - [li] [/li]
351   *  - [b] [/b]
352   *  - [i] [/i]
353   *  - [url] [/url]
354   *  - carriage return is replaced by a <br>
355   *
356   * @param String $text : text to convert
357   * @return String : BB to HTML text
358   */
359  static public function BBtoHTML($text)
360  {
361    $patterns = Array(
362      '/\[li\](.*?)\[\/li\]\n*/im',
363      '/\[b\](.*?)\[\/b\]/ism',
364      '/\[i\](.*?)\[\/i\]/ism',
365      '/\[p\](.*?)\[\/p\]/ism',
366      '/\[url\]([\w]+?:\/\/[^ \"\n\r\t<]*?)\[\/url\]/ism',
367      '/\[url=([\w]+?:\/\/[^ \"\n\r\t<]*?)\](.*?)\[\/url\]/ism',
368      '/\n{0,1}\[ul\]\n{0,1}/im',
369      '/\n{0,1}\[\/ul\]\n{0,1}/im',
370      '/\n{0,1}\[ol\]\n{0,1}/im',
371      '/\n{0,1}\[\/ol\]\n{0,1}/im',
372      '/\n/im',
373    );
374    $replacements = Array(
375      '<li>\1</li>',
376      '<b>\1</b>',
377      '<i>\1</i>',
378      '<p>\1</p>',
379      '<a href="\1">\1</a>',
380      '<a href="\1">\2</a>',
381      '<ul>',
382      '</ul>',
383      '<ol>',
384      '</ol>',
385      '<br>',
386    );
387
388    return(preg_replace($patterns, $replacements, $text));
389  }
390
391  /**
392   * apply [var] tag
393   *
394   * [var=<name>]
395   * with <name> :
396   *  - USER
397   *  - GALLERY_TITLE
398   *  - NB_PHOTOS
399   *  - CATEGORY
400   *  - TOKEN
401   *  - IP
402   *
403   * @param String $text : text to convert
404   * @return String : processed text
405   */
406  static public function VarToHTML($text)
407  {
408    global $user, $page, $conf;
409
410    $patterns = Array(
411      '/\[var=user\]/im',
412      '/\[var=gallery_title\]/im',
413      '/\[var=nb_photos\]/im',
414      '/\[var=category\]/im',
415      '/\[var=token\]/im',
416      '/\[var=ip\]/im'
417    );
418    $replacements = Array(
419      isset($user['username'])?$user['username']:'',
420      isset($conf['gallery_title'])?$conf['gallery_title']:'',
421      isset($user['nb_total_images'])?$user['nb_total_images']:'',
422      isset($page['category']['name'])?$page['category']['name']:'',
423      get_pwg_token(),
424      $_SERVER['REMOTE_ADDR']
425    );
426
427    return(preg_replace($patterns, $replacements, $text));
428  }
429
430  /**
431   * apply [form_mail] tag
432   *
433   * @param String $text : text to convert
434   * @return String : processed text
435   */
436  static public function FormMailToHTML($text)
437  {
438    global $template;
439
440    $file=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.'templates/GPCFormMsg.tpl';
441    if(!file_exists($file)) $file=dirname(dirname(__FILE__))."/templates/GPCFormMsg.tpl";
442
443    $template->set_filename('gpc_form', $file);
444
445    $template->assign('token', get_pwg_token() );
446
447    $patterns = Array(
448      '/\[form_mail\]/im'
449    );
450    $replacements = Array(
451      $template->parse('gpc_form', true)
452    );
453
454    if(preg_match($patterns[0], $text)>0)
455    {
456      GPCCore::addHeaderJS('gpc.markup.formMail', GPC_PATH.'js/markup.formMail.js', array('jquery'));
457      return(preg_replace($patterns, $replacements, $text));
458    }
459    return($text);
460  }
461
462  /**
463   * apply [tab], [/tab] and [tabs] tags
464   *
465   * @param String $text : text to convert
466   * @return String : processed text
467   */
468  static public function TabsToHTML($text)
469  {
470    $result=array();
471
472    $tabs='';
473    if(preg_match_all('/\[tab=([^(;\]).]*)(?:;(default))?;([^\].]*)\]/im', $text, $result, PREG_SET_ORDER)>0)
474    {
475      foreach($result as $val)
476      {
477        $tabs.="<li class='gpcTabSeparator'><a id='iGpcTab".$val[1]."' class='".($val[2]=='default'?'gpcTabSelected':'gpcTabNotSelected')."' tabId='#iGpcTabContent".$val[1]."'>".$val[3]."</a></li>";
478      }
479      $tabs="<div id='iGpcTabs'><ul>".$tabs."</ul></div>";
480    }
481    else return($text);
482
483    $patterns = Array(
484      '/\[tabs\]/im',
485      '/\[tab=([^(;\]).]*)(?!;default);.*\]/im',
486      '/\[tab=([^(;\]).]*);default;(.*)\]/im',
487      '/\[\/tab\]/im'
488    );
489    $replacements = Array(
490      $tabs,
491      '<div id="iGpcTabContent\1" class="gpcTabContent" style="display:none;">',
492      '<div id="iGpcTabContent\1" class="gpcTabContent">',
493      '</div>'
494    );
495
496    if(preg_match($patterns[0], $text)>0)
497    {
498      GPCCore::addHeaderJS('gpc.markup.tabs', GPC_PATH.'js/markup.tabs.js', array('jquery'));
499      GPCCore::addHeaderCSS('gpc.markup.tabs', GPC_PATH.'css/gpcTabs.css');
500      return(preg_replace($patterns, $replacements, $text));
501    }
502    return($text);
503  }
504
505  static public function applyMarkups($text)
506  {
507    global $conf;
508
509    if(isset($conf['gpc.markup.form']) && $conf['gpc.markup.form'])
510    {
511      $text=GPCCore::FormMailToHTML($text);
512    }
513
514    if(isset($conf['gpc.markup.tabs']) && $conf['gpc.markup.tabs'])
515    {
516      $text=GPCCore::TabsToHTML($text);
517    }
518
519    if(isset($conf['gpc.markup.var']) && $conf['gpc.markup.var'])
520    {
521      $text=GPCCore::VarToHTML($text);
522    }
523
524    if(isset($conf['gpc.markup.bb']) && $conf['gpc.markup.bb'])
525    {
526      $text=GPCCore::BBtoHTML($text);
527    }
528
529
530    return($text);
531  }
532
533  /**
534   * used to add a css file in the header
535   *
536   * @param String $id : a unique id for the file
537   * @param String $file : the css file
538   */
539  static public function addHeaderCSS($id, $file, $order=0)
540  {
541    global $template;
542
543    if(!array_key_exists($file, self::$headerItems['css']) and file_exists($file))
544    {
545      self::$headerItems['css'][$id]=$file;
546      $template->func_combine_css(array('path'=>$file, 'order'=>$order), $template->smarty);
547    }
548  }
549  static public function addHeaderJS($id, $file, $require=array())
550  {
551    global $template;
552
553    if(!array_key_exists($file, self::$headerItems['js']) and file_exists($file))
554    {
555      self::$headerItems['js'][$id]=$file;
556      $template->scriptLoader->add($id, 'header', $require, $file, 0);
557    }
558  }
559
560  /**
561   * add a ui component ; css & js dependencies are managed
562   *
563   * @param Array $list : possibles values are
564   *                        - inputCheckbox
565   *                        - inputColorPicker
566   *                        - inputColorsFB
567   *                        - inputConsole
568   *                        - inputDotArea
569   *                        - inputList
570   *                        - inputNum
571   *                        - inputPosition
572   *                        - inputRadio
573   *                        - inputStatusBar
574   *                        - inputText
575   *                        - categorySelector
576   */
577  static public function addUI($list)
578  {
579    global $template;
580
581    if(is_string($list)) $list=explode(',', $list);
582    if(!is_array($list)) return(false);
583
584    if(defined('IN_ADMIN'))
585    {
586      $themeFile=GPC_PATH.'css/%s_'.$template->get_themeconf('name').'.css';
587    }
588    else
589    {
590      $themeFile='themes/'.$template->get_themeconf('name').'/css/GPC%s.css';
591    }
592
593    foreach($list as $ui)
594    {
595      switch($ui)
596      {
597        case 'categorySelector':
598          self::addHeaderCSS('gpc.categorySelector', GPC_PATH.'css/categorySelector.css');
599          self::addHeaderCSS('gpc.categorySelectorT', sprintf($themeFile, 'categorySelector'));
600          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
601          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
602          self::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
603          self::addHeaderJS('gpc.categorySelector', GPC_PATH.'js/ui.categorySelector.js', array('jquery.ui.widget'));
604          break;
605        case 'inputCheckbox':
606          self::addHeaderCSS('gpc.inputCheckbox', GPC_PATH.'css/inputCheckbox.css');
607          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
608          self::addHeaderJS('gpc.inputCheckbox', GPC_PATH.'js/ui.inputCheckbox.js', array('jquery.ui'));
609          break;
610        case 'inputColorPicker':
611          self::addHeaderCSS('gpc.inputText', GPC_PATH.'css/inputText.css');
612          self::addHeaderCSS('gpc.inputNum', GPC_PATH.'css/inputNum.css');
613          self::addHeaderCSS('gpc.inputColorsFB', GPC_PATH.'css/inputColorsFB.css');
614          self::addHeaderCSS('gpc.inputDotArea', GPC_PATH.'css/inputDotArea.css');
615          self::addHeaderCSS('gpc.inputColorPicker', GPC_PATH.'css/inputColorPicker.css');
616          self::addHeaderCSS('gpc.inputTextT', sprintf($themeFile, 'inputText'));
617          self::addHeaderCSS('gpc.inputNumT', sprintf($themeFile, 'inputNum'));
618          self::addHeaderCSS('gpc.inputColorsFBT', sprintf($themeFile, 'inputColorsFB'));
619          self::addHeaderCSS('gpc.inputDotAreaT', sprintf($themeFile, 'inputDotArea'));
620          self::addHeaderCSS('gpc.inputColorPickerT', sprintf($themeFile, 'inputColorPicker'));
621          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
622          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
623          self::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
624          self::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery.ui.widget'));
625          self::addHeaderJS('jquery.ui.draggable', 'themes/default/js/ui/jquery.ui.draggable.js', array('jquery.ui.widget'));
626          self::addHeaderJS('jquery.ui.dialog', 'themes/default/js/ui/jquery.ui.dialog.js', array('jquery.ui.widget'));
627          self::addHeaderJS('jquery.ui.slider', 'themes/default/js/ui/jquery.ui.slider.js', array('jquery.ui.widget'));
628          self::addHeaderJS('gpc.inputText', GPC_PATH.'js/ui.inputText.js', array('jquery.ui.widget'));
629          self::addHeaderJS('gpc.inputNum', GPC_PATH.'js/ui.inputNum.js', array('jquery.ui.widget'));
630          self::addHeaderJS('gpc.inputColorsFB', GPC_PATH.'js/ui.inputColorsFB.js', array('jquery.ui.widget'));
631          self::addHeaderJS('gpc.inputDotArea', GPC_PATH.'js/ui.inputDotArea.js', array('jquery.ui.widget'));
632          self::addHeaderJS('gpc.inputColorPicker', GPC_PATH.'js/ui.inputColorPicker.js', array('jquery.ui.slider','gpc.inputText','gpc.inputNum','gpc.inputColorsFB','gpc.inputDotArea'));
633          break;
634        case 'inputColorsFB':
635          self::addHeaderCSS('gpc.inputColorsFB', GPC_PATH.'css/inputColorsFB.css');
636          self::addHeaderCSS('gpc.inputColorsFBT', sprintf($themeFile, 'inputColorsFB'));
637          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
638          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
639          self::addHeaderJS('gpc.inputColorsFB', GPC_PATH.'js/ui.inputColorsFB.js', array('jquery.ui.widget'));
640          break;
641        case 'inputConsole':
642          self::addHeaderCSS('gpc.inputConsole', GPC_PATH.'css/inputConsole.css');
643          self::addHeaderCSS('gpc.inputConsoleT', sprintf($themeFile, 'inputConsole'));
644          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
645          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
646          self::addHeaderJS('gpc.inputConsole', GPC_PATH.'js/ui.inputConsole.js', array('jquery.ui.widget'));
647          break;
648        case 'inputDotArea':
649          self::addHeaderCSS('gpc.inputDotArea', GPC_PATH.'css/inputDotArea.css');
650          self::addHeaderCSS('gpc.inputDotAreaT', sprintf($themeFile, 'inputDotArea'));
651          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
652          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
653          self::addHeaderJS('gpc.inputDotArea', GPC_PATH.'js/ui.inputDotArea.js', array('jquery.ui.widget'));
654          break;
655        case 'inputList':
656          self::addHeaderCSS('gpc.inputList', GPC_PATH.'css/inputList.css');
657          self::addHeaderCSS('gpc.inputListT', sprintf($themeFile, 'inputList'));
658          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
659          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
660          self::addHeaderJS('gpc.inputList', GPC_PATH.'js/ui.inputList.js', array('jquery.ui.widget'));
661          break;
662        case 'inputNum':
663          self::addHeaderCSS('gpc.inputNum', GPC_PATH.'css/inputNum.css');
664          self::addHeaderCSS('gpc.inputNumT', sprintf($themeFile, 'inputNum'));
665          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
666          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
667          self::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
668          self::addHeaderJS('jquery.ui.slider', 'themes/default/js/ui/jquery.ui.slider.js', array('jquery.ui.widget'));
669          self::addHeaderJS('gpc.inputNum', GPC_PATH.'js/ui.inputNum.js', array('jquery','jquery.ui.slider'));
670          break;
671        case 'inputPosition':
672          self::addHeaderCSS('gpc.inputPosition', GPC_PATH.'css/inputPosition.css');
673          self::addHeaderCSS('gpc.inputPositionT', sprintf($themeFile, 'inputPosition'));
674          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
675          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
676          self::addHeaderJS('gpc.inputPosition', GPC_PATH.'js/ui.inputPosition.js', array('jquery.ui.widget'));
677          break;
678        case 'inputRadio':
679          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
680          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
681          self::addHeaderJS('gpc.inputRadio', GPC_PATH.'js/ui.inputRadio.js', array('jquery.ui.widget'));
682          break;
683        case 'inputStatusBar':
684          self::addHeaderCSS('gpc.inputStatusBar', GPC_PATH.'css/inputStatusBar.css');
685          self::addHeaderCSS('gpc.inputStatusBarT', sprintf($themeFile, 'inputStatusBar'));
686          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
687          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
688          self::addHeaderJS('gpc.inputStatusBar', GPC_PATH.'js/ui.inputStatusBar.js', array('jquery.ui.widget'));
689          break;
690        case 'inputSwitchButton':
691          self::addHeaderCSS('gpc.inputSwitchButton', GPC_PATH.'css/inputSwitchButton.css');
692          self::addHeaderCSS('gpc.inputSwitchButtonT', sprintf($themeFile, 'inputSwitchButton'));
693          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
694          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
695          self::addHeaderJS('gpc.inputSwitchButton', GPC_PATH.'js/ui.inputSwitchButton.js', array('jquery.ui.widget'));
696          break;
697        case 'inputText':
698          self::addHeaderCSS('gpc.inputText', GPC_PATH.'css/inputText.css');
699          self::addHeaderCSS('gpc.inputTextT', sprintf($themeFile, 'inputText'));
700          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
701          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
702          self::addHeaderJS('gpc.inputText', GPC_PATH.'js/ui.inputText.js', array('jquery.ui.widget'));
703          break;
704        case 'simpleTip':
705          self::addHeaderCSS('gpc.simpleTip', GPC_PATH.'css/simpleTip.css');
706          self::addHeaderCSS('gpc.simpleTipT', sprintf($themeFile, 'simpleTip'));
707          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
708          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
709          self::addHeaderJS('gpc.simpleTip', GPC_PATH.'js/simpleTip.js', array('jquery.ui.widget'));
710          break;
711      }
712    }
713  }
714
715
716  /**
717   * use the extended description get_user_language_desc() function if exist
718   * otherwise returns the value
719   *
720   * @param String $value : value to translate
721   * @return String : translated value
722   */
723  static public function getUserLanguageDesc($value)
724  {
725    if(function_exists('get_user_language_desc'))
726    {
727      return(get_user_language_desc($value));
728    }
729    else
730    {
731      return($value);
732    }
733  }
734
735
736  /**
737   * remove a path recursively
738   *
739   * @param String $directory : directory to remove
740   * @param Bool $removePath : if set to true, remove the path himself, if set
741   *                           to false, remove only file & sub-directories
742   * @return Bool : true if directory was succesfully removed, otherwise false
743   */
744  static public function rmDir($directory, $removePath=true)
745  {
746    $directory=rtrim($directory, '\/').'/';
747    $returned=true;
748    if(file_exists($directory) and is_dir($directory) and $directory!='./' and $directory!='../')
749    {
750      $dhandle=scandir($directory);
751      foreach($dhandle as $file)
752      {
753        if($file!='.' and $file!='..' )
754        {
755          if(is_dir($directory.$file))
756          {
757            $returned=self::rmDir($directory.$file, true) & $returned;
758          }
759          else
760          {
761            $returned=unlink($directory.$file) & $returned;
762          }
763        }
764      }
765      if($returned and $removePath) $returned=rmdir($directory);
766    }
767    return($returned);
768  }
769
770
771  /**
772   * returns the piwigo system path
773   * @return String
774   */
775  static public function getPiwigoSystemPath()
776  {
777    return(self::$piwigoSystemPath);
778  }
779
780
781 /**
782  * formats a file size into a human readable size
783  *
784  * @param String $format : "A"  : auto
785  *                         "Ai" : auto (io)
786  *                         "O"  : o
787  *                         "K"  : Ko
788  *                         "M"  : Mo
789  *                         "G"  : Go
790  *                         "Ki" : Kio
791  *                         "Mi" : Mio
792  *                         "Gi" : Gio
793  * @param String $thsep : thousand separator
794  * @param Integer $prec : number of decimals
795  * @param Bool $visible : display or not the unit
796  * @return String : a formatted file size
797  */
798 static public function formatOctet($octets, $format="Ai", $thsep="", $prec=2, $visible=true)
799 {
800  if($format=="Ai")
801  {
802   if($octets<1024)
803   { $format="O"; }
804   elseif($octets<1024000)
805   { $format="Ki"; }
806   elseif($octets<1024000000)
807   { $format="Mi"; }
808   else
809   { $format="Gi"; }
810  }
811  elseif($format=="A")
812  {
813   if($octets<1000)
814   { $format="O"; }
815   elseif($octets<1000000)
816   { $format="Ki"; }
817   elseif($octets<1000000000)
818   { $format="Mi"; }
819   else
820   { $format="Gi"; }
821  }
822
823  switch($format)
824  {
825   case "O":
826    $unit="o"; $div=1;
827    break;
828   case "K":
829    $unit="Ko"; $div=1000;
830    break;
831   case "M":
832    $unit="Mo"; $div=1000000;
833    break;
834   case "G":
835    $unit="Go"; $div=1000000000;
836    break;
837   case "Ki":
838    $unit="Kio"; $div=1024;
839    break;
840   case "Mi":
841    $unit="Mio"; $div=1024000;
842    break;
843   case "Gi":
844    $unit="Gio"; $div=1024000000;
845    break;
846  }
847
848  $returned=number_format($octets/$div, $prec, '.', $thsep);
849  if($visible) $returned.=' '.$unit;
850  return($returned);
851 } //function formatOctet
852
853
854} //class
855
856//add_event_handler('loc_begin_page_header', array('GPCCore', 'applyHeaderItems'), 10);
857
858GPCCore::init();
859
860?>
Note: See TracBrowser for help on using the repository browser.