| 1 |
<?php
|
| 2 |
// $Id: fileapi_ui.module,v 1.1 2006/09/27 07:40:54 dopry Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* enables a user interface for managing fileapi mountpoints.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help().
|
| 11 |
*/
|
| 12 |
function fileapi_ui_help($section) {
|
| 13 |
switch ($section) {
|
| 14 |
case 'admin/settings/modules#description':
|
| 15 |
return t('fileapi user interface for managing mountpoints, and enabling simpletests.');
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Implementation of hook_perm
|
| 21 |
*/
|
| 22 |
function fileapi_ui_perms() {
|
| 23 |
return array('administer fileapi mountpoints');
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implmentation of hook_menu
|
| 28 |
* create menu callbacks for utilities
|
| 29 |
* and load storage drivers.
|
| 30 |
*/
|
| 31 |
function fileapi_ui_menu($may_cache) {
|
| 32 |
$items = array();
|
| 33 |
if ($may_cache) {
|
| 34 |
|
| 35 |
$items[] = array(
|
| 36 |
'path' => 'admin/settings/fileapi',
|
| 37 |
'title' => t('fileapi'),
|
| 38 |
'callback' => 'drupal_get_form',
|
| 39 |
'callback arguments' => array('fileapi_admin_settings'),
|
| 40 |
'access' => user_access('administer fileapi mountpoints'),
|
| 41 |
'type' => MENU_NORMAL_ITEM,
|
| 42 |
);
|
| 43 |
|
| 44 |
$items[] = array(
|
| 45 |
'path' => 'admin/settings/fileapi/mountpoint',
|
| 46 |
'title' => t('mountpoints'),
|
| 47 |
'callback' => 'fileapi_mountpoint_list',
|
| 48 |
'access' => user_access('administer fileapi mountpoints'),
|
| 49 |
'type' => MENU_NORMAL_ITEM,
|
| 50 |
);
|
| 51 |
|
| 52 |
$items[] = array(
|
| 53 |
'path' => 'admin/settings/fileapi/mountpoint/list',
|
| 54 |
'title' => t('list'),
|
| 55 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 56 |
'weight' => 1,
|
| 57 |
);
|
| 58 |
|
| 59 |
$items[] = array(
|
| 60 |
'path' => 'admin/settings/fileapi/mountpoint/edit',
|
| 61 |
'title' => t('edit'),
|
| 62 |
'callback' => 'drupal_get_form',
|
| 63 |
'callback arguments' => array('fileapi_mountpoint_edit_form'),
|
| 64 |
'access' => user_access('administer fileapi mountpoints'),
|
| 65 |
'type' => MENU_CALLBACK,
|
| 66 |
'weight' => 2,
|
| 67 |
);
|
| 68 |
|
| 69 |
$items[] = array(
|
| 70 |
'path' => 'admin/settings/fileapi/mountpoint/add',
|
| 71 |
'title' => t('add'),
|
| 72 |
'callback' => 'drupal_get_form',
|
| 73 |
'callback arguments' => array('fileapi_mountpoint_add_form'),
|
| 74 |
'access' => user_access('administer fileapi mountpoints'),
|
| 75 |
'type' => MENU_LOCAL_TASK,
|
| 76 |
'weight' => 2,
|
| 77 |
);
|
| 78 |
|
| 79 |
$items[] = array(
|
| 80 |
'path' => 'admin/settings/fileapi/mountpoint/delete',
|
| 81 |
'title' => t('delete'),
|
| 82 |
'callback' => 'drupal_get_form',
|
| 83 |
'callback arguments' => array('fileapi_mountpoint_delete_form'),
|
| 84 |
'access' => user_access('administer fileapi mountpoints'),
|
| 85 |
'type' => MENU_CALLBACK,
|
| 86 |
'weight' => 2,
|
| 87 |
);
|
| 88 |
}
|
| 89 |
return $items;
|
| 90 |
}
|
| 91 |
|
| 92 |
/**
|
| 93 |
* fileapi settings form.
|
| 94 |
*/
|
| 95 |
function fileapi_ui_admin_settings() {
|
| 96 |
|
| 97 |
$form['fileapi_public_path'] = array(
|
| 98 |
'#title' => t('Public Files Path')
|
| 99 |
'#description' => t('The filesystem path where publicly accessible files should be stored.'),
|
| 100 |
'#type' => 'textfield',
|
| 101 |
'#default_value' => fileapi_public_path(),
|
| 102 |
);
|
| 103 |
$form['fileapi_private_path'] = array(
|
| 104 |
'#title' => t('Public Files Path')
|
| 105 |
'#description' => t('The filesystem path where publicly accessible files should be stored.'),
|
| 106 |
'#type' => 'textfield',
|
| 107 |
'#default_value' => fileapi_private_path(),
|
| 108 |
);
|
| 109 |
$form['fileapi_tmp_path'] = array(
|
| 110 |
'#title' => t('Public Files Path')
|
| 111 |
'#description' => t('The filesystem path where publicly accessible files should be stored.'),
|
| 112 |
'#type' => 'textfield',
|
| 113 |
'#default_value' => fileapi_tmp_path(),
|
| 114 |
);
|
| 115 |
|
| 116 |
|
| 117 |
return system_settings_form($form);
|
| 118 |
}
|
| 119 |
|
| 120 |
|
| 121 |
function fileapi_ui_mountpoint_list() {
|
| 122 |
$form = array('#tree' => TRUE);
|
| 123 |
$result = db_query('SELECT * FROM {fileapi_mountpoint}');
|
| 124 |
$rows = array();
|
| 125 |
$header = array(t('name'), t('Mountpoint'), t('Driver'), '', '');
|
| 126 |
while( $mountpoint = db_fetch_array($result) ) {
|
| 127 |
//debug_msg($repository);
|
| 128 |
$row = array();
|
| 129 |
$row[] = $mountpoint['name'];
|
| 130 |
$row[] = $mountpoint['mountpoint'];
|
| 131 |
$row[] = $mountpoint['driver'];
|
| 132 |
if (!$mountpoint['system']) {
|
| 133 |
$row[] = l(t('Edit'), 'admin/settings/fileapi/mountpoint/edit/'. $mountpoint['frid']);
|
| 134 |
$row[] = l(t('Delete'), 'admin/settings/fileapi/mountpoint/delete/'. $mountpoint['frid']);
|
| 135 |
}
|
| 136 |
else {
|
| 137 |
$row[] = '';
|
| 138 |
$row[] = '';
|
| 139 |
}
|
| 140 |
$rows[] = $row;
|
| 141 |
}
|
| 142 |
return theme('table', $header, $rows);
|
| 143 |
}
|
| 144 |
|
| 145 |
|
| 146 |
function fileapi_ui_mountpoint_edit_form($frid) {
|
| 147 |
$form = array();
|
| 148 |
$result = db_query('SELECT * FROM {fileapi_mountpoint} WHERE frid="%s"', $frid);
|
| 149 |
while( $mountpoint = db_fetch_array($result) ) {
|
| 150 |
drupal_set_title($mountpoint['mountpoint'] .' '. t('edit'));
|
| 151 |
$mountpoint['settings'] = unserialize($mountpoint['settings']);
|
| 152 |
$form = fileapi_mountpoint_add_form($mountpoint);
|
| 153 |
$form['frid'] = array('#type' => 'value', '#value' => $mountpoint['frid']);
|
| 154 |
}
|
| 155 |
//drupal_set_message('<pre>'. print_r($form, true) .'</pre>');
|
| 156 |
return $form;
|
| 157 |
}
|
| 158 |
|
| 159 |
function fileapi_ui_mountpoint_edit_form_submit($form_id, $form_values) {
|
| 160 |
if (user_access('administer mountpoints')) {
|
| 161 |
//debug_msg($form_values, 'updating with');
|
| 162 |
db_query("UPDATE {fileapi_mountpoint} SET name='%s', mountpoint='%s', access_control= '%s', settings='%s' WHERE frid=%d",
|
| 163 |
$form_values['name'], $form_values['mountpoint'], $form_values['access control'], serialize($form_values['settings']), $form_values['frid']);
|
| 164 |
}
|
| 165 |
return 'admin/settings/fileapi/mountpoint/list';
|
| 166 |
}
|
| 167 |
|
| 168 |
function fileapi_ui_mountpoint_add_form($form_values = NULL) {
|
| 169 |
//debug_msg($form_values, 'add_form');
|
| 170 |
$form = array('#multistep' => TRUE);
|
| 171 |
$form['name'] = array(
|
| 172 |
'#title' => t('Name'),
|
| 173 |
'#type' => 'textfield',
|
| 174 |
'#default_value' => $form_values['name'],
|
| 175 |
);
|
| 176 |
$form['mountpoint'] = array(
|
| 177 |
'#title' => t('Mountpoint'),
|
| 178 |
'#type' => 'textfield',
|
| 179 |
'#default_value' => $form_values['mountpoint'],
|
| 180 |
);
|
| 181 |
|
| 182 |
$form['access control'] = array(
|
| 183 |
'#type' => 'select',
|
| 184 |
'#title' => t('Default Access Control Handler'),
|
| 185 |
//@todo: replace will call back to get access control systems.
|
| 186 |
'#options' => array(FALSE => t('No Access Control')),
|
| 187 |
'#default_value' => _fileapi_default_access_control(),
|
| 188 |
);
|
| 189 |
|
| 190 |
$drivers = fileapi_get_enabled_drivers();
|
| 191 |
$form['driver'] = array(
|
| 192 |
'#type' => 'select',
|
| 193 |
'#title'=> t('Driver'),
|
| 194 |
'#options' => $drivers,
|
| 195 |
'#default_value' => $form_values['driver'],
|
| 196 |
);
|
| 197 |
|
| 198 |
if (isset($form_values['driver'])) {
|
| 199 |
$form['settings'] = drupal_retrieve_form('fileapi_driver_'. $drivers[$form_values['driver']] .'_settings_form', $form_values['settings'] );
|
| 200 |
$form['driver']['#type'] = 'value';
|
| 201 |
}
|
| 202 |
|
| 203 |
$form['submit'] = array(
|
| 204 |
'#type' => 'submit',
|
| 205 |
'#value' => t('submit'),
|
| 206 |
);
|
| 207 |
|
| 208 |
return $form;
|
| 209 |
}
|
| 210 |
|
| 211 |
|
| 212 |
function fileapi_ui_mountpoint_add_form_validate() {
|
| 213 |
//drupal_set_message('fileapi_mountpoint_add_form_validate');
|
| 214 |
}
|
| 215 |
function fileapi_ui_mountpoint_add_form_submit($form_id, $form_values) {
|
| 216 |
drupal_set_message('fileapi_mountpoint_add_form_submit');
|
| 217 |
//debug_msg($form_values);
|
| 218 |
if($form_values['driver'] != $form_values['settings']['driver']) {
|
| 219 |
return FALSE;
|
| 220 |
}
|
| 221 |
//lose stuff we don't wnat in the db.
|
| 222 |
unset($form_values['settings']['driver']);
|
| 223 |
db_query("INSERT INTO {fileapi_mountpoint} (name, driver, access_control, settings)
|
| 224 |
VALUES ('%s', '%s', '%s', '%s')", $form_values['name'], $form_values['driver'],
|
| 225 |
$form_values['access control'], serialize($form_values['settings']));
|
| 226 |
|
| 227 |
return 'admin/settings/fileapi/mountpoint/list';
|
| 228 |
|
| 229 |
}
|
| 230 |
|
| 231 |
function fileapi_ui_mountpoint_delete_form($frid) {
|
| 232 |
$form['frid'] = array('#type' => 'value', '#value' => $frid);
|
| 233 |
return confirm_form($form,
|
| 234 |
t('Are you sure you want to delete repository %name?', array('%name' => db_result(db_query('SELECT name FROM {fileapi_mountpoint} WHERE frid = %d', $frid)))),
|
| 235 |
'admin/settings/fileapi/mountpoint/list',
|
| 236 |
t('Your settings will be lost. This action can not be undone.'),
|
| 237 |
t('Delete'),
|
| 238 |
t('Cancel')
|
| 239 |
);
|
| 240 |
}
|
| 241 |
|
| 242 |
|
| 243 |
function fileapi_ui_mountpoint_delete_form_submit($form_id, $form_values) {
|
| 244 |
$mountpoint = db_fetch_array(db_query('SELECT * FROM {fileapi_mountpoint} WHERE frid=%d', $form_values['frid']));
|
| 245 |
if (!$mountpoint['system']) {
|
| 246 |
if (user_access('administer mountpoints')) {
|
| 247 |
db_query('DELETE FROM {fileapi_mountpoint} WHERE frid=%d', $form_values['frid']);
|
| 248 |
drupal_set_message('Mountpoint '. $mountpoint['name'] .' was deleted');
|
| 249 |
}
|
| 250 |
else {
|
| 251 |
drupal_set_message('You lack sufficient priveleges to delete'. $mountpoint['name']);
|
| 252 |
}
|
| 253 |
}
|
| 254 |
else {
|
| 255 |
drupal_set_message($mountpoint['name'] .' is a system mountpoint and cannot be deleted.');
|
| 256 |
}
|
| 257 |
return 'admin/settings/fileapi/mountpoint/list';
|
| 258 |
}
|
| 259 |
|
| 260 |
/**
|
| 261 |
* form after_build function for validating that directories exist and are writable
|
| 262 |
* @param $element
|
| 263 |
* form element containing a path to be validated.
|
| 264 |
* @return form element.
|
| 265 |
*/
|
| 266 |
|
| 267 |
function fileapi_ui_validate_path($element) {
|
| 268 |
if (!is_dir($element['#value'])) {
|
| 269 |
form_set_error($element['#parents'][0], t('%title does not exist.', array('%title' => theme('placeholder', $element['#title']))));
|
| 270 |
}
|
| 271 |
if (!is_writable($element['#value'])) {
|
| 272 |
form_set_error($element['#parents'][0], t('%title is not writable.', array('%title' => theme('placeholder', $element['#title']))));
|
| 273 |
}
|
| 274 |
return $element;
|
| 275 |
}
|
| 276 |
|