[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/pathauto/ -> pathauto_node.inc (source)

   1  <?php
   2  // $Id: pathauto_node.inc,v 1.47.2.3 2010/07/31 15:57:16 davereid Exp $
   3  
   4  /**
   5   * @file
   6   * Hook implementations for node module integration.
   7   *
   8   * @ingroup pathauto
   9   */
  10  
  11  /**
  12   * Implements hook_pathauto().
  13   */
  14  function node_pathauto($op) {
  15    switch ($op) {
  16      case 'settings':
  17        $settings = array();
  18        $settings['module'] = 'node';
  19        $settings['token_type'] = 'node';
  20        $settings['groupheader'] = t('Node paths');
  21        $settings['patterndescr'] = t('Default path pattern (applies to all node types with blank patterns below)');
  22        $settings['patterndefault'] = 'content/[title-raw]';
  23        $settings['bulkname'] = t('Bulk generate aliases for nodes that are not aliased');
  24        $settings['bulkdescr'] = t('Generate aliases for all existing nodes which do not already have aliases.');
  25  
  26        $patterns = token_get_list('node');
  27        foreach ($patterns as $type => $pattern_set) {
  28          if ($type != 'global') {
  29            foreach ($pattern_set as $pattern => $description) {
  30              $settings['placeholders']['['. $pattern .']'] = $description;
  31            }
  32          }
  33        }
  34        $settings['supportsfeeds'] = 'feed';
  35  
  36        if (module_exists('locale')) {
  37          $languages = array('' => t('Language neutral')) + locale_language_list('name');
  38        }
  39        else {
  40          $languages = array();
  41        }
  42        foreach (node_get_types('names') as $node_type => $node_name) {
  43          if (variable_get('language_content_type_'. $node_type, 0) && count($languages)) {
  44            $settings['patternitems'][$node_type] = t('Default path pattern for @node_type (applies to all @node_type node types with blank patterns below)', array('@node_type' => $node_name));
  45            foreach ($languages as $lang_code => $lang_name) {
  46              if (!empty($lang_code)) {
  47                $settings['patternitems'][$node_type .'_'. $lang_code] = t('Pattern for all @node_type paths in @language', array('@node_type' => $node_name, '@language' => $lang_name));
  48              }
  49              else {
  50                $settings['patternitems'][$node_type .'_'. $lang_code] = t('Pattern for all language neutral @node_type paths', array('@node_type' => $node_name));
  51              }
  52            }
  53          }
  54          else {
  55            $settings['patternitems'][$node_type] = t('Pattern for all @node_type paths', array('@node_type' => $node_name));
  56          }
  57        }
  58        return (object) $settings;
  59      default:
  60        break;
  61    }
  62  }
  63  
  64  /**
  65   * Generate aliases for all nodes without aliases.
  66   */
  67  function node_pathauto_bulkupdate() {
  68    // From all node types, only attempt to update those with patterns
  69    $pattern_types = array();
  70  
  71    // If there's a default pattern we assume all types might be updated.
  72    if (trim(variable_get('pathauto_node_pattern', ''))) {
  73      $pattern_types = array_keys(node_get_types('names'));
  74    }
  75    else {
  76      // Check first for a node specific pattern...
  77      $languages = array();
  78      if (module_exists('locale')) {
  79        $languages = array('' => t('Language neutral')) + locale_language_list('name');
  80      }
  81      foreach (array_keys(node_get_types('names')) as $type) {
  82        if (trim(variable_get('pathauto_node_'. $type .'_pattern', ''))) {
  83          $pattern_types[$type] = $type;
  84          continue;
  85        }
  86        // ...then for a node-language pattern.
  87        if (variable_get('language_content_type_'. $type, 0) && $languages) {
  88          foreach ($languages as $lang_code => $lang_name) {
  89            if (trim(variable_get('pathauto_node_'. $type .'_'. $lang_code .'_pattern', ''))) {
  90              $pattern_types[$type] = $type;
  91              continue 2;
  92            }
  93          }
  94        }
  95      }
  96    }
  97  
  98    $count = 0;
  99    if (count($pattern_types)) {
 100      $query = "SELECT n.nid, n.vid, n.type, n.title, n.uid, n.created, n.language, alias.src, alias.dst FROM {node} n LEFT JOIN {url_alias} alias ON CONCAT('node/', CAST(n.nid AS CHAR)) = alias.src WHERE alias.src IS NULL AND n.type IN (". db_placeholders($pattern_types, 'varchar') .')';
 101      $result = db_query_range($query, $pattern_types, 0, variable_get('pathauto_max_bulk_update', 50));
 102  
 103      $placeholders = array();
 104      while ($node_ref = db_fetch_object($result)) {
 105        $node = node_load($node_ref->nid, NULL, TRUE);
 106        $node->src = $node_ref->src;
 107        $node->dst = $node_ref->dst;
 108        if (module_exists('taxonomy')) {
 109          // Must populate the terms for the node here for the category
 110          // placeholders to work
 111          $node->taxonomy = array_keys(taxonomy_node_get_terms($node));
 112        }
 113        $placeholders = pathauto_get_placeholders('node', $node);
 114        $source = "node/$node->nid";
 115        if (pathauto_create_alias('node', 'bulkupdate', $placeholders, $source, $node->nid, $node->type, $node->language)) {
 116          $count++;
 117        }
 118      }
 119    }
 120  
 121    drupal_set_message(format_plural($count,
 122      'Bulk generation of nodes completed, one alias generated.',
 123      'Bulk generation of nodes completed, @count aliases generated.'));
 124  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7