Friday, October 30, 2009

Drupal In White House

The White House Web site has caught a case of Drupal. The open-source software package helps people create and manage their Web sites. And this week, a new WhiteHouse.gov site arrived that had been built via the Drupal code.

Companies like Nike, Warner Bros. and Yahoo use Drupal for various parts of their Web sites. All told, close to 500,000 Drupal-based sites are on the Web, according to Thomas Erickson, the chief executive of Acquia.

To some, the White House shift to Drupal from a proprietary software package represented a serious seal of approval for open-source software.

“While open source is already widespread throughout the government, its adoption by the White House will almost certainly give permission for much wider uptake,” wrote Tim O’Reilly, who publishes books and holds conferences about open-source software.Like many open-source companies, Acquia sells service and support to back up the free Drupal. It claims about 300 customers, and “that number is doubling every quarter,”

Monday, October 12, 2009

Basic Drupal Notes

Configuration

1. After installation, it is a good idea to set site configuration by going to Administer -> Settings -> Site Information to set email address, slogan, footer, greeting for anonymous user, etc.

2. Create an administer role and assigning permissions.

3. Enables the modules that you want to use by going to Administer -> Site Building -> Modules.. The Path module allows users to create URL alias to pages, which can benefit SEO when pages are named appropriately. These alias can be viewed at Administer -> Url Aliases.

4. Clean URL feature eliminates the query string parameters in the URL path and is recommended for SEO and can be done by Administration - > Settings -> Clean URLs . For this to work, your server must be Apache servers which have the LoadModule rewrite_module and mod_rewrite configured in httpd.conf. In the settings page, there is a test for you to run to see if your server is configured correctly or not. If you enable Clean URL without proper server configuration, you can get back to the admin page to disable the feature by using the non-clean URL of the form http://www.yourdomain.com/?q=admin/settings

5. Whether or not to allow users to post comments to your stories is controlled by Administer -> Content Management -> Content Type -> Edit.

6. You can configure your Contact form by Administer -> Site Building -> Menu -> Contact.

7. If you site is having problems because you are installing Drupal in a subdirectory, you might need to adjust the $base_url property in sites/default/settings.php.


Template Writing

1. Don't use relative image paths in the tpl files. Instead use ...

'< img src="/images/yourimage.gif" />'

2. Drupal caches on the server for non-registered users. So when you make changes to the template, one way to force Drupal to update its cache is to click on "Save Configuration" in Admin -> Site Building -> Modules. Also refresh your browser cache as well. Or you can run "DELETE * FROM cache;" on your database. Also your webhost may be caching. To mitigate that, you can do http://www.yourdomain.com/?dsfkds where the query string is some random characters.

3. If you want to change the User Login block, try to change it with CSS first. If you really want to get to the code, the function starts at user_login_block() in user.module and traces to drupal_render_form() and theme_form_element() and theme_button() in form.inc.

4.
Misc Notes

5. The MySQL username and password access can be found in sites/default/settings.php in the form...

$db_url = 'mysql://username:password@localhost/databasename';

6. If you don't want the login box to be displayed, you can disable the block and use the following to login...

http://www.yourdomain.net/user

or

http://www.yourdomain.net/?q=user

7. You can determine which node id a page is by printing out ...

nid); ?>

Then you can write PHP if condition and apply them to specific pages such as ...

