/[drupal]/contributions/modules/copyright/copyright.module
ViewVC logotype

Diff of /contributions/modules/copyright/copyright.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.14, Sun Feb 25 07:57:14 2007 UTC revision 1.15, Fri Aug 8 19:51:37 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: copyright.module,v 1.13 2006/08/17 15:09:55 robrechtj Exp $  // $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>  /** Copyright (c) 2004 Matthew Schwartz  <matt at mattschwartz dot net>
5      Contributors:      Contributors:
# Line 36  Line 36 
36   * - proofread and maybe extend documentation (hook_help())   * - 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   * - 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?   * - does it makes sense to have a 'admin/configure/view/$cpyid' page for all copyrights?
  * - do we really need theme_add_css() in hook_menu()? Looks to me we could add it to hook_block()  
39   * - node copyright block, to be displayed in 'content' region for 'node' pages   * - 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   * - are there other content types (eg the 'container' from category.module) that actually warrant the
41   *   same treatment as book pages?   *   same treatment as book pages?
42   * - document all functions   * - document all functions
43   */   */
44    
 /************************************************************  
  * Drupal hooks.  
  ************************************************************/  
   
45  /**  /**
46   * Implementation of hook_help().   * Implementation of hook_help().
47   */   */
48  function copyright_help($section) {  function copyright_help($path, $args) {
49    switch ($section) {    switch ($path) {
50      case 'admin/modules#description':      case 'admin/content/copyright':
       return t('Site-wide and node-specific copyright management.');  
   
     case 'admin/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).');        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/copyright/add':      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'));        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':      case 'admin/help#copyright':
57        return t('<h3>Copyright and licenses</h3>        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>  <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>  <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>  <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>  <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>  <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>  <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' => theme('placeholder', variable_get('site_name', ''))));  <dt>@source_url</dt><dd>URL to the full license text</dd></dl>', array('%site_name' => variable_get('site_name', 'Drupal')));
65    }    }
66  }  }
67    
# Line 83  function copyright_perm() { Line 75  function copyright_perm() {
75  /**  /**
76   * Implementation of hook_menu().   * Implementation of hook_menu().
77   */   */
78  function copyright_menu($may_cache) {  function copyright_menu() {
79    $items = array();    $items = array();
80    
81    if ($may_cache) {    $items['admin/content/copyright'] = array(
82      $items[] = array(      'title' => 'Copyright',
83        'path' => 'admin/copyright',      'description' => 'Create and manage different copyrights and licenses that users can use.',
84        'title' => t('copyright'),      'page callback' => 'drupal_get_form',
85        'callback' => 'copyright_admin',      'page arguments' => array('copyright_list'),
86        'access' => user_access('administer copyright'),      'access callback' => 'user_access',
87      );      'access arguments' => array('administer copyright'),
88      $items[] = array(      'file' => 'copyright.admin.inc',
89        'path' => 'admin/copyright/list',    );
90        'title' => t('list'),  
91        'type' => MENU_DEFAULT_LOCAL_TASK,    $items['admin/content/copyright/list'] = array(
92        'access' => user_access('administer copyright'),      'title' => 'List',
93      );      'type' => MENU_DEFAULT_LOCAL_TASK,
94      $items[] = array(      'weight' => -10,
95        'path' => 'admin/copyright/add',    );
96        'title' => t('add'),  
97        'weight' => 10,    $items['admin/content/copyright/add'] = array(
98        'type' => MENU_LOCAL_TASK,      'title' => 'Add copyright',
99        'access' => user_access('administer copyright'),      'type' => MENU_LOCAL_TASK,
100      );      'weight' => 0,
101      $items[] = array(      'page callback' => 'drupal_get_form',
102        'path' => 'admin/copyright/edit',      'page arguments' => array('copyright_add'),
103        'title' => t('edit copyright'),      'access callback' => 'user_access',
104        'type' => MENU_CALLBACK,      'access arguments' => array('administer copyright'),
105        'access' => user_access('administer copyright'),      'file' => 'copyright.admin.inc',
106      );    );
107      $items[] = array(  
108        'path' => 'admin/copyright/delete',    $items['admin/content/copyright/%copyright/edit'] = array(
109        'title' => t('delete copyright'),      'title' => 'Edit',
110        'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
111        'access' => user_access('administer copyright'),      'page callback' => 'drupal_get_form',
112      );      'page arguments' => array('copyright_edit', 3),
113        'access callback' => 'user_access',
114      $paths = copyright_get_license_local_paths();      'access arguments' => array('administer copyright'),
115      foreach ($paths as $path) {      'file' => 'copyright.admin.inc',
116        $items[] = array(    );
117          'path' => $path->source_url,  
118          'title' => t($path->name),    $items['admin/content/copyright/%copyright/delete'] = array(
119          'type' => MENU_CALLBACK,      'title' => 'Delete',
120          'callback' => 'copyright_show_license',      'type' => MENU_CALLBACK,
121          'callback arguments' => array($path->cpyid),      'page callback' => 'drupal_get_form',
122          'access' => user_access('access content'),      'page arguments' => array('copyright_delete', 3),
123        );      'access callback' => 'user_access',
124      }      'access arguments' => array('administer copyright'),
125    }      'file' => 'copyright.admin.inc',
126    else {    );
     theme_add_style(drupal_get_path('module', 'copyright') . '/copyright.css');  
   }  
127    
128    return $items;    return $items;
129  }  }
# Line 159  function copyright_block($op = 'list', $ Line 149  function copyright_block($op = 'list', $
149      }      }
150    
151      if ($license) {      if ($license) {
152          drupal_add_css(drupal_get_path('module', 'copyright') .'/copyright.css');
153        return array(        return array(
154          'subject' => t('Copyright'),          'subject' => t('Copyright'),
155          'content' => theme('copyright_block', copyright_notice($license)),          'content' => theme('copyright_block', copyright_notice($license)),
# Line 167  function copyright_block($op = 'list', $ Line 158  function copyright_block($op = 'list', $
158    }    }
159  }  }
160    
161  /******************************************************************  /**
162   * Menu callback: admin/copyright/* switch.   * Implementation of hook_theme().
163   ******************************************************************/   */
164    function copyright_theme() {
165  function copyright_admin($op = 'list', $cpyid = NULL) {    return array(
166    switch ($op) {      'copyright_footer' => array(
167      case 'edit':        'arguments' => array(
168        if (isset($cpyid) && is_numeric($cpyid)) {          'license' => NULL,
169          $edit = (array) copyright_get_license($cpyid);        ),
170        }      ),
171        //fall-through      'copyright_block' => array(
172      case 'add':        'arguments' => array(
173        $edit = (isset($edit) ? $edit : array());          'license' => NULL,
174        $form = copyright_edit_license_form($edit);        ),
175        return drupal_get_form('copyright_edit_license', $form);      ),
   
     case 'list':  
       return copyright_admin_overview();  
   
     case 'delete':  
       return copyright_admin_delete($cpyid);  
   }  
   return drupal_not_found();  
 }  
   
   
 /******************************************************************  
  * Menu callback: admin/copyright/add and admin/copyright/edit.  
  ******************************************************************/  
   
 function copyright_edit_license_form($edit = array()) {  
   $form = array();  
   
   $form['name'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Copyright or license name'),  
     '#default_value' => $edit['name'],  
     '#maxlength' => 60,  
     '#description' => t('Short name'),  
     '#required' => TRUE,  
   );  
   $form['description'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Description'),  
     '#default_value' => $edit['description'],  
     '#maxlength' => 255,  
     '#description' => t('Longer description'),  
   );  
   $form['image_url'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Image URL'),  
     '#default_value' => $edit['image_url'],  
     '#maxlength' => 255,  
     '#description' => ('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.'),  
   );  
   $form['source_url'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Source URL'),  
     '#default_value' => $edit['source_url'],  
     '#maxlength' => 255,  
     '#description' => ('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").'),  
   );  
   $form['site_notice'] = array(  
     '#type' => 'textarea',  
     '#title' => t('Site notice'),  
     '#default_value' => $edit['site_notice'],  
     '#rows' => 5,  
     '#description' => t('Notice displayed for entire site (in footer or block). HTML is allowed and variables include %year, %site, and %source_url.'),  
     '#required' => TRUE,  
   );  
   $form['node_notice'] = array(  
     '#type' => 'textarea',  
     '#title' => t('Node notice'),  
     '#default_value' => $edit['node_notice'],  
     '#rows' => 5,  
     '#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.'),  
     '#required' => TRUE,  
   );  
   $form['license'] = array(  
     '#type' => 'textarea',  
     '#title' => t('Full copyright or license'),  
     '#default_value' => $edit['license'],  
     '#rows' => 20,  
     '#description' => t('The complete text or HTML of the copyright or license. Leave empty to use Source URL (above).'),  
176    );    );
177    }
178    
179    $form['submit'] = array(  /**
180      '#type' => 'submit',   * Implementation of hook_user().
181      '#value' => t('Submit'),   */
182    );  function copyright_user($op, &$edit, &$account, $category = NULL) {
183    if ($edit['cpyid']) {    switch ($op) {
184      if ($edit['cpyid'] != variable_get('copyright-default', 1)) {      case 'categories':
185        $form['delete'] = array(        $items = array();
186          '#type' => 'submit',        $items[] = array(
187          '#value' => t('Delete'),          'name' => 'copyright',
188            'title' => t('License'),
189            'weight' => 5,
190        );        );
191      }        return $items;
     $form['cpyid'] = array(  
       '#type' => 'hidden',  
       '#value' => $edit['cpyid'],  
     );  
   }  
192    
193    return $form;      case 'form':
194  }        $form = array();
195          if ($category == 'copyright') {
196  function copyright_edit_license_submit($form_id, $form_values) {          $default = copyright_user_get_default($account->uid);
197    $goto = 'admin/copyright/list';          $licenses = copyright_get_license_names();
198    
199    switch ($_POST['op'] && user_access('administer copyright')) {          $form['copyright_user_default'] = array(
200      case t('Submit'):            '#type' => 'radios',
201        if (isset($form_values['cpyid'])) {            '#title' => t('Default license'),
202          $cpyid = $form_values['cpyid'];            '#options' => $licenses,
203          _copyright_db_update_copyright($form_values);            '#default_value' => $default,
204          module_invoke_all('copyright', 'update', 'license', $form_values);          );
         $message = t('Updated copyright %name.', array('%name' => theme('placeholder', $form_values['name'])));  
       }  
       else {  
         $cpyid = db_next_id('{copyrights}_cpyid');  
         $form_values['cpyid'] = $cpyid;  
         _copyright_db_insert_copyright($form_values);  
         module_invoke_all('copyright', 'insert', 'license', $edit);  
         $message = t('Created new copyright %name.', array('%name' => theme('placeholder', $form_values['name'])));  
205        }        }
206        cache_clear_all();        return $form;
       break;  
207    
208      case t('Delete'):      case 'delete':
209        $goto = 'admin/copyright/delete/' . $form_values['cpyid'];        copyright_user_del_default($account->uid);
210        break;        break;
   }  
   
   if ($message) {  
     drupal_set_message($message);  
   }  
   
   return $goto;  
 }  
   
 /******************************************************************  
  * Menu callback: admin/copyright/delete.  
  ******************************************************************/  
211    
212  function copyright_admin_delete($cpyid) {      case 'insert':
213    if (user_access('administer copyright')) {      case 'update':
214      if (is_numeric($cpyid) && $license = copyright_get_license($cpyid)) {        copyright_user_set_default($account->uid, $edit['copyright_user_default']);
215        if (variable_get('copyright-default', 1) == $cpyid) {        $edit['copyright_user_default'] = NULL;
216          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' => theme('placeholder', $license->name), '%overview-url' => url('admin/copyright/list')));        break;
       }  
       else {  
         $form = array();  
         $form['cpyid'] = array(  
           '#type' => 'value',  
           '#value' => $cpyid,  
         );  
         $form['license'] = array(  
           '#type' => 'value',  
           '#value' => $license,  
         );  
         return confirm_form('copyright_admin_delete', $form, t('Are you sure you want to delete %title?', array('%title' => theme('placeholder', $license->name))), $_GET['destination'] ? $_GET['destination'] : 'admin/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'));  
       }  
     }  
     return drupal_not_found();  
   }  
   return drupal_access_denied();  
 }  
   
 function copyright_admin_delete_submit($form_id, $form_values) {  
   if ($form_values['confirm']) {  
     $license = $form_values['license'];  
     db_query("DELETE FROM {copyrights} WHERE cpyid = %d", $license->cpyid);  
     db_query("DELETE FROM {copyright_node} WHERE cpyid = %d", $license->cpyid);  
     cache_clear_all();  
     drupal_set_message(t('Deleted copyright "%name". All nodes set to that copyright have been set back to the site default.', array('%name' => theme('placeholder', $license->name))));  
217    }    }
   return 'admin/copyright/list';  
