| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: xmlsitemap_taxonomy.module,v 1.1.4.27 2010/04/30 03:31:19 davereid Exp $ 3 4 /** 5 * Implements hook_xmlsitemap_link_info(). 6 */ 7 function xmlsitemap_taxonomy_xmlsitemap_link_info() { 8 $types['taxonomy_term'] = array( 9 'label' => t('Taxonomy'), 10 'bundle label' => t('Vocabulary'), 11 'base table' => 'term_data', 12 'entity keys' => array( 13 'id' => 'tid', 14 'bundle' => 'vid', 15 ), 16 'path callback' => 'taxonomy_term_path', 17 'load hook' => 'taxonomy_get_term', 18 'xmlsitemap' => array( 19 'process callback' => 'xmlsitemap_taxonomy_xmlsitemap_process_taxonomy_term_links', 20 ), 21 ); 22 foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) { 23 $types['taxonomy_term']['bundles'][$vid] = array( 24 'label' => $vocabulary->name, 25 'admin' => array( 26 'real path' => 'admin/content/taxonomy/edit/vocabulary/' . $vid, 27 'access arguments' => array('administer taxonomy'), 28 ), 29 ); 30 } 31 return $types; 32 } 33 34 /** 35 * Implements hook_cron(). 36 * 37 * Process old taxonomy terms not found in the {xmlsitemap} table. 38 */ 39 function xmlsitemap_taxonomy_cron() { 40 xmlsitemap_taxonomy_xmlsitemap_index_links(xmlsitemap_var('batch_limit')); 41 } 42 43 /** 44 * Implements hook_xmlsitemap_index_links(). 45 */ 46 function xmlsitemap_taxonomy_xmlsitemap_index_links($limit) { 47 if ($vids = xmlsitemap_get_link_type_enabled_bundles('taxonomy_term')) { 48 $query = db_query_range("SELECT t.tid FROM {term_data} t LEFT JOIN {xmlsitemap} x ON x.type = 'taxonomy_term' AND t.tid = x.id WHERE x.id IS NULL AND t.vid IN (" . db_placeholders($vids) . ") ORDER BY t.tid DESC", $vids, 0, $limit); 49 $tids = array(); 50 while ($tid = db_result($query)) { 51 $tids[] = $tid; 52 } 53 xmlsitemap_taxonomy_xmlsitemap_process_taxonomy_term_links($tids); 54 } 55 } 56 57 /** 58 * Process taxonomy term sitemap links. 59 * 60 * @param $tids 61 * An array of taxonomy term IDs. 62 */ 63 function xmlsitemap_taxonomy_xmlsitemap_process_taxonomy_term_links(array $tids) { 64 foreach ($tids as $tid) { 65 $term = taxonomy_get_term($tid); 66 $link = xmlsitemap_taxonomy_create_link($term); 67 xmlsitemap_link_save($link); 68 } 69 } 70 71 /** 72 * Implements hook_form_FORM_ID_alter(). 73 * 74 * @see taxonomy_form_vocabulary() 75 * @see xmlsitemap_add_link_bundle_settings() 76 */ 77 function xmlsitemap_taxonomy_form_taxonomy_form_vocabulary_alter(&$form, $form_state) { 78 $vid = isset($form['vid']['#value']) ? $form['vid']['#value'] : 0; 79 80 module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin'); 81 xmlsitemap_add_link_bundle_settings($form, $form_state, 'taxonomy_term', $vid); 82 83 // The submit and delete buttons need to be weighted down. 84 $form['submit'] += array('#weight' => 50); 85 if (isset($form['delete'])) { 86 $form['delete'] += array('#weight' => 51); 87 } 88 } 89 90 /** 91 * Implements hook_form_FORM_ID_alter(). 92 */ 93 function xmlsitemap_taxonomy_form_taxonomy_form_term_alter(&$form, $form_state) { 94 // Because the same form is used for deletion in confirm_form, we must check 95 // if the normal editing form elements are present. Hopefully this is fixed 96 // in Drupal 7. 97 if (isset($form['identification'])) { 98 // Add the link options. 99 module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin'); 100 xmlsitemap_add_form_link_options($form, 'taxonomy_term', $form['vid']['#value'], $form['#term']['tid']); 101 102 // The submit and delete buttons need to be weighted down. 103 $form['submit'] += array('#weight' => 100); 104 if (isset($form['delete'])) { 105 $form['delete'] += array('#weight' => 110); 106 } 107 } 108 } 109 110 /** 111 * Implements hook_taxonomy(). 112 */ 113 function xmlsitemap_taxonomy_taxonomy($op, $type, $array = NULL) { 114 if ($type == 'vocabulary') { 115 $vid = $array['vid']; 116 if ($op == 'insert' || $op == 'update') { 117 if (isset($array['xmlsitemap'])) { 118 xmlsitemap_link_bundle_settings_save('taxonomy_term', $vid, $array['xmlsitemap']); 119 } 120 } 121 elseif ($op == 'delete') { 122 xmlsitemap_link_bundle_delete('taxonomy_term', $vid); 123 } 124 } 125 if ($type == 'term') { 126 $tid = $array['tid']; 127 if ($op == 'insert' || $op == 'update') { 128 $term = (object) $array; 129 $link = xmlsitemap_taxonomy_create_link($term); 130 xmlsitemap_link_save($link); 131 } 132 elseif ($op == 'delete') { 133 xmlsitemap_link_delete('taxonomy_term', $tid); 134 } 135 } 136 } 137 138 /** 139 * Create a sitemap link from a taxonomy term. 140 * 141 * @param $term 142 * A taxonomy term object. 143 * @return 144 * An array representing a sitemap link. 145 */ 146 function xmlsitemap_taxonomy_create_link(stdClass &$term) { 147 if (!isset($term->xmlsitemap)) { 148 $term->xmlsitemap = array(); 149 if ($term->tid && $link = xmlsitemap_link_load('taxonomy_term', $term->tid)) { 150 $term->xmlsitemap = $link; 151 } 152 } 153 154 $settings = xmlsitemap_link_bundle_load('taxonomy_term', $term->vid); 155 156 $term->xmlsitemap += array( 157 'id' => $term->tid, 158 'type' => 'taxonomy_term', 159 'subtype' => $term->vid, 160 'loc' => taxonomy_term_path($term), 161 'status' => $settings['status'], 162 'status_default' => $settings['status'], 163 'status_override' => 0, 164 'priority' => $settings['priority'], 165 'priority_default' => $settings['priority'], 166 'priority_override' => 0, 167 ); 168 169 // The following values must always be checked because they are volatile. 170 // @todo How can/should we check taxonomy term access? 171 $term->xmlsitemap['access'] = 1; 172 $term->xmlsitemap['language'] = isset($term->language) ? $term->language : ''; 173 174 return $term->xmlsitemap; 175 } 176 177 /** 178 * Calculate the priority of a taxonomy term based on depth and weight. 179 */ 180 //function xmlsitemap_taxonomy_calculate_term_priority(stdClass $term) { 181 // // Calculate priority. 182 // // Min weight = -128 183 // // Max weight = 127 184 // // Max depth = ? 185 //} 186 187 /** 188 * Find the tree depth of a taxonomy term. 189 * 190 * @param $term 191 * A taxonomy term object. 192 * @return 193 * The tree depth of the term. 194 */ 195 function xmlsitemap_taxonomy_get_term_depth(stdClass $term) { 196 static $depths = array(); 197 198 if (!isset($depths[$term->tid])) { 199 if ($parent = db_result(db_query("SELECT parent FROM {term_hierarchy} WHERE tid = %d", $term->tid))) { 200 // If the term has a parent, the term's depth is the parent's depth + 1. 201 if (!isset($depths[$parent])) { 202 $depths[$parent] = xmlsitemap_taxonomy_get_term_depth($parent); 203 } 204 $depths[$term->tid] = $depths[$parent] + 1; 205 } 206 else { 207 // Term has no parents, so depth is 0. 208 $depths[$term->tid] = 0; 209 } 210 } 211 212 return $depths[$term->tid]; 213 } 214 215 /** 216 * Find the number of nodes that are associated with a taxonomy term. 217 * 218 * @param $term 219 * A taxonomy term object. 220 * @return 221 * The number of nodes associated with the term. 222 */ 223 function xmlsitemap_taxonomy_get_node_count(stdClass $term) { 224 // @todo Use db_rewrite_sql() w/ switch user. 225 return db_result(db_query_range("SELECT COUNT(tn.nid) FROM {term_node} tn LEFT JOIN {node n} USING (nid) WHERE tn.tid = %d AND n.status = 1", $term->tid, 0, 1)); 226 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |