Completed
Push — master ( 565410...3576c2 )
by cam
04:33
created
ecrire/inc/chercher_logo.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Logos
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -37,31 +37,31 @@  discard block
 block discarded – undo
37 37
  **/
38 38
 function inc_chercher_logo_dist($id, $_id_objet, $mode = 'on') {
39 39
 
40
-	$mode = preg_replace(",\W,", '', $mode);
41
-	if ($mode) {
42
-		// chercher dans la base
43
-		$mode_document = 'logo' . $mode;
44
-		$objet = objet_type($_id_objet);
45
-		$doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', "D.mode=".sql_quote($mode_document)." AND L.objet=".sql_quote($objet)." AND id_objet=".intval($id));
46
-		if ($doc) {
47
-			$d = get_spip_doc($doc['fichier']);
48
-			return array($d, _DIR_IMG, basename($d), $d['extension'], @filemtime($d), $doc);
49
-		}
40
+    $mode = preg_replace(",\W,", '', $mode);
41
+    if ($mode) {
42
+        // chercher dans la base
43
+        $mode_document = 'logo' . $mode;
44
+        $objet = objet_type($_id_objet);
45
+        $doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', "D.mode=".sql_quote($mode_document)." AND L.objet=".sql_quote($objet)." AND id_objet=".intval($id));
46
+        if ($doc) {
47
+            $d = get_spip_doc($doc['fichier']);
48
+            return array($d, _DIR_IMG, basename($d), $d['extension'], @filemtime($d), $doc);
49
+        }
50 50
 
51
-		# TODO : deprecated
52
-		# attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval()
53
-		$type = type_du_logo($_id_objet);
54
-		$nom = $type . $mode . intval($id);
51
+        # TODO : deprecated
52
+        # attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval()
53
+        $type = type_du_logo($_id_objet);
54
+        $nom = $type . $mode . intval($id);
55 55
 
56
-		foreach ($GLOBALS['formats_logos'] as $format) {
57
-			if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) {
58
-				return array($d, _DIR_LOGOS, $nom, $format, @filemtime($d));
59
-			}
60
-		}
61
-	}
56
+        foreach ($GLOBALS['formats_logos'] as $format) {
57
+            if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) {
58
+                return array($d, _DIR_LOGOS, $nom, $format, @filemtime($d));
59
+            }
60
+        }
61
+    }
62 62
 
63
-	# coherence de type pour servir comme filtre (formulaire_login)
64
-	return array();
63
+    # coherence de type pour servir comme filtre (formulaire_login)
64
+    return array();
65 65
 }
66 66
 
67 67
 /**
@@ -80,15 +80,15 @@  discard block
 block discarded – undo
80 80
  * @deprecated
81 81
  **/
82 82
 function type_du_logo($_id_objet) {
83
-	return isset($GLOBALS['table_logos'][$_id_objet])
84
-		? $GLOBALS['table_logos'][$_id_objet]
85
-		: objet_type(preg_replace(',^id_,', '', $_id_objet));
83
+    return isset($GLOBALS['table_logos'][$_id_objet])
84
+        ? $GLOBALS['table_logos'][$_id_objet]
85
+        : objet_type(preg_replace(',^id_,', '', $_id_objet));
86 86
 }
87 87
 
88 88
 // Exceptions standards (historique)
