Luxbum.net - Script de galerie photo

Changeset 201

Show
Ignore:
Timestamp:
05/20/07 19:51:29 (2 years ago)
Author:
nicolas
Message:

php4 to php5
add a part of Pluf framework : Template & view model
rewrite of the entire ui/view part
some work with xdebug profiling to enhance performances
selection system is complete : download selection, selection on first
page

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/.htaccess.rewrite

    r189 r201  
    11RewriteEngine on 
    22 
    3 RewriteRule ^(image|album|folder|meta|photo|comments|slide\-show|private|file)/(.*)$ /index.php?/$1/$2 
     3RewriteRule ^(flv|flvdl|image|album|folder|meta|photo|comments|slide\-show|private)/(.*)$ /index.php?/$1/$2 
    44 
     5RewriteRule ^(select|unselect|selectiong|deleteselection|downloadselection)/(.*)$ /index.php?/$1/$2 
    56 
    67RewriteRule ^(.*)/_javascript/(.*)$ /_javascript/$2 [L] 
    78RewriteRule ^(.*)/templates/(.*)$ /templates/$2 [L] 
    89 
     10 
  • trunk/api/Pluf/HTTP.php

    r194 r201  
    5656        } 
    5757    } 
     58     
     59     
    5860} 
    5961 
  • trunk/api/inc/HTTP.php

    r194 r201  
    11<?php 
    2 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 
    3 /* 
    4 # ***** BEGIN LICENSE BLOCK ***** 
    5 # This file is part of Plume Framework, a simple PHP Application Framework. 
    6 # Copyright (C) 2001-2006 Loic d'Anterroches and contributors. 
    7 # 
    8 # Plume Framework is free software; you can redistribute it and/or modify 
    9 # it under the terms of the GNU Lesser General Public License as published by 
    10 # the Free Software Foundation; either version 2.1 of the License, or 
    11 # (at your option) any later version. 
    12 # 
    13 # Plume Framework is distributed in the hope that it will be useful, 
    14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
    15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    16 # GNU Lesser General Public License for more details. 
    17 # 
    18 # You should have received a copy of the GNU Lesser General Public License 
    19 # along with this program; if not, write to the Free Software 
    20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    21 # 
    22 # ***** END LICENSE BLOCK ***** */ 
    232 
    243/** 
    25  * Base HTTP tools. 
     4 *  
    265 */ 
    27 class Pluf_HTTP 
    28 
    29  
    30     /** 
    31      * Break magic_quotes 
    32      * 
    33      * @credit Olivier Meunier 
    34      */ 
    35     function removeTheMagic() 
    36     { 
    37         if (get_magic_quotes_gpc()) { 
    38             if (!empty($_GET)) { 
    39                 array_walk($_GET, 'Pluf_HTTP_magicStrip'); 
    40             } 
    41             if (!empty($_POST)) { 
    42                 array_walk($_POST, 'Pluf_HTTP_magicStrip'); 
    43             } 
    44             if (!empty($_REQUEST)) { 
    45                 array_walk($_REQUEST, 'Pluf_HTTP_magicStrip'); 
    46             } 
    47             if (!empty($_COOKIE)) { 
    48                 array_walk($_COOKIE, 'Pluf_HTTP_magicStrip'); 
    49             } 
    50         } 
    51         if (function_exists('ini_set')) { 
    52             @ini_set('session.use_cookies', '1'); 
    53             @ini_set('session.use_only_cookies', '1'); 
    54             @ini_set('session.use_trans_sid', '0'); 
    55             @ini_set('url_rewriter.tags', ''); 
    56         } 
    57     } 
    58 
    59  
    60  
    61 /** 
    62  * Break magic_quotes 
    63  * 
    64  * @credit Olivier Meunier 
    65  */ 
    66 function Pluf_HTTP_magicStrip(&$k, $key) 
    67 
    68     $k = Pluf_HTTP_handleMagicQuotes($k); 
    69 
    70  
    71 /** 
    72  * Break magic_quotes 
    73  * 
    74  * @credit Olivier Meunier 
    75  */ 
    76 function Pluf_HTTP_handleMagicQuotes(&$value) 
    77 
    78     if (is_array($value)) { 
    79         $result = array(); 
    80         foreach ($value as $k => $v) { 
    81             if (is_array($v)) { 
    82                 $result[$k] = Pluf_HTTP_handleMagicQuotes($v); 
    83             } else { 
    84                 $result[$k] = stripslashes($v); 
    85             } 
    86         } 
    87         return $result; 
    88     } else { 
    89         return stripslashes($value); 
    90     } 
     6abstract class HTTP { 
     7   /** 
     8    * Return a date and time string that is conformant to RFC 2616 
     9    * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3 
     10    * 
     11    * @param int $time the unix timestamp of the date we want to return, 
     12    *                empty if we want the current time 
     13    * @return string a date-string conformant to the RFC 2616 
     14    */ 
     15   static function getHttpDate($time='') { 
     16      if ($time == '') { 
     17         $time = time(); 
     18      } 
     19      /* Use fixed list of weekdays and months, so we don't have to fiddle with locale stuff */ 
     20      $months = array('01' => 'Jan', '02' => 'Feb', '03' => 'Mar', 
     21                      '04' => 'Apr', '05' => 'May', '06' => 'Jun', 
     22                      '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', 
     23                      '10' => 'Oct', '11' => 'Nov', '12' => 'Dec'); 
     24      $weekdays = array('1' => 'Mon', '2' => 'Tue', '3' => 'Wed', 
     25                      '4' => 'Thu', '5' => 'Fri', '6' => 'Sat', 
     26                      '0' => 'Sun'); 
     27      $dow = $weekdays[gmstrftime('%w', $time)]; 
     28      $month = $months[gmstrftime('%m', $time)]; 
     29      $out = gmstrftime('%%s, %d %%s %Y %H:%M:%S GMT', $time); 
     30      return sprintf($out, $dow, $month); 
     31   } 
    9132} 
    9233 
  • trunk/api/inc/Recordset.php

    r179 r201  
    1212# 
    1313# Contributor(s): 
    14 #    Loïc d'Anterroches 
     14#    Loïc d'Anterroches 
    1515*/ 
    1616 
     
    1818   * @package inc 
    1919   */ 
    20 class Recordset2 
     20class inc_Recordset implements  Iterator  
    2121{ 
    2222   var $arrayField = array(); 
     
    2424   var $arrayList = array(); // tableau contenant la liste 
    2525   var $intIndex; //index pour parcourir les enregistrements 
    26    var $intRowCount=0; // nombre d'enregistrements 
     26   private $intRowCount=0; // nombre d'enregistrements 
    2727   var $endOfPage=-1; 
    2828   var $startOfPage=-1; 
     
    3030 
    3131 
    32    function recordset2() { 
     32   function inc_Recordset() { 
    3333      $this->intIndex = 0; 
    3434   } 
     
    7777   /** 
    7878    * Get the current row of data. 
     79    * @return CommonFile 
    7980    */ 
    8081   function f() { 
    81       if (/*!$this->EOP() && */!$this->BOF() && !$this->EOF()) { 
     82      //if (/*!$this->EOP() && */!$this->BOF() && !$this->EOF()) { 
    8283         return $this->arrayList[$this->intIndex]; 
    83      
    84       return false; 
     84      //
     85      //return false; 
    8586   } 
    8687 
     
    9798   function moveStart() { 
    9899      $this->intIndex = 0; 
     100      return true; 
     101   } 
     102 
     103   function moveStartPage() { 
     104      if ($this->startOfPage == -1) { 
     105         $this->intIndex = 0; 
     106      } 
     107      else { 
     108         $this->intIndex = $this->startOfPage; 
     109      } 
    99110      return true; 
    100111   } 
     
    163174      reset ($this->arrayList); 
    164175   } 
     176    
     177    
     178    function current () { 
     179       return $this->f(); 
     180    } 
     181        function key () { 
     182           return $this->intIndex; 
     183        } 
     184        function next () { 
     185           $this->intIndex++; 
     186           //$this->moveNext(); 
     187           return $this->f(); 
     188        } 
     189        function rewind () { 
     190           $this->moveStartPage(); 
     191        } 
     192        function valid () { 
     193           return !($this->intIndex == $this->intRowCount || $this->intIndex == $this->endOfPage);//$this->EOP(); 
     194        } 
    165195} 
    166196 
  • trunk/api/inc/SortableRecordset.php

    r191 r201  
    44 * @package inc 
    55 */ 
    6 class SortableRecordset extends Recordset2
     6class inc_SortableRecordset extends inc_Recordset
    77 
    88   var $sortList = array(); 
  • trunk/api/inc/ZipFile.php

    r130 r201  
    2525 * @access  public 
    2626 */ 
    27 class zipfile 
     27class inc_ZipFile 
    2828{ 
    2929    /** 
  • trunk/api/inc/dispatcher.php

    r194 r201  
    4141    */ 
    4242   function Launch($query='') { 
     43      $query = rawurldecode($query); 
    4344      $query = preg_replace('#^(/)+#', '/', '/'.$query);//echo $query; 
    4445      $this->loadBuiltinControllers(); 
    4546      $this->loadControllers(); 
    46       $this->match($query); 
     47      //$this->match($query); 
     48 
     49      $query = preg_replace('#^(/)+#', '/', '/'.$query); 
     50      $req = new Pluf_HTTP_Request($query); 
     51      $middleware = array(); 
     52      foreach (Pluf::f('middleware_classes', array()) as $mw) { 
     53         $middleware[] = new $mw(); 
     54      } 
     55      $skip = false; 
     56      foreach ($middleware as $mw) { 
     57         if (method_exists($mw, 'process_request')) { 
     58            $res = $mw->process_request($req); 
     59            if ($res !== false) { 
     60               // $res is a response 
     61               $res->render(); 
     62               $skip = true; 
     63               break; 
     64            } 
     65         } 
     66      } 
     67      if ($skip === false) { 
     68         $response = Dispatcher::match($req); 
     69         foreach ($middleware as $mw) { 
     70            if (method_exists($mw, 'process_response')) { 
     71               $response = $mw->process_response($req, $response); 
     72            } 
     73         } 
     74         $response->render(); 
     75      } 
    4776   } 
    4877 
     
    5382    * @param string Query string 
    5483    */ 
    55    function match($query) { 
    56       $query = rawurldecode($query); 
     84   function match($req) { 
    5785 
    5886      // Order the controllers by priority 
     
    6391 
    6492      $res = 200; 
    65       foreach ($GLOBALS['_PX_control'] as $key => $control) { 
    66          //echo $control['regex'].'<br>'; 
    67          if (preg_match($control['regex'], $query, $match)) { 
    68             if ($res == 404 and $control['priority'] < 8) { 
    69                continue; 
     93      foreach ($GLOBALS['_PX_control'] as $key => $ctl) { 
     94         $match = array(); 
     95         if (preg_match($ctl['regex'], $req->query, $match)) { 
     96            try { 
     97               $m = new $ctl['plugin'](); 
     98               if (!isset($ctl['params'])) { 
     99                  return $m->$ctl['method']($req, $match); 
     100               } 
     101               else { 
     102                  return $m->$ctl['method']($req, $match, $ctl['params']); 
     103               } 
    70104            } 
    71  
    72             //$res = call_user_func(array($control['plugin'], 'action'), 
    73             //                      $match); 
    74             $obj = new $control['plugin']; 
    75             $res = $obj->action($match); 
    76             if ($res != 301 and $res != 404) { 
    77                showDebugInfo(); 
    78                return; 
     105            catch (Pluf_HTTP_Error404 $e) { 
     106               return new Pluf_HTTP_Response_NotFound(""); 
    79107            } 
    80             if ($res == 301 and !empty($GLOBALS['_PX_redirect'])) { 
    81                header('Location: '.$GLOBALS['_PX_redirect']); 
    82                return; 
     108            catch (Exception $e) { 
     109               if ($GLOBALS['debug'] == true) { 
     110                  return new Pluf_HTTP_Response_ServerErrorDebug($e); 
     111               } 
     112               else { 
     113                  return new Pluf_HTTP_Response_ServerError($e->getMessage()); 
     114               } 
    83115            } 
    84116         } 
    85117      } 
     118      return new Pluf_HTTP_Response_NotFound("No Matching view"); 
    86119   } 
    87120 
     
    108141         if ($entry != '.' && $entry != '..' 
    109142             && is_dir($this->pluginPath.$entry)  
    110              && file_exists($this->pluginPath.$entry.'/register.php')) { 
     143         && file_exists($this->pluginPath.$entry.'/register.php')) { 
    111144            include_once($this->pluginPath.$entry.'/register.php'); 
    112145         } 
     
    133166    * @return void 
    134167    */ 
    135    function registerController($plugin, $regex, $priority=5) { 
     168   function registerController($plugin, $method, $regex, $priority=5) { 
    136169      if (!isset($GLOBALS['_PX_control'])) { 
    137170         $GLOBALS['_PX_control'] = array(); 
    138171      } 
    139172      $GLOBALS['_PX_control'][] = array('plugin' => $plugin, 
    140       'regex' => $regex, 
    141       'priority' => $priority); 
     173                                                                        'method' => $method, 
     174                                                                        'regex' => $regex, 
     175                                                                        'priority' => $priority); 
    142176   } 
    143  
    144177} 
    145178 
  • trunk/api/inc/files.php

    r195 r201  
    1010    */ 
    1111   function addTailSlash ($dir) { 
    12       if (strlen($dir) > 1 && $dir[strlen ($dir) - 1] != '/') { 
     12      $size = strlen($dir); 
     13      if ($size > 1 && $dir[$size - 1] != '/') { 
    1314         $dir = $dir.'/'; 
    1415      } 
     
    2021    */ 
    2122   function removeTailSlash ($dir) { 
    22       if (strlen ($dir) == 0) { 
     23      $size = strlen($dir); 
     24      if ($size == 0) { 
    2325         return $dir; 
    2426      } 
    25       if ($dir[strlen ($dir) - 1] == '/') { 
    26          $dir = substr ($dir, 0, strlen ($dir) - 1); 
     27      if ($dir[$size - 1] == '/') { 
     28         $dir = substr ($dir, 0, $size - 1); 
    2729      } 
    2830      return $dir; 
     
    180182   function getExtension($f) { 
    181183      $f = explode('.',basename($f)); 
    182  
    183       if (count($f) <= 1) { 
     184      $c = count($f); 
     185       
     186      if ($c <= 1) { 
    184187         return ''; 
    185188      } 
    186189 
    187       return strtolower($f[count($f)-1]); 
     190      return strtolower($f[$c - 1]); 
    188191   } 
    189192 
  • trunk/api/inc/image.meta.php

    r150 r201  
    2727   * @package inc 
    2828   */ 
    29 class ImageMeta extends Recordset2 
     29class ImageMeta extends inc_Recordset 
    3030{ 
    3131   var $meta = array(); 
     
    3636 
    3737   function ImageMeta($f) { 
    38       parent::Recordset2(); 
     38      parent::inc_Recordset(); 
    3939      $this->loadFile($f); 
    4040   } 
     
    176176      } 
    177177 
    178       $d = @exif_read_data($f,'ANY_TAG'); 
     178      $d = @exif_read_data($f, EXIF|COMMENT); 
    179179 
    180180      if (!is_array($d)) { 
     
    368368      $this->value = $value; 
    369369   } 
     370    
     371   function getName() { 
     372      return $this->name; 
     373   } 
     374    
     375   function getValue() { 
     376      return $this->value; 
     377   } 
    370378} 
    371379 
  • trunk/api/inc/imagetoolkit.imagemagick.php

    r200 r201  
    3636         // Other methods 
    3737         else { 
    38             $cmd = 'convert -quality 80 -treedepth 5 -resize %dx%d -geometry %dx%d %s %s'; 
     38            $cmd = 'convert -quality 65 -treedepth 5 -resize %dx%d -geometry %dx%d %s %s'; 
    3939            $cmd = sprintf($cmd,  
    4040                           $this->imageDestWidth, $this->imageDestHeight, 
  • trunk/api/inc/imagetoolkit.php

    r189 r201  
    2323   var $imageDestWidth; 
    2424   var $imageDestHeight; 
    25  
     25   var $mode; 
     26    
     27   static function factory($imagePath, $imageDriver='') { 
     28      if ($imageDriver === '') { 
     29         $imageDriver = Pluf::f('image_generation_driver'); 
     30      } 
     31      switch($imageDriver) { 
     32         case 'gd': 
     33            return new ImageToolkitGD($imagePath); 
     34            break; 
     35 
     36         case 'imagemagick': 
     37            return new ImageToolkitImageMagick($imagePath); 
     38            break; 
     39 
     40         case 'imagick': 
     41            break; 
     42      } 
     43   } 
     44    
    2645   /** 
    2746    * Constructeur par dᅵfaut 
  • trunk/api/inc/l10n.php

    r130 r201  
    3636      return $GLOBALS['_PX_locale'][$t]; 
    3737   } 
    38    elseif ($GLOBALS['debug'] === true) { 
     38   elseif (Pluf::f('debug') === true) { 
    3939      $GLOBALS['_PX_debug_data']['untranslated'][$t] = $t; 
    4040   } 
  • trunk/api/inc/paginator.php

    r133 r201  
    11<?php 
     2 
     3class Page { 
     4   private $text; 
     5   private $imageName; 
     6   private $page; 
     7    
     8   /** 
     9    * @param string $text 
     10    * @param string $imageName 
     11    * @param int $page 
     12    */ 
     13   function __construct($text, $imageName, $page) { 
     14      $this->text = $text; 
     15      $this->imageName = $imageName; 
     16      $this->page = $page; 
     17   } 
     18    
     19   function getText() { 
     20      return $this->text; 
     21   } 
     22    
     23   function getImageName() { 
     24      return $this->imageName; 
     25   } 
     26    
     27   function getPage() { 
     28      return $this->page; 
     29   } 
     30} 
    231 
    332  /** 
    433   * @package inc 
    534   */ 
    6 class Paginator extends Recordset2 { 
     35class Paginator extends inc_Recordset { 
     36   var $res; 
    737   var $currentPage; 
    838   var $countPages; 
     
    1040   var $totalPages; 
    1141 
    12    function Paginator($currentPage, $countPages, $elementsByPage = 7, $nb_bouton_page = 3) { 
    13       parent::Recordset2(); 
     42   function Paginator($res, $currentPage, $countPages, $elementsByPage = 7, $nb_bouton_page = 3) { 
     43      parent::inc_Recordset(); 
     44      $this->res = $res; 
    1445      $this->currentPage = $currentPage; 
    1546      $this->countPages = $countPages; 
     
    5384      if ($first_button > 0) { 
    5485         $mini = true; 
    55          $this->addToList(array('&lt;&lt;', $this->getPictureNumber(0), 0)); 
    56          $this->addToList(array('&lt;', $this->getPictureNumber($this->currentPage-2), 0)); 
     86         $this->addToList(new Page('&lt;&lt;', $this->getPictureNumber(0), 0)); 
     87         $this->addToList(new Page('&lt;', $this->getPictureNumber($this->currentPage-2), 0)); 
    5788      } 
    5889 
     
    6091      for ($j=$first_button; $j < $last_button; $j++) { 
    6192         $mini = true; 
    62          $this->addToList(array($j+1, $this->getPictureNumber($j), $j+1)); 
     93         $this->addToList(new Page($j+1, $this->getPictureNumber($j), $j+1)); 
    6394      } 
    6495 
     
    6697      if ( $last_button < $nb_sql ) { 
    6798         $mini = true; 
    68          $this->addToList(array('&gt;', $this->getPictureNumber($j), 0)); 
    69          $this->addToList(array('&gt;&gt;', $this->getPictureNumber($nb_sql-1), 0)); 
     99         $this->addToList(new Page('&gt;', $this->getPictureNumber($j), 0)); 
     100         $this->addToList(new Page('&gt;&gt;', $this->getPictureNumber($nb_sql-1), 0)); 
    70101      } 
    71102   } 
     
    87118      return  ($this->currentPage * $this->elementsByPage) - (2 * $this->elementsByPage); 
    88119   } 
     120    
     121   function getLinkVignette($return = false) { 
     122      $this->res->move($this->f()->getImageName()); 
     123       
     124      $file = $this->res->f(); 
     125      return link::gallery($file->getDir(), $file->getFile()); 
     126   } 
    89127 
     128    
     129   function isFirst() { 
     130      return $this->getCurrentPage() == 1; 
     131   } 
     132 
     133   /** 
     134    * 
     135    */ 
     136   function isLast() { 
     137      return $this->getCurrentPage() == $this->getTotalPages(); 
     138   } 
     139    
     140   /** 
     141    * @return string the link url to consult the previous page in a gallery page 
     142    */ 
     143   public function getLinkPreviousPageGallery() { 
     144      if ($this->isFirst()) { 
     145         return ''; 
     146      } 
     147      $this->res->move($this->prevPage()); 
     148      $file = $this->res->f(); 
     149      return link::gallery($file->getDir(), $file->getFile()); 
     150   } 
     151    
     152   /** 
     153    * @return string the link url to consult the next page in a gallery page 
     154    */ 
     155   public function getLinkNextPageGallery() { 
     156      if ($this->isLast()) { 
     157         return ''; 
     158      } 
     159      $this->res->move($this->nextPage()); 
     160      $file = $this->res->f(); 
     161      return link::gallery($file->getDir(), $file->getFile()); 
     162   } 
     163    
    90164} 
    91165?> 
  • trunk/api/inc/verif.php

    r130 r201  
    77    
    88   /** 
    9     * Vérifie si le format du nom du dossier est correct 
     9    * Vᅵrifie si le format du nom du dossier est correct 
    1010    * @param String dir Dossier de l'image 
    1111    */ 
     
    1818    
    1919   /** 
    20     * Vérifie si l'image existe 
     20    * Vᅵrifie si l'image existe 
    2121    * @param String dir Dossier de l'image 
    2222    * @param String $img Nom de l'image 
    2323    */ 
    2424   function photo ($dir, $img) { 
    25       if (!is_file (luxbum::getImage ($dir, $img))) { 
     25      if (!is_file(luxbum::getImage($dir, $img))) { 
    2626         return false; 
    2727      } 
     
    3030 
    3131   /** 
    32     * Vérifie si le dossier est correct 
     32    * Vᅵrifie si le dossier est correct 
    3333    */ 
    3434   function isDir ($dir) { 
     
    4242 
    4343   /** 
    44     * Vérifie si un couple dossier/image est correct. 
     44    * Vᅵrifie si un couple dossier/image est correct. 
    4545    * Exit si erreur ! 
    4646    * @param String dir Dossier de l'image 
  • trunk/api/process/commentaire.php

    r164 r201  
    2525   /** 
    2626    *  
     27    * @param Pluf_HTTP_Request $request 
    2728    */ 
    28    function fillFromPost () { 
     29   function fillFromPost ($request) { 
    2930      // Auteur, obligatoire 
    30       if (isset ($_POST['author']) && $_POST['author'] != '') { 
    31          $this->setAuthor (protege_input ($_POST['author'])); 
     31      if (isset ($request->POST['author']) && $request->POST['author'] != '') { 
     32         $this->setAuthor (protege_input ($request->POST['author'])); 
    3233      } 
    3334      else { 
     
    3637 
    3738      // Contenu, obligatoire 
    38       if (isset ($_POST['content']) && trim ($_POST['content']) != '') { 
    39          $this->setContent (protege_input ($_POST['content'])); 
     39      if (isset ($request->POST['content']) && trim ($request->POST['content']) != '') { 
     40         $this->setContent (protege_input ($request->POST['content'])); 
    4041      } 
    4142      else { 
     
    4445 
    4546      // Site 
    46       if (isset ($_POST['website']) && $_POST['website'] != '') { 
    47          $this->setWebsite (protege_input ($_POST['website'])); 
     47      if (isset ($request->POST['website']) && $request->POST['website'] != '') { 
     48         $this->setWebsite (protege_input ($request->POST['website'])); 
    4849