| 1 |
<?php
|
| 2 |
// $Id:
|
| 3 |
|
| 4 |
function api_page_admin_form() {
|
| 5 |
$branches = api_get_branches();
|
| 6 |
$form = array();
|
| 7 |
|
| 8 |
if (count($branches) > 0) {
|
| 9 |
$form['branches'] = array(
|
| 10 |
'#theme' => 'api_branch_table',
|
| 11 |
);
|
| 12 |
foreach ($branches as $branch) {
|
| 13 |
$form['branches'][$branch->branch_name]['default_branch'] = array(
|
| 14 |
'#type' => 'radio',
|
| 15 |
'#default_value' => variable_get('api_default_branch', NULL),
|
| 16 |
'#return_value' => $branch->branch_name,
|
| 17 |
);
|
| 18 |
$form['branches'][$branch->branch_name]['title'] = array(
|
| 19 |
'#value' => l($branch->title, 'admin/settings/api/branches/'. $branch->branch_name),
|
| 20 |
);
|
| 21 |
$form['branches'][$branch->branch_name]['branch_name'] = array(
|
| 22 |
'#value' => $branch->branch_name,
|
| 23 |
);
|
| 24 |
$form['branches'][$branch->branch_name]['directory'] = array(
|
| 25 |
'#value' => str_replace("\n", '<br />', check_plain($branch->directory)),
|
| 26 |
);
|
| 27 |
}
|
| 28 |
}
|
| 29 |
else {
|
| 30 |
$form['branches'] = array(
|
| 31 |
'#value' => '<p><em>'. t('There are no branches yet. You can <a href="@url">add a branch</a>.', array('@url' => url('admin/settings/api/branches/new'))) .'</em></p>',
|
| 32 |
);
|
| 33 |
}
|
| 34 |
|
| 35 |
$form['submit'] = array(
|
| 36 |
'#type' => 'submit',
|
| 37 |
'#value' => t('Save changes'),
|
| 38 |
);
|
| 39 |
|
| 40 |
return $form;
|
| 41 |
}
|
| 42 |
|
| 43 |
function theme_api_branch_table($element) {
|
| 44 |
$header = array(
|
| 45 |
t('Default'),
|
| 46 |
t('Page label'),
|
| 47 |
t('URL label'),
|
| 48 |
t('Directories'),
|
| 49 |
);
|
| 50 |
$rows = array();
|
| 51 |
foreach (element_children($element) as $key) {
|
| 52 |
$row = array();
|
| 53 |
foreach (element_children($element[$key]) as $child) {
|
| 54 |
$row[] = drupal_render($element[$key][$child]);
|
| 55 |
}
|
| 56 |
$rows[] = $row;
|
| 57 |
}
|
| 58 |
return theme('table', $header, $rows);
|
| 59 |
}
|
| 60 |
|
| 61 |
function api_page_admin_form_submit($form, &$form_state) {
|
| 62 |
if (!empty($form_state['values']['default_branch'])) {
|
| 63 |
variable_set('api_default_branch', $form_state['values']['default_branch']);
|
| 64 |
}
|
| 65 |
|
| 66 |
// We may have menu changes, so clear the menu cache for all users.
|
| 67 |
cache_clear_all('*', 'cache_menu', TRUE);
|
| 68 |
|
| 69 |
drupal_set_message(t('Changes saved.'));
|
| 70 |
}
|
| 71 |
|
| 72 |
function api_branch_edit_form($form_state, $branch_name = NULL) {
|
| 73 |
$branches = api_get_branches();
|
| 74 |
if (is_null($branch_name)) {
|
| 75 |
$branch->branch_name = '';
|
| 76 |
$branch->title = '';
|
| 77 |
$branch->directory = '';
|
| 78 |
}
|
| 79 |
else {
|
| 80 |
$branch = $branches[$branch_name];
|
| 81 |
}
|
| 82 |
$form = array();
|
| 83 |
|
| 84 |
$form['branch_name'] = array(
|
| 85 |
'#title' => t('URL label'),
|
| 86 |
'#type' => 'textfield',
|
| 87 |
'#default_value' => $branch->branch_name,
|
| 88 |
'#required' => TRUE,
|
| 89 |
);
|
| 90 |
$form['title'] = array(
|
| 91 |
'#title' => t('Page label'),
|
| 92 |
'#type' => 'textfield',
|
| 93 |
'#default_value' => $branch->title,
|
| 94 |
'#required' => TRUE,
|
| 95 |
);
|
| 96 |
$form['directory'] = array(
|
| 97 |
'#title' => t('Directories'),
|
| 98 |
'#type' => 'textarea',
|
| 99 |
'#default_value' => $branch->directory,
|
| 100 |
'#rows' => 3,
|
| 101 |
'#description' => t('Absolute paths to index, one per line.'),
|
| 102 |
'#required' => TRUE,
|
| 103 |
);
|
| 104 |
$form['submit'] = array(
|
| 105 |
'#type' => 'submit',
|
| 106 |
'#value' => t('Save branch'),
|
| 107 |
);
|
| 108 |
if (!is_null($branch_name)) {
|
| 109 |
$form[] = array(
|
| 110 |
'#value' => l(t('Delete'), 'admin/settings/api/branches/'. $branch->branch_name .'/delete'),
|
| 111 |
);
|
| 112 |
}
|
| 113 |
|
| 114 |
return $form;
|
| 115 |
}
|
| 116 |
|
| 117 |
function api_branch_edit_form_validate($form, &$form_state) {
|
| 118 |
// Check for bad characters in branch names.
|
| 119 |
if (preg_match('/[^A-Za-z0-9-_.]/', $form_state['values']['branch_name'])) {
|
| 120 |
form_set_error('branch_name', t("Only letters, numbers, '.', '-' and '_' are allowed in the URL label."));
|
| 121 |
}
|
| 122 |
|
| 123 |
// Check for duplicate branch names.
|
| 124 |
$branches = api_get_branches();
|
| 125 |
if (!empty($form['branch_name']['#default_value'])) {
|
| 126 |
unset($branches[$form['branch_name']['#default_value']]);
|
| 127 |
}
|
| 128 |
if (isset($branches[$form_state['values']['branch_name']])) {
|
| 129 |
form_set_error('branch_name', t('%branch_name is already used by another branch.', array('%branch_name' => $form_state['values']['branch_name'])));
|
| 130 |
}
|
| 131 |
|
| 132 |
// Check for valid directories.
|
| 133 |
foreach (explode("\n", $form_state['values']['directory']) as $directory) {
|
| 134 |
$directory = trim($directory);
|
| 135 |
if (!is_dir($directory)) {
|
| 136 |
form_set_error('directory', t('%directory is not a directory.', array('%directory' => $directory)));
|
| 137 |
}
|
| 138 |
elseif (!is_readable($directory)) {
|
| 139 |
form_set_error('directory', t('%directory is not readable by PHP.', array('%directory' => $directory)));
|
| 140 |
}
|
| 141 |
}
|
| 142 |
}
|
| 143 |
|
| 144 |
function api_branch_edit_form_submit($form, &$form_state) {
|
| 145 |
$branch->branch_name = $form_state['values']['branch_name'];
|
| 146 |
$branch->title = $form_state['values']['title'];
|
| 147 |
$branch->directory = $form_state['values']['directory'];
|
| 148 |
|
| 149 |
api_save_branch($branch, $form['branch_name']['#default_value']);
|
| 150 |
|
| 151 |
drupal_set_message(t('Saved %branch_name.', array('%branch_name' => $branch->branch_name)));
|
| 152 |
$form_state['redirect'] = 'admin/settings/api';
|
| 153 |
}
|
| 154 |
|
| 155 |
function api_branch_delete_form($form_state, $branch_name) {
|
| 156 |
$form = array();
|
| 157 |
$form['branch_name'] = array(
|
| 158 |
'#type' => 'value',
|
| 159 |
'#value' => $branch_name,
|
| 160 |
);
|
| 161 |
return confirm_form($form, t('Are you sure you want to delete %branch_name?', array('%branch_name' => $branch_name)), 'admin/settings/api', NULL, t('Delete'));
|
| 162 |
}
|
| 163 |
|
| 164 |
function api_branch_delete_form_submit($form, &$form_state) {
|
| 165 |
db_query("DELETE FROM {api_branch} WHERE branch_name = '%s'", $form['branch_name']['#value']);
|
| 166 |
db_query("DELETE t FROM {api_file} t INNER JOIN {api_documentation} d ON d.did = t.did WHERE d.branch_name = '%s'", $form['branch_name']['#value']);
|
| 167 |
db_query("DELETE t FROM {api_function} t INNER JOIN {api_documentation} d ON d.did = t.did WHERE d.branch_name = '%s'", $form['branch_name']['#value']);
|
| 168 |
db_query("DELETE t FROM {api_reference_storage} t INNER JOIN {api_documentation} d ON d.did = t.from_did WHERE d.branch_name = '%s'", $form['branch_name']['#value']);
|
| 169 |
db_query("DELETE t FROM {api_reference_storage} t INNER JOIN {api_documentation} d ON d.did = t.to_did WHERE d.branch_name = '%s'", $form['branch_name']['#value']);
|
| 170 |
db_query("DELETE t FROM {api_documentation} t INNER JOIN {api_documentation} d ON d.did = t.did WHERE d.branch_name = '%s'", $form['branch_name']['#value']);
|
| 171 |
|
| 172 |
if (variable_get('api_default_branch', NULL) == $form['branch_name']['#value']) {
|
| 173 |
variable_set('api_default_branch', NULL);
|
| 174 |
}
|
| 175 |
|
| 176 |
menu_rebuild();
|
| 177 |
$form_state['redirect'] = 'admin/settings/api';
|
| 178 |
}
|
| 179 |
|
| 180 |
function api_php_manual_index_form() {
|
| 181 |
$form = array();
|
| 182 |
$form['api_php_funcsummary'] = array(
|
| 183 |
'#type' => 'textfield',
|
| 184 |
'#default_value' => variable_get('api_php_funcsummary', 'http://cvs.php.net/viewvc.cgi/phpdoc/funcsummary.txt?view=co'),
|
| 185 |
'#description' => t('The URL of the PHP function summary document.'),
|
| 186 |
);
|
| 187 |
$form['api_php_funcpath'] = array(
|
| 188 |
'#type' => 'textfield',
|
| 189 |
'#default_value' => variable_get('api_php_funcpath', 'http://php.net/!function'),
|
| 190 |
'#description' => t('The URL format used to build the link to php functions. Use the variable <em>!function</em> in place of the function name.'),
|
| 191 |
);
|
| 192 |
$form['submit'] = array(
|
| 193 |
'#type' => 'submit',
|
| 194 |
'#value' => t('Index PHP manual pages'),
|
| 195 |
);
|
| 196 |
return $form;
|
| 197 |
}
|
| 198 |
|
| 199 |
function api_php_manual_index_form_submit($form, &$form_state) {
|
| 200 |
include_once(drupal_get_path('module', 'api') .'/parser.inc');
|
| 201 |
variable_set('api_php_funcsummary', $form_state['values']['api_php_funcsummary']);
|
| 202 |
variable_set('api_php_funcpath', $form_state['values']['api_php_funcpath']);
|
| 203 |
db_query("DELETE FROM {api_documentation} WHERE branch_name = 'php'");
|
| 204 |
api_parse_php_manual($form_state['values']['api_php_funcsummary']);
|
| 205 |
drupal_set_message(t('Manual pages scanned.'));
|
| 206 |
}
|
| 207 |
|
| 208 |
function api_reindex_form() {
|
| 209 |
$form = array();
|
| 210 |
|
| 211 |
$form['submit'] = array(
|
| 212 |
'#type' => 'submit',
|
| 213 |
'#value' => t('Reindex'),
|
| 214 |
);
|
| 215 |
|
| 216 |
return $form;
|
| 217 |
}
|
| 218 |
|
| 219 |
function api_reindex_form_submit($form, &$form_state) {
|
| 220 |
db_query("UPDATE {api_file} SET modified = 52");
|
| 221 |
drupal_set_message(t('All files have been tagged for reindexing. The index will be rebuilt during the next few runs of !cron.', array('!cron' => l('cron.php', 'admin/reports/status/run-cron'))));
|
| 222 |
}
|