-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoUpdate.php
79 lines (63 loc) · 1.93 KB
/
autoUpdate.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
<?php
/**
* @author Savaş Can ALTUn <[email protected]>
* @link http://savascanaltun.com.tr
* @link http://github.com/saltun
* @since 31.08.2014
* @example example.php
* @version 1.0
*/
class autoUpdate{
public $sourceurl;
public $file;
public function getSource($url){
$user = getenv('USER_AGENT');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $user);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_REFERER, 'http://www.savascanaltun.com.tr');
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
if($data) return $data; else return false;
}
public function dateControl($myDate,$updateDate){
$ilk = strtotime($myDate);
$son = strtotime($updateDate);
$sf=$ilk-$son;
if ($sf==0) {
exit();
}
if ($ilk-$son > 0)
{ return 1; }
else
{
return 0;
}
}
protected function updateControl($source){
preg_match_all('#/* * Update :(.*?) */#si',$source,$update);
$updateDate=$update[1][0];
$updateDate=str_replace("*","",$updateDate);
return $updateDate;
}
public function control(){
$gitsource=$this->getSource($this->sourceurl);
$myfileSource=file_get_contents($this->file);
$myDate=$this->updateControl($myfileSource);
$myDate=date('Y-m-d',strtotime($myDate));
$updateDate=$this->updateControl($gitsource);
$updateDate=date('Y-m-d',strtotime($updateDate));
if (!$this->dateControl($myDate,$updateDate)) {
$dosya = fopen($this->file, 'w');
fwrite($dosya, $gitsource);
fclose($dosya);
}
}
}
?>