Jump to content

[SOLVED] Warning: simplexml_load_string() error with twitter? Please help if you can


Presto-X

Recommended Posts

Hello everyone,

 

First off thank you very much for taking the time to read my post.

 

I have a custom Twitter feed reader built in php, it has been working great over the past month or two, but today it stopped working :( The following is the error messages:

 

Warning: simplexml_load_string() [function.simplexml-load-string]: namespace error : Namespace prefix twitter on geo is not defined in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: <twitter:geo> in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: namespace error : Namespace prefix twitter on geo is not defined in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: <twitter:geo> in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: namespace error : Namespace prefix twitter on geo is not defined in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: <twitter:geo> in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: namespace error : Namespace prefix twitter on geo is not defined in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: <twitter:geo> in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/*******/public_html/modules/mod_twitter/tmpl/default.php on line 107

 

And here is the code that we are using:

<?php
// Get all of the accounts from the module's parameters
$usernames = $params->get('account');
// Get the number of tweets to be displayed from the module's parameters
if (!is_numeric($params->get('tweets'))){
  $tweets = 10;
}else{
  $tweets = $params->get('tweets');
}
// This comes before the entire block of tweets.
$prefix = $params->get('prefix');
// This comes after the entire block of tweets.
$suffix = $params->get('suffix');

// Configure relative date and time
function smartTime($time){
  define("SECOND", 1);
  define("MINUTE", 60 * SECOND);
  define("HOUR", 60 * MINUTE);
  define("DAY", 24 * HOUR);
  define("MONTH", 30 * DAY);

$delta = time() - $time;
if ($delta < 2 * MINUTE){
	return "About 1 min ago";
}
if ($delta < 45 * MINUTE){
	return "About ".floor($delta / MINUTE) . " min ago";
}
if ($delta < 90 * MINUTE){
	return "About 1 hour ago";
}
if ($delta < 24 * HOUR){
	return "About ".floor($delta / HOUR) . " hours ago";
}
if ($delta < 48 * HOUR){
	return "Yesterday";
}
if ($delta < 30 * DAY){
	return floor($delta / DAY) . " days ago";
}
if ($delta < 12 * MONTH){
	$months = floor($delta / DAY / 30);
	return $months <= 1 ? "1 month ago" : $months . " months ago";
}else{
	$years = floor($delta / DAY / 365);
	return $years <= 1 ? "1 year ago" : $years . " years ago";
}
}

// Check if the cache folder exists if not create it
if (!file_exists('cache/mod_twitter/')){
  mkdir("cache/mod_twitter", 0777);
}

// Set cache file name and path
$Tfile = getcwd() . "/cache/mod_twitter/twitter_feed.cashe";

$exploded = explode(' ', $usernames);
$ulength = count($exploded);

$tsections = 0;
$tsections = intval($ulength / 7);
if ($ulength > ($tsections * 7)) {
  $tsections = $tsections + 1;	
}

$fed = "";

for ($u = 0; $u < $tsections; $u++)
{
  $llimit = ($u * 7) + 1;
  if (($llimit + 6) < $ulength)
  {
    $ulimit = $llimit + 6;
  }
  else
  {
    $ulimit = $ulength;
  }
  $usernamed = $exploded[$llimit - 1];

  for ($o = $llimit; $o < $ulimit; $o++)
  {
  $usernamed = $usernamed . ' ' . $exploded[$o];
  }
  
  $usernames = str_replace(" ", "+OR+from%3A", $usernamed);
  $feed = "http://search.twitter.com/search.atom?q=from%3A" . $usernames . "&rpp=" . $tweets;

  $feded = file_get_contents($feed);

  $fedd = explode('<entry>', $feded, 2);
  $feddd = explode('</feed>', '<entry>' . $fedd[1]);
  $fed = $fed . $feddd[0];
}

$fed = '<feed>' . $fed . '</feed>';
$fed = str_replace('<twitter:source>', '<twittersource>', $fed);
$fed = str_replace('</twitter:source>', '</twittersource>', $fed);
$fed = str_replace('<twitter:lang>', '<twitterlang>', $fed);
$fed = str_replace('</twitter:lang>', '</twitterlang>', $fed);

// This comes before the entire block of tweets.
echo $prefix;

$xml = simplexml_load_string($fed);
$i = 0;
foreach ($xml->entry as $entryed) {
  $published = $entryed->published;
  $published = str_replace(' ', '', $published);
  $published = str_replace(':', '', $published);
  $published = str_replace('-', '', $published);
  for ($j=65; $j<91; $j++)
  {
    $published = str_replace(chr($j), '', $published);	  
  }
  for ($j=97; $j<123; $j++)
  {
    $published = str_replace(chr($j), '', $published);	  
  }


  $entries[$i][0] = $published;
  $entries[$i][1] = $entryed->asXML();
  $i++;
}
sort($entries);
$fed = "";
for ($e=count($entries); $e>=0; $e--)
{
$fed = $fed . $entries[$e][1];
}


$fed = '<feed>' . $fed . '</feed>';


if (strpos($fed, '</entry>') !== false)
{
  $Handle = fopen($Tfile, 'w');
  fwrite($Handle, $fed); 
  fclose($Handle); 
}  
else
{
  $fed = file_get_contents($Tfile, FILE_USE_INCLUDE_PATH);
}

  $feed = $fed;
  $clean = explode("<entry>", $feed);
  $amount = count($clean) - 1;

  for ($i = 1; $i <= $tweets; $i++) {
    $entry_close = explode("</entry>", $clean[$i]);
    $clean_content_1 = explode("<content type=\"html\">", $entry_close[0]);
    $clean_content = explode("</content>", $clean_content_1[1]);
    $clean_name_2 = explode("<name>", $entry_close[0]);
    $clean_name_1 = explode("(", $clean_name_2[1]);
    $clean_name = explode(")</name>", $clean_name_1[1]);
    $clean_uri_1 = explode("<uri>", $entry_close[0]);
    $clean_uri = explode("</uri>", $clean_uri_1[1]);
    $clean_published_1 = explode("<published>", $entry_close[0]);
    $clean_published = explode("Z", $clean_published_1[1]);
$clean_published = str_replace("T", " ", $clean_published);
$clean_time_1 = explode("<published>", $entry_close[0]);
$clean_time = explode("</published>", $clean_time_1[1]);
$unix_time = strtotime($clean_time[0]);
$date = smartTime($unix_time);
    $displayDate = date($params->get('dateformat'), strtotime($clean_published[0]));
    $accountname = explode(")", $clean_name_1[1]);

// twitter wrapper tag
$displaytweets  = '<'.$params->get('divspan').' class="tweetswrapper'.$params->get('moduleclass_sfx').'">';

// display tweet icon
if($params->get('showicon')== "1"):
  $displaytweets .= '<'.$params->get('divspan').' class="tweet_icon'.$params->get('moduleclass_sfx').'">';
  $displaytweets .= '<img src="modules/mod_twitter/images/twitter.png" />';
  $displaytweets .= '</'.$params->get('divspan').'>';
endif;

// tweets content wrapper
if($params->get('showicon')== "1"):
  $displaytweets .= '<'.$params->get('divspan').' class="tweet'.$params->get('moduleclass_sfx').'">';
endif;

// display tweet date
if(($params->get('showdate')== "1")or($params->get('smartTime')== "1")):
  $displaytweets .= '<'.$params->get('divspan').' class="tweet_date'.$params->get('moduleclass_sfx').'">';
  if(($params->get('showdate')== "0")&&($params->get('smartTime')== "1")):
    $displaytweets .= $date;
  elseif(($params->get('showdate')== "1")&&($params->get('smartTime')== "0")):
    $displaytweets .= $displayDate;
  else:
    $displaytweets .= $date.' - '.$displayDate;
  endif;
  $displaytweets .= '</'.$params->get('divspan').'>';
endif;

// tweet content
$displaytweets .= '<'.$params->get('divspan').' class="tweet_content'.$params->get('moduleclass_sfx').'">';
$displaytweets .= html_entity_decode(str_replace("#fb", "", $clean_content[0]));
$displaytweets .= '</'.$params->get('divspan').'>';

// display read more
if($params->get('displayreadmore') == "1"):
  $displaytweets .= '<'.$params->get('divspan').' class="tweet_readmore'.$params->get('moduleclass_sfx').'" align="'.$params->get('readmorealign').'">';
      $displaytweets .= '<a href="' . $clean_uri[0] . '" title="Read more over at the ' . $clean_name[0] . ' twitter page!" id="twitter_link" target="'.$params->get('twitterTarget').'">'.$params->get('readmoretext').' »</a>';
  $displaytweets .= '</'.$params->get('divspan').'>';
    endif;

// display tweet twitter
if($params->get('submittedby')== "1"):
  $displaytweets .= '<'.$params->get('divspan').' class="tweet_submitted_by'.$params->get('moduleclass_sfx').'">';
  $displaytweets .= 'by: <a href="http://twitter.com/'.$clean_name_1[0].'" target="'.$params->get('twitterTarget').'">'.$accountname[0].'</a>';
  $displaytweets .= '</'.$params->get('divspan').'>';
endif;

// closing tweet wrapper
if($params->get('showicon')== "1"):
  $displaytweets .= '</'.$params->get('divspan').'>';
endif;

// closing twitter wrapper
$displaytweets .= '</'.$params->get('divspan').'>';

// twitter clear any css floats
    $displaytweets .= '<div class="tweet_clear"></div>';

// display full tweet
if(!empty($clean_content[0])){
  echo $displaytweets;
}

}

// This comes after the entire block of tweets.
echo $suffix;

?>

Ok I think I found the problem it looks like twitter added a new row to it's feed? <twitter:geo> I added this to my code around line 107 and all is well again.

 

I changed this code:

$fed = '<feed>' . $fed . '</feed>';
$fed = str_replace('<twitter:source>', '<twittersource>', $fed);
$fed = str_replace('</twitter:source>', '</twittersource>', $fed);
$fed = str_replace('<twitter:lang>', '<twitterlang>', $fed);
$fed = str_replace('</twitter:lang>', '</twitterlang>', $fed);

 

To this:

$fed = '<feed>' . $fed . '</feed>';
$fed = str_replace('<twitter:geo>', '<twittergeo>', $fed);
$fed = str_replace('</twitter:geo>', '</twittergeo>', $fed);
$fed = str_replace('<twitter:source>', '<twittersource>', $fed);
$fed = str_replace('</twitter:source>', '</twittersource>', $fed);
$fed = str_replace('<twitter:lang>', '<twitterlang>', $fed);
$fed = str_replace('</twitter:lang>', '</twitterlang>', $fed);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.