Completed
Pull Request — master (#39)
by
unknown
07:42
created
ecrire/action/logout.php 2 patches
Indentation   +82 added lines, -82 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
 include_spip('inc/cookie');
@@ -34,68 +34,68 @@  discard block
 block discarded – undo
34 34
  *
35 35
  */
36 36
 function action_logout_dist() {
37
-	$logout = _request('logout');
38
-	$url = securiser_redirect_action(_request('url'));
39
-	// cas particulier, logout dans l'espace public
40
-	if ($logout == 'public' and !$url) {
41
-		$url = url_de_base();
42
-	}
43
-
44
-	// seul le loge peut se deloger (mais id_auteur peut valoir 0 apres une restauration avortee)
45
-	if (isset($GLOBALS['visiteur_session']['id_auteur'])
46
-		and is_numeric($GLOBALS['visiteur_session']['id_auteur'])
47
-		// des sessions anonymes avec id_auteur=0 existent, mais elle n'ont pas de statut : double check
48
-		and isset($GLOBALS['visiteur_session']['statut'])
49
-	) {
50
-
51
-		// il faut un jeton pour fermer la session (eviter les CSRF)
52
-		if (!$jeton = _request('jeton')
53
-			or !verifier_jeton_logout($jeton, $GLOBALS['visiteur_session'])
54
-		) {
55
-			$jeton = generer_jeton_logout($GLOBALS['visiteur_session']);
56
-			$action = generer_url_action("logout", "jeton=$jeton");
57
-			$action = parametre_url($action, 'logout', _request('logout'));
58
-			$action = parametre_url($action, 'url', _request('url'));
59
-			include_spip("inc/minipres");
60
-			include_spip("inc/filtres");
61
-			$texte = bouton_action(_T('spip:icone_deconnecter'), $action);
62
-			$texte = "<div class='boutons'>$texte</div>";
63
-			$texte .= '<script type="text/javascript">document.write("<style>body{visibility:hidden;}</style>");window.document.forms[0].submit();</script>';
64
-			$res = minipres(_T('spip:icone_deconnecter'), $texte, '', true);
65
-			echo $res;
66
-
67
-			return;
68
-		}
69
-
70
-		include_spip('inc/auth');
71
-		auth_trace($GLOBALS['visiteur_session'], '0000-00-00 00:00:00');
72
-		// le logout explicite vaut destruction de toutes les sessions
73
-		if (isset($_COOKIE['spip_session'])) {
74
-			$session = charger_fonction('session', 'inc');
75
-			$session($GLOBALS['visiteur_session']['id_auteur']);
76
-			spip_setcookie('spip_session', $_COOKIE['spip_session'], time() - 3600);
77
-		}
78
-		// si authentification http, et que la personne est loge,
79
-		// pour se deconnecter, il faut proposer un nouveau formulaire de connexion http
80
-		if (isset($_SERVER['PHP_AUTH_USER'])
81
-			and !$GLOBALS['ignore_auth_http']
82
-			and $GLOBALS['auth_can_disconnect']
83
-		) {
84
-			ask_php_auth(_T('login_deconnexion_ok'),
85
-				_T('login_verifiez_navigateur'),
86
-				_T('login_retour_public'),
87
-				"redirect=" . _DIR_RESTREINT_ABS,
88
-				_T('login_test_navigateur'),
89
-				true);
90
-
91
-		}
92
-	}
93
-
94
-	// Rediriger en contrant le cache navigateur (Safari3)
95
-	include_spip('inc/headers');
96
-	redirige_par_entete($url
97
-		? parametre_url($url, 'var_hasard', uniqid(rand()), '&')
98
-		: generer_url_public('login'));
37
+    $logout = _request('logout');
38
+    $url = securiser_redirect_action(_request('url'));
39
+    // cas particulier, logout dans l'espace public
40
+    if ($logout == 'public' and !$url) {
41
+        $url = url_de_base();
42
+    }
43
+
44
+    // seul le loge peut se deloger (mais id_auteur peut valoir 0 apres une restauration avortee)
45
+    if (isset($GLOBALS['visiteur_session']['id_auteur'])
46
+        and is_numeric($GLOBALS['visiteur_session']['id_auteur'])
47
+        // des sessions anonymes avec id_auteur=0 existent, mais elle n'ont pas de statut : double check
48
+        and isset($GLOBALS['visiteur_session']['statut'])
49
+    ) {
50
+
51
+        // il faut un jeton pour fermer la session (eviter les CSRF)
52
+        if (!$jeton = _request('jeton')
53
+            or !verifier_jeton_logout($jeton, $GLOBALS['visiteur_session'])
54
+        ) {
55
+            $jeton = generer_jeton_logout($GLOBALS['visiteur_session']);
56
+            $action = generer_url_action("logout", "jeton=$jeton");
57
+            $action = parametre_url($action, 'logout', _request('logout'));
58
+            $action = parametre_url($action, 'url', _request('url'));
59
+            include_spip("inc/minipres");
60
+            include_spip("inc/filtres");
61
+            $texte = bouton_action(_T('spip:icone_deconnecter'), $action);
62
+            $texte = "<div class='boutons'>$texte</div>";
63
+            $texte .= '<script type="text/javascript">document.write("<style>body{visibility:hidden;}</style>");window.document.forms[0].submit();</script>';
64
+            $res = minipres(_T('spip:icone_deconnecter'), $texte, '', true);
65
+            echo $res;
66
+
67
+            return;
68
+        }
69
+
70
+        include_spip('inc/auth');
71
+        auth_trace($GLOBALS['visiteur_session'], '0000-00-00 00:00:00');
72
+        // le logout explicite vaut destruction de toutes les sessions
73
+        if (isset($_COOKIE['spip_session'])) {
74
+            $session = charger_fonction('session', 'inc');
75
+            $session($GLOBALS['visiteur_session']['id_auteur']);
76
+            spip_setcookie('spip_session', $_COOKIE['spip_session'], time() - 3600);
77
+        }
78
+        // si authentification http, et que la personne est loge,
79
+        // pour se deconnecter, il faut proposer un nouveau formulaire de connexion http
80
+        if (isset($_SERVER['PHP_AUTH_USER'])
81
+            and !$GLOBALS['ignore_auth_http']
82
+            and $GLOBALS['auth_can_disconnect']
83
+        ) {
84
+            ask_php_auth(_T('login_deconnexion_ok'),
85
+                _T('login_verifiez_navigateur'),
86
+                _T('login_retour_public'),
87
+                "redirect=" . _DIR_RESTREINT_ABS,
88
+                _T('login_test_navigateur'),
89
+                true);
90
+
91
+        }
92
+    }
93
+
94
+    // Rediriger en contrant le cache navigateur (Safari3)
95
+    include_spip('inc/headers');
96
+    redirige_par_entete($url
97
+        ? parametre_url($url, 'var_hasard', uniqid(rand()), '&')
98
+        : generer_url_public('login'));
99 99
 }
100 100
 
101 101
 /**
@@ -106,18 +106,18 @@  discard block
 block discarded – undo
106 106
  * @return string
107 107
  */
108 108
 function generer_jeton_logout($session, $alea = null) {
109
-	if (is_null($alea)) {
110
-		include_spip('inc/acces');
111
-		$alea = charger_aleas();
112
-	}
113
-
114
-	$jeton = md5($session['date_session']
115
-		. $session['id_auteur']
116
-		. $session['statut']
117
-		. $alea
118
-	);
119
-
120
-	return $jeton;
109
+    if (is_null($alea)) {
110
+        include_spip('inc/acces');
111
+        $alea = charger_aleas();
112
+    }
113
+
114
+    $jeton = md5($session['date_session']
115
+        . $session['id_auteur']
116
+        . $session['statut']
117
+        . $alea
118
+    );
119
+
120
+    return $jeton;
121 121
 }
122 122
 
123 123
 /**
@@ -131,13 +131,13 @@  discard block
 block discarded – undo
131 131
  * @return bool
132 132
  */
133 133
 function verifier_jeton_logout($jeton, $session) {
134
-	if (generer_jeton_logout($session) === $jeton) {
135
-		return true;
136
-	}
134
+    if (generer_jeton_logout($session) === $jeton) {
135
+        return true;
136
+    }
137 137
 
138
-	if (generer_jeton_logout($session, $GLOBALS['meta']['alea_ephemere_ancien']) === $jeton) {
139
-		return true;
140
-	}
138
+    if (generer_jeton_logout($session, $GLOBALS['meta']['alea_ephemere_ancien']) === $jeton) {
139
+        return true;
140
+    }
141 141
 
142
-	return false;
142
+    return false;
143 143
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
 			ask_php_auth(_T('login_deconnexion_ok'),
85 85
 				_T('login_verifiez_navigateur'),
86 86
 				_T('login_retour_public'),
87
-				"redirect=" . _DIR_RESTREINT_ABS,
87
+				"redirect="._DIR_RESTREINT_ABS,
88 88
 				_T('login_test_navigateur'),
89 89
 				true);
90 90
 
Please login to merge, or discard this patch.
ecrire/action/forcer_job.php 1 patch
Indentation   +10 added lines, -10 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
 /**
@@ -26,15 +26,15 @@  discard block
 block discarded – undo
26 26
  * @return void
27 27
  */
28 28
 function action_forcer_job_dist() {
29
-	$securiser_action = charger_fonction('securiser_action', 'inc');
30
-	$id_job = $securiser_action();
29
+    $securiser_action = charger_fonction('securiser_action', 'inc');
30
+    $id_job = $securiser_action();
31 31
 
32
-	if ($id_job = intval($id_job)
33
-		and autoriser('forcer', 'job', $id_job)
34
-	) {
35
-		include_spip('inc/queue');
36
-		include_spip('inc/genie');
37
-		queue_schedule(array($id_job));
38
-	}
32
+    if ($id_job = intval($id_job)
33
+        and autoriser('forcer', 'job', $id_job)
34
+    ) {
35
+        include_spip('inc/queue');
36
+        include_spip('inc/genie');
37
+        queue_schedule(array($id_job));
38
+    }
39 39
 
40 40
 }
Please login to merge, or discard this patch.
ecrire/action/purger.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Cache
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -39,54 +39,54 @@  discard block
 block discarded – undo
39 39
  *     de l'action sécurisée.
40 40
  */
41 41
 function action_purger_dist($arg = null) {
42
-	if (is_null($arg)) {
43
-		$securiser_action = charger_fonction('securiser_action', 'inc');
44
-		$arg = $securiser_action();
45
-	}
42
+    if (is_null($arg)) {
43
+        $securiser_action = charger_fonction('securiser_action', 'inc');
44
+        $arg = $securiser_action();
45
+    }
46 46
 
47
-	include_spip('inc/invalideur');
47
+    include_spip('inc/invalideur');
48 48
 
49
-	spip_log("purger $arg");
49
+    spip_log("purger $arg");
50 50
 
51
-	switch ($arg) {
52
-		case 'inhibe_cache':
53
-			// inhiber le cache pendant 24h
54
-			ecrire_meta('cache_inhib', $_SERVER['REQUEST_TIME'] + 24 * 3600);
55
-			break;
56
-		case 'reactive_cache':
57
-			effacer_meta('cache_inhib');
58
-			break;
51
+    switch ($arg) {
52
+        case 'inhibe_cache':
53
+            // inhiber le cache pendant 24h
54
+            ecrire_meta('cache_inhib', $_SERVER['REQUEST_TIME'] + 24 * 3600);
55
+            break;
56
+        case 'reactive_cache':
57
+            effacer_meta('cache_inhib');
58
+            break;
59 59
 
60
-		case 'cache':
61
-			supprime_invalideurs();
62
-			@spip_unlink(_CACHE_RUBRIQUES);
63
-			@spip_unlink(_CACHE_CHEMIN);
64
-			@spip_unlink(_DIR_TMP . "plugin_xml_cache.gz");
65
-			// on ne supprime que _CACHE_PLUGINS_OPT qui declenche la reconstruction des 3
66
-			// _CACHE_PIPELINES _CACHE_PLUGINS_PATH et _CACHE_PLUGINS_FCT
67
-			// pour eviter des problemes de concurence
68
-			// cf http://core.spip.net/issues/2989
69
-			//@spip_unlink(_CACHE_PIPELINES);
70
-			//@spip_unlink(_CACHE_PLUGINS_PATH);
71
-			//@spip_unlink(_CACHE_PLUGINS_FCT);
72
-			@spip_unlink(_CACHE_PLUGINS_OPT);
73
-			purger_repertoire(_DIR_CACHE, array('subdir' => true));
74
-			purger_repertoire(_DIR_AIDE);
75
-			purger_repertoire(_DIR_VAR . 'cache-css');
76
-			purger_repertoire(_DIR_VAR . 'cache-js');
77
-			break;
60
+        case 'cache':
61
+            supprime_invalideurs();
62
+            @spip_unlink(_CACHE_RUBRIQUES);
63
+            @spip_unlink(_CACHE_CHEMIN);
64
+            @spip_unlink(_DIR_TMP . "plugin_xml_cache.gz");
65
+            // on ne supprime que _CACHE_PLUGINS_OPT qui declenche la reconstruction des 3
66
+            // _CACHE_PIPELINES _CACHE_PLUGINS_PATH et _CACHE_PLUGINS_FCT
67
+            // pour eviter des problemes de concurence
68
+            // cf http://core.spip.net/issues/2989
69
+            //@spip_unlink(_CACHE_PIPELINES);
70
+            //@spip_unlink(_CACHE_PLUGINS_PATH);
71
+            //@spip_unlink(_CACHE_PLUGINS_FCT);
72
+            @spip_unlink(_CACHE_PLUGINS_OPT);
73
+            purger_repertoire(_DIR_CACHE, array('subdir' => true));
74
+            purger_repertoire(_DIR_AIDE);
75
+            purger_repertoire(_DIR_VAR . 'cache-css');
76
+            purger_repertoire(_DIR_VAR . 'cache-js');
77
+            break;
78 78
 
79
-		case 'squelettes':
80
-			purger_repertoire(_DIR_SKELS);
81
-			break;
79
+        case 'squelettes':
80
+            purger_repertoire(_DIR_SKELS);
81
+            break;
82 82
 
83
-		case 'vignettes':
84
-			purger_repertoire(_DIR_VAR, array('subdir' => true));
85
-			supprime_invalideurs();
86
-			purger_repertoire(_DIR_CACHE, array('subdir' => true));
87
-			break;
88
-	}
83
+        case 'vignettes':
84
+            purger_repertoire(_DIR_VAR, array('subdir' => true));
85
+            supprime_invalideurs();
86
+            purger_repertoire(_DIR_CACHE, array('subdir' => true));
87
+            break;
88
+    }
89 89
 
90
-	// le faire savoir aux plugins
91
-	pipeline('trig_purger', $arg);
90
+    // le faire savoir aux plugins
91
+    pipeline('trig_purger', $arg);
92 92
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 			supprime_invalideurs();
62 62
 			@spip_unlink(_CACHE_RUBRIQUES);
63 63
 			@spip_unlink(_CACHE_CHEMIN);
64
-			@spip_unlink(_DIR_TMP . "plugin_xml_cache.gz");
64
+			@spip_unlink(_DIR_TMP."plugin_xml_cache.gz");
65 65
 			// on ne supprime que _CACHE_PLUGINS_OPT qui declenche la reconstruction des 3
66 66
 			// _CACHE_PIPELINES _CACHE_PLUGINS_PATH et _CACHE_PLUGINS_FCT
67 67
 			// pour eviter des problemes de concurence
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 			@spip_unlink(_CACHE_PLUGINS_OPT);
73 73
 			purger_repertoire(_DIR_CACHE, array('subdir' => true));
74 74
 			purger_repertoire(_DIR_AIDE);
75
-			purger_repertoire(_DIR_VAR . 'cache-css');
76
-			purger_repertoire(_DIR_VAR . 'cache-js');
75
+			purger_repertoire(_DIR_VAR.'cache-css');
76
+			purger_repertoire(_DIR_VAR.'cache-js');
77 77
 			break;
78 78
 
79 79
 		case 'squelettes':
Please login to merge, or discard this patch.
ecrire/action/etre_webmestre.php 1 patch
Indentation   +21 added lines, -21 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
 include_spip('inc/actions');
@@ -29,22 +29,22 @@  discard block
 block discarded – undo
29 29
  * @return void
30 30
  */
31 31
 function action_etre_webmestre_dist() {
32
-	$securiser_action = charger_fonction('securiser_action', 'inc');
33
-	$time = $securiser_action();
34
-
35
-	if (time() - $time < 15 * 60
36
-		and $GLOBALS['visiteur_session']['statut'] == '0minirezo'
37
-		and $GLOBALS['visiteur_session']['webmestre'] !== 'oui'
38
-	) {
39
-		$action = _T('info_admin_etre_webmestre');
40
-		$admin = charger_fonction('admin', 'inc');
41
-		// lance la verif par ftp et l'appel
42
-		// a base_etre_webmestre_dist quand c'est OK
43
-		if ($r = $admin('etre_webmestre', $action)) {
44
-			echo $r;
45
-			exit;
46
-		}
47
-	}
32
+    $securiser_action = charger_fonction('securiser_action', 'inc');
33
+    $time = $securiser_action();
34
+
35
+    if (time() - $time < 15 * 60
36
+        and $GLOBALS['visiteur_session']['statut'] == '0minirezo'
37
+        and $GLOBALS['visiteur_session']['webmestre'] !== 'oui'
38
+    ) {
39
+        $action = _T('info_admin_etre_webmestre');
40
+        $admin = charger_fonction('admin', 'inc');
41
+        // lance la verif par ftp et l'appel
42
+        // a base_etre_webmestre_dist quand c'est OK
43
+        if ($r = $admin('etre_webmestre', $action)) {
44
+            echo $r;
45
+            exit;
46
+        }
47
+    }
48 48
 
49 49
 }
50 50
 
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
  * @return void
55 55
  */
56 56
 function base_etre_webmestre_dist() {
57
-	if ($GLOBALS['visiteur_session']['statut'] == '0minirezo' and $GLOBALS['visiteur_session']['webmestre'] !== 'oui') {
58
-		include_spip('action/editer_auteur');
59
-		instituer_auteur($GLOBALS['visiteur_session']['id_auteur'], array('webmestre' => 'oui'), true);
60
-	}
57
+    if ($GLOBALS['visiteur_session']['statut'] == '0minirezo' and $GLOBALS['visiteur_session']['webmestre'] !== 'oui') {
58
+        include_spip('action/editer_auteur');
59
+        instituer_auteur($GLOBALS['visiteur_session']['id_auteur'], array('webmestre' => 'oui'), true);
60
+    }
61 61
 }
Please login to merge, or discard this patch.
ecrire/action/editer_logo.php 2 patches
Indentation   +139 added lines, -139 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,16 +30,16 @@  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
-		spip_unlink($logo[0]);
42
-	}
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
+        spip_unlink($logo[0]);
42
+    }
43 43
 }
