Changeset 546 for trunk/b2-include/b2functions.php
- Timestamp:
- 11/12/2003 03:22:47 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/b2-include/b2functions.php
r534 r546 547 547 } 548 548 549 function get_commentdata($comment_ID,$no_cache=0 ) { // less flexible, but saves DB queries549 function get_commentdata($comment_ID,$no_cache=0,$include_unapproved=false) { // less flexible, but saves DB queries 550 550 global $postc,$id,$commentdata,$tablecomments,$querycount, $wpdb; 551 551 if ($no_cache) { 552 $myrow = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID = $comment_ID", ARRAY_A); 552 $query = "SELECT * FROM $tablecomments WHERE comment_ID = $comment_ID"; 553 if (false == $include_unapproved) { 554 $query .= " AND comment_approved = '1'"; 555 } 556 $myrow = $wpdb->get_row($query, ARRAY_A); 553 557 ++$querycount; 554 558 } else { … … 1311 1315 } 1312 1316 1317 /* wp_set_comment_status: 1318 part of otaku42's comment moderation hack 1319 changes the status of a comment according to $comment_status. 1320 allowed values: 1321 hold : set comment_approve field to 0 1322 approve: set comment_approve field to 1 1323 delete : remove comment out of database 1324 1325 returns true if change could be applied 1326 returns false on database error or invalid value for $comment_status 1327 */ 1328 function wp_set_comment_status($comment_id, $comment_status) { 1329 global $wpdb, $tablecomments; 1330 1331 switch($comment_status) { 1332 case 'hold': 1333 $query = "UPDATE $tablecomments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; 1334 break; 1335 case 'approve': 1336 $query = "UPDATE $tablecomments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; 1337 break; 1338 case 'delete': 1339 $query = "DELETE FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1"; 1340 break; 1341 default: 1342 return false; 1343 } 1344 1345 if ($wpdb->query($query)) { 1346 return true; 1347 } else { 1348 return false; 1349 } 1350 } 1351 1352 1353 /* wp_get_comment_status 1354 part of otaku42's comment moderation hack 1355 gets the current status of a comment 1356 1357 returned values: 1358 "approved" : comment has been approved 1359 "unapproved": comment has not been approved 1360 "deleted ": comment not found in database 1361 1362 a (boolean) false signals an error 1363 */ 1364 function wp_get_comment_status($comment_id) { 1365 global $wpdb, $tablecomments; 1366 1367 $result = $wpdb->get_var("SELECT comment_approved FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1"); 1368 if ($result == NULL) { 1369 return "deleted"; 1370 } else if ($result == "1") { 1371 return "approved"; 1372 } else if ($result == "0") { 1373 return "unapproved"; 1374 } else { 1375 return false; 1376 } 1377 } 1378 1379 1380 /* wp_notify_postauthor 1381 notifies the author of a post about a new comment 1382 needs the id of the new comment 1383 always returns true 1384 */ 1385 function wp_notify_postauthor($comment_id) { 1386 global $wpdb, $tablecomments, $tableposts, $tableusers; 1387 global $querystring_start, $querystring_equal, $querystring_separator; 1388 global $blogfilename, $blogname, $siteurl; 1389 1390 $comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1"); 1391 $post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1"); 1392 $user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID='$post->post_author' LIMIT 1"); 1393 1394 if ("" != $user->user_email) { 1395 $comment_author_domain = gethostbyaddr($comment->comment_author_IP); 1396 1397 $notify_message = "New comment on your post #$comment->comment_post_ID \"".stripslashes($post->post_title)."\"\r\n\r\n"; 1398 $notify_message .= "Author : $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; 1399 $notify_message .= "E-mail : $comment->comment_author_email\r\n"; 1400 $notify_message .= "URL : $comment->comment_author_url\r\n"; 1401 $notify_message .= "Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=$comment->comment_author_IP\r\n"; 1402 $notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n"; 1403 $notify_message .= "You can see all comments on this post here: \r\n"; 1404 $notify_message .= $siteurl.'/'.$blogfilename.'?p='.$comment_post_ID.'&c=1#comments'; 1405 1406 $subject = '[' . stripslashes($blogname) . '] Comment: "' .stripslashes($post->post_title).'"'; 1407 if ('' != $comment->comment_author_email) { 1408 $from = "From: \"$comment->comment_author\" <$comment->comment_author_email>"; 1409 } else { 1410 $from = 'From: "' . stripslashes($comment->comment_author) . "\" <$user->user_email>"; 1411 } 1412 $from .= "\nX-Mailer: WordPress $b2_version with PHP/" . phpversion(); 1413 1414 @mail($user->user_email, $subject, $notify_message, $from); 1415 } 1416 1417 return true; 1418 } 1419 1420 /* wp_notify_moderator 1421 notifies the moderator of the blog (usually the admin) 1422 about a new comment that waits for approval 1423 always returns true 1424 */ 1425 function wp_notify_moderator($comment_id) { 1426 global $wpdb, $tablecomments, $tableposts, $tableusers; 1427 global $querystring_start, $querystring_equal, $querystring_separator; 1428 global $blogfilename, $blogname, $siteurl; 1429 1430 $comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1"); 1431 $post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1"); 1432 $user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID='$post->post_author' LIMIT 1"); 1433 1434 $comment_author_domain = gethostbyaddr($comment->comment_author_IP); 1435 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $tablecomments WHERE comment_approved = '0'"); 1436 1437 $notify_message = "A new comment on the post #$comment->comment_post_ID \"".stripslashes($post->post_title)."\" is waiting for your approval\r\n\r\n"; 1438 $notify_message .= "Author : $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; 1439 $notify_message .= "E-mail : $comment->comment_author_email\r\n"; 1440 $notify_message .= "URL : $comment->comment_author_url\r\n"; 1441 $notify_message .= "Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=$comment->comment_author_IP\r\n"; 1442 $notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n"; 1443 $notify_message .= "To approve this comment, visit: $siteurl/wp-admin/wp-post.php?action=mailapprovecomment&p=".$comment->comment_post_ID."&comment=$comment_id\r\n"; 1444 $notify_message .= "To delete this comment, visit: $siteurl/wp-admin/wp-post.php?action=confirmdeletecomment&p=".$comment->comment_post_ID."&comment=$comment_id\r\n"; 1445 $notify_message .= "Currently $comments_waiting comments are waiting for approval. Please visit the moderation panel:\r\n"; 1446 $notify_message .= "$siteurl/wp-admin/wp-moderation.php\r\n"; 1447 1448 $subject = '[' . stripslashes($blogname) . '] Please approve: "' .stripslashes($post->post_title).'"'; 1449 $admin_email = get_settings("admin_email"); 1450 $from = "From: $admin_email"; 1451 $from .= "\nX-Mailer: WordPress $b2_version with PHP/" . phpversion(); 1452 1453 @mail($admin_email, $subject, $notify_message, $from); 1454 1455 return true; 1456 } 1457 1313 1458 1314 1459 // implementation of in_array that also should work on PHP3
Note: See TracChangeset
for help on using the changeset viewer.