Jump to content

Trying to display RSS feeds in Client Area, without success...


-M-

Recommended Posts

We normally use MagicParser on our website to display useful RSS feeds from everywhere. We collected several feeds and they are formed together with MagicParser.

 

However I haven't have the faintest clue on how to add it to the Client Area. Since it's not allowed to include PHP files in there.

 

Below is the full code we use to display it on our main website, which works, but now I want to display it also in the Client Area (on the home page). I tried several things, but for some reason I seem to fail every single time. I now have changed so much, that I am going to revert to my backup prior to this. It's giving me a headache, especially since it should be this hard, I guess, but I don't have PHP skills or similar... :|

 

	require("../includes/MagicParser.php");
function cacheFetch($url,$age){
	$cacheDir = "../includes/cache/";
	$filename = $cacheDir.md5($url);
	return $filename;
}
function tidy_substr($text,$length,$append=""){
	if (strlen($text) > $length){
	  $breakOffset = $length;
	  if ($breakOffset !== false){
		$text = substr($text,0,$breakOffset).$append;
	  }
	}
	return $text;
}
   global $page;
   global $itemsPerPage;
   global $counter;
   $page = (isset($_GET["page"])?intval($_GET["page"]):1);
   $itemsPerPage = 33;
   $counter = 0;

				$items = array();
				function rssburo($item) {
				global $items;
				global $page;
				global $itemsPerPage;
				global $counter;
				$counter++;

				if ($counter < (($page-1)*$itemsPerPage)) return FALSE;
					$items[] = $item;
					return ($counter == ($page * $itemsPerPage));
				}

				if ($filename = cacheFetch("https://urlwithfeeds/index.php?/News/Feed",3600)) {
					MagicParser_parse($filename,"rssburo","xml|RSS/CHANNEL/ITEM/");

				if ($counter==0)  {
					echo "<li>Op dit moment is er een technische storing. Probeer het later nogmaals.</li>";
					echo "";
				  }
				}

				if ($counter) {
				  $featuredTitle = (isset($_GET["title"])?$_GET["title"]:"");

				  // if no title passed, make first item featured
				  if (!$featuredTitle) $featuredTitle = $items[0]["TITLE"];

				  // display featured item
				  foreach($items as $item) {
					if ($item["TITLE"] <> $featuredTitle) continue;

					$time = $item["PUBDATE"];
					$time = strtotime($time);
					$time = strftime('%e %B %Y om %H:%M',$time);

					$notime = $item["PUBDATE"];
					$notime = strtotime($notime);
					$notime = strftime('%e %B %Y',$notime);
					$content = $item["CONTENT:ENCODED"];

					print "<title>".tidy_substr($item["TITLE"],92,"...")."</title>";
					print "<meta name='description' content='RSS nieuwsmelding: ".$item["TITLE"]."' />";
					print "<div class='panel panel-default'>";
					print "<div class='panel-heading'>";
					print "<h5 class='panel-title smallpaneltxt'><a href='".$item["LINK"]."'>".tidy_substr($item["TITLE"],200,"...")."</a></h5> <span class='float:right;padding-left:10px;'>".$time."</span>";
					print "</div>";
					print "<div class='panel-body nwscontentlinks'>";
					print "<img class='floatr10' src='images/logo-rss-nieuws.png' alt='rss en meldingen'>";
					print "".$content."";
					print "<hr>";
					print "RSS Feeds";
					print "</div>";
					print "</div>";

					break;
				  }


				  // display other items

				  print "<div class='panel panel-default'>";
				  print "<div class='panel-heading'>";
				  print "<h5 class='panel-title smallpaneltxt'>Eerdere nieuwsberichten en meldingen</h5>";
				  print "</div>";
				  print "<div class='panel-body'>";

				  foreach($items as $item) {
					if ($item["TITLE"] == $featuredTitle) continue;
					//print "<h5>".$notime." <a class='fw400i' href='?page=".$page."&title=".urlencode($item["TITLE"])."'>".tidy_substr($item["TITLE"],108,"...")."</a></h5>";
					print "<div class='fnieuws'><a href='?page=".$page."&title=".urlencode($item["TITLE"])."'>".tidy_substr($item["TITLE"],133,"...")."</a></div>";
				  }

				  print "</div>";
				  print "</div>";

				  if ($counter == ($page * $itemsPerPage)) {
					print " <a class='btn btn-primary' role='button' href='?page=".($page+1)."'><< oudere meldingen</a>";
				  }
				  if ($page > 1) {
					//print " <a href='?page=".($page-1)."'>Recenter nieuws</a> ";
					print "<a class='btn btn-primary fnieuwsbutton' role='button' href='?page=".($page-1)."'>nieuwere meldingen >></a>";
				  }
				}

 