44 44
 
45 45
 /**
@@ -56,132 +56,132 @@  discard block
 block discarded – undo
56 56
  *     Erreur, sinon ''
57 57
  */
58 58
 function logo_modifier($objet, $id_objet, $etat, $source) {
59
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
60
-	$objet = objet_type($objet);
61
-	$primary = id_table_objet($objet);
62
-	include_spip('inc/chercher_logo');
63
-	$type = type_du_logo($primary);
64
-
65
-	// nom du logo
66
-	$nom = $type . $etat . $id_objet;
67
-
68
-	// supprimer le logo eventueel existant
69
-	logo_supprimer($objet, $id_objet, $etat);
70
-
71
-	include_spip('inc/documents');
72
-	$erreur = '';
73
-
74
-	if (!$source) {
75
-		spip_log('spip_image_ajouter : source inconnue');
76
-		$erreur = 'source inconnue';
77
-
78
-		return $erreur;
79
-	}
80
-
81
-	$file_tmp = _DIR_LOGOS . $nom . '.tmp';
82
-
83
-	$ok = false;
84
-	// fichier dans upload/
85
-	if (is_string($source)) {
86
-		if (file_exists($source)) {
87
-			$ok = @copy($source, $file_tmp);
88
-		} elseif (file_exists($f = determine_upload() . $source)) {
89
-			$ok = @copy($f, $file_tmp);
90
-		}
91
-	} elseif (!$erreur = check_upload_error($source['error'], '', true)) {
92
-		// Intercepter une erreur a l'envoi
93
-		// analyse le type de l'image (on ne fait pas confiance au nom de
94
-		// fichier envoye par le browser : pour les Macs c'est plus sur)
95
-		$ok = deplacer_fichier_upload($source['tmp_name'], $file_tmp);
96
-	}
97
-
98
-	if ($erreur) {
99
-		return $erreur;
100
-	}
101
-	if (!$ok or !file_exists($file_tmp)) {
102
-		spip_log($erreur = "probleme de copie pour $file_tmp ");
103
-
104
-		return $erreur;
105
-	}
106
-
107
-	$size = @getimagesize($file_tmp);
108
-	$extension = !$size ? '' : ($size[2] > 3 ? '' : $GLOBALS['formats_logos'][$size[2] - 1]);
109
-	if ($extension) {
110
-		@rename($file_tmp, $file_tmp . ".$extension");
111
-		$file_tmp = $file_tmp . ".$extension";
112
-		$poids = filesize($file_tmp);
113
-
114
-		if (defined('_LOGO_MAX_WIDTH') or defined('_LOGO_MAX_HEIGHT')) {
115
-			if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH)
116
-				or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT)
117
-			) {
118
-				$max_width = (defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH) ? _LOGO_MAX_WIDTH : '*';
119
-				$max_height = (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT) ? _LOGO_MAX_HEIGHT : '*';
120
-
121
-				// pas la peine d'embeter le redacteur avec ca si on a active le calcul des miniatures
122
-				// on met directement a la taille maxi a la volee
123
-				if (isset($GLOBALS['meta']['creer_preview']) and $GLOBALS['meta']['creer_preview'] == 'oui') {
124
-					include_spip('inc/filtres');
125
-					$img = filtrer('image_reduire', $file_tmp, $max_width, $max_height);
126
-					$img = extraire_attribut($img, 'src');
127
-					$img = supprimer_timestamp($img);
128
-					if (@file_exists($img) and $img !== $file_tmp) {
129
-						spip_unlink($file_tmp);
130
-						@rename($img, $file_tmp);
131
-						$size = @getimagesize($file_tmp);
132
-					}
133
-				}
134
-				// verifier au cas ou image_reduire a echoue
135
-				if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH)
136
-					or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT)
137
-				) {
138
-					spip_unlink($file_tmp);
139
-					$erreur = _T(
140
-						'info_logo_max_poids',
141
-						array(
142
-							'maxi' =>
143
-								_T(
144
-									'info_largeur_vignette',
145
-									array(
146
-										'largeur_vignette' => $max_width,
147
-										'hauteur_vignette' => $max_height
148
-									)
149
-								),
150
-							'actuel' =>
151
-								_T(
152
-									'info_largeur_vignette',
153
-									array(
154
-										'largeur_vignette' => $size[0],
155
-										'hauteur_vignette' => $size[1]
156
-									)
157
-								)
158
-						)
159
-					);
160
-				}
161
-			}
162
-		}
163
-
164
-		if (!$erreur and defined('_LOGO_MAX_SIZE') and _LOGO_MAX_SIZE and $poids > _LOGO_MAX_SIZE * 1024) {
165
-			spip_unlink($file_tmp);
166
-			$erreur = _T(
167
-				'info_logo_max_poids',
168
-				array(
169
-					'maxi' => taille_en_octets(_LOGO_MAX_SIZE * 1024),
170
-					'actuel' => taille_en_octets($poids)
171
-				)
172
-			);
173
-		}
174
-
175
-		if (!$erreur) {
176
-			@rename($file_tmp, _DIR_LOGOS . $nom . ".$extension");
177
-		}
178
-	} else {
179
-		spip_unlink($file_tmp);
180
-		$erreur = _T(
181
-			'info_logo_format_interdit',
182
-			array('formats' => join(', ', $GLOBALS['formats_logos']))
183
-		);
184
-	}
185
-
186
-	return $erreur;
59
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
60
+    $objet = objet_type($objet);
61
+    $primary = id_table_objet($objet);
62
+    include_spip('inc/chercher_logo');
63
+    $type = type_du_logo($primary);
64
+
65
+    // nom du logo
66
+    $nom = $type . $etat . $id_objet;
67
+
68
+    // supprimer le logo eventueel existant
69
+    logo_supprimer($objet, $id_objet, $etat);
70
+
71
+    include_spip('inc/documents');
72
+    $erreur = '';
73
+
74
+    if (!$source) {
75
+        spip_log('spip_image_ajouter : source inconnue');
76
+        $erreur = 'source inconnue';
77
+
78
+        return $erreur;
79
+    }
80
+
81
+    $file_tmp = _DIR_LOGOS . $nom . '.tmp';
82
+
83
+    $ok = false;
84
+    // fichier dans upload/
85
+    if (is_string($source)) {
86
+        if (file_exists($source)) {
87
+            $ok = @copy($source, $file_tmp);
88
+        } elseif (file_exists($f = determine_upload() . $source)) {
89
+            $ok = @copy($f, $file_tmp);
90
+        }
91
+    } elseif (!$erreur = check_upload_error($source['error'], '', true)) {
92
+        // Intercepter une erreur a l'envoi
93
+        // analyse le type de l'image (on ne fait pas confiance au nom de
94
+        // fichier envoye par le browser : pour les Macs c'est plus sur)
95
+        $ok = deplacer_fichier_upload($source['tmp_name'], $file_tmp);
96
+    }
97
+
98
+    if ($erreur) {
99
+        return $erreur;
100
+    }
101
+    if (!$ok or !file_exists($file_tmp)) {
102
+        spip_log($erreur = "probleme de copie pour $file_tmp ");
103
+
104
+        return $erreur;
105
+    }
106
+
107
+    $size = @getimagesize($file_tmp);
108
+    $extension = !$size ? '' : ($size[2] > 3 ? '' : $GLOBALS['formats_logos'][$size[2] - 1]);
109
+    if ($extension) {
110
+        @rename($file_tmp, $file_tmp . ".$extension");
111
+        $file_tmp = $file_tmp . ".$extension";
112
+        $poids = filesize($file_tmp);
113
+
114
+        if (defined('_LOGO_MAX_WIDTH') or defined('_LOGO_MAX_HEIGHT')) {
115
+            if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH)
116
+                or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT)
117
+            ) {
118
+                $max_width = (defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH) ? _LOGO_MAX_WIDTH : '*';
119
+                $max_height = (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT) ? _LOGO_MAX_HEIGHT : '*';
120
+
121
+                // pas la peine d'embeter le redacteur avec ca si on a active le calcul des miniatures
122
+                // on met directement a la taille maxi a la volee
123
+                if (isset($GLOBALS['meta']['creer_preview']) and $GLOBALS['meta']['creer_preview'] == 'oui') {
124
+                    include_spip('inc/filtres');
125
+                    $img = filtrer('image_reduire', $file_tmp, $max_width, $max_height);
126
+                    $img = extraire_attribut($img, 'src');
127
+                    $img = supprimer_timestamp($img);
128
+                    if (@file_exists($img) and $img !== $file_tmp) {
129
+                        spip_unlink($file_tmp);
130
+                        @rename($img, $file_tmp);
131
+                        $size = @getimagesize($file_tmp);
132
+                    }
133
+                }
134
+                // verifier au cas ou image_reduire a echoue
135
+                if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH)
136
+                    or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT)
137
+                ) {
138
+                    spip_unlink($file_tmp);
139
+                    $erreur = _T(
140
+                        'info_logo_max_poids',
141
+                        array(
142
+                            'maxi' =>
143
+                                _T(
144
+                                    'info_largeur_vignette',
145
+                                    array(
146
+                                        'largeur_vignette' => $max_width,
147
+                                        'hauteur_vignette' => $max_height
148
+                                    )
149
+                                ),
150
+                            'actuel' =>
151
+                                _T(
152
+                                    'info_largeur_vignette',
153
+                                    array(
154
+                                        'largeur_vignette' => $size[0],
155
+                                        'hauteur_vignette' => $size[1]
156
+                                    )
157
+                                )
158
+                        )
159
+                    );
160
+                }
161
+            }
162
+        }
163
+
164
+        if (!$erreur and defined('_LOGO_MAX_SIZE') and _LOGO_MAX_SIZE and $poids > _LOGO_MAX_SIZE * 1024) {
165
+            spip_unlink($file_tmp);
166
+            $erreur = _T(
167
+                'info_logo_max_poids',
168
+                array(
169
+                    'maxi' => taille_en_octets(_LOGO_MAX_SIZE * 1024),
170
+                    'actuel' => taille_en_octets($poids)
171
+                )
172
+            );
173
+        }
174
+
175
+        if (!$erreur) {
176
+            @rename($file_tmp, _DIR_LOGOS . $nom . ".$extension");
177
+        }
178
+    } else {
179
+        spip_unlink($file_tmp);
180
+        $erreur = _T(
181
+            'info_logo_format_interdit',
182
+            array('formats' => join(', ', $GLOBALS['formats_logos']))
183
+        );
184
+    }
185
+
186
+    return $erreur;
187 187
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	$type = type_du_logo($primary);
64 64
 
