[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / inc / icone_renommer.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 include_spip('inc/boutons');
16 include_spip('base/objets');
17
18 function inc_icone_renommer_dist($fond,$fonction){
19 $size = 24;
20 if (preg_match("/(?:-([0-9]{1,3}))?([.](gif|png))?$/i",$fond,$match)
21 AND ((isset($match[0]) AND $match[0]) OR (isset($match[1]) AND $match[1]))) {
22 if (isset($match[1]) AND $match[1]) {
23 $size = $match[1];
24 }
25 $type = substr($fond,0,-strlen($match[0]));
26 if (!isset($match[2]) OR !$match[2]) {
27 $fond .= ".png";
28 }
29 }
30 else {
31 $type = $fond;
32 $fond .= ".png";
33 }
34
35 $rtl = false;
36 if (preg_match(',[-_]rtl$,i',$type,$match)){
37 $rtl = true;
38 $type = substr($type,0,-strlen($match[0]));
39 }
40
41 // objet_type garde invariant tout ce qui ne commence par par id_, spip_
42 // et ne finit pas par un s, sauf si c'est une exception declaree
43 $type = objet_type($type, false);
44
45 $dir = "images/";
46 $f = "$type-$size.png";
47 if ($icone = find_in_theme($dir.$f)){
48 $dir = dirname($icone);
49 $fond = $icone;
50
51 if ($rtl
52 AND $fr = "$type-rtl-$size.png"
53 AND file_exists($dir.'/'.$fr))
54 $type = "$type-rtl";
55
56 $action = $fonction;
57 if ($action=="supprimer.gif"){
58 $action = "del";
59 }
60 elseif ($action=="creer.gif"){
61 $action = "new";
62 }
63 elseif ($action=="edit.gif"){
64 $action = "edit";
65 }
66 if (!in_array($action,array('del','new','edit')))
67 $action = "";
68 if ($action){
69 if ($fa = "$type-$action-$size.png"
70 AND file_exists($dir.'/'.$fa)){
71 $fond = $dir .'/'. $fa;
72 $fonction = "";
73 }
74 else {
75 $fonction = "$action-$size.png";
76 }
77 }
78 // c'est bon !
79 return array($fond,$fonction);
80 }
81
82 return array($fond,$fonction);
83 }
84 ?>