fix missing bold for your account item
[brisk.git] / web / brisk-fb-whois.php
1 <?php
2
3 // $a = array('name' => 'my name with & and /' );
4 // echo json_encode($a);
5 // echo "{ name: 'pippopluto' }";
6
7 // http://www.alternativeoutput.it/briskblog/doku.php?id=utenti:social&do=edit
8 // header: ^  A  ^^
9 // footer: ===== Per essere aggiunto =====
10 // |mop|[[https://www.facebook.com/bi.cci.5|bi.cci.5]]|
11
12 function retrieve_login($userid)
13 {
14     $cache_file = '/var/www/webspace/brisk-priv/brisk-fb-whois.cache';
15     // $cache_file = '/tmp/brisk-fb-whois.cache';
16     $cache_max_age = 3600;
17
18     $page_name = 'http://www.alternativeoutput.it/briskblog/doku.php?id=utenti:social&do=edit';
19     $userid_pfx = 'https://www.facebook.com/';
20
21     $curtime = time();
22     $is_cache = FALSE;
23
24     if (!file_exists($cache_file) || ($curtime - filemtime($cache_file)) > $cache_max_age) {
25         if (($content = file_get_contents($page_name)) == FALSE) {
26             echo json_encode(array('name' => 'problemi sul server', 'is_cache' => $is_cache, 'err' => 2));
27             exit;
28         }
29         file_put_contents($cache_file, $content);
30         $is_cache = FALSE;
31     }
32     else {
33         if (($content = file_get_contents($cache_file)) == FALSE) {
34             echo json_encode(array('name' => 'problemi sul server', 'is_cache' => $is_cache, 'err' => 2));
35             exit;
36         }
37         $is_cache = TRUE;
38     }
39     $content_ar = explode("\n", $content);
40     $st = 0;
41     foreach($content_ar as $key => $value) {
42         switch ($st) {
43         case 0:
44             if (substr($value, 0, 8) == '^  A  ^^') {
45                 $st = 1;
46             }
47             break;
48
49         case 1:
50             if (substr($value, 0, 31) == '===== Per essere aggiunto =====') {
51                 $st = 2;
52                 break;
53             }
54             if (strstr($value, $userid_pfx.$userid.'|')) {
55                 $ret_ar = explode('|', $value);
56                 echo json_encode(array('name' => $ret_ar[1], 'is_cache' => $is_cache, 'err' => 0));
57                 exit;
58             }
59             break;
60
61         case 2:
62             echo json_encode(array('name' => 'utente non trovato', 'is_cache' => $is_cache, 'err' => 1));
63             exit;
64             break;
65         }
66     }
67 }
68
69 retrieve_login($userid);
70
71 ?>