mode = variable_get('subdomain_mode', 'user'); $this->source = variable_get('subdomain_source', 'default'); $this->home = variable_get('subdomain_home', 'default'); $this->view = variable_get('subdomain_view', ''); if ($this->source == 'default') { $this->form_field = $this->default_form_field(); } else { $this->form_field = 'subdomain'; } } function default_form_field() { return 'name'; } function get_homepage_path($sid) { if ($this->home == 'default') { return subdomain()->base_path($sid); } else { return "subdomain/homepage/$sid"; } } function data_handler($op, $requireMode, $object) { if ($requireMode == $this->mode) { switch ($op) { case 'insert': if (user_access('create subdomains')) { $this->save($object); } break; case 'update': if (user_access('edit subdomains')) { $this->save($object); } break; case 'delete': $this->delete($object); break; } } } /** * Prepares subdomain for saving */ function clean($raw) { // Replace spaces with dashes] & convert to lower case $raw = strtolower(str_replace(" ", "-", $raw)); return preg_replace("/[^a-z-]/", "", $raw); } function exists($value) { $sid = subdomain_get_sid($value); return !empty($sid); } function save_record($id, $raw, $insert = FALSE) { $row->sid = $id; $row->subdomain = $this->clean($raw); if ($row->subdomain) { drupal_write_record('subdomain', $row, $insert ? array() : array('sid')); } else { // Delete subdomain if blank (site admins can enter blank subdomains) $this->delete_record($row->sid); } } function delete_record($sid) { db_query('DELETE FROM {subdomain} WHERE sid = :sid', array(':sid' => $sid)); } }