3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2020 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
14 * Déclarations relatives à la base de données
16 * @package SPIP\Medias\Pipelines
19 if (!defined('_ECRIRE_INC_VERSION')) {
24 * Interfaces des tables documents pour le compilateur
26 * @param array $interfaces
29 function medias_declarer_tables_interfaces($interfaces) {
30 $interfaces['table_des_tables']['documents'] = 'documents';
31 $interfaces['table_des_tables']['types_documents'] = 'types_documents';
33 $interfaces['exceptions_des_tables']['documents']['type_document'] = array('types_documents', 'titre');
34 $interfaces['exceptions_des_tables']['documents']['extension_document'] = array('types_documents', 'extension');
35 $interfaces['exceptions_des_tables']['documents']['mime_type'] = array('types_documents', 'mime_type');
36 $interfaces['exceptions_des_tables']['documents']['media_document'] = array('types_documents', 'media');
38 $interfaces['exceptions_des_jointures']['spip_documents']['id_forum'] = array('spip_documents_liens', 'id_forum');
39 $interfaces['exceptions_des_jointures']['spip_documents']['vu'] = array('spip_documents_liens', 'vu');
40 $interfaces['table_date']['types_documents'] = 'date';
42 $interfaces['table_des_traitements']['FICHIER'][] = 'get_spip_doc(%s)';
49 * Table principale spip_documents et spip_types_documents
51 * @param array $tables_principales
54 function medias_declarer_tables_principales($tables_principales) {
56 $spip_types_documents = array(
57 'extension' => "varchar(10) DEFAULT '' NOT NULL",
58 'titre' => "text DEFAULT '' NOT NULL",
59 'descriptif' => "text DEFAULT '' NOT NULL",
60 'mime_type' => "varchar(100) DEFAULT '' NOT NULL",
61 'inclus' => "ENUM('non', 'image', 'embed') DEFAULT 'non' NOT NULL",
62 'upload' => "ENUM('oui', 'non') DEFAULT 'oui' NOT NULL",
63 'media_defaut' => "varchar(10) DEFAULT 'file' NOT NULL",
67 $spip_types_documents_key = array(
68 'PRIMARY KEY' => 'extension',
69 'KEY inclus' => 'inclus'
72 $tables_principales['spip_types_documents'] =
73 array('field' => &$spip_types_documents, 'key' => &$spip_types_documents_key);
75 return $tables_principales;
79 * Table des liens documents-objets spip_documents_liens
81 * @param array $tables_auxiliaires
84 function medias_declarer_tables_auxiliaires($tables_auxiliaires) {
86 $spip_documents_liens = array(
87 'id_document' => "bigint(21) DEFAULT '0' NOT NULL",
88 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
89 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
90 'vu' => "ENUM('non', 'oui') DEFAULT 'non' NOT NULL",
91 'rang_lien' => "int(4) DEFAULT '0' NOT NULL"
94 $spip_documents_liens_key = array(
95 'PRIMARY KEY' => 'id_document,id_objet,objet',
96 'KEY id_document' => 'id_document',
97 'KEY id_objet' => 'id_objet',
98 'KEY objet' => 'objet',
101 $tables_auxiliaires['spip_documents_liens'] = array(
102 'field' => &$spip_documents_liens,
103 'key' => &$spip_documents_liens_key
106 return $tables_auxiliaires;
110 * Declarer le surnom des breves
112 * @param array $surnoms
115 function medias_declarer_tables_objets_surnoms($surnoms) {
116 $surnoms['type_document'] = 'types_documents'; # hum
117 #$surnoms['extension'] = "types_documents"; # hum
118 #$surnoms['type'] = "types_documents"; # a ajouter pour id_table_objet('type')=='extension' ?
122 function medias_declarer_tables_objets_sql($tables) {
123 $tables['spip_articles']['champs_versionnes'][] = 'jointure_documents';
124 $tables['spip_documents'] = array(
125 'table_objet_surnoms' => array('doc', 'img', 'emb'),
126 'type_surnoms' => array(),
127 'url_voir' => 'document_edit',
128 'url_edit' => 'document_edit',
130 'texte_retour' => 'icone_retour',
131 'texte_objets' => 'medias:objet_documents',
132 'texte_objet' => 'medias:objet_document',
133 'texte_modifier' => 'medias:info_modifier_document',
134 'info_aucun_objet' => 'medias:aucun_document',
135 'info_1_objet' => 'medias:un_document',
136 'info_nb_objets' => 'medias:des_documents',
137 'titre' => "CASE WHEN length(titre)>0 THEN titre ELSE fichier END as titre, '' AS lang",
139 'principale' => 'oui',
141 'id_document' => 'bigint(21) NOT NULL',
142 'id_vignette' => "bigint(21) DEFAULT '0' NOT NULL",
143 'extension' => "VARCHAR(10) DEFAULT '' NOT NULL",
144 'titre' => "text DEFAULT '' NOT NULL",
145 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
146 'descriptif' => "text DEFAULT '' NOT NULL",
147 'fichier' => "text NOT NULL DEFAULT ''",
148 'taille' => 'bigint',
149 'largeur' => 'integer',
150 'hauteur' => 'integer',
151 'duree' => 'integer',
152 'media' => "varchar(10) DEFAULT 'file' NOT NULL",
153 'mode' => "varchar(10) DEFAULT 'document' NOT NULL",
154 'distant' => "VARCHAR(3) DEFAULT 'non'",
155 'statut' => "varchar(10) DEFAULT '0' NOT NULL",
156 'credits' => "text DEFAULT '' NOT NULL",
157 'date_publication' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
158 'brise' => 'tinyint DEFAULT 0',
162 'PRIMARY KEY' => 'id_document',
163 'KEY id_vignette' => 'id_vignette',
164 'KEY mode' => 'mode',
165 'KEY extension' => 'extension'
168 'id_document' => 'id_document',
169 'extension' => 'extension'
174 'publie' => 'publie',
175 'previsu' => 'publie,prop,prepa',
176 'post_date' => 'date_publication',
177 'exception' => array('statut', 'tout')
180 'tables_jointures' => array('types_documents'),
181 'rechercher_champs' => array(
187 'champs_editables' => array(
203 'champs_versionnes' => array(
216 'modeles' => array('document', 'doc', 'img', 'emb', 'image', 'video', 'text', 'audio', 'application'),
219 // jointures sur les forum pour tous les objets
220 $tables[]['tables_jointures'][] = 'documents_liens';
222 // recherche jointe sur les documents pour les articles et rubriques
223 $tables['spip_articles']['rechercher_jointures']['document'] = array('titre' => 2, 'descriptif' => 1);
224 $tables['spip_rubriques']['rechercher_jointures']['document'] = array('titre' => 2, 'descriptif' => 1);
230 * Creer la table des types de document
232 * @param string $serveur
233 * @param string $champ_media
236 function creer_base_types_doc($serveur = '', $champ_media = 'media_defaut') {
237 global $tables_images, $tables_sequences, $tables_documents, $tables_mime;
238 include_spip('base/typedoc');
239 include_spip('base/abstract_sql');
241 // charger en memoire tous les types deja definis pour limiter les requettes
242 $rows = sql_allfetsel('mime_type,titre,inclus,extension,' . $champ_media . ',upload,descriptif', 'spip_types_documents', '', '', '', '', '', $serveur);
244 foreach ($rows as $k => $row) {
245 $deja[$row['extension']] = &$rows[$k];
248 $insertions = array();
251 foreach ($tables_mime as $extension => $type_mime) {
252 if (isset($tables_images[$extension])) {
253 $titre = $tables_images[$extension];
256 if (isset($tables_sequences[$extension])) {
257 $titre = $tables_sequences[$extension];
261 if (isset($tables_documents[$extension])) {
262 $titre = $tables_documents[$extension];
271 if (preg_match(',^image/,', $type_mime) or in_array($type_mime, array('application/illustrator'))) {
273 } elseif (preg_match(',^audio/,', $type_mime)) {
275 } elseif (preg_match(',^video/,', $type_mime) or in_array(
277 array('application/ogg', 'application/x-shockwave-flash', 'application/mp4')
283 'mime_type' => $type_mime,
286 'extension' => $extension,
287 $champ_media => $media,
291 if (!isset($deja[$extension])) {
292 $insertions[] = $set;
293 } elseif (array_diff($deja[$extension], $set)) {
294 $updates[$extension] = $set;
298 if (count($updates)) {
299 foreach ($updates as $extension => $set) {
300 sql_updateq('spip_types_documents', $set, 'extension=' . sql_quote($extension));
305 sql_insertq_multi('spip_types_documents', $insertions, '', $serveur);
311 * Optimiser la base de données en supprimant les liens orphelins
316 function medias_optimiser_base_disparus($flux) {
318 include_spip('action/editer_liens');
319 // optimiser les liens morts :
320 // entre documents vers des objets effaces
321 // depuis des documents effaces
322 $flux['data'] +
= objet_optimiser_liens(array('document' => '*'), '*');
324 // on ne nettoie volontairement pas automatiquement les documents orphelins