65 65
 	// nom du logo
66
-	$nom = $type . $etat . $id_objet;
66
+	$nom = $type.$etat.$id_objet;
67 67
 
68 68
 	// supprimer le logo eventueel existant
69 69
 	logo_supprimer($objet, $id_objet, $etat);
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
 		return $erreur;
79 79
 	}
80 80
 
81
-	$file_tmp = _DIR_LOGOS . $nom . '.tmp';
81
+	$file_tmp = _DIR_LOGOS.$nom.'.tmp';
82 82
 
83 83
 	$ok = false;
84 84
 	// fichier dans upload/
85 85
 	if (is_string($source)) {
86 86
 		if (file_exists($source)) {
87 87
 			$ok = @copy($source, $file_tmp);
88
-		} elseif (file_exists($f = determine_upload() . $source)) {
88
+		} elseif (file_exists($f = determine_upload().$source)) {
89 89
 			$ok = @copy($f, $file_tmp);
90 90
 		}
91 91
 	} elseif (!$erreur = check_upload_error($source['error'], '', true)) {
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	$size = @getimagesize($file_tmp);
108 108
 	$extension = !$size ? '' : ($size[2] > 3 ? '' : $GLOBALS['formats_logos'][$size[2] - 1]);
109 109
 	if ($extension) {
110
-		@rename($file_tmp, $file_tmp . ".$extension");
111
-		$file_tmp = $file_tmp . ".$extension";
110
+		@rename($file_tmp, $file_tmp.".$extension");
111
+		$file_tmp = $file_tmp.".$extension";
112 112
 		$poids = filesize($file_tmp);
113 113
 
114 114
 		if (defined('_LOGO_MAX_WIDTH') or defined('_LOGO_MAX_HEIGHT')) {
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		}
174 174
 
175 175
 		if (!$erreur) {
176
-			@rename($file_tmp, _DIR_LOGOS . $nom . ".$extension");
176
+			@rename($file_tmp, _DIR_LOGOS.$nom.".$extension");
177 177
 		}
178 178
 	} else {
179 179
 		spip_unlink($file_tmp);
Please login to merge, or discard this patch.
ecrire/action/annuler_job.php 1 patch
Indentation   +8 added lines, -8 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
 /**
@@ -26,12 +26,12 @@  discard block
 block discarded – undo
26 26
  * @return void
27 27
  */
28 28
 function action_annuler_job_dist() {
29
-	$securiser_action = charger_fonction('securiser_action', 'inc');
30
-	$id_job = $securiser_action();
29
+    $securiser_action = charger_fonction('securiser_action', 'inc');
30
+    $id_job = $securiser_action();
31 31
 
32
-	if ($id_job = intval($id_job)
33
-		and autoriser('annuler', 'job', $id_job)
34
-	) {
35
-		job_queue_remove($id_job);
36
-	}
32
+    if ($id_job = intval($id_job)
33
+        and autoriser('annuler', 'job', $id_job)
34
+    ) {
35
+        job_queue_remove($id_job);
36
+    }
37 37
 }
Please login to merge, or discard this patch.
ecrire/action/activer_plugins.php 2 patches
Indentation   +44 added lines, -44 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
 /**
@@ -28,47 +28,47 @@  discard block
 block discarded – undo
28 28
  * @return void
29 29
  */
30 30
 function enregistre_modif_plugin() {
31
-	include_spip('inc/plugin');
32
-	// recuperer les plugins dans l'ordre des $_POST
33
-	$test = array();
34
-	foreach (liste_plugin_files() as $file) {
35
-		$test['s' . substr(md5(_DIR_PLUGINS . $file), 0, 16)] = $file;
36
-	}
37
-	if (defined('_DIR_PLUGINS_SUPPL')) {
38
-		foreach (liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file) {
39
-			$test['s' . substr(md5(_DIR_PLUGINS_SUPPL . $file), 0, 16)] = $file;
40
-		}
41
-	}
31
+    include_spip('inc/plugin');
32
+    // recuperer les plugins dans l'ordre des $_POST
33
+    $test = array();
34
+    foreach (liste_plugin_files() as $file) {
35
+        $test['s' . substr(md5(_DIR_PLUGINS . $file), 0, 16)] = $file;
36
+    }
37
+    if (defined('_DIR_PLUGINS_SUPPL')) {
38
+        foreach (liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file) {
39
+            $test['s' . substr(md5(_DIR_PLUGINS_SUPPL . $file), 0, 16)] = $file;
40
+        }
41
+    }
42 42
 
43
-	$plugin = array();
43
+    $plugin = array();
44 44
 
45
-	foreach ($_POST as $choix => $val) {
46
-		if (isset($test[$choix]) && $val == 'O') {
47
-			$plugin[] = $test[$choix];
48
-		}
49
-	}
45
+    foreach ($_POST as $choix => $val) {
46
+        if (isset($test[$choix]) && $val == 'O') {
47
+            $plugin[] = $test[$choix];
48
+        }
49
+    }
50 50
 
51
-	spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ": " . join(',',
52
-			$plugin));
53
-	ecrire_plugin_actifs($plugin);
51
+    spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ": " . join(',',
52
+            $plugin));
53
+    ecrire_plugin_actifs($plugin);
54 54
 
55
-	// Chaque fois que l'on valide des plugins, on memorise la liste de ces plugins comme etant "interessants", avec un score initial, qui sera decremente a chaque tour : ainsi un plugin active pourra reter visible a l'ecran, jusqu'a ce qu'il tombe dans l'oubli.
56
-	$plugins_interessants = @unserialize($GLOBALS['meta']['plugins_interessants']);
57
-	if (!is_array($plugins_interessants)) {
58
-		$plugins_interessants = array();
59
-	}
55
+    // Chaque fois que l'on valide des plugins, on memorise la liste de ces plugins comme etant "interessants", avec un score initial, qui sera decremente a chaque tour : ainsi un plugin active pourra reter visible a l'ecran, jusqu'a ce qu'il tombe dans l'oubli.
56
+    $plugins_interessants = @unserialize($GLOBALS['meta']['plugins_interessants']);
57
+    if (!is_array($plugins_interessants)) {
58
+        $plugins_interessants = array();
59
+    }
60 60
 
61
-	$plugins_interessants2 = array();
61
+    $plugins_interessants2 = array();
62 62
 
63
-	foreach ($plugins_interessants as $plug => $score) {
64
-		if ($score > 1) {
65
-			$plugins_interessants2[$plug] = $score - 1;
66
-		}
67
-	}
68
-	foreach ($plugin as $plug) {
69
-		$plugins_interessants2[$plug] = 10;
70
-	} // score initial
71
-	ecrire_meta('plugins_interessants', serialize($plugins_interessants2));
63
+    foreach ($plugins_interessants as $plug => $score) {
64
+        if ($score > 1) {
65
+            $plugins_interessants2[$plug] = $score - 1;
66
+        }
67
+    }
68
+    foreach ($plugin as $plug) {
69
+        $plugins_interessants2[$plug] = 10;
70
+    } // score initial
71
+    ecrire_meta('plugins_interessants', serialize($plugins_interessants2));
72 72
 }
73 73
 
74 74
 /**
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function action_activer_plugins_dist() {
82 82
 
83
-	$securiser_action = charger_fonction('securiser_action', 'inc');
84
-	$securiser_action();
83
+    $securiser_action = charger_fonction('securiser_action', 'inc');
84
+    $securiser_action();
85 85
 
86
-	if (!autoriser('configurer', '_plugins')) {
87
-		die('erreur');
88
-	}
89
-	// forcer la maj des meta pour les cas de modif de numero de version base via phpmyadmin
90
-	lire_metas();
91
-	enregistre_modif_plugin();
86
+    if (!autoriser('configurer', '_plugins')) {
87
+        die('erreur');
88
+    }
89
+    // forcer la maj des meta pour les cas de modif de numero de version base via phpmyadmin
90
+    lire_metas();
91
+    enregistre_modif_plugin();
92 92
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
 	// recuperer les plugins dans l'ordre des $_POST
33 33
 	$test = array();
34 34
 	foreach (liste_plugin_files() as $file) {
35
-		$test['s' . substr(md5(_DIR_PLUGINS . $file), 0, 16)] = $file;
35
+		$test['s'.substr(md5(_DIR_PLUGINS.$file), 0, 16)] = $file;
36 36
 	}
37 37
 	if (defined('_DIR_PLUGINS_SUPPL')) {
38 38
 		foreach (liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file) {
39
-			$test['s' . substr(md5(_DIR_PLUGINS_SUPPL . $file), 0, 16)] = $file;
39
+			$test['s'.substr(md5(_DIR_PLUGINS_SUPPL.$file), 0, 16)] = $file;
40 40
 		}
41 41
 	}
42 42
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		}
49 49
 	}
50 50
 
51
-	spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ": " . join(',',
51
+	spip_log("Changement des plugins actifs par l'auteur ".$GLOBALS['visiteur_session']['id_auteur'].": ".join(',',
52 52
 			$plugin));
53 53
 	ecrire_plugin_actifs($plugin);
54 54
 
Please login to merge, or discard this patch.
ecrire/action/ajouter_lien.php 1 patch
Indentation   +9 added lines, -9 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
 /**
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
  * @return void
35 35
  */
