|
|
|
@ -24,40 +24,40 @@ if (!defined('_ECRIRE_INC_VERSION')) {
|
|
|
|
|
* - sous la forme d'une valeur simple si l'information demandée est unique (chaine) |
|
|
|
|
* - sous la forme d'un tableau associatif indexé par le nom du champ sinon. |
|
|
|
|
*/ |
|
|
|
|
function type_plugin_lire($typologie, $type_plugin, $informations = array()) { |
|
|
|
|
static $description_type = array(); |
|
|
|
|
static $configurations = array(); |
|
|
|
|
function type_plugin_lire($typologie, $type_plugin, $informations = []) { |
|
|
|
|
static $description_type = []; |
|
|
|
|
static $configurations = []; |
|
|
|
|
|
|
|
|
|
if (!isset($description_type[$typologie][$type_plugin])) { |
|
|
|
|
// Déterminer les informations du groupe typologique si il n'est pas encore stocké. |
|
|
|
|
if (!isset($configurations[$typologie])) { |
|
|
|
|
include_spip('inc/config'); |
|
|
|
|
$configurations[$typologie] = lire_config("svptype/typologies/${typologie}", array()); |
|
|
|
|
$configurations[$typologie] = lire_config("svptype/typologies/{$typologie}", []); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Chargement de la description nécessaire du type de plugin en base de données. |
|
|
|
|
// -- seules l'id, l'id_parent, la profondeur, l'identifiant typologique, le titre et le descriptif sont utiles. |
|
|
|
|
$champs_type_plugin = array('id_mot', 'id_parent', 'identifiant', 'profondeur', 'titre', 'descriptif'); |
|
|
|
|
$champs_type_plugin = ['id_mot', 'id_parent', 'identifiant', 'profondeur', 'titre', 'descriptif']; |
|
|
|
|
// -- on construit la condition soit sur l'id_mot soit sur l'identifiant en fonction de ce qui est passé |
|
|
|
|
// dans le paramètre $type_plugin. |
|
|
|
|
if ($id_mot = intval($type_plugin)) { |
|
|
|
|
$where = array( |
|
|
|
|
if ($id_mot = (int) $type_plugin) { |
|
|
|
|
$where = [ |
|
|
|
|
'id_mot=' . $id_mot, |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
} else { |
|
|
|
|
$where = array( |
|
|
|
|
'id_groupe=' . intval($configurations[$typologie]['id_groupe']), |
|
|
|
|
$where = [ |
|
|
|
|
'id_groupe=' . (int) ($configurations[$typologie]['id_groupe']), |
|
|
|
|
'identifiant=' . sql_quote($type_plugin) |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
$description = sql_fetsel($champs_type_plugin, 'spip_mots', $where); |
|
|
|
|
|
|
|
|
|
// Sauvegarde de la description de la page pour une consultation ultérieure dans le même hit. |
|
|
|
|
if ($description) { |
|
|
|
|
// Traitements des champs entiers id et profondeur |
|
|
|
|
$description['id_mot'] = intval($description['id_mot']); |
|
|
|
|
$description['id_parent'] = intval($description['id_parent']); |
|
|
|
|
$description['profondeur'] = intval($description['profondeur']); |
|
|
|
|
$description['id_mot'] = (int) ($description['id_mot']); |
|
|
|
|
$description['id_parent'] = (int) ($description['id_parent']); |
|
|
|
|
$description['profondeur'] = (int) ($description['profondeur']); |
|
|
|
|
|
|
|
|
|
// Stockage de la description |
|
|
|
|
$description_type[$typologie][$type_plugin] = $description; |
|
|
|
@ -69,7 +69,10 @@ function type_plugin_lire($typologie, $type_plugin, $informations = array()) {
|
|
|
|
|
|
|
|
|
|
// On ne retourne que les champs demandés |
|
|
|
|
$type_plugin_lu = $description_type[$typologie][$type_plugin]; |
|
|
|
|
if ($type_plugin_lu and $informations) { |
|
|
|
|
if ( |
|
|
|
|
$type_plugin_lu |
|
|
|
|
and $informations |
|
|
|
|
) { |
|
|
|
|
// Extraction des seules informations demandées. |
|
|
|
|
// -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
|
|
|
// -- si une information n'est pas un champ valide elle n'est pas renvoyée sans monter d'erreur. |
|
|
|
@ -100,36 +103,35 @@ function type_plugin_lire($typologie, $type_plugin, $informations = array()) {
|
|
|
|
|
* |
|
|
|
|
* @api |
|
|
|
|
* |
|
|
|
|
* @param string $typologie Typologie concernée : categorie, tag... |
|
|
|
|
* @param array $filtres Liste des couples (champ, valeur) ou tableau vide. |
|
|
|
|
* @param string|array $informations Identifiant d'un champ ou de plusieurs champs de la description d'un type de plugin. |
|
|
|
|
* Si l'argument est vide, la fonction renvoie les descriptions complètes. |
|
|
|
|
* @param string $typologie Typologie concernée : categorie, tag... |
|
|
|
|
* @param array $filtres Liste des couples (champ, valeur) ou tableau vide. |
|
|
|
|
* @param array|string $informations Identifiant d'un champ ou de plusieurs champs de la description d'un type de plugin. |
|
|
|
|
* Si l'argument est vide, la fonction renvoie les descriptions complètes. |
|
|
|
|
* |
|
|
|
|
* @return array Description complète ou information précise pour chaque type de plugin de la typologie concernée. |
|
|
|
|
*/ |
|
|
|
|
function type_plugin_repertorier($typologie, $filtres = array(), $informations = array()) { |
|
|
|
|
|
|
|
|
|
function type_plugin_repertorier($typologie, $filtres = [], $informations = []) { |
|
|
|
|
// Utilisation d'une statique pour éviter les requêtes multiples sur le même hit. |
|
|
|
|
static $types = array(); |
|
|
|
|
static $types = []; |
|
|
|
|
|
|
|
|
|
if (!isset($types[$typologie])) { |
|
|
|
|
// On récupère l'id du groupe pour le type précisé (categorie, tag). |
|
|
|
|
include_spip('inc/config'); |
|
|
|
|
$id_groupe = lire_config("svptype/typologies/${typologie}/id_groupe", 0); |
|
|
|
|
$id_groupe = lire_config("svptype/typologies/{$typologie}/id_groupe", 0); |
|
|
|
|
|
|
|
|
|
// On récupère la description complète de toutes les catégories de plugin |
|
|
|
|
$from = array('spip_mots'); |
|
|
|
|
$where = array('id_groupe=' . $id_groupe); |
|
|
|
|
$order_by = array('identifiant'); |
|
|
|
|
$from = ['spip_mots']; |
|
|
|
|
$where = ['id_groupe=' . $id_groupe]; |
|
|
|
|
$order_by = ['identifiant']; |
|
|
|
|
$types[$typologie] = sql_allfetsel('*', $from, $where, '', $order_by); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Refactoring du tableau suivant les champs demandés et application des filtres. |
|
|
|
|
$types_filtrees = array(); |
|
|
|
|
$types_filtrees = []; |
|
|
|
|
if (!is_array($informations)) { |
|
|
|
|
$informations = array($informations); |
|
|
|
|
$informations = [$informations]; |
|
|
|
|
} |
|
|
|
|
$informations = $informations ? array_flip($informations) : array(); |
|
|
|
|
$informations = $informations ? array_flip($informations) : []; |
|
|
|
|
foreach ($types[$typologie] as $_cle => $_type) { |
|
|
|
|
// On détermine si on retient ou pas le type. |
|
|
|
|
$filtre_ok = true; |
|
|
|
@ -165,28 +167,27 @@ function type_plugin_repertorier($typologie, $filtres = array(), $informations =
|
|
|
|
|
* |
|
|
|
|
* @return array Description de chaque affectation (type de plugin, plugin) de la typologie concernée. |
|
|
|
|
*/ |
|
|
|
|
function type_plugin_repertorier_affectation($typologie, $filtres = array()) { |
|
|
|
|
|
|
|
|
|
function type_plugin_repertorier_affectation($typologie, $filtres = []) { |
|
|
|
|
// On récupère l'id du groupe pour la typologie concernée. |
|
|
|
|
include_spip('inc/config'); |
|
|
|
|
$id_groupe = lire_config("svptype/typologies/${typologie}/id_groupe", 0); |
|
|
|
|
$id_groupe = lire_config("svptype/typologies/{$typologie}/id_groupe", 0); |
|
|
|
|
|
|
|
|
|
// On initialise la jointure pour récupérer l'identifiant du type de plugin et pas uniquement son id. |
|
|
|
|
$from = array('spip_plugins_typologies', 'spip_mots'); |
|
|
|
|
$select = array( |
|
|
|
|
$from = ['spip_plugins_typologies', 'spip_mots']; |
|
|
|
|
$select = [ |
|
|
|
|
'spip_plugins_typologies.id_groupe', |
|
|
|
|
'spip_plugins_typologies.id_mot', |
|
|
|
|
'spip_mots.identifiant as identifiant_mot', |
|
|
|
|
'spip_plugins_typologies.prefixe' |
|
|
|
|
); |
|
|
|
|
$order_by = array('spip_plugins_typologies.id_mot', 'spip_plugins_typologies.prefixe'); |
|
|
|
|
]; |
|
|
|
|
$order_by = ['spip_plugins_typologies.id_mot', 'spip_plugins_typologies.prefixe']; |
|
|
|
|
|
|
|
|
|
// On calcule les conditions en y intégrant les critères si ils existent |
|
|
|
|
// -- conditions minimales |
|
|
|
|
$where = array( |
|
|
|
|
$where = [ |
|
|
|
|
'spip_plugins_typologies.id_groupe=' . $id_groupe, |
|
|
|
|
'spip_plugins_typologies.id_mot=spip_mots.id_mot' |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
// -- conditions issues des filtres |
|
|
|
|
if ($filtres) { |
|
|
|
|
// Traitement du cas où le critère 'type' est utilisé : on le transforme en un critère id_mot. |
|
|
|
@ -207,10 +208,10 @@ function type_plugin_repertorier_affectation($typologie, $filtres = array()) {
|
|
|
|
|
foreach ($filtres as $_critere => $_valeur) { |
|
|
|
|
if ($_critere == 'id_mot') { |
|
|
|
|
$where[] = is_array($_valeur) |
|
|
|
|
? sql_in("spip_plugins_typologies.${_critere}", $_valeur) |
|
|
|
|
: "spip_plugins_typologies.${_critere}=" . intval($_valeur); |
|
|
|
|
? sql_in("spip_plugins_typologies.{$_critere}", $_valeur) |
|
|
|
|
: "spip_plugins_typologies.{$_critere}=" . (int) $_valeur; |
|
|
|
|
} elseif ($_critere == 'prefixe') { |
|
|
|
|
$where[] = "spip_plugins_typologies.${_critere}=" . sql_quote(strtoupper($_valeur)); |
|
|
|
|
$where[] = "spip_plugins_typologies.{$_critere}=" . sql_quote(strtoupper($_valeur)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -232,13 +233,12 @@ function type_plugin_repertorier_affectation($typologie, $filtres = array()) {
|
|
|
|
|
* @return array Liste des enfants d'un type de plugin ou tableau vide si aucun. |
|
|
|
|
*/ |
|
|
|
|
function type_plugin_repertorier_enfant($typologie, $type_plugin) { |
|
|
|
|
|
|
|
|
|
// Initialisations statiques pour les performances. |
|
|
|
|
static $enfants = array(); |
|
|
|
|
static $enfants = []; |
|
|
|
|
|
|
|
|
|
// Le type est fourni soit sous forme de son identifiant soit de son id. |
|
|
|
|
// On calcule dans tous les cas l'id. |
|
|
|
|
if (!$id_mot = intval($type_plugin)) { |
|
|
|
|
if (!$id_mot = (int) $type_plugin) { |
|
|
|
|
// On a passé l'identifiant, il faut déterminer l'id du mot. |
|
|
|
|
$id_mot = type_plugin_lire($typologie, $type_plugin, 'id_mot'); |
|
|
|
|
} |
|
|
|
@ -263,7 +263,6 @@ function type_plugin_repertorier_enfant($typologie, $type_plugin) {
|
|
|
|
|
* @return int Nombre d'enfants d'un type de plugin ou 0 si aucun. |
|
|
|
|
*/ |
|
|
|
|
function type_plugin_compter_enfant($typologie, $type_plugin) { |
|
|
|
|
|
|
|
|
|
return count(type_plugin_repertorier_enfant($typologie, $type_plugin)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -278,20 +277,19 @@ function type_plugin_compter_enfant($typologie, $type_plugin) {
|
|
|
|
|
* @return int Nombre d'affectations (type de plugin, plugin) d'un type de plugin ou 0 si aucun. |
|
|
|
|
*/ |
|
|
|
|
function type_plugin_compter_affectation($typologie, $type_plugin) { |
|
|
|
|
|
|
|
|
|
// Initialisations statiques pour les performances. |
|
|
|
|
static $compteurs = array(); |
|
|
|
|
static $configurations_typologie = array(); |
|
|
|
|
static $compteurs = []; |
|
|
|
|
static $configurations_typologie = []; |
|
|
|
|
|
|
|
|
|
// Déterminer les informations du groupe typologique si il n'est pas encore stocké. |
|
|
|
|
if (!isset($configurations_typologie[$typologie])) { |
|
|
|
|
include_spip('inc/config'); |
|
|
|
|
$configurations_typologie[$typologie] = lire_config("svptype/typologies/${typologie}", array()); |
|
|
|
|
$configurations_typologie[$typologie] = lire_config("svptype/typologies/{$typologie}", []); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Le type est fourni soit sous forme de son identifiant soit de son id. |
|
|
|
|
// Extrait les informations du type de plugin pour utiliser id_mot et profondeur. |
|
|
|
|
$description_type = type_plugin_lire($typologie, $type_plugin, array('id_mot', 'profondeur')); |
|
|
|
|
$description_type = type_plugin_lire($typologie, $type_plugin, ['id_mot', 'profondeur']); |
|
|
|
|
$id_mot = $description_type['id_mot']; |
|
|
|
|
|
|
|
|
|
// Recherche des affectations de plugin. Pour les catégories qui sont arborescentes, il faut distinguer : |
|
|
|
@ -299,7 +297,7 @@ function type_plugin_compter_affectation($typologie, $type_plugin) {
|
|
|
|
|
// -- et les catégories feuille auxquelles sont attachés les plugins (auteur/extension) |
|
|
|
|
if (!isset($compteurs[$id_mot])) { |
|
|
|
|
// Initialisation de la condition sur le groupe de mots. |
|
|
|
|
$where = array('id_groupe=' . intval($configurations_typologie[$typologie]['id_groupe'])); |
|
|
|
|
$where = ['id_groupe=' . (int) ($configurations_typologie[$typologie]['id_groupe'])]; |
|
|
|
|
|
|
|
|
|
// Déterminer le mode de recherche suivant que : |
|
|
|
|
// - la typologie est arborescente ou pas |
|
|
|
@ -330,10 +328,10 @@ function type_plugin_elaborer_condition($typologie, $type_plugin, $vue) {
|
|
|
|
|
if ($type_plugin) { |
|
|
|
|
// Déterminer les informations de configuration de la typologie. |
|
|
|
|
include_spip('inc/config'); |
|
|
|
|
if ($config_typologie = lire_config("svptype/typologies/${typologie}", array())) { |
|
|
|
|
if ($config_typologie = lire_config("svptype/typologies/{$typologie}", [])) { |
|
|
|
|
// On détermine l'id et la profondeur du type. |
|
|
|
|
include_spip('inc/svptype_type_plugin'); |
|
|
|
|
if ($description_type_plugin = type_plugin_lire($typologie, $type_plugin, array('id_mot', 'profondeur', 'id_parent'))) { |
|
|
|
|
if ($description_type_plugin = type_plugin_lire($typologie, $type_plugin, ['id_mot', 'profondeur', 'id_parent'])) { |
|
|
|
|
// On détermine la profondeur du type qui est plus fiable que de tester l'existence d'un "/". |
|
|
|
|
$id = $description_type_plugin['id_mot']; |
|
|
|
|
$profondeur = $description_type_plugin['profondeur']; |
|
|
|
@ -346,7 +344,7 @@ function type_plugin_elaborer_condition($typologie, $type_plugin, $vue) {
|
|
|
|
|
$filtre = 'id_mot=' . $id; |
|
|
|
|
} elseif ($vue === 'navigation') { |
|
|
|
|
$filtre = $config_typologie['est_arborescente'] |
|
|
|
|
? 'id_mot=' . intval($id_parent) |
|
|
|
|
? 'id_mot=' . (int) $id_parent |
|
|
|
|
: ''; |
|
|
|
|
} else { |
|
|
|
|
$filtre = 'plugins_typologies.id_mot=' . $id; |
|
|
|
|