| 1 |
<?php
|
| 2 |
// $Id: pr.module,v 0.1 2005/11/17 12:30:39 daryl Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Allows your users to vote up items in a pr queue and lets privileged users mark items responded to.
|
| 7 |
*/
|
| 8 |
|
| 9 |
function pr_respond($iid){
|
| 10 |
$objResponse = new xajaxResponse();
|
| 11 |
if(user_access('bump from queue') && intval($iid) > 0){
|
| 12 |
$result=db_query("SELECT COUNT(*) as cnt FROM pr_aggregator WHERE iid=%d",$iid);
|
| 13 |
$obj=db_fetch_object($result);
|
| 14 |
if($obj->cnt > 0){
|
| 15 |
db_query("UPDATE pr_aggregator SET responded_to=1 WHERE iid=%d",$iid);
|
| 16 |
}
|
| 17 |
else{
|
| 18 |
db_query("INSERT INTO pr_aggregator (pid, iid, responded_to, rating) VALUES (NULL, %d, 1, 0)",$iid);
|
| 19 |
}
|
| 20 |
$objResponse->addAssign("pr_rating_remove_" . $iid ,"innerHTML","responded!");
|
| 21 |
}
|
| 22 |
return $objResponse->getXML();
|
| 23 |
}
|
| 24 |
|
| 25 |
function pr_rate($iid){
|
| 26 |
global $user;
|
| 27 |
$uid=intval($user->uid);
|
| 28 |
$objResponse = new xajaxResponse();
|
| 29 |
if($uid > 0 && user_access('rate pr')){
|
| 30 |
$result=db_query("SELECT COUNT(*) as cnt FROM pr_ratings WHERE uid=%d AND iid=%d",$uid,$iid);
|
| 31 |
$obj=db_fetch_object($result);
|
| 32 |
if($obj->cnt == 0){
|
| 33 |
$result2=db_query("SELECT COUNT(*) as cnt FROM pr_aggregator WHERE iid=%d",$iid);
|
| 34 |
$obj2=db_fetch_object($result2);
|
| 35 |
if($obj2->cnt > 0){
|
| 36 |
$result=db_query("SELECT rating FROM pr_aggregator WHERE iid=%d",$iid);
|
| 37 |
$article=db_fetch_object($result);
|
| 38 |
$innerHTML=$article->rating + 1;
|
| 39 |
db_query("UPDATE pr_aggregator SET rating = (rating + 1) WHERE iid=%d",$iid);
|
| 40 |
}
|
| 41 |
else{
|
| 42 |
db_query("INSERT INTO pr_aggregator (pid, iid, responded_to, rating) VALUES (NULL, %d, 0, 1)",$iid);
|
| 43 |
$innerHTML="1";
|
| 44 |
}
|
| 45 |
db_query("INSERT INTO pr_ratings VALUES (NULL,%d,%d)",$iid,$uid);
|
| 46 |
$objResponse->addAssign("pr_rating_" . $iid ,"innerHTML",$innerHTML);
|
| 47 |
$objResponse->addAssign("pr_rating_vote_" . $iid ,"innerHTML","voted!");
|
| 48 |
}
|
| 49 |
}
|
| 50 |
return $objResponse->getXML();
|
| 51 |
}
|
| 52 |
|
| 53 |
/**
|
| 54 |
* Implementation of hook_help().
|
| 55 |
*/
|
| 56 |
function pr_help($section) {
|
| 57 |
switch ($section) {
|
| 58 |
case 'admin/help#pr':
|
| 59 |
return t("Enter help text here");
|
| 60 |
case 'admin/modules#description':
|
| 61 |
return t("Enter description here.");
|
| 62 |
case 'node/add#pr':
|
| 63 |
return t("Enter help text here.");
|
| 64 |
}
|
| 65 |
}
|
| 66 |
|
| 67 |
/**
|
| 68 |
* Implementation of hook_access().
|
| 69 |
*/
|
| 70 |
function pr_access($op, $node) {
|
| 71 |
if ($op == 'bump') {
|
| 72 |
return user_access('bump from queue');
|
| 73 |
}
|
| 74 |
if ($op == 'rate') {
|
| 75 |
return user_access('rate pr');
|
| 76 |
}
|
| 77 |
}
|
| 78 |
|
| 79 |
/**
|
| 80 |
* Implementation of hook_block().
|
| 81 |
*
|
| 82 |
* Generates a block containing the latest poll.
|
| 83 |
*/
|
| 84 |
function pr_block($op = 'list', $delta = 0) {
|
| 85 |
if (user_access('access content')) {
|
| 86 |
if ($op == 'list') {
|
| 87 |
$blocks[0]['info'] = t('Recent PR');
|
| 88 |
return $blocks;
|
| 89 |
}
|
| 90 |
else if ($op == 'view') {
|
| 91 |
// Retrieve the latest pr.
|
| 92 |
//$sql = db_rewrite_sql("SELECT MAX(n.created) FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = 1 AND p.active = 1 AND n.moderate = 0");
|
| 93 |
$block['subject'] = t('PR');
|
| 94 |
$block['content'] = t('Add stuff here');
|
| 95 |
return $block;
|
| 96 |
}
|
| 97 |
}
|
| 98 |
}
|
| 99 |
|
| 100 |
|
| 101 |
/**
|
| 102 |
* Register functions to be included in the xajax javascript include.
|
| 103 |
* The xajax module must be installed in order for this to work.
|
| 104 |
* Additionally, these functions should be defined and should perform xajax
|
| 105 |
* and drupal logic.
|
| 106 |
*/
|
| 107 |
function pr_xajax_init(&$xajax){
|
| 108 |
$xajax->registerFunction("pr_rate");
|
| 109 |
$xajax->registerFunction("pr_respond");
|
| 110 |
}
|
| 111 |
|
| 112 |
/**
|
| 113 |
* Implementation of hook_menu().
|
| 114 |
*/
|
| 115 |
function pr_menu($may_cache) {
|
| 116 |
$items = array();
|
| 117 |
|
| 118 |
$items[] = array('path' => 'pr', 'title' => t('PR'),
|
| 119 |
'callback' => 'pr_page',
|
| 120 |
'access' => user_access('access content'),
|
| 121 |
'type' => MENU_SUGGESTED_ITEM);
|
| 122 |
|
| 123 |
return $items;
|
| 124 |
}
|
| 125 |
|
| 126 |
/** Implementation of hook_node_name().
|
| 127 |
*/
|
| 128 |
function pr_node_name($node) {
|
| 129 |
return t("pr");
|
| 130 |
}
|
| 131 |
|
| 132 |
function pr_page() {
|
| 133 |
global $user;
|
| 134 |
$nav=array();
|
| 135 |
$display_number=25;
|
| 136 |
$output='';
|
| 137 |
|
| 138 |
if(!$_GET["sort"]){ $_GET["sort"]="timestamp"; }
|
| 139 |
if(!$_GET["filter"]){ $_GET["filter"]=0; }
|
| 140 |
if(!$_GET["from"]){ $_GET["from"]=0; }
|
| 141 |
|
| 142 |
switch($_GET["filter"]){
|
| 143 |
case 0:
|
| 144 |
$responded_to=" AND (pr_aggregator.responded_to IS NULL OR pr_aggregator.responded_to=0)";
|
| 145 |
break;
|
| 146 |
case 1:
|
| 147 |
$responded_to=" AND pr_aggregator.responded_to=1";
|
| 148 |
break;
|
| 149 |
default:
|
| 150 |
$responded_to="";
|
| 151 |
}
|
| 152 |
|
| 153 |
$nav["sort"]=$_GET["sort"];
|
| 154 |
$nav["filter"]=$_GET["filter"];
|
| 155 |
|
| 156 |
$breadcrumbs=array(
|
| 157 |
array(
|
| 158 |
"group" => "sort",
|
| 159 |
"label" => "Sort by: ",
|
| 160 |
"items" => array(
|
| 161 |
array(
|
| 162 |
"label" => "Rating",
|
| 163 |
"val" => "rating",
|
| 164 |
"link" => "/pr/?sort=rating&from=0&filter=" . $nav["filter"]
|
| 165 |
),
|
| 166 |
array(
|
| 167 |
"label" => "Date",
|
| 168 |
"val" => "timestamp",
|
| 169 |
"link" => "/pr/?sort=timestamp&from=0&filter=" . $nav["filter"]
|
| 170 |
)
|
| 171 |
)
|
| 172 |
),
|
| 173 |
array(
|
| 174 |
"group" => "filter",
|
| 175 |
"label" => "Show: ",
|
| 176 |
"items" => array(
|
| 177 |
array(
|
| 178 |
"label" => "All",
|
| 179 |
"val" => "2",
|
| 180 |
"link" => "/pr/?sort=" . $nav["sort"] . "&from=0&filter=2"
|
| 181 |
),
|
| 182 |
array(
|
| 183 |
"label" => "Unresponded To",
|
| 184 |
"val" => "0",
|
| 185 |
"link" => "/pr/?sort=" . $nav["sort"] . "&from=0&filter=0"
|
| 186 |
),
|
| 187 |
array(
|
| 188 |
"label" => "Responded To",
|
| 189 |
"val" => "1",
|
| 190 |
"link" => "/pr/?sort=" . $nav["sort"] . "&from=0&filter=1"
|
| 191 |
)
|
| 192 |
|
| 193 |
)
|
| 194 |
)
|
| 195 |
);
|
| 196 |
|
| 197 |
foreach($breadcrumbs as $bc){
|
| 198 |
$breadcrumb_links=array();
|
| 199 |
$output .= $bc["label"];
|
| 200 |
foreach($bc["items"] as $item){
|
| 201 |
if($_GET[$bc["group"]]==$item["val"]){
|
| 202 |
array_push($breadcrumb_links,'<b>' . $item["label"] . '</b>');
|
| 203 |
}
|
| 204 |
else{
|
| 205 |
array_push($breadcrumb_links,'<a href="' . $item["link"] . '">' . $item["label"] . '</a>');
|
| 206 |
}
|
| 207 |
}
|
| 208 |
$output .= join(" | ",$breadcrumb_links) . '<br />';
|
| 209 |
}
|
| 210 |
|
| 211 |
$category_filter=array(
|
| 212 |
"from_clause" => "",
|
| 213 |
"where_clause" => ""
|
| 214 |
);
|
| 215 |
|
| 216 |
$cat=variable_get('pr_aggregator_category',0);
|
| 217 |
if($cat > 0){
|
| 218 |
$category_filter["from_clause"]="aggregator_category_feed, ";
|
| 219 |
$category_filter["where_clause"]=" AND (aggregator_category_feed.cid=" . $cat . " AND aggregator_item.fid=aggregator_category_feed.fid)";
|
| 220 |
}
|
| 221 |
|
| 222 |
//$sql="SELECT aggregator_item.iid, aggregator_item.title, pr_aggregator.rating, aggregator_item.description, aggregator_item.timestamp, pr_aggregator.responded_to, pr_ratings.uid AS has_rated FROM aggregator_item LEFT OUTER JOIN pr_aggregator ON aggregator_item.iid=pr_aggregator.iid LEFT OUTER JOIN pr_ratings ON aggregator_item.iid=pr_ratings.iid AND pr_ratings.uid=" . intval($user->uid) . " WHERE 1=1 " . $responded_to . " ORDER BY " . (($nav["sort"]=="rating")?"rating":"timestamp") . " DESC";
|
| 223 |
$sql="SELECT aggregator_item.iid, aggregator_item.title, aggregator_item.link, pr_aggregator.rating, aggregator_item.description, aggregator_item.timestamp, pr_aggregator.responded_to, pr_ratings.uid AS has_rated FROM " . $category_filter["from_clause"] . "aggregator_item LEFT OUTER JOIN pr_aggregator ON aggregator_item.iid=pr_aggregator.iid LEFT OUTER JOIN pr_ratings ON aggregator_item.iid=pr_ratings.iid AND pr_ratings.uid=" . intval($user->uid) . " WHERE 1=1 ". $category_filter["where_clause"] . $responded_to . " ORDER BY " . (($nav["sort"]=="rating")?"rating":"timestamp") . " DESC";
|
| 224 |
//die($sql);
|
| 225 |
$count_sql="SELECT count(*) FROM aggregator_item LEFT OUTER JOIN pr_aggregator ON aggregator_item.iid=pr_aggregator.iid WHERE 1=1 " . $responded_to;
|
| 226 |
$result = pager_query($sql, $display_number, 0, $count_sql);
|
| 227 |
|
| 228 |
|
| 229 |
//=============
|
| 230 |
|
| 231 |
$output .= '<div id="pr_list">
|
| 232 |
<ul>';
|
| 233 |
while ($node = db_fetch_object($result)) {
|
| 234 |
$output .= "\t" . '<li class="pr_item">
|
| 235 |
<ul>
|
| 236 |
<li>
|
| 237 |
<div class="pr_stats">
|
| 238 |
<div class="pr_count">
|
| 239 |
<div id="pr_rating_' . $node->iid . '">' . (($node->rating > 0)?$node->rating:0) . '</div> flocker' . (($node->rating==1)?'':'s') . '
|
| 240 |
</div>' . "\n";
|
| 241 |
if(user_access('rate pr')){
|
| 242 |
$output .= '<div class="pr_vote">' . "\n";
|
| 243 |
$output .= '<span id="pr_rating_vote_' . $node->iid . '">';
|
| 244 |
if(intval($node->has_rated) > 0){
|
| 245 |
$output .= 'voted!';
|
| 246 |
}
|
| 247 |
else{
|
| 248 |
$output .= '<a href="javascript:void(0)" onclick="xajax_pr_rate(\'' . $node->iid . '\'); return false;">vote</a>';
|
| 249 |
}
|
| 250 |
$output .= "</span>\n";
|
| 251 |
$output .="\t" . '</div>';
|
| 252 |
}
|
| 253 |
if(user_access('bump from queue')){
|
| 254 |
$output .="\t" . '<div class="pr_respond">
|
| 255 |
<span id="pr_rating_remove_' . $node->iid . '">';
|
| 256 |
$output .= (($node->responded_to==0)?'<a href="javascript:void(0)" onclick="xajax_pr_respond(\'' . $node->iid . '\'); return false;">respond</a>':'responded!');
|
| 257 |
$output .="\t" . '</span>
|
| 258 |
</div>' . "\n";
|
| 259 |
}
|
| 260 |
$output .= "\t" . '</div>
|
| 261 |
</li>
|
| 262 |
<li class="pr_details">
|
| 263 |
<h4 class="title"><a class="url taggedlink" href="' . $node->link . '">' . t($node->title) . '</a></h4>
|
| 264 |
<span class="meta">' . t(date('m-d-Y, H:i:s',$node->timestamp)) . '</span>
|
| 265 |
<div class="pr_description">
|
| 266 |
' . t($node->description) . '
|
| 267 |
</div>
|
| 268 |
</li>
|
| 269 |
</ul>
|
| 270 |
</li>' . "\n";
|
| 271 |
}
|
| 272 |
$output .= "\t" . '</ul>
|
| 273 |
</div>' . "\n";
|
| 274 |
|
| 275 |
|
| 276 |
//=============
|
| 277 |
|
| 278 |
|
| 279 |
$output .= theme("pager", NULL, $display_number, 0, $nav);
|
| 280 |
print theme('page', $output);
|
| 281 |
}
|
| 282 |
|
| 283 |
/**
|
| 284 |
* Implementation of hook_perm().
|
| 285 |
*/
|
| 286 |
function pr_perm() {
|
| 287 |
return array('bump from queue', 'rate pr');
|
| 288 |
}
|
| 289 |
|
| 290 |
/**
|
| 291 |
* Implementation of hook_settings().
|
| 292 |
*
|
| 293 |
*/
|
| 294 |
function pr_settings(){
|
| 295 |
$categories=array("0" => "All");
|
| 296 |
$result=db_query("SELECT cid, title FROM aggregator_category");
|
| 297 |
while($cat = db_fetch_object($result)){
|
| 298 |
$categories[$cat->cid]=$cat->title;
|
| 299 |
}
|
| 300 |
|
| 301 |
$output = form_select(
|
| 302 |
t('Category to pull feeds from.'),
|
| 303 |
'pr_aggregator_category',
|
| 304 |
variable_get('pr_aggregator_category',0),
|
| 305 |
$categories,
|
| 306 |
t('Determines which aggregator categories to display in the PR tool.')
|
| 307 |
);
|
| 308 |
|
| 309 |
return $output;
|
| 310 |
}
|
| 311 |
|
| 312 |
?>
|