0) { $day_diff = floor($diff / 86400); if($day_diff == 0) { if($diff < 60) return 'just now'; if($diff < 120) return '1 minuto fa'; if($diff < 3600) return floor($diff / 60) . ' minuti fa'; if($diff < 7200) return '1 ora fa'; if($diff < 86400) return floor($diff / 3600) . ' ore fa'; } if($day_diff == 1) return 'Ieri'; if($day_diff < 7) return $day_diff . ' giorni fa'; if($day_diff < 31) return ceil($day_diff / 7) . ' settimane fa'; if($day_diff < 60) return 'ultimo mese'; return date('F Y', $ts); } else { $diff = abs($diff); $day_diff = floor($diff / 86400); if($day_diff == 0) { if($diff < 120) return 'in un minuto'; if($diff < 3600) return 'in ' . floor($diff / 60) . ' minuti'; if($diff < 7200) return 'in un\'ora'; if($diff < 86400) return 'in ' . floor($diff / 3600) . ' ore'; } if($day_diff == 1) return 'Domani'; if($day_diff < 4) return date('l', $ts); if($day_diff < 7 + (7 - date('w'))) return 'prossima settimana'; if(ceil($day_diff / 7) < 4) return 'in ' . ceil($day_diff / 7) . ' settimane'; if(date('n', $ts) == date('n') + 1) return 'prossimo mese'; return date('F Y', $ts); } } // facebook php sdk //require_once('facebook/facebook.php'); /* require_once './facebook-php-sdk/src/facebook.php'; $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true, )); */ // *********************************************** // GRAPH API // *********************************************** function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); return $data; } // 1) Access Token $app_token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&client_secret=" . $app_secret . "&grant_type=client_credentials"; $response = get_data($app_token_url); // we get a string. DOC: file_get_contents reads a file into a string (memorizza il contenuto del file in una stringa) $params = null; parse_str($response, $params); // parse access_token=... into var. DOC: parse_str function parses a query string into variables (second parameter indicates that the variables will be stored in an array) //echo "This app's access token is:
" . $params['access_token'] . "

"; $request_url = "https://graph.facebook.com/".$page_id."/feed/?access_token=".$params['access_token']; // 2) get the feed & JSON decoding // echo "Page requests:
" . $request_url . "

"; $requests = get_data($request_url); $fb_response = json_decode($requests); $request_urlB = "https://graph.facebook.com/".$page_id."/?access_token=".$params['access_token']; $requestsB = get_data($request_urlB); $fb_responseB = json_decode($requestsB); // avatar $picture= "https://graph.facebook.com/".$page_id."/picture?redirect=false&type=small&access_token=".$params['access_token']; $getP = get_data($picture); $getPjson = json_decode($getP); // *********************************************** // FQL // *********************************************** // query the 'page' database table because // we need to get: fan count / name / pic /* $result = $facebook->api(array( 'method' => 'fql.query', 'query' => 'select fan_count, name, pic from page where page_id = '.$page_id.';' )); // add the values to the vars $fb_fans = $result[0]['fan_count']; $fb_name = $result[0]['name']; $fb_pic = $result[0]['pic']; */ ?>
page counter / page name ?>
data->url; // FUNCTIONS function cropWord_($str) { // use this function if you want to crop too long words $arrayWords = explode(" ",$str); $length = count($arrayWords); for ($i = 0; $i < $length; $i++) { if (strlen($arrayWords[$i]) > 50) $arrayWords[$i] = substr($arrayWords[$i],0,50)." ... "; //print $arrayWords[$i]; } return implode(" ",$arrayWords); } function cropString_($str, $chars) { // use this function if you want to crop too long strings if (strlen($str) <= $chars) return $str; $new = wordwrap($str, $chars, "|"); $result=explode("|",$new); return $result[0]." [...]"; } // START $i = 0; // var_dump($fb_response->from->name); foreach($fb_response->data as $item) { $fb_likes = count($item->likes->data); $tipo = $item->type; // little-endian date format $data = strtotime($item->created_time); $data_convertita = date("d-m-Y H:i",$data); $data_convertita = time2str($data_convertita); // name control $name_writer = $item->from->name; //echo 'NAME WRITER: '.$name_writer; //echo ' / FB PAGE: '.$fb_name; // iteration (MAX 5) if (++$i ==40) break; // type if ($tipo == "link") { echo '
'; // link OR picture if (!empty($item->link) && empty($item->picture)) { echo '' . $data_convertita . ''; echo '
'. $item->link . '
'; } else if (!empty($item->link) && !empty($item->picture)) { echo '
'; echo '
'; if (!empty($item->message)) { echo '
'. $item->message . '
'; } else if (!empty($item->story)) { echo '
' . $item->story . '
'; } echo '
' . $item->name . '
'; echo $item->caption .'
'; echo $item->description; echo '' . $data_convertita . ''; // echo ''.$fb_likes.''; echo '
'; } echo '
'; } else if ($tipo == "status") { echo '
'; // story OR message if (!empty($item->message)) { echo '
'. $item->message . '
'; } else if (!empty($item->story)) { echo '
' . $item->story . '
'; } echo '' . $data_convertita . ''; echo '
'; } else if ($tipo == "photo") { echo '
'; // story OR message echo '
'; echo '
'; echo '
' . $item->name . '
'; if (!empty($item->message)) { echo '
'. cropWord_($item->message) . '
'; } else if (!empty($item->story)) { echo '
' . $item->story . '
'; } echo $item->caption .'
'; echo $item->description; // echo '

'.$fb_likes.''; echo '
'; echo ''. $data_convertita . ' '.$fb_likes.''; echo '
'; } else if ($tipo == "video") { echo '
'; // story OR message if (!empty($item->message)) { echo '
'. cropWord_($item->message) . '
'; } else if (!empty($item->story)) { echo '
' . $item->story . '
'; } // link OR picture if (!empty($item->link) && empty($item->picture)) { echo '
'. $item->link . '
'; echo '' . $data_convertita . ''; } else if (!empty($item->link) && !empty($item->picture)) { echo '
'; echo '
'; echo '
' . $item->name . '
'; echo $item->caption .'
'; echo $item->description; echo '

'.$fb_likes.''; echo '
'; echo '' . $data_convertita . ''; } echo '
'; } } ?>