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