| 1 |
<?php
|
| 2 |
// $Id: copyright.module,v 1.13.4.25 2007/10/05 15:47:40 robrechtj Exp $
|
| 3 |
|
| 4 |
/** Copyright (c) 2004 Matthew Schwartz <matt at mattschwartz dot net>
|
| 5 |
Contributors:
|
| 6 |
Dries Buytaert - code from taxonomy.module
|
| 7 |
Ber Kessels
|
| 8 |
Robrecht Jacques
|
| 9 |
|
| 10 |
This file is a contributed module of Drupal.
|
| 11 |
|
| 12 |
Drupal and this module are free software; you can redistribute this file
|
| 13 |
and/or modify it under the terms of the GNU General Public License as
|
| 14 |
published by the Free Software Foundation; either version 2 of the License,
|
| 15 |
or (at your option) any later version.
|
| 16 |
|
| 17 |
This file is distributed in the hope that it will be useful,
|
| 18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 20 |
GNU General Public License for more details.
|
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License
|
| 23 |
along with this file; if not, write to the Free Software
|
| 24 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 25 |
*/
|
| 26 |
|
| 27 |
/**
|
| 28 |
* @file
|
| 29 |
* Assign copyright licenses to site and nodes.
|
| 30 |
*
|
| 31 |
* TODO:
|
| 32 |
* - does it not make sense to make copyrights nodes?
|
| 33 |
* - check all these cache_clear_all() things - do we need them all?
|
| 34 |
* - check whether books works as expected
|
| 35 |
* - check whether we've put 'administer copyright' everywhere where needed
|
| 36 |
* - proofread and maybe extend documentation (hook_help())
|
| 37 |
* - figure out the right way to do 'view license' - this get_local_paths() looks a bit funny
|
| 38 |
* - does it makes sense to have a 'admin/configure/view/$cpyid' page for all copyrights?
|
| 39 |
* - node copyright block, to be displayed in 'content' region for 'node' pages
|
| 40 |
* - are there other content types (eg the 'container' from category.module) that actually warrant the
|
| 41 |
* same treatment as book pages?
|
| 42 |
* - document all functions
|
| 43 |
*/
|
| 44 |
|
| 45 |
/**
|
| 46 |
* Implementation of hook_help().
|
| 47 |
*/
|
| 48 |
function copyright_help($path, $args) {
|
| 49 |
switch ($path) {
|
| 50 |
case 'admin/content/copyright':
|
| 51 |
return t('The copyright module allows you to select a copyright for display on the site and each node. Some common copyright options are built in. You also have the option to create your own copyright(s).');
|
| 52 |
|
| 53 |
case 'admin/content/copyright/add':
|
| 54 |
return t('Create a new copyright to associate to the site and/or nodes. Create your own custom license or paste information from common licenses, like those offered by <a href="@commons">Creative Commons</a>.', array('@commons' => 'http://www.creativecommons.org'));
|
| 55 |
|
| 56 |
case 'admin/help#copyright':
|
| 57 |
return t('<h3>Copyright and licenses</h3>
|
| 58 |
<p>All works created in the United States and some other countries are considered to have an exclusive copyright by default, even without a copyright notice present. But it\'s generally good practice to assign a copyright to a web site by displaying a notice. You have the option to reserve all rights, put it into the public domain, or provide a variety of licenses which fall between. For many web sites it\'s often desirable to have different pages licensed in different ways, especially when the content is provided by more than one person or collected from other sources.</p>
|
| 59 |
<h4>Copyright notices</h4>
|
| 60 |
<p>When creating notices for the site and pages, the following variables can be inserted (and will be replaced automatcially for display):</p><dl>
|
| 61 |
<dt>@year</dt><dd>For a node it\'s the year of its creation, for the site it\'s the current year</dd>
|
| 62 |
<dt>@author</dt><dd>Applicable only to node notices, this is the author of the node or an alternate if specified</dd>
|
| 63 |
<dt>@site</dt><dd>Name of this Drupal site (currently: %site_name)</dd>
|
| 64 |
<dt>@source_url</dt><dd>URL to the full license text</dd></dl>', array('%site_name' => variable_get('site_name', 'Drupal')));
|
| 65 |
}
|
| 66 |
}
|
| 67 |
|
| 68 |
/**
|
| 69 |
* Implementation of hook_perm().
|
| 70 |
*/
|
| 71 |
function copyright_perm() {
|
| 72 |
return array('administer copyright');
|
| 73 |
}
|
| 74 |
|
| 75 |
/**
|
| 76 |
* Implementation of hook_menu().
|
| 77 |
*/
|
| 78 |
function copyright_menu() {
|
| 79 |
$items = array();
|
| 80 |
|
| 81 |
$items['admin/content/copyright'] = array(
|
| 82 |
'title' => 'Copyright',
|
| 83 |
'description' => 'Create and manage different copyrights and licenses that users can use.',
|
| 84 |
'page callback' => 'drupal_get_form',
|
| 85 |
'page arguments' => array('copyright_list'),
|
| 86 |
'access callback' => 'user_access',
|
| 87 |
'access arguments' => array('administer copyright'),
|
| 88 |
'file' => 'copyright.admin.inc',
|
| 89 |
);
|
| 90 |
|
| 91 |
$items['admin/content/copyright/list'] = array(
|
| 92 |
'title' => 'List',
|
| 93 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 94 |
'weight' => -10,
|
| 95 |
);
|
| 96 |
|
| 97 |
$items['admin/content/copyright/add'] = array(
|
| 98 |
'title' => 'Add copyright',
|
| 99 |
'type' => MENU_LOCAL_TASK,
|
| 100 |
'weight' => 0,
|
| 101 |
'page callback' => 'drupal_get_form',
|
| 102 |
'page arguments' => array('copyright_add'),
|
| 103 |
'access callback' => 'user_access',
|
| 104 |
'access arguments' => array('administer copyright'),
|
| 105 |
'file' => 'copyright.admin.inc',
|
| 106 |
);
|
| 107 |
|
| 108 |
$items['admin/content/copyright/%copyright/edit'] = array(
|
| 109 |
'title' => 'Edit',
|
| 110 |
'type' => MENU_CALLBACK,
|
| 111 |
'page callback' => 'drupal_get_form',
|
| 112 |
'page arguments' => array('copyright_edit', 3),
|
| 113 |
'access callback' => 'user_access',
|
| 114 |
'access arguments' => array('administer copyright'),
|
| 115 |
'file' => 'copyright.admin.inc',
|
| 116 |
);
|
| 117 |
|
| 118 |
$items['admin/content/copyright/%copyright/delete'] = array(
|
| 119 |
'title' => 'Delete',
|
| 120 |
'type' => MENU_CALLBACK,
|
| 121 |
'page callback' => 'drupal_get_form',
|
| 122 |
'page arguments' => array('copyright_delete', 3),
|
| 123 |
'access callback' => 'user_access',
|
| 124 |
'access arguments' => array('administer copyright'),
|
| 125 |
'file' => 'copyright.admin.inc',
|
| 126 |
);
|
| 127 |
|
| 128 |
return $items;
|
| 129 |
}
|
| 130 |
|
| 131 |
/**
|
| 132 |
* Implementation of hook_block().
|
| 133 |
*
|
| 134 |
* NOTE: Maybe in the future have this check if the currently displayed node is using
|
| 135 |
* a license other than the site default and display that in its place. The trick would
|
| 136 |
* then be to *not* also display the text at the bottom of the node. It needs to be an admin setting.
|
| 137 |
*/
|
| 138 |
function copyright_block($op = 'list', $delta = 0) {
|
| 139 |
if ($op == 'list') {
|
| 140 |
return array(
|
| 141 |
'site' => array('info' => t('Site copyright'), 'status' => 1, 'region' => 'footer'),
|
| 142 |
);
|
| 143 |
}
|
| 144 |
else if ($op == 'view') {
|
| 145 |
switch ($delta) {
|
| 146 |
case 'site':
|
| 147 |
$license = copyright_get_license(variable_get('copyright-default', 1));
|
| 148 |
break;
|
| 149 |
}
|
| 150 |
|
| 151 |
if ($license) {
|
| 152 |
drupal_add_css(drupal_get_path('module', 'copyright') .'/copyright.css');
|
| 153 |
return array(
|
| 154 |
'subject' => t('Copyright'),
|
| 155 |
'content' => theme('copyright_block', copyright_notice($license)),
|
| 156 |
);
|
| 157 |
}
|
| 158 |
}
|
| 159 |
}
|
| 160 |
|
| 161 |
/**
|
| 162 |
* Implementation of hook_theme().
|
| 163 |
*/
|
| 164 |
function copyright_theme() {
|
| 165 |
return array(
|
| 166 |
'copyright_footer' => array(
|
| 167 |
'arguments' => array(
|
| 168 |
'license' => NULL,
|
| 169 |
),
|
| 170 |
),
|
| 171 |
'copyright_block' => array(
|
| 172 |
'arguments' => array(
|
| 173 |
'license' => NULL,
|
| 174 |
),
|
| 175 |
),
|
| 176 |
);
|
| 177 |
}
|
| 178 |
|
| 179 |
/**
|
| 180 |
* Implementation of hook_user().
|
| 181 |
*/
|
| 182 |
function copyright_user($op, &$edit, &$account, $category = NULL) {
|
| 183 |
switch ($op) {
|
| 184 |
case 'categories':
|
| 185 |
$items = array();
|
| 186 |
$items[] = array(
|
| 187 |
'name' => 'copyright',
|
| 188 |
'title' => t('License'),
|
| 189 |
'weight' => 5,
|
| 190 |
);
|
| 191 |
return $items;
|
| 192 |
|
| 193 |
case 'form':
|
| 194 |
$form = array();
|
| 195 |
if ($category == 'copyright') {
|
| 196 |
$default = copyright_user_get_default($account->uid);
|
| 197 |
$licenses = copyright_get_license_names();
|
| 198 |
|
| 199 |
$form['copyright_user_default'] = array(
|
| 200 |
'#type' => 'radios',
|
| 201 |
'#title' => t('Default license'),
|
| 202 |
'#options' => $licenses,
|
| 203 |
'#default_value' => $default,
|
| 204 |
);
|
| 205 |
}
|
| 206 |
return $form;
|
| 207 |
|
| 208 |
case 'delete':
|
| 209 |
copyright_user_del_default($account->uid);
|
| 210 |
break;
|
| 211 |
|
| 212 |
case 'insert':
|
| 213 |
case 'update':
|
| 214 |
copyright_user_set_default($account->uid, $edit['copyright_user_default']);
|
| 215 |
$edit['copyright_user_default'] = NULL;
|
| 216 |
break;
|
| 217 |
}
|
| 218 |
}
|
| 219 |
|
| 220 |
/**
|
| 221 |
* Implementation of hook_node_operations().
|
| 222 |
*/
|
| 223 |
function copyright_node_operations() {
|
| 224 |
$operations = array();
|
| 225 |
foreach (copyright_get_license_names() as $cpyid => $license) {
|
| 226 |
$operations[] = array(
|
| 227 |
'label' => t('Assign @name license', array('@name' => $license)),
|
| 228 |
'callback' => 'copyright_assign_license',
|
| 229 |
'callback arguments' => array($cpyid),
|
| 230 |
);
|
| 231 |
}
|
| 232 |
return $operations;
|
| 233 |
}
|
| 234 |
|
| 235 |
/**
|
| 236 |
* Implementation of hook_node_type().
|
| 237 |
*/
|
| 238 |
function copyright_node_type($op, $info) {
|
| 239 |
switch ($op) {
|
| 240 |
case 'delete':
|
| 241 |
variable_del('copyright-enable_'. $info->type);
|
| 242 |
break;
|
| 243 |
|
| 244 |
case 'update':
|
| 245 |
if (!empty($info->old_type) && $info->old_type != $info->type) {
|
| 246 |
$setting = variable_get('copyright-enable_'. $info->old_type, 0);
|
| 247 |
variable_del('copyright-enable_'. $info->old_type);
|
| 248 |
variable_set('copyright-enable_'. $info->type, $setting);
|
| 249 |
}
|
| 250 |
break;
|
| 251 |
}
|
| 252 |
}
|
| 253 |
|
| 254 |
/**
|
| 255 |
* Implementation of hook_nodeapi().
|
| 256 |
*/
|
| 257 |
function copyright_nodeapi(&$node, $op, $arg = 0) {
|
| 258 |
if (variable_get('copyright-enable_'. $node->type, 0)) {
|
| 259 |
switch ($op) {
|
| 260 |
case 'view':
|
| 261 |
$node_license = copyright_get_node_license($node->nid);
|
| 262 |
if (!$node_license && $node->parent) {
|
| 263 |
// $node->parent set at node load time by book.module
|
| 264 |
$node_license = copyright_parent_node($node->parent);
|
| 265 |
}
|
| 266 |
if ($node_license && $node_license->cpyid != variable_get('copyright-default', 1)) {
|
| 267 |
// The node has a license other than the site's default
|
| 268 |
$license = copyright_get_license($node_license->cpyid);
|
| 269 |
$node->content['copyright'] = array(
|
| 270 |
'#value' => theme('copyright_footer', copyright_notice($license, $node, $node_license)),
|
| 271 |
'#weight' => 10,
|
| 272 |
);
|
| 273 |
drupal_add_css(drupal_get_path('module', 'copyright') .'/copyright.css');
|
| 274 |
}
|
| 275 |
break;
|
| 276 |
|
| 277 |
case 'insert':
|
| 278 |
case 'update':
|
| 279 |
if (isset($node->cpyid)) {
|
| 280 |
copyright_node_save($node->nid, $node->cpyid, $node->copyright_show_children, $node->original_author, $node->copyright_children_allow_set);
|
| 281 |
}
|
| 282 |
break;
|
| 283 |
|
| 284 |
case 'delete':
|
| 285 |
copyright_node_delete($node->nid);
|
| 286 |
break;
|
| 287 |
|
| 288 |
case 'load':
|
| 289 |
$node_license = (array) copyright_get_node_license($node->nid);
|
| 290 |
foreach ($node_license as $key => $value) {
|
| 291 |
$node->$key = $value;
|
| 292 |
}
|
| 293 |
break;
|
| 294 |
}
|
| 295 |
}
|
| 296 |
}
|
| 297 |
|
| 298 |
/**
|
| 299 |
* Implementation of hook_form_alter().
|
| 300 |
*
|
| 301 |
* - add copyright select box to node edit forms if enabled,
|
| 302 |
* - add enable/disable copyright to node workflow settings.
|
| 303 |
*/
|
| 304 |
function copyright_form_alter(&$form, $form_state, $form_id) {
|
| 305 |
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
|
| 306 |
$type = $form['#node_type']->type;
|
| 307 |
$form['workflow']['copyright-enable'] = array(
|
| 308 |
'#type' => 'radios',
|
| 309 |
'#title' => t('Allow copyright selection'),
|
| 310 |
'#default_value' => variable_get('copyright-enable_'. $type, 0),
|
| 311 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 312 |
'#description' => t('Enable the copyright selection for individual nodes of this content type.'),
|
| 313 |
);
|
| 314 |
}
|
| 315 |
|
| 316 |
if (isset($form['type'])) {
|
| 317 |
$node = $form['#node'];
|
| 318 |
$type = $node->type;
|
| 319 |
|
| 320 |
// Extending node edit forms.
|
| 321 |
if ($form_id == $type .'_node_form' && variable_get('copyright-enable_'. $type, FALSE)) {
|
| 322 |
global $user;
|
| 323 |
|
| 324 |
if (($user->uid == $node->uid || user_access('administer copyright')) &&
|
| 325 |
(!$node->parent || copyright_parent_allow($node->parent))) {
|
| 326 |
$licenses = copyright_get_license_names();
|
| 327 |
$site_default = variable_get('copyright-default', 1);
|
| 328 |
$user_default = copyright_user_get_default($user->uid);
|
| 329 |
|
| 330 |
foreach ($licenses as $cpyid => $license) {
|
| 331 |
$notices = array();
|
| 332 |
if ($cpyid == $site_default) {
|
| 333 |
$notices[] = t('site default');
|
| 334 |
}
|
| 335 |
if ($cpyid == $user_default) {
|
| 336 |
$notices[] = t('your default');
|
| 337 |
}
|
| 338 |
if (isset($node->cpyid) && $cpyid == $node->cpyid) {
|
| 339 |
$notices[] = t('current license');
|
| 340 |
}
|
| 341 |
|
| 342 |
if (count($notices) > 0) {
|
| 343 |
$licenses[$cpyid] .= ' ('. implode(', ', $notices) .')';
|
| 344 |
}
|
| 345 |
}
|
| 346 |
|
| 347 |
if ($node->cpyid) {
|
| 348 |
$selected_cpyid = $node->cpyid;
|
| 349 |
$author = $node->original_author;
|
| 350 |
}
|
| 351 |
else if ($node_license = copyright_get_node_license($node->nid)) {
|
| 352 |
$selected_cpyid = $node_license->cpyid;
|
| 353 |
$author = $node_license->original_author;
|
| 354 |
}
|
| 355 |
else if ($user_default) {
|
| 356 |
$selected_cpyid = $user_default;
|
| 357 |
$author = '';
|
| 358 |
}
|
| 359 |
else {
|
| 360 |
$selected_cpyid = $site_default;
|
| 361 |
$author = '';
|
| 362 |
}
|
| 363 |
|
| 364 |
$form['copyright'] = array(
|
| 365 |
'#type' => 'fieldset',
|
| 366 |
'#title' => t('Copyright'),
|
| 367 |
'#collapsible' => TRUE,
|
| 368 |
'#collapsed' => TRUE, //TODO: only collapse if there is nothing filled in
|
| 369 |
);
|
| 370 |
$form['copyright']['cpyid'] = array(
|
| 371 |
'#type' => 'select',
|
| 372 |
'#title' => t('Copyright'),
|
| 373 |
'#default_value' => $selected_cpyid,
|
| 374 |
'#options' => $licenses,
|
| 375 |
'#description' => t('Select the copyright to use for this node.'),
|
| 376 |
);
|
| 377 |
$form['copyright']['original_author'] = array(
|
| 378 |
'#type' => 'textfield',
|
| 379 |
'#title' => t('Original author'),
|
| 380 |
'#default_value' => $author,
|
| 381 |
'#maxlength' => 255,
|
| 382 |
'#description' => t('Copyright owner of this post if other than the poster.'),
|
| 383 |
);
|
| 384 |
|
| 385 |
if ($node->type == 'book') {
|
| 386 |
$form['copyright']['copyright_show_children'] = array(
|
| 387 |
'#type' => 'checkbox',
|
| 388 |
'#title' => t('Show this copyright for children (if different than site default).'),
|
| 389 |
'#default_value' => ($node_license ? $node_license->children_show_notice : $node->children_show_notice),
|
| 390 |
);
|
| 391 |
$form['copyright']['copyright_children_allow_set'] = array(
|
| 392 |
'#type' => 'checkbox',
|
| 393 |
'#title' => t('Allow children to set different copyright or license.'),
|
| 394 |
'#default_value' => ($node_license ? $node_license->children_allow_set : $node->children_allow_set),
|
| 395 |
);
|
| 396 |
}
|
| 397 |
}
|
| 398 |
}
|
| 399 |
}
|
| 400 |
return $form;
|
| 401 |
}
|
| 402 |
|
| 403 |
/**
|
| 404 |
* Save copyright associated with a given node.
|
| 405 |
*/
|
| 406 |
function copyright_node_save($nid, $cpyid, $children_show_notice = 1, $original_author = NULL, $children_allow_set = 1) {
|
| 407 |
// If the new copyright setting is being set to the default, delete the association if it exists
|
| 408 |
if ($cpyid == variable_get('copyright-default', 1) && !$original_author && $children_allow_set) {
|
| 409 |
copyright_node_delete($nid);
|
| 410 |
}
|
| 411 |
else {
|
| 412 |
$license = copyright_get_node_license($nid);
|
| 413 |
$original_author = trim($original_author);
|
| 414 |
if ($license->cpyid) {
|
| 415 |
db_query("UPDATE {copyright_node} SET cpyid = %d, children_show_notice = %d, children_allow_set = %d, original_author = '%s' WHERE nid = %d", $cpyid, $children_show_notice, $children_allow_set, $original_author, $nid);
|
| 416 |
}
|
| 417 |
else {
|
| 418 |
db_query("INSERT INTO {copyright_node} (nid, cpyid, children_show_notice, children_allow_set, original_author) VALUES (%d, %d, %d, %d, '%s')", $nid, $cpyid, $children_show_notice, $children_allow_set, $original_author);
|
| 419 |
}
|
| 420 |
}
|
| 421 |
}
|
| 422 |
|
| 423 |
/**
|
| 424 |
* Assign the same copyright to several nodes.
|
| 425 |
*/
|
| 426 |
function copyright_assign_license($nids, $cpyid) {
|
| 427 |
foreach ($nids as $nid) {
|
| 428 |
copyright_node_save($nid, $cpyid);
|
| 429 |
}
|
| 430 |
}
|
| 431 |
|
| 432 |
/**
|
| 433 |
* Remove associations of a node to its copyright.
|
| 434 |
*/
|
| 435 |
function copyright_node_delete($nid) {
|
| 436 |
db_query("DELETE FROM {copyright_node} WHERE nid = %d", $nid);
|
| 437 |
}
|
| 438 |
|
| 439 |
/******************************************************************
|
| 440 |
* Database access functions (public).
|
| 441 |
******************************************************************/
|
| 442 |
|
| 443 |
/**
|
| 444 |
* Return an array of all copyrights/licenses (cpyid and name only)
|
| 445 |
*/
|
| 446 |
function copyright_get_license_names() {
|
| 447 |
static $licenses;
|
| 448 |
if (!isset($licenses)) {
|
| 449 |
$result = db_query("SELECT cpyid, name FROM {copyrights} ORDER BY name");
|
| 450 |
$licenses = array();
|
| 451 |
while ($license = db_fetch_object($result)) {
|
| 452 |
$licenses[$license->cpyid] = $license->name;
|
| 453 |
}
|
| 454 |
}
|
| 455 |
return $licenses;
|
| 456 |
}
|
| 457 |
|
| 458 |
/**
|
| 459 |
* Return a single copyright/license object
|
| 460 |
*/
|
| 461 |
function copyright_get_license($cpyid) {
|
| 462 |
$result = db_query("SELECT * FROM {copyrights} WHERE cpyid = %d", $cpyid);
|
| 463 |
return db_fetch_object($result);
|
| 464 |
}
|
| 465 |
|
| 466 |
/**
|
| 467 |
* Returns an array of all copyright/license objects
|
| 468 |
*/
|
| 469 |
function copyright_get_licenses() {
|
| 470 |
$result = db_query("SELECT * FROM {copyrights} ORDER BY name");
|
| 471 |
$licenses = array();
|
| 472 |
while ($license = db_fetch_object($result)) {
|
| 473 |
$licenses[$license->cpyid] = $license;
|
| 474 |
}
|
| 475 |
return $licenses;
|
| 476 |
}
|
| 477 |
|
| 478 |
/**
|
| 479 |
* Return details of license and rules associated with a node
|
| 480 |
*/
|
| 481 |
function copyright_get_node_license($nid) {
|
| 482 |
$result = db_query("SELECT * FROM {copyright_node} WHERE nid = %d", $nid);
|
| 483 |
return db_fetch_object($result);
|
| 484 |
}
|
| 485 |
|
| 486 |
/**
|
| 487 |
* Return an array of all local paths which will have license pages created by this module
|
| 488 |
*/
|
| 489 |
function copyright_get_license_local_paths() {
|
| 490 |
//TODO: what is this source_url NOT LIKE '\%' ??
|
| 491 |
$result = db_query("SELECT cpyid, name, source_url FROM {copyrights} WHERE source_url NOT LIKE 'http:%' AND source_url NOT LIKE '\%'");
|
| 492 |
$licenses = array();
|
| 493 |
while ($license = db_fetch_object($result)) {
|
| 494 |
$licenses[$license->cpyid] = $license;
|
| 495 |
}
|
| 496 |
return $licenses;
|
| 497 |
}
|
| 498 |
|
| 499 |
/**
|
| 500 |
* Return the copyright_node info of the nearest ancestor book page; NULL if none
|
| 501 |
*
|
| 502 |
* NOTE: This function relies on the book table (from the book module) existing and working as it has.
|
| 503 |
* It's unlikely that a change to the book module would break this, but it's possible. This function
|
| 504 |
* won't be called unless a node to display is of type book, so we don't need to check for the book module's existence.
|
| 505 |
* I was going to use the book_location function from book.module but that would double the number of
|
| 506 |
* queries executed (after each of its queries I'd have to perform my own). This is more efficient.
|
| 507 |
* Also note we don't check node security because even if the user doesn't
|
| 508 |
* have the right to access a parent we still want to show the parent's copyright on this page.
|
| 509 |
*/
|
| 510 |
function copyright_from_book_parent($nid_parent) {
|
| 511 |
$parent = db_fetch_object(db_query("SELECT n.nid, b.parent, c.cpyid, c.children_show_notice, c.original_author, c.children_allow_set FROM {node} n INNER JOIN {book} b ON n.nid = b.nid LEFT OUTER JOIN {copyright_node} c ON n.nid = c.nid WHERE n.nid = %d", $nid_parent));
|
| 512 |
if ($parent->nid) {
|
| 513 |
if ($parent->cpyid) {
|
| 514 |
// Parent has its own copyright
|
| 515 |
return $parent;
|
| 516 |
}
|
| 517 |
else if ($parent->parent) {
|
| 518 |
// Parent doesn't have its own cpyid set, but parent does exist, so look deeper
|
| 519 |
return copyright_from_book_parent($parent->parent);
|
| 520 |
}
|
| 521 |
}
|
| 522 |
// If we got here there is no parent, so stop looking
|
| 523 |
return NULL;
|
| 524 |
}
|
| 525 |
|
| 526 |
/**
|
| 527 |
* Return the copyright_node info of a parent requiring its children show notice; NULL if none
|
| 528 |
*/
|
| 529 |
function copyright_parent_node($nid_parent) {
|
| 530 |
$parent = copyright_from_book_parent($nid_parent);
|
| 531 |
if ($parent->children_show_notice) {
|
| 532 |
return $parent;
|
| 533 |
}
|
| 534 |
else if ($parent->parent) {
|
| 535 |
return copyright_parent_node($parent->parent);
|
| 536 |
}
|
| 537 |
return NULL;
|
| 538 |
}
|
| 539 |
|
| 540 |
/**
|
| 541 |
* Return TRUE if ancestors allow setting of copyright
|
| 542 |
*/
|
| 543 |
function copyright_parent_allow($nid_parent) {
|
| 544 |
$parent = copyright_from_book_parent($nid_parent);
|
| 545 |
if ($parent && !$parent->children_allow_set) {
|
| 546 |
return FALSE;
|
| 547 |
}
|
| 548 |
else if ($parent->parent) {
|
| 549 |
return copyright_parent_allow($parent->parent);
|
| 550 |
}
|
| 551 |
// No parent dis-allows, so allow
|
| 552 |
return TRUE;
|
| 553 |
}
|
| 554 |
|
| 555 |
/**
|
| 556 |
* Save a default copyright for a given user.
|
| 557 |
*/
|
| 558 |
function copyright_user_set_default($uid, $cpyid) {
|
| 559 |
$default = copyright_user_get_default($uid);
|
| 560 |
if ($default !== FALSE) {
|
| 561 |
return db_query("UPDATE {copyright_user} SET cpyid = %d WHERE uid = %d", $cpyid, $uid);
|
| 562 |
}
|
| 563 |
return db_query("INSERT {copyright_user} (cpyid, uid) VALUES (%d, %d)", $cpyid, $uid);
|
| 564 |
}
|
| 565 |
|
| 566 |
/**
|
| 567 |
* Delete a default copyright for a given user.
|
| 568 |
*/
|
| 569 |
function copyright_user_del_default($uid) {
|
| 570 |
return db_query("DELETE FROM {copyright_user} WHERE uid = %d", $uid);
|
| 571 |
}
|
| 572 |
|
| 573 |
/**
|
| 574 |
* Get a default copyright for a given user.
|
| 575 |
*/
|
| 576 |
function copyright_user_get_default($uid) {
|
| 577 |
return db_result(db_query("SELECT cpyid FROM {copyright_user} WHERE uid = %d", $uid));
|
| 578 |
}
|
| 579 |
|
| 580 |
/******************************************************************
|
| 581 |
* Display functions (output text and themes).
|
| 582 |
******************************************************************/
|
| 583 |
|
| 584 |
/**
|
| 585 |
* Return HTML for display of a copyright notice.
|
| 586 |
*/
|
| 587 |
function copyright_notice($license, $node = NULL, $node_license = NULL) {
|
| 588 |
if (isset($node)) {
|
| 589 |
$notice = $license->node_notice;
|
| 590 |
$author = ($node_license->original_author ? $node_license->original_author : $node->original_author);
|
| 591 |
if (!$author) {
|
| 592 |
$user = user_load(array('uid' => $node->uid));
|
| 593 |
$author = $user->name;
|
| 594 |
}
|
| 595 |
$year = format_date($node->created, 'custom', 'Y');
|
| 596 |
}
|
| 597 |
else {
|
| 598 |
$notice = $license->site_notice;
|
| 599 |
$today = getdate();
|
| 600 |
$year = $today['year'];
|
| 601 |
$author = '';
|
| 602 |
}
|
| 603 |
|
| 604 |
$placeholders = array(
|
| 605 |
'@year' => $year,
|
| 606 |
'@author' => $author,
|
| 607 |
'@site' => variable_get('site_name', 'Drupal'),
|
| 608 |
'@source_url' => $license->source_url,
|
| 609 |
);
|
| 610 |
|
| 611 |
$img = '';
|
| 612 |
if ($license->image_url) {
|
| 613 |
$img = theme('image', $license->image_url, $alt = '', $title = $license->description, $attr = '', $getsize = false);
|
| 614 |
if ($license->source_url) {
|
| 615 |
$img = l($img, $license->source_url, array(), NULL, NULL, FALSE, TRUE);
|
| 616 |
}
|
| 617 |
$img = '<div class="copyright-image">'. $img .'</div>';
|
| 618 |
}
|
| 619 |
|
| 620 |
return $img . t($notice, $placeholders);
|
| 621 |
}
|
| 622 |
|
| 623 |
/**
|
| 624 |
* Generate a complete license for display
|
| 625 |
*/
|
| 626 |
function copyright_show_license($cpyid) {
|
| 627 |
$license = copyright_get_license($cpyid);
|
| 628 |
return $license->license;
|
| 629 |
}
|
| 630 |
|
| 631 |
/**
|
| 632 |
* Theming function for displaying a themed copyright notice
|
| 633 |
* in all page footers and the bottom of all nodes.
|
| 634 |
*
|
| 635 |
* The default is to center and dull the text.
|
| 636 |
*/
|
| 637 |
function theme_copyright_footer($notice) {
|
| 638 |
return '<div class="copyright-footer">' . $notice . '</div>';
|
| 639 |
}
|
| 640 |
|
| 641 |
/**
|
| 642 |
* Theming function for displaying a themed copyright notice
|
| 643 |
* in a block.
|
| 644 |
*
|
| 645 |
* The default is to simply center.
|
| 646 |
*/
|
| 647 |
function theme_copyright_block($notice) {
|
| 648 |
return $notice;
|
| 649 |
}
|
| 650 |
|
| 651 |
/******************************************************************
|
| 652 |
* Database access functions (private).
|
| 653 |
******************************************************************/
|
| 654 |
|
| 655 |
function _copyright_db_insert_copyright($edit) {
|
| 656 |
return db_query("INSERT INTO {copyrights} (cpyid, name, description, site_notice, node_notice, image_url, source_url, license) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $edit['cpyid'], $edit['name'], $edit['description'], $edit['site_notice'], $edit['node_notice'], $edit['image_url'], $edit['source_url'], $edit['license']);
|
| 657 |
}
|
| 658 |
|
| 659 |
function _copyright_db_update_copyright($edit) {
|
| 660 |
return db_query("UPDATE {copyrights} SET name = '%s', description = '%s', site_notice = '%s', node_notice = '%s', image_url = '%s', source_url = '%s', license = '%s' WHERE cpyid = %d", $edit['name'], $edit['description'], $edit['site_notice'], $edit['node_notice'], $edit['image_url'], $edit['source_url'], $edit['license'], $edit['cpyid']);
|
| 661 |
}
|
| 662 |
|
| 663 |
/******************************************************************
|
| 664 |
* Support for views module.
|
| 665 |
******************************************************************/
|
| 666 |
|
| 667 |
/**
|
| 668 |
* Implementation of hook_views_table().
|
| 669 |
*
|
| 670 |
* See: http://drupal.org/handbook/modules/views/api
|
| 671 |
*/
|
| 672 |
function copyright_views_tables() {
|
| 673 |
$tables = array();
|
| 674 |
$tables['copyright_node'] = array(
|
| 675 |
'name' => 'copyright_node',
|
| 676 |
'join' => array(
|
| 677 |
'left' => array(
|
| 678 |
'table' => 'node',
|
| 679 |
'field' => 'nid'
|
| 680 |
),
|
| 681 |
'right' => array(
|
| 682 |
'field' => 'nid'
|
| 683 |
)
|
| 684 |
),
|
| 685 |
'fields' => array(
|
| 686 |
'cpyid' => array(
|
| 687 |
'name' => t('Node: Copyright'),
|
| 688 |
'sortable' => TRUE,
|
| 689 |
'handler' => 'views_handler_field_copyright',
|
| 690 |
'help' => t('This will display the nodes license.'),
|
| 691 |
),
|
| 692 |
),
|
| 693 |
'filters' => array(
|
| 694 |
'cpyid' => array(
|
| 695 |
'name' => t('Node: Copyright'),
|
| 696 |
'list' => 'views_handler_filter_copyright',
|
| 697 |
'list-type' => 'list',
|
| 698 |
'operator' => 'views_handler_operator_or',
|
| 699 |
'value-type' => 'array',
|
| 700 |
'help' => t('Include or exclude nodes of the selected license.'),
|
| 701 |
),
|
| 702 |
),
|
| 703 |
);
|
| 704 |
return $tables;
|
| 705 |
}
|
| 706 |
|
| 707 |
/*
|
| 708 |
* Views handler for copyright field.
|
| 709 |
*
|
| 710 |
* @return
|
| 711 |
* String. License name.
|
| 712 |
*/
|
| 713 |
function views_handler_field_copyright($fieldinfo, $fielddata, $value, $data) {
|
| 714 |
$licenses = copyright_get_license_names();
|
| 715 |
return $licenses[$value];
|
| 716 |
}
|
| 717 |
|
| 718 |
/*
|
| 719 |
* Views handler for copyright filter.
|
| 720 |
*
|
| 721 |
* @return
|
| 722 |
* Array of ($cpyid => $license->name).
|
| 723 |
*/
|
| 724 |
function views_handler_filter_copyright($op) {
|
| 725 |
return copyright_get_license_names();
|
| 726 |
}
|
| 727 |
|