| 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 |
* Administrative pages.
|
| 30 |
*/
|
| 31 |
|
| 32 |
/******************************************************************
|
| 33 |
* Menu callback: admin/content/copyright/add and
|
| 34 |
* admin/content/copyright/edit.
|
| 35 |
******************************************************************/
|
| 36 |
|
| 37 |
function copyright_edit(&$form_state, $edit) {
|
| 38 |
$form = array();
|
| 39 |
|
| 40 |
$form['name'] = array(
|
| 41 |
'#type' => 'textfield',
|
| 42 |
'#title' => t('Copyright or license name'),
|
| 43 |
'#default_value' => $edit['name'],
|
| 44 |
'#maxlength' => 60,
|
| 45 |
'#description' => t('Short name'),
|
| 46 |
'#required' => TRUE,
|
| 47 |
);
|
| 48 |
$form['description'] = array(
|
| 49 |
'#type' => 'textfield',
|
| 50 |
'#title' => t('Description'),
|
| 51 |
'#default_value' => $edit['description'],
|
| 52 |
'#maxlength' => 255,
|
| 53 |
'#description' => t('Longer description'),
|
| 54 |
);
|
| 55 |
$form['image_url'] = array(
|
| 56 |
'#type' => 'textfield',
|
| 57 |
'#title' => t('Image URL'),
|
| 58 |
'#default_value' => $edit['image_url'],
|
| 59 |
'#maxlength' => 255,
|
| 60 |
'#description' => t('URL (relative or absolute) to an image associated with this copyright or license. If provided it will automatically be displayed along with the copyright notice.'),
|
| 61 |
);
|
| 62 |
$form['source_url'] = array(
|
| 63 |
'#type' => 'textfield',
|
| 64 |
'#title' => t('Source URL'),
|
| 65 |
'#default_value' => $edit['source_url'],
|
| 66 |
'#maxlength' => 255,
|
| 67 |
'#description' => t('URL (relative or absolute) to the complete text or HTML of the copyright or license. To dynamically have a page created with the full license text below set a relative path without a leading backslash (e.g. "copyright").'),
|
| 68 |
);
|
| 69 |
$form['site_notice'] = array(
|
| 70 |
'#type' => 'textarea',
|
| 71 |
'#title' => t('Site notice'),
|
| 72 |
'#default_value' => $edit['site_notice'],
|
| 73 |
'#rows' => 5,
|
| 74 |
'#description' => t('Notice displayed for entire site (in footer or block). HTML is allowed and variables include @year, @site and @source_url.'),
|
| 75 |
'#required' => TRUE,
|
| 76 |
);
|
| 77 |
$form['node_notice'] = array(
|
| 78 |
'#type' => 'textarea',
|
| 79 |
'#title' => t('Node notice'),
|
| 80 |
'#default_value' => $edit['node_notice'],
|
| 81 |
'#rows' => 5,
|
| 82 |
'#description' => t('Notice displayed for nodes which are not using the site default. HTML is allowed and variables include @year, @author, @site and @source_url.'),
|
| 83 |
'#required' => TRUE,
|
| 84 |
);
|
| 85 |
$form['license'] = array(
|
| 86 |
'#type' => 'textarea',
|
| 87 |
'#title' => t('Full copyright or license'),
|
| 88 |
'#default_value' => $edit['license'],
|
| 89 |
'#rows' => 20,
|
| 90 |
'#description' => t('The complete text or HTML of the copyright or license. Leave empty to use Source URL (above).'),
|
| 91 |
);
|
| 92 |
|
| 93 |
$form['submit'] = array(
|
| 94 |
'#type' => 'submit',
|
| 95 |
'#value' => t('Save'),
|
| 96 |
'#submit' => array('copyright_edit_submit_save'),
|
| 97 |
);
|
| 98 |
if ($edit['cpyid']) {
|
| 99 |
$form['delete'] = array(
|
| 100 |
'#type' => 'submit',
|
| 101 |
'#value' => t('Delete'),
|
| 102 |
'#submit' => array('copyright_edit_submit_delete'),
|
| 103 |
'#disabled' => (variable_get('copyright-default', 1) == $edit['cpyid']),
|
| 104 |
);
|
| 105 |
$form['cpyid'] = array(
|
| 106 |
'#type' => 'hidden',
|
| 107 |
'#value' => $edit['cpyid'],
|
| 108 |
);
|
| 109 |
}
|
| 110 |
|
| 111 |
return $form;
|
| 112 |
}
|
| 113 |
|
| 114 |
function copyright_edit_submit_save($form, $form_state) {
|
| 115 |
$goto = 'admin/content/copyright/list';
|
| 116 |
|
| 117 |
if (isset($form_state['values']['cpyid'])) {
|
| 118 |
$cpyid = $form_state['values']['cpyid'];
|
| 119 |
_copyright_db_update_copyright($form_state['values']);
|
| 120 |
module_invoke_all('copyright', 'update', 'license', $form_state['values']);
|
| 121 |
drupal_set_message(t('Updated copyright %name.', array('%name' => $form_state['values']['name'])));
|
| 122 |
}
|
| 123 |
else {
|
| 124 |
$form_state['values']['cpyid'] = _copyright_db_insert_copyright($form_values);
|
| 125 |
module_invoke_all('copyright', 'insert', 'license', $form_state['values']);
|
| 126 |
drupal_set_message(t('Created new copyright %name.', array('%name' => $form_values['name'])));
|
| 127 |
}
|
| 128 |
cache_clear_all();
|
| 129 |
$form_state['redirect'] = 'admin/content/copyright/list';
|
| 130 |
}
|
| 131 |
|
| 132 |
/******************************************************************
|
| 133 |
* Menu callback: admin/content/copyright/delete.
|
| 134 |
******************************************************************/
|
| 135 |
|
| 136 |
function copyright_admin_delete($cpyid) {
|
| 137 |
if (user_access('administer copyright')) {
|
| 138 |
if (is_numeric($cpyid) && $license = copyright_get_license($cpyid)) {
|
| 139 |
if (variable_get('copyright-default', 1) == $cpyid) {
|
| 140 |
return t('You can not delete the "%name" copyright because it is currently configured as the site-wide default copyright. Go to the <a href="@overview-url">copyright overview page</a> to change the site-wide default copyright first and then delete this copyright.', array('%name' => $license->name, '@overview-url' => url('admin/content/copyright/list')));
|
| 141 |
}
|
| 142 |
else {
|
| 143 |
$form = array();
|
| 144 |
$form['cpyid'] = array(
|
| 145 |
'#type' => 'value',
|
| 146 |
'#value' => $cpyid,
|
| 147 |
);
|
| 148 |
$form['license'] = array(
|
| 149 |
'#type' => 'value',
|
| 150 |
'#value' => $license,
|
| 151 |
);
|
| 152 |
return confirm_form($form, t('Are you sure you want to delete %title?', array('%title' => $license->name)), $_GET['destination'] ? $_GET['destination'] : 'admin/content/copyright/list', t('This will reset all nodes using this copyright back to the site default. This action cannot be undone.'), t('Delete'), t('Cancel'));
|
| 153 |
}
|
| 154 |
}
|
| 155 |
return drupal_not_found();
|
| 156 |
}
|
| 157 |
return drupal_access_denied();
|
| 158 |
}
|
| 159 |
|
| 160 |
function copyright_admin_delete_submit($form_id, $form_values) {
|
| 161 |
if ($form_values['confirm']) {
|
| 162 |
$license = $form_values['license'];
|
| 163 |
db_query("DELETE FROM {copyrights} WHERE cpyid = %d", $license->cpyid);
|
| 164 |
db_query("DELETE FROM {copyright_node} WHERE cpyid = %d", $license->cpyid);
|
| 165 |
cache_clear_all();
|
| 166 |
drupal_set_message(t('Deleted copyright "%name". All nodes set to that copyright have been set back to the site default.', array('%name' => $license->name)));
|
| 167 |
}
|
| 168 |
return 'admin/content/copyright/list';
|
| 169 |
}
|
| 170 |
|
| 171 |
/******************************************************************
|
| 172 |
* Menu callback: admin/content/copyright/list.
|
| 173 |
******************************************************************/
|
| 174 |
|
| 175 |
function copyright_admin_overview() {
|
| 176 |
$form = array();
|
| 177 |
$options = array();
|
| 178 |
|
| 179 |
$default = variable_get('copyright-default', 1);
|
| 180 |
|
| 181 |
foreach (copyright_get_licenses() as $license) {
|
| 182 |
$options[$license->cpyid] = $license->name;
|
| 183 |
|
| 184 |
$form[$license->name] = array(
|
| 185 |
'#type' => 'item',
|
| 186 |
'#title' => $license->name,
|
| 187 |
'#description' => $license->description,
|
| 188 |
);
|
| 189 |
|
| 190 |
$form[$license->name]['cpyid'] = array(
|
| 191 |
'#type' => 'hidden',
|
| 192 |
'#value' => $license->cpyid,
|
| 193 |
);
|
| 194 |
|
| 195 |
$operations = l(t('edit'), 'admin/content/copyright/edit/'. $license->cpyid);
|
| 196 |
if ($license->cpyid != $default) {
|
| 197 |
$operations .= ' '. l(t('delete'), 'admin/content/copyright/delete/'. $license->cpyid);
|
| 198 |
}
|
| 199 |
$form[$license->name]['operations'] = array(
|
| 200 |
'#value' => $operations,
|
| 201 |
);
|
| 202 |
}
|
| 203 |
|
| 204 |
$form['default'] = array(
|
| 205 |
'#type' => 'radios',
|
| 206 |
'#options' => $options,
|
| 207 |
'#default_value' => variable_get('copyright-default', 1),
|
| 208 |
);
|
| 209 |
|
| 210 |
$form['submit'] = array(
|
| 211 |
'#type' => 'submit',
|
| 212 |
'#value' => t('Set default copyright'),
|
| 213 |
);
|
| 214 |
|
| 215 |
return $form;
|
| 216 |
}
|
| 217 |
|
| 218 |
function copyright_admin_overview_submit($form_id, $form_values) {
|
| 219 |
if (is_numeric($form_values['default'])) {
|
| 220 |
drupal_set_message(t('Default site-wide copyright updated.'));
|
| 221 |
variable_set('copyright-default', $form_values['default']);
|
| 222 |
}
|
| 223 |
}
|
| 224 |
|
| 225 |
function theme_copyright_admin_overview($form) {
|
| 226 |
$rows = array();
|
| 227 |
foreach (element_children($form) as $name) {
|
| 228 |
$element = $form[$name];
|
| 229 |
if (isset($element['operations'])) {
|
| 230 |
$form['default'][$element['cpyid']['#value']]['#title'] = '';
|
| 231 |
$rows[] = array(
|
| 232 |
drupal_render($form['default'][$element['cpyid']['#value']]),
|
| 233 |
check_plain($name),
|
| 234 |
drupal_render($element['operations']),
|
| 235 |
);
|
| 236 |
unset($form[$name]);
|
| 237 |
}
|
| 238 |
}
|
| 239 |
$header = array(t('Default'), t('Name'), t('Operations'));
|
| 240 |
$output = theme('table', $header, $rows);
|
| 241 |
$output .= drupal_render($form);
|
| 242 |
return $output;
|
| 243 |
}
|
| 244 |
|