You are here:  » Blog functionality?


Blog functionality?

Submitted by frychiko on Sat, 2008-05-24 08:54 in

Has anyone integrated a wordpress or drupal CMS with pricetapestry?

Is there someway to add blog functionality without writing one myself...

cheers,
Peter

Submitted by support on Sun, 2008-05-25 08:23

Hello Peter,

My recommendation when it comes to this sort of thing is not to try and integrate them too tightly. Rather, what I suggest is using one package as your main top level site (either a blog or Price Tapestry); and then install the other into a sub-directory.

For example, if you have a Price Tapestry installation and want to add Blog functionality to your site; consider installing something like Wordpress into a sub-directory.

Then you can do 2 things:

1) Bring elements from the software installed in a sub-directory into the top level home page. For example, all Blog scripts generate an RSS feed, which can then be used easily to add headlines and snippets to your Price Tapestry home-page; perhaps even using MagicParser.php which is included as part of the Price Tapestry script - you can see demo source code on this page:

http://www.magicparser.com/node/26

2) Make both scripts look the same using their template / other methods of managing the HTML.

Cheers,
David.

Submitted by mally on Sun, 2008-05-25 16:55

Hello David

I tried adding the following code into my products.php howevet got errors.

Any advice?

Cheers

Mally

<?php
  header("Content-Type: text/html;charset=utf-8");
  require("MagicParser.php");
  function myRecordHandler($item)
  {
    print "<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print "<p>".$item["DESCRIPTION"]."</p>";
  }
  print "<h1>BBC News Headlines</h1>";
  $url = "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
  MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

Errors below

Warning: require(/includes/MagicParser.php) [function.require]: failed to open stream: No such file or directory in /home/maggyorg/public_html/html/product.php on line 24
Fatal error: require() [function.require]: Failed opening required '/includes/MagicParser.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/maggyorg/public_html/html/product.php on line 24

Submitted by support on Mon, 2008-05-26 07:23

Hi Mally,

I'm slightly confused by the error message as it refers to "includes/MagicParser.php" (which is the correct path); rather than just "MagicParser.php" on it's own, which is what I would expect to have generated the "file not found" error.

I would make sure that you are using the following code:

<?php
  
require("includes/MagicParser.php");
  function 
myRecordHandler($item)
  {
    print 
"<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
  }
  print 
"<h1>BBC News Headlines</h1>";
  
$url "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

Note that I have also removed the first line that sets the content-type header as this will cause errors at this point in the code as headers will have already been sent to the browser...

Cheers,
David.

Submitted by mally on Mon, 2008-05-26 07:37

Hello David,

The above code works, must have been the original code calling the headers twice.

Thanks again

Cheers

Mally

Submitted by bloach on Sun, 2008-06-15 03:23

Hi David,

This is a great piece of code to ensure that your pages remain fresh in Google Index and search engines have the incentive to come back to re-index your pages on a frequent basis.

Two Questions:

1) How can we limit the number of number of XML items e.g. I would like to show 1 or 2 items only.

2) How can we format it so that it has a fixed width in the side bar in case of long titles.

Thanks and really appreciate your help.

_____________________________________________________
My Australian Shopping Comparison Site

Australian Shopping Comparison

Submitted by support on Sun, 2008-06-15 08:14

Hi,

To limit the results to 2 items, change the myRecordHandler function as shown below. This uses the fact that Magic Parser will stop if the function returns TRUE.

  function myRecordHandler($item)
  {
    global $numItems;
    print "<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print "<p>".$item["DESCRIPTION"]."</p>";
    $numItems++;
    return ($numItems == 2);
  }

To fix the size of your side-bar, the easiest thing to do is probably to use the max-width CSS property. If you have used a table for your layout; modify the <td> tag for example:

<td style='max-width:200px;'>

I'm not a CSS expert, but that _should_ work...!

Cheers,
David.

Submitted by Rocket32 on Fri, 2009-03-13 02:59

What code can I use to display a coupon RSS Feed with about 10 items, and I would like a limit of 6 random items from the same coupon feed every time the page reloads?

Submitted by support on Fri, 2009-03-13 11:10

Hi Richard,

6 random items from an RSS feed would work something like this....

<?php
  
require("includes/MagicParser.php");
  
$items = array();
  function 
myRecordHandler($item)
  {
    global 
$items;
    
$items[] = $item;
  }
  
$url "http://www.example.com/coupons.rss";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
shuffle($items); // randomise the $items array
  
$i 0;
  foreach(
$items as $item)
  {
    print 
"<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    
$i++;
    if (
$i==6) break; // change for different number of random items
  
}
?>

Change the value of $url of course to the URL of your coupon feed and that should get you close!

