--- D:/Install_files/Web/CMS/drupal-modules/authorship-original/authorship/authorship.module Tue Feb 06 20:46:20 2007 +++ D:/Install_files/Web/CMS/drupal-modules/authorship/authorship.module Tue Apr 10 15:16:06 2007 @@ -45,7 +45,7 @@ */ function authorship_form_alter($form_id, &$form) { global $user; - + _authorship_debug("authorship_form_alter(" . $form['#node']->nid . ")"); if ($form_id == 'node_type_form' && isset($form['#node_type'])) { @@ -58,7 +58,7 @@ '#title' => t('The profile variable name used to store the real name'), '#default_value' => variable_get('authorship_real_name_'. $form['#node_type']->type, 'profile_real_name_'. $form['#node_type']->type), '#description' => t('Ensure the value entered here matches the variable '. - 'name that was given to the Real Name vlaue in the '. + 'name that was given to the Real Name value in the '. 'profile module settings area.') ); $form['workflow']['authorship']['authorship'] = array( @@ -84,6 +84,47 @@ } } } + + if(isset($form['#id']) && $form['#id'] == 'comment-form' ) { + if (variable_get('authorship_comment', 0)) { + $row = db_fetch_object(db_query("SELECT authorship FROM {node_authorship} WHERE nid = '%s'", $form['cid']['#value'])); + $authorship = $row->authorship; + + if ($user->uid == 1 || user_access('admin authorship') || user_access('user use authorship')) { + $form['authoring'] = array( + '#type' => 'fieldset', + '#title' => t('Authoring information'), + '#weight' => 9, + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + $form['authoring']['authorship'] = array( + '#type' => 'textfield', + '#title' => t('Authorship display setting'), + '#default_value' => $authorship, + '#description' => t('The name to display as the submitter. '. + 'Leave blank for normal operation') + ); + } + } + } + + if(isset($form['#id']) && $form['#id'] == 'comment-admin-settings' ) { + $form['posting_settings']['authorship_real_name_comment'] = array( + '#type' => 'textfield', + '#title' => t('The profile variable name used to store the real name'), + '#default_value' => variable_get('authorship_real_name_comment', 'profile_real_name_comment'), + '#description' => t('Ensure the value entered here matches the variable '. + 'name that was given to the Real Name value in the '. + 'profile module settings area.') + ); + $form['posting_settings']['authorship_comment'] = array( + '#type' => 'radios', + '#title' => t('Enable authorship module functionality'), + '#default_value' => variable_get('authorship_comment', 0), + '#options' => array(t('Disabled'), t('Enabled')), + ); + } } /* }}} */ @@ -92,13 +133,13 @@ * Implementation of hook_nodeapi() */ function authorship_nodeapi(&$node, $op, $teaser, $page) { - + _authorship_debug("authorship_nodeapi(" . $node->nid . ", $op)"); switch ($op) { case 'load': $sql = "SELECT authorship, profile_real_name ". - "FROM {node_authorship} WHERE nid = %d"; + "FROM {node_authorship} WHERE nid = %d AND cid = 0"; $row = db_fetch_object(db_query($sql, $node->nid)); $node->authorship = $row->authorship; $node->profile_real_name = $row->profile_real_name; @@ -106,7 +147,7 @@ case 'insert': case 'update': db_query("DELETE FROM {node_authorship} WHERE nid = %d", $node->nid); - db_query("INSERT INTO {node_authorship} (nid, authorship, profile_real_name) VALUES (%d, '%s', %d)", + if($node->authorship != "" || $node->profile_real_name != "") db_query("INSERT INTO {node_authorship} (nid, authorship, profile_real_name) VALUES (%d, '%s', %d)", $node->nid, $node->authorship, $node->profile_real_name); break; case 'delete': @@ -123,6 +164,42 @@ break; // end 'view' } // end switch } + +/* {{{ authorship_comment() */ +/** + * Implementation of hook_comment() + */ +function authorship_comment(&$comment, $op) { +//echo "$op
"; print_r($comment); echo "

"; + + switch ($op) { + case 'insert': + case 'update': + db_query("DELETE FROM {node_authorship} WHERE cid = %d LIMIT 1", $comment['cid']); + if($comment['authorship'] != "" || $comment['profile_real_name'] != "") db_query("INSERT INTO {node_authorship} (nid, cid, authorship, profile_real_name) VALUES (%d, %d, '%s', %d)", + $comment['nid'], $comment['cid'], $comment['authorship'], $comment['profile_real_name']); + break; + case 'delete': + db_query("DELETE FROM {node_authorship} WHERE cid = %d", $comment->cid); + break; + case 'view': + // no 'load' option for $op in hook_comment, therefore we get the authorship info from the DB here + if(!isset($comment->authorship) && $comment->cid != "" ) { + $sql = "SELECT authorship, profile_real_name ". + "FROM {node_authorship} WHERE cid = %d"; + $row = db_fetch_object(db_query($sql, $comment->cid)); + $comment->authorship = $row->authorship; + $comment->profile_real_name = $row->profile_real_name; + } + $comment->type = 'comment'; + if ($name_rewrite = _authorship_name_rewrite($comment)) { + $temp = $comment->name; + $comment->name = $name_rewrite; + $comment->authorship = $temp; + } + break; // end 'view' + } // end switch +} /* }}} */ /*=========================*/ @@ -143,7 +220,7 @@ * false on no rewrite to take place */ function _authorship_name_rewrite($node) { - + //echo "nid $node->nid cid $node->cid uid $node->uid rewrite
"; $local_name_rewrite = FALSE; // prepare default is false if (!(int)variable_get('authorship_' . $node->type, 0)) { @@ -152,14 +229,14 @@ $node_user = user_load(array('uid' => $node->uid)); $field = variable_get('authorship_real_name_'. $node->type, 'profile_real_name_'. $node->type); - + //echo "node_user "; print_r($node_user); echo "
"; if (isset($node->authorship) && strlen($node->authorship) > 0) { $local_name_rewrite = $node->authorship; } elseif(isset($node_user->$field) && strlen($node_user->$field) > 0) { $local_name_rewrite = $node_user->$field; } - + return $local_name_rewrite; } /* }}} */