Index: workflow.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/workflow/workflow.module,v retrieving revision 1.54.2.6 diff -u -p -r1.54.2.6 workflow.module --- workflow.module 2 Mar 2007 20:51:57 -0000 1.54.2.6 +++ workflow.module 27 Dec 2007 15:35:37 -0000 @@ -1947,3 +1947,78 @@ function workflow_cron() { cache_clear_all(); } } + +/** + * Implementation of hook_token_values() + */ +function workflow_token_values($type, $object = NULL) { + if ($type == 'node' || $type == 'workflow') { + $node = (object)$object; + $wid = workflow_get_workflow_for_type($node->type); + } + switch ($type) { + + case "node": + + case 'workflow': + if ($wid) { + $values['workflow-name'] = workflow_get_name($wid); + } + + // cast to an object just in case fussy drupal gave us an array + $node = (object)$object; + + if ($wid) { + $states = workflow_get_states($wid); + } else { + break; + } + + $result = db_query_range("SELECT h.* FROM {workflow_node_history} h WHERE nid = %d ORDER BY stamp DESC",$node->nid,0,1); + + if ($row = db_fetch_object($result)) { + $account = user_load( array ('uid' => $row->uid)); + $comment = $row->comment; + } + + $values['workflow-current-state-name'] = $states[$row->sid]; + $values['workflow-old-state-name'] = $states[$row->old_sid]; + + $values['workflow-current-state-date-iso'] = date('Ymdhis',$row->stamp); + $values['workflow-current-state-date-tstamp'] = $row->stamp; + $values['workflow-current-state-date-formatted'] = date('M d, Y h:i:s', $row->stamp); + + $values['workflow-current-state-updating-user-name'] = $account->uid ? $account->name : variable_get('anonymous', 'Anonymous'); + $values['workflow-current-state-updating-user-uid'] = $account->uid; + $values['workflow-current-state-updating-user-mail'] = $account->uid ? $account->mail : ''; + + $values['workflow-current-state-log-entry'] = $row->comment; + break; + } + + return $values; +} + +/** + * Implementation of hook_token_list() + */ +function workflow_token_list($type = 'all') { + + if ($type == 'workflow' || $type == 'node' || $type == 'all') { + $tokens['workflow']['workflow-name'] = 'Name of workflow appied to this node'; + $tokens['workflow']['workflow-current-state-name'] = 'Current state of content'; + $tokens['workflow']['workflow-old-state-name'] = 'Old state of content'; + $tokens['workflow']['workflow-current-state-date-iso'] = 'Date of last state change (ISO)'; + $tokens['workflow']['workflow-current-state-date-tstamp'] = 'Date of last state change (timestamp)'; + $tokens['workflow']['workflow-current-state-date-formatted'] = 'Date of last state change (formated - M d, Y h:i:s)';; + + $tokens['workflow']['workflow-current-state-updating-user-name'] = 'Username of last state changer'; + $tokens['workflow']['workflow-current-state-updating-user-uid'] = 'uid of last state changer'; + $tokens['workflow']['workflow-current-state-updating-user-mail'] = 'email of last state changer'; + + $tokens['workflow']['workflow-current-state-log-entry'] = 'Last workflow comment log'; + $tokens['node'] = $tokens['workflow']; + } + + return $tokens; +}