nid == 33) { ?>
< style >
< /style >

Upgrading from Drupal 5 to Drupal 6

MasteringDrupal.com

Thursday, April 23, 2009

FileField and ImageField for Drupal 6 Released

For drupal 6, image field was recenly released where it can be integrated with CCK.Probably the most exciting improvement is the addition of upload progress indication. This enhancement requires the PECL uploadprogress PHP extension, but adds a real asset to sites that use FileField for podcasts, videos, or other large files.ImageField is now completely dependent on FileField for its data handling. This means less duplicated, less bugs, and more compatibility between add-on modules. If an add-on module works for FileField, it automatically works for ImageField. This means that ImageField is now purely a "widget" for CCK, not a "field" any more.

Hook file support

Other modules can use FileField's hook_file() implementation to help determine when and where a file is in use. This means modules like the new FileField Sources module can reuse existing images on multiple nodes, even use IMCE to browse existing images and reuse them (as long as the files are assigned an FID in the database).

Sunday, February 22, 2009

Google Maps in Drupal

Below are some brief instructions on how to use it:

Step 1. Create a map with macro creator

Each site includes a macro to create a map that you can customize it as you see fit. You can see the GMap Macro on my site here. To create a map:

* Scroll to the bottom of the macro to define the Map Height and Map Width. This is in pixels (try "500px" by "500px" to start with) and make sure you include the "px" after the number. Scroll back to the top and you will see the template map has automatically resized.
* Move the map around with the mouse to the area you want to include. Also adjust the zoom control to achieve the level of magnification you want. You can choose between a basic map, a Satellite map or a hybrid version by switching between the buttons.
* You can add points, lines or circles by (single) clicking on the map. You can switch between these options with the pull down menu where it says Click Map. Experiment by clicking around a map to see what happens.
* Some of the line/polygon settings are a little temperamental, but the marker options work well allowing you to change the marker type. It is possible to link one marker to another.
* To remove a marker make sure the Click Marker option is set to "remove" and then click the marker to be removed on the map.
* Each map needs a different name or identifier (set to "map" by default). Type this in to the Map id attribute field. This can only contain numbers letters and the "-" symbol, and must be unique for each map that will appear on the same page.
* The Control feature (None|Large|Small) allows you to specify whether there is a zoom control on the map and what size it is.
* There are all sorts of advanced options available for customizing your map. The most important of these is the ability to have feeds that take information from a local RSS feed with geolocation data and dynamically plot this on the map. I'll blog about this separately when I have figured out how to do it!

Step 2. Put the map on a webpage (node) in your site

Scroll down to the bottom of the macro and copy the Macro Text that appears in the text box. You then need to paste this into the body field of a new page (node). When you do this make sure to disable rich text (just underneath the text box) and under Input Format select the GMap Filter option. You can add any other information to the page with HTML or the rich text editor.Just do not change the GMap Macro text. When you are done, click Submit and the new page with your Google Map and any plotted points, lines or polygons will appear.

Friday, February 6, 2009

AHAH Helper Module For Drupal

The ahah helper module provides a neat function ‘ahah_helper_path’ to let drupal know about new field elements. This way you can set the path “magically” and the helper module takes care of how the new fields will be rendered. You can use it like this:


$form[’slide_form’][‘new_field’] = array
// field properties …
The ahah property path will be:
‘#ahah’ = array (
‘path’ => ahah_helper_path(array(’slide_form’, ‘new_field’)),
// other properties
);


This helper module makes it very easy to update a form with your own ajax-driven field addtions. It helps memorizing the form so your new fields are known by drupal. At the form api reference link, we can see which fields can trigger this behavior: button, checkbox, image button, password, radio, select, submit, textarea, textfield.

An extra advantage of using the ahah helper module is that when javascript is disabled, the same function will be called with a normal post and this will work just fine. Sometimes it can be helpfull to check #first_time parameters in callbacks to see if the data was previously saved.

Sunday, February 1, 2009

Theming Drupal 6 from the module

You start with creating a DOT info file for your module. The name of which would be in our case special_page.info.

;$Id$
name = Special Page
description = Provides a template file for my content type CONTENT_TYPE.
core = 6.x

Then you go about creating your DOT module file, ie: special_page.module.

// $Id$
/**
* @file
* Module that provides a special template for pages that show
* ONE node of content type CONTENT_TYPE_NAME.
*/

You probably should implement HOOK_help() in your module, but I will skip that, and cut the chase to what we really need.

At this point, you need to tell the theme system to use your template, and to use it only in certain situations. Your 'situations' will differ from mine. In my case, I wanted the theme system to use my template on a node page, hence any page with path node/nid, yet only on pages that show the node in view 'mode', so I did not want the template to be used when the path is node/nid/edit for example. There are many ways to skin the cat here. I decided to use the fact that a $node object is passed to the page.tpl.php template only when the page is a node page, as you will see in the following code snippet. Here, I will make use of a preprocess function to pass on to the theme system a suggestion about a new module-supplied template.

function special_page_preprocess_page(&$variables) {
// If this is a node page (not a list of nodes page) and
// the node is shown in 'view' mode rather than 'edit' or whatever.
if (isset($variables['node']) && (arg(2) === NULL)) {
// If the content type of that one node is 'CONTENT_TYPE_NAME'.
if ($variables['node']->type == 'CONTENT_TYPE_NAME') {
$variables['template_file'] = 'page-CONTENT_TYPE_NAME';
}
}
}

