function querypath_examples_show_twitter in QueryPath 6
Same name and namespace in other branches
- 7.3 querypath_examples.module \querypath_examples_show_twitter()
- 7.2 querypath_examples.module \querypath_examples_show_twitter()
1 string reference to 'querypath_examples_show_twitter'
- querypath_examples_menu in ./
querypath_examples.module - Implements hook_menu();
File
- ./
querypath_examples.module, line 147 - The main file for querypath_examples.
Code
function querypath_examples_show_twitter() {
$out = '<h2>' . t('Fetch and display the public twitter feed.') . '</h2>';
$out .= '<p>' . t('Display the most recent entries on the Twitter public timeline.') . '</p>';
try {
$ul = qp('<?xml version="1.0"?><ul/>');
$url = 'http://twitter.com/statuses/public_timeline.xml';
$tpl = '<li>
<div style="height: 55px">
<img style="float:left" width="50" height="50" src="@img"/>
<strong>@uname</strong><em>@ts</em><br/>
@txt
</div>
</li>';
foreach (qp($url, 'status') as $status) {
$data = array();
$data['@ts'] = substr($status
->children('created_at')
->text(), 0, 20);
$data['@txt'] = filter_xss_admin($status
->next('text')
->text());
$data['@uname'] = htmlentities($status
->parent()
->find('user>screen_name')
->text());
$data['@img'] = $status
->next('profile_image_url')
->text();
$data = strtr($tpl, $data);
$ul
->append($data);
}
$out .= $ul
->html();
} catch (Exception $e) {
drupal_set_message('Error:' . $e
->getMessage(), 'status');
}
$code = '
<?php
$ul = qp(\'<?xml version="1.0"?><ul/>\');
$url = \'http://twitter.com/statuses/public_timeline.xml\';
$tpl = \'<li>
<div style="height: 55px">
<img style="float:left" width="50" height="50" src="@img"/>
<strong>@uname</strong><em>@ts</em><br/>
@txt
</div>
</li>\';
foreach (qp($url, \'status\') as $status) {
$data = array();
$data[\'@ts\'] = substr($status->children(\'created_at\')->text(), 0, 20);
$data[\'@txt\'] = filter_xss_admin($status->next(\'text\')->text());
$data[\'@uname\'] = htmlentities($status->parent()->find(\'user>screen_name\')->text());
$data[\'@img\'] = $status->next(\'profile_image_url\')->text();
$data = strtr($tpl, $data);
$ul->append($data);
}
$out .= $ul->html();
?>';
$out .= '<h2>' . t('The Code:') . '</h2>';
$out .= highlight_string($code, TRUE);
$out .= '<h2>' . t('References:') . '</h2>';
$out .= l('The QueryPath API', 'http://querypath.org');
return $out;
}