source: trunk/admin/thumbnail.php @ 10571

Last change on this file since 10571 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
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23
24include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
25include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
26
27check_status(ACCESS_ADMINISTRATOR);
28
29// +-----------------------------------------------------------------------+
30// |                          Load configuration                           |
31// +-----------------------------------------------------------------------+
32prepare_upload_configuration();
33
34$upload_form_config = get_upload_form_config();
35
36$form_values = array();
37
38foreach ($upload_form_config as $param_shortname => $param)
39{
40  $param_name = 'upload_form_'.$param_shortname;
41  $form_values[$param_shortname] = $conf[$param_name];
42}
43
44// +-----------------------------------------------------------------------+
45// |                   search pictures without thumbnails                  |
46// +-----------------------------------------------------------------------+
47$wo_thumbnails = array();
48
49// what is the directory to search in ?
50$query = '
51SELECT galleries_url FROM '.SITES_TABLE.'
52  WHERE galleries_url NOT LIKE \'http://%\'
53;';
54$result = pwg_query($query);
55while ( $row=pwg_db_fetch_assoc($result) )
56{
57  $basedir = preg_replace('#/*$#', '', $row['galleries_url']);
58  $fs = get_fs($basedir);
59
60  // because isset is one hundred time faster than in_array
61  $fs['thumbnails'] = array_flip($fs['thumbnails']);
62
63  foreach ($fs['elements'] as $path)
64  {
65    // only pictures need thumbnails
66    if (in_array(get_extension($path), $conf['picture_ext']))
67    {
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))
74      {
75        continue;
76      }
77     
78      // searching the element
79      $filename_wo_ext = get_filename_wo_extension($filename);
80      $tn_ext = '';
81      $base_test = $dirname.'/'.$conf['dir_thumbnail'].'/';
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      }
96    }
97  } // next element
98} // next site id
99
100// +-----------------------------------------------------------------------+
101// |             form & pictures without thumbnails display                |
102// +-----------------------------------------------------------------------+
103$template->set_filenames( array('thumbnail'=>'thumbnail.tpl') );
104
105if (count($wo_thumbnails) > 0)
106{
107  foreach ($wo_thumbnails as $path)
108  {
109    list($width, $height) = getimagesize($path);
110    $size = floor(filesize($path) / 1024).' KB';
111
112    $template->append(
113      'remainings',
114      array(
115        'PATH'=>$path,
116        'FILESIZE_IMG'=>$size,
117        'WIDTH_IMG'=>$width,
118        'HEIGHT_IMG'=>$height,
119      )
120    );
121  }
122}
123
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),
137    'U_HELP' => get_root_url().'admin/popuphelp.php?page=thumbnail',
138  )
139);
140
141$template->assign_var_from_handle('ADMIN_CONTENT', 'thumbnail');
142?>
Note: See TracBrowser for help on using the repository browser.