Cheers,
David.

Submitted by Rocket32 on Sat, 2009-03-14 13:46

Is it possible to get a rss feed from shareasale deals database at http://www.shareasale.com/dealdatabase2.xml? You can pull up this in a dealsdatabase folder on the shareasale affiliate ftp account. Is it possible to keep this feed updated with only deals from certain merchants, let's say keep merchant id's 2034,3214,34565 and 3456 and strip the rest? Also within the xml deals database on the ftp site, YOURUSERID would have to be changed to your affiliate id xxxxxx. I am trying to make a coupon page with lets say dog coupons from dog merchants. I think it need to login to the ftp account to download the database, but keeeping it updated daily is the question?

Submitted by support on Sat, 2009-03-14 22:34

Hi Richard,

If the coupon feed contains multiple merchants (and this is not configurable) it should be straight forward to modify the code above so that only coupons from the desired merchants are shown. Could you perhaps zip and email me an example of the coupon feed to have a look at and I'll what could be done?

With regards to keeping it up to date, the above code can reference a local file - so if you regularly (just like you do with the normal product feeds) upload the coupon file to your /feeds/ directory, then inplace of:

  $url = "http://www.example.com/coupons.rss";

...just use:

  $url = "feeds/coupons.rss";

Cheers,
David.

Submitted by Rocket32 on Sun, 2009-04-19 18:26

Is it possible to parse more than 1 rss feed on the same page from different rss links? I am using rss feeds from different merchants wihtin different networks. I cannot seem to get it to parse correctly on the same coupon page. I am using the following code several times after each other on the same page, but changing the url link to the rss feed. It comes back as error. I'm thinking I may need to loop the different feed on onto one page some how where they are separated by a horizontal rule.

<?php
  
require("includes/MagicParser.php");
  
$items = array();
  function 
myRecordHandler($item)
  {
    global 
$items;
    
$items[] = $item;
  }
  
$url "http://www.rsslink.com/feed.rss";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
shuffle($items); // randomise the $items array
  
$i 0;
  foreach(
$items as $item)
  {
    print 
"<h2><a target='_BLANK' href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    
$i++;
    if (
$i==6) break; // change for different number of random items
  
}
?>

Submitted by support on Mon, 2009-04-20 07:14

Hi,

The errors are almost certainly because of the duplication of the call to include MagicParser.php and the myRecordHandler function.

What you would need to do is separate out those parts into a single script, and then have your code to parse each of the individual files in their own files. In other words, this part must only occur once:

<?php
  
require("includes/MagicParser.php");
  function 
myRecordHandler($item)
  {
    global 
$items;
    
$items[] = $item;
  }
?>

...and then this part can repeat with different $url values...

<?php
  $items 
= array();
  
$url "http://www.rsslink.com/feed.rss";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
shuffle($items); // randomise the $items array
  
$i 0;
  foreach(
$items as $item)
  {
    print 
"<h2><a target='_BLANK' href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    
$i++;
    if (
$i==6) break; // change for different number of random items
  
}
?>

Alternatively of course, you could always have just one file containing all the code.

Cheers,
David.

Submitted by Rocket32 on Sun, 2009-08-23 15:40

How do I fix a feed that has messed up characters in the Title or a name within the title. I tried to do a search and replace, but it does not work. I used the following code;

<?php
  $items 
= array();
  
$url "http://www.rsslink.com/feed.rss";
  
$items str_replace('é','',$items);
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
shuffle($items); // randomise the $items array
  
$i 0;
  foreach(
$items as $item)
  {
    print 
"<h2><a target='_BLANK' href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    
$i++;
    if (
$i==6) break; // change for different number of random items
  
}
?>

What can I modify to delete 'é' from within the title of my rss feeds?

Submitted by support on Mon, 2009-08-24 08:31

Hi,

When output such as "é" is displayed that normally means that the output of the PHP is script is not in the same character set as the data. It is normally easily fixed by adding the appropriate content-type header to your script. First try utf-8 by adding the following code at the very top of the script (immediately after the opening PHP tag):

  header("Content-Type: text/html; charset=utf-8");

If that doesn't make any difference, try iso-8859-1 in place of utf-8 and that should do the trick!

Cheers,
David.

Submitted by Rocket32 on Tue, 2009-11-10 02:14

Hello. For some reason I cannot get the following feed to display onsite:

{link saved}

When entered into the url to parse. It shows up blank on site with no feed, but it does show an xml page when displayed with the browser. Any suggestions on getting Magic Parser to Parse this url.

Submitted by support on Tue, 2009-11-10 09:48

Hi,

It has parsed OK for me using the Format String:

xml|COUPONFEED/LINK/

