source: extensions/Ajax_Thumbnailer/admin/thumbnailer_admin.php @ 4549

Last change on this file since 4549 was 4549, checked in by Dsls, 14 years ago

Ajax_Thumbnailer 0.3

File size: 3.1 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3define ('AT_PATH',PHPWG_PLUGINS_PATH . 'AjaxThumbnailer');
4$me = get_plugin_data($plugin_id);
5
6load_language('plugin.lang', AT_PATH.'/');
7 
8global $template;
9$template->set_filenames( array('plugin_admin_content' => dirname(__FILE__).'/thumbnailer_admin.tpl') );
10// +-----------------------------------------------------------------------+
11// |                   search pictures without thumbnails                  |
12// +-----------------------------------------------------------------------+
13$wo_thumbnails = array();
14$thumbnalized = array();
15
16
17// what is the directory to search in ?
18$query = '
19SELECT galleries_url FROM '.SITES_TABLE.'
20  WHERE galleries_url NOT LIKE "http://%"
21;';
22$result = pwg_query($query);
23while ( $row=mysql_fetch_assoc($result) )
24{
25  $basedir = preg_replace('#/*$#', '', $row['galleries_url']);
26  $fs = get_fs($basedir);
27
28  // because isset is one hundred time faster than in_array
29  $fs['thumbnails'] = array_flip($fs['thumbnails']);
30
31  foreach ($fs['elements'] as $path)
32  {
33    // only pictures need thumbnails
34    if (in_array(get_extension($path), $conf['picture_ext']))
35    {
36      $dirname = dirname($path);
37      $filename = basename($path);
38 
39      // only files matching the authorized filename pattern can be considered
40      // as "without thumbnail"
41      if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
42      {
43        continue;
44      }
45     
46      // searching the element
47      $filename_wo_ext = get_filename_wo_extension($filename);
48      $tn_ext = '';
49      $base_test = $dirname.'/thumbnail/';
50      $base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.';
51      foreach ($conf['picture_ext'] as $ext)
52      {
53        if (isset($fs['thumbnails'][$base_test.$ext]))
54        {
55          $tn_ext = $ext;
56          break;
57        }
58      }
59     
60      if (empty($tn_ext))
61      {
62        array_push($wo_thumbnails, $path);
63      }
64    }
65  } // next element
66} // next site id
67
68  $form_url = get_root_url().'admin.php?page=thumbnail';
69  $gd = !empty($_POST['gd']) ? $_POST['gd'] : 2;
70  $width = !empty($_POST['width']) ? $_POST['width'] : $conf['tn_width'];
71  $height = !empty($_POST['height']) ? $_POST['height'] : $conf['tn_height'];
72  $n = !empty($_POST['n']) ? $_POST['n'] : 5;
73 
74  $template->assign(
75    'params',
76    array(
77      'F_ACTION'=> $form_url,
78      'GD_SELECTED' => $gd,
79      'N_SELECTED' => $n,
80      'WIDTH_TN'=>$width,
81      'HEIGHT_TN'=>$height,
82      ));
83
84  $template->assign(
85    'TOTAL_NB_REMAINING',
86    count($wo_thumbnails));
87  $template->assign(
88    'plugin',
89    array(
90                'path' => AT_PATH
91        ));
92
93  foreach ($wo_thumbnails as $path)
94  {
95    list($width, $height) = getimagesize($path);
96    $size = floor(filesize($path) / 1024).' KB';
97
98    $template->append(
99      'wo_thumbnails',
100      array(
101        'PATH'=>$path,
102        'FILESIZE_IMG'=>$size,
103        'WIDTH_IMG'=>$width,
104        'HEIGHT_IMG'=>$height,
105        ));
106  }
107 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
108?>
Note: See TracBrowser for help on using the repository browser.