Archive

Posts Tagged ‘configuration’

Drupal Most Recent Poll Block Not Caching

July 21st, 2009 260 comments

I was working on my new Drupal site, Shop the Internet, yesterday and I tried to insert a poll into a sidebar block that would ask the users which online shopping site did they prefer: Amazon, Bestbuy, Newegg, Target, or Walmart.  To test the poll I click Amazon and viola, it posted my vote.  Success!  Or so I thought…I was logged in to my admin panel in Firefox so I tried it in Internet Explorer.  When I refreshed the page, it said it was voted on and was showing the results.  So obviously the poll must have been more advanced than I thought, using IP address over cookies.  So again I tried it on Google Chrome and same thing.  Okay everything is fine.  So I go back to work with my site.  However after half an hour when my cache data was set to reset I decided to retest it and so I opened Internet Explorer and went to Shop the Internet…but now the poll was available to be voted on.  Of course I instantly realized this was because the caching of the poll was wrong, it was caching the poll and saving it as the cached version so that anyone who viewed it after I had voted on it would see the results only for another half an hour.  So I started my research on Google of course.

I searched for a bit, but no results and I was wondering if it were my fault that the poll was being cached.  But eventually I came upon a Drupal forum post http://drupal.org/node/523676 which gave a patch which is transcribed below:

diff -urp –strip-trailing-cr ../drupal-6.x-dev/modules/poll/poll.install ./modules/poll/poll.install
— ../drupal-6.x-dev/modules/poll/poll.install 2009-01-06 16:46:37.000000000 +0100
+++ ./modules/poll/poll.install 2009-07-18 22:29:37.000000000 +0200
@@ -130,3 +130,21 @@ function poll_schema() {
return $schema;
}