Could you perhaps have a go with this test script:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    
print_r($record);
  }
  
$url "{link saved}";
  
MagicParser_parse($url,"myRecordHandler","xml|COUPONFEED/LINK/");
?>

Cheers,
David.

Submitted by Rocket32 on Thu, 2009-11-26 14:58

I tried the test script on a different hosting and it worked, but for some reason I get a blank page on the hosting that I preferred to use this script.

Any ideas.

Submitted by support on Thu, 2009-11-26 15:09

Hi,

This would imply that the server on which it is not working does not have URL Wrappers enabled - in other words PHP is unable to open a URL using fopen(). However, it is becoming more common for CURL to be installed, which can be used as an alternative method for retrieving remote URLs. To give it a go, in place of:

  $url = "{link saved}";
  MagicParser_parse($url,"myRecordHandler","xml|COUPONFEED/LINK/");

...try using:

  $url = "{link saved}";
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0 );
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $xml = curl_exec ( $ch );
  MagicParser_parse("string://".$xml,"myRecordHandler","xml|COUPONFEED/LINK/");

Hope this helps!

Cheers,
David.

Submitted by Rocket32 on Thu, 2009-11-26 17:59

Worked perfect. Thanks a bunch. Needed that.

Submitted by Rocket32 on Fri, 2013-08-23 02:53

Hello David, Is there a way to take a RSS feed's link that has 100s of titles & descriptions & put its results into a page breadcrumb format with pricetapestry from a coupon.php file in the pt directory or a /coupon folder in pt directory that still uses the magic parser. I am trying to use a feed the has a few 100 title & descriptions that I would like to be split into pages with maybe 20 of them per page.

I am using the following code.

<?php
  $items 
= array();
  
$url "http://www.rsslink.com/feed.rss";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
shuffle($items); // randomise the $items array
  
$i 0;
  foreach(
$items as $item)
  {
    print 
"<h2><a target='_BLANK' href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    
$i++;
    if (
$i==6) break; // change for different number of random items
  
}
?>

Submitted by Rocket32 on Sat, 2013-11-16 16:02

How do I get the code below to have navigation of page numbers for that feed, instead of just next page? Bread crumb style. I am trying to see if a rewrite rule is needed, or it should be manual depending on the number of pages. I like the navigation in the html folder, but I think this would need something different because it does not use the search.php (q).

It is a on a custom page on the PT Site.

<?php
   
require("includes/MagicParser.php");
   
$page $_GET["page"];
  if (!
$page$page 1;
  
$items_per_page 15;
  function 
myRecordHandler($item)
  {
    global 
$page;
    global 
$items_per_page;
    global 
$counter;
    
$counter++;
    if (
$counter <= (($page-1)*$items_per_page)) return false;
     print 
"<h2><a target='_BLANK' href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    return (
$counter == ($page*$items_per_page));
  }
  print 
"<h1>Coupon Feed</h1>";
  
$items = array();
  
$url "http://feedslink.com";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
shuffle($items);
  print 
"<h2><a href='?page=".($page+1)."'>Next Page</a></h2>";
?>

Submitted by support on Sun, 2013-11-17 10:16

Hi Rocket32,

html/navigation.php requires the $navigation["resultCount"] to be populated, so to avoid parsing the file twice, consider the example below which makes a single parse of the feed into a global $items array. This can be used to set $navigation["resultCount"] with count(), and then a second foreach loop calling your original myRecordHandler function (renamed to myDisplayRecordHandler) to display the items.

Because html/navigation.php uses the global $config_resultsPerPage, i've renamed $items_per_page to this in the example...

