? .discussthis.module.swp ? discussthis_6.patch Index: discussthis.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/discussthis/discussthis.info,v retrieving revision 1.2 diff -u -p -r1.2 discussthis.info --- discussthis.info 24 Jun 2008 01:05:27 -0000 1.2 +++ discussthis.info 21 Sep 2008 10:00:56 -0000 @@ -1,4 +1,7 @@ ; $Id: discussthis.info,v 1.2 2008/06/24 01:05:27 spiderman Exp $ name = Discuss This description = "Adds discuss this links to a forum topic for specific node types" -dependencies = forum token +dependencies[] = forum +dependencies[] = token +version = 6.x-0.1-alpha +core = 6.x Index: discussthis.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/discussthis/discussthis.install,v retrieving revision 1.1 diff -u -p -r1.1 discussthis.install --- discussthis.install 19 Jun 2008 22:00:41 -0000 1.1 +++ discussthis.install 21 Sep 2008 10:00:56 -0000 @@ -7,40 +7,51 @@ * nid->forum(tid) mapping. **/ function discussthis_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {discussthis} ( - nid int unsigned NOT NULL default '0', - topic_nid int unsigned NOT NULL default '0', - PRIMARY KEY (nid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); - - db_query("CREATE TABLE {discussthis_forums} ( - nid int unsigned NOT NULL default '0', - forum_tid int unsigned NOT NULL default '0', - PRIMARY KEY (nid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); - - drupal_set_message(t("Discuss This! module installed. Configure !perm and !settings to continue", array('!perm' => l('Administer > User > Access Control','admin/user/access'), '!settings' => l('Administer > Site Configuration > Discuss This', 'admin/settings/discussthis')))); - break; - case 'pgsql': // someone else? - break; - } + drupal_install_schema('discussthis'); + drupal_set_message(t("Discuss This! module installed. Configure !perm and !settings to continue", array('!perm' => l('Administer > User > Access Control','admin/user/access'), '!settings' => l('Administer > Site Configuration > Discuss This', 'admin/settings/discussthis')))); } -function discussthis_update_1() { - $ret = array(); - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql("CREATE TABLE {discussthis_forums} ( - nid int unsigned NOT NULL default '0', - forum_tid int unsigned NOT NULL default '0', - PRIMARY KEY (nid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); - } - return $ret; +/** + * Implementation of hook_schema(). + * @see hook_schema + */ +function discussthis_schema(){ + $schema['discussthis'] = array( + 'fields' => array( + 'nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => '0' + ), + 'topic_nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => '0' + ), + ), + 'primary key' => array('nid') + ); + $schema['discussthis_forums'] = array( + 'fields' => array( + 'nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => '0' + ), + 'forum_tid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => '0' + ), + ), + 'primary key' => array('nid') + ); + + return $schema; } /** @@ -51,4 +62,3 @@ function discussthis_uninstall() { db_query('DROP TABLE {discussthis_forums'); // variable_del('discussthis_nodetypes') } - Index: discussthis.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/discussthis/discussthis.module,v retrieving revision 1.7 diff -u -p -r1.7 discussthis.module --- discussthis.module 25 Jun 2008 14:20:44 -0000 1.7 +++ discussthis.module 21 Sep 2008 10:00:57 -0000 @@ -8,13 +8,13 @@ * @param section which section of the site we're displaying help for * @return help text for section **/ -function discussthis_help($section='') { +function discussthis_help($section = '') { $output = ''; switch ($section) { case 'admin/help#discussthis': $output = '

'. t('Displays links to discussion forums for a given node. Administrators can select the types of nodes for which this is enabled, and for each of these, which forum new topics should be created in.') .'

'; - $output .= filter_filter('process', 2, null, file_get_contents(dirname(__FILE__) .'/README.txt') ); + $output .= filter_filter('process', 2, null, file_get_contents(dirname(__FILE__) .'/README.txt')); break; } @@ -34,31 +34,30 @@ function discussthis_perm() { * @param may_cache whether the menu items might be cached * @return array list of menu items **/ -function discussthis_menu($may_cache) { +function discussthis_menu() { $items = array(); - if (!$may_cache) { - $items[] = array( - 'path' => 'admin/settings/discussthis', - 'title' => t('Discuss This'), - 'description' => t('Configure discuss this module defaults, including what node types and what forums to link to.'), - 'callback' => 'drupal_get_form', - 'callback arguments' => 'discussthis_admin', - 'access' => user_access('administer discuss this'), - 'type' => MENU_NORMAL_ITEM, - ); - $items[] = array( - 'path' => 'discussthis/new', - 'callback' => 'discussthis_new', - 'access' => user_access('access discuss this links'), - 'type' => MENU_CALLBACK, - ); - $items[] = array('path' => 'discussthis/autocomplete', - 'title' => t('Autocomplete forum topics'), - 'callback' => 'discussthis_autocomplete', - 'access' => user_access('access content'), - 'type' => MENU_CALLBACK); - } + $items['admin/settings/discussthis'] = array( + 'title' => t('Discuss This'), + 'description' => t('Configure discuss this module defaults, including what node types and what forums to link to.'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('discussthis_admin'), + 'access arguments' => array('administer discuss this'), + 'type' => MENU_NORMAL_ITEM, + ); + + $items['discussthis/new'] = array( + 'page callback' => 'discussthis_new', + 'access arguments' => array('access discuss this links'), + 'type' => MENU_CALLBACK, + ); + + $items['discussthis/autocomplete'] = array( + 'title' => t('Autocomplete forum topics'), + 'page callback' => 'discussthis_autocomplete', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK + ); return $items; } @@ -102,17 +101,17 @@ function discussthis_nodeapi(&$node, $op $topic_nid = _discussthis_get_topic($node->nid); // lookup a nid for the topic, if it exists (otherwise 0) # grab X most recent comments, and attach them to the node: - $result = db_query_range('SELECT c.nid, c.uid, c.name, c.subject, c.cid, c.timestamp FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid WHERE c.nid = %d AND n.status = 1 AND c.status = %d ORDER BY c.cid DESC', $topic_nid, COMMENT_PUBLISHED, 0, variable_get('discussthis_comments',10)); + $result = db_query_range('SELECT c.nid, c.uid, c.name, c.subject, c.cid, c.timestamp FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid WHERE c.nid = %d AND n.status = 1 AND c.status = %d ORDER BY c.cid DESC', $topic_nid, COMMENT_PUBLISHED, 0, variable_get('discussthis_comments', 10)); while ($comment = db_fetch_object($result)) { - $comments[] = theme('discussthis_comment',$topic_nid,$comment); + $comments[] = theme('discussthis_comment', $topic_nid, $comment); } - $node->content['discussthis_comments'] = array( - '#value' => theme('item_list',$comments), - '#weight' => 50, - ); - } + $node->content['discussthis_comments'] = array( + '#value' => theme('item_list', $comments), + '#weight' => 50, + ); + } break; case 'load': // return array of fields => values to be merged into $node @@ -171,7 +170,7 @@ function discussthis_link($type, $node = * @param form_id the id of the form to be altered * @param form the form itself **/ -function discussthis_form_alter($form_id, &$form) { +function discussthis_form_alter(&$form, $form_state, $form_id) { // We're only modifying node forms, if the type field isn't set we don't need // to bother; otherwise, store it for later retrieval. if (isset($form['type'])) { @@ -185,7 +184,9 @@ function discussthis_form_alter($form_id } # only modify the form if this node type is discussthis-enabled - if (!variable_get('discussthis_node_'.$type,0)) { return; } + if (!variable_get('discussthis_node_'. $type, 0)) { + return; + } // The discuss this link is enabled on a per node type basis. The variable used to store // this information is named using both the name of this module, to avoid namespace @@ -203,7 +204,9 @@ function discussthis_form_alter($form_id if ($forum_tid && user_access('override discuss this forums')) { $forums = forum_get_forums(); foreach ($forums as $tid => $forum) { - if (!$forum->container) { $discussthis_forums[$tid] = $forum->name; } + if (!$forum->container) { + $discussthis_forums[$tid] = $forum->name; + } } $form['discussthis'] = array( @@ -237,22 +240,42 @@ function discussthis_form_alter($form_id } } +//function theme_discussthis_comment($topic_nid,$comment) { +/** + * Implementation of hook_theme(). + * @see hook_theme + */ +function discussthis_theme() { + return array( + 'discussthis_comment' => array( + 'arguments' => array( + 'topic_nid' => 0, + 'comment' => NULL + ), + ), + ); +} + /** * Generate HTML for the discussthis block * @param op the operation from the URL * @param delta offset * @returns block HTML */ -function discussthis_block($op='list', $delta=0) { +function discussthis_block($op = 'list', $delta = 0, $edit = array()) { if ($op == 'list') { - $block[0]['info'] = t('Discuss This'); - return $block; + $blocks[0]['info'] = t('Discuss This'); + // recent comments are per forum topic -> per page + $blocks[0]['cache'] = BLOCK_CACHE_PER_PAGE; + return $blocks; } else if ($op == 'view') { - // show a list of recent comments in the relevant discussion topic for this node - $block['subject'] = t('Discuss This!'); - $block['content'] = ''; - return $block; + if ($delta == 0) { + // show a list of recent comments in the relevant discussion topic for this node + $block['subject'] = t('Discuss This!'); + $block['content'] = ''; + return $block; + } } } @@ -282,7 +305,7 @@ function discussthis_token_values($type, if ($type == 'discussthis') { $tokens['node-link'] = l(t($object->title), 'node/'. $object->nid); $tokens['node-title'] = t($object->title); - $tokens['node-type-name'] = node_get_types('name',$object); + $tokens['node-type-name'] = node_get_types('name', $object); $tokens['node-type'] = $object->type; return $tokens; } @@ -326,8 +349,8 @@ function discussthis_admin() { $form['discussthis_newtemplate'] = array( '#type' => 'textarea', '#title' => t('Template for auto-created Forum discussions'), - '#description' => theme('token_help','discussthis'), - '#default_value' => variable_get('discussthis_newtemplate',$default_body), + '#description' => theme('token_help', 'discussthis'), + '#default_value' => variable_get('discussthis_newtemplate', $default_body), '#weight' => -2, ); @@ -335,7 +358,7 @@ function discussthis_admin() { '#type' => 'select', '#title' => t('How many recent comments should be displayed with non-teaser node view?'), '#options' => array(1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 10 => '10'), - '#default_value' => variable_get('discussthis_comments',10), + '#default_value' => variable_get('discussthis_comments', 10), ); $form['discussthis_nodetypes'] = array( @@ -349,7 +372,9 @@ function discussthis_admin() { $forums = forum_get_forums(); $discussthis_forums = array('0' => '-- select --'); foreach ($forums as $tid => $forum) { - if (!$forum->container) { $discussthis_forums[$tid] = $forum->name; } + if (!$forum->container) { + $discussthis_forums[$tid] = $forum->name; + } } // This should probably be within the node type config page, or else use some AJAXy thing to update @@ -437,10 +462,14 @@ function _discussthis_set_forum($nid, $t **/ function _discussthis_get_topic($nid) { // lookup the nid in the db table, and return it's corresponding forum topic nid, otherwise 0 - $sql = 'SELECT topic_nid FROM {discussthis} WHERE nid=%d'; + $sql = 'SELECT topic_nid FROM {discussthis} WHERE nid = %d'; $topic = db_result(db_query($sql, $nid)); - if ($topic) { return $topic; } - else { return 0; } + if ($topic) { + return $topic; + } + else { + return 0; + } } /** @@ -478,11 +507,11 @@ function _discussthis_new_topic($nid) { $newnode = array('type' => 'forum'); $values = array(); $values['name'] = variable_get('discussthis_author', $admin->name); - $values['title'] = token_replace(variable_get('discussthis_newsubject','[node-title]'), 'discussthis', $node); + $values['title'] = token_replace(variable_get('discussthis_newsubject', '[node-title]'), 'discussthis', $node); $default_body = 'Following is a discussion on the [node-type-name] item titled: [node-link]'. '.
Below is the discussion so far. Feel free to add your own comments!
'; - $values['body'] = token_replace(variable_get('discussthis_newtemplate',$default_body), 'discussthis', $node); + $values['body'] = token_replace(variable_get('discussthis_newtemplate', $default_body), 'discussthis', $node); $values['taxonomy'][1] = $tid; $values['status'] = 1; @@ -511,9 +540,9 @@ function _discussthis_new_topic($nid) { // Theme Functions -function theme_discussthis_comment($topic_nid,$comment) { +function theme_discussthis_comment($topic_nid, $comment) { $output = "
\n"; - $output .= ' '. l($comment->subject, 'node/'. $topic_nid, null, null, "comment-$comment->cid") .' '; + $output .= ' '. l($comment->subject, 'node/'. $topic_nid, array(), null, "comment-$comment->cid") .' '; $output .= ''. t('by') .' '. theme('username', $comment) ."\n"; $output .= "
\n"; return $output;