$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 ' '; $result = db_query("SELECT time FROM {$db_prefix}sbox_content ORDER BY time DESC LIMIT 1", __FILE__, __LINE__); $row = mysql_fetch_assoc($result); $refreshBlocked = false; $delta = time() - $row['time']; if ((!empty($_REQUEST['action'])) && ($_REQUEST['action'] == 'write')) $dontblock = true; else $dontblock = false; if (($delta > $modSettings['lastActive']*60) && ($modSettings['sbox_BlockRefresh'] == '1') && (!$dontblock)) { $refreshBlocked = true; } else { echo ' '; } echo ' '; if (!empty($_REQUEST['action'])) switch ($_REQUEST['action']) { case 'write': if (((!$context['user']['is_guest']) || ($modSettings['sbox_GuestAllowed'] == '1')) && !empty($_REQUEST['sboxText'])) { $content=$_REQUEST['sboxText']; // get current timestamp $date = time(); $posterip = $user_info['ip']; $pip = explode('.', $posterip); $piph = sprintf("%02s%02s%02s%02s", dechex($pip[0]), dechex($pip[1]), dechex($pip[2]), dechex($pip[3])); // handle special characters $content = addslashes($piph . $content); // insert shout message into database $sql = "INSERT INTO " . $db_prefix . "sbox_content (ID_MEMBER, content, time) VALUES ('" . $context['user']['id'] . "', '" . $content . "', '$date')"; db_query($sql, __FILE__, __LINE__); // delete old shout messages (get id of last shouting and delete all shoutings as defined in settings $result = db_query("SELECT id FROM " . $db_prefix . "sbox_content WHERE ID_MEMBER='" . $context['user']['id'] . "' AND content='" . $content . "' AND time='$date'", __FILE__, __LINE__); $rows = mysql_fetch_assoc($result); $sql = 'DELETE FROM ' . $db_prefix . "sbox_content WHERE id < '" . ($rows["id"]-$modSettings['sbox_MaxLines']) . "'"; db_query($sql, __FILE__, __LINE__); // write into history if needed if ($modSettings['sbox_DoHistory'] == '1') { $ds = date('Y-m-d', $date) . ' | ' . date('H:i.s', $date); $content = stripslashes($content); // shouting content $content = substr($content, 8); $content = htmlentities($content); if ($modSettings['sbox_AllowBBC'] == '1' && ($context['user']['id'] > 0 || $modSettings['sbox_GuestBBC'] == '1')) { $content = parse_bbc($content); } $output = '[ ' . $ds . ' ] ' . $sbox_NickPrefix; if ($context['user']['id'] > 0) { $output .= ''; $output .= ((!empty($context['user']['name']))?$context['user']['name']:$context['user']['username']); $output .= ''; } else { $output .= 'Guest-' . base_convert($piph, 16, 36); } $output .= $sbox_NickSuffix . ' ' . $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)) { $lockDir = $sbox_HistoryFile . '.lock'; $start = time(); while ((is_dir($lockDir)) && ((time() - $start) < 5)) { usleep(100000); // sleep 1/10th of a second (for a PC these are ages!) } if (!is_dir($lockDir)) @unlink($sbox_HistoryFile); } } break; case 'kill': if (!empty($_REQUEST['kill']) && ($context['user']['is_admin'] || ($modSettings['sbox_ModsRule'] && count(boardsAllowedTo('moderate_board'))>0))) { $sql = 'DELETE FROM ' . $db_prefix . 'sbox_content WHERE id=' . intval($_REQUEST['kill']); db_query($sql, __FILE__, __LINE__); } break; } // close header and open body echo ' '; echo "\n" . '
[ ' . strftime($user_info['time_format'], forum_time(true)) . ' ]'; if ($refreshBlocked) { echo ' [ ' . $txt['sbox_RefreshBlocked'] . ' ]'; } echo '
'; if ($context['user']['is_admin']) { if ($modSettings['sbox_DoHistory'] == '1') { echo "\n" . '
'; if (file_exists($sbox_HistoryFile)) { echo '[' . $txt['sbox_History'] . ']'; echo ' [' . $txt['sbox_HistoryClear'] . ']'; } else { echo '[' . $txt['sbox_HistoryNotFound'] . ']'; } echo '
'; } } /* if (!empty($settings['display_who_viewing'])) { echo ''; if ($settings['display_who_viewing'] == 1) echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt[19]; else echo empty($context['view_members_list']) ? '0 ' . $txt[19] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) or $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')'); echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_board'], ''; } */ // get shout messages out of database $result = db_query(" SELECT * FROM {$db_prefix}sbox_content AS sb LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = sb.ID_MEMBER) ORDER BY id DESC, time ASC LIMIT " . $modSettings['sbox_MaxLines'], __FILE__, __LINE__); if(mysql_num_rows($result)) { $lname = ''; $count = 0; $div = false; $alert = false; while($row = mysql_fetch_assoc($result)) { $name = $row['ID_MEMBER']; // user name $date = forum_time(true, $row['time']); // shouting date and time $content = stripslashes($row['content']); // shouting content $piph = substr($content, 0, 8); $content = substr($content, 8); $content = htmlentities($content); if ($modSettings['sbox_AllowBBC'] == '1' && ($name > 0 || $modSettings['sbox_GuestBBC'] == '1')) { $content = parse_bbc($content); } if (!empty($_REQUEST['ts']) && !$div && $date<$_REQUEST['ts']) { if ($count > 0 && $modSettings['sbox_NewShoutsBar'] == '1') { echo '
' . "\n"; } $div = true; } if ($name != $lname) { $count++; // increase counter } $lname = $name; // display shouting message and use a different color each second row if ($count % 2 == 0) { $divclass = 'Odd'; } else { $divclass = 'Even'; } /* $r = $g = $b = 0; for ($i=0;$i'; */ echo "\n" . '
'; if ($context['user']['is_admin'] || ($modSettings['sbox_ModsRule'] && count(boardsAllowedTo('moderate_board'))>0)) { echo '[X]'; } $wd = $txt['days_short'][date('w', $date)]; $ts = date('H:i', $date); $ds = $wd . ' | ' . $ts; // highlight username, realname and make sound if (!empty($context['user']['name']) && strpos($content, $context['user']['name']) !== false) { if ($div === false) $alert = true; $content = str_replace($context['user']['name'], '' . $context['user']['name'] . '', $content); } if (!empty($user_info['username']) && $user_info['username'] != $context['user']['name'] && strpos($content, $user_info['username']) !== false) { if ($div === false) $alert = true; $content = str_replace($user_info['username'], '' . $user_info['username'] . '', $content); } echo '[ ' . $ds . ' ] ' . $sbox_NickPrefix; if ($name > 0) { if ($modSettings['sbox_UserLinksVisible'] == '1') echo ''; echo ((!empty($row['realName']))?$row['realName']:$row['memberName']); if ($modSettings['sbox_UserLinksVisible'] == '1') echo ''; } else { echo $txt['sbox_Guest'] . '-' . base_convert($piph, 16, 36); } echo $sbox_NickSuffix . ' ' . $content . '
'; } if (($modSettings['sbox_EnableSounds']) && ($alert === true) && ($div === true)) { echo '' . "\n"; } } ?>