= $endYear; $i--) { for ($j = 1; $j <= 12; $j++) { refreshCachedRequest($j, $i, $board, $currentLocale); if (date("Y") == $i && date("n") == $j) { break; } } } } function refreshCachedRequest($month, $year, $board, $currentLocale) { $request = retreiveMonthFromFenix($month, $year, $board, $currentLocale); if ($request != null && $request != "") { $request = utf8_encode($request); $path = cacheFilePathFor($month, $year, $board, $currentLocale); writeToFile($path, $request); } } function retreiveMonthFromFenix($month, $year, $board, $currentLocale) { global $fenixAnnouncementExportURL; $contents = ''; $handle = @fopen($fenixAnnouncementExportURL . '?method=getAnnouncements&announcementBoardId=' . $board . '&selectedYear=' . $year . '&selectedMonth=' . $month . '&language=' . $currentLocale, "r"); if ($handle) { while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); } return $contents; } function cacheFilePathFor($month, $year, $board, $currentLocale) { return filePathPrefixFor($month, $year, $board, $currentLocale) . '.cache'; } function filePathPrefixFor($month, $year, $board, $currentLocale) { global $HOMEDIR; $fullMonth = $month >= 10 ? $month : '0' . $month; return $HOMEDIR . '/newscache/' . $board . '.' . $fullMonth . '.' . $year . '.' . $currentLocale; } function writeToFile($path, $content) { $file = fopen($path, 'w+'); // binary update mode if (flock($file, LOCK_EX)) { // do an exclusive lock rewind($file); fwrite($file, $content); fflush($file); ftruncate($file, ftell($file)); flock($file, LOCK_UN); // release the lock } fclose($file); } ?>