[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / action / calculer_taille_cache.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15
16
17 /**
18 * Calculer la taille du cache ou du cache image pour l'afficher en ajax sur la page d'admin de SPIP
19 *
20 * @param string|null $arg
21 */
22 function action_calculer_taille_cache_dist($arg=null){
23 if (is_null($arg)){
24 $securiser_action = charger_fonction('securiser_action', 'inc');
25 $arg = $securiser_action();
26 }
27 include_spip('inc/filtres');
28
29 if ($arg=='images'){
30 $taille = calculer_taille_dossier(_DIR_VAR);
31 $res = _T('ecrire:taille_cache_image',
32 array(
33 'dir' => joli_repertoire(_DIR_VAR),
34 'taille' => "<b>".(taille_en_octets($taille) > 0 ? taille_en_octets($taille) : "0 octet")."</b>"
35 )
36 );
37 }
38 else {
39 include_spip('inc/invalideur');
40 $taille =
41 calculer_taille_dossier(_DIR_CACHE_XML)
42 +calculer_taille_dossier(_DIR_CACHE.'skel/')
43 +calculer_taille_dossier(_DIR_CACHE.'wheels/')
44 +calculer_taille_dossier(_DIR_CACHE.'contextes/')
45 ;
46 $taille += intval(taille_du_cache());
47 if ($taille<=150000){
48 $res = _T('taille_cache_vide');
49 }
50 elseif ($taille<=1024*1024){
51 $res = _T('taille_cache_moins_de',array('octets'=>taille_en_octets(1024*1024)));
52 }
53 else {
54 $res = _T('taille_cache_octets',array('octets'=>taille_en_octets($taille)));
55 }
56 $res = "<b>$res</b>";
57 }
58
59 $res = "<p>$res</p>";
60 ajax_retour($res);
61 }
62
63
64 /**
65 * Calculer la taille d'un dossier, sous dossiers inclus
66 *
67 * http://doc.spip.org/@calculer_taille_dossier
68 *
69 * @param $dir
70 * @return int
71 */
72 function calculer_taille_dossier ($dir) {
73 $handle = @opendir($dir);
74 if (!$handle) return 0;
75 $taille = 0;
76 while (($fichier = @readdir($handle)) !== false) {
77 // Eviter ".", "..", ".htaccess", etc.
78 if ($fichier[0] == '.') continue;
79 if (is_file($d = "$dir/$fichier")) {
80 $taille += filesize($d);
81 }
82 else if (is_dir($d))
83 $taille += calculer_taille_dossier($d);
84 }
85 closedir($handle);
86 return $taille;
87 }
88
89 ?>