* @version version 0.1
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
function plugin_ust_recorded_inline()
{
$args = func_get_args();
return call_user_func_array('plugin_ust_recorded_convert', $args);
}
function plugin_ust_recorded_convert()
{
$argv = func_get_args();
$argc = func_num_args();
$id = $argv[0];
if (empty($id)) return '#ust_recorded: ID parameter must be set.';
$command = 'listAllVideos';
$ustream_api = 'http://api.ustream.tv/php/channel/' . $id . '/' . $command;
$response = file_get_contents($ustream_api);
$data = unserialize($response);
$retval = "
\n";
foreach ($data['results'] as $video) {
$lensec = (int)( $video['lengthInSecond'] );
$min = (int)( $lensec / 60 );
$sec = $lensec % 60;
$title = ust_recorded_encode( $video['title'] );
$retval .= '- ' . $title . "
\n";
$retval .= "Total Views: " . $video['totalViews'] . " | Length: " . $min . ":" . $sec . "
\n";
}
$retval .= "
\n";
return $retval;
}
function ust_recorded_encode($buf)
{
// Detect encoding
$matches = array();
if(preg_match('/<\?xml [^>]*\bencoding="([a-z0-9-_]+)"/i', $buf, $matches)) {
$encoding = $matches[1];
} else {
$encoding = mb_detect_encoding($buf);
}
// Normalize to UTF-8 / ASCII
if (! in_array(strtolower($encoding), array('us-ascii', 'iso-8859-1', 'utf-8'))) {
$buf = mb_convert_encoding($buf, 'utf-8', $encoding);
$encoding = 'utf-8';
}
// Unescape already-escaped chars (<, >, &, ...) in RSS body before htmlspecialchars()
$buf = strtr($buf, array_flip(get_html_translation_table(ENT_COMPAT)));
// Escape
$buf = htmlspecialchars($buf);
// Encoding conversion
$buf = mb_convert_encoding($buf, SOURCE_ENCODING, $encoding);
return trim($buf);
}
?>