| 1 |
<?php
|
| 2 |
// $Id: gotwo.admin.inc,v 1.1.2.14 2009/08/26 18:53:11 hass Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Administrative page callbacks for the gotwo module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_settings
|
| 11 |
*/
|
| 12 |
function gotwo_admin_settings_form() {
|
| 13 |
$form['gotwo_numeric'] = array(
|
| 14 |
'#type' => 'checkbox',
|
| 15 |
'#title' => t('Numerical urls'),
|
| 16 |
'#description' => t('Use numbers instead of a more friendlier url. "go/1234" instead of "go/some/location".'),
|
| 17 |
'#default_value' => variable_get('gotwo_numeric', FALSE),
|
| 18 |
);
|
| 19 |
$form['gotwo_max_length'] = array(
|
| 20 |
'#type' => 'textfield',
|
| 21 |
'#title' => t('Maximum length of target labels'),
|
| 22 |
'#description' => t('Target labels are the parts after the "go/" part of the shown url. The absolute maximum is 128.'),
|
| 23 |
'#default_value' => min(variable_get('gotwo_max_length', 128), 128),
|
| 24 |
'#size' => 10,
|
| 25 |
);
|
| 26 |
$form['gotwo_disclaimer_boolean'] = array(
|
| 27 |
'#type' => 'checkbox',
|
| 28 |
'#title' => t('Disclaimer'),
|
| 29 |
'#description' => t('Check to add a disclaimer before redirecting to the Gotwo links'),
|
| 30 |
'#default_value' => variable_get('gotwo_disclaimer_boolean', FALSE),
|
| 31 |
);
|
| 32 |
$form['gotwo_disclaimer_time'] = array(
|
| 33 |
'#type' => 'select',
|
| 34 |
'#title' => t('# of seconds until refresh'),
|
| 35 |
'#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 10, 15, 30, 45, 60)),
|
| 36 |
'#description' => t('Number of seconds until the page will be redirected to the requested URL, 0 means no refresh'),
|
| 37 |
'#default_value' => variable_get('gotwo_disclaimer_time', 0),
|
| 38 |
);
|
| 39 |
$form['gotwo_disclaimer_text'] = array(
|
| 40 |
'#type' => 'textarea',
|
| 41 |
'#title' => t('Disclaimer Text'),
|
| 42 |
'#description' => t('The disclaimer that will be presented to the user before they are redirected<br /><strong>Variables available:</strong><br /> %url = url to be redirected to <br />%seconds = # of seconds until page redirects'),
|
| 43 |
'#default_value' => variable_get('gotwo_disclaimer_text',''),
|
| 44 |
);
|
| 45 |
|
| 46 |
return system_settings_form($form);
|
| 47 |
}
|
| 48 |
|
| 49 |
/**
|
| 50 |
* Shows the list of go redirects
|
| 51 |
*/
|
| 52 |
function _gotwo_list() {
|
| 53 |
$access = user_access('edit gotwo redirects');
|
| 54 |
|
| 55 |
$header = array(
|
| 56 |
array('data' => t('ID'), 'field' => 'gid'),
|
| 57 |
array('data' => t('Label'), 'field' => 'src'),
|
| 58 |
array('data' => t('Destination'), 'field' => 'dst'),
|
| 59 |
array('data' => t('Counter'), 'field' => 'cnt', 'sort' => 'desc'),
|
| 60 |
);
|
| 61 |
if ($access) {
|
| 62 |
$header[] = array('data' => t('Operations'));
|
| 63 |
}
|
| 64 |
|
| 65 |
$sql = 'SELECT * FROM {gotwo}';
|
| 66 |
$tablesort = tablesort_sql($header);
|
| 67 |
$result = pager_query($sql . $tablesort, 50);
|
| 68 |
|
| 69 |
$rows = array();
|
| 70 |
while ($go = db_fetch_object($result)) {
|
| 71 |
$i = count($rows);
|
| 72 |
$rows[$i] = array(
|
| 73 |
'data' => array(
|
| 74 |
$go->gid,
|
| 75 |
check_plain($go->src),
|
| 76 |
check_plain($go->dst),
|
| 77 |
$go->cnt
|
| 78 |
)
|
| 79 |
);
|
| 80 |
if ($access) {
|
| 81 |
$rows[$i]['data'][] = l(t('Reset'), 'admin/build/gotwo/reset/'. $go->gid, array('title' => t('Reset the counter'))) .' ยท '. l(t('Delete'), 'admin/build/gotwo/delete/'. $go->gid);
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
if (!$rows) {
|
| 86 |
$rows[] = array(array('data' => t('No redirects available.'), 'colspan' => ($access ? 5 : 4)));
|
| 87 |
}
|
| 88 |
|
| 89 |
$output = theme('table', $header, $rows);
|
| 90 |
$output .= theme('pager', NULL, 50, 0);
|
| 91 |
|
| 92 |
return $output;
|
| 93 |
}
|
| 94 |
|
| 95 |
/**
|
| 96 |
* Create confirmation form for click counter item reset.
|
| 97 |
*/
|
| 98 |
function gotwo_reset_form($form_state, $edit) {
|
| 99 |
$form['gid'] = array('#type' => 'value', '#value' => $edit->gid);
|
| 100 |
|
| 101 |
return confirm_form(
|
| 102 |
$form,
|
| 103 |
t('Reset the counter for %label', array('%label' => $edit->src)),
|
| 104 |
'admin/build/gotwo',
|
| 105 |
'<p>'. t('Are you sure you want to reset the click counter for %label? This action cannot be undone.', array('%label' => $edit->src)) .'</p>',
|
| 106 |
t('Reset'),
|
| 107 |
t('Cancel')
|
| 108 |
);
|
| 109 |
}
|
| 110 |
|
| 111 |
/**
|
| 112 |
* Form submit handler for click counter item reset.
|
| 113 |
*/
|
| 114 |
function gotwo_reset_form_submit($form, &$form_state) {
|
| 115 |
db_query("UPDATE {gotwo} SET cnt = %d WHERE gid = %d", 0, $form_state['values']['gid']);
|
| 116 |
$form_state['redirect'] = 'admin/build/gotwo';
|
| 117 |
}
|
| 118 |
|
| 119 |
/**
|
| 120 |
* Build delete form
|
| 121 |
*/
|
| 122 |
function gotwo_delete_form($form_state, $edit) {
|
| 123 |
$form['gid'] = array('#type' => 'value', '#value' => $edit->gid);
|
| 124 |
|
| 125 |
return confirm_form(
|
| 126 |
$form,
|
| 127 |
t('Delete go redirect %label', array('%label' => $edit->src)),
|
| 128 |
'admin/build/gotwo',
|
| 129 |
'<p>'. t('Are you sure you want to delete the go redirect %label? This action cannot be undone. The link will become broken, a new one might be automatically created when a node linking to it is edited.', array('%label' => $edit->src)) .'</p>',
|
| 130 |
t('Delete'),
|
| 131 |
t('Cancel')
|
| 132 |
);
|
| 133 |
}
|
| 134 |
|
| 135 |
/**
|
| 136 |
* Delete redirect form submitted
|
| 137 |
*/
|
| 138 |
function gotwo_delete_form_submit($form, &$form_state) {
|
| 139 |
db_query('DELETE FROM {gotwo} WHERE gid = %d', $form_state['values']['gid']);
|
| 140 |
$form_state['redirect'] = 'admin/build/gotwo';
|
| 141 |
}
|
| 142 |
|
| 143 |
/**
|
| 144 |
* Manually add a go redirect
|
| 145 |
*/
|
| 146 |
function gotwo_add_form(){
|
| 147 |
|
| 148 |
$form['src'] = array(
|
| 149 |
'#type' => 'textfield',
|
| 150 |
'#title' => t('Label'),
|
| 151 |
'#description' => t('The label used in the go url, this will automatically be made suitable.'),
|
| 152 |
'#required' => TRUE,
|
| 153 |
);
|
| 154 |
$form['dst'] = array(
|
| 155 |
'#type' => 'textfield',
|
| 156 |
'#title' => t('Destination'),
|
| 157 |
'#description' => t('The target url. Can be a relative drupal url or an absolute url.'),
|
| 158 |
'#required' => TRUE,
|
| 159 |
'#maxlength' => 255,
|
| 160 |
);
|
| 161 |
$form['submit'] = array(
|
| 162 |
'#type' => 'submit',
|
| 163 |
'#value' => t('Add'),
|
| 164 |
);
|
| 165 |
return $form;
|
| 166 |
}
|
| 167 |
|
| 168 |
/**
|
| 169 |
* Go redirect submitted
|
| 170 |
*/
|
| 171 |
function gotwo_add_form_submit($form, &$form_state) {
|
| 172 |
$res = _gotwo_get($form_state['values']['dst'], $form_state['values']['src']);
|
| 173 |
$form_state['redirect'] = 'admin/build/gotwo';
|
| 174 |
}
|