I can change the CSS and HTML stuff, but I will do that after I know how to add this. Maybe I can fetch this page through some magic variables or similar? But I don't know how. I already looked at the docs, but still, it's all acadabra for me. :(

 

If it's too much to ask, which I can fully understand, an example of how to make this work would also be appreciated...

 

Thank you in advance.

 

Regards

Link to comment
Share on other sites

We normally use MagicParser on our website to display useful RSS feeds from everywhere. We collected several feeds and they are formed together with MagicParser.

 

However I haven't have the faintest clue on how to add it to the Client Area. Since it's not allowed to include PHP files in there.

well you still can include php in the templates - not long-term, but certainly in the short-term.

 

if I paste your above code into the top of homepage.tpl, wrap it in {php}{/php} tags, it generates two errors (but the second is caused by the first) - the first is the require path as I don't have magicparser installed.

 

I think if you got that path correct to that magicparser.php file (plus the cache link?), the above should work - certainly if I remove the require link, and the second issue, it outputs a Dutch message to homepage.tpl with no PHP errors.

 

xCQeejy.png

 

just remember to enable "Smarty PHP Tags" in setup -> general settings -> security

Link to comment
Share on other sites

Hi brian (are you always online or something? :P)

 

Yeah, I did enable the smart php thingie. But it says it isn't recommended though, but that's for something later. If I can run it on my main website without issues, it should be safe enough to run it elsewhere also I guess...

 

Anyways, I just tried it (this time I also enabled php errors and debugging) also in homepage.tpl. Though I get the html/css stuff (including the buttons older/newer), but that's it. I don't get any feeds at all.

 

I just re-checked it again and also checked the html source. The only thing it's showing is:

 

<div class='panel panel-default'><div class='panel-heading'><h5 class='panel-title smallpaneltxt'>Eerdere nieuwsberichten en meldingen</h5></div><div class='panel-body'></div></div> <a class='btn btn-primary' role='button' href='?page=2'><< oudere meldingen</a>

 

That's all. No feeds whatsoever. And the feeds are working 100% sure, cause they are working on our main test page anyways.

 

I think I will look at it again tomorrow or after the weekend. Getting a bit tired now of fooling around with this.

 

My first idea was, to add this is in a panel, on the home page of the client area, but I cannot even get this to work, even when I put it in homepage.tpl.

Link to comment
Share on other sites

Hi brian (are you always online or something? :P)

it just seems like it! - actually, i've been here far less than normal today! :)

 

Yeah, I did enable the smart php thingie. But it says it isn't recommended though, but that's for something later. If I can run it on my main website without issues, it should be safe enough to run it elsewhere also I guess...

the biggest reason not to use it is because it will eventually be removed from WHMCS as a feature.. personally, I wouldn't overly worry about it from a security point of view.

 

Anyways, I just tried it (this time I also enabled php errors and debugging) also in homepage.tpl. Though I get the html/css stuff (including the buttons older/newer), but that's it. I don't get any feeds at all.

difficult to help with this one, as MagicParser isn't free and I don't know your feeds!

 

My first idea was, to add this is in a panel, on the home page of the client area, but I cannot even get this to work, even when I put it in homepage.tpl.

in some ways, that might be slightly easier - as the panels are written in php, so there would be no issues from that respect.

Edited by brian!
Link to comment
Share on other sites

it just seems like it! - actually, i've been here far less than normal today! :)

 

You stopped doing housework and watching tennis? :P

 

the biggest reason not to use it is because it will eventually be removed from WHMCS as a feature.. personally, I wouldn't overly worry about it from a security point of view.

 

A different, more difficult way, would be to use a hook to display the feeds and use the script, right?

Are there any different examples of running codes and scripts through those hooks, other than the two on WHMCS docs? Any good resource place to educate myself a bit? My PHP are pretty bad (it stops after echo "Hello World" :P), but when I see examples, I most of the time can get things to work.

 

difficult to help with this one, as MagicParser isn't free and I don't know your feeds!

 

Yeah, fully understand. No worries.

 

in some ways, that might be slightly easier - as the panels are written in php, so there would be no issues from that respect.

 

I thought this would be easier, like in copy and paste. If I can get this to work, I (eventually) would figure out how to place it in the panels. Or maybe easier; just use the CSS code of the panels and wrap the PHP in there on homepage.tpl.

Link to comment
Share on other sites

Minor update.

 

Well instead of using my customised version of the RSS output by Machform, I used their example code (which you can test on their website of MagicParser) and copied that into homepage.tpl.

 

And guess what. It displayed RSS feeds. Not how I want it to be displayed, but at least I made some progress. :)

 

