function homebox_check_page_object in Homebox 6.3
Same name and namespace in other branches
- 6.2 homebox.module \homebox_check_page_object()
- 7.3 homebox.module \homebox_check_page_object()
- 7.2 homebox.module \homebox_check_page_object()
Validation helper to check a page object
Parameters
$data: A page object either in the form of imported PHP code or an actual object
$name: Optionally specify and override the machine name of the page
$element: Optionally specify a form element name to be used to throw form errors
Return value
A complete page object, or FALSE if data was invalid
4 calls to homebox_check_page_object()
- homebox_admin_page_validate in ./
homebox.admin.inc - homebox_get_page in ./
homebox.module - Helper function to fetch a page from the database or from a module implementing hook_homebox()
- homebox_pages in ./
homebox.module - Retrieve an array of all available pages either in the database or by hook_homebox()
- homebox_save_page in ./
homebox.module - Helper function to save an existing page
File
- ./
homebox.module, line 1008 - Homebox main file, takes care of global functions settings constants, etc.
Code
function homebox_check_page_object($data, $name = NULL, $element = NULL) {
$homebox = '';
if (!is_object($data)) {
// Evaluate the imported object
ob_start();
eval($data);
ob_end_clean();
}
else {
// Not importing - just use $data
$homebox = $data;
}
// Whether or not the import is valid
$status = TRUE;
// Check if data was a valid object
if (!is_object($homebox)) {
$status = FALSE;
}
else {
// Check individual settings
foreach ($homebox->settings as $key => $value) {
switch ($key) {
case 'regions':
// Only allow numbers 1-9
if ($value > 9 || $value < 1) {
$status = FALSE;
break 2;
}
case 'menu':
case 'enabled':
case 'auto_save':
case 'cache':
case 'full':
case 'color':
// Check that the previous are numeric values
if (!is_numeric($value)) {
$status = FALSE;
break 2;
}
break;
case 'title':
// Filter title and make sure it still exists afterwards
$homebox->settings[$key] = filter_xss($value);
if (!$homebox->settings[$key]) {
$status = FALSE;
break 2;
}
break;
case 'path':
if (!homebox_check_path($value, NULL, $element)) {
$status = FALSE;
break 2;
}
break;
case 'colors':
case 'roles':
if (!is_array($value)) {
$status = FALSE;
break 2;
}
break;
case 'blocks':
// Check that at least one block was provided
if (!count($homebox->settings['blocks'])) {
$status = FALSE;
break 2;
}
break;
case 'widths':
if ($homebox->settings['widths']) {
if (!is_array($homebox->settings['widths']) || count($homebox->settings['widths']) > $homebox->settings['regions']) {
$status = FALSE;
break 2;
}
foreach ($homebox->settings['widths'] as $width) {
if (!is_numeric($width) || $width > 100 || $width < 0) {
$status = FALSE;
break 3;
}
}
}
break;
}
}
// If name is explicitly specified, used it
$homebox->name = $name ? $name : $homebox->name;
// Check name
if ($status && $homebox->name && !homebox_check_name($homebox->name, $element)) {
$status = FALSE;
}
// Make sure the required values actually exist
$required_keys = array(
'path',
'blocks',
'title',
'regions',
);
if ($status) {
foreach ($required_keys as $key) {
if (!array_key_exists($key, $homebox->settings)) {
$status = FALSE;
break;
}
}
}
}
// If the import isn't valid, and form element provided,
// then flag a form error
if (!$status && $element) {
form_set_error($element, t('Invalid import data provided.'));
}
return $status ? $homebox : FALSE;
}