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

Diff of /contributions/modules/authorship/authorship.module

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

revision 1.4.2.3, Thu Jul 12 21:58:26 2007 UTC revision 1.4.2.4, Thu Jul 12 22:05:55 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: authorship.module,v 1.4.2.2 2007/06/29 11:04:51 karpuz Exp $  // $Id: authorship.module,v 1.4.2.3 2007/07/12 21:58:26 karpuz Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 58  function authorship_form_alter($form_id, Line 58  function authorship_form_alter($form_id,
58        '#title' => t('The profile variable name used to store the real name'),        '#title' => t('The profile variable name used to store the real name'),
59        '#default_value' => variable_get('authorship_real_name_'. $form['#node_type']->type, 'profile_real_name_'. $form['#node_type']->type),        '#default_value' => variable_get('authorship_real_name_'. $form['#node_type']->type, 'profile_real_name_'. $form['#node_type']->type),
60        '#description' => t('Ensure the value entered here matches the variable '.        '#description' => t('Ensure the value entered here matches the variable '.
61                            'name that was given to the Real Name vlaue in the '.                            'name that was given to the Real Name value in the '.
62                            'profile module settings area.')                            'profile module settings area.')
63      );      );
64      $form['workflow']['authorship']['authorship'] = array(      $form['workflow']['authorship']['authorship'] = array(
# Line 84  function authorship_form_alter($form_id, Line 84  function authorship_form_alter($form_id,
84        }        }
85      }      }
86    }    }
87    
88      if(isset($form['#id']) && $form['#id'] == 'comment-form' ) {
89        if (variable_get('authorship_comment', 0)) {
90          $row = db_fetch_object(db_query("SELECT authorship FROM {node_authorship} WHERE nid = '%s'", $form['cid']['#value']));
91          $authorship = $row->authorship;
92    
93          if ($user->uid == 1 || user_access('admin authorship') || user_access('user use authorship')) {
94            $form['authoring'] = array(
95              '#type' => 'fieldset',
96              '#title' => t('Authoring information'),
97              '#weight' => 9,
98              '#collapsible' => TRUE,
99              '#collapsed' => FALSE,
100            );
101            $form['authoring']['authorship'] = array(
102              '#type' => 'textfield',
103              '#title' => t('Authorship display setting'),
104              '#default_value' => $authorship,
105              '#description' => t('The name to display as the submitter. '.
106                                  'Leave blank for normal operation')
107            );
108          }
109        }
110      }
111    
112      if(isset($form['#id']) && $form['#id'] == 'comment-admin-settings' ) {
113        $form['posting_settings']['authorship_real_name_comment'] = array(
114          '#type' => 'textfield',
115          '#title' => t('The profile variable name used to store the real name'),
116          '#default_value' => variable_get('authorship_real_name_comment', 'profile_real_name_comment'),
117          '#description' => t('Ensure the value entered here matches the variable '.
118                              'name that was given to the Real Name value in the '.
119                              'profile module settings area.')
120        );
121        $form['posting_settings']['authorship_comment'] = array(
122          '#type' => 'radios',
123          '#title' => t('Enable authorship module functionality'),
124          '#default_value' => variable_get('authorship_comment', 0),
125          '#options' => array(t('Disabled'), t('Enabled')),
126        );
127      }
128  }  }
129  /* }}} */  /* }}} */
130    
# Line 98  function authorship_nodeapi(&$node, $op, Line 139  function authorship_nodeapi(&$node, $op,
139    switch ($op) {    switch ($op) {
140      case 'load':      case 'load':
141        $sql = "SELECT authorship, profile_real_name ".        $sql = "SELECT authorship, profile_real_name ".
142               "FROM {node_authorship} WHERE nid = %d";               "FROM {node_authorship} WHERE nid = %d AND cid = 0";
143        $row = db_fetch_object(db_query($sql, $node->nid));        $row = db_fetch_object(db_query($sql, $node->nid));
144        $node->authorship = $row->authorship;        $node->authorship = $row->authorship;
145        $node->profile_real_name = $row->profile_real_name;        $node->profile_real_name = $row->profile_real_name;
# Line 106  function authorship_nodeapi(&$node, $op, Line 147  function authorship_nodeapi(&$node, $op,
147      case 'insert':      case 'insert':
148      case 'update':      case 'update':
149        db_query("DELETE FROM {node_authorship} WHERE nid = %d", $node->nid);        db_query("DELETE FROM {node_authorship} WHERE nid = %d", $node->nid);
150        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)",
151                 $node->nid, $node->authorship, $node->profile_real_name);                 $node->nid, $node->authorship, $node->profile_real_name);
152        break;        break;
153      case 'delete':      case 'delete':
# Line 129  function authorship_nodeapi(&$node, $op, Line 170  function authorship_nodeapi(&$node, $op,
170  }  }
171  /* }}} */  /* }}} */
172    
173    /* {{{ authorship_comment() */
174    /**
175     * Implementation of hook_comment()
176     */
177    function authorship_comment(&$comment, $op) {
178    //echo "$op <pre>"; print_r($comment); echo "</pre><hr/>";
179    
180      switch ($op) {
181        case 'insert':
182        case 'update':
183          db_query("DELETE FROM {node_authorship} WHERE cid = %d LIMIT 1", $comment['cid']);
184          if($comment['authorship'] != "" || $comment['profile_real_name'] != "") db_query("INSERT INTO {node_authorship} (nid, cid, authorship, profile_real_name) VALUES (%d, %d, '%s', %d)",
185                     $comment['nid'], $comment['cid'], $comment['authorship'], $comment['profile_real_name']);
186          break;
187        case 'delete':
188          db_query("DELETE FROM {node_authorship} WHERE cid = %d", $comment->cid);
189          break;
190        case 'view':
191          // no 'load' option for $op in hook_comment, therefore we get the authorship info from the DB here
192          if(!isset($comment->authorship) && $comment->cid != "" ) {
193            $sql = "SELECT authorship, profile_real_name ".
194                   "FROM {node_authorship} WHERE cid = %d";
195            $row = db_fetch_object(db_query($sql, $comment->cid));
196            $comment->authorship = $row->authorship;
197            $comment->profile_real_name = $row->profile_real_name;
198          }
199          $comment->type = 'comment';
200          if ($name_rewrite = _authorship_name_rewrite($comment)) {
201            $temp = $comment->name;
202            $comment->name = $name_rewrite;
203            $comment->authorship = $temp;
204          }
205          break; // end 'view'
206      } // end switch
207    }
208    /* }}} */
209    
210  /*=========================*/  /*=========================*/
211  /* Helper functions follow */  /* Helper functions follow */
212  /*=========================*/  /*=========================*/

Legend:
Removed from v.1.4.2.3  
changed lines
  Added in v.1.4.2.4

  ViewVC Help
Powered by ViewVC 1.1.2