| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: google_keyhaviour.admin.inc,v 1.1.2.3 2009/05/03 03:14:49 danielb Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* The google_keyhaviour admin screens. |
* The google_keyhaviour admin screens. |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
|
| 10 |
/** |
/** |
| 11 |
* Admin google_keyhaviour list page. |
* Admin google_keyhaviour list page. |
| 12 |
*/ |
*/ |
| 13 |
function google_keyhaviour_admin_list() { |
function google_keyhaviour_admin_list() { |
| 14 |
$output = ''; |
$output = ''; |
| 15 |
$google_keyhaviours = google_keyhaviour_load_multiple(); |
$google_keyhaviours = google_keyhaviour_load_multiple(); |
| 16 |
if (!$google_keyhaviours) { |
if (!$google_keyhaviours) { |
| 17 |
$output .= t('There are currently no google keyhaviour rules configured.'); |
$output .= t('There are currently no google keyhaviour rules configured.'); |
| 18 |
} |
} |
| 19 |
else { |
else { |
| 20 |
$output .= drupal_get_form('google_keyhaviour_admin_list_form', $google_keyhaviours); |
$output .= drupal_get_form('google_keyhaviour_admin_list_form', $google_keyhaviours); |
| 21 |
} |
} |
| 22 |
$output .= drupal_get_form('google_keyhaviour_admin_add_form'); |
$output .= drupal_get_form('google_keyhaviour_admin_add_form'); |
| 23 |
return $output; |
return $output; |
| 24 |
} |
} |
| 25 |
|
|
| 26 |
/** |
/** |
| 27 |
* Admin google_keyhaviour list form. |
* Admin google_keyhaviour list form. |
| 28 |
*/ |
*/ |
| 29 |
function google_keyhaviour_admin_list_form($form_state, $google_keyhaviours) { |
function google_keyhaviour_admin_list_form($form_state, $google_keyhaviours) { |
| 30 |
$form = array(); |
$form = array(); |
| 31 |
$form['#tree'] = TRUE; |
$form['#tree'] = TRUE; |
| 32 |
$form['rules'] = array( |
$form['rules'] = array( |
| 33 |
'#title' => t('Google keyhaviour rules'), |
'#title' => t('Google keyhaviour rules'), |
| 34 |
'#heading' => t('Rule'), |
'#heading' => t('Rule'), |
| 35 |
'#weight' => 200, |
'#weight' => 200, |
| 36 |
'#theme' => 'google_keyhaviour_admin_edit_table', |
'#theme' => 'google_keyhaviour_admin_edit_table', |
| 37 |
'#description' => t('These actions let you manipulate template variables'), |
'#description' => t('These actions let you manipulate template variables'), |
| 38 |
); |
); |
| 39 |
foreach ((array)$google_keyhaviours as $google_keyhaviour) { |
foreach ((array)$google_keyhaviours as $google_keyhaviour) { |
| 40 |
$rule_output = "<div class='google_keyhaviour-rule'>"; |
$rule_output = '<div class="google_keyhaviour-rule">'; |
| 41 |
$rule_output .= check_plain($google_keyhaviour->settings['title']); |
$rule_output .= check_plain($google_keyhaviour->settings['title']); |
| 42 |
$rule_output .= "</div>"; |
$rule_output .= '</div>'; |
| 43 |
$form['rules'][$google_keyhaviour->google_keyhaviour_id]['value']['#value'] = $rule_output; |
$form['rules'][$google_keyhaviour->google_keyhaviour_id]['value']['#value'] = $rule_output; |
| 44 |
$form['rules'][$google_keyhaviour->google_keyhaviour_id]['ops']['#value'] = |
$form['rules'][$google_keyhaviour->google_keyhaviour_id]['ops']['#value'] = |
| 45 |
l('Edit', 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit') |
l(t('Edit'), 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit') |
| 46 |
. t(" | ") . l('Delete', 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/delete'); |
. ' | ' . l(t('Delete'), 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/delete'); |
| 47 |
$form['rules'][$google_keyhaviour->google_keyhaviour_id]['weight'] = array( |
$form['rules'][$google_keyhaviour->google_keyhaviour_id]['weight'] = array( |
| 48 |
'#type' => 'weight', |
'#type' => 'weight', |
| 49 |
'#delta' => count($google_keyhaviours), |
'#delta' => count($google_keyhaviours), |
| 50 |
'#default_value' => $google_keyhaviour->weight, |
'#default_value' => $google_keyhaviour->weight, |
| 51 |
); |
); |
| 52 |
} |
} |
| 53 |
$form['submit'] = array( |
$form['submit'] = array( |
| 54 |
'#type' => 'submit', |
'#type' => 'submit', |
| 55 |
'#value' => t('Save google keyhaviour rules order'), |
'#value' => t('Save google keyhaviour rules order'), |
| 56 |
'#weight' => 10010, |
'#weight' => 10010, |
| 57 |
); |
); |
| 58 |
return $form; |
return $form; |
| 59 |
} |
} |
| 60 |
|
|
| 61 |
/** |
/** |
| 62 |
* Submit function for admin google_keyhaviour list form. |
* Submit function for admin google_keyhaviour list form. |
| 63 |
*/ |
*/ |
| 64 |
function google_keyhaviour_admin_list_form_submit($form, &$form_state) { |
function google_keyhaviour_admin_list_form_submit($form, &$form_state) { |
| 65 |
$values = &$form_state['values']; |
$values = &$form_state['values']; |
| 66 |
if (is_array($values['rules'])) { |
if (is_array($values['rules'])) { |
| 67 |
foreach ($values['rules'] as $google_keyhaviour_id => $value) { |
foreach ($values['rules'] as $google_keyhaviour_id => $value) { |
| 68 |
$google_keyhaviour = (object)array( |
$google_keyhaviour = (object)array( |
| 69 |
'google_keyhaviour_id' => $google_keyhaviour_id, |
'google_keyhaviour_id' => $google_keyhaviour_id, |
| 70 |
'weight' => $value['weight'], |
'weight' => $value['weight'], |
| 71 |
); |
); |
| 72 |
$google_keyhaviour = google_keyhaviour_save($google_keyhaviour); |
$google_keyhaviour = google_keyhaviour_save($google_keyhaviour); |
| 73 |
} |
} |
| 74 |
} |
} |
| 75 |
} |
} |
| 76 |
|
|
| 77 |
/** |
/** |
| 78 |
* Admin google_keyhaviour add form. |
* Admin google_keyhaviour add form. |
| 79 |
*/ |
*/ |
| 80 |
function google_keyhaviour_admin_add_form($form_state) { |
function google_keyhaviour_admin_add_form($form_state) { |
| 81 |
$form = array(); |
$form = array(); |
| 82 |
$form['submit'] = array( |
$form['submit'] = array( |
| 83 |
'#type' => 'submit', |
'#type' => 'submit', |
| 84 |
'#value' => t('Add google keyhaviour rule'), |
'#value' => t('Add google keyhaviour rule'), |
| 85 |
'#weight' => 22, |
'#weight' => 22, |
| 86 |
); |
); |
| 87 |
return $form; |
return $form; |
| 88 |
} |
} |
| 89 |
|
|
| 90 |
/** |
/** |
| 91 |
* Submit function for admin google_keyhaviour add form. |
* Submit function for admin google_keyhaviour add form. |
| 92 |
*/ |
*/ |
| 93 |
function google_keyhaviour_admin_add_form_submit($form, &$form_state) { |
function google_keyhaviour_admin_add_form_submit($form, &$form_state) { |
| 94 |
$values = &$form_state['values']; |
$values = &$form_state['values']; |
| 95 |
$google_keyhaviour = (object)array('settings' => array()); |
$google_keyhaviour = (object)array('settings' => array()); |
| 96 |
$google_keyhaviour = google_keyhaviour_save($google_keyhaviour); |
$google_keyhaviour = google_keyhaviour_save($google_keyhaviour); |
| 97 |
$google_keyhaviour->settings = array( |
$google_keyhaviour->settings = array( |
| 98 |
'title' => t('Rule !id', array('!id' => $google_keyhaviour->google_keyhaviour_id)), |
'title' => t('Rule !id', array('!id' => $google_keyhaviour->google_keyhaviour_id)), |
| 99 |
); |
); |
| 100 |
$google_keyhaviour = google_keyhaviour_save($google_keyhaviour); |
$google_keyhaviour = google_keyhaviour_save($google_keyhaviour); |
| 101 |
drupal_set_message('A google keyhaviour rule was added. Configure the google keyhaviour rule below.'); |
drupal_set_message('A google keyhaviour rule was added. Configure the google keyhaviour rule below.'); |
| 102 |
drupal_goto('admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit'); |
drupal_goto('admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit'); |
| 103 |
} |
} |
| 104 |
|
|
| 105 |
/** |
/** |
| 106 |
* Admin google_keyhaviour edit page. |
* Admin google_keyhaviour edit page. |
| 107 |
*/ |
*/ |
| 108 |
function google_keyhaviour_admin_edit($form_state, $google_keyhaviour) { |
function google_keyhaviour_admin_edit($form_state, $google_keyhaviour) { |
| 109 |
global $custom_theme; |
global $custom_theme; |
| 110 |
|
|
| 111 |
// If non-default theme configuration has been selected, set the custom theme. |
// If non-default theme configuration has been selected, set the custom theme. |
| 112 |
$custom_theme = isset($theme) ? $theme : variable_get('theme_default', 'garland'); |
$custom_theme = isset($theme) ? $theme : variable_get('theme_default', 'garland'); |
| 113 |
|
|
| 114 |
// Fetch and sort blocks |
// Fetch and sort blocks |
| 115 |
module_load_include('inc', 'block', 'block.admin'); |
module_load_include('inc', 'block', 'block.admin'); |
| 116 |
$blocks = _block_rehash(); |
$blocks = _block_rehash(); |
| 117 |
usort($blocks, '_block_compare'); |
usort($blocks, '_block_compare'); |
| 118 |
|
|
| 119 |
|
|
| 120 |
$form_state['storage']['google_keyhaviour'] = $google_keyhaviour; |
$form_state['storage']['google_keyhaviour'] = $google_keyhaviour; |
| 121 |
$settings = &$google_keyhaviour->settings; |
$settings = &$google_keyhaviour->settings; |
| 122 |
|
|
| 123 |
// build the form |
// build the form |
| 124 |
$form = array(); |
$form = array(); |
| 125 |
$form['#tree'] = TRUE; |
$form['#tree'] = TRUE; |
| 126 |
$form['google_keyhaviour_id'] = array( |
$form['google_keyhaviour_id'] = array( |
| 127 |
'#type' => 'value', |
'#type' => 'value', |
| 128 |
'#value' => $google_keyhaviour->google_keyhaviour_id ? $google_keyhaviour->google_keyhaviour_id : 'add', |
'#value' => $google_keyhaviour->google_keyhaviour_id ? $google_keyhaviour->google_keyhaviour_id : 'add', |
| 129 |
'#weight' => 0, |
'#weight' => 0, |
| 130 |
); |
); |
| 131 |
$form['settings'] = array( |
$form['settings'] = array( |
| 132 |
'#weight' => 60, |
'#weight' => 60, |
| 133 |
); |
); |
| 134 |
|
|
| 135 |
$form['settings']['title'] = array( |
$form['settings']['title'] = array( |
| 136 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 137 |
'#title' => t('Title'), |
'#title' => t('Title'), |
| 138 |
'#default_value' => $settings['title'], |
'#default_value' => $settings['title'], |
| 139 |
'#size' => 40, |
'#size' => 40, |
| 140 |
'#maxlength' => 255, |
'#maxlength' => 255, |
| 141 |
'#required' => TRUE, |
'#required' => TRUE, |
| 142 |
'#weight' => 20, |
'#weight' => 20, |
| 143 |
); |
); |
| 144 |
|
|
| 145 |
|
|
| 146 |
$form['settings']['conditions'] = array( |
$form['settings']['conditions'] = array( |
| 147 |
'#weight' => 60, |
'#weight' => 60, |
| 148 |
'#title' => t('Conditions'), |
'#title' => t('Conditions'), |
| 149 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 150 |
'#description' => t('Save this page to add more conditions.'), |
'#description' => t('Save this page to add more conditions.'), |
| 151 |
); |
); |
| 152 |
|
|
| 153 |
$form['settings']['conditions']['operator'] = array( |
$form['settings']['conditions']['operator'] = array( |
| 154 |
'#type' => 'radios', |
'#type' => 'radios', |
| 155 |
'#title' => t('Conditions operator'), |
'#title' => t('Conditions operator'), |
| 156 |
'#default_value' => $settings['conditions']['operator'] ? $settings['conditions']['operator'] : '&&', |
'#default_value' => $settings['conditions']['operator'] ? $settings['conditions']['operator'] : '&&', |
| 157 |
'#options' => array( |
'#options' => array( |
| 158 |
'&&' => t('<b>and</b> - all conditions must be met'), |
'&&' => t('<b>and</b> - all conditions must be met'), |
| 159 |
'||' => t('<b>or</b> - any condition can be met'), |
'||' => t('<b>or</b> - any condition can be met'), |
| 160 |
), |
), |
| 161 |
'#weight' => 0, |
'#weight' => 0, |
| 162 |
); |
); |
| 163 |
unset($settings['conditions']['operator']); |
unset($settings['conditions']['operator']); |
| 164 |
|
|
| 165 |
$settings['conditions'][] = array( |
$settings['conditions'][] = array( |
| 166 |
'match' => '', |
'match' => '', |
| 167 |
'phrase' => '', |
'phrase' => '', |
| 168 |
); |
); |
| 169 |
|
|
| 170 |
foreach ($settings['conditions'] as $key => $condition) { |
foreach ($settings['conditions'] as $key => $condition) { |
| 171 |
$form['settings']['conditions'][$key] = array( |
$form['settings']['conditions'][$key] = array( |
| 172 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 173 |
); |
); |
| 174 |
$form['settings']['conditions'][$key]['match'] = array( |
$form['settings']['conditions'][$key]['match'] = array( |
| 175 |
'#type' => 'select', |
'#type' => 'select', |
| 176 |
'#prefix' => '<span class="prefix">'. t('The google keywords') .'</span>', |
'#prefix' => '<span class="prefix">'. t('The google keywords') .'</span>', |
| 177 |
'#default_value' => $condition['match'], |
'#default_value' => $condition['match'], |
| 178 |
'#options' => array( |
'#options' => array( |
| 179 |
'' => '', |
'' => '', |
| 180 |
'contain' => t('contain the following phrase:'), |
'contain' => t('contain the following phrase:'), |
| 181 |
'do not contain' => t('do not contain the following phrase:'), |
'do not contain' => t('do not contain the following phrase:'), |
| 182 |
'are exactly' => t('are exactly the following phrase:'), |
'are exactly' => t('are exactly the following phrase:'), |
| 183 |
'exist' => t('exist (no need to add a phrase)'), |
'exist' => t('exist (no need to add a phrase)'), |
| 184 |
), |
), |
| 185 |
); |
); |
| 186 |
$form['settings']['conditions'][$key]['phrase'] = array( |
$form['settings']['conditions'][$key]['phrase'] = array( |
| 187 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 188 |
'#default_value' => $condition['phrase'], |
'#default_value' => $condition['phrase'], |
| 189 |
); |
); |
| 190 |
} |
} |
| 191 |
|
|
| 192 |
$form['settings']['blocks'] = array( |
$form['settings']['blocks'] = array( |
| 193 |
'#weight' => 70, |
'#weight' => 70, |
| 194 |
'#title' => t('Block visibility'), |
'#title' => t('Block visibility'), |
| 195 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 196 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 197 |
'#collapsed' => $block_collapse, |
'#collapsed' => $block_collapse, |
| 198 |
); |
); |
| 199 |
|
|
| 200 |
$form['settings']['blocks']['visibility'] = array( |
$form['settings']['blocks']['visibility'] = array( |
| 201 |
'#type' => 'radios', |
'#type' => 'radios', |
| 202 |
'#weight' => 0, |
'#weight' => 0, |
| 203 |
'#default_value' => $settings['blocks']['visibility'] ? $settings['blocks']['visibility'] : 'show', |
'#default_value' => $settings['blocks']['visibility'] ? $settings['blocks']['visibility'] : 'show', |
| 204 |
'#options' => array ( |
'#options' => array ( |
| 205 |
'show' => t('Show all blocks'), |
'show' => t('Show all blocks'), |
| 206 |
'hide' => t('Hide all blocks'), |
'hide' => t('Hide all blocks'), |
| 207 |
), |
), |
| 208 |
); |
); |
| 209 |
|
|
| 210 |
$block_options = array(); |
$block_options = array(); |
| 211 |
foreach ($blocks as $i => $block) { |
foreach ($blocks as $i => $block) { |
| 212 |
if ($block['region'] != -1) { // hide disabled blocks |
if ($block['region'] != -1) { // hide disabled blocks |
| 213 |
$block_options[$block['bid']] = $block['info'] .' ('. google_keyhaviour_to_display($block['region']) .')'; |
$block_options[$block['bid']] = $block['info'] .' ('. google_keyhaviour_to_display($block['region']) .')'; |
| 214 |
} |
} |
| 215 |
} |
} |
| 216 |
|
|
| 217 |
$form['settings']['blocks']['exceptions'] = array( |
$form['settings']['blocks']['exceptions'] = array( |
| 218 |
'#type' => 'checkboxes', |
'#type' => 'checkboxes', |
| 219 |
'#title' => t('Except for these'), |
'#title' => t('Except for these'), |
| 220 |
'#weight' => 2, |
'#weight' => 2, |
| 221 |
'#default_value' => $settings['blocks']['exceptions'] ? $settings['blocks']['exceptions'] : array(), |
'#default_value' => $settings['blocks']['exceptions'] ? $settings['blocks']['exceptions'] : array(), |
| 222 |
'#options' => $block_options, |
'#options' => $block_options, |
| 223 |
); |
); |
| 224 |
|
|
| 225 |
if (!empty($google_keyhaviour->actions)) { |
if (!empty($google_keyhaviour->actions)) { |
| 226 |
$form['actions'] = array( |
$form['actions'] = array( |
| 227 |
'#title' => t('Actions'), |
'#title' => t('Actions'), |
| 228 |
'#heading' => t('Action'), |
'#heading' => t('Action'), |
| 229 |
'#weight' => 200, |
'#weight' => 200, |
| 230 |
'#theme' => 'google_keyhaviour_admin_edit_table', |
'#theme' => 'google_keyhaviour_admin_edit_table', |
| 231 |
'#description' => t('These actions let you manipulate template variables'), |
'#description' => t('These actions let you manipulate template variables'), |
| 232 |
); |
); |
| 233 |
foreach ($google_keyhaviour->actions as $key => $value) { |
foreach ($google_keyhaviour->actions as $key => $value) { |
| 234 |
$action_output = "<div class='google_keyhaviour-action'>"; |
$action_output = '<div class="google_keyhaviour-action">'; |
| 235 |
$action_output .= "<span class='google_keyhaviour-action-verb'>". google_keyhaviour_to_display($value->settings['verb']) ."</span><span class='space'> </span>"; |
$action_output .= '<span class="google_keyhaviour-action-verb">'. google_keyhaviour_to_display($value->settings['verb']) .'</span><span class="space"> </span>'; |
| 236 |
$action_output .= "<span class='google_keyhaviour-action-var'>". google_keyhaviour_admin_list_variables($value->settings['var']) ."</span>"; |
$action_output .= '<span class="google_keyhaviour-action-var">'. google_keyhaviour_admin_list_variables($value->settings['var']) .'</span>'; |
| 237 |
$action_output .= "<span class='google_keyhaviour-action-with'><span class='with-prefix'> with </span>". $value->settings['with'] ."</span>"; |
$action_output .= '<span class="google_keyhaviour-action-with"><span class="with-prefix"> with </span>'. $value->settings['with'] .'</span>'; |
| 238 |
$action_output .= "</div>"; |
$action_output .= '</div>'; |
| 239 |
$form['actions'][$value->google_keyhaviour_action_id]['value']['#value'] = $action_output; |
$form['actions'][$value->google_keyhaviour_action_id]['value']['#value'] = $action_output; |
| 240 |
$form['actions'][$value->google_keyhaviour_action_id]['ops']['#value'] = |
$form['actions'][$value->google_keyhaviour_action_id]['ops']['#value'] = |
| 241 |
l('Edit', 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit/'. $value->google_keyhaviour_action_id .'/edit') |
l(t('Edit'), 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit/'. $value->google_keyhaviour_action_id .'/edit') |
| 242 |
. t(" | ") . l('Delete', 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit/'. $value->google_keyhaviour_action_id .'/delete'); |
. ' | ' . l(t('Delete'), 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit/'. $value->google_keyhaviour_action_id .'/delete'); |
| 243 |
$form['actions'][$value->google_keyhaviour_action_id]['weight'] = array( |
$form['actions'][$value->google_keyhaviour_action_id]['weight'] = array( |
| 244 |
'#type' => 'weight', |
'#type' => 'weight', |
| 245 |
'#delta' => count($google_keyhaviour->actions), |
'#delta' => count($google_keyhaviour->actions), |
| 246 |
'#default_value' => $key, |
'#default_value' => $key, |
| 247 |
); |
); |
| 248 |
} |
} |
| 249 |
} |
} |
| 250 |
else { |
else { |
| 251 |
$form['no_actions'] = array( |
$form['no_actions'] = array( |
| 252 |
'#value' => t(' |
'#value' => t(' |
| 253 |
<div id="edit-no-actions-wrapper" class="form-item"> |
<div id="edit-no-actions-wrapper" class="form-item"> |
| 254 |
<label for="edit-path">Actions:</label> |
<label for="edit-path">'. t('Actions') .':</label> |
| 255 |
There are currently no actions configured for this google keyhaviour rule. |
'. t('There are currently no actions configured for this google keyhaviour rule.') .' |
| 256 |
</div> |
</div> |
| 257 |
'), |
'), |
| 258 |
'#weight' => 100, |
'#weight' => 100, |
| 259 |
); |
); |
| 260 |
} |
} |
| 261 |
|
|
| 262 |
$form['addaction'] = array( |
$form['addaction'] = array( |
| 263 |
'#type' => 'submit', |
'#type' => 'submit', |
| 264 |
'#value' => t('Add google keyhaviour action'), |
'#value' => t('Add google keyhaviour action'), |
| 265 |
'#weight' => 10001, |
'#weight' => 10001, |
| 266 |
'#prefix' => '<div>', |
'#prefix' => '<div>', |
| 267 |
'#suffix' => '</div>', |
'#suffix' => '</div>', |
| 268 |
); |
); |
| 269 |
|
|
| 270 |
$form['submit'] = array( |
$form['submit'] = array( |
| 271 |
'#type' => 'submit', |
'#type' => 'submit', |
| 272 |
'#value' => t('Save google keyhaviour rule'), |
'#value' => t('Save google keyhaviour rule'), |
| 273 |
'#weight' => 10010, |
'#weight' => 10010, |
| 274 |
); |
); |
| 275 |
$form['delete'] = array( |
$form['delete'] = array( |
| 276 |
'#type' => 'submit', |
'#type' => 'submit', |
| 277 |
'#value' => t('Delete google keyhaviour rule'), |
'#value' => t('Delete google keyhaviour rule'), |
| 278 |
'#weight' => 10020, |
'#weight' => 10020, |
| 279 |
); |
); |
| 280 |
return $form; |
return $form; |
| 281 |
} |
} |
| 282 |
|
|
| 283 |
/** |
/** |
| 284 |
* Submit function for admin google_keyhaviour add/edit page. |
* Submit function for admin google_keyhaviour add/edit page. |
| 285 |
*/ |
*/ |
| 286 |
function google_keyhaviour_admin_edit_submit($form, &$form_state) { |
function google_keyhaviour_admin_edit_submit($form, &$form_state) { |
| 287 |
$values = &$form_state['values']; |
$values = &$form_state['values']; |
| 288 |
if ($form_state['clicked_button']['#id'] == 'edit-delete') { |
if ($form_state['clicked_button']['#id'] == 'edit-delete') { |
| 289 |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/delete'); |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/delete'); |
| 290 |
} |
} |
| 291 |
else { |
else { |
| 292 |
// remove blank conditions |
// remove blank conditions |
| 293 |
foreach ($values['settings']['conditions'] as $key => $value) { |
foreach ($values['settings']['conditions'] as $key => $value) { |
| 294 |
if (is_numeric($key)) { |
if (is_numeric($key)) { |
| 295 |
if ($value['match'] != 'exist' && !$value['phrase']) { |
if ($value['match'] != 'exist' && !$value['phrase']) { |
| 296 |
unset($values['settings']['conditions'][$key]); |
unset($values['settings']['conditions'][$key]); |
| 297 |
} |
} |
| 298 |
} |
} |
| 299 |
} |
} |
| 300 |
$google_keyhaviour = (object)array( |
$google_keyhaviour = (object)array( |
| 301 |
'google_keyhaviour_id' => $values['google_keyhaviour_id'], |
'google_keyhaviour_id' => $values['google_keyhaviour_id'], |
| 302 |
'settings' => $values['settings'], |
'settings' => $values['settings'], |
| 303 |
); |
); |
| 304 |
$google_keyhaviour = google_keyhaviour_save($google_keyhaviour); |
$google_keyhaviour = google_keyhaviour_save($google_keyhaviour); |
| 305 |
if (is_array($values['actions'])) { |
if (is_array($values['actions'])) { |
| 306 |
foreach ($values['actions'] as $google_keyhaviour_action_id => $value) { |
foreach ($values['actions'] as $google_keyhaviour_action_id => $value) { |
| 307 |
$google_keyhaviour_action = (object)array( |
$google_keyhaviour_action = (object)array( |
| 308 |
'google_keyhaviour_action_id' => $google_keyhaviour_action_id, |
'google_keyhaviour_action_id' => $google_keyhaviour_action_id, |
| 309 |
'weight' => $value['weight'], |
'weight' => $value['weight'], |
| 310 |
); |
); |
| 311 |
$google_keyhaviour_action = google_keyhaviour_action_save($google_keyhaviour_action); |
$google_keyhaviour_action = google_keyhaviour_action_save($google_keyhaviour_action); |
| 312 |
} |
} |
| 313 |
} |
} |
| 314 |
drupal_set_message('The google keyhaviour rule was saved.'); |
drupal_set_message(t('The google keyhaviour rule was saved.')); |
| 315 |
|
|
| 316 |
if ($form_state['clicked_button']['#id'] == 'edit-addaction') { |
if ($form_state['clicked_button']['#id'] == 'edit-addaction') { |
| 317 |
$google_keyhaviour_action = (object)array( |
$google_keyhaviour_action = (object)array( |
| 318 |
'google_keyhaviour_id' => $values['google_keyhaviour_id'], |
'google_keyhaviour_id' => $values['google_keyhaviour_id'], |
| 319 |
); |
); |
| 320 |
$google_keyhaviour_action = google_keyhaviour_action_save($google_keyhaviour_action); |
$google_keyhaviour_action = google_keyhaviour_action_save($google_keyhaviour_action); |
| 321 |
$google_keyhaviour_action->title = t('Google keyhaviour action !1', array('!1' => $google_keyhaviour_action->google_keyhaviour_action_id)); |
$google_keyhaviour_action->title = t('Google keyhaviour action !1', array('!1' => $google_keyhaviour_action->google_keyhaviour_action_id)); |
| 322 |
$google_keyhaviour_action = google_keyhaviour_action_save($google_keyhaviour_action); |
$google_keyhaviour_action = google_keyhaviour_action_save($google_keyhaviour_action); |
| 323 |
drupal_set_message('A google keyhaviour action was added. Configure the action below.'); |
drupal_set_message(t('A google keyhaviour action was added. Configure the action below.')); |
| 324 |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/edit/'. $google_keyhaviour_action->google_keyhaviour_action_id .'/edit/'); |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/edit/'. $google_keyhaviour_action->google_keyhaviour_action_id .'/edit/'); |
| 325 |
} |
} |
| 326 |
else { |
else { |
| 327 |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/edit/'); |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/edit/'); |
| 328 |
} |
} |
| 329 |
} |
} |
| 330 |
} |
} |
| 331 |
|
|
| 332 |
/** |
/** |
| 333 |
* Admin google_keyhaviour delete page. |
* Admin google_keyhaviour delete page. |
| 334 |
*/ |
*/ |
| 335 |
function google_keyhaviour_admin_delete($form_state, $google_keyhaviour) { |
function google_keyhaviour_admin_delete($form_state, $google_keyhaviour) { |
| 336 |
$form_state['storage']['google_keyhaviour'] = $google_keyhaviour; |
$form_state['storage']['google_keyhaviour'] = $google_keyhaviour; |
| 337 |
// build the form |
// build the form |
| 338 |
$form = array(); |
$form = array(); |
| 339 |
$form['#tree'] = TRUE; |
$form['#tree'] = TRUE; |
| 340 |
$form['google_keyhaviour_id'] = array( |
$form['google_keyhaviour_id'] = array( |
| 341 |
'#type' => 'value', |
'#type' => 'value', |
| 342 |
'#value' => $google_keyhaviour->google_keyhaviour_id, |
'#value' => $google_keyhaviour->google_keyhaviour_id, |
| 343 |
); |
); |
| 344 |
return confirm_form($form, |
return confirm_form($form, |
| 345 |
t('Are you sure you want to delete the %gkt google keyhaviour?', array('%gkt' => $google_keyhaviour->settings['title'])), |
t('Are you sure you want to delete the %gkt google keyhaviour?', array('%gkt' => $google_keyhaviour->settings['title'])), |
| 346 |
$_GET['destination'] ? $_GET['destination'] : 'admin/build/google_keyhaviour', |
$_GET['destination'] ? $_GET['destination'] : 'admin/build/google_keyhaviour', |
| 347 |
t('This action cannot be undone.'), |
t('This action cannot be undone.'), |
| 348 |
t('Delete'), t('Cancel')); |
t('Delete'), t('Cancel')); |
| 349 |
} |
} |
| 350 |
|
|
| 351 |
/** |
/** |
| 352 |
* Submit function for admin google_keyhaviour delete page. |
* Submit function for admin google_keyhaviour delete page. |
| 353 |
*/ |
*/ |
| 354 |
function google_keyhaviour_admin_delete_submit($form, &$form_state) { |
function google_keyhaviour_admin_delete_submit($form, &$form_state) { |
| 355 |
$google_keyhaviour_id = &$form_state['values']['google_keyhaviour_id']; |
$google_keyhaviour_id = &$form_state['values']['google_keyhaviour_id']; |
| 356 |
google_keyhaviour_delete($google_keyhaviour_id); |
google_keyhaviour_delete($google_keyhaviour_id); |
| 357 |
menu_rebuild(); |
menu_rebuild(); |
| 358 |
drupal_goto('admin/build/google_keyhaviour'); |
drupal_goto('admin/build/google_keyhaviour'); |
| 359 |
} |
} |
| 360 |
|
|
| 361 |
/** |
/** |
| 362 |
* Admin google_keyhaviour action add/edit page. |
* Admin google_keyhaviour action add/edit page. |
| 363 |
* Must have a google_keyhaviour object at this point. |
* Must have a google_keyhaviour object at this point. |
| 364 |
*/ |
*/ |
| 365 |
function google_keyhaviour_admin_action_edit($form_state, $google_keyhaviour, $google_keyhaviour_action_id) { |
function google_keyhaviour_admin_action_edit($form_state, $google_keyhaviour, $google_keyhaviour_action_id) { |
| 366 |
$action = google_keyhaviour_admin_get_action_defaults($google_keyhaviour, $google_keyhaviour_action_id); |
$action = google_keyhaviour_admin_get_action_defaults($google_keyhaviour, $google_keyhaviour_action_id); |
| 367 |
$form_state['storage']['google_keyhaviour'] = $google_keyhaviour; |
$form_state['storage']['google_keyhaviour'] = $google_keyhaviour; |
| 368 |
$form_state['storage']['google_keyhaviour_action_id'] = $google_keyhaviour_action_id; |
$form_state['storage']['google_keyhaviour_action_id'] = $google_keyhaviour_action_id; |
| 369 |
$form_state['storage']['google_keyhaviour_action_defaults'] = $action; |
$form_state['storage']['google_keyhaviour_action_defaults'] = $action; |
| 370 |
$settings = &$action->settings; |
$settings = &$action->settings; |
| 371 |
|
|
| 372 |
$form = array(); |
$form = array(); |
| 373 |
|
|
| 374 |
$form['#tree'] = TRUE; |
$form['#tree'] = TRUE; |
| 375 |
|
|
| 376 |
$form['google_keyhaviour_id'] = array( |
$form['google_keyhaviour_id'] = array( |
| 377 |
'#type' => 'value', |
'#type' => 'value', |
| 378 |
'#value' => $google_keyhaviour->google_keyhaviour_id, |
'#value' => $google_keyhaviour->google_keyhaviour_id, |
| 379 |
'#weight' => 0, |
'#weight' => 0, |
| 380 |
); |
); |
| 381 |
|
|
| 382 |
$form['google_keyhaviour_action_id'] = array( |
$form['google_keyhaviour_action_id'] = array( |
| 383 |
'#type' => 'value', |
'#type' => 'value', |
| 384 |
'#value' => $google_keyhaviour_action_id, |
'#value' => $google_keyhaviour_action_id, |
| 385 |
'#weight' => 2, |
'#weight' => 2, |
| 386 |
); |
); |
| 387 |
|
|
| 388 |
$form['settings'] = array( |
$form['settings'] = array( |
| 389 |
'#weight' => 30, |
'#weight' => 30, |
| 390 |
); |
); |
| 391 |
|
|
| 392 |
$form['settings']['verb'] = array( |
$form['settings']['verb'] = array( |
| 393 |
'#type' => 'select', |
'#type' => 'select', |
| 394 |
'#default_value' => $settings['verb'], |
'#default_value' => $settings['verb'], |
| 395 |
'#options' => array( |
'#options' => array( |
| 396 |
'' => '', |
'' => '', |
| 397 |
'append' => t('Append'), |
'append' => t('Append'), |
| 398 |
'prepend' => t('Prepend'), |
'prepend' => t('Prepend'), |
| 399 |
'replace' => t('Replace'), |
'replace' => t('Replace'), |
| 400 |
), |
), |
| 401 |
'#weight' => '4', |
'#weight' => '4', |
| 402 |
'#required' => TRUE, |
'#required' => TRUE, |
| 403 |
); |
); |
| 404 |
|
|
| 405 |
$form['settings']['var'] = array( |
$form['settings']['var'] = array( |
| 406 |
'#type' => 'select', |
'#type' => 'select', |
| 407 |
'#default_value' => $settings['var'], |
'#default_value' => $settings['var'], |
| 408 |
'#options' => array('' => '') + google_keyhaviour_admin_list_variables(), |
'#options' => array('' => '') + google_keyhaviour_admin_list_variables(), |
| 409 |
'#weight' => '6', |
'#weight' => '6', |
| 410 |
'#required' => TRUE, |
'#required' => TRUE, |
| 411 |
); |
); |
| 412 |
|
|
| 413 |
$form['settings']['with'] = array( |
$form['settings']['with'] = array( |
| 414 |
'#type' => 'textarea', |
'#type' => 'textarea', |
| 415 |
'#title' => t('with'), |
'#title' => t('with'), |
| 416 |
'#default_value' => $settings['with'], |
'#default_value' => $settings['with'], |
| 417 |
'#required' => FALSE, |
'#required' => FALSE, |
| 418 |
'#rows' => 12, |
'#rows' => 12, |
| 419 |
'#weight' => '8', |
'#weight' => '8', |
| 420 |
'#description' => t('Use <i><keywords></i> to display the user\'s Google Keywords.'), |
'#description' => t('Use <i><keywords></i> to display the user\'s Google Keywords.'), |
| 421 |
); |
); |
| 422 |
|
|
| 423 |
$form['submit'] = array( |
$form['submit'] = array( |
| 424 |
'#type' => 'submit', |
'#type' => 'submit', |
| 425 |
'#value' => t('Save google keyhaviour action'), |
'#value' => t('Save google keyhaviour action'), |
| 426 |
'#weight' => 10000, |
'#weight' => 10000, |
| 427 |
); |
); |
| 428 |
|
|
| 429 |
$form['delete'] = array( |
$form['delete'] = array( |
| 430 |
'#type' => 'submit', |
'#type' => 'submit', |
| 431 |
'#value' => t('Delete google keyhaviour action'), |
'#value' => t('Delete google keyhaviour action'), |
| 432 |
'#weight' => 10020, |
'#weight' => 10020, |
| 433 |
); |
); |
| 434 |
|
|
| 435 |
return $form; |
return $form; |
| 436 |
} |
} |
| 437 |
|
|
| 438 |
/** |
/** |
| 439 |
* Submit function for admin google_keyhaviour add/edit page. |
* Submit function for admin google_keyhaviour add/edit page. |
| 440 |
*/ |
*/ |
| 441 |
function google_keyhaviour_admin_action_edit_submit($form, &$form_state) { |
function google_keyhaviour_admin_action_edit_submit($form, &$form_state) { |
| 442 |
$values = &$form_state['values']; |
$values = &$form_state['values']; |
| 443 |
if ($form_state['clicked_button']['#id'] == 'edit-delete') { |
if ($form_state['clicked_button']['#id'] == 'edit-delete') { |
| 444 |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/edit/'. $values['google_keyhaviour_action_id'] .'/delete'); |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/edit/'. $values['google_keyhaviour_action_id'] .'/delete'); |
| 445 |
} |
} |
| 446 |
else { |
else { |
| 447 |
$google_keyhaviour_action = (object)array( |
$google_keyhaviour_action = (object)array( |
| 448 |
'google_keyhaviour_action_id' => $values['google_keyhaviour_action_id'], |
'google_keyhaviour_action_id' => $values['google_keyhaviour_action_id'], |
| 449 |
'google_keyhaviour_id' => $values['google_keyhaviour_id'], |
'google_keyhaviour_id' => $values['google_keyhaviour_id'], |
| 450 |
'settings' => $values['settings'], |
'settings' => $values['settings'], |
| 451 |
); |
); |
| 452 |
$google_keyhaviour_action = google_keyhaviour_action_save($google_keyhaviour_action); |
$google_keyhaviour_action = google_keyhaviour_action_save($google_keyhaviour_action); |
| 453 |
|
|
| 454 |
drupal_set_message('The google keyhaviour action was saved.'); |
drupal_set_message(t('The google keyhaviour action was saved.')); |
| 455 |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/edit'); |
drupal_goto('admin/build/google_keyhaviour/'. $values['google_keyhaviour_id'] .'/edit'); |
| 456 |
} |
} |
| 457 |
} |
} |
| 458 |
|
|
| 459 |
/** |
/** |
| 460 |
* Admin google_keyhaviour delete page |
* Admin google_keyhaviour delete page |
| 461 |
*/ |
*/ |
| 462 |
function google_keyhaviour_admin_action_delete($form_state, $google_keyhaviour, $google_keyhaviour_action_id) { |
function google_keyhaviour_admin_action_delete($form_state, $google_keyhaviour, $google_keyhaviour_action_id) { |
| 463 |
$action = google_keyhaviour_admin_get_action_defaults($google_keyhaviour, $google_keyhaviour_action_id); |
$action = google_keyhaviour_admin_get_action_defaults($google_keyhaviour, $google_keyhaviour_action_id); |
| 464 |
|
|
| 465 |
$form = array(); |
$form = array(); |
| 466 |
$form['#tree'] = TRUE; |
$form['#tree'] = TRUE; |
| 467 |
$form['google_keyhaviour_action_id'] = array( |
$form['google_keyhaviour_action_id'] = array( |
| 468 |
'#type' => 'value', |
'#type' => 'value', |
| 469 |
'#value' => $google_keyhaviour_action_id, |
'#value' => $google_keyhaviour_action_id, |
| 470 |
); |
); |
| 471 |
$form['google_keyhaviour_id'] = array( |
$form['google_keyhaviour_id'] = array( |
| 472 |
'#type' => 'value', |
'#type' => 'value', |
| 473 |
'#value' => $google_keyhaviour->google_keyhaviour_id, |
'#value' => $google_keyhaviour->google_keyhaviour_id, |
| 474 |
); |
); |
| 475 |
return confirm_form($form, |
return confirm_form($form, |
| 476 |
t('Are you sure you want to delete the google keyhaviour action?'), |
t('Are you sure you want to delete the google keyhaviour action?'), |
| 477 |
$_GET['destination'] ? $_GET['destination'] : 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit', |
$_GET['destination'] ? $_GET['destination'] : 'admin/build/google_keyhaviour/'. $google_keyhaviour->google_keyhaviour_id .'/edit', |
| 478 |
t('This action cannot be undone.'), |
t('This action cannot be undone.'), |
| 479 |
t('Delete'), t('Cancel')); |
t('Delete'), t('Cancel')); |
| 480 |
} |
} |
| 481 |
|
|
| 482 |
/** |
/** |
| 483 |
* Submit function for admin google_keyhaviour delete page. |
* Submit function for admin google_keyhaviour delete page. |
| 484 |
*/ |
*/ |
| 485 |
function google_keyhaviour_admin_action_delete_submit($form, &$form_state) { |
function google_keyhaviour_admin_action_delete_submit($form, &$form_state) { |
| 486 |
$google_keyhaviour_action_id = &$form_state['values']['google_keyhaviour_action_id']; |
$google_keyhaviour_action_id = &$form_state['values']['google_keyhaviour_action_id']; |
| 487 |
$google_keyhaviour_id = &$form_state['values']['google_keyhaviour_id']; |
$google_keyhaviour_id = &$form_state['values']['google_keyhaviour_id']; |
| 488 |
google_keyhaviour_action_delete($google_keyhaviour_action_id); |
google_keyhaviour_action_delete($google_keyhaviour_action_id); |
| 489 |
drupal_goto('admin/build/google_keyhaviour/'. $google_keyhaviour_id .'/edit'); |
drupal_goto('admin/build/google_keyhaviour/'. $google_keyhaviour_id .'/edit'); |
| 490 |
} |
} |
| 491 |
|
|
| 492 |
/** |
/** |
| 493 |
* Default settings for an action. |
* Default settings for an action. |
| 494 |
*/ |
*/ |
| 495 |
function google_keyhaviour_admin_get_action_defaults($google_keyhaviour, $google_keyhaviour_action_id) { |
function google_keyhaviour_admin_get_action_defaults($google_keyhaviour, $google_keyhaviour_action_id) { |
| 496 |
// because we are not keying by $google_keyhaviour_action_id, we have to find the correct action like this. |
// because we are not keying by $google_keyhaviour_action_id, we have to find the correct action like this. |
| 497 |
$key = $google_keyhaviour->actions_index[$google_keyhaviour_action_id]; |
$key = $google_keyhaviour->actions_index[$google_keyhaviour_action_id]; |
| 498 |
return $google_keyhaviour->actions[$key]; |
return $google_keyhaviour->actions[$key]; |
| 499 |
} |
} |
| 500 |
|
|
| 501 |
/** |
/** |
| 502 |
* Get a list of variables for admin selection. |
* Get a list of variables for admin selection. |
| 503 |
*/ |
*/ |
| 504 |
function google_keyhaviour_admin_list_variables($variable = NULL) { |
function google_keyhaviour_admin_list_variables($variable = NULL) { |
| 505 |
static $list = array(); |
static $list = array(); |
| 506 |
if (empty($list)) { |
if (empty($list)) { |
| 507 |
$variables = array( |
$variables = array( |
| 508 |
'base_path', |
'base_path', |
| 509 |
'body_classes', |
'body_classes', |
| 510 |
'breadcrumb', |
'breadcrumb', |
| 511 |
'closure', |
'closure', |
| 512 |
'content', |
'content', |
| 513 |
'db_is_active', |
'db_is_active', |
| 514 |
'directory', |
'directory', |
| 515 |
'feed_icons', |
'feed_icons', |
| 516 |
'footer', |
'footer', |
| 517 |
'footer_message', |
'footer_message', |
| 518 |
'front_page', |
'front_page', |
| 519 |
'head', |
'head', |
| 520 |
'head_title', |
'head_title', |
| 521 |
'header', |
'header', |
| 522 |
'help', |
'help', |
| 523 |
'id', |
'id', |
| 524 |
'is_admin', |
'is_admin', |
| 525 |
'is_front', |
'is_front', |
| 526 |
'layout', |
'layout', |
| 527 |
'left', |
'left', |
| 528 |
'logged_in', |
'logged_in', |
| 529 |
'logo', |
'logo', |
| 530 |
'messages', |
'messages', |
| 531 |
'mission', |
'mission', |
| 532 |
'right', |
'right', |
| 533 |
'scripts', |
'scripts', |
| 534 |
'search_box', |
'search_box', |
| 535 |
'show_blocks', |
'show_blocks', |
| 536 |
'show_messages', |
'show_messages', |
| 537 |
'site_name', |
'site_name', |
| 538 |
'site_slogan', |
'site_slogan', |
| 539 |
'styles', |
'styles', |
| 540 |
'tabs', |
'tabs', |
| 541 |
'title', |
'title', |
| 542 |
'zebra', |
'zebra', |
| 543 |
); |
); |
| 544 |
foreach ($variables as $var) { |
foreach ($variables as $var) { |
| 545 |
$list[$var] = '$'. $var; |
$list[$var] = '$'. $var; |
| 546 |
} |
} |
| 547 |
} |
} |
| 548 |
if ($variable) { |
if ($variable) { |
| 549 |
return $list[$variable]; |
return $list[$variable]; |
| 550 |
} |
} |
| 551 |
return $list; |
return $list; |
| 552 |
/* |
/* |
| 553 |
To do; |
To do; |
| 554 |
shall we handle these objects and arrays? |
shall we handle these objects and arrays? |
| 555 |
* template_files |
* template_files |
| 556 |
* user |
* user |
| 557 |
* language |
* language |
| 558 |
* primary_links |
* primary_links |
| 559 |
* secondary_links |
* secondary_links |
| 560 |
* css |
* css |
| 561 |
*/ |
*/ |
| 562 |
} |
} |