/** * 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; }
public static function wipeCache($gameID, $turn = false) { $dir = self::gameFolder($gameID); if (defined('DATC')) { libCache::wipeDir($dir, '*json*'); } else { libCache::wipeDir($dir, $turn === false ? '*.*' : '*' . $turn . '-*.*'); } }
public static function wipeCache($id, $glob = '*.*') { $dir = self::cacheDir($id); libCache::wipeDir($dir, $glob); file_put_contents($dir . '/index.html', ''); }