| 1 |
<?php |
<?php |
| 2 |
/* $Id$ |
/* $Id:$ |
| 3 |
* |
* |
| 4 |
* Drupal Module: Path Access |
* Drupal Module: Path Access |
| 5 |
* Restrict access to any drupal path on a per user role basis |
* Restrict access to any drupal path on a per user role basis |
| 47 |
// Match path if necessary |
// Match path if necessary |
| 48 |
if ($pages) { |
if ($pages) { |
| 49 |
// The current page |
// The current page |
| 50 |
$path = drupal_get_path_alias($_GET['q']); |
$path = drupal_get_path_alias(check_plain($_GET['q'])); |
| 51 |
|
|
| 52 |
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($pages, '/')) .')$/'; |
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($pages, '/')) .')$/'; |
| 53 |
$page_match = ($visibility xor preg_match($regexp, $path)); |
$page_match = ($visibility xor preg_match($regexp, $path)); |
| 58 |
|
|
| 59 |
|
|
| 60 |
// Check that the current page is not a protected page before blocking user |
// Check that the current page is not a protected page before blocking user |
| 61 |
if($page_match && !path_access_protected_pages($path)) { |
if ($page_match && !path_access_protected_pages($path)) { |
| 62 |
// Initialize locale |
// Initialize locale |
| 63 |
$GLOBALS['locale'] = locale_initialize(); |
$GLOBALS['locale'] = locale_initialize(); |
| 64 |
drupal_access_denied(); |
drupal_access_denied(); |
| 65 |
exit; |
exit; |
| 66 |
} |
} |
|
|
|
| 67 |
} |
} |
| 68 |
|
|
| 69 |
|
|
| 105 |
|
|
| 106 |
$output = theme('table', $header, $rows); |
$output = theme('table', $header, $rows); |
| 107 |
|
|
| 108 |
print theme('page', $output); |
return $output; |
| 109 |
} |
} |
| 110 |
|
|
| 111 |
|
|
| 113 |
* Menu callback; displays the configuration form. |
* Menu callback; displays the configuration form. |
| 114 |
*/ |
*/ |
| 115 |
function path_access_admin_role_configure() { |
function path_access_admin_role_configure() { |
| 116 |
$roleid = arg(4); |
$roleid = (integer)arg(4); |
| 117 |
|
|
| 118 |
$settings = db_fetch_array(db_query("SELECT * FROM {path_access} pa INNER JOIN {role} r ON pa.rid = r.rid WHERE pa.rid = %d", $roleid)); |
$settings = db_fetch_array(db_query("SELECT * FROM {path_access} pa INNER JOIN {role} r ON pa.rid = r.rid WHERE pa.rid = %d", $roleid)); |
| 119 |
|
|
| 120 |
// Obtain role name for the page if there is no existing path settings for this role id |
// Obtain role name for the page if there is no existing path settings for this role id |
| 121 |
if(!$settings) { |
if (!$settings) { |
| 122 |
$rolename = db_result(db_query("SELECT name FROM {role} WHERE rid = %d", $roleid)); |
$rolename = db_result(db_query("SELECT name FROM {role} WHERE rid = %d", $roleid)); |
| 123 |
$pid = db_next_id('path_access'); |
$pid = db_next_id('path_access'); |
| 124 |
db_query("INSERT INTO {path_access} (pid, rid, pages, visibility) VALUES (%d, %d, '', '')", $pid, $roleid); |
db_query("INSERT INTO {path_access} (pid, rid, pages, visibility) VALUES (%d, %d, '', '')", $pid, $roleid); |
| 168 |
// prevent the logout page from being listed |
// prevent the logout page from being listed |
| 169 |
$pages = explode("\n", $form['pages']); |
$pages = explode("\n", $form['pages']); |
| 170 |
|
|
| 171 |
if(in_array('logout', $pages)) { |
if (in_array('logout', $pages)) { |
| 172 |
form_set_error('pages', t('You cannot block access to the %logout page.', array('%logout' => 'logout'))); |
form_set_error('pages', t('You cannot block access to the %logout page.', array('%logout' => 'logout'))); |
| 173 |
} |
} |
| 174 |
} |
} |
| 181 |
db_query("UPDATE {path_access} SET visibility = %d, pages = '%s' WHERE rid = %d", $form['visibility'], $form['pages'], $form['rid']); |
db_query("UPDATE {path_access} SET visibility = %d, pages = '%s' WHERE rid = %d", $form['visibility'], $form['pages'], $form['rid']); |
| 182 |
|
|
| 183 |
drupal_set_message('The path access configuration has been saved.'); |
drupal_set_message('The path access configuration has been saved.'); |
| 184 |
drupal_goto('admin/user/pathaccess'); |
|
| 185 |
|
return 'admin/user/pathaccess'; |
| 186 |
} |
} |
| 187 |
|
|
| 188 |
|
|