Web design, programming, graphics, and pretty much anything else I care about.

drupal

Apache rewrite for subdirectory-based Drupal multisite

In a multisite setup where there is a mix of sites based on subdomains, as well as subdirectories, the rewrite can be more complicated. Use this for the subdirectory based sites:

Errors running update with drush, backup directory

I kept running into errors when doing updates with drush on my web servers.

Restricting access to user profile

Here is a helpful little snippet to prevent a user from accessing their own profile page, or changing their password. This is useful for cases where people are using some kind of guest account, or shared account.

WebFM and mime types

WebFM calls the deprecated mime_content_type() function which returned the file type for MP4s as text/plain rather than video/mp4. The file /etc/httpd/conf/magic had to be modified by adding 2 lines:

4   string   ftypmp42   video/mp4
4   string   ftypisom   video/mp4

To verify that this worked:

echo "<?php echo mime_content_type('/mnt/video/PA/Walzer.hi.mp4'); ?>" | php

returned

video/mp4

(it returned text/plain before the change)

Drupal multisite configuration

Drupal can do the following:

www.example.com
site1.example.com
site2.example.com
www.example.com/site3
www.example.com/site4

All these sites can use the same Drupal installation. The key is to point all of them at the same index.php file, which is in the root of the Drupal installation. This requires either a symbolic link to connect a site sub-directory to the installation directory, or Apache modification to do it. Once the request is received by Drupal, it will know which site to retrieve. /smoke and mirrors

Drupal cookie domain

$cookie_domain = 'david.narrabilis.com';

Must be set in settings.php for FCKEditor's (CKEditor) file manager to work. Otherwise, you get a pop up error when you try to access it via the "Bowse Server" button. Like when trying to insert an image. Also, if this setting is incorrect, it can cause various things on a Drupal site to not work. For example, I could not log in to an otherwise functional site. When I tried to install another, with this misconfigured, the installation failed half way through with some mysql syntax error.

Retrieving custom field formats in Drupal template files

This is part of CCK:

<?php
content_format
('field_cckfieldname', $node->field_cckfieldname[0], 'machine_name_of_custom_format')
?>

You send it the name of the field you are referencing, the data, and the name of the format you want. If you don't include the format, it uses the default for that field. It returns fully-formatted HTML. Example,

<span class="date-display-single">Friday, October 16, 2009, at 8:00 pm</span>

Node reference URL widget not checking user access?

I seem to have a bug in the Node reference URL widget module (http://drupal.org/project/nodereference_url). It is not checking to see if the user has the correct permissions to create a node of the type being referenced. The link to create a node should not appear if they do not have access.

On this line

<?php
if ($field['referenceable_types'][$object->type] && user_access('create ' . $object->type . ' content')) {
?>

I replaced $object->type with $target_type and it seems to work fine.

<?php

WebFM icons

WebFM uses multiple methods for determining what type of file it is dealing with, and thus, what icon to display. When inserting a file into the database it used the php function mime_get_content to determine the type of file. If this function does not exist WebFM uses its own function to determine the mime type. This function is in the webfm_mime_types.inc file. Basically, it just goes by the file extension.