36 36
 function action_ajouter_lien_dist($arg = null) {
37
-	if (is_null($arg)) {
38
-		$securiser_action = charger_fonction('securiser_action', 'inc');
39
-		$arg = $securiser_action();
40
-	}
37
+    if (is_null($arg)) {
38
+        $securiser_action = charger_fonction('securiser_action', 'inc');
39
+        $arg = $securiser_action();
40
+    }
41 41
 
42
-	$arg = explode("-", $arg);
43
-	list($objet_source, $ids, $objet_lie, $idl) = $arg;
42
+    $arg = explode("-", $arg);
43
+    list($objet_source, $ids, $objet_lie, $idl) = $arg;
44 44
 
45
-	include_spip('action/editer_liens');
46
-	objet_associer(array($objet_source => $ids), array($objet_lie => $idl));
45
+    include_spip('action/editer_liens');
46
+    objet_associer(array($objet_source => $ids), array($objet_lie => $idl));
47 47
 }
Please login to merge, or discard this patch.
ecrire/action/editer_objet.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
  * @return mixed|string
76 76
  */
77 77
 function objet_modifier($objet, $id, $set = null) {
78
-	if (include_spip('action/editer_' . $objet)
79
-		and function_exists($modifier = $objet . "_modifier")
78
+	if (include_spip('action/editer_'.$objet)
79
+		and function_exists($modifier = $objet."_modifier")
80 80
 	) {
81 81
 		return $modifier($id, $set);
82 82
 	}
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
  * @return bool|int
160 160
  */
161 161
 function objet_inserer($objet, $id_parent = null, $set = null) {
162
-	if (include_spip('action/editer_' . $objet)
163
-		and function_exists($inserer = $objet . "_inserer")
162
+	if (include_spip('action/editer_'.$objet)
163
+		and function_exists($inserer = $objet."_inserer")
164 164
 	) {
165 165
 		return $inserer($id_parent, $set);
166 166
 	}
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 			$row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1");
182 182
 			$id_rubrique = $row['id_rubrique'];
183 183
 		} else {
184
-			$row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
184
+			$row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=".intval($id_rubrique));
185 185
 		}
186 186
 
187 187
 		$champs['id_rubrique'] = $id_rubrique;
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
  * @return string
288 288
  */
289 289
 function objet_instituer($objet, $id, $c, $calcul_rub = true) {
290
-	if (include_spip('action/editer_' . $objet)
291
-		and function_exists($instituer = $objet . "_instituer")
290
+	if (include_spip('action/editer_'.$objet)
291
+		and function_exists($instituer = $objet."_instituer")
292 292
 	) {
293 293
 		return $instituer($id, $c, $calcul_rub);
294 294
 	}
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 	$sel[] = ($champ_date ? "$champ_date as date" : "'' as date");
318 318
 	$sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : "0 as id_rubrique");
319 319
 
320
-	$row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id));
320
+	$row = sql_fetsel($sel, $table_sql, id_table_objet($objet).'='.intval($id));
321 321
 
322 322
 	$id_rubrique = $row['id_rubrique'];
323 323
 	$statut_ancien = $statut = $row['statut'];
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 			if ($s != 'publie' and autoriser('modifier', $objet, $id)) {
340 340
 				$statut = $champs['statut'] = $s;
341 341
 			} else {
342
-				spip_log("editer_objet $id refus " . join(' ', $c));
342
+				spip_log("editer_objet $id refus ".join(' ', $c));
343 343
 			}
344 344
 		}
345 345
 
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		and isset($c['id_parent'])
368 368
 		and $id_parent = $c['id_parent']
369 369
 		and $id_parent != $id_rubrique
370
-		and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent)))
370
+		and (sql_fetsel('1', "spip_rubriques", "id_rubrique=".intval($id_parent)))
371 371
 	) {
372 372
 		$champs['id_rubrique'] = $id_parent;
373 373
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 	// changer aussi son secteur et sa langue (si heritee)
463 463
 	if (isset($champs['id_rubrique'])) {
464 464
 
465
-		$row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique']));
465
+		$row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=".sql_quote($champs['id_rubrique']));
466 466
 		$langue = $row_rub['lang'];
467 467
 
468 468
 		if (isset($desc['field']['id_secteur'])) {
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 
472 472
 		if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
473 473
 			if (sql_fetsel('1', $table_sql,
474
-				id_table_objet($objet) . "=" . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) {
474
+				id_table_objet($objet)."=".intval($id)." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue))) {
475 475
 				$champs['lang'] = $langue;
476 476
 			}
477 477
 		}
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	if (!$champs) {
481 481
 		return;
482 482
 	}
483
-	sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id));
483
+	sql_updateq($table_sql, $champs, id_table_objet($objet).'='.intval($id));
484 484
 
485 485
 	// Changer le statut des rubriques concernees
486 486
 	if ($cond) {
Please login to merge, or discard this patch.
Indentation   +395 added lines, -395 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
 /**
@@ -33,36 +33,36 @@  discard block
 block discarded – undo
33 33
  */
34 34
 function action_editer_objet_dist($id = null, $objet = null, $set = null) {
35 35
 
36
-	// appel direct depuis une url avec arg = "objet/id"
37
-	if (is_null($id) or is_null($objet)) {
38
-		$securiser_action = charger_fonction('securiser_action', 'inc');
39
-		$arg = $securiser_action();
40
-		list($objet, $id) = array_pad(explode("/", $arg, 2), 2, null);
41
-	}
42
-
43
-	// appel incorrect ou depuis une url erronnée interdit
44
-	if (is_null($id) or is_null($objet)) {
45
-		include_spip('inc/minipres');
46
-		echo minipres(_T('info_acces_interdit'));
47
-		die();
48
-	}
49
-
50
-	// si id n'est pas un nombre, c'est une creation
51
-	// mais on verifie qu'on a toutes les donnees qu'il faut.
52
-	if (!$id = intval($id)) {
53
-		// on ne sait pas si un parent existe mais on essaye
54
-		$id_parent = _request('id_parent');
55
-		$id = objet_inserer($objet, $id_parent);
56
-	}
57
-
58
-	if (!($id = intval($id)) > 0) {
59
-		return array($id, _L('echec enregistrement en base'));
60
-	}
61
-
62
-	// Enregistre l'envoi dans la BD
63
-	$err = objet_modifier($objet, $id, $set);
64
-
65
-	return array($id, $err);
36
+    // appel direct depuis une url avec arg = "objet/id"
37
+    if (is_null($id) or is_null($objet)) {
38
+        $securiser_action = charger_fonction('securiser_action', 'inc');
39
+        $arg = $securiser_action();
40
+        list($objet, $id) = array_pad(explode("/", $arg, 2), 2, null);
41
+    }
42
+
43
+    // appel incorrect ou depuis une url erronnée interdit
44
+    if (is_null($id) or is_null($objet)) {
45
+        include_spip('inc/minipres');
46
+        echo minipres(_T('info_acces_interdit'));
47
+        die();
48
+    }
49
+
50
+    // si id n'est pas un nombre, c'est une creation
51
+    // mais on verifie qu'on a toutes les donnees qu'il faut.
52
+    if (!$id = intval($id)) {
53
+        // on ne sait pas si un parent existe mais on essaye
54
+        $id_parent = _request('id_parent');
55
+        $id = objet_inserer($objet, $id_parent);
56
+    }
57
+
58
+    if (!($id = intval($id)) > 0) {
59
+        return array($id, _L('echec enregistrement en base'));
60
+    }
61
+
62
+    // Enregistre l'envoi dans la BD
63
+    $err = objet_modifier($objet, $id, $set);
64
+
65
+    return array($id, $err);
66 66
 }
67 67
 
68 68
 /**
@@ -75,76 +75,76 @@  discard block
 block discarded – undo
75 75
  * @return mixed|string
76 76
  */
77 77
 function objet_modifier($objet, $id, $set = null) {
78
-	if (include_spip('action/editer_' . $objet)
79
-		and function_exists($modifier = $objet . "_modifier")
80
-	) {
81
-		return $modifier($id, $set);
82
-	}
83
-
84
-	$table_sql = table_objet_sql($objet);
85
-	$trouver_table = charger_fonction('trouver_table', 'base');
86
-	$desc = $trouver_table($table_sql);
87
-	if (!$desc or !isset($desc['field'])) {
88
-		spip_log("Objet $objet inconnu dans objet_modifier", _LOG_ERREUR);
89
-
90
-		return _L("Erreur objet $objet inconnu");
91
-	}
92
-	include_spip('inc/modifier');
93
-
94
-	$champ_date = '';
95
-	if (isset($desc['date']) and $desc['date']) {
96
-		$champ_date = $desc['date'];
97
-	} elseif (isset($desc['field']['date'])) {
98
-		$champ_date = 'date';
99
-	}
100
-
101
-	$white = array_keys($desc['field']);
102
-	// on ne traite pas la cle primaire par defaut, notamment car
103
-	// sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base
104
-	$white = array_diff($white, array($desc['key']['PRIMARY KEY']));
105
-
106
-	if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) {
107
-		$white = $desc['champs_editables'];
108
-	}
109
-	$c = collecter_requests(
110
-	// white list
111
-		$white,
112
-		// black list
113
-		array($champ_date, 'statut', 'id_parent', 'id_secteur'),
114
-		// donnees eventuellement fournies
115
-		$set
116
-	);
117
-
118
-	// Si l'objet est publie, invalider les caches et demander sa reindexation
119
-	if (objet_test_si_publie($objet, $id)) {
120
-		$invalideur = "id='$objet/$id'";
121
-		$indexation = true;
122
-	} else {
123
-		$invalideur = "";
124
-		$indexation = false;
125
-	}
126
-
127
-	if ($err = objet_modifier_champs($objet, $id,
128
-		array(
129
-			'data' => $set,
130
-			'nonvide' => '',
131
-			'invalideur' => $invalideur,
132
-			'indexation' => $indexation,
133
-			// champ a mettre a date('Y-m-d H:i:s') s'il y a modif
134
-			'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '')
135
-		),
136
-		$c)
137
-	) {
138
-		return $err;
139
-	}
140
-
141
-	// Modification de statut, changement de rubrique ?
142
-	// FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout
143
-	//         le tableau $set hors black liste, mais du coup on a possiblement des champs en trop. 
144
-	$c = collecter_requests(array($champ_date, 'statut', 'id_parent'), array(), $set);
145
-	$err = objet_instituer($objet, $id, $c);
146
-
147
-	return $err;
78
+    if (include_spip('action/editer_' . $objet)
79
+        and function_exists($modifier = $objet . "_modifier")
80
+    ) {
81
+        return $modifier($id, $set);
82
+    }
83
+
84
+    $table_sql = table_objet_sql($objet);
85
+    $trouver_table = charger_fonction('trouver_table', 'base');
86
+    $desc = $trouver_table($table_sql);
87
+    if (!$desc or !isset($desc['field'])) {
88
+        spip_log("Objet $objet inconnu dans objet_modifier", _LOG_ERREUR);
89
+
90
+        return _L("Erreur objet $objet inconnu");
91
+    }
92
+    include_spip('inc/modifier');
93
+
94
+    $champ_date = '';
95
+    if (isset($desc['date']) and $desc['date']) {
96
+        $champ_date = $desc['date'];
97
+    } elseif (isset($desc['field']['date'])) {
98
+        $champ_date = 'date';
99
+    }
100
+
101
+    $white = array_keys($desc['field']);
102
+    // on ne traite pas la cle primaire par defaut, notamment car
103
+    // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base
104
+    $white = array_diff($white, array($desc['key']['PRIMARY KEY']));
105
+
106
+    if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) {
107
+        $white = $desc['champs_editables'];
108
+    }
109
+    $c = collecter_requests(
110
+    // white list
111
+        $white,
112
+        // black list
113
+        array($champ_date, 'statut', 'id_parent', 'id_secteur'),
114
+        // donnees eventuellement fournies
115
+        $set
116
+    );
117
+
118
+    // Si l'objet est publie, invalider les caches et demander sa reindexation
119
+    if (objet_test_si_publie($objet, $id)) {
120
+        $invalideur = "id='$objet/$id'";
121
+        $indexation = true;
122
+    } else {
123
+        $invalideur = "";
124
+        $indexation = false;
125
+    }
126
+
127
+    if ($err = objet_modifier_champs($objet, $id,
128
+        array(
129
+            'data' => $set,
130
+            'nonvide' => '',
131
+            'invalideur' => $invalideur,
132
+            'indexation' => $indexation,
133
+            // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
134
+            'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '')
135
+        ),
136
+        $c)
137
+    ) {
138
+        return $err;
139
+    }
140
+
141
+    // Modification de statut, changement de rubrique ?
142
+    // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout
143
+    //         le tableau $set hors black liste, mais du coup on a possiblement des champs en trop. 
144
+    $c = collecter_requests(array($champ_date, 'statut', 'id_parent'), array(), $set);
145
+    $err = objet_instituer($objet, $id, $c);
146
+
147
+    return $err;
148 148
 }
