[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7