Maintenant, si le fichier wheel ne possède pas d'extension, on cherche le fichier en lui ajoutant l'extension json ou yaml dans l'ordre choisi par la constante _WHEELS_FORMAT_DEFAUT.

Pour spip on positionne le défaut à json de façon à se passer de la librairie YAML.
Les plugins qui utilisent encore le YAML peuvent toujours fonctionner mais doivent nécessiter le plugin YAML en plus de Textwheel.
pull/4837/head
Eric Lupinacci 2 years ago committed by Gitea
parent 18b2b7ce58
commit cb6f209a6c

@ -24,8 +24,8 @@ if (!defined('_ECRIRE_INC_VERSION')) {
// Pour choisir le JSON ou le YAML
if (!defined('_WHEELS_FORMAT')) {
define('_WHEELS_FORMAT', 'json');
if (!defined('_WHEELS_FORMAT_DEFAUT')) {
define('_WHEELS_FORMAT_DEFAUT', 'json');
}
require_once dirname(__FILE__) . "/textwheelrule.php";
@ -74,30 +74,35 @@ abstract class TextWheelDataSet {
* @return array
*/
protected function loadFile(&$file, $default_path = '') {
// On détermine si le JSON ou le YAML est fourni pour la wheel sachant que le JSON est prioritaire
if (!preg_match(',[.](yaml|json)$,i', $file, $matches)) {
// Le fichier est fourni sans son extension, on essaie avec le json puis le yaml sinon.
$file = $file . '.json';
$format = 'json';
if (!$file = $this->findFile($file, $default_path)) {
$file = $file . '.yaml';
$format = 'yaml';
if (!$file = $this->findFile($file, $default_path)) {
return array();
$formats = (_WHEELS_FORMAT_DEFAUT === 'json') ? array('json', 'yaml') : array('yaml', 'json');
$name = $file;
foreach ($formats as $format) {
$file = $name . '.' . $format;
if ($file = $this->findFile($file, $default_path)) {
break;
}
}
} else {
$format = $matches[1];
if (!$file = $this->findFile($file, $default_path)) {
return array();
}
}
if (
!$file
or (!$file = $this->findFile($file, $default_path))
) {
return array();
}
defined('_YAML_EVAL_PHP') || define('_YAML_EVAL_PHP', false);
if ($format == 'json') {
$dataset = json_decode(file_get_contents($file), true);
} elseif (defined('_DIR_PLUGIN_YAML')) {
include_spip('inc/yaml');
$dataset = yaml_decode(file_get_contents($file));
} else {
$dataset = defined(_DIR_PLUGIN_YAML) ? yaml_decode(file_get_contents($file)) : array();
$dataset = array();
}
if (is_null($dataset)) {

@ -22,11 +22,6 @@ if (!defined('_WHEELS_VERSION')) {
define('_WHEELS_VERSION', 68672);
}
// Pour choisir le JSON ou le YAML
if (!defined('_WHEELS_FILE_EXTENSION')) {
define('_WHEELS_FILE_EXTENSION', '.' . _WHEELS_FORMAT);
}
//
// Definition des principales wheels de SPIP
//

Loading…
Cancel
Save