/[drupal]/contributions/modules/multisite_manager/multisite_manager.admin.inc
ViewVC logotype

Diff of /contributions/modules/multisite_manager/multisite_manager.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Wed Mar 12 19:10:34 2008 UTC revision 1.1.2.1, Wed Mar 12 19:10:34 2008 UTC
# Line 0  Line 1 
1    <?php
2    // $Id: multisite_manager.admin.inc
3    /**
4     * author: Schuyler Duveen
5     * sponsor: Columbia Univeristy Center for New Media Teaching & Learning
6     * URL: http://drupal.org/project/multisite_manager
7     * License: GPL v2 or any later version
8    
9     */
10    
11    function multisite_manager_admin_settings_validate($form_id, $form_values) {
12      if ($form_values['module'] == 'multisite_manager') {
13        if (empty($form_values['multisite_manager_dbprefix_default']) && empty($form_values['multisite_manager_dbpath_default'])) {
14          form_set_error('multisite_manager_dbprefix_default', t('You must, at least, enter a database or table prefix string.  Both cannot be empty'));
15        }
16      }
17    }
18    
19    function multisite_manager_admin_settings() {
20      $defaults = array('db_prefix' => '{shortname}_',
21                        'db_path' => '',
22                        'link' => '{base_url}/site/{shortname}',
23                        'admin_account' => 'copy creator',
24                        'profile' => 'default',
25                        'install_immediate' => TRUE,
26                        'run_cron' => 0,
27                        );
28      $form['multisite_manager_run_cron'] = array(
29        '#type' => 'checkbox',
30        '#title' => t('Run drupal sites\' cron jobs'),
31        '#required' => FALSE,
32        '#default_value' => variable_get('multisite_manager_run_cron', $defaults['run_cron']),
33        '#description' => t('This sets whether each drupal site\'s cron jobs will be run when this master site\'s cron is run.  If this is unset no drupal site will have their cron jobs executed regardless of each individual sites\' settings for running cron jobs.')
34      );
35      $form['multisite_manager_install_immediate'] = array(
36        '#type' => 'checkbox',
37        '#title' => t('Install site upon node creation'),
38        '#required' => FALSE,
39        '#default_value' => variable_get('multisite_manager_install_immediate', $defaults['install_immediate']),
40        '#description' => t('This sets whether Drupal site\'s creation is done upon node creation or wether it is delayed until the batch create script is run.')
41      );
42      $form['multisite_manager_dbprefix_default'] = array(
43        '#type' => 'textfield',
44        '#title' => t('Table prefix default'),
45        '#required' => FALSE,
46        '#default_value' => variable_get('multisite_manager_dbprefix_default', $defaults['db_prefix']),
47        '#description' => t('This is the default prefix that will be forced on those without "advanced database setup" rights. {shortname} stands for the shortname field input when creating the site.  If you make the default database different from the current one, you can reasonably make this empty.')
48      );
49      $form['multisite_manager_dbpath_default'] = array(
50        '#type' => 'textfield',
51        '#title' => t('Database name default'),
52        '#required' => FALSE,
53        '#default_value' => variable_get('multisite_manager_dbpath_default', $defaults['db_path']),
54        '#description' => t('If left blank, it will use the current database.  Otherwise, "{shortname}" will be replaced, so another common default might be "{shortname}_drupal". Do NOT set this unless the current database account has CREATE access in MySQL or CREATEDB access in Postgres. To ensure database data is not overwritten, if you install in another database, it is either required that your current database have some db_prefix OR that it will be a new database--i.e. that your entry here includes "{shortname}".'),
55      );
56      $form['multisite_manager_link_default'] = array(
57        '#type' => 'textfield',
58        '#title' => t('Link default'),
59        '#required' => FALSE,
60        '#default_value' => variable_get('multisite_manager_link_default', $defaults['link']),
61        '#description' => t('This is where the site will be accessible by default.  If you setup your ./sites/default/settings.php correctly along with your web server (e.g. apache/htaccess) config, you can anticipate where the new site will live and forward the user to the new site location upon creation.  Here, there are two dynamic variables, {base_url} and {shortname}.')
62      );
63      $form['multisite_manager_admin_account'] = array(
64        '#type' => 'radios',
65        '#title' => t('Admin account on new sites'),
66        '#required' => TRUE,
67        '#options' => array(
68                            'copy admin' => t('Copy the admin account from this site'),
69                            'copy creator' => t('Copy the account of the creator'),
70                            'do nothing' => t('Do nothing (only choose this if all profiles available do something instead.  the default profile does not)'),
71                            /*'prompt creator' => '',*/
72                            ),
73        '#default_value' => variable_get('multisite_manager_admin_account', $defaults['admin_account']),
74      );
75      $form['multisite_manager_profile_default'] = array(
76        '#type' => 'radios',
77        '#title' => t('Profile default'),
78        '#required' => FALSE,
79        '#options' => _multisite_manager_profile_options(),
80        '#default_value' => variable_get('multisite_manager_profile_default', $defaults['profile']),
81      );
82    
83      return system_settings_form($form);
84    }
85    
86    /*
87     * multisite_manager_admin_file_settingsdotphp
88     * @return string of PHP code that would be included based on the default settings for link/database name
89     */
90    function multisite_manager_admin_file_settingsdotphp() {
91      global $base_url;
92      $link = variable_get('multisite_manager_link_default', '');
93      ///
94      $fakenode = new stdClass();
95      $fakenode->shortname = '". $my_site_base ."';
96      $fakenode->db_prefix = variable_get('multisite_manager_dbprefix_default', '');
97      $fakenode->db_user = '';
98      $fakenode->db_pass = '<b style="color:red">DATABASE_PASSWORD</b>';
99      $fakenode->db_path = variable_get('multisite_manager_dbpath_default', '');
100      $newdb = _multisite_manager_dbobj($fakenode);
101    
102      $recommended_directory = '';
103    
104      if (!$link || !$fakenode->db_path) {
105        return "ERROR: no link or db url";
106      }
107      $link = str_replace('{base_url}', $base_url, $link);
108    
109      //$url_pieces[2] is hostname, $url_pieces[3] is path
110      $url_pieces = explode('/', $link, 4);
111    
112      $rv = array('<p>Based on your configuration in '.l( 'Multisite Manager Defaults','admin/settings/multisite_manager/defaults').' The following code should be added to a special settings.php file which .  Note, <b>This is an experimental feature</b> and you should look over this carefully before adding it in place of the database configuration (Also, please '.l('report suggestions/issues','http://drupal.org/project/multisite_manager') .').</p><blockquote><pre><code>',
113                  '$matches = FALSE;');
114    
115      $host_regex = str_replace('{shortname}', '(\w+)', $url_pieces[2]);
116      $path_regex = str_replace('{shortname}', '(\w+)', $url_pieces[3]);
117    
118      //assumes shortname will never be the TLD
119      $recommended_directory = preg_replace('|\(\\w\+\)[^.]*\.|','',$host_regex);
120      ///shortname in hostname
121      if (strpos($url_pieces[2],'{shortname}') !== FALSE) {
122        $rv[] = 'if (preg_match("|'. $host_regex .'|",$_SERVER["HTTP_HOST"], $matches)';
123        $rv[] = '    && preg_match("|'. $path_regex .'|",request_uri())';
124        $rv[] = '    && $matches)';
125        $rv[] = '{';
126      }///shortname in path
127      elseif (strpos($url_pieces[3],'{shortname}') !== FALSE) {
128        $rv[] = 'if (preg_match("|'. $host_regex .'|",$_SERVER["HTTP_HOST"])';
129        $rv[] = '    && preg_match("|'. $path_regex .'|",request_uri(), $matches)';
130        $rv[] = '    && $matches)';
131        $rv[] = '{';
132        $recommended_directory .= '.' . str_replace('/','.',preg_replace('|(/[^/]*)?\(\\\w\+\)([^/]*)|','',$path_regex));
133      }
134      else {
135        ///{shortname} has to appear in the link somewhere!
136        return "ERROR: shortname must be in the link template " .$url_pieces[2] .'XX' . $url_pieces[3];
137      }
138      $rv[] = '  $my_site_base = $matches[1];';
139    
140      ///prefix
141      $rv[] = '  $db_prefix = "' . $newdb['prefix'] .'";';
142      ///needs URL structure
143      $rv[] = '  $base_url = "'. str_replace('{shortname}','". $my_site_base ."',$link) .'";  // NO trailing slash!';
144    
145      ///needs newDB URI structure
146      $rv[] = '  $db_url = "' .$newdb['url'] .'";';
147    
148      $rv[] = '  ///This assumes you have a ./files directory in your base drupal directory';
149      $rv[] = '  $conf = array(';
150      $rv[] = '     "file_directory_path" => "files/".$my_site_base,';
151      $rv[] = '  );';
152      $rv[] = '}';
153    
154      $rv[] = "</code></pre></blockquote>";
155      $rv[] = 'Suggested directory under sites/ to include settings.php file: <b>' . $recommended_directory . "</b></p>";
156      return implode("\n",$rv);
157    }
158    
159    
160    // vim:fenc=utf-8:ft=php:ai:si:ts=2:sw=2:et:

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.2