public function add($csvRow) { $lock = fopen("../storage/waitlists/update.lock", "r"); if (flock($lock, LOCK_SH)) { if (!file_exists($this->filePath)) { $entry = "Course,Section,First Name,Last Name,Email,Student ID,Reason" . $csvRow; } else { $entry = $csvRow; } $fp = fopen($this->filePath, 'a'); chmod($this->filePath, 0600); // lock file for write if (flock($fp, LOCK_EX)) { // write entire line before releasing lock set_file_buffer($fp, 0); fwrite($fp, $entry); flock($fp, LOCK_UN); } else { error_log("could not obtain lock for " . $this->department . " file."); } fclose($fp); } else { error_log("Could not add to waitlists"); } flock($lock, LOCK_UN); fclose($lock); }
function plugin_counter_get_count($page) { global $vars; static $counters = array(); static $default; if (!isset($default)) { $default = array('total' => 0, 'date' => get_date('Y/m/d'), 'today' => 0, 'yesterday' => 0, 'ip' => ''); } if (!is_page($page)) { return $default; } if (isset($counters[$page])) { return $counters[$page]; } // Set default $counters[$page] = $default; $modify = FALSE; $file = COUNTER_DIR . encode($page) . PLUGIN_COUNTER_SUFFIX; $fp = fopen($file, file_exists($file) ? 'r+' : 'w+') or die('counter.inc.php: Cannot open COUTER_DIR/' . basename($file)); set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); foreach ($default as $key => $val) { // Update $counters[$page][$key] = rtrim(fgets($fp, 256)); if (feof($fp)) { break; } } if ($counters[$page]['date'] != $default['date']) { // New day $modify = TRUE; $is_yesterday = $counters[$page]['date'] == get_date('Y/m/d', strtotime('yesterday', UTIME)); $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR']; $counters[$page]['date'] = $default['date']; $counters[$page]['yesterday'] = $is_yesterday ? $counters[$page]['today'] : 0; $counters[$page]['today'] = 1; $counters[$page]['total']++; } else { if ($counters[$page]['ip'] != $_SERVER['REMOTE_ADDR']) { // Not the same host $modify = TRUE; $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR']; $counters[$page]['today']++; $counters[$page]['total']++; } } // Modify if ($modify && $vars['cmd'] == 'read') { rewind($fp); ftruncate($fp, 0); foreach (array_keys($default) as $key) { fputs($fp, $counters[$page][$key] . "\n"); } } flock($fp, LOCK_UN); fclose($fp); return $counters[$page]; }
function ref_save($page) { global $referer, $use_spam_check; // if (PKWK_READONLY || ! $referer || empty($_SERVER['HTTP_REFERER'])) return TRUE; // if (auth::check_role('readonly') || ! $referer || empty($_SERVER['HTTP_REFERER'])) return TRUE; if (!$referer || empty($_SERVER['HTTP_REFERER'])) { return TRUE; } $url = $_SERVER['HTTP_REFERER']; // Validate URI (Ignore own) $parse_url = parse_url($url); if ($parse_url === FALSE || !isset($parse_url['host']) || $parse_url['host'] == $_SERVER['HTTP_HOST']) { return TRUE; } // Blocking SPAM if ($use_spam_check['referer'] && SpamCheck($parse_url['host'])) { return TRUE; } if (!is_dir(REFERER_DIR)) { die('No such directory: REFERER_DIR'); } if (!is_writable(REFERER_DIR)) { die('Permission denied to write: REFERER_DIR'); } // Update referer data if (ereg("[,\"\n\r]", $url)) { $url = '"' . str_replace('"', '""', $url) . '"'; } $data = ref_get_data($page, 3); $d_url = rawurldecode($url); if (!isset($data[$d_url])) { $data[$d_url] = array('', UTIME, 0, $url, 1); } $data[$d_url][0] = UTIME; $data[$d_url][2]++; $filename = ref_get_filename($page); $fp = fopen($filename, 'w'); if ($fp === FALSE) { return FALSE; } set_file_buffer($fp, 0); @flock($fp, LOCK_EX); rewind($fp); foreach ($data as $line) { $str = trim(join(',', $line)); if ($str != '') { fwrite($fp, $str . "\n"); } } @flock($fp, LOCK_UN); fclose($fp); return TRUE; }
function nel_write_file($filename, $output, $chmod) { $fp = fopen($filename, "w"); if (!$fp) { echo 'Failed to open file for writing. Check permissions.'; return FALSE; } set_file_buffer($fp, 0); rewind($fp); fputs($fp, $output); fclose($fp); chmod($filename, $chmod); return TRUE; }
function get_ticket($newticket = FALSE) { $file = CACHE_DIR . 'ticket.dat'; if (file_exists($file) && $newticket !== TRUE) { $fp = fopen($file, 'r') or die_message('Cannot open ' . 'CACHE_DIR/' . 'ticket.dat'); $ticket = trim(fread($fp, filesize($file))); fclose($fp); } else { $ticket = md5(mt_rand()); pkwk_touch_file($file); $fp = fopen($file, 'r+') or die_message('Cannot open ' . 'CACHE_DIR/' . 'ticket.dat'); set_file_buffer($fp, 0); @flock($fp, LOCK_EX); $last = ignore_user_abort(1); ftruncate($fp, 0); rewind($fp); fputs($fp, $ticket . "\n"); ignore_user_abort($last); @flock($fp, LOCK_UN); fclose($fp); } return $ticket; }
function plugin_tb_save($url, $tb_id) { global $vars, $trackback, $use_spam_check; static $fields = array('url', 'title', 'excerpt', 'blog_name'); $die = ''; if (!$trackback) { $die .= 'TrackBack feature disabled. '; } if ($url == '') { $die .= 'URL parameter is not set. '; } if ($tb_id == '') { $die .= 'TrackBack Ping ID is not set. '; } if ($die != '') { plugin_tb_return(PLUGIN_TB_ERROR, $die); } if (!file_exists(TRACKBACK_DIR)) { plugin_tb_return(PLUGIN_TB_ERROR, 'No such directory: TRACKBACK_DIR'); } if (!is_writable(TRACKBACK_DIR)) { plugin_tb_return(PLUGIN_TB_ERROR, 'Permission denied: TRACKBACK_DIR'); } $page = tb_id2page($tb_id); if ($page === FALSE) { plugin_tb_return(PLUGIN_TB_ERROR, 'TrackBack ID is invalid.'); } // URL validation (maybe worse of processing time limit) if (!is_url($url)) { plugin_tb_return(PLUGIN_TB_ERROR, 'URL is fictitious.'); } if (PLUGIN_TB_SITE_CHECK === TRUE) { $result = http_request($url); if ($result['rc'] !== 200) { plugin_tb_return(PLUGIN_TB_ERROR, 'URL is fictitious.'); } $urlbase = get_script_absuri(); $matches = array(); if (preg_match_all('#' . preg_quote($urlbase, '#') . '#i', $result['data'], $matches) == 0) { honeypot_write(); if (PLUGIN_TB_HTTP_ERROR === TRUE && is_sapi_clicgi() === FALSE) { header('HTTP/1.0 403 Forbidden'); exit; } plugin_tb_return(PLUGIN_TB_ERROR, 'Writing is prohibited.'); } } else { $result = http_request($url, 'HEAD'); if ($result['rc'] !== 200) { plugin_tb_return(PLUGIN_TB_ERROR, 'URL is fictitious.'); } } // Update TrackBack Ping data $filename = tb_get_filename($page); $data = tb_get($filename); $matches = array(); $items = array(UTIME); foreach ($fields as $key) { $value = isset($vars[$key]) ? $vars[$key] : ''; if (preg_match('/[,"' . "\n\r" . ']/', $value)) { $value = '"' . str_replace('"', '""', $value) . '"'; } $items[$key] = $value; // minimum checking from SPAM if (preg_match_all('/a\\s+href=/i', $items[$key], $matches) >= 1) { honeypot_write(); if (PLUGIN_TB_HTTP_ERROR === TRUE && is_sapi_clicgi() === FALSE) { header('HTTP/1.0 400 Bad Request'); exit; } plugin_tb_return(PLUGIN_TB_ERROR, 'Writing is prohibited.'); } } // minimum checking from SPAM #2 foreach (array('title', 'excerpt', 'blog_name') as $key) { if (preg_match_all('#http\\://#i', $items[$key], $matches) >= 1) { honeypot_write(); if (PLUGIN_TB_HTTP_ERROR === TRUE && is_sapi_clicgi() === FALSE) { header('HTTP/1.0 400 Bad Request'); exit; } plugin_tb_return(PLUGIN_TB_ERROR, 'Writing is prohibited.'); } } // Blocking SPAM if ($use_spam_check['trackback'] && SpamCheck($items['url'])) { plugin_tb_return(1, 'Writing is prohibited.'); } $data[rawurldecode($items['url'])] = $items; $fp = fopen($filename, 'w'); set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); foreach ($data as $line) { $line = preg_replace('/[\\r\\n]/s', '', $line); // One line, one ping fwrite($fp, join(',', $line) . "\n"); } flock($fp, LOCK_UN); fclose($fp); plugin_tb_return(PLUGIN_TB_OK); // Return OK }
/** * Reads heads of file into an array * * PHP API Extension * * @access public * @static * @param string $file filename * @param int $count number of executed fgets, usually equivalent to number of lines * @param boolean $lock use lock or not * @param int $buffer number of bytes to be read in one fgets * @return array * @version $Id: v 1.0 2008-06-05 11:14:46 sonots $ */ function file_head($file, $count = 1, $lock = true, $buffer = 8192) { $array = array(); $fp = @fopen($file, 'r'); if ($fp === false) { return false; } set_file_buffer($fp, 0); if ($lock) { @flock($fp, LOCK_SH); } rewind($fp); $index = 0; while (!feof($fp)) { $line = fgets($fp, $buffer); if ($line != false) { $array[] = $line; } if (++$index >= $count) { break; } } if ($lock) { @flock($fp, LOCK_UN); } if (!fclose($fp)) { return false; } return $array; }
$domains[] = $parts[$i]; } } } // Load previous results $fp = fopen('testsuite.txt', 'rt'); if (!$fp) { $results = array(); } else { $results = unserialize(fgets($fp)); fclose($fp); } // Test domains include 'whois.main.php'; $whois = new Whois(); set_file_buffer(STDIN, 0); foreach ($domains as $key => $domain) { echo "\nTesting {$domain} ---------------------------------\n"; $result = $whois->Lookup($domain); unset($result['rawdata']); if (!isset($results[$domain])) { print_r($result); $res = get_answer("Add result for {$domain}"); if ($res) { // Add as it is unset($result['regrinfo']['disclaimer']); $results[$domain] = $result; } } else { // Compare with previous result unset($result['regrinfo']['disclaimer']);
function tb_get($file, $key = 1) { if (!file_exists($file)) { return array(); } $result = array(); $fp = @fopen($file, 'r'); set_file_buffer($fp, 0); @flock($fp, LOCK_EX); rewind($fp); while ($data = @fgets($fp, 8192)) { // $data[$key] = URL $data = csv_explode(',', $data); $result[rawurldecode($data[$key])] = $data; } @flock($fp, LOCK_UN); fclose($fp); return $result; }
/** * キャッシュに書き込む * 引数は添付ファイル名, HTML変換後のファイル */ function _plugin_code_write_cache($fname, $html) { global $vars; // 添付ファイルのあるページ: defaultは現在のページ名 $page = isset($vars['page']) ? $vars['page'] : ''; // ファイル名にページ名(ページ参照パス)が合成されているか // (Page_name/maybe-separated-with/slashes/ATTACHED_FILENAME) if (preg_match('#^(.+)/([^/]+)$#', $fname, $matches)) { if ($matches[1] == '.' || $matches[1] == '..') { $matches[1] .= '/'; } // Restore relative paths $fname = $matches[2]; $page = get_fullname(strip_bracket($matches[1]), $page); // strip is a compat $file = encode($page) . '_' . encode($fname); } else { // Simple single argument $file = encode($page) . '_' . encode($fname); } $fp = fopen(CACHE_DIR . 'code/' . $file . '.html', 'w') or die_message('Cannot write cache file ' . CACHE_DIR . 'code/' . $file . '.html' . '<br />Maybe permission is not writable or filename is too long'); set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); fputs($fp, $html); flock($fp, LOCK_UN); fclose($fp); }
function updateLastDatabaseError() { global $boarddir; // Find out this way if we can even write things on this filesystem. // In addition, store things first in the backup file $last_settings_change = @filemtime($boarddir . '/Settings.php'); // Make sure the backup file is there... $file = $boarddir . '/Settings_bak.php'; if ((!file_exists($file) || filesize($file) == 0) && !copy($boarddir . '/Settings.php', $file)) { return false; } // ...and writable! if (!is_writable($file)) { chmod($file, 0755); if (!is_writable($file)) { chmod($file, 0775); if (!is_writable($file)) { chmod($file, 0777); if (!is_writable($file)) { return false; } } } } // Put the new timestamp. $data = file_get_contents($file); $data = preg_replace('~\\$db_last_error = \\d+;~', '$db_last_error = ' . time() . ';', $data); // Open the backup file for writing if ($fp = @fopen($file, 'w')) { // Reset the file buffer. set_file_buffer($fp, 0); // Update the file. $t = flock($fp, LOCK_EX); $bytes = fwrite($fp, $data); flock($fp, LOCK_UN); fclose($fp); // Was it a success? // ...only relevant if we're still dealing with the same good ole' settings file. clearstatcache(); if ($bytes == strlen($data) && filemtime($boarddir . '/Settings.php') === $last_settings_change) { // This is our new Settings file... // At least this one is an atomic operation @copy($file, $boarddir . '/Settings.php'); return true; } else { // Oops. Someone might have been faster // or we have no more disk space left, troubles, troubles... // Copy the file back and run for your life! @copy($boarddir . '/Settings.php', $file); } } return false; }
static function lockr($fp) { set_file_buffer($fp, 0); if (!flock($fp, LOCK_SH)) { HakoError::lockFail(); } rewind($fp); }
function putstatus() { $this->status['count'] = join(',', $this->status['count']); $fp = fopen($this->logname, 'wb') or die_message('cannot write ' . $this->logname); set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); foreach ($this->status as $key => $value) { fwrite($fp, $value . "\n"); } flock($fp, LOCK_UN); fclose($fp); }
function init() { $err = ""; $chkfile = array(LOGFILE, TREEFILE); if (!is_writable(realpath("./"))) { error("カレントディレクトリに書けません<br>"); } foreach ($chkfile as $value) { if (!file_exists(realpath($value))) { $fp = fopen($value, "w"); set_file_buffer($fp, 0); if ($value == LOGFILE) { fputs($fp, "1,2002/01/01(月) 00:00,名無し,,無題,本文なし,,,,,,,,\n"); } if ($value == TREEFILE) { fputs($fp, "1\n"); } fclose($fp); if (file_exists(realpath($value))) { @chmod($value, 0666); } } if (!is_writable(realpath($value))) { $err .= $value . "を書けません<br>"; } if (!is_readable(realpath($value))) { $err .= $value . "を読めません<br>"; } } @mkdir(IMG_DIR, 0777); @chmod(IMG_DIR, 0777); if (!is_dir(realpath(IMG_DIR))) { $err .= IMG_DIR . "がありません<br>"; } if (!is_writable(realpath(IMG_DIR))) { $err .= IMG_DIR . "を書けません<br>"; } if (!is_readable(realpath(IMG_DIR))) { $err .= IMG_DIR . "を読めません<br>"; } if (USE_THUMB) { @mkdir(THUMB_DIR, 0777); @chmod(THUMB_DIR, 0777); if (!is_dir(realpath(IMG_DIR))) { $err .= THUMB_DIR . "がありません<br>"; } if (!is_writable(realpath(THUMB_DIR))) { $err .= THUMB_DIR . "を書けません<br>"; } if (!is_readable(realpath(THUMB_DIR))) { $err .= THUMB_DIR . "を読めません<br>"; } } if ($err) { error($err); } }
function ref_save($page) { global $referer; if (PKWK_READONLY || !$referer || empty($_SERVER['HTTP_REFERER'])) { return true; } $url = $_SERVER['HTTP_REFERER']; // Validate URI (Ignore own) $parse_url = parse_url($url); if (empty($parse_url['host']) || $parse_url['host'] == $_SERVER['HTTP_HOST']) { return true; } if (!is_dir(TRACKBACK_DIR)) { die('No such directory: TRACKBACK_DIR'); } if (!is_writable(TRACKBACK_DIR)) { die('Permission denied to write: TRACKBACK_DIR'); } // Update referer data if (ereg("[,\"\n\r]", $url)) { $url = '"' . str_replace('"', '""', $url) . '"'; } $filename = tb_get_filename($page, '.ref'); $data = tb_get($filename, 3); $d_url = rawurldecode($url); if (!isset($data[$d_url])) { $data[$d_url] = array('', UTIME, 0, $url, 1); } $data[$d_url][0] = UTIME; $data[$d_url][2]++; $fp = fopen($filename, 'w'); if ($fp === false) { return false; } set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); foreach ($data as $line) { fwrite($fp, join(',', $line) . "\n"); } flock($fp, LOCK_UN); fclose($fp); return true; }
/** * キャッシュに書き込む * 引数は添付ファイル名, HTML変換後のファイル */ function _plugin_code_write_cache($fname, $html, $option) { // 添付ファイルのあるページ: defaultは現在のページ名 $page = isset($this->root->vars['page']) ? $this->root->vars['page'] : ''; // ファイル名にページ名(ページ参照パス)が合成されているか // (Page_name/maybe-separated-with/slashes/ATTACHED_FILENAME) if (preg_match('#^(.+)/([^/]+)$#', $fname, $matches)) { if ($matches[1] == '.' || $matches[1] == '..') { $matches[1] .= '/'; } // Restore relative paths $fname = $matches[2]; $page = $this->func->get_fullname($this->func->strip_bracket($matches[1]), $page); // strip is a compat // $file = $this->func->encode($page) . '_' . $this->func->encode($fname); //} else { // // Simple single argument // $file = $this->func->encode($page) . '_' . $this->func->encode($fname); } $file = $this->func->encode($page) . '_' . $this->func->encode($fname); // md5ハッシュ取得 list(, , , , , , , , $md5) = array_pad(@file($this->cont['UPLOAD_DIR'] . $file . ".log"), 9, ""); $md5 = trim($md5); $html = $this->func->strip_MyHostUrl($html); $data = serialize(array($html, $option, $md5)); $fp = fopen($this->cont['CACHE_DIR'] . 'plugin/' . $file . ($this->cont['UA_PROFILE'] === 'keitai' ? '.k' : '') . '.code', 'wb') or $this->func->die_message('Cannot write cache file ' . $this->cont['CACHE_DIR'] . 'plugin/' . $file . '.code' . '<br />Maybe permission is not writable or filename is too long'); set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); fputs($fp, $data); flock($fp, LOCK_UN); fclose($fp); }
function tb_get($file, $key = 1) { if (!is_file($file)) { return array(); } $result = array(); $fp = @fopen($file, 'r'); set_file_buffer($fp, 0); flock($fp, LOCK_SH); rewind($fp); while ($data = @fgetcsv($fp, 8192, ',')) { // $data[$key] = URL $result[rawurldecode($data[$key])] = $data; } flock($fp, LOCK_UN); fclose($fp); return $result; }
function put_lastmodified() { global $maxshow, $whatsnew, $autolink; if (PKWK_READONLY) { return; } // Do nothing // Get WHOLE page list $pages = get_existpages(); // Check ALL filetime $recent_pages = array(); foreach ($pages as $page) { if ($page != $whatsnew && !check_non_list($page)) { $recent_pages[$page] = get_filetime($page); } } // Sort decending order of last-modification date arsort($recent_pages, SORT_NUMERIC); // Cut unused lines // BugTrack2/179: array_splice() will break integer keys in hashtable $count = $maxshow + PKWK_MAXSHOW_ALLOWANCE; $_recent = array(); foreach ($recent_pages as $key => $value) { unset($recent_pages[$key]); $_recent[$key] = $value; if (--$count < 1) { break; } } $recent_pages =& $_recent; // Re-create PKWK_MAXSHOW_CACHE $file = CACHE_DIR . PKWK_MAXSHOW_CACHE; pkwk_touch_file($file); $fp = fopen($file, 'r+') or die_message('Cannot open' . 'CACHE_DIR/' . PKWK_MAXSHOW_CACHE); set_file_buffer($fp, 0); flock($fp, LOCK_EX); ftruncate($fp, 0); rewind($fp); foreach ($recent_pages as $page => $time) { fputs($fp, $time . "\t" . $page . "\n"); } flock($fp, LOCK_UN); fclose($fp); // Create RecentChanges $file = get_filename($whatsnew); pkwk_touch_file($file); $fp = fopen($file, 'r+') or die_message('Cannot open ' . htmlspecialchars($whatsnew)); set_file_buffer($fp, 0); flock($fp, LOCK_EX); ftruncate($fp, 0); rewind($fp); foreach (array_keys($recent_pages) as $page) { $time = $recent_pages[$page]; $s_lastmod = htmlspecialchars(format_date($time)); $s_page = htmlspecialchars($page); fputs($fp, '-' . $s_lastmod . ' - [[' . $s_page . ']]' . "\n"); } fputs($fp, '#norelated' . "\n"); // :) flock($fp, LOCK_UN); fclose($fp); // For AutoLink if ($autolink) { list($pattern, $pattern_a, $forceignorelist) = get_autolink_pattern($pages); $file = CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE; pkwk_touch_file($file); $fp = fopen($file, 'r+') or die_message('Cannot open ' . 'CACHE_DIR/' . PKWK_AUTOLINK_REGEX_CACHE); set_file_buffer($fp, 0); flock($fp, LOCK_EX); ftruncate($fp, 0); rewind($fp); fputs($fp, $pattern . "\n"); fputs($fp, $pattern_a . "\n"); fputs($fp, join("\t", $forceignorelist) . "\n"); flock($fp, LOCK_UN); fclose($fp); } }
function write_eeprom_cfg_file() { global $sernos, $nsernos, $bddb_cfgdir, $numerrs, $cfgerrs; global $date, $batch, $type_vals, $rev; global $sdram_vals, $sdram_nbits; global $flash_vals, $flash_nbits; global $zbt_vals, $zbt_nbits; global $xlxtyp_vals, $xlxspd_vals, $xlxtmp_vals, $xlxgrd_vals; global $cputyp, $cputyp_vals, $clk_vals; global $hstype, $hstype_vals, $hschin, $hschout; $numerrs = 0; $cfgerrs = array(); for ($i = 0; $i < $nsernos; $i++) { $serno = sprintf("%010d", $sernos[$i]); $wfp = @fopen($bddb_cfgdir . "/{$serno}.cfg", "w"); if (!$wfp) { $cfgerrs[$i] = 'file create fail'; $numerrs++; continue; } set_file_buffer($wfp, 0); if (!fprintf($wfp, "serno=%d\n", $sernos[$i])) { $cfgerrs[$i] = 'cfg wr fail (serno)'; fclose($wfp); $numerrs++; continue; } if (!fprintf($wfp, "date=%s\n", $date)) { $cfgerrs[$i] = 'cfg wr fail (date)'; fclose($wfp); $numerrs++; continue; } if ($batch != '') { if (!fprintf($wfp, "batch=%s\n", $batch)) { $cfgerrs[$i] = 'cfg wr fail (batch)'; fclose($wfp); $numerrs++; continue; } } $typei = enum_to_index("type", $type_vals); if (!fprintf($wfp, "type=%d\n", $typei)) { $cfgerrs[$i] = 'cfg wr fail (type)'; fclose($wfp); $numerrs++; continue; } if (!fprintf($wfp, "rev=%d\n", $rev)) { $cfgerrs[$i] = 'cfg wr fail (rev)'; fclose($wfp); $numerrs++; continue; } $s = gather_enum_multi_write("sdram", 4, $sdram_vals, $sdram_nbits); if ($s != '') { $b = fprintf($wfp, "sdram=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (sdram)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("flash", 4, $flash_vals, $flash_nbits); if ($s != '') { $b = fprintf($wfp, "flash=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (flash)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("zbt", 16, $zbt_vals, $zbt_nbits); if ($s != '') { $b = fprintf($wfp, "zbt=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (zbt)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("xlxtyp", 4, $xlxtyp_vals); if ($s != '') { $b = fprintf($wfp, "xlxtyp=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (xlxtyp)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("xlxspd", 4, $xlxspd_vals); if ($s != '') { $b = fprintf($wfp, "xlxspd=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (xlxspd)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("xlxtmp", 4, $xlxtmp_vals); if ($s != '') { $b = fprintf($wfp, "xlxtmp=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (xlxtmp)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("xlxgrd", 4, $xlxgrd_vals); if ($s != '') { $b = fprintf($wfp, "xlxgrd=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (xlxgrd)'; fclose($wfp); $numerrs++; continue; } } if ($cputyp != '') { $cputypi = enum_to_index("cputyp", $cputyp_vals); $cpuspdi = enum_to_index("cpuspd", $clk_vals); $busspdi = enum_to_index("busspd", $clk_vals); $cpmspdi = enum_to_index("cpmspd", $clk_vals); $b = fprintf($wfp, "cputyp=%d\ncpuspd=%d\n" . "busspd=%d\ncpmspd=%d\n", $cputypi, $cpuspdi, $busspdi, $cpmspdi); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (cputyp)'; fclose($wfp); $numerrs++; continue; } } if ($hstype != '') { $hstypei = enum_to_index("hstype", $hstype_vals); $b = fprintf($wfp, "hstype=%d\n" . "hschin=%s\nhschout=%s\n", $hstypei, $hschin, $hschout); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (hstype)'; fclose($wfp); $numerrs++; continue; } } if (!fclose($wfp)) { $cfgerrs[$i] = 'file cls fail'; $numerrs++; } } return $numerrs; }
function plugin_tb_save($url, $tb_id) { // global $vars, $trackback; // static $fields = array( /* UTIME, */ 'url', 'title', 'excerpt', 'blog_name'); static $fields = array(); if (!isset($fields[$this->xpwiki->pid])) { $fields[$this->xpwiki->pid] = array('url', 'title', 'excerpt', 'blog_name'); } $die = ''; if (!$this->root->trackback) { $die .= 'TrackBack feature disabled. '; } if ($url == '') { $die .= 'URL parameter is not set. '; } if ($tb_id == '') { $die .= 'TrackBack Ping ID is not set. '; } if ($die != '') { return array($this->cont['PLUGIN_TB_ERROR'], $die); } if (!file_exists($this->cont['TRACKBACK_DIR'])) { return array($this->cont['PLUGIN_TB_ERROR'], 'No such directory: TRACKBACK_DIR'); } if (!is_writable($this->cont['TRACKBACK_DIR'])) { return array($this->cont['PLUGIN_TB_ERROR'], 'Permission denied: TRACKBACK_DIR'); } $page = $this->func->tb_id2page($tb_id); if ($page === FALSE) { return array($this->cont['PLUGIN_TB_ERROR'], 'TrackBack ID is invalid.'); } // URL validation (maybe worse of processing time limit) $result = $this->func->http_request($url, 'HEAD'); if ($result['rc'] !== 200) { return array($this->cont['PLUGIN_TB_ERROR'], 'URL is fictitious.'); } // Update TrackBack Ping data $filename = $this->func->tb_get_filename($page); $data = $this->func->tb_get($filename); $items = array($this->cont['UTIME']); foreach ($fields[$this->xpwiki->pid] as $key) { $value = isset($this->root->vars[$key]) ? $this->root->vars[$key] : ''; if (preg_match('/[,"' . "\n\r" . ']/', $value)) { $value = '"' . str_replace('"', '""', $value) . '"'; } $items[$key] = $value; } $data[rawurldecode($items['url'])] = $items; $fp = fopen($filename, 'w'); set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); foreach ($data as $line) { $line = preg_replace('/[\\r\\n]/s', '', $line); // One line, one ping fwrite($fp, join(',', $line) . "\n"); } flock($fp, LOCK_UN); fclose($fp); return array($this->cont['PLUGIN_TB_NOERROR'], ''); }
/** * Store a value in cache. * * @param string $key * @param mixed $value * @param int $ttl = 120 */ public static function putCache($key, $value, $ttl = 120) { if (-1 == self::$API) { return; } self::$cache_count++; if (self::$want_debug) { self::$cache_hits[self::$cache_count] = array('k' => $key, 'd' => 'put', 's' => $value === null ? 0 : strlen(serialize($value))); $st = microtime(); } $key = self::$basekey . strtr($key, ':', '-'); $value = $value === null ? null : serialize($value); switch (self::$API) { case 5: $key = str_replace(' ', '_', $key); $instance = self::getMemcachedServer(); $instance->set($key, $value, $ttl); break; case 4: if (empty(self::$memcached)) { self::getMemcacheServer(); } if (!self::$memcached) { return; } memcache_set(self::$memcached, $key, $value, 0, $ttl); break; case 1: // An extended key is needed to counteract a bug in APC. if ($value === null) { apc_delete($key . 'smf'); } else { apc_store($key . 'smf', $value, $ttl); } break; case 3: output_cache_put($key, $value); break; case 2: if ($value === null) { xcache_unset($key); } else { xcache_set($key, $value, $ttl); } break; case 0: if ($value === null) { @unlink(self::$cachedir . '/data_' . $key . '.php'); } else { $cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>'; $fh = @fopen(self::$cachedir . '/data_' . $key . '.php', 'w'); if ($fh) { // Write the file. set_file_buffer($fh, 0); flock($fh, LOCK_EX); $cache_bytes = fwrite($fh, $cache_data); flock($fh, LOCK_UN); fclose($fh); // Check that the cache write was successful; all the data should be written // If it fails due to low diskspace, remove the cache file if ($cache_bytes != strlen($cache_data)) { @unlink(self::$cachedir . '/data_' . $key . '.php'); } } } break; } if (isset($db_show_debug) && $db_show_debug === true) { self::$cache_hits[self::$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); } }
function _nglog_process($ip) { global $BANPATTERN; if (!$this->nglogdays) { return 0; } $log_modified = 0; $nglogip = array(); $nglog = array(); $fp = @fopen($this->nglogfile, 'r+b') or fopen($this->nglogfile, 'a+b'); set_file_buffer($fp, 0); flock($fp, 2); $fsize = filesize($this->nglogfile); $buf = $fsize ? fread($fp, $fsize) : ''; $line = explode("\n", $buf); foreach ($line as $l) { $val = explode("\t", $l); if (isset($val[1])) { if ($val[1] + 86400 * $this->nglogdays > time()) { $nglog[] = $l; if ($val[2] != 'badip' && $val[2] != 'ckban' && $val[2] != 'lgban' && $val[2] != 'cokie') { $nglogip[$val[0]] = isset($nglogip[$val[0]]) ? $nglogip[$val[0]] + 1 : 1; } } else { $this->_nglog_append($val[0], $val[2], $val[3], $val[4], $val[1]); $log_modified = 1; } } } if ($log_modified) { ftruncate($fp, 0); set_file_buffer($fp, 0); rewind($fp); fputs($fp, implode("\n", $nglog) . "\n"); } fclose($fp); if (!in_array($ip, $BANPATTERN) && isset($nglogip[$ip]) && $nglogip[$ip] > 5) { return 1; } else { return 0; } }
/** * 短縮URLテーブルを再構築する。 * すべての短縮URLを作り直す */ function plugin_update_tinycode_reset() { global $defaultpage; $qm = get_qm(); //まずファイルサイズを0にする $file = CACHE_DIR . QHM_TINYURL_TABLE; $fp = fopen($file, 'w') or die_message($qm->replace('file.err_cannot_open', h($file))); set_file_buffer($fp, 0); flock($fp, LOCK_EX); fputs($fp, ''); flock($fp, LOCK_UN); fclose($fp); //再構築 $exists = get_existpages(); foreach ($exists as $v) { add_tinycode($v); } return true; }
function updateCourses() { // compare today's date to date courses were last modified // demo values of now // fall quarter // $now = new DateTime("2015-05-23"); // winter quarter // $now = new DateTime("2016-11-09"); // spring quarter // $now = new DateTime("2015-02-15"); $file_path = dirname(__FILE__) . "/../storage/courses/engr.ser"; $log_file = dirname(__FILE__) . "/../storage/logs/updates.txt"; $fp = fopen($file_path, "r"); $lf = fopen($log_file, "a"); $now = new DateTime(); $modified = new DateTime("@" . filemtime($file_path)); $created = new DateTime("@" . filectime($file_path)); $diff = $now->diff($modified); $curr_year = intval($now->format("y")); $curr_month = intval($now->format('m')); // month that quarter's classes should appear $winter_start = 11; $spring_start = 2; $fall_start = 5; // value added to reach year for term value in query $offset = 21; // Checking quarter, deleting waitlists, and updating course file all atomic if (flock($fp, LOCK_EX)) { $courses = unserialize(fread($fp, filesize($file_path))); $current_quarter = $courses['quarter']; // winter term range. 11, 12, 1 if ($curr_month >= $winter_start || $curr_month < $spring_start) { $quarter = "20"; if ($curr_month == 11 || $curr_month == 12) { $curr_year += 1; } } else { if ($curr_month >= $spring_start && $curr_month < $fall_start) { $quarter = "40"; } else { $quarter = "00"; $curr_year += 1; } } $year = $curr_year + $offset; if ($current_quarter != $year . $quarter) { // clean waitlists // echo"cleaning waitlists <br/>"; $update_lock = fopen(dirname(__FILE__) . "/../storage/waitlists/update.lock", "r"); if (flock($update_lock, LOCK_EX)) { foreach ($courses as $department => $val) { if ($department == "quarter") { continue; } $path = dirname(__FILE__) . "/../storage/waitlists/" . $department . ".csv"; // echo$path . "<br/>"; if (file_exists($path)) { unlink($path); } } if (flock($lf, LOCK_EX)) { $entry = "Waitlists for quarter " . $current_quarter . " deleted on " . $now->format("m/d/y") . " at " . $now->format("H:i:s") . "\n"; fwrite($lf, $entry); flock($lf, LOCK_UN); } } else { error_log("Couldn't delete waitlists"); } flock($update_lock, LOCK_UN); fclose($update_lock); } // If it has been over an hour since the course list was last updated, // update the course list if ($now->diff($modified)->h < 2 && $current_quarter == $year . $quarter) { // echo"Not running query"; flock($fp, LOCK_UN); fclose($fp); return; } fclose($fp); // tests // echo"now: " . $now->format("m/d/y, H:i:s") . "<br/>"; // echo"modified: " . $modified->format("m/d/y, H:i:s") . "<br/>"; // echo'"created": ' . $created->format("m/d/y, H:i:s") . "<br/>"; // echo$diff->h . ":" . $diff->i . ":" . $diff->s . "<br/>"; // echo$year.$quarter . "<br/>"; // echo$current_quarter; $term = $year . $quarter; $courseArray = array(); $wsdl = 'http://cms01.scu.edu/docs/ws/catalog/project.cfc?wsdl'; $client = new SoapClient($wsdl); $args = array(); $results = $client->__soapCall('qSchools', $args); $schools = $results->data; $schoolid = "EGR"; //// echo"$schoolid\n"; $args = array('schoolid' => $schoolid); // get all subjects (AMTH, COEN, MECH, etc.) associated with a school (Engineering, Business, etc.) $results = $client->__soapCall('qSubjects', $args); $subjects = $results->data; foreach ($subjects as $subject) { $subjectid = $subject[0]; $args = array('subjectid' => $subjectid, 'term' => $term); // get all courses associate with a subject $results = $client->__soapCall('qCourses', $args); $courses = $results->data; //print_r($results->columnList); foreach ($courses as $course) { // only return undergradute courses // is there a query associated with this field? if ($course[0] != "UGRD") { continue; } $courseid = $course[5]; $args = array('courseid' => $courseid, 'term' => $term); // get all classes associated with a course for that term $results = $client->__soapCall('qCourse', $args); $classes = $results->data; foreach ($classes as $class) { $courseArray[$subjectid][$course[3]][] = $class[0]; } } $courseArray["quarter"] = $term; } //print_r($courseArray); // serialize array and write to file $fp = fopen($file_path, "w"); set_file_buffer($fp, 0); fwrite($fp, serialize($courseArray)); if (flock($lf, LOCK_EX)) { $entry = "Waitlists for quarter " . $year . $quarter . " updated on " . $now->format("m/d/y") . " at " . $now->format("H:i:s") . "\n"; fwrite($lf, $entry); } flock($lf, LOCK_UN); fclose($lf); flock($fp, LOCK_UN); fclose($fp); } else { error_log("Could not update waitlist at this time. Please try again."); } }
function XMLParseFile(&$parser, $file, $store_positions, $cache = "", $case_folding = 0, $target_encoding = "ISO-8859-1", $simplified_xml = 0, $fail_on_non_simplified_xml = 0) { if (!file_exists($file)) { return "the XML file to parse ({$file}) does not exist"; } if (strcmp($cache, "")) { if (file_exists($cache) && filectime($file) <= filectime($cache)) { if ($cache_file = fopen($cache, "r")) { if (function_exists("set_file_buffer")) { set_file_buffer($cache_file, 0); } if (!($cache_contents = fread($cache_file, filesize($cache)))) { $error = "could not read from the XML cache file {$cache}"; } else { $error = ""; } fclose($cache_file); if (!strcmp($error, "")) { if (GetType($parser = unserialize($cache_contents)) == "object" && isset($parser->structure)) { if (!isset($parser->simplified_xml)) { $parser->simplified_xml = 0; } if (($simplified_xml || !$parser->simplified_xml) && (!$store_positions || $parser->store_positions)) { return ""; } } else { $error = "it was not specified a valid cache object in XML file ({$cache})"; } } } else { $error = "could not open cache XML file ({$cache})"; } if (strcmp($error, "")) { return $error; } } } $parser = new xml_parser_class(); $parser->store_positions = $store_positions; $parser->case_folding = $case_folding; $parser->target_encoding = $target_encoding; $parser->simplified_xml = $simplified_xml; $parser->fail_on_non_simplified_xml = $fail_on_non_simplified_xml; if (!strcmp($error = $parser->ParseFile($file), "") && strcmp($cache, "")) { if ($cache_file = fopen($cache, "w")) { if (function_exists("set_file_buffer")) { set_file_buffer($cache_file, 0); } if (!fwrite($cache_file, serialize($parser))) { $error = "could to write to the XML cache file ({$cache})"; } fclose($cache_file); if (strcmp($error, "")) { unlink($cache); } } else { $error = "could not open for writing to the cache file ({$cache})"; } } return $error; }
function plugin_counter_get_count($page) { global $vars; static $counters = array(); static $default; static $localtime; if (!isset($localtime)) { list($zone, $zonetime) = set_timezone(DEFAULT_LANG); $localtime = UTIME + $zonetime; } if (!isset($default)) { $default = array('total' => 0, 'date' => gmdate('Y/m/d', $localtime), 'today' => 0, 'yesterday' => 0, 'ip' => ''); } if (!is_page($page)) { return $default; } if (isset($counters[$page])) { return $counters[$page]; } // Set default $counters[$page] = $default; $modify = FALSE; // Open $file = COUNTER_DIR . encode($page) . PLUGIN_COUNTER_SUFFIX; touch($file); $fp = fopen($file, 'r+') or die('counter.inc.php: Cannot open COUTER_DIR/' . basename($file)); set_file_buffer($fp, 0); @flock($fp, LOCK_EX); rewind($fp); // Read foreach ($default as $key => $val) { // Update $counters[$page][$key] = rtrim(fgets($fp, 256)); if (feof($fp)) { break; } } // Anothoer day? $remoteip = get_remoteip(); if ($counters[$page]['date'] != $default['date']) { $modify = TRUE; $yesterday = gmmktime(0, 0, 0, gmdate('m', $localtime), gmdate('d', $localtime) - 1, gmdate('Y', $localtime)); $is_yesterday = $counters[$page]['date'] == gmdate('Y/m/d', $yesterday); $counters[$page]['ip'] = $remoteip; $counters[$page]['date'] = $default['date']; $counters[$page]['yesterday'] = $is_yesterday ? $counters[$page]['today'] : 0; $counters[$page]['today'] = 1; $counters[$page]['total']++; } else { if ($counters[$page]['ip'] != $remoteip) { // Not the same host $modify = TRUE; $counters[$page]['ip'] = $remoteip; $counters[$page]['today']++; $counters[$page]['total']++; } } // Modify if ($modify && $vars['cmd'] == 'read') { rewind($fp); ftruncate($fp, 0); foreach (array_keys($default) as $key) { fputs($fp, $counters[$page][$key] . "\n"); } } // Close @flock($fp, LOCK_UN); fclose($fp); return $counters[$page]; }
/** * Put data in the cache * * Adds data to whatever cache method we're using * * @param string $key the cache data identifier * @param mixed $value the value to be stored * @param int $ttl how long are we going to cache this data (in seconds) * @return void * @since 0.1.0 */ function smfapi_cachePutData($key, $value, $ttl = 120) { global $boardurl, $sourcedir, $modSettings, $memcached; global $cache_hits, $cache_count, $db_show_debug, $cachedir; if (empty($modSettings['cache_enable']) && !empty($modSettings)) { return; } $cache_count = isset($cache_count) ? $cache_count + 1 : 1; if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count] = array('k' => $key, 'd' => 'put', 's' => $value === null ? 0 : strlen(serialize($value))); $st = microtime(); } $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . strtr($key, ':', '-'); $value = $value === null ? null : serialize($value); // eAccelerator... if (function_exists('eaccelerator_put')) { if (mt_rand(0, 10) == 1) { eaccelerator_gc(); } if ($value === null) { @eaccelerator_rm($key); } else { eaccelerator_put($key, $value, $ttl); } } elseif (function_exists('mmcache_put')) { if (mt_rand(0, 10) == 1) { mmcache_gc(); } if ($value === null) { @mmcache_rm($key); } else { mmcache_put($key, $value, $ttl); } } elseif (function_exists('apc_store')) { // An extended key is needed to counteract a bug in APC. if ($value === null) { apc_delete($key . 'smf'); } else { apc_store($key . 'smf', $value, $ttl); } } elseif (function_exists('output_cache_put')) { output_cache_put($key, $value); } elseif (function_exists('xcache_set') && ini_get('xcache.var_size') > 0) { if ($value === null) { xcache_unset($key); } else { xcache_set($key, $value, $ttl); } } else { if ($value === null) { @unlink($cachedir . '/data_' . $key . '.php'); } else { $cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>'; $fh = @fopen($cachedir . '/data_' . $key . '.php', 'w'); if ($fh) { // write the file. set_file_buffer($fh, 0); flock($fh, LOCK_EX); $cache_bytes = fwrite($fh, $cache_data); flock($fh, LOCK_UN); fclose($fh); // check that the cache write was successful; all the data should be written // if it fails due to low diskspace, remove the cache file if ($cache_bytes != strlen($cache_data)) { @unlink($cachedir . '/data_' . $key . '.php'); } } } } if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); } return; }
function autolink_pattern_write($filename, $autolink_pattern) { list($pattern, $pattern_a, $forceignorelist) = $autolink_pattern; $fp = fopen($filename, 'w') or die_message('Cannot open ' . $filename . '<br />Maybe permission is not writable'); set_file_buffer($fp, 0); @flock($fp, LOCK_EX); rewind($fp); fputs($fp, $pattern . "\n"); fputs($fp, $pattern_a . "\n"); fputs($fp, join("\t", $forceignorelist) . "\n"); @flock($fp, LOCK_UN); @fclose($fp); }
function plugin_online_sweep_records($host = '') { // Open $fp = @fopen(PLUGIN_ONLINE_USER_LIST, 'r+'); if ($fp == FALSE) { return FALSE; } set_file_buffer($fp, 0); flock($fp, LOCK_EX); // Read to check $lines = @file(PLUGIN_ONLINE_USER_LIST); if ($lines === FALSE) { $lines = array(); } // Need modify? $line_count = $count = count($lines); $matches = array(); $dirty = FALSE; for ($i = 0; $i < $line_count; $i++) { if (!preg_match(PLUGIN_ONLINE_LIST_REGEX, $lines[$i], $matches) || $matches[2] + PLUGIN_ONLINE_TIMEOUT <= UTIME || $matches[2] > UTIME || $matches[1] == $host) { unset($lines[$i]); // Invalid or outdated or invalid date --$count; $dirty = TRUE; } } if ($host != '') { // Add new, at the top of the record array_unshift($lines, strtr($host, "\n", '') . '|' . UTIME . "\n"); ++$count; $dirty = TRUE; } if ($dirty) { // Write if (!ftruncate($fp, 0)) { return FALSE; } rewind($fp); fputs($fp, join('', $lines)); } flock($fp, LOCK_UN); if (!fclose($fp)) { return FALSE; } return $count; // Number of lines == Number of users online }
function _init_PukiWiki_env() { //他のPukiWikiシステムとの連携時の初期化 Original By nao-pon // PukiWikiMod用共通リンクへの対応 // AutoLink有効時に、AutoLinkデータ読込と、AutoLinkデータ更新時のキャッシュクリア // PukiWikiMod 共通リンクディレクトリ読み込み by nao-pon $wiki_common_dirs = ""; if (defined('MOD_PUKI_WIKI_CACHE_DIR')) { if (MOD_PUKI_WIKI_VER == "1.3" && file_exists(MOD_PUKI_WIKI_CACHE_DIR . "config.php")) { include MOD_PUKI_WIKI_CACHE_DIR . "config.php"; } } // PukiWikiMod 共通リンクディレクトリ展開 $wiki_common_dirs = preg_split("/\\s+/", trim($wiki_common_dirs)); sort($wiki_common_dirs, SORT_STRING); PukiWikiConfig::setParam('wiki_common_dirs', $wiki_common_dirs); // AutoLinkデータ読み込みとチェック(AutoLink有効時のみ) $autolink_dat = array(); if (PukiWikiConfig::getParam('autolink') && defined('MOD_PUKI_WIKI_CACHE_DIR') && file_exists(MOD_PUKI_WIKI_CACHE_DIR . 'autolink.dat')) { $autolink_dat = file(MOD_PUKI_WIKI_CACHE_DIR . 'autolink.dat'); if (!file_exists(MOD_PUKI_CACHE_DIR . 'autolink.dat') || $autolink_dat != file(MOD_PUKI_CACHE_DIR . 'autolink.dat')) { // 比較用オートリンクデータを保存 @(list($pattern, $pattern_a, $forceignorelist) = $autolink_dat); if ($fp = fopen(MOD_PUKI_CACHE_DIR . 'autolink.dat', 'wb')) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); fputs($fp, trim($pattern) . "\n"); if (count($autolink_dat) == 3) { fputs($fp, trim($pattern_a) . "\n"); fputs($fp, trim($forceignorelist) . "\n"); } flock($fp, LOCK_UN); fclose($fp); } else { // die_message('Cannot write autolink file '. MOD_PUKI_CACHE_DIR . '/autolink.dat<br />Maybe permission is not writable'); } // オートリンクデータが更新されているのでキャッシュをクリア $dh = dir(MOD_PUKI_CACHE_DIR); while (($file = $dh->read()) !== FALSE) { if (substr($file, -6) != '.cache') { continue; } $file = MOD_PUKI_CACHE_DIR . $file; unlink($file); } $dh->close(); } } PukiWikiConfig::setParam('autolink_dat', $autolink_dat); // ページ名エイリアス取得 PukiWikiConfig::setParam('pagename_aliases', PukiWikiFunc::get_pagename_aliases()); }