Referers in b2++

I’ve integrated part of the Nathan’s referer code into b2++. It’s in the form of a prefunction as it creates a global referers tag you can put into your site templates.
Currently it creates a different tag if you’re viewing a single post or a whole blog/category. This allows the template designer to use the postreferers tag when listing referers to a single post, or use refererlinks to list the site referers list. Add this code to your index.tpl to enable it:

{if $refererlinks != “”}
<blockquote>
Referers:
<ol>
{foreach from=$refererlinks item=link}
<li> <a href=”{$link.referingURL}”>{$link.baseDomain}</a> ({$link.visitTimes})
{/foreach}
</ol>
</blockquote>
{/if}

Flavour it to suit your own blog design. Substitute $postreferers for $refererlinks and put the same code into post.tpl to see single post refererers. The final b2++ 0.6 will have this in place, and all you’ll need to do is update your templates from the Template Chooser.

Update!
Because of the caching on this site many referers were lost, I changed the referer plugin into a Smarty insert plugin.
Insert functions are executed every time a page is loaded and because of the way they operate, I’ve had to hard-code the html it outputs for the time being.
Anyway, ignore the instructions above. If you want to record and display referers on your blog on this site, then add the following code to index.tpl (anywhere will do, but make sure there’s enough space for it!)

{insert name=”getreferer” mode=”index”}

Add the following to post.tpl if you want to show referers to individual posts too:

{insert name=”getreferer” mode=”post”}

There’s some problem with it as is though, sometimes the insert function doesn’t execute. I’ll have a look at why tomorrow.

Update 2
I still don’t know why insert functions didn’t work, that’s something I’ll have to bring up on the Smarty mailing list tomorrow. I reverted to recording every referer on each request, but the list of referers for any page is only updated when the page cache is updated.

Linux to Symbian File Transfer – HOWTO

I finally got to see my phone’s filesystem from Linux this morning! I used p3nfs to connect my Nokia 7650 and Red Hat 9 Linux box. Here’s how.

  • Login to your Linux box as root.
  • Make sure you have the following rpms installed: bluez-libs-devel, bluez-libs, bluez-utils. They’re available from your local apt-rpm repository (just apt-get install them!) or from http://bluez.sf.net
  • Copy the following lines to your /etc/modules.conf

    # bluetooth stuff
    alias net-pf-31 bluez
    alias bt-proto-0 l2cap
    alias bt-proto-2 sco
    alias bt-proto-3 rfcomm

  • Start Bluetooth services: /etc/init.d/bluetooth start
  • Create the bluetooth device if it doesn’t exist: mknod /dev/rfcomm0 c 216 0
  • Create a directory for the mobile to be mounted on: mkdir /mnt/psion
  • Download p3nfs from the site above. Copy the nfsapp for your phone to your phone (you’ll have to mail it to your phone, wap, or bluetooth in Windows.)
  • p3nfsd doesn’t compile on Red Hat 9, but it’s simple to fix that. cd into the nfsd directory, edit “mp_mount.c” and remove any mention of extern int errno from it and add #include <errno.h> at the top of the file. Do the same in “mp_xmit.c” and compile using make clean;make
  • Follow the instructions in README.bluetooth.linux (find the BDADDR, bind to the device, and start the nfs app and servers.
  • cd into /mnt/psion and look around your phone!

This is in fact more useful than the Windows tools I have. I couldn’t send images from my phone to my desktop software, and there’s quite a few of them. Using this, I simply went into /mnt/psion/C:/Nokia/Images/ and “mv”ed the files onto my PC!
There’s an “Installs” directory there too so I presume that’s where the .sis and .jar files go to install applications. Will test later. /me’s happy!
This howto wouldn’t have been possible without the invaluable page Tom wrote about his own experiences. Thanks! And of course Google helped me compile p3nfsd!

$2 trillion fine for Microsoft security snafu?

Doubtful it’ll happen..

Microsoft’s latest security lapse with its Passport information service could trigger a $2.2 trillion fine on the company courtesy of the US government.

Microsoft on Thursday admitted that a flaw in the password reset tool of its Passport service could compromise the information stored on all 200 million users. It scampered to post a fix and is looking into potential exploits, but the damage to Microsoft may already have been done.

MVC, PHP and Smarty Caching…

Moving a purely procedural program to an OO design is a mammoth task, especially when that program is several years old and had bits added on over the while.
I’ve pruned out a lot of the extra features that are not needed now, and some that are simply silly, but now I’m coming to a stumbling block.

Smarty can cache content. The beauty of that is I can avoid a whole load of expensive operations like database queries, information lookups from remote sources, code loops, etc. In an MVC application, where should the check for cache freshness be?

  • Should it be in the controller class so it can call the functions of the model to create the view?
  • Should it be in the model, so the controller doesn’t have to know about the model? The model is where the expensive operations are anyway.
  • Should it be in the view, because that’s the locality of freshness information? Isn’t caching an element of the display procedure?

If it’s in the controller, then the controller has to know about caching, is that bad?
If it’s in the model, then the controller is ignorant, and therefore not a controller.
If it’s in the view, the controller is ignorant, and the view is now “controlling” if functions are called in the model.
You can see where my reasoning is going with this..
The controller should probably have access to the cache information. It shouldn’t talk directly to the Smarty instance in the view however. It should talk to a function that takes data from the model, checks the cached views against that data and any timeouts and returns true or false.
For example:

class exampleController
{
  function exampleController()
  {
    // skip unimportant bits.
    // create model and view
    if( $this->view->is_cached() == false )
    {
      // do some expensive operations in
      // the model to create the view.
    }
  }
}

Or should that is_cached() function be in the model? Please comment if you have any insights!