Now I am gonna cut and paste partially and see where it stops.

 

After that, I am going to try to get it inside a panel. But doubt I will be succesful with that :P

 

//edit

 

Oh here is the basic/stripped version for outputting the RSS, as you can see it differs a lot from the one I orginally used (which actually does work on the main website though):

 

{php}
 require("../includes/MagicParser.php");
 function myRecordHandler($record)
 {
   // This is where you write your code to process each record, such as loading a database
   // You can display the record contents using PHP's internal print_r() function:
   print_r($record);
   // The following code will print out each field in your sample data:
   print $record["ITEM"];
   print $record["TITLE"];
   print $record["LINK"];
   print $record["GUID"];
   print $record["GUID-ISPERMALINK"];
   print $record["PUBDATE"];
   print $record["DC:CREATOR"];
   print $record["DESCRIPTION"];
   print $record["CONTENT:ENCODED"];
 }

 MagicParser_parse("https://sitewithrssfeeds.com/rss/index.php?/News/Feed","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
{/php}

Link to comment
Share on other sites

After that, I am going to try to get it inside a panel. But doubt I will be successful with that :P

this morning, I took a look at adding RSS feeds into homepage panels - turns out to be relatively straightforward... but these hooks always are after you figure them out! :roll:

 

here's an image from my v6 dev site - contains two new RSS feed panels... the red panel is coded to only show the top story, the blue one shows the top 5 stories (with each story linked appropriately).

 

lbwxSK8.png

 

 

the above example is using a BBC News feed - but it works equally well with Sky, Reuters, CNN, Fox or even using the WHMCS Announcements RSS link. :idea:

 

I should also add that it doesn't use any secondary files or parser (so no MagicParser or equivalent required) - it's entirely self-contained - in fact, the whole hook is currently only about 30 lines long... and over half of that is for the panel creation! :)

 

the next step will be to decide whether to work it up into an addon and release it, or just post the hook code... but that'll be a decision for next week.

Link to comment
Share on other sites

Wow... Looking awesome brian!

 

Mine looks less nice, but I think I do know what was going wrong now. I think there is an issue with cache function and/or some html/php tags not working as they should.

 

Still I would love to see how you setup your hook code, because, to my limited understanding, it's possible to run PHP from the hook without issues in comparism to running PHP ({php}{/php}) from with templates, right?

Link to comment
Share on other sites

to my limited understanding, it's possible to run PHP from the hook without issues in comparison to running PHP ({php}{/php}) from with templates, right?

yeah - the hook themselves are just PHP, so adding a little more PHP to them isn't a major issue - it should be easier than adding {php} to the templates!

 

Any news on this Brian? :)

not really, i've been having internet connections issues for a week - there have been times when I couldn't even browse the web - let alone do anything more than that!

Link to comment
Share on other sites

  • 5 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated