entry as $item ){ $fblink=$item->link['href']; $tmp=preg_replace('`]*>.+?`is','',$item->content);$tmp1=str_replace('#villerssurmer','',$tmp); $tmp2=str_replace('
','',$tmp1);$tmp2=str_replace('
','',$tmp2);$tmp2=str_replace('
','',$tmp2); $tab_post[$i]=array('public'=> strtotime($item->published),'type'=> 'facebook', 'texte' => $tmp2, 'lien' => $fblink); if( $i == 10 ) break; $i++; } //Twitter $consumer_key = 'yycyM2vfaKZvDSbHEnWhw9rtg'; $consumer_secret = 'DbBNQe0yZsRjcCKqFAU96xLhHjDMXsa7UVUVmMqhsTN9ykvtMV'; $oauth_access_token = '3309221338-txJRSeHCwL03ozICtsGTOEZOP0P8gQ7JyNfND1l'; $oauth_access_token_secret = 'tVgb3sUW0p9YdN625v4BZrCmsTKLSGdeWx01p7Nds7npK'; error_reporting(E_ALL ^ E_NOTICE); $screen_name ="OTVillersurmer"; $count = 10; function buildBaseString($baseURI, $method, $params) { $r = array(); ksort($params); foreach($params as $key=>$value){ $r[] = "$key=" . rawurlencode($value); } return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r)); } function buildAuthorizationHeader($oauth) { $r = 'Authorization: OAuth '; $values = array(); foreach($oauth as $key=>$value) $values[] = "$key=\"" . rawurlencode($value) . "\""; $r .= implode(', ', $values); return $r; } $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $oauth = array( 'screen_name' => $screen_name, 'count' => $count, 'oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0'); $base_info = buildBaseString($url, 'GET', $oauth); $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret); $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true)); $oauth['oauth_signature'] = $oauth_signature; $header = array(buildAuthorizationHeader($oauth), 'Expect:'); $options = array( CURLOPT_HTTPHEADER => $header, //CURLOPT_POSTFIELDS => $postfields, CURLOPT_HEADER => false, CURLOPT_URL => $url . '?screen_name='.rawurlencode($screen_name).'&count='.$count, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false); $feed = curl_init(); curl_setopt_array($feed, $options); $json = curl_exec($feed); curl_close($feed); $twitter_data = json_decode($json); $count = 0; if(is_array($twitter_data)) { foreach($twitter_data as $row) { if($count > 0) { $json_format .= ' '; } $media = $row->entities->media; $attached = ""; if(!empty($media)) { foreach($media as $key) { $attached .= ' '; } } $tp_text=str_replace('"',' ',$row->text); if(strpos($tp_text,'http://')){$tp_lien=substr($tp_text,strpos($tp_text,'http://'));$tp_text=substr($tp_text,0,strpos($tp_text,'http://')-1); ;}else $tp_lien=''; //$json_format .= '$TW_title['.$count.']="'.$tp_text.'";$TW_id['.$count.']="'.$row->id_str.'";$TW_author['.$count.']="'.$row->user->screen_name.'";$TW_published['.$count.']='.strtotime($row->created_at).';$TW_media['.$count.']="'.$key->media_url.'";$TW_link['.$count.']="'.$tp_lien.'";'; $tab_post[$count+10]=array('public'=> strtotime($row->created_at),'type'=> 'twitter', 'texte' => $tp_text, 'lien' => $row->id_str); $count++; } } //print_r($tab_post); function fonctionComparaison($a, $b){ return $a['public'] > $b['public']; } usort($tab_post, 'fonctionComparaison'); $time=time(); $social='
'; for($z=19;$z>=0;$z--){ $difftime=dateDiff($time, $tab_post[$z]['public']); if($tab_post[$z][type]=="facebook")$social.='"; function dateDiff($time1, $time2, $precision = 6) { // If not numeric then convert texts to unix timestamps if (!is_int($time1)) { $time1 = strtotime($time1); } if (!is_int($time2)) { $time2 = strtotime($time2); } // If time1 is bigger than time2 // Then swap time1 and time2 if ($time1 > $time2) { $ttime = $time1; $time1 = $time2; $time2 = $ttime; } // Set up intervals and diffs arrays $intervals = array('year','month','day','hour','minute'); $diffs = array(); // Loop thru all intervals foreach ($intervals as $interval) { // Set default diff to 0 $diffs[$interval] = 0; // Create temp time from time1 and interval $ttime = strtotime("+1 " . $interval, $time1); // Loop until temp time is smaller than time2 while ($time2 >= $ttime) { $time1 = $ttime; $diffs[$interval]++; // Create new temp time from time1 and interval $ttime = strtotime("+1 " . $interval, $time1); } } $count = 0; $times = array(); // Loop thru all diffs foreach ($diffs as $interval => $value) { // Break if we have needed precission if ($count >= $precision) { break; } // Add value and interval // if value is bigger than 0 if ($value > 0) { // Add s if value is not 1 if ($value != 1) { $interval .= "s"; } // Add value and interval to times array //$intervals_no['second'] = 'seconde'; //$intervals_no['seconds'] = 'secondes'; $intervals_no['minute'] = 'mn'; $intervals_no['minutes'] = 'mn'; $intervals_no['hour'] = 'h'; $intervals_no['hours'] = 'h'; $intervals_no['day'] = 'jour'; $intervals_no['days'] = 'jours'; $intervals_no['month'] = 'mois'; $intervals_no['months'] = 'mois'; $intervals_no['year'] = 'an'; $intervals_no['years'] = 'ans'; $times[] = $value . " " . $intervals_no[$interval]; $count++; } } // Return string with times return implode(" ", $times); } $fichier = fopen('../office/librairie/feeds/sociaux.php', 'w+'); //$fichier = fopen('sociaux.php', 'w+'); fwrite($fichier, $social); fclose($fichier); ?>