source: trunk/admin/thumbnail.php @ 10570

Last change on this file since 10570 was 10570, checked in by patdenice, 14 years ago

feature:2274
Create thumbnail through ajax.
Remove $conftn_width, $conftn_height and $conftn_compression_level parameters.

  • Property svn:eol-style set to LF
File size: 5.2 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// +-----------------------------------------------------------------------+
103if (count($wo_thumbnails) > 0)
104{
105  foreach ($wo_thumbnails as $path)
106  {
107    list($width, $height) = getimagesize($path);
108    $size = floor(filesize($path) / 1024).' KB';
109
110    $template->append(
111      'remainings',
112      array(
113        'PATH'=>$path,
114        'FILESIZE_IMG'=>$size,
115        'WIDTH_IMG'=>$width,
116        'HEIGHT_IMG'=>$height,
117        ));
118  }
119}
120
121foreach (array_keys($upload_form_config) as $field)
122{
123  if (is_bool($upload_form_config[$field]['default']))
124  {
125    $form_values[$field] = $form_values[$field] ? 'checked="checked"' : '';
126  }
127}
128
129$template->assign(
130  array(
131    'F_ACTION' => get_root_url().'admin.php?page=thumbnail',
132    'values' => $form_values,
133    'TOTAL_NB_REMAINING' => count($wo_thumbnails),
134  )
135);
136
137// +-----------------------------------------------------------------------+
138// |                           return to admin                             |
139// +-----------------------------------------------------------------------+
140$template->set_filenames( array('thumbnail'=>'thumbnail.tpl') );
141
142$template->assign('U_HELP', get_root_url().'admin/popuphelp.php?page=thumbnail');
143
144$template->assign_var_from_handle('ADMIN_CONTENT', 'thumbnail');
145?>
Note: See TracBrowser for help on using the repository browser.