Готового модуля нет, поэтому интегрируем ручками.
Регистрируем пользователя Instagram на сайте followgram.me, после этого xml постов доступен по адресу http://followgram.me/user_name/rss.
Дальше дело техники. Создаём материал с форматом текста "PHP" и вносим снипет:
<? // ---------------------------------------------------------------------- // CONFIG $site_name = "default"; $instagram_user = "user_name"; // your instagram username $cachetime = 2; // 2 hours $file = DRUPAL_ROOT ."/sites/".$site_name."/files/".$instagram_user."_instagram.txt"; // file used to cache content // ---------------------------------------------------------------------- function getFollowgram($u) { // function read instagram feed through followgram.me service, thanks Fabio Lalli // twitter @fabiolalli $url = "http://followgram.me/".$u."/rss"; $s = file_get_contents($url); preg_match_all('#<item>(.*)</item>#Us', $s, $items); $ar = array(); for($i=0;$i<count($items[1]);$i++) { $item = $items[1][$i]; preg_match_all('#<link>(.*)</link>#Us', $item, $temp); $link = $temp[1][0]; preg_match_all('#<pubDate>(.*)</pubDate>#Us', $item, $temp); $date = date("d-m-Y H:i:s",strtotime($temp[1][0])); preg_match_all('#<title>(.*)</title>#Us', $item, $temp); $title = $temp[1][0]; preg_match_all('#<img src="([^>]*)">#Us', $item, $temp); $thumb = $temp[1][0]; $ar['date'][$i] = $date; $ar['image'][$i] = str_replace("_5.jpg","_6.jpg",$thumb); $ar['bigimage'][$i] = str_replace("_5.jpg","_7.jpg",$thumb); $ar['link'][$i] = $link; $ar['title'][$i] = $title; } return $ar; } function checkValidFile($f,$hours) { // Function thar check if a file is older than X hours $durata=60*60 * $hours; $daquanto=$durata+1; if (file_exists($f)) $daquanto=time()-filemtime($f); else return false; if ($daquanto<=$durata) { // existing file is still valid $t = ($durata-$daquanto); $s = $t % 60; $m = floor($t/60) % 60; $h = floor($t/3600) % 24; $g = floor($t/3600/24); return true; } else { // existing file is old return false; } } // ----------------------------------------------- // load cached file if (!file_exists($file)) $archive=""; else { $rHandle = fopen($file, 'r'); $archive = fread($rHandle, filesize($file)); fclose($rHandle); } // ----------------------------------------------- // check for new feed every X hours if(!checkValidFile($file, $cachetime)) { $r = getFollowgram($instagram_user); // add new images to archive file for ($i=floor(count($r,COUNT_RECURSIVE)/count($r)); $i>=0; $i--) { if($r['image'][$i]) { $temp = "<li><img src='".$r['image'][$i]."'/><span>".$r['date'][$i]."<br/>".$r['title'][$i]."</span></li>"; if(!stristr($archive,basename($r['image'][$i]))) $archive = $temp.$archive; } } // save new file $f = fopen($file,'w'); fwrite($f,$archive); } ?> <style> ul.instagram {list-style:none;margin:0 auto;padding:0;} ul.instagram li { float:left; width:306px;height:306px;position:relative;} ul.instagram li span { position:absolute; left:0;bottom:0;background-color:#000;color:#fff; height:auto;font-family:trebuchet ms,trebuchet;font-size:12px;width:300px;padding:3px;} </style> <script> jQuery(document).ready(function() { jQuery('li span').hide(); jQuery('li').mouseenter(function(){ jQuery(this).find('span').show(); }); jQuery('li').mouseleave(function(){ jQuery(this).find('span').hide(); }); } ); </script> <ul class="instagram"><?=$archive?></ul>
$site_name - имя сайта при многосайтовой установке
$instagram_user - имя пользователя Instagram
Данные кешируются в файле, время жизни кеша - $cachetime



Добавить комментарий