Then feel free to create such template file. As a reminder, no need to add the tpl.php extension to the value you assign to $variables['template_file']. Also, that name can be anything, I am just following conventions here by prefixing with page, as in page-SOMETHING.tpl.php. Make sure that the name you provide here matches the name of your template file.

Then, you are faced with a small problem: the template file will need to be placed in the theme folder in order to be picked up by Drupal's theme system. But you don't want that. So what to do? Here comes a situation where we can use the module hook HOOK_theme_registry_alter(). For the theme hook you want to provide special theming for (hook in theme parlance here), you will have to tell Drupal Hey, Drupal, please look in my module folder over here, you may find a template file you will need.

function special_page_theme_registry_alter(&$theme_registry) {
$theme_hook = 'page'; // my hook name
// Get the path to this module
$modulepath = drupal_get_path('module', 'special_page');
// Add the module path on top in the array of paths
array_unshift($theme_registry[$theme_hook]['theme paths'], $modulepath);
// dsm($theme_registry[$theme_hook]['theme paths']);
}

And you are done.

Friday, January 30, 2009

Drupal Sites

Below is a very short list of other companies who have chosen the drupal framework recently.
All the links are to the Drupal sites.

1) FedEx : A very well known express delivery company


2)The United Nations : A site that supports and inspires people from around the world to take action in support of the Millennium Development Goals.


3) Nike : A well known sports site with a large database


4) Warner Brothers Records : A huge site with a very different Theme for drupal.


5) Freshbrain: A safe enviroment for high school students [where they ] will be able to do activities and projects using our state of the art platform, tools, training and with the support communities and advisors!


6) Team Sugar : Womens social network and community


7) Lifetime TV : massive Drupal site with a movie database,television schedule, videos,photos, editor-produced articles,
user-produced stories, games, tag clouds, topic-based search, and beautiful theme.


8) Project Opus : Local music community.Music events and people where you live; free music hosting and play list.


9) Adrenaline Hub : The action sports community site with news aggregation and video upload.


10) SonyBMG : Britney Spears Blackout Magazine: Videos, events, photos,Lyrics etc.

Monday, January 26, 2009

Drupal's File Download

10 things about file download in drupal:

1. The problem : Using Drupal’s in-core upload module, and no “node access control” contributed module, anonymous users can either download all files attachments, or none of them. The trick : in the case where anonymous users are forbidden access to uploaded files, automatically generate a message to inform them that one or more files are attached to a post. Involves : modifications to node.tpl.php and the use of Drupal’s function format_plural(). This section provides sample code safe to copy from the pdf to your template file in your favorite text editor. download permission

2. The problem : Drupal’s core upload module does not keep track of file downloads, even when the download method is set to private. The trick : install the contributed module download_count. This module writes a descriptive message in your logs whenever a person or robot is attempting to download an attached file. The module also keeps a record of total download hits, and last download time, to display on a dedicated page and in nodes (to which these files are attached). In your tracking of file downloads, you can chose to disregard file attachments with particular extensions. download statistics

3. This third point explains when, why and how to use the hook function file_download. Using this function, we can :
* Keep track of file downloads — and this section tells us what files the function can do bookkeeping of.
* Allow files that aren’t recorded in the upload module’s table {files} to be downloaded by returning an appropriate HTTP header for them.
* Block the download of particular files of our chosing.

This section provides two code examples : one in which we allow the download/display of an image that sits outside the web root, and an other in which we allow the download of any file through an “open or save to disk” prompt. module development

4. This point describes 5 Drupal functions to use when dealing with file download :
* file_directory_path()
* variable_get('file_downloads')
* file_create_url($relativepath)
* file_create_path($relativepath)
* theme_image() should be called through the rooter function theme()

The section explains when to use these functions and what to expect from them. It also provides sample code. file path

5. This section explains how to use private download — and why we should use the ../privateFolder notation when specifying our File System Path. File System Path for private download.

6. Challenge : we need to change when and how the attachment table is displayed. The solution : we use the themeable function theme_upload_attachments($files) to print the table in node.tpl.php — hence printing the value returned by theme('upload_attachments', $files) — or we override that function in template.php. This section provides sample code, and it reminds us of the difference between the variables $teaser and $node->teaser in the template file node.tpl.php : $teaser is a boolean, TRUE if we are to display the teaser as content, while $node->teaser is the content of that teaser. attachment table

