| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: project_legacy_paths.module,v 1.1 2009/01/12 22:57:50 dww Exp $ 3 4 /** 5 * @file Redirect project browsing paths from the Drupal 5 form to the Drupal 6 form. 6 */ 7 8 function project_legacy_paths_menu(){ 9 $items = array(); 10 11 // Project browsing pages 12 if (project_use_taxonomy()) { 13 $items['project/%project_legacy_paths_top_level_term/%'] = array( 14 'access callback' => TRUE, 15 'page callback' => 'project_legacy_paths_page_callback', 16 'page arguments' => array(1, 2), 17 ); 18 $items['project/%project_legacy_paths_top_level_term/%/%'] = array( 19 'access callback' => TRUE, 20 'page callback' => 'project_legacy_paths_page_callback', 21 'page arguments' => array(1, 2, 3), 22 ); 23 } 24 return $items; 25 } 26 27 /** 28 * Menu load function for project type top level terms (eg. modules, themes, etc.). 29 */ 30 function project_legacy_paths_top_level_term_load($term_name) { 31 $project_type_vid = _project_get_vid(); 32 if (empty($project_type_vid)) { 33 return FALSE; 34 } 35 36 $db_result = db_query(db_rewrite_sql("SELECT * FROM {term_data} t INNER JOIN {term_hierarchy} th ON t.tid = th.tid WHERE LOWER(t.name) = LOWER('%s') AND th.parent = 0 AND t.vid = %d", 't', 'tid'), trim($term_name), $project_type_vid); 37 $result = array(); 38 while ($term = db_fetch_object($db_result)) { 39 $result[] = $term; 40 } 41 if (!empty($result)) { 42 return $result[0]; 43 } 44 else { 45 return FALSE; 46 } 47 } 48 49 /** 50 * Implementation of hook_project_sort_methods(). 51 * 52 * The code in this function is the (slightly modified) relevant piece of code 53 * from the project_project_sort_methods() function in the Drupal 5 version 54 * of the project module. This code is here because the Drupal 6 55 * version of the project module no longer contains this function. 56 */ 57 function project_legacy_paths_project_sort_methods($op, $method = NULL) { 58 if ($op == 'methods') { 59 $methods = array(); 60 $methods['name'] = 'project'; 61 $methods['date'] = 'project'; 62 // The D5 version put the next line within an if (project_use_taxonomy()) 63 // block, but since we're already checking for that in 64 // project_legacy_paths_menu() there is no need to check again. 65 $methods['category'] = 'project'; 66 return $methods; 67 } 68 } 69 70 /** 71 * Validate the arguments to see if they would have lead to an actual page 72 * in the Drupal 5 version of the project module. If not, the user 73 * will be given a page not found error. Otherwise, determine what the D6 74 * URL would be and redirect the user there. 75 */ 76 function project_legacy_paths_page_callback($top_level_term, $sort_method = NULL, $category_tid = NULL) { 77 // Validate $sort_method. 78 $sort_methods = module_invoke_all('project_sort_methods', 'methods'); 79 if (!empty($sort_methods) && !empty($sort_method)) { 80 if (!array_key_exists($sort_method, $sort_methods)) { 81 return MENU_NOT_FOUND; 82 } 83 } 84 else { 85 return MENU_NOT_FOUND; 86 } 87 88 // Validate $category_tid. 89 if (isset($category_tid)) { 90 if (!is_numeric($category_tid)) { 91 return MENU_NOT_FOUND; 92 } 93 94 // Since 'category' is the only sorting method that uses $category_tid, make 95 // sure the sort method is 'category'. 96 if ($sort_method != 'category') { 97 return MENU_NOT_FOUND; 98 } 99 100 // Determine if $category_tid has $top_level_term as its parent. 101 if (!db_result(db_query(db_rewrite_sql("SELECT t.tid FROM {term_data} t INNER JOIN {term_hierarchy} th ON t.tid = th.tid WHERE t.tid = %d AND th.parent = %d", 't', 'tid'), $category_tid, $top_level_term->tid))) { 102 return MENU_NOT_FOUND; 103 } 104 } 105 106 // At this point we know that all of the parameters to this function 107 // are valid and would have returned a page in the D5 version of project. 108 // Now, we just need to redirect to the appropriate URL. 109 110 // @TODO: Below are several variables which we should not hard code. 111 // We need to figure out how exactly we want to do this. Perhaps put the code 112 // below in a separate hook function or something. 113 $base = 'project'; 114 $sort_by_identifier = 'sort_by'; 115 $project_type_term_identifier = 'type'; 116 117 $base_path = $base . '/' . strtolower($top_level_term->name); 118 119 // Build an array with query key/value properties. 120 $query = array(); 121 if ($sort_method == 'date') { 122 $query[$sort_by_identifier] = 'changed'; 123 } 124 elseif ($sort_method == 'name') { 125 $query[$sort_by_identifier] = 'title'; 126 } 127 elseif ($sort_method == 'category') { 128 $query[$project_type_term_identifier] = $category_tid; 129 } 130 drupal_goto($base_path, $query, NULL, 301); 131 } 132
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 |