Skip to content

Instantly share code, notes, and snippets.

@zhabinka
Last active January 2, 2016 09:46
Show Gist options
  • Save zhabinka/12c65a158a9cec2c3af5 to your computer and use it in GitHub Desktop.
Save zhabinka/12c65a158a9cec2c3af5 to your computer and use it in GitHub Desktop.
Сниппет для вывода ленты статусов из Twitter
<?php
/*
*
* vjikTwitter v0.2.1
* Сниппет для вывода ленты статусов из Twitter
*
* Автор: Предводителев Сергей
* Сайт: http://predvoditelev.ru/
* E-mail: [email protected]
*
* 01.10.2010
*
*/
(isset($name)) ? $name: $name='';
(isset($count)) ? $count: $count=5;
(isset($classEven)) ? $classEven: $classEven='';
(isset($tpl)) ? $tpl: $tpl='';
(isset($tplEven)) ? $tplEven: $tplEven='';
(isset($dateFormat)) ? $dateFormat: $dateFormat='';
if ($tpl!='') $tpl = $modx->getChunk($tpl);
if ($tplEven!='') $tplEven = $modx->getChunk($tplEven);
if ($name=='') {
echo 'Не указано имя twitter-аккаунта';
} else {
$out = '';
$xml = 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name='.$name.'&include_rts=1&count='.$count;
$xml = simplexml_load_file($xml);
for ($i=0; $i<$count; $i++){
$ph['status'] = $xml->status[$i]->text;
$ph['status'] = preg_replace('|(http:\/\/)(\S+)|si', '<a href="http://\\2">\\2</a>', $ph['status']);
$ph['date'] = strtotime($xml->status[$i]->created_at);
if ($dateFormat=='') {
$ph['date'] = $modx->toDateFormat($ph['date']);
} else {
$ph['date'] = strftime($dateFormat, $ph['date']);
}
if ($tpl!='') {
if ( ($i%2!=0) && ($tplEven!='') ) {
$s = $tplEven;
} else {
$s = $tpl;
}
foreach ($ph as $key => $value) {
$s = str_replace('[+'.$key.'+]', $value, $s);
}
$out.= preg_replace('/(\[\+.*?\+\])/' ,'', $s);
} else {
echo '<p'.( ( ($classEven!='') && ($i%2!=0) ) ? ' class="'.$classEven.'"' : '').'><small>'.$ph['date'].'</small><br>'.$ph['status'].'</p>';
}
}
echo $out;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment