/[drupal]/contributions/modules/front/front_page.module
ViewVC logotype

Contents of /contributions/modules/front/front_page.module

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


Revision 1.81 - (show annotations) (download) (as text)
Tue Apr 29 08:34:03 2008 UTC (18 months, 4 weeks ago) by augustin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.80: +2 -2 lines
File MIME type: text/x-php
#251292 core bug: no html allowed in fieldset title causing the role name
not to be displayed in the fieldset title.
1 <?php
2 // $Id: front_page.module,v 1.80 2008/04/29 08:08:03 augustin Exp $
3 /**
4 *
5 * This module allows the site admin to set advanced front page settings.
6 *
7 * This version works with Drupal 5.0 and will not work with earlier versions of Drupal
8 *
9 * This module was developed by Dublin Drupaller and various members of the drupal community
10 *
11 * If you have any ideas/patches or requests, please post them on the drupal.org
12 * site or email us at gus(at)modernmediamuse.com
13 *
14 */
15
16 /**
17 * Implementation of hook_help().
18 */
19 function front_page_help($section) {
20 switch ($section) {
21 case 'admin/settings/front':
22 $roles = user_roles();
23 $special_note = '';
24 if (count($roles) >= 3) {
25 krsort($roles);
26 $special_note = '<fieldset>'. t('<legend>front page by role usage</legend><p><strong>Note:</strong>When using the front pages by role option, please note that if a user has multiple roles the first role match will determine which front page they see. Here is the order that the roles will be checked (from left to right).</p>') .'<p>';
27 foreach ($roles as $role_id => $role_name) {
28 $special_note .= "<strong>$role_id</strong> $role_name | ";
29 }
30 $special_note .= '</p>'. t('<p>The default setting for new roles is SAME AS AUTHENTICATED USERS.</p>') .'</fieldset>';
31 }
32 return t('<p>Setup custom front pages for your site. Click on the option to expand the form and customise your settings.</p><p><em>Anonymous User</em> = visitor not logged in | <em>Authenticated User</em> = visitor who is logged in</p>') . $special_note;
33 }
34 }
35
36 /**
37 * Implementation of hook_menu.
38 */
39 function front_page_menu() {
40 $items['admin/settings/front'] = array(
41 'title' => 'Advanced front page settings',
42 'description' => 'Specify a unique layout or splash page based on role type - override your HOME and breadcrumb links - display a custom mission style notice for users who haven\'t visited in a while - disable site and display a \'temporarily offline\' message.',
43 'page callback' => 'drupal_get_form',
44 'page arguments' => array('front_page_admin'),
45 'access arguments' => array('administer menu'));
46 $items['front_page'] = array(
47 'title' => '',
48 'page callback' => 'front_page',
49 'access arguments' => array('access frontpage'),
50 'type' => MENU_SUGGESTED_ITEM);
51 return $items;
52 }
53
54 /**
55 * Implementation of hook_perm.
56 */
57 function front_page_perm() {
58 return array('access frontpage');
59 }
60
61 /**
62 * This function sets up the admin/build/front_page settings page.
63 *
64 */
65 function front_page_admin() {
66 // Load any existing settings and build the by redirect by role form
67 $form['byrole'] = array(
68 '#type' => 'fieldset',
69 '#title' => t('Home pages'),
70 '#description' => t('Designate a home page for each role. "Splash" pages will be used only when users are connecting from external sites. Spash pages must be in the form "node/x" where x is the id of a node, e.g., "node/21" (without the quotes). Only the body of the node will be displayed. Home pages are displayed when users follow internal home links, or for external links where there is no splash page designated, and may point to any page on the site.'),
71 '#theme' => 'front_page_roles',
72 '#collapsible' => true,
73 '#tree' => true,
74 );
75
76 // build the form for roles
77 $roles = user_roles();
78 foreach (element_children($roles) as $role) {
79 $rolename = $roles[$role];
80
81 $form[$role] = array(
82 '#type' => 'fieldset',
83 '#collapsible' => true,
84 '#collapsed' => true,
85 '#title' => t('Front Page for !rolename.', array('!rolename' => $rolename)),
86 );
87
88 $form[$role]['front_'. $role .'_text'] = array(
89 '#type' => 'textarea',
90 '#title' => t('Body'),
91 '#default_value' => variable_get('front_'. $role .'_text', ''),
92 '#cols' => 60,
93 '#rows' => 20,
94 '#description' => t('Paste your HTML or TEXT here.') .'<br /><br />'. t('You can paste in the full HTML code for a complete page and include a different style sheet in the HEAD of the document if you want a completely different layout and style to the rest of your site.'),
95 );
96
97 // Set the type options common for all roles.
98 $options = array(
99 'themed' => t('themed'),
100 'full' => t('full'),
101 'redirect' => t('redirect'),
102 );
103
104 // Set the description common for all roles.
105 $description = '<dl><dt>'. t('themed') .'</dt>
106 <dd>'. t('means your default layout, theme and stylesheet will be loaded with your custom front_page.') .'</dd></dl>';
107 $description .= '<dl><dt>'. t('full') .'</dt>
108 <dd>'. t('allows you to have a completely different layout, style sheet etc.') .'</dd></dl>';
109 $description .= '<dl><dt>'. t('redirect') .'</dt>
110 <dd>'. t('will automatically redirect visitors already logged in to a specific page specified in the REDIRECT TO box.') .'</dd></dl>';
111
112 // Set the options that varies from role to role.
113 switch ($role) {
114 case 1: // Anonymous user
115 $default_value = variable_get('front_1_type', 'themed');
116 break;
117 case 2: // Authenticated user
118 $default_value = variable_get('front_2_type', 'same_as_anon');
119 $options['same_as_anon'] = t('same as anonymous users');
120 $description .= '<dl><dt>'. t('same as anonymous users') .'</dt>
121 <dd>'. t('will display the same content as for Anonymous users.') .'</dd></dl>';
122 break;
123 default: // Other roles
124 $default_value = variable_get('front_'. $role .'_type', 'same_as_anon');
125 $options['same_as_anon'] = t('same as anonymous users');
126 $options['sameasauth'] = t('same as authenticated users');
127 $description .= '<dl><dt>'. t('same as anonymous users') .'</dt>
128 <dd>'. t('will display the same content as for Anonymous users.') .'</dd></dl>';
129 $description .= '<dl><dt>'. t('same as authenticated users') .'</dt>
130 <dd>'. t('will display the same content as for Authenticated (logged in) users.') .'</dd></dl>';
131 break;
132 }
133
134 $form[$role]['front_'. $role .'_type'] = array(
135 '#type' => 'select',
136 '#title' => t('Select type'),
137 '#default_value' => $default_value,
138 '#options' => $options,
139 '#description' => '<p>'. $description .'</p>',
140 );
141
142 $form[$role]['front_'. $role .'_redirect'] = array(
143 '#type' => 'textfield',
144 '#title' => t('Redirect to'),
145 '#default_value' => variable_get('front_'. $role .'_redirect', 'node'),
146 '#cols' => 20,
147 '#rows' => 1,
148 '#description' => t('If you have selected <strong>REDIRECT</strong> you need to specify where the user should be pointed to. If you are not using clean URLs, specify the part after "?q=". If unsure, specify "node".'),
149 );
150
151 $form[$role]['front_'. $role .'_php'] = array(
152 '#type' => 'checkbox',
153 '#title' => t('Allow embedded PHP code in this front page'),
154 '#return_value' => 1, '#default_value' => variable_get('front_'. $role .'_php', 0),
155 '#description' => t('If this option is enabled, the body text can have embedded &lt;?php...?&gt; tags with PHP code inside. Click on the special Handbook pages for tips on <a href="http://drupal.org/node/23220">Using PHP snippets in your front_page</a>.'),
156 );
157 }
158
159 $form['front_offline'] = array(
160 '#type' => 'fieldset',
161 '#collapsible' => true,
162 '#collapsed' => true,
163 '#title' => t('Custom "Temporarily Offline" message and disable site for all except admins'),
164 );
165
166 $form['front_offline']['site_offline'] = array(
167 '#type' => 'radios',
168 '#title' => t('Site maintenance'),
169 '#default_value' => variable_get('site_offline', 0),
170 '#options' => array(t('Online'), t('Off-line')),
171 '#description' => t('When set to "Online", all visitors will be able to browse your site normally. When set to "Off-line", only users with the "administer site configuration" permission will be able to access your site to perform maintenance; all other visitors will see the site off-line message configured below. Authorized users can log in during "Off-line" mode directly via the <a href="@user-login">user login</a> page.', array('@user-login' => url('user', array('query' => drupal_get_destination())))),
172 );
173
174 $form['front_offline']['site_offline_message'] = array(
175 '#type' => 'textarea',
176 '#title' => t('Site off-line message'),
177 '#default_value' => variable_get('site_offline_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', t('This Drupal site'))))),
178 '#description' => t('Message to show visitors when the site is in off-line mode.')
179 );
180
181 $form['special_notice'] = array(
182 '#type' => 'fieldset',
183 '#collapsible' => true,
184 '#collapsed' => true,
185 '#title' => t('Custom mission for Authenticated Users who haven\'t visited the site for a set period'),
186 );
187
188 $form['special_notice']['special_notice_time'] = array(
189 '#type' => 'select',
190 '#title' => t('Been away for'),
191 '#default_value' => variable_get('special_notice_time', ''),
192 '#options' => array(
193 'one day' => t('one day') ,
194 'one week' => t('one week') ,
195 'one month' => t('one month'),
196 'three months' => t('three months'),
197 'six months' => t('six months'),
198 'one year' => t('one year'),
199 ),
200 '#description' => t('<p>The length of time to check for when users see the special notice which will be displayed as a <em>mission</em> style notice on the front page.<p> '),
201 );
202
203 $form['special_notice']['special_notice_text'] = array(
204 '#type' => 'textarea',
205 '#title' => t('Body'),
206 '#default_value' => variable_get('special_notice_text', ''),
207 '#cols' => 60,
208 '#rows' => 10,
209 '#description' => t('Paste your HTML or TEXT here. It will be displayed as a <em>mission</em> style notice on the front page.'),
210 );
211
212 $form['override'] = array(
213 '#type' => 'fieldset',
214 '#collapsible' => true,
215 '#collapsed' => true,
216 '#title' => t('Override your HOME breadcrumb links'),
217 );
218
219 $form['override']['front_page_breadcrumb'] = array(
220 '#type' => 'checkbox',
221 '#title' => t('Redirect your site HOME links'),
222 '#return_value' => 1,
223 '#default_value' => variable_get('front_page_breadcrumb', 0),
224 '#description' => t('Check this box if you want to redirect users who click on any HOME links (including the HOME breadcrumb link). Useful if you have a splash page you don\'t want users brought back to when they click on HOME links from within your site.')
225 );
226
227 $form['override']['front_page_breadcrumb_redirect'] = array(
228 '#type' => 'textfield',
229 '#title' => t('Redirect your site HOME links to'),
230 '#default_value' => variable_get('front_page_breadcrumb_redirect', ''),
231 '#cols' => 20, '#rows' => 1,
232 '#description' => t('Specify where the user should be redirected to. An example would be <em>node/12</em>. Leave blank when you\'re not using HOME redirect.'),
233 '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
234 );
235
236 $form['site'] = array(
237 '#type' => 'fieldset',
238 '#collapsible' => true,
239 '#collapsed' => false,
240 '#title' => t('Activate your front_page settings'),
241 );
242
243 $form['site']['site_frontpage'] = array(
244 '#type' => 'textfield',
245 '#title' => t('Default front page'),
246 '#default_value' => variable_get('site_frontpage', 'node'),
247 '#size' => 40,
248 '#description' => t('Change this setting to <em>front_page</em> to activate your front page settings.'),
249 '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
250 );
251
252
253 return system_settings_form($form);
254 }
255
256
257 /***********************************************
258 * Function to handle the display of the front page.
259 */
260 function front_page() {
261 // Set a default value for landing zone if no front_page variables are filled.
262 // If the module is turned on but empty in certain areas then a redirection loop will occur.
263 // Defaulting to 'node' prevents this.
264 $output = 'node';
265
266 // Set the time to check against the last access of the user by the variable set in settings.
267 switch (variable_get('front_special_notice_time', '')) {
268 case 'one day' :
269 $check_time = (time() - (24 * 60 * 60));
270 break;
271 case 'one week' :
272 $check_time = (time() - (7 * 24 * 60 * 60));
273 break;
274 case 'one month' :
275 $check_time = (time() - (30 * 24 * 60 * 60));
276 break;
277 case 'three months' :
278 $check_time = (time() - (90 * 24 * 60 * 60));
279 break;
280 case 'six months' :
281 $check_time = (time() - (180 * 24 * 60 * 60));
282 break;
283 case 'one year' :
284 $check_time = (time() - (360 * 24 * 60 * 60));
285 break;
286 }
287
288 //this checks to see if you are overriding HOME links on the site
289 if (variable_get('front_page_breadcrumb', 0)) {
290 // This checks to see if the referer is an internal HOME link or not.
291 $newhome = variable_get('front_page_breadcrumb_redirect', 'node');
292 $ref = $_SERVER['HTTP_REFERER'];
293 global $user, $base_url;
294 $parsed_url=parse_url($base_url);
295 $domain = $parsed_url['host'];
296 if (stristr($ref, $domain)) {
297 drupal_goto($path = $newhome, $query = null, $fragment = null);
298 }
299 }
300
301 // the following is the code that loads the front_page settings
302 global $user;
303
304 // if the user is not logged in load up the page for anonymous users
305 if (!$user->uid) {
306 $output = variable_get('front_1_text', 'drupal');
307
308 // If PHP code execution is allowed then use eval.
309 if (variable_get('front_1_php', 0)) {
310 $output = drupal_eval($output);
311 }
312 $fptype = variable_get('front_1_type', 'drupal');
313 switch ($fptype) {
314 case 'themed':
315 print theme('page', $output);
316 return;
317
318 case 'full':
319 print $output;
320 return;
321
322 case 'redirect':
323 $output = variable_get('front_1_redirect', 'drupal');
324 drupal_goto($path = $output, $query = null, $fragment = null);
325 break;
326 }
327 }
328
329
330 $roles = ""; //make sure the roles variable is clear
331 $roles = user_roles(); //load up the user roles for the site
332 krsort($roles); //reverse the order of role types so it checks the highest or more recent role type first.
333 $siteroles = count($roles);
334
335 /* this is where the front page by role stuff happens */
336 if ($user->uid) { //if the user is logged in and the site has more than 2 roles setup
337 foreach ($roles as $role_id => $role_name) { // run through each role type starting at the most recent working backwards
338 // if the current visitor has a role type that matches and if the front page setting for that role type is not empty.
339 if (array_key_exists($role_id, $user->roles)) {
340 if ((variable_get('special_notice_text', '') != '') && ($user->access < $check_time)) {
341 $output = '<div id="mission">';
342 $output .= variable_get('special_notice_text', '');
343 $output .= '</div>';
344 $output .= variable_get('front_'. $role_id .'_text', '');
345 }
346 else {
347 $output = variable_get('front_'. $role_id .'_text', '');
348 }
349 // if PHP code execution is allowed then use eval
350 if (variable_get('front_'. $role_id .'_php', 0)) {
351 $output = drupal_eval($output);
352 }
353 $fptype = variable_get('front_'. $role_id .'_type', 'drupal'); //check whether it is a themed or full front page.
354 switch ($fptype) {
355 case 'themed':
356 print theme('page', $output);
357 return;
358
359 case 'full':
360 print $output;
361 return;
362
363 case 'same_as_anon':
364 $output = variable_get('front_1_text', 'drupal');
365 // If PHP code execution is allowed then use eval.
366 if (variable_get('front_1_php', 0)) {
367 $output = drupal_eval($output);
368 }
369 $fptype = variable_get('front_1_type', 'drupal');
370 switch ($fptype) {
371 case 'themed':
372 print theme('page', $output);
373 return;
374
375 case 'full':
376 print $output;
377 return;
378
379 case 'redirect':
380 $output = variable_get('front_1_redirect', 'drupal');
381 drupal_goto($path = $output, $query = null, $fragment = null);
382 break;
383 }
384
385 case 'sameasauth':
386 $output = variable_get('front_2_text', 'drupal');
387 // If PHP code execution is allowed then use eval.
388 if (variable_get('front_2_php', 0)) {
389 $output = drupal_eval($output);
390 }
391 $fptype = variable_get('front_2_type', 'drupal');
392 switch ($fptype) {
393 case 'themed':
394 print theme('page', $output);
395 return;
396
397 case 'full':
398 print $output;
399 return;
400
401 case 'redirect':
402 $output = variable_get('front_2_redirect', 'drupal');
403 drupal_goto($path = $output, $query = null, $fragment = null);
404 break;
405 }
406
407 case 'redirect':
408 $output = variable_get('front_'. $role_id .'_redirect', 'drupal');
409 drupal_goto($path = $output, $query = null, $fragment = null);
410 break;
411
412 }
413 }
414 }
415 }
416 }
417

  ViewVC Help
Powered by ViewVC 1.1.2