Recent Topics

1 Feb 08, 2005 23:04    

Some of you may remember me asking about how to do this a few months back (not that there are any remnants of the thread left to be found.)

Anyway, I figured it out so sharing for anyone else who wants to do the same:

Firstly you'll want to get the RSS URLs from you NetFlix account. Login, view your queue, scroll to the bottom of the page and click "RSS" in the footer. That will display the RSS urls for your recent activity, your queue, etc.

I hacked up RSS_Get v.1.45 (2/01/05) by Aaron Dunlap http://www.aarondunlap.com to maked this happen

I put my hacked version of Aaron's script (below) in
$b2ehomedir/plugins/rss_get


<!---

  =========================
  RSS_Get by Aaron Dunlap
  http://www.aarondunlap.com
  =========================
  aaron 'at' aarondunlap.com
  =========================
  Version 1.45 (2/01/05)

-->
<?php

  //==========================
  // The following line declares how long to wait before reloading the RSS feed.
  // Keep in mind, many sites discourage people from pulling its feed more often than 30 minutes.
  // For example, Slashdot.org may ban your server if it tries to load the rss feed too often.

  // You may change the below line.
  //==========================

  $minutes = 120; //How often to update the image. 0 indicates that image updates every time it is called (heavy strain on bandwidth & server)

  //==========================
  // The next 3 lines are default settings for the script to use, if they are not set prior to including this script

  // You may change the next 3 lines.
  //==========================

  $default_url = "http://rss.netflix.com/TrackingRSS?id=P7097096287801732051477071912380244"; //URL for the RSS/XML feed you're subscribing to.
// $default_displayname = "||||"; //Title to appear before headlines. Should be feed-specific
  $default_number = 10; //How many headlines to display. If you set it higher than the ammount of headlines, it will stop there

  //==========================
  // The next line is what directory to dump the htm files generated by this script.
  // It should be relative to the location of this script, and it *MUST* have a trailing slash if it's a seperate dir.
  // If you want the files to be dumped in the same dir as this script, set it to ""

  // You may change the next line
  //==========================

  $filename = "$b2ehomeurl/plugins/rss_get/rss/";

  //==========================
  // The next line is whether or not the script should auto-update.
  // If enabled, the script will check to see if a newer version of this script is available and will
  // automatically download and install it. Your current version of the script will be backed up  in your $filename
  // directory.

  // If you have manually edited this script, you should disable this. Otherwise, it is recomended that you enable it.

  // You may change the next line
  //==========================

  $autoupdate = FALSE;


  //XXXXXXXXXXXXXXXXXXXXXXXXXX
  // Everything below is functional code.
