source: trunk/admin/thumbnail.php @ 10638

Last change on this file since 10638 was 10571, checked in by patdenice, 13 years ago

feature:2274
Bug corrected with crop option.
Clean code.
Add sentence in thumbnails page for regeneration.

  • Property svn:eol-style set to LF
File size: 5.0 KB
RevLine 
[2]1<?php
[362]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[1072]23
24include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
[10570]25include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
[1072]26
[10570]27check_status(ACCESS_ADMINISTRATOR);
28
[1072]29// +-----------------------------------------------------------------------+
[10570]30// |                          Load configuration                           |
[1072]31// +-----------------------------------------------------------------------+
[10570]32prepare_upload_configuration();
[1072]33
[10570]34$upload_form_config = get_upload_form_config();
[2]35
[10570]36$form_values = array();
[5957]37
[10570]38foreach ($upload_form_config as $param_shortname => $param)
[2428]39{
[10570]40  $param_name = 'upload_form_'.$param_shortname;
41  $form_values[$param_shortname] = $conf[$param_name];
[2428]42}
43
[695]44// +-----------------------------------------------------------------------+
45// |                   search pictures without thumbnails                  |
46// +-----------------------------------------------------------------------+
47$wo_thumbnails = array();
[393]48
[695]49// what is the directory to search in ?
50$query = '
[1814]51SELECT galleries_url FROM '.SITES_TABLE.'
[6550]52  WHERE galleries_url NOT LIKE \'http://%\'
[695]53;';
[1814]54$result = pwg_query($query);
[4325]55while ( $row=pwg_db_fetch_assoc($result) )
[1814]56{
57  $basedir = preg_replace('#/*$#', '', $row['galleries_url']);
58  $fs = get_fs($basedir);
[695]59
[1814]60  // because isset is one hundred time faster than in_array
61  $fs['thumbnails'] = array_flip($fs['thumbnails']);
[695]62
[1814]63  foreach ($fs['elements'] as $path)
[2]64  {
[1814]65    // only pictures need thumbnails
66    if (in_array(get_extension($path), $conf['picture_ext']))
[703]67    {
[1814]68      $dirname = dirname($path);
69      $filename = basename($path);
70 
71      // only files matching the authorized filename pattern can be considered
72      // as "without thumbnail"
73      if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
[695]74      {
[1814]75        continue;
[695]76      }
[1814]77     
78      // searching the element
79      $filename_wo_ext = get_filename_wo_extension($filename);
80      $tn_ext = '';
[3720]81      $base_test = $dirname.'/'.$conf['dir_thumbnail'].'/';
[1814]82      $base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.';
83      foreach ($conf['picture_ext'] as $ext)
84      {
85        if (isset($fs['thumbnails'][$base_test.$ext]))
86        {
87          $tn_ext = $ext;
88          break;
89        }
90      }
91     
92      if (empty($tn_ext))
93      {
94        array_push($wo_thumbnails, $path);
95      }
[695]96    }
[1814]97  } // next element
98} // next site id
[695]99
100// +-----------------------------------------------------------------------+
101// |             form & pictures without thumbnails display                |
102// +-----------------------------------------------------------------------+
[10571]103$template->set_filenames( array('thumbnail'=>'thumbnail.tpl') );
104
[10570]105if (count($wo_thumbnails) > 0)
[695]106{
[10570]107  foreach ($wo_thumbnails as $path)
[2]108  {
[695]109    list($width, $height) = getimagesize($path);
110    $size = floor(filesize($path) / 1024).' KB';
111
[2250]112    $template->append(
113      'remainings',
[665]114      array(
[695]115        'PATH'=>$path,
116        'FILESIZE_IMG'=>$size,
117        'WIDTH_IMG'=>$width,
118        'HEIGHT_IMG'=>$height,
[10571]119      )
120    );
[665]121  }
[2]122}
[2250]123
[10570]124foreach (array_keys($upload_form_config) as $field)
125{
126  if (is_bool($upload_form_config[$field]['default']))
127  {
128    $form_values[$field] = $form_values[$field] ? 'checked="checked"' : '';
129  }
130}
131
132$template->assign(
133  array(
134    'F_ACTION' => get_root_url().'admin.php?page=thumbnail',
135    'values' => $form_values,
136    'TOTAL_NB_REMAINING' => count($wo_thumbnails),
[10571]137    'U_HELP' => get_root_url().'admin/popuphelp.php?page=thumbnail',
[10570]138  )
139);
140
[393]141$template->assign_var_from_handle('ADMIN_CONTENT', 'thumbnail');
[362]142?>
Note: See TracBrowser for help on using the repository browser.