Planet Drupal

Turn off maintenance mode on separate paths in Drupal 7

We have faced with the problem. We use Ajax Login/Register module but put site in Maintenance mode.

But we need to have Sign up ability. Ajax Register module show Sign up form in popup, content is requested from "ajax_register/register". But in maintenance mode we can see Maintenance page response...

But fortunately we have hook_menu_site_status_alter. Thus we can turn off Maintenance mode in our module on separate path:

function ajax_register_fix_menu_site_status_alter(&$menu_site_status, $path) {
  if (
$menu_site_status == MENU_SITE_OFFLINE && user_is_anonymous() && $path == 'ajax_register/register') {
$menu_site_status = MENU_SITE_ONLINE;

This is content of ajax_register_fix.module custom module.

Anchors Panels Navigation Module

Several years ago I have a dream to put my own personal site into One Page solution.
Due to I'm Drupal developer Drupal was selected as platform for my site.
Thus Single Page Website Module was done.

This module is some kind of out of box solution. One can turned it on, do several settings on the module settings page and have One Page website on Drupal CMS engine.

But due to architecture of the module it has a lot of significant restrictions that will be difficult to resolve. The main problem is the limited number of themes that people can use with that module. By the fact Bartik theme and it's subthemes only works correct with the module. This issue connected with some automatic actions that module should perform with page template to make it One Page site.

There are a lot of other issues and limitations that restrict significantly abilities of Single Page Website module. There is no any multilingual support and there is no ability to set two One Page Landings, there is no ability to have link in menu that go to the separate Drupal or external page and so on, and so on...

The talk about weak and strong points of Single Page Website module is out of scope of this post, I'm ready to provide my thoughts but in the other post that will be created soon I hope :-)

The topic of this post is Anchors Panels Navigation Module. What made me make a second approach to the One Page site on Drupal? I think that if we can use higher layer of abstraction in the architecture we can avoid any theme dependence. But we should find some kind of wrapper to combine our One page site from different content parts.

I have used Panels module. If you would like to create some Landing Page with anchor navigation inside it, please use Anchors Panels Navigation module. Please use development version it should works, but some decoration moments I should finished before an official release.

There are several simple steps that you should do to obtain One Page site on the base of Panels with anchor navigation:

  1. Turn on Anchors Panels Navigation module. Panels, Panel nodes and Ctools are required also.

  2. Create several pages with content that you would like to have on One page Panel
  3. Create Panel an put nodes that you did on previous step into the Panel areas.
  4. For each region that you would like to have anchor set CSS id in Panels settings.

  5. Put several links to created Panels node with anchors equal the IDs into any Drupal menu. You can have some other links in that menu too.

  6. Now you have Landing Page with anchors. The module does not provide any CSS altering of the page so to set your menu in fixed position you should do some CSS changes manually. I found CSS Injector module is helpful to set some specific CSS rules on the separate Palels page.

The results here:

Feel free to ask any questions and send any ideas about that approach. Thanks!

Blog tags: 

Don't forget to check Backup&Migrate settings after D6 to D7 upgrade!

Several days ago we upgraded simple Drupal 6 site to Drupal 7. After core upgrade process was finished we turned on all necessary modules such as Admin menu and Backup & Migrate.

Some features required custom update by scripts and some manual work, we made backup before this activity.
... something went wrong and we go back by restoring DB via Backup&Migrate module and site wend down :-(

When we took a look on DB backup script we found that there was empty dump with the structure of some tables.
So as a result the data in several tables was killed.

When we repeated upgrade process again and took a look on Backup&Migrate advanced settings we were shocked

incorrect table exclude settings

By some reason all tables was excluded from backup.

After we align B&M settings backup became works correctly :-)

The main idea of this post due to automatic upgrade process you should double check settings of contributed modules, upgrade can make them different according initial state.

And, of course, backups is necessary part of site development activity but you should be sure that your backups correct.

How to delete users without any role in Drupal 7

We faced of one of the projects that we supported with large amount of spam registrations. But there were valid users with assigned roles that should not be deleted.

Short script was written to resolve this task:

require_once './includes/';
define('DRUPAL_ROOT', '<path_to_you_Drupal_folder>'); // optional
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // load Drupal to use Drupal API
$query = 'SELECT users.uid as uid FROM {users} LEFT JOIN {users_roles} ON users.uid = users_roles.uid WHERE users.uid != 0 AND users_roles.uid IS null ORDER BY users.uid DESC LIMIT 300';
$result = db_query($query);
while (
$row = $result->fetchObject()) {
'300 spam users were deleted!'

Let me explain this code in details:

If we would like to use Drupal API and DB connection in any separate script not in our custom Drupal module we need to start with these lines:

require_once './includes/';
define('DRUPAL_ROOT', '<path_to_you_Drupal_folder>'); // optional
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // load Drupal to use Drupal API

Attention! You should put your path instead ''.
Some times script can work without 'DRUPAL_ROOT' definition, but some times can't like in our case.

Authenticated User role ID is 2. But there is no any record with that role ID in {users_roles} table, so we should select all user IDs that have no records in {users_roles} table users_roles.uid IS null.

And do not forget to exclude Anonymous user record users.uid != 0.
Other wise we can delete record with 0 UID from {users} table, that serve for Anonymous user purpose.

Start to delete most resent users ORDER BY users.uid DESC.

Due to user_delete() function require pretty large number of SQL requests it is reasonable to set some limit LIMIT 300.

If there are a lot of spam users you can set cron task, for example:

*/02 * * * * /usr/bin/wget -O - -q -t 1 >/dev/null 2>&1

Swipe Photo Gallery

We are happy to inform you that we have put new beautiful photo gallery module on

Project page:

This module show the matrix of images on one separate page. User can see only one page in matrix and go to the next with Up, Down, Right or Left key or using swipe in Up, Down, Right or Left direction.

You can see demo on
We have done site of Carol Sachs and understand that there are some custom solutions that we must share with world Drupal community.

The simple instruction how to use this module:

  1. Turn on module as usual drupal module.
  2. Check that you use Jquery 1.7 or higher with Jquery Update module!
  3. Put several nodes with Slide content type. This content type will appear automatically.
  4. Go to the configuration page admin/config/media/swipe_photo_gallery and set path where you would like to show your slides.
  5. Go to this page and enjoy your slides.

Feel free to send us any recommendations and ideas that can improve this module!

Blog tags: 

How to Add Circle Image Style into Rotating Banner SlideShow

During update work of the site of our Drupal department ( we faced following task: to upload rectangular images but to show circle ones on the pages of our site.

In the case if we are going to display circle image form Image or Media field it is easy to set image style preset and use it in the field display. But Rotating banner ( does not allow to use image styles without hack module.

It is extremely worth practice to hack contributes module even in no feather development status :-)

But how can avoid to hack module and use image style to make image be circle?

By the way to do circle images with image style preset you can use ImageCache Action Module (

Ok, back to our task. We can try to use hook_preprocess_image(). In our theme template.php file we put following code:

function sfdev_preprocess_image(&$vars) {
$vars['attributes']['class']) && $vars['attributes']['class'] == 'rb-background-image') {
$url_splits = explode(variable_get('file_public_path', conf_path() . '/files/'), $vars['path']);
$vars['path'] = image_style_url('circle', file_build_uri($url_splits[1]));

Fortunately each rotating banner add 'rb-background-image' to each image. So we can separate this kind of images from the other ones:
if(isset($vars['attributes']['class']) && $vars['attributes']['class'] == 'rb-background-image') {

Before implementing hook_preprocess_image we should create 'circle' image style to use it in this function.
To make Drupal create circle image we should just simply request it via image style URL:
image_style_url('circle', file_build_uri($url_splits[1]));
So the main idea to put image style URL instead original one.

By the way, after some discussions we decide to create circle images manually, because in some cases they should not be circle :-)
And these cases are not predictable :-(

Blog tags: 

We should not use a drupal_goto function in our module hooks!

Today one of my colleague nortmas had explained to the young developers one not obvious but extremely important point. In the begin of my career of Drupal developer I often did that kind of mistake.

I would like to share with us his message:

You should not put drupal_goto() into the hooks of our custom module!


Because our hook function is into the queue of the other functions that represent the same hook in the other contributed and custom modules. The order depends on the weight of the module and alphabetic order in the case of equal weights.

In the case if you will put drupal_goto in your hook function code, you will take away the ability to do necessary actions of the modules that located in the back of the hook order queue.

In any case you should avoid drupal_goto() function in your code because it indicated poor codding style like for example goto operator in classic C language.

Thank you, Dmitry for that helpful blog topic!

Blog tags: 

Cursor Easy Change module

We, like any active Drupal team, faced with the task of recruiting new staff. To begin with, to cut off unwanted people, the usual step is the test task. Commonly in our practice we ask the applicant to create simple module. But Drupal has a lot of contributed modules that cover all needs of ordinary developer. So if we ask applicants to repeat some existing solution they can look for contributed solution... Yes, it is good skill to easy implementation of contributed solution with some customization. But we would like to see how applicant will create solution from scratch. Recently we have to propose the most amazing tasks, which may be completely useless, just for fun only.

Below I would like to show the result of such test task, that was successfully done.

Every beginner in the web development area is seeking to add to the site as many different effects as it possible, wanting to impress site visitor. A little creative effects, which can easily to surprise is custom cursor on the site. We ask the applicant create Drupal module that will provide to the admin of the site the set of cursors to apply via CSS.
You can find the result in the sandbox project.
Also one can download archive here.

The solution is really simple. The form of theme settings is altered.

There is no ability to upload cursors but there are several cases that we can use to show the ability of such kind of effect.
In addition in the module there is function that stores the selected version of the cursor in the system variable and hook_init, which adds the necessary CSS file.

It is really easy module so the main question to the community:

Whether it should stay in the sandbox?

Or we should modify it by adding the ability to load custom cursors and make a full project?

How to set image style in your own module in Drupal 7

Some time ago one of our customers asked to port gallery from Drupal 6 site to Drupal 7 one.
The module was not complex, the main difficult that I faced during the process to change Image Cache approach to the Image style one that native in Drupal 7. The main idea is to set resize rules of thumbnails in the gallery. Users should no do that themselves.

Previously in Drupal 6 there was following solution. The Image Cache preset set in the .install file.

* Implementation of hook_install().
function ms_gallery_install() {
// Create preset.

ms_gallery_install_imagecache_presets() {
// First, build an array of all the preset names so we do not make duplicates
  // Set the argument to TRUE to reset the cache
$presets = imagecache_presets(TRUE);
$preset_names = array();

// If there are any presets
if ($presets != '') {
    foreach (
$presets as $preset) {
$preset_names[] = $preset['presetname'];

// Prepare to install ImageCache presets
$imagecache_presets = array();
$imagecache_actions = array();

// We are checking to make sure the preset name does not exist before creating
if (!in_array('ms_gallery', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'ms_gallery',
$imagecache_actions['ms_gallery'][] = array(
'action' => 'imagecache_scale_and_crop',
'data' => array(
'width' => 120,
'height' => 67,
'weight' => 0,
// Need to install preset, id will be returned by function,
  // Then install action add presetid to action prior to install:
foreach ($imagecache_presets as $preset) {
$preset = imagecache_preset_save($preset);
    foreach (
$imagecache_actions[$preset['presetname']] as $action) {
$action['presetid'] = $preset['presetid'];
drupal_set_message(t('ImageCache preset %id: %name and corresponding actions saved.', array('%id' => $preset['presetid'], '%name' => $preset['presetname'])));

Above the part of ms_gallery.install code. I would like to show how to set Image Cache preset programmatically.

In the case of Drupal 7 there is no Image Cache module. Instead it we should use Image Style approach that included in the Drupal 7 core.
I try to find any example in the Google, but the examples that I found does not work.

There is no any other option that to study And after several hours I have found following beautiful HOOK:

In terms of this hook to solve my task will be so easy!

function ms_gallery_image_default_styles() {
$styles = array();

$styles['carousel_gallery'] = array(
'effects' => array(
'name' => 'image_scale_and_crop',
'data' => array(
'width' => 120,
'height' => 67,
'upscale' => 1,
'weight' => 0,


I really like Drupal 7 :-)

How to exclude the current node from a list view in Drupal 7

This is the instructions corresponds Drupal 7 + views 3.

There is a standard problem, we have the teaser of a random node in the block,
but it would be wrong to deduce the node teaser page on the page of it's full view.
Lets do following in views settings:

1. Click on the "advanced" fieldset.
2. Click on add under "contextual filters". We are going to add new contextual filter.
3. Choose Content:nid.
4. Under "when the filter variable is not available", choose "provide default value".
5. From the drop down menu select "content id from url".
6. Scroll all the way down to the bottom of the window and click on the "More" link.
7. Click "Exclude".
8. And be happy!