"0", "menu"=>"", "access"=>"0", "cat"=>""); $param[menu] = set_menu(); $param[access] = access_count("data/access.txt", "data/access.loc"); switch ($mode) { default: $rss = $_GET['rss']; if ($rss == "") { $xml = "data/index.rdf"; $xsl = "rdf.xsl"; $cat = urldecode($_GET['cat']); $cat = mb_convert_encoding($cat, "utf-8", "EUC"); $param[cat] = $cat; } else { $xsl = $_GET['xsl']; $no = get_inc_no("data/inc_no.txt", "data/inc_no.loc", 10); $tmp_rss = sprintf("data/rss%02d.xml", $no); // $rss = urldecode($rss); rss_copy($rss, $tmp_rss); $xml = $tmp_rss; } $objPrc = xslt_create(); $result = xslt_process($objPrc, $xml, $xsl, NULL, $arg, $param); print $result; break; case "regist": $rss = $_POST['rss']; $rss_enc = urlencode($rss); $rss_ver = get_rss_data($rss); if ($rss_ver != "null") { $encoding = strtolower($encoding); if ($encoding != "utf-8") { $title = mb_convert_encoding($title, "utf-8", $encoding); $discription = mb_convert_encoding($discription, "utf-8", $encoding); } $cat_no = $cat_max - 1; for ($i = 0; $i < count($cat_tbl); $i++) { $p = mb_strpos($title, $cat_tbl[$i][0], 0, "utf-8"); if ($p !== FALSE) { $category = $cat_tbl[$i][1]; $cat_no = $cat_tbl[$i][2]; break; } } $rc = append_rss_data(); if ($rc == "0") { count_category_no($cat_no); $param[err] = "0"; } else { $param[err] = "2"; } } else { $param[err] = "1"; } $xml = "data/index.rdf"; $xsl = "rdf.xsl"; $objPrc = xslt_create(); $result = xslt_process($objPrc, $xml, $xsl, NULL, $arg, $param); print $result; break; } function set_menu() { global $cat_tbl, $cat_cnt, $cat_max; $a[0] = "全体"; for ($i = 0; $i < count($cat_tbl); $i++) { $a[$cat_tbl[$i][2]] = $cat_tbl[$i][1]; } $a[count($a)] = "その他"; $cat_max = count($a); $menu = ""; for ($i = 0; $i < count($a); $i++) { $enc = urlencode($a[$i]); $menu = $menu . "
  • $a[$i] ($cat_cnt[$i])
  • "; } return $menu; } function access_count($count_file, $lock_file) { $fp2 = fopen($lock_file, "w"); flock($fp2, LOCK_EX); $fp1 = fopen($count_file, "r"); if ($fp1 != false) { $buffer = fgets($fp1, 128); $tmp1 = explode(" ", $buffer); $access = $tmp1[0]; fclose($fp1); } $access++; $fp1 = fopen($count_file, "w"); fwrite($fp1, "$access "); fclose($fp1); flock($fp2, LOCK_UN); fclose($fp2); return $access; } function get_inc_no($count_file, $lock_file, $max) { $fp2 = fopen($lock_file, "w"); flock($fp2, LOCK_EX); $fp1 = fopen($count_file, "r"); if ($fp1 != false) { $buffer = fgets($fp1, 128); $tmp1 = explode(" ", $buffer); $access = $tmp1[0]; fclose($fp1); } $access = ($access + 1) % $max; $fp1 = fopen($count_file, "w"); fwrite($fp1, "$access "); fclose($fp1); flock($fp2, LOCK_UN); fclose($fp2); return $access; } function rss_copy($src, $dst) { $fp1 = fopen($src, "r"); $fp2 = fopen($dst, "w"); if (($fp1 != false) && ($fp2 != false)) { fwrite($fp2, fgets($fp1, 2048)); fwrite($fp2, fgets($fp1, 2048)); fwrite($fp2, fgets($fp1, 2048)); fwrite($fp2, fgets($fp1, 2048)); while (!feof ($fp1)) { $buf1 = fgets($fp1, 2048); $buf1 = str_replace("", " -->", $buf1); $buf1 = str_replace("", " -->", $buf1); fwrite($fp2, $buf1); } fclose($fp2); fclose($fp1); } } function get_rss_data($src) { global $encoding, $title, $link, $discription, $creator, $build_date; $rss_ver = "null"; $fp1 = fopen($src, "r"); if ($fp1 != false) { $buf1 = fgets($fp1, 2048); $encoding = get_attribute($buf1, "encoding"); for ($i = 0; $i < 4; $i++) { $buf1 = fgets($fp1, 2048); $pos = strpos($buf1, ""); if ($s === FALSE) return ""; $e = strpos($str, "<", $s+1); if ($e === FALSE) $e = strlen($str); return substr($str, $s+1, ($e-$s)-1); } function get_attribute($str, $name) { $p = strpos($str, $name); $str = substr($str, $p); $a = explode("\"", $str); return $a[1]; } function append_rss_data() { global $rss, $rss_enc, $rss_ver, $title, $link, $discription, $creator, $category, $build_date; $act_date = date("Y-m-d H:i:s+09:00"); $rss_src = "data/index.rdf"; $rss_old = "data/index.rdf.old"; $rss_tmp1 = "data/index.rdf.tmp1"; $rss_tmp2 = "data/index.rdf.tmp2"; $fp1 = fopen($rss_src, "r"); if ($fp1 != false) { while (!feof ($fp1)) { $buf1 = fgets($fp1, 2048); $p = strpos($buf1, $rss_enc); if ($p !== FALSE) return "1"; $p = strpos($buf1, ""); if ($p !== FALSE) break; } fclose($fp1); } $fp3 = fopen("data/append_rss.loc", "w"); flock($fp3, LOCK_EX); copy($rss_src, $rss_old); $fp1 = fopen($rss_src, "r"); $fp2 = fopen($rss_tmp1, "w"); if (($fp1 != false) && ($fp2 != false)) { while (!feof ($fp1)) { $buf1 = fgets($fp1, 2048); $p = strpos($buf1, ""); if ($p !== FALSE) { fwrite($fp2, "$act_date\n"); break; } else { fwrite($fp2, $buf1); } } while (!feof ($fp1)) { $buf1 = fgets($fp1, 2048); $p = strpos($buf1, ""); if ($p !== FALSE) { fwrite($fp2, $buf1); fwrite($fp2, "\n"); break; } else { fwrite($fp2, $buf1); } } while (!feof ($fp1)) { $buf1 = fgets($fp1, 2048); $p = strpos($buf1, ""); if ($p !== FALSE) { fwrite($fp2, $buf1); fwrite($fp2, "\n"); fwrite($fp2, "$title\n"); fwrite($fp2, "http://yama-tabi.net/link/antenna/index.php?rss=$rss_enc&xsl=$rss_ver\n"); fwrite($fp2, "$discription\n"); fwrite($fp2, "$category\n"); fwrite($fp2, "$creator\n"); fwrite($fp2, "$build_date\n"); fwrite($fp2, "\n"); break; } else { fwrite($fp2, $buf1); } } while (!feof ($fp1)) { fwrite($fp2, fgets($fp1, 2048)); } fclose($fp2); fclose($fp1); chmod ($rss_tmp1, 0666); rename($rss_src, $rss_tmp2); rename($rss_tmp1, $rss_src); unlink($rss_tmp2); } flock($fp3, LOCK_UN); fclose($fp3); return "0"; } function count_category_no($cat_no) { $cat_no_src = "data/category.cnt"; $cat_no_tmp1 = "data/category.cnt.tmp1"; $cat_no_tmp2 = "data/category.cnt.tmp2"; $fp3 = fopen("data/category_no.loc", "w"); flock($fp3, LOCK_EX); $fp1 = fopen($cat_no_src, "r"); $fp2 = fopen($cat_no_tmp1, "w"); if (($fp1 != false) && ($fp2 != false)) { for ($i = 0; $i < 7; $i++) { fwrite($fp2, fgets($fp1, 128)); } $buf1 = fgets($fp1, 128); $tmp1 = explode(",", $buf1); $cnt = $tmp1[0]; $cnt++; fwrite($fp2, "$cnt,\n"); for ($i = 0; $i < $cat_no - 1; $i++) { fwrite($fp2, fgets($fp1, 128)); } $buf1 = fgets($fp1, 128); $tmp1 = explode(",", $buf1); $cnt = $tmp1[0]; $cnt++; fwrite($fp2, "$cnt,\n"); while (!feof ($fp1)) { fwrite($fp2, fgets($fp1, 128)); } fclose($fp2); fclose($fp1); chmod ($cat_no_tmp1, 0666); rename($cat_no_src, $cat_no_tmp2); rename($cat_no_tmp1, $cat_no_src); unlink($cat_no_tmp2); } flock($fp3, LOCK_UN); fclose($fp3); } ?>