7. What we should know about uploading two files with the same name when using the Drupal core upload module. filename versus filepath.

8. This section explains what hot linking is, and presents 3 different methods to try and prevent it. However, I only recommend the first method, and explain why the others are flawed (these others use the value $_SERVER['HTTP-REFERER']). leaching

9. The problem : when clean URLs is enabled, we cannot use relative paths to files and images in our html markup. This problem has been discussed on Drupal.org. There are at least 4 solutions to this problem :
* Use an absolute path, possibly resorting to a subdomain or a virtual host.
* Use the contributed filter module pathfilter, which has been ported to Drupal 6.
* Set the input format to php and use the function base_path().
* Set the input format to php and use the function file_create_url() — when the file we want to link to is inside the File System Path.
relative versus abolute path with clean URLs

10. This section provides a recipe to scan directories for particular files using the Drupal function file_scan_directory. It provides sample code on how to pick a random image from a folder and all its subfolders. scanning the file system path folder.

Thursday, January 22, 2009

Optimizing Drupal database

There are two easy ways to optimize the tables in your Drupal database.
The easiest way is to install the DB Maintenance module. Information on how to install a Drupal module is available in our Drupal tutorial.
After the module is installed and activated, you can access it from your Drupal admin area > Administer > Site configuration > DB maintenance. Select the tables which you wish to optimize and click Optimize now.

The other, slightly more complicated way, is to create a php script with the sql query. The code you should include in the php file should be similar to this:

$db = mysql_connect('localhost','user','password');
if(!$db) echo "cannot connect to the database";
mysql_select_db('user_drpl1');
$result=mysql_query('OPTIMIZE TABLE accesslog,cache,comments,node,users,watchdog;');
echo mysql_error();
?>

Change user, password and user_drpl1 to reflect your Drupal MySQL username, password and database.
This will optimize the tables accesslog, cache, comments, node, users and watchdog. Feel free to add or remove tables from the query.

Once you have inserted the code, save the file. For the purposes of this example, we'll assume that the file is called optimize.php. Once the file is saved in your Drupal folder, you can execute it directly from a browser:
http://www.yourdomain.com/drupal/optimize.php
If you get a blank page without any errors, this means that the tables have been successfully optimized :)
You can also set a cron job in order to execute the optimization script at regular intervals. The cron job you set should be similar to this:

php /home/user/public_html/drupal/optimize.php

Make sure you don't set the cron to be executed too often. Once a week should be more than enough to keep your tables optimized

Friday, January 16, 2009

Simple Test Module - Drupal

Drupal is currently lacking a test suite to be run by developers before submitting important patches. The simpletest module shows some great promise but it is unfortunately not widely adopted yet and there aren't many tests written. See here for a tutorial on how to write tests for your module.

The following setup isn't really a test suite but it is a start to avoid the most embarrassing errors.

Proceed as follows:

1. Enable the menu module and disable the 'log out' link.
2. If you have the image module installed, enable the image module and set permissions so images can be written for the userid running the link check. This will avoid image creation errors when crawling with image enabled.
3. Run
wget --mirror --delete-after http://example.com/

where example.com is your development site. This command will crawl your site very quickly which can put a large stress on the site. You can add --wait=5 to the options if you don't want to perform the stress test.
4. If you want to test as an authenticated user you first should login to the site using a browser and get the authenticated cookie. Then do
wget --mirror --delete-after --load-cookies=/path/to/cookies.txt http://example.com/

where /path/to/cookies.txt is the cookie for your site inside your cookie directory. The exact location of this cookie depends on which browser you are using.
5. You can repeat for each of your roles on your site, and look for errors users with different roles might experience.

Note that this can take some time. wget will access every Drupal page linked from anywhere on your site. You can later have a look at the error logs and find out if any errors where caused. This will not test submitting forms. You can test submitting forms through simple test module.

Wednesday, January 14, 2009

Drupal - Like or Dislike

The review written by Justin James for Drupal is in an article titled, A product review of the Drupal Content Management System, does it make the grade? The author states that "Drupal does not make the grade". He bases his opinion on issues with usability and ease of installation. With regards to usability he says:

Drupal fails on these measures. There were links to create content, which I happily followed. I was immediately presented with an interesting dilemma: do I want to create a "page" or a "story?" The system explained that a "page" is for something like an "About Us" page, and a "story" contained content like a blog. This did not make any sense to me...Every other system I have used (that I can recall) lets you define a particular "page" as a blog, and then just add content to the blog.

