00001 <?php
00002
00003
00016 function drupal_init_path() {
00017 if (!empty($_GET['q'])) {
00018 $_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
00019 }
00020 else {
00021 $_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
00022 }
00023 }
00024
00046 function drupal_lookup_path($action, $path = '', $path_language = '') {
00047 global $language;
00048
00049 static $map = array(), $no_src = array();
00050
00051 $path_language = $path_language ? $path_language : $language->language;
00052
00053 if ($action == 'wipe') {
00054 $map = array();
00055 $no_src = array();
00056 }
00057 elseif (module_exists('path') && $path != '') {
00058 if ($action == 'alias') {
00059 if (isset($map[$path_language][$path])) {
00060 return $map[$path_language][$path];
00061 }
00062
00063 $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language));
00064 $map[$path_language][$path] = $alias;
00065 return $alias;
00066 }
00067
00068
00069 elseif ($action == 'source' && !isset($no_src[$path_language][$path])) {
00070
00071 $src = '';
00072 if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) {
00073
00074 if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language))) {
00075 $map[$path_language][$src] = $path;
00076 }
00077 else {
00078
00079
00080
00081 $no_src[$path_language][$path] = TRUE;
00082 }
00083 }
00084 return $src;
00085 }
00086 }
00087
00088 return FALSE;
00089 }
00090
00103 function drupal_get_path_alias($path, $path_language = '') {
00104 $result = $path;
00105 if ($alias = drupal_lookup_path('alias', $path, $path_language)) {
00106 $result = $alias;
00107 }
00108 return $result;
00109 }
00110
00123 function drupal_get_normal_path($path, $path_language = '') {
00124 $result = $path;
00125 if ($src = drupal_lookup_path('source', $path, $path_language)) {
00126 $result = $src;
00127 }
00128 if (function_exists('custom_url_rewrite_inbound')) {
00129
00130 custom_url_rewrite_inbound($result, $path, $path_language);
00131 }
00132 return $result;
00133 }
00134
00154 function arg($index = NULL, $path = NULL) {
00155 static $arguments;
00156
00157 if (!isset($path)) {
00158 $path = $_GET['q'];
00159 }
00160 if (!isset($arguments[$path])) {
00161 $arguments[$path] = explode('/', $path);
00162 }
00163 if (!isset($index)) {
00164 return $arguments[$path];
00165 }
00166 if (isset($arguments[$path][$index])) {
00167 return $arguments[$path][$index];
00168 }
00169 }
00170
00177 function drupal_get_title() {
00178 $title = drupal_set_title();
00179
00180
00181 if (!isset($title) && function_exists('menu_get_active_title')) {
00182 $title = check_plain(menu_get_active_title());
00183 }
00184
00185 return $title;
00186 }
00187
00198 function drupal_set_title($title = NULL) {
00199 static $stored_title;
00200
00201 if (isset($title)) {
00202 $stored_title = $title;
00203 }
00204 return $stored_title;
00205 }
00206
00213 function drupal_is_front_page() {
00214
00215
00216 return $_GET['q'] == drupal_get_normal_path(variable_get('site_frontpage', 'node'));
00217 }
00218
00230 function drupal_match_path($path, $patterns) {
00231 static $regexps;
00232
00233 if (!isset($regexps[$patterns])) {
00234 $regexps[$patterns] = '/^(' . preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\2'), preg_quote($patterns, '/')) . ')$/';
00235 }
00236 return preg_match($regexps[$patterns], $path);
00237 }