149 149
 
150 150
 /**
@@ -159,120 +159,120 @@  discard block
 block discarded – undo
159 159
  * @return bool|int
160 160
  */
161 161
 function objet_inserer($objet, $id_parent = null, $set = null) {
162
-	if (include_spip('action/editer_' . $objet)
163
-		and function_exists($inserer = $objet . "_inserer")
164
-	) {
165
-		return $inserer($id_parent, $set);
166
-	}
167
-
168
-	$table_sql = table_objet_sql($objet);
169
-	$trouver_table = charger_fonction('trouver_table', 'base');
170
-	$desc = $trouver_table($table_sql);
171
-	if (!$desc or !isset($desc['field'])) {
172
-		return 0;
173
-	}
174
-
175
-	$lang_rub = "";
176
-	$champs = array();
177
-	if (isset($desc['field']['id_rubrique'])) {
178
-		// Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet
179
-		// dans la premiere rubrique racine
180
-		if (!$id_rubrique = intval($id_parent)) {
181
-			$row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1");
182
-			$id_rubrique = $row['id_rubrique'];
183
-		} else {
184
-			$row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
185
-		}
186
-
187
-		$champs['id_rubrique'] = $id_rubrique;
188
-		if (isset($desc['field']['id_secteur'])) {
189
-			$champs['id_secteur'] = $row['id_secteur'];
190
-		}
191
-		$lang_rub = $row['lang'];
192
-	}
193
-
194
-	// La langue a la creation : si les liens de traduction sont autorises
195
-	// dans les rubriques, on essaie avec la langue de l'auteur,
196
-	// ou a defaut celle de la rubrique
197
-	// Sinon c'est la langue de la rubrique qui est choisie + heritee
198
-	if (isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array($table_sql,
199
-			explode(',', $GLOBALS['meta']['multi_objets']))
200
-	) {
201
-		lang_select($GLOBALS['visiteur_session']['lang']);
202
-		if (in_array($GLOBALS['spip_lang'],
203
-			explode(',', $GLOBALS['meta']['langues_multilingue']))) {
204
-			$champs['lang'] = $GLOBALS['spip_lang'];
205
-			if (isset($desc['field']['langue_choisie'])) {
206
-				$champs['langue_choisie'] = 'oui';
207
-			}
208
-		}
209
-	} elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
210
-		$champs['lang'] = ($lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']);
211
-		$champs['langue_choisie'] = 'non';
212
-	}
213
-
214
-	if (isset($desc['field']['statut'])) {
215
-		if (isset($desc['statut_textes_instituer'])) {
216
-			$cles_statut = array_keys($desc['statut_textes_instituer']);
217
-			$champs['statut'] = reset($cles_statut);
218
-		} else {
219
-			$champs['statut'] = 'prepa';
220
-		}
221
-	}
222
-
223
-
224
-	if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) {
225
-		$champs[$d] = date('Y-m-d H:i:s');
226
-	}
227
-
228
-	if ($set) {
229
-		$champs = array_merge($champs, $set);
230
-	}
231
-
232
-	// Envoyer aux plugins
233
-	$champs = pipeline('pre_insertion',
234
-		array(
235
-			'args' => array(
236
-				'table' => $table_sql,
237
-				'id_parent' => $id_parent,
238
-			),
239
-			'data' => $champs
240
-		)
241
-	);
242
-
243
-	$id = sql_insertq($table_sql, $champs);
244
-
245
-	if ($id) {
246
-		// controler si le serveur n'a pas renvoye une erreur
247
-		// et associer l'auteur sinon
248
-		// si la table n'a pas deja un champ id_auteur
249
-		// et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association)
250
-		if ($id > 0
251
-			and !isset($desc['field']['id_auteur'])
252
-		) {
253
-			$id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
254
-				$GLOBALS['visiteur_session']['id_auteur']
255
-				: _request('id_auteur'));
256
-			if ($id_auteur) {
257
-				include_spip('action/editer_auteur');
258
-				auteur_associer($id_auteur, array($objet => $id));
259
-			}
260
-		}
261
-
262
-		pipeline('post_insertion',
263
-			array(
264
-				'args' => array(
265
-					'table' => $table_sql,
266
-					'id_parent' => $id_parent,
267
-					'id_objet' => $id,
268
-				),
269
-				'data' => $champs
270
-			)
271
-		);
272
-
273
-	}
274
-
275
-	return $id;
162
+    if (include_spip('action/editer_' . $objet)
163
+        and function_exists($inserer = $objet . "_inserer")
164
+    ) {
165
+        return $inserer($id_parent, $set);
166
+    }
167
+
168
+    $table_sql = table_objet_sql($objet);
169
+    $trouver_table = charger_fonction('trouver_table', 'base');
170
+    $desc = $trouver_table($table_sql);
171
+    if (!$desc or !isset($desc['field'])) {
172
+        return 0;
173
+    }
174
+
175
+    $lang_rub = "";
176
+    $champs = array();
177
+    if (isset($desc['field']['id_rubrique'])) {
178
+        // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet
179
+        // dans la premiere rubrique racine
180
+        if (!$id_rubrique = intval($id_parent)) {
181
+            $row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1");
182
+            $id_rubrique = $row['id_rubrique'];
183
+        } else {
184
+            $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
185
+        }
186
+
187
+        $champs['id_rubrique'] = $id_rubrique;
188
+        if (isset($desc['field']['id_secteur'])) {
189
+            $champs['id_secteur'] = $row['id_secteur'];
190
+        }
191
+        $lang_rub = $row['lang'];
192
+    }
193
+
194
+    // La langue a la creation : si les liens de traduction sont autorises
195
+    // dans les rubriques, on essaie avec la langue de l'auteur,
196
+    // ou a defaut celle de la rubrique
197
+    // Sinon c'est la langue de la rubrique qui est choisie + heritee
198
+    if (isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array($table_sql,
199
+            explode(',', $GLOBALS['meta']['multi_objets']))
200
+    ) {
201
+        lang_select($GLOBALS['visiteur_session']['lang']);
202
+        if (in_array($GLOBALS['spip_lang'],
203
+            explode(',', $GLOBALS['meta']['langues_multilingue']))) {
204
+            $champs['lang'] = $GLOBALS['spip_lang'];
205
+            if (isset($desc['field']['langue_choisie'])) {
206
+                $champs['langue_choisie'] = 'oui';
207
+            }
208
+        }
209
+    } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
210
+        $champs['lang'] = ($lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']);
211
+        $champs['langue_choisie'] = 'non';
212
+    }
213
+
214
+    if (isset($desc['field']['statut'])) {
215
+        if (isset($desc['statut_textes_instituer'])) {
216
+            $cles_statut = array_keys($desc['statut_textes_instituer']);
217
+            $champs['statut'] = reset($cles_statut);
218
+        } else {
219
+            $champs['statut'] = 'prepa';
220
+        }
221
+    }
222
+
223
+
224
+    if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) {
225
+        $champs[$d] = date('Y-m-d H:i:s');
226
+    }
227
+
228
+    if ($set) {
229
+        $champs = array_merge($champs, $set);
230
+    }
231
+
232
+    // Envoyer aux plugins
233
+    $champs = pipeline('pre_insertion',
234
+        array(
235
+            'args' => array(
236
+                'table' => $table_sql,
237
+                'id_parent' => $id_parent,
238
+            ),
239
+            'data' => $champs
240
+        )
241
+    );
242
+
243
+    $id = sql_insertq($table_sql, $champs);
244
+
245
+    if ($id) {
246
+        // controler si le serveur n'a pas renvoye une erreur
247
+        // et associer l'auteur sinon
248
+        // si la table n'a pas deja un champ id_auteur
249
+        // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association)
250
+        if ($id > 0
251
+            and !isset($desc['field']['id_auteur'])
252
+        ) {
253
+            $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
254
+                $GLOBALS['visiteur_session']['id_auteur']
255
+                : _request('id_auteur'));
256
+            if ($id_auteur) {
257
+                include_spip('action/editer_auteur');
258
+                auteur_associer($id_auteur, array($objet => $id));
259
+            }
260
+        }
261
+
262
+        pipeline('post_insertion',
263
+            array(
264
+                'args' => array(
265
+                    'table' => $table_sql,
266
+                    'id_parent' => $id_parent,
267
+                    'id_objet' => $id,
268
+                ),
269
+                'data' => $champs
270
+            )
271
+        );
272
+
273
+    }
274
+
275
+    return $id;
276 276
 }
