| 1 |
<?php
|
| 2 |
// $Id: live.module,v 1.6 2009/07/29 20:40:08 Gurpartap Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_perm().
|
| 6 |
*/
|
| 7 |
function live_perm() {
|
| 8 |
return array('use live comment preview', 'use live node preview', 'administer live preview');
|
| 9 |
}
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Implementation of hook_menu().
|
| 13 |
*/
|
| 14 |
function live_menu() {
|
| 15 |
$items = array();
|
| 16 |
|
| 17 |
$items['live/comment/preview'] = array(
|
| 18 |
'page callback' => 'live_comment_preview',
|
| 19 |
'access callback' => 'live_comment_preview_access',
|
| 20 |
'file' => 'comment/live.comment.inc',
|
| 21 |
'type' => MENU_CALLBACK,
|
| 22 |
);
|
| 23 |
|
| 24 |
$items['live/node/preview'] = array(
|
| 25 |
'page callback' => 'live_node_preview',
|
| 26 |
'access arguments' => array('use live node preview'),
|
| 27 |
'file' => 'node/live.node.inc',
|
| 28 |
'type' => MENU_CALLBACK,
|
| 29 |
);
|
| 30 |
|
| 31 |
$items['admin/settings/live'] = array(
|
| 32 |
'title' => t('Live'),
|
| 33 |
'description' => t('Basic configuration for preview placements and effects.'),
|
| 34 |
'page callback' => 'drupal_get_form',
|
| 35 |
'page arguments' => array('live_settings'),
|
| 36 |
'access callback' => 'user_access',
|
| 37 |
'access arguments' => array('administer live preview'),
|
| 38 |
'type' => MENU_NORMAL_ITEM,
|
| 39 |
);
|
| 40 |
|
| 41 |
return $items;
|
| 42 |
}
|
| 43 |
|
| 44 |
function live_comment_preview_access() {
|
| 45 |
return (user_access('post comments') && user_access('use live comment preview'));
|
| 46 |
}
|
| 47 |
|
| 48 |
/**
|
| 49 |
* Implementation of hook_theme().
|
| 50 |
*/
|
| 51 |
function live_theme() {
|
| 52 |
return array(
|
| 53 |
'live_node_preview' => array('node' => NULL),
|
| 54 |
);
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 58 |
* Implementation of hook_form_alter().
|
| 59 |
*/
|
| 60 |
function live_form_alter(&$form, $form_state, $form_id) {
|
| 61 |
if ($form_id == 'comment_form' && (!isset($form['#after_build']) || $form['#after_build'][0] != 'comment_form_add_preview') && user_access('use live comment preview')) {
|
| 62 |
global $user;
|
| 63 |
$path = drupal_get_path('module', 'live');
|
| 64 |
$token_value = isset($form['#token']) ? $form['#token'] : ('comment'. $form["#parameters"][1]['nid'] . $form["#parameters"][1]['pid']);
|
| 65 |
|
| 66 |
drupal_add_js(array(
|
| 67 |
'live' => array(
|
| 68 |
'comment' => array(
|
| 69 |
'uid' => !empty($form['_author']) ? $user->uid : $form['uid']['#value'],
|
| 70 |
'token_value' => $token_value,
|
| 71 |
'module_path' => $path,
|
| 72 |
'element' => variable_get('live_comment_preview_element', 'form#comment-form'),
|
| 73 |
'placement' => variable_get('live_comment_preview_element_method', 'append'),
|
| 74 |
'refresh_delay' => variable_get('live_comment_preview_delay', 1200),
|
| 75 |
),
|
| 76 |
)
|
| 77 |
), 'setting');
|
| 78 |
|
| 79 |
drupal_add_css($path . '/live.css');
|
| 80 |
drupal_add_js($path . '/live.js');
|
| 81 |
drupal_add_js($path . '/comment/live.comment.js');
|
| 82 |
}
|
| 83 |
else if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id
|
| 84 |
&& in_array($form['type']['#value'], variable_get('live_node_preview_types_enabled', array()), TRUE) && user_access('use live node preview')) {
|
| 85 |
$path = drupal_get_path('module', 'live');
|
| 86 |
$token_value = isset($form['#token']) ? $form['#token'] : ($form['type']['#value'] . '_node_form');
|
| 87 |
|
| 88 |
drupal_add_js(array(
|
| 89 |
'live' => array(
|
| 90 |
'node' => array(
|
| 91 |
'node_type' => $form['type']['#value'],
|
| 92 |
'token_value' => $token_value,
|
| 93 |
'module_path' => $path,
|
| 94 |
'element' => variable_get('live_node_preview_element', 'form#node-form'),
|
| 95 |
'placement' => variable_get('live_node_preview_element_method', 'append'),
|
| 96 |
),
|
| 97 |
)
|
| 98 |
), 'setting');
|
| 99 |
|
| 100 |
drupal_add_css($path . '/live.css');
|
| 101 |
drupal_add_js($path . '/live.js');
|
| 102 |
drupal_add_js($path . '/node/live.node.js');
|
| 103 |
}
|
| 104 |
}
|
| 105 |
|
| 106 |
/**
|
| 107 |
* Live Comments settings page.
|
| 108 |
*/
|
| 109 |
function live_settings() {
|
| 110 |
$form = array();
|
| 111 |
|
| 112 |
$form['live_comment_preview'] = array(
|
| 113 |
'#type' => 'fieldset',
|
| 114 |
'#title' => t('Live Comment Preview settings'),
|
| 115 |
'#collapsible' => TRUE,
|
| 116 |
'#collapsed' => FALSE,
|
| 117 |
);
|
| 118 |
|
| 119 |
$form['live_comment_preview']['live_comment_preview_element'] = array(
|
| 120 |
'#type' => 'textfield',
|
| 121 |
'#title' => t('CSS selector to attach comment preview box to'),
|
| 122 |
'#default_value' => variable_get('live_comment_preview_element', 'form#comment-form'),
|
| 123 |
'#description' => t('A valid CSS selector to attach the comment preview box to. <em>Example: body, form#comment-form, div.my-class</em>'),
|
| 124 |
'#required' => TRUE,
|
| 125 |
);
|
| 126 |
|
| 127 |
$form['live_comment_preview']['live_comment_preview_element_method'] = array(
|
| 128 |
'#type' => 'radios',
|
| 129 |
'#title' => t('Attach method'),
|
| 130 |
'#options' => drupal_map_assoc(array('prepend', 'append', 'replace')),
|
| 131 |
'#default_value' => variable_get('live_comment_preview_element_method', 'append'),
|
| 132 |
'#description' => t('Choose how the comment preview box should be attached to the above selector.'),
|
| 133 |
'#required' => TRUE,
|
| 134 |
);
|
| 135 |
|
| 136 |
$form['live_comment_preview']['live_comment_preview_delay'] = array(
|
| 137 |
'#type' => 'textfield',
|
| 138 |
'#title' => t('Threshold delay for refresh'),
|
| 139 |
'#size' => 4,
|
| 140 |
'#default_value' => variable_get('live_comment_preview_delay', 1200),
|
| 141 |
'#description' => t('After how long (in milliseconds) should comment preview update on focus, keyup or blur event.'),
|
| 142 |
);
|
| 143 |
|
| 144 |
$form['live_node_preview'] = array(
|
| 145 |
'#type' => 'fieldset',
|
| 146 |
'#title' => t('Live Node Preview settings'),
|
| 147 |
'#collapsible' => TRUE,
|
| 148 |
'#collapsed' => FALSE,
|
| 149 |
);
|
| 150 |
|
| 151 |
$form['live_node_preview']['live_node_preview_element'] = array(
|
| 152 |
'#type' => 'textfield',
|
| 153 |
'#title' => t('CSS selector to attach node preview box to'),
|
| 154 |
'#default_value' => variable_get('live_node_preview_element', 'form#node-form'),
|
| 155 |
'#description' => t('A valid CSS selector to attach the node preview box to. <em>Example: body, form#node-form, div.my-class</em>'),
|
| 156 |
'#required' => TRUE,
|
| 157 |
);
|
| 158 |
|
| 159 |
$form['live_node_preview']['live_node_preview_element_method'] = array(
|
| 160 |
'#type' => 'radios',
|
| 161 |
'#title' => t('Attach method'),
|
| 162 |
'#options' => drupal_map_assoc(array('prepend', 'append', 'replace')),
|
| 163 |
'#default_value' => variable_get('live_node_preview_element_method', 'append'),
|
| 164 |
'#description' => t('Choose how the node preview box should be attached to the above selector.'),
|
| 165 |
'#required' => TRUE,
|
| 166 |
);
|
| 167 |
|
| 168 |
$form['live_node_preview']['live_node_preview_types_enabled'] = array(
|
| 169 |
'#type' => 'checkboxes',
|
| 170 |
'#title' => t('Node types'),
|
| 171 |
'#description' => t('Select the node types you want to enable live previews for.'),
|
| 172 |
'#default_value' => variable_get('live_node_preview_types_enabled', array()),
|
| 173 |
'#options' => node_get_types('names'),
|
| 174 |
);
|
| 175 |
|
| 176 |
return system_settings_form($form);
|
| 177 |
}
|