Nov 16

Anonymous users, $_SESSION and you!

Category: Code

During the final stages of development on our staging system we noticed that anonymous users were not able to read and write from the $_SESSION.  Scouring for information at 7PM on a Tuesday night we came across the $user object in the Pro Drupal Development book.  Somewhat of a comfort to me and my boss we looked at the $user object in detail and found that it stored a serialized version of $_SESSION in $user->session.  We thought to ourselves does an anonymous user have to de-serialize and serialize data every time it wants to read and write to the session?  That couldn’t have been the case and we moved forward looking for another solution.  Fast forwarding to to Wednesday morning (as my boss suggested I go home instead of writing an anonymous user session handler) I come back to the problem at hand.  What is causing my session to be deleted when browsing the site as an anonymous user going from page to page?

At this point I was using venerable functions such as session_id(), and debug_print_backtrace() to see what might be causing this anomaly.  Alas I could not find anything relevant and then decided to scour the forums using the site’s search function.  I came across a few posts that had merit but one finally caught my eye:

http://drupal.org/node/192165#comment-630167

Now this post mentioned that the user whose uid was zero is missing from the database and that restoring it was the fix.  Sure enough I opened a terminal, logged into our database and executed SELECT * FROM users WHERE uid=0;, to my surprise there was no user with a uid of zero.  Thinking back to when we first installed Drupal, my boss and I looked at the database and sure enough we though that a user with uid set to zero and no user name and or password was a bug and probably just deleted the row.  Now looking back, the bug was actually introduced by us.

But the moral of the story is that if $_SESSION is not being stored as an anonymous user from page to page, take a look at the users table in the database.  Chances are that you can save yourself a lot of debugging time by making sure that a user of uid set to zero exists.  If there isn’t one in the database there is a simple fix for this issue, execute the following SQL command: INSERT INTO users (uid) VALUES (0);

Clear your cache and then go back to the pages in question and see if it makes any differences in what values are stored in $_SESSION as an anonymous user.

No comments

Nov 13

Eclipse Zend PDT with RSE

Category: Code, General, Music

So at work I was using an IDE called Komodo.  It had great feature support, worked with the Drupal API for auto-complete and was even cool enough to have FTP remote access so you can do your work on a development server then SSH to that server and commit your revisions.  Then came along the Komodo slow down.

The Komodo slow down can best be described as the file typing a character every two seconds even though it only took you about .3 seconds to type the whole word.  Doing research on the issue yielded lackluster results in the ActiveState community.  Thus the search for a new IDE began.

I remember using the Zend PDT while it was just hitting 1.0 status.  It was a diamond but a roughly cut diamond and in the interests of getting a project done sooner rather than later I kept with Komodo.

Coming full circle I took another look at the project today and found some interesting developments.  The CDT and RSE plugins have suddenly surfaced (I couldn’t find any info on them when I first used PDT).  I also figured out that to get to my remote development box I can use said plugins.  Installation was a snap and within twenty minutes I had a full development IDE up and running and communicating with my development server making changes and testing them in real time.  The only tricky part was getting RSE up and running.  For those that can’t figure it out from the Eclipse pages it is really just adding a new remote site under the find new software dialog (Help->Software Updates->Find and Install).  Just name the new remote site RSE and point it to http://download.eclipse.org/dsdp/tm/updates/2.0/.  Here is a quick screen shot of it up and running on my machine:

Also while doing this whole setup I was listening too In This Moment.  Maria Brink is one hot piece of …

No comments

Oct 25

My journey with Drupal.

Category: Code, Music

So for the past six or seven months I have been training in the arts of the Drupal community.  I have touched a wide range of modules ranging from email forwarding to Panels and Views.  If I had to come up with a list of modules I have touched recently here is a ls -al from the modules folder:

-bash-3.00$ ls -al
total 176
drwxr-xr-x  44 beta psacln 4096 Oct  4 10:25 .
drwxr-xr-x   5 beta psacln 4096 Oct  4 10:25 ..
drwxr-xr-x   5 beta psacln 4096 Oct  4 10:25 admin_menu
drwxr-xr-x   6 beta psacln 4096 Oct  4 10:25 ahah_forms
drwxr-xr-x   7 beta psacln 4096 Oct  4 10:25 bueditor
drwxr-xr-x   5 beta psacln 4096 Oct  4 10:25 calendar
drwxr-xr-x   5 beta psacln 4096 Oct  4 10:25 cck
drwxr-xr-x   3 beta psacln 4096 Oct  4 10:25 cck_taxonomy
drwxr-xr-x  15 beta psacln 4096 Oct 12 15:17 custom
drwxr-xr-x  11 beta psacln 4096 Oct  4 10:25 date
drwxr-xr-x   4 beta psacln 4096 Oct 24 09:48 dcl_importer
drwxr-xr-x   5 beta psacln 4096 Oct  4 10:25 devel
drwxr-xr-x   3 beta psacln 4096 Oct  9 11:37 editorsmodule
drwxr-xr-x   3 beta psacln 4096 Oct  4 10:25 editview
drwxr-xr-x   4 beta psacln 4096 Oct 24 17:53 forward
drwxr-xr-x   5 beta psacln 4096 Oct  4 10:25 image
drwxr-xr-x   4 beta psacln 4096 Oct 20 19:55 invite
drwxr-xr-x   3 beta psacln 4096 Oct  4 10:25 invite_site_report
drwxr-xr-x   4 beta psacln 4096 Oct  4 10:25 jquery_update
drwxr-xr-x  11 beta psacln 4096 Oct  4 10:25 jstools
drwxr-xr-x   7 beta psacln 4096 Oct  4 10:25 lightbox2
drwxr-xr-x   6 beta psacln 4096 Oct  4 10:25 node_import
drwxr-xr-x   4 beta psacln 4096 Oct  4 10:25 nodequeue
drwxr-xr-x   3 beta psacln 4096 Oct  4 10:25 pagequeue
drwxr-xr-x  23 beta psacln 4096 Oct  4 10:25 panels
drwxr-xr-x   5 beta psacln 4096 Oct  4 10:25 pathauto
drwxr-xr-x   3 beta psacln 4096 Oct  4 10:25 persistent_login
drwxr-xr-x   4 beta psacln 4096 Oct  4 10:25 pmail
drwxr-xr-x   4 beta psacln 4096 Oct  4 10:25 scheduler
drwxr-xr-x   7 beta psacln 4096 Oct 25 17:35 .svn
drwxr-xr-x   4 beta psacln 4096 Oct  4 10:25 tagadelic
drwxr-xr-x   3 beta psacln 4096 Oct  4 10:25 taxonomy_csv
drwxr-xr-x   3 beta psacln 4096 Oct 25 17:05 thrillist
drwxr-xr-x   3 beta psacln 4096 Oct 24 11:32 thrillistad
drwxr-xr-x   3 beta psacln 4096 Oct 24 18:18 thrillistemailheader
drwxr-xr-x   3 beta psacln 4096 Oct  4 10:25 thrillistfooter
drwxr-xr-x   3 beta psacln 4096 Oct 23 18:57 thrillistheader
drwxr-xr-x   4 beta psacln 4096 Oct  4 10:25 token
drwxr-xr-x   3 beta psacln 4096 Oct  4 10:25 user_import
drwxr-xr-x   3 beta psacln 4096 Oct 15 08:38 utility
drwxr-xr-x   7 beta psacln 4096 Oct  4 10:25 video
drwxr-xr-x   5 beta psacln 4096 Oct  6 12:35 views
drwxr-xr-x   4 beta psacln 4096 Oct  4 10:25 views_fastsearch
drwxr-xr-x   5 beta psacln 4096 Oct 13 09:39 webform
-bash-3.00$

As you can see it is getting quite crowded in there.  I can’t wait for this project to be over so the world can feast upon our glory!  Also the new Weezer albumn is pretty damn good, scope it out when you get a chance.

No comments

Oct 25

Where’s my Chrome?

Category: Uncategorized

So Chrome has been around for a while.  Interesting to say the least.  But as a big advocate of the open source community I couldn’t help but notice the one thing that they left out…  A Linux version.  Of course folks will argue that the installed user base of Linux is too small for a release right away, this is my reply:

