Here is the contents contained in that LastRSS PHP File: lastRSS.

  • Profile Image
    Asked on September 05, 2012 at 07:21 PM

    Here is the contents contained in that LastRSS PHP File:


    PHP script text




    lastRSS 0.9.1

    Simple yet powerfull PHP class to parse RSS files.

    by Vojtech Semecky, webmaster @ webdot . cz

    Latest version, features, manual and examples:



    This program is free software; you can redistribute it and/or

    modify it under the terms of the GNU General Public License (GPL)

    as published by the Free Software Foundation; either version 2

    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,

    but WITHOUT ANY WARRANTY; without even the implied warranty of


    GNU General Public License for more details.

    To read the license please visit




    * lastRSS

    * Simple yet powerfull PHP class to parse RSS files.


    class lastRSS {

    // -------------------------------------------------------------------

    // Public properties

    // -------------------------------------------------------------------

    var $default_cp = 'UTF-8';

    var $CDATA = 'nochange';

    var $cp = '';

    var $items_limit = 0;

    var $stripHTML = False;

    var $date_format = '';

    // -------------------------------------------------------------------

    // Private variables

    // -------------------------------------------------------------------

    var $channeltags = array ('title', 'link', 'description', 'language', 'copyright', 'managingEditor', 'webMaster', 'lastBuildDate', 'rating', 'docs');

    var $itemtags = array('title', 'link', 'description', 'author', 'category', 'comments', 'enclosure', 'guid', 'pubDate', 'source');

    var $imagetags = array('title', 'url', 'link', 'width', 'height');

    var $textinputtags = array('title', 'description', 'name', 'link');

    // -------------------------------------------------------------------

    // Parse RSS file and returns associative array.

    // -------------------------------------------------------------------

    function Get ($rss_url) {


    if ($this->cache_dir != '') {

    $cache_file = $this->cache_dir . '/rsscache_' . md5($rss_url);

    $timedif = @(time() - filemtime($cache_file));

    if ($timedif < $this->cache_time) {

    // cached file is fresh enough, return cached array

    $result = unserialize(join('', file($cache_file)));

    // set 'cached' to 1 only if cached file is correct

    if ($result) $result['cached'] = 1;

    } else {

    // cached file is too old, create new

    $result = $this->Parse($rss_url);

    $serialized = serialize($result);

    if ($f = @fopen($cache_file, 'w')) {

    fwrite ($f, $serialized, strlen($serialized));



    if ($result) $result['cached'] = 0;



    // If CACHE DISABLED >> load and parse the file directly

    else {

    $result = $this->Parse($rss_url);

    if ($result) $result['cached'] = 0;


    // return result

    return $result;


    // -------------------------------------------------------------------

    // Modification of preg_match(); return trimed field with index 1

    // from 'classic' preg_match() array output

    // -------------------------------------------------------------------

    function my_preg_match ($pattern, $subject) {

    // start regullar expression

    preg_match($pattern, $subject, $out);

    // if there is some result... process it and return it

    if(isset($out[1])) {

    // Process CDATA (if present)

    if ($this->CDATA == 'content') { // Get CDATA content (without CDATA tag)

    $out[1] = strtr($out[1], array(''=>'', ''=>''));

    } elseif ($this->CDATA == 'strip') { // Strip CDATA

    $out[1] = strtr($out[1], array(''=>'', ''=>''));


    // If code page is set convert character encoding to required

    if ($this->cp != '')

    //$out[1] = $this->MyConvertEncoding($this->rsscp, $this->cp, $out[1]);

    $out[1] = iconv($this->rsscp, $this->cp.'//TRANSLIT', $out[1]);

    // Return result

    return trim($out[1]);

    } else {

    // if there is NO result, return empty string

    return '';



    // -------------------------------------------------------------------

    // Replace HTML entities &something; by real characters

    // -------------------------------------------------------------------

    function unhtmlentities ($string) {

    // Get HTML entities table

    $trans_tbl = get_html_translation_table (HTML_ENTITIES, ENT_QUOTES);

    // Flip keys<==>values

    $trans_tbl = array_flip ($trans_tbl);

    // Add support for ' entity (missing in HTML_ENTITIES)

    $trans_tbl += array(''' => "'");

    // Replace entities by values

    return strtr ($string, $trans_tbl);


    // -------------------------------------------------------------------

    // Parse() is private method used by Get() to load and parse RSS file.

    // Don't use Parse() in your scripts - use Get($rss_file) instead.

    // -------------------------------------------------------------------

    function Parse ($rss_url) {

    // Open and load RSS file

    if ($f = @fopen($rss_url, 'r')) {

    $rss_content = '';

    while (!feof($f)) {

    $rss_content .= fgets($f, 4096);



    // Parse document encoding

    $result['encoding'] = $this->my_preg_match("'encoding=[\'\"](.*?)[\'\"]'si", $rss_content);

    // if document codepage is specified, use it

    if ($result['encoding'] != '')

    { $this->rsscp = $result['encoding']; } // This is used in my_preg_match()

    // otherwise use the default codepage


    { $this->rsscp = $this->default_cp; } // This is used in my_preg_match()

    // Parse CHANNEL info

    preg_match("'(.*?)'si", $rss_content, $out_channel);

    foreach($this->channeltags as $channeltag)


    $temp = $this->my_preg_match("'<$channeltag.*?>(.*?)$channeltag>'si", $out_channel[1]);

    if ($temp != '') $result[$channeltag] = $temp; // Set only if not empty


    // If date_format is specified and lastBuildDate is valid

    if ($this->date_format != '' && ($timestamp = strtotime($result['lastBuildDate'])) !==-1) {

    // convert lastBuildDate to specified date format

    $result['lastBuildDate'] = date($this->date_format, $timestamp);


    // Parse TEXTINPUT info

    preg_match("']*[^/])>(.*?)'si", $rss_content, $out_textinfo);

    // This a little strange regexp means:

    // Look for tag with or without any attributes, but skip truncated version (it's not beggining tag)

    if (isset($out_textinfo[2])) {

    foreach($this->textinputtags as $textinputtag) {

    $temp = $this->my_preg_match("'<$textinputtag.*?>(.*?)$textinputtag>'si", $out_textinfo[2]);

    if ($temp != '') $result['textinput_'.$textinputtag] = $temp; // Set only if not empty



    // Parse IMAGE info

    preg_match("'(.*?)'si", $rss_content, $out_imageinfo);

    if (isset($out_imageinfo[1])) {

    foreach($this->imagetags as $imagetag) {

    $temp = $this->my_preg_match("'<$imagetag.*?>(.*?)$imagetag>'si", $out_imageinfo[1]);

    if ($temp != '') $result['image_'.$imagetag] = $temp; // Set only if not empty



    // Parse ITEMS

    preg_match_all("'(.*?)'si", $rss_content, $items);

    $rss_items = $items[2];

    $i = 0;

    $result['items'] = array(); // create array even if there are no items

    foreach($rss_items as $rss_item) {

    // If number of items is lower then limit: Parse one item

    if ($i < $this->items_limit || $this->items_limit == 0) {

    foreach($this->itemtags as $itemtag) {

    $temp = $this->my_preg_match("'<$itemtag.*?>(.*?)$itemtag>'si", $rss_item);

    if ($temp != '') $result['items'][$i][$itemtag] = $temp; // Set only if not empty


    // Strip HTML tags and other bullshit from DESCRIPTION

    if ($this->stripHTML && $result['items'][$i]['description'])

    $result['items'][$i]['description'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['description'])));

    // Strip HTML tags and other bullshit from TITLE

    if ($this->stripHTML && $result['items'][$i]['title'])

    $result['items'][$i]['title'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['title'])));

    // If date_format is specified and pubDate is valid

    if ($this->date_format != '' && ($timestamp = strtotime($result['items'][$i]['pubDate'])) !==-1) {

    // convert pubDate to specified date format

    $result['items'][$i]['pubDate'] = date($this->date_format, $timestamp);


    // Item counter




    $result['items_count'] = $i;

    return $result;


    else // Error in opening return False


    return False;





    This is a re-post of a comment on Create a Submission Limit Using JotForm with PHP and RSS Reports

  • Profile Image
    Answered on September 05, 2012 at 07:41 PM

    I've uploaded this to my server / host (BlueHost)  I opened the file and added the code as per JotForm recommendations.  I added the form's code given for embed (didn't work) then I tried the source code which didn't work either.  

    I suspect I am missing something(s)




  • Profile Image
    Answered on September 05, 2012 at 10:41 PM

    Hello Jay,

    I noticed a number of threads due to the comments you have posted on the user guide.  Let's tackle it on this thread alone.

    1st, can you share with us which form is it that you're working on?

  • Profile Image
    Answered on September 05, 2012 at 10:49 PM

    I have a few payments forms that will require the submission limitations to work using this PHP file but I just got word that the submissions limit option has been enabled again so that might solve the issue...or will it? 

    I am wanting to limit submissions for certain purchase forms because we will only have a limited quantity.  Will the limit submissions option work for that? The problem we were seeing before was that when someone filled out a form and hit submit and got redirected to the paypal page, it still counted as a submission.  This was using the method of creating a unique ID and and conditions.



    When Unique ID field hits 020, hide submit button and show 'sold out' image.

    Does this use a different format and will a submission only count as a submission once payment has been a successfully completed?  or will this still count 'incomeplete submissions' as being submissions?


  • Profile Image
    Answered on September 05, 2012 at 10:50 PM

    Here is the form:

  • Profile Image
    Answered on September 05, 2012 at 11:41 PM

    It's only very recent also that I heard about the reactivation of the submissions limit in the form builder's preferences.  Yes, this will answer to your concern to disable the form when it reaches a certain number of submissions.  Although I tested it and found that it's not yet fully functional.  We'll update you on this feature.

    If you wish to use the RSS report; what the submission limits using the RSS does is that it counts the total number of submissions it shows in the RSS, so this will not be dependent on the unique ID.

    Assuming that you have already created your RSS report and uploaded the lastRSS.php file to your website, what you need to do next is create a PHP file where you will put your form's source code. 

    This is what contents of the PHP file should look like:


    include "Your directory to the file/lastRSS.php";

    // Create lastRSS object
    $rss = new lastRSS;

    // Set your preferred submission limit here
    $limit_num = "20";

    // Set cache dir and cache time limit (1200 seconds)
    // (don't forget to chmod cahce dir to 777 to allow writing)
    $rss->cache_dir = '';
    $rss->cache_time = 0;
    $rss->cp = 'US-ASCII';
    $rss->date_format = 'l';

    // Try to load and parse RSS file
    $rssurl = '';

    if ($rs = $rss->get($rssurl)) {

        if($rs[items_count] >= "$limit_num")
             echo "You can no longer submit an entry";
         } else {


             (your form's source here)


    else {
        echo "Error: It's not possible to get $rssurl...";


    Notice the underlined ones.  These are the values that you will be editing, depending on your preference.

    Let's stop here for now for you to catch up (If in case you wish to use this feature instead)

  • Profile Image
    Answered on September 06, 2012 at 01:57 AM

    Thanks Liyam.  If the set submissions options in the advanced options on the form builder gets working properly that would be preferable but this will have to do in the interim.  


    I am not quite sure what you're meaning by uploading the lastRSS.php file to my website.  What do you mean upload it to my website?  I have uploaded it to BlueHost which is where I host everything.  Is that what you mean? 

  • Profile Image
    Answered on September 06, 2012 at 02:06 AM

    Hello jaycw7.  What I mean by uploading it to your website is that you should have a hosting service that can be viewed via http on the web. It is necessary to have at least a web hosting account where you can upload your files.

    So for example, I have a web hosting account somewhere and I also have assigned to it the domain name, then if I uploaded the file test.html, I can visit and view the page test.html to

    Regarding your BlueHost.  May we know the domain name of the website that you have in BlueHost?

  • Profile Image
    Answered on September 06, 2012 at 02:30 AM

    Thanks Liyam.

    I host everything on BlueHost and I did upload that php file.  I am just not understanding what I do from there.  The php file has all that code above...I'm just not sure what I do from there.  Let's just leave it and I will have one of my web developers work on us all the headache.