summaryrefslogtreecommitdiff
path: root/includes/path.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/path.inc')
-rw-r--r--includes/path.inc62
1 files changed, 62 insertions, 0 deletions
diff --git a/includes/path.inc b/includes/path.inc
index 3ce40a818..12214daad 100644
--- a/includes/path.inc
+++ b/includes/path.inc
@@ -482,3 +482,65 @@ function path_delete($criteria) {
drupal_clear_path_cache();
}
+/**
+ * Determine whether a path is in the administrative section of the site.
+ *
+ * By default, paths are considered to be non-administrative. If a path does not
+ * match any of the patterns in path_get_admin_paths(), or if it matches both
+ * administrative and non-administrative patterns, it is considered
+ * non-administrative.
+ *
+ * @param $path
+ * A Drupal path.
+ * @return
+ * TRUE if the path is administrative, FALSE otherwise.
+ *
+ * @see path_get_admin_paths()
+ * @see hook_admin_paths()
+ * @see hook_admin_paths_alter()
+ */
+function path_is_admin($path) {
+ $path_map = &drupal_static(__FUNCTION__);
+ if (!isset($path_map['admin'][$path])) {
+ $patterns = path_get_admin_paths();
+ $path_map['admin'][$path] = drupal_match_path($path, $patterns['admin']);
+ $path_map['non_admin'][$path] = drupal_match_path($path, $patterns['non_admin']);
+ }
+ return $path_map['admin'][$path] && !$path_map['non_admin'][$path];
+}
+
+/**
+ * Get a list of administrative and non-administrative paths.
+ *
+ * @return array
+ * An associative array containing the following keys:
+ * 'admin': An array of administrative paths and regular expressions
+ * in a format suitable for drupal_match_path().
+ * 'non_admin': An array of non-administrative paths and regular expressions.
+ *
+ * @see hook_admin_paths()
+ * @see hook_admin_paths_alter()
+ */
+function path_get_admin_paths() {
+ $patterns = &drupal_static(__FUNCTION__);
+ if (!isset($patterns)) {
+ $paths = module_invoke_all('admin_paths');
+ drupal_alter('admin_paths', $paths);
+ // Combine all admin paths into one array, and likewise for non-admin paths,
+ // for easier handling.
+ $patterns = array();
+ $patterns['admin'] = array();
+ $patterns['non_admin'] = array();
+ foreach ($paths as $path => $enabled) {
+ if ($enabled) {
+ $patterns['admin'][] = $path;
+ }
+ else {
+ $patterns['non_admin'][] = $path;
+ }
+ }
+ $patterns['admin'] = implode("\n", $patterns['admin']);
+ $patterns['non_admin'] = implode("\n", $patterns['non_admin']);
+ }
+ return $patterns;
+}