// You should not change it unless you know what you're doing.
  //XXXXXXXXXXXXXXXXXXXXXXXXXX

  $version = 1.45;

  //If these variables aren't declared already, use defaults.
  if (!$url) { $url = $default_url; }
  if (!$displayname) { $displayname = $default_displayname; }
  if (!$number) { $number = $default_number; }


  //In-URL definitions. Cannot be used for including, but it works great for testing.
  if (isset($_GET['url'])) { $url = $_GET['url'];}
  if (isset($_GET['number'])) { $number = $_GET['number'];}
  if (isset($_GET['displayname'])) { $displayname = $_GET['displayname'];}
  if (isset($_GET['rssHeadline'])) { $rssHeadline = $_GET['rssHeadline'];}
  $basefile = $filename;
  $versionfile = $filename."updatelog.htm"; //File for update attempt log
  $filename .= md5($url).".htm"; //Prepare filename for htm output


  //==========================
  // Script updating. Checks to see if an update attempt has been made in 24 hours, then goes ahead.
  //==========================
  if (((is_file($versionfile)) && (((time()-filemtime($versionfile)) >= (24 * 60 * 60))) || (!is_file($versionfile))) && ($autoupdate == TRUE)) {
        $fd = fopen ($versionfile , "a");
        $out = "<i>[".date("m/d/y H:i:s")."]</i> Attempting to aquire latest version number: ";
        fwrite ($fd , $out);
        require 'http://www.aarondunlap.com/code/rss_get_version.php';

        if ((isset($latestversion)) && (isset($versionURL))) {
                $out = "<b>Aquired!</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Comparing version numbers: ";
                fwrite ($fd , $out);
                if ($version < $latestversion) {
                        $out = "<b>Your version ($version) is out-of-date. Updating to version $latestversion.</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Loa
ding updated script: ";
                        fwrite ($fd , $out);

                        //Reads the new file from my server
                        if (@$newversfile = fopen($versionURL,"r")) {

                                while (!feof($newversfile)) {
                                        $newvers .= fgets($newversfile);
                                }

                                //Transfers currently existing settings onto the update.
                                $newvers = str_replace("http://www.aarondunlap.com/rss.php?mode=hl",$default_url,$newvers);
                                $newvers = str_replace("|| aarondunlap.com ||",$default_displayname,$newvers);
                                $newvers = str_replace('$default_number = 5;','$default_number = '.$default_number.';',$newvers);
                                $newvers = str_replace('$autoupdate = TRUE;','$autoupdate = '.$autoupdate.';',$newvers);
                                $newvers = str_replace('$filename = "rss/";','$filename = "'.$basefile.'";',$newvers);
                                $newvers = str_replace('$minutes = 15;','$minutes = '.$minutes.';',$newvers);


                                $out = "<b>Opened</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Checking write-access in directory: ";
                                fwrite ($fd , $out);

                                //Checks to make sure we can write in this directory
                                if (is_writable(getcwd())) {
                                        $out = "<b>Writable!</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Writing new version to temporary file: ";
                                        fwrite ($fd , $out);

                                        $outfile = fopen("rss_get_temp.txt","w+");
                                        fwrite($outfile, $newvers);
                                        fclose($outfile);
                                        $out = "<b>Written.</b><br>\n<i>[".date("m/d/y H:i:s")."]</i> Backing up outdated file in $basefile directory:";
                                        fwrite ($fd , $out);

                                        $mefile = substr($_SERVER['PHP_SELF'],1);

                                        //Backs up the current script (this one) into the rss folder
                                        if (!copy($mefile,$basefile."backup_".date("m-d-y_(H.i)").".php")) {
                                                $out = "<b>Failed.</b><hr>\n";
                                                fwrite ($fd , $out);
                                                fclose($fd);
                                        } else {
                                                $out = "<b>Moved.</b><br>\n<i>[".date("m/d/y H:i:s")."]</i> Replacing script with new version:";
                                                fwrite ($fd , $out);

                                                //Renames the temp file as this file, effectively replacing it.
                                                if (@!rename("rss_get_temp.txt",$mefile)) {
  //Dude, look at these if blocks!                      $out = "<b>Failed.</b><hr>\n";
                                                        fwrite ($fd , $out);
                                                        fclose($fd);
                                                } else {
                                                        chmod($mefile,774);
                                                        $out = "<b>Replaced</b><br>\n<i>[".date("m/d/y H:i:s")."]</i><b> RSS_GET updating complete. </b>\n<br
><i>[".date("m/d/y H:i:s")."]</i><b>Version note from author:</b>".$message."<hr>\n";
                                                        fwrite ($fd , $out);
                                                        fclose($fd);
                                                }

                                        }

                                } else {
                                        $out = "<b>Not Writable.</b><hr>\n";
                                        fwrite ($fd , $out);
                                        fclose($fd);
                                }

                        } else {
                                $out = "<b>Failed.</b><hr>\n";
                                fwrite ($fd , $out);
                                fclose($fd);
                        }
                } else {
                        $out = "<b>Your version is current</b><hr>\n";
                        fwrite ($fd , $out);
                }

        } else {
                $out = "<b>Failed.</b><hr>\n";
                fwrite ($fd , $out);
                fclose($fd);
         }
 } // That's a lot of elses! Alright, we're done with the update thing.
//==========================
  // Check the modify time of the htm file for this feed, and see if it's too new to reload the feed.
  // If the file is too new, it loads the htm file. This stops the script from constantly pulling the feed.
  //==========================

  if (($minutes > 0) && (is_file($filename)) && (((time()-filemtime($filename)) < ($minutes * 60)))) {
        include $filename;
        $time = floor((time()-filemtime($filename)) / 60); //See how many "minutes ago" the file was made.
        echo "<br><i><span class=\"updated\">Updated $time minutes ago.</span></i>"; //Include "minutes ago" after output.

  } elseif (@fopen($url,"r")) { //Makes sure the file can actually be accessed.

          //==========================
          // If we're down here, it means that the feed needs to be reloaded.
          //==========================

          $rssHandle = fopen($url,"r") ; // Open the rss file for reading

          while (!feof($rssHandle)) {
                $rssData .= fgets($rssHandle);
          }

          //==========================
          // Feed parsing
          //==========================
          $tag = "item ";
          $rssData =  preg_replace("/<" . $tag . "(.|\s)*?>/","<item>",$rssData);
          $rssData = chop($rssData); // Strip any whitespace from the end of the string
          $rssData = ereg_replace("[\r,\n]", "", $rssData); //Clear line breaks
          $rssData = strstr($rssData,"<item>"); //Remove everything before <item>.

          //==========================
          // Strip specific tags and their content from the feed, to lighten the strain on the processor.

          // Currently, only the <description></description> tags are stripped, we don't need them and sometimes
          // they are REALLY long, getting rid of them now makes it easier to parse later.
          //==========================
          $tags_and_content_to_strip = Array("description");

          foreach ($tags_and_content_to_strip as $tag) {
               $rssData = preg_replace("/<" . $tag . ">(.|\s)*?<\/" . $tag . ">/","",$rssData);
          }

          $rssData = str_replace("<item>","", $rssData); //Remove <item> itself
          $rssData = urldecode($rssData); //Replace any silly %20-type characters with their readable replacement.
          $rssData = str_replace(strstr("</channel>",$rssData),"",$rssData);
          $rssArray = explode("</item>",$rssData); //Creates an Array from all the headlines

          $title = array();
          $link = array();

          //==========================
          // This loop creates an array for links and one for titles.
          //==========================
          $x = 0;
          while($x < $number) {
                $link[$x] = strstr($rssArray[$x],"<link>"); //Remove everything before <link>
                $link[$x] = ereg_replace("<link>","",$link[$x]);

                $link[$x] = str_replace(strstr($link[$x],"</link>"),"",$link[$x]);
                $link[$x] = trim($link[$x]);

                $title[$x] = strstr($rssArray[$x],"<title>");
                $title[$x] = ereg_replace("<title>","",$title[$x]); // Remove the leading <title> tags from the selected headline
                $title[$x] = str_replace(strstr($title[$x],"</title>"),"",$title[$x]); //  Remove </title> and anything after it
                $title[$x] = trim($title[$x]);

                if ($title[$x] == "") { $number = $x; break; } //If there are no more headlines, reset $number to the max.
                $x++;
          }

          //==========================
          // Writing the file
          //==========================
          $fp = fopen($filename, "w+");
          $x=0;
          fwrite($fp,"<ul>"); //open the unordered list

          while ($x < $number) { //This loop writes each line individualy.
                fwrite($fp,"<li><a class=\"headlinellink\" href=\"$link[$x]\">$title[$x]</a>");
                $x++;
          }
         fclose($fp);
         include $filename;
         echo "</ul>";

 } else {
        //==========================
        // Error handling:
        // (rss url given is unreadable)
        //==========================
        echo "<b>Could not connect to $url. </b>";

}

?>

Then I put the following into $b2ehomedir/skins/smoothCurrency/_main.php between the end of the div for the archives and before the beginning of the div for the linkblog:


<div class="bSideItem">
    <h3>Recent Netflix Activity</h3>

<?

      $url = "http://rss.netflix.com/TrackingRSS?id=P7097096287801732051477071912380244"; //URL for Netflix Recent Activity
$displayname = "&nbsp;";
$number = 10;
include '$b2ehomedir/plugins/rss_get/rss_get.php';

?></div>

<div class="bSideItem">
    <h3>Next 5 In our Netflix Queue</h3>

<?

      $url = "http://rss.netflix.com/QueueRSS?id=P7097096287801732051477071912380244"; //URL for Netflix Recent Activity
$displayname = "";
$number = 5;
include '$b2ehomedir/plugins/rss_get/rss_get.php';

?></div>

could use better tweaking to work better with different skins, and who knows what else i did sloppily. i'm not a coder.

see it in action at http://blogs.utiligeek.com/stevensblog.php

enjoy,
~gpf

p.s. if you like this hack and find it useful/fun, post a reply here to prolong the life of this thread and save it from the auto-prune monster so others can enjoy it too.

2 Feb 08, 2005 23:10

The forums were hacked and the freshest backup was older than the hack. Thus everything between backup and hack is gone.

3 Feb 08, 2005 23:16

drat. was it a phpbb vulnerability or a lucky script kiddie with a dictionary attack script?

5 May 10, 2005 23:13

I tried to utilize your plugin - saved the rss_get.php file where you said and copied the other section of code to the _main.php file within my selected skin but i'm getting an error when i view the page.

Would you mind looking at my page - it displays the error instead of my queue and letting me know what i did wrong? http://www.pyrofenix.com/blog/

THANKS!

6 Jun 24, 2005 20:29

I've got the script working and set the number of entries to 5 for my Queue but it still displays 10.

Any idea why?


Form is loading...