@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/headers'); |
@@ -19,55 +19,55 @@ discard block |
||
| 19 | 19 | // https://code.spip.net/@install_etape_4_dist |
| 20 | 20 | function install_etape_4_dist() { |
| 21 | 21 | |
| 22 | - // creer le repertoire cache, qui sert partout ! |
|
| 23 | - if (!@file_exists(_DIR_CACHE)) { |
|
| 24 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 25 | - $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 26 | - } |
|
| 22 | + // creer le repertoire cache, qui sert partout ! |
|
| 23 | + if (!@file_exists(_DIR_CACHE)) { |
|
| 24 | + $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 25 | + $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 30 | - echo info_progression_etape(4, 'etape_', 'install/'); |
|
| 29 | + echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 30 | + echo info_progression_etape(4, 'etape_', 'install/'); |
|
| 31 | 31 | |
| 32 | - echo "<div class='success'><b>" |
|
| 33 | - . _T('info_derniere_etape') |
|
| 34 | - . '</b><p>' |
|
| 35 | - . _T('info_utilisation_spip') |
|
| 36 | - . '</p></div>'; |
|
| 32 | + echo "<div class='success'><b>" |
|
| 33 | + . _T('info_derniere_etape') |
|
| 34 | + . '</b><p>' |
|
| 35 | + . _T('info_utilisation_spip') |
|
| 36 | + . '</p></div>'; |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - echo '<p>' |
|
| 40 | - . _T( |
|
| 41 | - 'plugin_info_plugins_dist_1', |
|
| 42 | - array('plugins_dist' => '<tt>' . joli_repertoire(_DIR_PLUGINS_DIST) . '</tt>') |
|
| 43 | - ) |
|
| 44 | - . '</p>'; |
|
| 39 | + echo '<p>' |
|
| 40 | + . _T( |
|
| 41 | + 'plugin_info_plugins_dist_1', |
|
| 42 | + array('plugins_dist' => '<tt>' . joli_repertoire(_DIR_PLUGINS_DIST) . '</tt>') |
|
| 43 | + ) |
|
| 44 | + . '</p>'; |
|
| 45 | 45 | |
| 46 | - // installer les extensions |
|
| 47 | - include_spip('inc/plugin'); |
|
| 48 | - $afficher = charger_fonction('afficher_liste', 'plugins'); |
|
| 49 | - echo $afficher(self(), liste_plugin_files(_DIR_PLUGINS_DIST), array(), array(), _DIR_PLUGINS_DIST, |
|
| 50 | - 'afficher_nom_plugin'); |
|
| 46 | + // installer les extensions |
|
| 47 | + include_spip('inc/plugin'); |
|
| 48 | + $afficher = charger_fonction('afficher_liste', 'plugins'); |
|
| 49 | + echo $afficher(self(), liste_plugin_files(_DIR_PLUGINS_DIST), array(), array(), _DIR_PLUGINS_DIST, |
|
| 50 | + 'afficher_nom_plugin'); |
|
| 51 | 51 | |
| 52 | - // si la base de SPIP est up, on peut installer les plugins, sinon on passe cette etape |
|
| 53 | - // car les plugins supposent que la base de SPIP est dans son etat normal (mise a jour) |
|
| 54 | - // au premier passage dans l'espace prive on aura une demande d'upgrade qui se poursuit sur la page plugin |
|
| 55 | - // et procede alors a l'installation |
|
| 56 | - if (!isset($GLOBALS['meta']['version_installee']) |
|
| 57 | - or ($GLOBALS['spip_version_base'] == (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 58 | - ) { |
|
| 59 | - plugin_installes_meta(); |
|
| 60 | - } |
|
| 52 | + // si la base de SPIP est up, on peut installer les plugins, sinon on passe cette etape |
|
| 53 | + // car les plugins supposent que la base de SPIP est dans son etat normal (mise a jour) |
|
| 54 | + // au premier passage dans l'espace prive on aura une demande d'upgrade qui se poursuit sur la page plugin |
|
| 55 | + // et procede alors a l'installation |
|
| 56 | + if (!isset($GLOBALS['meta']['version_installee']) |
|
| 57 | + or ($GLOBALS['spip_version_base'] == (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 58 | + ) { |
|
| 59 | + plugin_installes_meta(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - // mettre a jour si necessaire l'adresse du site |
|
| 63 | - // securite si on arrive plus a se loger |
|
| 64 | - include_spip('inc/config'); |
|
| 65 | - appliquer_adresse_site(''); |
|
| 62 | + // mettre a jour si necessaire l'adresse du site |
|
| 63 | + // securite si on arrive plus a se loger |
|
| 64 | + include_spip('inc/config'); |
|
| 65 | + appliquer_adresse_site(''); |
|
| 66 | 66 | |
| 67 | - // aller a la derniere etape qui clos l'install et redirige |
|
| 68 | - $suite = "\n<input type='hidden' name='etape' value='fin' />" |
|
| 69 | - . bouton_suivant(_T('login_espace_prive')); |
|
| 67 | + // aller a la derniere etape qui clos l'install et redirige |
|
| 68 | + $suite = "\n<input type='hidden' name='etape' value='fin' />" |
|
| 69 | + . bouton_suivant(_T('login_espace_prive')); |
|
| 70 | 70 | |
| 71 | - echo generer_form_ecrire('install', $suite); |
|
| 72 | - echo install_fin_html(); |
|
| 71 | + echo generer_form_ecrire('install', $suite); |
|
| 72 | + echo install_fin_html(); |
|
| 73 | 73 | } |
@@ -12,77 +12,77 @@ |
||
| 12 | 12 | |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // https://code.spip.net/@install_etape_ldap2_dist |
| 19 | 19 | function install_etape_ldap2_dist() { |
| 20 | - echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 21 | - |
|
| 22 | - $adresse_ldap = _request('adresse_ldap'); |
|
| 23 | - |
|
| 24 | - $port_ldap = _request('port_ldap'); |
|
| 25 | - |
|
| 26 | - $tls_ldap = _request('tls_ldap'); |
|
| 27 | - |
|
| 28 | - $protocole_ldap = _request('protocole_ldap'); |
|
| 29 | - |
|
| 30 | - $login_ldap = _request('login_ldap'); |
|
| 31 | - |
|
| 32 | - $pass_ldap = _request('pass_ldap'); |
|
| 33 | - |
|
| 34 | - $port_ldap = intval($port_ldap); |
|
| 35 | - |
|
| 36 | - $tls = false; |
|
| 37 | - |
|
| 38 | - if ($tls_ldap == 'oui') { |
|
| 39 | - if ($port_ldap == 636) { |
|
| 40 | - $adresse_ldap = "ldaps://$adresse_ldap"; |
|
| 41 | - } else { |
|
| 42 | - $tls = true; |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 46 | - $erreur = "ldap_connect($adresse_ldap, $port_ldap)"; |
|
| 47 | - |
|
| 48 | - if ($ldap_link) { |
|
| 49 | - if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) { |
|
| 50 | - $protocole_ldap = 2; |
|
| 51 | - ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap); |
|
| 52 | - } |
|
| 53 | - if ($tls === true) { |
|
| 54 | - if (!ldap_start_tls($ldap_link)) { |
|
| 55 | - $erreur = "ldap_start_tls($ldap_link) $adresse_ldap, $port_ldap"; |
|
| 56 | - $ldap_link = false; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - if ($ldap_link) { |
|
| 60 | - $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 61 | - $erreur = "ldap_bind('$ldap_link', '$login_ldap', '$pass_ldap'): $adresse_ldap, $port_ldap"; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if ($ldap_link) { |
|
| 66 | - echo info_etape( |
|
| 67 | - _T('titre_connexion_ldap'), |
|
| 68 | - info_progression_etape(2, 'etape_ldap', 'install/') |
|
| 69 | - ), _T('info_connexion_ldap_ok'); |
|
| 70 | - echo generer_form_ecrire('install', ( |
|
| 71 | - "\n<input type='hidden' name='etape' value='ldap3' />" |
|
| 72 | - . "\n<input type='hidden' name='adresse_ldap' value=\"$adresse_ldap\" />" |
|
| 73 | - . "\n<input type='hidden' name='port_ldap' value=\"$port_ldap\" />" |
|
| 74 | - . "\n<input type='hidden' name='login_ldap' value=\"$login_ldap\" />" |
|
| 75 | - . "\n<input type='hidden' name='pass_ldap' value=\"$pass_ldap\" />" |
|
| 76 | - . "\n<input type='hidden' name='protocole_ldap' value=\"$protocole_ldap\" />" |
|
| 77 | - . "\n<input type='hidden' name='tls_ldap' value=\"$tls_ldap\" />" |
|
| 78 | - . bouton_suivant())); |
|
| 79 | - } else { |
|
| 80 | - echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
|
| 81 | - "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 82 | - '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 83 | - "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 84 | - '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - echo install_fin_html(); |
|
| 20 | + echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 21 | + |
|
| 22 | + $adresse_ldap = _request('adresse_ldap'); |
|
| 23 | + |
|
| 24 | + $port_ldap = _request('port_ldap'); |
|
| 25 | + |
|
| 26 | + $tls_ldap = _request('tls_ldap'); |
|
| 27 | + |
|
| 28 | + $protocole_ldap = _request('protocole_ldap'); |
|
| 29 | + |
|
| 30 | + $login_ldap = _request('login_ldap'); |
|
| 31 | + |
|
| 32 | + $pass_ldap = _request('pass_ldap'); |
|
| 33 | + |
|
| 34 | + $port_ldap = intval($port_ldap); |
|
| 35 | + |
|
| 36 | + $tls = false; |
|
| 37 | + |
|
| 38 | + if ($tls_ldap == 'oui') { |
|
| 39 | + if ($port_ldap == 636) { |
|
| 40 | + $adresse_ldap = "ldaps://$adresse_ldap"; |
|
| 41 | + } else { |
|
| 42 | + $tls = true; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 46 | + $erreur = "ldap_connect($adresse_ldap, $port_ldap)"; |
|
| 47 | + |
|
| 48 | + if ($ldap_link) { |
|
| 49 | + if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) { |
|
| 50 | + $protocole_ldap = 2; |
|
| 51 | + ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap); |
|
| 52 | + } |
|
| 53 | + if ($tls === true) { |
|
| 54 | + if (!ldap_start_tls($ldap_link)) { |
|
| 55 | + $erreur = "ldap_start_tls($ldap_link) $adresse_ldap, $port_ldap"; |
|
| 56 | + $ldap_link = false; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + if ($ldap_link) { |
|
| 60 | + $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 61 | + $erreur = "ldap_bind('$ldap_link', '$login_ldap', '$pass_ldap'): $adresse_ldap, $port_ldap"; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if ($ldap_link) { |
|
| 66 | + echo info_etape( |
|
| 67 | + _T('titre_connexion_ldap'), |
|
| 68 | + info_progression_etape(2, 'etape_ldap', 'install/') |
|
| 69 | + ), _T('info_connexion_ldap_ok'); |
|
| 70 | + echo generer_form_ecrire('install', ( |
|
| 71 | + "\n<input type='hidden' name='etape' value='ldap3' />" |
|
| 72 | + . "\n<input type='hidden' name='adresse_ldap' value=\"$adresse_ldap\" />" |
|
| 73 | + . "\n<input type='hidden' name='port_ldap' value=\"$port_ldap\" />" |
|
| 74 | + . "\n<input type='hidden' name='login_ldap' value=\"$login_ldap\" />" |
|
| 75 | + . "\n<input type='hidden' name='pass_ldap' value=\"$pass_ldap\" />" |
|
| 76 | + . "\n<input type='hidden' name='protocole_ldap' value=\"$protocole_ldap\" />" |
|
| 77 | + . "\n<input type='hidden' name='tls_ldap' value=\"$tls_ldap\" />" |
|
| 78 | + . bouton_suivant())); |
|
| 79 | + } else { |
|
| 80 | + echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
|
| 81 | + "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 82 | + '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 83 | + "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 84 | + '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + echo install_fin_html(); |
|
| 88 | 88 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/headers'); |
@@ -21,64 +21,64 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | // https://code.spip.net/@install_etape_fin_dist |
| 23 | 23 | function install_etape_fin_dist() { |
| 24 | - ecrire_acces(); |
|
| 24 | + ecrire_acces(); |
|
| 25 | 25 | |
| 26 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CHMOD_TMP); |
|
| 27 | - if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 28 | - if (!@rename(_FILE_CHMOD_TMP, $f)) { |
|
| 29 | - if (@copy(_FILE_CHMOD_TMP, $f)) { |
|
| 30 | - spip_unlink(_FILE_CHMOD_TMP); |
|
| 31 | - } |
|
| 32 | - } |
|
| 33 | - } |
|
| 26 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CHMOD_TMP); |
|
| 27 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 28 | + if (!@rename(_FILE_CHMOD_TMP, $f)) { |
|
| 29 | + if (@copy(_FILE_CHMOD_TMP, $f)) { |
|
| 30 | + spip_unlink(_FILE_CHMOD_TMP); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CONNECT_TMP); |
|
| 36 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 37 | - spip_log("renomme $f"); |
|
| 38 | - if (!@rename(_FILE_CONNECT_TMP, $f)) { |
|
| 39 | - if (@copy(_FILE_CONNECT_TMP, $f)) { |
|
| 40 | - @spip_unlink(_FILE_CONNECT_TMP); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 35 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CONNECT_TMP); |
|
| 36 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 37 | + spip_log("renomme $f"); |
|
| 38 | + if (!@rename(_FILE_CONNECT_TMP, $f)) { |
|
| 39 | + if (@copy(_FILE_CONNECT_TMP, $f)) { |
|
| 40 | + @spip_unlink(_FILE_CONNECT_TMP); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - // creer le repertoire cache, qui sert partout ! |
|
| 46 | - // deja fait en etape 4 en principe, on garde au cas ou |
|
| 47 | - if (!@file_exists(_DIR_CACHE)) { |
|
| 48 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 49 | - $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 50 | - } |
|
| 45 | + // creer le repertoire cache, qui sert partout ! |
|
| 46 | + // deja fait en etape 4 en principe, on garde au cas ou |
|
| 47 | + if (!@file_exists(_DIR_CACHE)) { |
|
| 48 | + $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 49 | + $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // Verifier la securite des htaccess |
|
| 53 | - // Si elle ne fonctionne pas, prevenir |
|
| 54 | - $msg = install_verifier_htaccess(); |
|
| 55 | - if ($msg) { |
|
| 56 | - $cible = _T('public:accueil_site'); |
|
| 57 | - $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 58 | - echo minipres('AUTO', $msg . $cible); |
|
| 59 | - // ok, deboucher dans l'espace prive |
|
| 60 | - } else { |
|
| 61 | - redirige_url_ecrire('accueil'); |
|
| 62 | - } |
|
| 52 | + // Verifier la securite des htaccess |
|
| 53 | + // Si elle ne fonctionne pas, prevenir |
|
| 54 | + $msg = install_verifier_htaccess(); |
|
| 55 | + if ($msg) { |
|
| 56 | + $cible = _T('public:accueil_site'); |
|
| 57 | + $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 58 | + echo minipres('AUTO', $msg . $cible); |
|
| 59 | + // ok, deboucher dans l'espace prive |
|
| 60 | + } else { |
|
| 61 | + redirige_url_ecrire('accueil'); |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function install_verifier_htaccess() { |
| 66 | - if (verifier_htaccess(_DIR_TMP, true) |
|
| 67 | - and verifier_htaccess(_DIR_CONNECT, true) |
|
| 68 | - ) { |
|
| 69 | - return ''; |
|
| 70 | - } |
|
| 66 | + if (verifier_htaccess(_DIR_TMP, true) |
|
| 67 | + and verifier_htaccess(_DIR_CONNECT, true) |
|
| 68 | + ) { |
|
| 69 | + return ''; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $titre = _T('htaccess_inoperant'); |
|
| 72 | + $titre = _T('htaccess_inoperant'); |
|
| 73 | 73 | |
| 74 | - $averti = _T( |
|
| 75 | - 'htaccess_a_simuler', |
|
| 76 | - array( |
|
| 77 | - 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 78 | - 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
|
| 79 | - 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 80 | - ) |
|
| 81 | - ); |
|
| 74 | + $averti = _T( |
|
| 75 | + 'htaccess_a_simuler', |
|
| 76 | + array( |
|
| 77 | + 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 78 | + 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
|
| 79 | + 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 80 | + ) |
|
| 81 | + ); |
|
| 82 | 82 | |
| 83 | - return "<div class='error'><h3>$titre</h3><p>$averti</p></div>"; |
|
| 83 | + return "<div class='error'><h3>$titre</h3><p>$averti</p></div>"; |
|
| 84 | 84 | } |
@@ -11,11 +11,11 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | if (defined('_TEST_DIRS')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | define('_TEST_DIRS', '1'); |
| 21 | 21 | |
@@ -27,42 +27,42 @@ discard block |
||
| 27 | 27 | // |
| 28 | 28 | // https://code.spip.net/@test_ecrire |
| 29 | 29 | function test_ecrire($my_dir) { |
| 30 | - static $chmod = 0; |
|
| 31 | - |
|
| 32 | - $ok = false; |
|
| 33 | - $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 34 | - $self = basename($script); |
|
| 35 | - $uid = @fileowner('.'); |
|
| 36 | - $uid2 = @fileowner($self); |
|
| 37 | - $gid = @filegroup('.'); |
|
| 38 | - $gid2 = @filegroup($self); |
|
| 39 | - $perms = @fileperms($self); |
|
| 40 | - |
|
| 41 | - // Comparer l'appartenance d'un fichier cree par PHP |
|
| 42 | - // avec celle du script et du repertoire courant |
|
| 43 | - if (!$chmod) { |
|
| 44 | - @rmdir('test'); |
|
| 45 | - spip_unlink('test'); // effacer au cas ou |
|
| 46 | - @touch('test'); |
|
| 47 | - if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 48 | - $chmod = 0700; |
|
| 49 | - } else { |
|
| 50 | - if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 51 | - $chmod = 0770; |
|
| 52 | - } else { |
|
| 53 | - $chmod = 0777; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - // Appliquer de plus les droits d'acces du script |
|
| 57 | - if ($perms > 0) { |
|
| 58 | - $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 59 | - $chmod |= $perms; |
|
| 60 | - } |
|
| 61 | - spip_unlink('test'); |
|
| 62 | - } |
|
| 63 | - $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 64 | - |
|
| 65 | - return $ok ? $chmod : false; |
|
| 30 | + static $chmod = 0; |
|
| 31 | + |
|
| 32 | + $ok = false; |
|
| 33 | + $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 34 | + $self = basename($script); |
|
| 35 | + $uid = @fileowner('.'); |
|
| 36 | + $uid2 = @fileowner($self); |
|
| 37 | + $gid = @filegroup('.'); |
|
| 38 | + $gid2 = @filegroup($self); |
|
| 39 | + $perms = @fileperms($self); |
|
| 40 | + |
|
| 41 | + // Comparer l'appartenance d'un fichier cree par PHP |
|
| 42 | + // avec celle du script et du repertoire courant |
|
| 43 | + if (!$chmod) { |
|
| 44 | + @rmdir('test'); |
|
| 45 | + spip_unlink('test'); // effacer au cas ou |
|
| 46 | + @touch('test'); |
|
| 47 | + if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 48 | + $chmod = 0700; |
|
| 49 | + } else { |
|
| 50 | + if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 51 | + $chmod = 0770; |
|
| 52 | + } else { |
|
| 53 | + $chmod = 0777; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + // Appliquer de plus les droits d'acces du script |
|
| 57 | + if ($perms > 0) { |
|
| 58 | + $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 59 | + $chmod |= $perms; |
|
| 60 | + } |
|
| 61 | + spip_unlink('test'); |
|
| 62 | + } |
|
| 63 | + $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 64 | + |
|
| 65 | + return $ok ? $chmod : false; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // |
@@ -73,83 +73,83 @@ discard block |
||
| 73 | 73 | // https://code.spip.net/@install_etape_chmod_dist |
| 74 | 74 | function install_etape_chmod_dist() { |
| 75 | 75 | |
| 76 | - $test_dir = _request('test_dir'); |
|
| 77 | - $chmod = 0; |
|
| 78 | - |
|
| 79 | - if ($test_dir) { |
|
| 80 | - if (substr($test_dir, -1) !== '/') { |
|
| 81 | - $test_dir .= '/'; |
|
| 82 | - } |
|
| 83 | - if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 84 | - $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 85 | - } |
|
| 86 | - } else { |
|
| 87 | - if (!_FILE_CONNECT) { |
|
| 88 | - $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 89 | - $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $bad_dirs = array(); |
|
| 94 | - $absent_dirs = array(); |
|
| 95 | - |
|
| 96 | - foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 97 | - $test = test_ecrire($my_dir); |
|
| 98 | - if (!$test) { |
|
| 99 | - $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 100 | - if (@file_exists($my_dir)) { |
|
| 101 | - $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 102 | - } else { |
|
| 103 | - $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 104 | - } |
|
| 105 | - } else { |
|
| 106 | - $chmod = max($chmod, $test); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if ($bad_dirs or $absent_dirs) { |
|
| 111 | - if (!_FILE_CONNECT) { |
|
| 112 | - $titre = _T('dirs_preliminaire'); |
|
| 113 | - $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 114 | - } else { |
|
| 115 | - $titre = _T('dirs_probleme_droits'); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 120 | - |
|
| 121 | - if ($bad_dirs) { |
|
| 122 | - $res .= |
|
| 123 | - _T( |
|
| 124 | - 'dirs_repertoires_suivants', |
|
| 125 | - array('bad_dirs' => join("\n", array_keys($bad_dirs))) |
|
| 126 | - ) . |
|
| 127 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ($absent_dirs) { |
|
| 131 | - $res .= |
|
| 132 | - _T( |
|
| 133 | - 'dirs_repertoires_absents', |
|
| 134 | - array('bad_dirs' => join("\n", array_keys($absent_dirs))) |
|
| 135 | - ) . |
|
| 136 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 137 | - } |
|
| 138 | - $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 139 | - |
|
| 140 | - $t = _T('login_recharger'); |
|
| 141 | - $t = (!$test_dir ? '' : |
|
| 142 | - "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 143 | - . "<input type='hidden' name='etape' value='chmod' />" |
|
| 144 | - . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 145 | - |
|
| 146 | - echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 147 | - } else { |
|
| 148 | - $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 149 | - if (!$deja) { |
|
| 150 | - redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 151 | - } else { |
|
| 152 | - redirige_url_ecrire(); |
|
| 153 | - } |
|
| 154 | - } |
|
| 76 | + $test_dir = _request('test_dir'); |
|
| 77 | + $chmod = 0; |
|
| 78 | + |
|
| 79 | + if ($test_dir) { |
|
| 80 | + if (substr($test_dir, -1) !== '/') { |
|
| 81 | + $test_dir .= '/'; |
|
| 82 | + } |
|
| 83 | + if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 84 | + $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 85 | + } |
|
| 86 | + } else { |
|
| 87 | + if (!_FILE_CONNECT) { |
|
| 88 | + $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 89 | + $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $bad_dirs = array(); |
|
| 94 | + $absent_dirs = array(); |
|
| 95 | + |
|
| 96 | + foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 97 | + $test = test_ecrire($my_dir); |
|
| 98 | + if (!$test) { |
|
| 99 | + $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 100 | + if (@file_exists($my_dir)) { |
|
| 101 | + $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 102 | + } else { |
|
| 103 | + $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 104 | + } |
|
| 105 | + } else { |
|
| 106 | + $chmod = max($chmod, $test); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if ($bad_dirs or $absent_dirs) { |
|
| 111 | + if (!_FILE_CONNECT) { |
|
| 112 | + $titre = _T('dirs_preliminaire'); |
|
| 113 | + $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 114 | + } else { |
|
| 115 | + $titre = _T('dirs_probleme_droits'); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 120 | + |
|
| 121 | + if ($bad_dirs) { |
|
| 122 | + $res .= |
|
| 123 | + _T( |
|
| 124 | + 'dirs_repertoires_suivants', |
|
| 125 | + array('bad_dirs' => join("\n", array_keys($bad_dirs))) |
|
| 126 | + ) . |
|
| 127 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ($absent_dirs) { |
|
| 131 | + $res .= |
|
| 132 | + _T( |
|
| 133 | + 'dirs_repertoires_absents', |
|
| 134 | + array('bad_dirs' => join("\n", array_keys($absent_dirs))) |
|
| 135 | + ) . |
|
| 136 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 137 | + } |
|
| 138 | + $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 139 | + |
|
| 140 | + $t = _T('login_recharger'); |
|
| 141 | + $t = (!$test_dir ? '' : |
|
| 142 | + "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 143 | + . "<input type='hidden' name='etape' value='chmod' />" |
|
| 144 | + . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 145 | + |
|
| 146 | + echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 147 | + } else { |
|
| 148 | + $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 149 | + if (!$deja) { |
|
| 150 | + redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 151 | + } else { |
|
| 152 | + redirige_url_ecrire(); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | 155 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Installation |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/acces'); |
@@ -33,18 +33,18 @@ discard block |
||
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | 35 | function base_determine_autoinc($table, $desc = array()) { |
| 36 | - if ($t = lister_tables_principales() and isset($t[$table])) { |
|
| 37 | - $autoinc = true; |
|
| 38 | - } elseif ($t = lister_tables_auxiliaires() and isset($t[$table])) { |
|
| 39 | - $autoinc = false; |
|
| 40 | - } else { |
|
| 41 | - // essayer de faire au mieux ! |
|
| 42 | - $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 43 | - and strpos($desc['key']['PRIMARY KEY'], ',') === false |
|
| 44 | - and strpos($desc['field'][$desc['key']['PRIMARY KEY']], 'default') === false); |
|
| 45 | - } |
|
| 36 | + if ($t = lister_tables_principales() and isset($t[$table])) { |
|
| 37 | + $autoinc = true; |
|
| 38 | + } elseif ($t = lister_tables_auxiliaires() and isset($t[$table])) { |
|
| 39 | + $autoinc = false; |
|
| 40 | + } else { |
|
| 41 | + // essayer de faire au mieux ! |
|
| 42 | + $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 43 | + and strpos($desc['key']['PRIMARY KEY'], ',') === false |
|
| 44 | + and strpos($desc['field'][$desc['key']['PRIMARY KEY']], 'default') === false); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $autoinc; |
|
| 47 | + return $autoinc; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -61,59 +61,59 @@ discard block |
||
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | 63 | function creer_ou_upgrader_table($table, $desc, $autoinc, $upgrade = false, $serveur = '') { |
| 64 | - #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 65 | - $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 66 | - #if (!$sql_desc) $sql_desc = false; |
|
| 67 | - #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 68 | - if (!$sql_desc) { |
|
| 69 | - if ($autoinc === 'auto') { |
|
| 70 | - $autoinc = base_determine_autoinc($table, $desc); |
|
| 71 | - } |
|
| 72 | - #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 73 | - if (isset($desc['field']) and isset($desc['key'])) { |
|
| 74 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 75 | - } |
|
| 76 | - // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 77 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 78 | - #if (!$sql_desc) $sql_desc = false; |
|
| 79 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 80 | - if (!$sql_desc) { |
|
| 81 | - // on retente avec un sleep ? |
|
| 82 | - sleep(1); |
|
| 83 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 84 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 85 | - #if (!$sql_desc) $sql_desc = false; |
|
| 86 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 87 | - if (!$sql_desc) { |
|
| 88 | - spip_log("Echec creation table $table", "maj" . _LOG_CRITIQUE); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 93 | - // ajouter les champs manquants |
|
| 94 | - // on ne supprime jamais les champs, car c'est dangereux |
|
| 95 | - // c'est toujours a faire manuellement |
|
| 96 | - $last = ''; |
|
| 97 | - if (isset($desc['field'])) { |
|
| 98 | - foreach ($desc['field'] as $field => $type) { |
|
| 99 | - if (!isset($sql_desc['field'][$field])) { |
|
| 100 | - sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ""), $serveur); |
|
| 101 | - } |
|
| 102 | - $last = $field; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - if (isset($desc['key'])) { |
|
| 106 | - foreach ($desc['key'] as $key => $type) { |
|
| 107 | - // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 108 | - // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 109 | - if (!isset($sql_desc['key'][$key]) and !isset($sql_desc['key']["$key $type"])) { |
|
| 110 | - sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 111 | - } |
|
| 112 | - $last = $field; |
|
| 113 | - } |
|
| 114 | - } |
|
| 64 | + #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 65 | + $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 66 | + #if (!$sql_desc) $sql_desc = false; |
|
| 67 | + #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 68 | + if (!$sql_desc) { |
|
| 69 | + if ($autoinc === 'auto') { |
|
| 70 | + $autoinc = base_determine_autoinc($table, $desc); |
|
| 71 | + } |
|
| 72 | + #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 73 | + if (isset($desc['field']) and isset($desc['key'])) { |
|
| 74 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 75 | + } |
|
| 76 | + // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 77 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 78 | + #if (!$sql_desc) $sql_desc = false; |
|
| 79 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 80 | + if (!$sql_desc) { |
|
| 81 | + // on retente avec un sleep ? |
|
| 82 | + sleep(1); |
|
| 83 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 84 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 85 | + #if (!$sql_desc) $sql_desc = false; |
|
| 86 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 87 | + if (!$sql_desc) { |
|
| 88 | + spip_log("Echec creation table $table", "maj" . _LOG_CRITIQUE); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 93 | + // ajouter les champs manquants |
|
| 94 | + // on ne supprime jamais les champs, car c'est dangereux |
|
| 95 | + // c'est toujours a faire manuellement |
|
| 96 | + $last = ''; |
|
| 97 | + if (isset($desc['field'])) { |
|
| 98 | + foreach ($desc['field'] as $field => $type) { |
|
| 99 | + if (!isset($sql_desc['field'][$field])) { |
|
| 100 | + sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ""), $serveur); |
|
| 101 | + } |
|
| 102 | + $last = $field; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + if (isset($desc['key'])) { |
|
| 106 | + foreach ($desc['key'] as $key => $type) { |
|
| 107 | + // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 108 | + // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 109 | + if (!isset($sql_desc['key'][$key]) and !isset($sql_desc['key']["$key $type"])) { |
|
| 110 | + sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 111 | + } |
|
| 112 | + $last = $field; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - } |
|
| 116 | + } |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -135,26 +135,26 @@ discard block |
||
| 135 | 135 | * @return void |
| 136 | 136 | */ |
| 137 | 137 | function alterer_base($tables_inc, $tables_noinc, $up = false, $serveur = '') { |
| 138 | - if ($up === false) { |
|
| 139 | - $old = false; |
|
| 140 | - $up = array(); |
|
| 141 | - } else { |
|
| 142 | - $old = true; |
|
| 143 | - if (!is_array($up)) { |
|
| 144 | - $up = array($up); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - foreach ($tables_inc as $k => $v) { |
|
| 148 | - if (!$old or in_array($k, $up)) { |
|
| 149 | - creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 150 | - } |
|
| 151 | - } |
|
| 138 | + if ($up === false) { |
|
| 139 | + $old = false; |
|
| 140 | + $up = array(); |
|
| 141 | + } else { |
|
| 142 | + $old = true; |
|
| 143 | + if (!is_array($up)) { |
|
| 144 | + $up = array($up); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + foreach ($tables_inc as $k => $v) { |
|
| 148 | + if (!$old or in_array($k, $up)) { |
|
| 149 | + creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - foreach ($tables_noinc as $k => $v) { |
|
| 154 | - if (!$old or in_array($k, $up)) { |
|
| 155 | - creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 156 | - } |
|
| 157 | - } |
|
| 153 | + foreach ($tables_noinc as $k => $v) { |
|
| 154 | + if (!$old or in_array($k, $up)) { |
|
| 155 | + creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -174,16 +174,16 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | function creer_base($serveur = '') { |
| 176 | 176 | |
| 177 | - // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 178 | - // de la conformite de la base |
|
| 179 | - // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 177 | + // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 178 | + // de la conformite de la base |
|
| 179 | + // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 180 | 180 | |
| 181 | - alterer_base( |
|
| 182 | - lister_tables_principales(), |
|
| 183 | - lister_tables_auxiliaires(), |
|
| 184 | - false, |
|
| 185 | - $serveur |
|
| 186 | - ); |
|
| 181 | + alterer_base( |
|
| 182 | + lister_tables_principales(), |
|
| 183 | + lister_tables_auxiliaires(), |
|
| 184 | + false, |
|
| 185 | + $serveur |
|
| 186 | + ); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | * @return void |
| 204 | 204 | */ |
| 205 | 205 | function maj_tables($upgrade_tables = array(), $serveur = '') { |
| 206 | - alterer_base( |
|
| 207 | - lister_tables_principales(), |
|
| 208 | - lister_tables_auxiliaires(), |
|
| 209 | - $upgrade_tables, |
|
| 210 | - $serveur |
|
| 211 | - ); |
|
| 206 | + alterer_base( |
|
| 207 | + lister_tables_principales(), |
|
| 208 | + lister_tables_auxiliaires(), |
|
| 209 | + $upgrade_tables, |
|
| 210 | + $serveur |
|
| 211 | + ); |
|
| 212 | 212 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/actions'); |
@@ -29,22 +29,22 @@ discard block |
||
| 29 | 29 | * @return void |
| 30 | 30 | */ |
| 31 | 31 | function action_etre_webmestre_dist() { |
| 32 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 33 | - $time = $securiser_action(); |
|
| 34 | - |
|
| 35 | - if (time() - $time < 15 * 60 |
|
| 36 | - and $GLOBALS['visiteur_session']['statut'] == '0minirezo' |
|
| 37 | - and $GLOBALS['visiteur_session']['webmestre'] !== 'oui' |
|
| 38 | - ) { |
|
| 39 | - $action = _T('info_admin_etre_webmestre'); |
|
| 40 | - $admin = charger_fonction('admin', 'inc'); |
|
| 41 | - // lance la verif par ftp et l'appel |
|
| 42 | - // a base_etre_webmestre_dist quand c'est OK |
|
| 43 | - if ($r = $admin('etre_webmestre', $action)) { |
|
| 44 | - echo $r; |
|
| 45 | - exit; |
|
| 46 | - } |
|
| 47 | - } |
|
| 32 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 33 | + $time = $securiser_action(); |
|
| 34 | + |
|
| 35 | + if (time() - $time < 15 * 60 |
|
| 36 | + and $GLOBALS['visiteur_session']['statut'] == '0minirezo' |
|
| 37 | + and $GLOBALS['visiteur_session']['webmestre'] !== 'oui' |
|
| 38 | + ) { |
|
| 39 | + $action = _T('info_admin_etre_webmestre'); |
|
| 40 | + $admin = charger_fonction('admin', 'inc'); |
|
| 41 | + // lance la verif par ftp et l'appel |
|
| 42 | + // a base_etre_webmestre_dist quand c'est OK |
|
| 43 | + if ($r = $admin('etre_webmestre', $action)) { |
|
| 44 | + echo $r; |
|
| 45 | + exit; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * @return void |
| 55 | 55 | */ |
| 56 | 56 | function base_etre_webmestre_dist() { |
| 57 | - if ($GLOBALS['visiteur_session']['statut'] == '0minirezo' and $GLOBALS['visiteur_session']['webmestre'] !== 'oui') { |
|
| 58 | - include_spip('action/editer_auteur'); |
|
| 59 | - auteur_instituer($GLOBALS['visiteur_session']['id_auteur'], array('webmestre' => 'oui'), true); |
|
| 60 | - } |
|
| 57 | + if ($GLOBALS['visiteur_session']['statut'] == '0minirezo' and $GLOBALS['visiteur_session']['webmestre'] !== 'oui') { |
|
| 58 | + include_spip('action/editer_auteur'); |
|
| 59 | + auteur_instituer($GLOBALS['visiteur_session']['id_auteur'], array('webmestre' => 'oui'), true); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/charsets'); |
| 23 | 23 | include_spip('inc/texte'); |
@@ -25,189 +25,189 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // https://code.spip.net/@ligne_plug |
| 27 | 27 | function plugins_afficher_plugin_dist( |
| 28 | - $url_page, |
|
| 29 | - $plug_file, |
|
| 30 | - $checked, |
|
| 31 | - $actif, |
|
| 32 | - $expose = false, |
|
| 33 | - $class_li = "item", |
|
| 34 | - $dir_plugins = _DIR_PLUGINS |
|
| 28 | + $url_page, |
|
| 29 | + $plug_file, |
|
| 30 | + $checked, |
|
| 31 | + $actif, |
|
| 32 | + $expose = false, |
|
| 33 | + $class_li = "item", |
|
| 34 | + $dir_plugins = _DIR_PLUGINS |
|
| 35 | 35 | ) { |
| 36 | 36 | |
| 37 | - static $id_input = 0; |
|
| 38 | - static $versions = array(); |
|
| 39 | - |
|
| 40 | - $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | - $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | - $prefix = $info['prefix']; |
|
| 44 | - $cfg = ""; |
|
| 45 | - $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | - $erreur = ""; |
|
| 48 | - |
|
| 49 | - if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | - $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | - $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | - _T('plugin_info_non_compatible_spip')); |
|
| 53 | - $class_li .= " disabled"; |
|
| 54 | - $checkable = false; |
|
| 55 | - } elseif (isset($info['erreur'])) { |
|
| 56 | - $class_li .= " error"; |
|
| 57 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | - _T('plugin_info_erreur_xml')) |
|
| 59 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | - $checkable = false; |
|
| 61 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | - $class_li .= " error"; |
|
| 63 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | - " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | - . "<div class='erreur'>" . implode("<br />", |
|
| 66 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | - } else { |
|
| 68 | - $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // numerotons les occurrences d'un meme prefix |
|
| 72 | - $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 73 | - |
|
| 74 | - $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | - |
|
| 76 | - return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | - . ((!$checkable and !$checked) |
|
| 78 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | - . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | - . $cfg |
|
| 81 | - . $erreur |
|
| 82 | - . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | - ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | - . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | - . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | - . "</div>" |
|
| 87 | - . "</li>"; |
|
| 37 | + static $id_input = 0; |
|
| 38 | + static $versions = array(); |
|
| 39 | + |
|
| 40 | + $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | + $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | + $prefix = $info['prefix']; |
|
| 44 | + $cfg = ""; |
|
| 45 | + $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | + $erreur = ""; |
|
| 48 | + |
|
| 49 | + if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | + $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | + $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | + _T('plugin_info_non_compatible_spip')); |
|
| 53 | + $class_li .= " disabled"; |
|
| 54 | + $checkable = false; |
|
| 55 | + } elseif (isset($info['erreur'])) { |
|
| 56 | + $class_li .= " error"; |
|
| 57 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | + _T('plugin_info_erreur_xml')) |
|
| 59 | + . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | + $checkable = false; |
|
| 61 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | + $class_li .= " error"; |
|
| 63 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | + " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | + . "<div class='erreur'>" . implode("<br />", |
|
| 66 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | + } else { |
|
| 68 | + $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // numerotons les occurrences d'un meme prefix |
|
| 72 | + $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 73 | + |
|
| 74 | + $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | + |
|
| 76 | + return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | + . ((!$checkable and !$checked) |
|
| 78 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | + . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | + . $cfg |
|
| 81 | + . $erreur |
|
| 82 | + . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | + ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | + . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | + . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | + . "</div>" |
|
| 87 | + . "</li>"; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function plugin_bouton_config($nom, $infos, $dir) { |
| 91 | - // la verification se base sur le filesystem |
|
| 92 | - // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | - $prefix = strtolower($infos['prefix']); |
|
| 94 | - // si paquet.xml fournit un squelette, le prendre |
|
| 95 | - if (isset($infos['config']) and $infos['config']) { |
|
| 96 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | - array( |
|
| 98 | - 'script' => 'configurer_' . $prefix, |
|
| 99 | - 'nom' => $nom |
|
| 100 | - )); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // si le plugin CFG est la, l'essayer |
|
| 104 | - if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | - { |
|
| 107 | - if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | - return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // sinon prendre le squelette std sur le nom std |
|
| 114 | - return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | - array( |
|
| 116 | - 'script' => 'configurer_' . $prefix, |
|
| 117 | - 'nom' => $nom |
|
| 118 | - )); |
|
| 91 | + // la verification se base sur le filesystem |
|
| 92 | + // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | + $prefix = strtolower($infos['prefix']); |
|
| 94 | + // si paquet.xml fournit un squelette, le prendre |
|
| 95 | + if (isset($infos['config']) and $infos['config']) { |
|
| 96 | + return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | + array( |
|
| 98 | + 'script' => 'configurer_' . $prefix, |
|
| 99 | + 'nom' => $nom |
|
| 100 | + )); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // si le plugin CFG est la, l'essayer |
|
| 104 | + if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | + if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | + { |
|
| 107 | + if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | + return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // sinon prendre le squelette std sur le nom std |
|
| 114 | + return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | + array( |
|
| 116 | + 'script' => 'configurer_' . $prefix, |
|
| 117 | + 'nom' => $nom |
|
| 118 | + )); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // checkbox pour activer ou desactiver |
| 122 | 122 | // si ce n'est pas une extension |
| 123 | 123 | |
| 124 | 124 | function plugin_checkbox($id_input, $file, $actif) { |
| 125 | - $name = substr(md5($file), 0, 16); |
|
| 126 | - |
|
| 127 | - return "<div class='check'>\n" |
|
| 128 | - . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | - . ($actif ? " checked='checked'" : "") |
|
| 130 | - . " class='checkbox' value='O' />" |
|
| 131 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | - . "</div>"; |
|
| 125 | + $name = substr(md5($file), 0, 16); |
|
| 126 | + |
|
| 127 | + return "<div class='check'>\n" |
|
| 128 | + . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | + . ($actif ? " checked='checked'" : "") |
|
| 130 | + . " class='checkbox' value='O' />" |
|
| 131 | + . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | + . "</div>"; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function plugin_nom($info, $dir_plugins, $plug_file) { |
| 136 | - $prefix = $info['prefix']; |
|
| 137 | - $dir = "$dir_plugins$plug_file"; |
|
| 138 | - // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | - if ($info['dtd'] == "paquet") { |
|
| 140 | - $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix"); |
|
| 141 | - if (!$nom) { |
|
| 142 | - $nom = typo($info['nom']); |
|
| 143 | - } |
|
| 144 | - } else { |
|
| 145 | - $nom = typo(attribut_html($info['nom'])); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return trim($nom); |
|
| 136 | + $prefix = $info['prefix']; |
|
| 137 | + $dir = "$dir_plugins$plug_file"; |
|
| 138 | + // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | + if ($info['dtd'] == "paquet") { |
|
| 140 | + $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix"); |
|
| 141 | + if (!$nom) { |
|
| 142 | + $nom = typo($info['nom']); |
|
| 143 | + } |
|
| 144 | + } else { |
|
| 145 | + $nom = typo(attribut_html($info['nom'])); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return trim($nom); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Cartouche Resume |
| 152 | 152 | function plugin_resume($info, $dir_plugins, $plug_file, $url_page) { |
| 153 | - $prefix = $info['prefix']; |
|
| 154 | - $dir = "$dir_plugins$plug_file"; |
|
| 155 | - $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | - // une seule ligne dans le slogan : couper si besoin |
|
| 157 | - if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | - $slogan = substr($slogan, 0, $p); |
|
| 159 | - } |
|
| 160 | - // couper par securite |
|
| 161 | - $slogan = couper($slogan, 80); |
|
| 162 | - |
|
| 163 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | - |
|
| 165 | - $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | - |
|
| 167 | - $icon_class = 'icon'; |
|
| 168 | - $img = ''; |
|
| 169 | - if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 170 | - if ($img = chemin_image("$dir/$i")) { |
|
| 171 | - $img = http_img_pack($img, '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - if (!$img) { |
|
| 175 | - $img = http_img_pack("plugin-xx.svg", '', " width='32' height='32'"); |
|
| 176 | - $icon_class .= ' no-logo'; |
|
| 177 | - } |
|
| 178 | - else { |
|
| 153 | + $prefix = $info['prefix']; |
|
| 154 | + $dir = "$dir_plugins$plug_file"; |
|
| 155 | + $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | + // une seule ligne dans le slogan : couper si besoin |
|
| 157 | + if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | + $slogan = substr($slogan, 0, $p); |
|
| 159 | + } |
|
| 160 | + // couper par securite |
|
| 161 | + $slogan = couper($slogan, 80); |
|
| 162 | + |
|
| 163 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | + |
|
| 165 | + $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | + |
|
| 167 | + $icon_class = 'icon'; |
|
| 168 | + $img = ''; |
|
| 169 | + if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 170 | + if ($img = chemin_image("$dir/$i")) { |
|
| 171 | + $img = http_img_pack($img, '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + if (!$img) { |
|
| 175 | + $img = http_img_pack("plugin-xx.svg", '', " width='32' height='32'"); |
|
| 176 | + $icon_class .= ' no-logo'; |
|
| 177 | + } |
|
| 178 | + else { |
|
| 179 | 179 | # $img = "<img src='$img' width='32' height='32' alt='' />"; |
| 180 | - } |
|
| 181 | - $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>"; |
|
| 182 | - |
|
| 183 | - return "<div class='resume'>" |
|
| 184 | - . "<h3><a href='$url' rel='info'>" |
|
| 185 | - . $nom |
|
| 186 | - . "</a></h3>" |
|
| 187 | - . " <span class='version'>" . $info['version'] . "</span>" |
|
| 188 | - . " <span class='etat'> - " |
|
| 189 | - . plugin_etat_en_clair($info['etat']) |
|
| 190 | - . "</span>" |
|
| 191 | - . "<div class='short'>" . $slogan . "</div>" |
|
| 192 | - . $i |
|
| 193 | - . "</div>"; |
|
| 180 | + } |
|
| 181 | + $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>"; |
|
| 182 | + |
|
| 183 | + return "<div class='resume'>" |
|
| 184 | + . "<h3><a href='$url' rel='info'>" |
|
| 185 | + . $nom |
|
| 186 | + . "</a></h3>" |
|
| 187 | + . " <span class='version'>" . $info['version'] . "</span>" |
|
| 188 | + . " <span class='etat'> - " |
|
| 189 | + . plugin_etat_en_clair($info['etat']) |
|
| 190 | + . "</span>" |
|
| 191 | + . "<div class='short'>" . $slogan . "</div>" |
|
| 192 | + . $i |
|
| 193 | + . "</div>"; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 197 | - if (!$dir_plugins) { |
|
| 198 | - $dir_plugins = _DIR_PLUGINS; |
|
| 199 | - } |
|
| 197 | + if (!$dir_plugins) { |
|
| 198 | + $dir_plugins = _DIR_PLUGINS; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 202 | - $text = _T('bouton_desinstaller'); |
|
| 203 | - $text2 = _T('info_desinstaller_plugin'); |
|
| 204 | - $file = basename($plug_file); |
|
| 201 | + $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 202 | + $text = _T('bouton_desinstaller'); |
|
| 203 | + $text2 = _T('info_desinstaller_plugin'); |
|
| 204 | + $file = basename($plug_file); |
|
| 205 | 205 | |
| 206 | - return "<div class='actions'>[" . |
|
| 207 | - "<a href='$action' |
|
| 206 | + return "<div class='actions'>[" . |
|
| 207 | + "<a href='$action' |
|
| 208 | 208 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 209 | - . $text |
|
| 210 | - . "</a>]</div>"; |
|
| 209 | + . $text |
|
| 210 | + . "</a>]</div>"; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -221,137 +221,137 @@ discard block |
||
| 221 | 221 | * Traduction de l'état dans la langue en cours |
| 222 | 222 | **/ |
| 223 | 223 | function plugin_etat_en_clair($etat) { |
| 224 | - if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 225 | - $etat = 'developpement'; |
|
| 226 | - } |
|
| 224 | + if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 225 | + $etat = 'developpement'; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - return _T('plugin_etat_' . $etat); |
|
| 228 | + return _T('plugin_etat_' . $etat); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // https://code.spip.net/@plugin_propre |
| 232 | 232 | function plugin_propre($texte, $module = '',$propre='propre') { |
| 233 | - // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 234 | - if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 235 | - $module = substr($module, strlen(_DIR_RACINE)); |
|
| 236 | - } |
|
| 237 | - if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 238 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - return $propre($texte); |
|
| 233 | + // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 234 | + if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 235 | + $module = substr($module, strlen(_DIR_RACINE)); |
|
| 236 | + } |
|
| 237 | + if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 238 | + $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + return $propre($texte); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | function plugin_typo($texte, $module = '') { |
| 245 | - return plugin_propre($texte, $module, 'typo'); |
|
| 245 | + return plugin_propre($texte, $module, 'typo'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
| 249 | 249 | // https://code.spip.net/@affiche_bloc_plugin |
| 250 | 250 | function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) { |
| 251 | - if (!$dir_plugins) { |
|
| 252 | - $dir_plugins = _DIR_PLUGINS; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $prefix = $info['prefix']; |
|
| 256 | - $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 257 | - |
|
| 258 | - $s = ""; |
|
| 259 | - // TODO: le traiter_multi ici n'est pas beau |
|
| 260 | - // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 261 | - // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 262 | - $description = ""; |
|
| 263 | - if (isset($info['description'])) { |
|
| 264 | - $description = plugin_propre($info['description'], $dir); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - if (isset($info['documentation']) |
|
| 268 | - and $lien = $info['documentation'] |
|
| 269 | - ) { |
|
| 270 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 271 | - } |
|
| 272 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 273 | - |
|
| 274 | - if (isset($info['auteur'])) { |
|
| 275 | - if (is_array($info['auteur'])) { |
|
| 276 | - $a = formater_credits($info['auteur'], ', '); |
|
| 277 | - } // pour compat mais ne doit plus arriver |
|
| 278 | - else { |
|
| 279 | - $a = trim($info['auteur']); |
|
| 280 | - } |
|
| 281 | - if ($a) { |
|
| 282 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 283 | - $dir)) . "</dd>\n"; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if (isset($info['credit'])) { |
|
| 288 | - if ($a = formater_credits($info['credit'], ', ')) { |
|
| 289 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 290 | - $dir)) . "</dd>\n"; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (isset($info['licence'])) { |
|
| 295 | - if (is_array($info['licence'])) { |
|
| 296 | - $a = formater_credits($info['licence'], ', '); |
|
| 297 | - } // pour compat mais ne doit plus arriver |
|
| 298 | - else { |
|
| 299 | - $a = trim($info['licence']); |
|
| 300 | - } |
|
| 301 | - if ($a) { |
|
| 302 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 303 | - $dir)) . "</dd>\n"; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $s = "<dl class='description'>$s</dl>"; |
|
| 308 | - |
|
| 309 | - // |
|
| 310 | - // Ajouter les infos techniques |
|
| 311 | - // |
|
| 312 | - $infotech = array(); |
|
| 313 | - |
|
| 314 | - $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 315 | - // Version VCS |
|
| 316 | - if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 317 | - $version .= ' ' . $vcs; |
|
| 318 | - } |
|
| 319 | - $version .= "</dd>"; |
|
| 320 | - $infotech[] = $version; |
|
| 321 | - $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 322 | - // source zip le cas echeant |
|
| 323 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 324 | - and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 325 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 326 | - : ''; |
|
| 327 | - |
|
| 328 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 329 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 330 | - array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 331 | - |
|
| 332 | - $s .= "<dl class='tech'>" |
|
| 333 | - . join('', $infotech) |
|
| 334 | - . "</dl>"; |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - return $s; |
|
| 251 | + if (!$dir_plugins) { |
|
| 252 | + $dir_plugins = _DIR_PLUGINS; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $prefix = $info['prefix']; |
|
| 256 | + $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 257 | + |
|
| 258 | + $s = ""; |
|
| 259 | + // TODO: le traiter_multi ici n'est pas beau |
|
| 260 | + // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 261 | + // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 262 | + $description = ""; |
|
| 263 | + if (isset($info['description'])) { |
|
| 264 | + $description = plugin_propre($info['description'], $dir); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + if (isset($info['documentation']) |
|
| 268 | + and $lien = $info['documentation'] |
|
| 269 | + ) { |
|
| 270 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 271 | + } |
|
| 272 | + $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 273 | + |
|
| 274 | + if (isset($info['auteur'])) { |
|
| 275 | + if (is_array($info['auteur'])) { |
|
| 276 | + $a = formater_credits($info['auteur'], ', '); |
|
| 277 | + } // pour compat mais ne doit plus arriver |
|
| 278 | + else { |
|
| 279 | + $a = trim($info['auteur']); |
|
| 280 | + } |
|
| 281 | + if ($a) { |
|
| 282 | + $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 283 | + $dir)) . "</dd>\n"; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if (isset($info['credit'])) { |
|
| 288 | + if ($a = formater_credits($info['credit'], ', ')) { |
|
| 289 | + $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 290 | + $dir)) . "</dd>\n"; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (isset($info['licence'])) { |
|
| 295 | + if (is_array($info['licence'])) { |
|
| 296 | + $a = formater_credits($info['licence'], ', '); |
|
| 297 | + } // pour compat mais ne doit plus arriver |
|
| 298 | + else { |
|
| 299 | + $a = trim($info['licence']); |
|
| 300 | + } |
|
| 301 | + if ($a) { |
|
| 302 | + $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 303 | + $dir)) . "</dd>\n"; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $s = "<dl class='description'>$s</dl>"; |
|
| 308 | + |
|
| 309 | + // |
|
| 310 | + // Ajouter les infos techniques |
|
| 311 | + // |
|
| 312 | + $infotech = array(); |
|
| 313 | + |
|
| 314 | + $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 315 | + // Version VCS |
|
| 316 | + if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 317 | + $version .= ' ' . $vcs; |
|
| 318 | + } |
|
| 319 | + $version .= "</dd>"; |
|
| 320 | + $infotech[] = $version; |
|
| 321 | + $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 322 | + // source zip le cas echeant |
|
| 323 | + $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 324 | + and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 325 | + ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 326 | + : ''; |
|
| 327 | + |
|
| 328 | + $infotech[] = !$info['necessite'] ? '' : |
|
| 329 | + ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 330 | + array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 331 | + |
|
| 332 | + $s .= "<dl class='tech'>" |
|
| 333 | + . join('', $infotech) |
|
| 334 | + . "</dl>"; |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + return $s; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | function formater_credits($infos, $sep = ', ') { |
| 341 | - $texte = ''; |
|
| 342 | - |
|
| 343 | - foreach ($infos as $_credit) { |
|
| 344 | - if ($texte) { |
|
| 345 | - $texte .= $sep; |
|
| 346 | - } |
|
| 347 | - // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 348 | - $texte .= |
|
| 349 | - (!is_array($_credit)) |
|
| 350 | - ? PtoBR(propre($_credit)) |
|
| 351 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 352 | - $_credit['nom'] . |
|
| 353 | - ($_credit['url'] ? '</a>' : ''); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - return $texte; |
|
| 341 | + $texte = ''; |
|
| 342 | + |
|
| 343 | + foreach ($infos as $_credit) { |
|
| 344 | + if ($texte) { |
|
| 345 | + $texte .= $sep; |
|
| 346 | + } |
|
| 347 | + // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 348 | + $texte .= |
|
| 349 | + (!is_array($_credit)) |
|
| 350 | + ? PtoBR(propre($_credit)) |
|
| 351 | + : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 352 | + $_credit['nom'] . |
|
| 353 | + ($_credit['url'] ? '</a>' : ''); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + return $texte; |
|
| 357 | 357 | } |
@@ -11,126 +11,126 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 18 | - $preaff = $preaff ? "<BB$nom>$preaff" : ""; |
|
| 19 | - $avant = $avant ? "<B$nom>$avant" : ""; |
|
| 20 | - $apres = $apres ? "$apres</B$nom>" : ""; |
|
| 21 | - $altern = $altern ? "$altern<//B$nom>" : ""; |
|
| 22 | - $postaff = $postaff ? "$postaff</BB$nom>" : ""; |
|
| 23 | - if (!$corps) { |
|
| 24 | - $corps = " />"; |
|
| 25 | - } else { |
|
| 26 | - $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 18 | + $preaff = $preaff ? "<BB$nom>$preaff" : ""; |
|
| 19 | + $avant = $avant ? "<B$nom>$avant" : ""; |
|
| 20 | + $apres = $apres ? "$apres</B$nom>" : ""; |
|
| 21 | + $altern = $altern ? "$altern<//B$nom>" : ""; |
|
| 22 | + $postaff = $postaff ? "$postaff</BB$nom>" : ""; |
|
| 23 | + if (!$corps) { |
|
| 24 | + $corps = " />"; |
|
| 25 | + } else { |
|
| 26 | + $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | - if (strpos($file, '#') === false) { |
|
| 34 | - $t = $file ? ("(" . $file . ")") : ""; |
|
| 35 | - } else { |
|
| 36 | - $t = "{fond=" . $file . '}'; |
|
| 37 | - } |
|
| 38 | - $args = !$args ? '' : ("{" . join(", ", $args) . "}"); |
|
| 39 | - |
|
| 40 | - return ("<INCLURE" . $t . $args . ">"); |
|
| 33 | + if (strpos($file, '#') === false) { |
|
| 34 | + $t = $file ? ("(" . $file . ")") : ""; |
|
| 35 | + } else { |
|
| 36 | + $t = "{fond=" . $file . '}'; |
|
| 37 | + } |
|
| 38 | + $args = !$args ? '' : ("{" . join(", ", $args) . "}"); |
|
| 39 | + |
|
| 40 | + return ("<INCLURE" . $t . $args . ">"); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | - $contenu = array(); |
|
| 45 | - foreach ($args as $l => $t) { |
|
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | - } |
|
| 44 | + $contenu = array(); |
|
| 45 | + foreach ($args as $l => $t) { |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return ("<multi>" . join(" ", $contenu) . "</multi>"); |
|
| 49 | + return ("<multi>" . join(" ", $contenu) . "</multi>"); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | - foreach ($args as $k => $v) { |
|
| 54 | - $args[$k] = "$k=$v"; |
|
| 55 | - } |
|
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 53 | + foreach ($args as $k => $v) { |
|
| 54 | + $args[$k] = "$k=$v"; |
|
| 55 | + } |
|
| 56 | + $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 57 | 57 | |
| 58 | - return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>"); |
|
| 58 | + return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>"); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | - $nom = "#" |
|
| 63 | - . ($boucle ? ($boucle . ":") : "") |
|
| 64 | - . $nom |
|
| 65 | - . $etoile |
|
| 66 | - . $args |
|
| 67 | - . $filtres; |
|
| 62 | + $nom = "#" |
|
| 63 | + . ($boucle ? ($boucle . ":") : "") |
|
| 64 | + . $nom |
|
| 65 | + . $etoile |
|
| 66 | + . $args |
|
| 67 | + . $filtres; |
|
| 68 | 68 | |
| 69 | - // Determiner si c'est un champ etendu, |
|
| 69 | + // Determiner si c'est un champ etendu, |
|
| 70 | 70 | |
| 71 | - $s = ($avant or $apres or $filtres |
|
| 72 | - or (strpos($args, '(#') !== false)); |
|
| 71 | + $s = ($avant or $apres or $filtres |
|
| 72 | + or (strpos($args, '(#') !== false)); |
|
| 73 | 73 | |
| 74 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 74 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function format_critere_html($critere) { |
| 78 | - foreach ($critere as $k => $crit) { |
|
| 79 | - $crit_s = ''; |
|
| 80 | - foreach ($crit as $operande) { |
|
| 81 | - list($type, $valeur) = $operande; |
|
| 82 | - if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | - $valeur = substr($valeur, 1, -1); |
|
| 84 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | - $valeur = substr($valeur, 1, -1); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - $crit_s .= $valeur; |
|
| 89 | - } |
|
| 90 | - $critere[$k] = $crit_s; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return (!$critere ? "" : ("{" . join(",", $critere) . "}")); |
|
| 78 | + foreach ($critere as $k => $crit) { |
|
| 79 | + $crit_s = ''; |
|
| 80 | + foreach ($crit as $operande) { |
|
| 81 | + list($type, $valeur) = $operande; |
|
| 82 | + if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | + $valeur = substr($valeur, 1, -1); |
|
| 84 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | + $valeur = substr($valeur, 1, -1); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + $crit_s .= $valeur; |
|
| 89 | + } |
|
| 90 | + $critere[$k] = $crit_s; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return (!$critere ? "" : ("{" . join(",", $critere) . "}")); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | - . (!$args ? "" : ("{" . join(",", $args) . "}"))); |
|
| 97 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | + . (!$args ? "" : ("{" . join(",", $args) . "}"))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 102 | 102 | function format_suite_html($args) { |
| 103 | - for ($i = 0; $i < count($args) - 1; $i++) { |
|
| 104 | - list($texte, $type) = $args[$i]; |
|
| 105 | - list($texte2, $type2) = $args[$i + 1]; |
|
| 106 | - if (!$texte or !$texte2) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - $c1 = substr($texte, -1); |
|
| 110 | - if ($type2 !== 'texte') { |
|
| 111 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | - // ou assimiles, forcer la notation pleine |
|
| 113 | - if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - if ($type == 'texte') { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - // si un champ ou assimiles est suivi d'un texte |
|
| 121 | - // et si celui-ci commence par un caractere de champ |
|
| 122 | - // forcer la notation pleine |
|
| 123 | - if (($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 124 | - or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 125 | - ) { |
|
| 126 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return join("", array_map(function($arg) { return reset($arg); }, $args)); |
|
| 103 | + for ($i = 0; $i < count($args) - 1; $i++) { |
|
| 104 | + list($texte, $type) = $args[$i]; |
|
| 105 | + list($texte2, $type2) = $args[$i + 1]; |
|
| 106 | + if (!$texte or !$texte2) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + $c1 = substr($texte, -1); |
|
| 110 | + if ($type2 !== 'texte') { |
|
| 111 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | + // ou assimiles, forcer la notation pleine |
|
| 113 | + if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + if ($type == 'texte') { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + // si un champ ou assimiles est suivi d'un texte |
|
| 121 | + // et si celui-ci commence par un caractere de champ |
|
| 122 | + // forcer la notation pleine |
|
| 123 | + if (($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 124 | + or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 125 | + ) { |
|
| 126 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return join("", array_map(function($arg) { return reset($arg); }, $args)); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | function format_texte_html($texte) { |
| 135 | - return $texte; |
|
| 135 | + return $texte; |
|
| 136 | 136 | } |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = array( |
|
| 47 | - 'field' => array( |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = array( |
|
| 47 | + 'field' => array( |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,505 +62,505 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** |
|
| 66 | - * tableau de donnees |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - protected $tableau = array(); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Conditions de filtrage |
|
| 74 | - * ie criteres de selection |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $filtre = array(); |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Cle courante |
|
| 83 | - * |
|
| 84 | - * @var null |
|
| 85 | - */ |
|
| 86 | - protected $cle = null; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Valeur courante |
|
| 90 | - * |
|
| 91 | - * @var null |
|
| 92 | - */ |
|
| 93 | - protected $valeur = null; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Erreur presente ? |
|
| 97 | - * |
|
| 98 | - * @var bool |
|
| 99 | - **/ |
|
| 100 | - public $err = false; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Calcul du total des elements |
|
| 104 | - * |
|
| 105 | - * @var int|null |
|
| 106 | - **/ |
|
| 107 | - public $total = null; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Constructeur |
|
| 111 | - * |
|
| 112 | - * @param $command |
|
| 113 | - * @param array $info |
|
| 114 | - */ |
|
| 115 | - public function __construct($command, $info = array()) { |
|
| 116 | - $this->type = 'DATA'; |
|
| 117 | - $this->command = $command; |
|
| 118 | - $this->info = $info; |
|
| 119 | - |
|
| 120 | - $this->select($command); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Revenir au depart |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function rewind() { |
|
| 129 | - reset($this->tableau); |
|
| 130 | - $this->cle = key($this->tableau); |
|
| 131 | - $this->valeur = current($this->tableau); |
|
| 132 | - next($this->tableau); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Déclarer les critères exceptions |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function exception_des_criteres() { |
|
| 141 | - return array('tableau'); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Récupérer depuis le cache si possible |
|
| 146 | - * |
|
| 147 | - * @param string $cle |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - protected function cache_get($cle) { |
|
| 151 | - if (!$cle) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - # utiliser memoization si dispo |
|
| 155 | - if (!function_exists('cache_get')) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return cache_get($cle); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Stocker en cache si possible |
|
| 164 | - * |
|
| 165 | - * @param string $cle |
|
| 166 | - * @param int $ttl |
|
| 167 | - * @param null|mixed $valeur |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | - if (!$cle) { |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - if (is_null($valeur)) { |
|
| 175 | - $valeur = $this->tableau; |
|
| 176 | - } |
|
| 177 | - # utiliser memoization si dispo |
|
| 178 | - if (!function_exists('cache_set')) { |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return cache_set($cle, |
|
| 183 | - array( |
|
| 184 | - 'data' => $valeur, |
|
| 185 | - 'time' => time(), |
|
| 186 | - 'ttl' => $ttl |
|
| 187 | - ), |
|
| 188 | - 3600 + $ttl); |
|
| 189 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Aller chercher les données de la boucle DATA |
|
| 195 | - * |
|
| 196 | - * @throws Exception |
|
| 197 | - * @param array $command |
|
| 198 | - * @return void |
|
| 199 | - */ |
|
| 200 | - protected function select($command) { |
|
| 201 | - |
|
| 202 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | - // le type se retrouve dans la commande 'from' |
|
| 204 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | - if (isset($this->command['from'][0])) { |
|
| 206 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | - } |
|
| 209 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | - // les commandes connues pour l'iterateur DATA |
|
| 214 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | - |
|
| 216 | - // {source format, [URL], [arg2]...} |
|
| 217 | - if (isset($this->command['source']) |
|
| 218 | - and isset($this->command['sourcemode']) |
|
| 219 | - ) { |
|
| 220 | - $this->select_source(); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Critere {liste X1, X2, X3} |
|
| 224 | - if (isset($this->command['liste'])) { |
|
| 225 | - $this->select_liste(); |
|
| 226 | - } |
|
| 227 | - if (isset($this->command['enum'])) { |
|
| 228 | - $this->select_enum(); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | - if (!is_array($this->tableau)) { |
|
| 233 | - $this->err = true; |
|
| 234 | - spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // {datapath query.results} |
|
| 238 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | - if (!$this->err |
|
| 240 | - and isset($this->command['datapath']) |
|
| 241 | - and is_array($this->command['datapath']) |
|
| 242 | - ) { |
|
| 243 | - $this->select_datapath(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // tri {par x} |
|
| 247 | - if ($this->command['orderby']) { |
|
| 248 | - $this->select_orderby(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | - if ($this->command['groupby']) { |
|
| 253 | - $this->select_groupby(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $this->rewind(); |
|
| 257 | - #var_dump($this->tableau); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Aller chercher les donnees de la boucle DATA |
|
| 263 | - * depuis une source |
|
| 264 | - * {source format, [URL], [arg2]...} |
|
| 265 | - */ |
|
| 266 | - protected function select_source() { |
|
| 267 | - # un peu crado : avant de charger le cache il faut charger |
|
| 268 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | - # l'objet en cache ; cf plugins/icalendar |
|
| 270 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | - if (isset($this->command['sourcemode']) |
|
| 272 | - and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | - ) { |
|
| 274 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - # le premier argument peut etre un array, une URL etc. |
|
| 278 | - $src = $this->command['source'][0]; |
|
| 279 | - |
|
| 280 | - # avons-nous un cache dispo ? |
|
| 281 | - $cle = null; |
|
| 282 | - if (is_string($src)) { |
|
| 283 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $cache = $this->cache_get($cle); |
|
| 287 | - if (isset($this->command['datacache'])) { |
|
| 288 | - $ttl = intval($this->command['datacache']); |
|
| 289 | - } |
|
| 290 | - if ($cache |
|
| 291 | - and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | - > time()) |
|
| 293 | - and !(_request('var_mode') === 'recalcul' |
|
| 294 | - and include_spip('inc/autoriser') |
|
| 295 | - and autoriser('recalcul') |
|
| 296 | - ) |
|
| 297 | - ) { |
|
| 298 | - $this->tableau = $cache['data']; |
|
| 299 | - } else { |
|
| 300 | - try { |
|
| 301 | - if (isset($this->command['sourcemode']) |
|
| 302 | - and in_array($this->command['sourcemode'], |
|
| 303 | - array('table', 'array', 'tableau')) |
|
| 304 | - ) { |
|
| 305 | - if (is_array($a = $src) |
|
| 306 | - or (is_string($a) |
|
| 307 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 308 | - and is_array($a = @unserialize($a))) |
|
| 309 | - ) { |
|
| 310 | - $this->tableau = $a; |
|
| 311 | - } |
|
| 312 | - } else { |
|
| 313 | - $data = $src; |
|
| 314 | - if (is_string($src)) { |
|
| 315 | - if (tester_url_absolue($src)) { |
|
| 316 | - include_spip('inc/distant'); |
|
| 317 | - $data = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 318 | - if (!$data) { |
|
| 319 | - throw new Exception("404"); |
|
| 320 | - } |
|
| 321 | - if (!isset($ttl)) { |
|
| 322 | - $ttl = 24 * 3600; |
|
| 323 | - } |
|
| 324 | - } elseif (@is_dir($src)) { |
|
| 325 | - $data = $src; |
|
| 326 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 327 | - $data = spip_file_get_contents($src); |
|
| 328 | - } |
|
| 329 | - if (!isset($ttl)) { |
|
| 330 | - $ttl = 10; |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if (!$this->err |
|
| 335 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 336 | - ) { |
|
| 337 | - $args = $this->command['source']; |
|
| 338 | - $args[0] = $data; |
|
| 339 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 340 | - $this->tableau = $a; |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if (!is_array($this->tableau)) { |
|
| 346 | - $this->err = true; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 350 | - $this->cache_set($cle, $ttl); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - } catch (Exception $e) { |
|
| 354 | - $e = $e->getMessage(); |
|
| 355 | - $err = sprintf("[%s, %s] $e", |
|
| 356 | - $src, |
|
| 357 | - $this->command['sourcemode']); |
|
| 358 | - erreur_squelette(array($err, array())); |
|
| 359 | - $this->err = true; |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 364 | - if ($this->err |
|
| 365 | - and $cache |
|
| 366 | - ) { |
|
| 367 | - $this->tableau = $cache['data']; |
|
| 368 | - $this->err = false; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Retourne un tableau donne depuis un critère liste |
|
| 375 | - * |
|
| 376 | - * Critère `{liste X1, X2, X3}` |
|
| 377 | - * |
|
| 378 | - * @see critere_DATA_liste_dist() |
|
| 379 | - * |
|
| 380 | - **/ |
|
| 381 | - protected function select_liste() { |
|
| 382 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 383 | - if (!isset($this->command['liste'][1])) { |
|
| 384 | - if (!is_array($this->command['liste'][0])) { |
|
| 385 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 386 | - } else { |
|
| 387 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - $this->tableau = $this->command['liste']; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Retourne un tableau donne depuis un critere liste |
|
| 395 | - * Critere {enum Xmin, Xmax} |
|
| 396 | - * |
|
| 397 | - **/ |
|
| 398 | - protected function select_enum() { |
|
| 399 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 400 | - if (!isset($this->command['enum'][1])) { |
|
| 401 | - if (!is_array($this->command['enum'][0])) { |
|
| 402 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 403 | - } else { |
|
| 404 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - if (count($this->command['enum']) >= 3) { |
|
| 408 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 409 | - array_shift($this->command['enum'])); |
|
| 410 | - } else { |
|
| 411 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 412 | - } |
|
| 413 | - $this->tableau = $enum; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 419 | - * {datapath query.results} |
|
| 420 | - * |
|
| 421 | - **/ |
|
| 422 | - protected function select_datapath() { |
|
| 423 | - $base = reset($this->command['datapath']); |
|
| 424 | - if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 425 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 426 | - if (!is_array($this->tableau)) { |
|
| 427 | - $this->tableau = array(); |
|
| 428 | - $this->err = true; |
|
| 429 | - spip_log("datapath '$base' absent"); |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Ordonner les resultats |
|
| 436 | - * {par x} |
|
| 437 | - * |
|
| 438 | - **/ |
|
| 439 | - protected function select_orderby() { |
|
| 440 | - $sortfunc = ''; |
|
| 441 | - $aleas = 0; |
|
| 442 | - foreach ($this->command['orderby'] as $tri) { |
|
| 443 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 444 | - if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 445 | - $r = array_pad($r, 3, null); |
|
| 446 | - |
|
| 447 | - // tri par cle |
|
| 448 | - if ($r[1] == 'cle') { |
|
| 449 | - if (isset($r[2]) and $r[2]) { |
|
| 450 | - krsort($this->tableau); |
|
| 451 | - } else { |
|
| 452 | - ksort($this->tableau); |
|
| 453 | - } |
|
| 454 | - } # {par hasard} |
|
| 455 | - else { |
|
| 456 | - if ($r[1] == 'hasard') { |
|
| 457 | - $k = array_keys($this->tableau); |
|
| 458 | - shuffle($k); |
|
| 459 | - $v = array(); |
|
| 460 | - foreach ($k as $cle) { |
|
| 461 | - $v[$cle] = $this->tableau[$cle]; |
|
| 462 | - } |
|
| 463 | - $this->tableau = $v; |
|
| 464 | - } else { |
|
| 465 | - # {par valeur} |
|
| 466 | - if ($r[1] == 'valeur') { |
|
| 467 | - $tv = '%s'; |
|
| 468 | - } # {par valeur/xx/yy} ?? |
|
| 469 | - else { |
|
| 470 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 471 | - } |
|
| 472 | - $sortfunc .= ' |
|
| 65 | + /** |
|
| 66 | + * tableau de donnees |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $tableau = array(); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Conditions de filtrage |
|
| 74 | + * ie criteres de selection |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $filtre = array(); |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Cle courante |
|
| 83 | + * |
|
| 84 | + * @var null |
|
| 85 | + */ |
|
| 86 | + protected $cle = null; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Valeur courante |
|
| 90 | + * |
|
| 91 | + * @var null |
|
| 92 | + */ |
|
| 93 | + protected $valeur = null; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Erreur presente ? |
|
| 97 | + * |
|
| 98 | + * @var bool |
|
| 99 | + **/ |
|
| 100 | + public $err = false; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Calcul du total des elements |
|
| 104 | + * |
|
| 105 | + * @var int|null |
|
| 106 | + **/ |
|
| 107 | + public $total = null; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Constructeur |
|
| 111 | + * |
|
| 112 | + * @param $command |
|
| 113 | + * @param array $info |
|
| 114 | + */ |
|
| 115 | + public function __construct($command, $info = array()) { |
|
| 116 | + $this->type = 'DATA'; |
|
| 117 | + $this->command = $command; |
|
| 118 | + $this->info = $info; |
|
| 119 | + |
|
| 120 | + $this->select($command); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Revenir au depart |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function rewind() { |
|
| 129 | + reset($this->tableau); |
|
| 130 | + $this->cle = key($this->tableau); |
|
| 131 | + $this->valeur = current($this->tableau); |
|
| 132 | + next($this->tableau); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Déclarer les critères exceptions |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function exception_des_criteres() { |
|
| 141 | + return array('tableau'); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Récupérer depuis le cache si possible |
|
| 146 | + * |
|
| 147 | + * @param string $cle |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + protected function cache_get($cle) { |
|
| 151 | + if (!$cle) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + # utiliser memoization si dispo |
|
| 155 | + if (!function_exists('cache_get')) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return cache_get($cle); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Stocker en cache si possible |
|
| 164 | + * |
|
| 165 | + * @param string $cle |
|
| 166 | + * @param int $ttl |
|
| 167 | + * @param null|mixed $valeur |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | + if (!$cle) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + if (is_null($valeur)) { |
|
| 175 | + $valeur = $this->tableau; |
|
| 176 | + } |
|
| 177 | + # utiliser memoization si dispo |
|
| 178 | + if (!function_exists('cache_set')) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return cache_set($cle, |
|
| 183 | + array( |
|
| 184 | + 'data' => $valeur, |
|
| 185 | + 'time' => time(), |
|
| 186 | + 'ttl' => $ttl |
|
| 187 | + ), |
|
| 188 | + 3600 + $ttl); |
|
| 189 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Aller chercher les données de la boucle DATA |
|
| 195 | + * |
|
| 196 | + * @throws Exception |
|
| 197 | + * @param array $command |
|
| 198 | + * @return void |
|
| 199 | + */ |
|
| 200 | + protected function select($command) { |
|
| 201 | + |
|
| 202 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | + // le type se retrouve dans la commande 'from' |
|
| 204 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | + if (isset($this->command['from'][0])) { |
|
| 206 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | + } |
|
| 209 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | + // les commandes connues pour l'iterateur DATA |
|
| 214 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | + |
|
| 216 | + // {source format, [URL], [arg2]...} |
|
| 217 | + if (isset($this->command['source']) |
|
| 218 | + and isset($this->command['sourcemode']) |
|
| 219 | + ) { |
|
| 220 | + $this->select_source(); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Critere {liste X1, X2, X3} |
|
| 224 | + if (isset($this->command['liste'])) { |
|
| 225 | + $this->select_liste(); |
|
| 226 | + } |
|
| 227 | + if (isset($this->command['enum'])) { |
|
| 228 | + $this->select_enum(); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | + if (!is_array($this->tableau)) { |
|
| 233 | + $this->err = true; |
|
| 234 | + spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // {datapath query.results} |
|
| 238 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | + if (!$this->err |
|
| 240 | + and isset($this->command['datapath']) |
|
| 241 | + and is_array($this->command['datapath']) |
|
| 242 | + ) { |
|
| 243 | + $this->select_datapath(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // tri {par x} |
|
| 247 | + if ($this->command['orderby']) { |
|
| 248 | + $this->select_orderby(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | + if ($this->command['groupby']) { |
|
| 253 | + $this->select_groupby(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $this->rewind(); |
|
| 257 | + #var_dump($this->tableau); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Aller chercher les donnees de la boucle DATA |
|
| 263 | + * depuis une source |
|
| 264 | + * {source format, [URL], [arg2]...} |
|
| 265 | + */ |
|
| 266 | + protected function select_source() { |
|
| 267 | + # un peu crado : avant de charger le cache il faut charger |
|
| 268 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | + # l'objet en cache ; cf plugins/icalendar |
|
| 270 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | + if (isset($this->command['sourcemode']) |
|
| 272 | + and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | + ) { |
|
| 274 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + # le premier argument peut etre un array, une URL etc. |
|
| 278 | + $src = $this->command['source'][0]; |
|
| 279 | + |
|
| 280 | + # avons-nous un cache dispo ? |
|
| 281 | + $cle = null; |
|
| 282 | + if (is_string($src)) { |
|
| 283 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $cache = $this->cache_get($cle); |
|
| 287 | + if (isset($this->command['datacache'])) { |
|
| 288 | + $ttl = intval($this->command['datacache']); |
|
| 289 | + } |
|
| 290 | + if ($cache |
|
| 291 | + and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | + > time()) |
|
| 293 | + and !(_request('var_mode') === 'recalcul' |
|
| 294 | + and include_spip('inc/autoriser') |
|
| 295 | + and autoriser('recalcul') |
|
| 296 | + ) |
|
| 297 | + ) { |
|
| 298 | + $this->tableau = $cache['data']; |
|
| 299 | + } else { |
|
| 300 | + try { |
|
| 301 | + if (isset($this->command['sourcemode']) |
|
| 302 | + and in_array($this->command['sourcemode'], |
|
| 303 | + array('table', 'array', 'tableau')) |
|
| 304 | + ) { |
|
| 305 | + if (is_array($a = $src) |
|
| 306 | + or (is_string($a) |
|
| 307 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 308 | + and is_array($a = @unserialize($a))) |
|
| 309 | + ) { |
|
| 310 | + $this->tableau = $a; |
|
| 311 | + } |
|
| 312 | + } else { |
|
| 313 | + $data = $src; |
|
| 314 | + if (is_string($src)) { |
|
| 315 | + if (tester_url_absolue($src)) { |
|
| 316 | + include_spip('inc/distant'); |
|
| 317 | + $data = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 318 | + if (!$data) { |
|
| 319 | + throw new Exception("404"); |
|
| 320 | + } |
|
| 321 | + if (!isset($ttl)) { |
|
| 322 | + $ttl = 24 * 3600; |
|
| 323 | + } |
|
| 324 | + } elseif (@is_dir($src)) { |
|
| 325 | + $data = $src; |
|
| 326 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 327 | + $data = spip_file_get_contents($src); |
|
| 328 | + } |
|
| 329 | + if (!isset($ttl)) { |
|
| 330 | + $ttl = 10; |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if (!$this->err |
|
| 335 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 336 | + ) { |
|
| 337 | + $args = $this->command['source']; |
|
| 338 | + $args[0] = $data; |
|
| 339 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 340 | + $this->tableau = $a; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if (!is_array($this->tableau)) { |
|
| 346 | + $this->err = true; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 350 | + $this->cache_set($cle, $ttl); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + } catch (Exception $e) { |
|
| 354 | + $e = $e->getMessage(); |
|
| 355 | + $err = sprintf("[%s, %s] $e", |
|
| 356 | + $src, |
|
| 357 | + $this->command['sourcemode']); |
|
| 358 | + erreur_squelette(array($err, array())); |
|
| 359 | + $this->err = true; |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 364 | + if ($this->err |
|
| 365 | + and $cache |
|
| 366 | + ) { |
|
| 367 | + $this->tableau = $cache['data']; |
|
| 368 | + $this->err = false; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Retourne un tableau donne depuis un critère liste |
|
| 375 | + * |
|
| 376 | + * Critère `{liste X1, X2, X3}` |
|
| 377 | + * |
|
| 378 | + * @see critere_DATA_liste_dist() |
|
| 379 | + * |
|
| 380 | + **/ |
|
| 381 | + protected function select_liste() { |
|
| 382 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 383 | + if (!isset($this->command['liste'][1])) { |
|
| 384 | + if (!is_array($this->command['liste'][0])) { |
|
| 385 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 386 | + } else { |
|
| 387 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + $this->tableau = $this->command['liste']; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Retourne un tableau donne depuis un critere liste |
|
| 395 | + * Critere {enum Xmin, Xmax} |
|
| 396 | + * |
|
| 397 | + **/ |
|
| 398 | + protected function select_enum() { |
|
| 399 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 400 | + if (!isset($this->command['enum'][1])) { |
|
| 401 | + if (!is_array($this->command['enum'][0])) { |
|
| 402 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 403 | + } else { |
|
| 404 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + if (count($this->command['enum']) >= 3) { |
|
| 408 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 409 | + array_shift($this->command['enum'])); |
|
| 410 | + } else { |
|
| 411 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 412 | + } |
|
| 413 | + $this->tableau = $enum; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 419 | + * {datapath query.results} |
|
| 420 | + * |
|
| 421 | + **/ |
|
| 422 | + protected function select_datapath() { |
|
| 423 | + $base = reset($this->command['datapath']); |
|
| 424 | + if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 425 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 426 | + if (!is_array($this->tableau)) { |
|
| 427 | + $this->tableau = array(); |
|
| 428 | + $this->err = true; |
|
| 429 | + spip_log("datapath '$base' absent"); |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Ordonner les resultats |
|
| 436 | + * {par x} |
|
| 437 | + * |
|
| 438 | + **/ |
|
| 439 | + protected function select_orderby() { |
|
| 440 | + $sortfunc = ''; |
|
| 441 | + $aleas = 0; |
|
| 442 | + foreach ($this->command['orderby'] as $tri) { |
|
| 443 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 444 | + if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 445 | + $r = array_pad($r, 3, null); |
|
| 446 | + |
|
| 447 | + // tri par cle |
|
| 448 | + if ($r[1] == 'cle') { |
|
| 449 | + if (isset($r[2]) and $r[2]) { |
|
| 450 | + krsort($this->tableau); |
|
| 451 | + } else { |
|
| 452 | + ksort($this->tableau); |
|
| 453 | + } |
|
| 454 | + } # {par hasard} |
|
| 455 | + else { |
|
| 456 | + if ($r[1] == 'hasard') { |
|
| 457 | + $k = array_keys($this->tableau); |
|
| 458 | + shuffle($k); |
|
| 459 | + $v = array(); |
|
| 460 | + foreach ($k as $cle) { |
|
| 461 | + $v[$cle] = $this->tableau[$cle]; |
|
| 462 | + } |
|
| 463 | + $this->tableau = $v; |
|
| 464 | + } else { |
|
| 465 | + # {par valeur} |
|
| 466 | + if ($r[1] == 'valeur') { |
|
| 467 | + $tv = '%s'; |
|
| 468 | + } # {par valeur/xx/yy} ?? |
|
| 469 | + else { |
|
| 470 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 471 | + } |
|
| 472 | + $sortfunc .= ' |
|
| 473 | 473 | $a = ' . sprintf($tv, '$aa') . '; |
| 474 | 474 | $b = ' . sprintf($tv, '$bb') . '; |
| 475 | 475 | if ($a <> $b) |
| 476 | 476 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 477 | - } |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if ($sortfunc) { |
|
| 483 | - $sortfunc .= "\n return 0;"; |
|
| 484 | - uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 485 | - return eval($sortfunc); |
|
| 486 | - }); |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Grouper les resultats |
|
| 493 | - * {fusion /x/y/z} |
|
| 494 | - * |
|
| 495 | - **/ |
|
| 496 | - protected function select_groupby() { |
|
| 497 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 498 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 499 | - $vu = array(); |
|
| 500 | - foreach ($this->tableau as $k => $v) { |
|
| 501 | - $val = table_valeur($v, $fusion); |
|
| 502 | - if (isset($vu[$val])) { |
|
| 503 | - unset($this->tableau[$k]); |
|
| 504 | - } else { |
|
| 505 | - $vu[$val] = true; |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * L'iterateur est-il encore valide ? |
|
| 514 | - * |
|
| 515 | - * @return bool |
|
| 516 | - */ |
|
| 517 | - public function valid() { |
|
| 518 | - return !is_null($this->cle); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Retourner la valeur |
|
| 523 | - * |
|
| 524 | - * @return null |
|
| 525 | - */ |
|
| 526 | - public function current() { |
|
| 527 | - return $this->valeur; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * Retourner la cle |
|
| 532 | - * |
|
| 533 | - * @return null |
|
| 534 | - */ |
|
| 535 | - public function key() { |
|
| 536 | - return $this->cle; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Passer a la valeur suivante |
|
| 541 | - * |
|
| 542 | - * @return void |
|
| 543 | - */ |
|
| 544 | - public function next() { |
|
| 545 | - if ($this->valid()) { |
|
| 546 | - $this->cle = key($this->tableau); |
|
| 547 | - $this->valeur = current($this->tableau); |
|
| 548 | - next($this->tableau); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Compter le nombre total de resultats |
|
| 554 | - * |
|
| 555 | - * @return int |
|
| 556 | - */ |
|
| 557 | - public function count() { |
|
| 558 | - if (is_null($this->total)) { |
|
| 559 | - $this->total = count($this->tableau); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return $this->total; |
|
| 563 | - } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if ($sortfunc) { |
|
| 483 | + $sortfunc .= "\n return 0;"; |
|
| 484 | + uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 485 | + return eval($sortfunc); |
|
| 486 | + }); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Grouper les resultats |
|
| 493 | + * {fusion /x/y/z} |
|
| 494 | + * |
|
| 495 | + **/ |
|
| 496 | + protected function select_groupby() { |
|
| 497 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 498 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 499 | + $vu = array(); |
|
| 500 | + foreach ($this->tableau as $k => $v) { |
|
| 501 | + $val = table_valeur($v, $fusion); |
|
| 502 | + if (isset($vu[$val])) { |
|
| 503 | + unset($this->tableau[$k]); |
|
| 504 | + } else { |
|
| 505 | + $vu[$val] = true; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * L'iterateur est-il encore valide ? |
|
| 514 | + * |
|
| 515 | + * @return bool |
|
| 516 | + */ |
|
| 517 | + public function valid() { |
|
| 518 | + return !is_null($this->cle); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Retourner la valeur |
|
| 523 | + * |
|
| 524 | + * @return null |
|
| 525 | + */ |
|
| 526 | + public function current() { |
|
| 527 | + return $this->valeur; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * Retourner la cle |
|
| 532 | + * |
|
| 533 | + * @return null |
|
| 534 | + */ |
|
| 535 | + public function key() { |
|
| 536 | + return $this->cle; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Passer a la valeur suivante |
|
| 541 | + * |
|
| 542 | + * @return void |
|
| 543 | + */ |
|
| 544 | + public function next() { |
|
| 545 | + if ($this->valid()) { |
|
| 546 | + $this->cle = key($this->tableau); |
|
| 547 | + $this->valeur = current($this->tableau); |
|
| 548 | + next($this->tableau); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Compter le nombre total de resultats |
|
| 554 | + * |
|
| 555 | + * @return int |
|
| 556 | + */ |
|
| 557 | + public function count() { |
|
| 558 | + if (is_null($this->total)) { |
|
| 559 | + $this->total = count($this->tableau); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return $this->total; |
|
| 563 | + } |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /* |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @return array |
| 575 | 575 | */ |
| 576 | 576 | function inc_file_to_array_dist($data) { |
| 577 | - return preg_split('/\r?\n/', $data); |
|
| 577 | + return preg_split('/\r?\n/', $data); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -583,9 +583,9 @@ discard block |
||
| 583 | 583 | * @return array |
| 584 | 584 | */ |
| 585 | 585 | function inc_plugins_to_array_dist() { |
| 586 | - include_spip('inc/plugin'); |
|
| 586 | + include_spip('inc/plugin'); |
|
| 587 | 587 | |
| 588 | - return liste_chemin_plugin_actifs(); |
|
| 588 | + return liste_chemin_plugin_actifs(); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | * @return array |
| 596 | 596 | */ |
| 597 | 597 | function inc_xml_to_array_dist($data) { |
| 598 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 598 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -607,14 +607,14 @@ discard block |
||
| 607 | 607 | * |
| 608 | 608 | */ |
| 609 | 609 | function inc_object_to_array($object) { |
| 610 | - if (!is_object($object) && !is_array($object)) { |
|
| 611 | - return $object; |
|
| 612 | - } |
|
| 613 | - if (is_object($object)) { |
|
| 614 | - $object = get_object_vars($object); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return array_map('inc_object_to_array', $object); |
|
| 610 | + if (!is_object($object) && !is_array($object)) { |
|
| 611 | + return $object; |
|
| 612 | + } |
|
| 613 | + if (is_object($object)) { |
|
| 614 | + $object = get_object_vars($object); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return array_map('inc_object_to_array', $object); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -624,20 +624,20 @@ discard block |
||
| 624 | 624 | * @return array|bool |
| 625 | 625 | */ |
| 626 | 626 | function inc_sql_to_array_dist($data) { |
| 627 | - # sortir le connecteur de $data |
|
| 628 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 629 | - $serveur = (string)$v[1]; |
|
| 630 | - $req = trim($v[2]); |
|
| 631 | - if ($s = sql_query($req, $serveur)) { |
|
| 632 | - $r = array(); |
|
| 633 | - while ($t = sql_fetch($s)) { |
|
| 634 | - $r[] = $t; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - return $r; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - return false; |
|
| 627 | + # sortir le connecteur de $data |
|
| 628 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 629 | + $serveur = (string)$v[1]; |
|
| 630 | + $req = trim($v[2]); |
|
| 631 | + if ($s = sql_query($req, $serveur)) { |
|
| 632 | + $r = array(); |
|
| 633 | + while ($t = sql_fetch($s)) { |
|
| 634 | + $r[] = $t; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + return $r; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + return false; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** |
@@ -647,9 +647,9 @@ discard block |
||
| 647 | 647 | * @return array|bool |
| 648 | 648 | */ |
| 649 | 649 | function inc_json_to_array_dist($data) { |
| 650 | - if (is_array($json = json_decode($data, true))) { |
|
| 651 | - return (array)$json; |
|
| 652 | - } |
|
| 650 | + if (is_array($json = json_decode($data, true))) { |
|
| 651 | + return (array)$json; |
|
| 652 | + } |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
@@ -659,30 +659,30 @@ discard block |
||
| 659 | 659 | * @return array|bool |
| 660 | 660 | */ |
| 661 | 661 | function inc_csv_to_array_dist($data) { |
| 662 | - include_spip('inc/csv'); |
|
| 663 | - list($entete, $csv) = analyse_csv($data); |
|
| 664 | - array_unshift($csv, $entete); |
|
| 665 | - |
|
| 666 | - include_spip('inc/charsets'); |
|
| 667 | - $i = 1; |
|
| 668 | - foreach ($entete as $k => $v) { |
|
| 669 | - if (trim($v) == "") { |
|
| 670 | - $v = "col" . $i; |
|
| 671 | - } // reperer des eventuelles cases vides |
|
| 672 | - if (is_numeric($v) and $v < 0) { |
|
| 673 | - $v = "__" . $v; |
|
| 674 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 675 | - if (is_numeric($v)) { |
|
| 676 | - $v = "_" . $v; |
|
| 677 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 678 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 679 | - foreach ($csv as &$item) { |
|
| 680 | - $item[$v] = &$item[$k]; |
|
| 681 | - } |
|
| 682 | - $i++; |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return $csv; |
|
| 662 | + include_spip('inc/csv'); |
|
| 663 | + list($entete, $csv) = analyse_csv($data); |
|
| 664 | + array_unshift($csv, $entete); |
|
| 665 | + |
|
| 666 | + include_spip('inc/charsets'); |
|
| 667 | + $i = 1; |
|
| 668 | + foreach ($entete as $k => $v) { |
|
| 669 | + if (trim($v) == "") { |
|
| 670 | + $v = "col" . $i; |
|
| 671 | + } // reperer des eventuelles cases vides |
|
| 672 | + if (is_numeric($v) and $v < 0) { |
|
| 673 | + $v = "__" . $v; |
|
| 674 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 675 | + if (is_numeric($v)) { |
|
| 676 | + $v = "_" . $v; |
|
| 677 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 678 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 679 | + foreach ($csv as &$item) { |
|
| 680 | + $item[$v] = &$item[$k]; |
|
| 681 | + } |
|
| 682 | + $i++; |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return $csv; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | /** |
@@ -692,12 +692,12 @@ discard block |
||
| 692 | 692 | * @return array|bool |
| 693 | 693 | */ |
| 694 | 694 | function inc_rss_to_array_dist($data) { |
| 695 | - include_spip('inc/syndic'); |
|
| 696 | - if (is_array($rss = analyser_backend($data))) { |
|
| 697 | - $tableau = $rss; |
|
| 698 | - } |
|
| 695 | + include_spip('inc/syndic'); |
|
| 696 | + if (is_array($rss = analyser_backend($data))) { |
|
| 697 | + $tableau = $rss; |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | - return $tableau; |
|
| 700 | + return $tableau; |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | /** |
@@ -707,9 +707,9 @@ discard block |
||
| 707 | 707 | * @return array|bool |
| 708 | 708 | */ |
| 709 | 709 | function inc_atom_to_array_dist($data) { |
| 710 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 710 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 711 | 711 | |
| 712 | - return $rss_to_array($data); |
|
| 712 | + return $rss_to_array($data); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /** |
@@ -720,11 +720,11 @@ discard block |
||
| 720 | 720 | * @return array|bool |
| 721 | 721 | */ |
| 722 | 722 | function inc_glob_to_array_dist($data) { |
| 723 | - $a = glob($data, |
|
| 724 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 725 | - ); |
|
| 723 | + $a = glob($data, |
|
| 724 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 725 | + ); |
|
| 726 | 726 | |
| 727 | - return $a ? $a : array(); |
|
| 727 | + return $a ? $a : array(); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -735,14 +735,14 @@ discard block |
||
| 735 | 735 | * @throws Exception |
| 736 | 736 | */ |
| 737 | 737 | function inc_yaml_to_array_dist($data) { |
| 738 | - include_spip('inc/yaml-mini'); |
|
| 739 | - if (!function_exists("yaml_decode")) { |
|
| 740 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 738 | + include_spip('inc/yaml-mini'); |
|
| 739 | + if (!function_exists("yaml_decode")) { |
|
| 740 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 741 | 741 | |
| 742 | - return false; |
|
| 743 | - } |
|
| 742 | + return false; |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | - return yaml_decode($data); |
|
| 745 | + return yaml_decode($data); |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * @return array|bool |
| 758 | 758 | */ |
| 759 | 759 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 760 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 760 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -769,23 +769,23 @@ discard block |
||
| 769 | 769 | * @return array|bool |
| 770 | 770 | */ |
| 771 | 771 | function inc_ls_to_array_dist($data) { |
| 772 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 773 | - $a = $glob_to_array($data); |
|
| 774 | - foreach ($a as &$v) { |
|
| 775 | - $b = (array)@stat($v); |
|
| 776 | - foreach ($b as $k => $ignore) { |
|
| 777 | - if (is_numeric($k)) { |
|
| 778 | - unset($b[$k]); |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 782 | - $v = array_merge( |
|
| 783 | - pathinfo($v), |
|
| 784 | - $b |
|
| 785 | - ); |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - return $a; |
|
| 772 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 773 | + $a = $glob_to_array($data); |
|
| 774 | + foreach ($a as &$v) { |
|
| 775 | + $b = (array)@stat($v); |
|
| 776 | + foreach ($b as $k => $ignore) { |
|
| 777 | + if (is_numeric($k)) { |
|
| 778 | + unset($b[$k]); |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 782 | + $v = array_merge( |
|
| 783 | + pathinfo($v), |
|
| 784 | + $b |
|
| 785 | + ); |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + return $a; |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -795,24 +795,24 @@ discard block |
||
| 795 | 795 | * @return array|bool |
| 796 | 796 | */ |
| 797 | 797 | function XMLObjectToArray($object) { |
| 798 | - $xml_array = array(); |
|
| 799 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 800 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 801 | - $key .= '-' . uniqid(); |
|
| 802 | - } |
|
| 803 | - $vars = get_object_vars($object->current()); |
|
| 804 | - if (isset($vars['@attributes'])) { |
|
| 805 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 806 | - $xml_array[$key][$k] = $v; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - if ($object->hasChildren()) { |
|
| 810 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 811 | - $object->current()); |
|
| 812 | - } else { |
|
| 813 | - $xml_array[$key][] = strval($object->current()); |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - return $xml_array; |
|
| 798 | + $xml_array = array(); |
|
| 799 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 800 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 801 | + $key .= '-' . uniqid(); |
|
| 802 | + } |
|
| 803 | + $vars = get_object_vars($object->current()); |
|
| 804 | + if (isset($vars['@attributes'])) { |
|
| 805 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 806 | + $xml_array[$key][$k] = $v; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + if ($object->hasChildren()) { |
|
| 810 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 811 | + $object->current()); |
|
| 812 | + } else { |
|
| 813 | + $xml_array[$key][] = strval($object->current()); |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + return $xml_array; |
|
| 818 | 818 | } |