/[drupal]/contributions/modules/node_redirect/node_redirect.module
ViewVC logotype

Contents of /contributions/modules/node_redirect/node_redirect.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Wed Nov 5 05:05:04 2008 UTC (12 months, 3 weeks ago) by jrglasgow
Branch: MAIN
CVS Tags: DRUPAL-6--1-1, HEAD
Changes since 1.2: +35 -5 lines
File MIME type: text/x-php
had to port some changes I had made in the D5 version just before committing
1 <?php
2 // $Id: node_redirect.module,v 1.2 2008/11/05 03:51:53 jrglasgow Exp $
3
4 /**
5 * Implementation of hook_menu().
6 */
7 function node_redirect_menu() {
8 $items = array();
9 $items['admin/settings/node_redirect'] = array(
10 'title' => 'Node Redirect',
11 'description' => 'Manage Node Redirect Settings',
12 'page callback' => 'drupal_get_form',
13 'page arguments' => array('_node_redirect_admin_settings_form'),
14 'access arguments' => array('administer site configuration'),
15 );
16 if (variable_get('node_redirect_menu_item_name', '') && (variable_get('node_redirect_menu', 'none') != 'none') && variable_get('node_redirect_path_base', '')) {
17 $items['redirect'] = array(
18 'title' => variable_get('node_redirect_menu_item_name', ''),
19 'description' => variable_get('node_redirect_form_question', 'Where would you like to go?'),
20 'menu_name' => variable_get('node_redirect_menu', ''),
21 'page callback' => '_node_redirect_redirect',
22 'access callback' => TRUE,
23 '#attributes' => array(
24 'class' => 'thickbox',
25 ),
26 'type' => MENU_NORMAL_ITEM,
27 );
28 }
29 return $items;
30 }
31 /**
32 * create the node redirection page
33 */
34 function _node_redirect_redirect() {
35 $output .= drupal_get_form('_node_redirect_redirect_form');
36 return $output;
37 }
38 /**
39 * cerate the node redirection form
40 */
41 function _node_redirect_redirect_form() {
42 $form = array();
43 $form['node_redirect_node'] = array(
44 '#title' => variable_get('node_redirect_menu_item_name'),
45 '#description' => variable_get('node_redirect_form_question'),
46 '#type' => 'textfield',
47 );
48 $form['submit'] = array(
49 '#type' => 'submit',
50 '#value' => 'Submit',
51 );
52 return $form;
53 }
54 /**
55 * handle submission of node redirection form
56 */
57 function _node_redirect_redirect_form_submit($form, &$form_state) {
58 if (!empty($form_state['values']['node_redirect_node'])) {
59 $base = variable_get('node_redirect_path_base');
60 $path = array();
61 $path[] = $base;
62 $path[] = $form_state['values']['node_redirect_node'];
63 $full_path = implode('/', $path);
64 $sql = "
65 SELECT
66 *
67 FROM
68 {url_alias}
69 WHERE
70 dst='%s'
71 ";
72 $result = db_query($sql, $full_path);
73 if ($row = db_fetch_object($result)) {
74 drupal_goto($full_path);
75 }
76 else {
77 drupal_set_message(str_replace('%entry', check_plain($form['node_redirect_node']), variable_get('node_redirect_path_error', 'Page was not found!')));
78 }
79 }
80 }
81 function _node_redirect_admin_settings_form() {
82 $form = array();
83 $form['node_redirect_menu_item_name'] = array(
84 '#title' => t('Menu Item Name'),
85 '#description' => t('What name do you want the menu item to have?'),
86 '#type' => 'textfield',
87 '#default_value' => variable_get('node_redirect_menu_item_name', ''),
88 '#required' => TRUE,
89 );
90 $menus = array('none' => 'None');
91 $menus += menu_get_menus(TRUE);
92 $form['node_redirect_menu'] = array(
93 '#title' => t('Menu'),
94 '#description' => t('Which menu do you want the menu item attached to?'),
95 '#type' => 'select',
96 '#default_value' => variable_get('node_redirect_menu', 'none'),
97 '#options' => $menus,
98 );
99 $form['node_redirect_form_question'] = array(
100 '#title' => t('Form Question'),
101 '#description' => t('What question do you want the user to be asked when they see the redirection form?'),
102 '#type' => 'textfield',
103 '#required' => TRUE,
104 '#default_value' => variable_get('node_redirect_form_question', 'Where would you like to go?'),
105 );
106 $form['node_redirect_path_base'] = array(
107 '#title' => t('Path Base'),
108 '#description' => t('What is the base path for the redirection?'),
109 '#type' => 'textfield',
110 '#required' => TRUE,
111 '#default_value' => variable_get('node_redirect_path_base', ''),
112 );
113 $form['node_redirect_path_error'] = array(
114 '#title' => t('Error Message'),
115 '#description' => t('What message do you want the user to see when the requested page does not exist? The variable %entry will be replaced with the text given by the user.'),
116 '#type' => 'textfield',
117 '#default_value' => variable_get('node_redirect_path_error', 'Page was not found!'),
118 );
119 $form['submit'] = array(
120 '#type' => 'submit',
121 '#value' => t('Save Settings'),
122 );
123 $form['reset'] = array(
124 '#type' => 'submit',
125 '#value' => t('Reset to Defaults'),
126 );
127 return $form;
128 }
129 function _node_redirect_admin_settings_form_submit($form, &$form_state) {
130 #drupal_set_message('$form_state = <pre>'. print_r($form_state, TRUE) .'</pre>');
131 foreach ($form_state['values'] as $key => $value) {
132 //drupal_set_message($key .' => '. $value);
133 switch ($form_state['values']['op']) {
134 case 'Save Settings':
135 if (strpos($key, 'node_redirect') !== FALSE) {
136 variable_set($key, $value);
137 }
138 break;
139 case 'Reset to Defaults':
140 if (strpos($key, 'node_redirect') !== FALSE) {
141 variable_del($key, $value);
142 }
143 break;
144 }
145 }
146 // clear the menu cache so the new item can be added
147 menu_cache_clear();
148 }
149 function node_redirect_link_alter(&$item, $menu) {
150 $args = func_get_args();
151 //drupal_set_message('$args = <pre>'. print_r($args, TRUE) .'</pre>');
152 }
153
154 function node_redirect_init() {
155 $title = variable_get('node_redirect_form_question', 'Where would you like to go?');
156 //drupal_set_message('title = '. $title);
157 $js = "$(function() {
158 var class = $(\"a[title='". $title ."']\").attr('class') + ' thickbox';
159 $(\"a[title='". $title ."']\").attr('class', class);
160 var href = $(\"a[title='". $title ."']\").attr('href') + '?TB_iframe=true&height=200&width=300&modal=true';
161 $(\"a[title='". $title ."']\").attr('href', href);
162 })";
163 //drupal_set_message('$js = '. $js);
164 drupal_add_js($js, 'inline');
165 }

  ViewVC Help
Powered by ViewVC 1.1.2