function hosting_site_available_options in Hosting 6.2
Same name and namespace in other branches
- 7.4 site/hosting_site.form.inc \hosting_site_available_options()
- 7.3 site/hosting_site.form.inc \hosting_site_available_options()
Pass in a site node and return an array of valid options for it's fields.
Modules can define the hook_hosting_site_options_alter function to modify which fields are available for selection.
4 calls to hosting_site_available_options()
- hosting_site_validate in site/
hosting_site.form.inc - Implements hook_validate().
- hosting_ssl_nodeapi_site_validate in web_server/
ssl/ hosting_ssl.nodeapi.inc - hosting_task_migrate_form in migrate/
hosting_migrate.module - Implementation of hook_form().
- _hosting_site_form_check in site/
hosting_site.module
File
- site/
hosting_site.form.inc, line 91 - Site node form.
Code
function hosting_site_available_options($node, $platform = NULL) {
// cast to object if it's an array.
$node = is_array($node) ? (object) $node : clone $node;
$return = array();
$return['profile'] = array();
$return['platform'] = array();
$return['site_language'] = array();
if (!hosting_feature('client')) {
// Setting the return value of a text field to null,
// will signal to the front end that the field needs to
// be displayed, but is not editable.
$return['client'] = NULL;
}
// Load up the user we'll use to check platform and profile access
$user = user_load($GLOBALS['user']->uid);
// Install profiles
$profiles = hosting_get_profiles();
$platform_profiles = array();
foreach ($profiles as $id => $name) {
// Don't allow a site to be provisioned with hostslave or hostmaster profile
if (in_array($name, array(
'Hostslave',
'Hostmaster',
))) {
unset($profiles[$id]);
}
// Trim down the list of profiles to those that are available and the user has access to
// XXX This hack (next 22 lines) hides profiles that can't be accessed
// Eventually we should lighten up the content of this callback
$result = db_query("SELECT l.nid FROM hosting_package_instance i\n JOIN hosting_package p ON p.nid = i.package_id\n JOIN hosting_platform l ON l.nid = i.rid WHERE i.package_id = %d\n AND p.package_type = 'profile' AND l.status = %d;", $id, HOSTING_PLATFORM_ENABLED);
if (is_null($platform)) {
$allowed_plats = _hosting_get_allowed_platforms($user->uid);
}
else {
$allowed_plats = array(
$platform => $platform,
);
}
$access_check = FALSE;
while ($row = db_fetch_array($result)) {
if (!is_null($platform) && array_key_exists($row['nid'], $allowed_plats)) {
$platform_profiles[$id] = $name;
}
elseif (array_key_exists($row['nid'], $allowed_plats)) {
$access_check = TRUE;
}
elseif (!($unrestricted = db_result(db_query("SELECT cid FROM {hosting_platform_client_access} WHERE pid = '%d' LIMIT 1", $row['nid'])))) {
$access_check = TRUE;
}
}
if (!$access_check) {
unset($profiles[$id]);
}
}
if (!is_null($platform)) {
$profiles = $platform_profiles;
}
reset($profiles);
$return['profile'] = array_keys($profiles);
if (!isset($node->profile)) {
$node->profile = hosting_get_default_profile($return['profile'][0]);
}
// filter the available platforms based on which clients the user has access to.
if (!is_null($platform)) {
$node->profile = $return['profile'][0];
$return['platform'] = array(
$platform,
);
}
else {
$options = array();
$platforms = hosting_get_profile_platforms($node->profile, isset($node->check_profile_migrations) ? $node->check_profile_migrations : FALSE);
if (sizeof($platforms)) {
foreach ($platforms as $nid => $title) {
$platform = node_load($nid);
if ($platform->platform_status != HOSTING_PLATFORM_LOCKED || user_access('create sites on locked platforms')) {
if (!isset($platform->clients) || sizeof(array_intersect(array_keys($user->client_id), $platform->clients)) || $user->uid == 1) {
$options[] = $nid;
}
}
}
$return['platform'] = $options;
}
}
if (!isset($node->platform) || !in_array($node->platform, $return['platform'])) {
$node->platform = $return['platform'][0];
}
$return['site_language'] = array_keys((array) hosting_get_profile_languages($node->profile, $node->platform));
drupal_alter('hosting_site_options', $return, $node);
return $return;
}