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

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

feature:2634- compatibility with Piwigo 2.4
+add some objects on js framework

File size: 41.0 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|         |            | * Add js objects: inputDate, inputFilterBox, inputPages, inputSortBox, inputTag
71|         |            |                   dynamicTable
72|         |            |
73|         |            | * AddHeaderCSS and AddJS are ignored if called in an ajax session (AJAX_CALL defined)
74|         |            |
75|         |            |
76|         |            |
77|         |            |
78
79  ------------------------------------------------------------------------------
80    no constructor, only static function are provided
81    - static function loadConfig
82    - static function loadConfigFromFile
83    - static function saveConfig
84    - static function deleteConfig
85    - static function getRegistered
86    - static function getModulesInfos
87    - static function register
88    - static function unregister
89    - static function BBtoHTML
90    - static function VarToHTML
91    - static function TabsToHTML
92    - static function FormMailToHTML
93    - static function addHeaderCSS
94    - static function addHeaderJS
95    - static function addUI
96    - static function getUserLanguageDesc
97    - static function getPiwigoSystemPath
98    - static function formatOctet
99    - static function rmDir
100    - static function applyMarkups
101    - static function setTemplateToken
102    - static function addHeaderContent
103   ---------------------------------------------------------------------- */
104
105
106
107class GPCCore
108{
109  static private $piwigoSystemPath;
110
111  static public $pluginName = "GPCCore";
112  static protected $headerItems = array(
113    'css' => array(),
114    'js'  => array()
115  );
116
117  static public function init()
118  {
119    global $conf;
120
121    self::$piwigoSystemPath=dirname(dirname(dirname(dirname(__FILE__))));
122
123    if((isset($conf['gpc.markup.bb']) && $conf['gpc.markup.bb']) ||
124       (isset($conf['gpc.markup.var']) && $conf['gpc.markup.var']) ||
125       (isset($conf['gpc.markup.form']) && $conf['gpc.markup.form'])
126      )
127    {
128      add_event_handler('render_category_name', array('GPCCore', 'applyMarkups'), EVENT_HANDLER_PRIORITY_NEUTRAL+5);
129      add_event_handler('render_category_description', array('GPCCore', 'applyMarkups'), EVENT_HANDLER_PRIORITY_NEUTRAL+5, 2);
130      add_event_handler('render_element_description', array('GPCCore', 'applyMarkups'), EVENT_HANDLER_PRIORITY_NEUTRAL+5);
131      add_event_handler('AP_render_content', array('GPCCore', 'applyMarkups'), EVENT_HANDLER_PRIORITY_NEUTRAL+5);
132    }
133  }
134
135  /* ---------------------------------------------------------------------------
136   * grum plugin classes informations functions
137   * -------------------------------------------------------------------------*/
138  static public function getModulesInfos()
139  {
140    return(
141      Array(
142        Array('name' => "CommonPlugin", 'version' => "2.3.0"),
143        Array('name' => "GPCAjax", 'version' => "3.1.0"),
144        Array('name' => "GPCCategorySelector", 'version' => "1.0.1"),
145        Array('name' => "GPCCore", 'version' => "1.4.1"),
146        //Array('name' => "GPCCss", 'version' => "3.1.0"),  removed with v1.4.1
147        Array('name' => "GPCPagesNavigation", 'version' => "2.0.0"),
148        Array('name' => "GPCPublicIntegration", 'version' => "2.0.0"),
149        Array('name' => "GPCRequestBuilder", 'version' => "1.1.7"),
150        Array('name' => "GPCTables", 'version' => "1.5.0"),
151        Array('name' => "GPCTabSheet", 'version' => "1.1.1"),
152        Array('name' => "GPCTranslate", 'version' => "2.1.1"),
153        Array('name' => "GPCUsersGroups", 'version' => "2.1.0"),
154        Array('name' => "GPCUserAgent", 'version' => "1.0.0")
155      )
156    );
157  }
158
159
160  /* ---------------------------------------------------------------------------
161   * register oriented functions
162   * -------------------------------------------------------------------------*/
163
164  /**
165   * register a plugin using GPC
166   *
167   * @param String $pluginName : the plugin name
168   * @param String $release : the plugin version like "2.0.0"
169   * @param String $GPCNeed : the minimal version of GPC needed by the plugin to
170   *                          work
171   * @return Boolean : true if registering is Ok, otherwise false
172   */
173  static public function register($plugin, $release, $GPCneeded)
174  {
175    $config=Array();
176    if(!self::loadConfig(self::$pluginName, $config))
177    {
178      $config['registered']=array();
179    }
180
181    $config['registered'][$plugin]=Array(
182      'name' => $plugin,
183      'release' => $release,
184      'needed' => $GPCneeded,
185      'date' => date("Y-m-d"),
186    );
187    return(self::saveConfig(self::$pluginName, $config));
188  }
189
190  /**
191   * unregister a plugin using GPC
192   *
193   * assume that if the plugin was not registerd before, unregistering returns
194   * a true value
195   *
196   * @param String $pluginName : the plugin name
197   * @return Boolean : true if registering is Ok, otherwise false
198   */
199  static public function unregister($plugin)
200  {
201    $config=Array();
202    if(self::loadConfig(self::$pluginName, $config))
203    {
204      if(array_key_exists('registered', $config))
205      {
206        if(array_key_exists($plugin, $config['registered']))
207        {
208          unset($config['registered'][$plugin]);
209          return(self::saveConfig(self::$pluginName, $config));
210        }
211      }
212    }
213    // assume if the plugin was not registered before, unregistering it is OK
214    return(true);
215  }
216
217  /**
218   * return the list of registered plugins
219   * @return Array : list of registered plugins
220   */
221  static public function getRegistered()
222  {
223    $config=Array();
224    if(self::loadConfig(self::$pluginName, $config))
225    {
226      if(array_key_exists('registered', $config))
227      {
228        return($config['registered']);
229      }
230    }
231    return(Array());
232  }
233
234
235
236  /* ---------------------------------------------------------------------------
237   * config oriented functions
238   * -------------------------------------------------------------------------*/
239
240  /**
241   *  load config from CONFIG_TABLE into an array
242   *
243   * @param String $pluginName : the plugin name, must contain only alphanumerical
244   *                             character
245   * @param Array $config : array, initialized or not with default values ; the
246   *                        config values are loaded in this value
247   * @return Boolean : true if config is loaded, otherwise false
248   */
249  static public function loadConfig($pluginName, &$config=Array())
250  {
251    global $conf;
252
253    if(!isset($conf[$pluginName.'_config']))
254    {
255      return(false);
256    }
257
258    $configValues = unserialize($conf[$pluginName.'_config']);
259    reset($configValues);
260    while (list($key, $val) = each($configValues))
261    {
262      if(is_array($val))
263      {
264        foreach($val as $key2 => $val2)
265        {
266          $config[$key][$key2]=$val2;
267        }
268      }
269      else
270      {
271        $config[$key] =$val;
272      }
273    }
274
275    $conf[$pluginName.'_config']=serialize($config);
276
277    return(true);
278  }
279
280  /**
281   *  load config from a file into an array
282   *
283   *  note : the config file is a PHP file one var $conf used as an array,
284   *  like the piwigo $conf var
285   *
286   * @param String $fileName : the file name
287   * @param Array $config : array, initialized or not with default values ; the
288   *                        config values are loaded in this value
289   * @return Boolean : true if config is loaded, otherwise false
290   */
291  static public function loadConfigFromFile($fileName, &$config=Array())
292  {
293    $conf=array();
294
295    if(!is_array($config) or !file_exists($fileName))
296    {
297      return(false);
298    }
299
300    include_once($fileName);
301
302    foreach($conf as $key=>$val)
303    {
304      $config[$key]=$val;
305    }
306    return(true);
307  }
308
309
310  /**
311   * save var $my_config into CONFIG_TABLE
312   *
313   * @param String $pluginName : the plugin name, must contain only alphanumerical
314   *                             character
315   * @param Array $config : array of configuration values
316   * @return Boolean : true if config is saved, otherwise false
317   */
318  static public function saveConfig($pluginName, $config)
319  {
320    global $conf;
321
322    $sql="REPLACE INTO ".CONFIG_TABLE."
323           VALUES('".$pluginName."_config', '"
324           .pwg_db_real_escape_string(serialize($config))."', '')";
325    $result=pwg_query($sql);
326    if($result)
327    {
328      $conf[$pluginName.'_config']=serialize($config);
329      return true;
330    }
331    else
332    {
333      return false;
334    }
335  }
336
337  /**
338   * delete config from CONFIG_TABLE
339   *
340   * @param String $pluginName : the plugin name, must contain only alphanumerical
341   *                             character ; if empty, assume GPCCore config
342   * @return Boolean : true if config is deleted, otherwise false
343   */
344  static public function deleteConfig($pluginName='')
345  {
346    if($pluginName=='') $pluginName=self::$pluginName;
347    $sql="DELETE FROM ".CONFIG_TABLE."
348          WHERE param='".$pluginName."_config'";
349    $result=pwg_query($sql);
350    if($result)
351    { return true; }
352    else
353    { return false; }
354  }
355
356
357  /**
358   * convert (light) BB tag to HTML tag
359   *
360   * all BB codes are not recognized, only :
361   *  - [ul] [/ul]
362   *  - [li] [/li]
363   *  - [b] [/b]
364   *  - [i] [/i]
365   *  - [url] [/url]
366   *  - carriage return is replaced by a <br>
367   *
368   * @param String $text : text to convert
369   * @return String : BB to HTML text
370   */
371  static public function BBtoHTML($text)
372  {
373    $patterns = Array(
374      '/\[li\](.*?)\[\/li\]\n*/im',
375      '/\[b\](.*?)\[\/b\]/ism',
376      '/\[i\](.*?)\[\/i\]/ism',
377      '/\[p\](.*?)\[\/p\]/ism',
378      '/\[url\]([\w]+?:\/\/[^ \"\n\r\t<]*?)\[\/url\]/ism',
379      '/\[url=([\w]+?:\/\/[^ \"\n\r\t<]*?)\](.*?)\[\/url\]/ism',
380      '/\n{0,1}\[ul\]\n{0,1}/im',
381      '/\n{0,1}\[\/ul\]\n{0,1}/im',
382      '/\n{0,1}\[ol\]\n{0,1}/im',
383      '/\n{0,1}\[\/ol\]\n{0,1}/im',
384      '/\n/im',
385    );
386    $replacements = Array(
387      '<li>\1</li>',
388      '<b>\1</b>',
389      '<i>\1</i>',
390      '<p>\1</p>',
391      '<a href="\1">\1</a>',
392      '<a href="\1">\2</a>',
393      '<ul>',
394      '</ul>',
395      '<ol>',
396      '</ol>',
397      '<br>',
398    );
399
400    return(preg_replace($patterns, $replacements, $text));
401  }
402
403  /**
404   * apply [var] tag
405   *
406   * [var=<name>]
407   * with <name> :
408   *  - USER
409   *  - GALLERY_TITLE
410   *  - NB_PHOTOS
411   *  - CATEGORY
412   *  - TOKEN
413   *  - IP
414   *
415   * @param String $text : text to convert
416   * @return String : processed text
417   */
418  static public function VarToHTML($text)
419  {
420    global $user, $page, $conf;
421
422    $patterns = Array(
423      '/\[var=user\]/im',
424      '/\[var=gallery_title\]/im',
425      '/\[var=nb_photos\]/im',
426      '/\[var=category\]/im',
427      '/\[var=token\]/im',
428      '/\[var=ip\]/im'
429    );
430    $replacements = Array(
431      isset($user['username'])?$user['username']:'',
432      isset($conf['gallery_title'])?$conf['gallery_title']:'',
433      isset($user['nb_total_images'])?$user['nb_total_images']:'',
434      isset($page['category']['name'])?$page['category']['name']:'',
435      get_pwg_token(),
436      $_SERVER['REMOTE_ADDR']
437    );
438
439    return(preg_replace($patterns, $replacements, $text));
440  }
441
442  /**
443   * apply [form_mail] tag
444   *
445   * @param String $text : text to convert
446   * @return String : processed text
447   */
448  static public function FormMailToHTML($text)
449  {
450    global $template;
451
452    $file=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.'templates/GPCFormMsg.tpl';
453    if(!file_exists($file)) $file=dirname(dirname(__FILE__))."/templates/GPCFormMsg.tpl";
454
455    $template->set_filename('gpc_form', $file);
456
457    $template->assign('token', get_pwg_token() );
458
459    $patterns = Array(
460      '/\[form_mail\]/im'
461    );
462    $replacements = Array(
463      $template->parse('gpc_form', true)
464    );
465
466    if(preg_match($patterns[0], $text)>0)
467    {
468      GPCCore::addHeaderJS('gpc.markup.formMail', GPC_PATH.'js/markup.formMail.js', array('jquery'));
469      return(preg_replace($patterns, $replacements, $text));
470    }
471    return($text);
472  }
473
474  /**
475   * apply [tab], [/tab] and [tabs] tags
476   *
477   * @param String $text : text to convert
478   * @return String : processed text
479   */
480  static public function TabsToHTML($text)
481  {
482    $result=array();
483
484    $tabs='';
485    if(preg_match_all('/\[tab=([^(;\]).]*)(?:;(default))?;([^\].]*)\]/im', $text, $result, PREG_SET_ORDER)>0)
486    {
487      foreach($result as $val)
488      {
489        $tabs.="<li class='gpcTabSeparator'><a id='iGpcTab".$val[1]."' class='".($val[2]=='default'?'gpcTabSelected':'gpcTabNotSelected')."' tabId='#iGpcTabContent".$val[1]."'>".$val[3]."</a></li>";
490      }
491      $tabs="<div id='iGpcTabs'><ul>".$tabs."</ul></div>";
492    }
493    else return($text);
494
495    $patterns = Array(
496      '/\[tabs\]/im',
497      '/\[tab=([^(;\]).]*)(?!;default);.*\]/im',
498      '/\[tab=([^(;\]).]*);default;(.*)\]/im',
499      '/\[\/tab\]/im'
500    );
501    $replacements = Array(
502      $tabs,
503      '<div id="iGpcTabContent\1" class="gpcTabContent" style="display:none;">',
504      '<div id="iGpcTabContent\1" class="gpcTabContent">',
505      '</div>'
506    );
507
508    if(preg_match($patterns[0], $text)>0)
509    {
510      GPCCore::addHeaderJS('gpc.markup.tabs', GPC_PATH.'js/markup.tabs.js', array('jquery'));
511      GPCCore::addHeaderCSS('gpc.markup.tabs', GPC_PATH.'css/gpcTabs.css');
512      return(preg_replace($patterns, $replacements, $text));
513    }
514    return($text);
515  }
516
517  /**
518   * analyze and replace markups by their value, according to $conf parameted
519   * @param String $text: text to analyze
520   * @return String: analyzed text
521   */
522  static public function applyMarkups($text)
523  {
524    global $conf;
525
526    if(isset($conf['gpc.markup.form']) && $conf['gpc.markup.form'])
527    {
528      $text=GPCCore::FormMailToHTML($text);
529    }
530
531    if(isset($conf['gpc.markup.tabs']) && $conf['gpc.markup.tabs'])
532    {
533      $text=GPCCore::TabsToHTML($text);
534    }
535
536    if(isset($conf['gpc.markup.var']) && $conf['gpc.markup.var'])
537    {
538      $text=GPCCore::VarToHTML($text);
539    }
540
541    if(isset($conf['gpc.markup.bb']) && $conf['gpc.markup.bb'])
542    {
543      $text=GPCCore::BBtoHTML($text);
544    }
545
546
547    return($text);
548  }
549
550  /**
551   * used to add a js or css directly in the header
552   *
553   * @param String $id : a unique id for the file
554   * @param String $file : the css file
555   * @param String $order: priority
556   */
557  static public function addHeaderContent($type, $content)
558  {
559    global $template;
560    $null=null;
561
562    if(defined('AJAX_CALL')) return(false); // not needed for an ajax call
563
564    switch($type)
565    {
566      case 'css':
567        $template->block_html_style(null, $content, $null, $null);
568        break;
569      case 'js':
570        $template->block_html_head(null, '<script type="text/javascript">'.$content.'</script>', $null, $null);
571        break;
572    }
573  }
574
575  /**
576   * used to add a css file in the header
577   *
578   * @param String $id : a unique id for the file
579   * @param String $file : the css file
580   * @param String $order: priority
581   */
582  static public function addHeaderCSS($id, $file, $order=0)
583  {
584    global $template;
585
586    if(defined('AJAX_CALL')) return(false); // no CSS needed for an ajax call
587    if(!array_key_exists($id, self::$headerItems['css']) and file_exists($file))
588    {
589      self::$headerItems['css'][$id]=$file;
590      $template->func_combine_css(array('path'=>$file, 'order'=>$order), $template->smarty);
591    }
592  }
593
594  /**
595   * used to add a js file in the header
596   *
597   * @param String $id : a unique id for the file
598   * @param String $file : the js file
599   * @param Array $require : list of required files
600   */
601  static public function addHeaderJS($id, $file, $require=array())
602  {
603    global $template;
604
605    if(defined('AJAX_CALL')) return(false); // no JS needed for an ajax call
606    if(!array_key_exists($id, self::$headerItems['js']) and file_exists($file))
607    {
608      self::$headerItems['js'][$id]=$file;
609      $template->scriptLoader->add($id, 'header', $require, $file, 0);
610    }
611  }
612
613  /**
614   * add a ui component ; css & js dependencies are managed
615   *
616   * @param Array $list : possibles values are
617   *                        - categorySelector
618   *                        - dynamicTable
619   *                        - inputCheckbox
620   *                        - inputColorPicker
621   *                        - inputColorsFB
622   *                        - inputConsole
623   *                        - inputDate
624   *                        - inputDotArea
625   *                        - inputFilterBox
626   *                        - inputList
627   *                        - inputNum
628   *                        - inputPosition
629   *                        - inputRadio
630   *                        - inputSortBox
631   *                        - inputStatusBar
632   *                        - inputTag
633   *                        - inputText
634   */
635  static public function addUI($list)
636  {
637    global $template;
638
639    if(is_string($list)) $list=explode(',', $list);
640    if(!is_array($list)) return(false);
641
642    if(defined('IN_ADMIN'))
643    {
644      $themeFile=GPC_PATH.'css/%s_'.$template->get_themeconf('name').'.css';
645    }
646    else
647    {
648      $themeFile='themes/'.$template->get_themeconf('name').'/css/GPC%s.css';
649    }
650
651    foreach($list as $ui)
652    {
653      switch($ui)
654      {
655        case 'gpcCSS':
656          $fileName='./plugins/'.basename(dirname(dirname(__FILE__))).'/css/gpc';
657          self::addHeaderCSS('gpc.css', $fileName.'.css', 10);
658          self::addHeaderCSS('gpc.cssT', $fileName.'_'.$template->get_themeconf('name').'.css', 15);
659          break;
660        case 'categorySelector':
661          self::addHeaderCSS('gpc.categorySelector', GPC_PATH.'css/categorySelector.css');
662          self::addHeaderCSS('gpc.categorySelectorT', sprintf($themeFile, 'categorySelector'));
663          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
664          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
665          self::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
666          self::addHeaderJS('gpc.categorySelector', GPC_PATH.'js/ui.categorySelector.js', array('jquery.ui.widget'));
667          break;
668        case 'inputCheckbox':
669          self::addHeaderCSS('gpc.inputCheckbox', GPC_PATH.'css/inputCheckbox.css');
670          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
671          self::addHeaderJS('gpc.inputCheckbox', GPC_PATH.'js/ui.inputCheckbox.js', array('jquery.ui'));
672          break;
673        case 'inputColorPicker':
674          self::addHeaderCSS('gpc.inputText', GPC_PATH.'css/inputText.css');
675          self::addHeaderCSS('gpc.inputNum', GPC_PATH.'css/inputNum.css');
676          self::addHeaderCSS('gpc.inputColorsFB', GPC_PATH.'css/inputColorsFB.css');
677          self::addHeaderCSS('gpc.inputDotArea', GPC_PATH.'css/inputDotArea.css');
678          self::addHeaderCSS('gpc.inputColorPicker', GPC_PATH.'css/inputColorPicker.css');
679          self::addHeaderCSS('gpc.inputTextT', sprintf($themeFile, 'inputText'));
680          self::addHeaderCSS('gpc.inputNumT', sprintf($themeFile, 'inputNum'));
681          self::addHeaderCSS('gpc.inputColorsFBT', sprintf($themeFile, 'inputColorsFB'));
682          self::addHeaderCSS('gpc.inputDotAreaT', sprintf($themeFile, 'inputDotArea'));
683          self::addHeaderCSS('gpc.inputColorPickerT', sprintf($themeFile, 'inputColorPicker'));
684          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
685          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
686          self::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
687          self::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery.ui.widget'));
688          self::addHeaderJS('jquery.ui.draggable', 'themes/default/js/ui/jquery.ui.draggable.js', array('jquery.ui.widget'));
689          self::addHeaderJS('jquery.ui.dialog', 'themes/default/js/ui/jquery.ui.dialog.js', array('jquery.ui.widget'));
690          self::addHeaderJS('jquery.ui.slider', 'themes/default/js/ui/jquery.ui.slider.js', array('jquery.ui.widget'));
691          self::addHeaderJS('gpc.inputText', GPC_PATH.'js/ui.inputText.js', array('jquery.ui.widget'));
692          self::addHeaderJS('gpc.inputNum', GPC_PATH.'js/ui.inputNum.js', array('jquery.ui.widget'));
693          self::addHeaderJS('gpc.inputColorsFB', GPC_PATH.'js/ui.inputColorsFB.js', array('jquery.ui.widget'));
694          self::addHeaderJS('gpc.inputDotArea', GPC_PATH.'js/ui.inputDotArea.js', array('jquery.ui.widget'));
695          self::addHeaderJS('gpc.inputColorPicker', GPC_PATH.'js/ui.inputColorPicker.js', array('jquery.ui.slider','gpc.inputText','gpc.inputNum','gpc.inputColorsFB','gpc.inputDotArea'));
696          break;
697        case 'inputColorsFB':
698          self::addHeaderCSS('gpc.inputColorsFB', GPC_PATH.'css/inputColorsFB.css');
699          self::addHeaderCSS('gpc.inputColorsFBT', sprintf($themeFile, 'inputColorsFB'));
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.inputColorsFB', GPC_PATH.'js/ui.inputColorsFB.js', array('jquery.ui.widget'));
703          break;
704        case 'inputConsole':
705          self::addHeaderCSS('gpc.inputConsole', GPC_PATH.'css/inputConsole.css');
706          self::addHeaderCSS('gpc.inputConsoleT', sprintf($themeFile, 'inputConsole'));
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.inputConsole', GPC_PATH.'js/ui.inputConsole.js', array('jquery.ui.widget'));
710          break;
711        case 'inputDate':
712          self::addHeaderCSS('gpc.inputDate', GPC_PATH.'css/inputDate.css');
713          self::addHeaderCSS('gpc.inputDateT', sprintf($themeFile, 'inputDate'));
714          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
715          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
716          self::addHeaderJS('jquery.ui.datepicker', 'themes/default/js/ui/jquery.ui.datepicker.js', array('jquery.ui.widget'));
717          self::addHeaderJS('gpc.inputDate', GPC_PATH.'js/ui.inputDate.js', array('jquery.ui.widget'));
718          break;
719        case 'inputDotArea':
720          self::addHeaderCSS('gpc.inputDotArea', GPC_PATH.'css/inputDotArea.css');
721          self::addHeaderCSS('gpc.inputDotAreaT', sprintf($themeFile, 'inputDotArea'));
722          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
723          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
724          self::addHeaderJS('gpc.inputDotArea', GPC_PATH.'js/ui.inputDotArea.js', array('jquery.ui.widget'));
725          break;
726        case 'inputFilterBox':
727          self::addHeaderCSS('gpc.inputNum', GPC_PATH.'css/inputNum.css');
728          self::addHeaderCSS('gpc.inputNumT', sprintf($themeFile, 'inputNum'));
729          self::addHeaderCSS('gpc.inputDate', GPC_PATH.'css/inputDate.css');
730          self::addHeaderCSS('gpc.inputDateT', sprintf($themeFile, 'inputDate'));
731          self::addHeaderCSS('gpc.inputText', GPC_PATH.'css/inputText.css');
732          self::addHeaderCSS('gpc.inputTextT', sprintf($themeFile, 'inputText'));
733          self::addHeaderCSS('gpc.inputList', GPC_PATH.'css/inputList.css');
734          self::addHeaderCSS('gpc.inputListT', sprintf($themeFile, 'inputList'));
735          self::addHeaderCSS('gpc.inputFilterBox', GPC_PATH.'css/inputFilterBox.css');
736          self::addHeaderCSS('gpc.inputFilterBoxT', sprintf($themeFile, 'inputFilterBox'));
737
738          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
739          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
740
741          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
742          self::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
743          self::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery.ui.mouse'));
744          self::addHeaderJS('jquery.ui.resizable', 'themes/default/js/ui/jquery.ui.resizable.js', array('jquery.ui.position'));
745          self::addHeaderJS('jquery.ui.draggable', 'themes/default/js/ui/jquery.ui.draggable.js', array('jquery.ui.resizable'));
746          self::addHeaderJS('jquery.ui.sortable', 'themes/default/js/ui/jquery.ui.sortable.js', array('jquery.ui.draggable'));
747          self::addHeaderJS('jquery.ui.dialog', 'themes/default/js/ui/jquery.ui.dialog.js', array('jquery.ui.sortable'));
748
749          self::addHeaderJS('gpc.inputNum', GPC_PATH.'js/ui.inputNum.js', array('jquery.ui.dialog'));
750          self::addHeaderJS('gpc.inputList', GPC_PATH.'js/ui.inputList.js', array('jquery.ui.dialog'));
751          self::addHeaderJS('gpc.inputText', GPC_PATH.'js/ui.inputText.js', array('jquery.ui.dialog'));
752          self::addHeaderJS('gpc.inputDate', GPC_PATH.'js/ui.inputDate.js', array('jquery.ui.dialog'));
753          self::addHeaderJS('gpc.inputFilterBox', GPC_PATH.'js/ui.inputFilterBox.js', array('jquery.ui.dialog'));
754          break;
755        case 'inputList':
756          self::addHeaderCSS('gpc.inputList', GPC_PATH.'css/inputList.css');
757          self::addHeaderCSS('gpc.inputListT', sprintf($themeFile, 'inputList'));
758          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
759          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
760          self::addHeaderJS('gpc.inputList', GPC_PATH.'js/ui.inputList.js', array('jquery.ui.widget'));
761          break;
762        case 'inputNum':
763          self::addHeaderCSS('gpc.inputNum', GPC_PATH.'css/inputNum.css');
764          self::addHeaderCSS('gpc.inputNumT', sprintf($themeFile, 'inputNum'));
765          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
766          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
767          self::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
768          self::addHeaderJS('jquery.ui.slider', 'themes/default/js/ui/jquery.ui.slider.js', array('jquery.ui.widget'));
769          self::addHeaderJS('gpc.inputNum', GPC_PATH.'js/ui.inputNum.js', array('jquery','jquery.ui.slider'));
770          break;
771        case 'inputPages':
772          self::addHeaderCSS('gpc.inputPages', GPC_PATH.'css/inputPages.css');
773          self::addHeaderCSS('gpc.inputPagesT', sprintf($themeFile, 'inputPages'));
774          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
775          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
776          self::addHeaderJS('gpc.inputPages', GPC_PATH.'js/ui.inputPages.js', array('jquery','jquery.ui.widget'));
777          break;
778        case 'inputPosition':
779          self::addHeaderCSS('gpc.inputPosition', GPC_PATH.'css/inputPosition.css');
780          self::addHeaderCSS('gpc.inputPositionT', sprintf($themeFile, 'inputPosition'));
781          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
782          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
783          self::addHeaderJS('gpc.inputPosition', GPC_PATH.'js/ui.inputPosition.js', array('jquery.ui.widget'));
784          break;
785        case 'inputRadio':
786          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
787          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
788          self::addHeaderJS('gpc.inputRadio', GPC_PATH.'js/ui.inputRadio.js', array('jquery.ui.widget'));
789          break;
790        case 'inputSortBox':
791          self::addHeaderCSS('gpc.inputSortBox', GPC_PATH.'css/inputSortBox.css');
792          self::addHeaderCSS('gpc.inputSortBoxT', sprintf($themeFile, 'inputSortBox'));
793          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
794          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
795          self::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
796          self::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery.ui.mouse'));
797          self::addHeaderJS('jquery.ui.draggable', 'themes/default/js/ui/jquery.ui.draggable.js', array('jquery.ui.position'));
798          self::addHeaderJS('jquery.ui.sortable', 'themes/default/js/ui/jquery.ui.sortable.js', array('jquery.ui.draggable'));
799          self::addHeaderJS('jquery.ui.dialog', 'themes/default/js/ui/jquery.ui.dialog.js', array('jquery.ui.sortable'));
800          self::addHeaderJS('gpc.inputSortBox', GPC_PATH.'js/ui.inputSortBox.js', array('jquery.ui.dialog'));
801          break;
802        case 'inputStatusBar':
803          self::addHeaderCSS('gpc.inputStatusBar', GPC_PATH.'css/inputStatusBar.css');
804          self::addHeaderCSS('gpc.inputStatusBarT', sprintf($themeFile, 'inputStatusBar'));
805          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
806          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
807          self::addHeaderJS('gpc.inputStatusBar', GPC_PATH.'js/ui.inputStatusBar.js', array('jquery.ui.widget'));
808          break;
809        case 'inputSwitchButton':
810          self::addHeaderCSS('gpc.inputSwitchButton', GPC_PATH.'css/inputSwitchButton.css');
811          self::addHeaderCSS('gpc.inputSwitchButtonT', sprintf($themeFile, 'inputSwitchButton'));
812          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
813          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
814          self::addHeaderJS('gpc.inputSwitchButton', GPC_PATH.'js/ui.inputSwitchButton.js', array('jquery.ui.widget'));
815          break;
816        case 'inputTag':
817          self::addHeaderCSS('gpc.inputTag', GPC_PATH.'css/inputTag.css');
818          self::addHeaderCSS('gpc.inputTagT', sprintf($themeFile, 'inputTag'));
819          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
820          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
821          self::addHeaderJS('gpc.inputTag', GPC_PATH.'js/ui.inputTag.js', array('jquery.ui.widget'));
822          break;
823        case 'inputText':
824          self::addHeaderCSS('gpc.inputText', GPC_PATH.'css/inputText.css');
825          self::addHeaderCSS('gpc.inputTextT', sprintf($themeFile, 'inputText'));
826          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
827          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
828          self::addHeaderJS('gpc.inputText', GPC_PATH.'js/ui.inputText.js', array('jquery.ui.widget'));
829          break;
830        case 'simpleTip':
831          self::addHeaderCSS('gpc.simpleTip', GPC_PATH.'css/simpleTip.css');
832          self::addHeaderCSS('gpc.simpleTipT', sprintf($themeFile, 'simpleTip'));
833          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
834          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
835          self::addHeaderJS('gpc.simpleTip', GPC_PATH.'js/simpleTip.js', array('jquery.ui.widget'));
836          break;
837        case 'dynamicTable':
838          self::addHeaderCSS('gpc.inputNum', GPC_PATH.'css/inputNum.css');
839          self::addHeaderCSS('gpc.inputNumT', sprintf($themeFile, 'inputNum'));
840          self::addHeaderCSS('gpc.inputDate', GPC_PATH.'css/inputDate.css');
841          self::addHeaderCSS('gpc.inputDateT', sprintf($themeFile, 'inputDate'));
842          self::addHeaderCSS('gpc.inputText', GPC_PATH.'css/inputText.css');
843          self::addHeaderCSS('gpc.inputTextT', sprintf($themeFile, 'inputText'));
844          self::addHeaderCSS('gpc.inputList', GPC_PATH.'css/inputList.css');
845          self::addHeaderCSS('gpc.inputListT', sprintf($themeFile, 'inputList'));
846          self::addHeaderCSS('gpc.inputSortBox', GPC_PATH.'css/inputSortBox.css');
847          self::addHeaderCSS('gpc.inputSortBoxT', sprintf($themeFile, 'inputSortBox'));
848          self::addHeaderCSS('gpc.inputFilterBox', GPC_PATH.'css/inputFilterBox.css');
849          self::addHeaderCSS('gpc.inputFilterBoxT', sprintf($themeFile, 'inputFilterBox'));
850          self::addHeaderCSS('gpc.inputPages', GPC_PATH.'css/inputPages.css');
851          self::addHeaderCSS('gpc.inputPagesT', sprintf($themeFile, 'inputPages'));
852          self::addHeaderCSS('gpc.inputDynamicTable', GPC_PATH.'css/inputDynamicTable.css');
853          self::addHeaderCSS('gpc.inputDynamicTableT', sprintf($themeFile, 'inputDynamicTable'));
854
855          self::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
856          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
857
858          self::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
859          self::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
860          self::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery.ui.mouse'));
861          self::addHeaderJS('jquery.ui.resizable', 'themes/default/js/ui/jquery.ui.resizable.js', array('jquery.ui.position'));
862          self::addHeaderJS('jquery.ui.draggable', 'themes/default/js/ui/jquery.ui.draggable.js', array('jquery.ui.resizable'));
863          self::addHeaderJS('jquery.ui.sortable', 'themes/default/js/ui/jquery.ui.sortable.js', array('jquery.ui.draggable'));
864          self::addHeaderJS('jquery.ui.dialog', 'themes/default/js/ui/jquery.ui.dialog.js', array('jquery.ui.sortable'));
865
866          self::addHeaderJS('gpc.inputNum', GPC_PATH.'js/ui.inputNum.js', array('jquery.ui.dialog'));
867          self::addHeaderJS('gpc.inputList', GPC_PATH.'js/ui.inputList.js', array('jquery.ui.dialog'));
868          self::addHeaderJS('gpc.inputText', GPC_PATH.'js/ui.inputText.js', array('jquery.ui.dialog'));
869          self::addHeaderJS('gpc.inputDate', GPC_PATH.'js/ui.inputDate.js', array('jquery.ui.dialog'));
870          self::addHeaderJS('gpc.inputFilterBox', GPC_PATH.'js/ui.inputFilterBox.js', array('jquery.ui.dialog'));
871          self::addHeaderJS('gpc.inputSortBox', GPC_PATH.'js/ui.inputSortBox.js', array('jquery.ui.dialog'));
872          self::addHeaderJS('gpc.inputPages', GPC_PATH.'js/ui.inputPages.js', array('jquery.ui.dialog'));
873          self::addHeaderJS('gpc.dynamicTable', GPC_PATH.'js/ui.dynamicTable.js', array('jquery.ui.dialog'));
874          break;
875      }
876    }
877  }
878
879
880  /**
881   * use the extended description get_user_language_desc() function if exist
882   * otherwise returns the value
883   *
884   * @param String $value : value to translate
885   * @return String : translated value
886   */
887  static public function getUserLanguageDesc($value)
888  {
889    if(function_exists('get_user_language_desc'))
890    {
891      return(get_user_language_desc($value));
892    }
893    else
894    {
895      return($value);
896    }
897  }
898
899
900  /**
901   * remove a path recursively
902   *
903   * @param String $directory : directory to remove
904   * @param Bool $removePath : if set to true, remove the path himself, if set
905   *                           to false, remove only file & sub-directories
906   * @return Bool : true if directory was succesfully removed, otherwise false
907   */
908  static public function rmDir($directory, $removePath=true)
909  {
910    $directory=rtrim($directory, '\/').'/';
911    $returned=true;
912    if(file_exists($directory) and is_dir($directory) and $directory!='./' and $directory!='../')
913    {
914      $dhandle=scandir($directory);
915      foreach($dhandle as $file)
916      {
917        if($file!='.' and $file!='..' )
918        {
919          if(is_dir($directory.$file))
920          {
921            $returned=self::rmDir($directory.$file, true) & $returned;
922          }
923          else
924          {
925            $returned=unlink($directory.$file) & $returned;
926          }
927        }
928      }
929      if($returned and $removePath) $returned=rmdir($directory);
930    }
931    return($returned);
932  }
933
934
935  /**
936   * returns the piwigo system path
937   * @return String
938   */
939  static public function getPiwigoSystemPath()
940  {
941    return(self::$piwigoSystemPath);
942  }
943
944
945 /**
946  * formats a file size into a human readable size
947  *
948  * @param String $format : "A"  : auto
949  *                         "Ai" : auto (io)
950  *                         "O"  : o
951  *                         "K"  : Ko
952  *                         "M"  : Mo
953  *                         "G"  : Go
954  *                         "Ki" : Kio
955  *                         "Mi" : Mio
956  *                         "Gi" : Gio
957  * @param String $thsep : thousand separator
958  * @param Integer $prec : number of decimals
959  * @param Bool $visible : display or not the unit
960  * @return String : a formatted file size
961  */
962 static public function formatOctet($octets, $format="Ai", $thsep="", $prec=2, $visible=true)
963 {
964  if($format=="Ai")
965  {
966   if($octets<1024)
967   { $format="O"; }
968   elseif($octets<1024000)
969   { $format="Ki"; }
970   elseif($octets<1024000000)
971   { $format="Mi"; }
972   else
973   { $format="Gi"; }
974  }
975  elseif($format=="A")
976  {
977   if($octets<1000)
978   { $format="O"; }
979   elseif($octets<1000000)
980   { $format="Ki"; }
981   elseif($octets<1000000000)
982   { $format="Mi"; }
983   else
984   { $format="Gi"; }
985  }
986
987  switch($format)
988  {
989   case "O":
990    $unit="o"; $div=1;
991    break;
992   case "K":
993    $unit="Ko"; $div=1000;
994    break;
995   case "M":
996    $unit="Mo"; $div=1000000;
997    break;
998   case "G":
999    $unit="Go"; $div=1000000000;
1000    break;
1001   case "Ki":
1002    $unit="Kio"; $div=1024;
1003    break;
1004   case "Mi":
1005    $unit="Mio"; $div=1024000;
1006    break;
1007   case "Gi":
1008    $unit="Gio"; $div=1024000000;
1009    break;
1010  }
1011
1012  $returned=number_format($octets/$div, $prec, '.', $thsep);
1013  if($visible) $returned.=' '.$unit;
1014  return($returned);
1015 } //function formatOctet
1016
1017
1018 /**
1019  * affect a valid token in a template var {$token}
1020  */
1021 static public function setTemplateToken()
1022 {
1023   global $template;
1024
1025   $template->assign('token', get_pwg_token());
1026 }
1027
1028
1029} //class
1030
1031GPCCore::init();
1032
1033?>
Note: See TracBrowser for help on using the repository browser.