You are here

function dynamic_background_blog_dynamic_background_css in Dynamic Background 7.2

Same name and namespace in other branches
  1. 6 modules/dynamic_background_blog/dynamic_background_blog.module \dynamic_background_blog_dynamic_background_css()
  2. 7 modules/dynamic_background_blog/dynamic_background_blog.module \dynamic_background_blog_dynamic_background_css()

Implements hook_dynamic_background_css().

File

modules/dynamic_background_blog/dynamic_background_blog.module, line 125
This module provides the user blog's with the option to use different dynamic background images for each blog.

Code

function dynamic_background_blog_dynamic_background_css($vars) {
  $uid = NULL;

  // There are two ways to detecte the different parts of a blog. The path
  // /blog/%uid_optional of the node type blog. First we look at the node type,
  // then the path.
  if (isset($vars['node']) && $vars['node']->type == 'blog') {
    $uid = $vars['node']->uid;
  }
  else {

    // Try to find the uid by using path.
    $parts = explode('/', drupal_get_path_alias());
    if (count($parts) >= 2 && $parts[0] == DYNAMIC_BACKGROUND_BLOG_PATH && is_numeric($parts[1])) {

      // Test that the 2nd part is an int (might be a user id).
      $uid = (int) $parts[1];
    }
  }

  // If user id was found, try to load blog background image if one is definded.
  if (!is_null($uid)) {
    $image = dynamic_background_active_image('blog', $uid);

    // If no image have been found try to select random image (if configured).
    $image_behaviour = variable_get('dynamic_background_blog_image_behaviour', array());
    if (!$image && (isset($image_behaviour['random']) && $image_behaviour['random'])) {
      $image = dynamic_background_random_image('blog', $uid);
    }
    if ($image) {

      // Load image style settings.
      $image_style = variable_get('dynamic_background_blog_image_style', FALSE);
      return array(
        'image' => $image,
        'configuration' => variable_get('dynamic_background_blog_css', array()),
        'image_style' => $image_style ? $image_style['style'] : FALSE,
        'weight' => 230,
      );
    }
  }
}