示例#1
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new Cache();
     }
     return self::$instance;
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * 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);
     }
 }
示例#4
0
 public static function wipeCache($id, $glob = '*.*')
 {
     $dir = self::cacheDir($id);
     libCache::wipeDir($dir, $glob);
     file_put_contents($dir . '/index.html', '');
 }
示例#5
0
libHTML::starthtml(l_t('GameMaster'));
print '<div class="content">';
$DB->sql_put("COMMIT");
// Unlock our user row, to prevent deadlocks below
// This means our $User object should only be used for reading from
ini_set('memory_limit', "40M");
ini_set('max_execution_time', '40');
/*
 * - Update session table
 * - Update misc values (if running as admin/mod)
 * - Check last process time, pause processing/save current process time
 * - Check queue and games table for games to process, votes to enact, and system functions to perform
 */
print l_t('Updating session table') . '<br />';
libGameMaster::updateSessionTable();
$statsDir = libCache::dirName('stats');
$onlineFile = $statsDir . '/onlineUsers.json';
$tabl = $DB->sql_tabl("SELECT userID FROM wD_Sessions");
$onlineUsers = array();
while (list($userID) = $DB->tabl_row($tabl)) {
    $onlineUsers[] = $userID;
}
file_put_contents($onlineFile, 'onlineUsers=$A([' . implode(',', $onlineUsers) . ']);');
//- Update misc values (if running as admin/mod)
if (!$User->type['System'] || time() % (15 * 60) <= 5 * 60) {
    print l_t('Updating Misc values') . '<br />';
    miscUpdate::errorLog();
    miscUpdate::forum();
    miscUpdate::game();
    miscUpdate::user();
}
示例#6
0
print $forumPager->html();
if ($User->type['User']) {
    print '<div id="forumOpenPostbox" style="' . ($postboxopen ? libHTML::$hideStyle : '') . '" >
			<form action="forum.php#postbox" method="get" onsubmit="$(\'forumPostbox\').show(); $(\'forumOpenPostbox\').hide(); return false;">
			<p style="padding:5px;">
				<input type="hidden" name="postboxopen" value="1" />
				<input type="hidden" name="page" value="' . $forumPager->pageCount . '" />
				<input type="submit" class="form-submit" value="' . l_t('New thread') . '" />
			</p>
		</form>
		</div>';
}
print '<div style="clear:both;"> </div>
		</div>
		';
$cacheHTML = libCache::dirName('forum') . '/page_' . $forumPager->currentPage . '.html';
if (file_exists($cacheHTML)) {
    print $cacheHTML;
}
$tabl = $DB->sql_tabl("SELECT\r\n\tf.id, f.fromUserID, f.timeSent, f.message, f.subject, f.replies,\r\n\t\tu.username as fromusername, u.points as points, f.latestReplySent, IF(s.userID IS NULL,0,1) as online, u.type as userType, \r\n\t\tf.likeCount as likeCount, \r\n\t\tf.silenceID,\r\n\t\tsilence.userID as silenceUserID,\r\n\t\tsilence.postID as silencePostID,\r\n\t\tsilence.moderatorUserID as silenceModeratorUserID,\r\n\t\tsilence.enabled as silenceEnabled,\r\n\t\tsilence.startTime as silenceStartTime,\r\n\t\tsilence.length as silenceLength,\r\n\t\tsilence.reason as silenceReason\r\n\tFROM wD_ForumMessages f\r\n\tINNER JOIN wD_Users u ON ( f.fromUserID = u.id )\r\n\tLEFT JOIN wD_Sessions s ON ( u.id = s.userID )\r\n\tLEFT JOIN wD_Silences silence ON ( f.silenceID = silence.id )\r\n\tWHERE f.type = 'ThreadStart'\r\n\tORDER BY f.latestReplySent DESC\r\n\t" . $forumPager->SQLLimit());
/*
 * If it's a new post, jump to it
 *
 */
$switch = 2;
while ($message = $DB->tabl_hash($tabl)) {
    if (Silence::isSilenced($message)) {
        $silence = new Silence($message);
    } else {
        unset($silence);
    }
示例#7
0
    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;
    }
示例#8
0
   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>';
示例#10
0
		</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>&nbsp;</li>';
//print '<li><a href="profile.php?detail=reports&userID='.$UserProfile->id.'" class="light">View/post a moderator report</a></li>';
//print '<li>&nbsp;</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']) {
示例#11
0
 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);
 }
示例#12
0
 */
 print '<div class="content-bare content-home-header">';
 // content-follow-on">';
 print '<table class="homeTable"><tr>';
 print '<td class="homeMessages">';
 $liveGames = libHome::upcomingLiveGames();
 if ($liveGames != '') {
     print '<div class="homeHeader">' . l_t('Upcoming live games') . ' <a href="gamelistings.php?page-games=1&gamelistType=New">' . libHTML::link() . '</a></div>';
     print $liveGames;
 }
 print '<div class="homeHeader">' . l_t('Forum') . ' <a href="forum.php">' . libHTML::link() . '</a></div>';
 if (file_exists(libCache::dirName('forum') . '/home-forum.html')) {
     print file_get_contents(libCache::dirName('forum') . '/home-forum.html');
 } else {
     $buf_home_forum = libHome::forumNew();
     file_put_contents(libCache::dirName('forum') . '/home-forum.html', $buf_home_forum);
     print $buf_home_forum;
 }
 print '</td>';
 print '<td class="homeSplit"></td>';
 print '<td class="homeGameNotices">';
 /*$buf = libHome::PMs();
 	if(strlen($buf))
 		print '<div class="homeHeader">Private messages</div>'.$buf;
 	*/
 print '<div class="homeHeader">' . l_t('Notices') . ' <a href="index.php?notices=on">' . libHTML::link() . '</a></div>';
 print libHome::Notice();
 print '</td>';
 print '<td class="homeSplit"></td>';
 print '<td class="homeGamesStats">';
 print '<div class="homeHeader">' . l_t('My games') . ' <a href="gamelistings.php?page=1&gamelistType=My games">' . libHTML::link() . '</a></div>';