From e9836b4d826acee030a4fb2e04859e70c1b33118 Mon Sep 17 00:00:00 2001 From: Shawn Kwang <kwangs@uwm.edu> Date: Wed, 5 Sep 2018 11:22:33 -0500 Subject: [PATCH 1/2] Drupal: Added boincuser_quote module. This small module does one thing: it atlers the comment form to replace the drupal username with the BOINC display name, when quoting another user in the forums. Module weight is +1 to ensure it activates after the 'quote' module. https://dev.gridrepublic.org/browse/DBOINCP-284 --- .../boincuser_quote/boincuser_quote.info | 9 +++ .../boincuser_quote/boincuser_quote.install | 21 ++++++ .../boincuser_quote/boincuser_quote.module | 74 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.info create mode 100644 drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.install create mode 100644 drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.module diff --git a/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.info b/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.info new file mode 100644 index 0000000000..6c77eb83d8 --- /dev/null +++ b/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.info @@ -0,0 +1,9 @@ +; $Id$ +name = BOINC user quote +description = Module that alters the quote module to print a user's BOINC display name in forums when being quoted. +core = 6.x +dependencies[] = boincuser +dependencies[] = quote +package = BOINC + +datestamp = "1536162592" diff --git a/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.install b/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.install new file mode 100644 index 0000000000..c036f9c2fb --- /dev/null +++ b/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.install @@ -0,0 +1,21 @@ +<?php + +/** + * @file + * BOINC User quote - Installation routines + */ + +/** + * Implementation of hook_install(). + */ +function boincuser_quote_install() { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + db_query("UPDATE {system} SET weight=1 WHERE name='boincuser_quote'"); + break; + case 'pgsql': + db_query("UPDATE {system} SET weight=1 WHERE name='boincuser_quote'"); + break; + } +} diff --git a/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.module b/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.module new file mode 100644 index 0000000000..fb3b7f1e48 --- /dev/null +++ b/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.module @@ -0,0 +1,74 @@ +<?php + +/** + * @file + * BOINC user quote - Custom BOINC quote module + */ + +/** + * Description + * + * This module does one simple thing: it alters the comment form to + * use the BOINC user's display name when being quoted. Otherwise the + * 'quote' module will display the Drupal username, which is not + * desired. + * + * This module is weighted to +1 to make sure the hook 'fires' after + * the quote module's hook(s). + */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Includes that provide supporting functions + * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Hooks into core modules + * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/** + * Implementation of hook_form_alter() + */ + +function boincuser_quote_form_alter(&$form, $form_state, $form_id) { + //global $user; + switch ($form_id) { + // Comment form + case 'comment_form': + // If there is a quote as part of the comment body, replace the + // first instance of quote=author with quote=boincusername. This + // is done with regexp. + // Modify for quotes only + if ((isset($_POST['quote']) || isset($_GET['quote']) && $_GET['quote'])) { + // If default_value is already set, then modify it + if (isset($form['comment_filter']['comment']['#default_value'])) { + $nid = arg(2); + $cid = arg(3); + + $replace = FALSE; + if ($cid) { + $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0', $cid)); + if ($comment->uid) { + $account = user_load($comment->uid); + $boincusername = (!empty($account)) ? $account->boincuser_name : variable_get('anonymous', 'Anonymous'); + $replace = TRUE; + } + } + elseif ($nid && _quote_variable_get('node_link_display')) { + $node = node_load(array('nid' => $nid)); + if (in_array($node->type, _quote_variable_get('node_types'))) { + $account = user_load($node->uid); + $boincusername = (!empty($account)) ? $account->boincuser_name : variable_get('anonymous', 'Anonymous'); + $replace = TRUE; + } + } + + // Replace the quoted author name (drupal name) with BOINC username. + if ($replace) { + $form['comment_filter']['comment']['#default_value'] = preg_replace("/\[quote=(.*?)\]/", "[quote=${boincusername}]", $form['comment_filter']['comment']['#default_value'], 1); + } + } + } + break; + } +} From 24b6b8ee6468b7d1a30a774801704cfff0410dd2 Mon Sep 17 00:00:00 2001 From: tristanolive <tristan.olive@studiodelta.us> Date: Wed, 12 Sep 2018 21:10:54 -0400 Subject: [PATCH 2/2] Clean out a leftover line of dev code --- .../modules/boincuser/boincuser_quote/boincuser_quote.module | 1 - 1 file changed, 1 deletion(-) diff --git a/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.module b/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.module index fb3b7f1e48..85cc8e6d77 100644 --- a/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.module +++ b/drupal/sites/default/boinc/modules/boincuser/boincuser_quote/boincuser_quote.module @@ -31,7 +31,6 @@ */ function boincuser_quote_form_alter(&$form, $form_state, $form_id) { - //global $user; switch ($form_id) { // Comment form case 'comment_form':