218  }  }
219    
220  /******************************************************************  /**
221   * Menu callback: admin/copyright/list.   * Implementation of hook_node_operations().
222   ******************************************************************/   */
223    function copyright_node_operations() {
224  function copyright_admin_overview() {    $operations = array();
225    foreach (copyright_get_licenses() as $license) {    foreach (copyright_get_license_names() as $cpyid => $license) {
226      $default = ($license->cpyid == variable_get('copyright-default', 1));      $operations[] = array(
227      $form[$license->name] = array(        'label' => t('Assign @name license', array('@name' => $license)),
228        '#type' => 'item',        'callback' => 'copyright_assign_license',
229        '#title' => $license->name,        'callback arguments' => array($cpyid),
       '#description' => $license->description,  
     );  
     $form[$license->name]['cpyid'] = array(  
       '#type' => 'hidden',  
       '#value' => $license->cpyid,  
     );  
     $operations = l(t('edit'), 'admin/copyright/edit/'. $license->cpyid);  
     $operations .= $default ? '' : ' '. l(t('delete'), 'admin/copyright/delete/'. $license->cpyid);  
     $form[$license->name]['operations'] = array(  
       '#value' => $operations,  
230      );      );
     $options[$license->cpyid] = $license->name;  
231    }    }
232    $form['default'] = array(    return $operations;
     '#type' => 'radios',  
     '#options' => $options,  
     '#default_value' => variable_get('copyright-default', 1),  
   );  
   
   $form['submit'] = array(  
     '#type' => 'submit',  
     '#value' => t('Set default copyright'),  
   );  
   return drupal_get_form('copyright_admin_overview', $form);  
233  }  }
234    
235  function copyright_admin_overview_submit($form_id, $form_values) {  /**
236    if (is_numeric($form_values['default'])) {   * Implementation of hook_node_type().
237      drupal_set_message(t('Default site-wide copyright updated.'));   */
238      variable_set('copyright-default', $form_values['default']);  function copyright_node_type($op, $info) {
239    }    switch ($op) {
240  }      case 'delete':
241          variable_del('copyright-enable_'. $info->type);
242          break;
243    
244  function theme_copyright_admin_overview($form) {      case 'update':
245    $rows = array();        if (!empty($info->old_type) && $info->old_type != $info->type) {
246    foreach (element_children($form) as $name) {          $setting = variable_get('copyright-enable_'. $info->old_type, 0);
247      $element = $form[$name];          variable_del('copyright-enable_'. $info->old_type);
248      if (isset($element['operations'])) {          variable_set('copyright-enable_'. $info->type, $setting);
249        $form['default'][$element['cpyid']['#value']]['#title'] = '';        }
250        $rows[] = array(        break;
         form_render($form['default'][$element['cpyid']['#value']]),  
         check_plain($name),  
         form_render($element['operations']),  
       );  
       unset($form[$name]);  
     }  
251    }    }
   $header = array(t('Default'), t('Name'), t('Operations'));  
   $output = theme('table', $header, $rows);  
   $output .= form_render($form);  
   return $output;  
252  }  }
253    
 /******************************************************************  
  * Copyright/license node association.  
  ******************************************************************/  
   
