function homebox_check_path in Homebox 7.2
Same name and namespace in other branches
- 6.3 homebox.module \homebox_check_path()
- 6.2 homebox.module \homebox_check_path()
- 7.3 homebox.module \homebox_check_path()
Validation helper function for page path
Parameters
$path: The path to be tested for the page
$name: Optional, the name of the page we're checking
$element: Optional, the form element identifier to throw form errors
Return value
TRUE if path is valid to use, otherwise, FALSE.
2 calls to homebox_check_path()
- homebox_admin_page_validate in ./
homebox.admin.inc - Validation functino for the admin page form.
- homebox_check_page_object in ./
homebox.module - Validation helper to check a page object
File
- ./
homebox.module, line 1016 - Homebox main file, takes care of global functions settings constants, etc.
Code
function homebox_check_path($path, $name = NULL, $element = NULL) {
// Ensure path fits the rules:
if (preg_match('/[^-a-z0-9_\\/]/', $path)) {
if ($element) {
form_set_error($element, t('Path must be lowercase alphanumeric, underscores, dashes, or forward-slashes only.'));
}
return FALSE;
}
// Check path for preceeding or trailing forward slashes
if (substr($path, 0, 1) == '/' || substr($path, strlen($path) - 1, 1) == '/') {
if ($element) {
form_set_error($element, t('Path cannot begin or end with a slash.'));
}
return FALSE;
}
// Check path against existing Homebox paths
$pages = db_query("SELECT * FROM {homebox_pages}");
foreach ($pages as $page) {
$page->settings = unserialize($page->settings);
// If this is the page we're checking, skip it
if ($name && $name == $page->name) {
continue;
}
if ($page->settings['path'] == $path) {
if ($element) {
form_set_error($element, t('The chosen path is already in use.'));
}
return FALSE;
}
}
return TRUE;
}