(don't forget to replace {link saved} with your coupons feed URL!)

<?php
  
require("includes/MagicParser.php");
  
$page $_GET["page"];
  if (!
$page$page 1;
  
$count 0;
  
$config_resultsPerPage 15;
  function 
myDisplayRecordHandler($item)
  {
    global 
$page;
    global 
$config_resultsPerPage;
    global 
$counter;
    
$counter++;
    if (
$counter <= (($page-1)*$config_resultsPerPage)) return false;
    print 
"<h2><a target='_BLANK' href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    return (
$counter == ($page*$config_resultsPerPage));
  }
  print 
"<h1>Coupon Feed</h1>";
  
$items = array();
  function 
myRecordHandler($item)
  {
    global 
$items;
    
$items[] = $item;
  }
  
$url "{link saved}";
  
MagicParser_parse("string://".$xml,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
$navigation["resultCount"] = count($items);
  foreach(
$items as $item)
  {
    if (
myDisplayRecordHandler($item)) break;
  }
  require(
"html/navigation.php");
?>

Let me know when the above is up and running which will get the core navigation functionality working, and then I'll describe a couple more changes to implement caching (to avoid having to fetch the remote URL every page view) and using rewrite to clean the URLs...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Tue, 2013-11-19 05:44

I replaced the code, but now the feeds are not showing. Just title showing with no feeds.

Submitted by support on Tue, 2013-11-19 11:30

Hi Rocket32,

I'd missed out the line to fetch the URL - apologies for that, please try the below (don't forget to replace {link saved} with your source URL) which I've modified slightly to include translate.php (required by html/navigation.php) and also set the variables that html/navigation.php is expecting to avoid unset warnings if configured to be displayed on your server...

<?php
  
require("includes/MagicParser.php");
  require(
"includes/translate.php");
  
$page = (isset($_GET["page"])?intval($_GET["page"]):"1");
  
$count 0;
  
$config_resultsPerPage 5;
  function 
myDisplayRecordHandler($item)
  {
    global 
$page;
    global 
$config_resultsPerPage;
    global 
$counter;
    
$counter++;
    if (
$counter <= (($page-1)*$config_resultsPerPage)) return false;
    print 
"<h2><a target='_BLANK' href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    return (
$counter == ($page*$config_resultsPerPage));
  }
  print 
"<h1>Coupon Feed</h1>";
  
$items = array();
  function 
myRecordHandler($item)
  {
    global 
$items;
    
$items[] = $item;
  }
  
$url "{link saved}";
  
$xml file_get_contents($url);
  
MagicParser_parse("string://".$xml,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
$navigation["resultCount"] = count($items);
  foreach(
$items as $item)
  {
    if (
myDisplayRecordHandler($item)) break;
  }
  
$rewrite FALSE;$q "";$sort="";
  require(
"html/navigation.php");
?>

f you wanted to contain the output within your standard Price Tapestry template files, then where you have the following code in the above example:

  require("includes/translate.php");

...REPLACE with:

  require("includes/common.php");
  $header["title"] = "Coupon Feed";
  $header["meta"]["description"] = "Meta description here if required";
  $header["meta"]["keywords"] = "meta, keywords, here";
  require("html/header.php");

...and at the end of the script:

  require("html/footer.php");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Wed, 2013-11-20 03:59

Thanks David. It works perfect. Would you recommend sorting of items on page numbers after feed is counted? If its possible, how is it accomplished with the above script?

Submitted by support on Wed, 2013-11-20 08:53

Hi,

PHP's usort() function can be used to sort the $items array however you like. For example, if there is a DISCOUNT field in each record of your feed and you wanted to sort by that, then where you have this line:

  foreach($items as $item)

...REPLACE with:

  function cmp($a,$b)
  {
    if ($a["DISCOUNT"] == $b["DISCOUNT"]) return 0;
    return ($a["DISCOUNT"] < $b["DISCOUNT"]) ? -1 : 1;
  }
  usort($items,"cmp");
  foreach($items as $item)

To see all fields available in each item record; temporarily add the following code to your myRecordHandler function;

  print "<pre>";
  print_r($item);
  print "</pre>";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by philstone on Wed, 2015-12-09 15:46

Hi David

I am using this code to show the last few blog enteries, however I would like show specific categories of feeds under different sub folders, so display the general category and that installation category

eg

toys would show posts from :
$url = "https://www.example.com/blog/category/news/feed/"; &
$url = "https://www.example.com/blog/category/toys/feed/"; &

would this be possible to add to this code?

<?php
  
require("includes/MagicParser.php");
  
$items = array();
  function 
myRecordHandler($item)
  {
    global 
$items;
    
$items[] = $item;
  }
  
$url "https://www.example.com/blog/feed/";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
shuffle($items); // randomise the $items array
  
$i 0;
  foreach(
$items as $item)
  {
    print 
"<h2><a target='_BLANK' href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    
$i++;
    if (
$i==6) break; // change for different number of random items
  
}
?>

Submitted by support on Wed, 2015-12-09 16:05

Hi Phil,

The tidiest way would be to loop over an array of urls to parse (as long as they are the same format) into a single $items array - for example;

<?php
  
require("includes/MagicParser.php");
  
$items = array();
  function 
myRecordHandler($item)
  {
    global 
$items;
    
$items[] = $item;
  }
  
$urls = array();
  
$urls[] = "https://www.example.com/blog/category/news/feed/";
  
$urls[] = "https://www.example.com/blog/category/toys/feed/";
  foreach(
$urls as $url)
  {
    
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  }
  
shuffle($items); // randomise the $items array
  
$i 0;
  foreach(
$items as $item)
  {
    print 
"<h2><a target='_BLANK' href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    
$i++;
    if (
$i==6) break; // change for different number of random items
  
}
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com