PEEL Shopping
Open source ecommerce : PEEL Shopping
clean_folders.php
Go to the documentation of this file.
1 <?php
2 // This file should be in UTF8 without BOM - Accents examples: éèê
3 // +----------------------------------------------------------------------+
4 // | Copyright (c) 2004-2015 Advisto SAS, service PEEL - contact@peel.fr |
5 // +----------------------------------------------------------------------+
6 // | This file is part of PEEL Shopping 8.0.0, which is subject to an |
7 // | opensource GPL license: you are allowed to customize the code |
8 // | for your own needs, but must keep your changes under GPL |
9 // | More information: https://www.peel.fr/lire/licence-gpl-70.html |
10 // +----------------------------------------------------------------------+
11 // | Author: Advisto SAS, RCS 479 205 452, France, https://www.peel.fr/ |
12 // +----------------------------------------------------------------------+
13 // $Id: clean_folders.php 46935 2015-09-18 08:49:48Z gboussin $
14 define('IN_PEEL_ADMIN', true);
15 include("../configuration.inc.php");
17 necessite_priv("admin_manage");
18 
19 $GLOBALS['DOC_TITLE'] = $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_TITLE'];
20 
21 $errorMsg = '';
22 $form_values = array();
23 $form_values['file_shortpath'] = '';
24 $form_values['tx_qualite'] = $GLOBALS['site_parameters']['jpeg_quality'];
25 $form_values['enlighten'] = '';
26 $form_values['size_ko'] = 500;
27 $accepted_formats['form_image'] = array('jpg', 'JPG', 'jpeg', 'JPEG');
28 
29 include($GLOBALS['repertoire_modele'] . "/admin_haut.php");
30 
31 $output = '';
32 // si un clic a été fait sur le bouton supprimer alors on vide le réperoire
33 if (vb($_GET['suppr']) == 'thumbs') {
34  $files_deleted = nettoyer_dir($GLOBALS['uploaddir'] . '/thumbs');
35 } elseif (vb($_GET['suppr']) == 'cache') {
36  $files_deleted = nettoyer_dir($GLOBALS['dirroot'] . '/' . $GLOBALS['site_parameters']['cache_folder']);
37 }
38 if (isset($files_deleted)) {
39  $output .= $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_CLEAN_FOLDERS_MSG_FILES_DELETED'], $files_deleted)))->fetch();
40 }
41 $show_form = true;
42 if (isset($_POST['file_shortpath']) && isset($_POST['tx_qualite'])) {
43  if (empty($_POST['file_shortpath'])) {
44  $errorMsg .= ' ' . $GLOBALS['STR_ADMIN_ERR_EMPTY_PATH'] . '<br />';
45  }
46  if (empty($_POST['tx_qualite'])) {
47  $errorMsg .= ' ' . $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_ERR_EMPTY_QUALITY'];
48  } elseif (is_numeric($_POST['tx_qualite'])) {
49  if ($_POST['tx_qualite'] > 100 || $_POST['tx_qualite'] <= 0) {
50  $errorMsg .= $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_QUALITY_LABEL'];
51  }
52  } else {
53  $errorMsg .= $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_ERR_QUALITY'];
54  }
55  if (!empty($errorMsg)) {
56  $form_values['file_shortpath'] = $_POST['file_shortpath'];
57  $form_values['tx_qualite'] = $_POST['tx_qualite'];
58  $form_values['enlighten'] = vb($_POST['enlighten']);
59  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $errorMsg))->fetch();
60  } else {
61  $show_form = false;
62  $i = 0;
63  $j = 0;
64  if (substr($_POST['file_shortpath'], -1) == '/') {
65  $_POST['file_shortpath'] = substr($_POST['file_shortpath'], 0, strlen($_POST['file_shortpath'])-1);
66  }
67  $chemin_final = $dirroot . '/' . $_POST['file_shortpath'];
68  if (is_dir($chemin_final)) {
69  if ($dir_pointer = opendir($chemin_final)) {
70  while (false !== ($filename = readdir($dir_pointer))) {
71  if ($filename != '.' && $filename != '..' && is_file($chemin_final . '/' . $filename) && filesize($chemin_final . '/' . $filename) >= vn($_POST['size_ko']) * 1024) {
72  $array = explode('.', $filename);
73  $extension = $array[count($array) - 1];
74  if (in_array(String::strtolower($extension), $accepted_formats['form_image'])) {
75  echo filesize($chemin_final . '/' . $filename) . ' - ' . $chemin_final . '/' . $filename;
76  image_resize($chemin_final . '/' . $filename, $chemin_final . '/' . $filename, $GLOBALS['site_parameters']['image_max_width'], $GLOBALS['site_parameters']['image_max_height'], false, true, vn($_POST['size_ko']) * 1024, $_POST['tx_qualite'], (vb($_POST['enlighten']) == 'on'?1.6:1.0));
77  $i++;
78  }
79  } else {
80  $j++;
81  if ($j % 100 == 0) {
82  echo $j . '... ';
83  // Force l'envoi du HTML juste généré au navigateur, pour que l'utilisateur suive en temps réel l'avancée
84  flush();
85  }
86  // echo $chemin_final . '/' . $filename.'<br />';
87  }
88  }
89  closedir($dir_pointer);
90  } else {
91  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_ERR_OPEN_DIRECTORY']))->fetch();
92  }
93  } elseif (is_file($chemin_final) && filesize($chemin_final) >= vn($_POST['size_ko']) * 1024) {
94  image_resize($chemin_final, $chemin_final, $GLOBALS['site_parameters']['image_max_width'], $GLOBALS['site_parameters']['image_max_height'], false, true, vn($_POST['size_ko']) * 1024, $_POST['tx_qualite'], 1.0);
95  $i++;
96  }
97  $output .= $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_CLEAN_FOLDERS_MSG_IMAGES_OPTIMIZED_OK'], $i)))->fetch();
98  }
99 }
100 if (!empty($_GET['create_thumbs_subfolders']) || !empty($_GET['delete_thumbs_not_in_subfolders'])) {
101  $folder_origin = '/home/back214750/.snapshots/daily.0/localhost/home/algomtl/domains/algomtl.com/public_html/upload/thumbs/'; //$GLOBALS['uploaddir'] . '/thumbs/';
102  $folder = $GLOBALS['uploaddir'] . '/thumbs/';
103  if (is_dir($folder_origin)) {
104  $dir_pointer = opendir($folder_origin);
105  if(!empty($dir_pointer)) {
106  $i = 0;
107  while (false !== ($filename = readdir($dir_pointer))) {
108  if ($filename != '.' && $filename != '..' && is_file($folder_origin . '/' . $filename)) {
109  $filename_no_ext = pathinfo($filename, PATHINFO_FILENAME);
110  if(String::substr($filename_no_ext, -5, 1) != '-') {
111  echo '<b>' . $filename . ' NOK nom</b><br />';
112  } else {
113  if(!empty($_GET['create_thumbs_subfolders'])) {
114  $folder1 = String::substr($filename_no_ext, -4, 2);
115  $folder2 = ''; //String::substr($filename_no_ext, -2, 2);
116  if(!is_file($folder . '/' . $folder1 . '/' . (!empty($folder2) ? $folder2 . '/':'') . $filename)) {
117  if(!is_dir($folder . '/' . $folder1)) {
118  mkdir($folder . '/' . $folder1);
119  }
120  if(!empty($folder2) && !is_dir($folder . '/' . $folder1 . '/' . $folder2)) {
121  mkdir($folder . '/' . $folder1 . '/' . $folder2);
122  }
123  if(empty($_GET['test'])) {
124  copy($folder_origin . '/' . $filename, $folder . '/' . $folder1.'/' . (!empty($folder2) ? $folder2 . '/':'') . $filename);
125  }
126  echo '' . $filename . ' copied<br />';
127  } else {
128  echo '' . $filename . ' already exists<br />';
129  }
130  }
131  if(!empty($_GET['delete_thumbs_not_in_subfolders'])) {
132  if(empty($_GET['test'])) {
133  unlink($folder_origin . '/' . $filename);
134  }
135  echo '' . $filename . ' deleted<br />';
136  }
137  }
138  }
139  $i++;
140  if($i==100) {
141  // On recharge la page pour recommencer
142  echo '<meta http-equiv="refresh" content="1; url='.get_current_url(true).'">';
143  die();
144  }
145  if($i%20==0) {
146  sleep(1);
147  }
148  }
149  }
150  } else {
151  echo $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => sprintf('%s not found', $folder)))->fetch();
152  }
153  echo $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => 'FINISHED'))->fetch();
154 }
155 
157  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_clean_folders.tpl');
158  $tpl->assign('action_thumbs', $GLOBALS['administrer_url'] . '/clean_folders.php?suppr=thumbs');
159  $tpl->assign('action_cache', $GLOBALS['administrer_url'] . '/clean_folders.php?suppr=cache');
160  $tpl->assign('action_images', $GLOBALS['administrer_url'] . '/clean_folders.php');
161  $tpl->assign('dirroot', $GLOBALS['dirroot']);
162  $tpl->assign('file_shortpath', $form_values['file_shortpath']);
163  $tpl->assign('tx_qualite', $form_values['tx_qualite']);
164  $tpl->assign('size_ko', $form_values['size_ko']);
165  $tpl->assign('enlighten', $form_values['enlighten']);
166  $tpl->assign('STR_TEXT_CONFIG', $GLOBALS['STR_TEXT_CONFIG']);
167  $tpl->assign('STR_CLEAN', $GLOBALS['STR_CLEAN']);
168  $tpl->assign('STR_SUBMIT', $GLOBALS['STR_SUBMIT']);
169  $tpl->assign('STR_ADMIN_CLEAN_FOLDERS_QUALITY', $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_QUALITY']);
170  $tpl->assign('STR_ADMIN_CLEAN_FOLDERS_MINIMAL_SIZE', $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_MINIMAL_SIZE']);
171  $tpl->assign('STR_KILOBYTE', $GLOBALS['STR_KILOBYTE']);
172  $tpl->assign('STR_ADMIN_CLEAN_FOLDERS_EMPTY_CACHE', $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_EMPTY_CACHE']);
173  $tpl->assign('STR_ADMIN_CLEAN_FOLDERS_EMPTY_CACHE_EXPLAIN', $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_EMPTY_CACHE_EXPLAIN']);
174  $tpl->assign('STR_ADMIN_CLEAN_FOLDERS_OPTIMIZE_IMAGES_EXPLAIN', $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_OPTIMIZE_IMAGES_EXPLAIN']);
175  $tpl->assign('STR_ADMIN_IMAGE_SHORT_PATH', $GLOBALS['STR_ADMIN_IMAGE_SHORT_PATH']);
176  $tpl->assign('STR_ADMIN_CLEAN_FOLDERS_ENLIGHTEN_IMAGE', $GLOBALS['STR_ADMIN_CLEAN_FOLDERS_ENLIGHTEN_IMAGE']);
177  $tpl->assign('STR_ADMIN_CONFIRM_JAVASCRIPT', $GLOBALS['STR_ADMIN_CONFIRM_JAVASCRIPT']);
178  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
179  $tpl->assign('STR_REFRESH', $GLOBALS['STR_REFRESH']);
180  $output .= $tpl->fetch();
181 }
182 echo $output;
183 include($GLOBALS['repertoire_modele'] . "/admin_bas.php");
184 
$accepted_formats['form_image']
$GLOBALS['DOC_TITLE']
$extension
static strtolower($string)
Returns string with all alphabetic characters converted to lowercase.
Definition: String.php:135
if(!empty($_GET['id'])) if(isset($_POST['form_name'], $_POST['form_subject'], $_POST['form_text'], $_POST['form_lang'])&&empty($_GET['id'])) if(empty($_GET['id'])) $tpl
$output
necessite_priv($priv, $demo_allowed=true, $configuration_modification=false)
Cette fonction vérifie si l'utilisateur a les privilèges de $priv.
Definition: fonctions.php:1575
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
necessite_identification()
Si l'utilisateur n'est pas connecté à un compte, on affiche une page d'identification et arrête le sc...
Definition: fonctions.php:1596
if(!defined('IN_PEEL')) image_resize($origin_filename_with_path, $new_filename_with_path, $destinationW=null, $destinationH=null, $resize_even_if_smaller=false, $allow_keep_origin_file_if_resize_not_needed=true, $filesize_limit_keep_origin_file=102400, $jpeg_quality=85, $gammacorrect=1.0)
On redimensionne l'image pour qu'elle ne dépasse pas la taille de destination Le ratio largeur / haut...
Definition: images.php:33
$errorMsg
vn(&$var, $default=0)
Variable nulle if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:110
$form_values
$filename
nettoyer_dir($dir, $older_than_seconds=3, $filename_beginning=null, $create_files_array_found_instead_of_delete=false)
Effacement des fichiers trouvés répondant aux critères en argument, en effaçant récusivement le conte...
Definition: fonctions.php:3934
if(vb($_GET['suppr'])== 'thumbs') elseif(vb($_GET['suppr'])== 'cache') if(isset($files_deleted)) $show_form
static substr($string, $start, $length=null)
Returns the portion of string specified by the start and length parameters.
Definition: String.php:112

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:29:01 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.