Ignore:
Timestamp:
Oct 20, 2010, 11:04:22 PM (14 years ago)
Author:
grum
Message:

fix bug on the rbuilder and migrate ajax call on the gpc ajax manager
fix bug:1945
add some functionnalities

Location:
extensions/GrumPluginClasses/classes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/GrumPluginClasses/classes/CommonPlugin.class.inc.php

    r6975 r7310  
    125125  public function __construct($prefixeTable, $filelocation)
    126126  {
    127     $this->debug_file="debug.txt";
     127    $this->debug_file=GPCCore::getPiwigoSystemPath()."/_data/debug.txt";
    128128
    129129    $this->fileLocation=$filelocation;
  • extensions/GrumPluginClasses/classes/GPCCategorySelector.class.inc.php

    r7175 r7310  
    33 * -----------------------------------------------------------------------------
    44 * class name     : GPCCategorySelector
    5  * class version  : 1.0.0
    6  * plugin version : 3.3.0
    7  * date           : 2010-10-09
     5 * class version  : 1.0.1
     6 * plugin version : 3.3.3
     7 * date           : 2010-10-20
    88 * -----------------------------------------------------------------------------
    99 * author: grum at piwigo.org
     
    1414 *
    1515| release | date       |
    16 | 1.0.0   | 2010/04/18 | * create class
    17 |         |            |
    18 |         |            |
     16| 1.0.0   | 2010/10/09 | * create class
     17|         |            |
     18| 1.0.1   | 2010/10/20 | * fix bug on the private select methods
    1919|         |            |
    2020|         |            |
     
    242242
    243243    $sql="SELECT DISTINCT pct.id, pct.name, pct.global_rank AS rank, pct.status
    244           FROM (".CATEGORIES_TABLE." pct ";
    245 
    246     if($this->options['userMode']==self::USER_MODE_PUBLIC)
    247     {
    248       $sql.=" JOIN ".USER_CACHE_CATEGORIES_TABLE." pucc
    249                 ON (pucc.cat_id = pct.id) AND pucc.user_id='".$user['id']."') ";
    250     }
    251     else
    252     {
    253       $sql.=") ";
    254     }
     244          FROM ".CATEGORIES_TABLE." pct ";
    255245
    256246    switch($this->options['filter'])
     
    260250        break;
    261251      case self::FILTER_ACCESSIBLE :
    262         $sql.=" JOIN (
    263                   SELECT DISTINCT pgat.cat_id AS catId FROM ".GROUP_ACCESS_TABLE." pgat
    264                   UNION DISTINCT
    265                   SELECT DISTINCT puat.cat_id AS catId FROM ".USER_ACCESS_TABLE." puat
    266                      ) pat
    267                 ON (pat.catId = pct.id AND pct.status = 'private') OR (pct.status = 'public') ";
     252        if(!is_admin())
     253        {
     254          $sql.=" JOIN ".USER_CACHE_CATEGORIES_TABLE." pucc
     255                  ON (pucc.cat_id = pct.id) AND pucc.user_id='".$user['id']."' ";
     256        }
     257        else
     258        {
     259          $sql.=" JOIN (
     260                    SELECT DISTINCT pgat.cat_id AS catId FROM ".GROUP_ACCESS_TABLE." pgat
     261                    UNION DISTINCT
     262                    SELECT DISTINCT puat.cat_id AS catId FROM ".USER_ACCESS_TABLE." puat
     263                    UNION DISTINCT
     264                    SELECT DISTINCT pct2.id AS catId FROM ".CATEGORIES_TABLE." pct2 WHERE pct2.status='public'
     265                       ) pat
     266                  ON pat.catId = pct.id ";
     267        }
     268
    268269        break;
    269270    }
  • extensions/GrumPluginClasses/classes/GPCCore.class.inc.php

    r7175 r7310  
    33/* -----------------------------------------------------------------------------
    44  class name     : GPCCore
    5   class version  : 1.3.0
    6   plugin version : 3.3.0
    7   date           : 2010-07-28
     5  class version  : 1.3.1
     6  plugin version : 3.3.2
     7  date           : 2010-10-20
    88  ------------------------------------------------------------------------------
    99  author: grum at piwigo.org
     
    2121|         |            |
    2222| 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
    2331|         |            |
    2432|         |            |
     
    3745    - static function addHeaderCSS
    3846    - static function addHeaderJS
     47    - static function getUserLanguageDesc
     48    - static function getPiwigoSystemPath
     49    - static function formatOctet
    3950   ---------------------------------------------------------------------- */
    4051
     
    4354class GPCCore
    4455{
     56  static private $piwigoSystemPath;
     57
    4558  static public $pluginName = "GPCCore";
    4659  static protected $headerItems = array(
     
    4861    'js'  => array()
    4962  );
     63
     64  static public function init()
     65  {
     66    self::$piwigoSystemPath=dirname(dirname(dirname(dirname(__FILE__))));
     67  }
    5068
    5169  /* ---------------------------------------------------------------------------
     
    328346    global $template;
    329347
     348    if(!isset($template->known_scripts)) $template->known_scripts=array();
     349
    330350    if(!array_key_exists($id,  $template->known_scripts) and !array_key_exists($file, self::$headerItems['js']))
    331351    {
    332      $template->known_scripts[$id]=$url;
     352     $template->known_scripts[$id]=$file;
    333353     self::$headerItems['js'][$id]=$file;
    334354    }
     
    345365    foreach(self::$headerItems['css'] as $file)
    346366    {
    347       $template->block_html_head(null, '<link rel="stylesheet" type="text/css" href="'.$file.'"/>', $template->smarty, $false);
     367      $template->append('head_elements', '<link rel="stylesheet" type="text/css" href="'.$file.'"/>');
    348368    }
    349369
    350370    foreach(self::$headerItems['js'] as $file)
    351371    {
    352       $template->block_html_head(null, '<script type="text/javascript" src="'.$file.'"></script>', $template->smarty, $false);
    353     }
    354   }
     372      $template->append('head_elements', '<script type="text/javascript" src="'.$file.'"></script>');
     373    }
     374  }
     375
     376  /**
     377   * use the extended description get_user_language_desc() function if exist
     378   * otherwise returns the value
     379   *
     380   * @param String $value : value to translate
     381   * @return String : translated value
     382   */
     383  static public function getUserLanguageDesc($value)
     384  {
     385    if(function_exists('get_user_language_desc'))
     386    {
     387      return(get_user_language_desc($value));
     388    }
     389    else
     390    {
     391      return($value);
     392    }
     393  }
     394
     395  /**
     396   * returns the piwigo system path
     397   * @return String
     398   */
     399  static public function getPiwigoSystemPath()
     400  {
     401    return(self::$piwigoSystemPath);
     402  }
     403
     404
     405 /**
     406  * formats a file size into a human readable size
     407  *
     408  * @param String $format : "A"  : auto
     409  *                         "Ai" : auto (io)
     410  *                         "O"  : o
     411  *                         "K"  : Ko
     412  *                         "M"  : Mo
     413  *                         "G"  : Go
     414  *                         "Ki" : Kio
     415  *                         "Mi" : Mio
     416  *                         "Gi" : Gio
     417  * @param String $thsep : thousand separator
     418  * @param Integer $prec : number of decimals
     419  * @param Bool $visible : display or not the unit
     420  * @return String : a formatted file size
     421  */
     422 static public function formatOctet($octets, $format="Ai", $thsep="", $prec=2, $visible=true)
     423 {
     424  if($format=="Ai")
     425  {
     426   if($octets<1024)
     427   { $format="O"; }
     428   elseif($octets<1024000)
     429   { $format="Ki"; }
     430   elseif($octets<1024000000)
     431   { $format="Mi"; }
     432   else
     433   { $format="Gi"; }
     434  }
     435  elseif($format=="A")
     436  {
     437   if($octets<1000)
     438   { $format="O"; }
     439   elseif($octets<1000000)
     440   { $format="Ki"; }
     441   elseif($octets<1000000000)
     442   { $format="Mi"; }
     443   else
     444   { $format="Gi"; }
     445  }
     446
     447  switch($format)
     448  {
     449   case "O":
     450    $unit="o"; $div=1;
     451    break;
     452   case "K":
     453    $unit="Ko"; $div=1000;
     454    break;
     455   case "M":
     456    $unit="Mo"; $div=1000000;
     457    break;
     458   case "G":
     459    $unit="Go"; $div=1000000000;
     460    break;
     461   case "Ki":
     462    $unit="Kio"; $div=1024;
     463    break;
     464   case "Mi":
     465    $unit="Mio"; $div=1024000;
     466    break;
     467   case "Gi":
     468    $unit="Gio"; $div=1024000000;
     469    break;
     470  }
     471
     472  $returned=number_format($octets/$div, $prec, '.', $thsep);
     473  if($visible) $returned.=' '.$unit;
     474  return($returned);
     475 } //function formatOctet
     476
    355477
    356478} //class
    357479
    358 add_event_handler('loc_end_page_header', array('GPCCore', 'applyHeaderItems'));
    359 
     480add_event_handler('loc_begin_page_header', array('GPCCore', 'applyHeaderItems'), 10);
     481
     482GPCCore::init();
    360483
    361484?>
  • extensions/GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php

    r7200 r7310  
    7171|         |            |   . adding 'DISTINCT' keyword to the SQL requests
    7272|         |            |
     73|         |            | * ajax management moved into the gpc_ajax.php file
     74|         |            |
     75|         |            | * fix bug on user level access to picture
    7376|         |            |
    7477|         |            |
     
    7982  --------------------------------------------------------------------------- */
    8083
    81 include_once('GPCAjax.class.inc.php');
    8284include_once('GPCTables.class.inc.php');
    8385
     
    397399  static public function updateTables($pluginPreviousRelease)
    398400  {
     401    $tablef=new GPCTables(array(self::$tables['temp']));
     402
    399403    switch($pluginPreviousRelease)
    400404    {
     
    415419
    416420
    417         $tablef=new GPCTables(array(self::$tables['temp']));
    418421
    419422        $tablef->create($tablesCreate);
     
    459462  static public function loadJSandCSS()
    460463  {
    461     add_event_handler('loc_end_page_header', array('GPCRequestBuilder', 'insertJSandCSSFiles'));
     464    add_event_handler('loc_begin_page_header', array('GPCRequestBuilder', 'insertJSandCSSFiles'), 9);
    462465  }
    463466
     
    466469   * insert JS a CSS file in header
    467470   *
    468    * the function is declared public because it used by the 'loc_end_page_header'
     471   * the function is declared public because it used by the 'loc_begin_page_header'
    469472   * event callback
    470473   *
     
    475478  {
    476479    global $template;
     480
    477481
    478482    $baseName=basename(dirname(dirname(__FILE__))).'/css/';
     
    480484
    481485    $baseName=basename(dirname(dirname(__FILE__))).'/js/';
    482     $template->append('head_elements', '<script type="text/javascript" src="plugins/'.$baseName.'external/interface/interface.js"></script>');
    483     $template->append('head_elements', '<script type="text/javascript" src="plugins/'.$baseName.'external/inestedsortable.pack.js"></script>');
    484     $template->append('head_elements', '<script type="text/javascript" src="plugins/'.$baseName.'criteriaBuilder.packed.js"></script>');
     486    GPCCore::addHeaderJS('jquery', 'themes/default/js/jquery.packed.js');
     487    GPCCore::addHeaderJS('gpc.interface', 'plugins/'.$baseName.'external/interface/interface.js');
     488    GPCCore::addHeaderJS('gpc.inestedsortable', 'plugins/'.$baseName.'external/inestedsortable.pack.js');
     489    GPCCore::addHeaderJS('gpc.criteriaBuilder', 'plugins/'.$baseName.'criteriaBuilder.js');
     490
    485491    $template->append('head_elements',
    486492"<script type=\"text/javascript\">
     
    490496      imgEditUrl:'',
    491497      imgDeleteUrl:'',
    492       ajaxUrl:'admin.php?page=plugin&section=".basename(GPC_DIR)."/admin/plugin_admin.php&searchRequest=',
     498      ajaxUrl:'plugins/GrumPluginClasses/gpc_ajax.php',
    493499  }
    494500</script>");
     
    501507   * @return String : a ready to use HTML code
    502508   */
    503   static public function executeRequest()
    504   {
    505     if(self::checkAjaxRequest())
    506     {
    507       switch($_REQUEST['searchRequest'])
    508       {
    509         case 'execute':
    510           $result=self::doCache();
    511           break;
    512         case 'getPage':
    513           $result=self::getPage($_REQUEST['requestNumber'], $_REQUEST['page'], $_REQUEST['numPerPage']);
    514           break;
    515       }
    516       GPCAjax::returnResult($result);
    517     }
    518     else
    519     {
    520       GPCAjax::returnResult(l10n('gpc_rb_invalid_request'));
    521     }
     509  static public function executeRequest($ajaxfct)
     510  {
     511    switch($ajaxfct)
     512    {
     513      case 'admin.rbuilder.searchExecute':
     514        $result=self::doCache();
     515        break;
     516      case 'admin.rbuilder.searchGetPage':
     517        $result=self::getPage($_REQUEST['requestNumber'], $_REQUEST['page'], $_REQUEST['numPerPage']);
     518        break;
     519    }
     520    return($result);
    522521  }
    523522
     
    566565
    567566    $sql="INSERT INTO ".self::$tables['temp']." ".self::buildGroupRequest($_REQUEST[$_REQUEST['requestName']], $tmpWHERE, $_REQUEST['operator'], ' AND ', $requestNumber);
    568 //echo $sql;
     567
    569568    $result=pwg_query($sql);
    570569
     
    602601      'SELECT' => 'pit.id',
    603602      'FROM' => '',
    604       'WHERE' => '',
     603      'WHERE' => 'pit.level <= '.$user['level'],
    605604      'GROUPBY' => '',
    606605      'FILTER' => '',
     
    13011300
    13021301  /**
    1303    * check if this is a valid ajax request
    1304    *
    1305    * @return Boolean : true if this is a valide ajax request
    1306    */
    1307   static protected function checkAjaxRequest()
    1308   {
    1309     if(isset($_REQUEST['searchRequest']))
    1310     {
    1311       if($_REQUEST['searchRequest']=='execute')
    1312       {
    1313         if(!isset($_REQUEST['requestName'])) return(false);
    1314 
    1315         return(true);
    1316       }
    1317 
    1318       if($_REQUEST['searchRequest']=='getPage')
    1319       {
    1320         if(!isset($_REQUEST['requestNumber'])) return(false);
    1321 
    1322         if(!isset($_REQUEST['page']))
    1323         {
    1324           $_REQUEST['page']=0;
    1325         }
    1326         if($_REQUEST['page']<0) $_REQUEST['page']=0;
    1327 
    1328         if(!isset($_REQUEST['numPerPage']))
    1329         {
    1330           $_REQUEST['numPerPage']=25;
    1331         }
    1332 
    1333         if($_REQUEST['numPerPage']>100) $_REQUEST['numPerPage']=100;
    1334 
    1335         return(true);
    1336       }
    1337 
    1338     }
    1339     return(false);
    1340   }
    1341 
    1342 
    1343 
    1344   /**
    13451302   * display search page
    13461303   *
Note: See TracChangeset for help on using the changeset viewer.