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

Last change on this file since 12215 was 12215, checked in by grum, 13 years ago

fix bugs
bug:2160 - CategorySelector : extended description are not managed
+add some functions to GPCCore

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