@@ -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 | /** |
@@ -33,109 +33,109 @@ discard block |
||
| 33 | 33 | * @return array |
| 34 | 34 | */ |
| 35 | 35 | function plugins_get_infos_dist($plug = false, $reload = false, $dir = _DIR_PLUGINS, $clean_old = false) { |
| 36 | - static $cache = ''; |
|
| 37 | - static $filecache = ''; |
|
| 38 | - |
|
| 39 | - if ($cache === '') { |
|
| 40 | - $filecache = _DIR_TMP . "plugin_xml_cache.gz"; |
|
| 41 | - if (is_file($filecache)) { |
|
| 42 | - lire_fichier($filecache, $contenu); |
|
| 43 | - $cache = unserialize($contenu); |
|
| 44 | - } |
|
| 45 | - if (!is_array($cache)) { |
|
| 46 | - $cache = array(); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') { |
|
| 51 | - $reload = true; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($plug === false) { |
|
| 55 | - ecrire_fichier($filecache, serialize($cache)); |
|
| 56 | - |
|
| 57 | - return $cache; |
|
| 58 | - } elseif (is_string($plug)) { |
|
| 59 | - $res = plugins_get_infos_un($plug, $reload, $dir, $cache); |
|
| 60 | - } elseif (is_array($plug)) { |
|
| 61 | - $res = false; |
|
| 62 | - if (!$reload) { |
|
| 63 | - $reload = -1; |
|
| 64 | - } |
|
| 65 | - foreach ($plug as $nom) { |
|
| 66 | - $res |= plugins_get_infos_un($nom, $reload, $dir, $cache); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - // Nettoyer le cache des vieux plugins qui ne sont plus la |
|
| 70 | - if ($clean_old and isset($cache[$dir]) and count($cache[$dir])) { |
|
| 71 | - foreach (array_keys($cache[$dir]) as $p) { |
|
| 72 | - if (!in_array($p, $plug)) { |
|
| 73 | - unset($cache[$dir][$p]); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - if ($res) { |
|
| 79 | - ecrire_fichier($filecache, serialize($cache)); |
|
| 80 | - } |
|
| 81 | - if (!isset($cache[$dir])) { |
|
| 82 | - return array(); |
|
| 83 | - } |
|
| 84 | - if (is_string($plug)) { |
|
| 85 | - return isset($cache[$dir][$plug]) ? $cache[$dir][$plug] : array(); |
|
| 86 | - } else { |
|
| 87 | - return $cache[$dir]; |
|
| 88 | - } |
|
| 36 | + static $cache = ''; |
|
| 37 | + static $filecache = ''; |
|
| 38 | + |
|
| 39 | + if ($cache === '') { |
|
| 40 | + $filecache = _DIR_TMP . "plugin_xml_cache.gz"; |
|
| 41 | + if (is_file($filecache)) { |
|
| 42 | + lire_fichier($filecache, $contenu); |
|
| 43 | + $cache = unserialize($contenu); |
|
| 44 | + } |
|
| 45 | + if (!is_array($cache)) { |
|
| 46 | + $cache = array(); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') { |
|
| 51 | + $reload = true; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($plug === false) { |
|
| 55 | + ecrire_fichier($filecache, serialize($cache)); |
|
| 56 | + |
|
| 57 | + return $cache; |
|
| 58 | + } elseif (is_string($plug)) { |
|
| 59 | + $res = plugins_get_infos_un($plug, $reload, $dir, $cache); |
|
| 60 | + } elseif (is_array($plug)) { |
|
| 61 | + $res = false; |
|
| 62 | + if (!$reload) { |
|
| 63 | + $reload = -1; |
|
| 64 | + } |
|
| 65 | + foreach ($plug as $nom) { |
|
| 66 | + $res |= plugins_get_infos_un($nom, $reload, $dir, $cache); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + // Nettoyer le cache des vieux plugins qui ne sont plus la |
|
| 70 | + if ($clean_old and isset($cache[$dir]) and count($cache[$dir])) { |
|
| 71 | + foreach (array_keys($cache[$dir]) as $p) { |
|
| 72 | + if (!in_array($p, $plug)) { |
|
| 73 | + unset($cache[$dir][$p]); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + if ($res) { |
|
| 79 | + ecrire_fichier($filecache, serialize($cache)); |
|
| 80 | + } |
|
| 81 | + if (!isset($cache[$dir])) { |
|
| 82 | + return array(); |
|
| 83 | + } |
|
| 84 | + if (is_string($plug)) { |
|
| 85 | + return isset($cache[$dir][$plug]) ? $cache[$dir][$plug] : array(); |
|
| 86 | + } else { |
|
| 87 | + return $cache[$dir]; |
|
| 88 | + } |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | function plugins_get_infos_un($plug, $reload, $dir, &$cache) { |
| 93 | - if (!is_readable($file = "$dir$plug/paquet.xml")) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - $time = intval(@filemtime($file)); |
|
| 97 | - if ($time < 0) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - $md5 = md5_file($file); |
|
| 101 | - |
|
| 102 | - $pcache = isset($cache[$dir][$plug]) |
|
| 103 | - ? $cache[$dir][$plug] |
|
| 104 | - : array('filemtime' => 0, 'md5_file' => ''); |
|
| 105 | - |
|
| 106 | - // si le cache est valide |
|
| 107 | - if ((intval($reload) <= 0) |
|
| 108 | - and ($time > 0) |
|
| 109 | - and ($time <= $pcache['filemtime']) |
|
| 110 | - and $md5 == $pcache['md5_file'] |
|
| 111 | - ) { |
|
| 112 | - return false; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // si on arrive pas a lire le fichier, se contenter du cache |
|
| 116 | - if (!($texte = spip_file_get_contents($file))) { |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $f = charger_fonction('infos_paquet', 'plugins'); |
|
| 121 | - $ret = $f($texte, $plug, $dir); |
|
| 122 | - $ret['filemtime'] = $time; |
|
| 123 | - $ret['md5_file'] = $md5; |
|
| 124 | - // Si on lit le paquet.xml de SPIP, on rajoute un procure php afin que les plugins puissent |
|
| 125 | - // utiliser un necessite php. SPIP procure donc la version php courante du serveur. |
|
| 126 | - // chaque librairie php est aussi procurée, par exemple 'php:curl'. |
|
| 127 | - if (isset($ret['prefix']) and $ret['prefix'] == 'spip') { |
|
| 128 | - $ret['procure']['php'] = array('nom' => 'php', 'version' => phpversion()); |
|
| 129 | - foreach (get_loaded_extensions() as $ext) { |
|
| 130 | - $ret['procure']['php:' . $ext] = array('nom' => 'php:' . $ext, 'version' => phpversion($ext)); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - $diff = ($ret != $pcache); |
|
| 134 | - |
|
| 135 | - if ($diff) { |
|
| 136 | - $cache[$dir][$plug] = $ret; |
|
| 93 | + if (!is_readable($file = "$dir$plug/paquet.xml")) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + $time = intval(@filemtime($file)); |
|
| 97 | + if ($time < 0) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + $md5 = md5_file($file); |
|
| 101 | + |
|
| 102 | + $pcache = isset($cache[$dir][$plug]) |
|
| 103 | + ? $cache[$dir][$plug] |
|
| 104 | + : array('filemtime' => 0, 'md5_file' => ''); |
|
| 105 | + |
|
| 106 | + // si le cache est valide |
|
| 107 | + if ((intval($reload) <= 0) |
|
| 108 | + and ($time > 0) |
|
| 109 | + and ($time <= $pcache['filemtime']) |
|
| 110 | + and $md5 == $pcache['md5_file'] |
|
| 111 | + ) { |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // si on arrive pas a lire le fichier, se contenter du cache |
|
| 116 | + if (!($texte = spip_file_get_contents($file))) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $f = charger_fonction('infos_paquet', 'plugins'); |
|
| 121 | + $ret = $f($texte, $plug, $dir); |
|
| 122 | + $ret['filemtime'] = $time; |
|
| 123 | + $ret['md5_file'] = $md5; |
|
| 124 | + // Si on lit le paquet.xml de SPIP, on rajoute un procure php afin que les plugins puissent |
|
| 125 | + // utiliser un necessite php. SPIP procure donc la version php courante du serveur. |
|
| 126 | + // chaque librairie php est aussi procurée, par exemple 'php:curl'. |
|
| 127 | + if (isset($ret['prefix']) and $ret['prefix'] == 'spip') { |
|
| 128 | + $ret['procure']['php'] = array('nom' => 'php', 'version' => phpversion()); |
|
| 129 | + foreach (get_loaded_extensions() as $ext) { |
|
| 130 | + $ret['procure']['php:' . $ext] = array('nom' => 'php:' . $ext, 'version' => phpversion($ext)); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + $diff = ($ret != $pcache); |
|
| 134 | + |
|
| 135 | + if ($diff) { |
|
| 136 | + $cache[$dir][$plug] = $ret; |
|
| 137 | 137 | # echo count($cache[$dir]), $dir,$plug, " $reloadc<br>"; |
| 138 | - } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - return $diff; |
|
| 140 | + return $diff; |
|
| 141 | 141 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | static $filecache = ''; |
| 38 | 38 | |
| 39 | 39 | if ($cache === '') { |
| 40 | - $filecache = _DIR_TMP . "plugin_xml_cache.gz"; |
|
| 40 | + $filecache = _DIR_TMP."plugin_xml_cache.gz"; |
|
| 41 | 41 | if (is_file($filecache)) { |
| 42 | 42 | lire_fichier($filecache, $contenu); |
| 43 | 43 | $cache = unserialize($contenu); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | if (isset($ret['prefix']) and $ret['prefix'] == 'spip') { |
| 128 | 128 | $ret['procure']['php'] = array('nom' => 'php', 'version' => phpversion()); |
| 129 | 129 | foreach (get_loaded_extensions() as $ext) { |
| 130 | - $ret['procure']['php:' . $ext] = array('nom' => 'php:' . $ext, 'version' => phpversion($ext)); |
|
| 130 | + $ret['procure']['php:'.$ext] = array('nom' => 'php:'.$ext, 'version' => phpversion($ext)); |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | $diff = ($ret != $pcache); |