/**
* Object for getting, parsing, and prepping external related content
*
* @author Husani S. Oakley
* @version 1.0
*/
class SMIRC{
var $total_results;
var $page_title;
var $default_header_text = "Blog discussions:";
var $search_urls = array(
"google_blogsearch_norss" => "http://blogsearch.google.com/blogsearch?client=news&um=1&hl=en&scoring=d&q=SEARCHTERM&ie=utf-8",
"google_blogsearch" => "http://blogsearch.google.com/blogsearch_feeds?client=news&um=1&hl=en&scoring=d&q=SEARCHTERM&ie=utf-8&num=NUMRESULTS&output=rss",
"twitter_search" => "http://search.twitter.com/search.atom?q=SEARCHTERM&rpp=NUMRESULTS"
);
/**
* constructor
*/
function SMIRC($page_title, $title_separators, $required_keyword, $data_sources, $header_text, $animation=false){
$this->page_title = $page_title;
$this->title_separators = $title_separators;
$this->required_keyword = $required_keyword;
$this->data_sources = $data_sources;
if($header_text == ""){
$this->header_text = $this->default_header_text;
} else {
$this->header_text = $header_text;
}
$this->animation = $animation;
}
/**
* main work method. create url, get data, parse, prep and return xhtml
*/
function getContent(){
//don't bother doing anything if we don't have any data sources
if(!is_array($this->data_sources)){ return false; }
//if we have delimiter characters, use them to split up the title
$searchterm = $this->_getSearchTerm();
//start assembling data
foreach($this->data_sources as $source_array){
//prep url
$data_source = str_replace("SEARCHTERM", $searchterm, $this->search_urls[$source_array[0]]);
$data_source = str_replace("NUMRESULTS", $source_array[1], $data_source);
//get data, put into array
$rss_data_array[$source_array[0]]['results'] = $this->_getResults($data_source, split("\n", $source_array[2]));
$rss_data_array[$source_array[0]]['header'] = $source_array[3];
}
//create and return xhtml for all sources
$xhtml = $this->_createXHTML($rss_data_array, $this->header_text);
return $xhtml;
}
/**
* create and return all xhtml
*/
function _createXHTML($rss_array, $header_text){
foreach($rss_array as $data_source => $results_and_header){
//run function to get xhtml from rss object -- name of function depends on data source.
$lists_xhtml .= $this->$data_source($results_and_header['results'], $results_and_header['header']);
}
if($lists_xhtml == ""){
//no results = no xhtml
return false;
} else {
$all_xhtml = '
';
return $all_xhtml;
}
}
/**
* GOOGLE BLOGSEARCH: iterate through rss object and create standards-compliant xhtml for the resultset, while ignoring items in exclude list
*/
function google_blogsearch($rss_items, $result_header){
$list_xhtml = "";
if(count($rss_items) >= 1){
$list_xhtml = "
$result_header
";
foreach($rss_items as $item){
$fixed_item = $this->_parseItem($item);
$list_xhtml .= '
';
}
}
return $list_xhtml;
}
/**
* TWITTER SEARCH: iterate through rss object and create standards-compliant xhtml for the resultset
* search.twitter.com doesn't seem to have results limits, so we'll have to do that manually.
*/
function twitter_search($rss_items, $result_header){
$list_xhtml = "";
if(count($rss_items) >= 1){
$list_xhtml = "
$result_header
";
foreach($rss_items as $item){
$fixed_item = $this->_parseItem($item);
$list_xhtml .= '