Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
my script have an error on the line 132, so the cron ends with error, can you assist? I didn't made this script and the coder is not available anymore, so if someone can help me I will really appreciate
thank you
<?php
include('/home/admin/domains/domain.com/public_html/admin/inc/connect.inc.php');
require_once('/home/admin/domains/domain.com/public_html/inc/lastadd.php");
echo RSS_Display("http://www.site.com/embedrss", 12);
?>
<?
$RSS_Content = array();
function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("description");
$tnl = $tnl->item(0);
$description = $tnl->firstChild->textContent;
$y["title"] = $title;
$y["link"] = $link;
$y["description"] = $description;
$y["type"] = $type;
return $y;
}
function RSS_Channel($channel)
{
global $RSS_Content;
$items = $channel->getElementsByTagName("item");
// Processing channel
$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);
// Processing articles
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
function RSS_Retrieve($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
RSS_Channel($channel);
}
}
function RSS_RetrieveLinks($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
}
function RSS_Display($url, $size = 15, $site = 0)
{
global $RSS_Content;
$opened = false;
$page = "";
$site = (intval($site) == 0) ? 1 : 0;
RSS_Retrieve($url);
if($size > 0)
$recents = array_slice($RSS_Content, $site, $size + 1 - $site);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0)
{
if($opened == true)
{
$page .="";
$opened = false;
}
$page .="";
}
else
{
if($opened == false)
{
$page .= "";
$opened = true;
}
}
$title = $article["title"];
$link = $article["link"];
$links[]=$link;
$description = $article["description"];
$page .= "";
if($description != false)
{
$page .= "";
}
$page .= "";
if($type==0)
{
$page .="";
}
}
if($opened == true)
{
$page .="";
}
?>
<?
foreach($links as $lnk) {
$ch = curl_init();//start curl
curl_setopt($ch, CURLOPT_URL, $lnk); //curl Targeted URL
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$source = curl_exec($ch);
$videoid_start = strpos($source,'http://www.traileraddict.com/emd/');
$videoid_end = $videoid_start+60;
$poster_start = strpos($source,'dir=');
$poster_end = strpos($source,'.jpg" style="');
$desc_start = strpos($source,'Upscale Font');
$desc_end = strpos($source,'Tags:');
$title_start = strpos($source,'<title>');
$title_end = strpos($source,'</title>');
$videoid_content="";
$poster_content='';
$desc_content='';
$title_content='';
/*HERE STATRTS THE Poster CODE*/
for ($i=$poster_start;$i<$poster_end;$i++) {
$poster_content .= $source[$i];
}
$poster_content= trim(str_replace('dir=','',$poster_content));
/*HERE STATRTS THE Title CODE*/
for ($i=$title_start;$i<$title_end;$i++) {
$title_content .= $source[$i];
}
$title_content= trim(str_replace('<title>','',$title_content));
$title_content= trim(str_replace(' - Trailer Addict','',$title_content));
if (empty($title_content))
{
?>
<center>No Title</center>
<?
}
if (empty($poster_content))
{
$contents = file_get_contents('/home2/playtwof/public_html/dailytrailers/posters/noposter.jpg');
$title_poster = $title_content;
$title_poster = trim(str_replace(' ','',$title_poster));
$title_poster = trim(str_replace(':','',$title_poster));
$title_poster = trim(str_replace("'","",$title_poster));
$title_poster = trim(str_replace("&","",$title_poster));
$fp = fopen('/home2/playtwof/public_html/dailytrailers/posters/'.$title_poster.'.jpg', 'w');
fwrite($fp, $contents);
fclose($fp);
}
else {
$contents = file_get_contents('http://www.traileraddict.com'.$poster_content.'.jpg');
$title_poster = $title_content;
$title_poster = trim(str_replace(' ','',$title_poster));
$title_poster = trim(str_replace(':','',$title_poster));
$title_poster = trim(str_replace("'","",$title_poster));
$title_poster = trim(str_replace("&","",$title_poster));
$fp = fopen('/home2/playtwof/public_html/dailytrailers/posters/'.$title_poster.'.jpg', 'w');
fwrite($fp, $contents);
fclose($fp);
}
/*HERE ENDS THE Poster CODE*/
/*HERE ENDS THE Title CODE*/
/*HERE STATRTS THE Description CODE*/
for ($i=$desc_start;$i<$desc_end;$i++) {
$desc_content .= $source[$i];
}
$desc_content= trim(str_replace('Upscale Font','',$desc_content));
$desc_content= trim(str_replace('<a href="/tags/hatchet">','',$desc_content));
$desc_content= trim(str_replace('<span id="morelink" name="morelink"><img src="/images/moreinfo.png" alt="More Trailer Details" border="0" align="absmiddle">','',$desc_content));
$desc_content= trim(str_replace('</div>','',$desc_content));
$desc_content= trim(str_replace('" style="float:left; margin-top:2px;" border="0" />','',$desc_content));
$desc_content= trim(str_replace('<span id="moredet" name="moredet" style="display:none;">','',$desc_content));
$desc_content= trim(str_replace('<img src="/images/lessinfo.png" alt="Hide Trailer Details" border="0" align="absmiddle"></a></span> <span id="morelink" name="morelink"><img src="/images/moreinfo.png" alt="More Trailer Details" border="0" align="absmiddle"><br></span> </span>','',$desc_content)); $desc_content= trim(str_replace('<img src="/images/lessinfo.png" alt="Hide Trailer Details" border="0" align="absmiddle">','',$desc_content));
$desc_content= trim(str_replace('<span id="morelink" name="morelink"><img src="/images/moreinfo.png" alt="More Trailer Details" border="0" align="absmiddle">','',$desc_content));
if (empty($desc_content))
{
?>
<center>Sorry, No description for this trailer!<br /></center>
<?
}
for ($i=$videoid_start;$i<$videoid_end;$i++) {
if (is_numeric($source[$i]))
$videoid_content .= $source[$i];
}
$desc_content= trim(str_replace("'","",$desc_content));
$title_content = trim(str_replace("'",'',$title_content));
$title_poster = trim(str_replace("'","",$title_poster));
mysql_query("insert into trailer set titlu='$title_content',poster='$title_poster.jpg',descriere='$desc_content',video_id='$videoid_content',hits=1");
}
}
?>
You have an error in this line - it begins with a single quote, and ends in a double quote:
require_once('/home/admin/domains/domain.com/public_html/inc/lastadd.php");
this should be a single quote------^
Related
Here is the code I have, I cannot work out what is causing the delays?
To load the remote URL it doesn't take more than a second, should I pass a user_agent?
Please excuse if this is a stupid question, I'm new to PHP, would it be worth setting a timeout as part of the curl request?
<?php
$url = $_GET['url'];
if(!filter_var($url, FILTER_VALIDATE_URL)) {
?>
{"errors":1,"message":"The URL was not valid"}
<?php
die();
}
$p=parse_url($url);
$baseurl = $p['scheme'] . '://' . $p['host'];
$path_parts = pathinfo($url);
$current_dir = $path_parts['dirname'];
Function check_img($file) {
$x = #getimagesize($file);
if ($x) {
switch ($x['mime']) {
case "image/gif" || "image/jpeg" || "image/png":
$response = true;
break;
default:
$response = false;
break;
}
} else {
$response = false;
}
return $response;
}
function ranger($url){
$headers = array(
"Range: bytes=0-605768"
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$html = file_get_contents_curl($url);
//parsing begins here:
$doc = new DOMDocument();
#$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
// Get all image tags
$imageTags = $doc->getElementsByTagName('img');
$numImages = $doc->getElementsByTagName('img')->length;
//get and display what you need:
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('property') == 'og:image' || $meta->getAttribute('name') == 'og:image')
$fb_image = $meta->getAttribute('content');
$fb_image = isset($fb_image) ? $fb_image : '';
}
?>
{
"resource_images": {
"url" : "<?php echo $url?>",
"baseurl" : "<?php echo $baseurl?>",
"fb" : "<?php echo $fb_image?>",
"images" : [<?php
$i = 0;
$image_results = array();
$numItems = count($imageTags);
if ($fb_image !== '') {
$image_results[] = $fb_image;
}
foreach($imageTags as $tag) {
if ($i >= 25) {
break;
}
if (substr($tag->getAttribute('src'),0,4) === 'http') {
$img = $tag->getAttribute('src');
} elseif (substr($tag->getAttribute('src'),0,1) === '/') {
$img = $baseurl . $tag->getAttribute('src');
} else {
$img = $current_dir . $tag->getAttribute('src');
}
$exists = check_img($img);
if ($exists) {
$raw = ranger($img);
$im = imagecreatefromstring($raw);
$width = imagesx($im);
$height = imagesy($im);
if ($width > 300) {
$image_results[] = str_replace('"', "", $img);
}
if(++$i < $numItems && ++$i < 25) {
echo ",";
}
}
}
$i = 0;
foreach($image_results as $img_url) {
?>
{
"url" : "<?php echo str_replace('"', "", $img_url);?>",
"count" : <?php echo count($image_results)?>
}
<?php
if(++$i < count($image_results) && $i < 15) {
echo ",";
}
}?>
]
}
}
use this at the beginning:
set_time_limit(0)
Yes, definately a timeout on the curl, as this can go on forever.
What I would do in this case is to pinpoint the code that is taking up alot of the time like this:
<?php
function microtime_float() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float(); //this # the top of ur file
// process some code
// ...
// show results, this can be anywhere, inside a function, loop etc,
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Did it in $time seconds\n . <br>";
I wouldnt time the whole script but go part by part and find out where the wait is.
I am new to php, trying to get a RSS Reader to display a message when there is nothing to display.
I asked for some help yesterday and was kindly assisted, and it made sense, but for some reason it is not storing it.
Hoping someone could tell me what is wrong with the following php.
<?php
require_once("rsslib.php");
$url = "http://www.bom.gov.au/fwo/IDZ00063.warnings_land_qld.xml";
$rss123 = RSS_Display($url, 3, false, true);
if (count($rss123) < 1)
{
// nothing shown, do whatever you want
echo 'There are no current warnings';
echo '<style type="text/css">
#flashing_wrapper {
display: none;
}
</style>';
}
else
{
// something to display
echo $rss123;
}
?>
My problem is, it doesnt seem to be storing a value in $rss123.
It can be viewed at the following address - http://goo.gl/12XQSe
Thanks in advanced,
Pete
----- EDIT ------
As requested in a comment, RSS_Display is from the rsslib.php file, which is as follows
<?php
/*
RSS Extractor and Displayer
(c) 2007-2010 Scriptol.com - Licence Mozilla 1.1.
rsslib.php
Requirements:
- PHP 5.
- A RSS feed.
Using the library:
Insert this code into the page that displays the RSS feed:
<?php
require_once("rsslib.php");
echo RSS_Display("http://www.xul.fr/rss.xml", 15);
? >
*/
$RSS_Content = array();
function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("pubDate");
$tnl = $tnl->item(0);
$date = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("description");
$tnl = $tnl->item(0);
$description = $tnl->firstChild->textContent;
$y["title"] = $title;
$y["link"] = $link;
$y["date"] = $date;
$y["description"] = $description;
$y["type"] = $type;
return $y;
}
function RSS_Channel($channel)
{
global $RSS_Content;
$items = $channel->getElementsByTagName("item");
// Processing channel
$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);
// Processing articles
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
function RSS_Retrieve($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
RSS_Channel($channel);
}
}
function RSS_RetrieveLinks($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
}
function RSS_Links($url, $size = 15)
{
global $RSS_Content;
$page = "<ul>";
RSS_RetrieveLinks($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size + 1);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0) continue;
$title = $article["title"];
$link = $article["link"];
$page .= "<li>$title</li>\n";
}
$page .="</ul>\n";
return $page;
}
function RSS_Display($url, $size = 18, $site = 0, $withdate = 0)
{
global $RSS_Content;
$opened = false;
$page = "";
$site = (intval($site) == 0) ? 1 : 0;
RSS_Retrieve($url);
if($size > 0)
$recents = array_slice($RSS_Content, $site, $size + 1 - $site);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0)
{
if($opened == true)
{
$page .="</ul>\n";
$opened = false;
}
$page .="<b>";
}
else
{
if($opened == false)
{
$page .= "<ul>\n";
$opened = true;
}
}
$title = $article["title"];
$link = $article["link"];
$page .= "<li>$title";
if($withdate)
{
$date = $article["date"];
$page .=' <span class="rssdate">'.$date.'</span>';
}
$description = $article["description"];
if($description != false)
{
$page .= "<br><span class='rssdesc'>$description</span>";
}
$page .= "</li>\n";
if($type==0)
{
$page .="</b><br />";
}
}
if($opened == true)
{
$page .="</ul>\n";
}
return $page."\n";
}
?>
There seems to be something wrong with the xml file you are using. I tried the with a another xml by replacing the url with the mentioned value. $url = "http://www.scriptol.com/rss.xml";
Oddly enough it seems to be working now with the old xml as well.
I am parsing a xml and but there is a tag which contain image and text both and i want to seprate both image and text in diffrent columns of table in my design layout but i dont know how to do it. please help me. my php file is :
<?php
$RSS_Content = array();
function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("description");
$tnl = $tnl->item(0);
$img = $tnl->firstChild->textContent;
$y["title"] = $title;
$y["link"] = $link;
$y["description"] = $img;
$y["type"] = $type;
return $y;
}
function RSS_Channel($channel)
{
global $RSS_Content;
$items = $channel->getElementsByTagName("item");
// Processing channel
$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);
// Processing articles
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
function RSS_Retrieve($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
RSS_Channel($channel);
}
}
function RSS_RetrieveLinks($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = RSS_Tags($item, 1);
array_push($RSS_Content, $y);
}
}
}
function RSS_Links($url, $size = 15)
{
global $RSS_Content;
$page = "<ul>";
RSS_RetrieveLinks($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size + 1);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0) continue;
$title = $article["title"];
$link = $article["link"];
$img = $article["description"];
$page .= "$title\n";
}
$page .="</ul>\n";
return $page;
}
function RSS_Display($url, $click, $size = 8, $site = 0, $withdate = 0)
{
global $RSS_Content;
$opened = false;
$page = "";
$site = (intval($site) == 0) ? 1 : 0;
RSS_Retrieve($url);
if($size > 0)
$recents = array_slice($RSS_Content, $site, $size + 1 - $site);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0)
{
if($opened == true)
{
$page .="</ul>\n";
$opened = false;
}
$page .="<b>";
}
else
{
if($opened == false)
{
$page .= "<table width='369' border='0'>
<tr>";
$opened = true;
}
}
$title = $article["title"];
$link = $article["link"];
$img = $article["description"];
$page .= "<td width='125' align='center' valign='middle'>
<div align='center'>$img</div></td>
<td width='228' align='left' valign='middle'><div align='left'><a
href=\"$click\" target='_top'>$title</a></div></td>";
if($withdate)
{
$date = $article["date"];
$page .=' <span class="rssdate">'.$date.'</span>';
}
if($type==0)
{
$page .="<br />";
}
}
if($opened == true)
{
$page .="</tr>
</table>";
}
return $page."\n";
}
?>
To separate the image and description you need to parse the HTML that is stored inside the description element again as XML. Luckily it is valid XML inside that element, therefore you can do this straight forward with SimpleXML, the following code-example take the URL and converts each item *description* into the text only and extracts the src attribute of the image to store it as the image element:
<item>
<title>Fake encounter: BJP backs Kataria, says CBI targeting Modi</title>
<link>http://ibnlive.in.com/news/fake-encounter-bjp-backs-kataria-says-cbi-targeting-modi/391802-37-64.html</link>
<description>The BJP lashed out at the CBI and questioned its 'shoddy investigation' into the Sohrabuddin fake encounter case.</description>
<pubDate>Wed, 15 May 2013 13:48:56 +0530</pubDate>
<guid>http://ibnlive.in.com/news/fake-encounter-bjp-backs-kataria-says-cbi-targeting-modi/391802-37-64.html</guid>
<image>http://static.ibnlive.in.com/ibnlive/pix/sitepix/05_2013/bjplive_kataria3.jpg</image>
</item>
The code-example is:
$url = 'http://ibnlive.in.com/ibnrss/top.xml';
$feed = simplexml_load_file($url);
$items = $feed->xpath('(//channel/item)');
foreach ($items as $item) {
list($description, $image) =
simplexml_load_string("<r>$item->description</r>")
->xpath('(/r|/r//#src)');
$item->description = (string)$description;
$item->image = (string)$image;
}
You can then import the SimpleXML into a DOMElement with dom_import_simplexml() however honestly, I just would wrap that little HTML creation as well into a foreach of SimpleXML because you can make use of LimitIterator for the paging as well as you could with DOMDocument and the data you access is actually easily at hand with SimpleXML, it's just easy to pass along the XML elements as SimpleXMLElements instead of parsing into an array first and then processing the array. That's moot.
I have two pages, one is the script itself, and the other the page that calls it. I can display my feed fine, but I need to display it in reverse order. (oldest first). I have tried the two asort and arsort functions, but I cant get them to work.
Here is the code:
$RSS_Content = array();
function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->data;
$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->data;
//$tnl = $item->getElementsByTagName("description");
// $tnl = $tnl->item(0);
// $description = $tnl->firstChild->data;
$y["title"] = $title;
$y["link"] = $link;
//$y["description"] = $description;
$y["type"] = $type;
return $y;
}
function RSS_Channel($channel)
{
global $RSS_Content;
$items = $channel->getElementsByTagName("item");
// Processing channel
$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);
// Processing articles
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
function RSS_Retrieve($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
RSS_Channel($channel);
}
}
function RSS_RetrieveLinks($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
}
function RSS_Links($url, $size)
{
global $RSS_Content;
$page = "<ul>";
RSS_RetrieveLinks($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0) continue;
$title = $article["title"];
$link = $article["link"];
$page .= "<li>$title</li>\n";
}
$page .="</ul>\n";
return $page;
}
function RSS_Display($url, $size)
{
global $RSS_Content;
asort($RSS_Content);
$opened = false;
$page = "";
RSS_Retrieve($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0)
{
if($opened == true)
{
$page .="</ul>\n";
$opened = false;
}
$page .="<b>";
}
else
{
if($opened == false)
{
$page .= "<ul>\n";
$opened = true;
}
}
$title = $article["title"];
$link = $article["link"];
// $description = $article["description"];
$page .= "<p>$title";
// if($description != false)
{
//$page .= "<br>$description";
}
$page .= "</p>\n";
if($type==0)
{
$page .="</b><br />";
}
}
if($opened == true)
{
$page .="</ul>\n";
}
return $page."\n";
}
Then on the second page, I have this:
$url = "feedurlhere.xml";
echo RSS_Links($url, 10);
?>
</div>
Thanks to Scriptol, the answer is:
change all instances of array_push to array_switch
Cheers
Facebook integration has been working perfectly on my site for some time, then overnight something happened at facebook because it's now failing.
Can someone have a look at the code I use all over my site and advise what I should do to get this working again as soon as possible, without having to remodel the whole implementation?
<?php
// http://developers.facebook.com/docs/reference/fql/user
class Facebook_class
{
var $cookie;
function Facebook_class() {
$this->cookie = $this->get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
}
function getUserid() {
$cookie = $this->getCookie();
$fb_userid = $cookie['uid'];
return $fb_userid;
}
function getProfilePicture() {
$url = 'https://graph.facebook.com/'.$this->getUserid().'/picture?type=large';
//$url = 'api.facebook.com/method/fql.query?query=SELECT pic_big FROM user WHERE uid = '.$this->getUserid();
$url = $this->get_redirect_url($url);
return $url;
}
function getUserData() {
if($this->getCookie()) {
$url = 'https://graph.facebook.com/me?access_token='.$this->getAccessToken();
$userData = json_decode(file_get_contents($url));
return $userData;
}
}
function getCookie() {
return $this->cookie;
}
function getAccessToken() {
return $this->cookie['access_token'];
}
function loadJsSDK($path_to_library='') {
echo '<script type="text/javascript">
//<![CDATA[ ';
?>
function logoutFacebookUser(){FB.logout(function(response){window.location.reload();});}
function fbActionConnect(){FB.login(function(response){if (response.session){window.location = "http://www.mysite.com/signin/fbconnect";if(response.perms){}else{}}else{}}, {perms:'publish_stream,email'});}
function fbAppActionConnect(){FB.login(function(response){if (response.session){window.location = "http://www.mysite.com/signin/fbappconnect";if(response.perms){}else{}}else{}}, {perms:'publish_stream,email'});}
function fbLinkActionConnect(){FB.login(function(response){if (response.session){window.location = "http://www.mysite.com/index.php?name=signin&file=MyServices&op=linkacc";if(response.perms){}else {}}else{}},{perms:'publish_stream,email'});}
function fbActionCartConnect(id, sport) {FB.login(function(response){if(response.session){window.location = "//index.php?name=signin&file=cart&id=" + id + "&sport=" + sport + "&op=fbsignup";if (response.perms){}else{}}else{}},{perms:'publish_stream,email'});}
window.fbAsyncInit = function() {FB.init({appId: xxxxxxxxxxxxxxxxx, channelUrl:'http://www.mysite.com/channel.html', status: true, cookie: true, xfbml: true});};(function() {var e = document.createElement('script'); e.async = true;e.src = document.location.protocol +'//connect.facebook.net/en_US/all.js';document.getElementById('fb-root').appendChild(e);}());//]]></script>
<?php
}
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
function get_redirect_url($url) {
$redirect_url = null;
$url_parts = #parse_url($url);
if (!$url_parts) return false;
if (!isset($url_parts['host'])) return false; //can't process relative URLs
if (!isset($url_parts['path'])) $url_parts['path'] = '/';
$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
if (!$sock) return false;
$request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";
$request .= 'Host: ' . $url_parts['host'] . "\r\n";
$request .= "Connection: Close\r\n\r\n";
fwrite($sock, $request);
$response = '';
while(!feof($sock)) $response .= fread($sock, 8192);
fclose($sock);
if (preg_match('/^Location: (.+?)$/m', $response, $matches)){
if ( substr($matches[1], 0, 1) == "/" )
return $url_parts['scheme'] . "://" . $url_parts['host'] . trim($matches[1]);
else
return trim($matches[1]);
} else {
return false;
}
}
function getFacebookFriends($criteria='') {
$name = $criteria['name'];
if($name=='') $name = 'me';
$url = 'https://graph.facebook.com/'.$name.'/friends?access_token='.$this->getAccessToken();
$content = #file_get_contents($url,0,null,null);
$content = json_decode($content,true);
$users = $this->formatFacebookUsers($content);
return $users;
}
function formatFacebookUsers($content) {
for($i=0; $i<count($content['data']); $i++) {
$id = $content['data'][$i]['id'];
$name = $content['data'][$i]['name'];
$picture = 'https://graph.facebook.com/'.$id.'/picture?type=square'; //square, small, large
$url = 'http://www.facebook.com/profile.php?id='.$id;
$users[$i]['id'] = $id;
$users[$i]['name'] = $name;
$users[$i]['picture'] = $picture;
$users[$i]['url'] = $url;
}
return $users;
}
function getFacebookAccounts() {
$url = 'https://graph.facebook.com/me/accounts?access_token='.$this->getAccessToken();
$content = #file_get_contents($url,0,null,null);
$content = json_decode($content,true);
return $content;
}
function displayUsersIcons($criteria) {
$users = $criteria['users'];
$nb_display = $criteria['nb_display'];
$width = $criteria['width'];
if($width=='') $width="30";
if($nb_display>count($users) || $nb_display=='') $nb_display=count($users); //display value never bigger than nb users
$display = '';
for($i=0;$i<$nb_display;$i++) {
$name = $users[$i]['name'];
$picture = $users[$i]['picture'];
$url = $users[$i]['url'];
$display .= '<a href="'.$url.'" target="_blank" title="'.$name.'">';
$display .= '<img src="'.$picture.'" width="'.$width.'" style="padding:2px;">';
$display .= '</a>';
}
return $display;
}
function getFacebookFeeds() {
$url = 'https://graph.facebook.com/me/posts?access_token='.$this->getAccessToken();
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
$data = json_decode($data,true);
$dataList = $this->formatFacebookPosts($data);
return $dataList;
}
function formatFacebookPosts($data) {
$i=0;
foreach($data['data'] as $value) {
$id = $value['id'];
$from_id = $value['from']['id'];
$from_name = $value['from']['name'];
$type = $value['type']; //video, link, status, picture, swf
$message = $value['message'];
$picture = $value['picture'];
$link = $value['link'];
$source = $value['source']; //for videos
$name = $value['name']; //for videos or links
$caption = $value['caption']; //for videos (domain name url) or links
$description = $value['description']; //for videos
$icon = $value['icon'];
$created = $value['created_time'];
$likes_nb = $value['likes'];
$comments = $value['comments']['data']; //(message, created_time)
$comments_nb = $value['comments']['count'];
$action_comment = $value['actions'][0]['link'];
$picture_url = 'https://graph.facebook.com/'.$from_id.'/picture';
$profile_url = 'http://www.facebook.com/profile.php?id='.$from_id;
$attribution = $value['attribution'];
if($type=='status') {
$dataList[$i]['id'] = $id;
$dataList[$i]['from_id'] = $from_id;
$dataList[$i]['from_name'] = $from_name;
$dataList[$i]['type'] = $type;
$dataList[$i]['message'] = $message;
$dataList[$i]['picture'] = $picture;
$dataList[$i]['link'] = $link;
$dataList[$i]['source'] = $source;
$dataList[$i]['name'] = $name;
$dataList[$i]['caption'] = $caption;
$dataList[$i]['description'] = $description;
$dataList[$i]['icon'] = $icon;
$dataList[$i]['created'] = $created;
$dataList[$i]['attribution'] = $attribution;
$dataList[$i]['likes_nb'] = $likes_nb;
$dataList[$i]['comments'] = $comments;
$dataList[$i]['comments_nb'] = $comments_nb;
$dataList[$i]['action_comment'] = $action_comment;
$dataList[$i]['picture_url'] = $picture_url;
$dataList[$i]['profile_url'] = $profile_url;
$i++;
}
}
return $dataList;
}
function updateFacebookStatus($status) {
$postParms = "access_token=".$this->getAccessToken()."&message=".$status;
$ch = curl_init('https://graph.facebook.com/me/feed');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParms);
$results = curl_exec($ch);
curl_close($ch);
}
function postmsg() {
$FILE_PATH = $_SERVER["DOCUMENT_ROOT"]."images/default/webedition1.jpg";
$token=$this->getAccessToken();
if (file_exists($FILE_PATH)) {
$args = array('message' => 'From the coaches locker');
$args['image'] = '#' . realpath($FILE_PATH);
$arr_attachment = array('image' => '#'.realpath($FILE_PATH),
'message' => 'Test caption'
);
$_curl = curl_init();
curl_setopt($_curl, CURLOPT_URL, "https://graph.facebook.com/me/photos?access_token=".$token);
curl_setopt($_curl, CURLOPT_HEADER, false);
curl_setopt($_curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($_curl, CURLOPT_POST, true);
curl_setopt($_curl, CURLOPT_POSTFIELDS, $arr_attachment);
curl_setopt($_curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($_curl, CURLOPT_SSL_VERIFYPEER, 0);
$_photo = curl_exec($_curl);
echo($_photo);
} else {
echo "cannot find file:".$FILE_PATH;
}
}
}
?>
Thanks.
Facebook introduced some breaking changes for OAuth2 authentication to the JavaScript SDK yesterday: http://developers.facebook.com/blog/post/614/
More details: http://developers.facebook.com/blog/post/525/
Basically some changes I've seen were:
FB.getSession() now changed to FB.getAuthResponse()
FB.init() now has the 'oath' value as always 'true'.
'perms' is now changed to 'scope' in the login button html
Possibly FB.Event.subscribe('auth.sessionChange'..) is now FB.Event.subscribe('auth.authResponseChange'..)
Hope that helps.