[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

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

   1  <?php
   2  // $Id: pathauto_taxonomy.inc,v 1.39.2.5 2010/07/31 15:57:16 davereid Exp $
   3  
   4  /**
   5   * @file
   6   * Hook implementations for taxonomy module integration.
   7   *
   8   * @ingroup pathauto
   9   */
  10  
  11  /**
  12   * Implements hook_pathauto().
  13   */
  14  function taxonomy_pathauto($op) {
  15    switch ($op) {
  16      case 'settings':
  17        $settings = array();
  18        $settings['module'] = 'taxonomy';
  19        $settings['token_type'] = 'taxonomy';
  20        $settings['groupheader'] = t('Taxonomy term paths');
  21        $settings['patterndescr'] = t('Default path pattern (applies to all vocabularies with blank patterns below)');
  22        $settings['patterndefault'] = 'category/[vocab-raw]/[catpath-raw]';
  23        $patterns = token_get_list('taxonomy');
  24        foreach ($patterns as $type => $pattern_set) {
  25          if ($type != 'global') {
  26            foreach ($pattern_set as $pattern => $description) {
  27              $settings['placeholders']['['. $pattern .']'] = $description;
  28            }
  29          }
  30        }
  31        $settings['supportsfeeds'] = '0/feed';
  32        $settings['bulkname'] = t('Bulk generate aliases for terms that are not aliased');
  33        $settings['bulkdescr'] = t('Generate aliases for all existing terms which do not already have aliases.');
  34  
  35        $vocabularies = taxonomy_get_vocabularies();
  36        if (sizeof($vocabularies) > 0) {
  37          $settings['patternitems'] = array();
  38          $forum_vid = variable_get('forum_nav_vocabulary', '');
  39          foreach ($vocabularies as $vocab) {
  40            if ($vocab->vid != $forum_vid) {
  41              $vocabname = $vocab->name;
  42              $fieldlabel = t('Pattern for all %vocab-name paths', array('%vocab-name' => $vocabname));
  43              $settings['patternitems'][$vocab->vid] = $fieldlabel;
  44            }
  45          }
  46        }
  47        return (object) $settings;
  48      default:
  49        break;
  50    }
  51  }
  52  
  53  /**
  54   * Generate aliases for all categories without aliases.
  55   */
  56  function taxonomy_pathauto_bulkupdate() {
  57    // From all node types, only attempt to update those with patterns
  58    $pattern_vids = array();
  59    foreach (taxonomy_get_vocabularies() as $vid => $info) {
  60      $pattern = trim(variable_get('pathauto_taxonomy_'. $vid .'_pattern', ''));
  61  
  62      // If it's not set, check the default
  63      // TODO - If there's a default we shouldn't do this crazy where statement because all vocabs get aliases
  64      // TODO - Special casing to exclude the forum vid (and the images vid and...?)
  65      if (empty($pattern)) {
  66        $pattern = trim(variable_get('pathauto_taxonomy_pattern', ''));
  67      }
  68      if (!empty($pattern)) {
  69        $pattern_vids[] = $vid;
  70        if (empty($vid_where)) {
  71          $vid_where = " AND (vid = '%s' ";
  72        }
  73        else {
  74          $vid_where .= " OR vid = '%s'";
  75        }
  76      }
  77    }
  78    $vid_where .= ')';
  79  
  80    // Exclude the forums and join all the args into one array so they can be passed to db_query
  81    $forum_vid[] = variable_get('forum_nav_vocabulary', '');
  82    $query_args = array_merge($forum_vid, $pattern_vids);
  83    $query = "SELECT tid, vid, name, description, src, dst FROM {term_data} LEFT JOIN {url_alias} ON CONCAT('taxonomy/term/', CAST(tid AS CHAR)) = src WHERE src IS NULL AND vid <> %d ". $vid_where;
  84    $result = db_query_range($query, $query_args, 0, variable_get('pathauto_max_bulk_update', 50));
  85  
  86    $count = 0;
  87    $placeholders = array();
  88    while ($category = db_fetch_object($result)) {
  89      $count += _taxonomy_pathauto_alias($category, 'bulkupdate');
  90    }
  91  
  92    drupal_set_message(format_plural($count,
  93      'Bulk generation of terms completed, one alias generated.',
  94      'Bulk generation of terms completed, @count aliases generated.'));
  95  }
  96  
  97  /**
  98   * Create aliases for taxonomy objects.
  99   *
 100   * @param $category
 101   *   A taxonomy object.
 102   */
 103  function _taxonomy_pathauto_alias($category, $op) {
 104    $count = 0;
 105  
 106    $placeholders = pathauto_get_placeholders('taxonomy', $category);
 107  
 108    $forum_vid = variable_get('forum_nav_vocabulary', '');
 109    // If we're in a forum vocabulary, also create a forum container, forum, or forum topic alias.
 110    if (module_exists('forum') && $forum_vid == (int)$category->vid) {
 111      $source = 'forum/'. $category->tid;
 112      if (pathauto_create_alias('forum', $op, $placeholders, $source, $category->tid, $category->vid)) {
 113        $count++;
 114      }
 115    }
 116    else {
 117      $source = taxonomy_term_path($category);
 118      if (pathauto_create_alias('taxonomy', $op, $placeholders, $source, $category->tid, $category->vid)) {
 119        $count++;
 120      }
 121    }
 122    return $count;
 123  }
 124  
 125  /**
 126   * Implementation of hook_pathauto() for forum module.
 127   */
 128  function forum_pathauto($op) {
 129    switch ($op) {
 130      case 'settings':
 131        $settings = array();
 132        $settings['module'] = 'forum';
 133        $settings['token_type'] = 'taxonomy';
 134        $settings['groupheader'] = t('Forum paths');
 135        $settings['patterndescr'] = t('Pattern for forums and forum containers');
 136        $settings['patterndefault'] = '[vocab-raw]/[catpath-raw]';
 137        $patterns = token_get_list('taxonomy');
 138        foreach ($patterns as $type => $pattern_set) {
 139          if ($type != 'global') {
 140            foreach ($pattern_set as $pattern => $description) {
 141              $settings['placeholders']['['. $pattern .']'] = $description;
 142            }
 143          }
 144        }
 145        $settings['supportsfeeds'] = '0/feed';
 146        $settings['bulkname'] = t('Bulk generate aliases for forum paths that are not aliased');
 147        $settings['bulkdescr'] = t('Generate aliases for all existing forums and forum containers which do not already have aliases.');
 148        return (object) $settings;
 149      default:
 150        break;
 151    }
 152  }
 153  
 154  /**
 155   * Generate aliases for all forums and forum containers without aliases.
 156   */
 157  function forum_pathauto_bulkupdate() {
 158    $forum_vid = variable_get('forum_nav_vocabulary', '');
 159    $query = "SELECT tid, vid, name, description, src, dst FROM {term_data} LEFT JOIN {url_alias} ON CONCAT('forum/', CAST(tid AS CHAR)) = src WHERE vid = %d AND src IS NULL";
 160    $result = db_query_range($query, $forum_vid, 0, variable_get('pathauto_max_bulk_update', 50));
 161  
 162    $count = 0;
 163    $placeholders = array();
 164    while ($category = db_fetch_object($result)) {
 165      $count = _taxonomy_pathauto_alias($category, 'bulkupdate') + $count;
 166    }
 167  
 168    drupal_set_message(format_plural($count,
 169      'Bulk update of forums and forum containers completed, one alias generated.',
 170      'Bulk update of forums and forum containers completed, @count aliases generated.'));
 171  }


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