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

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

feature:2436 - Compatibility with Piwigo 2.4

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