08.14
jQuery is going mobile in 2010.
A mobile version has been announced to facilitate simple crossplatform crossdevice development.
The jQuery team continues to impress!
Laughing. Coding. Rocking. Ranting. Thoughts and life of a web developer.
jQuery is going mobile in 2010.
A mobile version has been announced to facilitate simple crossplatform crossdevice development.
The jQuery team continues to impress!
I submitted a module I created for a project to Drupal.org 7 days ago and haven’t heard much of anything back on whether it will be approved or not.
Instead of sit idle, I decided to learn how to use Git and get my first account on GitHub to share this module to the world.
User Alerts repo URL: http://github.com/kevinquillen/User-Alerts
This module provides a simple way to show urgent message on the website. Think of CNN Breaking News, when they show a short message the top of the site.
Alerts can be set on a timer and cleared with cron, or the user can close the alert after reading it. A cookie is set so they do not see the message again. This is to ensure alerts work for sites that don’t have authenticated Drupal users, so anonymous users are tracked.
How to use this module:
You can also set some global settings for alerts at admin/settings/user-alert.
I have tested this module and it does work as intended. I have not fully tested it under Boost or Drupal normal cache. Hopefully users will report back issues and I can address them.
When working with Drupal and XML/SOAP data, you might be coding right along and run into this error:
Warning: unserialize() [function.unserialize]: Node no longer exists
What happened?!
Well, if you are working with XML/SOAP data and try to save it with variable_set() or watchdog(), both of these Drupal functions serialize the data before they are saved to the database, a common method of saving and logging changes in Drupal.
However, if you are parsing XML with SimpleXML, you may think you are working with a string, but in fact are working with a object. What happens then is when variable_set(), watchdog() or functions like it are called, the data passed in is run through serialize and later read with unserialize.
The problem with that is SimpleXML can create objects with invisible properties, and when Drupal tries to serialize your data, its expecting a string and not an object. The quick way around this is to typecast the value you want to save:
Before:
if ($xml_response) { watchdog('mymodule', 'User @user saved, key @key', array('@user' => $user->name, '@key' => $xml_response->MyResponseObject->unique_key_value), WATCHDOG_NOTICE); }
After:
if ($xml_response) { $key = (string)$xml_response->MyResponseObject->unique_key_value; watchdog('mymodule', 'User @user saved, key @key', array('@user' => $user->name, '@key' => $key), WATCHDOG_NOTICE); }
But wait, you changed your code, and you still see the error at the top of your page?
No problem. Now the issue is that you have data in the database that you need to get rid of, because Drupal is trying to read the borked entries back with unserialize(). In my example above, all I needed to do was the following in MySQL:
TRUNCATE watchdog;
This clears out the watchdog table, getting rid of my bad logs. If you saved a variable the same way I was trying to save a response above, you will either need to go in with MySQL and delete the variable, or you can do variable_del(‘variable_name’); in the code with the same effect.
Hope this helps!
I downloaded the latest stable release of Drush this morning, and ran it, only to have it error out and not do anything, which is a first with Drush for me.
The error is “Fatal error, class Console_Table not found in file…“.
Using the link below:
http://svn.php.net/viewvc/pear/packages/Console_Table/trunk/Table.php? revision=267580&view=co
Copy that code and save the file as table.inc. Place the file in /drush/includes/ and drush should then be working for you.
I’m not sure why this suddenly started happening, someone noted it could be from the move from CVS to SVN over at php.net.
Update: Thanks to DaveReid, more information here: http://drupal.org/node/875192
We recently completed a project which required a feature that there was no current Drupal module for. The closest around was admin_message, but wasn’t fully what I needed to do.
The feature is really simple. The client wanted a way to immediately show an alert on the page when they had something critical to announce. Think of Breaking News on CNN, the yellow banner that appears at the top. It shows above the content, everyone sees it, and you can X it out if you like. When you X it out, it fades away nicely, thanks to the excellent jQuery library.
Implementing it was actually really simple. I am in the process of cleaning up the code and submitting it to drupal.org. The hardest part to get around was controlling when to display the message to the user, and if they had closed it before. Don’t want someone seeing the same message multiple times with a closing button that doesn’t work, after all.
In order to do that, I would need to ‘remember’ the user for as long as I could. The first thing that came to mind was utilizing $_SESSION and/or the Drupal user object. I quickly found out that Drupal does not store any data about anonymous users, does not retain a cookie or save session data on them. This presented a problem in actually tracking a visitor.
I would need to use a cookie. However, it appears that Drupal has no wrapper/functions to make use of a cookie beyond the scope of the user object, which I needed in this case. I was able to get a few nudges in the right direction from fellow developers and came up with a solution that worked for me.
When a person comes to the site, we need to create a cookie and immediately set it. When cookies are set, they are not available until the next request, and we need to sidestep that as well. In the cookie, we are going to generate a Unique User ID (UUID) and store it. As long as cookies are enabled, the feature will work. True, you could use the IP to track someone, but if they are visiting from a company network or office, it is not too reliable.
The solution is pretty straightforward:
function mymodule_init() {
if (!isset($_COOKIE['UUID'])) {
$uuid = mymodule_get_uuid();
setcookie('UUID', $uuid, time() + 31536000, '/');
if (request_uri() == '/') {
drupal_goto('index.htm');
} else {
drupal_goto(request_uri());
}
}
}
So, when the hook_init() function is invoked by Drupal, our code is included. It checks for UUID in the cookie, and if it doesn’t exist, we generate a UUID (using another function), then call setcookie() to create our cookie value. Then, we immediately redirect the user to their page request using drupal_goto(). The first line redirects the user to the homepage if that was their initial request, without that, they are sent to http://www.yoursite.com// with an extra slash on the end. Cosmetic (and webstat) fix, you don’t have to do that if you don’t want to. drupal_goto() happens so fast the user does not realize anything happened, and our cookie is available right away.
It’s also important to note the ‘/’ in the setcookie(). This is an optional argument denoting the path of the cookie, but I could not get setcookie() to work in Drupal without it. Also, make sure your session and/or cookie lifetime is not set to 0 in settings.php. Your mileage may vary.
So now we have a UUID for the user. When they click on an alert to close it, an AJAX function fires, and their UUID is written to the database to indicate the UUID, node ID that performed a close action. This is a very useful solution when you want to track a user who may not be logged in (and may never log in).
For more information regarding cookies in Drupal, check out these links. Most of them are discussions I started to help me find an answer.
http://stackoverflow.com/questions/3397735/hook-user-op-load-does-not- fire
http://stackoverflow.com/questions/3197742/cnn-style-alert-in-drupal
To all the people who have been submitting comments on articles and wound up in the approval void, I am sorry. I was not receiving any notifications from Wordpress that I had comments pending.
I have not played Dragon Age since those original posts but the strategies should still work. I look forward to playing the expansion pack DLCs to Dragon Age soon, and of course, Dragon Age 2 next year.