Monthly Archives: March 2010

Handling user permissions

Drupal´s permission assigning scheme is very powerful.  For my site I was interested in creating several roles, like blogger, news editor, etc. This is done from admin>user management>roles, and permissions for the created roles are handled from admin>user management>permissions. For example, the “news writer” role has permissions to access the admin menu (under administration menu module heading), create news content, and access administration pages (under system module). This last is essential as without it all other actions we´ve assigned permissions for cant be carried out.

Another thing that I adjusted was the ability to have anonymous users posting comments, by activating comments and access comments permissions. Again this last permission may not seem that obvious but it is essential to remember.

It happened to me that I tweaked some permissions that resulted in anonymous users not being able to see content in the site. Actions can´t be undone and appropriate permissions are hard to remember before any change results in a potential catastrophe. The same can eventually happen when installing or removing new modules. The solution is rebuilding permissions, from content>post settings. This wipes all the current node permissions.

Contact forms in drupal

The webform module adds a new node type called webform to drupal, to enable having contact forms, questionnaires, surveys, etc. This involves 2 steps:

1-creating the webform and its configuration, from content management>create content>webform; here we give the form a name, add the email address we want the information be submitted to, and other customization settings like permissions. Description box is what the user will see on the screen.

2-building the form components: after the newly created webform is submitted we are taken to a screen that allows us to build your actual form. What we do here is begin to create your fields. We can create text fields, text areas etc., making fields mandatory if needed, as well as assign a weight to ensure each field is in the order desired.

A final touch is disabling the “display post information” for content type webform, so that the outputted form doesn’t display at the top “submitted by Username on date” text. This can be done from admin/build/themes/settings, under global settings, unchecking the display for webforms.

One last thing to remember is that in order to have access to the form, a new item has to be added to the menu (primary links in my case) with the url to the form.

Attaching images to nodes

This was achieved by enabling filefield and imagefield, as part of cck. I added in content type “news” a new field as shown in this capture:

ImageField is completely dependent on FileField for its data handling. This means that ImageField is now purely a “widget” for CCK, not a “field” any more, as it was in previous versions of this module.

The idea was to allow the user to upload an image, then drupal automatically:

-resizes the original image to thumbnail, to display in the node teaser.

-resizes the original image to slightly larger size than a thumbnail in the full node display page, and a javascript library (highslide, lightbox or the likes) allows to elegantly display the image at full size when user clicks on the image.

The user doesn´t have to worry about manually resizing file resolution. So, imagefield module adds the image to the news content type, ImageCache module creates the resizing/cropping presets, and Lightbox2 module displays the image at full size. The 3 modules work very well with each other. Enabling the ImageAPI GD2 module that comes in the imagecache installation is crucial, as otherwise imagecache causes drupal to output the wrong path to the thumbnails (*). The 5 modules that come with imagecache module download need to be activated. I also activated the lightbox2 module.

I created 2 presets in admin>site building>imagecache, “thumbpreset” for resizing to thumbnail and “thumbfornewsnode” for resizing to slightly larger than thumbnail. From admin>content types>news>display fields tab, settings for the output of the custom created image field can be adjusted: “thumbpreset” for the node teaser, and “lightbox2: thumbfornewsnode>original” for full node. I then adjusted from admin>site building>views to output a thumbnail in the news content type teaser page. CSS did the rest, by applying padding and a grey border to the thumbnail, to achieve the photography frame effect:

.imagecache-thumbpreset{
border:1px solid #CCC;
background-color:#FFF;
padding:5px;
}

And the following style to make the “thumbfornewsnode” float to the right, when displayed at full node:

.field-field-thumb{
float:right;
padding:10px;
}
One last thing to remember is that each user role that wishes to view the images generated by a particular preset must be given permission on the admin/user/permissions page.

The following link provided help:
http://www.juliakm.com/using-imagecache-and-cck-imagefield-add-image-drupal

*: as reported in the list of bugs in: http://drupal.org/node/371195#comment-1282828

Google adsense in drupal 6

In order to introduce google adsense on any site, an account has to be created and activated on google.com/adsense. Once the application is reviewed by google, it will generate javascript code that we can reference drupal to, to make it display the ads. The module adsense takes care of everything. Installation requires to enable the AdSense core as well as Managed Ads. From site configuration>adsense , 3 tabs display: publisher ID, manage ads, settings. Settings can be left at default, manage ads tells drupal how many blocks are created for the ads, and publisher id requires to enter in a textbox the id of your personal google adsense account ( “pub-xxxxxx”). From there on we can go to configure the google adsense blocks created by the module, in site building>blocks. The newly created blocks can be configured in size (under “ad format”, it is recommended to stick to the same settings chosen in the google adsense account) and alignment, but most importantly here is where the ad slot id code generated in the javascript code from google has to be pasted in.

This was very helpful: http://bri-space.com/content/configuring-drupal-6-google-adsense-module

Theming the user login block

I wanted to style the login block to be horizontal rather than vertical, to make better use of the space, as it was taking too much vertical space. Among the different ways to customize the user login block, I went for a combination of css+jquery, without editing any *.tpl file or modifying markup. Results can be seen in the picture below:

The trick here consisted of using a jquery overlabel script and adding it to the theme´s js folder, and creating a script.js file with the following code to make the labels be displayed in the input forms and hide when text is inputted or display when they are empty:

$(document).ready(function() {

$(“#header label”).overlabel();

});

CSS did the rest. I created an overlabel stylesheet to take care of the custom login block, and updated the theme´s .info file to include the mentioned stylesheet and scripts. Once again, drupal wouldn’t see the changes until the modules page at the backend is refreshed. For cross-browser compatibility, some styles had to be tweaked for the internet explorer browser to render appropriately.

Following link served as reference:

http://www.topnotchthemes.com/blog/081204/horizontal-user-login-block-using-css-and-jquery