277 277
 
278 278
 
@@ -289,128 +289,128 @@  discard block
 block discarded – undo
289 289
  * @return string
290 290
  */
291 291
 function objet_instituer($objet, $id, $c, $calcul_rub = true) {
292
-	if (include_spip('action/editer_' . $objet)
293
-		and function_exists($instituer = $objet . "_instituer")
294
-	) {
295
-		return $instituer($id, $c, $calcul_rub);
296
-	}
297
-
298
-	$table_sql = table_objet_sql($objet);
299
-	$trouver_table = charger_fonction('trouver_table', 'base');
300
-	$desc = $trouver_table($table_sql);
301
-	if (!$desc or !isset($desc['field'])) {
302
-		return _L("Impossible d'instituer $objet : non connu en base");
303
-	}
304
-
305
-	include_spip('inc/autoriser');
306
-	include_spip('inc/rubriques');
307
-	include_spip('inc/modifier');
308
-
309
-	$sel = array();
310
-	$sel[] = (isset($desc['field']['statut']) ? "statut" : "'' as statut");
311
-
312
-	$champ_date = '';
313
-	if (isset($desc['date']) and $desc['date']) {
314
-		$champ_date = $desc['date'];
315
-	} elseif (isset($desc['field']['date'])) {
316
-		$champ_date = 'date';
317
-	}
318
-
319
-	$sel[] = ($champ_date ? "$champ_date as date" : "'' as date");
320
-	$sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : "0 as id_rubrique");
321
-
322
-	$row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id));
323
-
324
-	$id_rubrique = $row['id_rubrique'];
325
-	$statut_ancien = $statut = $row['statut'];
326
-	$date_ancienne = $date = $row['date'];
327
-	$champs = array();
328
-
329
-	$d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null;
330
-	$s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut;
331
-
332
-	// cf autorisations dans inc/instituer_objet
333
-	if ($s != $statut or ($d and $d != $date)) {
334
-		if ($id_rubrique ?
335
-			autoriser('publierdans', 'rubrique', $id_rubrique)
336
-			:
337
-			autoriser('instituer', $objet, $id, null, array('statut' => $s))
338
-		) {
339
-			$statut = $champs['statut'] = $s;
340
-		} else {
341
-			if ($s != 'publie' and autoriser('modifier', $objet, $id)) {
342
-				$statut = $champs['statut'] = $s;
343
-			} else {
344
-				spip_log("editer_objet $id refus " . join(' ', $c));
345
-			}
346
-		}
347
-
348
-		// En cas de publication, fixer la date a "maintenant"
349
-		// sauf si $c commande autre chose
350
-		// ou si l'objet est deja date dans le futur
351
-		// En cas de proposition d'un objet (mais pas depublication), idem
352
-		if ($champ_date) {
353
-			if ($champs['statut'] == 'publie'
354
-				or ($champs['statut'] == 'prop' and !in_array($statut_ancien, array('publie', 'prop')))
355
-				or $d
356
-			) {
357
-				if ($d or strtotime($d = $date) > time()) {
358
-					$champs[$champ_date] = $date = $d;
359
-				} else {
360
-					$champs[$champ_date] = $date = date('Y-m-d H:i:s');
361
-				}
362
-			}
363
-		}
364
-	}
365
-
366
-	// Verifier que la rubrique demandee existe et est differente
367
-	// de la rubrique actuelle
368
-	if ($id_rubrique
369
-		and isset($c['id_parent'])
370
-		and $id_parent = $c['id_parent']
371
-		and $id_parent != $id_rubrique
372
-		and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent)))
373
-	) {
374
-		$champs['id_rubrique'] = $id_parent;
375
-
376
-		// si l'objet etait publie
377
-		// et que le demandeur n'est pas admin de la rubrique
378
-		// repasser l'objet en statut 'propose'.
379
-		if ($statut == 'publie'
380
-			and !autoriser('publierdans', 'rubrique', $id_rubrique)
381
-		) {
382
-			$champs['statut'] = 'prop';
383
-		}
384
-	}
385
-
386
-
387
-	// Envoyer aux plugins
388
-	$champs = pipeline('pre_edition',
389
-		array(
390
-			'args' => array(
391
-				'table' => $table_sql,
392
-				'id_objet' => $id,
393
-				'action' => 'instituer',
394
-				'statut_ancien' => $statut_ancien,
395
-				'date_ancienne' => $date_ancienne,
396
-				'id_parent_ancien' => $id_rubrique,
397
-			),
398
-			'data' => $champs
399
-		)
400
-	);
401
-
402
-	if (!count($champs)) {
403
-		return '';
404
-	}
405
-
406
-	// Envoyer les modifs.
407
-	objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
408
-
409
-	// Invalider les caches
410
-	include_spip('inc/invalideur');
411
-	suivre_invalideur("id='$objet/$id'");
412
-
413
-	/*
292
+    if (include_spip('action/editer_' . $objet)
293
+        and function_exists($instituer = $objet . "_instituer")
294
+    ) {
295
+        return $instituer($id, $c, $calcul_rub);
296
+    }
297
+
298
+    $table_sql = table_objet_sql($objet);
299
+    $trouver_table = charger_fonction('trouver_table', 'base');
300
+    $desc = $trouver_table($table_sql);
301
+    if (!$desc or !isset($desc['field'])) {
302
+        return _L("Impossible d'instituer $objet : non connu en base");
303
+    }
304
+
305
+    include_spip('inc/autoriser');
306
+    include_spip('inc/rubriques');
307
+    include_spip('inc/modifier');
308
+
309
+    $sel = array();
310
+    $sel[] = (isset($desc['field']['statut']) ? "statut" : "'' as statut");
311
+
312
+    $champ_date = '';
313
+    if (isset($desc['date']) and $desc['date']) {
314
+        $champ_date = $desc['date'];
315
+    } elseif (isset($desc['field']['date'])) {
316
+        $champ_date = 'date';
317
+    }
318
+
319
+    $sel[] = ($champ_date ? "$champ_date as date" : "'' as date");
320
+    $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : "0 as id_rubrique");
321
+
322
+    $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id));
323
+
324
+    $id_rubrique = $row['id_rubrique'];
325
+    $statut_ancien = $statut = $row['statut'];
326
+    $date_ancienne = $date = $row['date'];
327
+    $champs = array();
328
+
329
+    $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null;
330
+    $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut;
331
+
332
+    // cf autorisations dans inc/instituer_objet
333
+    if ($s != $statut or ($d and $d != $date)) {
334
+        if ($id_rubrique ?
335
+            autoriser('publierdans', 'rubrique', $id_rubrique)
336
+            :
337
+            autoriser('instituer', $objet, $id, null, array('statut' => $s))
338
+        ) {
339
+            $statut = $champs['statut'] = $s;
340
+        } else {
341
+            if ($s != 'publie' and autoriser('modifier', $objet, $id)) {
342
+                $statut = $champs['statut'] = $s;
343
+            } else {
344
+                spip_log("editer_objet $id refus " . join(' ', $c));
345
+            }
346
+        }
347
+
348
+        // En cas de publication, fixer la date a "maintenant"
349
+        // sauf si $c commande autre chose
350
+        // ou si l'objet est deja date dans le futur
351
+        // En cas de proposition d'un objet (mais pas depublication), idem
352
+        if ($champ_date) {
353
+            if ($champs['statut'] == 'publie'
354
+                or ($champs['statut'] == 'prop' and !in_array($statut_ancien, array('publie', 'prop')))
355
+                or $d
356
+            ) {
357
+                if ($d or strtotime($d = $date) > time()) {
358
+                    $champs[$champ_date] = $date = $d;
359
+                } else {
360
+                    $champs[$champ_date] = $date = date('Y-m-d H:i:s');
361
+                }
362
+            }
363
+        }
364
+    }
365
+
366
+    // Verifier que la rubrique demandee existe et est differente
367
+    // de la rubrique actuelle
368
+    if ($id_rubrique
369
+        and isset($c['id_parent'])
370
+        and $id_parent = $c['id_parent']
371
+        and $id_parent != $id_rubrique
372
+        and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent)))
373
+    ) {
374
+        $champs['id_rubrique'] = $id_parent;
375
+
376
+        // si l'objet etait publie
377
+        // et que le demandeur n'est pas admin de la rubrique
378
+        // repasser l'objet en statut 'propose'.
379
+        if ($statut == 'publie'
380
+            and !autoriser('publierdans', 'rubrique', $id_rubrique)
381
+        ) {
382
+            $champs['statut'] = 'prop';
383
+        }
384
+    }
385
+
386
+
387
+    // Envoyer aux plugins
388
+    $champs = pipeline('pre_edition',
389
+        array(
390
+            'args' => array(
391
+                'table' => $table_sql,
392
+                'id_objet' => $id,
393
+                'action' => 'instituer',
394
+                'statut_ancien' => $statut_ancien,
395
+                'date_ancienne' => $date_ancienne,
396
+                'id_parent_ancien' => $id_rubrique,
397
+            ),
398
+            'data' => $champs
399
+        )
400
+    );
401
+
402
+    if (!count($champs)) {
403
+        return '';
404
+    }
405
+
406
+    // Envoyer les modifs.
407
+    objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
408
+
409
+    // Invalider les caches
410
+    include_spip('inc/invalideur');
411
+    suivre_invalideur("id='$objet/$id'");
412
+
413
+    /*
414 414
 	if ($date) {
415 415
 		$t = strtotime($date);
416 416
 		$p = @$GLOBALS['meta']['date_prochain_postdate'];
@@ -419,29 +419,29 @@  discard block
 block discarded – undo
419 419
 		}
420 420
 	}*/
