Valider c2fa8db3 rédigé par cedric@yterium.com's avatar cedric@yterium.com
Parcourir les fichiers

Une action pour renseigner les paquet d'un plugin, interrogeable par ?lien_doc= ou ?prefixe= :

http://plugins.spip.net/infos_plugin.api/?lien_doc=http://www.spip-contrib.net/Polyhierarchie

Renvoie un tableau json renseignant les paquet dispos pour chaque version 2.x ou 3.x de SPIP
parent f7d37cf6
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours
+1 −0
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
* text=auto !eol
action/api_infos_plugin.php -text
/aide.html -text
/aide_fonctions.php -text
/backend-paquets.html -text
+65 −0
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
<?php
/**
 * Infos plugin
 * Licence GPL3
 *
 */

if (!defined('_ECRIRE_INC_VERSION')) return;

function action_api_infos_plugin_dist(){

	$where = array();

	if ($l = _request('lien_doc'))
		$where = "lien_doc=" . sql_quote($l);

	if ($p = _request('prefixe'))
		$where = "prefixe=" . sql_quote($p);

	include_spip("inc/plugin");
	$vtarget = array('2.0', '2.1', '3.0', '3.1');
	$res = array();
	if (count($where)){
		$paquets = sql_allfetsel('*', 'spip_paquets', $where, '', 'version DESC');
		foreach ($paquets as $paquet){
			$prefixe = $paquet['prefixe'];
			foreach ($vtarget as $v){
				$vindex = "SPIP-$v";
				if (!isset($res['plugins'][$prefixe][$vindex])
					OR !$res['plugins'][$prefixe][$vindex]
				){
					if (
					     plugin_version_compatible($paquet['compatibilite_spip'],"$v.0")
					  OR plugin_version_compatible($paquet['compatibilite_spip'],"$v.90")
					){
						$pv = explode('.',$paquet['version']);
						$pv = array_map('intval',$pv);
						$pv = implode('.',$pv);
						$res['plugins'][$prefixe][$vindex] = array(
							'version' => $pv,
							'lien_doc' => $paquet['lien_doc'],
							'logo' => $paquet['logo'],
							'archive' => dirname($paquet['logo']).'/'.$paquet['nom_archive'],
							'date' => $paquet['maj_archive'],
						);
					}
					else
						$res['plugins'][$prefixe][$vindex] = false;
				}
			}
		}

	}
	if (!$res){
		include_spip('inc/headers');
		http_status(404);
		echo "404 Not Found";
	}
	else {
		$res = json_encode($res);
		$content_type = "application/json";
		header("Content-type: $content_type; charest=utf-8");
		echo $res;
	}
}