Drupal

How to format dates and times in Drupal

in

A couple of useful Drupal functions for formatting date and time. format_interval

$age = format_interval(time() - $node->created,1) . t(' ago');

The above outputs:

12 weeks ago

You second argument controls how many fields are outputted. If you passed "3" as the granularity option, then the output might look like:

12 weeks 4 days 16 hours ago

format_date

How to fix favicon.ico page not found in Drupal

in

Problem / Symptoms

Your Drupal 5.x or 6.x installation is throwing "Page not found" errors for favicon.ico.  (You can see this in Admin > Logs > Recent Log Entries > Page Not Found)

What's going on?

There is no favicon.ico in the Drupal root directory. 

Drupal's themeing system inserts the following line into your website's source.  This is why when you view your site, you see a favicon in your browser, even though there is no favicon.ico in Drupal's root directory.

<link rel="shortcut icon" href="/misc/favicon.ico" type="image/x-icon" />

But not everyone pays attention to the shortcut link in the page head section.  Some browsers (eg., on bookmarks) or websites (eg., del.icio.us) look for http://example.com/favicon.ico directly.  These requests result in a full Drupal bootstrap, only to have Drupal return a 404 and log the page not found.  Wasted resources.

What we want is to avoid Drupal altogether for direct requests for /favico

Solution(s)

A. Quickest fix for simple installations

If you're using Drupal for a single site, you can just upload a copy of your favicon.ico to your site's root directory. 

B. Multi-site installations

However, if you have a multi-site installation, dropping the favicon in the root directory will cause it to be used for all your sites.  That's no good.  To get around that, you can use the following rewrite rules to point requests for /favicon.ico to the real location. 

Adsense module hack - giving users credit on their user profile

in
The Adsense module allows you (the webmaster) to share revenue with content contributing users. You can assign a percentage to share with users. If you have the referral module installed, you can also give a cut to referring users. On the Killer Aces network, we want to give users credit on their profile pages as well. This requires a little theme hacking. How to give users Adsense credit on their profile page Step 1: Allow customization of the profile page Create a user_profile.tpl.php template file in your theme directory. Here's a basic user profile to get you started. The drupal.org handbook on customizing the user profile has a bunch of handy snippets. You'll need to add the following overriding function in template.php so the newly created user_profile.tpl.php will be used. /** * Catch the theme_profile_profile function, and redirect through the template api */ function phptemplate_user_profile($user, $fields = array()) { return _phptemplate_callback('user_profile', array('user' => $user, 'fields' => $fields)); } Step 2: Force the Adsense module to use the adsense_client_id of your choosing Insert the following code somewhere in user_profile.tpl.php. This overrides the default usage of the site's client id on the profile page. <?php if (module_exist('adsense')) { $uid = $user->uid; static $client; $client = adsense_get_client_id($uid,'blog'); } ?> Note: The above code was for Drupal 4.7. In Drupal 5.x, module_exist() becomes module_exists().

How to control teaser breaks with the TinyMCE editor in Drupal

The TinyMCE module comes packaged with the drupalbreak plugin. This TinyMCE plugin (not the Drupal module) adds two buttons that create a teaser or page break. (The teaser break is a built-in Drupal core feature. The page break requires the paging module.) The code to create these breaks is: <!--break--> <!--pagebreak--> 1. Copy the entire directory tinymce/plugins/drupalbreak into the plugins directory of the TinyMCE actual. (tinymce/tinymce/jscripts/tiny_mce/plugins/) % cd ~/public_html/drupalbase/ % cp -r modules/tinymce/plugins/drupalbreak/ modules/tinymce/tinymce/jscripts/tiny_mce/plugins/ 2. To add the break buttons to your TinyMCE profile, first insert the following lines to modules/tinymce/plugin_reg.php. Place them near the end of the file, just before you see return $plugins. $plugins['drupalbreak'] = array(); $plugins['drupalbreak']['theme_advanced_buttons3'] = array('drupalbreak', 'drupalpagebreak'); 3. Add the buttons to your TinyMCE profiles at admin/settings/tinymce.
Syndicate content

luigi