421 421
 
422
-	// Pipeline
423
-	pipeline('post_edition',
424
-		array(
425
-			'args' => array(
426
-				'table' => $table_sql,
427
-				'id_objet' => $id,
428
-				'action' => 'instituer',
429
-				'statut_ancien' => $statut_ancien,
430
-				'date_ancienne' => $date_ancienne,
431
-				'id_parent_ancien' => $id_rubrique,
432
-			),
433
-			'data' => $champs
434
-		)
435
-	);
436
-
437
-	// Notifications
438
-	if ($notifications = charger_fonction('notifications', 'inc')) {
439
-		$notifications("instituer$objet", $id,
440
-			array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne)
441
-		);
442
-	}
443
-
444
-	return ''; // pas d'erreur
422
+    // Pipeline
423
+    pipeline('post_edition',
424
+        array(
425
+            'args' => array(
426
+                'table' => $table_sql,
427
+                'id_objet' => $id,
428
+                'action' => 'instituer',
429
+                'statut_ancien' => $statut_ancien,
430
+                'date_ancienne' => $date_ancienne,
431
+                'id_parent_ancien' => $id_rubrique,
432
+            ),
433
+            'data' => $champs
434
+        )
435
+    );
436
+
437
+    // Notifications
438
+    if ($notifications = charger_fonction('notifications', 'inc')) {
439
+        $notifications("instituer$objet", $id,
440
+            array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne)
441
+        );
442
+    }
443
+
444
+    return ''; // pas d'erreur
445 445
 }
446 446
 
447 447
 /**
@@ -456,39 +456,39 @@  discard block
 block discarded – undo
456 456
  * @return void
457 457
  */
458 458
 function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) {
459
-	$table_sql = table_objet_sql($objet);
460
-	$trouver_table = charger_fonction('trouver_table', 'base');
461
-	$desc = $trouver_table($table_sql);
462
-
463
-	// Si on deplace l'objet
464
-	// changer aussi son secteur et sa langue (si heritee)
465
-	if (isset($champs['id_rubrique'])) {
466
-
467
-		$row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique']));
468
-		$langue = $row_rub['lang'];
469
-
470
-		if (isset($desc['field']['id_secteur'])) {
471
-			$champs['id_secteur'] = $row_rub['id_secteur'];
472
-		}
473
-
474
-		if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
475
-			if (sql_fetsel('1', $table_sql,
476
-				id_table_objet($objet) . "=" . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) {
477
-				$champs['lang'] = $langue;
478
-			}
479
-		}
480
-	}
481
-
482
-	if (!$champs) {
483
-		return;
484
-	}
485
-	sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id));
486
-
487
-	// Changer le statut des rubriques concernees
488
-	if ($cond) {
489
-		include_spip('inc/rubriques');
490
-		//$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false;
491
-		$postdate = false;
492
-		calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate);
493
-	}
459
+    $table_sql = table_objet_sql($objet);
460
+    $trouver_table = charger_fonction('trouver_table', 'base');
461
+    $desc = $trouver_table($table_sql);
462
+
463
+    // Si on deplace l'objet
464
+    // changer aussi son secteur et sa langue (si heritee)
465
+    if (isset($champs['id_rubrique'])) {
466
+
467
+        $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique']));
468
+        $langue = $row_rub['lang'];
469
+
470
+        if (isset($desc['field']['id_secteur'])) {
471
+            $champs['id_secteur'] = $row_rub['id_secteur'];
472
+        }
473
+
474
+        if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
475
+            if (sql_fetsel('1', $table_sql,
476
+                id_table_objet($objet) . "=" . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) {
477
+                $champs['lang'] = $langue;
478
+            }
479
+        }
480
+    }
481
+
482
+    if (!$champs) {
483
+        return;
484
+    }
485
+    sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id));
486
+
487
+    // Changer le statut des rubriques concernees
488
+    if ($cond) {
489
+        include_spip('inc/rubriques');
490
+        //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false;
491
+        $postdate = false;
492
+        calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate);
493
+    }
494 494
 }
Please login to merge, or discard this patch.