diff --git nodeauthor.info nodeauthor.info index 5416915..6d88d18 100644 --- nodeauthor.info +++ nodeauthor.info @@ -1,4 +1,5 @@ ; $Id name = Nodeauthor description = A simple module that adds an 'About Author' field to the bottom of selected node types which can be populated by users when they edit their profile. -core = 6.x +core = 7.x +files[] = nodeauthor.module diff --git nodeauthor.module nodeauthor.module index 54b5a29..3765c2e 100644 --- nodeauthor.module +++ nodeauthor.module @@ -12,22 +12,42 @@ /** * Implementation of hook_help(). */ -function nodeauthor_help($section) { +function nodeauthor_help($path, $arg) { } /** - * Implementation of hook_perm(). + * Implementation of hook_permission(). */ -function nodeauthor_perm() { - return array("edit own info", "view author info"); +function nodeauthor_permission() { + return array( + 'edit own info' => array( + 'title' => t('Edit own NodeAuthor info'), + 'description' => t('The user will be able to edit her/his own NodeAuthor informations'), + ), + 'view author info' => array( + 'title' => t('View NodeAuthor info'), + 'description' => t('View the NodeAuthor informations'), + ), + ); } /** - * Implementation of hook_user(). + * Implementation of hook_user_form(). */ -function nodeauthor_user($op, &$edit, &$account, $category = NULL) { - if (($op == 'form') || ($op == 'register')) { +function nodeauthor_user_form(&$edit, &$account, $category = NULL) { + return _nodeauthor_user_form($account); +} + +/** + * Implementation of hook_user_register(). + */ +function nodeauthor_user_register(&$edit, &$account, $category = NULL) { + return _nodeauthor_user_form($account); +} + +function _nodeauthor_user_form($account) { + $form = array(); if (user_access('edit own info', $account)) { $form['userinfo'] = array( '#type' => 'fieldset', @@ -39,11 +59,10 @@ function nodeauthor_user($op, &$edit, &$account, $category = NULL) { $form['userinfo']['info'] = array( '#type' => 'textarea', '#title' => t('Short info'), - '#default_value' => $account->info, - '#description' => t('This info will be displayed in your content as "author information".') + '#default_value' => isset($account->info) ? $account->info : '', + '#description' => t('This info will be displayed in your content as "author information".'), + '#text_format' => isset($account->format) ? $account->format : FILTER_FORMAT_DEFAULT, ); - $form['userinfo']['format'] = filter_form($account->format); - } } return $form; } @@ -67,8 +86,8 @@ function nodeauthor_menu() { * Implementation of hook_settings(). */ function nodeauthor_admin_settings() { - $types = node_get_types(); - while(list($type, $type_name) = each($types)) { + $types = node_type_get_types(); + while (list($type, $type_name) = each($types)) { $options[$type] = $type_name->name; } @@ -101,20 +120,19 @@ function nodeauthor_admin_settings() { /** - * Implementation of hook_nodeapi(). + * Implementation of hook_node_alter(). */ -function nodeauthor_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { - switch ($op) { - case 'alter': +function nodeauthor_node_alter(&$node, $teaser = NULL, $page = NULL) { if (user_access("view author info")) { $allowed = variable_get('nodes_add_info', array()); if ($allowed[$node->type]) { - $user = user_load(array('uid' => $node->uid)); + $user = user_load($node->uid); if (!empty($user->info)) { // Display picture if enabled if (variable_get('showpicture', 0) && !empty($user->picture)) { $picture = $user->picture; - } else { + } + else { $picture = NULL; } $path = drupal_get_path('module', 'nodeauthor'); @@ -124,8 +142,6 @@ function nodeauthor_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { } } } - break; - } } /** * Implementation of hook_theme(). @@ -146,7 +162,7 @@ function nodeauthor_theme() { function theme_authorinfo($info, $picture) { $output = "
';