-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull.inc.php
109 lines (98 loc) · 3.94 KB
/
pull.inc.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
<?php
//--------------------------------------------------------------
// -------------------------------------------------------------
function pull($type, $name) {
// LEAGUE
if($type == 'league') {
$infos['url'] = 'http://www.footbo.com/Competitions/' . $name;
// check cache before do a request
if ( false === ( $html = get_transient( $type . '_' . $name ) ) ) {
$html = my_curl($infos['url']);
if(!empty($html) && $html != null && $html != false)
// set cache
set_transient($type . '_' . $name, $html, 60 * (int) get_option('footbo-field-cache'));
}
return fetch_league($html);
}
// ***************************************************************************
// FIXTURE recent
if($type == 'fixture') {
$infos['url'] = 'http://www.footbo.com/Teams/' . $name;
// check cache before do a request
if ( false === ( $html = get_transient( $type . '_' . $name ) ) ) {
$html = my_curl($infos['url']);
if(!empty($html) && $html != null && $html != false)
// set cache
set_transient($type . '_' . $name, $html, 60 * (int) get_option('footbo-field-cache'));
}
return fetch_fixture($html);
}
// ***************************************************************************
// FIXTURE all
if($type == 'fixture_all') {
$infos['url'] = 'http://www.footbo.com/Teams/' . $name . '/Fixtures';
if ( false === ( $html = get_transient( $type . '_' . $name ) ) ) {
$html = my_curl($infos['url']);
if(!empty($html) && $html != null && $html != false)
// set cache
set_transient($type . '_' . $name, $html, 60 * (int) get_option('footbo-field-cache'));
}
return fetch_fixture_all($html);
}
// ***************************************************************************
}
// -------------------------------------------------------------
// -------------------------------------------------------------
// fixture table - REGEX
function fetch_fixture($html) {
// just what we need - table with fixtures
if( preg_match_all('/<div class="FootboControl">.*?(<table.*?class="TeamGames">(.)*?<\/table>)/is', $html, $match) ) {
// strip attributes from <tr>
$raw = preg_replace("/<([a-z][a-z0-9]*)(?:[^>]*(\ssrc=['\"][^'\"]*['\"]))?[^>]*?(\/?)>/i",'<$1$2$3>', $match[1][0]);
return $raw;
}
else {
return false;
}
}
// ***************************************************************************
// all fixture - REGEX
function fetch_fixture_all($html) {
if( preg_match_all('/<h3\sclass="Header">.*?<\/h3>\s?<table\sclass="GamesView".*?>[.\s]*?<\/table>/is', $html, $match) ) {
// remove last td
// remove attributes
foreach($match[0] as $m) {
$last_td = preg_replace("/<td\s?class=\"GamesViewLeague\".*?<\/td>/is", '', $m);
$striped[] = preg_replace("/<([a-z][a-z0-9]*)(?:[^>]*(\ssrc=['\"][^'\"]*['\"]))?[^>]*?(\/?)>/i",'<$1$2$3>', $last_td);
}
return $striped;
}
else
return false;
}
// ***************************************************************************
// league table - REGEX
function fetch_league($html, $ajax = false) {
if( preg_match_all('/<td\sclass="StandingsBox">\s?(<table.*>[.\s]*?<\/table>)\s?<\/td>/is', $html, $match) ) {
$match[1][0] = preg_replace("/<([a-z][a-z0-9]*)(?:[^>]*(\ssrc=['\"][^'\"]*['\"]))?[^>]*?(\/?)>/i",'<$1$2$3>', $match[1][0]);
return $match[1][0];
}
else{
return false;
}
}
// -------------------------------------------------------------
// -------------------------------------------------------------
// curl
function my_curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
// -------------------------------------------------------------
// -------------------------------------------------------------