…………………./´¯/)
………………..,/¯../
………………./…./
…………./´¯/’…’/´¯¯`·¸
………./’/…/…./……./¨¯\
……..(’(…´…´…. ¯~/’…’)
………\……………..’…../
……….”…\………. _.·´
…………\…………..(
…………..\………….\…

I wonder how many Linux distributions were used in the development of Chrome on the XP/Vista platform?  How many of their servers internally are Linux based.  How many of their desktops are Linux based that actually are browsing the web right now?  This is a rant/sarcastic look at things.  The project is open source but only has a working executable on a Windows platform?  Now Google knows what’s best for Google but I know what is best for my Laptop so that even when Chrome comes out I may still be using FireFox as I feel that I have been snubbed by a company that apparently is distributing its new browser with a restricted BSD license.

Plus it is only a matter of time before someone rips the engine from Chrome and puts it in another browser.

No comments

Oct 15

The Sprint Touch Diamond…

Category: General

Well after a great night of partying at the Showtime house thanks to my company (http://www.thrillist.com) I happened to have lost my phone in a taxi cab.  Sucks to be me (well not really).  So I upgraded (when I say upgraded I mean replaced) my phone to the Sprint Touch Diamond.  I do have to say I was quite impressed with it as it worked with my Mac right out of the box.  It seems HTC and Microsoft have gotten Windows Mobile 6.1 down to a science.

I am content with the device and am having a blast installing all sorts of apps onto it.  I recommend anyone interested in upgrading to visit a Sprint store and try one out.

No comments

Aug 4

Linux, CIFS, and the Nas200…

Category: Code, General

There isn’t much information in regards to how to utilize the Nas200 from linksys with a Linux operating system.  Lets look at the facts of the situation here.  Linux allows many different file systems to be mounted: SMB, NFS, CIFS, etc..  The Nas200 supports CIFS, bingo bango we got a match here!.  So lets take for example that you have your Nas200 sitting at 192.168.1.5 and the folder you want to mount is “anthony”.  Your mount command would look like this:

sudo mount -o user=anthony //192.168.1.5/anthony /media/nas200/

Now this assumes that /media/nas200 is a valid directory.  You have just mounted your Nas200 and any respectable media player (Amarok) can now see your mounted drives and stream your music.  Very cool stuff indeed!  You can even add it to an alias in an *.rc file so you can mount it on a whim!  Thanks to jervine@#suse on freenode for the help!

No comments

Aug 1

Testing my LightBox plugin…

Category: General, Music

Why not showcase some music and a new wordpress plugin.  Lightbox is awesome.  Just click on the image below:

But also check out his set on MCAST exclusively on mercuryserver.com

No comments

Aug 1

FAPI Quick Tips

Category: Code

Pre selecting a select list in Drupal is not as easy as it seems.  First take a look at the following array:

$form['contacts'] = array(
‘#type’ => ’select’,
‘#multiple’ => TRUE,
‘#size’ => ‘6′,
‘#title’ => ‘Contacts’,
‘#options’ => $contacts,
‘#default_value’ => $def_contacts
);

There are a couple of things to take notice here.  ‘#options’ is the total list of options in the array so lets say ‘$contacts’ looks like so:

$contacts = array(
'foo' => 'bar',
'foi' => 'baz',
'john' => 'digweed',
'sasha' => 'has no last name'
'steven' => 'segal'
);

You have an array with the following keys: foo, foi, john, sasha, and steven.  Say we wanted to preselect ‘digweed’ and ’segal’ this is where we build ‘$def_contacts’.  The key (no pun intended) to having Drupal preselect items in the select list is to pass the keys of the ‘$contacts’ array in an array itself.  So if we wanted to have the form preselect existing items that might be part of a node or coming from a database we could build ‘$def_values’ as this:

$def_values = array('john', 'steven');

This all seems very simple but it takes a little time to understand as it is well hidden underneath those Drupal API docs.

No comments

Jul 9

Drupal conventions plain and simple.

Category: Code

There are some common misconceptions about doing certain tasks in Drupal. I take the following to be more of a random collection of thoughts about Drupal and some of the explanations behind them. Lets take for example the CCK node types and forms.

When you build in the CCK you are building a node type but some things are not apparent such as how do I access the CCK node type form on another page? The answer is not simple because the documentation is sparse in this area. I have found that if you want to call a CCK node add/edit from you can do so by appending the machine readable name of the node with “_node_form”. So for example lets say we have a CCK node type with the label “article” the internal form name would be “article_node_form”. Now to call a form is very simple, all you have to do is

function show_me($node_id)
{
$output = ”;
$article_node = node_load($node_id);
$output .= drupal_get_form(’article_node_form’, $article_node);

return $output;
}

As you can see pre-loading any form with a node is just a simple matter of loading the node and then passing it as a second parameter. It took me quite a while to dig through the API and the docs on drupal.org to figure this out.

Additionally theming the form elements is also very trivial once you sift through the documentation You can create a theme function that takes the form as a parameter. So we have our CCK form and we can theme this just like any other form. Usually this is done by pre-pending “theme_” to the form name in our case “article_node_form”. The completed function name would be “theme_article_node_form” For example:

function theme_article_node_form($form)
{
// render specific elements of the form.
$output .= drupal_render($form['title']);

// most important is to render anything additionally such as submit hooks
$output .= drupal_render($form);
return $output;
}

The key to the “theme_” hook is that you can do anything with the form elements and combine them with html attributes. Take for example this complete example of a theming function I built to put certain elements in a table:

function theme_advertisement_node_form($form)
{
$output = ”;
$output .= drupal_render($form['title']);
$output .= drupal_render($form['field_campaign_reference']);
$output .= drupal_render($form['taxonomy']);

foreach($form['field_editions']['keys']['#options'] as $eid => $edition)
{
// get the machine label for the edition
$edition_info = db_fetch_array(db_query(”select label from {edition} where name=’%s’;”, $edition));
$row = array();
$row[] = drupal_render($form['field_editions']['keys'][$eid]);
$row[] = drupal_render($form[$edition_info['label']]['revenue']);
$row[] = drupal_render($form[$edition_info['label']]['offset_revenue']);
$row[] = drupal_render($form[$edition_info['label']]['no_commission']);
$rows[] = $row;
}

$table_header = array(
array(’data’ => ‘Edition’),
array(’data’ => ‘Revenue’),
array(’data’ => ‘Offset Revenue’),
array(’data’ => ‘No Commission’)
);

//$output .= drupal_render($form['field_editions']['keys']['#title']);
$output .= theme(’table’, $table_header, $rows);
$output .= drupal_render($form['field_flight_date']);
$output .= drupal_render($form['field_required_sends']);
$output .= drupal_render($form['field_cpm']);
$output .= drupal_render($form['field_total_revenue']);
$output .= drupal_render($form['field_creative_approved']);
$output .= drupal_render($form['field_invoiced']);
$output .= drupal_render($form['image_attach']);
$output .= drupal_render($form['submit']);

// unset any form elements we didn’t use
unset($form['field_editions']);

$output .= drupal_render($form);

return $output;
}

That should wrap anything in regards to theming and working with CCK node types.

No comments

Jul 3

To drupal or not to drupal that is the question…

Category: Code, General, Music

So I was debating using Drupal which we are basing the company that I work for enterprise site or just scrap the existing WordPress and do a fresh install with a new theme.  Well if you can’t tell I went with the latter.  So I have been busy learning the nuances of Drupal 5.7 and have come to the following conclusion.

1. It is some what great, major companies use Drupal and accomplish great things.

2. You can do some cool stuff with it, even build some excellent modules.

3. You can also learn to bang your head against the damn wall…

Numero tres is more of a product of you staring at the api.drupal.org site, your code, back a the api.drupal.org site, then your code, asking your boss why it might not work (not that he is a Drupal master of course), then going onto #drupal on Freenode and not finding the info, then going back to your code realizing you have spaces in your array keys, then you fix it…

So that is it in a nut shell.  If you are feeling quite peckish, take a look at Sasha & Digweeds set over @ mercuryserver.com.  Shizzle my nizzle.

No comments

Next Page »