I decided to try to make a "page." I was confronted by a plain area to enter text, with no WYSIWYG editing capabilities. I actually considered this to be good, because I have had so many problems with Web-based WYSIWYG editors. However, less than advanced users will be pretty helpless putting content into Drupal.

Ouch! The author also concludes that "Drupal may be a decent choice for an ISP, but its difficult installation, lack of simple on-line content management, and failure to provide asset management make it too hard to use for the average user for anything above and beyond basic site creation." Double ouch!

Most of my early complaints centered over some of the "special" privileges needed when accessing the MySQL database. Database privileges such as LOCK TABLES are not provided by all host providers. There are time when potential Drupal users talk about what they don't like about Drupal. Instead of acknowledging the user's remarks may have validity, there were those that who replied with what. Their simple reply would be that "Drupal isn't for everyone".Drupal's strength is understood not with the first impression it gives users, but with the final impression it leaves users. IBM's project development series involving Drupal and other open source projects should become a good read and the start of some great discussions ahead.

Tuesday, January 13, 2009

Create Link From Drupal To Moodle

This assumes that a) you have CCK and Computed Field installed

First, give every DrupalEd course an automatic alias that is the same as your Moodle short-course name. (Yes, right now, we have to do that by hand. That needs to change eventually.)

Then, in Content Management -> Content Types -> Course -- create a new field called field_moodle_link (or something like that) and select Field Type -- Computed and create the field.

In the next page that pops up, fill in the Label with whatever you want the label to be on the Drupal Group page. Then I chose "Required" under data settings, but I'm not 100% sure that's necessary. And under Computed Code, enter this:

$db = mysql_connect("", "", "");
mysql_select_db("",$db);

#Enter base moodle website here
$website = "http://www.yourwebsitehere.org/moodle";

$nodepath = "node/";
$nodepath .= arg(1);
$shortname = drupal_get_path_alias($nodepath);

$query = "SELECT id,fullname from mdl_course where shortname='$shortname'";

# Standard debug test
# print("
$query");

$idquery = mysql_query($query);
if ($idarray = mysql_fetch_array($idquery))
{
$id = $idarray["id"];
$fullname = $idarray["fullname"];
$node_field[0]['value'] = "
$fullname";
}
else
{
$node_field[0]['value'] = "No Moodle Course w/ shortname: $shortname";
}
?>

Make sure "Display this field" is checked, and I use this as my display format:

$display = $node_field_item['value'] . "

";

And then save it.

Once it's saved, click "Manage Fields" and make sure that your new field has a lower numerical value than the Highlighted Content Field, so that it's at the top of the Drupal page.

Drupal Data Migration Services

Standard Data Migration into Drupal

If your moving from one technology to another one of the hardest areas to get right is the data migration. We have years of experience in migrating data from old systems into Drupal. Frequently we find that we are requested not to merely migrate from data from one application to Drupal but from multiple applications, this is where our knowledge and expertise in data architecture really come into play. We can take the headaches our of even the most complex data migrations.

Drupal SEO Website Migration / upgrades

It is imperative that you understand that moving from website technology to another that you don't lose your current SEO value. Many companies plough ahead and change their sites making what they think are great SEO improvements, but actually damage their position in Google and other Search engines by not doing the move properly. We have migrated countless sites without losing any of the existing search positions and still gaining by improving the seo.

Saturday, January 10, 2009

PHP Zend

Zend Platform is the only PHP Web application server for that supports the enterprise reliability and comprehensive performance features organizations need for business-critical applications. Platform PS provides the performance and management functions needed for every PHP deployment. Platform ES is the ultimate PHP solution incorporating enterprise-grade functionality for multi-server environments.Today's Web applications deliver diverse services including static content and rich media. By providing a multi-layered approach Zend Platform lets you easily optimize your application, according to the services you provide. Code acceleration, content caching, download optimization and configurable off-line processing capabilities give you the maximum performance options needed to get the most out of your business-critical applications.

Thursday, January 8, 2009

Drupal 6 Theme Registry

Drupal's theme registry maintains cached data on the available theming hooks and how to handle them.

For most theme developers, the registry does not have to be dealt with directly. Just remember to clear it when adding or removing theme functions and templates. Editing existing functions and templates does not require a registry rebuild.

To clear the theme registry, do one of the following things:

1. On the "Administer > Site configuration > Performance" page, click on the "Clear cached data" button.
2. With devel block enabled (comes with devel module), click the "Empty cache" link.
3. The API function drupal_rebuild_theme_registry.

The theme registry is cached data instructing Drupal on the available theming hooks and how to handle it by indicating its type. In previous versions all theming calls were handled on the fly. Since a lot more work is being done under the hood, the cached instructions speeds up the process especially for templates. The theme engine your theme is running under should automatically register all the theming hooks for you.

There are special cases where you may need to work with the registry directly. When your theme requires a new hook to be registered that was not already implemented on the layers below it (core, modules, engine). This includes some forms when they are not explicitly themed by core or modules but instead rely on the default form presentation.

* More details can be found in the sub-page, The theme registry for special cases.
* Do not confuse the theme registry with the theme's .info file which is also cached. Points 1 and 2 on clearing the registry will clear both.
* Your theme must be using phptemplate engine for the for its templates and functions to be discovered. Other engines should behave the same way. For engineless themes, it must be done manually. See phptemplate_theme to see how it is done.

Wednesday, January 7, 2009

Theming Drupal primary links with child sub-menus

Using 'Primary links' for your Drupal site's main navigation menu is a great idea. However, most themes by default display primary links in such a way that if the menu has sub-child menus, they will not be displayed. Fortunately, the solution is much easier that you'd think.

First off, the way that most themes generate primary links is like so:
theme('links', $primary_links);
As mentioned, this will only output the top-level menu items, like so:

  • Menu Item 1

  • Menu Item 2

  • Menu Item 3


That's not very useful for sites with a robust navigation tree.

To get around this, the simplest way is to remove the original theme() function outputing the primary links, and create a new region in your template where you'd like your navigation menu to show up. Then, you can assign the 'Primary links' block to that region, and the entire menu tree will be displayed there.

To create a region in Drupal 5:

You'll need to modify your theme's template.php file. If it doesn't yet have one, create it, and enter the following:

function name_of_theme_regions() {
return array(
'name_of_new_region' => t('name of new region'),
);
}

To create a region in Drupal 6:

In your theme's '.info' file, you'll need to define your new region. Put something like this:
regions[name_of_new_region] = name of new region

Be sure to replace 'name_of_theme' with the name of your theme, and 'name_of_new_region' with the name of your new region.

Outputting content of the new region

The key of the array item (or value in between brackets for Drupal 6) will be used as the variable name in your theme files, like '$name_of_new_region'.

The value of the array item (or value to the right of the equals sign for Drupal 6) will be used as the title of the region on the '/admin/build/block' page.

In your page.tpl.php file, output the content of the region like so:


Then, head over to '/admin/build/block' and set the 'Primary links' block to the region you just created.

Tuesday, January 6, 2009

Best Practices - Drupal 6

If you are going to invest the time to set up a CMS, then you should protect your investment by following some simple best practices. These guidelines are only suggestions. It is up to you to decide what is appropriate for your site.

The following list contains some quick pointers (for more detailed information, see the list of articles at the bottom of this page):

* Plan your site. Drupal provides a good toolset to help you build your site but you still need to plan. Good wireframes and proper planning can avoid significant misunderstandings and problems later.
* Plan for the future. You should revisit and reevaluate your site each time there is a major version release of Drupal. This does not mean you have to upgrade it, but you should evaluate and plan for an upgrade approximately each 12-24 months.
* Get involved in the community. This will help you follow development trends and, while helping others, you may just come across a cool idea that solves your own problem.
* Back up your site. Back up both the database and the files on the web server. Test your backups! If you don't test them, you have no idea if you are doing it right.
* Test your PHP snippets. Drupal gives you a great deal of power and flexibility when using PHP code in blocks. Unfortunately, a stray character or a missing semi-colon breaks PHP. Drupal then attempts to evaluate this broken code on any requested page, the PHP interpreter chokes on it and therefore your whole site is broken. Fortunately, there is a very simple and easy solution. Instead of writing and testing your code inside the administer > blocks page, go to create content and create a new story or page node. Use PHP input format, write the code, and the Preview to debug your code. When you are satisfied that your code is working, copy and paste the code into the block.

mktime in PHP

mktime -- Get Unix timestamp for a date

Note the strange order of arguments, which differs from the order of arguments in a regular Unix mktime() call and which does not lend itself well to leaving out parameters from right to left (see below). It is a common error to mix these values up in a script.

Returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970) and the time specified.

Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time.

is_dst can be set to 1 if the time is during daylight savings time, 0 if it is not, or -1 (the default) if it is unknown whether the time is within daylight savings time or not. If it's unknown, PHP tries to figure it out itself. This can cause unexpected (but not incorrect) results.

Note: is_dst was added in 3.0.10.

mktime() is useful for doing date arithmetic and validation, as it will automatically calculate the correct value for out-of-range input. For example, each of the following lines produces the string "Jan-01-1998".

Example: mktime() example


echo date("M-d-Y", mktime(0, 0, 0, 12, 32, 1997));

echo date("M-d-Y", mktime(0, 0, 0, 13, 1, 1997));

echo date("M-d-Y", mktime(0, 0, 0, 1, 1, 1998));

echo date("M-d-Y", mktime(0, 0, 0, 1, 1, 98));

?>

Year may be a two or four digit value, with values between 0-69 mapping to 2000-2069 and 70-99 to 1970-1999 (on systems where time_t is a 32bit signed integer, as most common today, the valid range for year is somewhere between 1901 and 2038).

Windows: Negative timestamps are not supported under any known version of Windows. Therefore the range of valid years includes only 1970 through 2038.

The last day of any given month can be expressed as the "0" day of the next month, not the -1 day. Both of the following examples will produce the string "The last day in Feb 2000 is: 29".

Monday, January 5, 2009

Drupal and CVS

CVS is how Drupal developers manage code. It is a tool for managing the revisions and releases of a software project that is being developed by multiple people. In such a project, each developer will create one (or more) separate copies of the code, then make local modifications to fix bugs or add features. After debugging this modified code, the developer uploads it to a server, where it is merged with the other developers' modified code to create the next release of the software. Often, two or more developers will modify the same module at the same time, which creates a big problem when they try to combine their work. It is very easy for one of them to unintentionally overwrite the other's changes.

CVS helps to manage this problem by maintaining a central code repository -- a directory on the CVS server that contains the definitive archive of a project's code, as well as a complete history of that code's development. You can use CVS to download a local copy of the code -- either the very latest version (which is often called HEAD, and is typically very unstable), or one of the earlier, stable versions (which are labelled with tags to identify them). When other developers change the code, CVS can download those changes and update your local copy.

When project maintainers make changes they wish to share, CVS is used to upload and commit them. If your changes threaten to overwrite those of another developer, CVS will warn you and give you a chance to resolve the conflict. And when you make a mistake, CVS can help you recover: you can read a complete log of all the changes to the code since the project began, retrieve versions of files from any time in the past, and generate patch files that summarize the difference between any two versions of the code.

In addition, CVS helps developers stay up to date on the state of the project. For example, the Drupal CVS server will email all CVS commits to all maintainers, automatically informing them of the work you have done.

Drupal and PHP

Drupal 7 and PHP 5.2

Drupal has long prided itself for staying ahead of the curve technologically. In order to be able to write the best quality Drupal software, Drupal developers need the best programming tools available. Today, the best PHP available is PHP 5.

PHP 5 has been deployed and tested in production environments for three years. Unfortunately, web hosts have been slow to adopt PHP 5, which has made it difficult for Drupal and many other PHP projects to fully embrace PHP 5's features.

Now a growing consortium of PHP projects have joined together and push for wider PHP 5 adoption. By all embracing PHP 5 together, the projects involved in the GoPHP 5 effort are sending a message to web hosts that it is time to embrace PHP's future.

Drupal is now part of that movement.

After much deliberation, the Drupal project is committed to the following path:

* As of Drupal 7, changes to Drupal which use language features found exclusively in PHP 5.2 will be considered for acceptance into Drupal core.
* This policy effectively means that Drupal 7 will be incompatible with PHP 4.

The Drupal developer community agrees that this change is best for the future of Drupal. We are excited by the potential that PHP 5 brings, and we look forward to building better software for the community.


Drupal 6 and PHP 4

The upcoming Drupal 6 and all current Drupal releases will remain PHP 4-compatible for as long as they are supported.

In Drupal 6, contributed Drupal modules and themes may declare their PHP version compatibility. Contributed modules can only be installed on systems that support the required PHP version. This change will allow developers to leverage PHP 5 features without breaking existing Drupal sites. This feature will let Drupal users evaluate the advantages of moving their sites to PHP 5.