| 1 |
<?php |
<?php |
| 2 |
// $Id: shoutbox.module,v 1.25.2.15 2008/07/15 08:11:17 disterics Exp $ |
// $Id: shoutbox.module,v 1.25.2.16 2008/07/24 08:03:14 disterics Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 47 |
'title' => 'Edit Shout', |
'title' => 'Edit Shout', |
| 48 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 49 |
'page arguments' => array('shoutbox_edit_form', 1), |
'page arguments' => array('shoutbox_edit_form', 1), |
| 50 |
'access_callback' => '_shoutbox_user_access', |
'access callback' => '_shoutbox_user_access', |
| 51 |
'access arguments' => array('edit own shouts'), |
'access arguments' => array('edit own shouts', 1), |
| 52 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 53 |
); |
); |
| 54 |
$items['shoutbox/%shoutbox/delete'] = array( |
$items['shoutbox/%shoutbox/delete'] = array( |
| 55 |
'title' => 'Delete Shout', |
'title' => 'Delete Shout', |
| 56 |
'page callback' => 'theme', |
'page callback' => 'theme', |
| 57 |
'page arguments' => array('shoutbox_delete_form', 1), |
'page arguments' => array('shoutbox_delete_form', 1), |
| 58 |
'access_callback' => '_shoutbox_user_access', |
'access callback' => '_shoutbox_user_access', |
| 59 |
'access arguments' => array('delete own shouts'), |
'access arguments' => array('delete own shouts', 1), |
| 60 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 61 |
); |
); |
| 62 |
$items['shoutbox/%shoutbox/publish'] = array( |
$items['shoutbox/%shoutbox/publish'] = array( |
| 63 |
'title' => 'Publish Shout', |
'title' => 'Publish Shout', |
| 64 |
'page callback' => 'theme', |
'page callback' => 'theme', |
| 65 |
'page arguments' => array('shoutbox_publish_form', 1), |
'page arguments' => array('shoutbox_publish_form', 1), |
| 66 |
'access_callback' => '_shoutbox_user_access', |
'access callback' => '_shoutbox_user_access', |
| 67 |
'access arguments' => array('moderate shoutbox'), |
'access arguments' => array('moderate shoutbox'), |
| 68 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 69 |
); |
); |
| 71 |
'title' => 'Unpublish Shout', |
'title' => 'Unpublish Shout', |
| 72 |
'page callback' => 'theme', |
'page callback' => 'theme', |
| 73 |
'page arguments' => array('shoutbox_unpublish_form', 1), |
'page arguments' => array('shoutbox_unpublish_form', 1), |
| 74 |
'access_callback' => '_shoutbox_user_access', |
'access callback' => '_shoutbox_user_access', |
| 75 |
'access arguments' => array('moderate shoutbox'), |
'access arguments' => array('moderate shoutbox'), |
| 76 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 77 |
); |
); |
| 88 |
} |
} |
| 89 |
|
|
| 90 |
/** |
/** |
| 91 |
* Implementation of hook_load() |
* Implementation of hook_load(). |
| 92 |
* |
* |
| 93 |
*/ |
*/ |
| 94 |
function shoutbox_load($shout_id) { |
function shoutbox_load($shout_id) { |
| 179 |
} |
} |
| 180 |
|
|
| 181 |
/** |
/** |
| 182 |
* Implementation of hook_simpletest(). |
* Implementation of hook_simpletest(). |
| 183 |
*/ |
*/ |
| 184 |
function shoutbox_simpletest() { |
function shoutbox_simpletest() { |
| 185 |
$dir = drupal_get_path('module', 'shoutbox') .'/tests'; |
$dir = drupal_get_path('module', 'shoutbox') .'/tests'; |
| 186 |
$tests = file_scan_directory($dir, '\.test$'); |
$tests = file_scan_directory($dir, '\.test$'); |
| 203 |
/** |
/** |
| 204 |
* Show paged view of full list of shouts. |
* Show paged view of full list of shouts. |
| 205 |
*/ |
*/ |
| 206 |
function shoutbox_page_view() { |
function shoutbox_page_view() { |
| 207 |
drupal_add_css(drupal_get_path('module', 'shoutbox') .'/shoutbox.css'); |
drupal_add_css(drupal_get_path('module', 'shoutbox') .'/shoutbox.css'); |
| 208 |
|
|
| 209 |
// Output the existing shoutbox posts. |
// Output the existing shoutbox posts. |
| 210 |
$shoutbox_posts_data = _shoutbox_display_posts(20, TRUE, TRUE); |
$shoutbox_posts_data = _shoutbox_display_posts(20, TRUE, TRUE); |
| 211 |
$output .= theme('table', array(), $shoutbox_posts_data['rows']); |
$output .= theme('table', array(), $shoutbox_posts_data['rows']); |
| 212 |
$output .= theme('pager', NULL, 3, 0); |
$output .= theme('pager', NULL, 3, 0); |
| 213 |
|
|
| 214 |
return $output; |
return $output; |
| 215 |
} |
} |
| 216 |
|
|
| 321 |
if ($alter_row_color) { |
if ($alter_row_color) { |
| 322 |
$shout_classes .= (($shout->color) ? ("shout-odd ") : ("shout-even ")); |
$shout_classes .= (($shout->color) ? ("shout-odd ") : ("shout-even ")); |
| 323 |
} |
} |
| 324 |
|
|
| 325 |
if ($shout->moderate == 1) { |
if ($shout->moderate == 1) { |
| 326 |
$shout_classes .= "shoutbox-unpublished "; |
$shout_classes .= "shoutbox-unpublished "; |
| 327 |
$shout->shout .= t("(This shout is waiting for approval by a moderator.)"); |
$shout->shout .= t("(This shout is waiting for approval by a moderator.)"); |
| 870 |
* HTML for show_amount number of posts. |
* HTML for show_amount number of posts. |
| 871 |
*/ |
*/ |
| 872 |
function _shoutbox_display_posts($show_amount, $wrap=TRUE, $pager=FALSE) { |
function _shoutbox_display_posts($show_amount, $wrap=TRUE, $pager=FALSE) { |
| 873 |
|
|
| 874 |
$color = 0; |
$color = 0; |
| 875 |
$count = 0; |
$count = 0; |
| 876 |
$output = ''; |
$output = ''; |
| 887 |
$result = pager_query("SELECT * FROM {shoutbox} ORDER BY created DESC", $show_amount); |
$result = pager_query("SELECT * FROM {shoutbox} ORDER BY created DESC", $show_amount); |
| 888 |
} |
} |
| 889 |
|
|
| 890 |
while ($shout = db_fetch_object($result)) { |
while ($shout = db_fetch_object($result)) { |
| 891 |
|
|
| 892 |
if (($shout->moderate == 0) || |
if (($shout->moderate == 0) || |
| 893 |
(_shoutbox_user_access('moderate shoutbox')) || |
(_shoutbox_user_access('moderate shoutbox')) || |
| 894 |
(_shoutbox_is_user_owned($shout))) { |
(_shoutbox_is_user_owned($shout))) { |
| 895 |
|
|
| 896 |
_shoutbox_sanitize_shout($shout); |
_shoutbox_sanitize_shout($shout); |
| 897 |
|
|
| 898 |
// Add edit/delete links depending on user's permissions. |
// Add edit/delete links depending on user's permissions. |
| 899 |
$shoutlinks = _shoutbox_get_links($shout); |
$shoutlinks = _shoutbox_get_links($shout); |
| 900 |
|
|
| 901 |
// Alternate colors for each post (row of the shoutbox). |
// Alternate colors for each post (row of the shoutbox). |
| 902 |
if ($color == 0) { |
if ($color == 0) { |
| 903 |
$color = 1; |
$color = 1; |
| 905 |
else { |
else { |
| 906 |
$color = 0; |
$color = 0; |
| 907 |
} |
} |
| 908 |
|
|
| 909 |
$shout->color = $color; |
$shout->color = $color; |
| 910 |
|
|
| 911 |
// Theme the shoutbox post. |
// Theme the shoutbox post. |
| 912 |
if ($ascending) { |
if ($ascending) { |
| 923 |
if (!$ascending) { |
if (!$ascending) { |
| 924 |
$rows = array_reverse($rows); |
$rows = array_reverse($rows); |
| 925 |
} |
} |
|
|
|
| 926 |
|
|
| 927 |
|
|
| 928 |
|
|
| 929 |
if (!$count) { |
if (!$count) { |
| 930 |
$output .= '<div class="shoutbox-even" title="no shouts">'. t("There are no shouts to view.") ."</div>\n"; |
$output .= '<div class="shoutbox-even" title="no shouts">'. t("There are no shouts to view.") ."</div>\n"; |
| 931 |
} |
} |
| 932 |
|
|
| 933 |
// Don't wrap for ahah refreshes |
// Don't wrap for ahah refreshes |
| 934 |
if ($wrap) { |
if ($wrap) { |
| 935 |
// Wrap shout box messages. |
// Wrap shout box messages. |
| 936 |
$output = "<div id=\"shoutbox-posts\">\n". $output ."</div>\n"; |
$output = "<div id=\"shoutbox-posts\">\n". $output ."</div>\n"; |
| 937 |
} |
} |
| 938 |
|
|
| 939 |
$output_data['count'] = $count; |
$output_data['count'] = $count; |
| 940 |
$output_data['output'] = $output; |
$output_data['output'] = $output; |
| 941 |
$output_data['rows'] = $rows; |
$output_data['rows'] = $rows; |
| 988 |
*/ |
*/ |
| 989 |
function _shoutbox_user_access($permission, $shout=NULL) { |
function _shoutbox_user_access($permission, $shout=NULL) { |
| 990 |
global $user; |
global $user; |
| 991 |
|
|
| 992 |
if (user_access('administer shoutbox')) { |
if (user_access('administer shoutbox')) { |
| 993 |
return TRUE; |
return TRUE; |
| 994 |
} |
} |
| 996 |
|
|
| 997 |
$user_timeout = FALSE; |
$user_timeout = FALSE; |
| 998 |
$user_owned = FALSE; |
$user_owned = FALSE; |
| 999 |
|
|
| 1000 |
$access_granted = user_access($permission); |
$access_granted = user_access($permission); |
| 1001 |
|
|
| 1002 |
// If user_access says no, it's definitely no. |
// If user_access says no, it's definitely no. |
| 1003 |
if (($access_granted) && |
if (($access_granted) && |
| 1004 |
(($permission == 'edit own shouts') || ($permission == 'delete own shouts'))) { |
(($permission == 'edit own shouts') || ($permission == 'delete own shouts'))) { |
| 1005 |
if (_shoutbox_is_user_owned($shout)) { |
if (_shoutbox_is_user_owned($shout)) { |
| 1006 |
// A registered user's own post. |
// A registered user's own post. |
| 1007 |
if (($shout->uid > 0) && ($shout->created < time() - 60 * variable_get('shoutbox_registered_timeout', 1440))) { |
if (($shout->uid > 0) && ($shout->created < time() - 60 * variable_get('shoutbox_registered_timeout', 1440))) { |
| 1008 |
$user_timeout = TRUE; |
$user_timeout = TRUE; |
| 1009 |
} |
} |
| 1010 |
// An anonymous user's own post. |
// An anonymous user's own post. |
| 1011 |
else if (($shout->uid == 0) && ($shout->created < (time() - 60 * variable_get('shoutbox_anonymous_timeout', 20)))) { |
else if (($shout->uid == 0) && ($shout->created < (time() - 60 * variable_get('shoutbox_anonymous_timeout', 20)))) { |
| 1012 |
$user_timeout = TRUE; |
$user_timeout = TRUE; |
| 1048 |
|
|
| 1049 |
if (count($formats) > 1) { |
if (count($formats) > 1) { |
| 1050 |
$form['#title'] = t('Shoutbox Input Format'); |
$form['#title'] = t('Shoutbox Input Format'); |
| 1051 |
} |
} |
| 1052 |
return $form; |
return $form; |
| 1053 |
} |
} |
| 1054 |
|
|
| 1055 |
/** |
/** |
| 1056 |
* Update the moderate bit in the database. |
* Update the moderate bit in the database. |
| 1057 |
* |
* |
| 1058 |
* @param $shout_id |
* @param $shout_id |
| 1059 |
* The shout id of the shout being moderated. |
* The shout id of the shout being moderated. |
| 1060 |
* |
* |
| 1061 |
* @param $moderate |
* @param $moderate |
| 1062 |
* The vale to set the moderate bit to. (0 or 1) |
* The vale to set the moderate bit to. (0 or 1) |
| 1063 |
* |
* |
| 1064 |
* @return |
* @return |
| 1065 |
* N/A |
* N/A |
| 1066 |
*/ |
*/ |
| 1067 |
function _shoutbox_moderate_shout($shout_id, $moderate) { |
function _shoutbox_moderate_shout($shout_id, $moderate) { |
| 1105 |
else if (($shout->uid == 0) && ($user->uid == 0)) { |
else if (($shout->uid == 0) && ($user->uid == 0)) { |
| 1106 |
if ($shout->sid == session_id()) { |
if ($shout->sid == session_id()) { |
| 1107 |
$user_owned = TRUE; |
$user_owned = TRUE; |
| 1108 |
} |
} |
| 1109 |
else if (empty($shout->sid) && !empty($shout->hostname)) { |
else if (empty($shout->sid) && !empty($shout->hostname)) { |
| 1110 |
$user_owned = ($shout->hostname == ip_address()); |
$user_owned = ($shout->hostname == ip_address()); |
| 1111 |
} |
} |