89 89
 $GLOBALS['table_logos'] = array(
90
-	'id_article' => 'art',
91
-	'id_auteur' => 'aut',
92
-	'id_rubrique' => 'rub',
93
-	'id_groupe' => 'groupe',
90
+    'id_article' => 'art',
91
+    'id_auteur' => 'aut',
92
+    'id_rubrique' => 'rub',
93
+    'id_groupe' => 'groupe',
94 94
 );
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	$mode = preg_replace(",\W,", '', $mode);
41 41
 	if ($mode) {
42 42
 		// chercher dans la base
43
-		$mode_document = 'logo' . $mode;
43
+		$mode_document = 'logo'.$mode;
44 44
 		$objet = objet_type($_id_objet);
45 45
 		$doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', "D.mode=".sql_quote($mode_document)." AND L.objet=".sql_quote($objet)." AND id_objet=".intval($id));
46 46
 		if ($doc) {
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 		# TODO : deprecated
52 52
 		# attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval()
53 53
 		$type = type_du_logo($_id_objet);
54
-		$nom = $type . $mode . intval($id);
54
+		$nom = $type.$mode.intval($id);
55 55
 
56 56
 		foreach ($GLOBALS['formats_logos'] as $format) {
57
-			if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) {
57
+			if (@file_exists($d = (_DIR_LOGOS.$nom.'.'.$format))) {
58 58
 				return array($d, _DIR_LOGOS, $nom, $format, @filemtime($d));
59 59
 			}
60 60
 		}
Please login to merge, or discard this patch.
ecrire/action/editer_logo.php 3 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -30,34 +30,34 @@  discard block
 block discarded – undo
30 30
  *     `on` ou `off`
31 31
  */
32 32
 function logo_supprimer($objet, $id_objet, $etat) {
33
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
34
-	$objet = objet_type($objet);
35
-	$primary = id_table_objet($objet);
36
-	include_spip('inc/chercher_logo');
37
-
38
-	// existe-t-il deja un logo ?
39
-	$logo = $chercher_logo($id_objet, $primary, $etat);
40
-	if ($logo) {
41
-		# TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base
42
-		if (count($logo) < 6) {
43
-			spip_unlink($logo[0]);
44
-		}
45
-		elseif ($doc = $logo[5]
46
-			and isset($doc['id_document'])
47
-		  and $id_document = $doc['id_document']) {
48
-
49
-			include_spip('action/editer_liens');
50
-			// supprimer le lien dans la base
51
-			objet_dissocier(array('document' => $id_document), array($objet => $id_objet), array('role' => '*'));
52
-
53
-			// verifier si il reste des liens avec d'autres objets et sinon supprimer
54
-			$liens = objet_trouver_liens(array('document' => $id_document), '*');
55
-			if (!count($liens)) {
56
-				$supprimer_document = charger_fonction('supprimer_document', 'action');
57
-				$supprimer_document($doc['id_document']);
58
-			}
59
-		}
60
-	}
33
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
34
+    $objet = objet_type($objet);
35
+    $primary = id_table_objet($objet);
36
+    include_spip('inc/chercher_logo');
37
+
38
+    // existe-t-il deja un logo ?
39
+    $logo = $chercher_logo($id_objet, $primary, $etat);
40
+    if ($logo) {
41
+        # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base
42
+        if (count($logo) < 6) {
43
+            spip_unlink($logo[0]);
44
+        }
45
+        elseif ($doc = $logo[5]
46
+            and isset($doc['id_document'])
47
+          and $id_document = $doc['id_document']) {
48
+
49
+            include_spip('action/editer_liens');
50
+            // supprimer le lien dans la base
51
+            objet_dissocier(array('document' => $id_document), array($objet => $id_objet), array('role' => '*'));
52
+
53
+            // verifier si il reste des liens avec d'autres objets et sinon supprimer
54
+            $liens = objet_trouver_liens(array('document' => $id_document), '*');
55
+            if (!count($liens)) {
56
+                $supprimer_document = charger_fonction('supprimer_document', 'action');
57
+                $supprimer_document($doc['id_document']);
58
+            }
59
+        }
60
+    }
61 61
 }
62 62
 
63 63
 /**
@@ -74,72 +74,72 @@  discard block
 block discarded – undo
74 74
  *     Erreur, sinon ''
75 75
  */
76 76
 function logo_modifier($objet, $id_objet, $etat, $source) {
77
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
78
-	$objet = objet_type($objet);
79
-	$primary = id_table_objet($objet);
80
-	include_spip('inc/chercher_logo');
81
-
82
-	$mode = preg_replace(",\W,", '', $etat);
83
-	if (!$mode){
84
-		spip_log("logo_modifier : etat $etat invalide", 'logo');
85
-		$erreur = 'etat invalide';
86
-
87
-		return $erreur;
88
-	}
89
-	// chercher dans la base
90
-	$mode_document = 'logo' . $mode;
91
-
92
-	// supprimer le logo eventueel existant
93
-	// TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple)
94
-	// mais de toute facon l'interface actuelle oblige a supprimer + reinserer
95
-	logo_supprimer($objet, $id_objet, $etat);
96
-
97
-
98
-	include_spip('inc/documents');
99
-	$erreur = '';
100
-
101
-	if (!$source) {
102
-		spip_log('spip_image_ajouter : source inconnue', 'logo');
103
-		$erreur = 'source inconnue';
104
-
105
-		return $erreur;
106
-	}
107
-
108
-	// fichier dans upload/
109
-	if (is_string($source)) {
110
-		$tmp_name = false;
111
-		if (file_exists($source)) {
112
-			$tmp_name = $source;
113
-		} elseif (file_exists($f = determine_upload() . $source)) {
114
-			$tmp_name = $f;
115
-		}
116
-		if (!$tmp_name) {
117
-			spip_log('spip_image_ajouter : source inconnue', 'logo');
118
-			$erreur = 'source inconnue';
119
-
120
-			return $erreur;
121
-		}
122
-		$source = array(
123
-			'tmp_name' => $tmp_name,
124
-			'name' => basename($tmp_name),
125
-		);
126
-	} elseif ($erreur = check_upload_error($source['error'], '', true)) {
127
-		return $erreur;
128
-	}
129
-
130
-	$source['mode'] = $mode_document;
131
-	$ajouter_documents = charger_fonction('ajouter_documents', 'action');
132
-	$ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document);
133
-
134
-	$id_document = reset($ajoutes);
135
-
136
-	if (!is_numeric($id_document)) {
137
-		$erreur = ($id_document ? $id_document : 'Erreur inconnue');
138
-		spip_log("Erreur ajout logo : $erreur pour source=".json_encode($source), 'logo');
139
-		return $erreur;
140
-	}
141
-
142
-	return ''; // tout est bon, pas d'erreur
77
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
78
+    $objet = objet_type($objet);
79
+    $primary = id_table_objet($objet);
80
+    include_spip('inc/chercher_logo');
81
+
82
+    $mode = preg_replace(",\W,", '', $etat);
83
+    if (!$mode){
84
+        spip_log("logo_modifier : etat $etat invalide", 'logo');
85
+        $erreur = 'etat invalide';
86
+
87
+        return $erreur;
88
+    }
89
+    // chercher dans la base
90
+    $mode_document = 'logo' . $mode;
91
+
92
+    // supprimer le logo eventueel existant
93
+    // TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple)
94
+    // mais de toute facon l'interface actuelle oblige a supprimer + reinserer
95
+    logo_supprimer($objet, $id_objet, $etat);
96
+
97
+
98
+    include_spip('inc/documents');
99
+    $erreur = '';
100
+
101
+    if (!$source) {
102
+        spip_log('spip_image_ajouter : source inconnue', 'logo');
103
+        $erreur = 'source inconnue';
104
+
105
+        return $erreur;
106
+    }
107
+
108
+    // fichier dans upload/
109
+    if (is_string($source)) {
110
+        $tmp_name = false;
111
+        if (file_exists($source)) {
112
+            $tmp_name = $source;
113
+        } elseif (file_exists($f = determine_upload() . $source)) {
114
+            $tmp_name = $f;
115
+        }
116
+        if (!$tmp_name) {
117
+            spip_log('spip_image_ajouter : source inconnue', 'logo');
118
+            $erreur = 'source inconnue';
119
+
120
+            return $erreur;
121
+        }
122
+        $source = array(
123
+            'tmp_name' => $tmp_name,
124
+            'name' => basename($tmp_name),
125
+        );
126
+    } elseif ($erreur = check_upload_error($source['error'], '', true)) {
127
+        return $erreur;
128
+    }
129
+
130
+    $source['mode'] = $mode_document;
131
+    $ajouter_documents = charger_fonction('ajouter_documents', 'action');
132
+    $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document);
133
+
134
+    $id_document = reset($ajoutes);
135
+
136
+    if (!is_numeric($id_document)) {
137
+        $erreur = ($id_document ? $id_document : 'Erreur inconnue');
138
+        spip_log("Erreur ajout logo : $erreur pour source=".json_encode($source), 'logo');
139
+        return $erreur;
140
+    }
141
+
142
+    return ''; // tout est bon, pas d'erreur
143 143
 
144 144
 }
