/**
* カレンダーを取得
*
* @param int $year 年
* @param int $month 月
* @return array
*/
function parse_show_calendar($year = 0, $month = 0)
{
if (empty($year) || empty($month)) {
$url = "show_calendar.pl";
} else {
$url = "show_calendar.pl?year=" . intval($year) . "&month=" . intval($month);
}
$content = $this->fetch($url);
$term = $this->get_cal_term("", $content);
//return $content;
$content = mb_convert_encoding($content,"UTF-8","EUC-JP");
preg_match(‘/<table width="670" border="0" cellspacing="1" cellpadding="3" class="calendarTable01">(.*?)<\/table>/s’, $content, $match);
$content = preg_replace(‘/<tr align="center" bgcolor="#fff1c4">.*?<\/tr>/is’, ”, $match[1]);
preg_match_all(‘/<td bgcolor="[^<>]+" align="left" valign="top"><font style="[^<>]+">(\S*?)<\/font>(.*?)<\/td>/is’, $content, $result, PREG_SET_ORDER);
foreach($result as $myrow) {
// $date = array("year" => $term[‘year’], "month" => $term[‘month’], "day" => intval($myrow[1]));
$date = $this->mktime(0, 0, 0, $month, $myrow[1], $year);
$schedule = explode("<br />", $myrow[2]);
foreach($schedule as $desc) {
if (preg_match(‘/<img src="(.*?)" width="16" height="16" align="middle" \/><a href=(\S*?)>(.*?)<\/a>/i’, $desc, $ret)) {
$icon = pathinfo($ret[1]);
$ret[2] = preg_replace(‘/"/i’,"",$ret[2]);
$item[] = array(‘title’ => $ret[3], ‘link’ => $this->base_url . $ret[2], ‘date’ => $date , "category" => $this->mixi_cal_icon[$icon[‘basename’]]);
} else if (preg_match(‘/<a href=".*?" onClick="MM_openBrWindow\(\'(view_schedule\.pl\?id=\d+)\’.*?\)"><img src="(\S*?)".*?>(.*?)<\/a>/i’, $desc, $ret)) {
$icon = pathinfo($ret[2]);
$item[] = array(‘title’ => $ret[3], ‘link’ => $this->base_url . $ret[1], ‘date’ => $date , "category" => $this->mixi_cal_icon[$icon[‘basename’]]);
}
}
}
return $item;
}
function &get_cal_term($act = "", &$content)
{
$result = array();
switch ($act) {
case ‘next’:
preg_match(‘/<a href="(show_calendar\.pl\?.*?)">([^<>]+?) >>/’, $content, $match);
$result = array("link" => $match[1], "title" => $match[2]);
break;
case ‘prev’:
preg_match(‘/<a href="(show_calendar\.pl\?.*?)"><< ([^<>]+)/’, $content, $match);
$result = array("link" => $match[1], "title" => $match[2]);
break;
default:
preg_match(‘/<a href="show_calendar\.pl\?year=(\d+)&month=(\d+).*?">[^&]*?<\/a>/’, $content, $match);
$result = array("year" => intval($match[1]), "month" => intval($match[2]));
//echo $content;
//var_dump($result);
}
return $result;
}