/** * Send a message to the public forum. The variables passed are assumed to be already sanitized * * @param int $toID User/Thread ID to send to * @param int $fromUserID UserID sent from * @param string $message The message to be sent * @param string[optional] $subject The subject * @param string[optional] $type 'Bulletin'(GameMaster->Player) 'ThreadStart'(User->All) 'ThreadReply'(User->Thread) * * @return int The message ID */ public static function send($toID, $fromUserID, $message, $subject = "", $type = 'Bulletin') { global $DB; if (defined('AdminUserSwitch')) { $fromUserID = AdminUserSwitch; } $message = self::linkify($message); $sentTime = time(); if (65000 < strlen($message)) { throw new Exception(l_t("Message too long")); } libCache::wipeDir(libCache::dirName('forum')); $DB->sql_put("INSERT INTO wD_ForumMessages\r\n\t\t\t\t\t\tSET toID = " . $toID . ", fromUserID = " . $fromUserID . ", timeSent = " . $sentTime . ",\r\n\t\t\t\t\t\tmessage = '" . $message . "', subject = '" . $subject . "', replies = 0,\r\n\t\t\t\t\t\ttype = '" . $type . "', latestReplySent = 0"); $id = $DB->last_inserted(); if ($type == 'ThreadReply') { $DB->sql_put("UPDATE wD_ForumMessages " . "SET latestReplySent = " . $id . ", replies = replies + 1 WHERE ( id=" . $id . " OR id=" . $toID . " )"); } else { $DB->sql_put("UPDATE wD_ForumMessages SET latestReplySent = id WHERE id = " . $id); } $tabl = $DB->sql_tabl("SELECT t.id FROM wD_ForumMessages t LEFT JOIN wD_ForumMessages r ON ( r.toID=t.id AND r.fromUserID=" . $fromUserID . " AND r.type='ThreadReply' ) WHERE t.type='ThreadStart' AND ( t.fromUserID=" . $fromUserID . " OR r.id IS NOT NULL ) GROUP BY t.id"); $participatedThreadIDs = array(); while (list($participatedThreadID) = $DB->tabl_row($tabl)) { $participatedThreadIDs[$participatedThreadID] = $participatedThreadID; } $cacheUserParticipatedThreadIDsFilename = libCache::dirID('users', $fromUserID) . '/readThreads.js'; file_put_contents($cacheUserParticipatedThreadIDsFilename, 'participatedThreadIDs = $A([' . implode(',', $participatedThreadIDs) . ']);'); return $id; }
/** * Create a tree-like folder for a game in a given base folder. e.g. gameFolder('../mapstore',12345) * will return '../mapstore/123/12345', and make sure that that directory exists. * This is used for storing maps, and orderlogs. * * @param $baseDirectory The base directory to write to * @param $gameID The gameID * @return string The game folder */ public static function gameFolder($gameID) { if (defined('DATC')) { return 'datc/maps'; } else { return libCache::dirID('games', $gameID); } }
public static function cacheDir($id) { return libCache::dirID('users', $id); }
private static function footerScripts() { global $User, $Locale; $jsVersion = 4; // increment this to force clients to reload their JS files $buf = ''; // onlineUsers, for the online icons $statsDir = libCache::dirName('stats'); $onlineFile = l_s($statsDir . '/onlineUsers.json'); if (file_exists($onlineFile)) { $buf .= '<script type="text/javascript" src="' . STATICSRV . $onlineFile . '"></script>'; } else { $buf .= '<script type="text/javascript">onlineUsers = $A([ ]);</script>'; } if (!is_object($User)) { return $buf; } elseif ($User->type['User']) { // Muted users $gameMutePairs = array(); foreach ($User->getMuteCountries() as $gameMutePair) { $gameMutePairs[] = '[' . $gameMutePair[0] . ',' . $gameMutePair[1] . ']'; } $buf .= ' <script type="text/javascript"> muteUsers = $A([' . implode(',', $User->getMuteUsers()) . ']); muteCountries = $A([' . implode(',', $gameMutePairs) . ']); muteThreads = $A([' . implode(',', $User->getMuteThreads()) . ']); </script>'; unset($gameMutePairs); self::$footerIncludes[] = l_j('mute.js'); self::$footerScript[] = l_jf('muteAll') . '();'; // Participated threads $cacheUserParticipatedThreadIDsFilename = libCache::dirID('users', $User->id) . '/readThreads.js'; if (file_exists($cacheUserParticipatedThreadIDsFilename)) { $buf .= '<script type="text/javascript" src="' . STATICSRV . $cacheUserParticipatedThreadIDsFilename . '?nocache=' . rand(0, 999999) . '"></script>'; libHTML::$footerScript[] = l_jf('setForumParticipatedIcons') . '();'; } } if (is_object($Locale)) { $Locale->onFinish(); } // Add the javascript includes: $footerIncludes = array(); $footerIncludes[] = l_j('../locales/layer.js'); $footerIncludes[] = l_j('../locales/English/layer.js'); $footerIncludes[] = l_j('contrib/sprintf.js'); $footerIncludes[] = l_j('utility.js'); $footerIncludes[] = l_j('cacheUpdate.js'); $footerIncludes[] = l_j('timeHandler.js'); $footerIncludes[] = l_j('forum.js'); $footerIncludes[] = l_j('Color.Vision.Daltonize.js'); // Don't localize all the footer includes here, as some of them may be dynamically generated foreach (array_merge($footerIncludes, self::$footerIncludes) as $includeJS) { // Add on the dynamically added includes $buf .= '<script type="text/javascript" src="' . STATICSRV . JSDIR . '/' . $includeJS . '?ver=' . $jsVersion . '"></script>'; } // Utility (error detection, message protection), HTML post-processing, // time handling functions. Only logged-in users need to run these $buf .= ' <script type="text/javascript"> var UserClass = function () { this.id=' . $User->id . '; this.username="******"; this.points=' . $User->points . ' this.lastMessageIDViewed=' . $User->lastMessageIDViewed . '; this.timeLastSessionEnded=' . $User->timeLastSessionEnded . '; this.token="' . md5(Config::$secret . $User->id . 'Array') . '"; } User = new UserClass(); WEBDIP_DEBUG=' . (Config::$debug ? 'true' : 'false') . '; document.observe("dom:loaded", function() { try { ' . l_jf('Locale.onLoad') . '(); ' . l_jf('onlineUsers.push') . '(User.id); ' . l_jf('setUserOnlineIcons') . '(); ' . l_jf('setForumMessageIcons') . '(); ' . l_jf('setPostsItalicized') . '(); ' . l_jf('updateTimestamps') . '(); ' . l_jf('updateUTCOffset') . '(); ' . l_jf('updateTimers') . '(); ' . implode("\n", self::$footerScript) . ' ' . l_jf('Locale.afterLoad') . '(); } catch( e ) { ' . (Config::$debug ? 'alert(e);' : '') . ' } }, this); </script> '; if (Config::$debug) { $buf .= '<br /><strong>JavaScript localization lookup failures:</strong><br /><span id="jsLocalizationDebug"></span>'; } return $buf; }
along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>. */ /** * @package Admin */ require_once 'header.php'; ini_set('memory_limit', "128M"); // 8M is the default ini_set('max_execution_time', '240'); if ($User->type['Moderator'] && isset($_REQUEST['viewOrderLogGame']) && isset($_REQUEST['viewOrderLogCountryID'])) { $gameID = (int) $_REQUEST['viewOrderLogGame']; $countryID = (int) $_REQUEST['viewOrderLogCountryID']; require_once l_r('objects/game.php'); $Variant = libVariant::loadFromGameID($gameID); $Game = $Variant->Game($gameID); if (!($data = file_get_contents(libCache::dirID(Config::orderlogDirectory(), $gameID, true) . '/' . $countryID . '.txt'))) { trigger_error(l_t("Couldn't open file %s.txt", $log)); } header('Content-type:text/plain'); print $data; die; } if ($User->type['Admin'] && isset($_REQUEST['viewErrorLog'])) { $log = (int) $_REQUEST['viewErrorLog']; if (!($data = file_get_contents(Config::errorlogDirectory() . '/' . $log . '.txt'))) { trigger_error(l_t("Couldn't open file %s.txt", $log)); } header('Content-type:text/plain'); print $data; die; }
$tabl = $DB->sql_tabl($query); while (list($row) = $DB->tabl_row($tabl)) { print $row . ', '; } } if ($User->type['Admin']) { // Get the order logs used to validate whether stories about orders being swapped around if (isset($_REQUEST['viewOrderLogGameID']) && isset($_REQUEST['viewOrderLogCountryID'])) { $viewOrderLogGameID = (int) $_REQUEST['viewOrderLogGameID']; $viewOrderLogCountryID = (int) $_REQUEST['viewOrderLogCountryID']; $orderlogDirectory = Config::orderlogDirectory(); if (false === $orderlogDirectory) { print '<p class="notice">' . l_t('Order logging not enabled; check config.php') . '</p>'; } else { require_once l_r('objects/game.php'); $logfile = libCache::dirID($orderlogDirectory, $viewOrderLogGameID, true) . '/' . $viewOrderLogCountryID . '.txt'; if (!file_exists($logfile)) { print '<p class="notice">' . l_t('No log file found for this gameID/countryID.') . '</p>'; } else { print '<pre>' . file_get_contents($logfile) . '</pre>'; } unset($logfile); } } else { $viewOrderLogGameID = ''; $viewOrderLogCountryID = ''; } print '<p><strong>' . l_t('Order logs:') . '</strong><form action="admincp.php" method="get"> ' . l_t('Game ID') . ': <input type="text" name="viewOrderLogGameID" value="' . $viewOrderLogGameID . '" /> ' . l_t('CountryID') . ': <input type="text" name="viewOrderLogCountryID" value="' . $viewOrderLogCountryID . '" /> <input type="submit" name="' . l_t('Submit') . '" /></form></p>';
</li>'; } elseif ($UserProfile->hideEmail == 'No') { $emailCacheFilename = libCache::dirID('users', $UserProfile->id) . '/email.png'; if (!file_exists($emailCacheFilename)) { $image = imagecreate(strlen($UserProfile->email) * 8, 15); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); imagestring($image, 2, 10, 1, $UserProfile->email, $black); imagepng($image, $emailCacheFilename); } print '<li><strong>' . l_t('E-mail:') . '</strong> <img src="' . STATICSRV . $emailCacheFilename . '" alt="' . l_t('[E-mail address image]') . '" title="' . l_t('To protect e-mails from spambots they are embedded in an image') . '" > </li>'; } if ($UserProfile->hideEmail != 'No') { $emailCacheFilename = libCache::dirID('users', $UserProfile->id) . '/email.png'; if (file_exists($emailCacheFilename)) { unlink($emailCacheFilename); } } if ($UserProfile->homepage) { print '<li><strong>' . l_t('Home page:') . '</strong> ' . $UserProfile->homepage . '</li>'; } print '<li> </li>'; //print '<li><a href="profile.php?detail=reports&userID='.$UserProfile->id.'" class="light">View/post a moderator report</a></li>'; //print '<li> </li>'; print '</li></ul></p></div><div style="clear:both"></div></div>'; // Start interactive area: if ($User->type['Moderator'] && $User->id != $UserProfile->id) { $modActions = array(); if ($User->type['Admin']) {
protected function log($logData) { $orderlogDirectory = Config::orderlogDirectory(); if (false === $orderlogDirectory) { return; } require_once l_r('objects/game.php'); $directory = libCache::dirID($orderlogDirectory, $this->gameID, true); $file = $this->countryID . '.txt'; if (!($orderLog = fopen($directory . '/' . $file, 'a'))) { trigger_error(l_t("Couldn't open order log file.")); } if (!fwrite($orderLog, 'Time: ' . gmdate("M d Y H:i:s") . " (UTC+0)\n" . $logData . "\n\n")) { trigger_error(l_t("Couldn't write to order log file.")); } fflush($orderLog) or trigger_error(l_t("Couldn't write to order log file.")); fclose($orderLog); }