Blog

01/07/2010

i18n : Best practice

  • a. Install i18n module
  • b. Add all the required languages in admin/settings/language
  • c. Configure the “Language negociation” to “path prefix only” in admin/settings/language/configure
  • d. Configure the “Content selection mode” to “Current language and language neutral” and check the “Switch interface for translating” in admin/settings/language/i18n
  • e. Make some variables multilanguage by adding a few lines in you settings.php file :
    /**
    * Multilingual settings
    *
    * This is a collection of variables that can be set up
    * for each language when i18n is enabled.
    * These are the basic ones for Drupal core,
    * but you can add your own here.
    */
    $conf['i18n_variables'] = array(
    // Site name, slogan, mission, etc..
    'site_name',
    'site_slogan',
    'site_mission',
    'site_footer',
    'anonymous',
    // Different front page for each language
    'site_frontpage',
    // Primary and secondary links
    'menu_primary_links_source',
    'menu_secondary_links_source',
    'menu_default_node_menu',
    // Contact form information
    'contact_form_information',
    );

This is the reason why I checked the “Switch interface for translating”, so if you go to “admin/settings/site-information” or “admin/build/menu/settings” and switch the language you can change the Site information and menu per language.

To be sure, you should see “This is a multilingual variable.” next to each variable you put in the settings file.

i18n : Menus and primary / secondary links

After a lot of problems with i18n and primary links, I finally decided to read the i18n documentation from A to Z, and the solution was there at page 2.

See the complete documentation.

02/07/2010

Image handling

filesystem

public : /sites/default/files

every files are downloadable, they can be hidden via permissions but accessible through file system

private : /system/files

drupal control file download and show 403 if no permission


cck

imagefield D7core

Depends on filefield D7core :  ajax uploads

-> restriction on image : type / size / resolution
-> features : alt / title tags with tokens, default image
-> display : image, link, path, IMAGECACHE preset

further config / features

-> “full” gd library (not default on debian like)  or this link
-> uploadprogress install it with pear  [pecl install uploadprogress]
-> max file size (htaccess or php.ini) :  [post_max_size = 100M] and [upload_max_filesize = 2M] directive

imagecache D7core : presets on cck + views

Depends on imageapi D7core and gd library [aptitude install php5-gd]
call with [print theme('imagecache', 'imagecache_preset_name', 'original_image_filepath', "alt_tag", "title_tag", "custom_attributes_as_class_or_id"); ]

-> play with size, rotation, + effects – desaturate (bw conversion) – sharpening
-> create image on demand. if file doesn’t exist, image cache create it

imagecache_actions D7 ?

-> “layer style“  : Watermark (place an image over a source picture), Background, text overlay, canvas manipulation
-> colors : colorize image, invert, darken / lighten
-> feature : rounded corners, alpha blending, file format switcher

imagecache_profiles
imagecrop / imagefield_crop :  js resizing
imagefield_extended : Add additional data to images other than the default Description, Title and Alt.
image_fupload : upload multiple images with one simple click

bonus :

image integration with wysiwyg

wysiwyg D7ready + tinymce (see wysiwyg config) + imce D7ready + imce_wysiwyg bridge D7?
activate in “button and plugin” > imce (wysiwyg > tinymce config)

alternative to imce filefield_insert “use a cck filefield for uploading images and send the image to the RTE”

lightbox integration and plenty of gallery modules…

Multisite setup

The goal is to have a single drupal core to handle multiple sites / instances

1. installation

install drupal as usual

2. directory structure

inside site/ create a directory for each of your site named yoursitename.tld

inside yoursitename.tld create

  • directories for the specific modules and themes (you can then split it in contrib/ and custom/) + files
  • copy settings.php and adapt db site’s specific values
  • put the modules used by every sites (cck, pathauto, devel, admin_menu, …) in site/all/modules

3. virtual host

  • DocumentRoot is the same for every sites : that’s where your installation sits (/var/www/drupal6 for example)
  • ServerName is the name of your site (!), drupal will use it to map the name of your site.tld with the site/ directory structure

4. pros

  • update core / shared modules only once
    => you can create a script to run cron for all sites
  • quick creation of new sites

5. cons

  • on core issues, all sites are down…
  • high load of the server
  • you have to manually run update.php on every site (it can take times when a site may be + – down)

more info on drupal’s website

6. sharing databases / tables

it’s possible to share data between sites.

example: if you want sitea and siteb using the same users, but with different content, you will have

  • 3 databases for the 2 sites, (1 for content sitea / siteb, 1 for shared tables)
  • shared tables (users, sessions,…) must be have the prefix of the shared database in settings.php / Database area ( shared_db. with . for sql join)
  • a default prefix (indicated only once) for other tables
  • $db_prefix = array( ‘default’ = ”, ‘users’ = ‘shared_db.’, ‘role’ = ‘shared_db.’, ‘sessions’ = ‘shared_db.’, );

  • to permit a same user login on sitea AND siteb, install single sign on module

note : it’s also possible to have only 1 databases with same prefixes for common table and different prefixes for the other ones (this time prefix without . ’cause we use the same db)

more info on drupal website

note : you can also take a look, at this video with interesting server settings

=> an other interresting module (not tested yet) : Domain

Concat multiple rows in one

I will take an example to explain this tip.

imagine we want to export our drupal users with their roles. if a user has 3 roles, the result of the join query will be 3 rows for him.

Using GROUP_CONCAT will give us all roles in one single row.

SELECT u.uid, u.name, u.mail,
 GROUP_CONCAT(DISTINCT r.name SEPARATOR '/') as roles
from users u
 inner join users_roles ur on ur.uid = u.uid
 inner join role r using(rid)
 GROUP BY u.uid

notice here the GROUP BY u.uid (otherwise all users will be concatenated in 1 row).

see the syntax of this function

Order your nodes by most recent post OR comment date

Hello,

ever wanted to sort your nodes by post or comment date like forums do ( last “action” first) ?

you can do that easily with mysql and greatest select

SELECT n.nid, title,
GREATEST(n.created, last_comment_timestamp) as dateup
 
FROM node n
INNER JOIN `node_comment_statistics` using(nid)
 
order by dateup desc