3 class mw_sourceml extends mw_plugin{
9 function description(){
10 return "Publication de sources musicales";
15 $env->set_link("admin/sourceml", $env->url("admin/sourceml"), "SourceML", 50);
16 $env->set_link("admin/sourceml/licences", $env->url("admin/licences"), "Licences", 10);
17 $env->set_link("admin/sourceml/cache", $env->url("admin/cache"), "Cache", 20);
18 $env->set_link("admin/sourceml/maintenance", $env->url("admin/maintenance"), "Maintenance", 30);
20 $env->set_link("users/authors", $env->url("users/groupes"), "Groupes", 30);
21 $env->set_link("users/albums", $env->url("users/albums"), "Albums", 31);
22 $env->set_link("users/morceaux", $env->url("users/morceaux"), "Morceaux", 32);
23 $env->set_link("users/pistes", $env->url("users/pistes"), "Sources", 33);
25 $invitations_title = "Invitations";
26 if($nb_invitations = $this->nb_invitations($env)) $invitations_title .= " (".$nb_invitations.")";
27 $env->set_link("users/sources_invitations", $env->url("users/sources_invitations"), $invitations_title, 34);
29 $env->set_link("menu_top/groupes", $env->url("sources/groupe"), "Groupes", 10);
30 $env->set_link("menu_top/albums", $env->url("sources/album"), "Albums", 11);
31 $env->set_link("menu_top/morceaux", $env->url("sources/morceau"), "Morceaux", 12);
32 $env->set_link("menu_top/pistes", $env->url("sources/piste"), "Sources", 13);
37 function enable($env){
41 function disable($env){
45 // ---------------------------------------------------------------------------------
49 function install($env){
51 $env->bdd("sgbd") == "mysql"
52 || $env->bdd("sgbd") == "pdo_mysql"
53 ) return $this->install_mysql($env);
55 $env->bdd("sgbd") == "pdo_sqlite"
56 ) return $this->install_sqlite($env);
57 return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
60 function install_mysql($env){
62 $sgbd = $data->sgbd();
65 $sgbd->table_exists("#--sml_authors")
66 || $sgbd->table_exists("#--sml_classes")
67 || $sgbd->table_exists("#--sml_licences")
68 || $sgbd->table_exists("#--sml_sources")
69 || $sgbd->table_exists("#--sml_sources_access")
70 || $sgbd->table_exists("#--sml_sources_authors")
71 || $sgbd->table_exists("#--sml_sources_infos")
72 || $sgbd->table_exists("#--sml_source_cache")
73 || $sgbd->table_exists("#--sml_source_compositions")
74 || $sgbd->table_exists("#--sml_source_derivations")
75 || $sgbd->table_exists("#--sml_source_documents")
76 || $sgbd->table_exists("#--sml_sources_invitations");
79 return "impossible de savoir si les tables existent deja";
82 return "des tables existent deja en base. installation annulee";
86 "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"";
90 "CREATE TABLE `#--sml_authors`("
91 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
92 ." `id_user` int(11) NOT NULL,"
93 ." `nom` varchar(255) NOT NULL,"
94 ." `image` varchar(255) DEFAULT NULL,"
95 ." `description` text,"
96 ." `email` varchar(255) NOT NULL,"
97 ." `contact_form` tinyint(4) NOT NULL,"
98 ." `captcha` tinyint(4) NOT NULL,"
99 ." PRIMARY KEY (`id`),"
100 ." KEY `id_user` (`id_user`)"
101 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
105 "CREATE TABLE `#--sml_classes`("
106 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
107 ." `nom` varchar(255) NOT NULL,"
108 ." PRIMARY KEY (`id`)"
109 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
113 "CREATE TABLE `#--sml_licences`("
114 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
115 ." `nom` varchar(255) NOT NULL,"
116 ." `url` varchar(255) NOT NULL,"
117 ." PRIMARY KEY (`id`)"
118 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
122 "CREATE TABLE `#--sml_sources`("
123 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
124 ." `id_class` int(11) NOT NULL,"
125 ." `reference` varchar(255) DEFAULT NULL,"
126 ." `titre` varchar(255) DEFAULT NULL,"
127 ." `licence` int(11) DEFAULT NULL,"
128 ." `date_creation` date DEFAULT NULL,"
129 ." `date_inscription` datetime NOT NULL,"
130 ." PRIMARY KEY (`id`),"
131 ." KEY `id_class` (`id_class`),"
132 ." KEY `licence` (`licence`)"
133 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
137 "CREATE TABLE `#--sml_sources_access`("
138 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
139 ." `nom` varchar(255) NOT NULL,"
140 ." `intitule` varchar(255) NOT NULL,"
141 ." PRIMARY KEY (`id`)"
142 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
146 "CREATE TABLE `#--sml_sources_authors`("
147 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
148 ." `id_source` int(11) NOT NULL,"
149 ." `id_author` int(11) NOT NULL,"
150 ." `id_sources_access` int(11) NOT NULL,"
151 ." PRIMARY KEY (`id`),"
152 ." KEY `id_object` (`id_source`),"
153 ." KEY `id_author` (`id_author`),"
154 ." KEY `id_sources_access` (`id_sources_access`)"
155 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
159 "CREATE TABLE `#--sml_sources_infos`("
160 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
161 ." `id_source` int(11) NOT NULL,"
162 ." `key` varchar(255) NOT NULL,"
163 ." `value` text NOT NULL,"
164 ." PRIMARY KEY (`id`),"
165 ." KEY `id_source` (`id_source`)"
166 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
170 "CREATE TABLE `#--sml_source_cache`("
171 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
172 ." `url` varchar(255) NOT NULL,"
173 ." `id_source` int(11) NOT NULL,"
174 ." `last_update` datetime NOT NULL,"
175 ." PRIMARY KEY (`id`)"
176 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
180 "CREATE TABLE `#--sml_source_compositions`("
181 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
182 ." `id_source` int(11) NOT NULL,"
183 ." `id_composition` int(11) NOT NULL,"
184 ." PRIMARY KEY (`id`),"
185 ." KEY `id_source` (`id_source`),"
186 ." KEY `id_composition` (`id_composition`)"
187 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
191 "CREATE TABLE `#--sml_source_derivations`("
192 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
193 ." `id_source` int(11) NOT NULL,"
194 ." `derivation` varchar(255) NOT NULL,"
195 ." PRIMARY KEY (`id`),"
196 ." KEY `derivation` (`derivation`)"
197 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
201 "CREATE TABLE `#--sml_source_documents`("
202 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
203 ." `id_source` int(11) NOT NULL,"
204 ." `nom` varchar(255) NOT NULL,"
205 ." `url` varchar(255) NOT NULL,"
206 ." PRIMARY KEY (`id`),"
207 ." KEY `id_source` (`id_source`)"
208 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
212 "CREATE TABLE `#--sml_sources_invitations`("
213 ." `id` INT(11) NOT NULL AUTO_INCREMENT,"
214 ." `id_user` INT(11) NOT NULL,"
215 ." `id_source` INT(11) NOT NULL,"
216 ." `id_author` INT(11) NOT NULL,"
217 ." `id_sources_access` INT(11) NOT NULL,"
218 ." `date_invitation` datetime NOT NULL,"
219 ." PRIMARY KEY (`id`)"
225 return "imposible de creer les tables en base";
229 "INSERT INTO `#--sml_licences` (`id`, `nom`, `url`) VALUES"
230 ."(1, 'Creative commons by-sa 2.0', 'http://creativecommons.org/licenses/by-sa/2.0/deed.fr'),"
231 ."(2, 'Creative Commons by-nc-nd 2.5', 'http://creativecommons.org/licenses/by-nc-nd/2.5/'),"
232 ."(3, 'Creative Commons by-nc-sa 2.5', 'http://creativecommons.org/licenses/by-nc-sa/2.5/'),"
233 ."(4, 'Creative Commons by-nc 2.5', 'http://creativecommons.org/licenses/by-nc/2.5/'),"
234 ."(5, 'Creative Commons by-nd 2.5', 'http://creativecommons.org/licenses/by-nd/2.5/'),"
235 ."(6, 'Creative Commons by-sa 2.5', 'http://creativecommons.org/licenses/by-sa/2.5/'),"
236 ."(7, 'Creative Commons by 2.5', 'http://creativecommons.org/licenses/by/2.5/'),"
237 ."(8, 'Licence Art Libre', 'http://artlibre.org/licence/lal/'),"
238 ."(9, 'Licence C Reaction', 'http://morne.free.fr/Necktar7/creactionfr.htm'),"
239 ."(10, 'Yellow OpenMusic License', 'http://openmusic.linuxtag.org/yellow.html'),"
240 ."(11, 'Green OpenMusic License', 'http://openmusic.linuxtag.org/green.html')";
244 "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES"
251 "INSERT INTO `mw_sml_sources_access` (`id`, `nom`, `intitule`) VALUES"
\r
252 ."(1, 'admin', 'administrateur'),"
\r
253 ."(2, 'editeur', 'éditeur'),"
\r
254 ."(3, 'contributeur', 'contributeur')";
259 return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
264 function install_sqlite($env){
265 $data = $env->data();
266 $sgbd = $data->sgbd();
269 $sgbd->table_exists("#--sml_authors")
270 || $sgbd->table_exists("#--sml_classes")
271 || $sgbd->table_exists("#--sml_licences")
272 || $sgbd->table_exists("#--sml_sources")
273 || $sgbd->table_exists("#--sml_sources_access")
274 || $sgbd->table_exists("#--sml_sources_authors")
275 || $sgbd->table_exists("#--sml_sources_infos")
276 || $sgbd->table_exists("#--sml_source_cache")
277 || $sgbd->table_exists("#--sml_source_compositions")
278 || $sgbd->table_exists("#--sml_source_derivations")
279 || $sgbd->table_exists("#--sml_source_documents")
280 || $sgbd->table_exists("#--sml_sources_invitations");
283 return "impossible de savoir si les tables existent deja";
286 return "des tables existent deja en base. installation annulee";
291 "CREATE TABLE #--sml_authors("
292 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
293 ." `id_user` INTEGER NOT NULL,"
294 ." `nom` TEXT NOT NULL,"
295 ." `image` TEXT DEFAULT NULL,"
296 ." `description` TEXT,"
297 ." `email` TEXT NOT NULL,"
298 ." `contact_form` INTEGER NOT NULL,"
299 ." `captcha` INTEGER NOT NULL"
304 "CREATE TABLE #--sml_classes("
305 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
306 ." `nom` TEXT NOT NULL"
311 "CREATE TABLE #--sml_licences("
312 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
313 ." `nom` TEXT NOT NULL,"
314 ." `url` TEXT NOT NULL"
319 "CREATE TABLE #--sml_sources("
320 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
321 ." `id_class` INTEGER NOT NULL,"
322 ." `reference` TEXT DEFAULT NULL,"
323 ." `titre` TEXT DEFAULT NULL,"
324 ." `licence` INTEGER DEFAULT NULL,"
325 ." `date_creation` TEXT DEFAULT NULL,"
326 ." `date_inscription` TEXT NOT NULL"
331 "CREATE TABLE #--sml_sources_access("
332 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
333 ." `nom` TEXT NOT NULL,"
334 ." `intitule` TEXT NOT NULL"
339 "CREATE TABLE #--sml_sources_authors("
340 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
341 ." `id_source` INTEGER NOT NULL,"
342 ." `id_author` INTEGER NOT NULL,"
343 ." `id_sources_access` INTEGER NOT NULL"
348 "CREATE TABLE #--sml_sources_infos("
349 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
350 ." `id_source` INTEGER NOT NULL,"
351 ." `key` TEXT NOT NULL,"
352 ." `value` TEXT NOT NULL"
357 "CREATE TABLE #--sml_source_cache("
358 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
359 ." `url` TEXT NOT NULL,"
360 ." `id_source` INTEGER NOT NULL,"
361 ." `last_update` TEXT NOT NULL"
366 "CREATE TABLE #--sml_source_compositions("
367 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
368 ." `id_source` INTEGER NOT NULL,"
369 ." `id_composition` INTEGER NOT NULL"
374 "CREATE TABLE #--sml_source_derivations("
375 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
376 ." `id_source` INTEGER NOT NULL,"
377 ." `derivation` TEXT NOT NULL"
382 "CREATE TABLE #--sml_source_documents("
383 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
384 ." `id_source` INTEGER NOT NULL,"
385 ." `nom` TEXT NOT NULL,"
386 ." `url` TEXT NOT NULL"
391 "CREATE TABLE #--sml_sources_invitations("
392 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
393 ." `id_user` INTEGER NOT NULL,"
394 ." `id_source` INTEGER NOT NULL,"
395 ." `id_author` INTEGER NOT NULL,"
396 ." `id_sources_access` INTEGER NOT NULL,"
397 ." `date_invitation` TEXT NOT NULL"
403 return "imposible de creer les tables en base";
407 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
408 ." VALUES(1, 'Creative commons by-sa 2.0', 'http://creativecommons.org/licenses/by-sa/2.0/deed.fr')";
412 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
413 ." VALUES (2, 'Creative Commons by-nc-nd 2.5', 'http://creativecommons.org/licenses/by-nc-nd/2.5/')";
417 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
418 ." VALUES (3, 'Creative Commons by-nc-sa 2.5', 'http://creativecommons.org/licenses/by-nc-sa/2.5/')";
422 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
423 ." VALUES (4, 'Creative Commons by-nc 2.5', 'http://creativecommons.org/licenses/by-nc/2.5/')";
427 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
428 ." VALUES (5, 'Creative Commons by-nd 2.5', 'http://creativecommons.org/licenses/by-nd/2.5/')";
432 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
433 ." VALUES (6, 'Creative Commons by-sa 2.5', 'http://creativecommons.org/licenses/by-sa/2.5/')";
437 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
438 ." VALUES (7, 'Creative Commons by 2.5', 'http://creativecommons.org/licenses/by/2.5/')";
442 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
443 ." VALUES (8, 'Licence Art Libre', 'http://artlibre.org/licence/lal/')";
447 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
448 ." VALUES (9, 'Licence C Reaction', 'http://morne.free.fr/Necktar7/creactionfr.htm')";
452 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
453 ." VALUES (10, 'Yellow OpenMusic License', 'http://openmusic.linuxtag.org/yellow.html')";
457 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
458 ." VALUES (11, 'Green OpenMusic License', 'http://openmusic.linuxtag.org/green.html')";
462 "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (1, 'album')";
466 "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (2, 'morceau')";
470 "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (3, 'piste')";
474 "INSERT INTO `mw_sml_sources_access` (`id`, `nom`, `intitule`) VALUES (1, 'admin', 'administrateur')";
\r
478 "INSERT INTO `mw_sml_sources_access` (`id`, `nom`, `intitule`) VALUES (2, 'editeur', 'éditeur')";
482 "INSERT INTO `mw_sml_sources_access` (`id`, `nom`, `intitule`) VALUES (3, 'contributeur', 'contributeur')";
487 return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
492 // ---------------------------------------------------------------------------------
496 function uninstall($env){
498 $env->bdd("sgbd") == "mysql"
499 || $env->bdd("sgbd") == "pdo_mysql"
500 || $env->bdd("sgbd") == "pdo_sqlite"
501 ) return $this->uninstall_sql($env);
502 return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
505 function uninstall_sql($env){
506 $data = $env->data();
507 $sgbd = $data->sgbd();
508 if(!$this->disable($env)) return "impossible de desactiver le plugin";
510 $sgbd->query("DROP TABLE #--sml_authors");
513 return "impossible de supprimer la table #--sml_authors";
516 $sgbd->query("DROP TABLE #--sml_classes");
519 return "impossible de supprimer la table #--sml_classes";
522 $sgbd->query("DROP TABLE #--sml_licences");
525 return "impossible de supprimer la table #--sml_licences";
528 $sgbd->query("DROP TABLE #--sml_sources");
531 return "impossible de supprimer la table #--sml_sources";
534 $sgbd->query("DROP TABLE #--sml_sources_access");
537 return "impossible de supprimer la table #--sml_sources_access";
540 $sgbd->query("DROP TABLE #--sml_sources_authors");
543 return "impossible de supprimer la table #--sml_sources_authors";
546 $sgbd->query("DROP TABLE #--sml_sources_infos");
549 return "impossible de supprimer la table #--sml_sources_infos";
552 $sgbd->query("DROP TABLE #--sml_source_cache");
555 return "impossible de supprimer la table #--sml_source_cache";
558 $sgbd->query("DROP TABLE #--sml_source_compositions");
561 return "impossible de supprimer la table #--sml_source_compositions";
564 $sgbd->query("DROP TABLE #--sml_source_derivations");
567 return "impossible de supprimer la table #--sml_source_derivations";
570 $sgbd->query("DROP TABLE #--sml_source_documents");
573 return "impossible de supprimer la table #--sml_source_documents";
576 $sgbd->query("DROP TABLE #--sml_sources_invitations");
579 return "impossible de supprimer la table #--sml_sources_invitations";
584 // ---------------------------------------------------------------------------------
585 // fonctions internes
588 function nb_invitations($env){
589 if($user = $env->user()){
590 $data = $env->data();
591 if($groupes = $data->groupes($user["id"])){
593 foreach($groupes["list"] as $id_groupe => $groupe) $groupes_in .= ($groupes_in ? "," : "").$id_groupe;
597 $invitations = $data->list_sml_sources_invitations(
599 "index_name" => "id",
600 "where"=> "id_author IN(".$groupes_in.") OR id_user=".$user["id"],
601 "order_by" => "date_invitation",
607 return $invitations["total"];