Gregory Go's blog

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 Watermark Images Using ImageMagick (composite) on the Command Line

These instructions are for watermarking images on the command line using the ImageMagick command "composite".  So you'll need to have SSH access to your images.  (To watermark images off-server -- ie., on your desktop in Windows -- check out this list of programs.)

1. Create a PNG watermark image

Using PNG, you can avoid distortion of the watermark when its composited

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. 

Extend 2WIRE wireless range using a Linksys WRT54G-TM

This article provides a step-by-step guide to extending the wireless network range of a 2WIRE DSL/cable wireless modem, using a Linksys WRT54G-TM. The important bits: * The router connected to the internet is the 2WIRE DSL modem that was provided by AT&T. It is a popular wireless modem that DSL providers give to their customers. The problem with the 2WIRE modems is their weak signal strength. [Note: If you just want to try to boost the signal strength of your 2WIRE modem, go to the administration screen and change the. Using a web browser connected to your network, go to the Web based admin panel of the 2WIRE. I found this at http://gateway.2wire.net. You can also try the default IP address of the 2WIRE modem -- http://192.168.1.64. Under the "Wireless Settings" screen, look for the option called "Power Setting". My 2WIRE defaults to a setting of 4/10. You can increase it to see if it helps extend your wireless network range. Note that this doesn't do anything about the 2WIRE being able to receive transmissions from a weak wireless card on a faraway laptop. The power setting only applies to the transmitting (sending) power of the 2WIRE.] The problem: The 2WIRE's wireless signal sucks. The wireless signal is extremely flaky beyond 60 feet or so. I want to extend it to the offices next door -- about 120 feet from the router, past metal shelving and one concrete wall. The solution: Repurpose an unused Linksys WRT54G-TM router as a second access point to the wireless network. So the end result is one unified wireless network, using two access points. You basically have to connect the 2nd router (Linksys) to the 1st router, then disable the router functionality of the 2nd router. Step-by-step Instructions: 1. Using an ethernet cable, connect the Linksys WRT54G-TM to the 2WIRE. DO NOT use the internet/uplink port. Use a regular LAN port on both sides of the cable.

Strange permission problems with vBulletin? Try rebuilding the bitfields

Problem 

Very strange permissions issues in vBulletin.

Solution 

Rebuild the bitfields by going to /admincp/index.php?do=buildbitfields

Discussion

On a new board that I was configuring, it somehow got into a weird state where the users in the Administrator usergroup had missing moderation options. In the Moderation pulldown (and in the Thread Tools pulldown), only a few of the moderation action choices were available.

I was pretty damn sure it was not a configuration issue, having triple- and quadruple-checked permissions, and creating test users from scratch. I was going crazy with frustration until I ran into this forum post that introduced me to rebuilding bitfields. Bitfields are rebuilt when products are added or removed.  Sometimes the process doesn't work perfectly.

So if you run into a crazy permissions issue that you're pretty darn sure is not a misconfiguration, try rebuilding the bitfields.

(This was for VB ver. 3.6.8)

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 fix vBulletin login problems

Update 2007/8/3: Actually, it was the enabling of mod_expire in the new .htaccess that was causing all the issues. Turned off mod_expire and things got back to normal. The following is still an interesting stroll through vBulletin cookies. Users reported VB forum issues starting today. We're using vBulletin 3.6.4. (We upgraded our Drupal installation for the same domain to 4.7.7 last night, so this is likely related to that. The .htaccess file seemed like a likely culprit, but it looked okay to me. After a little searching on vBulletin login issues, the following fixed the problem.) The problem: Can't login -- immediately redirected back to login page. Not credential error. Already logged in users reported session related weirdness -- posts not showing up for some users and/or forum index info mismatch with actual forum posts. The fix: Reset cookie domain to "blank" (was: ".wisebread.com") and cookie path to "/" (was "/"). Try this if your users are having login problems Things to try when users have problems logging in to a vBulletin forum (via this vbadvanced.com post): Ask users to clear cookies and restart browsers. This is really only appropriate for isolated incidents. In our case, the problem was reported by multiple users on the same day, so we tried solutions #2 and #3. As a forum admin, reset the cookie domain and path to defaults. You can find these settings at: Admin CP -> vBulletin Options -> Cookies and HTTP Header Options Cookie Domain: blank

How to send SMS messages by email

You can send SMS messages to mobile phones by email. Every major carrier also has their own email domain.
  • AT&T: 1234567890@txt.att.net
  • Nextel: 1234567890@messaging.nextel.com
  • Sprint: 1234567890@messaging.sprintpcs.com
  • T-Mobile: 1234567890@tmomail.net
  • Verizon: 1234567890@vtext.com
  • Virgin: 1234567890@vmobl.com
Use the full number, including the country code. And keep it to 160 characters. The T-Mobile works great. I use it to get text messages whenever the web server gets automatically restarted due to some problem. Works a little too well, if you know what I mean.

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.

Enable activeCollab debugging to prevent WSOD

I got the dreaded white screen of death (WSOD) for our activeCollab installation today. I moved the hosting for this site yesterday, so it's probably related to that. I just had no idea what the problem might be. No errors on the screen, nothing written to the apache logs. Damn. This is going to be a pain to track down.... (If you didn't know, activeCollab is basically a free open-source version of Basecamp. You have to install it on your own server, but it does a pretty damn good job of mimicking the functionality of Basecamp.) After searching around the activeCollab website, a user mentioned "turning on error messages in the config file". That was the key hint I needed. Here's the fix. Look for this line in your config/config.php file: define('DEBUG', false); Change "false" to "true" and you get debugging messages printed to the screen. The problem was clear as day once debugging was turned on. The error message mentioned not being able to access a certain file. The path to the file was pointing at the old server setup. I figured the old path was hard-coded into some config files during setup, but I had no idea which files needed fixing. To find the offending config, I ran a find and xargs. (Run this from your ssh shell.) find ./ac -type f | xargs grep oldpath This command says: find everything in the "ac" directory that is a file, then grep through each file to find a mention of "oldpath", and print the results. Turns out I needed to update cache/autoloader.php. This file contains hard-coded paths to various AC scripts. They were still pointing to the old paths. A simple search-and-replace of the old path with the new path, and our install was back in action.
Syndicate content

luigi