This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathical.php
110 lines (97 loc) · 4.42 KB
/
ical.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
require_once("apifunc.php");//機能定義ファイル読み込み
//$ptcUrl = "http://www.pasonatech.co.jp/event/rss_event.jsp";
$ptcUrl = "http://rss.pasonatech.co.jp/rss2/465";
// ■並列通信用マルチハンドルを用意■
$mh = curl_multi_init();
//通信先ごとにCurl Handleを作り、それを $mh にaddしていく
//(PasonaTech Event RSSY)
$ch_ptcurl = curl_init($ptcUrl);
curl_setopt($ch_ptcurl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch_ptcurl, CURLOPT_TIMEOUT, 5);
curl_multi_add_handle($mh, $ch_ptcurl);
// せーので複数の通信を同時実行。whileで全て返ってくるのを待ちます
do { curl_multi_exec($mh, $running); } while ( $running );
// 個々のXMLは、それぞれのCurl Handleを指定することで取得できる
$xml_ptcurl = curl_multi_getcontent($ch_ptcurl);
// 後始末
curl_multi_remove_handle($mh, $ch_ptcurl);
curl_close($ch_ptcurl);
curl_multi_close($mh);
// ■並列通信ここまで■
// ■各社データを配列変数へ格納■
// ■PasonaTech Event RSS ■
$xml = simplexml_load_string ($xml_ptcurl);
$hits = $xml->channel->item;
foreach ($hits as $hit) {
$title[] = $hit->title;
$linkurl[] = h($hit->link);
$description[] = h($hit->description);
$pubdate[] = h($hit->pubDate);
$location[] = h($hit->category[2]);
}
//header("Content-Type: text/Calendar");
//header("Content-Disposition: inline; filename=snickerjp.ics");
require_once './iCalcreator.class.php';
$v = new vcalendar( array(
'unique_id' => 'snicker-jp.info',
));
// initiate new CALENDAR
$v->setProperty( 'calscale'
, 'GREGORIAN' );
$v->setProperty( 'method'
, 'PUBLISH' );
$v->setProperty( 'X-WR-CALNAME'
, '勝手にPTイベント(β)' ); // set some X-properties, name, content.. .
$v->setProperty( 'X-WR-TIMEZONE'
, 'Asia/Tokyo' );
$v->setProperty( 'X-WR-CALDESC'
, 'パソナテックのイベントRSSをiCal形式に変換しました!(※現在テストUP中です。)' );
foreach ($title as $key => $value) {
//$pattern = '/[0-9][0-9][0-9][0-9]\\/[0-9][0-9]\\/[0-9][0-9]\(.*\)/';
//$pattern = '/[0-9][0-9][0-9][0-9]\\/[0-9][0-9]\\/[0-9][0-9].*[0-9][0-9]:.*:[0-9][0-9]/';
$pattern = '/\d{4}\\/\d{2}\\/\d{2}.*\d{2}:.*:\d{2}/';
preg_match($pattern, $description[$key], $matches);
$split_pattern = '/[\s-\/:]+|\(.*\)[\s]+/';
$split_pattern = '/[\D]+|\(.*\)[\s]+/';
$split_matches = preg_split($split_pattern, $matches[0]);
$pattern2 = '/\\[.*\\][\s]+/';
preg_match($pattern2, $title[$key], $matches2);
$sym = array("[", "]");
$matches2 = trim(str_replace($sym, "", $matches2[0]));
$dtstart = $split_matches[0].$split_matches[1].$split_matches[2].$split_matches[3].$split_matches[4];
//$hashlocation = sha1($matches2);
$hashlocation = md5($title[$key]);
$e = & $v->newComponent( 'vevent' ); // initiate a new EVENT
$e->setProperty( 'DTSTART'
, $split_matches[0], $split_matches[1], $split_matches[2], $split_matches[3], $split_matches[4], 00, "+090000" ); // 24 dec 2007 19.30
$e->setProperty( 'DTEND'
, $split_matches[0], $split_matches[1], $split_matches[2], $split_matches[5], $split_matches[6], 00, "+090000" ); // 24 dec 2007 19.30
$e->setProperty( 'CREATED'
, $split_matches[0], $split_matches[1], $split_matches[2], $split_matches[3], $split_matches[4], 00, "+090000" );
/*
$e->setProperty( 'description'
, $description[$key] ); // describe the event
*/
$e->setProperty( 'uid'
//, $dtstart.hash($matches2).'@snicker-jp.info');
, "$dtstart-$hashlocation@snicker-jp.info");
//, $start ); // uid
$e->setProperty( 'description'
, $linkurl[$key] ); // describe the event
$e->setProperty( 'LAST-MODIFIED'
, $split_matches[0], $split_matches[1], $split_matches[2], $split_matches[3], $split_matches[4], 00, "+090000" );
$e->setProperty( 'location'
, $matches2 ); // locate the event
$e->setProperty( 'STATUS'
, 'CONFIRMED' ); //
$e->setProperty( 'SUMMARY'
, $title[$key] ); // SUMMARY
}
/* alt. production */
$v->returnCalendar(); // generate and redirect output to user browser
/* alt. dev. and test */
//echo nl2br( $v->createCalendar()) ; // generate and get output in string, for testing?
//echo "<br />\n\n";
//print_r($matches2);
?>