+/**
+ * @defgroup updates-6.x-extra Extra poll updates for 6.x
+ * @{
+ */
+
+/**
+ * Fix cache mode for “Most recent poll” block.
+ */
+function poll_update_6000() {
+ $ret = array();
+ $ret[] = update_sql(“UPDATE {blocks} SET cache = 2 WHERE module = ‘poll’ AND delta = ’0′”);
+ return $ret;
+}
+
+/**
+ * @} End of “defgroup updates-6.x-extra”
+ * The next series of updates should start at 7000.
+ */
diff -urp –strip-trailing-cr ../drupal-6.x-dev/modules/poll/poll.module ./modules/poll/poll.module
— ../drupal-6.x-dev/modules/poll/poll.module 2008-12-18 16:46:20.000000000 +0100
+++ ./modules/poll/poll.module 2009-07-18 21:45:53.000000000 +0200
@@ -131,6 +131,7 @@ function poll_block($op = ‘list’, $delta
if (user_access(‘access content’)) {
if ($op == ‘list’) {
$blocks[0]['info'] = t(‘Most recent poll’);
+ $blocks[0]['cache'] = BLOCK_CACHE_PER_USER;
return $blocks;
}
else if ($op == ‘view’) {
@@ -776,6 +777,8 @@ function poll_cancel($form, &$form_state

// Subtract from the votes.
db_query(“UPDATE {poll_choices} SET chvotes = chvotes – 1 WHERE nid = %d AND chorder = %d”, $node->nid, $node->vote);
+
+ cache_clear_all();
}

/**

If this code looks strange to you you are not alone.  I was confused too.  I have patched files in linux before, but my webhost, Ixwebhosting, does not have access to ssh or the terminal in general so I was stuck.  This was an obvious bug and I could not fix it.  All I could find were links to how to convert a patch file to an exe on Windows, but first I have a linux server and also how would I have executed that anyway?  So I decided to do it the manual way, open the files and manually edit it.  Make sure you back up all original files before editing!

  1. First open  ./modules/poll/poll.install and go to line 130
    Find

    function poll_schema() {
       return $schema;
     }

    and add after it

    function poll_update_6000() {
      $ret = array();
      $ret[] = update_sql("UPDATE {blocks} SET cache = 2 WHERE module = 'poll' AND delta = '0'");
      return $ret;
    }
  2. Save and exit.  Next open  ./modules/poll/poll.module and go to line 131
    Find:

    if (user_access('access content')) {
         if ($op == 'list') {
           $blocks[0]['info'] = t('Most recent poll');
           return $blocks;
         }
         else if ($op == 'view') {

    and replace with:

    if (user_access('access content')) {
         if ($op == 'list') {
           $blocks[0]['info'] = t('Most recent poll');
          $blocks[0]['cache'] = BLOCK_CACHE_PER_USER;
           return $blocks;
         }
         else if ($op == 'view') {
  3. In the same file go to line 777
    Find:

    function poll_cancel($form, &$form_state) {
      $node = node_load($form['#nid']);
      global $user;
      if ($user->uid) {
        db_query('DELETE FROM {poll_votes} WHERE nid = %d and uid = %d', $node->nid, $user->uid);
      }
      else {
        db_query("DELETE FROM {poll_votes} WHERE nid = %d and hostname = '%s'", $node->nid, ip_address());
      }
      // Subtract from the votes.
      db_query("UPDATE {poll_choices} SET chvotes = chvotes - 1 WHERE nid = %d AND chorder = %d", $node->nid, $node->vote);
    }

    and replace with:

    function poll_cancel($form, &$form_state
    
       // Subtract from the votes.
       db_query("UPDATE {poll_choices} SET chvotes = chvotes - 1 WHERE nid = %d AND chorder = %d", $node->nid, $node->vote);
       cache_clear_all();
     }
  4. Save this file and upload.  Now the Poll block should work well.
ibed below:

Ip Filtering with Utorrent

December 9th, 2007 4,738 comments

Download IPFilter

I am not writing this post to encourage copyright infringement, you risk your own safety when you download illegal content, but I am writing this because there are legal things that can be downloaded through the Bitorrent method and if you are against the Patriot Act, or just like protecting your privacy then here is an overview of what I consider the best Bittorent Client out there.

Weighing in at a meager 263 KB is the mighty uTorrent, able to be customized to a great amount of personalization.  It not only is lightweight but packs as much punch as its biggest rival Azureus.  Utorrent allows you to sort torrents by % Completed, Date Completed, Seeder/Leecher ratio, and a whole variety of others.  It includes a user friendly system that is not bloated with ads or unnecessary junk like Azureus and shows you a simple list of all your current torrents.

However to get the most out of uTorrent, you need to enable some hidden features of the software.

Utorrent Download: http://utorrent.com

IP Filtering

One of the best features to protect your privacy in uTorrent is to enable IP Filtering.  It blocks out all the bad IP addresses that could compromise your privacy.

To enable this feature first open uTorrent and press CTRL + P to open the uTorrent Preferences and then go to the Advanced menu and find the setting labeled ipfilter.enable and make sure its value is set to “true”.  If not double click on the value and it should change to true.  A picture is below.

Once you have done that it is time to get the .dat file that includes the IP addresses.  To do so go to http://www.megaupload.com/?d=TZ1D5ZI2 and download to a directory where you know where to find it.  The old file I used to get was a tarball and needed Winrar to extract, however this version is a ZIP.   Once you have the ZIP extract it to a place you know where it is.  You should now have a file named ipfilter.dat . Now comes the final step.  If you are running Windows XP (which is what I use so if you don’t you will have to check documentation, go to Start -> Run.. and type “C:\Documents and Settings\YOUR NAME\Application Data\uTorrent” replace “YOUR NAME” with your username on your computer which should be easily found at the very top of your Start Menu when you open it.  Now copy the ipfilter.dat into this folder and restart uTorrent.  When you look in your logger on uTorrent, you should be presented with “Loaded ipfilter.dat (# entries).”  If not you did something wrong so repeat the process.

Other Preferences

If you wish extra protection go back to Preferences and set your settings to the following:

Bittorrent:

Queueing:

The rest of the settings are pretty much configurable based on your system and connection.  Fiddle around with them to see what works best for you. :)   Happy LEGAL Downloading!

[poll id="2"]

Great Legal Torrents:

http://www.ubuntu.com/

http://beta.legaltorrents.com/

Video Guides:

http://www.youtube.com/watch?v=R1qxUovxRls

http://www.youtube.com/watch?v=SAqvJIeyQXY

Other Ipfilter.dat sites:

http://www.atheistdictionary.com/ipfilter/ipfilter.dat