source: extensions/Copyrights/maintain.inc.php @ 10874

Last change on this file since 10874 was 10874, checked in by J.Commelin, 13 years ago

First commit to repository

File size: 2.2 KB
Line 
1<?php
2
3function plugin_install() {
4  global $conf, $prefixeTable;
5  $query = "
6    CREATE TABLE IF NOT EXISTS ".$prefixeTable."copyrights_admin (
7      cr_id int(11) NOT NULL AUTO_INCREMENT,
8      name varchar(255) UNIQUE NOT NULL,
9      url varchar(255) NOT NULL,
10      visible bool DEFAULT 0,
11      PRIMARY KEY (cr_id)
12    ) ENGINE=MyISAM DEFAULT CHARACTER SET utf8
13    ;";
14  pwg_query($query);
15
16  $query = "
17    CREATE TABLE IF NOT EXISTS ".$prefixeTable."copyrights_media (
18      media_id int(11) NOT NULL,
19      cr_id int(11) default NULL
20    ) ENGINE = MyISAM DEFAULT CHARACTER SET utf8
21    ;";
22  pwg_query($query);
23}
24
25function plugin_activate() {
26  global $prefixeTable;
27
28  $query = "
29    SELECT COUNT(*)
30    FROM ".$prefixeTable."copyrights_admin
31    ;";
32  list($counter) = pwg_db_fetch_row(pwg_query($query));
33  if (0 == $counter) {
34    copyrights_create_default();
35  }
36}
37
38function plugin_uninstall() {
39  global $prefixeTable;
40
41  $query = "
42    DROP TABLE ".$prefixeTable."copyrights_admin
43    ;";
44  pwg_query($query);
45
46  $query = "
47    DROP TABLE ".$prefixeTable."copyrights_media
48    ;";
49  pwg_query($query);
50}
51
52function copyrights_create_default() {
53  global $prefixeTable;
54
55  // Insert the copyrights of Creative Commons
56  $inserts = array(
57    array(
58      'name' => 'Creative Commons (BY)',
59      'url' => 'http://creativecommons.org/licenses/by/3.0/',
60      'visible' => 1
61    ),
62    array(
63      'name' => 'Creative Commons (BY-SA)',
64      'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
65      'visible' => 1
66    ),
67    array(
68      'name' => 'Creative Commons (BY-ND)',
69      'url' => 'http://creativecommons.org/licenses/by-nd/3.0/',
70      'visible' => 1
71    ),
72    array(
73      'name' => 'Creative Commons (BY-NC)',
74      'url' => 'http://creativecommons.org/licenses/by-nc/3.0/',
75      'visible' => 1
76    ),
77    array(
78      'name' => 'Creative Commons (BY-NC-SA)',
79      'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
80      'visible' => 1
81    ),
82    array(
83      'name' => 'Creative Commons (BY-NC-ND)',
84      'url' => 'http://creativecommons.org/licenses/by-nc-nd/3.0/',
85      'visible' => 1
86    )
87  );
88
89  mass_inserts(
90    $prefixeTable.'copyrights_admin',
91    array(
92      'name',
93      'url',
94      'visible'
95    ),
96    $inserts
97  );
98}
Note: See TracBrowser for help on using the repository browser.