| 1 |
<?php
|
| 2 |
// $Id: bugs.module,v 1.1 2006/01/05 03:57:06 daryl Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Enables users to mark nodes as eligible for consideration by someone creating bug reports.
|
| 7 |
* It's basically a way to let the community or privileged volunteers call relevant nodes
|
| 8 |
* to the attention of a bug master. Marked nodes are available as a feed.
|
| 9 |
*/
|
| 10 |
|
| 11 |
|
| 12 |
/**
|
| 13 |
* This function defines the appearance of the toggle link. Default output can be modified in settings.
|
| 14 |
*/
|
| 15 |
function bugs_get_status_div($nid,$status){
|
| 16 |
//If you change $bugno_form, be sure to change it in settings too.
|
| 17 |
//$bugno_form='<form><input type="text" id="bugs_bugno" name="bugs_bugno" size="5" /><input type="button" value="Enter Bug Number" onclick="xajax_bugs_add_bugno(__NODE_ID__,document.getElementById(\'bugs_bugno\').value)" /></form>';
|
| 18 |
//$bugno_form=preg_replace("/__NODE_ID__/",$nid,$bugno_form);
|
| 19 |
|
| 20 |
|
| 21 |
switch($status){
|
| 22 |
//Marked as bug already
|
| 23 |
case 'MARKED':
|
| 24 |
$output=variable_get('bugs_unmark_html','<p><a href="javascript:void(0)" style="text-decoration: none; color: #900;" onclick="__ONCLICK__">Remove this post from bug review consideration.</a>' . $bugno_form . '</p>');
|
| 25 |
//$output=variable_get('bugs_unmark_html','<p><a href="javascript:void(0)" style="text-decoration: none; color: #090;" onclick="__ONCLICK__">Prompt a bug review for this post.</a></p>');
|
| 26 |
$output=preg_replace("/__NODE_ID__/",$nid,$output);
|
| 27 |
$onclick='xajax_bugs_unmark(' . $nid . '); return false;';
|
| 28 |
break;
|
| 29 |
//Can be marked as a bug.
|
| 30 |
case 'TOMARK':
|
| 31 |
$output=variable_get('bugs_mark_html','<p><a href="javascript:void(0)" style="text-decoration: none; color: #090;" onclick="__ONCLICK__">Prompt a bug review for this post.</a></p>');
|
| 32 |
//$output=variable_get('bugs_mark_html','<p><a href="javascript:void(0)" style="text-decoration: none; color: #900;" onclick="__ONCLICK__">Remove this post from bug review consideration.</a>' . $bugno_form . '</p>');
|
| 33 |
$onclick='xajax_bugs_mark(' . $nid . '); return false;';
|
| 34 |
break;
|
| 35 |
//Already has a bug report associated with it
|
| 36 |
default:
|
| 37 |
$output=variable_get('bugs_bugno_html','<a style="color: #009;" href="__BUGURL__">Bug __BUGNO__ already logged!</a>');
|
| 38 |
$output=preg_replace("/__BUGURL__/",variable_get('bugs_base_tracker_url','http://drupal.org/project/issues/') . $status,$output);
|
| 39 |
$output=preg_replace("/__BUGNO__/",$status,$output);
|
| 40 |
|
| 41 |
|
| 42 |
}
|
| 43 |
return preg_replace("/__ONCLICK__/",$onclick,$output);
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Ajax callback for when bugs are marked.
|
| 48 |
*/
|
| 49 |
function bugs_mark($nid) {
|
| 50 |
$objResponse = new xajaxResponse();
|
| 51 |
$response=db_query("INSERT INTO bugs VALUES (NULL,%d,0)",$nid);
|
| 52 |
$innerHTML=bugs_get_status_div($nid,'MARKED');
|
| 53 |
$objResponse->addAssign("bug_status_div","innerHTML",$innerHTML);
|
| 54 |
return $objResponse->getXML();
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 58 |
* Ajax callback for when bugs are unmarked.
|
| 59 |
*/
|
| 60 |
function bugs_unmark($nid) {
|
| 61 |
$objResponse = new xajaxResponse();
|
| 62 |
$response=db_query("DELETE FROM bugs WHERE nid = %d",$nid);
|
| 63 |
$innerHTML=bugs_get_status_div($nid,'TOMARK');
|
| 64 |
$objResponse->addAssign("bug_status_div","innerHTML",$innerHTML);
|
| 65 |
return $objResponse->getXML();
|
| 66 |
}
|
| 67 |
|
| 68 |
function bugs_add_bugno($nid,$bugno) {
|
| 69 |
$objResponse = new xajaxResponse();
|
| 70 |
if(intval($bugno) > 0){
|
| 71 |
$response=db_query("DELETE FROM bugs WHERE nid = %d",$nid);
|
| 72 |
$response=db_query("INSERT INTO bugs VALUES (NULL,%d,%d)",$nid,$bugno);
|
| 73 |
$innerHTML=bugs_get_status_div($nid,$bugno);
|
| 74 |
}
|
| 75 |
else{
|
| 76 |
$innerHTML='Invaid number! ' . bugs_get_status_div($nid,'TOMARK');
|
| 77 |
}
|
| 78 |
$objResponse->addAssign("bug_status_div","innerHTML",$innerHTML);
|
| 79 |
return $objResponse->getXML();
|
| 80 |
}
|
| 81 |
|
| 82 |
/**
|
| 83 |
* Implementation of hook_help().
|
| 84 |
*/
|
| 85 |
function bugs_help($section) {
|
| 86 |
switch ($section) {
|
| 87 |
case 'admin/help#bugs':
|
| 88 |
return t("This module adds a div above node content allowing the given node to be toggled for consideration as a bug report. It comes complete with ajaxy goodness. The block does not update immediately upon toggling. Bugs marked for consideration are available via a feed at /bugs/feed as well. There is currently no automatic logging of bugs; this just helps float potential bug reports and expose them to a person who monitors the site/feed to create new bugs.");
|
| 89 |
case 'admin/modules#description':
|
| 90 |
return t("Easily mark nodes as candidates for bug reports.");
|
| 91 |
}
|
| 92 |
}
|
| 93 |
|
| 94 |
/**
|
| 95 |
* Implementation of hook_access().
|
| 96 |
*/
|
| 97 |
function bugs_access($op, $node) {
|
| 98 |
if ($op == 'list') {
|
| 99 |
return user_access('list bugs');
|
| 100 |
}
|
| 101 |
if ($op == 'mark') {
|
| 102 |
return user_access('mark nodes as bugs');
|
| 103 |
}
|
| 104 |
}
|
| 105 |
|
| 106 |
/**
|
| 107 |
* Implementation of hook_settings().
|
| 108 |
*
|
| 109 |
*/
|
| 110 |
|
| 111 |
function bugs_settings(){
|
| 112 |
$bugno_form='<form><input type="text" id="bugs_bugno" name="bugs_bugno" size="5" /><input type="button" value="Enter Bug Number" onclick="xajax_bugs_add_bugno(__NODE_ID__,document.getElementById(\'bugs_bugno\').value)" /></form>';
|
| 113 |
|
| 114 |
$output = form_textfield(
|
| 115 |
t('Base bug tracker url'),
|
| 116 |
'bugs_base_tracker_url',
|
| 117 |
variable_get('bugs_base_tracker_url', 'http://drupal.org/project/issues/'),
|
| 118 |
40, 60, t('Base bug tracker url to append bug numbers to.'));
|
| 119 |
|
| 120 |
$output .= form_textarea(
|
| 121 |
t('"Bug already exists" html'),
|
| 122 |
'bugs_bugno_html',
|
| 123 |
variable_get('bugs_bugno_html','<a style="color: #009;" href="__BUGURL__">Bug __BUGNO__ already logged!</a>'),
|
| 124 |
40, 4, t('Enter the HTML that should appear if a bug has already been logged and recorded for a given node. Be sure to include \'__BUGURL__\' as your href so that we can substitute the appropriate link and \'__BUGNO__\' anywhere you\'d like the bug number to be substituted.')
|
| 125 |
);
|
| 126 |
|
| 127 |
$output .= form_textarea(
|
| 128 |
t('"Mark this node" html'),
|
| 129 |
'bugs_mark_html',
|
| 130 |
variable_get('bugs_mark_html','<p><a href="javascript:void(0)" style="text-decoration: none; color: #090;" onclick="__ONCLICK__">Prompt a bug review for this post.</a></p>'),
|
| 131 |
40, 4, t('Enter the HTML that should appear when a node is not yet marked as a bug. Be sure to include \'onclick="__ONCLICK__"\' so that the appropriate click handler can be applied for ajax support.'));
|
| 132 |
|
| 133 |
$output .= form_textarea(
|
| 134 |
t('"Unmark this node" html'),
|
| 135 |
'bugs_unmark_html',
|
| 136 |
variable_get('bugs_unmark_html','<p><a href="javascript:void(0)" style="text-decoration: none; color: #900;" onclick="__ONCLICK__">Remove this post from bug review consideration.</a>' . $bugno_form . '</p>'),
|
| 137 |
40, 4, t('Enter the HTML that should appear when a node has been marked as a bug. Be sure to include \'onclick="__ONCLICK__"\' so that the appropriate click handler can be applied for ajax support.'));
|
| 138 |
|
| 139 |
$output .= form_select(
|
| 140 |
t('Toggle html position'),
|
| 141 |
'bugs_toggle_position',
|
| 142 |
variable_get('bugs_toggle_position','after'),
|
| 143 |
array('after' => 'after', before => 'before'),
|
| 144 |
t('Determines where the html to toggle node\'s bug status goes relative to the node\'s body.')
|
| 145 |
);
|
| 146 |
|
| 147 |
/**
|
| 148 |
* Started trying to make the toggle html relative to different elements, but it proved problematic, so I'm back-burnering.
|
| 149 |
*/
|
| 150 |
/*
|
| 151 |
$output .= form_select(
|
| 152 |
t('Adjacent node fragment for toggle'),
|
| 153 |
'bugs_adjacent_node',
|
| 154 |
variable_get('bugs_adjacent node','title'),
|
| 155 |
array('title' => 'Title', 'body' => 'Body', 'teaser' => 'Teaser'),
|
| 156 |
t('Determines what portion of a node the toggle html goes. The previous field sets the orientation.')
|
| 157 |
);
|
| 158 |
*/
|
| 159 |
|
| 160 |
return $output;
|
| 161 |
}
|
| 162 |
|
| 163 |
/**
|
| 164 |
* Implementation of hook_block().
|
| 165 |
*
|
| 166 |
* Generates a block containing the bugs marked. Might pay eventually to impose a limit.
|
| 167 |
*/
|
| 168 |
function bugs_block($op = 'list', $delta = 0) {
|
| 169 |
if (user_access('access content')) {
|
| 170 |
if ($op == 'list') {
|
| 171 |
$blocks[0]['info'] = t('Recent Bug Candidates');
|
| 172 |
return $blocks;
|
| 173 |
}
|
| 174 |
else if ($op == 'view') {
|
| 175 |
$result=db_query("select n.nid, n.title from bugs b, node n where b.nid=n.nid");
|
| 176 |
$block['subject'] = t('Recent Bug Candidates');
|
| 177 |
$block['content']='';
|
| 178 |
|
| 179 |
while($node=db_fetch_object($result)){
|
| 180 |
$block['content'] .= t('<li><a href="/node/' . $node->nid . '">' . $node->title . '</a></li>');
|
| 181 |
}
|
| 182 |
if($block['content'] != ''){
|
| 183 |
$block['content']=="<ul>\n" . $block['content'] . "\n</ul>\n";
|
| 184 |
}
|
| 185 |
else{
|
| 186 |
$block['content']='No bug candidates found!';
|
| 187 |
}
|
| 188 |
$block['content'] .= '</ul>';
|
| 189 |
|
| 190 |
return $block;
|
| 191 |
}
|
| 192 |
}
|
| 193 |
}
|
| 194 |
|
| 195 |
function bugs_add(){
|
| 196 |
return;
|
| 197 |
}
|
| 198 |
|
| 199 |
/**
|
| 200 |
* Implementation of hook_nodeapi().
|
| 201 |
*
|
| 202 |
* For a given node, if the user has access, show the bug toggling UI above the body of the node.
|
| 203 |
*/
|
| 204 |
function bugs_nodeapi(&$node, $op, $arg = 0){
|
| 205 |
switch($op){
|
| 206 |
case 'view':
|
| 207 |
$result=db_query("SELECT COUNT(*) as cnt FROM bugs WHERE nid=%d",$node->nid);
|
| 208 |
$obj=db_fetch_object($result);
|
| 209 |
|
| 210 |
$result=db_query("SELECT bug_no from bugs WHERE nid=%d AND bug_no > 0 LIMIT 1",$node->nid);
|
| 211 |
$bug=db_fetch_object($result);
|
| 212 |
|
| 213 |
if(user_access('mark nodes as bugs')){
|
| 214 |
if(variable_get('bugs_toggle_position','after')=='after'){
|
| 215 |
$before=$node->body;
|
| 216 |
$after="";
|
| 217 |
}
|
| 218 |
else{
|
| 219 |
$before="";
|
| 220 |
$after=$node->body;
|
| 221 |
}
|
| 222 |
|
| 223 |
if($obj->cnt > 0){
|
| 224 |
if(!($bug->bug_no > 0)){
|
| 225 |
$node->body = $before . '<div id="bug_status_div">' . bugs_get_status_div($node->nid,'MARKED') . '</div>' . $after;
|
| 226 |
}
|
| 227 |
}
|
| 228 |
else{
|
| 229 |
$node->body = $before . '<div id="bug_status_div">' . bugs_get_status_div($node->nid,'TOMARK') . '</div>' . $after;
|
| 230 |
}
|
| 231 |
}
|
| 232 |
else{
|
| 233 |
$after = $node->body;
|
| 234 |
}
|
| 235 |
if($bug->bug_no > 0){
|
| 236 |
$node->body = $before . '<div id="bug_status_div">' . bugs_get_status_div($node->nid,$bug->bug_no) . '</div>' . $after;
|
| 237 |
}
|
| 238 |
break;
|
| 239 |
default:
|
| 240 |
}
|
| 241 |
}
|
| 242 |
|
| 243 |
|
| 244 |
function bugs_xajax_init(&$xajax){
|
| 245 |
$xajax->registerFunction("bugs_mark");
|
| 246 |
$xajax->registerFunction("bugs_unmark");
|
| 247 |
$xajax->registerFunction("bugs_add_bugno");
|
| 248 |
}
|
| 249 |
|
| 250 |
/**
|
| 251 |
* Implementation of hook_menu().
|
| 252 |
*
|
| 253 |
* Ajax stuff courtesy of http://drupal.org/node/29035
|
| 254 |
*/
|
| 255 |
function bugs_menu($may_cache) {
|
| 256 |
$items = array();
|
| 257 |
|
| 258 |
$items[] = array('path' => 'bugs', 'title' => t('Bugs'),
|
| 259 |
'callback' => 'bugs_page',
|
| 260 |
'access' => user_access('access content'),
|
| 261 |
'type' => MENU_SUGGESTED_ITEM);
|
| 262 |
|
| 263 |
return $items;
|
| 264 |
}
|
| 265 |
|
| 266 |
/** Implementation of hook_node_name().
|
| 267 |
*/
|
| 268 |
function bugs_node_name($node) {
|
| 269 |
return t("bugs");
|
| 270 |
}
|
| 271 |
|
| 272 |
/**
|
| 273 |
* Displays an RSS feed containing recent blog entries of all users.
|
| 274 |
*/
|
| 275 |
function bugs_feed() {
|
| 276 |
$result=db_query("select n.nid, n.title, n.teaser, n.created, u.name, u.uid from bugs b, node n, users u where b.nid=n.nid AND u.uid=n.uid AND b.bug_no = 0 order by created desc");
|
| 277 |
$channel['title'] = variable_get('site_name', 'drupal') .' Bug Candidates';
|
| 278 |
$channel['link'] = url('', NULL, NULL, TRUE);
|
| 279 |
$channel['description'] = 'Nodes that have been marked for review and possible entry into Bugzilla.';
|
| 280 |
node_feed($result, $channel);
|
| 281 |
}
|
| 282 |
|
| 283 |
|
| 284 |
/**
|
| 285 |
* Implementation of hook_page().
|
| 286 |
*/
|
| 287 |
function bugs_page($a = NULL) {
|
| 288 |
if($a == 'feed'){
|
| 289 |
bugs_feed();
|
| 290 |
}
|
| 291 |
else{
|
| 292 |
bugs_view();
|
| 293 |
}
|
| 294 |
}
|
| 295 |
|
| 296 |
/**
|
| 297 |
* Implementation of hook_perm().
|
| 298 |
*/
|
| 299 |
function bugs_perm() {
|
| 300 |
//return array('list bugs', 'mark nodes as bugs');
|
| 301 |
return array('mark nodes as bugs');
|
| 302 |
}
|
| 303 |
|
| 304 |
/**
|
| 305 |
* Implementation of hook_view().
|
| 306 |
*
|
| 307 |
*/
|
| 308 |
function bugs_view(){
|
| 309 |
$output = '';
|
| 310 |
$result=db_query("select n.nid, n.title, n.teaser, n.created, u.name, u.uid from bugs b, node n, users u where b.nid=n.nid AND u.uid=n.uid AND b.bug_no = 0 order by created desc");
|
| 311 |
while($node=db_fetch_object($result)){
|
| 312 |
$output .= "\t" . '<li><a href="node/' . $node->nid . '">' . $node->title . '</a></li>' . "\n";
|
| 313 |
}
|
| 314 |
if($output != ''){
|
| 315 |
$output = "<ul>\n" . $output . "</ul>\n";
|
| 316 |
}
|
| 317 |
else{
|
| 318 |
$output='No nodes currently marked as bug candidates!';
|
| 319 |
}
|
| 320 |
print theme('page', $output);
|
| 321 |
}
|
| 322 |
|
| 323 |
?>
|