145 145
 
@@ -155,27 +155,27 @@  discard block
 block discarded – undo
155 155
  */
156 156
 // https://code.spip.net/@decoder_type_image
157 157
 function logo_decoder_type_image($type, $strict = false) {
158
-	switch ($type) {
159
-		case IMAGETYPE_GIF:
160
-			return 'gif';
161
-		case IMAGETYPE_JPEG:
162
-			return 'jpg';
163
-		case IMAGETYPE_PNG:
164
-			return 'png';
165
-		case IMAGETYPE_SWF:
166
-			return $strict ? '' : 'swf';
167
-		case IMAGETYPE_PSD:
168
-			return 'psd';
169
-		case IMAGETYPE_BMP:
170
-			return 'bmp';
171
-		case IMAGETYPE_TIFF_II:
172
-		case IMAGETYPE_TIFF_MM:
173
-			return 'tif';
174
-		case IMAGETYPE_WEBP:
175
-			return 'webp';
176
-		case IMAGETYPE_SVG:
177
-			return $strict ? '' : 'svg';
178
-		default:
179
-			return '';
180
-	}
158
+    switch ($type) {
159
+        case IMAGETYPE_GIF:
160
+            return 'gif';
161
+        case IMAGETYPE_JPEG:
162
+            return 'jpg';
163
+        case IMAGETYPE_PNG:
164
+            return 'png';
165
+        case IMAGETYPE_SWF:
166
+            return $strict ? '' : 'swf';
167
+        case IMAGETYPE_PSD:
168
+            return 'psd';
169
+        case IMAGETYPE_BMP:
170
+            return 'bmp';
171
+        case IMAGETYPE_TIFF_II:
172
+        case IMAGETYPE_TIFF_MM:
173
+            return 'tif';
174
+        case IMAGETYPE_WEBP:
175
+            return 'webp';
176
+        case IMAGETYPE_SVG:
177
+            return $strict ? '' : 'svg';
178
+        default:
179
+            return '';
180
+    }
181 181
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 	include_spip('inc/chercher_logo');
81 81
 
82 82
 	$mode = preg_replace(",\W,", '', $etat);
83
-	if (!$mode){
83
+	if (!$mode) {
84 84
 		spip_log("logo_modifier : etat $etat invalide", 'logo');
85 85
 		$erreur = 'etat invalide';
86 86
 
87 87
 		return $erreur;
88 88
 	}
89 89
 	// chercher dans la base
90
-	$mode_document = 'logo' . $mode;
90
+	$mode_document = 'logo'.$mode;
91 91
 
92 92
 	// supprimer le logo eventueel existant
93 93
 	// TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple)
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		$tmp_name = false;
111 111
 		if (file_exists($source)) {
112 112
 			$tmp_name = $source;
113
-		} elseif (file_exists($f = determine_upload() . $source)) {
113
+		} elseif (file_exists($f = determine_upload().$source)) {
114 114
 			$tmp_name = $f;
115 115
 		}
116 116
 		if (!$tmp_name) {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,8 +41,7 @@
 block discarded – undo
41 41
 		# TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base
42 42
 		if (count($logo) < 6) {
43 43
 			spip_unlink($logo[0]);
44
-		}
45
-		elseif ($doc = $logo[5]
44
+		} elseif ($doc = $logo[5]
46 45
 			and isset($doc['id_document'])
47 46
 		  and $id_document = $doc['id_document']) {
48 47
 
Please login to merge, or discard this patch.