Print module customization

Tested on: Drupal 5.7, Print 3.4

Drupal Printer Friendly module (Print) add “print this” functionality to nodes. Customization is pretty easy: according to README file you can add a print.tpl.php to your theme (or subtheme) directory and modify it. All override templates are (in check order):

  1. print.__node-type__.tpl.php in the theme directory
  2. print.__node-type__.tpl.php in the module directory
  3. print.tpl.php in the theme directory
  4. print.tpl.php in the module directory (supplied by the module)

You can copy the default print.tpl.php in module directory (4) to one of the 1-3 destinations files, then customize it. You can also use variables like $node->changed to enrich your template. You can read the dynamically generated list by Content Template module, if you have installed it.

DVD to video sharing under Linux howto

I have some DVD to publish on a popular video sharing service on the web. How to do that on Linux? Here a simple howto to achieve this.

First, get some useful software for this task. To do this you should sometimes add the Debian Multimedia repository to your /etc/apt/sources.list:

deb http://www.debian-multimedia.org etch main

Where “etch” is your distribution. Then run:

apt-get update

On sudo / superuser shell run:

  1. apt-get install avidemux acidrip lame x264 mplayer vorbis-tools dvdbackup
    Avidemux is a simple cut-and-paste non-linear editor and encoding software, acidrip a DVD-to-file ripper. X264 is a video encoder for the H.264/MPEG-4 AVC standard, lame an MP3 encoder and vorbis-tools contains OGG Vorbis encoders (a libre audio library).
  2. If you want to rip directly a DVD, encoding it as you wish without changes (cut and paste) from chapters, then use acidrip. For video use X264, for audio choose MP3 or Ogg Vorbis. (howto ends here)
  3. If you want to apply some changes, then first backup your dvd with dvdbackup:
    dvdbackup -i /dev/dvd -o my_destination_directory/ -n myDVDtitle -M
  4. Open the first huge .VOB file (eg. VTS_01_1.vob) with avidemux, then choose YES for indexing it
  5. Now you can export the whole file or part of it: choose x264 as video codec and Vorbis or Lame (MP3) as audio codec. Leave AVI as Format (or choose another).
  6. If you want to extract a portion of the video, move cursor to first frame of the selection and click A (Selection Start). Then go to last frame of the selection and click B (Selection End)
  7. Click to File -> Save Video to export the selected portion (read Avidemux wiki to more and detailed options). If files are compatible in width x height you can also use the “Append” function to queue more files generating and exporting a bigger one.

Now you can upload your video to popular online file sharing services. Enjoy!

Add to Bookmark / Favorites on Drupal

Tested on:

  • Drupal 5.x
  • Zen theme

On your page.tpl.php, change default node links rendering with this:

<?php if ($links): ?>
<div class=”links”>
<?php
# add to favorites / bookmarks link
$node->links['add2fav'] = Array(
‘title’=>trim(t(”Add to favorites”)),
‘href’=>$_GET['q'],
‘attributes’=>Array(
‘class’=>”add2fav”,
‘onclick’=>’bookmark()’,
)
);
# intercept and theme node links
print theme_links($node->links);
print ‘<script type=”text/javascript”>// <![CDATA[
function bookmark(){
var url = window.document.location;
var title = window.document.title;
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
window.external.AddFavorite(url,title);
} else if (navigator.appName == "Netscape") {
window.sidebar.addPanel(title,url,"");
} else {
alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
}
}
// ]]></script>’;
?>
</div>
<?php endif; ?>

Now any node has your “Add to favorites” link, try to click it.

If you wrap alert message in a t() function, you can also translate displayed message.

See also:

Image rollover on primary links Drupal howto

Tested on:

Do you remember my Customize links menu in Drupal mini-howto? You can use it to change text links in image links renaming and customizing theme_links function (from theme.inc) and adding it to your template.php.

On your template.php file, you have something like this:
$imglink_path = path_to_theme() . “/my_zen_subtheme/menu/” . str_replace(” “,”_”,strtolower($link['title']) . $imgsuffix . “.gif”);
$imglink = theme_image($imglink_path, $alt = $link['title'], $title = $link['title'], $attributes = NULL, $getsize = FALSE);
if(empty($imglink))
$imglink = $link['title'];

  1. Search for images in a defined folder by link title: if link title is “My Nice Link”, a “my_nice_link.gif” image is used.
  2. Generate HTML code for “my_nice_link.gif”. Note: getsize is set to FALSE to avoid errors on rollover
  3. If Drupal cannot generate HTML code for image (e.g. file not found) link is rendered as plain text

If you want to add a rollover effect on primary links images, you have to add this JQuery javascript code on page.tpl.php:

<script type=”text/javascript”>// <![CDATA[
$(document).ready(function()
{
$("#primary a").mouseover(function ()
{
$rollsrc = $(this).children("img").attr("src");
$matches = $rollsrc.match(/_active.gif$/);
if (!$matches) {
$rollON = $rollsrc.replace(/.gif$/,"_active.gif");
$(this).children("img").attr("src", $rollON);
}
});

$("#primary a").mouseout(function ()
{
$(this).children("img").attr("src", $rollsrc);
});
});
// ]]></script>

Where “_active” is the rollover image.

See also:

Netgear WG111 on Debian Lenny with ndiswrapper

Tested on: Debian Etch, Lenny/Sid (Testing), kernel 2.6

  1. Plug WG111 and type lsusb to verify hardware is plugged. You should get something like:
    Bus 003 Device 002: ID 0000:0000 NetGear, Inc. WG111 WiFi (v2)
    Bus 003 Device 001: ID 0000:0000
    Bus 001 Device 001: ID 0000:0000
    Bus 002 Device 001: ID 0000:0000
  2. On root shell, type:
    m-a prepare
    m-a a-i ndiswrapper
    modprobe ndiswrapper

    Now ndiswrapper module is loaded. (if you got a FATAL: Module ndiswrapper not found fatal error, repeat these steps)
  3. If interface is successfully modprobed, then type
    update-modules
    To create ndiswrapper module config files.
  4. Add
    ndiswrapper
    to /etc/modules to load this module on boot.

  5. apt-get install module-assistant wlassistant ndisgtk ndiswrapper-utils
    Install some utilities to configure wireless interface.
  6. Run ndisgtk (or type ndiswrapper -i /media/cdrom0/ndis5/netwg111.inf, where cdrom0 is Netgear driver disc)
  7. Select Netgear driver from CD-ROM (netwg111.inf): it’ll be copied automatically to /etc/ndiswrapper
  8. Copy other files under /media/cdrom0/ndis5 in /etc/ndiswrapper/netwg111/
  9. If interface is not detected, type ndiswrapper -m to write modprobe config files for it.
  10. Use gksu network-admin or gksu wlassistant to configure your wireless connection.

Tip: If after system upgrading you cannot access to wireless network, repeat step (2).

See also:

Translate Drupal block titles

A simple snippet based on theme_block() and t() functions. (Tested on Drupal 5.x, Zen subtheme).

  1. Copy and paste this code into your template.php:

    function zen_block($block) {
    $output = “<div class=\”block block-$block->module\” id=\”block-$block->module-$block->delta\”>\n”;
    $output .= ” <h2 class=\”title\”>”.t($block->subject).”</h2>\n”;
    $output .= ” <div class=\”content\”>$block->content</div>\n”;
    $output .= “</div>\n”;
    return $output;
    }

  2. Go to admin/settings/locale/string/search and search the title to translate from English to your localization language.

Add CSS class to drupal form fieldset

Tested on:

  • Drupal 5.x
  • Zen custom subtheme

Customizing Drupal form appearance may sound difficult. But to add a CSS class is (surprisingly!) simple using theme_fieldset themeable function.

  • Copy theme_fieldset code from Drupal manual page
  • Paste to your template.php:
    • If you’re using a Zen theme, change theme_fieldset to zen_fieldset. You can try to use this method with your theme prefix.
    • If you’re using a theme based on phptemplate engine, you can change theme_fieldset to zen_fieldset to have the same effect of above (try one of this, not both).
  • Change the resultant code as you wish.

I’ve attached an example to generate CSS class from fieldset title: Add CSS class to drupal form fieldset.

# custom fieldset CSS class from element #title
$css_class = “my-custom-class-”;
$css_class .= str_replace(” “,”-”,strtolower($element['#title']));
# using transliteration module to transliterate/strip non-ASCII character where available
if(module_exists(’transliteration’)){
# including Transliteration functions
require_once(drupal_get_path(’module’, ‘transliteration’) .’/transliteration.inc’);
$css_class = transliteration_clean_filename($css_class);
}

Adding this code to your template:

  • Take all Drupal generated fieldset title
    • e.g. “Impostazioni del menù”
  • Transform it in a CSS class using Transliteration module
    • e.g. “my-custom-class-impostazioni-del-menu”
  • Queue it with other CSS classes (where available)
    • e.g “collapsible my-custom-class-impostazioni-del-menu”

I apply a previous substitution of whitespace using “-” (transliteration module use underscore “_”) and you can do the same, but later remember to use transliteration_clean_filename to safely sanitize class name for any other case you’ve not contemplated (accents, special characters).

Customize links menu in Drupal

Tested on: Zen theme, Drupal 5.7

  1. Copy function theme_links from includes/themes.inc
  2. Paste it into your template.php
  3. Rename it in theme_primarylinks (or anything you want)
  4. In your page.tpl.php, change
    1. print theme(’links’, $primary_links);
    2. to print theme(’primarylinks’, $primary_links);
  5. Apply some changes to theme_primarylinks to customize your primary links.

According to theme manual, for any first argument passed to theme function a theme_functionname function is called.

Contemplate and views: create a link without $node->path

In contemplate and views, $node->path return current page path. But this variable is only available to users with “administer alias” permission, so as administrator you can view links, but as normal user you cannot use them.

Here a $node->path alternative:

l(strip_tags($node->title),"node/".$node->nid)

Since $node->title is raw input, strip_tags strips all HTML tags.
A node/$node->nid links to article. Drupal link function returns the (in case) aliased path.

Enable user profile field token on Drupal

Tested on:

  1. In token module directory, rename token_user.inc to token_user.inc.orig
  2. Copy pmail/patches/token_user.inc in  Token module directory
  3. Go to Personalized E-mails setting and watch your profile fields as tokens.

Next Page »