diff --git a/package-info.xml b/package-info.xml index 0dcb9d4..a4a5fdf 100644 --- a/package-info.xml +++ b/package-info.xml @@ -21,16 +21,17 @@ Copyright 2006 - Neither this package or any of it's contents may be distributed without authorisation. ]]> - sbox_v1.10.mod + sbox_11rc2.mod Uninstall will remove all the changes made by the shoutbox. You must do this before upgrading! - sbox_v1.10.mod + sbox_11rc2.mod + sbox_remove.php diff --git a/sboxDB.php b/sboxDB.php index a2571f3..d267c3c 100644 --- a/sboxDB.php +++ b/sboxDB.php @@ -8,8 +8,68 @@ require("../SSI.php"); if (!defined('SMF')) die('Hacking attempt...'); -// global variables -global $db_connection, $context, $settings, $txt, $user_info, $modSettings, $db_prefix; +// global variables (they are always global since we're here in the main routine) +// global $db_connection, $context, $settings, $txt, $user_info, $modSettings, $db_prefix, $boarddir, $boardurl; + +$sbox_HistoryFile = $boarddir . '/sbox.history.html'; + +// BEGIN: BORROWED FROM http://de2.php.net/manual/en/function.flock.php +/* + * I hope this is usefull. + * If mkdir() is atomic, + * then we do not need to worry about race conditions while trying to make the lockDir, + * unless of course were writing to NFS, for which this function will be useless. + * so thats why i pulled out the usleep(rand()) peice from the last version + * + * Again, its important to tailor some of the parameters to ones indivdual usage + * I set the default $timeLimit to 3/10th's of a second (maximum time allowed to achieve a lock), + * but if your writing some extrememly large files, and/or your server is very slow, you may need to increase it. + * Obviously, the $staleAge of the lock directory will be important to consider as well if the writing operations might take a while. + * My defaults are extrememly general and you're encouraged to set your own + * + * $timeLimit is in microseconds + * $staleAge is in seconds + */ + +function microtime_float() { + list($usec, $sec) = explode(' ', microtime()); + return ((float)$usec + (float)$sec); +} + +function locked_filewrite($filename, $data, $timeLimit = 300000, $staleAge = 5) { + ignore_user_abort(1); + $lockDir = $filename . '.lock'; + + if (is_dir($lockDir)) { + if ((time() - filemtime($lockDir)) > $staleAge) { + rmdir($lockDir); + } + } + + $locked = @mkdir($lockDir); + + if ($locked === false) { + $timeStart = microtime_float(); + do { + if ((microtime_float() - $timeStart) > $timeLimit) break; + $locked = @mkdir($lockDir); + } while ($locked === false); + } + + $success = false; + + if ($locked === true) { + $fp = @fopen($filename, 'at'); + if (@fwrite($fp, $data)) $success = true; + @fclose($fp); + rmdir($lockDir); + } + + ignore_user_abort(0); + return $success; +} +// END: BORROWED FROM http://de2.php.net/manual/en/function.flock.php + //display html header echo ' @@ -25,6 +85,10 @@ echo '<' . ((!empty($context['user']['name']))?$context['user']['name']:$context['user']['username']) . '> ' . $content . '
' . "\n"; + + if (!file_exists($sbox_HistoryFile)) { + // TODO: Prepare file ... HTML-header, stylesheet, etc. + } + + locked_filewrite($sbox_HistoryFile, $output); + } + } + break; + + case 'clearhist': + if ($context['user']['is_admin']) { + if (file_exists($sbox_HistoryFile)) { + // TODO: Check for existing lock, wait for lock to be released and delete then. + @unlink($sbox_HistoryFile); + } } break; @@ -100,8 +192,18 @@ echo ' echo "\n" . '
[ ' . strftime($user_info['time_format'], forum_time(true)) . ' ]
'; if ($context['user']['is_admin']) { + echo "\n" . '
'; + if ($modSettings['sbox_DoHistory'] == '1') { + if (file_exists($sbox_HistoryFile)) { + echo '[' . $txt['sbox_History'] . ']'; + echo ' [' . $txt['sbox_HistoryClear'] . ']'; + } else { + echo '[' . $txt['sbox_HistoryNotFound'] . ']'; + } + } // debug output for separator-bar -// echo "\n" . '
( CurTime: ' . forum_time(true) . ' / LastTime: ' . $_REQUEST['ts'] . ' )
'; +// echo ' ( CurTime: ' . forum_time(true) . ' / LastTime: ' . $_REQUEST['ts'] . ' )'; + echo '
'; } /* @@ -175,7 +277,7 @@ if(mysql_num_rows($result)) { echo "\n" . '
'; if ($context['user']['is_admin']) { - echo '[X]'; + echo '[X]'; } $wd = $txt['days_short'][date('w', $date)]; diff --git a/sbox_v1.10.mod b/sbox_11rc2.mod similarity index 94% rename from sbox_v1.10.mod rename to sbox_11rc2.mod index e3cf8a6..7604858 100644 --- a/sbox_v1.10.mod +++ b/sbox_11rc2.mod @@ -93,8 +93,8 @@ $txt['sbox_ModTitle'] = 'SMF Shoutbox'; $txt['sbox_Visible'] = 'Shoutbox is visible'; $txt['sbox_GuestAllowed'] = 'Guests are allowed to shout'; $txt['sbox_GuestVisible'] = 'Make Shoutbox visible to Guests'; -$txt['sbox_MaxLines'] = 'Maximum number of displayed lines'; -$txt['sbox_Height'] = 'Shoutbox height'; +$txt['sbox_MaxLines'] = 'Maximum number of displayed shouts'; +$txt['sbox_Height'] = 'Shoutbox height (px)'; $txt['sbox_SmiliesVisible'] = 'Smiley row is visible'; $txt['sbox_KillShout'] = 'Dou you want to kill this shout?'; $txt['sbox_TextSize1'] = '1. Font size'; @@ -108,6 +108,9 @@ $txt['sbox_FontFamily2'] = '2. Font family'; $txt['sbox_DoHistory'] = 'Create history of shouts'; $txt['sbox_AllowBBC'] = 'Allow BBCode'; $txt['sbox_Refresh'] = 'Refresh'; +$txt['sbox_History'] = 'History'; +$txt['sbox_HistoryClear'] = 'Clear history'; +$txt['sbox_HistoryNotFound'] = 'No history found.'; @@ -172,8 +175,8 @@ function ModifySboxSettings() $config_vars = array ( array('check', 'sbox_Visible'), - array('check', 'sbox_GuestAllowed'), array('check', 'sbox_GuestVisible'), + array('check', 'sbox_GuestAllowed'), array('check', 'sbox_SmiliesVisible'), array('check', 'sbox_AllowBBC'), array('check', 'sbox_DoHistory'), diff --git a/sbox_setup.php b/sbox_setup.php index 6d7204a..49d37b2 100644 --- a/sbox_setup.php +++ b/sbox_setup.php @@ -21,10 +21,10 @@ $overwrite_old_settings = false; $mod_settings = array( 'sbox_Visible' => '1', 'sbox_GuestAllowed' => '0', - 'sbox_GuestVisible' => '1', + 'sbox_GuestVisible' => '0', 'sbox_SmiliesVisible' => '1', 'sbox_AllowBBC' => '1', - 'sbox_DoHistory' => '0', + 'sbox_DoHistory' => '1', 'sbox_MaxLines' => '50', 'sbox_Height' => '180', 'sbox_RefreshTime' => '20',