254  /**  /**
255   * Implementation of hook_nodeapi().   * Implementation of hook_nodeapi().
256   */   */
257  function copyright_nodeapi(&$node, $op, $arg = 0) {  function copyright_nodeapi(&$node, $op, $arg = 0) {
258    if (variable_get('copyright-enable-'. $node->type, 0)) {    if (variable_get('copyright-enable_'. $node->type, 0)) {
259      switch ($op) {      switch ($op) {
260        case 'view':        case 'view':
261          $node_license = copyright_get_node_license($node->nid);          $node_license = copyright_get_node_license($node->nid);
# Line 424  function copyright_nodeapi(&$node, $op, Line 263  function copyright_nodeapi(&$node, $op,
263            // $node->parent set at node load time by book.module            // $node->parent set at node load time by book.module
264            $node_license = copyright_parent_node($node->parent);            $node_license = copyright_parent_node($node->parent);
265          }          }
266          if ($node_license) {          if ($node_license && $node_license->cpyid != variable_get('copyright-default', 1)) {
267            // The node has a license other than the site's default            // The node has a license other than the site's default
268            $license = copyright_get_license($node_license->cpyid);            $license = copyright_get_license($node_license->cpyid);
269            $node->body .= theme('copyright_footer', copyright_notice($license, $node, $node_license));            $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;          break;
276    
277        case 'insert':        case 'insert':
278        case 'update':        case 'update':
279          copyright_node_save($node->nid, $node->cpyid, $node->copyright_show_children, $node->original_author, $node->copyright_children_allow_set);          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;          break;
283    
284        case 'delete':        case 'delete':
# Line 456  function copyright_nodeapi(&$node, $op, Line 301  function copyright_nodeapi(&$node, $op,
301   * - add copyright select box to node edit forms if enabled,   * - add copyright select box to node edit forms if enabled,
302   * - add enable/disable copyright to node workflow settings.   * - add enable/disable copyright to node workflow settings.
303   */   */
304  function copyright_form_alter($form_id, &$form) {  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'])) {    if (isset($form['type'])) {
317      $type = $form['type']['#value'];      $node = $form['#node'];
318        $type = $node->type;
319    
320      // Extending node edit forms.      // Extending node edit forms.
321      if ($form_id == $type .'_node_form' && variable_get('copyright-enable-'. $type, FALSE)) {      if ($form_id == $type .'_node_form' && variable_get('copyright-enable_'. $type, FALSE)) {
322        global $user;        global $user;
       $node = $form['#node'];  
323    
324        if (($user->uid == $node->uid || user_access('administer copyright')) &&        if (($user->uid == $node->uid || user_access('administer copyright')) &&
325            (!$node->parent ||copyright_parent_allow($node->parent))) {            (!$node->parent || copyright_parent_allow($node->parent))) {
326          $licenses = copyright_get_license_names();          $licenses = copyright_get_license_names();
327          $default =  variable_get('copyright-default', 1);          $site_default = variable_get('copyright-default', 1);
328          $licenses[$default] .= ' (Site default)';          $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) {          if ($node->cpyid) {
348            $selected_cpyid = $node->cpyid;            $selected_cpyid = $node->cpyid;
# Line 479  function copyright_form_alter($form_id, Line 352  function copyright_form_alter($form_id,
352            $selected_cpyid = $node_license->cpyid;            $selected_cpyid = $node_license->cpyid;
353            $author = $node_license->original_author;            $author = $node_license->original_author;
354          }          }
355            else if ($user_default) {
356              $selected_cpyid = $user_default;
357              $author = '';
358            }
359          else {          else {
360            $selected_cpyid = $default;            $selected_cpyid = $site_default;
361            $author = '';            $author = '';
362          }          }
363    
# Line 519  function copyright_form_alter($form_id, Line 396  function copyright_form_alter($form_id,
396          }          }
397        }        }
398      }      }
     // Extending content type workflow.  
     else if ($type .'_node_settings' == $form_id) {  
       $form['workflow']['copyright-enable-'. $type] = array(  
         '#type' => 'radios',  
         '#title' => t('Allow copyright selection'),  
         '#default_value' => variable_get('copyright-enable-'. $type, 0),  
         '#options' => array(t('Disabled'), t('Enabled')),  
         '#description' => t('Enable the copyright selection for individual nodes of this content type.'),  
       );  
     }  
399    }    }
400    return $form;    return $form;
401  }  }
# Line 554  function copyright_node_save($nid, $cpyi Line 421  function copyright_node_save($nid, $cpyi
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.   * Remove associations of a node to its copyright.
434   */   */
435  function copyright_node_delete($nid) {  function copyright_node_delete($nid) {
# Line 568  function copyright_node_delete($nid) { Line 444  function copyright_node_delete($nid) {
444   * Return an array of all copyrights/licenses (cpyid and name only)   * Return an array of all copyrights/licenses (cpyid and name only)
445   */   */
446  function copyright_get_license_names() {  function copyright_get_license_names() {
447    $result = db_query("SELECT cpyid, name FROM {copyrights} ORDER BY name");    static $licenses;
448    $licenses = array();    if (!isset($licenses)) {
449    while ($license = db_fetch_object($result)) {      $result = db_query("SELECT cpyid, name FROM {copyrights} ORDER BY name");
450      $licenses[$license->cpyid] = $license->name;      $licenses = array();
451        while ($license = db_fetch_object($result)) {
452          $licenses[$license->cpyid] = $license->name;
453        }
454    }    }
455    return $licenses;    return $licenses;
456  }  }
# Line 673  function copyright_parent_allow($nid_par Line 552  function copyright_parent_allow($nid_par
552    return TRUE;    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).   * Display functions (output text and themes).
582   ******************************************************************/   ******************************************************************/
# Line 698  function copyright_notice($license, $nod Line 602  function copyright_notice($license, $nod
602    }    }
603    
604    $placeholders = array(    $placeholders = array(
605      '%year' => $year,      '@year' => $year,
606      '%author' => $author,      '@author' => $author,
607      '%site' => variable_get('site_name', ''),      '@site' => variable_get('site_name', 'Drupal'),
608      '%source_url' => $license->source_url,      '@source_url' => $license->source_url,
609    );    );
610    
611    $img = '';    $img = '';
# Line 755  function _copyright_db_insert_copyright( Line 659  function _copyright_db_insert_copyright(
659  function _copyright_db_update_copyright($edit) {  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']);    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    

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.2