Index: copyright.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/copyright/Attic/copyright.module,v retrieving revision 1.13.4.13 diff -u -r1.13.4.13 copyright.module --- copyright.module 26 Feb 2007 10:44:52 -0000 1.13.4.13 +++ copyright.module 25 May 2007 19:41:36 -0000 @@ -491,7 +491,33 @@ (!$node->parent || copyright_parent_allow($node->parent))) { $licenses = copyright_get_license_names(); $default = variable_get('copyright-default', 1); - $licenses[$default] .= ' (Site default)'; + $user_default = copyright_get_user_default($user->uid); + + foreach($licenses as $cpyid => &$license) { // Figure out helper text for each license + $notices = array(); + if ($cpyid == $default) { + $notices[] = t('site default'); + } + if ($cpyid == $user_default) { + $notices[] = t('your default'); + } + if ($node->cpyid && $cpyid == $node->cpyid) { + $notices[] = t('current license'); + } + + if ($notices) { + $license .= ' ('; + + foreach($notices as $key => $notice) { // Iterate through the accumulated notices and add the text + $license .= $notice; + if ($key < (count($notices) - 1)) { + $license .= ', '; + } + } + $license .= ')'; + } + } + if ($node->cpyid) { $selected_cpyid = $node->cpyid; @@ -501,6 +527,10 @@ $selected_cpyid = $node_license->cpyid; $author = $node_license->original_author; } + else if ($user_default) { + $selected_cpyid = $user_default; + $author = ''; + } else { $selected_cpyid = $default; $author = ''; @@ -768,3 +798,66 @@ 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']); } +/** + * Experimental implementation of hook_user(). + * + * Allows users to specify the default license for all their content. + */ + +function copyright_user($op = 'view', &$edit = NULL, &$account = NULL, $category = NULL) { + switch ($op) { + case 'categories': + $items[] = array('name' => 'copyright', + 'title' => t('License'), + 'weight' => 5); + return $items; + + case 'form': + if ($category == 'copyright') { + $default = copyright_get_user_default($account->uid); + $licenses = copyright_get_license_names(); + + $form['copyright_user'] = array( + '#type' => 'fieldset', + '#title' => 'Default license', + ); + $form['copyright_user']['copyright_user_default'] = array( + '#title' => t('Default license for your journal entries'), + '#type' => 'radios', + '#default_value' => $default && array_key_exists($default, $licenses) ? $default : NULL, + '#options' => $licenses + ); + return $form; + } + + case 'insert': + break; + + case 'update': + if ($category == 'copyright') { + copyright_user_save($account->uid, $edit['copyright_user_default']); + } + break; + + } +} + +function copyright_user_save($uid, $cpyid) { + $old_default = copyright_get_user_default($uid); + + if ($old_default) { + $query = "UPDATE {copyright_user} SET cpyid = %d WHERE uid = %d"; + } + else { + $query = "INSERT INTO {copyright_user} (cpyid, uid) VALUES (%d, %d)"; + } + + return db_query($query, $cpyid, $uid); +} + +function copyright_get_user_default($uid = 0) { + $query = "SELECT cpyid from {copyright_user} WHERE uid = %d"; + $default = db_result(db_query($query, $uid)); + return $default ? $default : 0; +} +