@@ -87,6 +87,9 @@ |
||
| 87 | 87 | return $res; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | +/** |
|
| 91 | + * @param string $default |
|
| 92 | + */ |
|
| 90 | 93 | function relayeur_saisie_ou_config($http_proxy, $default){ |
| 91 | 94 | // http_proxy : ne pas prendre en compte la modif si le password est '****' |
| 92 | 95 | if (preg_match(',:\*\*\*\*@,', $http_proxy)) |
@@ -15,124 +15,124 @@ |
||
| 15 | 15 | include_spip('inc/config'); |
| 16 | 16 | |
| 17 | 17 | function formulaires_configurer_relayeur_charger_dist(){ |
| 18 | - $valeurs = array( |
|
| 19 | - 'http_proxy' =>no_password_proxy_url(lire_config('http_proxy', '')), |
|
| 20 | - 'http_noproxy' => lire_config('http_noproxy', ''), |
|
| 21 | - 'test_proxy' => 'http://www.spip.net/', |
|
| 22 | - ); |
|
| 18 | + $valeurs = array( |
|
| 19 | + 'http_proxy' =>no_password_proxy_url(lire_config('http_proxy', '')), |
|
| 20 | + 'http_noproxy' => lire_config('http_noproxy', ''), |
|
| 21 | + 'test_proxy' => 'http://www.spip.net/', |
|
| 22 | + ); |
|
| 23 | 23 | |
| 24 | - return $valeurs; |
|
| 24 | + return $valeurs; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | function formulaires_configurer_relayeur_verifier_dist(){ |
| 28 | - $erreurs = array(); |
|
| 29 | - $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', '')); |
|
| 30 | - $http_noproxy = _request('http_noproxy'); |
|
| 31 | - |
|
| 32 | - if ($http_proxy AND !tester_url_absolue($http_proxy)){ |
|
| 33 | - $erreurs['http_proxy'] = _L('format_proxy_incorrect'); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - if (!isset($erreurs['http_proxy']) AND _request('tester_proxy')) { |
|
| 37 | - if (!$http_proxy) |
|
| 38 | - $erreurs['http_proxy'] = _T('info_obligatoire'); |
|
| 39 | - else { |
|
| 40 | - include_spip('inc/distant'); |
|
| 41 | - $test_proxy = _request('test_proxy'); |
|
| 42 | - $t = parse_url($test_proxy); |
|
| 43 | - if (!@$t['host']) { |
|
| 44 | - $erreurs['test_proxy'] = _T('info_adresse_non_indiquee'); |
|
| 45 | - } |
|
| 46 | - else { |
|
| 47 | - include_spip('inc/texte'); // pour aide, couper, lang |
|
| 48 | - $info = ""; |
|
| 49 | - if (!need_proxy($t['host'],$http_proxy,$http_noproxy)) |
|
| 50 | - $info = "<strong>"._T('page_pas_proxy')."</strong><br />"; |
|
| 51 | - |
|
| 52 | - // il faut fausser le proxy actuel pour faire le test ! |
|
| 53 | - $cur_http_proxy = $GLOBALS['meta']['http_proxy']; |
|
| 54 | - $cur_http_noproxy = $GLOBALS['meta']['http_noproxy']; |
|
| 55 | - $GLOBALS['meta']['http_proxy'] = $http_proxy; |
|
| 56 | - $GLOBALS['meta']['http_noproxy'] = $http_noproxy; |
|
| 57 | - $page = recuperer_page($test_proxy, true); |
|
| 58 | - $GLOBALS['meta']['http_proxy'] = $cur_http_proxy; |
|
| 59 | - $GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy; |
|
| 60 | - if ($page) { |
|
| 61 | - $erreurs['message_ok'] = _T('info_proxy_ok')."<br />$info\n<tt>".couper(entites_html($page),300)."</tt>"; |
|
| 62 | - } |
|
| 63 | - else { |
|
| 64 | - $erreurs['message_erreur'] = $info._T('info_impossible_lire_page', array('test_proxy' => "<tt>$test_proxy</tt>")) |
|
| 65 | - . " <b><tt>".no_password_proxy_url($http_proxy)."</tt></b>." |
|
| 66 | - . aide('confhttpproxy'); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - return $erreurs; |
|
| 28 | + $erreurs = array(); |
|
| 29 | + $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', '')); |
|
| 30 | + $http_noproxy = _request('http_noproxy'); |
|
| 31 | + |
|
| 32 | + if ($http_proxy AND !tester_url_absolue($http_proxy)){ |
|
| 33 | + $erreurs['http_proxy'] = _L('format_proxy_incorrect'); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + if (!isset($erreurs['http_proxy']) AND _request('tester_proxy')) { |
|
| 37 | + if (!$http_proxy) |
|
| 38 | + $erreurs['http_proxy'] = _T('info_obligatoire'); |
|
| 39 | + else { |
|
| 40 | + include_spip('inc/distant'); |
|
| 41 | + $test_proxy = _request('test_proxy'); |
|
| 42 | + $t = parse_url($test_proxy); |
|
| 43 | + if (!@$t['host']) { |
|
| 44 | + $erreurs['test_proxy'] = _T('info_adresse_non_indiquee'); |
|
| 45 | + } |
|
| 46 | + else { |
|
| 47 | + include_spip('inc/texte'); // pour aide, couper, lang |
|
| 48 | + $info = ""; |
|
| 49 | + if (!need_proxy($t['host'],$http_proxy,$http_noproxy)) |
|
| 50 | + $info = "<strong>"._T('page_pas_proxy')."</strong><br />"; |
|
| 51 | + |
|
| 52 | + // il faut fausser le proxy actuel pour faire le test ! |
|
| 53 | + $cur_http_proxy = $GLOBALS['meta']['http_proxy']; |
|
| 54 | + $cur_http_noproxy = $GLOBALS['meta']['http_noproxy']; |
|
| 55 | + $GLOBALS['meta']['http_proxy'] = $http_proxy; |
|
| 56 | + $GLOBALS['meta']['http_noproxy'] = $http_noproxy; |
|
| 57 | + $page = recuperer_page($test_proxy, true); |
|
| 58 | + $GLOBALS['meta']['http_proxy'] = $cur_http_proxy; |
|
| 59 | + $GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy; |
|
| 60 | + if ($page) { |
|
| 61 | + $erreurs['message_ok'] = _T('info_proxy_ok')."<br />$info\n<tt>".couper(entites_html($page),300)."</tt>"; |
|
| 62 | + } |
|
| 63 | + else { |
|
| 64 | + $erreurs['message_erreur'] = $info._T('info_impossible_lire_page', array('test_proxy' => "<tt>$test_proxy</tt>")) |
|
| 65 | + . " <b><tt>".no_password_proxy_url($http_proxy)."</tt></b>." |
|
| 66 | + . aide('confhttpproxy'); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + return $erreurs; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | function formulaires_configurer_relayeur_traiter_dist(){ |
| 76 | - $res = array('editable'=>true); |
|
| 76 | + $res = array('editable'=>true); |
|
| 77 | 77 | |
| 78 | - $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', '')); |
|
| 79 | - $http_noproxy = _request('http_noproxy'); |
|
| 80 | - if ($http_proxy !== NULL) |
|
| 81 | - ecrire_meta('http_proxy', $http_proxy); |
|
| 78 | + $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', '')); |
|
| 79 | + $http_noproxy = _request('http_noproxy'); |
|
| 80 | + if ($http_proxy !== NULL) |
|
| 81 | + ecrire_meta('http_proxy', $http_proxy); |
|
| 82 | 82 | |
| 83 | - if ($http_noproxy !== NULL) |
|
| 84 | - ecrire_meta('http_noproxy', $http_noproxy); |
|
| 83 | + if ($http_noproxy !== NULL) |
|
| 84 | + ecrire_meta('http_noproxy', $http_noproxy); |
|
| 85 | 85 | |
| 86 | - $res['message_ok'] = _T('config_info_enregistree'); |
|
| 87 | - return $res; |
|
| 86 | + $res['message_ok'] = _T('config_info_enregistree'); |
|
| 87 | + return $res; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function relayeur_saisie_ou_config($http_proxy, $default){ |
| 91 | - // http_proxy : ne pas prendre en compte la modif si le password est '****' |
|
| 92 | - if (preg_match(',:\*\*\*\*@,', $http_proxy)) |
|
| 93 | - $http_proxy = $default; |
|
| 94 | - return $http_proxy; |
|
| 91 | + // http_proxy : ne pas prendre en compte la modif si le password est '****' |
|
| 92 | + if (preg_match(',:\*\*\*\*@,', $http_proxy)) |
|
| 93 | + $http_proxy = $default; |
|
| 94 | + return $http_proxy; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // Function glue_url : le pendant de parse_url |
| 98 | 98 | // http://doc.spip.org/@glue_url |
| 99 | 99 | function glue_url ($url){ |
| 100 | - if (!is_array($url)){ |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 103 | - // scheme |
|
| 104 | - $uri = (!empty($url['scheme'])) ? $url['scheme'].'://' : ''; |
|
| 105 | - // user & pass |
|
| 106 | - if (!empty($url['user'])){ |
|
| 107 | - $uri .= $url['user'].':'.$url['pass'].'@'; |
|
| 108 | - } |
|
| 109 | - // host |
|
| 110 | - $uri .= $url['host']; |
|
| 111 | - // port |
|
| 112 | - $port = (!empty($url['port'])) ? ':'.$url['port'] : ''; |
|
| 113 | - $uri .= $port; |
|
| 114 | - // path |
|
| 115 | - $uri .= $url['path']; |
|
| 100 | + if (!is_array($url)){ |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | + // scheme |
|
| 104 | + $uri = (!empty($url['scheme'])) ? $url['scheme'].'://' : ''; |
|
| 105 | + // user & pass |
|
| 106 | + if (!empty($url['user'])){ |
|
| 107 | + $uri .= $url['user'].':'.$url['pass'].'@'; |
|
| 108 | + } |
|
| 109 | + // host |
|
| 110 | + $uri .= $url['host']; |
|
| 111 | + // port |
|
| 112 | + $port = (!empty($url['port'])) ? ':'.$url['port'] : ''; |
|
| 113 | + $uri .= $port; |
|
| 114 | + // path |
|
| 115 | + $uri .= $url['path']; |
|
| 116 | 116 | // fragment or query |
| 117 | - if (isset($url['fragment'])){ |
|
| 118 | - $uri .= '#'.$url['fragment']; |
|
| 119 | - } elseif (isset($url['query'])){ |
|
| 120 | - $uri .= '?'.$url['query']; |
|
| 121 | - } |
|
| 122 | - return $uri; |
|
| 117 | + if (isset($url['fragment'])){ |
|
| 118 | + $uri .= '#'.$url['fragment']; |
|
| 119 | + } elseif (isset($url['query'])){ |
|
| 120 | + $uri .= '?'.$url['query']; |
|
| 121 | + } |
|
| 122 | + return $uri; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | // Ne pas afficher la partie 'password' du proxy |
| 127 | 127 | // http://doc.spip.org/@no_password_proxy_url |
| 128 | 128 | function no_password_proxy_url($http_proxy) { |
| 129 | - if ($http_proxy |
|
| 130 | - AND $p = @parse_url($http_proxy) |
|
| 131 | - AND isset($p['pass']) |
|
| 132 | - AND $p['pass']) { |
|
| 133 | - $p['pass'] = '****'; |
|
| 134 | - $http_proxy = glue_url($p); |
|
| 135 | - } |
|
| 136 | - return $http_proxy; |
|
| 129 | + if ($http_proxy |
|
| 130 | + AND $p = @parse_url($http_proxy) |
|
| 131 | + AND isset($p['pass']) |
|
| 132 | + AND $p['pass']) { |
|
| 133 | + $p['pass'] = '****'; |
|
| 134 | + $http_proxy = glue_url($p); |
|
| 135 | + } |
|
| 136 | + return $http_proxy; |
|
| 137 | 137 | } |
| 138 | 138 | ?> |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | include_spip('inc/presentation'); |
| 15 | 15 | include_spip('inc/config'); |
| 16 | 16 | |
| 17 | -function formulaires_configurer_relayeur_charger_dist(){ |
|
| 17 | +function formulaires_configurer_relayeur_charger_dist() { |
|
| 18 | 18 | $valeurs = array( |
| 19 | 19 | 'http_proxy' =>no_password_proxy_url(lire_config('http_proxy', '')), |
| 20 | 20 | 'http_noproxy' => lire_config('http_noproxy', ''), |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | return $valeurs; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | -function formulaires_configurer_relayeur_verifier_dist(){ |
|
| 27 | +function formulaires_configurer_relayeur_verifier_dist() { |
|
| 28 | 28 | $erreurs = array(); |
| 29 | 29 | $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', '')); |
| 30 | 30 | $http_noproxy = _request('http_noproxy'); |
| 31 | 31 | |
| 32 | - if ($http_proxy AND !tester_url_absolue($http_proxy)){ |
|
| 32 | + if ($http_proxy AND !tester_url_absolue($http_proxy)) { |
|
| 33 | 33 | $erreurs['http_proxy'] = _L('format_proxy_incorrect'); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | else { |
| 47 | 47 | include_spip('inc/texte'); // pour aide, couper, lang |
| 48 | 48 | $info = ""; |
| 49 | - if (!need_proxy($t['host'],$http_proxy,$http_noproxy)) |
|
| 49 | + if (!need_proxy($t['host'], $http_proxy, $http_noproxy)) |
|
| 50 | 50 | $info = "<strong>"._T('page_pas_proxy')."</strong><br />"; |
| 51 | 51 | |
| 52 | 52 | // il faut fausser le proxy actuel pour faire le test ! |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $GLOBALS['meta']['http_proxy'] = $cur_http_proxy; |
| 59 | 59 | $GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy; |
| 60 | 60 | if ($page) { |
| 61 | - $erreurs['message_ok'] = _T('info_proxy_ok')."<br />$info\n<tt>".couper(entites_html($page),300)."</tt>"; |
|
| 61 | + $erreurs['message_ok'] = _T('info_proxy_ok')."<br />$info\n<tt>".couper(entites_html($page), 300)."</tt>"; |
|
| 62 | 62 | } |
| 63 | 63 | else { |
| 64 | 64 | $erreurs['message_erreur'] = $info._T('info_impossible_lire_page', array('test_proxy' => "<tt>$test_proxy</tt>")) |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | return $erreurs; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | -function formulaires_configurer_relayeur_traiter_dist(){ |
|
| 75 | +function formulaires_configurer_relayeur_traiter_dist() { |
|
| 76 | 76 | $res = array('editable'=>true); |
| 77 | 77 | |
| 78 | 78 | $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', '')); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | return $res; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | -function relayeur_saisie_ou_config($http_proxy, $default){ |
|
| 90 | +function relayeur_saisie_ou_config($http_proxy, $default) { |
|
| 91 | 91 | // http_proxy : ne pas prendre en compte la modif si le password est '****' |
| 92 | 92 | if (preg_match(',:\*\*\*\*@,', $http_proxy)) |
| 93 | 93 | $http_proxy = $default; |
@@ -96,14 +96,14 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | // Function glue_url : le pendant de parse_url |
| 98 | 98 | // http://doc.spip.org/@glue_url |
| 99 | -function glue_url ($url){ |
|
| 100 | - if (!is_array($url)){ |
|
| 99 | +function glue_url($url) { |
|
| 100 | + if (!is_array($url)) { |
|
| 101 | 101 | return false; |
| 102 | 102 | } |
| 103 | 103 | // scheme |
| 104 | 104 | $uri = (!empty($url['scheme'])) ? $url['scheme'].'://' : ''; |
| 105 | 105 | // user & pass |
| 106 | - if (!empty($url['user'])){ |
|
| 106 | + if (!empty($url['user'])) { |
|
| 107 | 107 | $uri .= $url['user'].':'.$url['pass'].'@'; |
| 108 | 108 | } |
| 109 | 109 | // host |
@@ -114,9 +114,9 @@ discard block |
||
| 114 | 114 | // path |
| 115 | 115 | $uri .= $url['path']; |
| 116 | 116 | // fragment or query |
| 117 | - if (isset($url['fragment'])){ |
|
| 117 | + if (isset($url['fragment'])) { |
|
| 118 | 118 | $uri .= '#'.$url['fragment']; |
| 119 | - } elseif (isset($url['query'])){ |
|
| 119 | + } elseif (isset($url['query'])) { |
|
| 120 | 120 | $uri .= '?'.$url['query']; |
| 121 | 121 | } |
| 122 | 122 | return $uri; |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | include_spip('inc/presentation'); |
| 15 | 17 | include_spip('inc/config'); |
| 16 | 18 | |
@@ -34,20 +36,20 @@ discard block |
||
| 34 | 36 | } |
| 35 | 37 | |
| 36 | 38 | if (!isset($erreurs['http_proxy']) AND _request('tester_proxy')) { |
| 37 | - if (!$http_proxy) |
|
| 38 | - $erreurs['http_proxy'] = _T('info_obligatoire'); |
|
| 39 | - else { |
|
| 39 | + if (!$http_proxy) { |
|
| 40 | + $erreurs['http_proxy'] = _T('info_obligatoire'); |
|
| 41 | + } else { |
|
| 40 | 42 | include_spip('inc/distant'); |
| 41 | 43 | $test_proxy = _request('test_proxy'); |
| 42 | 44 | $t = parse_url($test_proxy); |
| 43 | 45 | if (!@$t['host']) { |
| 44 | 46 | $erreurs['test_proxy'] = _T('info_adresse_non_indiquee'); |
| 45 | - } |
|
| 46 | - else { |
|
| 47 | + } else { |
|
| 47 | 48 | include_spip('inc/texte'); // pour aide, couper, lang |
| 48 | 49 | $info = ""; |
| 49 | - if (!need_proxy($t['host'],$http_proxy,$http_noproxy)) |
|
| 50 | - $info = "<strong>"._T('page_pas_proxy')."</strong><br />"; |
|
| 50 | + if (!need_proxy($t['host'],$http_proxy,$http_noproxy)) { |
|
| 51 | + $info = "<strong>"._T('page_pas_proxy')."</strong><br />"; |
|
| 52 | + } |
|
| 51 | 53 | |
| 52 | 54 | // il faut fausser le proxy actuel pour faire le test ! |
| 53 | 55 | $cur_http_proxy = $GLOBALS['meta']['http_proxy']; |
@@ -59,8 +61,7 @@ discard block |
||
| 59 | 61 | $GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy; |
| 60 | 62 | if ($page) { |
| 61 | 63 | $erreurs['message_ok'] = _T('info_proxy_ok')."<br />$info\n<tt>".couper(entites_html($page),300)."</tt>"; |
| 62 | - } |
|
| 63 | - else { |
|
| 64 | + } else { |
|
| 64 | 65 | $erreurs['message_erreur'] = $info._T('info_impossible_lire_page', array('test_proxy' => "<tt>$test_proxy</tt>")) |
| 65 | 66 | . " <b><tt>".no_password_proxy_url($http_proxy)."</tt></b>." |
| 66 | 67 | . aide('confhttpproxy'); |
@@ -77,11 +78,13 @@ discard block |
||
| 77 | 78 | |
| 78 | 79 | $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', '')); |
| 79 | 80 | $http_noproxy = _request('http_noproxy'); |
| 80 | - if ($http_proxy !== NULL) |
|
| 81 | - ecrire_meta('http_proxy', $http_proxy); |
|
| 81 | + if ($http_proxy !== NULL) { |
|
| 82 | + ecrire_meta('http_proxy', $http_proxy); |
|
| 83 | + } |
|
| 82 | 84 | |
| 83 | - if ($http_noproxy !== NULL) |
|
| 84 | - ecrire_meta('http_noproxy', $http_noproxy); |
|
| 85 | + if ($http_noproxy !== NULL) { |
|
| 86 | + ecrire_meta('http_noproxy', $http_noproxy); |
|
| 87 | + } |
|
| 85 | 88 | |
| 86 | 89 | $res['message_ok'] = _T('config_info_enregistree'); |
| 87 | 90 | return $res; |
@@ -89,8 +92,9 @@ discard block |
||
| 89 | 92 | |
| 90 | 93 | function relayeur_saisie_ou_config($http_proxy, $default){ |
| 91 | 94 | // http_proxy : ne pas prendre en compte la modif si le password est '****' |
| 92 | - if (preg_match(',:\*\*\*\*@,', $http_proxy)) |
|
| 93 | - $http_proxy = $default; |
|
| 95 | + if (preg_match(',:\*\*\*\*@,', $http_proxy)) { |
|
| 96 | + $http_proxy = $default; |
|
| 97 | + } |
|
| 94 | 98 | return $http_proxy; |
| 95 | 99 | } |
| 96 | 100 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | |
| 289 | 289 | // http://doc.spip.org/@spip_mysql_order |
| 290 | 290 | /** |
| 291 | - * @param $orderby |
|
| 291 | + * @param string $orderby |
|
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | 294 | function spip_mysql_order($orderby) |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | |
| 326 | 326 | // http://doc.spip.org/@calculer_mysql_expression |
| 327 | 327 | /** |
| 328 | - * @param $expression |
|
| 328 | + * @param string $expression |
|
| 329 | 329 | * @param $v |
| 330 | 330 | * @param string $join |
| 331 | 331 | * @return string |
@@ -420,9 +420,8 @@ discard block |
||
| 420 | 420 | /** |
| 421 | 421 | * Selectionne une base de donnees |
| 422 | 422 | * |
| 423 | - * @param string $nom |
|
| 424 | - * Nom de la base a utiliser |
|
| 425 | 423 | * |
| 424 | + * @param string $db |
|
| 426 | 425 | * @return bool |
| 427 | 426 | * True cas de success. |
| 428 | 427 | * False en cas d'erreur. |
@@ -828,7 +827,7 @@ discard block |
||
| 828 | 827 | // http://doc.spip.org/@spip_mysql_insert |
| 829 | 828 | /** |
| 830 | 829 | * @param $table |
| 831 | - * @param $champs |
|
| 830 | + * @param string $champs |
|
| 832 | 831 | * @param $valeurs |
| 833 | 832 | * @param string $desc |
| 834 | 833 | * @param string $serveur |
@@ -33,75 +33,75 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | |
| 35 | 35 | function req_mysql_dist($host, $port, $login, $pass, $db='', $prefixe='') { |
| 36 | - if (!charger_php_extension('mysql')) return false; |
|
| 37 | - if ($port > 0) $host = "$host:$port"; |
|
| 38 | - $link = @mysql_connect($host, $login, $pass, true); |
|
| 39 | - if (!$link) { |
|
| 40 | - spip_log('Echec mysql_connect. Erreur : ' . mysql_error(),'mysql.'._LOG_HS); |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 43 | - $last = ''; |
|
| 44 | - if (!$db) { |
|
| 45 | - $ok = $link; |
|
| 46 | - $db = 'spip'; |
|
| 47 | - } else { |
|
| 48 | - $ok = spip_mysql_selectdb($db); |
|
| 49 | - if (defined('_MYSQL_SET_SQL_MODE') |
|
| 50 | - OR defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 51 | - ) |
|
| 52 | - mysql_query($last = "set sql_mode=''"); |
|
| 53 | - } |
|
| 54 | - spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle sur $link" : 'impossible'), _LOG_DEBUG); |
|
| 55 | - |
|
| 56 | - return !$ok ? false : array( |
|
| 57 | - 'db' => $db, |
|
| 58 | - 'last' => $last, |
|
| 59 | - 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 60 | - 'link' => $GLOBALS['mysql_rappel_connexion'] ? $link : false, |
|
| 61 | - ); |
|
| 36 | + if (!charger_php_extension('mysql')) return false; |
|
| 37 | + if ($port > 0) $host = "$host:$port"; |
|
| 38 | + $link = @mysql_connect($host, $login, $pass, true); |
|
| 39 | + if (!$link) { |
|
| 40 | + spip_log('Echec mysql_connect. Erreur : ' . mysql_error(),'mysql.'._LOG_HS); |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | + $last = ''; |
|
| 44 | + if (!$db) { |
|
| 45 | + $ok = $link; |
|
| 46 | + $db = 'spip'; |
|
| 47 | + } else { |
|
| 48 | + $ok = spip_mysql_selectdb($db); |
|
| 49 | + if (defined('_MYSQL_SET_SQL_MODE') |
|
| 50 | + OR defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 51 | + ) |
|
| 52 | + mysql_query($last = "set sql_mode=''"); |
|
| 53 | + } |
|
| 54 | + spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle sur $link" : 'impossible'), _LOG_DEBUG); |
|
| 55 | + |
|
| 56 | + return !$ok ? false : array( |
|
| 57 | + 'db' => $db, |
|
| 58 | + 'last' => $last, |
|
| 59 | + 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 60 | + 'link' => $GLOBALS['mysql_rappel_connexion'] ? $link : false, |
|
| 61 | + ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $GLOBALS['spip_mysql_functions_1'] = array( |
| 65 | - 'alter' => 'spip_mysql_alter', |
|
| 66 | - 'count' => 'spip_mysql_count', |
|
| 67 | - 'countsel' => 'spip_mysql_countsel', |
|
| 68 | - 'create' => 'spip_mysql_create', |
|
| 69 | - 'create_base' => 'spip_mysql_create_base', |
|
| 70 | - 'create_view' => 'spip_mysql_create_view', |
|
| 71 | - 'date_proche' => 'spip_mysql_date_proche', |
|
| 72 | - 'delete' => 'spip_mysql_delete', |
|
| 73 | - 'drop_table' => 'spip_mysql_drop_table', |
|
| 74 | - 'drop_view' => 'spip_mysql_drop_view', |
|
| 75 | - 'errno' => 'spip_mysql_errno', |
|
| 76 | - 'error' => 'spip_mysql_error', |
|
| 77 | - 'explain' => 'spip_mysql_explain', |
|
| 78 | - 'fetch' => 'spip_mysql_fetch', |
|
| 79 | - 'seek' => 'spip_mysql_seek', |
|
| 80 | - 'free' => 'spip_mysql_free', |
|
| 81 | - 'hex' => 'spip_mysql_hex', |
|
| 82 | - 'in' => 'spip_mysql_in', |
|
| 83 | - 'insert' => 'spip_mysql_insert', |
|
| 84 | - 'insertq' => 'spip_mysql_insertq', |
|
| 85 | - 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 86 | - 'listdbs' => 'spip_mysql_listdbs', |
|
| 87 | - 'multi' => 'spip_mysql_multi', |
|
| 88 | - 'optimize' => 'spip_mysql_optimize', |
|
| 89 | - 'query' => 'spip_mysql_query', |
|
| 90 | - 'quote' => 'spip_mysql_quote', |
|
| 91 | - 'replace' => 'spip_mysql_replace', |
|
| 92 | - 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 93 | - 'repair' => 'spip_mysql_repair', |
|
| 94 | - 'select' => 'spip_mysql_select', |
|
| 95 | - 'selectdb' => 'spip_mysql_selectdb', |
|
| 96 | - 'set_charset' => 'spip_mysql_set_charset', |
|
| 97 | - 'get_charset' => 'spip_mysql_get_charset', |
|
| 98 | - 'showbase' => 'spip_mysql_showbase', |
|
| 99 | - 'showtable' => 'spip_mysql_showtable', |
|
| 100 | - 'update' => 'spip_mysql_update', |
|
| 101 | - 'updateq' => 'spip_mysql_updateq', |
|
| 102 | - |
|
| 103 | - // association de chaque nom http d'un charset aux couples MySQL |
|
| 104 | - 'charsets' => array( |
|
| 65 | + 'alter' => 'spip_mysql_alter', |
|
| 66 | + 'count' => 'spip_mysql_count', |
|
| 67 | + 'countsel' => 'spip_mysql_countsel', |
|
| 68 | + 'create' => 'spip_mysql_create', |
|
| 69 | + 'create_base' => 'spip_mysql_create_base', |
|
| 70 | + 'create_view' => 'spip_mysql_create_view', |
|
| 71 | + 'date_proche' => 'spip_mysql_date_proche', |
|
| 72 | + 'delete' => 'spip_mysql_delete', |
|
| 73 | + 'drop_table' => 'spip_mysql_drop_table', |
|
| 74 | + 'drop_view' => 'spip_mysql_drop_view', |
|
| 75 | + 'errno' => 'spip_mysql_errno', |
|
| 76 | + 'error' => 'spip_mysql_error', |
|
| 77 | + 'explain' => 'spip_mysql_explain', |
|
| 78 | + 'fetch' => 'spip_mysql_fetch', |
|
| 79 | + 'seek' => 'spip_mysql_seek', |
|
| 80 | + 'free' => 'spip_mysql_free', |
|
| 81 | + 'hex' => 'spip_mysql_hex', |
|
| 82 | + 'in' => 'spip_mysql_in', |
|
| 83 | + 'insert' => 'spip_mysql_insert', |
|
| 84 | + 'insertq' => 'spip_mysql_insertq', |
|
| 85 | + 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 86 | + 'listdbs' => 'spip_mysql_listdbs', |
|
| 87 | + 'multi' => 'spip_mysql_multi', |
|
| 88 | + 'optimize' => 'spip_mysql_optimize', |
|
| 89 | + 'query' => 'spip_mysql_query', |
|
| 90 | + 'quote' => 'spip_mysql_quote', |
|
| 91 | + 'replace' => 'spip_mysql_replace', |
|
| 92 | + 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 93 | + 'repair' => 'spip_mysql_repair', |
|
| 94 | + 'select' => 'spip_mysql_select', |
|
| 95 | + 'selectdb' => 'spip_mysql_selectdb', |
|
| 96 | + 'set_charset' => 'spip_mysql_set_charset', |
|
| 97 | + 'get_charset' => 'spip_mysql_get_charset', |
|
| 98 | + 'showbase' => 'spip_mysql_showbase', |
|
| 99 | + 'showtable' => 'spip_mysql_showtable', |
|
| 100 | + 'update' => 'spip_mysql_update', |
|
| 101 | + 'updateq' => 'spip_mysql_updateq', |
|
| 102 | + |
|
| 103 | + // association de chaque nom http d'un charset aux couples MySQL |
|
| 104 | + 'charsets' => array( |
|
| 105 | 105 | 'cp1250'=>array('charset'=>'cp1250','collation'=>'cp1250_general_ci'), |
| 106 | 106 | 'cp1251'=>array('charset'=>'cp1251','collation'=>'cp1251_general_ci'), |
| 107 | 107 | 'cp1256'=>array('charset'=>'cp1256','collation'=>'cp1256_general_ci'), |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | 'iso-8859-9'=>array('charset'=>'latin5','collation'=>'latin5_turkish_ci'), |
| 111 | 111 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 112 | 112 | 'utf-8'=>array('charset'=>'utf8','collation'=>'utf8_general_ci')) |
| 113 | - ); |
|
| 113 | + ); |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | * @return resource Ressource de résultats pour fetch() |
| 123 | 123 | */ |
| 124 | 124 | function spip_mysql_set_charset($charset, $serveur='',$requeter=true){ |
| 125 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 126 | - spip_log("changement de charset sql : "."SET NAMES "._q($charset), _LOG_DEBUG); |
|
| 127 | - return mysql_query($connexion['last'] = "SET NAMES "._q($charset)); |
|
| 125 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 126 | + spip_log("changement de charset sql : "."SET NAMES "._q($charset), _LOG_DEBUG); |
|
| 127 | + return mysql_query($connexion['last'] = "SET NAMES "._q($charset)); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
@@ -137,24 +137,23 @@ discard block |
||
| 137 | 137 | * @return array Description du charset (son nom est dans 'charset') |
| 138 | 138 | */ |
| 139 | 139 | function spip_mysql_get_charset($charset=array(), $serveur='',$requeter=true){ |
| 140 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 141 | - $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 142 | - . (!$charset ? '' : (" LIKE "._q($charset['charset']))); |
|
| 140 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 141 | + $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 142 | + . (!$charset ? '' : (" LIKE "._q($charset['charset']))); |
|
| 143 | 143 | |
| 144 | - return spip_mysql_fetch(mysql_query($c), NULL, $serveur); |
|
| 144 | + return spip_mysql_fetch(mysql_query($c), NULL, $serveur); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // obsolete, ne plus utiliser |
| 148 | 148 | // http://doc.spip.org/@spip_query_db |
| 149 | 149 | function spip_query_db($query, $serveur='',$requeter=true) { |
| 150 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 150 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Fonction de requete generale, munie d'une trace a la demande |
| 154 | 154 | |
| 155 | 155 | // http://doc.spip.org/@spip_mysql_query |
| 156 | 156 | /** |
| 157 | - |
|
| 158 | 157 | * @param $query |
| 159 | 158 | * @param string $serveur |
| 160 | 159 | * @param bool $requeter |
@@ -163,39 +162,39 @@ discard block |
||
| 163 | 162 | */ |
| 164 | 163 | function spip_mysql_query($query, $serveur='',$requeter=true) { |
| 165 | 164 | |
| 166 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 167 | - $prefixe = $connexion['prefixe']; |
|
| 168 | - $link = $connexion['link']; |
|
| 169 | - $db = $connexion['db']; |
|
| 165 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 166 | + $prefixe = $connexion['prefixe']; |
|
| 167 | + $link = $connexion['link']; |
|
| 168 | + $db = $connexion['db']; |
|
| 170 | 169 | |
| 171 | - $query = traite_query($query, $db, $prefixe); |
|
| 170 | + $query = traite_query($query, $db, $prefixe); |
|
| 172 | 171 | |
| 173 | - // renvoyer la requete inerte si demandee |
|
| 174 | - if (!$requeter) return $query; |
|
| 172 | + // renvoyer la requete inerte si demandee |
|
| 173 | + if (!$requeter) return $query; |
|
| 175 | 174 | |
| 176 | - if (isset($_GET['var_profile'])) { |
|
| 177 | - include_spip('public/tracer'); |
|
| 178 | - $t = trace_query_start(); |
|
| 179 | - } else $t = 0 ; |
|
| 175 | + if (isset($_GET['var_profile'])) { |
|
| 176 | + include_spip('public/tracer'); |
|
| 177 | + $t = trace_query_start(); |
|
| 178 | + } else $t = 0 ; |
|
| 180 | 179 | |
| 181 | - $connexion['last'] = $query; |
|
| 182 | - |
|
| 183 | - // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 184 | - $debug = ''; |
|
| 185 | - if (defined('_DEBUG_SLOW_QUERIES') AND _DEBUG_SLOW_QUERIES){ |
|
| 186 | - if(isset($GLOBALS['debug']['aucasou'])){ |
|
| 187 | - list(,$id,, $infos) = $GLOBALS['debug']['aucasou']; |
|
| 188 | - $debug .= "BOUCLE$id @ ".$infos[0] ." | "; |
|
| 189 | - } |
|
| 190 | - $debug .= $_SERVER['REQUEST_URI'].' + '.$GLOBALS['ip']; |
|
| 191 | - $debug = ' /* '. mysql_real_escape_string(str_replace('*/','@/',$debug)). ' */'; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $r = $link ? mysql_query($query.$debug, $link) : mysql_query($query.$debug); |
|
| 195 | - |
|
| 196 | - if ($e = spip_mysql_errno($serveur)) // Log de l'erreur eventuelle |
|
| 197 | - $e .= spip_mysql_error($query, $serveur); // et du fautif |
|
| 198 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 180 | + $connexion['last'] = $query; |
|
| 181 | + |
|
| 182 | + // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 183 | + $debug = ''; |
|
| 184 | + if (defined('_DEBUG_SLOW_QUERIES') AND _DEBUG_SLOW_QUERIES){ |
|
| 185 | + if(isset($GLOBALS['debug']['aucasou'])){ |
|
| 186 | + list(,$id,, $infos) = $GLOBALS['debug']['aucasou']; |
|
| 187 | + $debug .= "BOUCLE$id @ ".$infos[0] ." | "; |
|
| 188 | + } |
|
| 189 | + $debug .= $_SERVER['REQUEST_URI'].' + '.$GLOBALS['ip']; |
|
| 190 | + $debug = ' /* '. mysql_real_escape_string(str_replace('*/','@/',$debug)). ' */'; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $r = $link ? mysql_query($query.$debug, $link) : mysql_query($query.$debug); |
|
| 194 | + |
|
| 195 | + if ($e = spip_mysql_errno($serveur)) // Log de l'erreur eventuelle |
|
| 196 | + $e .= spip_mysql_error($query, $serveur); // et du fautif |
|
| 197 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 199 | 198 | } |
| 200 | 199 | |
| 201 | 200 | // http://doc.spip.org/@spip_mysql_alter |
@@ -206,11 +205,11 @@ discard block |
||
| 206 | 205 | * @return array|null|resource|string |
| 207 | 206 | */ |
| 208 | 207 | function spip_mysql_alter($query, $serveur='',$requeter=true){ |
| 209 | - // ici on supprime les ` entourant le nom de table pour permettre |
|
| 210 | - // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 211 | - // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 212 | - $query = preg_replace(",^TABLE\s*`([^`]*)`,i","TABLE \\1",$query); |
|
| 213 | - return spip_mysql_query("ALTER ".$query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 208 | + // ici on supprime les ` entourant le nom de table pour permettre |
|
| 209 | + // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 210 | + // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 211 | + $query = preg_replace(",^TABLE\s*`([^`]*)`,i","TABLE \\1",$query); |
|
| 212 | + return spip_mysql_query("ALTER ".$query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 214 | 213 | } |
| 215 | 214 | |
| 216 | 215 | // http://doc.spip.org/@spip_mysql_optimize |
@@ -221,8 +220,8 @@ discard block |
||
| 221 | 220 | * @return bool |
| 222 | 221 | */ |
| 223 | 222 | function spip_mysql_optimize($table, $serveur='',$requeter=true){ |
| 224 | - spip_mysql_query("OPTIMIZE TABLE ". $table); |
|
| 225 | - return true; |
|
| 223 | + spip_mysql_query("OPTIMIZE TABLE ". $table); |
|
| 224 | + return true; |
|
| 226 | 225 | } |
| 227 | 226 | |
| 228 | 227 | // http://doc.spip.org/@spip_mysql_explain |
@@ -233,15 +232,15 @@ discard block |
||
| 233 | 232 | * @return array |
| 234 | 233 | */ |
| 235 | 234 | function spip_mysql_explain($query, $serveur='',$requeter=true){ |
| 236 | - if (strpos(ltrim($query), 'SELECT') !== 0) return array(); |
|
| 237 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 238 | - $prefixe = $connexion['prefixe']; |
|
| 239 | - $link = $connexion['link']; |
|
| 240 | - $db = $connexion['db']; |
|
| 241 | - |
|
| 242 | - $query = 'EXPLAIN ' . traite_query($query, $db, $prefixe); |
|
| 243 | - $r = $link ? mysql_query($query, $link) : mysql_query($query); |
|
| 244 | - return spip_mysql_fetch($r, NULL, $serveur); |
|
| 235 | + if (strpos(ltrim($query), 'SELECT') !== 0) return array(); |
|
| 236 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 237 | + $prefixe = $connexion['prefixe']; |
|
| 238 | + $link = $connexion['link']; |
|
| 239 | + $db = $connexion['db']; |
|
| 240 | + |
|
| 241 | + $query = 'EXPLAIN ' . traite_query($query, $db, $prefixe); |
|
| 242 | + $r = $link ? mysql_query($query, $link) : mysql_query($query); |
|
| 243 | + return spip_mysql_fetch($r, NULL, $serveur); |
|
| 245 | 244 | } |
| 246 | 245 | // fonction instance de sql_select, voir ses specs dans abstract.php |
| 247 | 246 | // traite_query pourrait y etre fait d'avance ce serait moins cher |
@@ -262,24 +261,24 @@ discard block |
||
| 262 | 261 | * @return array|null|resource|string |
| 263 | 262 | */ |
| 264 | 263 | function spip_mysql_select($select, $from, $where='', |
| 265 | - $groupby='', $orderby='', $limit='', $having='', |
|
| 266 | - $serveur='',$requeter=true) { |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 270 | - $query = |
|
| 271 | - calculer_mysql_expression('SELECT', $select, ', ') |
|
| 272 | - . calculer_mysql_expression('FROM', $from, ', ') |
|
| 273 | - . calculer_mysql_expression('WHERE', $where) |
|
| 274 | - . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 275 | - . calculer_mysql_expression('HAVING', $having) |
|
| 276 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) :'') |
|
| 277 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 278 | - |
|
| 279 | - // renvoyer la requete inerte si demandee |
|
| 280 | - if ($requeter === false) return $query; |
|
| 281 | - $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 282 | - return $r ? $r : $query; |
|
| 264 | + $groupby='', $orderby='', $limit='', $having='', |
|
| 265 | + $serveur='',$requeter=true) { |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 269 | + $query = |
|
| 270 | + calculer_mysql_expression('SELECT', $select, ', ') |
|
| 271 | + . calculer_mysql_expression('FROM', $from, ', ') |
|
| 272 | + . calculer_mysql_expression('WHERE', $where) |
|
| 273 | + . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 274 | + . calculer_mysql_expression('HAVING', $having) |
|
| 275 | + . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) :'') |
|
| 276 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 277 | + |
|
| 278 | + // renvoyer la requete inerte si demandee |
|
| 279 | + if ($requeter === false) return $query; |
|
| 280 | + $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 281 | + return $r ? $r : $query; |
|
| 283 | 282 | } |
| 284 | 283 | |
| 285 | 284 | // 0+x avec un champ x commencant par des chiffres est converti par MySQL |
@@ -293,7 +292,7 @@ discard block |
||
| 293 | 292 | */ |
| 294 | 293 | function spip_mysql_order($orderby) |
| 295 | 294 | { |
| 296 | - return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 295 | + return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 297 | 296 | } |
| 298 | 297 | |
| 299 | 298 | |
@@ -304,23 +303,23 @@ discard block |
||
| 304 | 303 | */ |
| 305 | 304 | function calculer_mysql_where($v) |
| 306 | 305 | { |
| 307 | - if (!is_array($v)) |
|
| 308 | - return $v ; |
|
| 309 | - |
|
| 310 | - $op = array_shift($v); |
|
| 311 | - if (!($n=count($v))) |
|
| 312 | - return $op; |
|
| 313 | - else { |
|
| 314 | - $arg = calculer_mysql_where(array_shift($v)); |
|
| 315 | - if ($n==1) { |
|
| 316 | - return "$op($arg)"; |
|
| 317 | - } else { |
|
| 318 | - $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 319 | - if ($n==2) { |
|
| 320 | - return "($arg $op $arg2)"; |
|
| 321 | - } else return "($arg $op ($arg2) : $v[0])"; |
|
| 322 | - } |
|
| 323 | - } |
|
| 306 | + if (!is_array($v)) |
|
| 307 | + return $v ; |
|
| 308 | + |
|
| 309 | + $op = array_shift($v); |
|
| 310 | + if (!($n=count($v))) |
|
| 311 | + return $op; |
|
| 312 | + else { |
|
| 313 | + $arg = calculer_mysql_where(array_shift($v)); |
|
| 314 | + if ($n==1) { |
|
| 315 | + return "$op($arg)"; |
|
| 316 | + } else { |
|
| 317 | + $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 318 | + if ($n==2) { |
|
| 319 | + return "($arg $op $arg2)"; |
|
| 320 | + } else return "($arg $op ($arg2) : $v[0])"; |
|
| 321 | + } |
|
| 322 | + } |
|
| 324 | 323 | } |
| 325 | 324 | |
| 326 | 325 | // http://doc.spip.org/@calculer_mysql_expression |
@@ -331,19 +330,19 @@ discard block |
||
| 331 | 330 | * @return string |
| 332 | 331 | */ |
| 333 | 332 | function calculer_mysql_expression($expression, $v, $join = 'AND'){ |
| 334 | - if (empty($v)) |
|
| 335 | - return ''; |
|
| 333 | + if (empty($v)) |
|
| 334 | + return ''; |
|
| 336 | 335 | |
| 337 | - $exp = "\n$expression "; |
|
| 336 | + $exp = "\n$expression "; |
|
| 338 | 337 | |
| 339 | - if (!is_array($v)) { |
|
| 340 | - return $exp . $v; |
|
| 341 | - } else { |
|
| 342 | - if (strtoupper($join) === 'AND') |
|
| 343 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 344 | - else |
|
| 345 | - return $exp . join($join, $v); |
|
| 346 | - } |
|
| 338 | + if (!is_array($v)) { |
|
| 339 | + return $exp . $v; |
|
| 340 | + } else { |
|
| 341 | + if (strtoupper($join) === 'AND') |
|
| 342 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 343 | + else |
|
| 344 | + return $exp . join($join, $v); |
|
| 345 | + } |
|
| 347 | 346 | } |
| 348 | 347 | |
| 349 | 348 | // http://doc.spip.org/@spip_mysql_select_as |
@@ -353,25 +352,25 @@ discard block |
||
| 353 | 352 | */ |
| 354 | 353 | function spip_mysql_select_as($args) |
| 355 | 354 | { |
| 356 | - $res = ''; |
|
| 357 | - foreach($args as $k => $v) { |
|
| 358 | - if (substr($k,-1)=='@') { |
|
| 359 | - // c'est une jointure qui se refere au from precedent |
|
| 360 | - // pas de virgule |
|
| 361 | - $res .= ' ' . $v ; |
|
| 362 | - } |
|
| 363 | - else { |
|
| 364 | - if (!is_numeric($k)) { |
|
| 365 | - $p = strpos($v, " "); |
|
| 366 | - if ($p) |
|
| 367 | - $v = substr($v,0,$p) . " AS `$k`" . substr($v,$p); |
|
| 368 | - else $v .= " AS `$k`"; |
|
| 369 | - } |
|
| 355 | + $res = ''; |
|
| 356 | + foreach($args as $k => $v) { |
|
| 357 | + if (substr($k,-1)=='@') { |
|
| 358 | + // c'est une jointure qui se refere au from precedent |
|
| 359 | + // pas de virgule |
|
| 360 | + $res .= ' ' . $v ; |
|
| 361 | + } |
|
| 362 | + else { |
|
| 363 | + if (!is_numeric($k)) { |
|
| 364 | + $p = strpos($v, " "); |
|
| 365 | + if ($p) |
|
| 366 | + $v = substr($v,0,$p) . " AS `$k`" . substr($v,$p); |
|
| 367 | + else $v .= " AS `$k`"; |
|
| 368 | + } |
|
| 370 | 369 | |
| 371 | - $res .= ', ' . $v ; |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - return substr($res,2); |
|
| 370 | + $res .= ', ' . $v ; |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + return substr($res,2); |
|
| 375 | 374 | } |
| 376 | 375 | |
| 377 | 376 | // |
@@ -389,32 +388,32 @@ discard block |
||
| 389 | 388 | */ |
| 390 | 389 | function traite_query($query, $db='', $prefixe='') { |
| 391 | 390 | |
| 392 | - if ($GLOBALS['mysql_rappel_nom_base'] AND $db) |
|
| 393 | - $pref = '`'. $db.'`.'; |
|
| 394 | - else $pref = ''; |
|
| 395 | - |
|
| 396 | - if ($prefixe) |
|
| 397 | - $pref .= $prefixe . "_"; |
|
| 398 | - |
|
| 399 | - if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 400 | - $suite =''; |
|
| 401 | - } else { |
|
| 402 | - $suite = strstr($query, $regs[0]); |
|
| 403 | - $query = substr($query, 0, -strlen($suite)); |
|
| 404 | - // propager le prefixe en cas de requete imbriquee |
|
| 405 | - // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 406 | - // modifier une requete qui est en fait juste du texte dans un champ |
|
| 407 | - if (stripos($suite,"SELECT")!==false) { |
|
| 408 | - list($suite,$textes) = query_echappe_textes($suite); |
|
| 409 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) |
|
| 410 | - $suite = $r[1] . traite_query($r[2], $db, $prefixe); |
|
| 411 | - $suite = query_reinjecte_textes($suite, $textes); |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - $r = preg_replace(_SQL_PREFIXE_TABLE, '\1'.$pref, $query) . $suite; |
|
| 415 | - |
|
| 416 | - #spip_log("traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 417 | - return $r; |
|
| 391 | + if ($GLOBALS['mysql_rappel_nom_base'] AND $db) |
|
| 392 | + $pref = '`'. $db.'`.'; |
|
| 393 | + else $pref = ''; |
|
| 394 | + |
|
| 395 | + if ($prefixe) |
|
| 396 | + $pref .= $prefixe . "_"; |
|
| 397 | + |
|
| 398 | + if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 399 | + $suite =''; |
|
| 400 | + } else { |
|
| 401 | + $suite = strstr($query, $regs[0]); |
|
| 402 | + $query = substr($query, 0, -strlen($suite)); |
|
| 403 | + // propager le prefixe en cas de requete imbriquee |
|
| 404 | + // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 405 | + // modifier une requete qui est en fait juste du texte dans un champ |
|
| 406 | + if (stripos($suite,"SELECT")!==false) { |
|
| 407 | + list($suite,$textes) = query_echappe_textes($suite); |
|
| 408 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) |
|
| 409 | + $suite = $r[1] . traite_query($r[2], $db, $prefixe); |
|
| 410 | + $suite = query_reinjecte_textes($suite, $textes); |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + $r = preg_replace(_SQL_PREFIXE_TABLE, '\1'.$pref, $query) . $suite; |
|
| 414 | + |
|
| 415 | + #spip_log("traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 416 | + return $r; |
|
| 418 | 417 | } |
| 419 | 418 | |
| 420 | 419 | /** |
@@ -428,10 +427,10 @@ discard block |
||
| 428 | 427 | * False en cas d'erreur. |
| 429 | 428 | **/ |
| 430 | 429 | function spip_mysql_selectdb($db) { |
| 431 | - $ok = mysql_select_db($db); |
|
| 432 | - if (!$ok) |
|
| 433 | - spip_log('Echec mysql_selectdb. Erreur : ' . mysql_error(),'mysql.'._LOG_CRITIQUE); |
|
| 434 | - return $ok; |
|
| 430 | + $ok = mysql_select_db($db); |
|
| 431 | + if (!$ok) |
|
| 432 | + spip_log('Echec mysql_selectdb. Erreur : ' . mysql_error(),'mysql.'._LOG_CRITIQUE); |
|
| 433 | + return $ok; |
|
| 435 | 434 | } |
| 436 | 435 | |
| 437 | 436 | |
@@ -451,12 +450,12 @@ discard block |
||
| 451 | 450 | * Liste de noms de bases de donnees |
| 452 | 451 | **/ |
| 453 | 452 | function spip_mysql_listdbs($serveur='',$requeter=true) { |
| 454 | - $dbs = array(); |
|
| 455 | - if ($res = spip_mysql_query("SHOW DATABASES")){ |
|
| 456 | - while($row = mysql_fetch_assoc($res)) |
|
| 457 | - $dbs[] = $row['Database']; |
|
| 458 | - } |
|
| 459 | - return $dbs; |
|
| 453 | + $dbs = array(); |
|
| 454 | + if ($res = spip_mysql_query("SHOW DATABASES")){ |
|
| 455 | + while($row = mysql_fetch_assoc($res)) |
|
| 456 | + $dbs[] = $row['Database']; |
|
| 457 | + } |
|
| 458 | + return $dbs; |
|
| 460 | 459 | } |
| 461 | 460 | |
| 462 | 461 | // Fonction de creation d'une table SQL nommee $nom |
@@ -479,53 +478,53 @@ discard block |
||
| 479 | 478 | */ |
| 480 | 479 | function spip_mysql_create($nom, $champs, $cles, $autoinc=false, $temporary=false, $serveur='',$requeter=true) { |
| 481 | 480 | |
| 482 | - $query = ''; $keys = ''; $s = ''; $p=''; |
|
| 483 | - |
|
| 484 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 485 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 486 | - if (!is_array($champs) || !is_array($cles)) |
|
| 487 | - return; |
|
| 488 | - |
|
| 489 | - $res = spip_mysql_query("SELECT version() as v"); |
|
| 490 | - if (($row = mysql_fetch_array($res)) && (version_compare($row['v'],'5.0','>='))) { |
|
| 491 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - foreach($cles as $k => $v) { |
|
| 495 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 496 | - if ($k == "PRIMARY KEY") |
|
| 497 | - $p = $v; |
|
| 498 | - $s = ","; |
|
| 499 | - } |
|
| 500 | - $s = ''; |
|
| 481 | + $query = ''; $keys = ''; $s = ''; $p=''; |
|
| 482 | + |
|
| 483 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 484 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 485 | + if (!is_array($champs) || !is_array($cles)) |
|
| 486 | + return; |
|
| 487 | + |
|
| 488 | + $res = spip_mysql_query("SELECT version() as v"); |
|
| 489 | + if (($row = mysql_fetch_array($res)) && (version_compare($row['v'],'5.0','>='))) { |
|
| 490 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + foreach($cles as $k => $v) { |
|
| 494 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 495 | + if ($k == "PRIMARY KEY") |
|
| 496 | + $p = $v; |
|
| 497 | + $s = ","; |
|
| 498 | + } |
|
| 499 | + $s = ''; |
|
| 501 | 500 | |
| 502 | - $character_set = ""; |
|
| 503 | - if (@$GLOBALS['meta']['charset_sql_base']) |
|
| 504 | - $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 505 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) |
|
| 506 | - $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 507 | - |
|
| 508 | - foreach($champs as $k => $v) { |
|
| 509 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 510 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i',$v,$defs)){ |
|
| 511 | - if (preg_match(',(char|text),i',$defs[1]) |
|
| 512 | - AND !preg_match(',(binary|CHARACTER|COLLATE),i',$v) ){ |
|
| 513 | - $v = $defs[1] . $character_set . ' ' . substr($v,strlen($defs[1])); |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $query .= "$s\n\t\t$k $v" |
|
| 518 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 519 | - ? " auto_increment" |
|
| 520 | - : '' |
|
| 521 | - ); |
|
| 522 | - $s = ","; |
|
| 523 | - } |
|
| 524 | - $temporary = $temporary ? 'TEMPORARY':''; |
|
| 525 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")". |
|
| 526 | - ($character_set?" DEFAULT $character_set":"") |
|
| 527 | - ."\n"; |
|
| 528 | - return spip_mysql_query($q, $serveur); |
|
| 501 | + $character_set = ""; |
|
| 502 | + if (@$GLOBALS['meta']['charset_sql_base']) |
|
| 503 | + $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 504 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) |
|
| 505 | + $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 506 | + |
|
| 507 | + foreach($champs as $k => $v) { |
|
| 508 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 509 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i',$v,$defs)){ |
|
| 510 | + if (preg_match(',(char|text),i',$defs[1]) |
|
| 511 | + AND !preg_match(',(binary|CHARACTER|COLLATE),i',$v) ){ |
|
| 512 | + $v = $defs[1] . $character_set . ' ' . substr($v,strlen($defs[1])); |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + $query .= "$s\n\t\t$k $v" |
|
| 517 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 518 | + ? " auto_increment" |
|
| 519 | + : '' |
|
| 520 | + ); |
|
| 521 | + $s = ","; |
|
| 522 | + } |
|
| 523 | + $temporary = $temporary ? 'TEMPORARY':''; |
|
| 524 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")". |
|
| 525 | + ($character_set?" DEFAULT $character_set":"") |
|
| 526 | + ."\n"; |
|
| 527 | + return spip_mysql_query($q, $serveur); |
|
| 529 | 528 | } |
| 530 | 529 | |
| 531 | 530 | |
@@ -538,16 +537,16 @@ discard block |
||
| 538 | 537 | * Definition SQL adaptee pour MySQL d'un champ de table |
| 539 | 538 | */ |
| 540 | 539 | function _mysql_remplacements_definitions_table($query){ |
| 541 | - // quelques remplacements |
|
| 542 | - $num = "(\s*\([0-9]*\))?"; |
|
| 543 | - $enum = "(\s*\([^\)]*\))?"; |
|
| 540 | + // quelques remplacements |
|
| 541 | + $num = "(\s*\([0-9]*\))?"; |
|
| 542 | + $enum = "(\s*\([^\)]*\))?"; |
|
| 544 | 543 | |
| 545 | - $remplace = array( |
|
| 546 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 547 | - ); |
|
| 544 | + $remplace = array( |
|
| 545 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 546 | + ); |
|
| 548 | 547 | |
| 549 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 550 | - return $query; |
|
| 548 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 549 | + return $query; |
|
| 551 | 550 | } |
| 552 | 551 | |
| 553 | 552 | /** |
@@ -557,7 +556,7 @@ discard block |
||
| 557 | 556 | * @return array|null|resource|string |
| 558 | 557 | */ |
| 559 | 558 | function spip_mysql_create_base($nom, $serveur='',$requeter=true) { |
| 560 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 559 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 561 | 560 | } |
| 562 | 561 | |
| 563 | 562 | // Fonction de creation d'une vue SQL nommee $nom |
@@ -570,15 +569,15 @@ discard block |
||
| 570 | 569 | * @return array|bool|null|resource|string |
| 571 | 570 | */ |
| 572 | 571 | function spip_mysql_create_view($nom, $query_select, $serveur='',$requeter=true) { |
| 573 | - if (!$query_select) return false; |
|
| 574 | - // vue deja presente |
|
| 575 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 576 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 577 | - return false; |
|
| 578 | - } |
|
| 572 | + if (!$query_select) return false; |
|
| 573 | + // vue deja presente |
|
| 574 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 575 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 576 | + return false; |
|
| 577 | + } |
|
| 579 | 578 | |
| 580 | - $query = "CREATE VIEW $nom AS ". $query_select; |
|
| 581 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 579 | + $query = "CREATE VIEW $nom AS ". $query_select; |
|
| 580 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 582 | 581 | } |
| 583 | 582 | |
| 584 | 583 | |
@@ -592,8 +591,8 @@ discard block |
||
| 592 | 591 | */ |
| 593 | 592 | function spip_mysql_drop_table($table, $exist='', $serveur='',$requeter=true) |
| 594 | 593 | { |
| 595 | - if ($exist) $exist =" IF EXISTS"; |
|
| 596 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 594 | + if ($exist) $exist =" IF EXISTS"; |
|
| 595 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 597 | 596 | } |
| 598 | 597 | |
| 599 | 598 | // supprime une vue |
@@ -606,8 +605,8 @@ discard block |
||
| 606 | 605 | * @return array|null|resource|string |
| 607 | 606 | */ |
| 608 | 607 | function spip_mysql_drop_view($view, $exist='', $serveur='',$requeter=true) { |
| 609 | - if ($exist) $exist =" IF EXISTS"; |
|
| 610 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 608 | + if ($exist) $exist =" IF EXISTS"; |
|
| 609 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 611 | 610 | } |
| 612 | 611 | |
| 613 | 612 | /** |
@@ -625,7 +624,7 @@ discard block |
||
| 625 | 624 | **/ |
| 626 | 625 | function spip_mysql_showbase($match, $serveur='',$requeter=true) |
| 627 | 626 | { |
| 628 | - return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 627 | + return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 629 | 628 | } |
| 630 | 629 | |
| 631 | 630 | // http://doc.spip.org/@spip_mysql_repair |
@@ -637,7 +636,7 @@ discard block |
||
| 637 | 636 | */ |
| 638 | 637 | function spip_mysql_repair($table, $serveur='',$requeter=true) |
| 639 | 638 | { |
| 640 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 639 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 641 | 640 | } |
| 642 | 641 | |
| 643 | 642 | define('_MYSQL_RE_SHOW_TABLE', '/^[^(),]*\(((?:[^()]*\((?:[^()]*\([^()]*\))?[^()]*\)[^()]*)*[^()]*)\)[^()]*$/'); |
@@ -653,70 +652,70 @@ discard block |
||
| 653 | 652 | */ |
| 654 | 653 | function spip_mysql_showtable($nom_table, $serveur='',$requeter=true) |
| 655 | 654 | { |
| 656 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 657 | - if (!$s) return ''; |
|
| 658 | - if (!$requeter) return $s; |
|
| 659 | - |
|
| 660 | - list(,$a) = mysql_fetch_array($s ,MYSQL_NUM); |
|
| 661 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)){ |
|
| 662 | - $desc = $r[1]; |
|
| 663 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 664 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 665 | - if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 666 | - $namedkeys = $r[2]; |
|
| 667 | - $desc = $r[1]; |
|
| 668 | - } |
|
| 669 | - else |
|
| 670 | - $namedkeys = ""; |
|
| 671 | - |
|
| 672 | - $fields = array(); |
|
| 673 | - foreach(preg_split("/,\s*`/",$desc) as $v) { |
|
| 674 | - preg_match("/^\s*`?([^`]*)`\s*(.*)/",$v,$r); |
|
| 675 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 676 | - } |
|
| 677 | - $keys = array(); |
|
| 678 | - |
|
| 679 | - foreach(preg_split('/\)\s*(,|$)/',$namedkeys) as $v) { |
|
| 680 | - if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/",$v,$r)) { |
|
| 681 | - $k = str_replace("`", '', trim($r[1])); |
|
| 682 | - $t = strtolower(str_replace("`", '', $r[2])); |
|
| 683 | - if ($k && !isset($keys[$k])) $keys[$k] = $t; else $keys[] = $t; |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - spip_mysql_free($s); |
|
| 687 | - return array('field' => $fields, 'key' => $keys); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 691 | - if($res) { |
|
| 692 | - $nfields = array(); |
|
| 693 | - $nkeys = array(); |
|
| 694 | - while($val = spip_mysql_fetch($res)) { |
|
| 695 | - $nfields[$val["Field"]] = $val['Type']; |
|
| 696 | - if($val['Null']=='NO') { |
|
| 697 | - $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 698 | - } |
|
| 699 | - if($val['Default'] === '0' || $val['Default']) { |
|
| 700 | - if(preg_match('/[A-Z_]/',$val['Default'])) { |
|
| 701 | - $nfields[$val["Field"]] .= ' DEFAULT '.$val['Default']; |
|
| 702 | - } else { |
|
| 703 | - $nfields[$val["Field"]] .= " DEFAULT '".$val['Default']."'"; |
|
| 704 | - } |
|
| 705 | - } |
|
| 706 | - if($val['Extra']) |
|
| 707 | - $nfields[$val["Field"]] .= ' '.$val['Extra']; |
|
| 708 | - if($val['Key'] == 'PRI') { |
|
| 709 | - $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 710 | - } else if($val['Key'] == 'MUL') { |
|
| 711 | - $nkeys['KEY '.$val["Field"]] = $val["Field"]; |
|
| 712 | - } else if($val['Key'] == 'UNI') { |
|
| 713 | - $nkeys['UNIQUE KEY '.$val["Field"]] = $val["Field"]; |
|
| 714 | - } |
|
| 715 | - } |
|
| 716 | - spip_mysql_free($res); |
|
| 717 | - return array('field' => $nfields, 'key' => $nkeys); |
|
| 718 | - } |
|
| 719 | - return ""; |
|
| 655 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 656 | + if (!$s) return ''; |
|
| 657 | + if (!$requeter) return $s; |
|
| 658 | + |
|
| 659 | + list(,$a) = mysql_fetch_array($s ,MYSQL_NUM); |
|
| 660 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)){ |
|
| 661 | + $desc = $r[1]; |
|
| 662 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 663 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 664 | + if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 665 | + $namedkeys = $r[2]; |
|
| 666 | + $desc = $r[1]; |
|
| 667 | + } |
|
| 668 | + else |
|
| 669 | + $namedkeys = ""; |
|
| 670 | + |
|
| 671 | + $fields = array(); |
|
| 672 | + foreach(preg_split("/,\s*`/",$desc) as $v) { |
|
| 673 | + preg_match("/^\s*`?([^`]*)`\s*(.*)/",$v,$r); |
|
| 674 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 675 | + } |
|
| 676 | + $keys = array(); |
|
| 677 | + |
|
| 678 | + foreach(preg_split('/\)\s*(,|$)/',$namedkeys) as $v) { |
|
| 679 | + if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/",$v,$r)) { |
|
| 680 | + $k = str_replace("`", '', trim($r[1])); |
|
| 681 | + $t = strtolower(str_replace("`", '', $r[2])); |
|
| 682 | + if ($k && !isset($keys[$k])) $keys[$k] = $t; else $keys[] = $t; |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + spip_mysql_free($s); |
|
| 686 | + return array('field' => $fields, 'key' => $keys); |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 690 | + if($res) { |
|
| 691 | + $nfields = array(); |
|
| 692 | + $nkeys = array(); |
|
| 693 | + while($val = spip_mysql_fetch($res)) { |
|
| 694 | + $nfields[$val["Field"]] = $val['Type']; |
|
| 695 | + if($val['Null']=='NO') { |
|
| 696 | + $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 697 | + } |
|
| 698 | + if($val['Default'] === '0' || $val['Default']) { |
|
| 699 | + if(preg_match('/[A-Z_]/',$val['Default'])) { |
|
| 700 | + $nfields[$val["Field"]] .= ' DEFAULT '.$val['Default']; |
|
| 701 | + } else { |
|
| 702 | + $nfields[$val["Field"]] .= " DEFAULT '".$val['Default']."'"; |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | + if($val['Extra']) |
|
| 706 | + $nfields[$val["Field"]] .= ' '.$val['Extra']; |
|
| 707 | + if($val['Key'] == 'PRI') { |
|
| 708 | + $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 709 | + } else if($val['Key'] == 'MUL') { |
|
| 710 | + $nkeys['KEY '.$val["Field"]] = $val["Field"]; |
|
| 711 | + } else if($val['Key'] == 'UNI') { |
|
| 712 | + $nkeys['UNIQUE KEY '.$val["Field"]] = $val["Field"]; |
|
| 713 | + } |
|
| 714 | + } |
|
| 715 | + spip_mysql_free($res); |
|
| 716 | + return array('field' => $nfields, 'key' => $nkeys); |
|
| 717 | + } |
|
| 718 | + return ""; |
|
| 720 | 719 | } |
| 721 | 720 | |
| 722 | 721 | // |
@@ -732,18 +731,17 @@ discard block |
||
| 732 | 731 | * @return array |
| 733 | 732 | */ |
| 734 | 733 | function spip_mysql_fetch($r, $t='', $serveur='',$requeter=true) { |
| 735 | - if (!$t) $t = MYSQL_ASSOC; |
|
| 736 | - if ($r) return mysql_fetch_array($r, $t); |
|
| 734 | + if (!$t) $t = MYSQL_ASSOC; |
|
| 735 | + if ($r) return mysql_fetch_array($r, $t); |
|
| 737 | 736 | } |
| 738 | 737 | |
| 739 | 738 | function spip_mysql_seek($r, $row_number, $serveur='',$requeter=true) { |
| 740 | - if ($r and mysql_num_rows($r)) return mysql_data_seek($r,$row_number); |
|
| 739 | + if ($r and mysql_num_rows($r)) return mysql_data_seek($r,$row_number); |
|
| 741 | 740 | } |
| 742 | 741 | |
| 743 | 742 | |
| 744 | 743 | // http://doc.spip.org/@spip_mysql_countsel |
| 745 | 744 | /** |
| 746 | - |
|
| 747 | 745 | * @param array $from |
| 748 | 746 | * @param array $where |
| 749 | 747 | * @param string $groupby |
@@ -754,17 +752,17 @@ discard block |
||
| 754 | 752 | * |
| 755 | 753 | */ |
| 756 | 754 | function spip_mysql_countsel($from = array(), $where = array(), |
| 757 | - $groupby = '', $having = array(), $serveur='',$requeter=true) |
|
| 755 | + $groupby = '', $having = array(), $serveur='',$requeter=true) |
|
| 758 | 756 | { |
| 759 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 757 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 760 | 758 | |
| 761 | - $r = spip_mysql_select("COUNT($c)", $from, $where,'', '', '', $having, $serveur, $requeter); |
|
| 759 | + $r = spip_mysql_select("COUNT($c)", $from, $where,'', '', '', $having, $serveur, $requeter); |
|
| 762 | 760 | |
| 763 | - if (!$requeter) return $r; |
|
| 764 | - if (!is_resource($r)) return 0; |
|
| 765 | - list($c) = mysql_fetch_array($r, MYSQL_NUM); |
|
| 766 | - mysql_free_result($r); |
|
| 767 | - return $c; |
|
| 761 | + if (!$requeter) return $r; |
|
| 762 | + if (!is_resource($r)) return 0; |
|
| 763 | + list($c) = mysql_fetch_array($r, MYSQL_NUM); |
|
| 764 | + mysql_free_result($r); |
|
| 765 | + return $c; |
|
| 768 | 766 | } |
| 769 | 767 | |
| 770 | 768 | // Bien specifier le serveur auquel on s'adresse, |
@@ -777,10 +775,10 @@ discard block |
||
| 777 | 775 | * @return string |
| 778 | 776 | */ |
| 779 | 777 | function spip_mysql_error($query='', $serveur='',$requeter=true) { |
| 780 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 781 | - $s = $link ? mysql_error($link) : mysql_error(); |
|
| 782 | - if ($s) spip_log("$s - $query", 'mysql.'._LOG_ERREUR); |
|
| 783 | - return $s; |
|
| 778 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 779 | + $s = $link ? mysql_error($link) : mysql_error(); |
|
| 780 | + if ($s) spip_log("$s - $query", 'mysql.'._LOG_ERREUR); |
|
| 781 | + return $s; |
|
| 784 | 782 | } |
| 785 | 783 | |
| 786 | 784 | // A transposer dans les portages |
@@ -791,14 +789,14 @@ discard block |
||
| 791 | 789 | * @return int |
| 792 | 790 | */ |
| 793 | 791 | function spip_mysql_errno($serveur='',$requeter=true) { |
| 794 | - $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 795 | - $s = $link ? mysql_errno($link) : mysql_errno(); |
|
| 796 | - // 2006 MySQL server has gone away |
|
| 797 | - // 2013 Lost connection to MySQL server during query |
|
| 798 | - if (in_array($s, array(2006,2013))) |
|
| 799 | - define('spip_interdire_cache', true); |
|
| 800 | - if ($s) spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 801 | - return $s; |
|
| 792 | + $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 793 | + $s = $link ? mysql_errno($link) : mysql_errno(); |
|
| 794 | + // 2006 MySQL server has gone away |
|
| 795 | + // 2013 Lost connection to MySQL server during query |
|
| 796 | + if (in_array($s, array(2006,2013))) |
|
| 797 | + define('spip_interdire_cache', true); |
|
| 798 | + if ($s) spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 799 | + return $s; |
|
| 802 | 800 | } |
| 803 | 801 | |
| 804 | 802 | // Interface de abstract_sql |
@@ -810,7 +808,7 @@ discard block |
||
| 810 | 808 | * @return int |
| 811 | 809 | */ |
| 812 | 810 | function spip_mysql_count($r, $serveur='',$requeter=true) { |
| 813 | - if ($r) return mysql_num_rows($r); |
|
| 811 | + if ($r) return mysql_num_rows($r); |
|
| 814 | 812 | } |
| 815 | 813 | |
| 816 | 814 | |
@@ -822,7 +820,7 @@ discard block |
||
| 822 | 820 | * @return bool |
| 823 | 821 | */ |
| 824 | 822 | function spip_mysql_free($r, $serveur='',$requeter=true) { |
| 825 | - return (is_resource($r)?mysql_free_result($r):false); |
|
| 823 | + return (is_resource($r)?mysql_free_result($r):false); |
|
| 826 | 824 | } |
| 827 | 825 | |
| 828 | 826 | // http://doc.spip.org/@spip_mysql_insert |
@@ -837,32 +835,32 @@ discard block |
||
| 837 | 835 | */ |
| 838 | 836 | function spip_mysql_insert($table, $champs, $valeurs, $desc='', $serveur='',$requeter=true) { |
| 839 | 837 | |
| 840 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 841 | - $prefixe = $connexion['prefixe']; |
|
| 842 | - $link = $connexion['link']; |
|
| 843 | - $db = $connexion['db']; |
|
| 838 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 839 | + $prefixe = $connexion['prefixe']; |
|
| 840 | + $link = $connexion['link']; |
|
| 841 | + $db = $connexion['db']; |
|
| 844 | 842 | |
| 845 | - if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 843 | + if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 846 | 844 | |
| 847 | - $query ="INSERT INTO $table $champs VALUES $valeurs"; |
|
| 848 | - if (!$requeter) return $query; |
|
| 845 | + $query ="INSERT INTO $table $champs VALUES $valeurs"; |
|
| 846 | + if (!$requeter) return $query; |
|
| 849 | 847 | |
| 850 | - if (isset($_GET['var_profile'])) { |
|
| 851 | - include_spip('public/tracer'); |
|
| 852 | - $t = trace_query_start(); |
|
| 853 | - } else $t = 0 ; |
|
| 854 | - |
|
| 855 | - $connexion['last'] = $query; |
|
| 856 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 857 | - if (mysql_query($query, $link)) |
|
| 858 | - $r = mysql_insert_id($link); |
|
| 859 | - else { |
|
| 860 | - if ($e = spip_mysql_errno($serveur)) // Log de l'erreur eventuelle |
|
| 861 | - $e .= spip_mysql_error($query, $serveur); // et du fautif |
|
| 862 | - } |
|
| 863 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 864 | - |
|
| 865 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 848 | + if (isset($_GET['var_profile'])) { |
|
| 849 | + include_spip('public/tracer'); |
|
| 850 | + $t = trace_query_start(); |
|
| 851 | + } else $t = 0 ; |
|
| 852 | + |
|
| 853 | + $connexion['last'] = $query; |
|
| 854 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 855 | + if (mysql_query($query, $link)) |
|
| 856 | + $r = mysql_insert_id($link); |
|
| 857 | + else { |
|
| 858 | + if ($e = spip_mysql_errno($serveur)) // Log de l'erreur eventuelle |
|
| 859 | + $e .= spip_mysql_error($query, $serveur); // et du fautif |
|
| 860 | + } |
|
| 861 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 862 | + |
|
| 863 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 866 | 864 | } |
| 867 | 865 | |
| 868 | 866 | // http://doc.spip.org/@spip_mysql_insertq |
@@ -876,15 +874,15 @@ discard block |
||
| 876 | 874 | */ |
| 877 | 875 | function spip_mysql_insertq($table, $couples=array(), $desc=array(), $serveur='',$requeter=true) { |
| 878 | 876 | |
| 879 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 880 | - if (!$desc) $couples = array(); |
|
| 881 | - $fields = isset($desc['field'])?$desc['field']:array(); |
|
| 877 | + if (!$desc) $desc = description_table($table, $serveur); |
|
| 878 | + if (!$desc) $couples = array(); |
|
| 879 | + $fields = isset($desc['field'])?$desc['field']:array(); |
|
| 882 | 880 | |
| 883 | - foreach ($couples as $champ => $val) { |
|
| 884 | - $couples[$champ]= spip_mysql_cite($val, $fields[$champ]); |
|
| 885 | - } |
|
| 881 | + foreach ($couples as $champ => $val) { |
|
| 882 | + $couples[$champ]= spip_mysql_cite($val, $fields[$champ]); |
|
| 883 | + } |
|
| 886 | 884 | |
| 887 | - return spip_mysql_insert($table, "(".join(',',array_keys($couples)).")", "(".join(',', $couples).")", $desc, $serveur, $requeter); |
|
| 885 | + return spip_mysql_insert($table, "(".join(',',array_keys($couples)).")", "(".join(',', $couples).")", $desc, $serveur, $requeter); |
|
| 888 | 886 | } |
| 889 | 887 | |
| 890 | 888 | |
@@ -899,29 +897,29 @@ discard block |
||
| 899 | 897 | */ |
| 900 | 898 | function spip_mysql_insertq_multi($table, $tab_couples=array(), $desc=array(), $serveur='',$requeter=true) { |
| 901 | 899 | |
| 902 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 903 | - if (!$desc) $tab_couples = array(); |
|
| 904 | - $fields = isset($desc['field'])?$desc['field']:array(); |
|
| 900 | + if (!$desc) $desc = description_table($table, $serveur); |
|
| 901 | + if (!$desc) $tab_couples = array(); |
|
| 902 | + $fields = isset($desc['field'])?$desc['field']:array(); |
|
| 905 | 903 | |
| 906 | - $cles = "(" . join(',',array_keys(reset($tab_couples))) . ')'; |
|
| 907 | - $valeurs = array(); |
|
| 908 | - $r = false; |
|
| 909 | - |
|
| 910 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 911 | - foreach ($tab_couples as $couples) { |
|
| 912 | - foreach ($couples as $champ => $val){ |
|
| 913 | - $couples[$champ]= spip_mysql_cite($val, $fields[$champ]); |
|
| 914 | - } |
|
| 915 | - $valeurs[] = '(' .join(',', $couples) . ')'; |
|
| 916 | - if (count($valeurs)>=100){ |
|
| 917 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 918 | - $valeurs = array(); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - if (count($valeurs)) |
|
| 922 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 923 | - |
|
| 924 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 904 | + $cles = "(" . join(',',array_keys(reset($tab_couples))) . ')'; |
|
| 905 | + $valeurs = array(); |
|
| 906 | + $r = false; |
|
| 907 | + |
|
| 908 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 909 | + foreach ($tab_couples as $couples) { |
|
| 910 | + foreach ($couples as $champ => $val){ |
|
| 911 | + $couples[$champ]= spip_mysql_cite($val, $fields[$champ]); |
|
| 912 | + } |
|
| 913 | + $valeurs[] = '(' .join(',', $couples) . ')'; |
|
| 914 | + if (count($valeurs)>=100){ |
|
| 915 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 916 | + $valeurs = array(); |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | + if (count($valeurs)) |
|
| 920 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 921 | + |
|
| 922 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 925 | 923 | } |
| 926 | 924 | |
| 927 | 925 | // http://doc.spip.org/@spip_mysql_update |
@@ -935,15 +933,15 @@ discard block |
||
| 935 | 933 | * @return array|null|resource|string |
| 936 | 934 | */ |
| 937 | 935 | function spip_mysql_update($table, $champs, $where='', $desc='', $serveur='',$requeter=true) { |
| 938 | - $set = array(); |
|
| 939 | - foreach ($champs as $champ => $val) |
|
| 940 | - $set[] = $champ . "=$val"; |
|
| 941 | - if (!empty($set)) |
|
| 942 | - return spip_mysql_query( |
|
| 943 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 944 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 945 | - . calculer_mysql_expression('WHERE', $where), |
|
| 946 | - $serveur, $requeter); |
|
| 936 | + $set = array(); |
|
| 937 | + foreach ($champs as $champ => $val) |
|
| 938 | + $set[] = $champ . "=$val"; |
|
| 939 | + if (!empty($set)) |
|
| 940 | + return spip_mysql_query( |
|
| 941 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 942 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 943 | + . calculer_mysql_expression('WHERE', $where), |
|
| 944 | + $serveur, $requeter); |
|
| 947 | 945 | } |
| 948 | 946 | |
| 949 | 947 | // idem, mais les valeurs sont des constantes a mettre entre apostrophes |
@@ -960,18 +958,18 @@ discard block |
||
| 960 | 958 | */ |
| 961 | 959 | function spip_mysql_updateq($table, $champs, $where='', $desc=array(), $serveur='',$requeter=true) { |
| 962 | 960 | |
| 963 | - if (!$champs) return; |
|
| 964 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 965 | - if (!$desc) $champs = array(); else $fields = $desc['field']; |
|
| 966 | - $set = array(); |
|
| 967 | - foreach ($champs as $champ => $val) { |
|
| 968 | - $set[] = $champ . '=' . spip_mysql_cite($val, $fields[$champ]); |
|
| 969 | - } |
|
| 970 | - return spip_mysql_query( |
|
| 971 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 972 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 973 | - . calculer_mysql_expression('WHERE', $where), |
|
| 974 | - $serveur, $requeter); |
|
| 961 | + if (!$champs) return; |
|
| 962 | + if (!$desc) $desc = description_table($table, $serveur); |
|
| 963 | + if (!$desc) $champs = array(); else $fields = $desc['field']; |
|
| 964 | + $set = array(); |
|
| 965 | + foreach ($champs as $champ => $val) { |
|
| 966 | + $set[] = $champ . '=' . spip_mysql_cite($val, $fields[$champ]); |
|
| 967 | + } |
|
| 968 | + return spip_mysql_query( |
|
| 969 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 970 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 971 | + . calculer_mysql_expression('WHERE', $where), |
|
| 972 | + $serveur, $requeter); |
|
| 975 | 973 | } |
| 976 | 974 | |
| 977 | 975 | // http://doc.spip.org/@spip_mysql_delete |
@@ -983,18 +981,18 @@ discard block |
||
| 983 | 981 | * @return array|bool|int|null|resource|string |
| 984 | 982 | */ |
| 985 | 983 | function spip_mysql_delete($table, $where='', $serveur='',$requeter=true) { |
| 986 | - $res = spip_mysql_query( |
|
| 987 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 988 | - . calculer_mysql_expression('WHERE', $where), |
|
| 989 | - $serveur, $requeter); |
|
| 990 | - if (!$requeter) return $res; |
|
| 991 | - if ($res){ |
|
| 992 | - $connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 993 | - $link = $connexion['link']; |
|
| 994 | - return $link ? mysql_affected_rows($link) : mysql_affected_rows(); |
|
| 995 | - } |
|
| 996 | - else |
|
| 997 | - return false; |
|
| 984 | + $res = spip_mysql_query( |
|
| 985 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 986 | + . calculer_mysql_expression('WHERE', $where), |
|
| 987 | + $serveur, $requeter); |
|
| 988 | + if (!$requeter) return $res; |
|
| 989 | + if ($res){ |
|
| 990 | + $connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 991 | + $link = $connexion['link']; |
|
| 992 | + return $link ? mysql_affected_rows($link) : mysql_affected_rows(); |
|
| 993 | + } |
|
| 994 | + else |
|
| 995 | + return false; |
|
| 998 | 996 | } |
| 999 | 997 | |
| 1000 | 998 | // http://doc.spip.org/@spip_mysql_replace |
@@ -1007,7 +1005,7 @@ discard block |
||
| 1007 | 1005 | * @return array|null|resource|string |
| 1008 | 1006 | */ |
| 1009 | 1007 | function spip_mysql_replace($table, $couples, $desc=array(), $serveur='',$requeter=true) { |
| 1010 | - return spip_mysql_query("REPLACE $table (" . join(',',array_keys($couples)) . ') VALUES (' .join(',',array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1008 | + return spip_mysql_query("REPLACE $table (" . join(',',array_keys($couples)) . ') VALUES (' .join(',',array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1011 | 1009 | } |
| 1012 | 1010 | |
| 1013 | 1011 | |
@@ -1021,19 +1019,18 @@ discard block |
||
| 1021 | 1019 | * @return array|null|resource|string |
| 1022 | 1020 | */ |
| 1023 | 1021 | function spip_mysql_replace_multi($table, $tab_couples, $desc=array(), $serveur='',$requeter=true) { |
| 1024 | - $cles = "(" . join(',',array_keys($tab_couples[0])). ')'; |
|
| 1025 | - $valeurs = array(); |
|
| 1026 | - foreach ($tab_couples as $couples) { |
|
| 1027 | - $valeurs[] = '(' .join(',',array_map('_q', $couples)) . ')'; |
|
| 1028 | - } |
|
| 1029 | - $valeurs = implode(', ',$valeurs); |
|
| 1030 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1022 | + $cles = "(" . join(',',array_keys($tab_couples[0])). ')'; |
|
| 1023 | + $valeurs = array(); |
|
| 1024 | + foreach ($tab_couples as $couples) { |
|
| 1025 | + $valeurs[] = '(' .join(',',array_map('_q', $couples)) . ')'; |
|
| 1026 | + } |
|
| 1027 | + $valeurs = implode(', ',$valeurs); |
|
| 1028 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1031 | 1029 | } |
| 1032 | 1030 | |
| 1033 | 1031 | |
| 1034 | 1032 | // http://doc.spip.org/@spip_mysql_multi |
| 1035 | 1033 | /** |
| 1036 | - |
|
| 1037 | 1034 | * @param $objet |
| 1038 | 1035 | * @param $lang |
| 1039 | 1036 | * @return string |
@@ -1041,32 +1038,32 @@ discard block |
||
| 1041 | 1038 | */ |
| 1042 | 1039 | |
| 1043 | 1040 | function spip_mysql_multi ($objet, $lang) { |
| 1044 | - $lengthlang = strlen("[$lang]"); |
|
| 1045 | - $posmulti = "INSTR(".$objet.", '<multi>')"; |
|
| 1046 | - $posfinmulti = "INSTR(".$objet.", '</multi>')"; |
|
| 1047 | - $debutchaine = "LEFT(".$objet.", $posmulti-1)"; |
|
| 1048 | - $finchaine = "RIGHT(".$objet.", CHAR_LENGTH(".$objet.") -(7+$posfinmulti))"; |
|
| 1049 | - $chainemulti = "TRIM(SUBSTRING(".$objet.", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1050 | - $poslang = "INSTR($chainemulti,'[".$lang."]')"; |
|
| 1051 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1052 | - $chainelang = "TRIM(SUBSTRING(".$objet.", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1053 | - $posfinlang = "INSTR(".$chainelang.", '[')"; |
|
| 1054 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1055 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1056 | - $retour = "(TRIM(IF($posmulti = 0 , ". |
|
| 1057 | - " TRIM(".$objet."), ". |
|
| 1058 | - " CONCAT( ". |
|
| 1059 | - " $debutchaine, ". |
|
| 1060 | - " IF( ". |
|
| 1061 | - " $poslang = 0, ". |
|
| 1062 | - " $chainemulti, ". |
|
| 1063 | - " $chainelang". |
|
| 1064 | - " ), ". |
|
| 1065 | - " $finchaine". |
|
| 1066 | - " ) ". |
|
| 1067 | - "))) AS multi"; |
|
| 1068 | - |
|
| 1069 | - return $retour; |
|
| 1041 | + $lengthlang = strlen("[$lang]"); |
|
| 1042 | + $posmulti = "INSTR(".$objet.", '<multi>')"; |
|
| 1043 | + $posfinmulti = "INSTR(".$objet.", '</multi>')"; |
|
| 1044 | + $debutchaine = "LEFT(".$objet.", $posmulti-1)"; |
|
| 1045 | + $finchaine = "RIGHT(".$objet.", CHAR_LENGTH(".$objet.") -(7+$posfinmulti))"; |
|
| 1046 | + $chainemulti = "TRIM(SUBSTRING(".$objet.", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1047 | + $poslang = "INSTR($chainemulti,'[".$lang."]')"; |
|
| 1048 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1049 | + $chainelang = "TRIM(SUBSTRING(".$objet.", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1050 | + $posfinlang = "INSTR(".$chainelang.", '[')"; |
|
| 1051 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1052 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1053 | + $retour = "(TRIM(IF($posmulti = 0 , ". |
|
| 1054 | + " TRIM(".$objet."), ". |
|
| 1055 | + " CONCAT( ". |
|
| 1056 | + " $debutchaine, ". |
|
| 1057 | + " IF( ". |
|
| 1058 | + " $poslang = 0, ". |
|
| 1059 | + " $chainemulti, ". |
|
| 1060 | + " $chainelang". |
|
| 1061 | + " ), ". |
|
| 1062 | + " $finchaine". |
|
| 1063 | + " ) ". |
|
| 1064 | + "))) AS multi"; |
|
| 1065 | + |
|
| 1066 | + return $retour; |
|
| 1070 | 1067 | } |
| 1071 | 1068 | |
| 1072 | 1069 | // http://doc.spip.org/@spip_mysql_hex |
@@ -1076,7 +1073,7 @@ discard block |
||
| 1076 | 1073 | */ |
| 1077 | 1074 | function spip_mysql_hex($v) |
| 1078 | 1075 | { |
| 1079 | - return "0x" . $v; |
|
| 1076 | + return "0x" . $v; |
|
| 1080 | 1077 | } |
| 1081 | 1078 | |
| 1082 | 1079 | /** |
@@ -1085,18 +1082,18 @@ discard block |
||
| 1085 | 1082 | * @return array|int|string |
| 1086 | 1083 | */ |
| 1087 | 1084 | function spip_mysql_quote($v, $type='') { |
| 1088 | - if ($type) { |
|
| 1089 | - if (!is_array($v)) |
|
| 1090 | - return spip_mysql_cite($v,$type); |
|
| 1091 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1092 | - foreach($v as $k=>$r) |
|
| 1093 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1094 | - return $v; |
|
| 1095 | - } |
|
| 1096 | - // si on ne connait pas le type, s'en remettre a _q : |
|
| 1097 | - // on ne fera pas mieux |
|
| 1098 | - else |
|
| 1099 | - return _q($v); |
|
| 1085 | + if ($type) { |
|
| 1086 | + if (!is_array($v)) |
|
| 1087 | + return spip_mysql_cite($v,$type); |
|
| 1088 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1089 | + foreach($v as $k=>$r) |
|
| 1090 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1091 | + return $v; |
|
| 1092 | + } |
|
| 1093 | + // si on ne connait pas le type, s'en remettre a _q : |
|
| 1094 | + // on ne fera pas mieux |
|
| 1095 | + else |
|
| 1096 | + return _q($v); |
|
| 1100 | 1097 | } |
| 1101 | 1098 | |
| 1102 | 1099 | /** |
@@ -1107,17 +1104,17 @@ discard block |
||
| 1107 | 1104 | */ |
| 1108 | 1105 | function spip_mysql_date_proche($champ, $interval, $unite) |
| 1109 | 1106 | { |
| 1110 | - return '(' |
|
| 1111 | - . $champ |
|
| 1107 | + return '(' |
|
| 1108 | + . $champ |
|
| 1112 | 1109 | . (($interval <= 0) ? '>' : '<') |
| 1113 | 1110 | . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
| 1114 | - . '(' |
|
| 1115 | - . sql_quote(date('Y-m-d H:i:s')) |
|
| 1116 | - . ', INTERVAL ' |
|
| 1117 | - . (($interval > 0) ? $interval : (0-$interval)) |
|
| 1118 | - . ' ' |
|
| 1119 | - . $unite |
|
| 1120 | - . '))'; |
|
| 1111 | + . '(' |
|
| 1112 | + . sql_quote(date('Y-m-d H:i:s')) |
|
| 1113 | + . ', INTERVAL ' |
|
| 1114 | + . (($interval > 0) ? $interval : (0-$interval)) |
|
| 1115 | + . ' ' |
|
| 1116 | + . $unite |
|
| 1117 | + . '))'; |
|
| 1121 | 1118 | } |
| 1122 | 1119 | |
| 1123 | 1120 | // |
@@ -1133,21 +1130,21 @@ discard block |
||
| 1133 | 1130 | * @return string |
| 1134 | 1131 | */ |
| 1135 | 1132 | function spip_mysql_in($val, $valeurs, $not='', $serveur='',$requeter=true) { |
| 1136 | - $n = $i = 0; |
|
| 1137 | - $in_sql =""; |
|
| 1138 | - while ($n = strpos($valeurs, ',', $n+1)) { |
|
| 1139 | - if ((++$i) >= 255) { |
|
| 1140 | - $in_sql .= "($val $not IN (" . |
|
| 1141 | - substr($valeurs, 0, $n) . |
|
| 1142 | - "))\n" . |
|
| 1143 | - ($not ? "AND\t" : "OR\t"); |
|
| 1144 | - $valeurs = substr($valeurs, $n+1); |
|
| 1145 | - $i = $n = 0; |
|
| 1146 | - } |
|
| 1147 | - } |
|
| 1148 | - $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1149 | - |
|
| 1150 | - return "($in_sql)"; |
|
| 1133 | + $n = $i = 0; |
|
| 1134 | + $in_sql =""; |
|
| 1135 | + while ($n = strpos($valeurs, ',', $n+1)) { |
|
| 1136 | + if ((++$i) >= 255) { |
|
| 1137 | + $in_sql .= "($val $not IN (" . |
|
| 1138 | + substr($valeurs, 0, $n) . |
|
| 1139 | + "))\n" . |
|
| 1140 | + ($not ? "AND\t" : "OR\t"); |
|
| 1141 | + $valeurs = substr($valeurs, $n+1); |
|
| 1142 | + $i = $n = 0; |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1146 | + |
|
| 1147 | + return "($in_sql)"; |
|
| 1151 | 1148 | } |
| 1152 | 1149 | |
| 1153 | 1150 | // pour compatibilite. Ne plus utiliser. |
@@ -1159,11 +1156,11 @@ discard block |
||
| 1159 | 1156 | * @return string |
| 1160 | 1157 | */ |
| 1161 | 1158 | function calcul_mysql_in($val, $valeurs, $not='') { |
| 1162 | - if (is_array($valeurs)) |
|
| 1163 | - $valeurs = join(',', array_map('_q', $valeurs)); |
|
| 1164 | - elseif ($valeurs[0]===',') $valeurs = substr($valeurs,1); |
|
| 1165 | - if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1'); |
|
| 1166 | - return spip_mysql_in($val, $valeurs, $not); |
|
| 1159 | + if (is_array($valeurs)) |
|
| 1160 | + $valeurs = join(',', array_map('_q', $valeurs)); |
|
| 1161 | + elseif ($valeurs[0]===',') $valeurs = substr($valeurs,1); |
|
| 1162 | + if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1'); |
|
| 1163 | + return spip_mysql_in($val, $valeurs, $not); |
|
| 1167 | 1164 | } |
| 1168 | 1165 | |
| 1169 | 1166 | // http://doc.spip.org/@spip_mysql_cite |
@@ -1173,19 +1170,19 @@ discard block |
||
| 1173 | 1170 | * @return int|string |
| 1174 | 1171 | */ |
| 1175 | 1172 | function spip_mysql_cite($v, $type) { |
| 1176 | - if(is_null($v) |
|
| 1177 | - AND stripos($type,"NOT NULL")===false) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1178 | - if (sql_test_date($type) AND preg_match('/^\w+\(/', $v)) |
|
| 1179 | - return $v; |
|
| 1180 | - if (sql_test_int($type)) { |
|
| 1181 | - if (is_numeric($v) OR (ctype_xdigit(substr($v,2)) |
|
| 1182 | - AND $v[0]=='0' AND $v[1]=='x')) |
|
| 1183 | - return $v; |
|
| 1184 | - // si pas numerique, forcer le intval |
|
| 1185 | - else |
|
| 1186 | - return intval($v); |
|
| 1187 | - } |
|
| 1188 | - return ("'" . addslashes($v) . "'"); |
|
| 1173 | + if(is_null($v) |
|
| 1174 | + AND stripos($type,"NOT NULL")===false) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1175 | + if (sql_test_date($type) AND preg_match('/^\w+\(/', $v)) |
|
| 1176 | + return $v; |
|
| 1177 | + if (sql_test_int($type)) { |
|
| 1178 | + if (is_numeric($v) OR (ctype_xdigit(substr($v,2)) |
|
| 1179 | + AND $v[0]=='0' AND $v[1]=='x')) |
|
| 1180 | + return $v; |
|
| 1181 | + // si pas numerique, forcer le intval |
|
| 1182 | + else |
|
| 1183 | + return intval($v); |
|
| 1184 | + } |
|
| 1185 | + return ("'" . addslashes($v) . "'"); |
|
| 1189 | 1186 | } |
| 1190 | 1187 | |
| 1191 | 1188 | // Ces deux fonctions n'ont pas d'equivalent exact PostGres |
@@ -1203,17 +1200,17 @@ discard block |
||
| 1203 | 1200 | */ |
| 1204 | 1201 | function spip_get_lock($nom, $timeout = 0) { |
| 1205 | 1202 | |
| 1206 | - define('_LOCK_TIME', intval(time()/3600-316982)); |
|
| 1203 | + define('_LOCK_TIME', intval(time()/3600-316982)); |
|
| 1207 | 1204 | |
| 1208 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1209 | - $bd = $connexion['db']; |
|
| 1210 | - $prefixe = $connexion['prefixe']; |
|
| 1211 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1205 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1206 | + $bd = $connexion['db']; |
|
| 1207 | + $prefixe = $connexion['prefixe']; |
|
| 1208 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1212 | 1209 | |
| 1213 | - $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1214 | - $q = @sql_fetch(mysql_query($q)); |
|
| 1215 | - if (!$q) spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1216 | - return $q['n']; |
|
| 1210 | + $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1211 | + $q = @sql_fetch(mysql_query($q)); |
|
| 1212 | + if (!$q) spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1213 | + return $q['n']; |
|
| 1217 | 1214 | } |
| 1218 | 1215 | |
| 1219 | 1216 | // http://doc.spip.org/@spip_release_lock |
@@ -1222,13 +1219,13 @@ discard block |
||
| 1222 | 1219 | */ |
| 1223 | 1220 | function spip_release_lock($nom) { |
| 1224 | 1221 | |
| 1225 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1226 | - $bd = $connexion['db']; |
|
| 1227 | - $prefixe = $connexion['prefixe']; |
|
| 1228 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1222 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1223 | + $bd = $connexion['db']; |
|
| 1224 | + $prefixe = $connexion['prefixe']; |
|
| 1225 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1229 | 1226 | |
| 1230 | - $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1231 | - @mysql_query($q); |
|
| 1227 | + $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1228 | + @mysql_query($q); |
|
| 1232 | 1229 | } |
| 1233 | 1230 | |
| 1234 | 1231 | // Renvoie false si on n'a pas les fonctions mysql (pour l'install) |
@@ -1237,8 +1234,8 @@ discard block |
||
| 1237 | 1234 | * @return bool |
| 1238 | 1235 | */ |
| 1239 | 1236 | function spip_versions_mysql() { |
| 1240 | - charger_php_extension('mysql'); |
|
| 1241 | - return function_exists('mysql_query'); |
|
| 1237 | + charger_php_extension('mysql'); |
|
| 1238 | + return function_exists('mysql_query'); |
|
| 1242 | 1239 | } |
| 1243 | 1240 | |
| 1244 | 1241 | // Tester si mysql ne veut pas du nom de la base dans les requetes |
@@ -1250,18 +1247,18 @@ discard block |
||
| 1250 | 1247 | */ |
| 1251 | 1248 | function test_rappel_nom_base_mysql($server_db) |
| 1252 | 1249 | { |
| 1253 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1254 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1255 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1256 | - |
|
| 1257 | - if ($ok) { |
|
| 1258 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1259 | - return ''; |
|
| 1260 | - } else { |
|
| 1261 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1262 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; ". |
|
| 1263 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1264 | - } |
|
| 1250 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1251 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1252 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1253 | + |
|
| 1254 | + if ($ok) { |
|
| 1255 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1256 | + return ''; |
|
| 1257 | + } else { |
|
| 1258 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1259 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; ". |
|
| 1260 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1261 | + } |
|
| 1265 | 1262 | } |
| 1266 | 1263 | |
| 1267 | 1264 | // http://doc.spip.org/@test_sql_mode_mysql |
@@ -1270,13 +1267,13 @@ discard block |
||
| 1270 | 1267 | * @return string |
| 1271 | 1268 | */ |
| 1272 | 1269 | function test_sql_mode_mysql($server_db){ |
| 1273 | - $res = sql_select("version() as v",'','','','','','',$server_db); |
|
| 1274 | - $row = sql_fetch($res,$server_db); |
|
| 1275 | - if (version_compare($row['v'],'5.0.0','>=')){ |
|
| 1276 | - define('_MYSQL_SET_SQL_MODE',true); |
|
| 1277 | - return "define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1278 | - } |
|
| 1279 | - return ''; |
|
| 1270 | + $res = sql_select("version() as v",'','','','','','',$server_db); |
|
| 1271 | + $row = sql_fetch($res,$server_db); |
|
| 1272 | + if (version_compare($row['v'],'5.0.0','>=')){ |
|
| 1273 | + define('_MYSQL_SET_SQL_MODE',true); |
|
| 1274 | + return "define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1275 | + } |
|
| 1276 | + return ''; |
|
| 1280 | 1277 | } |
| 1281 | 1278 | |
| 1282 | 1279 | ?> |
@@ -17,7 +17,9 @@ discard block |
||
| 17 | 17 | * @package SPIP\SQL\MySQL |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 20 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 21 | + return; |
|
| 22 | +} |
|
| 21 | 23 | |
| 22 | 24 | // fonction pour la premiere connexion a un serveur MySQL |
| 23 | 25 | |
@@ -33,8 +35,12 @@ discard block |
||
| 33 | 35 | */ |
| 34 | 36 | |
| 35 | 37 | function req_mysql_dist($host, $port, $login, $pass, $db='', $prefixe='') { |
| 36 | - if (!charger_php_extension('mysql')) return false; |
|
| 37 | - if ($port > 0) $host = "$host:$port"; |
|
| 38 | + if (!charger_php_extension('mysql')) { |
|
| 39 | + return false; |
|
| 40 | + } |
|
| 41 | + if ($port > 0) { |
|
| 42 | + $host = "$host:$port"; |
|
| 43 | + } |
|
| 38 | 44 | $link = @mysql_connect($host, $login, $pass, true); |
| 39 | 45 | if (!$link) { |
| 40 | 46 | spip_log('Echec mysql_connect. Erreur : ' . mysql_error(),'mysql.'._LOG_HS); |
@@ -48,8 +54,9 @@ discard block |
||
| 48 | 54 | $ok = spip_mysql_selectdb($db); |
| 49 | 55 | if (defined('_MYSQL_SET_SQL_MODE') |
| 50 | 56 | OR defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
| 51 | - ) |
|
| 52 | - mysql_query($last = "set sql_mode=''"); |
|
| 57 | + ) { |
|
| 58 | + mysql_query($last = "set sql_mode=''"); |
|
| 59 | + } |
|
| 53 | 60 | } |
| 54 | 61 | spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle sur $link" : 'impossible'), _LOG_DEBUG); |
| 55 | 62 | |
@@ -171,12 +178,16 @@ discard block |
||
| 171 | 178 | $query = traite_query($query, $db, $prefixe); |
| 172 | 179 | |
| 173 | 180 | // renvoyer la requete inerte si demandee |
| 174 | - if (!$requeter) return $query; |
|
| 181 | + if (!$requeter) { |
|
| 182 | + return $query; |
|
| 183 | + } |
|
| 175 | 184 | |
| 176 | 185 | if (isset($_GET['var_profile'])) { |
| 177 | 186 | include_spip('public/tracer'); |
| 178 | 187 | $t = trace_query_start(); |
| 179 | - } else $t = 0 ; |
|
| 188 | + } else { |
|
| 189 | + $t = 0 ; |
|
| 190 | + } |
|
| 180 | 191 | |
| 181 | 192 | $connexion['last'] = $query; |
| 182 | 193 | |
@@ -193,8 +204,11 @@ discard block |
||
| 193 | 204 | |
| 194 | 205 | $r = $link ? mysql_query($query.$debug, $link) : mysql_query($query.$debug); |
| 195 | 206 | |
| 196 | - if ($e = spip_mysql_errno($serveur)) // Log de l'erreur eventuelle |
|
| 197 | - $e .= spip_mysql_error($query, $serveur); // et du fautif |
|
| 207 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 208 | + // Log de l'erreur eventuelle |
|
| 209 | + $e .= spip_mysql_error($query, $serveur); |
|
| 210 | + } |
|
| 211 | + // et du fautif |
|
| 198 | 212 | return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
| 199 | 213 | } |
| 200 | 214 | |
@@ -233,7 +247,9 @@ discard block |
||
| 233 | 247 | * @return array |
| 234 | 248 | */ |
| 235 | 249 | function spip_mysql_explain($query, $serveur='',$requeter=true){ |
| 236 | - if (strpos(ltrim($query), 'SELECT') !== 0) return array(); |
|
| 250 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 251 | + return array(); |
|
| 252 | + } |
|
| 237 | 253 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 238 | 254 | $prefixe = $connexion['prefixe']; |
| 239 | 255 | $link = $connexion['link']; |
@@ -277,7 +293,9 @@ discard block |
||
| 277 | 293 | . ($limit ? "\nLIMIT $limit" : ''); |
| 278 | 294 | |
| 279 | 295 | // renvoyer la requete inerte si demandee |
| 280 | - if ($requeter === false) return $query; |
|
| 296 | + if ($requeter === false) { |
|
| 297 | + return $query; |
|
| 298 | + } |
|
| 281 | 299 | $r = spip_mysql_query($query, $serveur, $requeter); |
| 282 | 300 | return $r ? $r : $query; |
| 283 | 301 | } |
@@ -304,13 +322,14 @@ discard block |
||
| 304 | 322 | */ |
| 305 | 323 | function calculer_mysql_where($v) |
| 306 | 324 | { |
| 307 | - if (!is_array($v)) |
|
| 308 | - return $v ; |
|
| 325 | + if (!is_array($v)) { |
|
| 326 | + return $v ; |
|
| 327 | + } |
|
| 309 | 328 | |
| 310 | 329 | $op = array_shift($v); |
| 311 | - if (!($n=count($v))) |
|
| 312 | - return $op; |
|
| 313 | - else { |
|
| 330 | + if (!($n=count($v))) { |
|
| 331 | + return $op; |
|
| 332 | + } else { |
|
| 314 | 333 | $arg = calculer_mysql_where(array_shift($v)); |
| 315 | 334 | if ($n==1) { |
| 316 | 335 | return "$op($arg)"; |
@@ -318,7 +337,9 @@ discard block |
||
| 318 | 337 | $arg2 = calculer_mysql_where(array_shift($v)); |
| 319 | 338 | if ($n==2) { |
| 320 | 339 | return "($arg $op $arg2)"; |
| 321 | - } else return "($arg $op ($arg2) : $v[0])"; |
|
| 340 | + } else { |
|
| 341 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 342 | + } |
|
| 322 | 343 | } |
| 323 | 344 | } |
| 324 | 345 | } |
@@ -331,18 +352,20 @@ discard block |
||
| 331 | 352 | * @return string |
| 332 | 353 | */ |
| 333 | 354 | function calculer_mysql_expression($expression, $v, $join = 'AND'){ |
| 334 | - if (empty($v)) |
|
| 335 | - return ''; |
|
| 355 | + if (empty($v)) { |
|
| 356 | + return ''; |
|
| 357 | + } |
|
| 336 | 358 | |
| 337 | 359 | $exp = "\n$expression "; |
| 338 | 360 | |
| 339 | 361 | if (!is_array($v)) { |
| 340 | 362 | return $exp . $v; |
| 341 | 363 | } else { |
| 342 | - if (strtoupper($join) === 'AND') |
|
| 343 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 344 | - else |
|
| 345 | - return $exp . join($join, $v); |
|
| 364 | + if (strtoupper($join) === 'AND') { |
|
| 365 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 366 | + } else { |
|
| 367 | + return $exp . join($join, $v); |
|
| 368 | + } |
|
| 346 | 369 | } |
| 347 | 370 | } |
| 348 | 371 | |
@@ -359,13 +382,14 @@ discard block |
||
| 359 | 382 | // c'est une jointure qui se refere au from precedent |
| 360 | 383 | // pas de virgule |
| 361 | 384 | $res .= ' ' . $v ; |
| 362 | - } |
|
| 363 | - else { |
|
| 385 | + } else { |
|
| 364 | 386 | if (!is_numeric($k)) { |
| 365 | 387 | $p = strpos($v, " "); |
| 366 | - if ($p) |
|
| 367 | - $v = substr($v,0,$p) . " AS `$k`" . substr($v,$p); |
|
| 368 | - else $v .= " AS `$k`"; |
|
| 388 | + if ($p) { |
|
| 389 | + $v = substr($v,0,$p) . " AS `$k`" . substr($v,$p); |
|
| 390 | + } else { |
|
| 391 | + $v .= " AS `$k`"; |
|
| 392 | + } |
|
| 369 | 393 | } |
| 370 | 394 | |
| 371 | 395 | $res .= ', ' . $v ; |
@@ -389,12 +413,15 @@ discard block |
||
| 389 | 413 | */ |
| 390 | 414 | function traite_query($query, $db='', $prefixe='') { |
| 391 | 415 | |
| 392 | - if ($GLOBALS['mysql_rappel_nom_base'] AND $db) |
|
| 393 | - $pref = '`'. $db.'`.'; |
|
| 394 | - else $pref = ''; |
|
| 416 | + if ($GLOBALS['mysql_rappel_nom_base'] AND $db) { |
|
| 417 | + $pref = '`'. $db.'`.'; |
|
| 418 | + } else { |
|
| 419 | + $pref = ''; |
|
| 420 | + } |
|
| 395 | 421 | |
| 396 | - if ($prefixe) |
|
| 397 | - $pref .= $prefixe . "_"; |
|
| 422 | + if ($prefixe) { |
|
| 423 | + $pref .= $prefixe . "_"; |
|
| 424 | + } |
|
| 398 | 425 | |
| 399 | 426 | if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
| 400 | 427 | $suite =''; |
@@ -406,8 +433,9 @@ discard block |
||
| 406 | 433 | // modifier une requete qui est en fait juste du texte dans un champ |
| 407 | 434 | if (stripos($suite,"SELECT")!==false) { |
| 408 | 435 | list($suite,$textes) = query_echappe_textes($suite); |
| 409 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) |
|
| 410 | - $suite = $r[1] . traite_query($r[2], $db, $prefixe); |
|
| 436 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
|
| 437 | + $suite = $r[1] . traite_query($r[2], $db, $prefixe); |
|
| 438 | + } |
|
| 411 | 439 | $suite = query_reinjecte_textes($suite, $textes); |
| 412 | 440 | } |
| 413 | 441 | } |
@@ -429,8 +457,9 @@ discard block |
||
| 429 | 457 | **/ |
| 430 | 458 | function spip_mysql_selectdb($db) { |
| 431 | 459 | $ok = mysql_select_db($db); |
| 432 | - if (!$ok) |
|
| 433 | - spip_log('Echec mysql_selectdb. Erreur : ' . mysql_error(),'mysql.'._LOG_CRITIQUE); |
|
| 460 | + if (!$ok) { |
|
| 461 | + spip_log('Echec mysql_selectdb. Erreur : ' . mysql_error(),'mysql.'._LOG_CRITIQUE); |
|
| 462 | + } |
|
| 434 | 463 | return $ok; |
| 435 | 464 | } |
| 436 | 465 | |
@@ -453,8 +482,9 @@ discard block |
||
| 453 | 482 | function spip_mysql_listdbs($serveur='',$requeter=true) { |
| 454 | 483 | $dbs = array(); |
| 455 | 484 | if ($res = spip_mysql_query("SHOW DATABASES")){ |
| 456 | - while($row = mysql_fetch_assoc($res)) |
|
| 457 | - $dbs[] = $row['Database']; |
|
| 485 | + while($row = mysql_fetch_assoc($res)) { |
|
| 486 | + $dbs[] = $row['Database']; |
|
| 487 | + } |
|
| 458 | 488 | } |
| 459 | 489 | return $dbs; |
| 460 | 490 | } |
@@ -483,8 +513,9 @@ discard block |
||
| 483 | 513 | |
| 484 | 514 | // certains plugins declarent les tables (permet leur inclusion dans le dump) |
| 485 | 515 | // sans les renseigner (laisse le compilo recuperer la description) |
| 486 | - if (!is_array($champs) || !is_array($cles)) |
|
| 487 | - return; |
|
| 516 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 517 | + return; |
|
| 518 | + } |
|
| 488 | 519 | |
| 489 | 520 | $res = spip_mysql_query("SELECT version() as v"); |
| 490 | 521 | if (($row = mysql_fetch_array($res)) && (version_compare($row['v'],'5.0','>='))) { |
@@ -493,17 +524,20 @@ discard block |
||
| 493 | 524 | |
| 494 | 525 | foreach($cles as $k => $v) { |
| 495 | 526 | $keys .= "$s\n\t\t$k ($v)"; |
| 496 | - if ($k == "PRIMARY KEY") |
|
| 497 | - $p = $v; |
|
| 527 | + if ($k == "PRIMARY KEY") { |
|
| 528 | + $p = $v; |
|
| 529 | + } |
|
| 498 | 530 | $s = ","; |
| 499 | 531 | } |
| 500 | 532 | $s = ''; |
| 501 | 533 | |
| 502 | 534 | $character_set = ""; |
| 503 | - if (@$GLOBALS['meta']['charset_sql_base']) |
|
| 504 | - $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 505 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) |
|
| 506 | - $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 535 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 536 | + $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 537 | + } |
|
| 538 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 539 | + $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 540 | + } |
|
| 507 | 541 | |
| 508 | 542 | foreach($champs as $k => $v) { |
| 509 | 543 | $v = _mysql_remplacements_definitions_table($v); |
@@ -570,7 +604,9 @@ discard block |
||
| 570 | 604 | * @return array|bool|null|resource|string |
| 571 | 605 | */ |
| 572 | 606 | function spip_mysql_create_view($nom, $query_select, $serveur='',$requeter=true) { |
| 573 | - if (!$query_select) return false; |
|
| 607 | + if (!$query_select) { |
|
| 608 | + return false; |
|
| 609 | + } |
|
| 574 | 610 | // vue deja presente |
| 575 | 611 | if (sql_showtable($nom, false, $serveur)) { |
| 576 | 612 | spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
@@ -592,7 +628,9 @@ discard block |
||
| 592 | 628 | */ |
| 593 | 629 | function spip_mysql_drop_table($table, $exist='', $serveur='',$requeter=true) |
| 594 | 630 | { |
| 595 | - if ($exist) $exist =" IF EXISTS"; |
|
| 631 | + if ($exist) { |
|
| 632 | + $exist =" IF EXISTS"; |
|
| 633 | + } |
|
| 596 | 634 | return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
| 597 | 635 | } |
| 598 | 636 | |
@@ -606,7 +644,9 @@ discard block |
||
| 606 | 644 | * @return array|null|resource|string |
| 607 | 645 | */ |
| 608 | 646 | function spip_mysql_drop_view($view, $exist='', $serveur='',$requeter=true) { |
| 609 | - if ($exist) $exist =" IF EXISTS"; |
|
| 647 | + if ($exist) { |
|
| 648 | + $exist =" IF EXISTS"; |
|
| 649 | + } |
|
| 610 | 650 | return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
| 611 | 651 | } |
| 612 | 652 | |
@@ -654,8 +694,12 @@ discard block |
||
| 654 | 694 | function spip_mysql_showtable($nom_table, $serveur='',$requeter=true) |
| 655 | 695 | { |
| 656 | 696 | $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
| 657 | - if (!$s) return ''; |
|
| 658 | - if (!$requeter) return $s; |
|
| 697 | + if (!$s) { |
|
| 698 | + return ''; |
|
| 699 | + } |
|
| 700 | + if (!$requeter) { |
|
| 701 | + return $s; |
|
| 702 | + } |
|
| 659 | 703 | |
| 660 | 704 | list(,$a) = mysql_fetch_array($s ,MYSQL_NUM); |
| 661 | 705 | if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)){ |
@@ -665,9 +709,9 @@ discard block |
||
| 665 | 709 | if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
| 666 | 710 | $namedkeys = $r[2]; |
| 667 | 711 | $desc = $r[1]; |
| 712 | + } else { |
|
| 713 | + $namedkeys = ""; |
|
| 668 | 714 | } |
| 669 | - else |
|
| 670 | - $namedkeys = ""; |
|
| 671 | 715 | |
| 672 | 716 | $fields = array(); |
| 673 | 717 | foreach(preg_split("/,\s*`/",$desc) as $v) { |
@@ -680,7 +724,11 @@ discard block |
||
| 680 | 724 | if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/",$v,$r)) { |
| 681 | 725 | $k = str_replace("`", '', trim($r[1])); |
| 682 | 726 | $t = strtolower(str_replace("`", '', $r[2])); |
| 683 | - if ($k && !isset($keys[$k])) $keys[$k] = $t; else $keys[] = $t; |
|
| 727 | + if ($k && !isset($keys[$k])) { |
|
| 728 | + $keys[$k] = $t; |
|
| 729 | + } else { |
|
| 730 | + $keys[] = $t; |
|
| 731 | + } |
|
| 684 | 732 | } |
| 685 | 733 | } |
| 686 | 734 | spip_mysql_free($s); |
@@ -703,8 +751,9 @@ discard block |
||
| 703 | 751 | $nfields[$val["Field"]] .= " DEFAULT '".$val['Default']."'"; |
| 704 | 752 | } |
| 705 | 753 | } |
| 706 | - if($val['Extra']) |
|
| 707 | - $nfields[$val["Field"]] .= ' '.$val['Extra']; |
|
| 754 | + if($val['Extra']) { |
|
| 755 | + $nfields[$val["Field"]] .= ' '.$val['Extra']; |
|
| 756 | + } |
|
| 708 | 757 | if($val['Key'] == 'PRI') { |
| 709 | 758 | $nkeys['PRIMARY KEY'] = $val["Field"]; |
| 710 | 759 | } else if($val['Key'] == 'MUL') { |
@@ -732,13 +781,19 @@ discard block |
||
| 732 | 781 | * @return array |
| 733 | 782 | */ |
| 734 | 783 | function spip_mysql_fetch($r, $t='', $serveur='',$requeter=true) { |
| 735 | - if (!$t) $t = MYSQL_ASSOC; |
|
| 736 | - if ($r) return mysql_fetch_array($r, $t); |
|
| 737 | -} |
|
| 784 | + if (!$t) { |
|
| 785 | + $t = MYSQL_ASSOC; |
|
| 786 | + } |
|
| 787 | + if ($r) { |
|
| 788 | + return mysql_fetch_array($r, $t); |
|
| 789 | + } |
|
| 790 | + } |
|
| 738 | 791 | |
| 739 | 792 | function spip_mysql_seek($r, $row_number, $serveur='',$requeter=true) { |
| 740 | - if ($r and mysql_num_rows($r)) return mysql_data_seek($r,$row_number); |
|
| 741 | -} |
|
| 793 | + if ($r and mysql_num_rows($r)) { |
|
| 794 | + return mysql_data_seek($r,$row_number); |
|
| 795 | + } |
|
| 796 | + } |
|
| 742 | 797 | |
| 743 | 798 | |
| 744 | 799 | // http://doc.spip.org/@spip_mysql_countsel |
@@ -760,8 +815,12 @@ discard block |
||
| 760 | 815 | |
| 761 | 816 | $r = spip_mysql_select("COUNT($c)", $from, $where,'', '', '', $having, $serveur, $requeter); |
| 762 | 817 | |
| 763 | - if (!$requeter) return $r; |
|
| 764 | - if (!is_resource($r)) return 0; |
|
| 818 | + if (!$requeter) { |
|
| 819 | + return $r; |
|
| 820 | + } |
|
| 821 | + if (!is_resource($r)) { |
|
| 822 | + return 0; |
|
| 823 | + } |
|
| 765 | 824 | list($c) = mysql_fetch_array($r, MYSQL_NUM); |
| 766 | 825 | mysql_free_result($r); |
| 767 | 826 | return $c; |
@@ -779,7 +838,9 @@ discard block |
||
| 779 | 838 | function spip_mysql_error($query='', $serveur='',$requeter=true) { |
| 780 | 839 | $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
| 781 | 840 | $s = $link ? mysql_error($link) : mysql_error(); |
| 782 | - if ($s) spip_log("$s - $query", 'mysql.'._LOG_ERREUR); |
|
| 841 | + if ($s) { |
|
| 842 | + spip_log("$s - $query", 'mysql.'._LOG_ERREUR); |
|
| 843 | + } |
|
| 783 | 844 | return $s; |
| 784 | 845 | } |
| 785 | 846 | |
@@ -795,9 +856,12 @@ discard block |
||
| 795 | 856 | $s = $link ? mysql_errno($link) : mysql_errno(); |
| 796 | 857 | // 2006 MySQL server has gone away |
| 797 | 858 | // 2013 Lost connection to MySQL server during query |
| 798 | - if (in_array($s, array(2006,2013))) |
|
| 799 | - define('spip_interdire_cache', true); |
|
| 800 | - if ($s) spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 859 | + if (in_array($s, array(2006,2013))) { |
|
| 860 | + define('spip_interdire_cache', true); |
|
| 861 | + } |
|
| 862 | + if ($s) { |
|
| 863 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 864 | + } |
|
| 801 | 865 | return $s; |
| 802 | 866 | } |
| 803 | 867 | |
@@ -810,8 +874,10 @@ discard block |
||
| 810 | 874 | * @return int |
| 811 | 875 | */ |
| 812 | 876 | function spip_mysql_count($r, $serveur='',$requeter=true) { |
| 813 | - if ($r) return mysql_num_rows($r); |
|
| 814 | -} |
|
| 877 | + if ($r) { |
|
| 878 | + return mysql_num_rows($r); |
|
| 879 | + } |
|
| 880 | + } |
|
| 815 | 881 | |
| 816 | 882 | |
| 817 | 883 | // http://doc.spip.org/@spip_mysql_free |
@@ -842,23 +908,32 @@ discard block |
||
| 842 | 908 | $link = $connexion['link']; |
| 843 | 909 | $db = $connexion['db']; |
| 844 | 910 | |
| 845 | - if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 911 | + if ($prefixe) { |
|
| 912 | + $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 913 | + } |
|
| 846 | 914 | |
| 847 | 915 | $query ="INSERT INTO $table $champs VALUES $valeurs"; |
| 848 | - if (!$requeter) return $query; |
|
| 916 | + if (!$requeter) { |
|
| 917 | + return $query; |
|
| 918 | + } |
|
| 849 | 919 | |
| 850 | 920 | if (isset($_GET['var_profile'])) { |
| 851 | 921 | include_spip('public/tracer'); |
| 852 | 922 | $t = trace_query_start(); |
| 853 | - } else $t = 0 ; |
|
| 923 | + } else { |
|
| 924 | + $t = 0 ; |
|
| 925 | + } |
|
| 854 | 926 | |
| 855 | 927 | $connexion['last'] = $query; |
| 856 | 928 | #spip_log($query, 'mysql.'._LOG_DEBUG); |
| 857 | - if (mysql_query($query, $link)) |
|
| 858 | - $r = mysql_insert_id($link); |
|
| 859 | - else { |
|
| 860 | - if ($e = spip_mysql_errno($serveur)) // Log de l'erreur eventuelle |
|
| 861 | - $e .= spip_mysql_error($query, $serveur); // et du fautif |
|
| 929 | + if (mysql_query($query, $link)) { |
|
| 930 | + $r = mysql_insert_id($link); |
|
| 931 | + } else { |
|
| 932 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 933 | + // Log de l'erreur eventuelle |
|
| 934 | + $e .= spip_mysql_error($query, $serveur); |
|
| 935 | + } |
|
| 936 | + // et du fautif |
|
| 862 | 937 | } |
| 863 | 938 | return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
| 864 | 939 | |
@@ -876,8 +951,12 @@ discard block |
||
| 876 | 951 | */ |
| 877 | 952 | function spip_mysql_insertq($table, $couples=array(), $desc=array(), $serveur='',$requeter=true) { |
| 878 | 953 | |
| 879 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 880 | - if (!$desc) $couples = array(); |
|
| 954 | + if (!$desc) { |
|
| 955 | + $desc = description_table($table, $serveur); |
|
| 956 | + } |
|
| 957 | + if (!$desc) { |
|
| 958 | + $couples = array(); |
|
| 959 | + } |
|
| 881 | 960 | $fields = isset($desc['field'])?$desc['field']:array(); |
| 882 | 961 | |
| 883 | 962 | foreach ($couples as $champ => $val) { |
@@ -899,8 +978,12 @@ discard block |
||
| 899 | 978 | */ |
| 900 | 979 | function spip_mysql_insertq_multi($table, $tab_couples=array(), $desc=array(), $serveur='',$requeter=true) { |
| 901 | 980 | |
| 902 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 903 | - if (!$desc) $tab_couples = array(); |
|
| 981 | + if (!$desc) { |
|
| 982 | + $desc = description_table($table, $serveur); |
|
| 983 | + } |
|
| 984 | + if (!$desc) { |
|
| 985 | + $tab_couples = array(); |
|
| 986 | + } |
|
| 904 | 987 | $fields = isset($desc['field'])?$desc['field']:array(); |
| 905 | 988 | |
| 906 | 989 | $cles = "(" . join(',',array_keys(reset($tab_couples))) . ')'; |
@@ -918,8 +1001,9 @@ discard block |
||
| 918 | 1001 | $valeurs = array(); |
| 919 | 1002 | } |
| 920 | 1003 | } |
| 921 | - if (count($valeurs)) |
|
| 922 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1004 | + if (count($valeurs)) { |
|
| 1005 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1006 | + } |
|
| 923 | 1007 | |
| 924 | 1008 | return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
| 925 | 1009 | } |
@@ -936,15 +1020,17 @@ discard block |
||
| 936 | 1020 | */ |
| 937 | 1021 | function spip_mysql_update($table, $champs, $where='', $desc='', $serveur='',$requeter=true) { |
| 938 | 1022 | $set = array(); |
| 939 | - foreach ($champs as $champ => $val) |
|
| 940 | - $set[] = $champ . "=$val"; |
|
| 941 | - if (!empty($set)) |
|
| 942 | - return spip_mysql_query( |
|
| 1023 | + foreach ($champs as $champ => $val) { |
|
| 1024 | + $set[] = $champ . "=$val"; |
|
| 1025 | + } |
|
| 1026 | + if (!empty($set)) { |
|
| 1027 | + return spip_mysql_query( |
|
| 943 | 1028 | calculer_mysql_expression('UPDATE', $table, ',') |
| 944 | 1029 | . calculer_mysql_expression('SET', $set, ',') |
| 945 | 1030 | . calculer_mysql_expression('WHERE', $where), |
| 946 | 1031 | $serveur, $requeter); |
| 947 | -} |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 948 | 1034 | |
| 949 | 1035 | // idem, mais les valeurs sont des constantes a mettre entre apostrophes |
| 950 | 1036 | // sauf les expressions de date lorsqu'il s'agit de fonctions SQL (NOW etc) |
@@ -960,9 +1046,17 @@ discard block |
||
| 960 | 1046 | */ |
| 961 | 1047 | function spip_mysql_updateq($table, $champs, $where='', $desc=array(), $serveur='',$requeter=true) { |
| 962 | 1048 | |
| 963 | - if (!$champs) return; |
|
| 964 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 965 | - if (!$desc) $champs = array(); else $fields = $desc['field']; |
|
| 1049 | + if (!$champs) { |
|
| 1050 | + return; |
|
| 1051 | + } |
|
| 1052 | + if (!$desc) { |
|
| 1053 | + $desc = description_table($table, $serveur); |
|
| 1054 | + } |
|
| 1055 | + if (!$desc) { |
|
| 1056 | + $champs = array(); |
|
| 1057 | + } else { |
|
| 1058 | + $fields = $desc['field']; |
|
| 1059 | + } |
|
| 966 | 1060 | $set = array(); |
| 967 | 1061 | foreach ($champs as $champ => $val) { |
| 968 | 1062 | $set[] = $champ . '=' . spip_mysql_cite($val, $fields[$champ]); |
@@ -987,15 +1081,17 @@ discard block |
||
| 987 | 1081 | calculer_mysql_expression('DELETE FROM', $table, ',') |
| 988 | 1082 | . calculer_mysql_expression('WHERE', $where), |
| 989 | 1083 | $serveur, $requeter); |
| 990 | - if (!$requeter) return $res; |
|
| 1084 | + if (!$requeter) { |
|
| 1085 | + return $res; |
|
| 1086 | + } |
|
| 991 | 1087 | if ($res){ |
| 992 | 1088 | $connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0]; |
| 993 | 1089 | $link = $connexion['link']; |
| 994 | 1090 | return $link ? mysql_affected_rows($link) : mysql_affected_rows(); |
| 1091 | + } else { |
|
| 1092 | + return false; |
|
| 1093 | + } |
|
| 995 | 1094 | } |
| 996 | - else |
|
| 997 | - return false; |
|
| 998 | -} |
|
| 999 | 1095 | |
| 1000 | 1096 | // http://doc.spip.org/@spip_mysql_replace |
| 1001 | 1097 | /** |
@@ -1086,18 +1182,21 @@ discard block |
||
| 1086 | 1182 | */ |
| 1087 | 1183 | function spip_mysql_quote($v, $type='') { |
| 1088 | 1184 | if ($type) { |
| 1089 | - if (!is_array($v)) |
|
| 1090 | - return spip_mysql_cite($v,$type); |
|
| 1185 | + if (!is_array($v)) { |
|
| 1186 | + return spip_mysql_cite($v,$type); |
|
| 1187 | + } |
|
| 1091 | 1188 | // si c'est un tableau, le parcourir en propageant le type |
| 1092 | - foreach($v as $k=>$r) |
|
| 1093 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1189 | + foreach($v as $k=>$r) { |
|
| 1190 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1191 | + } |
|
| 1094 | 1192 | return $v; |
| 1095 | 1193 | } |
| 1096 | 1194 | // si on ne connait pas le type, s'en remettre a _q : |
| 1097 | 1195 | // on ne fera pas mieux |
| 1098 | - else |
|
| 1099 | - return _q($v); |
|
| 1100 | -} |
|
| 1196 | + else { |
|
| 1197 | + return _q($v); |
|
| 1198 | + } |
|
| 1199 | + } |
|
| 1101 | 1200 | |
| 1102 | 1201 | /** |
| 1103 | 1202 | * @param $champ |
@@ -1159,10 +1258,14 @@ discard block |
||
| 1159 | 1258 | * @return string |
| 1160 | 1259 | */ |
| 1161 | 1260 | function calcul_mysql_in($val, $valeurs, $not='') { |
| 1162 | - if (is_array($valeurs)) |
|
| 1163 | - $valeurs = join(',', array_map('_q', $valeurs)); |
|
| 1164 | - elseif ($valeurs[0]===',') $valeurs = substr($valeurs,1); |
|
| 1165 | - if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1'); |
|
| 1261 | + if (is_array($valeurs)) { |
|
| 1262 | + $valeurs = join(',', array_map('_q', $valeurs)); |
|
| 1263 | + } elseif ($valeurs[0]===',') { |
|
| 1264 | + $valeurs = substr($valeurs,1); |
|
| 1265 | + } |
|
| 1266 | + if (!strlen(trim($valeurs))) { |
|
| 1267 | + return ($not ? "0=0" : '0=1'); |
|
| 1268 | + } |
|
| 1166 | 1269 | return spip_mysql_in($val, $valeurs, $not); |
| 1167 | 1270 | } |
| 1168 | 1271 | |
@@ -1174,16 +1277,22 @@ discard block |
||
| 1174 | 1277 | */ |
| 1175 | 1278 | function spip_mysql_cite($v, $type) { |
| 1176 | 1279 | if(is_null($v) |
| 1177 | - AND stripos($type,"NOT NULL")===false) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1178 | - if (sql_test_date($type) AND preg_match('/^\w+\(/', $v)) |
|
| 1179 | - return $v; |
|
| 1280 | + AND stripos($type,"NOT NULL")===false) { |
|
| 1281 | + return 'NULL'; |
|
| 1282 | + } |
|
| 1283 | + // null php se traduit en NULL SQL |
|
| 1284 | + if (sql_test_date($type) AND preg_match('/^\w+\(/', $v)) { |
|
| 1285 | + return $v; |
|
| 1286 | + } |
|
| 1180 | 1287 | if (sql_test_int($type)) { |
| 1181 | 1288 | if (is_numeric($v) OR (ctype_xdigit(substr($v,2)) |
| 1182 | - AND $v[0]=='0' AND $v[1]=='x')) |
|
| 1183 | - return $v; |
|
| 1289 | + AND $v[0]=='0' AND $v[1]=='x')) { |
|
| 1290 | + return $v; |
|
| 1291 | + } |
|
| 1184 | 1292 | // si pas numerique, forcer le intval |
| 1185 | - else |
|
| 1186 | - return intval($v); |
|
| 1293 | + else { |
|
| 1294 | + return intval($v); |
|
| 1295 | + } |
|
| 1187 | 1296 | } |
| 1188 | 1297 | return ("'" . addslashes($v) . "'"); |
| 1189 | 1298 | } |
@@ -1212,7 +1321,9 @@ discard block |
||
| 1212 | 1321 | |
| 1213 | 1322 | $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
| 1214 | 1323 | $q = @sql_fetch(mysql_query($q)); |
| 1215 | - if (!$q) spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1324 | + if (!$q) { |
|
| 1325 | + spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1326 | + } |
|
| 1216 | 1327 | return $q['n']; |
| 1217 | 1328 | } |
| 1218 | 1329 | |
@@ -32,12 +32,12 @@ discard block |
||
| 32 | 32 | * @return array|bool |
| 33 | 33 | */ |
| 34 | 34 | |
| 35 | -function req_mysql_dist($host, $port, $login, $pass, $db='', $prefixe='') { |
|
| 35 | +function req_mysql_dist($host, $port, $login, $pass, $db = '', $prefixe = '') { |
|
| 36 | 36 | if (!charger_php_extension('mysql')) return false; |
| 37 | 37 | if ($port > 0) $host = "$host:$port"; |
| 38 | 38 | $link = @mysql_connect($host, $login, $pass, true); |
| 39 | 39 | if (!$link) { |
| 40 | - spip_log('Echec mysql_connect. Erreur : ' . mysql_error(),'mysql.'._LOG_HS); |
|
| 40 | + spip_log('Echec mysql_connect. Erreur : '.mysql_error(), 'mysql.'._LOG_HS); |
|
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | 43 | $last = ''; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | ) |
| 52 | 52 | mysql_query($last = "set sql_mode=''"); |
| 53 | 53 | } |
| 54 | - spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle sur $link" : 'impossible'), _LOG_DEBUG); |
|
| 54 | + spip_log("Connexion vers $host, base $db, prefixe $prefixe ".($ok ? "operationnelle sur $link" : 'impossible'), _LOG_DEBUG); |
|
| 55 | 55 | |
| 56 | 56 | return !$ok ? false : array( |
| 57 | 57 | 'db' => $db, |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | // association de chaque nom http d'un charset aux couples MySQL |
| 104 | 104 | 'charsets' => array( |
| 105 | -'cp1250'=>array('charset'=>'cp1250','collation'=>'cp1250_general_ci'), |
|
| 106 | -'cp1251'=>array('charset'=>'cp1251','collation'=>'cp1251_general_ci'), |
|
| 107 | -'cp1256'=>array('charset'=>'cp1256','collation'=>'cp1256_general_ci'), |
|
| 108 | -'iso-8859-1'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
|
| 105 | +'cp1250'=>array('charset'=>'cp1250', 'collation'=>'cp1250_general_ci'), |
|
| 106 | +'cp1251'=>array('charset'=>'cp1251', 'collation'=>'cp1251_general_ci'), |
|
| 107 | +'cp1256'=>array('charset'=>'cp1256', 'collation'=>'cp1256_general_ci'), |
|
| 108 | +'iso-8859-1'=>array('charset'=>'latin1', 'collation'=>'latin1_swedish_ci'), |
|
| 109 | 109 | //'iso-8859-6'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 110 | -'iso-8859-9'=>array('charset'=>'latin5','collation'=>'latin5_turkish_ci'), |
|
| 110 | +'iso-8859-9'=>array('charset'=>'latin5', 'collation'=>'latin5_turkish_ci'), |
|
| 111 | 111 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 112 | -'utf-8'=>array('charset'=>'utf8','collation'=>'utf8_general_ci')) |
|
| 112 | +'utf-8'=>array('charset'=>'utf8', 'collation'=>'utf8_general_ci')) |
|
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | 115 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param bool $requeter inutilisé |
| 122 | 122 | * @return resource Ressource de résultats pour fetch() |
| 123 | 123 | */ |
| 124 | -function spip_mysql_set_charset($charset, $serveur='',$requeter=true){ |
|
| 124 | +function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
|
| 125 | 125 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 126 | 126 | spip_log("changement de charset sql : "."SET NAMES "._q($charset), _LOG_DEBUG); |
| 127 | 127 | return mysql_query($connexion['last'] = "SET NAMES "._q($charset)); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @param bool $requeter inutilisé |
| 137 | 137 | * @return array Description du charset (son nom est dans 'charset') |
| 138 | 138 | */ |
| 139 | -function spip_mysql_get_charset($charset=array(), $serveur='',$requeter=true){ |
|
| 139 | +function spip_mysql_get_charset($charset = array(), $serveur = '', $requeter = true) { |
|
| 140 | 140 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 141 | 141 | $connexion['last'] = $c = "SHOW CHARACTER SET" |
| 142 | 142 | . (!$charset ? '' : (" LIKE "._q($charset['charset']))); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | // obsolete, ne plus utiliser |
| 148 | 148 | // http://doc.spip.org/@spip_query_db |
| 149 | -function spip_query_db($query, $serveur='',$requeter=true) { |
|
| 149 | +function spip_query_db($query, $serveur = '', $requeter = true) { |
|
| 150 | 150 | return spip_mysql_query($query, $serveur, $requeter); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @return array|null|resource|string |
| 162 | 162 | * |
| 163 | 163 | */ |
| 164 | -function spip_mysql_query($query, $serveur='',$requeter=true) { |
|
| 164 | +function spip_mysql_query($query, $serveur = '', $requeter = true) { |
|
| 165 | 165 | |
| 166 | 166 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 167 | 167 | $prefixe = $connexion['prefixe']; |
@@ -176,19 +176,19 @@ discard block |
||
| 176 | 176 | if (isset($_GET['var_profile'])) { |
| 177 | 177 | include_spip('public/tracer'); |
| 178 | 178 | $t = trace_query_start(); |
| 179 | - } else $t = 0 ; |
|
| 179 | + } else $t = 0; |
|
| 180 | 180 | |
| 181 | 181 | $connexion['last'] = $query; |
| 182 | 182 | |
| 183 | 183 | // ajouter un debug utile dans log/mysql-slow.log ? |
| 184 | 184 | $debug = ''; |
| 185 | - if (defined('_DEBUG_SLOW_QUERIES') AND _DEBUG_SLOW_QUERIES){ |
|
| 186 | - if(isset($GLOBALS['debug']['aucasou'])){ |
|
| 185 | + if (defined('_DEBUG_SLOW_QUERIES') AND _DEBUG_SLOW_QUERIES) { |
|
| 186 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 187 | 187 | list(,$id,, $infos) = $GLOBALS['debug']['aucasou']; |
| 188 | - $debug .= "BOUCLE$id @ ".$infos[0] ." | "; |
|
| 188 | + $debug .= "BOUCLE$id @ ".$infos[0]." | "; |
|
| 189 | 189 | } |
| 190 | 190 | $debug .= $_SERVER['REQUEST_URI'].' + '.$GLOBALS['ip']; |
| 191 | - $debug = ' /* '. mysql_real_escape_string(str_replace('*/','@/',$debug)). ' */'; |
|
| 191 | + $debug = ' /* '.mysql_real_escape_string(str_replace('*/', '@/', $debug)).' */'; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | $r = $link ? mysql_query($query.$debug, $link) : mysql_query($query.$debug); |
@@ -205,11 +205,11 @@ discard block |
||
| 205 | 205 | * @param bool $requeter |
| 206 | 206 | * @return array|null|resource|string |
| 207 | 207 | */ |
| 208 | -function spip_mysql_alter($query, $serveur='',$requeter=true){ |
|
| 208 | +function spip_mysql_alter($query, $serveur = '', $requeter = true) { |
|
| 209 | 209 | // ici on supprime les ` entourant le nom de table pour permettre |
| 210 | 210 | // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
| 211 | 211 | // d'utiliser ceux-ci, copie-colle de phpmyadmin |
| 212 | - $query = preg_replace(",^TABLE\s*`([^`]*)`,i","TABLE \\1",$query); |
|
| 212 | + $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
|
| 213 | 213 | return spip_mysql_query("ALTER ".$query, $serveur, $requeter); # i.e. que PG se debrouille |
| 214 | 214 | } |
| 215 | 215 | |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | * @param bool $requeter |
| 221 | 221 | * @return bool |
| 222 | 222 | */ |
| 223 | -function spip_mysql_optimize($table, $serveur='',$requeter=true){ |
|
| 224 | - spip_mysql_query("OPTIMIZE TABLE ". $table); |
|
| 223 | +function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
|
| 224 | + spip_mysql_query("OPTIMIZE TABLE ".$table); |
|
| 225 | 225 | return true; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | * @param bool $requeter |
| 233 | 233 | * @return array |
| 234 | 234 | */ |
| 235 | -function spip_mysql_explain($query, $serveur='',$requeter=true){ |
|
| 235 | +function spip_mysql_explain($query, $serveur = '', $requeter = true) { |
|
| 236 | 236 | if (strpos(ltrim($query), 'SELECT') !== 0) return array(); |
| 237 | 237 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 238 | 238 | $prefixe = $connexion['prefixe']; |
| 239 | 239 | $link = $connexion['link']; |
| 240 | 240 | $db = $connexion['db']; |
| 241 | 241 | |
| 242 | - $query = 'EXPLAIN ' . traite_query($query, $db, $prefixe); |
|
| 242 | + $query = 'EXPLAIN '.traite_query($query, $db, $prefixe); |
|
| 243 | 243 | $r = $link ? mysql_query($query, $link) : mysql_query($query); |
| 244 | 244 | return spip_mysql_fetch($r, NULL, $serveur); |
| 245 | 245 | } |
@@ -261,9 +261,9 @@ discard block |
||
| 261 | 261 | * @param bool $requeter |
| 262 | 262 | * @return array|null|resource|string |
| 263 | 263 | */ |
| 264 | -function spip_mysql_select($select, $from, $where='', |
|
| 265 | - $groupby='', $orderby='', $limit='', $having='', |
|
| 266 | - $serveur='',$requeter=true) { |
|
| 264 | +function spip_mysql_select($select, $from, $where = '', |
|
| 265 | + $groupby = '', $orderby = '', $limit = '', $having = '', |
|
| 266 | + $serveur = '', $requeter = true) { |
|
| 267 | 267 | |
| 268 | 268 | |
| 269 | 269 | $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | . calculer_mysql_expression('WHERE', $where) |
| 274 | 274 | . calculer_mysql_expression('GROUP BY', $groupby, ',') |
| 275 | 275 | . calculer_mysql_expression('HAVING', $having) |
| 276 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) :'') |
|
| 276 | + . ($orderby ? ("\nORDER BY ".spip_mysql_order($orderby)) : '') |
|
| 277 | 277 | . ($limit ? "\nLIMIT $limit" : ''); |
| 278 | 278 | |
| 279 | 279 | // renvoyer la requete inerte si demandee |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | function spip_mysql_order($orderby) |
| 295 | 295 | { |
| 296 | - return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 296 | + return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
@@ -305,18 +305,18 @@ discard block |
||
| 305 | 305 | function calculer_mysql_where($v) |
| 306 | 306 | { |
| 307 | 307 | if (!is_array($v)) |
| 308 | - return $v ; |
|
| 308 | + return $v; |
|
| 309 | 309 | |
| 310 | 310 | $op = array_shift($v); |
| 311 | - if (!($n=count($v))) |
|
| 311 | + if (!($n = count($v))) |
|
| 312 | 312 | return $op; |
| 313 | 313 | else { |
| 314 | 314 | $arg = calculer_mysql_where(array_shift($v)); |
| 315 | - if ($n==1) { |
|
| 315 | + if ($n == 1) { |
|
| 316 | 316 | return "$op($arg)"; |
| 317 | 317 | } else { |
| 318 | 318 | $arg2 = calculer_mysql_where(array_shift($v)); |
| 319 | - if ($n==2) { |
|
| 319 | + if ($n == 2) { |
|
| 320 | 320 | return "($arg $op $arg2)"; |
| 321 | 321 | } else return "($arg $op ($arg2) : $v[0])"; |
| 322 | 322 | } |
@@ -330,19 +330,19 @@ discard block |
||
| 330 | 330 | * @param string $join |
| 331 | 331 | * @return string |
| 332 | 332 | */ |
| 333 | -function calculer_mysql_expression($expression, $v, $join = 'AND'){ |
|
| 333 | +function calculer_mysql_expression($expression, $v, $join = 'AND') { |
|
| 334 | 334 | if (empty($v)) |
| 335 | 335 | return ''; |
| 336 | 336 | |
| 337 | 337 | $exp = "\n$expression "; |
| 338 | 338 | |
| 339 | 339 | if (!is_array($v)) { |
| 340 | - return $exp . $v; |
|
| 340 | + return $exp.$v; |
|
| 341 | 341 | } else { |
| 342 | 342 | if (strtoupper($join) === 'AND') |
| 343 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 343 | + return $exp.join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 344 | 344 | else |
| 345 | - return $exp . join($join, $v); |
|
| 345 | + return $exp.join($join, $v); |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
@@ -354,24 +354,24 @@ discard block |
||
| 354 | 354 | function spip_mysql_select_as($args) |
| 355 | 355 | { |
| 356 | 356 | $res = ''; |
| 357 | - foreach($args as $k => $v) { |
|
| 358 | - if (substr($k,-1)=='@') { |
|
| 357 | + foreach ($args as $k => $v) { |
|
| 358 | + if (substr($k, -1) == '@') { |
|
| 359 | 359 | // c'est une jointure qui se refere au from precedent |
| 360 | 360 | // pas de virgule |
| 361 | - $res .= ' ' . $v ; |
|
| 361 | + $res .= ' '.$v; |
|
| 362 | 362 | } |
| 363 | 363 | else { |
| 364 | 364 | if (!is_numeric($k)) { |
| 365 | 365 | $p = strpos($v, " "); |
| 366 | 366 | if ($p) |
| 367 | - $v = substr($v,0,$p) . " AS `$k`" . substr($v,$p); |
|
| 367 | + $v = substr($v, 0, $p)." AS `$k`".substr($v, $p); |
|
| 368 | 368 | else $v .= " AS `$k`"; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - $res .= ', ' . $v ; |
|
| 371 | + $res .= ', '.$v; |
|
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | - return substr($res,2); |
|
| 374 | + return substr($res, 2); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // |
@@ -387,31 +387,31 @@ discard block |
||
| 387 | 387 | * @param string $prefixe |
| 388 | 388 | * @return array|null|string |
| 389 | 389 | */ |
| 390 | -function traite_query($query, $db='', $prefixe='') { |
|
| 390 | +function traite_query($query, $db = '', $prefixe = '') { |
|
| 391 | 391 | |
| 392 | 392 | if ($GLOBALS['mysql_rappel_nom_base'] AND $db) |
| 393 | - $pref = '`'. $db.'`.'; |
|
| 393 | + $pref = '`'.$db.'`.'; |
|
| 394 | 394 | else $pref = ''; |
| 395 | 395 | |
| 396 | 396 | if ($prefixe) |
| 397 | - $pref .= $prefixe . "_"; |
|
| 397 | + $pref .= $prefixe."_"; |
|
| 398 | 398 | |
| 399 | 399 | if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
| 400 | - $suite =''; |
|
| 400 | + $suite = ''; |
|
| 401 | 401 | } else { |
| 402 | 402 | $suite = strstr($query, $regs[0]); |
| 403 | 403 | $query = substr($query, 0, -strlen($suite)); |
| 404 | 404 | // propager le prefixe en cas de requete imbriquee |
| 405 | 405 | // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
| 406 | 406 | // modifier une requete qui est en fait juste du texte dans un champ |
| 407 | - if (stripos($suite,"SELECT")!==false) { |
|
| 408 | - list($suite,$textes) = query_echappe_textes($suite); |
|
| 407 | + if (stripos($suite, "SELECT") !== false) { |
|
| 408 | + list($suite, $textes) = query_echappe_textes($suite); |
|
| 409 | 409 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) |
| 410 | - $suite = $r[1] . traite_query($r[2], $db, $prefixe); |
|
| 410 | + $suite = $r[1].traite_query($r[2], $db, $prefixe); |
|
| 411 | 411 | $suite = query_reinjecte_textes($suite, $textes); |
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | - $r = preg_replace(_SQL_PREFIXE_TABLE, '\1'.$pref, $query) . $suite; |
|
| 414 | + $r = preg_replace(_SQL_PREFIXE_TABLE, '\1'.$pref, $query).$suite; |
|
| 415 | 415 | |
| 416 | 416 | #spip_log("traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
| 417 | 417 | return $r; |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | function spip_mysql_selectdb($db) { |
| 431 | 431 | $ok = mysql_select_db($db); |
| 432 | 432 | if (!$ok) |
| 433 | - spip_log('Echec mysql_selectdb. Erreur : ' . mysql_error(),'mysql.'._LOG_CRITIQUE); |
|
| 433 | + spip_log('Echec mysql_selectdb. Erreur : '.mysql_error(), 'mysql.'._LOG_CRITIQUE); |
|
| 434 | 434 | return $ok; |
| 435 | 435 | } |
| 436 | 436 | |
@@ -450,10 +450,10 @@ discard block |
||
| 450 | 450 | * @return array |
| 451 | 451 | * Liste de noms de bases de donnees |
| 452 | 452 | **/ |
| 453 | -function spip_mysql_listdbs($serveur='',$requeter=true) { |
|
| 453 | +function spip_mysql_listdbs($serveur = '', $requeter = true) { |
|
| 454 | 454 | $dbs = array(); |
| 455 | - if ($res = spip_mysql_query("SHOW DATABASES")){ |
|
| 456 | - while($row = mysql_fetch_assoc($res)) |
|
| 455 | + if ($res = spip_mysql_query("SHOW DATABASES")) { |
|
| 456 | + while ($row = mysql_fetch_assoc($res)) |
|
| 457 | 457 | $dbs[] = $row['Database']; |
| 458 | 458 | } |
| 459 | 459 | return $dbs; |
@@ -477,9 +477,9 @@ discard block |
||
| 477 | 477 | * @param bool $requeter |
| 478 | 478 | * @return array|null|resource|string |
| 479 | 479 | */ |
| 480 | -function spip_mysql_create($nom, $champs, $cles, $autoinc=false, $temporary=false, $serveur='',$requeter=true) { |
|
| 480 | +function spip_mysql_create($nom, $champs, $cles, $autoinc = false, $temporary = false, $serveur = '', $requeter = true) { |
|
| 481 | 481 | |
| 482 | - $query = ''; $keys = ''; $s = ''; $p=''; |
|
| 482 | + $query = ''; $keys = ''; $s = ''; $p = ''; |
|
| 483 | 483 | |
| 484 | 484 | // certains plugins declarent les tables (permet leur inclusion dans le dump) |
| 485 | 485 | // sans les renseigner (laisse le compilo recuperer la description) |
@@ -487,11 +487,11 @@ discard block |
||
| 487 | 487 | return; |
| 488 | 488 | |
| 489 | 489 | $res = spip_mysql_query("SELECT version() as v"); |
| 490 | - if (($row = mysql_fetch_array($res)) && (version_compare($row['v'],'5.0','>='))) { |
|
| 490 | + if (($row = mysql_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 491 | 491 | spip_mysql_query("SET sql_mode=''", $serveur); |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - foreach($cles as $k => $v) { |
|
| 494 | + foreach ($cles as $k => $v) { |
|
| 495 | 495 | $keys .= "$s\n\t\t$k ($v)"; |
| 496 | 496 | if ($k == "PRIMARY KEY") |
| 497 | 497 | $p = $v; |
@@ -505,12 +505,12 @@ discard block |
||
| 505 | 505 | if (@$GLOBALS['meta']['charset_collation_sql_base']) |
| 506 | 506 | $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
| 507 | 507 | |
| 508 | - foreach($champs as $k => $v) { |
|
| 508 | + foreach ($champs as $k => $v) { |
|
| 509 | 509 | $v = _mysql_remplacements_definitions_table($v); |
| 510 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i',$v,$defs)){ |
|
| 511 | - if (preg_match(',(char|text),i',$defs[1]) |
|
| 512 | - AND !preg_match(',(binary|CHARACTER|COLLATE),i',$v) ){ |
|
| 513 | - $v = $defs[1] . $character_set . ' ' . substr($v,strlen($defs[1])); |
|
| 510 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 511 | + if (preg_match(',(char|text),i', $defs[1]) |
|
| 512 | + AND !preg_match(',(binary|CHARACTER|COLLATE),i', $v)) { |
|
| 513 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | |
@@ -521,9 +521,9 @@ discard block |
||
| 521 | 521 | ); |
| 522 | 522 | $s = ","; |
| 523 | 523 | } |
| 524 | - $temporary = $temporary ? 'TEMPORARY':''; |
|
| 525 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")". |
|
| 526 | - ($character_set?" DEFAULT $character_set":"") |
|
| 524 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 525 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query".($keys ? ",$keys" : '').")". |
|
| 526 | + ($character_set ? " DEFAULT $character_set" : "") |
|
| 527 | 527 | ."\n"; |
| 528 | 528 | return spip_mysql_query($q, $serveur); |
| 529 | 529 | } |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | * @return string |
| 538 | 538 | * Definition SQL adaptee pour MySQL d'un champ de table |
| 539 | 539 | */ |
| 540 | -function _mysql_remplacements_definitions_table($query){ |
|
| 540 | +function _mysql_remplacements_definitions_table($query) { |
|
| 541 | 541 | // quelques remplacements |
| 542 | 542 | $num = "(\s*\([0-9]*\))?"; |
| 543 | 543 | $enum = "(\s*\([^\)]*\))?"; |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | * @param bool $requeter |
| 557 | 557 | * @return array|null|resource|string |
| 558 | 558 | */ |
| 559 | -function spip_mysql_create_base($nom, $serveur='',$requeter=true) { |
|
| 559 | +function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
|
| 560 | 560 | return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
| 561 | 561 | } |
| 562 | 562 | |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | * @param bool $requeter |
| 570 | 570 | * @return array|bool|null|resource|string |
| 571 | 571 | */ |
| 572 | -function spip_mysql_create_view($nom, $query_select, $serveur='',$requeter=true) { |
|
| 572 | +function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
|
| 573 | 573 | if (!$query_select) return false; |
| 574 | 574 | // vue deja presente |
| 575 | 575 | if (sql_showtable($nom, false, $serveur)) { |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | return false; |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - $query = "CREATE VIEW $nom AS ". $query_select; |
|
| 580 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 581 | 581 | return spip_mysql_query($query, $serveur, $requeter); |
| 582 | 582 | } |
| 583 | 583 | |
@@ -590,9 +590,9 @@ discard block |
||
| 590 | 590 | * @param bool $requeter |
| 591 | 591 | * @return array|null|resource|string |
| 592 | 592 | */ |
| 593 | -function spip_mysql_drop_table($table, $exist='', $serveur='',$requeter=true) |
|
| 593 | +function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) |
|
| 594 | 594 | { |
| 595 | - if ($exist) $exist =" IF EXISTS"; |
|
| 595 | + if ($exist) $exist = " IF EXISTS"; |
|
| 596 | 596 | return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
| 597 | 597 | } |
| 598 | 598 | |
@@ -605,8 +605,8 @@ discard block |
||
| 605 | 605 | * @param bool $requeter |
| 606 | 606 | * @return array|null|resource|string |
| 607 | 607 | */ |
| 608 | -function spip_mysql_drop_view($view, $exist='', $serveur='',$requeter=true) { |
|
| 609 | - if ($exist) $exist =" IF EXISTS"; |
|
| 608 | +function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
|
| 609 | + if ($exist) $exist = " IF EXISTS"; |
|
| 610 | 610 | return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
| 611 | 611 | } |
| 612 | 612 | |
@@ -623,9 +623,9 @@ discard block |
||
| 623 | 623 | * @return ressource |
| 624 | 624 | * Ressource à utiliser avec sql_fetch() |
| 625 | 625 | **/ |
| 626 | -function spip_mysql_showbase($match, $serveur='',$requeter=true) |
|
| 626 | +function spip_mysql_showbase($match, $serveur = '', $requeter = true) |
|
| 627 | 627 | { |
| 628 | - return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 628 | + return spip_mysql_query("SHOW TABLES LIKE "._q($match), $serveur, $requeter); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | // http://doc.spip.org/@spip_mysql_repair |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | * @param bool $requeter |
| 636 | 636 | * @return array|null|resource|string |
| 637 | 637 | */ |
| 638 | -function spip_mysql_repair($table, $serveur='',$requeter=true) |
|
| 638 | +function spip_mysql_repair($table, $serveur = '', $requeter = true) |
|
| 639 | 639 | { |
| 640 | 640 | return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
| 641 | 641 | } |
@@ -651,14 +651,14 @@ discard block |
||
| 651 | 651 | * @param bool $requeter |
| 652 | 652 | * @return array|null|resource|string |
| 653 | 653 | */ |
| 654 | -function spip_mysql_showtable($nom_table, $serveur='',$requeter=true) |
|
| 654 | +function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) |
|
| 655 | 655 | { |
| 656 | 656 | $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
| 657 | 657 | if (!$s) return ''; |
| 658 | 658 | if (!$requeter) return $s; |
| 659 | 659 | |
| 660 | - list(,$a) = mysql_fetch_array($s ,MYSQL_NUM); |
|
| 661 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)){ |
|
| 660 | + list(,$a) = mysql_fetch_array($s, MYSQL_NUM); |
|
| 661 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 662 | 662 | $desc = $r[1]; |
| 663 | 663 | // extraction d'une KEY éventuelle en prenant garde de ne pas |
| 664 | 664 | // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
@@ -670,14 +670,14 @@ discard block |
||
| 670 | 670 | $namedkeys = ""; |
| 671 | 671 | |
| 672 | 672 | $fields = array(); |
| 673 | - foreach(preg_split("/,\s*`/",$desc) as $v) { |
|
| 674 | - preg_match("/^\s*`?([^`]*)`\s*(.*)/",$v,$r); |
|
| 673 | + foreach (preg_split("/,\s*`/", $desc) as $v) { |
|
| 674 | + preg_match("/^\s*`?([^`]*)`\s*(.*)/", $v, $r); |
|
| 675 | 675 | $fields[strtolower($r[1])] = $r[2]; |
| 676 | 676 | } |
| 677 | 677 | $keys = array(); |
| 678 | 678 | |
| 679 | - foreach(preg_split('/\)\s*(,|$)/',$namedkeys) as $v) { |
|
| 680 | - if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/",$v,$r)) { |
|
| 679 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 680 | + if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/", $v, $r)) { |
|
| 681 | 681 | $k = str_replace("`", '', trim($r[1])); |
| 682 | 682 | $t = strtolower(str_replace("`", '', $r[2])); |
| 683 | 683 | if ($k && !isset($keys[$k])) $keys[$k] = $t; else $keys[] = $t; |
@@ -688,28 +688,28 @@ discard block |
||
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
| 691 | - if($res) { |
|
| 691 | + if ($res) { |
|
| 692 | 692 | $nfields = array(); |
| 693 | 693 | $nkeys = array(); |
| 694 | - while($val = spip_mysql_fetch($res)) { |
|
| 694 | + while ($val = spip_mysql_fetch($res)) { |
|
| 695 | 695 | $nfields[$val["Field"]] = $val['Type']; |
| 696 | - if($val['Null']=='NO') { |
|
| 696 | + if ($val['Null'] == 'NO') { |
|
| 697 | 697 | $nfields[$val["Field"]] .= ' NOT NULL'; |
| 698 | 698 | } |
| 699 | - if($val['Default'] === '0' || $val['Default']) { |
|
| 700 | - if(preg_match('/[A-Z_]/',$val['Default'])) { |
|
| 699 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 700 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 701 | 701 | $nfields[$val["Field"]] .= ' DEFAULT '.$val['Default']; |
| 702 | 702 | } else { |
| 703 | 703 | $nfields[$val["Field"]] .= " DEFAULT '".$val['Default']."'"; |
| 704 | 704 | } |
| 705 | 705 | } |
| 706 | - if($val['Extra']) |
|
| 706 | + if ($val['Extra']) |
|
| 707 | 707 | $nfields[$val["Field"]] .= ' '.$val['Extra']; |
| 708 | - if($val['Key'] == 'PRI') { |
|
| 708 | + if ($val['Key'] == 'PRI') { |
|
| 709 | 709 | $nkeys['PRIMARY KEY'] = $val["Field"]; |
| 710 | - } else if($val['Key'] == 'MUL') { |
|
| 710 | + } else if ($val['Key'] == 'MUL') { |
|
| 711 | 711 | $nkeys['KEY '.$val["Field"]] = $val["Field"]; |
| 712 | - } else if($val['Key'] == 'UNI') { |
|
| 712 | + } else if ($val['Key'] == 'UNI') { |
|
| 713 | 713 | $nkeys['UNIQUE KEY '.$val["Field"]] = $val["Field"]; |
| 714 | 714 | } |
| 715 | 715 | } |
@@ -731,13 +731,13 @@ discard block |
||
| 731 | 731 | * @param bool $requeter |
| 732 | 732 | * @return array |
| 733 | 733 | */ |
| 734 | -function spip_mysql_fetch($r, $t='', $serveur='',$requeter=true) { |
|
| 734 | +function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
|
| 735 | 735 | if (!$t) $t = MYSQL_ASSOC; |
| 736 | 736 | if ($r) return mysql_fetch_array($r, $t); |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | -function spip_mysql_seek($r, $row_number, $serveur='',$requeter=true) { |
|
| 740 | - if ($r and mysql_num_rows($r)) return mysql_data_seek($r,$row_number); |
|
| 739 | +function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
|
| 740 | + if ($r and mysql_num_rows($r)) return mysql_data_seek($r, $row_number); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | |
@@ -754,11 +754,11 @@ discard block |
||
| 754 | 754 | * |
| 755 | 755 | */ |
| 756 | 756 | function spip_mysql_countsel($from = array(), $where = array(), |
| 757 | - $groupby = '', $having = array(), $serveur='',$requeter=true) |
|
| 757 | + $groupby = '', $having = array(), $serveur = '', $requeter = true) |
|
| 758 | 758 | { |
| 759 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 759 | + $c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 760 | 760 | |
| 761 | - $r = spip_mysql_select("COUNT($c)", $from, $where,'', '', '', $having, $serveur, $requeter); |
|
| 761 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 762 | 762 | |
| 763 | 763 | if (!$requeter) return $r; |
| 764 | 764 | if (!is_resource($r)) return 0; |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | * @param bool $requeter |
| 777 | 777 | * @return string |
| 778 | 778 | */ |
| 779 | -function spip_mysql_error($query='', $serveur='',$requeter=true) { |
|
| 779 | +function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
|
| 780 | 780 | $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
| 781 | 781 | $s = $link ? mysql_error($link) : mysql_error(); |
| 782 | 782 | if ($s) spip_log("$s - $query", 'mysql.'._LOG_ERREUR); |
@@ -790,12 +790,12 @@ discard block |
||
| 790 | 790 | * @param bool $requeter |
| 791 | 791 | * @return int |
| 792 | 792 | */ |
| 793 | -function spip_mysql_errno($serveur='',$requeter=true) { |
|
| 793 | +function spip_mysql_errno($serveur = '', $requeter = true) { |
|
| 794 | 794 | $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
| 795 | 795 | $s = $link ? mysql_errno($link) : mysql_errno(); |
| 796 | 796 | // 2006 MySQL server has gone away |
| 797 | 797 | // 2013 Lost connection to MySQL server during query |
| 798 | - if (in_array($s, array(2006,2013))) |
|
| 798 | + if (in_array($s, array(2006, 2013))) |
|
| 799 | 799 | define('spip_interdire_cache', true); |
| 800 | 800 | if ($s) spip_log("Erreur mysql $s", _LOG_ERREUR); |
| 801 | 801 | return $s; |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | * @param bool $requeter |
| 810 | 810 | * @return int |
| 811 | 811 | */ |
| 812 | -function spip_mysql_count($r, $serveur='',$requeter=true) { |
|
| 812 | +function spip_mysql_count($r, $serveur = '', $requeter = true) { |
|
| 813 | 813 | if ($r) return mysql_num_rows($r); |
| 814 | 814 | } |
| 815 | 815 | |
@@ -821,8 +821,8 @@ discard block |
||
| 821 | 821 | * @param bool $requeter |
| 822 | 822 | * @return bool |
| 823 | 823 | */ |
| 824 | -function spip_mysql_free($r, $serveur='',$requeter=true) { |
|
| 825 | - return (is_resource($r)?mysql_free_result($r):false); |
|
| 824 | +function spip_mysql_free($r, $serveur = '', $requeter = true) { |
|
| 825 | + return (is_resource($r) ?mysql_free_result($r) : false); |
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | // http://doc.spip.org/@spip_mysql_insert |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | * @param bool $requeter |
| 836 | 836 | * @return int|string |
| 837 | 837 | */ |
| 838 | -function spip_mysql_insert($table, $champs, $valeurs, $desc='', $serveur='',$requeter=true) { |
|
| 838 | +function spip_mysql_insert($table, $champs, $valeurs, $desc = '', $serveur = '', $requeter = true) { |
|
| 839 | 839 | |
| 840 | 840 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 841 | 841 | $prefixe = $connexion['prefixe']; |
@@ -844,13 +844,13 @@ discard block |
||
| 844 | 844 | |
| 845 | 845 | if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
| 846 | 846 | |
| 847 | - $query ="INSERT INTO $table $champs VALUES $valeurs"; |
|
| 847 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 848 | 848 | if (!$requeter) return $query; |
| 849 | 849 | |
| 850 | 850 | if (isset($_GET['var_profile'])) { |
| 851 | 851 | include_spip('public/tracer'); |
| 852 | 852 | $t = trace_query_start(); |
| 853 | - } else $t = 0 ; |
|
| 853 | + } else $t = 0; |
|
| 854 | 854 | |
| 855 | 855 | $connexion['last'] = $query; |
| 856 | 856 | #spip_log($query, 'mysql.'._LOG_DEBUG); |
@@ -874,17 +874,17 @@ discard block |
||
| 874 | 874 | * @param bool $requeter |
| 875 | 875 | * @return int|string |
| 876 | 876 | */ |
| 877 | -function spip_mysql_insertq($table, $couples=array(), $desc=array(), $serveur='',$requeter=true) { |
|
| 877 | +function spip_mysql_insertq($table, $couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
|
| 878 | 878 | |
| 879 | 879 | if (!$desc) $desc = description_table($table, $serveur); |
| 880 | 880 | if (!$desc) $couples = array(); |
| 881 | - $fields = isset($desc['field'])?$desc['field']:array(); |
|
| 881 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 882 | 882 | |
| 883 | 883 | foreach ($couples as $champ => $val) { |
| 884 | - $couples[$champ]= spip_mysql_cite($val, $fields[$champ]); |
|
| 884 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | - return spip_mysql_insert($table, "(".join(',',array_keys($couples)).")", "(".join(',', $couples).")", $desc, $serveur, $requeter); |
|
| 887 | + return spip_mysql_insert($table, "(".join(',', array_keys($couples)).")", "(".join(',', $couples).")", $desc, $serveur, $requeter); |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | |
@@ -897,23 +897,23 @@ discard block |
||
| 897 | 897 | * @param bool $requeter |
| 898 | 898 | * @return bool|int|string |
| 899 | 899 | */ |
| 900 | -function spip_mysql_insertq_multi($table, $tab_couples=array(), $desc=array(), $serveur='',$requeter=true) { |
|
| 900 | +function spip_mysql_insertq_multi($table, $tab_couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
|
| 901 | 901 | |
| 902 | 902 | if (!$desc) $desc = description_table($table, $serveur); |
| 903 | 903 | if (!$desc) $tab_couples = array(); |
| 904 | - $fields = isset($desc['field'])?$desc['field']:array(); |
|
| 904 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 905 | 905 | |
| 906 | - $cles = "(" . join(',',array_keys(reset($tab_couples))) . ')'; |
|
| 906 | + $cles = "(".join(',', array_keys(reset($tab_couples))).')'; |
|
| 907 | 907 | $valeurs = array(); |
| 908 | 908 | $r = false; |
| 909 | 909 | |
| 910 | 910 | // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
| 911 | 911 | foreach ($tab_couples as $couples) { |
| 912 | - foreach ($couples as $champ => $val){ |
|
| 913 | - $couples[$champ]= spip_mysql_cite($val, $fields[$champ]); |
|
| 912 | + foreach ($couples as $champ => $val) { |
|
| 913 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 914 | 914 | } |
| 915 | - $valeurs[] = '(' .join(',', $couples) . ')'; |
|
| 916 | - if (count($valeurs)>=100){ |
|
| 915 | + $valeurs[] = '('.join(',', $couples).')'; |
|
| 916 | + if (count($valeurs) >= 100) { |
|
| 917 | 917 | $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
| 918 | 918 | $valeurs = array(); |
| 919 | 919 | } |
@@ -934,10 +934,10 @@ discard block |
||
| 934 | 934 | * @param bool $requeter |
| 935 | 935 | * @return array|null|resource|string |
| 936 | 936 | */ |
| 937 | -function spip_mysql_update($table, $champs, $where='', $desc='', $serveur='',$requeter=true) { |
|
| 937 | +function spip_mysql_update($table, $champs, $where = '', $desc = '', $serveur = '', $requeter = true) { |
|
| 938 | 938 | $set = array(); |
| 939 | 939 | foreach ($champs as $champ => $val) |
| 940 | - $set[] = $champ . "=$val"; |
|
| 940 | + $set[] = $champ."=$val"; |
|
| 941 | 941 | if (!empty($set)) |
| 942 | 942 | return spip_mysql_query( |
| 943 | 943 | calculer_mysql_expression('UPDATE', $table, ',') |
@@ -958,14 +958,14 @@ discard block |
||
| 958 | 958 | * @param bool $requeter |
| 959 | 959 | * @return array|null|resource|string |
| 960 | 960 | */ |
| 961 | -function spip_mysql_updateq($table, $champs, $where='', $desc=array(), $serveur='',$requeter=true) { |
|
| 961 | +function spip_mysql_updateq($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
|
| 962 | 962 | |
| 963 | 963 | if (!$champs) return; |
| 964 | 964 | if (!$desc) $desc = description_table($table, $serveur); |
| 965 | - if (!$desc) $champs = array(); else $fields = $desc['field']; |
|
| 965 | + if (!$desc) $champs = array(); else $fields = $desc['field']; |
|
| 966 | 966 | $set = array(); |
| 967 | 967 | foreach ($champs as $champ => $val) { |
| 968 | - $set[] = $champ . '=' . spip_mysql_cite($val, $fields[$champ]); |
|
| 968 | + $set[] = $champ.'='.spip_mysql_cite($val, $fields[$champ]); |
|
| 969 | 969 | } |
| 970 | 970 | return spip_mysql_query( |
| 971 | 971 | calculer_mysql_expression('UPDATE', $table, ',') |
@@ -982,13 +982,13 @@ discard block |
||
| 982 | 982 | * @param bool $requeter |
| 983 | 983 | * @return array|bool|int|null|resource|string |
| 984 | 984 | */ |
| 985 | -function spip_mysql_delete($table, $where='', $serveur='',$requeter=true) { |
|
| 985 | +function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
|
| 986 | 986 | $res = spip_mysql_query( |
| 987 | 987 | calculer_mysql_expression('DELETE FROM', $table, ',') |
| 988 | 988 | . calculer_mysql_expression('WHERE', $where), |
| 989 | 989 | $serveur, $requeter); |
| 990 | 990 | if (!$requeter) return $res; |
| 991 | - if ($res){ |
|
| 991 | + if ($res) { |
|
| 992 | 992 | $connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0]; |
| 993 | 993 | $link = $connexion['link']; |
| 994 | 994 | return $link ? mysql_affected_rows($link) : mysql_affected_rows(); |
@@ -1006,8 +1006,8 @@ discard block |
||
| 1006 | 1006 | * @param bool $requeter |
| 1007 | 1007 | * @return array|null|resource|string |
| 1008 | 1008 | */ |
| 1009 | -function spip_mysql_replace($table, $couples, $desc=array(), $serveur='',$requeter=true) { |
|
| 1010 | - return spip_mysql_query("REPLACE $table (" . join(',',array_keys($couples)) . ') VALUES (' .join(',',array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1009 | +function spip_mysql_replace($table, $couples, $desc = array(), $serveur = '', $requeter = true) { |
|
| 1010 | + return spip_mysql_query("REPLACE $table (".join(',', array_keys($couples)).') VALUES ('.join(',', array_map('_q', $couples)).')', $serveur, $requeter); |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | |
@@ -1020,13 +1020,13 @@ discard block |
||
| 1020 | 1020 | * @param bool $requeter |
| 1021 | 1021 | * @return array|null|resource|string |
| 1022 | 1022 | */ |
| 1023 | -function spip_mysql_replace_multi($table, $tab_couples, $desc=array(), $serveur='',$requeter=true) { |
|
| 1024 | - $cles = "(" . join(',',array_keys($tab_couples[0])). ')'; |
|
| 1023 | +function spip_mysql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
|
| 1024 | + $cles = "(".join(',', array_keys($tab_couples[0])).')'; |
|
| 1025 | 1025 | $valeurs = array(); |
| 1026 | 1026 | foreach ($tab_couples as $couples) { |
| 1027 | - $valeurs[] = '(' .join(',',array_map('_q', $couples)) . ')'; |
|
| 1027 | + $valeurs[] = '('.join(',', array_map('_q', $couples)).')'; |
|
| 1028 | 1028 | } |
| 1029 | - $valeurs = implode(', ',$valeurs); |
|
| 1029 | + $valeurs = implode(', ', $valeurs); |
|
| 1030 | 1030 | return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
| 1031 | 1031 | } |
| 1032 | 1032 | |
@@ -1040,7 +1040,7 @@ discard block |
||
| 1040 | 1040 | * |
| 1041 | 1041 | */ |
| 1042 | 1042 | |
| 1043 | -function spip_mysql_multi ($objet, $lang) { |
|
| 1043 | +function spip_mysql_multi($objet, $lang) { |
|
| 1044 | 1044 | $lengthlang = strlen("[$lang]"); |
| 1045 | 1045 | $posmulti = "INSTR(".$objet.", '<multi>')"; |
| 1046 | 1046 | $posfinmulti = "INSTR(".$objet.", '</multi>')"; |
@@ -1076,7 +1076,7 @@ discard block |
||
| 1076 | 1076 | */ |
| 1077 | 1077 | function spip_mysql_hex($v) |
| 1078 | 1078 | { |
| 1079 | - return "0x" . $v; |
|
| 1079 | + return "0x".$v; |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1084,12 +1084,12 @@ discard block |
||
| 1084 | 1084 | * @param string $type |
| 1085 | 1085 | * @return array|int|string |
| 1086 | 1086 | */ |
| 1087 | -function spip_mysql_quote($v, $type='') { |
|
| 1087 | +function spip_mysql_quote($v, $type = '') { |
|
| 1088 | 1088 | if ($type) { |
| 1089 | 1089 | if (!is_array($v)) |
| 1090 | - return spip_mysql_cite($v,$type); |
|
| 1090 | + return spip_mysql_cite($v, $type); |
|
| 1091 | 1091 | // si c'est un tableau, le parcourir en propageant le type |
| 1092 | - foreach($v as $k=>$r) |
|
| 1092 | + foreach ($v as $k=>$r) |
|
| 1093 | 1093 | $v[$k] = spip_mysql_quote($r, $type); |
| 1094 | 1094 | return $v; |
| 1095 | 1095 | } |
@@ -1114,7 +1114,7 @@ discard block |
||
| 1114 | 1114 | . '(' |
| 1115 | 1115 | . sql_quote(date('Y-m-d H:i:s')) |
| 1116 | 1116 | . ', INTERVAL ' |
| 1117 | - . (($interval > 0) ? $interval : (0-$interval)) |
|
| 1117 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1118 | 1118 | . ' ' |
| 1119 | 1119 | . $unite |
| 1120 | 1120 | . '))'; |
@@ -1132,16 +1132,16 @@ discard block |
||
| 1132 | 1132 | * @param bool $requeter |
| 1133 | 1133 | * @return string |
| 1134 | 1134 | */ |
| 1135 | -function spip_mysql_in($val, $valeurs, $not='', $serveur='',$requeter=true) { |
|
| 1135 | +function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
|
| 1136 | 1136 | $n = $i = 0; |
| 1137 | - $in_sql =""; |
|
| 1138 | - while ($n = strpos($valeurs, ',', $n+1)) { |
|
| 1137 | + $in_sql = ""; |
|
| 1138 | + while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1139 | 1139 | if ((++$i) >= 255) { |
| 1140 | - $in_sql .= "($val $not IN (" . |
|
| 1141 | - substr($valeurs, 0, $n) . |
|
| 1142 | - "))\n" . |
|
| 1140 | + $in_sql .= "($val $not IN (". |
|
| 1141 | + substr($valeurs, 0, $n). |
|
| 1142 | + "))\n". |
|
| 1143 | 1143 | ($not ? "AND\t" : "OR\t"); |
| 1144 | - $valeurs = substr($valeurs, $n+1); |
|
| 1144 | + $valeurs = substr($valeurs, $n + 1); |
|
| 1145 | 1145 | $i = $n = 0; |
| 1146 | 1146 | } |
| 1147 | 1147 | } |
@@ -1158,10 +1158,10 @@ discard block |
||
| 1158 | 1158 | * @param string $not |
| 1159 | 1159 | * @return string |
| 1160 | 1160 | */ |
| 1161 | -function calcul_mysql_in($val, $valeurs, $not='') { |
|
| 1161 | +function calcul_mysql_in($val, $valeurs, $not = '') { |
|
| 1162 | 1162 | if (is_array($valeurs)) |
| 1163 | 1163 | $valeurs = join(',', array_map('_q', $valeurs)); |
| 1164 | - elseif ($valeurs[0]===',') $valeurs = substr($valeurs,1); |
|
| 1164 | + elseif ($valeurs[0] === ',') $valeurs = substr($valeurs, 1); |
|
| 1165 | 1165 | if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1'); |
| 1166 | 1166 | return spip_mysql_in($val, $valeurs, $not); |
| 1167 | 1167 | } |
@@ -1173,19 +1173,19 @@ discard block |
||
| 1173 | 1173 | * @return int|string |
| 1174 | 1174 | */ |
| 1175 | 1175 | function spip_mysql_cite($v, $type) { |
| 1176 | - if(is_null($v) |
|
| 1177 | - AND stripos($type,"NOT NULL")===false) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1176 | + if (is_null($v) |
|
| 1177 | + AND stripos($type, "NOT NULL") === false) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1178 | 1178 | if (sql_test_date($type) AND preg_match('/^\w+\(/', $v)) |
| 1179 | 1179 | return $v; |
| 1180 | 1180 | if (sql_test_int($type)) { |
| 1181 | - if (is_numeric($v) OR (ctype_xdigit(substr($v,2)) |
|
| 1182 | - AND $v[0]=='0' AND $v[1]=='x')) |
|
| 1181 | + if (is_numeric($v) OR (ctype_xdigit(substr($v, 2)) |
|
| 1182 | + AND $v[0] == '0' AND $v[1] == 'x')) |
|
| 1183 | 1183 | return $v; |
| 1184 | 1184 | // si pas numerique, forcer le intval |
| 1185 | 1185 | else |
| 1186 | 1186 | return intval($v); |
| 1187 | 1187 | } |
| 1188 | - return ("'" . addslashes($v) . "'"); |
|
| 1188 | + return ("'".addslashes($v)."'"); |
|
| 1189 | 1189 | } |
| 1190 | 1190 | |
| 1191 | 1191 | // Ces deux fonctions n'ont pas d'equivalent exact PostGres |
@@ -1203,14 +1203,14 @@ discard block |
||
| 1203 | 1203 | */ |
| 1204 | 1204 | function spip_get_lock($nom, $timeout = 0) { |
| 1205 | 1205 | |
| 1206 | - define('_LOCK_TIME', intval(time()/3600-316982)); |
|
| 1206 | + define('_LOCK_TIME', intval(time() / 3600 - 316982)); |
|
| 1207 | 1207 | |
| 1208 | 1208 | $connexion = &$GLOBALS['connexions'][0]; |
| 1209 | 1209 | $bd = $connexion['db']; |
| 1210 | 1210 | $prefixe = $connexion['prefixe']; |
| 1211 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1211 | + $nom = "$bd:$prefixe:$nom"._LOCK_TIME; |
|
| 1212 | 1212 | |
| 1213 | - $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1213 | + $connexion['last'] = $q = "SELECT GET_LOCK("._q($nom).", $timeout) AS n"; |
|
| 1214 | 1214 | $q = @sql_fetch(mysql_query($q)); |
| 1215 | 1215 | if (!$q) spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
| 1216 | 1216 | return $q['n']; |
@@ -1225,9 +1225,9 @@ discard block |
||
| 1225 | 1225 | $connexion = &$GLOBALS['connexions'][0]; |
| 1226 | 1226 | $bd = $connexion['db']; |
| 1227 | 1227 | $prefixe = $connexion['prefixe']; |
| 1228 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1228 | + $nom = "$bd:$prefixe:$nom"._LOCK_TIME; |
|
| 1229 | 1229 | |
| 1230 | - $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1230 | + $connexion['last'] = $q = "SELECT RELEASE_LOCK("._q($nom).")"; |
|
| 1231 | 1231 | @mysql_query($q); |
| 1232 | 1232 | } |
| 1233 | 1233 | |
@@ -1269,11 +1269,11 @@ discard block |
||
| 1269 | 1269 | * @param $server_db |
| 1270 | 1270 | * @return string |
| 1271 | 1271 | */ |
| 1272 | -function test_sql_mode_mysql($server_db){ |
|
| 1273 | - $res = sql_select("version() as v",'','','','','','',$server_db); |
|
| 1274 | - $row = sql_fetch($res,$server_db); |
|
| 1275 | - if (version_compare($row['v'],'5.0.0','>=')){ |
|
| 1276 | - define('_MYSQL_SET_SQL_MODE',true); |
|
| 1272 | +function test_sql_mode_mysql($server_db) { |
|
| 1273 | + $res = sql_select("version() as v", '', '', '', '', '', '', $server_db); |
|
| 1274 | + $row = sql_fetch($res, $server_db); |
|
| 1275 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1276 | + define('_MYSQL_SET_SQL_MODE', true); |
|
| 1277 | 1277 | return "define('_MYSQL_SET_SQL_MODE',true);\n"; |
| 1278 | 1278 | } |
| 1279 | 1279 | return ''; |
@@ -177,7 +177,7 @@ |
||
| 177 | 177 | * |
| 178 | 178 | * @api |
| 179 | 179 | * @param array $objets_source |
| 180 | - * @param array|string $objets_lies |
|
| 180 | + * @param string $objets_lies |
|
| 181 | 181 | * @return int |
| 182 | 182 | */ |
| 183 | 183 | function objet_optimiser_liens($objets_source,$objets_lies){ |
@@ -32,18 +32,18 @@ discard block |
||
| 32 | 32 | * - array(clé primaire, nom de la table de lien) si associable |
| 33 | 33 | */ |
| 34 | 34 | function objet_associable($objet){ |
| 35 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 36 | - $table_sql = table_objet_sql($objet); |
|
| 37 | - |
|
| 38 | - $l=""; |
|
| 39 | - if ($primary = id_table_objet($objet) |
|
| 40 | - AND $trouver_table($l = $table_sql."_liens") |
|
| 41 | - AND !preg_match(',[^\w],',$primary) |
|
| 42 | - AND !preg_match(',[^\w],',$l)) |
|
| 43 | - return array($primary,$l); |
|
| 44 | - |
|
| 45 | - spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
|
| 46 | - return false; |
|
| 35 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 36 | + $table_sql = table_objet_sql($objet); |
|
| 37 | + |
|
| 38 | + $l=""; |
|
| 39 | + if ($primary = id_table_objet($objet) |
|
| 40 | + AND $trouver_table($l = $table_sql."_liens") |
|
| 41 | + AND !preg_match(',[^\w],',$primary) |
|
| 42 | + AND !preg_match(',[^\w],',$l)) |
|
| 43 | + return array($primary,$l); |
|
| 44 | + |
|
| 45 | + spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
|
| 46 | + return false; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -69,12 +69,12 @@ discard block |
||
| 69 | 69 | * @return bool|int |
| 70 | 70 | */ |
| 71 | 71 | function objet_associer($objets_source, $objets_lies, $qualif = null){ |
| 72 | - $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies); |
|
| 72 | + $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies); |
|
| 73 | 73 | |
| 74 | - if ($qualif) |
|
| 75 | - objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 74 | + if ($qualif) |
|
| 75 | + objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 76 | 76 | |
| 77 | - return $modifs; // pas d'erreur |
|
| 77 | + return $modifs; // pas d'erreur |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @return bool|int |
| 99 | 99 | */ |
| 100 | 100 | function objet_dissocier($objets_source,$objets_lies){ |
| 101 | - return objet_traiter_liaisons('lien_delete',$objets_source,$objets_lies); |
|
| 101 | + return objet_traiter_liaisons('lien_delete',$objets_source,$objets_lies); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @return bool|int |
| 125 | 125 | */ |
| 126 | 126 | function objet_qualifier_liens($objets_source,$objets_lies,$qualif){ |
| 127 | - return objet_traiter_liaisons('lien_set',$objets_source,$objets_lies,$qualif); |
|
| 127 | + return objet_traiter_liaisons('lien_set',$objets_source,$objets_lies,$qualif); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @return array |
| 158 | 158 | */ |
| 159 | 159 | function objet_trouver_liens($objets_source,$objets_lies){ |
| 160 | - return objet_traiter_liaisons('lien_find',$objets_source,$objets_lies); |
|
| 160 | + return objet_traiter_liaisons('lien_find',$objets_source,$objets_lies); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @return int |
| 182 | 182 | */ |
| 183 | 183 | function objet_optimiser_liens($objets_source,$objets_lies){ |
| 184 | - return objet_traiter_liaisons('lien_optimise',$objets_source,$objets_lies); |
|
| 184 | + return objet_traiter_liaisons('lien_optimise',$objets_source,$objets_lies); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
@@ -201,32 +201,32 @@ discard block |
||
| 201 | 201 | * Nombre de liens copiés |
| 202 | 202 | */ |
| 203 | 203 | function objet_dupliquer_liens($objet,$id_source,$id_cible,$types=null,$exclure_types=null){ |
| 204 | - include_spip('base/objets'); |
|
| 205 | - $tables = lister_tables_objets_sql(); |
|
| 206 | - $n = 0; |
|
| 207 | - foreach($tables as $table_sql => $infos){ |
|
| 208 | - if ( |
|
| 209 | - (is_null($types) OR in_array($infos['type'],$types)) |
|
| 210 | - AND (is_null($exclure_types) OR !in_array($infos['type'],$exclure_types)) |
|
| 211 | - ){ |
|
| 212 | - if (objet_associable($infos['type'])){ |
|
| 213 | - $liens = (($infos['type']==$objet)? |
|
| 214 | - objet_trouver_liens(array($objet=>$id_source),'*') |
|
| 215 | - : |
|
| 216 | - objet_trouver_liens(array($infos['type']=>'*'),array($objet=>$id_source))); |
|
| 217 | - foreach($liens as $lien){ |
|
| 218 | - $n++; |
|
| 219 | - if ($infos['type']==$objet){ |
|
| 220 | - objet_associer(array($objet=>$id_cible),array($lien['objet']=>$lien[$lien['objet']]),$lien); |
|
| 221 | - } |
|
| 222 | - else { |
|
| 223 | - objet_associer(array($infos['type']=>$lien[$infos['type']]),array($objet=>$id_cible),$lien); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - return $n; |
|
| 204 | + include_spip('base/objets'); |
|
| 205 | + $tables = lister_tables_objets_sql(); |
|
| 206 | + $n = 0; |
|
| 207 | + foreach($tables as $table_sql => $infos){ |
|
| 208 | + if ( |
|
| 209 | + (is_null($types) OR in_array($infos['type'],$types)) |
|
| 210 | + AND (is_null($exclure_types) OR !in_array($infos['type'],$exclure_types)) |
|
| 211 | + ){ |
|
| 212 | + if (objet_associable($infos['type'])){ |
|
| 213 | + $liens = (($infos['type']==$objet)? |
|
| 214 | + objet_trouver_liens(array($objet=>$id_source),'*') |
|
| 215 | + : |
|
| 216 | + objet_trouver_liens(array($infos['type']=>'*'),array($objet=>$id_source))); |
|
| 217 | + foreach($liens as $lien){ |
|
| 218 | + $n++; |
|
| 219 | + if ($infos['type']==$objet){ |
|
| 220 | + objet_associer(array($objet=>$id_cible),array($lien['objet']=>$lien[$lien['objet']]),$lien); |
|
| 221 | + } |
|
| 222 | + else { |
|
| 223 | + objet_associer(array($infos['type']=>$lien[$infos['type']]),array($objet=>$id_cible),$lien); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + return $n; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -258,36 +258,36 @@ discard block |
||
| 258 | 258 | * @return bool|int|array |
| 259 | 259 | */ |
| 260 | 260 | function objet_traiter_liaisons($operation,$objets_source,$objets_lies, $set = null){ |
| 261 | - // accepter une syntaxe minimale pour supprimer tous les liens |
|
| 262 | - if ($objets_lies=='*') $objets_lies = array('*'=>'*'); |
|
| 263 | - $modifs = 0; // compter le nombre de modifications |
|
| 264 | - $echec = null; |
|
| 265 | - foreach($objets_source as $objet=>$ids){ |
|
| 266 | - if ($a = objet_associable($objet)) { |
|
| 267 | - list($primary,$l) = $a; |
|
| 268 | - if (!is_array($ids)) |
|
| 269 | - $ids = array($ids); |
|
| 270 | - elseif(reset($ids)=="NOT"){ |
|
| 271 | - // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
|
| 272 | - $where = lien_where($primary,$ids,'*','*'); |
|
| 273 | - $ids = sql_allfetsel($primary,$l,$where); |
|
| 274 | - $ids = array_map('reset',$ids); |
|
| 275 | - } |
|
| 276 | - foreach($ids as $id) { |
|
| 277 | - $res = $operation($objet,$primary,$l,$id,$objets_lies,$set); |
|
| 278 | - if ($res===false) { |
|
| 279 | - spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id",_LOG_ERREUR); |
|
| 280 | - $echec = true; |
|
| 281 | - } |
|
| 282 | - else |
|
| 283 | - $modifs=($modifs?(is_array($res)?array_merge($modifs,$res):$modifs+$res):$res); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - else |
|
| 287 | - $echec = true; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return ($echec?false:$modifs); // pas d'erreur |
|
| 261 | + // accepter une syntaxe minimale pour supprimer tous les liens |
|
| 262 | + if ($objets_lies=='*') $objets_lies = array('*'=>'*'); |
|
| 263 | + $modifs = 0; // compter le nombre de modifications |
|
| 264 | + $echec = null; |
|
| 265 | + foreach($objets_source as $objet=>$ids){ |
|
| 266 | + if ($a = objet_associable($objet)) { |
|
| 267 | + list($primary,$l) = $a; |
|
| 268 | + if (!is_array($ids)) |
|
| 269 | + $ids = array($ids); |
|
| 270 | + elseif(reset($ids)=="NOT"){ |
|
| 271 | + // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
|
| 272 | + $where = lien_where($primary,$ids,'*','*'); |
|
| 273 | + $ids = sql_allfetsel($primary,$l,$where); |
|
| 274 | + $ids = array_map('reset',$ids); |
|
| 275 | + } |
|
| 276 | + foreach($ids as $id) { |
|
| 277 | + $res = $operation($objet,$primary,$l,$id,$objets_lies,$set); |
|
| 278 | + if ($res===false) { |
|
| 279 | + spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id",_LOG_ERREUR); |
|
| 280 | + $echec = true; |
|
| 281 | + } |
|
| 282 | + else |
|
| 283 | + $modifs=($modifs?(is_array($res)?array_merge($modifs,$res):$modifs+$res):$res); |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + else |
|
| 287 | + $echec = true; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return ($echec?false:$modifs); // pas d'erreur |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | |
@@ -310,59 +310,59 @@ discard block |
||
| 310 | 310 | * @return bool|int |
| 311 | 311 | */ |
| 312 | 312 | function lien_insert($objet_source,$primary,$table_lien,$id,$objets) { |
| 313 | - $ins = 0; |
|
| 314 | - $echec = null; |
|
| 315 | - foreach($objets as $objet => $id_objets){ |
|
| 316 | - if (!is_array($id_objets)) $id_objets = array($id_objets); |
|
| 317 | - foreach($id_objets as $id_objet) { |
|
| 318 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 319 | - // Envoyer aux plugins |
|
| 320 | - $id_objet = pipeline('pre_edition_lien', |
|
| 321 | - array( |
|
| 322 | - 'args' => array( |
|
| 323 | - 'table_lien' => $table_lien, |
|
| 324 | - 'objet_source' => $objet_source, |
|
| 325 | - 'id_objet_source' => $id, |
|
| 326 | - 'objet' => $objet, |
|
| 327 | - 'id_objet' => $id_objet, |
|
| 328 | - 'action'=>'insert', |
|
| 329 | - ), |
|
| 330 | - 'data' => $id_objet |
|
| 331 | - ) |
|
| 332 | - ); |
|
| 333 | - if ($id_objet=intval($id_objet) |
|
| 334 | - AND !sql_getfetsel( |
|
| 335 | - $primary, |
|
| 336 | - $table_lien, |
|
| 337 | - array('id_objet='.intval($id_objet), 'objet='.sql_quote($objet), $primary.'='.intval($id)))) |
|
| 338 | - { |
|
| 339 | - |
|
| 340 | - $e = sql_insertq($table_lien, array('id_objet' => $id_objet, 'objet'=>$objet, $primary=>$id)); |
|
| 341 | - if ($e!==false) { |
|
| 342 | - $ins++; |
|
| 343 | - lien_propage_date_modif($objet,$id_objet); |
|
| 344 | - lien_propage_date_modif($objet_source,$id); |
|
| 345 | - // Envoyer aux plugins |
|
| 346 | - pipeline('post_edition_lien', |
|
| 347 | - array( |
|
| 348 | - 'args' => array( |
|
| 349 | - 'table_lien' => $table_lien, |
|
| 350 | - 'objet_source' => $objet_source, |
|
| 351 | - 'id_objet_source' => $id, |
|
| 352 | - 'objet' => $objet, |
|
| 353 | - 'id_objet' => $id_objet, |
|
| 354 | - 'action'=>'insert', |
|
| 355 | - ), |
|
| 356 | - 'data' => $id_objet |
|
| 357 | - ) |
|
| 358 | - ); |
|
| 359 | - } |
|
| 360 | - else |
|
| 361 | - $echec = true; |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - return ($echec?false:$ins); |
|
| 313 | + $ins = 0; |
|
| 314 | + $echec = null; |
|
| 315 | + foreach($objets as $objet => $id_objets){ |
|
| 316 | + if (!is_array($id_objets)) $id_objets = array($id_objets); |
|
| 317 | + foreach($id_objets as $id_objet) { |
|
| 318 | + $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 319 | + // Envoyer aux plugins |
|
| 320 | + $id_objet = pipeline('pre_edition_lien', |
|
| 321 | + array( |
|
| 322 | + 'args' => array( |
|
| 323 | + 'table_lien' => $table_lien, |
|
| 324 | + 'objet_source' => $objet_source, |
|
| 325 | + 'id_objet_source' => $id, |
|
| 326 | + 'objet' => $objet, |
|
| 327 | + 'id_objet' => $id_objet, |
|
| 328 | + 'action'=>'insert', |
|
| 329 | + ), |
|
| 330 | + 'data' => $id_objet |
|
| 331 | + ) |
|
| 332 | + ); |
|
| 333 | + if ($id_objet=intval($id_objet) |
|
| 334 | + AND !sql_getfetsel( |
|
| 335 | + $primary, |
|
| 336 | + $table_lien, |
|
| 337 | + array('id_objet='.intval($id_objet), 'objet='.sql_quote($objet), $primary.'='.intval($id)))) |
|
| 338 | + { |
|
| 339 | + |
|
| 340 | + $e = sql_insertq($table_lien, array('id_objet' => $id_objet, 'objet'=>$objet, $primary=>$id)); |
|
| 341 | + if ($e!==false) { |
|
| 342 | + $ins++; |
|
| 343 | + lien_propage_date_modif($objet,$id_objet); |
|
| 344 | + lien_propage_date_modif($objet_source,$id); |
|
| 345 | + // Envoyer aux plugins |
|
| 346 | + pipeline('post_edition_lien', |
|
| 347 | + array( |
|
| 348 | + 'args' => array( |
|
| 349 | + 'table_lien' => $table_lien, |
|
| 350 | + 'objet_source' => $objet_source, |
|
| 351 | + 'id_objet_source' => $id, |
|
| 352 | + 'objet' => $objet, |
|
| 353 | + 'id_objet' => $id_objet, |
|
| 354 | + 'action'=>'insert', |
|
| 355 | + ), |
|
| 356 | + 'data' => $id_objet |
|
| 357 | + ) |
|
| 358 | + ); |
|
| 359 | + } |
|
| 360 | + else |
|
| 361 | + $echec = true; |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + return ($echec?false:$ins); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -376,36 +376,36 @@ discard block |
||
| 376 | 376 | * @return array |
| 377 | 377 | */ |
| 378 | 378 | function lien_where($primary, $id_source, $objet, $id_objet){ |
| 379 | - if ((!is_array($id_source) AND !strlen($id_source)) |
|
| 380 | - OR !strlen($objet) |
|
| 381 | - OR (!is_array($id_objet) AND !strlen($id_objet))) |
|
| 382 | - return array("0=1"); // securite |
|
| 383 | - |
|
| 384 | - $not=""; |
|
| 385 | - if (is_array($id_source) AND reset($id_source)=="NOT"){ |
|
| 386 | - $not = array_shift($id_source); |
|
| 387 | - $id_source = reset($id_source); |
|
| 388 | - } |
|
| 389 | - $where = array(); |
|
| 390 | - if ($id_source!=='*') |
|
| 391 | - $where[] = (is_array($id_source)?sql_in(addslashes($primary),array_map('intval',$id_source),$not):addslashes($primary) . ($not?"<>":"=") . intval($id_source)); |
|
| 392 | - elseif ($not) |
|
| 393 | - $where[] = "0=1"; // idiot mais quand meme |
|
| 394 | - |
|
| 395 | - $not=""; |
|
| 396 | - if (is_array($id_objet) AND reset($id_objet)=="NOT"){ |
|
| 397 | - $not = array_shift($id_objet); |
|
| 398 | - $id_objet = reset($id_objet); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - if ($objet!=='*') |
|
| 402 | - $where[] = "objet=".sql_quote($objet); |
|
| 403 | - if ($id_objet!=='*') |
|
| 404 | - $where[] = (is_array($id_objet)?sql_in('id_objet',array_map('intval',$id_objet),$not):"id_objet" . ($not?"<>":"=") . intval($id_objet)); |
|
| 405 | - elseif ($not) |
|
| 406 | - $where[] = "0=1"; // idiot mais quand meme |
|
| 407 | - |
|
| 408 | - return $where; |
|
| 379 | + if ((!is_array($id_source) AND !strlen($id_source)) |
|
| 380 | + OR !strlen($objet) |
|
| 381 | + OR (!is_array($id_objet) AND !strlen($id_objet))) |
|
| 382 | + return array("0=1"); // securite |
|
| 383 | + |
|
| 384 | + $not=""; |
|
| 385 | + if (is_array($id_source) AND reset($id_source)=="NOT"){ |
|
| 386 | + $not = array_shift($id_source); |
|
| 387 | + $id_source = reset($id_source); |
|
| 388 | + } |
|
| 389 | + $where = array(); |
|
| 390 | + if ($id_source!=='*') |
|
| 391 | + $where[] = (is_array($id_source)?sql_in(addslashes($primary),array_map('intval',$id_source),$not):addslashes($primary) . ($not?"<>":"=") . intval($id_source)); |
|
| 392 | + elseif ($not) |
|
| 393 | + $where[] = "0=1"; // idiot mais quand meme |
|
| 394 | + |
|
| 395 | + $not=""; |
|
| 396 | + if (is_array($id_objet) AND reset($id_objet)=="NOT"){ |
|
| 397 | + $not = array_shift($id_objet); |
|
| 398 | + $id_objet = reset($id_objet); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + if ($objet!=='*') |
|
| 402 | + $where[] = "objet=".sql_quote($objet); |
|
| 403 | + if ($id_objet!=='*') |
|
| 404 | + $where[] = (is_array($id_objet)?sql_in('id_objet',array_map('intval',$id_objet),$not):"id_objet" . ($not?"<>":"=") . intval($id_objet)); |
|
| 405 | + elseif ($not) |
|
| 406 | + $where[] = "0=1"; // idiot mais quand meme |
|
| 407 | + |
|
| 408 | + return $where; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -426,65 +426,65 @@ discard block |
||
| 426 | 426 | * @return bool|int |
| 427 | 427 | */ |
| 428 | 428 | function lien_delete($objet_source,$primary,$table_lien,$id,$objets){ |
| 429 | - $retire = array(); |
|
| 430 | - $dels = 0; |
|
| 431 | - $echec = false; |
|
| 432 | - foreach($objets as $objet => $id_objets){ |
|
| 433 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 434 | - if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 435 | - foreach($id_objets as $id_objet) { |
|
| 436 | - // id_objet peut valoir '*' |
|
| 437 | - $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 438 | - // lire les liens existants pour propager la date de modif |
|
| 439 | - $liens = sql_allfetsel("$primary,id_objet,objet",$table_lien,$where); |
|
| 440 | - // iterer sur les liens pour permettre aux plugins de gerer |
|
| 441 | - foreach($liens as $l){ |
|
| 442 | - // Envoyer aux plugins |
|
| 443 | - $id_o = pipeline('pre_edition_lien', |
|
| 444 | - array( |
|
| 445 | - 'args' => array( |
|
| 446 | - 'table_lien' => $table_lien, |
|
| 447 | - 'objet_source' => $objet_source, |
|
| 448 | - 'id_objet_source' => $l[$primary], |
|
| 449 | - 'objet' => $l['objet'], |
|
| 450 | - 'id_objet' => $l['id_objet'], |
|
| 451 | - 'action'=>'delete', |
|
| 452 | - ), |
|
| 453 | - 'data' => $l['id_objet'] |
|
| 454 | - ) |
|
| 455 | - ); |
|
| 456 | - if ($id_o=intval($id_o)){ |
|
| 457 | - $where = lien_where($primary, $l[$primary], $l['objet'], $id_o); |
|
| 458 | - $e = sql_delete($table_lien, $where); |
|
| 459 | - if ($e!==false){ |
|
| 460 | - $dels+=$e; |
|
| 461 | - lien_propage_date_modif($l['objet'],$id_o); |
|
| 462 | - lien_propage_date_modif($objet_source,$l[$primary]); |
|
| 463 | - } |
|
| 464 | - else |
|
| 465 | - $echec = true; |
|
| 466 | - $retire[] = array('source'=>array($objet_source=>$l[$primary]),'lien'=>array($l['objet']=>$id_o),'type'=>$l['objet'],'id'=>$id_o); |
|
| 467 | - // Envoyer aux plugins |
|
| 468 | - pipeline('post_edition_lien', |
|
| 469 | - array( |
|
| 470 | - 'args' => array( |
|
| 471 | - 'table_lien' => $table_lien, |
|
| 472 | - 'objet_source' => $objet_source, |
|
| 473 | - 'id_objet_source' => $l[$primary], |
|
| 474 | - 'objet' => $l['objet'], |
|
| 475 | - 'id_objet' => $id_o, |
|
| 476 | - 'action'=>'delete', |
|
| 477 | - ), |
|
| 478 | - 'data' => $id_o |
|
| 479 | - ) |
|
| 480 | - ); |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - pipeline('trig_supprimer_objets_lies',$retire); |
|
| 486 | - |
|
| 487 | - return ($echec?false:$dels); |
|
| 429 | + $retire = array(); |
|
| 430 | + $dels = 0; |
|
| 431 | + $echec = false; |
|
| 432 | + foreach($objets as $objet => $id_objets){ |
|
| 433 | + $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 434 | + if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 435 | + foreach($id_objets as $id_objet) { |
|
| 436 | + // id_objet peut valoir '*' |
|
| 437 | + $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 438 | + // lire les liens existants pour propager la date de modif |
|
| 439 | + $liens = sql_allfetsel("$primary,id_objet,objet",$table_lien,$where); |
|
| 440 | + // iterer sur les liens pour permettre aux plugins de gerer |
|
| 441 | + foreach($liens as $l){ |
|
| 442 | + // Envoyer aux plugins |
|
| 443 | + $id_o = pipeline('pre_edition_lien', |
|
| 444 | + array( |
|
| 445 | + 'args' => array( |
|
| 446 | + 'table_lien' => $table_lien, |
|
| 447 | + 'objet_source' => $objet_source, |
|
| 448 | + 'id_objet_source' => $l[$primary], |
|
| 449 | + 'objet' => $l['objet'], |
|
| 450 | + 'id_objet' => $l['id_objet'], |
|
| 451 | + 'action'=>'delete', |
|
| 452 | + ), |
|
| 453 | + 'data' => $l['id_objet'] |
|
| 454 | + ) |
|
| 455 | + ); |
|
| 456 | + if ($id_o=intval($id_o)){ |
|
| 457 | + $where = lien_where($primary, $l[$primary], $l['objet'], $id_o); |
|
| 458 | + $e = sql_delete($table_lien, $where); |
|
| 459 | + if ($e!==false){ |
|
| 460 | + $dels+=$e; |
|
| 461 | + lien_propage_date_modif($l['objet'],$id_o); |
|
| 462 | + lien_propage_date_modif($objet_source,$l[$primary]); |
|
| 463 | + } |
|
| 464 | + else |
|
| 465 | + $echec = true; |
|
| 466 | + $retire[] = array('source'=>array($objet_source=>$l[$primary]),'lien'=>array($l['objet']=>$id_o),'type'=>$l['objet'],'id'=>$id_o); |
|
| 467 | + // Envoyer aux plugins |
|
| 468 | + pipeline('post_edition_lien', |
|
| 469 | + array( |
|
| 470 | + 'args' => array( |
|
| 471 | + 'table_lien' => $table_lien, |
|
| 472 | + 'objet_source' => $objet_source, |
|
| 473 | + 'id_objet_source' => $l[$primary], |
|
| 474 | + 'objet' => $l['objet'], |
|
| 475 | + 'id_objet' => $id_o, |
|
| 476 | + 'action'=>'delete', |
|
| 477 | + ), |
|
| 478 | + 'data' => $id_o |
|
| 479 | + ) |
|
| 480 | + ); |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + pipeline('trig_supprimer_objets_lies',$retire); |
|
| 486 | + |
|
| 487 | + return ($echec?false:$dels); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
@@ -507,51 +507,51 @@ discard block |
||
| 507 | 507 | * @return bool|int |
| 508 | 508 | */ |
| 509 | 509 | function lien_optimise($objet_source,$primary,$table_lien,$id,$objets){ |
| 510 | - include_spip('genie/optimiser'); |
|
| 511 | - $echec = false; |
|
| 512 | - $dels = 0; |
|
| 513 | - foreach($objets as $objet => $id_objets){ |
|
| 514 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 515 | - if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 516 | - foreach($id_objets as $id_objet) { |
|
| 517 | - $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 518 | - # les liens vers un objet inexistant |
|
| 519 | - $r = sql_select("DISTINCT objet",$table_lien,$where); |
|
| 520 | - while ($t = sql_fetch($r)){ |
|
| 521 | - $type = $t['objet']; |
|
| 522 | - $spip_table_objet = table_objet_sql($type); |
|
| 523 | - $id_table_objet = id_table_objet($type); |
|
| 524 | - $res = sql_select("L.$primary AS id,L.id_objet", |
|
| 525 | - // la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes |
|
| 526 | - // du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN |
|
| 527 | - // il faut les eliminier en repetant la condition dans le where L.objet='xxx' |
|
| 528 | - "$table_lien AS L |
|
| 510 | + include_spip('genie/optimiser'); |
|
| 511 | + $echec = false; |
|
| 512 | + $dels = 0; |
|
| 513 | + foreach($objets as $objet => $id_objets){ |
|
| 514 | + $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 515 | + if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 516 | + foreach($id_objets as $id_objet) { |
|
| 517 | + $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 518 | + # les liens vers un objet inexistant |
|
| 519 | + $r = sql_select("DISTINCT objet",$table_lien,$where); |
|
| 520 | + while ($t = sql_fetch($r)){ |
|
| 521 | + $type = $t['objet']; |
|
| 522 | + $spip_table_objet = table_objet_sql($type); |
|
| 523 | + $id_table_objet = id_table_objet($type); |
|
| 524 | + $res = sql_select("L.$primary AS id,L.id_objet", |
|
| 525 | + // la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes |
|
| 526 | + // du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN |
|
| 527 | + // il faut les eliminier en repetant la condition dans le where L.objet='xxx' |
|
| 528 | + "$table_lien AS L |
|
| 529 | 529 | LEFT JOIN $spip_table_objet AS O |
| 530 | 530 | ON (O.$id_table_objet=L.id_objet AND L.objet=".sql_quote($type).")", |
| 531 | - "L.objet=".sql_quote($type)." AND O.$id_table_objet IS NULL"); |
|
| 532 | - // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
|
| 533 | - while ($row = sql_fetch($res)){ |
|
| 534 | - $e = sql_delete($table_lien, array("$primary=".$row['id'],"id_objet=".$row['id_objet'],"objet=".sql_quote($type))); |
|
| 535 | - if ($e!=false){ |
|
| 536 | - $dels+=$e; |
|
| 537 | - spip_log("Entree ".$row['id']."/".$row['id_objet']."/$type supprimee dans la table $table_lien",_LOG_INFO_IMPORTANTE); |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - # les liens depuis un objet inexistant |
|
| 543 | - $table_source = table_objet_sql($objet_source); |
|
| 544 | - // filtrer selon $id, $objet, $id_objet eventuellement fournis |
|
| 545 | - // (en general '*' pour chaque) |
|
| 546 | - $where = lien_where("L.$primary", $id, $objet, $id_objet); |
|
| 547 | - $where[] = "O.$primary IS NULL"; |
|
| 548 | - $res = sql_select("L.$primary AS id", |
|
| 549 | - "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary", |
|
| 550 | - $where); |
|
| 551 | - $dels+= optimiser_sansref($table_lien, $primary, $res); |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - return ($echec?false:$dels); |
|
| 531 | + "L.objet=".sql_quote($type)." AND O.$id_table_objet IS NULL"); |
|
| 532 | + // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
|
| 533 | + while ($row = sql_fetch($res)){ |
|
| 534 | + $e = sql_delete($table_lien, array("$primary=".$row['id'],"id_objet=".$row['id_objet'],"objet=".sql_quote($type))); |
|
| 535 | + if ($e!=false){ |
|
| 536 | + $dels+=$e; |
|
| 537 | + spip_log("Entree ".$row['id']."/".$row['id_objet']."/$type supprimee dans la table $table_lien",_LOG_INFO_IMPORTANTE); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + # les liens depuis un objet inexistant |
|
| 543 | + $table_source = table_objet_sql($objet_source); |
|
| 544 | + // filtrer selon $id, $objet, $id_objet eventuellement fournis |
|
| 545 | + // (en general '*' pour chaque) |
|
| 546 | + $where = lien_where("L.$primary", $id, $objet, $id_objet); |
|
| 547 | + $where[] = "O.$primary IS NULL"; |
|
| 548 | + $res = sql_select("L.$primary AS id", |
|
| 549 | + "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary", |
|
| 550 | + $where); |
|
| 551 | + $dels+= optimiser_sansref($table_lien, $primary, $res); |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + return ($echec?false:$dels); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | |
@@ -577,31 +577,31 @@ discard block |
||
| 577 | 577 | * @return bool|int |
| 578 | 578 | */ |
| 579 | 579 | function lien_set($objet_source,$primary,$table_lien,$id,$objets,$qualif){ |
| 580 | - $echec = null; |
|
| 581 | - $ok = 0; |
|
| 582 | - if (!$qualif) |
|
| 583 | - return false; |
|
| 584 | - // nettoyer qualif qui peut venir directement d'un objet_trouver_lien : |
|
| 585 | - unset($qualif[$primary]); |
|
| 586 | - unset($qualif[$objet_source]); |
|
| 587 | - if (isset($qualif['objet'])) { |
|
| 588 | - unset($qualif[$qualif['objet']]); |
|
| 589 | - } |
|
| 590 | - unset($qualif['objet']); |
|
| 591 | - unset($qualif['id_objet']); |
|
| 592 | - foreach($objets as $objet => $id_objets){ |
|
| 593 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 594 | - if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 595 | - foreach($id_objets as $id_objet) { |
|
| 596 | - $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 597 | - $e = sql_updateq($table_lien,$qualif,$where); |
|
| 598 | - if ($e===false) |
|
| 599 | - $echec = true; |
|
| 600 | - else |
|
| 601 | - $ok++; |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - return ($echec?false:$ok); |
|
| 580 | + $echec = null; |
|
| 581 | + $ok = 0; |
|
| 582 | + if (!$qualif) |
|
| 583 | + return false; |
|
| 584 | + // nettoyer qualif qui peut venir directement d'un objet_trouver_lien : |
|
| 585 | + unset($qualif[$primary]); |
|
| 586 | + unset($qualif[$objet_source]); |
|
| 587 | + if (isset($qualif['objet'])) { |
|
| 588 | + unset($qualif[$qualif['objet']]); |
|
| 589 | + } |
|
| 590 | + unset($qualif['objet']); |
|
| 591 | + unset($qualif['id_objet']); |
|
| 592 | + foreach($objets as $objet => $id_objets){ |
|
| 593 | + $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 594 | + if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 595 | + foreach($id_objets as $id_objet) { |
|
| 596 | + $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 597 | + $e = sql_updateq($table_lien,$qualif,$where); |
|
| 598 | + if ($e===false) |
|
| 599 | + $echec = true; |
|
| 600 | + else |
|
| 601 | + $ok++; |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + return ($echec?false:$ok); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -623,20 +623,20 @@ discard block |
||
| 623 | 623 | * @return array |
| 624 | 624 | */ |
| 625 | 625 | function lien_find($objet_source,$primary,$table_lien,$id,$objets){ |
| 626 | - $trouve = array(); |
|
| 627 | - foreach($objets as $objet => $id_objets){ |
|
| 628 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 629 | - // lien_where prend en charge les $id_objets sous forme int ou array |
|
| 630 | - $where = lien_where($primary, $id, $objet, $id_objets); |
|
| 631 | - $liens = sql_allfetsel('*',$table_lien,$where); |
|
| 632 | - // ajouter les entrees objet_source et objet cible par convenance |
|
| 633 | - foreach($liens as $l) { |
|
| 634 | - $l[$objet_source] = $l[$primary]; |
|
| 635 | - $l[$objet] = $l['id_objet']; |
|
| 636 | - $trouve[] = $l; |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - return $trouve; |
|
| 626 | + $trouve = array(); |
|
| 627 | + foreach($objets as $objet => $id_objets){ |
|
| 628 | + $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 629 | + // lien_where prend en charge les $id_objets sous forme int ou array |
|
| 630 | + $where = lien_where($primary, $id, $objet, $id_objets); |
|
| 631 | + $liens = sql_allfetsel('*',$table_lien,$where); |
|
| 632 | + // ajouter les entrees objet_source et objet cible par convenance |
|
| 633 | + foreach($liens as $l) { |
|
| 634 | + $l[$objet_source] = $l[$primary]; |
|
| 635 | + $l[$objet] = $l['id_objet']; |
|
| 636 | + $trouve[] = $l; |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + return $trouve; |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | /** |
@@ -647,14 +647,14 @@ discard block |
||
| 647 | 647 | * @param array|int $ids |
| 648 | 648 | */ |
| 649 | 649 | function lien_propage_date_modif($objet,$ids){ |
| 650 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 651 | - |
|
| 652 | - $table = table_objet_sql($objet); |
|
| 653 | - if ($desc = $trouver_table($table) |
|
| 654 | - AND isset($desc['field']['date_modif'])){ |
|
| 655 | - $primary = id_table_objet($objet); |
|
| 656 | - $where = (is_array($ids)?sql_in($primary, array_map('intval',$ids)):"$primary=".intval($ids)); |
|
| 657 | - sql_updateq($table, array('date_modif'=>date('Y-m-d H:i:s')), $where); |
|
| 658 | - } |
|
| 650 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 651 | + |
|
| 652 | + $table = table_objet_sql($objet); |
|
| 653 | + if ($desc = $trouver_table($table) |
|
| 654 | + AND isset($desc['field']['date_modif'])){ |
|
| 655 | + $primary = id_table_objet($objet); |
|
| 656 | + $where = (is_array($ids)?sql_in($primary, array_map('intval',$ids)):"$primary=".intval($ids)); |
|
| 657 | + sql_updateq($table, array('date_modif'=>date('Y-m-d H:i:s')), $where); |
|
| 658 | + } |
|
| 659 | 659 | } |
| 660 | 660 | ?> |
@@ -16,7 +16,9 @@ discard block |
||
| 16 | 16 | * @package SPIP\Liens\API |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 19 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 20 | + return; |
|
| 21 | +} |
|
| 20 | 22 | |
| 21 | 23 | |
| 22 | 24 | |
@@ -39,8 +41,9 @@ discard block |
||
| 39 | 41 | if ($primary = id_table_objet($objet) |
| 40 | 42 | AND $trouver_table($l = $table_sql."_liens") |
| 41 | 43 | AND !preg_match(',[^\w],',$primary) |
| 42 | - AND !preg_match(',[^\w],',$l)) |
|
| 43 | - return array($primary,$l); |
|
| 44 | + AND !preg_match(',[^\w],',$l)) { |
|
| 45 | + return array($primary,$l); |
|
| 46 | + } |
|
| 44 | 47 | |
| 45 | 48 | spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
| 46 | 49 | return false; |
@@ -71,8 +74,9 @@ discard block |
||
| 71 | 74 | function objet_associer($objets_source, $objets_lies, $qualif = null){ |
| 72 | 75 | $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies); |
| 73 | 76 | |
| 74 | - if ($qualif) |
|
| 75 | - objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 77 | + if ($qualif) { |
|
| 78 | + objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 79 | + } |
|
| 76 | 80 | |
| 77 | 81 | return $modifs; // pas d'erreur |
| 78 | 82 | } |
@@ -218,8 +222,7 @@ discard block |
||
| 218 | 222 | $n++; |
| 219 | 223 | if ($infos['type']==$objet){ |
| 220 | 224 | objet_associer(array($objet=>$id_cible),array($lien['objet']=>$lien[$lien['objet']]),$lien); |
| 221 | - } |
|
| 222 | - else { |
|
| 225 | + } else { |
|
| 223 | 226 | objet_associer(array($infos['type']=>$lien[$infos['type']]),array($objet=>$id_cible),$lien); |
| 224 | 227 | } |
| 225 | 228 | } |
@@ -259,15 +262,17 @@ discard block |
||
| 259 | 262 | */ |
| 260 | 263 | function objet_traiter_liaisons($operation,$objets_source,$objets_lies, $set = null){ |
| 261 | 264 | // accepter une syntaxe minimale pour supprimer tous les liens |
| 262 | - if ($objets_lies=='*') $objets_lies = array('*'=>'*'); |
|
| 265 | + if ($objets_lies=='*') { |
|
| 266 | + $objets_lies = array('*'=>'*'); |
|
| 267 | + } |
|
| 263 | 268 | $modifs = 0; // compter le nombre de modifications |
| 264 | 269 | $echec = null; |
| 265 | 270 | foreach($objets_source as $objet=>$ids){ |
| 266 | 271 | if ($a = objet_associable($objet)) { |
| 267 | 272 | list($primary,$l) = $a; |
| 268 | - if (!is_array($ids)) |
|
| 269 | - $ids = array($ids); |
|
| 270 | - elseif(reset($ids)=="NOT"){ |
|
| 273 | + if (!is_array($ids)) { |
|
| 274 | + $ids = array($ids); |
|
| 275 | + } elseif(reset($ids)=="NOT"){ |
|
| 271 | 276 | // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
| 272 | 277 | $where = lien_where($primary,$ids,'*','*'); |
| 273 | 278 | $ids = sql_allfetsel($primary,$l,$where); |
@@ -278,13 +283,13 @@ discard block |
||
| 278 | 283 | if ($res===false) { |
| 279 | 284 | spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id",_LOG_ERREUR); |
| 280 | 285 | $echec = true; |
| 286 | + } else { |
|
| 287 | + $modifs=($modifs?(is_array($res)?array_merge($modifs,$res):$modifs+$res):$res); |
|
| 281 | 288 | } |
| 282 | - else |
|
| 283 | - $modifs=($modifs?(is_array($res)?array_merge($modifs,$res):$modifs+$res):$res); |
|
| 284 | 289 | } |
| 290 | + } else { |
|
| 291 | + $echec = true; |
|
| 285 | 292 | } |
| 286 | - else |
|
| 287 | - $echec = true; |
|
| 288 | 293 | } |
| 289 | 294 | |
| 290 | 295 | return ($echec?false:$modifs); // pas d'erreur |
@@ -313,7 +318,9 @@ discard block |
||
| 313 | 318 | $ins = 0; |
| 314 | 319 | $echec = null; |
| 315 | 320 | foreach($objets as $objet => $id_objets){ |
| 316 | - if (!is_array($id_objets)) $id_objets = array($id_objets); |
|
| 321 | + if (!is_array($id_objets)) { |
|
| 322 | + $id_objets = array($id_objets); |
|
| 323 | + } |
|
| 317 | 324 | foreach($id_objets as $id_objet) { |
| 318 | 325 | $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
| 319 | 326 | // Envoyer aux plugins |
@@ -356,9 +363,9 @@ discard block |
||
| 356 | 363 | 'data' => $id_objet |
| 357 | 364 | ) |
| 358 | 365 | ); |
| 366 | + } else { |
|
| 367 | + $echec = true; |
|
| 359 | 368 | } |
| 360 | - else |
|
| 361 | - $echec = true; |
|
| 362 | 369 | } |
| 363 | 370 | } |
| 364 | 371 | } |
@@ -378,8 +385,10 @@ discard block |
||
| 378 | 385 | function lien_where($primary, $id_source, $objet, $id_objet){ |
| 379 | 386 | if ((!is_array($id_source) AND !strlen($id_source)) |
| 380 | 387 | OR !strlen($objet) |
| 381 | - OR (!is_array($id_objet) AND !strlen($id_objet))) |
|
| 382 | - return array("0=1"); // securite |
|
| 388 | + OR (!is_array($id_objet) AND !strlen($id_objet))) { |
|
| 389 | + return array("0=1"); |
|
| 390 | + } |
|
| 391 | + // securite |
|
| 383 | 392 | |
| 384 | 393 | $not=""; |
| 385 | 394 | if (is_array($id_source) AND reset($id_source)=="NOT"){ |
@@ -387,10 +396,12 @@ discard block |
||
| 387 | 396 | $id_source = reset($id_source); |
| 388 | 397 | } |
| 389 | 398 | $where = array(); |
| 390 | - if ($id_source!=='*') |
|
| 391 | - $where[] = (is_array($id_source)?sql_in(addslashes($primary),array_map('intval',$id_source),$not):addslashes($primary) . ($not?"<>":"=") . intval($id_source)); |
|
| 392 | - elseif ($not) |
|
| 393 | - $where[] = "0=1"; // idiot mais quand meme |
|
| 399 | + if ($id_source!=='*') { |
|
| 400 | + $where[] = (is_array($id_source)?sql_in(addslashes($primary),array_map('intval',$id_source),$not):addslashes($primary) . ($not?"<>":"=") . intval($id_source)); |
|
| 401 | + } elseif ($not) { |
|
| 402 | + $where[] = "0=1"; |
|
| 403 | + } |
|
| 404 | + // idiot mais quand meme |
|
| 394 | 405 | |
| 395 | 406 | $not=""; |
| 396 | 407 | if (is_array($id_objet) AND reset($id_objet)=="NOT"){ |
@@ -398,12 +409,15 @@ discard block |
||
| 398 | 409 | $id_objet = reset($id_objet); |
| 399 | 410 | } |
| 400 | 411 | |
| 401 | - if ($objet!=='*') |
|
| 402 | - $where[] = "objet=".sql_quote($objet); |
|
| 403 | - if ($id_objet!=='*') |
|
| 404 | - $where[] = (is_array($id_objet)?sql_in('id_objet',array_map('intval',$id_objet),$not):"id_objet" . ($not?"<>":"=") . intval($id_objet)); |
|
| 405 | - elseif ($not) |
|
| 406 | - $where[] = "0=1"; // idiot mais quand meme |
|
| 412 | + if ($objet!=='*') { |
|
| 413 | + $where[] = "objet=".sql_quote($objet); |
|
| 414 | + } |
|
| 415 | + if ($id_objet!=='*') { |
|
| 416 | + $where[] = (is_array($id_objet)?sql_in('id_objet',array_map('intval',$id_objet),$not):"id_objet" . ($not?"<>":"=") . intval($id_objet)); |
|
| 417 | + } elseif ($not) { |
|
| 418 | + $where[] = "0=1"; |
|
| 419 | + } |
|
| 420 | + // idiot mais quand meme |
|
| 407 | 421 | |
| 408 | 422 | return $where; |
| 409 | 423 | } |
@@ -431,7 +445,9 @@ discard block |
||
| 431 | 445 | $echec = false; |
| 432 | 446 | foreach($objets as $objet => $id_objets){ |
| 433 | 447 | $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
| 434 | - if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 448 | + if (!is_array($id_objets) OR reset($id_objets)=="NOT") { |
|
| 449 | + $id_objets = array($id_objets); |
|
| 450 | + } |
|
| 435 | 451 | foreach($id_objets as $id_objet) { |
| 436 | 452 | // id_objet peut valoir '*' |
| 437 | 453 | $where = lien_where($primary, $id, $objet, $id_objet); |
@@ -460,9 +476,9 @@ discard block |
||
| 460 | 476 | $dels+=$e; |
| 461 | 477 | lien_propage_date_modif($l['objet'],$id_o); |
| 462 | 478 | lien_propage_date_modif($objet_source,$l[$primary]); |
| 479 | + } else { |
|
| 480 | + $echec = true; |
|
| 463 | 481 | } |
| 464 | - else |
|
| 465 | - $echec = true; |
|
| 466 | 482 | $retire[] = array('source'=>array($objet_source=>$l[$primary]),'lien'=>array($l['objet']=>$id_o),'type'=>$l['objet'],'id'=>$id_o); |
| 467 | 483 | // Envoyer aux plugins |
| 468 | 484 | pipeline('post_edition_lien', |
@@ -512,7 +528,9 @@ discard block |
||
| 512 | 528 | $dels = 0; |
| 513 | 529 | foreach($objets as $objet => $id_objets){ |
| 514 | 530 | $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
| 515 | - if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 531 | + if (!is_array($id_objets) OR reset($id_objets)=="NOT") { |
|
| 532 | + $id_objets = array($id_objets); |
|
| 533 | + } |
|
| 516 | 534 | foreach($id_objets as $id_objet) { |
| 517 | 535 | $where = lien_where($primary, $id, $objet, $id_objet); |
| 518 | 536 | # les liens vers un objet inexistant |
@@ -579,8 +597,9 @@ discard block |
||
| 579 | 597 | function lien_set($objet_source,$primary,$table_lien,$id,$objets,$qualif){ |
| 580 | 598 | $echec = null; |
| 581 | 599 | $ok = 0; |
| 582 | - if (!$qualif) |
|
| 583 | - return false; |
|
| 600 | + if (!$qualif) { |
|
| 601 | + return false; |
|
| 602 | + } |
|
| 584 | 603 | // nettoyer qualif qui peut venir directement d'un objet_trouver_lien : |
| 585 | 604 | unset($qualif[$primary]); |
| 586 | 605 | unset($qualif[$objet_source]); |
@@ -591,14 +610,17 @@ discard block |
||
| 591 | 610 | unset($qualif['id_objet']); |
| 592 | 611 | foreach($objets as $objet => $id_objets){ |
| 593 | 612 | $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
| 594 | - if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 613 | + if (!is_array($id_objets) OR reset($id_objets)=="NOT") { |
|
| 614 | + $id_objets = array($id_objets); |
|
| 615 | + } |
|
| 595 | 616 | foreach($id_objets as $id_objet) { |
| 596 | 617 | $where = lien_where($primary, $id, $objet, $id_objet); |
| 597 | 618 | $e = sql_updateq($table_lien,$qualif,$where); |
| 598 | - if ($e===false) |
|
| 599 | - $echec = true; |
|
| 600 | - else |
|
| 601 | - $ok++; |
|
| 619 | + if ($e===false) { |
|
| 620 | + $echec = true; |
|
| 621 | + } else { |
|
| 622 | + $ok++; |
|
| 623 | + } |
|
| 602 | 624 | } |
| 603 | 625 | } |
| 604 | 626 | return ($echec?false:$ok); |
@@ -31,16 +31,16 @@ discard block |
||
| 31 | 31 | * - false si l'objet n'est pas associable. |
| 32 | 32 | * - array(clé primaire, nom de la table de lien) si associable |
| 33 | 33 | */ |
| 34 | -function objet_associable($objet){ |
|
| 35 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 34 | +function objet_associable($objet) { |
|
| 35 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 36 | 36 | $table_sql = table_objet_sql($objet); |
| 37 | 37 | |
| 38 | - $l=""; |
|
| 38 | + $l = ""; |
|
| 39 | 39 | if ($primary = id_table_objet($objet) |
| 40 | 40 | AND $trouver_table($l = $table_sql."_liens") |
| 41 | - AND !preg_match(',[^\w],',$primary) |
|
| 42 | - AND !preg_match(',[^\w],',$l)) |
|
| 43 | - return array($primary,$l); |
|
| 41 | + AND !preg_match(',[^\w],', $primary) |
|
| 42 | + AND !preg_match(',[^\w],', $l)) |
|
| 43 | + return array($primary, $l); |
|
| 44 | 44 | |
| 45 | 45 | spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
| 46 | 46 | return false; |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @param array $qualif |
| 69 | 69 | * @return bool|int |
| 70 | 70 | */ |
| 71 | -function objet_associer($objets_source, $objets_lies, $qualif = null){ |
|
| 71 | +function objet_associer($objets_source, $objets_lies, $qualif = null) { |
|
| 72 | 72 | $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies); |
| 73 | 73 | |
| 74 | 74 | if ($qualif) |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | * @param array|string $objets_lies |
| 98 | 98 | * @return bool|int |
| 99 | 99 | */ |
| 100 | -function objet_dissocier($objets_source,$objets_lies){ |
|
| 101 | - return objet_traiter_liaisons('lien_delete',$objets_source,$objets_lies); |
|
| 100 | +function objet_dissocier($objets_source, $objets_lies) { |
|
| 101 | + return objet_traiter_liaisons('lien_delete', $objets_source, $objets_lies); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | * @param array $qualif |
| 124 | 124 | * @return bool|int |
| 125 | 125 | */ |
| 126 | -function objet_qualifier_liens($objets_source,$objets_lies,$qualif){ |
|
| 127 | - return objet_traiter_liaisons('lien_set',$objets_source,$objets_lies,$qualif); |
|
| 126 | +function objet_qualifier_liens($objets_source, $objets_lies, $qualif) { |
|
| 127 | + return objet_traiter_liaisons('lien_set', $objets_source, $objets_lies, $qualif); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | * @param array|string $objets_lies |
| 157 | 157 | * @return array |
| 158 | 158 | */ |
| 159 | -function objet_trouver_liens($objets_source,$objets_lies){ |
|
| 160 | - return objet_traiter_liaisons('lien_find',$objets_source,$objets_lies); |
|
| 159 | +function objet_trouver_liens($objets_source, $objets_lies) { |
|
| 160 | + return objet_traiter_liaisons('lien_find', $objets_source, $objets_lies); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | * @param array|string $objets_lies |
| 181 | 181 | * @return int |
| 182 | 182 | */ |
| 183 | -function objet_optimiser_liens($objets_source,$objets_lies){ |
|
| 184 | - return objet_traiter_liaisons('lien_optimise',$objets_source,$objets_lies); |
|
| 183 | +function objet_optimiser_liens($objets_source, $objets_lies) { |
|
| 184 | + return objet_traiter_liaisons('lien_optimise', $objets_source, $objets_lies); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
@@ -200,27 +200,27 @@ discard block |
||
| 200 | 200 | * @return int |
| 201 | 201 | * Nombre de liens copiés |
| 202 | 202 | */ |
| 203 | -function objet_dupliquer_liens($objet,$id_source,$id_cible,$types=null,$exclure_types=null){ |
|
| 203 | +function objet_dupliquer_liens($objet, $id_source, $id_cible, $types = null, $exclure_types = null) { |
|
| 204 | 204 | include_spip('base/objets'); |
| 205 | 205 | $tables = lister_tables_objets_sql(); |
| 206 | 206 | $n = 0; |
| 207 | - foreach($tables as $table_sql => $infos){ |
|
| 207 | + foreach ($tables as $table_sql => $infos) { |
|
| 208 | 208 | if ( |
| 209 | - (is_null($types) OR in_array($infos['type'],$types)) |
|
| 210 | - AND (is_null($exclure_types) OR !in_array($infos['type'],$exclure_types)) |
|
| 211 | - ){ |
|
| 212 | - if (objet_associable($infos['type'])){ |
|
| 213 | - $liens = (($infos['type']==$objet)? |
|
| 214 | - objet_trouver_liens(array($objet=>$id_source),'*') |
|
| 209 | + (is_null($types) OR in_array($infos['type'], $types)) |
|
| 210 | + AND (is_null($exclure_types) OR !in_array($infos['type'], $exclure_types)) |
|
| 211 | + ) { |
|
| 212 | + if (objet_associable($infos['type'])) { |
|
| 213 | + $liens = (($infos['type'] == $objet) ? |
|
| 214 | + objet_trouver_liens(array($objet=>$id_source), '*') |
|
| 215 | 215 | : |
| 216 | - objet_trouver_liens(array($infos['type']=>'*'),array($objet=>$id_source))); |
|
| 217 | - foreach($liens as $lien){ |
|
| 216 | + objet_trouver_liens(array($infos['type']=>'*'), array($objet=>$id_source))); |
|
| 217 | + foreach ($liens as $lien) { |
|
| 218 | 218 | $n++; |
| 219 | - if ($infos['type']==$objet){ |
|
| 220 | - objet_associer(array($objet=>$id_cible),array($lien['objet']=>$lien[$lien['objet']]),$lien); |
|
| 219 | + if ($infos['type'] == $objet) { |
|
| 220 | + objet_associer(array($objet=>$id_cible), array($lien['objet']=>$lien[$lien['objet']]), $lien); |
|
| 221 | 221 | } |
| 222 | 222 | else { |
| 223 | - objet_associer(array($infos['type']=>$lien[$infos['type']]),array($objet=>$id_cible),$lien); |
|
| 223 | + objet_associer(array($infos['type']=>$lien[$infos['type']]), array($objet=>$id_cible), $lien); |
|
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -257,37 +257,37 @@ discard block |
||
| 257 | 257 | * @param array $set |
| 258 | 258 | * @return bool|int|array |
| 259 | 259 | */ |
| 260 | -function objet_traiter_liaisons($operation,$objets_source,$objets_lies, $set = null){ |
|
| 260 | +function objet_traiter_liaisons($operation, $objets_source, $objets_lies, $set = null) { |
|
| 261 | 261 | // accepter une syntaxe minimale pour supprimer tous les liens |
| 262 | - if ($objets_lies=='*') $objets_lies = array('*'=>'*'); |
|
| 262 | + if ($objets_lies == '*') $objets_lies = array('*'=>'*'); |
|
| 263 | 263 | $modifs = 0; // compter le nombre de modifications |
| 264 | 264 | $echec = null; |
| 265 | - foreach($objets_source as $objet=>$ids){ |
|
| 265 | + foreach ($objets_source as $objet=>$ids) { |
|
| 266 | 266 | if ($a = objet_associable($objet)) { |
| 267 | - list($primary,$l) = $a; |
|
| 267 | + list($primary, $l) = $a; |
|
| 268 | 268 | if (!is_array($ids)) |
| 269 | 269 | $ids = array($ids); |
| 270 | - elseif(reset($ids)=="NOT"){ |
|
| 270 | + elseif (reset($ids) == "NOT") { |
|
| 271 | 271 | // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
| 272 | - $where = lien_where($primary,$ids,'*','*'); |
|
| 273 | - $ids = sql_allfetsel($primary,$l,$where); |
|
| 274 | - $ids = array_map('reset',$ids); |
|
| 272 | + $where = lien_where($primary, $ids, '*', '*'); |
|
| 273 | + $ids = sql_allfetsel($primary, $l, $where); |
|
| 274 | + $ids = array_map('reset', $ids); |
|
| 275 | 275 | } |
| 276 | - foreach($ids as $id) { |
|
| 277 | - $res = $operation($objet,$primary,$l,$id,$objets_lies,$set); |
|
| 278 | - if ($res===false) { |
|
| 279 | - spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id",_LOG_ERREUR); |
|
| 276 | + foreach ($ids as $id) { |
|
| 277 | + $res = $operation($objet, $primary, $l, $id, $objets_lies, $set); |
|
| 278 | + if ($res === false) { |
|
| 279 | + spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id", _LOG_ERREUR); |
|
| 280 | 280 | $echec = true; |
| 281 | 281 | } |
| 282 | 282 | else |
| 283 | - $modifs=($modifs?(is_array($res)?array_merge($modifs,$res):$modifs+$res):$res); |
|
| 283 | + $modifs = ($modifs ? (is_array($res) ?array_merge($modifs, $res) : $modifs + $res) : $res); |
|
| 284 | 284 | } |
| 285 | 285 | } |
| 286 | 286 | else |
| 287 | 287 | $echec = true; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - return ($echec?false:$modifs); // pas d'erreur |
|
| 290 | + return ($echec ?false:$modifs); // pas d'erreur |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | * @param array $objets |
| 310 | 310 | * @return bool|int |
| 311 | 311 | */ |
| 312 | -function lien_insert($objet_source,$primary,$table_lien,$id,$objets) { |
|
| 312 | +function lien_insert($objet_source, $primary, $table_lien, $id, $objets) { |
|
| 313 | 313 | $ins = 0; |
| 314 | 314 | $echec = null; |
| 315 | - foreach($objets as $objet => $id_objets){ |
|
| 315 | + foreach ($objets as $objet => $id_objets) { |
|
| 316 | 316 | if (!is_array($id_objets)) $id_objets = array($id_objets); |
| 317 | - foreach($id_objets as $id_objet) { |
|
| 318 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 317 | + foreach ($id_objets as $id_objet) { |
|
| 318 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 319 | 319 | // Envoyer aux plugins |
| 320 | 320 | $id_objet = pipeline('pre_edition_lien', |
| 321 | 321 | array( |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | 'data' => $id_objet |
| 331 | 331 | ) |
| 332 | 332 | ); |
| 333 | - if ($id_objet=intval($id_objet) |
|
| 333 | + if ($id_objet = intval($id_objet) |
|
| 334 | 334 | AND !sql_getfetsel( |
| 335 | 335 | $primary, |
| 336 | 336 | $table_lien, |
@@ -338,10 +338,10 @@ discard block |
||
| 338 | 338 | { |
| 339 | 339 | |
| 340 | 340 | $e = sql_insertq($table_lien, array('id_objet' => $id_objet, 'objet'=>$objet, $primary=>$id)); |
| 341 | - if ($e!==false) { |
|
| 341 | + if ($e !== false) { |
|
| 342 | 342 | $ins++; |
| 343 | - lien_propage_date_modif($objet,$id_objet); |
|
| 344 | - lien_propage_date_modif($objet_source,$id); |
|
| 343 | + lien_propage_date_modif($objet, $id_objet); |
|
| 344 | + lien_propage_date_modif($objet_source, $id); |
|
| 345 | 345 | // Envoyer aux plugins |
| 346 | 346 | pipeline('post_edition_lien', |
| 347 | 347 | array( |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | - return ($echec?false:$ins); |
|
| 365 | + return ($echec ?false:$ins); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -375,33 +375,33 @@ discard block |
||
| 375 | 375 | * @param int|string|array $id_objet |
| 376 | 376 | * @return array |
| 377 | 377 | */ |
| 378 | -function lien_where($primary, $id_source, $objet, $id_objet){ |
|
| 378 | +function lien_where($primary, $id_source, $objet, $id_objet) { |
|
| 379 | 379 | if ((!is_array($id_source) AND !strlen($id_source)) |
| 380 | 380 | OR !strlen($objet) |
| 381 | 381 | OR (!is_array($id_objet) AND !strlen($id_objet))) |
| 382 | 382 | return array("0=1"); // securite |
| 383 | 383 | |
| 384 | - $not=""; |
|
| 385 | - if (is_array($id_source) AND reset($id_source)=="NOT"){ |
|
| 384 | + $not = ""; |
|
| 385 | + if (is_array($id_source) AND reset($id_source) == "NOT") { |
|
| 386 | 386 | $not = array_shift($id_source); |
| 387 | 387 | $id_source = reset($id_source); |
| 388 | 388 | } |
| 389 | 389 | $where = array(); |
| 390 | - if ($id_source!=='*') |
|
| 391 | - $where[] = (is_array($id_source)?sql_in(addslashes($primary),array_map('intval',$id_source),$not):addslashes($primary) . ($not?"<>":"=") . intval($id_source)); |
|
| 390 | + if ($id_source !== '*') |
|
| 391 | + $where[] = (is_array($id_source) ?sql_in(addslashes($primary), array_map('intval', $id_source), $not) : addslashes($primary).($not ? "<>" : "=").intval($id_source)); |
|
| 392 | 392 | elseif ($not) |
| 393 | 393 | $where[] = "0=1"; // idiot mais quand meme |
| 394 | 394 | |
| 395 | - $not=""; |
|
| 396 | - if (is_array($id_objet) AND reset($id_objet)=="NOT"){ |
|
| 395 | + $not = ""; |
|
| 396 | + if (is_array($id_objet) AND reset($id_objet) == "NOT") { |
|
| 397 | 397 | $not = array_shift($id_objet); |
| 398 | 398 | $id_objet = reset($id_objet); |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - if ($objet!=='*') |
|
| 401 | + if ($objet !== '*') |
|
| 402 | 402 | $where[] = "objet=".sql_quote($objet); |
| 403 | - if ($id_objet!=='*') |
|
| 404 | - $where[] = (is_array($id_objet)?sql_in('id_objet',array_map('intval',$id_objet),$not):"id_objet" . ($not?"<>":"=") . intval($id_objet)); |
|
| 403 | + if ($id_objet !== '*') |
|
| 404 | + $where[] = (is_array($id_objet) ?sql_in('id_objet', array_map('intval', $id_objet), $not) : "id_objet".($not ? "<>" : "=").intval($id_objet)); |
|
| 405 | 405 | elseif ($not) |
| 406 | 406 | $where[] = "0=1"; // idiot mais quand meme |
| 407 | 407 | |
@@ -425,20 +425,20 @@ discard block |
||
| 425 | 425 | * @param array $objets |
| 426 | 426 | * @return bool|int |
| 427 | 427 | */ |
| 428 | -function lien_delete($objet_source,$primary,$table_lien,$id,$objets){ |
|
| 428 | +function lien_delete($objet_source, $primary, $table_lien, $id, $objets) { |
|
| 429 | 429 | $retire = array(); |
| 430 | 430 | $dels = 0; |
| 431 | 431 | $echec = false; |
| 432 | - foreach($objets as $objet => $id_objets){ |
|
| 433 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 434 | - if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 435 | - foreach($id_objets as $id_objet) { |
|
| 432 | + foreach ($objets as $objet => $id_objets) { |
|
| 433 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 434 | + if (!is_array($id_objets) OR reset($id_objets) == "NOT") $id_objets = array($id_objets); |
|
| 435 | + foreach ($id_objets as $id_objet) { |
|
| 436 | 436 | // id_objet peut valoir '*' |
| 437 | 437 | $where = lien_where($primary, $id, $objet, $id_objet); |
| 438 | 438 | // lire les liens existants pour propager la date de modif |
| 439 | - $liens = sql_allfetsel("$primary,id_objet,objet",$table_lien,$where); |
|
| 439 | + $liens = sql_allfetsel("$primary,id_objet,objet", $table_lien, $where); |
|
| 440 | 440 | // iterer sur les liens pour permettre aux plugins de gerer |
| 441 | - foreach($liens as $l){ |
|
| 441 | + foreach ($liens as $l) { |
|
| 442 | 442 | // Envoyer aux plugins |
| 443 | 443 | $id_o = pipeline('pre_edition_lien', |
| 444 | 444 | array( |
@@ -453,17 +453,17 @@ discard block |
||
| 453 | 453 | 'data' => $l['id_objet'] |
| 454 | 454 | ) |
| 455 | 455 | ); |
| 456 | - if ($id_o=intval($id_o)){ |
|
| 456 | + if ($id_o = intval($id_o)) { |
|
| 457 | 457 | $where = lien_where($primary, $l[$primary], $l['objet'], $id_o); |
| 458 | 458 | $e = sql_delete($table_lien, $where); |
| 459 | - if ($e!==false){ |
|
| 460 | - $dels+=$e; |
|
| 461 | - lien_propage_date_modif($l['objet'],$id_o); |
|
| 462 | - lien_propage_date_modif($objet_source,$l[$primary]); |
|
| 459 | + if ($e !== false) { |
|
| 460 | + $dels += $e; |
|
| 461 | + lien_propage_date_modif($l['objet'], $id_o); |
|
| 462 | + lien_propage_date_modif($objet_source, $l[$primary]); |
|
| 463 | 463 | } |
| 464 | 464 | else |
| 465 | 465 | $echec = true; |
| 466 | - $retire[] = array('source'=>array($objet_source=>$l[$primary]),'lien'=>array($l['objet']=>$id_o),'type'=>$l['objet'],'id'=>$id_o); |
|
| 466 | + $retire[] = array('source'=>array($objet_source=>$l[$primary]), 'lien'=>array($l['objet']=>$id_o), 'type'=>$l['objet'], 'id'=>$id_o); |
|
| 467 | 467 | // Envoyer aux plugins |
| 468 | 468 | pipeline('post_edition_lien', |
| 469 | 469 | array( |
@@ -482,9 +482,9 @@ discard block |
||
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | - pipeline('trig_supprimer_objets_lies',$retire); |
|
| 485 | + pipeline('trig_supprimer_objets_lies', $retire); |
|
| 486 | 486 | |
| 487 | - return ($echec?false:$dels); |
|
| 487 | + return ($echec ?false:$dels); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
@@ -506,18 +506,18 @@ discard block |
||
| 506 | 506 | * @param array $objets |
| 507 | 507 | * @return bool|int |
| 508 | 508 | */ |
| 509 | -function lien_optimise($objet_source,$primary,$table_lien,$id,$objets){ |
|
| 509 | +function lien_optimise($objet_source, $primary, $table_lien, $id, $objets) { |
|
| 510 | 510 | include_spip('genie/optimiser'); |
| 511 | 511 | $echec = false; |
| 512 | 512 | $dels = 0; |
| 513 | - foreach($objets as $objet => $id_objets){ |
|
| 514 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 515 | - if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 516 | - foreach($id_objets as $id_objet) { |
|
| 513 | + foreach ($objets as $objet => $id_objets) { |
|
| 514 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 515 | + if (!is_array($id_objets) OR reset($id_objets) == "NOT") $id_objets = array($id_objets); |
|
| 516 | + foreach ($id_objets as $id_objet) { |
|
| 517 | 517 | $where = lien_where($primary, $id, $objet, $id_objet); |
| 518 | 518 | # les liens vers un objet inexistant |
| 519 | - $r = sql_select("DISTINCT objet",$table_lien,$where); |
|
| 520 | - while ($t = sql_fetch($r)){ |
|
| 519 | + $r = sql_select("DISTINCT objet", $table_lien, $where); |
|
| 520 | + while ($t = sql_fetch($r)) { |
|
| 521 | 521 | $type = $t['objet']; |
| 522 | 522 | $spip_table_objet = table_objet_sql($type); |
| 523 | 523 | $id_table_objet = id_table_objet($type); |
@@ -530,11 +530,11 @@ discard block |
||
| 530 | 530 | ON (O.$id_table_objet=L.id_objet AND L.objet=".sql_quote($type).")", |
| 531 | 531 | "L.objet=".sql_quote($type)." AND O.$id_table_objet IS NULL"); |
| 532 | 532 | // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
| 533 | - while ($row = sql_fetch($res)){ |
|
| 534 | - $e = sql_delete($table_lien, array("$primary=".$row['id'],"id_objet=".$row['id_objet'],"objet=".sql_quote($type))); |
|
| 535 | - if ($e!=false){ |
|
| 536 | - $dels+=$e; |
|
| 537 | - spip_log("Entree ".$row['id']."/".$row['id_objet']."/$type supprimee dans la table $table_lien",_LOG_INFO_IMPORTANTE); |
|
| 533 | + while ($row = sql_fetch($res)) { |
|
| 534 | + $e = sql_delete($table_lien, array("$primary=".$row['id'], "id_objet=".$row['id_objet'], "objet=".sql_quote($type))); |
|
| 535 | + if ($e != false) { |
|
| 536 | + $dels += $e; |
|
| 537 | + spip_log("Entree ".$row['id']."/".$row['id_objet']."/$type supprimee dans la table $table_lien", _LOG_INFO_IMPORTANTE); |
|
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | } |
@@ -548,10 +548,10 @@ discard block |
||
| 548 | 548 | $res = sql_select("L.$primary AS id", |
| 549 | 549 | "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary", |
| 550 | 550 | $where); |
| 551 | - $dels+= optimiser_sansref($table_lien, $primary, $res); |
|
| 551 | + $dels += optimiser_sansref($table_lien, $primary, $res); |
|
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | - return ($echec?false:$dels); |
|
| 554 | + return ($echec ?false:$dels); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | * @param array $qualif |
| 577 | 577 | * @return bool|int |
| 578 | 578 | */ |
| 579 | -function lien_set($objet_source,$primary,$table_lien,$id,$objets,$qualif){ |
|
| 579 | +function lien_set($objet_source, $primary, $table_lien, $id, $objets, $qualif) { |
|
| 580 | 580 | $echec = null; |
| 581 | 581 | $ok = 0; |
| 582 | 582 | if (!$qualif) |
@@ -589,19 +589,19 @@ discard block |
||
| 589 | 589 | } |
| 590 | 590 | unset($qualif['objet']); |
| 591 | 591 | unset($qualif['id_objet']); |
| 592 | - foreach($objets as $objet => $id_objets){ |
|
| 593 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 594 | - if (!is_array($id_objets) OR reset($id_objets)=="NOT") $id_objets = array($id_objets); |
|
| 595 | - foreach($id_objets as $id_objet) { |
|
| 592 | + foreach ($objets as $objet => $id_objets) { |
|
| 593 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 594 | + if (!is_array($id_objets) OR reset($id_objets) == "NOT") $id_objets = array($id_objets); |
|
| 595 | + foreach ($id_objets as $id_objet) { |
|
| 596 | 596 | $where = lien_where($primary, $id, $objet, $id_objet); |
| 597 | - $e = sql_updateq($table_lien,$qualif,$where); |
|
| 598 | - if ($e===false) |
|
| 597 | + $e = sql_updateq($table_lien, $qualif, $where); |
|
| 598 | + if ($e === false) |
|
| 599 | 599 | $echec = true; |
| 600 | 600 | else |
| 601 | 601 | $ok++; |
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | - return ($echec?false:$ok); |
|
| 604 | + return ($echec ?false:$ok); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -622,15 +622,15 @@ discard block |
||
| 622 | 622 | * @param array $objets |
| 623 | 623 | * @return array |
| 624 | 624 | */ |
| 625 | -function lien_find($objet_source,$primary,$table_lien,$id,$objets){ |
|
| 625 | +function lien_find($objet_source, $primary, $table_lien, $id, $objets) { |
|
| 626 | 626 | $trouve = array(); |
| 627 | - foreach($objets as $objet => $id_objets){ |
|
| 628 | - $objet = ($objet=='*')?$objet:objet_type($objet); # securite |
|
| 627 | + foreach ($objets as $objet => $id_objets) { |
|
| 628 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 629 | 629 | // lien_where prend en charge les $id_objets sous forme int ou array |
| 630 | 630 | $where = lien_where($primary, $id, $objet, $id_objets); |
| 631 | - $liens = sql_allfetsel('*',$table_lien,$where); |
|
| 631 | + $liens = sql_allfetsel('*', $table_lien, $where); |
|
| 632 | 632 | // ajouter les entrees objet_source et objet cible par convenance |
| 633 | - foreach($liens as $l) { |
|
| 633 | + foreach ($liens as $l) { |
|
| 634 | 634 | $l[$objet_source] = $l[$primary]; |
| 635 | 635 | $l[$objet] = $l['id_objet']; |
| 636 | 636 | $trouve[] = $l; |
@@ -646,14 +646,14 @@ discard block |
||
| 646 | 646 | * @param string $objet |
| 647 | 647 | * @param array|int $ids |
| 648 | 648 | */ |
| 649 | -function lien_propage_date_modif($objet,$ids){ |
|
| 650 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 649 | +function lien_propage_date_modif($objet, $ids) { |
|
| 650 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 651 | 651 | |
| 652 | 652 | $table = table_objet_sql($objet); |
| 653 | 653 | if ($desc = $trouver_table($table) |
| 654 | - AND isset($desc['field']['date_modif'])){ |
|
| 654 | + AND isset($desc['field']['date_modif'])) { |
|
| 655 | 655 | $primary = id_table_objet($objet); |
| 656 | - $where = (is_array($ids)?sql_in($primary, array_map('intval',$ids)):"$primary=".intval($ids)); |
|
| 656 | + $where = (is_array($ids) ?sql_in($primary, array_map('intval', $ids)) : "$primary=".intval($ids)); |
|
| 657 | 657 | sql_updateq($table, array('date_modif'=>date('Y-m-d H:i:s')), $where); |
| 658 | 658 | } |
| 659 | 659 | } |
@@ -45,6 +45,9 @@ |
||
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | +/** |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 48 | 51 | function menu_rubriques($complet = true){ |
| 49 | 52 | $ret = "<li class='toutsite'><a href='".generer_url_ecrire('plan')."'>"._T('info_tout_site')."</a></li>"; |
| 50 | 53 | |
@@ -18,142 +18,142 @@ |
||
| 18 | 18 | |
| 19 | 19 | function action_menu_rubriques_dist() { |
| 20 | 20 | |
| 21 | - // si pas acces a ecrire, pas acces au menu |
|
| 22 | - // on renvoi un 401 qui fait echouer la requete ajax silencieusement |
|
| 23 | - if (!autoriser('ecrire')){ |
|
| 24 | - $retour = "<ul class='cols_1'><li class='toutsite'><a href='".generer_url_ecrire('accueil')."'>"._T('public:lien_connecter')."</a></li></ul>"; |
|
| 25 | - include_spip('inc/actions'); |
|
| 26 | - ajax_retour($retour); |
|
| 27 | - exit; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - if ($date = intval(_request('date'))) |
|
| 31 | - header("Last-Modified: ".gmdate("D, d M Y H:i:s", $date)." GMT"); |
|
| 32 | - |
|
| 33 | - $r = gen_liste_rubriques(); |
|
| 34 | - if (!$r |
|
| 35 | - AND isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 36 | - AND !strstr($_SERVER['SERVER_SOFTWARE'],'IIS/')) { |
|
| 37 | - include_spip('inc/headers'); |
|
| 38 | - header('Content-Type: text/html; charset='. $GLOBALS['meta']['charset']); |
|
| 39 | - http_status(304); |
|
| 40 | - exit; |
|
| 41 | - } else { |
|
| 42 | - include_spip('inc/actions'); |
|
| 43 | - $ret = menu_rubriques(); |
|
| 44 | - ajax_retour($ret); |
|
| 45 | - } |
|
| 21 | + // si pas acces a ecrire, pas acces au menu |
|
| 22 | + // on renvoi un 401 qui fait echouer la requete ajax silencieusement |
|
| 23 | + if (!autoriser('ecrire')){ |
|
| 24 | + $retour = "<ul class='cols_1'><li class='toutsite'><a href='".generer_url_ecrire('accueil')."'>"._T('public:lien_connecter')."</a></li></ul>"; |
|
| 25 | + include_spip('inc/actions'); |
|
| 26 | + ajax_retour($retour); |
|
| 27 | + exit; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + if ($date = intval(_request('date'))) |
|
| 31 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s", $date)." GMT"); |
|
| 32 | + |
|
| 33 | + $r = gen_liste_rubriques(); |
|
| 34 | + if (!$r |
|
| 35 | + AND isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 36 | + AND !strstr($_SERVER['SERVER_SOFTWARE'],'IIS/')) { |
|
| 37 | + include_spip('inc/headers'); |
|
| 38 | + header('Content-Type: text/html; charset='. $GLOBALS['meta']['charset']); |
|
| 39 | + http_status(304); |
|
| 40 | + exit; |
|
| 41 | + } else { |
|
| 42 | + include_spip('inc/actions'); |
|
| 43 | + $ret = menu_rubriques(); |
|
| 44 | + ajax_retour($ret); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | function menu_rubriques($complet = true){ |
| 49 | - $ret = "<li class='toutsite'><a href='".generer_url_ecrire('plan')."'>"._T('info_tout_site')."</a></li>"; |
|
| 50 | - |
|
| 51 | - if (!$complet) { |
|
| 52 | - return "<ul class='cols_1'>$ret\n</ul>\n"; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - if (!isset($GLOBALS['db_art_cache'])){ |
|
| 56 | - gen_liste_rubriques(); |
|
| 57 | - } |
|
| 58 | - $arr_low = extraire_article(0, $GLOBALS['db_art_cache']); |
|
| 59 | - |
|
| 60 | - $total_lignes = $i = sizeof($arr_low); |
|
| 61 | - |
|
| 62 | - if ($i > 0) { |
|
| 63 | - $nb_col = min(8,ceil($total_lignes / 30)); |
|
| 64 | - if ($nb_col <= 1) $nb_col = ceil($total_lignes / 10); |
|
| 65 | - foreach( $arr_low as $id_rubrique => $titre_rubrique) { |
|
| 66 | - if (autoriser('voir','rubrique',$id_rubrique)){ |
|
| 67 | - $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i); |
|
| 68 | - $i++; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $ret = "<ul class='cols_$nb_col'>" |
|
| 73 | - . $ret |
|
| 74 | - . "\n</ul>\n"; |
|
| 75 | - } |
|
| 76 | - else |
|
| 77 | - $ret = "<ul class='cols_1'>$ret\n</ul>\n"; |
|
| 49 | + $ret = "<li class='toutsite'><a href='".generer_url_ecrire('plan')."'>"._T('info_tout_site')."</a></li>"; |
|
| 50 | + |
|
| 51 | + if (!$complet) { |
|
| 52 | + return "<ul class='cols_1'>$ret\n</ul>\n"; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + if (!isset($GLOBALS['db_art_cache'])){ |
|
| 56 | + gen_liste_rubriques(); |
|
| 57 | + } |
|
| 58 | + $arr_low = extraire_article(0, $GLOBALS['db_art_cache']); |
|
| 59 | + |
|
| 60 | + $total_lignes = $i = sizeof($arr_low); |
|
| 61 | + |
|
| 62 | + if ($i > 0) { |
|
| 63 | + $nb_col = min(8,ceil($total_lignes / 30)); |
|
| 64 | + if ($nb_col <= 1) $nb_col = ceil($total_lignes / 10); |
|
| 65 | + foreach( $arr_low as $id_rubrique => $titre_rubrique) { |
|
| 66 | + if (autoriser('voir','rubrique',$id_rubrique)){ |
|
| 67 | + $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i); |
|
| 68 | + $i++; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $ret = "<ul class='cols_$nb_col'>" |
|
| 73 | + . $ret |
|
| 74 | + . "\n</ul>\n"; |
|
| 75 | + } |
|
| 76 | + else |
|
| 77 | + $ret = "<ul class='cols_1'>$ret\n</ul>\n"; |
|
| 78 | 78 | |
| 79 | - return $ret; |
|
| 79 | + return $ret; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // http://doc.spip.org/@bandeau_rubrique |
| 83 | 83 | function bandeau_rubrique($id_rubrique, $titre_rubrique, $zdecal) { |
| 84 | - static $zmax = 6; |
|
| 85 | - |
|
| 86 | - $nav = "<a href='" |
|
| 87 | - . generer_url_entite($id_rubrique,'rubrique','','',false) |
|
| 88 | - . "'>" |
|
| 89 | - . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)) |
|
| 90 | - . "</a>\n"; |
|
| 91 | - |
|
| 92 | - // Limiter volontairement le nombre de sous-menus |
|
| 93 | - if (!(--$zmax)) { |
|
| 94 | - $zmax++; |
|
| 95 | - return "\n<li>$nav</li>"; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $arr_rub = extraire_article($id_rubrique, $GLOBALS['db_art_cache']); |
|
| 99 | - $i = sizeof($arr_rub); |
|
| 100 | - if (!$i) { |
|
| 101 | - $zmax++; |
|
| 102 | - return "\n<li>$nav</li>"; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - $nb_col = 1; |
|
| 107 | - if ($nb_rub = count($arr_rub)) { |
|
| 108 | - $nb_col = min(10,max(1,ceil($nb_rub / 10))); |
|
| 109 | - } |
|
| 110 | - $ret = "<li class='haschild'>$nav<ul class='cols_$nb_col'>"; |
|
| 111 | - foreach( $arr_rub as $id_rub => $titre_rub) { |
|
| 112 | - if (autoriser('voir','rubrique',$id_rub)){ |
|
| 113 | - $titre = supprimer_numero(typo($titre_rub)); |
|
| 114 | - $ret .= bandeau_rubrique($id_rub, $titre, $zdecal+$i); |
|
| 115 | - $i++; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - $ret .= "</ul></li>\n"; |
|
| 119 | - $zmax++; |
|
| 120 | - return $ret; |
|
| 84 | + static $zmax = 6; |
|
| 85 | + |
|
| 86 | + $nav = "<a href='" |
|
| 87 | + . generer_url_entite($id_rubrique,'rubrique','','',false) |
|
| 88 | + . "'>" |
|
| 89 | + . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)) |
|
| 90 | + . "</a>\n"; |
|
| 91 | + |
|
| 92 | + // Limiter volontairement le nombre de sous-menus |
|
| 93 | + if (!(--$zmax)) { |
|
| 94 | + $zmax++; |
|
| 95 | + return "\n<li>$nav</li>"; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $arr_rub = extraire_article($id_rubrique, $GLOBALS['db_art_cache']); |
|
| 99 | + $i = sizeof($arr_rub); |
|
| 100 | + if (!$i) { |
|
| 101 | + $zmax++; |
|
| 102 | + return "\n<li>$nav</li>"; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + $nb_col = 1; |
|
| 107 | + if ($nb_rub = count($arr_rub)) { |
|
| 108 | + $nb_col = min(10,max(1,ceil($nb_rub / 10))); |
|
| 109 | + } |
|
| 110 | + $ret = "<li class='haschild'>$nav<ul class='cols_$nb_col'>"; |
|
| 111 | + foreach( $arr_rub as $id_rub => $titre_rub) { |
|
| 112 | + if (autoriser('voir','rubrique',$id_rub)){ |
|
| 113 | + $titre = supprimer_numero(typo($titre_rub)); |
|
| 114 | + $ret .= bandeau_rubrique($id_rub, $titre, $zdecal+$i); |
|
| 115 | + $i++; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + $ret .= "</ul></li>\n"; |
|
| 119 | + $zmax++; |
|
| 120 | + return $ret; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
| 124 | 124 | // http://doc.spip.org/@extraire_article |
| 125 | 125 | function extraire_article($id_p, $t) { |
| 126 | - return array_key_exists($id_p, $t) ? $t[$id_p]: array(); |
|
| 126 | + return array_key_exists($id_p, $t) ? $t[$id_p]: array(); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // http://doc.spip.org/@gen_liste_rubriques |
| 130 | 130 | function gen_liste_rubriques() { |
| 131 | 131 | |
| 132 | - include_spip('inc/config'); |
|
| 133 | - // ici, un petit fichier cache ne fait pas de mal |
|
| 134 | - $last = lire_config('date_calcul_rubriques', 0); |
|
| 135 | - if (lire_fichier(_CACHE_RUBRIQUES, $cache)) { |
|
| 136 | - list($date,$GLOBALS['db_art_cache']) = @unserialize($cache); |
|
| 137 | - if ($date == $last) return false; // c'etait en cache :-) |
|
| 138 | - } |
|
| 139 | - // se restreindre aux rubriques utilisees recemment +secteurs |
|
| 132 | + include_spip('inc/config'); |
|
| 133 | + // ici, un petit fichier cache ne fait pas de mal |
|
| 134 | + $last = lire_config('date_calcul_rubriques', 0); |
|
| 135 | + if (lire_fichier(_CACHE_RUBRIQUES, $cache)) { |
|
| 136 | + list($date,$GLOBALS['db_art_cache']) = @unserialize($cache); |
|
| 137 | + if ($date == $last) return false; // c'etait en cache :-) |
|
| 138 | + } |
|
| 139 | + // se restreindre aux rubriques utilisees recemment +secteurs |
|
| 140 | 140 | |
| 141 | - $where = sql_in_select("id_rubrique", "id_rubrique", "spip_rubriques", "", "", "id_parent=0 DESC, date DESC", _CACHE_RUBRIQUES_MAX); |
|
| 141 | + $where = sql_in_select("id_rubrique", "id_rubrique", "spip_rubriques", "", "", "id_parent=0 DESC, date DESC", _CACHE_RUBRIQUES_MAX); |
|
| 142 | 142 | |
| 143 | - // puis refaire la requete pour avoir l'ordre alphabetique |
|
| 143 | + // puis refaire la requete pour avoir l'ordre alphabetique |
|
| 144 | 144 | |
| 145 | - $res = sql_select("id_rubrique, titre, id_parent", "spip_rubriques", $where, '', 'id_parent, 0+titre, titre'); |
|
| 145 | + $res = sql_select("id_rubrique, titre, id_parent", "spip_rubriques", $where, '', 'id_parent, 0+titre, titre'); |
|
| 146 | 146 | |
| 147 | - // il ne faut pas filtrer le autoriser voir ici |
|
| 148 | - // car on met le resultat en cache, commun a tout le monde |
|
| 149 | - $GLOBALS['db_art_cache'] = array(); |
|
| 150 | - while ($r = sql_fetch($res)) { |
|
| 151 | - $t = sinon($r['titre'], _T('ecrire:info_sans_titre')); |
|
| 152 | - $GLOBALS['db_art_cache'][$r['id_parent']][$r['id_rubrique']] = supprimer_numero(typo($t)); |
|
| 153 | - } |
|
| 147 | + // il ne faut pas filtrer le autoriser voir ici |
|
| 148 | + // car on met le resultat en cache, commun a tout le monde |
|
| 149 | + $GLOBALS['db_art_cache'] = array(); |
|
| 150 | + while ($r = sql_fetch($res)) { |
|
| 151 | + $t = sinon($r['titre'], _T('ecrire:info_sans_titre')); |
|
| 152 | + $GLOBALS['db_art_cache'][$r['id_parent']][$r['id_rubrique']] = supprimer_numero(typo($t)); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - $t = array($last ? $last : time(), $GLOBALS['db_art_cache']); |
|
| 156 | - ecrire_fichier(_CACHE_RUBRIQUES, serialize($t)); |
|
| 157 | - return true; |
|
| 155 | + $t = array($last ? $last : time(), $GLOBALS['db_art_cache']); |
|
| 156 | + ecrire_fichier(_CACHE_RUBRIQUES, serialize($t)); |
|
| 157 | + return true; |
|
| 158 | 158 | } |
| 159 | 159 | ?> |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | // si pas acces a ecrire, pas acces au menu |
| 22 | 22 | // on renvoi un 401 qui fait echouer la requete ajax silencieusement |
| 23 | - if (!autoriser('ecrire')){ |
|
| 23 | + if (!autoriser('ecrire')) { |
|
| 24 | 24 | $retour = "<ul class='cols_1'><li class='toutsite'><a href='".generer_url_ecrire('accueil')."'>"._T('public:lien_connecter')."</a></li></ul>"; |
| 25 | 25 | include_spip('inc/actions'); |
| 26 | 26 | ajax_retour($retour); |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | $r = gen_liste_rubriques(); |
| 34 | 34 | if (!$r |
| 35 | 35 | AND isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
| 36 | - AND !strstr($_SERVER['SERVER_SOFTWARE'],'IIS/')) { |
|
| 36 | + AND !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/')) { |
|
| 37 | 37 | include_spip('inc/headers'); |
| 38 | - header('Content-Type: text/html; charset='. $GLOBALS['meta']['charset']); |
|
| 38 | + header('Content-Type: text/html; charset='.$GLOBALS['meta']['charset']); |
|
| 39 | 39 | http_status(304); |
| 40 | 40 | exit; |
| 41 | 41 | } else { |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | -function menu_rubriques($complet = true){ |
|
| 48 | +function menu_rubriques($complet = true) { |
|
| 49 | 49 | $ret = "<li class='toutsite'><a href='".generer_url_ecrire('plan')."'>"._T('info_tout_site')."</a></li>"; |
| 50 | 50 | |
| 51 | 51 | if (!$complet) { |
| 52 | 52 | return "<ul class='cols_1'>$ret\n</ul>\n"; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if (!isset($GLOBALS['db_art_cache'])){ |
|
| 55 | + if (!isset($GLOBALS['db_art_cache'])) { |
|
| 56 | 56 | gen_liste_rubriques(); |
| 57 | 57 | } |
| 58 | 58 | $arr_low = extraire_article(0, $GLOBALS['db_art_cache']); |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | $total_lignes = $i = sizeof($arr_low); |
| 61 | 61 | |
| 62 | 62 | if ($i > 0) { |
| 63 | - $nb_col = min(8,ceil($total_lignes / 30)); |
|
| 64 | - if ($nb_col <= 1) $nb_col = ceil($total_lignes / 10); |
|
| 65 | - foreach( $arr_low as $id_rubrique => $titre_rubrique) { |
|
| 66 | - if (autoriser('voir','rubrique',$id_rubrique)){ |
|
| 63 | + $nb_col = min(8, ceil($total_lignes / 30)); |
|
| 64 | + if ($nb_col <= 1) $nb_col = ceil($total_lignes / 10); |
|
| 65 | + foreach ($arr_low as $id_rubrique => $titre_rubrique) { |
|
| 66 | + if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 67 | 67 | $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i); |
| 68 | 68 | $i++; |
| 69 | 69 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | static $zmax = 6; |
| 85 | 85 | |
| 86 | 86 | $nav = "<a href='" |
| 87 | - . generer_url_entite($id_rubrique,'rubrique','','',false) |
|
| 87 | + . generer_url_entite($id_rubrique, 'rubrique', '', '', false) |
|
| 88 | 88 | . "'>" |
| 89 | 89 | . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)) |
| 90 | 90 | . "</a>\n"; |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | $nb_col = 1; |
| 107 | 107 | if ($nb_rub = count($arr_rub)) { |
| 108 | - $nb_col = min(10,max(1,ceil($nb_rub / 10))); |
|
| 108 | + $nb_col = min(10, max(1, ceil($nb_rub / 10))); |
|
| 109 | 109 | } |
| 110 | 110 | $ret = "<li class='haschild'>$nav<ul class='cols_$nb_col'>"; |
| 111 | - foreach( $arr_rub as $id_rub => $titre_rub) { |
|
| 112 | - if (autoriser('voir','rubrique',$id_rub)){ |
|
| 111 | + foreach ($arr_rub as $id_rub => $titre_rub) { |
|
| 112 | + if (autoriser('voir', 'rubrique', $id_rub)) { |
|
| 113 | 113 | $titre = supprimer_numero(typo($titre_rub)); |
| 114 | - $ret .= bandeau_rubrique($id_rub, $titre, $zdecal+$i); |
|
| 114 | + $ret .= bandeau_rubrique($id_rub, $titre, $zdecal + $i); |
|
| 115 | 115 | $i++; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | // http://doc.spip.org/@extraire_article |
| 125 | 125 | function extraire_article($id_p, $t) { |
| 126 | - return array_key_exists($id_p, $t) ? $t[$id_p]: array(); |
|
| 126 | + return array_key_exists($id_p, $t) ? $t[$id_p] : array(); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // http://doc.spip.org/@gen_liste_rubriques |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | // ici, un petit fichier cache ne fait pas de mal |
| 134 | 134 | $last = lire_config('date_calcul_rubriques', 0); |
| 135 | 135 | if (lire_fichier(_CACHE_RUBRIQUES, $cache)) { |
| 136 | - list($date,$GLOBALS['db_art_cache']) = @unserialize($cache); |
|
| 136 | + list($date, $GLOBALS['db_art_cache']) = @unserialize($cache); |
|
| 137 | 137 | if ($date == $last) return false; // c'etait en cache :-) |
| 138 | 138 | } |
| 139 | 139 | // se restreindre aux rubriques utilisees recemment +secteurs |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | include_spip('inc/autoriser'); |
| 16 | 18 | include_spip('inc/texte'); |
@@ -27,8 +29,9 @@ discard block |
||
| 27 | 29 | exit; |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | - if ($date = intval(_request('date'))) |
|
| 31 | - header("Last-Modified: ".gmdate("D, d M Y H:i:s", $date)." GMT"); |
|
| 32 | + if ($date = intval(_request('date'))) { |
|
| 33 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s", $date)." GMT"); |
|
| 34 | + } |
|
| 32 | 35 | |
| 33 | 36 | $r = gen_liste_rubriques(); |
| 34 | 37 | if (!$r |
@@ -61,7 +64,9 @@ discard block |
||
| 61 | 64 | |
| 62 | 65 | if ($i > 0) { |
| 63 | 66 | $nb_col = min(8,ceil($total_lignes / 30)); |
| 64 | - if ($nb_col <= 1) $nb_col = ceil($total_lignes / 10); |
|
| 67 | + if ($nb_col <= 1) { |
|
| 68 | + $nb_col = ceil($total_lignes / 10); |
|
| 69 | + } |
|
| 65 | 70 | foreach( $arr_low as $id_rubrique => $titre_rubrique) { |
| 66 | 71 | if (autoriser('voir','rubrique',$id_rubrique)){ |
| 67 | 72 | $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i); |
@@ -72,9 +77,9 @@ discard block |
||
| 72 | 77 | $ret = "<ul class='cols_$nb_col'>" |
| 73 | 78 | . $ret |
| 74 | 79 | . "\n</ul>\n"; |
| 80 | + } else { |
|
| 81 | + $ret = "<ul class='cols_1'>$ret\n</ul>\n"; |
|
| 75 | 82 | } |
| 76 | - else |
|
| 77 | - $ret = "<ul class='cols_1'>$ret\n</ul>\n"; |
|
| 78 | 83 | |
| 79 | 84 | return $ret; |
| 80 | 85 | } |
@@ -134,7 +139,10 @@ discard block |
||
| 134 | 139 | $last = lire_config('date_calcul_rubriques', 0); |
| 135 | 140 | if (lire_fichier(_CACHE_RUBRIQUES, $cache)) { |
| 136 | 141 | list($date,$GLOBALS['db_art_cache']) = @unserialize($cache); |
| 137 | - if ($date == $last) return false; // c'etait en cache :-) |
|
| 142 | + if ($date == $last) { |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | + // c'etait en cache :-) |
|
| 138 | 146 | } |
| 139 | 147 | // se restreindre aux rubriques utilisees recemment +secteurs |
| 140 | 148 | |
@@ -266,7 +266,7 @@ |
||
| 266 | 266 | * @param $new_pass |
| 267 | 267 | * @param $id_auteur |
| 268 | 268 | * @param string $serveur |
| 269 | - * @return bool |
|
| 269 | + * @return string|boolean |
|
| 270 | 270 | * informe du succes ou de l'echec du changement du mot de passe |
| 271 | 271 | */ |
| 272 | 272 | function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur=''){ |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 18 | 18 | // ne pas ecraser une definition perso dans mes_options |
| 19 | 19 | if (!isset($GLOBALS['ldap_attributes']) OR !is_array($GLOBALS['ldap_attributes'])){ |
| 20 | - $GLOBALS['ldap_attributes'] = array( |
|
| 21 | - 'login' => array('sAMAccountName', 'uid', 'login', 'userid', 'cn','sn'), |
|
| 22 | - 'nom' => "cn", |
|
| 23 | - 'email' => "mail", |
|
| 24 | - 'bio' => "description"); |
|
| 20 | + $GLOBALS['ldap_attributes'] = array( |
|
| 21 | + 'login' => array('sAMAccountName', 'uid', 'login', 'userid', 'cn','sn'), |
|
| 22 | + 'nom' => "cn", |
|
| 23 | + 'email' => "mail", |
|
| 24 | + 'bio' => "description"); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -48,42 +48,42 @@ discard block |
||
| 48 | 48 | // http://doc.spip.org/@inc_auth_ldap_dist |
| 49 | 49 | function auth_ldap_dist ($login, $pass, $serveur='', $phpauth=false) { |
| 50 | 50 | |
| 51 | - #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 51 | + #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 52 | 52 | |
| 53 | - // Utilisateur connu ? |
|
| 54 | - // si http auth, inutile de reauthentifier: cela |
|
| 55 | - // ne marchera pas avec auth http autre que basic. |
|
| 56 | - $checkpass = isset($_SERVER["REMOTE_USER"])?false:true; |
|
| 57 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) return array(); |
|
| 58 | - $credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass); |
|
| 53 | + // Utilisateur connu ? |
|
| 54 | + // si http auth, inutile de reauthentifier: cela |
|
| 55 | + // ne marchera pas avec auth http autre que basic. |
|
| 56 | + $checkpass = isset($_SERVER["REMOTE_USER"])?false:true; |
|
| 57 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) return array(); |
|
| 58 | + $credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass); |
|
| 59 | 59 | |
| 60 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 61 | - $r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'",'','','','',$serveur); |
|
| 60 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 61 | + $r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'",'','','','',$serveur); |
|
| 62 | 62 | |
| 63 | - if ($r) return array_merge($r, $credentials_ldap); |
|
| 63 | + if ($r) return array_merge($r, $credentials_ldap); |
|
| 64 | 64 | |
| 65 | - // sinon importer les infos depuis LDAP, |
|
| 65 | + // sinon importer les infos depuis LDAP, |
|
| 66 | 66 | |
| 67 | - if ($GLOBALS['meta']["ldap_statut_import"] |
|
| 68 | - AND $desc = auth_ldap_retrouver($dn, array(), $serveur)) { |
|
| 69 | - // rajouter le statut indique a l'install |
|
| 70 | - $desc['statut'] = $GLOBALS['meta']["ldap_statut_import"]; |
|
| 71 | - $desc['login'] = $login; |
|
| 72 | - $desc['source'] = 'ldap'; |
|
| 73 | - $desc['pass'] = ''; |
|
| 67 | + if ($GLOBALS['meta']["ldap_statut_import"] |
|
| 68 | + AND $desc = auth_ldap_retrouver($dn, array(), $serveur)) { |
|
| 69 | + // rajouter le statut indique a l'install |
|
| 70 | + $desc['statut'] = $GLOBALS['meta']["ldap_statut_import"]; |
|
| 71 | + $desc['login'] = $login; |
|
| 72 | + $desc['source'] = 'ldap'; |
|
| 73 | + $desc['pass'] = ''; |
|
| 74 | 74 | |
| 75 | - $r = sql_insertq('spip_auteurs', $desc,'',$serveur); |
|
| 76 | - } |
|
| 75 | + $r = sql_insertq('spip_auteurs', $desc,'',$serveur); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - if ($r) |
|
| 79 | - return array_merge( |
|
| 80 | - $credentials_ldap, |
|
| 81 | - sql_fetsel("*", "spip_auteurs", "id_auteur=".intval($r),'','','','',$serveur) |
|
| 82 | - ); |
|
| 78 | + if ($r) |
|
| 79 | + return array_merge( |
|
| 80 | + $credentials_ldap, |
|
| 81 | + sql_fetsel("*", "spip_auteurs", "id_auteur=".intval($r),'','','','',$serveur) |
|
| 82 | + ); |
|
| 83 | 83 | |
| 84 | - // sinon echec |
|
| 85 | - spip_log("Creation de l'auteur '$login' impossible"); |
|
| 86 | - return array(); |
|
| 84 | + // sinon echec |
|
| 85 | + spip_log("Creation de l'auteur '$login' impossible"); |
|
| 86 | + return array(); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -96,24 +96,24 @@ discard block |
||
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | 98 | function auth_ldap_connect($serveur='') { |
| 99 | - include_spip('base/connect_sql'); |
|
| 100 | - static $connexions_ldap = array(); |
|
| 101 | - if (isset($connexions_ldap[$serveur])) return $connexions_ldap[$serveur]; |
|
| 102 | - $connexion = spip_connect($serveur); |
|
| 103 | - if (!is_array($connexion['ldap'])) { |
|
| 104 | - if ($connexion['authentification']['ldap']) { |
|
| 105 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 106 | - unset($GLOBALS['ldap_link']); |
|
| 107 | - if (is_readable($f)) { include_once($f); }; |
|
| 108 | - if (isset($GLOBALS['ldap_link'])) |
|
| 109 | - $connexion['ldap'] = array('link' => $GLOBALS['ldap_link'], |
|
| 110 | - 'base' => $GLOBALS['ldap_base']); |
|
| 111 | - else spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 112 | - if (isset($GLOBALS['ldap_champs'])) |
|
| 113 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 114 | - } else spip_log("connection LDAP $serveur inconnue"); |
|
| 115 | - } |
|
| 116 | - return $connexions_ldap[$serveur]=$connexion['ldap']; |
|
| 99 | + include_spip('base/connect_sql'); |
|
| 100 | + static $connexions_ldap = array(); |
|
| 101 | + if (isset($connexions_ldap[$serveur])) return $connexions_ldap[$serveur]; |
|
| 102 | + $connexion = spip_connect($serveur); |
|
| 103 | + if (!is_array($connexion['ldap'])) { |
|
| 104 | + if ($connexion['authentification']['ldap']) { |
|
| 105 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 106 | + unset($GLOBALS['ldap_link']); |
|
| 107 | + if (is_readable($f)) { include_once($f); }; |
|
| 108 | + if (isset($GLOBALS['ldap_link'])) |
|
| 109 | + $connexion['ldap'] = array('link' => $GLOBALS['ldap_link'], |
|
| 110 | + 'base' => $GLOBALS['ldap_base']); |
|
| 111 | + else spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 112 | + if (isset($GLOBALS['ldap_champs'])) |
|
| 113 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 114 | + } else spip_log("connection LDAP $serveur inconnue"); |
|
| 115 | + } |
|
| 116 | + return $connexions_ldap[$serveur]=$connexion['ldap']; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -127,44 +127,44 @@ discard block |
||
| 127 | 127 | * le login trouve ou chaine vide si non trouve |
| 128 | 128 | */ |
| 129 | 129 | function auth_ldap_search($login, $pass, $checkpass=true, $serveur=''){ |
| 130 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 131 | - $login_search = preg_replace("/[^-@._\s\d\w]/", "", $login); |
|
| 132 | - if (!strlen($login_search) OR ($checkpass AND !strlen($pass)) ) |
|
| 133 | - return ''; |
|
| 134 | - |
|
| 135 | - // verifier la connexion |
|
| 136 | - if (!$ldap = auth_ldap_connect($serveur)) |
|
| 137 | - return ''; |
|
| 138 | - |
|
| 139 | - $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; |
|
| 140 | - $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; |
|
| 141 | - $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 142 | - |
|
| 143 | - $logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']); |
|
| 144 | - |
|
| 145 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 146 | - foreach($logins as $att) { |
|
| 147 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", array("dn")); |
|
| 148 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 149 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 150 | - // (on veut un attribut unique) |
|
| 151 | - |
|
| 152 | - if (is_array($info) AND $info['count'] == 1) { |
|
| 153 | - $dn = $info[0]['dn']; |
|
| 154 | - if (!$checkpass) return $dn; |
|
| 155 | - if (@ldap_bind($ldap_link, $dn, $pass)) return $dn; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - if ($checkpass AND !isset($dn)) { |
|
| 160 | - // Si echec, essayer de deviner le DN |
|
| 161 | - foreach($logins as $att) { |
|
| 162 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 163 | - if (@ldap_bind($ldap_link, $dn, $pass)) |
|
| 164 | - return "$att=$login_search, $ldap_base"; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - return ''; |
|
| 130 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 131 | + $login_search = preg_replace("/[^-@._\s\d\w]/", "", $login); |
|
| 132 | + if (!strlen($login_search) OR ($checkpass AND !strlen($pass)) ) |
|
| 133 | + return ''; |
|
| 134 | + |
|
| 135 | + // verifier la connexion |
|
| 136 | + if (!$ldap = auth_ldap_connect($serveur)) |
|
| 137 | + return ''; |
|
| 138 | + |
|
| 139 | + $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; |
|
| 140 | + $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; |
|
| 141 | + $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 142 | + |
|
| 143 | + $logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']); |
|
| 144 | + |
|
| 145 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 146 | + foreach($logins as $att) { |
|
| 147 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", array("dn")); |
|
| 148 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 149 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 150 | + // (on veut un attribut unique) |
|
| 151 | + |
|
| 152 | + if (is_array($info) AND $info['count'] == 1) { |
|
| 153 | + $dn = $info[0]['dn']; |
|
| 154 | + if (!$checkpass) return $dn; |
|
| 155 | + if (@ldap_bind($ldap_link, $dn, $pass)) return $dn; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + if ($checkpass AND !isset($dn)) { |
|
| 160 | + // Si echec, essayer de deviner le DN |
|
| 161 | + foreach($logins as $att) { |
|
| 162 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 163 | + if (@ldap_bind($ldap_link, $dn, $pass)) |
|
| 164 | + return "$att=$login_search, $ldap_base"; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + return ''; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -176,33 +176,33 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | function auth_ldap_retrouver($dn, $desc=array(), $serveur='') |
| 178 | 178 | { |
| 179 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 179 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 180 | 180 | |
| 181 | - if (!$ldap = spip_connect_ldap($serveur)) { |
|
| 182 | - spip_log("ldap $serveur injoignable"); |
|
| 183 | - return array(); |
|
| 184 | - } |
|
| 181 | + if (!$ldap = spip_connect_ldap($serveur)) { |
|
| 182 | + spip_log("ldap $serveur injoignable"); |
|
| 183 | + return array(); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - $ldap_link = $ldap['link']; |
|
| 187 | - if (!$desc) { |
|
| 188 | - $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 189 | - unset($desc['login']); |
|
| 190 | - } |
|
| 191 | - $result = @ldap_read($ldap_link, $dn, "objectClass=*", array_values($desc)); |
|
| 186 | + $ldap_link = $ldap['link']; |
|
| 187 | + if (!$desc) { |
|
| 188 | + $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 189 | + unset($desc['login']); |
|
| 190 | + } |
|
| 191 | + $result = @ldap_read($ldap_link, $dn, "objectClass=*", array_values($desc)); |
|
| 192 | 192 | |
| 193 | - if (!$result) return array(); |
|
| 193 | + if (!$result) return array(); |
|
| 194 | 194 | |
| 195 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 196 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 197 | - if (!is_array($val) OR !is_array($val[0])) return array(); |
|
| 198 | - $val = $val[0]; |
|
| 195 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 196 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 197 | + if (!is_array($val) OR !is_array($val[0])) return array(); |
|
| 198 | + $val = $val[0]; |
|
| 199 | 199 | |
| 200 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 201 | - include_spip('inc/charsets'); |
|
| 200 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 201 | + include_spip('inc/charsets'); |
|
| 202 | 202 | |
| 203 | - foreach ($desc as $k => $v) |
|
| 204 | - $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 205 | - return $desc; |
|
| 203 | + foreach ($desc as $k => $v) |
|
| 204 | + $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 205 | + return $desc; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | function auth_ldap_retrouver_login($login, $serveur='') |
| 217 | 217 | { |
| 218 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 218 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | return false; |
| 275 | 275 | } |
| 276 | 276 | if (!$ldap = auth_ldap_connect($serveur)) |
| 277 | - return ''; |
|
| 277 | + return ''; |
|
| 278 | 278 | $link = $ldap['link']; |
| 279 | 279 | include_spip("inc/session"); |
| 280 | 280 | $dn = session_get('ldap_dn'); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | return false; |
| 283 | 283 | } |
| 284 | 284 | if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
| 285 | - return false; |
|
| 285 | + return false; |
|
| 286 | 286 | } |
| 287 | 287 | $encoded_pass = "{MD5}".base64_encode(pack("H*",md5($new_pass))); |
| 288 | 288 | $success = ldap_mod_replace($link, $dn, array('userPassword' => $encoded_pass)); |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
| 16 | 18 | |
@@ -54,13 +56,17 @@ discard block |
||
| 54 | 56 | // si http auth, inutile de reauthentifier: cela |
| 55 | 57 | // ne marchera pas avec auth http autre que basic. |
| 56 | 58 | $checkpass = isset($_SERVER["REMOTE_USER"])?false:true; |
| 57 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) return array(); |
|
| 59 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 60 | + return array(); |
|
| 61 | + } |
|
| 58 | 62 | $credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass); |
| 59 | 63 | |
| 60 | 64 | // Si l'utilisateur figure deja dans la base, y recuperer les infos |
| 61 | 65 | $r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'",'','','','',$serveur); |
| 62 | 66 | |
| 63 | - if ($r) return array_merge($r, $credentials_ldap); |
|
| 67 | + if ($r) { |
|
| 68 | + return array_merge($r, $credentials_ldap); |
|
| 69 | + } |
|
| 64 | 70 | |
| 65 | 71 | // sinon importer les infos depuis LDAP, |
| 66 | 72 | |
@@ -75,11 +81,12 @@ discard block |
||
| 75 | 81 | $r = sql_insertq('spip_auteurs', $desc,'',$serveur); |
| 76 | 82 | } |
| 77 | 83 | |
| 78 | - if ($r) |
|
| 79 | - return array_merge( |
|
| 84 | + if ($r) { |
|
| 85 | + return array_merge( |
|
| 80 | 86 | $credentials_ldap, |
| 81 | 87 | sql_fetsel("*", "spip_auteurs", "id_auteur=".intval($r),'','','','',$serveur) |
| 82 | 88 | ); |
| 89 | + } |
|
| 83 | 90 | |
| 84 | 91 | // sinon echec |
| 85 | 92 | spip_log("Creation de l'auteur '$login' impossible"); |
@@ -98,20 +105,27 @@ discard block |
||
| 98 | 105 | function auth_ldap_connect($serveur='') { |
| 99 | 106 | include_spip('base/connect_sql'); |
| 100 | 107 | static $connexions_ldap = array(); |
| 101 | - if (isset($connexions_ldap[$serveur])) return $connexions_ldap[$serveur]; |
|
| 108 | + if (isset($connexions_ldap[$serveur])) { |
|
| 109 | + return $connexions_ldap[$serveur]; |
|
| 110 | + } |
|
| 102 | 111 | $connexion = spip_connect($serveur); |
| 103 | 112 | if (!is_array($connexion['ldap'])) { |
| 104 | 113 | if ($connexion['authentification']['ldap']) { |
| 105 | 114 | $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
| 106 | 115 | unset($GLOBALS['ldap_link']); |
| 107 | 116 | if (is_readable($f)) { include_once($f); }; |
| 108 | - if (isset($GLOBALS['ldap_link'])) |
|
| 109 | - $connexion['ldap'] = array('link' => $GLOBALS['ldap_link'], |
|
| 117 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 118 | + $connexion['ldap'] = array('link' => $GLOBALS['ldap_link'], |
|
| 110 | 119 | 'base' => $GLOBALS['ldap_base']); |
| 111 | - else spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 112 | - if (isset($GLOBALS['ldap_champs'])) |
|
| 113 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 114 | - } else spip_log("connection LDAP $serveur inconnue"); |
|
| 120 | + } else { |
|
| 121 | + spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 122 | + } |
|
| 123 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 124 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 125 | + } |
|
| 126 | + } else { |
|
| 127 | + spip_log("connection LDAP $serveur inconnue"); |
|
| 128 | + } |
|
| 115 | 129 | } |
| 116 | 130 | return $connexions_ldap[$serveur]=$connexion['ldap']; |
| 117 | 131 | } |
@@ -129,12 +143,14 @@ discard block |
||
| 129 | 143 | function auth_ldap_search($login, $pass, $checkpass=true, $serveur=''){ |
| 130 | 144 | // Securite anti-injection et contre un serveur LDAP laxiste |
| 131 | 145 | $login_search = preg_replace("/[^-@._\s\d\w]/", "", $login); |
| 132 | - if (!strlen($login_search) OR ($checkpass AND !strlen($pass)) ) |
|
| 133 | - return ''; |
|
| 146 | + if (!strlen($login_search) OR ($checkpass AND !strlen($pass)) ) { |
|
| 147 | + return ''; |
|
| 148 | + } |
|
| 134 | 149 | |
| 135 | 150 | // verifier la connexion |
| 136 | - if (!$ldap = auth_ldap_connect($serveur)) |
|
| 137 | - return ''; |
|
| 151 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 152 | + return ''; |
|
| 153 | + } |
|
| 138 | 154 | |
| 139 | 155 | $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; |
| 140 | 156 | $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; |
@@ -151,8 +167,12 @@ discard block |
||
| 151 | 167 | |
| 152 | 168 | if (is_array($info) AND $info['count'] == 1) { |
| 153 | 169 | $dn = $info[0]['dn']; |
| 154 | - if (!$checkpass) return $dn; |
|
| 155 | - if (@ldap_bind($ldap_link, $dn, $pass)) return $dn; |
|
| 170 | + if (!$checkpass) { |
|
| 171 | + return $dn; |
|
| 172 | + } |
|
| 173 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 174 | + return $dn; |
|
| 175 | + } |
|
| 156 | 176 | } |
| 157 | 177 | } |
| 158 | 178 | |
@@ -160,8 +180,9 @@ discard block |
||
| 160 | 180 | // Si echec, essayer de deviner le DN |
| 161 | 181 | foreach($logins as $att) { |
| 162 | 182 | $dn = "$att=$login_search, $ldap_base"; |
| 163 | - if (@ldap_bind($ldap_link, $dn, $pass)) |
|
| 164 | - return "$att=$login_search, $ldap_base"; |
|
| 183 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 184 | + return "$att=$login_search, $ldap_base"; |
|
| 185 | + } |
|
| 165 | 186 | } |
| 166 | 187 | } |
| 167 | 188 | return ''; |
@@ -190,18 +211,23 @@ discard block |
||
| 190 | 211 | } |
| 191 | 212 | $result = @ldap_read($ldap_link, $dn, "objectClass=*", array_values($desc)); |
| 192 | 213 | |
| 193 | - if (!$result) return array(); |
|
| 214 | + if (!$result) { |
|
| 215 | + return array(); |
|
| 216 | + } |
|
| 194 | 217 | |
| 195 | 218 | // Recuperer les donnees du premier (unique?) compte de l'auteur |
| 196 | 219 | $val = @ldap_get_entries($ldap_link, $result); |
| 197 | - if (!is_array($val) OR !is_array($val[0])) return array(); |
|
| 220 | + if (!is_array($val) OR !is_array($val[0])) { |
|
| 221 | + return array(); |
|
| 222 | + } |
|
| 198 | 223 | $val = $val[0]; |
| 199 | 224 | |
| 200 | 225 | // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
| 201 | 226 | include_spip('inc/charsets'); |
| 202 | 227 | |
| 203 | - foreach ($desc as $k => $v) |
|
| 204 | - $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 228 | + foreach ($desc as $k => $v) { |
|
| 229 | + $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 230 | + } |
|
| 205 | 231 | return $desc; |
| 206 | 232 | } |
| 207 | 233 | |
@@ -273,8 +299,9 @@ discard block |
||
| 273 | 299 | if (is_null($new_pass) OR auth_ldap_verifier_pass($login, $new_pass,$id_auteur,$serveur)!='') { |
| 274 | 300 | return false; |
| 275 | 301 | } |
| 276 | - if (!$ldap = auth_ldap_connect($serveur)) |
|
| 277 | - return ''; |
|
| 302 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 303 | + return ''; |
|
| 304 | + } |
|
| 278 | 305 | $link = $ldap['link']; |
| 279 | 306 | include_spip("inc/session"); |
| 280 | 307 | $dn = session_get('ldap_dn'); |
@@ -16,9 +16,9 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 18 | 18 | // ne pas ecraser une definition perso dans mes_options |
| 19 | -if (!isset($GLOBALS['ldap_attributes']) OR !is_array($GLOBALS['ldap_attributes'])){ |
|
| 19 | +if (!isset($GLOBALS['ldap_attributes']) OR !is_array($GLOBALS['ldap_attributes'])) { |
|
| 20 | 20 | $GLOBALS['ldap_attributes'] = array( |
| 21 | - 'login' => array('sAMAccountName', 'uid', 'login', 'userid', 'cn','sn'), |
|
| 21 | + 'login' => array('sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'), |
|
| 22 | 22 | 'nom' => "cn", |
| 23 | 23 | 'email' => "mail", |
| 24 | 24 | 'bio' => "description"); |
@@ -46,19 +46,19 @@ discard block |
||
| 46 | 46 | * @return string |
| 47 | 47 | */ |
| 48 | 48 | // http://doc.spip.org/@inc_auth_ldap_dist |
| 49 | -function auth_ldap_dist ($login, $pass, $serveur='', $phpauth=false) { |
|
| 49 | +function auth_ldap_dist($login, $pass, $serveur = '', $phpauth = false) { |
|
| 50 | 50 | |
| 51 | 51 | #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
| 52 | 52 | |
| 53 | 53 | // Utilisateur connu ? |
| 54 | 54 | // si http auth, inutile de reauthentifier: cela |
| 55 | 55 | // ne marchera pas avec auth http autre que basic. |
| 56 | - $checkpass = isset($_SERVER["REMOTE_USER"])?false:true; |
|
| 56 | + $checkpass = isset($_SERVER["REMOTE_USER"]) ?false:true; |
|
| 57 | 57 | if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) return array(); |
| 58 | 58 | $credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass); |
| 59 | 59 | |
| 60 | 60 | // Si l'utilisateur figure deja dans la base, y recuperer les infos |
| 61 | - $r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'",'','','','',$serveur); |
|
| 61 | + $r = sql_fetsel("*", "spip_auteurs", "login=".sql_quote($login)." AND source='ldap'", '', '', '', '', $serveur); |
|
| 62 | 62 | |
| 63 | 63 | if ($r) return array_merge($r, $credentials_ldap); |
| 64 | 64 | |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | $desc['source'] = 'ldap'; |
| 73 | 73 | $desc['pass'] = ''; |
| 74 | 74 | |
| 75 | - $r = sql_insertq('spip_auteurs', $desc,'',$serveur); |
|
| 75 | + $r = sql_insertq('spip_auteurs', $desc, '', $serveur); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | if ($r) |
| 79 | 79 | return array_merge( |
| 80 | 80 | $credentials_ldap, |
| 81 | - sql_fetsel("*", "spip_auteurs", "id_auteur=".intval($r),'','','','',$serveur) |
|
| 81 | + sql_fetsel("*", "spip_auteurs", "id_auteur=".intval($r), '', '', '', '', $serveur) |
|
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | 84 | // sinon echec |
@@ -95,14 +95,14 @@ discard block |
||
| 95 | 95 | * @param string $serveur |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | -function auth_ldap_connect($serveur='') { |
|
| 98 | +function auth_ldap_connect($serveur = '') { |
|
| 99 | 99 | include_spip('base/connect_sql'); |
| 100 | 100 | static $connexions_ldap = array(); |
| 101 | 101 | if (isset($connexions_ldap[$serveur])) return $connexions_ldap[$serveur]; |
| 102 | 102 | $connexion = spip_connect($serveur); |
| 103 | 103 | if (!is_array($connexion['ldap'])) { |
| 104 | 104 | if ($connexion['authentification']['ldap']) { |
| 105 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 105 | + $f = _DIR_CONNECT.$connexion['authentification']['ldap']; |
|
| 106 | 106 | unset($GLOBALS['ldap_link']); |
| 107 | 107 | if (is_readable($f)) { include_once($f); }; |
| 108 | 108 | if (isset($GLOBALS['ldap_link'])) |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
| 114 | 114 | } else spip_log("connection LDAP $serveur inconnue"); |
| 115 | 115 | } |
| 116 | - return $connexions_ldap[$serveur]=$connexion['ldap']; |
|
| 116 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -126,10 +126,10 @@ discard block |
||
| 126 | 126 | * @return string |
| 127 | 127 | * le login trouve ou chaine vide si non trouve |
| 128 | 128 | */ |
| 129 | -function auth_ldap_search($login, $pass, $checkpass=true, $serveur=''){ |
|
| 129 | +function auth_ldap_search($login, $pass, $checkpass = true, $serveur = '') { |
|
| 130 | 130 | // Securite anti-injection et contre un serveur LDAP laxiste |
| 131 | 131 | $login_search = preg_replace("/[^-@._\s\d\w]/", "", $login); |
| 132 | - if (!strlen($login_search) OR ($checkpass AND !strlen($pass)) ) |
|
| 132 | + if (!strlen($login_search) OR ($checkpass AND !strlen($pass))) |
|
| 133 | 133 | return ''; |
| 134 | 134 | |
| 135 | 135 | // verifier la connexion |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; |
| 140 | 140 | $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; |
| 141 | - $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 141 | + $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 142 | 142 | |
| 143 | 143 | $logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']); |
| 144 | 144 | |
| 145 | 145 | // Tenter une recherche pour essayer de retrouver le DN |
| 146 | - foreach($logins as $att) { |
|
| 146 | + foreach ($logins as $att) { |
|
| 147 | 147 | $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", array("dn")); |
| 148 | 148 | $info = @ldap_get_entries($ldap_link, $result); |
| 149 | 149 | // Ne pas accepter les resultats si plus d'une entree |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | if ($checkpass AND !isset($dn)) { |
| 160 | 160 | // Si echec, essayer de deviner le DN |
| 161 | - foreach($logins as $att) { |
|
| 161 | + foreach ($logins as $att) { |
|
| 162 | 162 | $dn = "$att=$login_search, $ldap_base"; |
| 163 | 163 | if (@ldap_bind($ldap_link, $dn, $pass)) |
| 164 | 164 | return "$att=$login_search, $ldap_base"; |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @param string $serveur |
| 175 | 175 | * @return array |
| 176 | 176 | */ |
| 177 | -function auth_ldap_retrouver($dn, $desc=array(), $serveur='') |
|
| 177 | +function auth_ldap_retrouver($dn, $desc = array(), $serveur = '') |
|
| 178 | 178 | { |
| 179 | 179 | // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
| 180 | 180 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | $ldap_link = $ldap['link']; |
| 187 | 187 | if (!$desc) { |
| 188 | - $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 188 | + $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 189 | 189 | unset($desc['login']); |
| 190 | 190 | } |
| 191 | 191 | $result = @ldap_read($ldap_link, $dn, "objectClass=*", array_values($desc)); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @param string $serveur |
| 214 | 214 | * @return string |
| 215 | 215 | */ |
| 216 | -function auth_ldap_retrouver_login($login, $serveur='') |
|
| 216 | +function auth_ldap_retrouver_login($login, $serveur = '') |
|
| 217 | 217 | { |
| 218 | 218 | return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
| 219 | 219 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @return string |
| 234 | 234 | * message d'erreur si login non valide, chaine vide sinon |
| 235 | 235 | */ |
| 236 | -function auth_ldap_verifier_pass($login, $new_pass, $id_auteur=0, $serveur=''){ |
|
| 236 | +function auth_ldap_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
|
| 237 | 237 | include_spip('auth/spip'); |
| 238 | 238 | return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
| 239 | 239 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * by self write |
| 253 | 253 | * ... |
| 254 | 254 | */ |
| 255 | -function auth_ldap_autoriser_modifier_pass($serveur=''){ |
|
| 255 | +function auth_ldap_autoriser_modifier_pass($serveur = '') { |
|
| 256 | 256 | return true; |
| 257 | 257 | } |
| 258 | 258 | |
@@ -269,8 +269,8 @@ discard block |
||
| 269 | 269 | * @return bool |
| 270 | 270 | * informe du succes ou de l'echec du changement du mot de passe |
| 271 | 271 | */ |
| 272 | -function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur=''){ |
|
| 273 | - if (is_null($new_pass) OR auth_ldap_verifier_pass($login, $new_pass,$id_auteur,$serveur)!='') { |
|
| 272 | +function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
|
| 273 | + if (is_null($new_pass) OR auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 274 | 274 | return false; |
| 275 | 275 | } |
| 276 | 276 | if (!$ldap = auth_ldap_connect($serveur)) |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
| 285 | 285 | return false; |
| 286 | 286 | } |
| 287 | - $encoded_pass = "{MD5}".base64_encode(pack("H*",md5($new_pass))); |
|
| 287 | + $encoded_pass = "{MD5}".base64_encode(pack("H*", md5($new_pass))); |
|
| 288 | 288 | $success = ldap_mod_replace($link, $dn, array('userPassword' => $encoded_pass)); |
| 289 | 289 | return $success; |
| 290 | 290 | } |
@@ -56,7 +56,7 @@ |
||
| 56 | 56 | * @see trouver_fond() |
| 57 | 57 | * @param string |
| 58 | 58 | * Nom du formulaire |
| 59 | - * @return string|bool |
|
| 59 | + * @return string|false |
|
| 60 | 60 | * - string : chemin du squelette |
| 61 | 61 | * - false : pas de squelette trouvé |
| 62 | 62 | **/ |
@@ -32,22 +32,22 @@ discard block |
||
| 32 | 32 | * Saisie protégée |
| 33 | 33 | **/ |
| 34 | 34 | function protege_champ($texte){ |
| 35 | - if (is_array($texte)) |
|
| 36 | - $texte = array_map('protege_champ',$texte); |
|
| 37 | - else { |
|
| 38 | - // ne pas corrompre une valeur serialize |
|
| 39 | - if ((preg_match(",^[abis]:\d+[:;],", $texte) AND unserialize($texte)!=false) OR is_null($texte)) |
|
| 40 | - return $texte; |
|
| 41 | - if (is_string($texte) |
|
| 42 | - AND $texte |
|
| 43 | - AND strpbrk($texte, "&\"'<>")!==false |
|
| 44 | - ) { |
|
| 45 | - $texte = spip_htmlspecialchars($texte,ENT_QUOTES); |
|
| 46 | - } |
|
| 47 | - elseif(is_bool($texte)) |
|
| 48 | - $texte = ($texte?'1':''); |
|
| 49 | - } |
|
| 50 | - return $texte; |
|
| 35 | + if (is_array($texte)) |
|
| 36 | + $texte = array_map('protege_champ',$texte); |
|
| 37 | + else { |
|
| 38 | + // ne pas corrompre une valeur serialize |
|
| 39 | + if ((preg_match(",^[abis]:\d+[:;],", $texte) AND unserialize($texte)!=false) OR is_null($texte)) |
|
| 40 | + return $texte; |
|
| 41 | + if (is_string($texte) |
|
| 42 | + AND $texte |
|
| 43 | + AND strpbrk($texte, "&\"'<>")!==false |
|
| 44 | + ) { |
|
| 45 | + $texte = spip_htmlspecialchars($texte,ENT_QUOTES); |
|
| 46 | + } |
|
| 47 | + elseif(is_bool($texte)) |
|
| 48 | + $texte = ($texte?'1':''); |
|
| 49 | + } |
|
| 50 | + return $texte; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -62,14 +62,14 @@ discard block |
||
| 62 | 62 | **/ |
| 63 | 63 | function existe_formulaire($form) |
| 64 | 64 | { |
| 65 | - if (substr($form,0,11)=="FORMULAIRE_") |
|
| 66 | - $form = strtolower(substr($form,11)); |
|
| 67 | - else |
|
| 68 | - $form = strtolower($form); |
|
| 65 | + if (substr($form,0,11)=="FORMULAIRE_") |
|
| 66 | + $form = strtolower(substr($form,11)); |
|
| 67 | + else |
|
| 68 | + $form = strtolower($form); |
|
| 69 | 69 | |
| 70 | - if (!$form) return ''; // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 70 | + if (!$form) return ''; // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 71 | 71 | |
| 72 | - return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 72 | + return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -85,16 +85,16 @@ discard block |
||
| 85 | 85 | **/ |
| 86 | 86 | function balise_FORMULAIRE__dist($p) { |
| 87 | 87 | |
| 88 | - // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 89 | - // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 90 | - if (existe_formulaire($p->nom_champ)===FALSE) { |
|
| 91 | - $p->code = "''"; |
|
| 92 | - $p->interdire_scripts = false; |
|
| 93 | - return $p; |
|
| 94 | - } |
|
| 88 | + // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 89 | + // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 90 | + if (existe_formulaire($p->nom_champ)===FALSE) { |
|
| 91 | + $p->code = "''"; |
|
| 92 | + $p->interdire_scripts = false; |
|
| 93 | + return $p; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - // sinon renvoyer un code php dynamique |
|
| 97 | - return calculer_balise_dynamique($p, $p->nom_champ, array()); |
|
| 96 | + // sinon renvoyer un code php dynamique |
|
| 97 | + return calculer_balise_dynamique($p, $p->nom_champ, array()); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -108,22 +108,22 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | function balise_FORMULAIRE__dyn($form) |
| 110 | 110 | { |
| 111 | - $form = existe_formulaire($form); |
|
| 112 | - if (!$form) return ''; |
|
| 113 | - |
|
| 114 | - // deux moyen d'arriver ici : |
|
| 115 | - // soit #FORMULAIRE_XX reroute avec 'FORMULAIRE_XX' ajoute en premier arg |
|
| 116 | - // soit #FORMULAIRE_{xx} |
|
| 117 | - |
|
| 118 | - // recuperer les arguments passes a la balise |
|
| 119 | - // on enleve le premier qui est le nom de la balise |
|
| 120 | - // deja recupere ci-dessus |
|
| 121 | - |
|
| 122 | - $args = func_get_args(); |
|
| 123 | - array_shift($args); |
|
| 124 | - $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 125 | - if (!is_array($contexte)) return $contexte; |
|
| 126 | - return array("formulaires/$form", 3600, $contexte); |
|
| 111 | + $form = existe_formulaire($form); |
|
| 112 | + if (!$form) return ''; |
|
| 113 | + |
|
| 114 | + // deux moyen d'arriver ici : |
|
| 115 | + // soit #FORMULAIRE_XX reroute avec 'FORMULAIRE_XX' ajoute en premier arg |
|
| 116 | + // soit #FORMULAIRE_{xx} |
|
| 117 | + |
|
| 118 | + // recuperer les arguments passes a la balise |
|
| 119 | + // on enleve le premier qui est le nom de la balise |
|
| 120 | + // deja recupere ci-dessus |
|
| 121 | + |
|
| 122 | + $args = func_get_args(); |
|
| 123 | + array_shift($args); |
|
| 124 | + $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 125 | + if (!is_array($contexte)) return $contexte; |
|
| 126 | + return array("formulaires/$form", 3600, $contexte); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -138,108 +138,108 @@ discard block |
||
| 138 | 138 | **/ |
| 139 | 139 | function balise_FORMULAIRE__contexte($form, $args) |
| 140 | 140 | { |
| 141 | - // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 142 | - // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 143 | - // si poste, on recupere les erreurs |
|
| 144 | - |
|
| 145 | - $je_suis_poste = false; |
|
| 146 | - if ($post_form = _request('formulaire_action') |
|
| 147 | - AND $post_form==$form |
|
| 148 | - AND $p = _request('formulaire_action_args') |
|
| 149 | - AND is_array($p = decoder_contexte_ajax($p, $post_form))) { |
|
| 150 | - // enlever le faux attribut de langue masque |
|
| 151 | - array_shift($p); |
|
| 152 | - if (formulaire__identifier($form, $args, $p)) |
|
| 153 | - $je_suis_poste = true; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $editable = true; |
|
| 157 | - $erreurs = $post = array(); |
|
| 158 | - if ($je_suis_poste) { |
|
| 159 | - $post = traiter_formulaires_dynamiques(true); |
|
| 160 | - $e = "erreurs_$form"; |
|
| 161 | - $erreurs = isset($post[$e]) ? $post[$e] : array(); |
|
| 162 | - $editable = "editable_$form"; |
|
| 163 | - $editable = (!isset($post[$e])) |
|
| 164 | - || count($erreurs) |
|
| 165 | - || (isset($post[$editable]) && $post[$editable]); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 169 | - |
|
| 170 | - // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 171 | - // C'est plus fort qu'editable qui est gere par le squelette |
|
| 172 | - // Idealement $valeur doit etre alors un message explicatif. |
|
| 173 | - if (!is_array($valeurs)) return is_string($valeurs) ? $valeurs : ''; |
|
| 141 | + // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 142 | + // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 143 | + // si poste, on recupere les erreurs |
|
| 144 | + |
|
| 145 | + $je_suis_poste = false; |
|
| 146 | + if ($post_form = _request('formulaire_action') |
|
| 147 | + AND $post_form==$form |
|
| 148 | + AND $p = _request('formulaire_action_args') |
|
| 149 | + AND is_array($p = decoder_contexte_ajax($p, $post_form))) { |
|
| 150 | + // enlever le faux attribut de langue masque |
|
| 151 | + array_shift($p); |
|
| 152 | + if (formulaire__identifier($form, $args, $p)) |
|
| 153 | + $je_suis_poste = true; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $editable = true; |
|
| 157 | + $erreurs = $post = array(); |
|
| 158 | + if ($je_suis_poste) { |
|
| 159 | + $post = traiter_formulaires_dynamiques(true); |
|
| 160 | + $e = "erreurs_$form"; |
|
| 161 | + $erreurs = isset($post[$e]) ? $post[$e] : array(); |
|
| 162 | + $editable = "editable_$form"; |
|
| 163 | + $editable = (!isset($post[$e])) |
|
| 164 | + || count($erreurs) |
|
| 165 | + || (isset($post[$editable]) && $post[$editable]); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 169 | + |
|
| 170 | + // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 171 | + // C'est plus fort qu'editable qui est gere par le squelette |
|
| 172 | + // Idealement $valeur doit etre alors un message explicatif. |
|
| 173 | + if (!is_array($valeurs)) return is_string($valeurs) ? $valeurs : ''; |
|
| 174 | 174 | |
| 175 | - // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 176 | - // ou une action vide si elle ne sert pas |
|
| 177 | - $action = (isset($valeurs['action'])) ? $valeurs['action'] : self('&', true); |
|
| 178 | - // bug IEx : si action finit par / |
|
| 179 | - // IE croit que le <form ... action=../ > est autoferme |
|
| 180 | - if (substr($action,-1)=='/') { |
|
| 181 | - // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 182 | - $action .= '#'; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // recuperer la saisie en cours si erreurs |
|
| 186 | - // seulement si c'est ce formulaire qui est poste |
|
| 187 | - // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 188 | - $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 189 | - foreach(array_keys($valeurs) as $champ){ |
|
| 190 | - if ($champ[0]!=='_' AND !in_array($champ, array('message_ok','message_erreur','editable'))) { |
|
| 191 | - if ($dispo AND (($v = _request($champ))!==NULL)) |
|
| 192 | - $valeurs[$champ] = $v; |
|
| 193 | - // nettoyer l'url des champs qui vont etre saisis |
|
| 194 | - if ($action) |
|
| 195 | - $action = parametre_url($action,$champ,''); |
|
| 196 | - // proteger les ' et les " dans les champs que l'on va injecter |
|
| 197 | - $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - if ($action) { |
|
| 202 | - // nettoyer l'url |
|
| 203 | - $action = parametre_url($action,'formulaire_action',''); |
|
| 204 | - $action = parametre_url($action,'formulaire_action_args',''); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if (isset($valeurs['_action'])){ |
|
| 208 | - $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 209 | - $secu = $securiser_action(reset($valeurs['_action']),end($valeurs['_action']),'',-1); |
|
| 210 | - $valeurs['_hidden'] = (isset($valeurs['_hidden'])?$valeurs['_hidden']:'') . |
|
| 211 | - "<input type='hidden' name='arg' value='".$secu['arg']."' />" |
|
| 212 | - . "<input type='hidden' name='hash' value='".$secu['hash']."' />"; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // empiler la lang en tant que premier argument implicite du CVT |
|
| 216 | - // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 217 | - array_unshift($args, $GLOBALS['spip_lang']); |
|
| 218 | - |
|
| 219 | - $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 220 | - $valeurs['erreurs'] = $erreurs; |
|
| 221 | - $valeurs['action'] = $action; |
|
| 222 | - $valeurs['form'] = $form; |
|
| 223 | - |
|
| 224 | - if (!isset($valeurs['id'])) $valeurs['id'] = 'new'; |
|
| 225 | - // editable peut venir de charger() ou de traiter() sinon |
|
| 226 | - if (!isset($valeurs['editable'])) $valeurs['editable'] = $editable; |
|
| 227 | - // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 228 | - $valeurs['editable'] = ($valeurs['editable']?' ':''); |
|
| 229 | - |
|
| 230 | - if ($je_suis_poste) { |
|
| 231 | - $valeurs['message_erreur'] = ""; |
|
| 232 | - if (isset($erreurs['message_erreur'])) |
|
| 233 | - $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 234 | - |
|
| 235 | - $valeurs['message_ok'] = ""; |
|
| 236 | - if (isset($post["message_ok_$form"])) |
|
| 237 | - $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 238 | - elseif (isset($erreurs['message_ok'])) |
|
| 239 | - $valeurs['message_ok'] = $erreurs["message_ok"]; |
|
| 240 | - } |
|
| 175 | + // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 176 | + // ou une action vide si elle ne sert pas |
|
| 177 | + $action = (isset($valeurs['action'])) ? $valeurs['action'] : self('&', true); |
|
| 178 | + // bug IEx : si action finit par / |
|
| 179 | + // IE croit que le <form ... action=../ > est autoferme |
|
| 180 | + if (substr($action,-1)=='/') { |
|
| 181 | + // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 182 | + $action .= '#'; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // recuperer la saisie en cours si erreurs |
|
| 186 | + // seulement si c'est ce formulaire qui est poste |
|
| 187 | + // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 188 | + $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 189 | + foreach(array_keys($valeurs) as $champ){ |
|
| 190 | + if ($champ[0]!=='_' AND !in_array($champ, array('message_ok','message_erreur','editable'))) { |
|
| 191 | + if ($dispo AND (($v = _request($champ))!==NULL)) |
|
| 192 | + $valeurs[$champ] = $v; |
|
| 193 | + // nettoyer l'url des champs qui vont etre saisis |
|
| 194 | + if ($action) |
|
| 195 | + $action = parametre_url($action,$champ,''); |
|
| 196 | + // proteger les ' et les " dans les champs que l'on va injecter |
|
| 197 | + $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + if ($action) { |
|
| 202 | + // nettoyer l'url |
|
| 203 | + $action = parametre_url($action,'formulaire_action',''); |
|
| 204 | + $action = parametre_url($action,'formulaire_action_args',''); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if (isset($valeurs['_action'])){ |
|
| 208 | + $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 209 | + $secu = $securiser_action(reset($valeurs['_action']),end($valeurs['_action']),'',-1); |
|
| 210 | + $valeurs['_hidden'] = (isset($valeurs['_hidden'])?$valeurs['_hidden']:'') . |
|
| 211 | + "<input type='hidden' name='arg' value='".$secu['arg']."' />" |
|
| 212 | + . "<input type='hidden' name='hash' value='".$secu['hash']."' />"; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // empiler la lang en tant que premier argument implicite du CVT |
|
| 216 | + // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 217 | + array_unshift($args, $GLOBALS['spip_lang']); |
|
| 218 | + |
|
| 219 | + $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 220 | + $valeurs['erreurs'] = $erreurs; |
|
| 221 | + $valeurs['action'] = $action; |
|
| 222 | + $valeurs['form'] = $form; |
|
| 223 | + |
|
| 224 | + if (!isset($valeurs['id'])) $valeurs['id'] = 'new'; |
|
| 225 | + // editable peut venir de charger() ou de traiter() sinon |
|
| 226 | + if (!isset($valeurs['editable'])) $valeurs['editable'] = $editable; |
|
| 227 | + // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 228 | + $valeurs['editable'] = ($valeurs['editable']?' ':''); |
|
| 229 | + |
|
| 230 | + if ($je_suis_poste) { |
|
| 231 | + $valeurs['message_erreur'] = ""; |
|
| 232 | + if (isset($erreurs['message_erreur'])) |
|
| 233 | + $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 234 | + |
|
| 235 | + $valeurs['message_ok'] = ""; |
|
| 236 | + if (isset($post["message_ok_$form"])) |
|
| 237 | + $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 238 | + elseif (isset($erreurs['message_ok'])) |
|
| 239 | + $valeurs['message_ok'] = $erreurs["message_ok"]; |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $valeurs; |
|
| 242 | + return $valeurs; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -252,37 +252,37 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function formulaire__charger($form, $args, $poste) |
| 254 | 254 | { |
| 255 | - if ($charger_valeurs = charger_fonction("charger","formulaires/$form",true)) |
|
| 256 | - $valeurs = call_user_func_array($charger_valeurs,$args); |
|
| 257 | - else $valeurs = array(); |
|
| 258 | - |
|
| 259 | - $valeurs = pipeline( |
|
| 260 | - 'formulaire_charger', |
|
| 261 | - array( |
|
| 262 | - 'args'=>array('form'=>$form,'args'=>$args,'je_suis_poste'=>$poste), |
|
| 263 | - 'data'=>$valeurs) |
|
| 264 | - ); |
|
| 265 | - |
|
| 266 | - // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 267 | - if (is_array($valeurs)){ |
|
| 268 | - if (!isset($valeurs['_pipelines'])) $valeurs['_pipelines']=array(); |
|
| 269 | - // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 270 | - // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 271 | - if (isset($valeurs['_pipeline'])) { |
|
| 272 | - $pipe = is_array($valeurs['_pipeline'])?reset($valeurs['_pipeline']):$valeurs['_pipeline']; |
|
| 273 | - $args = is_array($valeurs['_pipeline'])?end($valeurs['_pipeline']):array(); |
|
| 274 | - |
|
| 275 | - $pipelines = array($pipe=>$args); |
|
| 276 | - $valeurs['_pipelines'] = array_merge($pipelines,$valeurs['_pipelines']); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 280 | - // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 281 | - // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 282 | - $valeurs['_pipelines']['formulaire_fond'] = array('form'=>$form,'args'=>$args,'je_suis_poste'=>$poste); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $valeurs; |
|
| 255 | + if ($charger_valeurs = charger_fonction("charger","formulaires/$form",true)) |
|
| 256 | + $valeurs = call_user_func_array($charger_valeurs,$args); |
|
| 257 | + else $valeurs = array(); |
|
| 258 | + |
|
| 259 | + $valeurs = pipeline( |
|
| 260 | + 'formulaire_charger', |
|
| 261 | + array( |
|
| 262 | + 'args'=>array('form'=>$form,'args'=>$args,'je_suis_poste'=>$poste), |
|
| 263 | + 'data'=>$valeurs) |
|
| 264 | + ); |
|
| 265 | + |
|
| 266 | + // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 267 | + if (is_array($valeurs)){ |
|
| 268 | + if (!isset($valeurs['_pipelines'])) $valeurs['_pipelines']=array(); |
|
| 269 | + // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 270 | + // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 271 | + if (isset($valeurs['_pipeline'])) { |
|
| 272 | + $pipe = is_array($valeurs['_pipeline'])?reset($valeurs['_pipeline']):$valeurs['_pipeline']; |
|
| 273 | + $args = is_array($valeurs['_pipeline'])?end($valeurs['_pipeline']):array(); |
|
| 274 | + |
|
| 275 | + $pipelines = array($pipe=>$args); |
|
| 276 | + $valeurs['_pipelines'] = array_merge($pipelines,$valeurs['_pipelines']); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 280 | + // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 281 | + // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 282 | + $valeurs['_pipelines']['formulaire_fond'] = array('form'=>$form,'args'=>$args,'je_suis_poste'=>$poste); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $valeurs; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -301,9 +301,9 @@ discard block |
||
| 301 | 301 | * @return bool |
| 302 | 302 | */ |
| 303 | 303 | function formulaire__identifier($form, $args, $p) { |
| 304 | - if ($identifier_args = charger_fonction("identifier","formulaires/$form",true)) { |
|
| 305 | - return call_user_func_array($identifier_args,$args)===call_user_func_array($identifier_args,$p); |
|
| 306 | - } |
|
| 307 | - return $args===$p; |
|
| 304 | + if ($identifier_args = charger_fonction("identifier","formulaires/$form",true)) { |
|
| 305 | + return call_user_func_array($identifier_args,$args)===call_user_func_array($identifier_args,$p); |
|
| 306 | + } |
|
| 307 | + return $args===$p; |
|
| 308 | 308 | } |
| 309 | 309 | ?> |
@@ -14,7 +14,9 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @package SPIP\Formulaires |
| 16 | 16 | **/ |
| 17 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 17 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 18 | + return; |
|
| 19 | +} |
|
| 18 | 20 | |
| 19 | 21 | include_spip('inc/filtres'); |
| 20 | 22 | include_spip('inc/texte'); |
@@ -32,20 +34,21 @@ discard block |
||
| 32 | 34 | * Saisie protégée |
| 33 | 35 | **/ |
| 34 | 36 | function protege_champ($texte){ |
| 35 | - if (is_array($texte)) |
|
| 36 | - $texte = array_map('protege_champ',$texte); |
|
| 37 | - else { |
|
| 37 | + if (is_array($texte)) { |
|
| 38 | + $texte = array_map('protege_champ',$texte); |
|
| 39 | + } else { |
|
| 38 | 40 | // ne pas corrompre une valeur serialize |
| 39 | - if ((preg_match(",^[abis]:\d+[:;],", $texte) AND unserialize($texte)!=false) OR is_null($texte)) |
|
| 40 | - return $texte; |
|
| 41 | + if ((preg_match(",^[abis]:\d+[:;],", $texte) AND unserialize($texte)!=false) OR is_null($texte)) { |
|
| 42 | + return $texte; |
|
| 43 | + } |
|
| 41 | 44 | if (is_string($texte) |
| 42 | 45 | AND $texte |
| 43 | 46 | AND strpbrk($texte, "&\"'<>")!==false |
| 44 | 47 | ) { |
| 45 | 48 | $texte = spip_htmlspecialchars($texte,ENT_QUOTES); |
| 49 | + } elseif(is_bool($texte)) { |
|
| 50 | + $texte = ($texte?'1':''); |
|
| 46 | 51 | } |
| 47 | - elseif(is_bool($texte)) |
|
| 48 | - $texte = ($texte?'1':''); |
|
| 49 | 52 | } |
| 50 | 53 | return $texte; |
| 51 | 54 | } |
@@ -62,12 +65,16 @@ discard block |
||
| 62 | 65 | **/ |
| 63 | 66 | function existe_formulaire($form) |
| 64 | 67 | { |
| 65 | - if (substr($form,0,11)=="FORMULAIRE_") |
|
| 66 | - $form = strtolower(substr($form,11)); |
|
| 67 | - else |
|
| 68 | - $form = strtolower($form); |
|
| 68 | + if (substr($form,0,11)=="FORMULAIRE_") { |
|
| 69 | + $form = strtolower(substr($form,11)); |
|
| 70 | + } else { |
|
| 71 | + $form = strtolower($form); |
|
| 72 | + } |
|
| 69 | 73 | |
| 70 | - if (!$form) return ''; // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 74 | + if (!$form) { |
|
| 75 | + return ''; |
|
| 76 | + } |
|
| 77 | + // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 71 | 78 | |
| 72 | 79 | return trouver_fond($form, 'formulaires/') ? $form : false; |
| 73 | 80 | } |
@@ -109,7 +116,9 @@ discard block |
||
| 109 | 116 | function balise_FORMULAIRE__dyn($form) |
| 110 | 117 | { |
| 111 | 118 | $form = existe_formulaire($form); |
| 112 | - if (!$form) return ''; |
|
| 119 | + if (!$form) { |
|
| 120 | + return ''; |
|
| 121 | + } |
|
| 113 | 122 | |
| 114 | 123 | // deux moyen d'arriver ici : |
| 115 | 124 | // soit #FORMULAIRE_XX reroute avec 'FORMULAIRE_XX' ajoute en premier arg |
@@ -122,7 +131,9 @@ discard block |
||
| 122 | 131 | $args = func_get_args(); |
| 123 | 132 | array_shift($args); |
| 124 | 133 | $contexte = balise_FORMULAIRE__contexte($form, $args); |
| 125 | - if (!is_array($contexte)) return $contexte; |
|
| 134 | + if (!is_array($contexte)) { |
|
| 135 | + return $contexte; |
|
| 136 | + } |
|
| 126 | 137 | return array("formulaires/$form", 3600, $contexte); |
| 127 | 138 | } |
| 128 | 139 | |
@@ -149,8 +160,9 @@ discard block |
||
| 149 | 160 | AND is_array($p = decoder_contexte_ajax($p, $post_form))) { |
| 150 | 161 | // enlever le faux attribut de langue masque |
| 151 | 162 | array_shift($p); |
| 152 | - if (formulaire__identifier($form, $args, $p)) |
|
| 153 | - $je_suis_poste = true; |
|
| 163 | + if (formulaire__identifier($form, $args, $p)) { |
|
| 164 | + $je_suis_poste = true; |
|
| 165 | + } |
|
| 154 | 166 | } |
| 155 | 167 | |
| 156 | 168 | $editable = true; |
@@ -170,7 +182,9 @@ discard block |
||
| 170 | 182 | // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
| 171 | 183 | // C'est plus fort qu'editable qui est gere par le squelette |
| 172 | 184 | // Idealement $valeur doit etre alors un message explicatif. |
| 173 | - if (!is_array($valeurs)) return is_string($valeurs) ? $valeurs : ''; |
|
| 185 | + if (!is_array($valeurs)) { |
|
| 186 | + return is_string($valeurs) ? $valeurs : ''; |
|
| 187 | + } |
|
| 174 | 188 | |
| 175 | 189 | // charger peut passer une action si le formulaire ne tourne pas sur self() |
| 176 | 190 | // ou une action vide si elle ne sert pas |
@@ -188,11 +202,13 @@ discard block |
||
| 188 | 202 | $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
| 189 | 203 | foreach(array_keys($valeurs) as $champ){ |
| 190 | 204 | if ($champ[0]!=='_' AND !in_array($champ, array('message_ok','message_erreur','editable'))) { |
| 191 | - if ($dispo AND (($v = _request($champ))!==NULL)) |
|
| 192 | - $valeurs[$champ] = $v; |
|
| 205 | + if ($dispo AND (($v = _request($champ))!==NULL)) { |
|
| 206 | + $valeurs[$champ] = $v; |
|
| 207 | + } |
|
| 193 | 208 | // nettoyer l'url des champs qui vont etre saisis |
| 194 | - if ($action) |
|
| 195 | - $action = parametre_url($action,$champ,''); |
|
| 209 | + if ($action) { |
|
| 210 | + $action = parametre_url($action,$champ,''); |
|
| 211 | + } |
|
| 196 | 212 | // proteger les ' et les " dans les champs que l'on va injecter |
| 197 | 213 | $valeurs[$champ] = protege_champ($valeurs[$champ]); |
| 198 | 214 | } |
@@ -221,22 +237,28 @@ discard block |
||
| 221 | 237 | $valeurs['action'] = $action; |
| 222 | 238 | $valeurs['form'] = $form; |
| 223 | 239 | |
| 224 | - if (!isset($valeurs['id'])) $valeurs['id'] = 'new'; |
|
| 240 | + if (!isset($valeurs['id'])) { |
|
| 241 | + $valeurs['id'] = 'new'; |
|
| 242 | + } |
|
| 225 | 243 | // editable peut venir de charger() ou de traiter() sinon |
| 226 | - if (!isset($valeurs['editable'])) $valeurs['editable'] = $editable; |
|
| 244 | + if (!isset($valeurs['editable'])) { |
|
| 245 | + $valeurs['editable'] = $editable; |
|
| 246 | + } |
|
| 227 | 247 | // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
| 228 | 248 | $valeurs['editable'] = ($valeurs['editable']?' ':''); |
| 229 | 249 | |
| 230 | 250 | if ($je_suis_poste) { |
| 231 | 251 | $valeurs['message_erreur'] = ""; |
| 232 | - if (isset($erreurs['message_erreur'])) |
|
| 233 | - $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 252 | + if (isset($erreurs['message_erreur'])) { |
|
| 253 | + $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 254 | + } |
|
| 234 | 255 | |
| 235 | 256 | $valeurs['message_ok'] = ""; |
| 236 | - if (isset($post["message_ok_$form"])) |
|
| 237 | - $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 238 | - elseif (isset($erreurs['message_ok'])) |
|
| 239 | - $valeurs['message_ok'] = $erreurs["message_ok"]; |
|
| 257 | + if (isset($post["message_ok_$form"])) { |
|
| 258 | + $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 259 | + } elseif (isset($erreurs['message_ok'])) { |
|
| 260 | + $valeurs['message_ok'] = $erreurs["message_ok"]; |
|
| 261 | + } |
|
| 240 | 262 | } |
| 241 | 263 | |
| 242 | 264 | return $valeurs; |
@@ -252,9 +274,11 @@ discard block |
||
| 252 | 274 | */ |
| 253 | 275 | function formulaire__charger($form, $args, $poste) |
| 254 | 276 | { |
| 255 | - if ($charger_valeurs = charger_fonction("charger","formulaires/$form",true)) |
|
| 256 | - $valeurs = call_user_func_array($charger_valeurs,$args); |
|
| 257 | - else $valeurs = array(); |
|
| 277 | + if ($charger_valeurs = charger_fonction("charger","formulaires/$form",true)) { |
|
| 278 | + $valeurs = call_user_func_array($charger_valeurs,$args); |
|
| 279 | + } else { |
|
| 280 | + $valeurs = array(); |
|
| 281 | + } |
|
| 258 | 282 | |
| 259 | 283 | $valeurs = pipeline( |
| 260 | 284 | 'formulaire_charger', |
@@ -265,7 +289,9 @@ discard block |
||
| 265 | 289 | |
| 266 | 290 | // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
| 267 | 291 | if (is_array($valeurs)){ |
| 268 | - if (!isset($valeurs['_pipelines'])) $valeurs['_pipelines']=array(); |
|
| 292 | + if (!isset($valeurs['_pipelines'])) { |
|
| 293 | + $valeurs['_pipelines']=array(); |
|
| 294 | + } |
|
| 269 | 295 | // l'ancien argument _pipeline devient maintenant _pipelines |
| 270 | 296 | // reinjectons le vieux _pipeline au debut de _pipelines |
| 271 | 297 | if (isset($valeurs['_pipeline'])) { |
@@ -31,21 +31,21 @@ discard block |
||
| 31 | 31 | * @return string|array |
| 32 | 32 | * Saisie protégée |
| 33 | 33 | **/ |
| 34 | -function protege_champ($texte){ |
|
| 34 | +function protege_champ($texte) { |
|
| 35 | 35 | if (is_array($texte)) |
| 36 | - $texte = array_map('protege_champ',$texte); |
|
| 36 | + $texte = array_map('protege_champ', $texte); |
|
| 37 | 37 | else { |
| 38 | 38 | // ne pas corrompre une valeur serialize |
| 39 | - if ((preg_match(",^[abis]:\d+[:;],", $texte) AND unserialize($texte)!=false) OR is_null($texte)) |
|
| 39 | + if ((preg_match(",^[abis]:\d+[:;],", $texte) AND unserialize($texte) != false) OR is_null($texte)) |
|
| 40 | 40 | return $texte; |
| 41 | 41 | if (is_string($texte) |
| 42 | 42 | AND $texte |
| 43 | - AND strpbrk($texte, "&\"'<>")!==false |
|
| 43 | + AND strpbrk($texte, "&\"'<>") !== false |
|
| 44 | 44 | ) { |
| 45 | - $texte = spip_htmlspecialchars($texte,ENT_QUOTES); |
|
| 45 | + $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 46 | 46 | } |
| 47 | - elseif(is_bool($texte)) |
|
| 48 | - $texte = ($texte?'1':''); |
|
| 47 | + elseif (is_bool($texte)) |
|
| 48 | + $texte = ($texte ? '1' : ''); |
|
| 49 | 49 | } |
| 50 | 50 | return $texte; |
| 51 | 51 | } |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | **/ |
| 63 | 63 | function existe_formulaire($form) |
| 64 | 64 | { |
| 65 | - if (substr($form,0,11)=="FORMULAIRE_") |
|
| 66 | - $form = strtolower(substr($form,11)); |
|
| 65 | + if (substr($form, 0, 11) == "FORMULAIRE_") |
|
| 66 | + $form = strtolower(substr($form, 11)); |
|
| 67 | 67 | else |
| 68 | 68 | $form = strtolower($form); |
| 69 | 69 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
| 89 | 89 | // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
| 90 | - if (existe_formulaire($p->nom_champ)===FALSE) { |
|
| 90 | + if (existe_formulaire($p->nom_champ) === FALSE) { |
|
| 91 | 91 | $p->code = "''"; |
| 92 | 92 | $p->interdire_scripts = false; |
| 93 | 93 | return $p; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | $je_suis_poste = false; |
| 146 | 146 | if ($post_form = _request('formulaire_action') |
| 147 | - AND $post_form==$form |
|
| 147 | + AND $post_form == $form |
|
| 148 | 148 | AND $p = _request('formulaire_action_args') |
| 149 | 149 | AND is_array($p = decoder_contexte_ajax($p, $post_form))) { |
| 150 | 150 | // enlever le faux attribut de langue masque |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $action = (isset($valeurs['action'])) ? $valeurs['action'] : self('&', true); |
| 178 | 178 | // bug IEx : si action finit par / |
| 179 | 179 | // IE croit que le <form ... action=../ > est autoferme |
| 180 | - if (substr($action,-1)=='/') { |
|
| 180 | + if (substr($action, -1) == '/') { |
|
| 181 | 181 | // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
| 182 | 182 | $action .= '#'; |
| 183 | 183 | } |
@@ -186,13 +186,13 @@ discard block |
||
| 186 | 186 | // seulement si c'est ce formulaire qui est poste |
| 187 | 187 | // ou si on le demande explicitement par le parametre _forcer_request = true |
| 188 | 188 | $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
| 189 | - foreach(array_keys($valeurs) as $champ){ |
|
| 190 | - if ($champ[0]!=='_' AND !in_array($champ, array('message_ok','message_erreur','editable'))) { |
|
| 191 | - if ($dispo AND (($v = _request($champ))!==NULL)) |
|
| 189 | + foreach (array_keys($valeurs) as $champ) { |
|
| 190 | + if ($champ[0] !== '_' AND !in_array($champ, array('message_ok', 'message_erreur', 'editable'))) { |
|
| 191 | + if ($dispo AND (($v = _request($champ)) !== NULL)) |
|
| 192 | 192 | $valeurs[$champ] = $v; |
| 193 | 193 | // nettoyer l'url des champs qui vont etre saisis |
| 194 | 194 | if ($action) |
| 195 | - $action = parametre_url($action,$champ,''); |
|
| 195 | + $action = parametre_url($action, $champ, ''); |
|
| 196 | 196 | // proteger les ' et les " dans les champs que l'on va injecter |
| 197 | 197 | $valeurs[$champ] = protege_champ($valeurs[$champ]); |
| 198 | 198 | } |
@@ -200,14 +200,14 @@ discard block |
||
| 200 | 200 | |
| 201 | 201 | if ($action) { |
| 202 | 202 | // nettoyer l'url |
| 203 | - $action = parametre_url($action,'formulaire_action',''); |
|
| 204 | - $action = parametre_url($action,'formulaire_action_args',''); |
|
| 203 | + $action = parametre_url($action, 'formulaire_action', ''); |
|
| 204 | + $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if (isset($valeurs['_action'])){ |
|
| 208 | - $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 209 | - $secu = $securiser_action(reset($valeurs['_action']),end($valeurs['_action']),'',-1); |
|
| 210 | - $valeurs['_hidden'] = (isset($valeurs['_hidden'])?$valeurs['_hidden']:'') . |
|
| 207 | + if (isset($valeurs['_action'])) { |
|
| 208 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 209 | + $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1); |
|
| 210 | + $valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : ''). |
|
| 211 | 211 | "<input type='hidden' name='arg' value='".$secu['arg']."' />" |
| 212 | 212 | . "<input type='hidden' name='hash' value='".$secu['hash']."' />"; |
| 213 | 213 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | // editable peut venir de charger() ou de traiter() sinon |
| 226 | 226 | if (!isset($valeurs['editable'])) $valeurs['editable'] = $editable; |
| 227 | 227 | // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
| 228 | - $valeurs['editable'] = ($valeurs['editable']?' ':''); |
|
| 228 | + $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 229 | 229 | |
| 230 | 230 | if ($je_suis_poste) { |
| 231 | 231 | $valeurs['message_erreur'] = ""; |
@@ -252,34 +252,34 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function formulaire__charger($form, $args, $poste) |
| 254 | 254 | { |
| 255 | - if ($charger_valeurs = charger_fonction("charger","formulaires/$form",true)) |
|
| 256 | - $valeurs = call_user_func_array($charger_valeurs,$args); |
|
| 255 | + if ($charger_valeurs = charger_fonction("charger", "formulaires/$form", true)) |
|
| 256 | + $valeurs = call_user_func_array($charger_valeurs, $args); |
|
| 257 | 257 | else $valeurs = array(); |
| 258 | 258 | |
| 259 | 259 | $valeurs = pipeline( |
| 260 | 260 | 'formulaire_charger', |
| 261 | 261 | array( |
| 262 | - 'args'=>array('form'=>$form,'args'=>$args,'je_suis_poste'=>$poste), |
|
| 262 | + 'args'=>array('form'=>$form, 'args'=>$args, 'je_suis_poste'=>$poste), |
|
| 263 | 263 | 'data'=>$valeurs) |
| 264 | 264 | ); |
| 265 | 265 | |
| 266 | 266 | // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
| 267 | - if (is_array($valeurs)){ |
|
| 268 | - if (!isset($valeurs['_pipelines'])) $valeurs['_pipelines']=array(); |
|
| 267 | + if (is_array($valeurs)) { |
|
| 268 | + if (!isset($valeurs['_pipelines'])) $valeurs['_pipelines'] = array(); |
|
| 269 | 269 | // l'ancien argument _pipeline devient maintenant _pipelines |
| 270 | 270 | // reinjectons le vieux _pipeline au debut de _pipelines |
| 271 | 271 | if (isset($valeurs['_pipeline'])) { |
| 272 | - $pipe = is_array($valeurs['_pipeline'])?reset($valeurs['_pipeline']):$valeurs['_pipeline']; |
|
| 273 | - $args = is_array($valeurs['_pipeline'])?end($valeurs['_pipeline']):array(); |
|
| 272 | + $pipe = is_array($valeurs['_pipeline']) ?reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 273 | + $args = is_array($valeurs['_pipeline']) ?end($valeurs['_pipeline']) : array(); |
|
| 274 | 274 | |
| 275 | 275 | $pipelines = array($pipe=>$args); |
| 276 | - $valeurs['_pipelines'] = array_merge($pipelines,$valeurs['_pipelines']); |
|
| 276 | + $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
| 280 | 280 | // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
| 281 | 281 | // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
| 282 | - $valeurs['_pipelines']['formulaire_fond'] = array('form'=>$form,'args'=>$args,'je_suis_poste'=>$poste); |
|
| 282 | + $valeurs['_pipelines']['formulaire_fond'] = array('form'=>$form, 'args'=>$args, 'je_suis_poste'=>$poste); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | return $valeurs; |
@@ -301,9 +301,9 @@ discard block |
||
| 301 | 301 | * @return bool |
| 302 | 302 | */ |
| 303 | 303 | function formulaire__identifier($form, $args, $p) { |
| 304 | - if ($identifier_args = charger_fonction("identifier","formulaires/$form",true)) { |
|
| 305 | - return call_user_func_array($identifier_args,$args)===call_user_func_array($identifier_args,$p); |
|
| 304 | + if ($identifier_args = charger_fonction("identifier", "formulaires/$form", true)) { |
|
| 305 | + return call_user_func_array($identifier_args, $args) === call_user_func_array($identifier_args, $p); |
|
| 306 | 306 | } |
| 307 | - return $args===$p; |
|
| 307 | + return $args === $p; |
|
| 308 | 308 | } |
| 309 | 309 | ?> |
@@ -25,6 +25,9 @@ |
||
| 25 | 25 | // car rien ne garantit que le .htaccess soit identique. A approfondir |
| 26 | 26 | |
| 27 | 27 | // http://doc.spip.org/@generer_generer_url |
| 28 | +/** |
|
| 29 | + * @param string $type |
|
| 30 | + */ |
|
| 28 | 31 | function generer_generer_url($type, $p){ |
| 29 | 32 | $_id = interprete_argument_balise(1,$p); |
| 30 | 33 | |
@@ -26,95 +26,95 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | // http://doc.spip.org/@generer_generer_url |
| 28 | 28 | function generer_generer_url($type, $p){ |
| 29 | - $_id = interprete_argument_balise(1,$p); |
|
| 29 | + $_id = interprete_argument_balise(1,$p); |
|
| 30 | 30 | |
| 31 | - if (!$_id) { |
|
| 32 | - $primary = id_table_objet($type); |
|
| 33 | - $_id = champ_sql($primary, $p); |
|
| 34 | - } |
|
| 31 | + if (!$_id) { |
|
| 32 | + $primary = id_table_objet($type); |
|
| 33 | + $_id = champ_sql($primary, $p); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - return generer_generer_url_arg($type, $p, $_id); |
|
| 36 | + return generer_generer_url_arg($type, $p, $_id); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | function generer_generer_url_arg($type, $p, $_id) |
| 40 | 40 | { |
| 41 | - if ($s = trouver_nom_serveur_distant($p)) { |
|
| 41 | + if ($s = trouver_nom_serveur_distant($p)) { |
|
| 42 | 42 | |
| 43 | 43 | // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
| 44 | - if (function_exists($f = 'generer_generer_url_'.$s)){ |
|
| 45 | - return $f($type, $_id, $s); |
|
| 46 | - } |
|
| 47 | - if (!$GLOBALS['connexions'][strtolower($s)]['spip_connect_version']) { |
|
| 48 | - return NULL; |
|
| 49 | - } |
|
| 50 | - $s = _q($s); |
|
| 51 | - # exception des urls de documents sur un serveur distant... |
|
| 52 | - if ($type == 'document') { |
|
| 53 | - return |
|
| 54 | - "quete_meta('adresse_site', $s) . '/' .\n\t" . |
|
| 55 | - "quete_meta('dir_img', $s) . \n\t" . |
|
| 56 | - "quete_fichier($_id,$s)"; |
|
| 57 | - } |
|
| 58 | - $s = ", '', '', $s, quete_meta('type_urls', $s)"; |
|
| 59 | - } |
|
| 60 | - else |
|
| 61 | - $s = ", '', '', true"; |
|
| 62 | - return "urlencode_1738(generer_url_entite($_id, '$type'$s))"; |
|
| 44 | + if (function_exists($f = 'generer_generer_url_'.$s)){ |
|
| 45 | + return $f($type, $_id, $s); |
|
| 46 | + } |
|
| 47 | + if (!$GLOBALS['connexions'][strtolower($s)]['spip_connect_version']) { |
|
| 48 | + return NULL; |
|
| 49 | + } |
|
| 50 | + $s = _q($s); |
|
| 51 | + # exception des urls de documents sur un serveur distant... |
|
| 52 | + if ($type == 'document') { |
|
| 53 | + return |
|
| 54 | + "quete_meta('adresse_site', $s) . '/' .\n\t" . |
|
| 55 | + "quete_meta('dir_img', $s) . \n\t" . |
|
| 56 | + "quete_fichier($_id,$s)"; |
|
| 57 | + } |
|
| 58 | + $s = ", '', '', $s, quete_meta('type_urls', $s)"; |
|
| 59 | + } |
|
| 60 | + else |
|
| 61 | + $s = ", '', '', true"; |
|
| 62 | + return "urlencode_1738(generer_url_entite($_id, '$type'$s))"; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | // http://doc.spip.org/@balise_URL__dist |
| 67 | 67 | function balise_URL__dist($p) { |
| 68 | 68 | |
| 69 | - $nom = $p->nom_champ; |
|
| 70 | - if ($nom === 'URL_') { |
|
| 71 | - $msg = array('zbug_balise_sans_argument', array('balise' => ' URL_')); |
|
| 72 | - erreur_squelette($msg, $p); |
|
| 73 | - $p->interdire_scripts = false; |
|
| 74 | - return $p; |
|
| 75 | - } elseif ($f = charger_fonction($nom, 'balise', true)) { |
|
| 76 | - return $f($p); |
|
| 77 | - }else { |
|
| 78 | - $nom = strtolower($nom); |
|
| 79 | - $code = generer_generer_url(substr($nom,4), $p); |
|
| 80 | - $code = champ_sql($nom, $p, $code); |
|
| 81 | - $p->code = $code; |
|
| 82 | - if (!$p->etoile) |
|
| 83 | - $p->code = "vider_url($code)"; |
|
| 84 | - $p->interdire_scripts = false; |
|
| 85 | - return $p; |
|
| 86 | - } |
|
| 69 | + $nom = $p->nom_champ; |
|
| 70 | + if ($nom === 'URL_') { |
|
| 71 | + $msg = array('zbug_balise_sans_argument', array('balise' => ' URL_')); |
|
| 72 | + erreur_squelette($msg, $p); |
|
| 73 | + $p->interdire_scripts = false; |
|
| 74 | + return $p; |
|
| 75 | + } elseif ($f = charger_fonction($nom, 'balise', true)) { |
|
| 76 | + return $f($p); |
|
| 77 | + }else { |
|
| 78 | + $nom = strtolower($nom); |
|
| 79 | + $code = generer_generer_url(substr($nom,4), $p); |
|
| 80 | + $code = champ_sql($nom, $p, $code); |
|
| 81 | + $p->code = $code; |
|
| 82 | + if (!$p->etoile) |
|
| 83 | + $p->code = "vider_url($code)"; |
|
| 84 | + $p->interdire_scripts = false; |
|
| 85 | + return $p; |
|
| 86 | + } |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // http://doc.spip.org/@balise_URL_ARTICLE_dist |
| 90 | 90 | function balise_URL_ARTICLE_dist($p) { |
| 91 | 91 | |
| 92 | - // Cas particulier des boucles (SYNDIC_ARTICLES) |
|
| 93 | - if ($p->type_requete == 'syndic_articles') { |
|
| 94 | - $code = champ_sql('url', $p); |
|
| 95 | - } else $code = generer_generer_url('article', $p); |
|
| 92 | + // Cas particulier des boucles (SYNDIC_ARTICLES) |
|
| 93 | + if ($p->type_requete == 'syndic_articles') { |
|
| 94 | + $code = champ_sql('url', $p); |
|
| 95 | + } else $code = generer_generer_url('article', $p); |
|
| 96 | 96 | |
| 97 | - $p->code = $code; |
|
| 98 | - if (!$p->etoile) |
|
| 99 | - $p->code = "vider_url($code)"; |
|
| 100 | - $p->interdire_scripts = false; |
|
| 101 | - return $p; |
|
| 97 | + $p->code = $code; |
|
| 98 | + if (!$p->etoile) |
|
| 99 | + $p->code = "vider_url($code)"; |
|
| 100 | + $p->interdire_scripts = false; |
|
| 101 | + return $p; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // http://doc.spip.org/@balise_URL_SITE_dist |
| 105 | 105 | function balise_URL_SITE_dist($p) |
| 106 | 106 | { |
| 107 | - $code = champ_sql('url_site', $p); |
|
| 108 | - if (strpos($code, '@$Pile[0]') !== false) { |
|
| 109 | - $code = generer_generer_url('site', $p); |
|
| 110 | - if ($code === NULL) return NULL; |
|
| 111 | - } else { |
|
| 112 | - if (!$p->etoile) |
|
| 113 | - $code = "calculer_url($code,'','url', \$connect)"; |
|
| 114 | - } |
|
| 115 | - $p->code = $code; |
|
| 116 | - $p->interdire_scripts = false; |
|
| 117 | - return $p; |
|
| 107 | + $code = champ_sql('url_site', $p); |
|
| 108 | + if (strpos($code, '@$Pile[0]') !== false) { |
|
| 109 | + $code = generer_generer_url('site', $p); |
|
| 110 | + if ($code === NULL) return NULL; |
|
| 111 | + } else { |
|
| 112 | + if (!$p->etoile) |
|
| 113 | + $code = "calculer_url($code,'','url', \$connect)"; |
|
| 114 | + } |
|
| 115 | + $p->code = $code; |
|
| 116 | + $p->interdire_scripts = false; |
|
| 117 | + return $p; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // Autres balises URL_*, qui ne concernent pas une table |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | // http://doc.spip.org/@balise_URL_SITE_SPIP_dist |
| 124 | 124 | function balise_URL_SITE_SPIP_dist($p) { |
| 125 | - $p->code = "sinon(\$GLOBALS['meta']['adresse_site'],'.')"; |
|
| 126 | - $p->code = "spip_htmlspecialchars(".$p->code.")"; |
|
| 127 | - $p->interdire_scripts = false; |
|
| 128 | - return $p; |
|
| 125 | + $p->code = "sinon(\$GLOBALS['meta']['adresse_site'],'.')"; |
|
| 126 | + $p->code = "spip_htmlspecialchars(".$p->code.")"; |
|
| 127 | + $p->interdire_scripts = false; |
|
| 128 | + return $p; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // |
@@ -137,36 +137,36 @@ discard block |
||
| 137 | 137 | // http://doc.spip.org/@balise_URL_PAGE_dist |
| 138 | 138 | function balise_URL_PAGE_dist($p) { |
| 139 | 139 | |
| 140 | - $code = interprete_argument_balise(1,$p); |
|
| 141 | - $args = interprete_argument_balise(2,$p); |
|
| 142 | - if ($args == NULL) |
|
| 143 | - $args = "''"; |
|
| 144 | - |
|
| 145 | - if ($s = trouver_nom_serveur_distant($p)) { |
|
| 146 | - // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
|
| 147 | - // elle devra aussi traiter le cas derogatoire type=page |
|
| 148 | - if (function_exists($f = 'generer_generer_url_'.$s)){ |
|
| 149 | - if ($args AND $args!=="''") $code .= ", $args"; |
|
| 150 | - $code = $f('page', $code, $s); |
|
| 151 | - return $p; |
|
| 152 | - } |
|
| 153 | - $s = 'connect=' . addslashes($s); |
|
| 154 | - $args = (($args AND $args!=="''") ? "$args . '&$s'" : "'$s'"); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (!$code) { |
|
| 158 | - $noentities = $p->etoile ? "'&'" : ''; |
|
| 159 | - $code = "url_de_base() . preg_replace(',^./,', '', self($noentities))"; |
|
| 160 | - } else{ |
|
| 161 | - if (!$args) $args = "''"; |
|
| 162 | - $noentities = $p->etoile ? ", true" : ''; |
|
| 163 | - $code = "generer_url_public($code, $args$noentities)"; |
|
| 164 | - } |
|
| 165 | - $p->code = $code; |
|
| 166 | - spip_log("connect vaut $s ca donne " . $p->code . " args $args"); |
|
| 167 | - |
|
| 168 | - #$p->interdire_scripts = true; |
|
| 169 | - return $p; |
|
| 140 | + $code = interprete_argument_balise(1,$p); |
|
| 141 | + $args = interprete_argument_balise(2,$p); |
|
| 142 | + if ($args == NULL) |
|
| 143 | + $args = "''"; |
|
| 144 | + |
|
| 145 | + if ($s = trouver_nom_serveur_distant($p)) { |
|
| 146 | + // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
|
| 147 | + // elle devra aussi traiter le cas derogatoire type=page |
|
| 148 | + if (function_exists($f = 'generer_generer_url_'.$s)){ |
|
| 149 | + if ($args AND $args!=="''") $code .= ", $args"; |
|
| 150 | + $code = $f('page', $code, $s); |
|
| 151 | + return $p; |
|
| 152 | + } |
|
| 153 | + $s = 'connect=' . addslashes($s); |
|
| 154 | + $args = (($args AND $args!=="''") ? "$args . '&$s'" : "'$s'"); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (!$code) { |
|
| 158 | + $noentities = $p->etoile ? "'&'" : ''; |
|
| 159 | + $code = "url_de_base() . preg_replace(',^./,', '', self($noentities))"; |
|
| 160 | + } else{ |
|
| 161 | + if (!$args) $args = "''"; |
|
| 162 | + $noentities = $p->etoile ? ", true" : ''; |
|
| 163 | + $code = "generer_url_public($code, $args$noentities)"; |
|
| 164 | + } |
|
| 165 | + $p->code = $code; |
|
| 166 | + spip_log("connect vaut $s ca donne " . $p->code . " args $args"); |
|
| 167 | + |
|
| 168 | + #$p->interdire_scripts = true; |
|
| 169 | + return $p; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // |
@@ -175,24 +175,24 @@ discard block |
||
| 175 | 175 | // http://doc.spip.org/@balise_URL_ECRIRE_dist |
| 176 | 176 | function balise_URL_ECRIRE_dist($p) { |
| 177 | 177 | |
| 178 | - $code = interprete_argument_balise(1,$p); |
|
| 179 | - if (!$code) { |
|
| 180 | - $fonc = "''"; |
|
| 181 | - } |
|
| 182 | - else { |
|
| 183 | - $fonc = $code; |
|
| 184 | - $args = interprete_argument_balise(2,$p); |
|
| 185 | - if ($args === NULL) { |
|
| 186 | - $args = "''"; |
|
| 187 | - } |
|
| 188 | - $noentities = $p->etoile ? ", true" : ''; |
|
| 189 | - if (($args != "''") OR $noentities) { |
|
| 190 | - $fonc .= ",$args$noentities"; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - $p->code = 'generer_url_ecrire(' . $fonc .')'; |
|
| 194 | - $p->interdire_scripts = false; |
|
| 195 | - return $p; |
|
| 178 | + $code = interprete_argument_balise(1,$p); |
|
| 179 | + if (!$code) { |
|
| 180 | + $fonc = "''"; |
|
| 181 | + } |
|
| 182 | + else { |
|
| 183 | + $fonc = $code; |
|
| 184 | + $args = interprete_argument_balise(2,$p); |
|
| 185 | + if ($args === NULL) { |
|
| 186 | + $args = "''"; |
|
| 187 | + } |
|
| 188 | + $noentities = $p->etoile ? ", true" : ''; |
|
| 189 | + if (($args != "''") OR $noentities) { |
|
| 190 | + $fonc .= ",$args$noentities"; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + $p->code = 'generer_url_ecrire(' . $fonc .')'; |
|
| 194 | + $p->interdire_scripts = false; |
|
| 195 | + return $p; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // |
@@ -200,21 +200,21 @@ discard block |
||
| 200 | 200 | // |
| 201 | 201 | // http://doc.spip.org/@balise_URL_ACTION_AUTEUR_dist |
| 202 | 202 | function balise_URL_ACTION_AUTEUR_dist($p) { |
| 203 | - $p->descr['session'] = true; |
|
| 204 | - |
|
| 205 | - $p->code = interprete_argument_balise(1,$p); |
|
| 206 | - $args = interprete_argument_balise(2,$p); |
|
| 207 | - if ($args != "''" && $args!==NULL) |
|
| 208 | - $p->code .= ",".$args; |
|
| 209 | - $redirect = interprete_argument_balise(3,$p); |
|
| 210 | - if ($redirect != "''" && $redirect!==NULL) { |
|
| 211 | - if ($args == "''" || $args===NULL) |
|
| 212 | - $p->code .= ",''"; |
|
| 213 | - $p->code .= ",".$redirect; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $p->code = "generer_action_auteur(" . $p->code . ")"; |
|
| 217 | - $p->interdire_scripts = false; |
|
| 218 | - return $p; |
|
| 203 | + $p->descr['session'] = true; |
|
| 204 | + |
|
| 205 | + $p->code = interprete_argument_balise(1,$p); |
|
| 206 | + $args = interprete_argument_balise(2,$p); |
|
| 207 | + if ($args != "''" && $args!==NULL) |
|
| 208 | + $p->code .= ",".$args; |
|
| 209 | + $redirect = interprete_argument_balise(3,$p); |
|
| 210 | + if ($redirect != "''" && $redirect!==NULL) { |
|
| 211 | + if ($args == "''" || $args===NULL) |
|
| 212 | + $p->code .= ",''"; |
|
| 213 | + $p->code .= ",".$redirect; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $p->code = "generer_action_auteur(" . $p->code . ")"; |
|
| 217 | + $p->interdire_scripts = false; |
|
| 218 | + return $p; |
|
| 219 | 219 | } |
| 220 | 220 | ?> |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | // car rien ne garantit que le .htaccess soit identique. A approfondir |
| 26 | 26 | |
| 27 | 27 | // http://doc.spip.org/@generer_generer_url |
| 28 | -function generer_generer_url($type, $p){ |
|
| 29 | - $_id = interprete_argument_balise(1,$p); |
|
| 28 | +function generer_generer_url($type, $p) { |
|
| 29 | + $_id = interprete_argument_balise(1, $p); |
|
| 30 | 30 | |
| 31 | 31 | if (!$_id) { |
| 32 | 32 | $primary = id_table_objet($type); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | if ($s = trouver_nom_serveur_distant($p)) { |
| 42 | 42 | |
| 43 | 43 | // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
| 44 | - if (function_exists($f = 'generer_generer_url_'.$s)){ |
|
| 44 | + if (function_exists($f = 'generer_generer_url_'.$s)) { |
|
| 45 | 45 | return $f($type, $_id, $s); |
| 46 | 46 | } |
| 47 | 47 | if (!$GLOBALS['connexions'][strtolower($s)]['spip_connect_version']) { |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | # exception des urls de documents sur un serveur distant... |
| 52 | 52 | if ($type == 'document') { |
| 53 | 53 | return |
| 54 | - "quete_meta('adresse_site', $s) . '/' .\n\t" . |
|
| 55 | - "quete_meta('dir_img', $s) . \n\t" . |
|
| 54 | + "quete_meta('adresse_site', $s) . '/' .\n\t". |
|
| 55 | + "quete_meta('dir_img', $s) . \n\t". |
|
| 56 | 56 | "quete_fichier($_id,$s)"; |
| 57 | 57 | } |
| 58 | 58 | $s = ", '', '', $s, quete_meta('type_urls', $s)"; |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | return $p; |
| 75 | 75 | } elseif ($f = charger_fonction($nom, 'balise', true)) { |
| 76 | 76 | return $f($p); |
| 77 | - }else { |
|
| 77 | + } else { |
|
| 78 | 78 | $nom = strtolower($nom); |
| 79 | - $code = generer_generer_url(substr($nom,4), $p); |
|
| 79 | + $code = generer_generer_url(substr($nom, 4), $p); |
|
| 80 | 80 | $code = champ_sql($nom, $p, $code); |
| 81 | 81 | $p->code = $code; |
| 82 | 82 | if (!$p->etoile) |
@@ -137,33 +137,33 @@ discard block |
||
| 137 | 137 | // http://doc.spip.org/@balise_URL_PAGE_dist |
| 138 | 138 | function balise_URL_PAGE_dist($p) { |
| 139 | 139 | |
| 140 | - $code = interprete_argument_balise(1,$p); |
|
| 141 | - $args = interprete_argument_balise(2,$p); |
|
| 140 | + $code = interprete_argument_balise(1, $p); |
|
| 141 | + $args = interprete_argument_balise(2, $p); |
|
| 142 | 142 | if ($args == NULL) |
| 143 | 143 | $args = "''"; |
| 144 | 144 | |
| 145 | 145 | if ($s = trouver_nom_serveur_distant($p)) { |
| 146 | 146 | // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
| 147 | 147 | // elle devra aussi traiter le cas derogatoire type=page |
| 148 | - if (function_exists($f = 'generer_generer_url_'.$s)){ |
|
| 149 | - if ($args AND $args!=="''") $code .= ", $args"; |
|
| 148 | + if (function_exists($f = 'generer_generer_url_'.$s)) { |
|
| 149 | + if ($args AND $args !== "''") $code .= ", $args"; |
|
| 150 | 150 | $code = $f('page', $code, $s); |
| 151 | 151 | return $p; |
| 152 | 152 | } |
| 153 | - $s = 'connect=' . addslashes($s); |
|
| 154 | - $args = (($args AND $args!=="''") ? "$args . '&$s'" : "'$s'"); |
|
| 153 | + $s = 'connect='.addslashes($s); |
|
| 154 | + $args = (($args AND $args !== "''") ? "$args . '&$s'" : "'$s'"); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (!$code) { |
| 158 | 158 | $noentities = $p->etoile ? "'&'" : ''; |
| 159 | 159 | $code = "url_de_base() . preg_replace(',^./,', '', self($noentities))"; |
| 160 | - } else{ |
|
| 160 | + } else { |
|
| 161 | 161 | if (!$args) $args = "''"; |
| 162 | 162 | $noentities = $p->etoile ? ", true" : ''; |
| 163 | 163 | $code = "generer_url_public($code, $args$noentities)"; |
| 164 | 164 | } |
| 165 | 165 | $p->code = $code; |
| 166 | - spip_log("connect vaut $s ca donne " . $p->code . " args $args"); |
|
| 166 | + spip_log("connect vaut $s ca donne ".$p->code." args $args"); |
|
| 167 | 167 | |
| 168 | 168 | #$p->interdire_scripts = true; |
| 169 | 169 | return $p; |
@@ -175,22 +175,22 @@ discard block |
||
| 175 | 175 | // http://doc.spip.org/@balise_URL_ECRIRE_dist |
| 176 | 176 | function balise_URL_ECRIRE_dist($p) { |
| 177 | 177 | |
| 178 | - $code = interprete_argument_balise(1,$p); |
|
| 178 | + $code = interprete_argument_balise(1, $p); |
|
| 179 | 179 | if (!$code) { |
| 180 | 180 | $fonc = "''"; |
| 181 | 181 | } |
| 182 | 182 | else { |
| 183 | 183 | $fonc = $code; |
| 184 | - $args = interprete_argument_balise(2,$p); |
|
| 184 | + $args = interprete_argument_balise(2, $p); |
|
| 185 | 185 | if ($args === NULL) { |
| 186 | 186 | $args = "''"; |
| 187 | 187 | } |
| 188 | 188 | $noentities = $p->etoile ? ", true" : ''; |
| 189 | - if (($args != "''") OR $noentities) { |
|
| 189 | + if (($args != "''") OR $noentities) { |
|
| 190 | 190 | $fonc .= ",$args$noentities"; |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | - $p->code = 'generer_url_ecrire(' . $fonc .')'; |
|
| 193 | + $p->code = 'generer_url_ecrire('.$fonc.')'; |
|
| 194 | 194 | $p->interdire_scripts = false; |
| 195 | 195 | return $p; |
| 196 | 196 | } |
@@ -202,18 +202,18 @@ discard block |
||
| 202 | 202 | function balise_URL_ACTION_AUTEUR_dist($p) { |
| 203 | 203 | $p->descr['session'] = true; |
| 204 | 204 | |
| 205 | - $p->code = interprete_argument_balise(1,$p); |
|
| 206 | - $args = interprete_argument_balise(2,$p); |
|
| 207 | - if ($args != "''" && $args!==NULL) |
|
| 205 | + $p->code = interprete_argument_balise(1, $p); |
|
| 206 | + $args = interprete_argument_balise(2, $p); |
|
| 207 | + if ($args != "''" && $args !== NULL) |
|
| 208 | 208 | $p->code .= ",".$args; |
| 209 | - $redirect = interprete_argument_balise(3,$p); |
|
| 210 | - if ($redirect != "''" && $redirect!==NULL) { |
|
| 211 | - if ($args == "''" || $args===NULL) |
|
| 209 | + $redirect = interprete_argument_balise(3, $p); |
|
| 210 | + if ($redirect != "''" && $redirect !== NULL) { |
|
| 211 | + if ($args == "''" || $args === NULL) |
|
| 212 | 212 | $p->code .= ",''"; |
| 213 | 213 | $p->code .= ",".$redirect; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - $p->code = "generer_action_auteur(" . $p->code . ")"; |
|
| 216 | + $p->code = "generer_action_auteur(".$p->code.")"; |
|
| 217 | 217 | $p->interdire_scripts = false; |
| 218 | 218 | return $p; |
| 219 | 219 | } |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | // Les balises URL_$type sont generiques, sauf qq cas particuliers. |
| 16 | 18 | // Si ces balises sont utilisees pour la base locale, |
@@ -56,9 +58,9 @@ discard block |
||
| 56 | 58 | "quete_fichier($_id,$s)"; |
| 57 | 59 | } |
| 58 | 60 | $s = ", '', '', $s, quete_meta('type_urls', $s)"; |
| 61 | + } else { |
|
| 62 | + $s = ", '', '', true"; |
|
| 59 | 63 | } |
| 60 | - else |
|
| 61 | - $s = ", '', '', true"; |
|
| 62 | 64 | return "urlencode_1738(generer_url_entite($_id, '$type'$s))"; |
| 63 | 65 | } |
| 64 | 66 | |
@@ -74,13 +76,14 @@ discard block |
||
| 74 | 76 | return $p; |
| 75 | 77 | } elseif ($f = charger_fonction($nom, 'balise', true)) { |
| 76 | 78 | return $f($p); |
| 77 | - }else { |
|
| 79 | + } else { |
|
| 78 | 80 | $nom = strtolower($nom); |
| 79 | 81 | $code = generer_generer_url(substr($nom,4), $p); |
| 80 | 82 | $code = champ_sql($nom, $p, $code); |
| 81 | 83 | $p->code = $code; |
| 82 | - if (!$p->etoile) |
|
| 83 | - $p->code = "vider_url($code)"; |
|
| 84 | + if (!$p->etoile) { |
|
| 85 | + $p->code = "vider_url($code)"; |
|
| 86 | + } |
|
| 84 | 87 | $p->interdire_scripts = false; |
| 85 | 88 | return $p; |
| 86 | 89 | } |
@@ -92,11 +95,14 @@ discard block |
||
| 92 | 95 | // Cas particulier des boucles (SYNDIC_ARTICLES) |
| 93 | 96 | if ($p->type_requete == 'syndic_articles') { |
| 94 | 97 | $code = champ_sql('url', $p); |
| 95 | - } else $code = generer_generer_url('article', $p); |
|
| 98 | + } else { |
|
| 99 | + $code = generer_generer_url('article', $p); |
|
| 100 | + } |
|
| 96 | 101 | |
| 97 | 102 | $p->code = $code; |
| 98 | - if (!$p->etoile) |
|
| 99 | - $p->code = "vider_url($code)"; |
|
| 103 | + if (!$p->etoile) { |
|
| 104 | + $p->code = "vider_url($code)"; |
|
| 105 | + } |
|
| 100 | 106 | $p->interdire_scripts = false; |
| 101 | 107 | return $p; |
| 102 | 108 | } |
@@ -107,10 +113,13 @@ discard block |
||
| 107 | 113 | $code = champ_sql('url_site', $p); |
| 108 | 114 | if (strpos($code, '@$Pile[0]') !== false) { |
| 109 | 115 | $code = generer_generer_url('site', $p); |
| 110 | - if ($code === NULL) return NULL; |
|
| 116 | + if ($code === NULL) { |
|
| 117 | + return NULL; |
|
| 118 | + } |
|
| 111 | 119 | } else { |
| 112 | - if (!$p->etoile) |
|
| 113 | - $code = "calculer_url($code,'','url', \$connect)"; |
|
| 120 | + if (!$p->etoile) { |
|
| 121 | + $code = "calculer_url($code,'','url', \$connect)"; |
|
| 122 | + } |
|
| 114 | 123 | } |
| 115 | 124 | $p->code = $code; |
| 116 | 125 | $p->interdire_scripts = false; |
@@ -139,14 +148,17 @@ discard block |
||
| 139 | 148 | |
| 140 | 149 | $code = interprete_argument_balise(1,$p); |
| 141 | 150 | $args = interprete_argument_balise(2,$p); |
| 142 | - if ($args == NULL) |
|
| 143 | - $args = "''"; |
|
| 151 | + if ($args == NULL) { |
|
| 152 | + $args = "''"; |
|
| 153 | + } |
|
| 144 | 154 | |
| 145 | 155 | if ($s = trouver_nom_serveur_distant($p)) { |
| 146 | 156 | // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
| 147 | 157 | // elle devra aussi traiter le cas derogatoire type=page |
| 148 | 158 | if (function_exists($f = 'generer_generer_url_'.$s)){ |
| 149 | - if ($args AND $args!=="''") $code .= ", $args"; |
|
| 159 | + if ($args AND $args!=="''") { |
|
| 160 | + $code .= ", $args"; |
|
| 161 | + } |
|
| 150 | 162 | $code = $f('page', $code, $s); |
| 151 | 163 | return $p; |
| 152 | 164 | } |
@@ -158,7 +170,9 @@ discard block |
||
| 158 | 170 | $noentities = $p->etoile ? "'&'" : ''; |
| 159 | 171 | $code = "url_de_base() . preg_replace(',^./,', '', self($noentities))"; |
| 160 | 172 | } else{ |
| 161 | - if (!$args) $args = "''"; |
|
| 173 | + if (!$args) { |
|
| 174 | + $args = "''"; |
|
| 175 | + } |
|
| 162 | 176 | $noentities = $p->etoile ? ", true" : ''; |
| 163 | 177 | $code = "generer_url_public($code, $args$noentities)"; |
| 164 | 178 | } |
@@ -178,8 +192,7 @@ discard block |
||
| 178 | 192 | $code = interprete_argument_balise(1,$p); |
| 179 | 193 | if (!$code) { |
| 180 | 194 | $fonc = "''"; |
| 181 | - } |
|
| 182 | - else { |
|
| 195 | + } else { |
|
| 183 | 196 | $fonc = $code; |
| 184 | 197 | $args = interprete_argument_balise(2,$p); |
| 185 | 198 | if ($args === NULL) { |
@@ -204,12 +217,14 @@ discard block |
||
| 204 | 217 | |
| 205 | 218 | $p->code = interprete_argument_balise(1,$p); |
| 206 | 219 | $args = interprete_argument_balise(2,$p); |
| 207 | - if ($args != "''" && $args!==NULL) |
|
| 208 | - $p->code .= ",".$args; |
|
| 220 | + if ($args != "''" && $args!==NULL) { |
|
| 221 | + $p->code .= ",".$args; |
|
| 222 | + } |
|
| 209 | 223 | $redirect = interprete_argument_balise(3,$p); |
| 210 | 224 | if ($redirect != "''" && $redirect!==NULL) { |
| 211 | - if ($args == "''" || $args===NULL) |
|
| 212 | - $p->code .= ",''"; |
|
| 225 | + if ($args == "''" || $args===NULL) { |
|
| 226 | + $p->code .= ",''"; |
|
| 227 | + } |
|
| 213 | 228 | $p->code .= ",".$redirect; |
| 214 | 229 | } |
| 215 | 230 | |
@@ -25,6 +25,9 @@ |
||
| 25 | 25 | // A l'installation, il faut simuler l'existence de ce fichier |
| 26 | 26 | |
| 27 | 27 | // http://doc.spip.org/@spip_connect |
| 28 | +/** |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 28 | 31 | function spip_connect($serveur='', $version='') { |
| 29 | 32 | global $connexions, $spip_sql_version; |
| 30 | 33 | |
@@ -26,108 +26,108 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | // http://doc.spip.org/@spip_connect |
| 28 | 28 | function spip_connect($serveur='', $version='') { |
| 29 | - global $connexions, $spip_sql_version; |
|
| 30 | - |
|
| 31 | - $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 32 | - $index = $serveur ? $serveur : 0; |
|
| 33 | - if (!$version) $version = $spip_sql_version; |
|
| 34 | - if (isset($connexions[$index][$version])) return $connexions[$index]; |
|
| 35 | - |
|
| 36 | - include_spip('base/abstract_sql'); |
|
| 37 | - $install = (_request('exec') == 'install'); |
|
| 38 | - |
|
| 39 | - // Premiere connexion ? |
|
| 40 | - if (!($old = isset($connexions[$index]))) { |
|
| 41 | - $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 42 | - ? '' // nom de serveur mal ecrit |
|
| 43 | - : ($serveur ? |
|
| 44 | - ( _DIR_CONNECT. $serveur . '.php') // serveur externe |
|
| 45 | - : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
|
| 46 | - : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 47 | - : ''))); // installation pas faite |
|
| 48 | - |
|
| 49 | - unset($GLOBALS['db_ok']); |
|
| 50 | - unset($GLOBALS['spip_connect_version']); |
|
| 51 | - if ($f) { |
|
| 52 | - if (is_readable($f)) { |
|
| 53 | - include($f); |
|
| 54 | - } elseif ($serveur AND !$install) { |
|
| 55 | - // chercher une declaration de serveur dans le path |
|
| 56 | - // qui pourra un jour servir a declarer des bases sqlite |
|
| 57 | - // par des plugins. Et sert aussi aux boucles POUR. |
|
| 58 | - find_in_path("$serveur.php",'connect/',true); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 62 | - // fera mieux la prochaine fois |
|
| 63 | - if ($install) return false; |
|
| 64 | - if ($f AND is_readable($f)) |
|
| 65 | - spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 66 | - else |
|
| 67 | - spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 68 | - spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 69 | - // ne plus reessayer si ce n'est pas l'install |
|
| 70 | - return $connexions[$index]=false; |
|
| 71 | - } |
|
| 72 | - $connexions[$index] = $GLOBALS['db_ok']; |
|
| 73 | - } |
|
| 74 | - // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 75 | - if (!$connexions[$index]) return false; |
|
| 76 | - |
|
| 77 | - // la connexion a reussi ou etait deja faite. |
|
| 78 | - // chargement de la version du jeu de fonctions |
|
| 79 | - // si pas dans le fichier par defaut |
|
| 80 | - $type = $GLOBALS['db_ok']['type']; |
|
| 81 | - $jeu = 'spip_' . $type .'_functions_' . $version; |
|
| 82 | - if (!isset($GLOBALS[$jeu])) { |
|
| 83 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)){ |
|
| 84 | - spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 85 | - // ne plus reessayer |
|
| 86 | - return $connexions[$index][$version] = array(); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - $connexions[$index][$version] = $GLOBALS[$jeu]; |
|
| 90 | - if ($old) return $connexions[$index]; |
|
| 91 | - |
|
| 92 | - $connexions[$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0; |
|
| 93 | - |
|
| 94 | - // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 95 | - // si l'installation l'a determine. |
|
| 96 | - // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 97 | - // s'ils le connaissent |
|
| 98 | - |
|
| 99 | - if (!$serveur) { |
|
| 100 | - $charset = spip_connect_main($GLOBALS[$jeu]); |
|
| 101 | - if (!$charset) { |
|
| 102 | - unset($connexions[$index]); |
|
| 103 | - spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT); |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - } else { |
|
| 107 | - // spip_meta n'existe pas toujours dans la base |
|
| 108 | - // C'est le cas d'un dump sqlite par exemple |
|
| 109 | - if ($connexions[$index]['spip_connect_version'] |
|
| 110 | - AND sql_showtable('spip_meta', true, $serveur) |
|
| 111 | - AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'",'','','','',$serveur)) |
|
| 112 | - $charset = $r; |
|
| 113 | - else $charset = -1; |
|
| 114 | - } |
|
| 115 | - if ($charset != -1) { |
|
| 116 | - $f = $GLOBALS[$jeu]['set_charset']; |
|
| 117 | - if (function_exists($f)) |
|
| 118 | - $f($charset, $serveur); |
|
| 119 | - } |
|
| 120 | - return $connexions[$index]; |
|
| 29 | + global $connexions, $spip_sql_version; |
|
| 30 | + |
|
| 31 | + $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 32 | + $index = $serveur ? $serveur : 0; |
|
| 33 | + if (!$version) $version = $spip_sql_version; |
|
| 34 | + if (isset($connexions[$index][$version])) return $connexions[$index]; |
|
| 35 | + |
|
| 36 | + include_spip('base/abstract_sql'); |
|
| 37 | + $install = (_request('exec') == 'install'); |
|
| 38 | + |
|
| 39 | + // Premiere connexion ? |
|
| 40 | + if (!($old = isset($connexions[$index]))) { |
|
| 41 | + $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 42 | + ? '' // nom de serveur mal ecrit |
|
| 43 | + : ($serveur ? |
|
| 44 | + ( _DIR_CONNECT. $serveur . '.php') // serveur externe |
|
| 45 | + : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
|
| 46 | + : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 47 | + : ''))); // installation pas faite |
|
| 48 | + |
|
| 49 | + unset($GLOBALS['db_ok']); |
|
| 50 | + unset($GLOBALS['spip_connect_version']); |
|
| 51 | + if ($f) { |
|
| 52 | + if (is_readable($f)) { |
|
| 53 | + include($f); |
|
| 54 | + } elseif ($serveur AND !$install) { |
|
| 55 | + // chercher une declaration de serveur dans le path |
|
| 56 | + // qui pourra un jour servir a declarer des bases sqlite |
|
| 57 | + // par des plugins. Et sert aussi aux boucles POUR. |
|
| 58 | + find_in_path("$serveur.php",'connect/',true); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 62 | + // fera mieux la prochaine fois |
|
| 63 | + if ($install) return false; |
|
| 64 | + if ($f AND is_readable($f)) |
|
| 65 | + spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 66 | + else |
|
| 67 | + spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 68 | + spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 69 | + // ne plus reessayer si ce n'est pas l'install |
|
| 70 | + return $connexions[$index]=false; |
|
| 71 | + } |
|
| 72 | + $connexions[$index] = $GLOBALS['db_ok']; |
|
| 73 | + } |
|
| 74 | + // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 75 | + if (!$connexions[$index]) return false; |
|
| 76 | + |
|
| 77 | + // la connexion a reussi ou etait deja faite. |
|
| 78 | + // chargement de la version du jeu de fonctions |
|
| 79 | + // si pas dans le fichier par defaut |
|
| 80 | + $type = $GLOBALS['db_ok']['type']; |
|
| 81 | + $jeu = 'spip_' . $type .'_functions_' . $version; |
|
| 82 | + if (!isset($GLOBALS[$jeu])) { |
|
| 83 | + if (!find_in_path($type . '_' . $version . '.php', 'req/', true)){ |
|
| 84 | + spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 85 | + // ne plus reessayer |
|
| 86 | + return $connexions[$index][$version] = array(); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + $connexions[$index][$version] = $GLOBALS[$jeu]; |
|
| 90 | + if ($old) return $connexions[$index]; |
|
| 91 | + |
|
| 92 | + $connexions[$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0; |
|
| 93 | + |
|
| 94 | + // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 95 | + // si l'installation l'a determine. |
|
| 96 | + // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 97 | + // s'ils le connaissent |
|
| 98 | + |
|
| 99 | + if (!$serveur) { |
|
| 100 | + $charset = spip_connect_main($GLOBALS[$jeu]); |
|
| 101 | + if (!$charset) { |
|
| 102 | + unset($connexions[$index]); |
|
| 103 | + spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT); |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | + } else { |
|
| 107 | + // spip_meta n'existe pas toujours dans la base |
|
| 108 | + // C'est le cas d'un dump sqlite par exemple |
|
| 109 | + if ($connexions[$index]['spip_connect_version'] |
|
| 110 | + AND sql_showtable('spip_meta', true, $serveur) |
|
| 111 | + AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'",'','','','',$serveur)) |
|
| 112 | + $charset = $r; |
|
| 113 | + else $charset = -1; |
|
| 114 | + } |
|
| 115 | + if ($charset != -1) { |
|
| 116 | + $f = $GLOBALS[$jeu]['set_charset']; |
|
| 117 | + if (function_exists($f)) |
|
| 118 | + $f($charset, $serveur); |
|
| 119 | + } |
|
| 120 | + return $connexions[$index]; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | function spip_sql_erreur($serveur='') |
| 124 | 124 | { |
| 125 | - $connexion = spip_connect($serveur); |
|
| 126 | - $e = sql_errno($serveur); |
|
| 127 | - $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
|
| 128 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\n" . $connexion['last']; |
|
| 129 | - $f = $t . $serveur; |
|
| 130 | - spip_log($m, $f.'.'._LOG_ERREUR); |
|
| 125 | + $connexion = spip_connect($serveur); |
|
| 126 | + $e = sql_errno($serveur); |
|
| 127 | + $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
|
| 128 | + $m = "Erreur $e de $t: " . sql_error($serveur) . "\n" . $connexion['last']; |
|
| 129 | + $f = $t . $serveur; |
|
| 130 | + spip_log($m, $f.'.'._LOG_ERREUR); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // Cette fonction ne doit etre appelee qu'a travers la fonction sql_serveur |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | // http://doc.spip.org/@spip_connect_sql |
| 139 | 139 | function spip_connect_sql($version, $ins='', $serveur='', $cont=false) { |
| 140 | - $desc = spip_connect($serveur, $version); |
|
| 141 | - if (function_exists($f = @$desc[$version][$ins])) return $f; |
|
| 142 | - if ($cont) return $desc; |
|
| 143 | - if ($ins) |
|
| 144 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 145 | - include_spip('inc/minipres'); |
|
| 146 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 147 | - exit; |
|
| 140 | + $desc = spip_connect($serveur, $version); |
|
| 141 | + if (function_exists($f = @$desc[$version][$ins])) return $f; |
|
| 142 | + if ($cont) return $desc; |
|
| 143 | + if ($ins) |
|
| 144 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 145 | + include_spip('inc/minipres'); |
|
| 146 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 147 | + exit; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -167,54 +167,54 @@ discard block |
||
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | 169 | function spip_connect_db($host, $port, $login, $pass, $db='', $type='mysql', $prefixe='', $auth='') { |
| 170 | - global $db_ok; |
|
| 171 | - |
|
| 172 | - // temps avant nouvelle tentative de connexion |
|
| 173 | - // suite a une connection echouee |
|
| 174 | - if (!defined('_CONNECT_RETRY_DELAY')) |
|
| 175 | - define('_CONNECT_RETRY_DELAY',30); |
|
| 176 | - |
|
| 177 | - $f = ""; |
|
| 178 | - // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 179 | - // pour ne pas declarer tout indisponible d'un coup |
|
| 180 | - // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 181 | - // car c'est un test de connexion |
|
| 182 | - if (!defined('_ECRIRE_INSTALL') AND !$db=="@test@") |
|
| 183 | - $f = _DIR_TMP . $type . '.' . substr(md5($host.$port.$db),0,8) . '.out'; |
|
| 184 | - elseif ($db=='@test@') |
|
| 185 | - $db = ''; |
|
| 186 | - |
|
| 187 | - if ($f |
|
| 188 | - AND @file_exists($f) |
|
| 189 | - AND (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)) { |
|
| 190 | - spip_log( "Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 191 | - return; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if (!$prefixe) |
|
| 195 | - $prefixe = isset($GLOBALS['table_prefix']) |
|
| 196 | - ? $GLOBALS['table_prefix'] : $db; |
|
| 197 | - $h = charger_fonction($type, 'req', true); |
|
| 198 | - if (!$h) { |
|
| 199 | - spip_log( "les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 200 | - return; |
|
| 201 | - } |
|
| 202 | - if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 203 | - |
|
| 204 | - if (!is_array($auth)) { |
|
| 205 | - // compatibilite version 0.7 initiale |
|
| 206 | - $g['ldap'] = $auth; |
|
| 207 | - $auth = array('ldap' => $auth); |
|
| 208 | - } |
|
| 209 | - $g['authentification'] = $auth; |
|
| 210 | - $g['type'] = $type; |
|
| 211 | - return $db_ok = $g; |
|
| 212 | - } |
|
| 213 | - // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 214 | - if ($f) { |
|
| 215 | - @touch($f); |
|
| 216 | - spip_log( "Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS); |
|
| 217 | - } |
|
| 170 | + global $db_ok; |
|
| 171 | + |
|
| 172 | + // temps avant nouvelle tentative de connexion |
|
| 173 | + // suite a une connection echouee |
|
| 174 | + if (!defined('_CONNECT_RETRY_DELAY')) |
|
| 175 | + define('_CONNECT_RETRY_DELAY',30); |
|
| 176 | + |
|
| 177 | + $f = ""; |
|
| 178 | + // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 179 | + // pour ne pas declarer tout indisponible d'un coup |
|
| 180 | + // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 181 | + // car c'est un test de connexion |
|
| 182 | + if (!defined('_ECRIRE_INSTALL') AND !$db=="@test@") |
|
| 183 | + $f = _DIR_TMP . $type . '.' . substr(md5($host.$port.$db),0,8) . '.out'; |
|
| 184 | + elseif ($db=='@test@') |
|
| 185 | + $db = ''; |
|
| 186 | + |
|
| 187 | + if ($f |
|
| 188 | + AND @file_exists($f) |
|
| 189 | + AND (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)) { |
|
| 190 | + spip_log( "Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 191 | + return; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if (!$prefixe) |
|
| 195 | + $prefixe = isset($GLOBALS['table_prefix']) |
|
| 196 | + ? $GLOBALS['table_prefix'] : $db; |
|
| 197 | + $h = charger_fonction($type, 'req', true); |
|
| 198 | + if (!$h) { |
|
| 199 | + spip_log( "les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 200 | + return; |
|
| 201 | + } |
|
| 202 | + if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 203 | + |
|
| 204 | + if (!is_array($auth)) { |
|
| 205 | + // compatibilite version 0.7 initiale |
|
| 206 | + $g['ldap'] = $auth; |
|
| 207 | + $auth = array('ldap' => $auth); |
|
| 208 | + } |
|
| 209 | + $g['authentification'] = $auth; |
|
| 210 | + $g['type'] = $type; |
|
| 211 | + return $db_ok = $g; |
|
| 212 | + } |
|
| 213 | + // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 214 | + if ($f) { |
|
| 215 | + @touch($f); |
|
| 216 | + spip_log( "Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS); |
|
| 217 | + } |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // Premiere connexion au serveur principal: |
@@ -233,25 +233,25 @@ discard block |
||
| 233 | 233 | // http://doc.spip.org/@spip_connect_main |
| 234 | 234 | function spip_connect_main($connexion) |
| 235 | 235 | { |
| 236 | - if ($GLOBALS['spip_connect_version']< 0.1 AND _DIR_RESTREINT){ |
|
| 237 | - include_spip('inc/headers'); |
|
| 238 | - redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - if (!($f = $connexion['select'])) return false; |
|
| 242 | - // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 243 | - if (!$r = $f('valeur','spip_meta', "nom='charset_sql_connexion'") |
|
| 244 | - OR is_string($r)) |
|
| 245 | - return false; |
|
| 246 | - if (!($f = $connexion['fetch'])) return false; |
|
| 247 | - $r = $f($r); |
|
| 248 | - return ($r['valeur'] ? $r['valeur'] : -1); |
|
| 236 | + if ($GLOBALS['spip_connect_version']< 0.1 AND _DIR_RESTREINT){ |
|
| 237 | + include_spip('inc/headers'); |
|
| 238 | + redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + if (!($f = $connexion['select'])) return false; |
|
| 242 | + // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 243 | + if (!$r = $f('valeur','spip_meta', "nom='charset_sql_connexion'") |
|
| 244 | + OR is_string($r)) |
|
| 245 | + return false; |
|
| 246 | + if (!($f = $connexion['fetch'])) return false; |
|
| 247 | + $r = $f($r); |
|
| 248 | + return ($r['valeur'] ? $r['valeur'] : -1); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // compatibilite |
| 252 | 252 | function spip_connect_ldap($serveur='') { |
| 253 | - include_spip('auth/ldap'); |
|
| 254 | - return auth_ldap_connect($serveur); |
|
| 253 | + include_spip('auth/ldap'); |
|
| 254 | + return auth_ldap_connect($serveur); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // Echappement d'une valeur (num, string, array) sous forme de chaine PHP |
@@ -259,23 +259,23 @@ discard block |
||
| 259 | 259 | // Usage sql un peu deprecie, a remplacer par sql_quote() |
| 260 | 260 | // http://doc.spip.org/@_q |
| 261 | 261 | function _q ($a) { |
| 262 | - return (is_numeric($a)) ? strval($a) : |
|
| 263 | - (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 264 | - : join(",", array_map('_q', $a))); |
|
| 262 | + return (is_numeric($a)) ? strval($a) : |
|
| 263 | + (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 264 | + : join(",", array_map('_q', $a))); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
| 268 | 268 | // Recuperer le nom de la table de jointure xxxx sur l'objet yyyy |
| 269 | 269 | // http://doc.spip.org/@table_jointure |
| 270 | 270 | function table_jointure($x, $y) { |
| 271 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 272 | - $xdesc = $trouver_table(table_objet($x)); |
|
| 273 | - $ydesc = $trouver_table(table_objet($y)); |
|
| 274 | - $ix = @$xdesc['key']["PRIMARY KEY"]; |
|
| 275 | - $iy = @$ydesc['key']["PRIMARY KEY"]; |
|
| 276 | - if ($table = $ydesc['tables_jointures'][$ix]) return $table; |
|
| 277 | - if ($table = $xdesc['tables_jointures'][$iy]) return $table; |
|
| 278 | - return ''; |
|
| 271 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 272 | + $xdesc = $trouver_table(table_objet($x)); |
|
| 273 | + $ydesc = $trouver_table(table_objet($y)); |
|
| 274 | + $ix = @$xdesc['key']["PRIMARY KEY"]; |
|
| 275 | + $iy = @$ydesc['key']["PRIMARY KEY"]; |
|
| 276 | + if ($table = $ydesc['tables_jointures'][$ix]) return $table; |
|
| 277 | + if ($table = $xdesc['tables_jointures'][$iy]) return $table; |
|
| 278 | + return ''; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -288,29 +288,29 @@ discard block |
||
| 288 | 288 | * @return array |
| 289 | 289 | */ |
| 290 | 290 | function query_echappe_textes($query){ |
| 291 | - static $codeEchappements = array("''"=>"\x1@##@\x1", "\'"=>"\x2@##@\x2", "\\\""=>"\x3@##@\x3"); |
|
| 292 | - $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 293 | - if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S",$query,$textes)){ |
|
| 294 | - $textes = reset($textes); // indice 0 du match |
|
| 295 | - switch(count($textes)){ |
|
| 296 | - case 0:$replace=array();break; |
|
| 297 | - case 1:$replace=array('%1$s');break; |
|
| 298 | - case 2:$replace=array('%1$s','%2$s');break; |
|
| 299 | - case 3:$replace=array('%1$s','%2$s','%3$s');break; |
|
| 300 | - case 4:$replace=array('%1$s','%2$s','%3$s','%4$s');break; |
|
| 301 | - case 5:$replace=array('%1$s','%2$s','%3$s','%4$s','%5$s');break; |
|
| 302 | - default: |
|
| 303 | - $replace = range(1,count($textes)); |
|
| 304 | - $replace = '%'.implode('$s,%',$replace).'$s'; |
|
| 305 | - $replace = explode(',',$replace); |
|
| 306 | - break; |
|
| 307 | - } |
|
| 308 | - $query = str_replace($textes,$replace,$query); |
|
| 309 | - } |
|
| 310 | - else |
|
| 311 | - $textes = array(); |
|
| 312 | - |
|
| 313 | - return array($query, $textes); |
|
| 291 | + static $codeEchappements = array("''"=>"\x1@##@\x1", "\'"=>"\x2@##@\x2", "\\\""=>"\x3@##@\x3"); |
|
| 292 | + $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 293 | + if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S",$query,$textes)){ |
|
| 294 | + $textes = reset($textes); // indice 0 du match |
|
| 295 | + switch(count($textes)){ |
|
| 296 | + case 0:$replace=array();break; |
|
| 297 | + case 1:$replace=array('%1$s');break; |
|
| 298 | + case 2:$replace=array('%1$s','%2$s');break; |
|
| 299 | + case 3:$replace=array('%1$s','%2$s','%3$s');break; |
|
| 300 | + case 4:$replace=array('%1$s','%2$s','%3$s','%4$s');break; |
|
| 301 | + case 5:$replace=array('%1$s','%2$s','%3$s','%4$s','%5$s');break; |
|
| 302 | + default: |
|
| 303 | + $replace = range(1,count($textes)); |
|
| 304 | + $replace = '%'.implode('$s,%',$replace).'$s'; |
|
| 305 | + $replace = explode(',',$replace); |
|
| 306 | + break; |
|
| 307 | + } |
|
| 308 | + $query = str_replace($textes,$replace,$query); |
|
| 309 | + } |
|
| 310 | + else |
|
| 311 | + $textes = array(); |
|
| 312 | + |
|
| 313 | + return array($query, $textes); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -322,37 +322,37 @@ discard block |
||
| 322 | 322 | * @return string |
| 323 | 323 | */ |
| 324 | 324 | function query_reinjecte_textes($query, $textes){ |
| 325 | - static $codeEchappements = array("''"=>"\x1@##@\x1", "\'"=>"\x2@##@\x2", "\\\""=>"\x3@##@\x3"); |
|
| 326 | - # debug de la substitution |
|
| 327 | - #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){ |
|
| 328 | - # spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR); |
|
| 329 | - # spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR); |
|
| 330 | - # spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR); |
|
| 331 | - #} |
|
| 332 | - switch (count($textes)){ |
|
| 333 | - case 0:break; |
|
| 334 | - case 1:$query=sprintf($query,$textes[0]);break; |
|
| 335 | - case 2:$query=sprintf($query,$textes[0],$textes[1]);break; |
|
| 336 | - case 3:$query=sprintf($query,$textes[0],$textes[1],$textes[2]);break; |
|
| 337 | - case 4:$query=sprintf($query,$textes[0],$textes[1],$textes[2],$textes[3]);break; |
|
| 338 | - case 5:$query=sprintf($query,$textes[0],$textes[1],$textes[2],$textes[3],$textes[4]);break; |
|
| 339 | - default: |
|
| 340 | - array_unshift($textes,$query); |
|
| 341 | - $query = call_user_func_array('sprintf',$textes); |
|
| 342 | - break; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 346 | - |
|
| 347 | - return $query; |
|
| 325 | + static $codeEchappements = array("''"=>"\x1@##@\x1", "\'"=>"\x2@##@\x2", "\\\""=>"\x3@##@\x3"); |
|
| 326 | + # debug de la substitution |
|
| 327 | + #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){ |
|
| 328 | + # spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR); |
|
| 329 | + # spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR); |
|
| 330 | + # spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR); |
|
| 331 | + #} |
|
| 332 | + switch (count($textes)){ |
|
| 333 | + case 0:break; |
|
| 334 | + case 1:$query=sprintf($query,$textes[0]);break; |
|
| 335 | + case 2:$query=sprintf($query,$textes[0],$textes[1]);break; |
|
| 336 | + case 3:$query=sprintf($query,$textes[0],$textes[1],$textes[2]);break; |
|
| 337 | + case 4:$query=sprintf($query,$textes[0],$textes[1],$textes[2],$textes[3]);break; |
|
| 338 | + case 5:$query=sprintf($query,$textes[0],$textes[1],$textes[2],$textes[3],$textes[4]);break; |
|
| 339 | + default: |
|
| 340 | + array_unshift($textes,$query); |
|
| 341 | + $query = call_user_func_array('sprintf',$textes); |
|
| 342 | + break; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 346 | + |
|
| 347 | + return $query; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | // Pour compatibilite. Ne plus utiliser. |
| 351 | 351 | // http://doc.spip.org/@spip_query |
| 352 | 352 | function spip_query($query, $serveur='') { |
| 353 | - global $spip_sql_version; |
|
| 354 | - $f = spip_connect_sql($spip_sql_version, 'query', $serveur, true); |
|
| 355 | - return function_exists($f) ? $f($query, $serveur) : false; |
|
| 353 | + global $spip_sql_version; |
|
| 354 | + $f = spip_connect_sql($spip_sql_version, 'query', $serveur, true); |
|
| 355 | + return function_exists($f) ? $f($query, $serveur) : false; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | ?> |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | -require_once _ROOT_RESTREINT . 'base/objets.php'; |
|
| 14 | +require_once _ROOT_RESTREINT.'base/objets.php'; |
|
| 15 | 15 | |
| 16 | 16 | // |
| 17 | 17 | // Utilitaires indispensables autour des serveurs SQL |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | // A l'installation, il faut simuler l'existence de ce fichier |
| 26 | 26 | |
| 27 | 27 | // http://doc.spip.org/@spip_connect |
| 28 | -function spip_connect($serveur='', $version='') { |
|
| 28 | +function spip_connect($serveur = '', $version = '') { |
|
| 29 | 29 | global $connexions, $spip_sql_version; |
| 30 | 30 | |
| 31 | 31 | $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
| 42 | 42 | ? '' // nom de serveur mal ecrit |
| 43 | 43 | : ($serveur ? |
| 44 | - ( _DIR_CONNECT. $serveur . '.php') // serveur externe |
|
| 44 | + (_DIR_CONNECT.$serveur.'.php') // serveur externe |
|
| 45 | 45 | : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
| 46 | 46 | : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
| 47 | 47 | : ''))); // installation pas faite |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | // chercher une declaration de serveur dans le path |
| 56 | 56 | // qui pourra un jour servir a declarer des bases sqlite |
| 57 | 57 | // par des plugins. Et sert aussi aux boucles POUR. |
| 58 | - find_in_path("$serveur.php",'connect/',true); |
|
| 58 | + find_in_path("$serveur.php", 'connect/', true); |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | if (!isset($GLOBALS['db_ok'])) { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
| 68 | 68 | spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
| 69 | 69 | // ne plus reessayer si ce n'est pas l'install |
| 70 | - return $connexions[$index]=false; |
|
| 70 | + return $connexions[$index] = false; |
|
| 71 | 71 | } |
| 72 | 72 | $connexions[$index] = $GLOBALS['db_ok']; |
| 73 | 73 | } |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | // chargement de la version du jeu de fonctions |
| 79 | 79 | // si pas dans le fichier par defaut |
| 80 | 80 | $type = $GLOBALS['db_ok']['type']; |
| 81 | - $jeu = 'spip_' . $type .'_functions_' . $version; |
|
| 81 | + $jeu = 'spip_'.$type.'_functions_'.$version; |
|
| 82 | 82 | if (!isset($GLOBALS[$jeu])) { |
| 83 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)){ |
|
| 83 | + if (!find_in_path($type.'_'.$version.'.php', 'req/', true)) { |
|
| 84 | 84 | spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
| 85 | 85 | // ne plus reessayer |
| 86 | 86 | return $connexions[$index][$version] = array(); |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT); |
| 104 | 104 | return false; |
| 105 | 105 | } |
| 106 | - } else { |
|
| 106 | + } else { |
|
| 107 | 107 | // spip_meta n'existe pas toujours dans la base |
| 108 | 108 | // C'est le cas d'un dump sqlite par exemple |
| 109 | 109 | if ($connexions[$index]['spip_connect_version'] |
| 110 | 110 | AND sql_showtable('spip_meta', true, $serveur) |
| 111 | - AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'",'','','','',$serveur)) |
|
| 111 | + AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)) |
|
| 112 | 112 | $charset = $r; |
| 113 | 113 | else $charset = -1; |
| 114 | 114 | } |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | return $connexions[$index]; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | -function spip_sql_erreur($serveur='') |
|
| 123 | +function spip_sql_erreur($serveur = '') |
|
| 124 | 124 | { |
| 125 | 125 | $connexion = spip_connect($serveur); |
| 126 | 126 | $e = sql_errno($serveur); |
| 127 | 127 | $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
| 128 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\n" . $connexion['last']; |
|
| 129 | - $f = $t . $serveur; |
|
| 128 | + $m = "Erreur $e de $t: ".sql_error($serveur)."\n".$connexion['last']; |
|
| 129 | + $f = $t.$serveur; |
|
| 130 | 130 | spip_log($m, $f.'.'._LOG_ERREUR); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | // connue seulement des convertisseurs automatiques |
| 137 | 137 | |
| 138 | 138 | // http://doc.spip.org/@spip_connect_sql |
| 139 | -function spip_connect_sql($version, $ins='', $serveur='', $cont=false) { |
|
| 139 | +function spip_connect_sql($version, $ins = '', $serveur = '', $cont = false) { |
|
| 140 | 140 | $desc = spip_connect($serveur, $version); |
| 141 | 141 | if (function_exists($f = @$desc[$version][$ins])) return $f; |
| 142 | 142 | if ($cont) return $desc; |
@@ -166,28 +166,28 @@ discard block |
||
| 166 | 166 | * @param string $auth |
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | -function spip_connect_db($host, $port, $login, $pass, $db='', $type='mysql', $prefixe='', $auth='') { |
|
| 169 | +function spip_connect_db($host, $port, $login, $pass, $db = '', $type = 'mysql', $prefixe = '', $auth = '') { |
|
| 170 | 170 | global $db_ok; |
| 171 | 171 | |
| 172 | 172 | // temps avant nouvelle tentative de connexion |
| 173 | 173 | // suite a une connection echouee |
| 174 | 174 | if (!defined('_CONNECT_RETRY_DELAY')) |
| 175 | - define('_CONNECT_RETRY_DELAY',30); |
|
| 175 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 176 | 176 | |
| 177 | 177 | $f = ""; |
| 178 | 178 | // un fichier de identifiant par combinaison (type,host,port,db) |
| 179 | 179 | // pour ne pas declarer tout indisponible d'un coup |
| 180 | 180 | // si en cours d'installation ou si db=@test@ on ne pose rien |
| 181 | 181 | // car c'est un test de connexion |
| 182 | - if (!defined('_ECRIRE_INSTALL') AND !$db=="@test@") |
|
| 183 | - $f = _DIR_TMP . $type . '.' . substr(md5($host.$port.$db),0,8) . '.out'; |
|
| 184 | - elseif ($db=='@test@') |
|
| 182 | + if (!defined('_ECRIRE_INSTALL') AND !$db == "@test@") |
|
| 183 | + $f = _DIR_TMP.$type.'.'.substr(md5($host.$port.$db), 0, 8).'.out'; |
|
| 184 | + elseif ($db == '@test@') |
|
| 185 | 185 | $db = ''; |
| 186 | 186 | |
| 187 | 187 | if ($f |
| 188 | 188 | AND @file_exists($f) |
| 189 | 189 | AND (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)) { |
| 190 | - spip_log( "Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 190 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | ? $GLOBALS['table_prefix'] : $db; |
| 197 | 197 | $h = charger_fonction($type, 'req', true); |
| 198 | 198 | if (!$h) { |
| 199 | - spip_log( "les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 199 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 200 | 200 | return; |
| 201 | 201 | } |
| 202 | 202 | if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | // En cas d'indisponibilite du serveur, eviter de le bombarder |
| 214 | 214 | if ($f) { |
| 215 | 215 | @touch($f); |
| 216 | - spip_log( "Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS); |
|
| 216 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS); |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
@@ -233,14 +233,14 @@ discard block |
||
| 233 | 233 | // http://doc.spip.org/@spip_connect_main |
| 234 | 234 | function spip_connect_main($connexion) |
| 235 | 235 | { |
| 236 | - if ($GLOBALS['spip_connect_version']< 0.1 AND _DIR_RESTREINT){ |
|
| 236 | + if ($GLOBALS['spip_connect_version'] < 0.1 AND _DIR_RESTREINT) { |
|
| 237 | 237 | include_spip('inc/headers'); |
| 238 | 238 | redirige_url_ecrire('upgrade', 'reinstall=oui'); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | if (!($f = $connexion['select'])) return false; |
| 242 | 242 | // en cas d'erreur select retourne la requette (is_string=true donc) |
| 243 | - if (!$r = $f('valeur','spip_meta', "nom='charset_sql_connexion'") |
|
| 243 | + if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 244 | 244 | OR is_string($r)) |
| 245 | 245 | return false; |
| 246 | 246 | if (!($f = $connexion['fetch'])) return false; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // compatibilite |
| 252 | -function spip_connect_ldap($serveur='') { |
|
| 252 | +function spip_connect_ldap($serveur = '') { |
|
| 253 | 253 | include_spip('auth/ldap'); |
| 254 | 254 | return auth_ldap_connect($serveur); |
| 255 | 255 | } |
@@ -258,9 +258,8 @@ discard block |
||
| 258 | 258 | // pour un array(1,'a',"a'") renvoie la chaine "'1','a','a\''" |
| 259 | 259 | // Usage sql un peu deprecie, a remplacer par sql_quote() |
| 260 | 260 | // http://doc.spip.org/@_q |
| 261 | -function _q ($a) { |
|
| 262 | - return (is_numeric($a)) ? strval($a) : |
|
| 263 | - (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 261 | +function _q($a) { |
|
| 262 | + return (is_numeric($a)) ? strval($a) : (!is_array($a) ? ("'".addslashes($a)."'") |
|
| 264 | 263 | : join(",", array_map('_q', $a))); |
| 265 | 264 | } |
| 266 | 265 | |
@@ -287,25 +286,25 @@ discard block |
||
| 287 | 286 | * @param string $query |
| 288 | 287 | * @return array |
| 289 | 288 | */ |
| 290 | -function query_echappe_textes($query){ |
|
| 289 | +function query_echappe_textes($query) { |
|
| 291 | 290 | static $codeEchappements = array("''"=>"\x1@##@\x1", "\'"=>"\x2@##@\x2", "\\\""=>"\x3@##@\x3"); |
| 292 | 291 | $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
| 293 | - if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S",$query,$textes)){ |
|
| 292 | + if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) { |
|
| 294 | 293 | $textes = reset($textes); // indice 0 du match |
| 295 | - switch(count($textes)){ |
|
| 296 | - case 0:$replace=array();break; |
|
| 297 | - case 1:$replace=array('%1$s');break; |
|
| 298 | - case 2:$replace=array('%1$s','%2$s');break; |
|
| 299 | - case 3:$replace=array('%1$s','%2$s','%3$s');break; |
|
| 300 | - case 4:$replace=array('%1$s','%2$s','%3$s','%4$s');break; |
|
| 301 | - case 5:$replace=array('%1$s','%2$s','%3$s','%4$s','%5$s');break; |
|
| 294 | + switch (count($textes)) { |
|
| 295 | + case 0:$replace = array(); break; |
|
| 296 | + case 1:$replace = array('%1$s'); break; |
|
| 297 | + case 2:$replace = array('%1$s', '%2$s'); break; |
|
| 298 | + case 3:$replace = array('%1$s', '%2$s', '%3$s'); break; |
|
| 299 | + case 4:$replace = array('%1$s', '%2$s', '%3$s', '%4$s'); break; |
|
| 300 | + case 5:$replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s'); break; |
|
| 302 | 301 | default: |
| 303 | - $replace = range(1,count($textes)); |
|
| 304 | - $replace = '%'.implode('$s,%',$replace).'$s'; |
|
| 305 | - $replace = explode(',',$replace); |
|
| 302 | + $replace = range(1, count($textes)); |
|
| 303 | + $replace = '%'.implode('$s,%', $replace).'$s'; |
|
| 304 | + $replace = explode(',', $replace); |
|
| 306 | 305 | break; |
| 307 | 306 | } |
| 308 | - $query = str_replace($textes,$replace,$query); |
|
| 307 | + $query = str_replace($textes, $replace, $query); |
|
| 309 | 308 | } |
| 310 | 309 | else |
| 311 | 310 | $textes = array(); |
@@ -321,7 +320,7 @@ discard block |
||
| 321 | 320 | * @param array $textes |
| 322 | 321 | * @return string |
| 323 | 322 | */ |
| 324 | -function query_reinjecte_textes($query, $textes){ |
|
| 323 | +function query_reinjecte_textes($query, $textes) { |
|
| 325 | 324 | static $codeEchappements = array("''"=>"\x1@##@\x1", "\'"=>"\x2@##@\x2", "\\\""=>"\x3@##@\x3"); |
| 326 | 325 | # debug de la substitution |
| 327 | 326 | #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){ |
@@ -329,16 +328,16 @@ discard block |
||
| 329 | 328 | # spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR); |
| 330 | 329 | # spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR); |
| 331 | 330 | #} |
| 332 | - switch (count($textes)){ |
|
| 331 | + switch (count($textes)) { |
|
| 333 | 332 | case 0:break; |
| 334 | - case 1:$query=sprintf($query,$textes[0]);break; |
|
| 335 | - case 2:$query=sprintf($query,$textes[0],$textes[1]);break; |
|
| 336 | - case 3:$query=sprintf($query,$textes[0],$textes[1],$textes[2]);break; |
|
| 337 | - case 4:$query=sprintf($query,$textes[0],$textes[1],$textes[2],$textes[3]);break; |
|
| 338 | - case 5:$query=sprintf($query,$textes[0],$textes[1],$textes[2],$textes[3],$textes[4]);break; |
|
| 333 | + case 1:$query = sprintf($query, $textes[0]); break; |
|
| 334 | + case 2:$query = sprintf($query, $textes[0], $textes[1]); break; |
|
| 335 | + case 3:$query = sprintf($query, $textes[0], $textes[1], $textes[2]); break; |
|
| 336 | + case 4:$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]); break; |
|
| 337 | + case 5:$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]); break; |
|
| 339 | 338 | default: |
| 340 | - array_unshift($textes,$query); |
|
| 341 | - $query = call_user_func_array('sprintf',$textes); |
|
| 339 | + array_unshift($textes, $query); |
|
| 340 | + $query = call_user_func_array('sprintf', $textes); |
|
| 342 | 341 | break; |
| 343 | 342 | } |
| 344 | 343 | |
@@ -349,7 +348,7 @@ discard block |
||
| 349 | 348 | |
| 350 | 349 | // Pour compatibilite. Ne plus utiliser. |
| 351 | 350 | // http://doc.spip.org/@spip_query |
| 352 | -function spip_query($query, $serveur='') { |
|
| 351 | +function spip_query($query, $serveur = '') { |
|
| 353 | 352 | global $spip_sql_version; |
| 354 | 353 | $f = spip_connect_sql($spip_sql_version, 'query', $serveur, true); |
| 355 | 354 | return function_exists($f) ? $f($query, $serveur) : false; |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | require_once _ROOT_RESTREINT . 'base/objets.php'; |
| 15 | 17 | |
| 16 | 18 | // |
@@ -30,8 +32,12 @@ discard block |
||
| 30 | 32 | |
| 31 | 33 | $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
| 32 | 34 | $index = $serveur ? $serveur : 0; |
| 33 | - if (!$version) $version = $spip_sql_version; |
|
| 34 | - if (isset($connexions[$index][$version])) return $connexions[$index]; |
|
| 35 | + if (!$version) { |
|
| 36 | + $version = $spip_sql_version; |
|
| 37 | + } |
|
| 38 | + if (isset($connexions[$index][$version])) { |
|
| 39 | + return $connexions[$index]; |
|
| 40 | + } |
|
| 35 | 41 | |
| 36 | 42 | include_spip('base/abstract_sql'); |
| 37 | 43 | $install = (_request('exec') == 'install'); |
@@ -60,11 +66,14 @@ discard block |
||
| 60 | 66 | } |
| 61 | 67 | if (!isset($GLOBALS['db_ok'])) { |
| 62 | 68 | // fera mieux la prochaine fois |
| 63 | - if ($install) return false; |
|
| 64 | - if ($f AND is_readable($f)) |
|
| 65 | - spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 66 | - else |
|
| 67 | - spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 69 | + if ($install) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + if ($f AND is_readable($f)) { |
|
| 73 | + spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 74 | + } else { |
|
| 75 | + spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 76 | + } |
|
| 68 | 77 | spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
| 69 | 78 | // ne plus reessayer si ce n'est pas l'install |
| 70 | 79 | return $connexions[$index]=false; |
@@ -72,7 +81,9 @@ discard block |
||
| 72 | 81 | $connexions[$index] = $GLOBALS['db_ok']; |
| 73 | 82 | } |
| 74 | 83 | // si la connexion a deja ete tentee mais a echoue, le dire! |
| 75 | - if (!$connexions[$index]) return false; |
|
| 84 | + if (!$connexions[$index]) { |
|
| 85 | + return false; |
|
| 86 | + } |
|
| 76 | 87 | |
| 77 | 88 | // la connexion a reussi ou etait deja faite. |
| 78 | 89 | // chargement de la version du jeu de fonctions |
@@ -87,7 +98,9 @@ discard block |
||
| 87 | 98 | } |
| 88 | 99 | } |
| 89 | 100 | $connexions[$index][$version] = $GLOBALS[$jeu]; |
| 90 | - if ($old) return $connexions[$index]; |
|
| 101 | + if ($old) { |
|
| 102 | + return $connexions[$index]; |
|
| 103 | + } |
|
| 91 | 104 | |
| 92 | 105 | $connexions[$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0; |
| 93 | 106 | |
@@ -108,14 +121,17 @@ discard block |
||
| 108 | 121 | // C'est le cas d'un dump sqlite par exemple |
| 109 | 122 | if ($connexions[$index]['spip_connect_version'] |
| 110 | 123 | AND sql_showtable('spip_meta', true, $serveur) |
| 111 | - AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'",'','','','',$serveur)) |
|
| 112 | - $charset = $r; |
|
| 113 | - else $charset = -1; |
|
| 124 | + AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'",'','','','',$serveur)) { |
|
| 125 | + $charset = $r; |
|
| 126 | + } else { |
|
| 127 | + $charset = -1; |
|
| 128 | + } |
|
| 114 | 129 | } |
| 115 | 130 | if ($charset != -1) { |
| 116 | 131 | $f = $GLOBALS[$jeu]['set_charset']; |
| 117 | - if (function_exists($f)) |
|
| 118 | - $f($charset, $serveur); |
|
| 132 | + if (function_exists($f)) { |
|
| 133 | + $f($charset, $serveur); |
|
| 134 | + } |
|
| 119 | 135 | } |
| 120 | 136 | return $connexions[$index]; |
| 121 | 137 | } |
@@ -138,10 +154,15 @@ discard block |
||
| 138 | 154 | // http://doc.spip.org/@spip_connect_sql |
| 139 | 155 | function spip_connect_sql($version, $ins='', $serveur='', $cont=false) { |
| 140 | 156 | $desc = spip_connect($serveur, $version); |
| 141 | - if (function_exists($f = @$desc[$version][$ins])) return $f; |
|
| 142 | - if ($cont) return $desc; |
|
| 143 | - if ($ins) |
|
| 144 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 157 | + if (function_exists($f = @$desc[$version][$ins])) { |
|
| 158 | + return $f; |
|
| 159 | + } |
|
| 160 | + if ($cont) { |
|
| 161 | + return $desc; |
|
| 162 | + } |
|
| 163 | + if ($ins) { |
|
| 164 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 165 | + } |
|
| 145 | 166 | include_spip('inc/minipres'); |
| 146 | 167 | echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
| 147 | 168 | exit; |
@@ -171,18 +192,20 @@ discard block |
||
| 171 | 192 | |
| 172 | 193 | // temps avant nouvelle tentative de connexion |
| 173 | 194 | // suite a une connection echouee |
| 174 | - if (!defined('_CONNECT_RETRY_DELAY')) |
|
| 175 | - define('_CONNECT_RETRY_DELAY',30); |
|
| 195 | + if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 196 | + define('_CONNECT_RETRY_DELAY',30); |
|
| 197 | + } |
|
| 176 | 198 | |
| 177 | 199 | $f = ""; |
| 178 | 200 | // un fichier de identifiant par combinaison (type,host,port,db) |
| 179 | 201 | // pour ne pas declarer tout indisponible d'un coup |
| 180 | 202 | // si en cours d'installation ou si db=@test@ on ne pose rien |
| 181 | 203 | // car c'est un test de connexion |
| 182 | - if (!defined('_ECRIRE_INSTALL') AND !$db=="@test@") |
|
| 183 | - $f = _DIR_TMP . $type . '.' . substr(md5($host.$port.$db),0,8) . '.out'; |
|
| 184 | - elseif ($db=='@test@') |
|
| 185 | - $db = ''; |
|
| 204 | + if (!defined('_ECRIRE_INSTALL') AND !$db=="@test@") { |
|
| 205 | + $f = _DIR_TMP . $type . '.' . substr(md5($host.$port.$db),0,8) . '.out'; |
|
| 206 | + } elseif ($db=='@test@') { |
|
| 207 | + $db = ''; |
|
| 208 | + } |
|
| 186 | 209 | |
| 187 | 210 | if ($f |
| 188 | 211 | AND @file_exists($f) |
@@ -191,9 +214,10 @@ discard block |
||
| 191 | 214 | return; |
| 192 | 215 | } |
| 193 | 216 | |
| 194 | - if (!$prefixe) |
|
| 195 | - $prefixe = isset($GLOBALS['table_prefix']) |
|
| 217 | + if (!$prefixe) { |
|
| 218 | + $prefixe = isset($GLOBALS['table_prefix']) |
|
| 196 | 219 | ? $GLOBALS['table_prefix'] : $db; |
| 220 | + } |
|
| 197 | 221 | $h = charger_fonction($type, 'req', true); |
| 198 | 222 | if (!$h) { |
| 199 | 223 | spip_log( "les requetes $type ne sont pas fournies", _LOG_HS); |
@@ -238,12 +262,17 @@ discard block |
||
| 238 | 262 | redirige_url_ecrire('upgrade', 'reinstall=oui'); |
| 239 | 263 | } |
| 240 | 264 | |
| 241 | - if (!($f = $connexion['select'])) return false; |
|
| 265 | + if (!($f = $connexion['select'])) { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 242 | 268 | // en cas d'erreur select retourne la requette (is_string=true donc) |
| 243 | 269 | if (!$r = $f('valeur','spip_meta', "nom='charset_sql_connexion'") |
| 244 | - OR is_string($r)) |
|
| 245 | - return false; |
|
| 246 | - if (!($f = $connexion['fetch'])) return false; |
|
| 270 | + OR is_string($r)) { |
|
| 271 | + return false; |
|
| 272 | + } |
|
| 273 | + if (!($f = $connexion['fetch'])) { |
|
| 274 | + return false; |
|
| 275 | + } |
|
| 247 | 276 | $r = $f($r); |
| 248 | 277 | return ($r['valeur'] ? $r['valeur'] : -1); |
| 249 | 278 | } |
@@ -273,8 +302,12 @@ discard block |
||
| 273 | 302 | $ydesc = $trouver_table(table_objet($y)); |
| 274 | 303 | $ix = @$xdesc['key']["PRIMARY KEY"]; |
| 275 | 304 | $iy = @$ydesc['key']["PRIMARY KEY"]; |
| 276 | - if ($table = $ydesc['tables_jointures'][$ix]) return $table; |
|
| 277 | - if ($table = $xdesc['tables_jointures'][$iy]) return $table; |
|
| 305 | + if ($table = $ydesc['tables_jointures'][$ix]) { |
|
| 306 | + return $table; |
|
| 307 | + } |
|
| 308 | + if ($table = $xdesc['tables_jointures'][$iy]) { |
|
| 309 | + return $table; |
|
| 310 | + } |
|
| 278 | 311 | return ''; |
| 279 | 312 | } |
| 280 | 313 | |
@@ -306,9 +339,9 @@ discard block |
||
| 306 | 339 | break; |
| 307 | 340 | } |
| 308 | 341 | $query = str_replace($textes,$replace,$query); |
| 342 | + } else { |
|
| 343 | + $textes = array(); |
|
| 309 | 344 | } |
| 310 | - else |
|
| 311 | - $textes = array(); |
|
| 312 | 345 | |
| 313 | 346 | return array($query, $textes); |
| 314 | 347 | } |
@@ -28,6 +28,11 @@ |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // http://doc.spip.org/@exec_rechercher_args |
| 31 | +/** |
|
| 32 | + * @param integer $id |
|
| 33 | + * @param integer $exclus |
|
| 34 | + * @param string $rac |
|
| 35 | + */ |
|
| 31 | 36 | function exec_rechercher_args($id, $type, $exclus, $rac, $do){ |
| 32 | 37 | if (!$do) $do = 'aff'; |
| 33 | 38 | |
@@ -16,81 +16,81 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | // http://doc.spip.org/@exec_rechercher_dist |
| 18 | 18 | function exec_rechercher_dist(){ |
| 19 | - $id = intval(_request('id')); |
|
| 20 | - $exclus = intval(_request('exclus')); |
|
| 21 | - $rac = spip_htmlentities(_request('rac')); |
|
| 22 | - $type = _request('type'); |
|
| 23 | - $do = _request('do'); |
|
| 24 | - if (preg_match('/^\w*$/', $do)) |
|
| 25 | - $r = exec_rechercher_args($id, $type, $exclus, $rac, $do); |
|
| 26 | - else $r = ''; |
|
| 27 | - ajax_retour($r); |
|
| 19 | + $id = intval(_request('id')); |
|
| 20 | + $exclus = intval(_request('exclus')); |
|
| 21 | + $rac = spip_htmlentities(_request('rac')); |
|
| 22 | + $type = _request('type'); |
|
| 23 | + $do = _request('do'); |
|
| 24 | + if (preg_match('/^\w*$/', $do)) |
|
| 25 | + $r = exec_rechercher_args($id, $type, $exclus, $rac, $do); |
|
| 26 | + else $r = ''; |
|
| 27 | + ajax_retour($r); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // http://doc.spip.org/@exec_rechercher_args |
| 31 | 31 | function exec_rechercher_args($id, $type, $exclus, $rac, $do){ |
| 32 | - if (!$do) $do = 'aff'; |
|
| 33 | - |
|
| 34 | - $where = preg_split(",\s+,", $type); |
|
| 35 | - if ($where){ |
|
| 36 | - foreach ($where as $k => $v){ |
|
| 37 | - $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v,'','string')), 1, -1) . "%'"; |
|
| 38 | - } |
|
| 39 | - $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
|
| 40 | - $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
|
| 41 | - $where_id = ("(id_rubrique = " . intval($type) . ")"); |
|
| 42 | - } else { |
|
| 43 | - $where_titre = " 1=2"; |
|
| 44 | - $where_desc = " 1=2"; |
|
| 45 | - $where_id = " 1=2"; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - if ($exclus){ |
|
| 49 | - include_spip('inc/rubriques'); |
|
| 50 | - $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 51 | - } else $where_exclus = ''; |
|
| 52 | - |
|
| 53 | - $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus"); |
|
| 54 | - |
|
| 55 | - $points = $rub = array(); |
|
| 56 | - |
|
| 57 | - while ($row = sql_fetch($res)){ |
|
| 58 | - $id_rubrique = $row["id_rubrique"]; |
|
| 59 | - $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 60 | - $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 61 | - $points[$id_rubrique] = $points[$id_rubrique]+3; |
|
| 62 | - } |
|
| 63 | - $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_titre$where_exclus"); |
|
| 64 | - |
|
| 65 | - while ($row = sql_fetch($res)){ |
|
| 66 | - $id_rubrique = $row["id_rubrique"]; |
|
| 67 | - $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 68 | - $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 69 | - if (isset($points[$id_rubrique])) |
|
| 70 | - $points[$id_rubrique] += 2; |
|
| 71 | - else $points[$id_rubrique] = 0; |
|
| 72 | - } |
|
| 73 | - $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_desc$where_exclus"); |
|
| 74 | - |
|
| 75 | - while ($row = sql_fetch($res)){ |
|
| 76 | - $id_rubrique = $row["id_rubrique"]; |
|
| 77 | - $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 78 | - $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 79 | - if (isset($points[$id_rubrique])) |
|
| 80 | - $points[$id_rubrique] += 1; |
|
| 81 | - else $points[$id_rubrique] = 0; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - if ($points){ |
|
| 85 | - arsort($points); |
|
| 86 | - $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
|
| 87 | - foreach ($rub as $k => $v){ |
|
| 88 | - $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
|
| 89 | - . " class='petite-rubrique'"; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return (proposer_item($points, $rub, $rac, $type, $do)); |
|
| 32 | + if (!$do) $do = 'aff'; |
|
| 33 | + |
|
| 34 | + $where = preg_split(",\s+,", $type); |
|
| 35 | + if ($where){ |
|
| 36 | + foreach ($where as $k => $v){ |
|
| 37 | + $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v,'','string')), 1, -1) . "%'"; |
|
| 38 | + } |
|
| 39 | + $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
|
| 40 | + $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
|
| 41 | + $where_id = ("(id_rubrique = " . intval($type) . ")"); |
|
| 42 | + } else { |
|
| 43 | + $where_titre = " 1=2"; |
|
| 44 | + $where_desc = " 1=2"; |
|
| 45 | + $where_id = " 1=2"; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + if ($exclus){ |
|
| 49 | + include_spip('inc/rubriques'); |
|
| 50 | + $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 51 | + } else $where_exclus = ''; |
|
| 52 | + |
|
| 53 | + $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus"); |
|
| 54 | + |
|
| 55 | + $points = $rub = array(); |
|
| 56 | + |
|
| 57 | + while ($row = sql_fetch($res)){ |
|
| 58 | + $id_rubrique = $row["id_rubrique"]; |
|
| 59 | + $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 60 | + $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 61 | + $points[$id_rubrique] = $points[$id_rubrique]+3; |
|
| 62 | + } |
|
| 63 | + $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_titre$where_exclus"); |
|
| 64 | + |
|
| 65 | + while ($row = sql_fetch($res)){ |
|
| 66 | + $id_rubrique = $row["id_rubrique"]; |
|
| 67 | + $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 68 | + $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 69 | + if (isset($points[$id_rubrique])) |
|
| 70 | + $points[$id_rubrique] += 2; |
|
| 71 | + else $points[$id_rubrique] = 0; |
|
| 72 | + } |
|
| 73 | + $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_desc$where_exclus"); |
|
| 74 | + |
|
| 75 | + while ($row = sql_fetch($res)){ |
|
| 76 | + $id_rubrique = $row["id_rubrique"]; |
|
| 77 | + $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 78 | + $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 79 | + if (isset($points[$id_rubrique])) |
|
| 80 | + $points[$id_rubrique] += 1; |
|
| 81 | + else $points[$id_rubrique] = 0; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + if ($points){ |
|
| 85 | + arsort($points); |
|
| 86 | + $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
|
| 87 | + foreach ($rub as $k => $v){ |
|
| 88 | + $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
|
| 89 | + . " class='petite-rubrique'"; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return (proposer_item($points, $rub, $rac, $type, $do)); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Resultat de la recherche interactive demandee par la fonction JS |
@@ -101,34 +101,34 @@ discard block |
||
| 101 | 101 | // http://doc.spip.org/@proposer_item |
| 102 | 102 | function proposer_item($ids, $titles, $rac, $type, $do){ |
| 103 | 103 | |
| 104 | - if (!$ids) |
|
| 105 | - return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
|
| 106 | - . spip_htmlentities($type) |
|
| 107 | - . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
|
| 104 | + if (!$ids) |
|
| 105 | + return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
|
| 106 | + . spip_htmlentities($type) |
|
| 107 | + . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
|
| 108 | 108 | |
| 109 | - $ret = ''; |
|
| 110 | - $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |
|
| 109 | + $ret = ''; |
|
| 110 | + $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |
|
| 111 | 111 | |
| 112 | - $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)"; |
|
| 112 | + $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)"; |
|
| 113 | 113 | |
| 114 | - $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');"; |
|
| 114 | + $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');"; |
|
| 115 | 115 | |
| 116 | - foreach ($ids as $id => $bof){ |
|
| 116 | + foreach ($ids as $id => $bof){ |
|
| 117 | 117 | |
| 118 | - $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r", " "); |
|
| 118 | + $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r", " "); |
|
| 119 | 119 | |
| 120 | - $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); " |
|
| 121 | - . $onClick |
|
| 122 | - . "\"\nondblclick=\"" |
|
| 123 | - . $ondbClick |
|
| 124 | - . $onClick |
|
| 125 | - . " \"><div" |
|
| 126 | - . $titles[$id]["atts"] |
|
| 127 | - . " title='$id'> " |
|
| 128 | - . $titre |
|
| 129 | - . "</div></div>"; |
|
| 130 | - } |
|
| 131 | - return $ret; |
|
| 120 | + $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); " |
|
| 121 | + . $onClick |
|
| 122 | + . "\"\nondblclick=\"" |
|
| 123 | + . $ondbClick |
|
| 124 | + . $onClick |
|
| 125 | + . " \"><div" |
|
| 126 | + . $titles[$id]["atts"] |
|
| 127 | + . " title='$id'> " |
|
| 128 | + . $titre |
|
| 129 | + . "</div></div>"; |
|
| 130 | + } |
|
| 131 | + return $ret; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | ?> |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | include_spip('inc/texte'); |
| 16 | 16 | |
| 17 | 17 | // http://doc.spip.org/@exec_rechercher_dist |
| 18 | -function exec_rechercher_dist(){ |
|
| 18 | +function exec_rechercher_dist() { |
|
| 19 | 19 | $id = intval(_request('id')); |
| 20 | 20 | $exclus = intval(_request('exclus')); |
| 21 | 21 | $rac = spip_htmlentities(_request('rac')); |
@@ -28,41 +28,41 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // http://doc.spip.org/@exec_rechercher_args |
| 31 | -function exec_rechercher_args($id, $type, $exclus, $rac, $do){ |
|
| 31 | +function exec_rechercher_args($id, $type, $exclus, $rac, $do) { |
|
| 32 | 32 | if (!$do) $do = 'aff'; |
| 33 | 33 | |
| 34 | 34 | $where = preg_split(",\s+,", $type); |
| 35 | - if ($where){ |
|
| 36 | - foreach ($where as $k => $v){ |
|
| 37 | - $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v,'','string')), 1, -1) . "%'"; |
|
| 35 | + if ($where) { |
|
| 36 | + foreach ($where as $k => $v) { |
|
| 37 | + $where[$k] = "'%".substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1)."%'"; |
|
| 38 | 38 | } |
| 39 | - $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
|
| 40 | - $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
|
| 41 | - $where_id = ("(id_rubrique = " . intval($type) . ")"); |
|
| 39 | + $where_titre = ("(titre LIKE ".join(" AND titre LIKE ", $where).")"); |
|
| 40 | + $where_desc = ("(descriptif LIKE ".join(" AND descriptif LIKE ", $where).")"); |
|
| 41 | + $where_id = ("(id_rubrique = ".intval($type).")"); |
|
| 42 | 42 | } else { |
| 43 | 43 | $where_titre = " 1=2"; |
| 44 | 44 | $where_desc = " 1=2"; |
| 45 | 45 | $where_id = " 1=2"; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if ($exclus){ |
|
| 48 | + if ($exclus) { |
|
| 49 | 49 | include_spip('inc/rubriques'); |
| 50 | - $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 50 | + $where_exclus = " AND ".sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 51 | 51 | } else $where_exclus = ''; |
| 52 | 52 | |
| 53 | 53 | $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus"); |
| 54 | 54 | |
| 55 | 55 | $points = $rub = array(); |
| 56 | 56 | |
| 57 | - while ($row = sql_fetch($res)){ |
|
| 57 | + while ($row = sql_fetch($res)) { |
|
| 58 | 58 | $id_rubrique = $row["id_rubrique"]; |
| 59 | 59 | $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
| 60 | 60 | $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
| 61 | - $points[$id_rubrique] = $points[$id_rubrique]+3; |
|
| 61 | + $points[$id_rubrique] = $points[$id_rubrique] + 3; |
|
| 62 | 62 | } |
| 63 | 63 | $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_titre$where_exclus"); |
| 64 | 64 | |
| 65 | - while ($row = sql_fetch($res)){ |
|
| 65 | + while ($row = sql_fetch($res)) { |
|
| 66 | 66 | $id_rubrique = $row["id_rubrique"]; |
| 67 | 67 | $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
| 68 | 68 | $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_desc$where_exclus"); |
| 74 | 74 | |
| 75 | - while ($row = sql_fetch($res)){ |
|
| 75 | + while ($row = sql_fetch($res)) { |
|
| 76 | 76 | $id_rubrique = $row["id_rubrique"]; |
| 77 | 77 | $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
| 78 | 78 | $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | else $points[$id_rubrique] = 0; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ($points){ |
|
| 84 | + if ($points) { |
|
| 85 | 85 | arsort($points); |
| 86 | - $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
|
| 87 | - foreach ($rub as $k => $v){ |
|
| 86 | + $style = " style='background-image: url(".chemin_image('secteur-12.png').")'"; |
|
| 87 | + foreach ($rub as $k => $v) { |
|
| 88 | 88 | $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
| 89 | 89 | . " class='petite-rubrique'"; |
| 90 | 90 | } |
@@ -99,21 +99,21 @@ discard block |
||
| 99 | 99 | // ==> attention a composer le message d'erreur avec au moins 2 balises |
| 100 | 100 | |
| 101 | 101 | // http://doc.spip.org/@proposer_item |
| 102 | -function proposer_item($ids, $titles, $rac, $type, $do){ |
|
| 102 | +function proposer_item($ids, $titles, $rac, $type, $do) { |
|
| 103 | 103 | |
| 104 | 104 | if (!$ids) |
| 105 | 105 | return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
| 106 | 106 | . spip_htmlentities($type) |
| 107 | - . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
|
| 107 | + . "</b> : "._T('avis_aucun_resultat')."</div>"; |
|
| 108 | 108 | |
| 109 | 109 | $ret = ''; |
| 110 | 110 | $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |
| 111 | 111 | |
| 112 | - $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)"; |
|
| 112 | + $onClick = "aff_selection(this.firstChild.title,'$rac"."_selection','$info', event)"; |
|
| 113 | 113 | |
| 114 | 114 | $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');"; |
| 115 | 115 | |
| 116 | - foreach ($ids as $id => $bof){ |
|
| 116 | + foreach ($ids as $id => $bof) { |
|
| 117 | 117 | |
| 118 | 118 | $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r", " "); |
| 119 | 119 | |
@@ -9,7 +9,9 @@ discard block |
||
| 9 | 9 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 12 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 13 | + return; |
|
| 14 | +} |
|
| 13 | 15 | |
| 14 | 16 | include_spip('inc/actions'); |
| 15 | 17 | include_spip('inc/texte'); |
@@ -21,15 +23,19 @@ discard block |
||
| 21 | 23 | $rac = spip_htmlentities(_request('rac')); |
| 22 | 24 | $type = _request('type'); |
| 23 | 25 | $do = _request('do'); |
| 24 | - if (preg_match('/^\w*$/', $do)) |
|
| 25 | - $r = exec_rechercher_args($id, $type, $exclus, $rac, $do); |
|
| 26 | - else $r = ''; |
|
| 26 | + if (preg_match('/^\w*$/', $do)) { |
|
| 27 | + $r = exec_rechercher_args($id, $type, $exclus, $rac, $do); |
|
| 28 | + } else { |
|
| 29 | + $r = ''; |
|
| 30 | + } |
|
| 27 | 31 | ajax_retour($r); |
| 28 | 32 | } |
| 29 | 33 | |
| 30 | 34 | // http://doc.spip.org/@exec_rechercher_args |
| 31 | 35 | function exec_rechercher_args($id, $type, $exclus, $rac, $do){ |
| 32 | - if (!$do) $do = 'aff'; |
|
| 36 | + if (!$do) { |
|
| 37 | + $do = 'aff'; |
|
| 38 | + } |
|
| 33 | 39 | |
| 34 | 40 | $where = preg_split(",\s+,", $type); |
| 35 | 41 | if ($where){ |
@@ -48,7 +54,9 @@ discard block |
||
| 48 | 54 | if ($exclus){ |
| 49 | 55 | include_spip('inc/rubriques'); |
| 50 | 56 | $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
| 51 | - } else $where_exclus = ''; |
|
| 57 | + } else { |
|
| 58 | + $where_exclus = ''; |
|
| 59 | + } |
|
| 52 | 60 | |
| 53 | 61 | $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus"); |
| 54 | 62 | |
@@ -66,9 +74,11 @@ discard block |
||
| 66 | 74 | $id_rubrique = $row["id_rubrique"]; |
| 67 | 75 | $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
| 68 | 76 | $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
| 69 | - if (isset($points[$id_rubrique])) |
|
| 70 | - $points[$id_rubrique] += 2; |
|
| 71 | - else $points[$id_rubrique] = 0; |
|
| 77 | + if (isset($points[$id_rubrique])) { |
|
| 78 | + $points[$id_rubrique] += 2; |
|
| 79 | + } else { |
|
| 80 | + $points[$id_rubrique] = 0; |
|
| 81 | + } |
|
| 72 | 82 | } |
| 73 | 83 | $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_desc$where_exclus"); |
| 74 | 84 | |
@@ -76,9 +86,11 @@ discard block |
||
| 76 | 86 | $id_rubrique = $row["id_rubrique"]; |
| 77 | 87 | $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
| 78 | 88 | $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
| 79 | - if (isset($points[$id_rubrique])) |
|
| 80 | - $points[$id_rubrique] += 1; |
|
| 81 | - else $points[$id_rubrique] = 0; |
|
| 89 | + if (isset($points[$id_rubrique])) { |
|
| 90 | + $points[$id_rubrique] += 1; |
|
| 91 | + } else { |
|
| 92 | + $points[$id_rubrique] = 0; |
|
| 93 | + } |
|
| 82 | 94 | } |
| 83 | 95 | |
| 84 | 96 | if ($points){ |
@@ -101,10 +113,11 @@ discard block |
||
| 101 | 113 | // http://doc.spip.org/@proposer_item |
| 102 | 114 | function proposer_item($ids, $titles, $rac, $type, $do){ |
| 103 | 115 | |
| 104 | - if (!$ids) |
|
| 105 | - return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
|
| 116 | + if (!$ids) { |
|
| 117 | + return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
|
| 106 | 118 | . spip_htmlentities($type) |
| 107 | 119 | . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
| 120 | + } |
|
| 108 | 121 | |
| 109 | 122 | $ret = ''; |
| 110 | 123 | $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |