| 1 |
<?php |
<?php |
| 2 |
// $Id: copyright.install,v 1.4 2006/08/20 18:19:21 robrechtj Exp $ |
// $Id: copyright.install,v 1.4.4.10 2007/10/05 15:47:40 robrechtj Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* Installing and updating the COPYRIGHT module. |
* Installing, uninstalling and updating the COPYRIGHT module. |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
| 10 |
* First-time install of the module. |
* Implementation of hook_install(). |
| 11 |
*/ |
*/ |
| 12 |
function copyright_install() { |
function copyright_install() { |
| 13 |
switch ($GLOBALS['db_type']) { |
drupal_install_schema('copyright'); |
|
case 'mysql': |
|
|
case 'mysqli': |
|
|
$ret = db_query("CREATE TABLE {copyrights} (". |
|
|
"cpyid int unsigned NOT NULL, ". |
|
|
"name varchar(60) NOT NULL, ". |
|
|
"description varchar(255) NULL DEFAULT NULL, ". |
|
|
"site_notice longtext NOT NULL, ". |
|
|
"node_notice longtext NOT NULL, ". |
|
|
"image_url varchar(255), ". |
|
|
"source_url varchar(255), ". |
|
|
"license longtext, ". |
|
|
"PRIMARY KEY (cpyid)) /*!40100 DEFAULT CHARACTER SET utf8 */"); |
|
|
|
|
|
$ret = $ret && |
|
|
db_query("INSERT INTO {sequences} (name, id) ". |
|
|
"VALUES ('{copyrights}_cpyid', 5)"); |
|
|
|
|
|
$ret = $ret && |
|
|
db_query("CREATE TABLE {copyright_node} (". |
|
|
"nid int unsigned NOT NULL, ". |
|
|
"cpyid int unsigned NOT NULL, ". |
|
|
"children_show_notice bool NOT NULL DEFAULT 1, ". |
|
|
"original_author varchar(255), ". |
|
|
"children_allow_set bool NOT NULL DEFAULT 1, ". |
|
|
"PRIMARY KEY (nid)) /*!40100 DEFAULT CHARACTER SET utf8 */"); |
|
|
break; |
|
|
|
|
|
case 'pgsql': |
|
|
$ret = db_query("CREATE TABLE {copyrights} (". |
|
|
"cpyid int not null primary key default nextval('{copyrights}_cpyid_seq'), ". |
|
|
"name varchar(60) NOT NULL, ". |
|
|
"description varchar(255) NULL DEFAULT NULL, ". |
|
|
"site_notice text NOT NULL, ". |
|
|
"node_notice text NOT NULL, ". |
|
|
"image_url varchar(255) NULL DEFAULT NULL, ". |
|
|
"source_url varchar(255) NULL DEFAULT NULL, ". |
|
|
"license text NULL)"); |
|
|
|
|
|
$ret = $ret && |
|
|
db_query("CREATE SEQUENCE {copyrights}_cpyid_seq START 5"); |
|
|
|
|
|
$ret = $ret && |
|
|
db_query("CREATE TABLE {copyright_node} (". |
|
|
"nid integer NOT NULL, ". |
|
|
"cpyid integer NOT NULL, ". |
|
|
"children_show_notice bool NOT NULL DEFAULT TRUE, ". |
|
|
"original_author varchar(255) NULL DEFAULT NULL, ". |
|
|
"children_allow_set bool NOT NULL DEFAULT TRUE, ". |
|
|
"PRIMARY KEY (nid))"); |
|
|
break; |
|
|
} |
|
|
|
|
|
if ($ret) { |
|
|
drupal_set_message(t('Copyright database tables installed.')); |
|
|
|
|
|
// Insert some common copyrights |
|
|
db_query("INSERT INTO {copyrights} (cpyid, name, description, site_notice, node_notice) VALUES (%d, '%s', '%s', '%s', '%s')", 1, 'All Rights Reserved', 'All Rights Reserved', 'Copyright © %year %site<br />All Rights Reserved', 'Copyright © %year %author<br />All Rights Reserved'); |
|
|
|
|
|
db_query("INSERT INTO {copyrights} (cpyid, name, description, site_notice, node_notice) VALUES (%d, '%s', '%s', '%s', '%s')", 2, 'Public Domain', 'Public Domain', 'All content of this site is released into the public domain except where otherwise noted.', 'This page is released into the public domain.'); |
|
| 14 |
|
|
| 15 |
db_query("INSERT INTO {copyrights} (cpyid, name, description, site_notice, node_notice) VALUES (%d, '%s', '%s', '%s', '%s')", 3, 'Creative Commons BY-NC-SA', 'Creative Commons Attribution-NonCommercial-ShareAlike 2.0 License', 'Except where otherwise noted, this work is licensed under a <a href="%source_url">Creative Commons License</a>. |
// Insert some common copyrights |
| 16 |
|
$copyrights = array( |
| 17 |
|
array( |
| 18 |
|
'name' => 'All Rights Reserved', |
| 19 |
|
'description' => 'All Rights Reserved', |
| 20 |
|
'site_notice' => 'Copyright © @year @site<br />All Rights Reserved', |
| 21 |
|
'node_notice' => 'Copyright © @year @author<br />All Rights Reserved', |
| 22 |
|
), |
| 23 |
|
|
| 24 |
|
array( |
| 25 |
|
'name' => 'Public Domain', |
| 26 |
|
'description' => 'Public Domain', |
| 27 |
|
'site_notice' => 'All content of this site is released into the public domain except where otherwise noted.', |
| 28 |
|
'node_notice' => 'This page is released into the public domain.', |
| 29 |
|
), |
| 30 |
|
|
| 31 |
|
array( |
| 32 |
|
'name' => 'Creative Commons BY-NC-SA', |
| 33 |
|
'description' => 'Creative Commons Attribution-NonCommercial-ShareAlike 2.0 License', |
| 34 |
|
'site_notice' => 'Except where otherwise noted, this work is licensed under a <a href="@source_url">Creative Commons License</a>. |
| 35 |
<!-- |
<!-- |
| 36 |
<rdf:RDF xmlns="http://web.resource.org/cc/" |
<rdf:RDF xmlns="http://web.resource.org/cc/" |
| 37 |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
| 48 |
<permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /> |
<permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /> |
| 49 |
</License> |
</License> |
| 50 |
</rdf:RDF> |
</rdf:RDF> |
| 51 |
-->', 'This page is licensed under a <a href="%source_url">Creative Commons License</a>.', 'http://creativecommons.org/licenses/by-nc-sa/2.0/', 'http://creativecommons.org/images/public/somerights20.gif'); |
-->', |
| 52 |
|
'node_notice' => 'This page is licensed under a <a href="@source_url">Creative Commons License</a>.', |
| 53 |
db_query("INSERT INTO {copyrights} (cpyid, name, description, site_notice, node_notice) VALUES (%d, '%s', '%s', '%s', '%s')", 4, 'Creative Commons BY', 'Creative Commons Attribution License', 'Except where otherwise noted, this work is licensed under a <a href="%source_url">Creative Commons License</a>. |
'source_url' => 'http://creativecommons.org/licenses/by-nc-sa/2.0/', |
| 54 |
|
'image_url' => 'http://creativecommons.org/images/public/somerights20.gif', |
| 55 |
|
), |
| 56 |
|
|
| 57 |
|
array( |
| 58 |
|
'name' => 'Creative Commons BY', |
| 59 |
|
'description' => 'Creative Commons Attribution License', |
| 60 |
|
'site_notice' => 'Except where otherwise noted, this work is licensed under a <a href="@source_url">Creative Commons License</a>. |
| 61 |
<!-- |
<!-- |
| 62 |
<rdf:RDF xmlns="http://web.resource.org/cc/" |
<rdf:RDF xmlns="http://web.resource.org/cc/" |
| 63 |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
| 74 |
<permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /> |
<permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /> |
| 75 |
</License> |
</License> |
| 76 |
</rdf:RDF> |
</rdf:RDF> |
| 77 |
-->', 'This page is licensed under a <a href="%source_url">Creative Commons License</a>.', 'http://creativecommons.org/licenses/by/2.0/', 'http://creativecommons.org/images/public/somerights20.gif'); |
-->', |
| 78 |
|
'node_notice' => 'This page is licensed under a <a href="@source_url">Creative Commons License</a>.', |
| 79 |
db_query("INSERT INTO {copyrights} (cpyid, name, description, site_notice, node_notice) VALUES (%d, '%s', '%s', '%s', '%s')", 5, 'GNU FDL', 'GNU Free Documentation License', 'Copyright (c) %year %site<br /> |
'source_url' => 'http://creativecommons.org/licenses/by/2.0/', |
| 80 |
|
'image_url' => 'http://creativecommons.org/images/public/somerights20.gif', |
| 81 |
|
), |
| 82 |
|
|
| 83 |
|
array( |
| 84 |
|
'name' => 'GNU FDL', |
| 85 |
|
'description' => 'GNU Free Documentation License', |
| 86 |
|
'site_notice' => 'Copyright (c) @year @site<br /> |
| 87 |
Permission is granted to copy, distribute and/or modify the content of<br /> |
Permission is granted to copy, distribute and/or modify the content of<br /> |
| 88 |
this site (except where otherwise noted) under the terms of the GNU Free<br /> |
this site (except where otherwise noted) under the terms of the GNU Free<br /> |
| 89 |
Documentation License, Version 1.2 or any later version published by the<br /> |
Documentation License, Version 1.2 or any later version published by the<br /> |
| 90 |
Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, <br /> |
Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, <br /> |
| 91 |
and no Back-Cover Texts. A copy of the license is available at <br /> |
and no Back-Cover Texts. A copy of the license is available at <br /> |
| 92 |
<a href="%source_url">%source_url</a>', 'Copyright (c) %year %author<br /> |
<a href="@source_url">@source_url</a>', |
| 93 |
|
'node_notice' => 'Copyright (c) @year @author<br /> |
| 94 |
Permission is granted to copy, distribute and/or modify the content of<br /> |
Permission is granted to copy, distribute and/or modify the content of<br /> |
| 95 |
this page under the terms of the GNU Free Documentation License, Version 1.2<br /> |
this page under the terms of the GNU Free Documentation License, Version 1.2<br /> |
| 96 |
or any later version published by the Free Software Foundation; with no <br /> |
or any later version published by the Free Software Foundation; with no <br /> |
| 97 |
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.<br /> |
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.<br /> |
| 98 |
A copy of the license is available at <a href="%source_url">%source_url</a>', |
A copy of the license is available at <a href="@source_url">@source_url</a>', |
| 99 |
'http://www.gnu.org/licenses/fdl.html'); |
'source_url' => 'http://www.gnu.org/licenses/fdl.html', |
| 100 |
} |
), |
| 101 |
else { |
); |
| 102 |
drupal_set_message(t('Copyright database tables could not be created. Please create them manually (see INSTALL.txt)'), 'error'); |
|
| 103 |
|
foreach ($copyrights as $copyright) { |
| 104 |
|
drupal_write_record($copyright); |
| 105 |
} |
} |
| 106 |
|
|
| 107 |
// Now make sure the footer-block is displayed right away. |
// Now make sure the footer-block is displayed right away. |
| 108 |
_block_rehash(); |
if (function_exists('_block_rehash')) { |
| 109 |
|
_block_rehash(); |
| 110 |
|
} |
| 111 |
} |
} |
| 112 |
|
|
| 113 |
/** |
/** |
| 114 |
* Update: UTF8 tables. |
* Implementation of hook_uninstall(). |
| 115 |
*/ |
*/ |
| 116 |
function copyright_update_1() { |
function copyright_uninstall() { |
| 117 |
return _system_update_utf8(array('copyrights', 'copyright_node')); |
drupal_uninstall_schema('copyright'); |
| 118 |
|
|
| 119 |
|
variable_del('copyright-default'); |
| 120 |
|
foreach ((array)node_get_types() as $type => $object) { |
| 121 |
|
variable_del('copyright-enable_'. $type); |
| 122 |
|
} |
| 123 |
} |
} |
| 124 |
|
|
| 125 |
/** |
/** |
| 126 |
* Update: |
* Implementation of hook_schema(). |
|
* - change the names of the variables, |
|
|
* - split variable 'copyright_nodetypes' into 'copyright-enable-$type'. |
|
| 127 |
*/ |
*/ |
| 128 |
function copyright_update_2() { |
function copyright_schema() { |
| 129 |
foreach (explode(',', variable_get('copyright_nodetypes', '')) as $nodetype) { |
$schema = array(); |
| 130 |
variable_set('copyright-enable-'. $nodetype, 1); |
|
| 131 |
} |
$schema['copyrights'] = array( |
| 132 |
variable_del('copyright_nodetypes'); |
'description' => t('Stores the list of available copyright licenses.'), |
| 133 |
variable_del('copyright_footer'); |
'fields' => array( |
| 134 |
variable_set('copyright-default', variable_get('copyright_default', 1)); |
'cpyid' => array( |
| 135 |
return; |
'type' => 'serial', |
| 136 |
|
'not null' => TRUE, |
| 137 |
|
'unsigned' => TRUE, |
| 138 |
|
), |
| 139 |
|
'name' => array( |
| 140 |
|
'type' => 'varchar', |
| 141 |
|
'length' => 60, |
| 142 |
|
'not null' => TRUE, |
| 143 |
|
'default' => '', |
| 144 |
|
), |
| 145 |
|
'description' => array( |
| 146 |
|
'type' => 'varchar', |
| 147 |
|
'length' => 255, |
| 148 |
|
), |
| 149 |
|
'site_notice' => array( |
| 150 |
|
'type' => 'text', |
| 151 |
|
'size' => 'medium', |
| 152 |
|
), |
| 153 |
|
'node_notice' => array( |
| 154 |
|
'type' => 'text', |
| 155 |
|
'size' => 'medium', |
| 156 |
|
), |
| 157 |
|
'image_url' => array( |
| 158 |
|
'type' => 'varchar', |
| 159 |
|
'length' => 255, |
| 160 |
|
), |
| 161 |
|
'source_url' => array( |
| 162 |
|
'type' => 'varchar', |
| 163 |
|
'length' => 255, |
| 164 |
|
), |
| 165 |
|
'license' => array( |
| 166 |
|
'type' => 'text', |
| 167 |
|
), |
| 168 |
|
), |
| 169 |
|
'primary key' => array('cpyid'), |
| 170 |
|
); |
| 171 |
|
|
| 172 |
|
$schema['copyright_node'] = array( |
| 173 |
|
'description' => t('Stores the cpyid - nid relation.'), |
| 174 |
|
'fields' => array( |
| 175 |
|
'nid' => array( |
| 176 |
|
'type' => 'int', |
| 177 |
|
'unsigned' => TRUE, |
| 178 |
|
'not null' => TRUE, |
| 179 |
|
), |
| 180 |
|
'cpyid' => array( |
| 181 |
|
'type' => 'int', |
| 182 |
|
'unsigned' => TRUE, |
| 183 |
|
'not null' => TRUE, |
| 184 |
|
), |
| 185 |
|
'children_show_notice' => array( |
| 186 |
|
'type' => 'int', |
| 187 |
|
'size' => 'tiny', |
| 188 |
|
'unsigned' => TRUE, |
| 189 |
|
'not null' => TRUE, |
| 190 |
|
'default' => 1, |
| 191 |
|
), |
| 192 |
|
'original_author' => array( |
| 193 |
|
'type' => 'varchar', |
| 194 |
|
'length' => 255, |
| 195 |
|
'default' => '', |
| 196 |
|
), |
| 197 |
|
'children_allow_set' => array( |
| 198 |
|
'type' => 'int', |
| 199 |
|
'size' => 'tiny', |
| 200 |
|
'unsigned' => TRUE, |
| 201 |
|
'not null' => TRUE, |
| 202 |
|
'default' => 1, |
| 203 |
|
), |
| 204 |
|
), |
| 205 |
|
'primary key' => array('nid'), |
| 206 |
|
); |
| 207 |
|
|
| 208 |
|
$schema['copyright_user'] = array( |
| 209 |
|
'description' => t('Stores the default copyright to use per user.'), |
| 210 |
|
'fields' => array( |
| 211 |
|
'uid' => array( |
| 212 |
|
'type' => 'int', |
| 213 |
|
'not null' => TRUE, |
| 214 |
|
'unsigned' => TRUE, |
| 215 |
|
), |
| 216 |
|
'cpyid' => array( |
| 217 |
|
'type' => 'int', |
| 218 |
|
'not null' => TRUE, |
| 219 |
|
'unsigned' => TRUE, |
| 220 |
|
'default' => 0, |
| 221 |
|
), |
| 222 |
|
'original_author' => array( |
| 223 |
|
'type' => 'varchar', |
| 224 |
|
'length' => 255, |
| 225 |
|
'default' => '', |
| 226 |
|
), |
| 227 |
|
), |
| 228 |
|
'primary key' => array('uid'), |
| 229 |
|
); |
| 230 |
|
|
| 231 |
|
return $schema; |
| 232 |
} |
} |
| 233 |
|
|
| 234 |
|
//TODO: update! {copyright_node}.children_show_notice and {copyright_node}.children_allow_set were BOOL and now they are TINYINT. |