You are here

gallery_assist_aliases.module in Gallery Assist 6

File

modules/gallery_assist_aliases/gallery_assist_aliases.module
View source
<?php

// $Id$

/**
 * @file 
 */

/**
 * Implementation of hook_help() 
 */
function gallery_assist_aliases_help($path, $arg) {
}

/**
 * Implementation of hook_nodeapi()
 */
function gallery_assist_aliases_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'load':
      if (module_exists('path')) {
        gallery_assist_aliases_create_simple($node);
      }
      break;
    case 'update':
      if (module_exists('path')) {
      }
      break;
  }
}

/**
 * Function to create or update aliases to the gallery images.
 * This function create alias to the part of the path containing the node path (node/NID).
 * Paths for gallery items will be not created.
 */
function gallery_assist_aliases_create_simple($node) {
  $default_path = "node/{$node->nid}";
  $node_path_id = db_result(db_query("SELECT pid FROM {url_alias} WHERE src = '%s'", $default_path));
  if ($node_path_id > 0) {

    // Check if path is set.
    if (drupal_get_path_alias($default_path) != $default_path) {

      // Do what if the gallery has images.
      if (count($node->gallitems) > 0) {
        foreach ($node->gallitems as $pid => $item) {
          $image_path = "node/{$node->nid}/{$pid}";

          // Check if item has an alias.
          if (drupal_get_path_alias($image_path) != drupal_get_path_alias($default_path) . '/' . $pid) {
            $path_id = db_result(db_query("SELECT pid FROM {url_alias} WHERE src = '%s'", $image_path));

            // If exists a entry do an update.
            if ($path_id) {
              if (module_exists('pathauto') && $node->gallconf[$node->type]['build_aliases'] == 1) {
                module_load_include('inc', 'pathauto', 'pathauto');
                $ptitle = empty($item->ptitle) ? $pid : pathauto_cleanstring($item->ptitle);
                $item_alias = drupal_get_path_alias($default_path) . '/' . $ptitle;
              }
              else {
                $item_alias = drupal_get_path_alias($default_path) . '/' . $pid;
              }
              path_set_alias($image_path, $item_alias, $path_id, $node->language);
            }
            else {
              if (module_exists('pathauto') && $node->gallconf[$node->type]['build_aliases'] == 1) {
                module_load_include('inc', 'pathauto', 'pathauto');
                $ptitle = empty($item->ptitle) ? $pid : pathauto_cleanstring($item->ptitle);
                $item_alias = drupal_get_path_alias($default_path) . '/' . $ptitle;
              }
              else {
                $item_alias = drupal_get_path_alias($default_path) . '/' . $pid;
              }
              path_set_alias($image_path, $item_alias, NULL, $node->language);
            }
          }
        }
      }
    }
  }
  else {
    if (count($node->gallitems) > 0) {
      foreach ($node->gallitems as $pid => $item) {
        $image_path = "node/{$node->nid}/{$pid}";

        // Check if item has an alias.
        if (drupal_get_path_alias($image_path) != $default_path . '/' . $pid) {
          $path_id = db_result(db_query("SELECT pid FROM {url_alias} WHERE src = '%s'", $image_path));

          // If exists a entry do an update.
          if ($path_id) {
            db_query("DELETE FROM {url_alias} WHERE pid = %d", $path_id);
          }
        }
      }
    }
  }
}

Functions

Namesort descending Description
gallery_assist_aliases_create_simple Function to create or update aliases to the gallery images. This function create alias to the part of the path containing the node path (node/NID). Paths for gallery items will be not created.
gallery_assist_aliases_help Implementation of hook_help()
gallery_assist_aliases_nodeapi Implementation of hook_nodeapi()