-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedium.php
More file actions
44 lines (36 loc) · 1.2 KB
/
Copy pathmedium.php
File metadata and controls
44 lines (36 loc) · 1.2 KB
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
<?php
error_reporting( 0 ); // don't let any php errors ruin the feed
$username = 'sftru';
$number_tweets = 10;
$feed = "https://medium.com/@sftru/latest?format=json";
$cache_file = dirname(__FILE__).'/cache/'.'medium-cache';
$modified = filemtime( $cache_file );
$now = time();
$interval = 800; // ten minutes
// check the cache file
if ( !$modified || ( ( $now - $modified ) > $interval ) ) {
/*
$bearer = 'AAAAAAAAAAAAAAAAAAAAALMNdwAAAAAA99FdRu5rJCjLwoqGDauThMMcP9w%3DxTYHAorjOH4vMMNte0jAAPaIbXW6dyZVhcrh8lVsgwncRizQgV';
$context = stream_context_create(array(
'http' => array(
'method'=>'GET',
'header'=>"Authorization: Bearer " . $bearer
)
));
*/
$json = file_get_contents( $feed );
$json = preg_replace("/^([^\{]+)/", "", $json);
// $json = file_get_contents( $feed, false, $context );
if ( $json ) {
$cache_static = fopen( $cache_file, 'w' );
fwrite( $cache_static, $json );
fclose( $cache_static );
}
}
header( 'Cache-Control: no-cache, must-revalidate' );
header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
header( 'Content-type: application/json' );
$json = file_get_contents( $cache_file );
// $json = preg_replace("/^([^\{]+)/", "", $json);
echo $json;
?>