'admin/settings/subdomain', 'title' => t('Subdomain settings'), 'description' => t('Configure subdomain settings.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('subdomain_admin_settings'), 'access' => user_access('administer site configuration') ); } return $items; } /** * Implementation of hook_nodeapi() */ function subdomain_nodeapi(&$node, $op, $teaser, $page) { if (module_exists('og') && og_is_group_type($node->type)) { switch ($op) { case 'validate': $type = node_get_types('type',$node); $type_name = strtolower($type->name); $type_title = strtolower($type->title_label); $node->title = trim($node->title); // Allow only letters, numbers, and spaces if (!preg_match('!^[a-zA-Z0-9 ]+$!', $node->title)) { form_set_error('title', "The $type_name's $type_title can contain only letters, numbers and spaces"); } // Disallow reserved subdomain elseif (subdomain_reserved($node->title)) { form_set_error('title', "Sorry. '$node->title' is not available for use. Please enter a different $type_title for your $type_name."); } // Ensure group name is unique elseif (db_result(db_query("SELECT 1 FROM {node} WHERE nid <> %d AND type = '%s' AND title = '%s'", $node->nid, $node->type, $node->title))) { form_set_error('title', "There is already a $type_name with that $type_title. Please enter a different $type_name"); } // Disallow changes to group name (to avoid SEO issues and path alias getting out of sync with group content aliases) if ($node->nid) { $currentgroupname = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $node->nid)); if (strtolower($currentgroupname) != strtolower($node->title)) { form_set_error('title', "Sorry, $type_name {$type_title}s are permanent and may not be changed. You can change capitalization only."); } } break; case 'load': $node->subdomain = subdomain_raw_to_subdomain($node->title); break; } } } /** * Implementation of hook_user */ function subdomain_user($op, &$edit, &$user_edit, $category = NULL) { if ($op == 'validate' && variable_get('subdomain_type', SUBDOMAIN_USER) == SUBDOMAIN_USER) { // for SEO, disallow username changes if subdomains are set to Node Authors if (is_numeric($user_edit->uid) && $user_edit->name != $edit['name']) { form_set_error('name', 'Sorry. Usernames are permanent and cannot be changed'); } // Allow only letters and spaces in usernames elseif (!preg_match('!^[a-zA-Z0-9 ]+$!', $edit['name'])) { form_set_error('name', 'User Names can contain only letters, numbers and spaces'); } } } /** * Implementation of hook_token_list() */ function subdomain_token_list($type = 'all') { if ($type == 'node') { $tokens['node']['subdomain'] = t('Subdomain token (place at the start of the path)'); } if ($type == 'taxonomy') { $tokens['taxonomy']['subdomain'] = t('Subdomain token (place at the start of the path)'); } elseif ($type == 'user') { $tokens['user']['subdomain'] = t('Subdomain token (place at the start of the path)'); } return $tokens; } /** * Implementation of hook_token_values() */ function subdomain_token_values($type, $object = NULL) { $values['subdomain'] = NULL; switch ($type) { case 'node': switch (variable_get('subdomain_type', SUBDOMAIN_USER)) { case SUBDOMAIN_GROUP: if (og_is_group_type($object->type)) { $values['subdomain'] = subdomain_build_token($object->title, $object->nid); } elseif (isset($object->og_groups)) { // 1st Group in og_groups array is used for subdomain if ($groupname = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $object->og_groups[0]))) { $values['subdomain'] = subdomain_build_token($groupname, $object->og_groups[0]); }; } else { $values['subdomain'] = ''; } break; case SUBDOMAIN_USER: if (!empty($object->name)) { $values['subdomain'] = subdomain_build_token($object->name, $object->uid); } break; case SUBDOMAIN_VOCAB: $vocab = variable_get('subdomain_vocab', NULL); if (is_array($object->taxonomy) && in_array($vocab, array_keys($object->taxonomy))) { if ($tid = is_array($object->taxonomy[$vocab]) ? array_shift($object->taxonomy[$vocab]) : $object->taxonomy[$vocab]) { $term_name = db_result(db_query("SELECT name FROM {term_data} WHERE tid = %d", $tid)); $values['subdomain'] = subdomain_build_token($term_name, $tid); } } break; } break; case 'taxonomy': if (variable_get('subdomain_type', SUBDOMAIN_USER) == SUBDOMAIN_VOCAB) { $values['subdomain'] = subdomain_build_token($object->name, $object->tid); } break; case 'user': if (variable_get('subdomain_type', SUBDOMAIN_USER) == SUBDOMAIN_USER) { $values['subdomain'] = subdomain_build_token($object->name, $object->uid); } } return $values; } /** * Implementation of hook_admin_settings() */ function subdomain_admin_settings() { drupal_add_js(drupal_get_path('module', 'subdomain') . '/subdomain.js'); $reserved_default = implode("\n", array('www', 'static')); $options[SUBDOMAIN_USER] = 'Node authors and author content'; if (module_exists('taxonomy')) { $vocabs = taxonomy_get_vocabularies(); if (is_array($vocabs) && count($vocabs)) { foreach ($vocabs as $vocab) { if (!$vocab->hierarchy) { $vocab_options[$vocab->vid] = $vocab->name; } } if (is_array($vocab_options)) { $options[SUBDOMAIN_VOCAB] = 'Taxonomy Vocabulary and associated content'; } } } if (module_exists('og')) { $options[SUBDOMAIN_GROUP] = 'Organic groups and group content'; } $form['subdomain_settings']['subdomain_base_domain'] = array( '#type' => 'textfield', '#title' => t('Base domain'), '#description' => 'Your website\'s root domain (e.g. example.com)', '#default_value' => variable_get('subdomain_base_domain', NULL) ); $form['subdomain_settings']['subdomain_type'] = array( '#type' => 'select', '#title' => t('Create subdomains for'), '#description' => !isset($options[SUBDOMAIN_GROUP]) || !isset($options[SUBDOMAIN_VOCAB]) ? 'To use Taxonomy or Organic Group mode, enable and configure those modules' : '', '#options' => $options, '#default_value' => variable_get('subdomain_type', SUBDOMAIN_USER) ); if (module_exists('taxonomy') && is_array($vocab_options)) { $form['subdomain_settings']['subdomain_vocab'] = array( '#type' => 'select', '#title' => t('With the selected vocabulary\'s terms'), '#options' => $vocab_options, '#default_value' => variable_get('subdomain_vocab', NULL), '#prefix' => '
' ); } $form['subdomain_settings']['subdomain_style'] = array( '#type' => 'select', '#title' => t('Using'), '#options' => array(SUBDOMAIN_STYLE_NAME => 'Group or Node Author name', SUBDOMAIN_STYLE_CUSTOM => 'Custom...'), '#default_value' => variable_get('subdomain_style', SUBDOMAIN_STYLE_NAME) ); $form['subdomain_settings']['subdomain_custom'] = array( '#type' => 'textfield', '#title' => t('Custom subdomain'), '#description' => 'You may use the tokens %name% and %id% for group-name/user-name and group-nid/user-uid respectively', '#default_value' => variable_get('subdomain_custom', NULL), '#prefix' => '