Changeset 606


Ignore:
Timestamp:
Nov 17, 2004, 12:38:34 AM (19 years ago)
Author:
plg
Message:
  • images.path column added to reduce database access
  • function mass_inserts moved from admin/remote_sites.php to admin/include/function.php
  • function mass_inserts used in admin/update.php
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r597 r606  
    785785  }
    786786}
     787
     788/**
     789 * inserts multiple lines in a table
     790 *
     791 * @param string table_name
     792 * @param array dbields
     793 * @param array inserts
     794 * @return void
     795 */
     796function mass_inserts($table_name, $dbfields, $inserts)
     797{
     798  // inserts all found categories
     799  $query = '
     800INSERT INTO '.$table_name.'
     801  ('.implode(',', $dbfields).')
     802   VALUES';
     803  foreach ($inserts as $insert_id => $insert)
     804  {
     805    $query.= '
     806  ';
     807    if ($insert_id > 0)
     808    {
     809      $query.= ',';
     810    }
     811    $query.= '(';
     812    foreach ($dbfields as $field_id => $dbfield)
     813    {
     814      if ($field_id > 0)
     815      {
     816        $query.= ',';
     817      }
     818     
     819      if (!isset($insert[$dbfield]) or $insert[$dbfield] == '')
     820      {
     821        $query.= 'NULL';
     822      }
     823      else
     824      {
     825        $query.= "'".$insert[$dbfield]."'";
     826      }
     827    }
     828    $query.=')';
     829  }
     830  $query.= '
     831;';
     832  pwg_query($query);
     833}
    787834?>
  • trunk/admin/infos_images.php

    r593 r606  
    320320  while ($row = mysql_fetch_array($result))
    321321  {
    322     $thumbnail_url = get_thumbnail_src($row['file'],
    323                                        $row['storage_category_id'],
    324                                        @$row['tn_ext']);
     322    $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
    325323
    326324    $template->assign_block_vars(
  • trunk/admin/picture_modify.php

    r593 r606  
    200200$dir_path = get_cat_display_name($current_category['name'], '->', '');
    201201
    202 $thumbnail_url = get_thumbnail_src($row['file'],
    203                                    $row['storage_category_id'],
    204                                    @$row['tn_ext']);
     202$thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
    205203
    206204$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
  • trunk/admin/remote_site.php

    r602 r606  
    110110
    111111  return $database_dirs;
    112 }
    113 
    114 /**
    115  * inserts multiple lines in a table
    116  *
    117  * @param string table_name
    118  * @param array dbields
    119  * @param array inserts
    120  * @return void
    121  */
    122 function mass_inserts($table_name, $dbfields, $inserts)
    123 {
    124   // inserts all found categories
    125   $query = '
    126 INSERT INTO '.$table_name.'
    127   ('.implode(',', $dbfields).')
    128    VALUES';
    129   foreach ($inserts as $insert_id => $insert)
    130   {
    131     $query.= '
    132   ';
    133     if ($insert_id > 0)
    134     {
    135       $query.= ',';
    136     }
    137     $query.= '(';
    138     foreach ($dbfields as $field_id => $dbfield)
    139     {
    140       if ($field_id > 0)
    141       {
    142         $query.= ',';
    143       }
    144      
    145       if (!isset($insert[$dbfield]) or $insert[$dbfield] == '')
    146       {
    147         $query.= 'NULL';
    148       }
    149       else
    150       {
    151         $query.= "'".$insert[$dbfield]."'";
    152       }
    153     }
    154     $query.=')';
    155   }
    156   $query.= '
    157 ;';
    158   pwg_query($query);
    159112}
    160113
     
    419372                             'keywords',
    420373                             'name',
    421                              'comment');
     374                             'comment',
     375                             'path');
    422376      foreach ($optional_atts as $att)
    423377      {
     
    435389    $dbfields = array('file','storage_category_id','date_available','tn_ext',
    436390                      'filesize','width','height','date_creation','author',
    437                       'keywords','name','comment');
     391                      'keywords','name','comment','path');
    438392    mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
    439393    $counts{'new_elements'}+= count($inserts);
  • trunk/admin/update.php

    r602 r606  
    3232include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
    3333
    34 define('CURRENT_DATE', "'".date('Y-m-d')."'");
     34define('CURRENT_DATE', date('Y-m-d'));
    3535// +-----------------------------------------------------------------------+
    3636// |                              functions                                |
     
    408408        {
    409409          $insert = array();
    410           $insert['file'] = "'".$unregistered_element."'";
     410          $insert['file'] = $unregistered_element;
    411411          $insert['storage_category_id'] = $category_id;
    412412          $insert['date_available'] = CURRENT_DATE;
    413           $insert['tn_ext'] = "'".$tn_ext."'";
     413          $insert['tn_ext'] = $tn_ext;
     414          $insert['path'] = $dir.$unregistered_element;
    414415
    415416          $counts['new_elements']++;
     
    447448
    448449        $insert = array();
    449         $insert['file'] = "'".$unregistered_element."'";
     450        $insert['file'] = $unregistered_element;
     451        $insert['path'] = $dir.$unregistered_element;
    450452        $insert['storage_category_id'] = $category_id;
    451453        $insert['date_available'] = CURRENT_DATE;
    452454        if ( $tn_ext != '' )
    453455        {
    454           $insert['tn_ext'] = "'".$tn_ext."'";
     456          $insert['tn_ext'] = $tn_ext;
    455457        }
    456458        if ( $representative_ext != '' )
    457459        {
    458           $insert['representative_ext'] = "'".$representative_ext."'";
     460          $insert['representative_ext'] = $representative_ext;
    459461        }
    460462
     
    476478    $dbfields = array(
    477479      'file','storage_category_id','date_available','tn_ext'
    478       ,'representative_ext'
     480      ,'representative_ext','path'
    479481      );
    480     $query = '
    481 INSERT INTO '.IMAGES_TABLE.'
    482   ('.implode(',', $dbfields).')
    483    VALUES
    484    ';
    485     foreach ($inserts as $insert_id => $insert)
    486     {
    487       $query.= '
    488 ';
    489       if ($insert_id > 0)
    490       {
    491         $query.= ',';
    492       }
    493       $query.= '(';
    494       foreach ($dbfields as $field_id => $dbfield)
    495       {
    496         if ($field_id > 0)
    497         {
    498           $query.= ',';
    499         }
    500        
    501         if (!isset($insert[$dbfield]) or $insert[$dbfield] == '')
    502         {
    503           $query.= 'NULL';
    504         }
    505         else
    506         {
    507           $query.= $insert[$dbfield];
    508         }
    509       }
    510       $query.=')';
    511     }
    512     $query.= '
    513 ;';
    514 
    515     pwg_query($query);
     482    mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
    516483
    517484    // what are the ids of the pictures in the $category_id ?
  • trunk/comments.php

    r593 r606  
    141141  // link to the full size picture
    142142  $query = '
    143 SELECT name,file,storage_category_id as cat_id,tn_ext
     143SELECT name,file,storage_category_id as cat_id,tn_ext,path
    144144  FROM '.IMAGES_TABLE.'
    145145  WHERE id = '.$row['image_id'].'
     
    167167  $name.= ' [ '.$subrow['file'].' ]';
    168168  // source of the thumbnail picture
    169   $thumbnail_src = get_thumbnail_src($subrow['file'],
    170                                      $subrow['cat_id'],
    171                                      @$subrow['tn_ext']);
     169  $thumbnail_src = get_thumbnail_src($subrow['path'], @$subrow['tn_ext']);
    172170  // link to the full size picture
    173171  $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
  • trunk/include/category_calendar.inc.php

    r593 r606  
    220220  {
    221221    $query = '
    222 SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
     222SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
    223223  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    224224  '.$page['where'].'
     
    230230    $row = mysql_fetch_array(pwg_query($query));
    231231   
    232     $thumbnail_src = get_thumbnail_src($row['file'],
    233                                        $row['storage_category_id'],
    234                                        @$row['tn_ext']);
     232    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
    235233   
    236234    $name = $calendar_year.' ('.$nb_pics.')';
     
    267265  {
    268266    $query = '
    269 SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
     267SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
    270268  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    271269  '.$page['where'].'
     
    278276    $row = mysql_fetch_array(pwg_query($query));
    279277   
    280     $thumbnail_src = get_thumbnail_src($row['file'],
    281                                        $row['storage_category_id'],
    282                                        @$row['tn_ext']);
     278    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
    283279   
    284280    $name = $lang['month'][$calendar_month];
     
    323319  {
    324320    $query = '
    325 SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
     321SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
    326322  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    327323  '.$page['where'].'
     
    333329    $row = mysql_fetch_array(pwg_query($query));
    334330   
    335     $thumbnail_src = get_thumbnail_src($row['file'],
    336                                        $row['storage_category_id'],
    337                                        @$row['tn_ext']);
     331    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
    338332
    339333    list($year,$month,$day) = explode('-', $calendar_day);
     
    386380   
    387381    $query = '
    388 SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
     382SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
    389383  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    390384  '.$page['where'].'
     
    402396    $row = mysql_fetch_array(pwg_query($query));
    403397   
    404     $thumbnail_src = get_thumbnail_src($row['file'],
    405                                        $row['storage_category_id'],
    406                                        @$row['tn_ext']);
     398    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
    407399   
    408400    $thumbnail_title = $lang['calendar_picture_hint'].$name;
  • trunk/include/category_default.inc.php

    r605 r606  
    3939 
    4040$query = '
    41 SELECT DISTINCT(id),file,date_available,category_id
     41SELECT DISTINCT(id),path,file,date_available,category_id
    4242       ,tn_ext,name,filesize,storage_category_id,average_rate
    4343  FROM '.IMAGES_TABLE.' AS i
     
    8181  }
    8282 
    83   $thumbnail_url = get_thumbnail_src($row['file'],
    84                                      $row['storage_category_id'],
    85                                      @$row['tn_ext']);
     83  $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
    8684 
    8785  // message in title for the thumbnail
  • trunk/include/category_recent_cats.inc.php

    r593 r606  
    6767 
    6868  $query = '
    69 SELECT id,file,tn_ext,storage_category_id
     69SELECT path,file,tn_ext
    7070  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    7171  WHERE category_id = '.$row['category_id'].'
     
    7676  LIMIT 0,1
    7777;';
    78   $subrow = mysql_fetch_array( pwg_query( $query ) );
     78  $subrow = mysql_fetch_array(pwg_query($query));
    7979
    80   $thumbnail_src = get_thumbnail_src($subrow['file'],
    81                                      $subrow['storage_category_id'],
    82                                      @$subrow['tn_ext']);
     80  $thumbnail_src = get_thumbnail_src($subrow['path'], @$subrow['tn_ext']);
    8381 
    8482  $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id'];
  • trunk/include/category_subcats.inc.php

    r593 r606  
    6565   
    6666  $query = '
    67 SELECT file,tn_ext,storage_category_id
     67SELECT file,path,tn_ext
    6868  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    6969  WHERE category_id = '.$non_empty_id.'
     
    8787  $image_row    = mysql_fetch_array($image_result);
    8888
    89   $thumbnail_link = get_thumbnail_src($image_row['file'],
    90                                       $image_row['storage_category_id'],
     89  $thumbnail_link = get_thumbnail_src($image_row['path'],
    9190                                      @$image_row['tn_ext']);
    9291
  • trunk/include/functions.inc.php

    r599 r606  
    571571 * given element
    572572 *
    573  * this function could have taken only the element id as parameter but to
    574  * optimize database access we directly ask file, storage category
    575  * identifier and extension since when this function is called,
    576  * PhpWebGallery should have all these infos. No need to retrieve them
    577  * another time in the database.
    578  *
    579573 * the returned string can represente the filepath of the thumbnail or the
    580574 * filepath to the corresponding icon for non picture elements
    581575 *
    582  * complete directories are cached to be used more than once during a page
    583  * generation (many thumbnails of the same category on the same page)
    584  *
    585  * @param string file
    586  * @param int storage_category_id
     576 * @param string path
    587577 * @param string tn_ext
    588578 * @return string
    589579 */
    590 function get_thumbnail_src($file, $storage_category_id, $tn_ext = '')
    591 {
    592   global $conf, $user, $array_cat_directories;
    593  
    594   if (!isset($array_cat_directories[$storage_category_id]))
    595   {
    596     $array_cat_directories[$storage_category_id] =
    597       get_complete_dir($storage_category_id);
    598   }
    599  
     580function get_thumbnail_src($path, $tn_ext = '')
     581{
     582  global $conf, $user;
     583
    600584  if ($tn_ext != '')
    601585  {
    602     $src = $array_cat_directories[$storage_category_id];
    603     $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
    604     $src.= get_filename_wo_extension($file);
     586    $src = substr_replace(get_filename_wo_extension($path),
     587                          '/thumbnail/'.$conf['prefix_thumbnail'],
     588                          strrpos($path,'/'),
     589                          1);
    605590    $src.= '.'.$tn_ext;
    606591  }
     
    609594    $src = PHPWG_ROOT_PATH;
    610595    $src.= 'template/'.$user['template'].'/mimetypes/';
    611     $src.= strtolower(get_extension($file)).'.png';
    612   }
    613 
     596    $src.= strtolower(get_extension($path)).'.png';
     597  }
     598 
    614599  return $src;
    615600}
  • trunk/install/dbscheme.txt

    r602 r606  
    7272column:date_metadata_update      table:images         type:date                     nullable:Y
    7373column:average_rate              table:images         type:float                    nullable:Y length:5,2 signed:N
     74column:path                      table:images         type:varchar                  nullable:N length:255 binary:N
    7475column:user_id                   table:rate           type:smallint                 nullable:N length:5   signed:N
    7576column:element_id                table:rate           type:mediumint                nullable:N length:8   signed:N
  • trunk/install/phpwebgallery_structure.sql

    r602 r606  
    141141  date_metadata_update date default NULL,
    142142  average_rate float(5,2) unsigned default NULL,
     143  path varchar(255) NOT NULL default '',
    143144  PRIMARY KEY  (id),
    144145  KEY images_i2 (date_available),
  • trunk/picture.php

    r605 r606  
    143143  }
    144144 
    145   if ( !isset($array_cat_directories[$row['storage_category_id']]))
    146   {
    147     $array_cat_directories[$row['storage_category_id']] =
    148       get_complete_dir( $row['storage_category_id'] );
    149   }
    150   $cat_directory = $array_cat_directories[$row['storage_category_id']];
     145  $cat_directory = dirname($row['path']);
    151146  $file_wo_ext = get_filename_wo_extension($row['file']);
    152147
     
    166161  if ($picture[$i]['is_picture'])
    167162  {
    168     $picture[$i]['src'] = $cat_directory.$row['file'];
     163    $picture[$i]['src'] = $row['path'];
    169164    // if we are working on the "current" element, we search if there is a
    170165    // high quality picture
     
    182177  if (!$picture[$i]['is_picture'])
    183178  {
    184     $picture[$i]['download'] = $cat_directory.$row['file'];
    185   }
    186 
    187   $picture[$i]['thumbnail'] = get_thumbnail_src($row['file'],
    188                                                 $row['storage_category_id'],
    189                                                 @$row['tn_ext']);
     179    $picture[$i]['download'] = $row['path'];
     180  }
     181
     182  $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
    190183 
    191184  if ( !empty( $row['name'] ) )
  • trunk/tools/create_listing_file.php

    r593 r606  
    311311function get_pictures($dir, $indent)
    312312{
    313   global $conf;
     313  global $conf, $page;
    314314 
    315315  // fs means FileSystem : $fs_files contains files in the filesystem found
     
    322322
    323323  $elements = array();
     324
     325  $print_dir = preg_replace('/^\.\//', '', $dir);
     326  $print_dir = preg_replace('/\/*$/', '/', $print_dir);
    324327 
    325328  foreach ($fs_files as $fs_file)
     
    327330    $element = array();
    328331    $element['file'] = $fs_file;
     332    $element['path'] = $page['url'].$print_dir.$fs_file;
    329333    $element['filesize'] = floor(filesize($dir.'/'.$fs_file) / 1024);
    330334   
     
    421425  $attributes = array('file','tn_ext','representative_ext','filesize',
    422426                      'width','height','date_creation','author','keywords',
    423                       'name','comment');
     427                      'name','comment','path');
    424428  foreach ($elements as $element)
    425429  {
     
    464468    $end = strrpos($_SERVER['PHP_SELF'], '/') + 1;
    465469    $local_folder = substr($_SERVER['PHP_SELF'], 0, $end);
    466     $url = 'http://'.$_SERVER['HTTP_HOST'].$local_folder;
     470    $page['url'] = 'http://'.$_SERVER['HTTP_HOST'].$local_folder;
    467471   
    468     $listing.= ' url="'.$url.'"';
     472    $listing.= ' url="'.$page['url'].'"';
    469473    $listing.= '/>'."\n";
    470474   
Note: See TracChangeset for help on using the changeset viewer.