| 1 |
<?php
|
| 2 |
// $Id: themesettings.module,v 1.10 2007/06/07 21:02:11 johnalbin Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Customizes the teaser's read more and comments links.
|
| 7 |
*
|
| 8 |
* Admins can change the text and placement of both the "Read more" and
|
| 9 |
* "Comments" links of the teaser. Both theme-specific and content-specific
|
| 10 |
* customization of the settings are possible.
|
| 11 |
*
|
| 12 |
* @author John Albin Wilkins (JohnAlbin) <john at albin dot net>
|
| 13 |
* @link http://www.albin.net
|
| 14 |
*/
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Modify the node to allow customization of read more, comments, etc.
|
| 18 |
*
|
| 19 |
* Implementation of hook_nodepi().
|
| 20 |
*
|
| 21 |
* @param $node
|
| 22 |
* The node the action is being performed on.
|
| 23 |
* @param $op
|
| 24 |
* What kind of action is being performed.
|
| 25 |
* @param $teaser
|
| 26 |
* Whether to display the teaser only, as on the main page.
|
| 27 |
* @param $page
|
| 28 |
* Whether the node is being displayed by itself as a page.
|
| 29 |
* @return
|
| 30 |
* The "load" operation should return an array containing pairs of
|
| 31 |
* fields => values to be merged into the node object. Otherwise, void.
|
| 32 |
*/
|
| 33 |
function themesettings_nodeapi(&$node, $op, $teaser, $page) {
|
| 34 |
switch ($op) {
|
| 35 |
case 'view':
|
| 36 |
// Save this information to be used during link_alter hook.
|
| 37 |
$node->display_teaser = $teaser;
|
| 38 |
break;
|
| 39 |
|
| 40 |
// Append the 'Read more' link to the content
|
| 41 |
case 'rss item':
|
| 42 |
if ($teaser and $node->readmore) {
|
| 43 |
// Turn off read more flag for RSS items.
|
| 44 |
$node->readmore = FALSE;
|
| 45 |
$rss_teaser = TRUE;
|
| 46 |
}
|
| 47 |
// Allow 'rss item' case to continue through 'alter' case.
|
| 48 |
case 'alter':
|
| 49 |
// Get current settings
|
| 50 |
global $theme_key;
|
| 51 |
$settings = _themesettings_get_settings($theme_key);
|
| 52 |
// Determine the node type
|
| 53 |
$readmore_node_type = isset($settings["ts_{$node->type}_readmore"]) ? $node->type : 'default';
|
| 54 |
// Create the link
|
| 55 |
if (isset($rss_teaser) or $teaser and $node->readmore and $settings["ts_{$readmore_node_type}_readmore_placement"] != 'links') {
|
| 56 |
$link = _themesettings_link(
|
| 57 |
$settings["ts_{$readmore_node_type}_readmore_prefix"],
|
| 58 |
$settings["ts_{$readmore_node_type}_readmore_suffix"],
|
| 59 |
$settings["ts_{$readmore_node_type}_readmore"],
|
| 60 |
"node/$node->nid",
|
| 61 |
array('title' => $settings["ts_{$readmore_node_type}_readmore_title"]),
|
| 62 |
NULL,
|
| 63 |
NULL,
|
| 64 |
($op == 'rss item') // Use an absolute link if it's an RSS item.
|
| 65 |
);
|
| 66 |
}
|
| 67 |
else {
|
| 68 |
$link = '';
|
| 69 |
}
|
| 70 |
// Optionally prepend or append the comments links
|
| 71 |
$comment_node_type = isset($settings["ts_{$node->type}_comment_singular"]) ? $node->type : 'default';
|
| 72 |
if ($op != 'rss item' and $teaser and $settings["ts_{$comment_node_type}_comment_teaser_placement"] != 'links') {
|
| 73 |
$all = comment_num_all($node->nid);
|
| 74 |
if ($all) {
|
| 75 |
$comment_link = _themesettings_link(
|
| 76 |
$settings["ts_{$comment_node_type}_comment_prefix"],
|
| 77 |
$settings["ts_{$comment_node_type}_comment_suffix"],
|
| 78 |
format_plural($all,
|
| 79 |
$settings["ts_{$comment_node_type}_comment_singular"],
|
| 80 |
$settings["ts_{$comment_node_type}_comment_plural"]
|
| 81 |
),
|
| 82 |
"node/$node->nid",
|
| 83 |
array('title' => $settings["ts_{$comment_node_type}_comment_title"]),
|
| 84 |
NULL,
|
| 85 |
'comments'
|
| 86 |
);
|
| 87 |
$new = comment_num_new($node->nid);
|
| 88 |
if ($new) {
|
| 89 |
$comment_link .= _themesettings_link(
|
| 90 |
$settings["ts_{$comment_node_type}_comment_new_prefix"],
|
| 91 |
$settings["ts_{$comment_node_type}_comment_new_suffix"],
|
| 92 |
format_plural($new,
|
| 93 |
$settings["ts_{$comment_node_type}_comment_new_singular"],
|
| 94 |
$settings["ts_{$comment_node_type}_comment_new_plural"]
|
| 95 |
),
|
| 96 |
"node/$node->nid",
|
| 97 |
array('title' => $settings["ts_{$comment_node_type}_comment_new_title"]),
|
| 98 |
NULL,
|
| 99 |
'new'
|
| 100 |
);
|
| 101 |
}
|
| 102 |
}
|
| 103 |
elseif (!$settings["ts_{$comment_node_type}_comment_add_disable"]) {
|
| 104 |
$comment_link = _themesettings_link(
|
| 105 |
$settings["ts_{$comment_node_type}_comment_add_prefix"],
|
| 106 |
$settings["ts_{$comment_node_type}_comment_add_suffix"],
|
| 107 |
$settings["ts_{$comment_node_type}_comment_add"],
|
| 108 |
"comment/reply/$node->nid",
|
| 109 |
array('title' => $settings["ts_{$comment_node_type}_comment_add_title"]),
|
| 110 |
NULL,
|
| 111 |
'comment-form'
|
| 112 |
);
|
| 113 |
}
|
| 114 |
if (isset($comment_link)) {
|
| 115 |
if ($settings["ts_{$comment_node_type}_comment_teaser_placement"] == 'prepend') {
|
| 116 |
$link = $comment_link . $link;
|
| 117 |
}
|
| 118 |
else {
|
| 119 |
$link .= $comment_link;
|
| 120 |
}
|
| 121 |
}
|
| 122 |
}
|
| 123 |
|
| 124 |
if ($link) {
|
| 125 |
switch ($settings["ts_{$readmore_node_type}_readmore_placement"]) {
|
| 126 |
// Append to end of last paragraph
|
| 127 |
case 'inline':
|
| 128 |
$original = $node->teaser;
|
| 129 |
// The regex <!--[^>]*--> is not perfect, since <!-- hello>world --> is a valid comment
|
| 130 |
$node->teaser = preg_replace(
|
| 131 |
'~((\s|<!--[^>]*-->|</p>|</div>)+)$~D',
|
| 132 |
' <span class="read-more">' . $link . '</span>$1',
|
| 133 |
$node->teaser);
|
| 134 |
if ($node->teaser != $original) {
|
| 135 |
break;
|
| 136 |
}
|
| 137 |
// Otherwise, we skip a 'break' and fall through to next method
|
| 138 |
// Append separate paragraph
|
| 139 |
case 'append':
|
| 140 |
$node->teaser .= '<p class="read-more">' . $link . '</p>';
|
| 141 |
break;
|
| 142 |
}
|
| 143 |
}
|
| 144 |
break;
|
| 145 |
}
|
| 146 |
}
|
| 147 |
|
| 148 |
/**
|
| 149 |
* Implementation of hook_link_alter().
|
| 150 |
*
|
| 151 |
* @param $node
|
| 152 |
* A node object for editing links on.
|
| 153 |
* @param $links
|
| 154 |
* Nested array of links for the node.
|
| 155 |
* @return
|
| 156 |
* void
|
| 157 |
*/
|
| 158 |
function themesettings_link_alter(&$node, &$links) {
|
| 159 |
|
| 160 |
// Get current settings
|
| 161 |
global $theme_key;
|
| 162 |
$settings = _themesettings_get_settings($theme_key);
|
| 163 |
|
| 164 |
// Determine the node type
|
| 165 |
$readmore_node_type = isset($settings["ts_{$node->type}_readmore"]) ? $node->type : 'default';
|
| 166 |
$comment_node_type = isset($settings["ts_{$node->type}_comment_singular"]) ? $node->type : 'default';
|
| 167 |
|
| 168 |
if ($node->display_teaser and $node->readmore) {
|
| 169 |
// If the Read more link will be added to the content, turn off the Readmore link
|
| 170 |
if ($settings["ts_{$readmore_node_type}_readmore_placement"] != 'links') {
|
| 171 |
unset($links['node_read_more']);
|
| 172 |
}
|
| 173 |
// If the Read more link is present, optionally turn off Comment add link
|
| 174 |
if ($settings["ts_{$comment_node_type}_comment_add_disable"]) {
|
| 175 |
unset($links['comment_add']);
|
| 176 |
}
|
| 177 |
}
|
| 178 |
// If the Comments link will be added to the content (append/prepend to read more), turn off links
|
| 179 |
if ($node->display_teaser and $settings["ts_{$comment_node_type}_comment_teaser_placement"] != 'links') {
|
| 180 |
unset($links['comment_comments']);
|
| 181 |
unset($links['comment_new_comments']);
|
| 182 |
unset($links['comment_add']);
|
| 183 |
}
|
| 184 |
|
| 185 |
// Read more link
|
| 186 |
if (isset($links['node_read_more'])) {
|
| 187 |
$links['node_read_more'] = array(
|
| 188 |
'title' => _themesettings_link(
|
| 189 |
$settings["ts_{$readmore_node_type}_readmore_prefix"],
|
| 190 |
$settings["ts_{$readmore_node_type}_readmore_suffix"],
|
| 191 |
$settings["ts_{$readmore_node_type}_readmore"],
|
| 192 |
"node/$node->nid",
|
| 193 |
array('title' => $settings["ts_{$readmore_node_type}_readmore_title"])
|
| 194 |
),
|
| 195 |
'html' => TRUE,
|
| 196 |
);
|
| 197 |
}
|
| 198 |
|
| 199 |
// Comments link
|
| 200 |
if (isset($links['comment_comments'])) {
|
| 201 |
$all = comment_num_all($node->nid);
|
| 202 |
$links['comment_comments'] = array(
|
| 203 |
'title' => _themesettings_link(
|
| 204 |
$settings["ts_{$comment_node_type}_comment_prefix"],
|
| 205 |
$settings["ts_{$comment_node_type}_comment_suffix"],
|
| 206 |
format_plural($all,
|
| 207 |
$settings["ts_{$comment_node_type}_comment_singular"],
|
| 208 |
$settings["ts_{$comment_node_type}_comment_plural"]
|
| 209 |
),
|
| 210 |
"node/$node->nid",
|
| 211 |
array('title' => $settings["ts_{$comment_node_type}_comment_title"]),
|
| 212 |
NULL,
|
| 213 |
'comments'
|
| 214 |
),
|
| 215 |
'html' => TRUE,
|
| 216 |
);
|
| 217 |
}
|
| 218 |
if (isset($links['comment_new_comments'])) {
|
| 219 |
$new = comment_num_new($node->nid);
|
| 220 |
$links['comment_new_comments'] = array(
|
| 221 |
'title' => _themesettings_link(
|
| 222 |
$settings["ts_{$comment_node_type}_comment_new_prefix"],
|
| 223 |
$settings["ts_{$comment_node_type}_comment_new_suffix"],
|
| 224 |
format_plural($new,
|
| 225 |
$settings["ts_{$comment_node_type}_comment_new_singular"],
|
| 226 |
$settings["ts_{$comment_node_type}_comment_new_plural"]
|
| 227 |
),
|
| 228 |
"node/$node->nid",
|
| 229 |
array('title' => $settings["ts_{$comment_node_type}_comment_new_title"]),
|
| 230 |
NULL,
|
| 231 |
'new'
|
| 232 |
),
|
| 233 |
'html' => TRUE,
|
| 234 |
);
|
| 235 |
}
|
| 236 |
if (isset($links['comment_add'])) {
|
| 237 |
if ($node->display_teaser) {
|
| 238 |
$links['comment_add'] = array(
|
| 239 |
'title' => _themesettings_link(
|
| 240 |
$settings["ts_{$comment_node_type}_comment_add_prefix"],
|
| 241 |
$settings["ts_{$comment_node_type}_comment_add_suffix"],
|
| 242 |
$settings["ts_{$comment_node_type}_comment_add"],
|
| 243 |
"comment/reply/$node->nid",
|
| 244 |
array('title' => $settings["ts_{$comment_node_type}_comment_add_title"]),
|
| 245 |
NULL,
|
| 246 |
'comment-form'
|
| 247 |
),
|
| 248 |
'html' => TRUE,
|
| 249 |
);
|
| 250 |
}
|
| 251 |
else {
|
| 252 |
$links['comment_add'] = array(
|
| 253 |
'title' => _themesettings_link(
|
| 254 |
$settings["ts_{$comment_node_type}_comment_node_prefix"],
|
| 255 |
$settings["ts_{$comment_node_type}_comment_node_suffix"],
|
| 256 |
$settings["ts_{$comment_node_type}_comment_node"],
|
| 257 |
"comment/reply/$node->nid",
|
| 258 |
array('title' => $settings["ts_{$comment_node_type}_comment_node_title"]),
|
| 259 |
NULL,
|
| 260 |
'comment-form'
|
| 261 |
),
|
| 262 |
'html' => TRUE,
|
| 263 |
);
|
| 264 |
}
|
| 265 |
}
|
| 266 |
}
|
| 267 |
|
| 268 |
/**
|
| 269 |
* Adds customization settings to the themes/settings form.
|
| 270 |
*
|
| 271 |
* Implementation of hook_form_alter().
|
| 272 |
*
|
| 273 |
* @param $form_id
|
| 274 |
* The id of the form.
|
| 275 |
* @param $form
|
| 276 |
* An array containing the form elements.
|
| 277 |
* @return
|
| 278 |
* void
|
| 279 |
*/
|
| 280 |
function themesettings_form_alter($form_id, &$form) {
|
| 281 |
|
| 282 |
switch ($form_id) {
|
| 283 |
case 'system_theme_settings':
|
| 284 |
// Grab the default settings first
|
| 285 |
$defaults =& _themesettings_defaults();
|
| 286 |
// Grab the specific theme settings
|
| 287 |
$var = $form['var']['#value'];
|
| 288 |
$settings = _themesettings_get_settings($var);
|
| 289 |
|
| 290 |
// Read more link settings
|
| 291 |
$form['readmore'] = array(
|
| 292 |
'#type' => 'fieldset',
|
| 293 |
'#title' => t('“Read more” link settings'),
|
| 294 |
'#description' => t('Customize the text and placement of the “Read more” link.'),
|
| 295 |
'#collapsible' => TRUE,
|
| 296 |
'#collapsed' => TRUE,
|
| 297 |
);
|
| 298 |
|
| 299 |
// Comments link settings
|
| 300 |
$form['comment'] = array(
|
| 301 |
'#type' => 'fieldset',
|
| 302 |
'#title' => t('“Comment” links settings'),
|
| 303 |
'#description' => t('Customize the text and placement of the “Comment” links.'),
|
| 304 |
'#collapsible' => TRUE,
|
| 305 |
'#collapsed' => TRUE,
|
| 306 |
);
|
| 307 |
|
| 308 |
// Get node-specific settings
|
| 309 |
foreach ((array('default' => 'Default') + node_get_types('names')) AS $type => $name) {
|
| 310 |
// Read more
|
| 311 |
$form['readmore'][$type] = array(
|
| 312 |
'#type' => 'fieldset',
|
| 313 |
'#title' => t('!name settings', array('!name' => t($name))),
|
| 314 |
'#collapsible' => TRUE,
|
| 315 |
'#collapsed' => FALSE,
|
| 316 |
);
|
| 317 |
$form['readmore'][$type]["ts_{$type}_readmore"] = array(
|
| 318 |
'#type' => 'textfield',
|
| 319 |
'#title' => t('Link text'),
|
| 320 |
'#default_value' => $settings["ts_{$type}_readmore"],
|
| 321 |
'#description' => t('HTML is allowed.'),
|
| 322 |
);
|
| 323 |
$form['readmore'][$type]["ts_{$type}_readmore_title"] = array(
|
| 324 |
'#type' => 'textfield',
|
| 325 |
'#title' => t('Title text (tool tip)'),
|
| 326 |
'#default_value' => $settings["ts_{$type}_readmore_title"],
|
| 327 |
'#description' => t('Displayed when hovering over link. Plain text only.'),
|
| 328 |
);
|
| 329 |
$form['readmore'][$type]["ts_{$type}_readmore_prefix"] = array(
|
| 330 |
'#type' => 'textfield',
|
| 331 |
'#title' => t('Prefix'),
|
| 332 |
'#default_value' => $settings["ts_{$type}_readmore_prefix"],
|
| 333 |
'#description' => t('Text or HTML placed before the link.'),
|
| 334 |
);
|
| 335 |
$form['readmore'][$type]["ts_{$type}_readmore_suffix"] = array(
|
| 336 |
'#type' => 'textfield',
|
| 337 |
'#title' => t('Suffix'),
|
| 338 |
'#default_value' => $settings["ts_{$type}_readmore_suffix"],
|
| 339 |
'#description' => t('Text or HTML placed after the link.'),
|
| 340 |
);
|
| 341 |
$form['readmore'][$type]["ts_{$type}_readmore_placement"] = array(
|
| 342 |
'#type' => 'radios',
|
| 343 |
'#title' => t('Link placement'),
|
| 344 |
'#default_value' => $settings["ts_{$type}_readmore_placement"],
|
| 345 |
'#options' => array(
|
| 346 |
'links' => t('Add to the links (default)'),
|
| 347 |
'append' => t('Add a paragraph to the teaser'),
|
| 348 |
'inline' => t('Add a sentence to the last paragraph of the teaser'),
|
| 349 |
),
|
| 350 |
);
|
| 351 |
// Comment
|
| 352 |
$form['comment'][$type] = array(
|
| 353 |
'#type' => 'fieldset',
|
| 354 |
'#title' => t('!name settings', array('!name' => t($name))),
|
| 355 |
'#collapsible' => TRUE,
|
| 356 |
'#collapsed' => FALSE,
|
| 357 |
);
|
| 358 |
$form['comment'][$type]['teaser'] = array(
|
| 359 |
'#type' => 'fieldset',
|
| 360 |
'#title' => t('Links when displaying teaser'),
|
| 361 |
'#collapsible' => TRUE,
|
| 362 |
'#collapsed' => FALSE,
|
| 363 |
);
|
| 364 |
$form['comment'][$type]['teaser']['add'] = array(
|
| 365 |
'#type' => 'fieldset',
|
| 366 |
'#title' => t('“Add new comment” link'),
|
| 367 |
'#description' => t('The link when there are no comments.'),
|
| 368 |
'#collapsible' => TRUE,
|
| 369 |
'#collapsed' => TRUE,
|
| 370 |
);
|
| 371 |
$form['comment'][$type]['teaser']['add']["ts_{$type}_comment_add"] = array(
|
| 372 |
'#type' => 'textfield',
|
| 373 |
'#title' => t('Link text'),
|
| 374 |
'#default_value' => $settings["ts_{$type}_comment_add"],
|
| 375 |
'#description' => t('HTML is allowed.'),
|
| 376 |
);
|
| 377 |
$form['comment'][$type]['teaser']['add']["ts_{$type}_comment_add_title"] = array(
|
| 378 |
'#type' => 'textfield',
|
| 379 |
'#title' => t('Title text (tool tip)'),
|
| 380 |
'#default_value' => $settings["ts_{$type}_comment_add_title"],
|
| 381 |
'#description' => t('Displayed when hovering over link. Plain text only.'),
|
| 382 |
);
|
| 383 |
$form['comment'][$type]['teaser']['add']['extra'] = array(
|
| 384 |
'#type' => 'fieldset',
|
| 385 |
'#title' => t('Options'),
|
| 386 |
'#collapsible' => TRUE,
|
| 387 |
'#collapsed' => TRUE,
|
| 388 |
);
|
| 389 |
$form['comment'][$type]['teaser']['add']['extra']["ts_{$type}_comment_add_prefix"] = array(
|
| 390 |
'#type' => 'textfield',
|
| 391 |
'#title' => t('Prefix'),
|
| 392 |
'#default_value' => $settings["ts_{$type}_comment_add_prefix"],
|
| 393 |
'#description' => t('Text or HTML placed before the link.'),
|
| 394 |
);
|
| 395 |
$form['comment'][$type]['teaser']['add']['extra']["ts_{$type}_comment_add_suffix"] = array(
|
| 396 |
'#type' => 'textfield',
|
| 397 |
'#title' => t('Suffix'),
|
| 398 |
'#default_value' => $settings["ts_{$type}_comment_add_suffix"],
|
| 399 |
'#description' => t('Text or HTML placed after the link.'),
|
| 400 |
);
|
| 401 |
$form['comment'][$type]['teaser']['add']['extra']["ts_{$type}_comment_add_disable"] = array(
|
| 402 |
'#type' => 'checkbox',
|
| 403 |
'#title' => t('Don’t show this link when “Read more” is present'),
|
| 404 |
'#default_value' => $settings["ts_{$type}_comment_add_disable"],
|
| 405 |
);
|
| 406 |
$form['comment'][$type]['teaser']['standard'] = array(
|
| 407 |
'#type' => 'fieldset',
|
| 408 |
'#title' => t('“Comments” link'),
|
| 409 |
'#description' => t('The link when there are one or more comments.'),
|
| 410 |
'#collapsible' => TRUE,
|
| 411 |
'#collapsed' => TRUE,
|
| 412 |
);
|
| 413 |
$form['comment'][$type]['teaser']['standard']["ts_{$type}_comment_singular"] = array(
|
| 414 |
'#type' => 'textfield',
|
| 415 |
'#title' => t('Link text when there is 1 comment'),
|
| 416 |
'#default_value' => $settings["ts_{$type}_comment_singular"],
|
| 417 |
'#description' => t('HTML is allowed.'),
|
| 418 |
);
|
| 419 |
$form['comment'][$type]['teaser']['standard']["ts_{$type}_comment_plural"] = array(
|
| 420 |
'#type' => 'textfield',
|
| 421 |
'#title' => t('Link text when there are multiple comments'),
|
| 422 |
'#default_value' => $settings["ts_{$type}_comment_plural"],
|
| 423 |
'#description' => t('HTML is allowed. @count will be replaced with the number of comments.'),
|
| 424 |
);
|
| 425 |
$form['comment'][$type]['teaser']['standard']["ts_{$type}_comment_title"] = array(
|
| 426 |
'#type' => 'textfield',
|
| 427 |
'#title' => t('Title text (tool tip)'),
|
| 428 |
'#default_value' => $settings["ts_{$type}_comment_title"],
|
| 429 |
'#description' => t('Displayed when hovering over link. Plain text only.'),
|
| 430 |
);
|
| 431 |
$form['comment'][$type]['teaser']['standard']['extra'] = array(
|
| 432 |
'#type' => 'fieldset',
|
| 433 |
'#title' => t('Options'),
|
| 434 |
'#collapsible' => TRUE,
|
| 435 |
'#collapsed' => TRUE,
|
| 436 |
);
|
| 437 |
$form['comment'][$type]['teaser']['standard']['extra']["ts_{$type}_comment_prefix"] = array(
|
| 438 |
'#type' => 'textfield',
|
| 439 |
'#title' => t('Prefix'),
|
| 440 |
'#default_value' => $settings["ts_{$type}_comment_prefix"],
|
| 441 |
'#description' => t('Text or HTML placed before the link.'),
|
| 442 |
);
|
| 443 |
$form['comment'][$type]['teaser']['standard']['extra']["ts_{$type}_comment_suffix"] = array(
|
| 444 |
'#type' => 'textfield',
|
| 445 |
'#title' => t('Suffix'),
|
| 446 |
'#default_value' => $settings["ts_{$type}_comment_suffix"],
|
| 447 |
'#description' => t('Text or HTML placed after the link.'),
|
| 448 |
);
|
| 449 |
$form['comment'][$type]['teaser']['new'] = array(
|
| 450 |
'#type' => 'fieldset',
|
| 451 |
'#title' => t('“New comments” link'),
|
| 452 |
'#description' => t('The link when there are one or more new comments.'),
|
| 453 |
'#collapsible' => TRUE,
|
| 454 |
'#collapsed' => TRUE,
|
| 455 |
);
|
| 456 |
$form['comment'][$type]['teaser']['new']["ts_{$type}_comment_new_singular"] = array(
|
| 457 |
'#type' => 'textfield',
|
| 458 |
'#title' => t('Link text when there is 1 new comment'),
|
| 459 |
'#default_value' => $settings["ts_{$type}_comment_new_singular"],
|
| 460 |
'#description' => t('HTML is allowed.'),
|
| 461 |
);
|
| 462 |
$form['comment'][$type]['teaser']['new']["ts_{$type}_comment_new_plural"] = array(
|
| 463 |
'#type' => 'textfield',
|
| 464 |
'#title' => t('Link text when there are multiple new comments'),
|
| 465 |
'#default_value' => $settings["ts_{$type}_comment_new_plural"],
|
| 466 |
'#description' => t('HTML is allowed. @count will be replaced with the number of comments.'),
|
| 467 |
);
|
| 468 |
$form['comment'][$type]['teaser']['new']["ts_{$type}_comment_new_title"] = array(
|
| 469 |
'#type' => 'textfield',
|
| 470 |
'#title' => t('Title text (tool tip)'),
|
| 471 |
'#default_value' => $settings["ts_{$type}_comment_new_title"],
|
| 472 |
'#description' => t('Displayed when hovering over link. Plain text only.'),
|
| 473 |
);
|
| 474 |
$form['comment'][$type]['teaser']['new']['extra'] = array(
|
| 475 |
'#type' => 'fieldset',
|
| 476 |
'#title' => t('Options'),
|
| 477 |
'#collapsible' => TRUE,
|
| 478 |
'#collapsed' => TRUE,
|
| 479 |
);
|
| 480 |
$form['comment'][$type]['teaser']['new']['extra']["ts_{$type}_comment_new_prefix"] = array(
|
| 481 |
'#type' => 'textfield',
|
| 482 |
'#title' => t('Prefix'),
|
| 483 |
'#default_value' => $settings["ts_{$type}_comment_new_prefix"],
|
| 484 |
'#description' => t('Text or HTML placed before the link.'),
|
| 485 |
);
|
| 486 |
$form['comment'][$type]['teaser']['new']['extra']["ts_{$type}_comment_new_suffix"] = array(
|
| 487 |
'#type' => 'textfield',
|
| 488 |
'#title' => t('Suffix'),
|
| 489 |
'#default_value' => $settings["ts_{$type}_comment_new_suffix"],
|
| 490 |
'#description' => t('Text or HTML placed after the link.'),
|
| 491 |
);
|
| 492 |
$form['comment'][$type]['teaser']["ts_{$type}_comment_teaser_placement"] = array(
|
| 493 |
'#type' => 'radios',
|
| 494 |
'#title' => t('Link placement'),
|
| 495 |
'#default_value' => $settings["ts_{$type}_comment_teaser_placement"],
|
| 496 |
'#options' => array(
|
| 497 |
'links' => t('Add to the links (default)'),
|
| 498 |
'prepend' => t('Prepend to “Read more” link'),
|
| 499 |
'append' => t('Append to “Read more” link'),
|
| 500 |
),
|
| 501 |
);
|
| 502 |
$form['comment'][$type]['node'] = array(
|
| 503 |
'#type' => 'fieldset',
|
| 504 |
'#title' => t('Links when displaying full content'),
|
| 505 |
'#collapsible' => TRUE,
|
| 506 |
'#collapsed' => FALSE,
|
| 507 |
);
|
| 508 |
$form['comment'][$type]['node']['add'] = array(
|
| 509 |
'#type' => 'fieldset',
|
| 510 |
'#title' => t('“Add new comment” link'),
|
| 511 |
'#description' => t('The link when the full content is being displayed.'),
|
| 512 |
'#collapsible' => TRUE,
|
| 513 |
'#collapsed' => TRUE,
|
| 514 |
);
|
| 515 |
$form['comment'][$type]['node']['add']["ts_{$type}_comment_node"] = array(
|
| 516 |
'#type' => 'textfield',
|
| 517 |
'#title' => t('Link text'),
|
| 518 |
'#default_value' => $settings["ts_{$type}_comment_node"],
|
| 519 |
'#description' => t('HTML is allowed.'),
|
| 520 |
);
|
| 521 |
$form['comment'][$type]['node']['add']["ts_{$type}_comment_node_title"] = array(
|
| 522 |
'#type' => 'textfield',
|
| 523 |
'#title' => t('Title text (tool tip)'),
|
| 524 |
'#default_value' => $settings["ts_{$type}_comment_node_title"],
|
| 525 |
'#description' => t('Displayed when hovering over link. Plain text only.'),
|
| 526 |
);
|
| 527 |
$form['comment'][$type]['node']['add']['extra'] = array(
|
| 528 |
'#type' => 'fieldset',
|
| 529 |
'#title' => t('Options'),
|
| 530 |
'#collapsible' => TRUE,
|
| 531 |
'#collapsed' => TRUE,
|
| 532 |
);
|
| 533 |
$form['comment'][$type]['node']['add']['extra']["ts_{$type}_comment_node_prefix"] = array(
|
| 534 |
'#type' => 'textfield',
|
| 535 |
'#title' => t('Prefix'),
|
| 536 |
'#default_value' => $settings["ts_{$type}_comment_node_prefix"],
|
| 537 |
'#description' => t('Text or HTML placed before the link.'),
|
| 538 |
);
|
| 539 |
$form['comment'][$type]['node']['add']['extra']["ts_{$type}_comment_node_suffix"] = array(
|
| 540 |
'#type' => 'textfield',
|
| 541 |
'#title' => t('Suffix'),
|
| 542 |
'#default_value' => $settings["ts_{$type}_comment_node_suffix"],
|
| 543 |
'#description' => t('Text or HTML placed after the link.'),
|
| 544 |
);
|
| 545 |
|
| 546 |
// Special options for default settings
|
| 547 |
if ($type == 'default') {
|
| 548 |
$form['readmore']['default']['#title'] = t('Default settings for any content type');
|
| 549 |
$form['readmore']['default']['#collapsed'] = $settings['ts_readmore_enable_content_type'] ? TRUE : FALSE;
|
| 550 |
$form['readmore']['ts_readmore_enable_content_type'] = array(
|
| 551 |
'#type' => 'checkbox',
|
| 552 |
'#title' => t('Enable separate settings for each content type'),
|
| 553 |
'#default_value' => $settings['ts_readmore_enable_content_type'],
|
| 554 |
);
|
| 555 |
/* $form['readmore']['ts_reamore_content_types'] = array(
|
| 556 |
'#value' => '<div id="themesettings-content-types">'
|
| 557 |
); */
|
| 558 |
$form['comment']['default']['#title'] = t('Default settings for any content type');
|
| 559 |
$form['comment']['default']['#collapsed'] = $settings['ts_comment_enable_content_type'] ? TRUE : FALSE;
|
| 560 |
$form['comment']['ts_comment_enable_content_type'] = array(
|
| 561 |
'#type' => 'checkbox',
|
| 562 |
'#title' => t('Enable separate settings for each content type'),
|
| 563 |
'#default_value' => $settings['ts_comment_enable_content_type'],
|
| 564 |
);
|
| 565 |
}
|
| 566 |
// Collapse if default settings are used
|
| 567 |
else {
|
| 568 |
if (!$settings['ts_readmore_enable_content_type'] or // remove the or clause if we add jquery hiding
|
| 569 |
$settings["ts_{$type}_readmore"] == $defaults["ts_default_readmore"] and
|
| 570 |
$settings["ts_{$type}_readmore_title"] == $defaults["ts_default_readmore_title"] and
|
| 571 |
$settings["ts_{$type}_readmore_prefix"] == $defaults["ts_default_readmore_prefix"] and
|
| 572 |
$settings["ts_{$type}_readmore_suffix"] == $defaults["ts_default_readmore_suffix"] and
|
| 573 |
$settings["ts_{$type}_readmore_placement"] == $defaults['ts_default_readmore_placement']
|
| 574 |
)
|
| 575 |
{
|
| 576 |
$form['readmore'][$type]['#collapsed'] = TRUE;
|
| 577 |
}
|
| 578 |
if (!$settings['ts_comment_enable_content_type'])
|
| 579 |
{
|
| 580 |
$form['comment'][$type]['#collapsed'] = TRUE;
|
| 581 |
}
|
| 582 |
}
|
| 583 |
}
|
| 584 |
/* $form['readmore']['ts_reamore_content_types_end'] = array(
|
| 585 |
'#value' => '</div><!-- /#themesettings-content-types -->'
|
| 586 |
); */
|
| 587 |
|
| 588 |
break;
|
| 589 |
}
|
| 590 |
}
|
| 591 |
|
| 592 |
/**
|
| 593 |
* Implementation of hook_node_type().
|
| 594 |
*
|
| 595 |
* Updates theme settings after a node type change.
|
| 596 |
*/
|
| 597 |
/*
|
| 598 |
function themesettings_node_type($op, $info) {
|
| 599 |
if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) {
|
| 600 |
$old = 'toggle_node_info_'. $info->old_type;
|
| 601 |
$new = 'toggle_node_info_'. $info->type;
|
| 602 |
|
| 603 |
$theme_settings = variable_get('theme_settings', array());
|
| 604 |
if (isset($theme_settings[$old])) {
|
| 605 |
$theme_settings[$new] = $theme_settings[$old];
|
| 606 |
unset($theme_settings[$old]);
|
| 607 |
variable_set('theme_settings', $theme_settings);
|
| 608 |
}
|
| 609 |
}
|
| 610 |
}
|
| 611 |
*/
|
| 612 |
|
| 613 |
/**
|
| 614 |
* Retrieves the basic theme settings defaults.
|
| 615 |
*
|
| 616 |
* @return
|
| 617 |
* An array of default settings.
|
| 618 |
*/
|
| 619 |
function &_themesettings_defaults_basic() {
|
| 620 |
$defaults = array(
|
| 621 |
'ts_readmore_enable_content_type' => 0,
|
| 622 |
'ts_default_readmore' => t('Read more'),
|
| 623 |
'ts_default_readmore_title' => t('Read the rest of this posting.'),
|
| 624 |
'ts_default_readmore_prefix' => '',
|
| 625 |
'ts_default_readmore_suffix' => '',
|
| 626 |
'ts_default_readmore_placement' => 'links',
|
| 627 |
'ts_comment_enable_content_type' => 0,
|
| 628 |
'ts_default_comment_singular' => t('1 comment'),
|
| 629 |
'ts_default_comment_plural' => t('@count comments'),
|
| 630 |
'ts_default_comment_title' => t('Jump to the first comment of this posting.'),
|
| 631 |
'ts_default_comment_prefix' => '',
|
| 632 |
'ts_default_comment_suffix' => '',
|
| 633 |
'ts_default_comment_new_singular' => t('1 new comment'),
|
| 634 |
'ts_default_comment_new_plural' => t('@count new comments'),
|
| 635 |
'ts_default_comment_new_title' => t('Jump to the first new comment of this posting.'),
|
| 636 |
'ts_default_comment_new_prefix' => '',
|
| 637 |
'ts_default_comment_new_suffix' => '',
|
| 638 |
'ts_default_comment_add' => t('Add new comment'),
|
| 639 |
'ts_default_comment_add_title' => t('Add a new comment to this page.'),
|
| 640 |
'ts_default_comment_add_prefix' => '',
|
| 641 |
'ts_default_comment_add_suffix' => '',
|
| 642 |
'ts_default_comment_add_disable' => 0,
|
| 643 |
'ts_default_comment_teaser_placement' => 'links',
|
| 644 |
'ts_default_comment_node' => t('Add new comment'),
|
| 645 |
'ts_default_comment_node_title' => t('Share your thoughts and opinions related to this posting.'),
|
| 646 |
'ts_default_comment_node_prefix' => '',
|
| 647 |
'ts_default_comment_node_suffix' => '',
|
| 648 |
);
|
| 649 |
return $defaults;
|
| 650 |
}
|
| 651 |
|
| 652 |
/**
|
| 653 |
* Retrieves the full theme settings defaults, including node-type-specific ones.
|
| 654 |
*
|
| 655 |
* @return
|
| 656 |
* An array of default settings.
|
| 657 |
*/
|
| 658 |
function &_themesettings_defaults() {
|
| 659 |
|
| 660 |
$defaults =& _themesettings_defaults_basic();
|
| 661 |
|
| 662 |
// Make the content-type defaults the same as the default theme settings,
|
| 663 |
// so we can tell if content-type-specific settings have been altered.
|
| 664 |
$defaults = array_merge($defaults, variable_get('theme_settings', array()));
|
| 665 |
|
| 666 |
// Set the content-type-specific defaults
|
| 667 |
foreach (node_get_types('names') AS $type => $name) {
|
| 668 |
$defaults["ts_{$type}_readmore"] = $defaults['ts_default_readmore'];
|
| 669 |
$defaults["ts_{$type}_readmore_title"] = $defaults['ts_default_readmore_title'];
|
| 670 |
$defaults["ts_{$type}_readmore_prefix"] = $defaults['ts_default_readmore_prefix'];
|
| 671 |
$defaults["ts_{$type}_readmore_suffix"] = $defaults['ts_default_readmore_suffix'];
|
| 672 |
$defaults["ts_{$type}_readmore_placement"] = $defaults['ts_default_readmore_placement'];
|
| 673 |
|
| 674 |
$defaults["ts_{$type}_comment_singular"] = $defaults['ts_default_comment_singular'];
|
| 675 |
$defaults["ts_{$type}_comment_plural"] = $defaults['ts_default_comment_plural'];
|
| 676 |
$defaults["ts_{$type}_comment_title"] = $defaults['ts_default_comment_title'];
|
| 677 |
$defaults["ts_{$type}_comment_prefix"] = $defaults['ts_default_comment_prefix'];
|
| 678 |
$defaults["ts_{$type}_comment_suffix"] = $defaults['ts_default_comment_suffix'];
|
| 679 |
$defaults["ts_{$type}_comment_new_singular"] = $defaults['ts_default_comment_new_singular'];
|
| 680 |
$defaults["ts_{$type}_comment_new_plural"] = $defaults['ts_default_comment_new_plural'];
|
| 681 |
$defaults["ts_{$type}_comment_new_title"] = $defaults['ts_default_comment_new_title'];
|
| 682 |
$defaults["ts_{$type}_comment_new_prefix"] = $defaults['ts_default_comment_new_prefix'];
|
| 683 |
$defaults["ts_{$type}_comment_new_suffix"] = $defaults['ts_default_comment_new_suffix'];
|
| 684 |
$defaults["ts_{$type}_comment_add"] = $defaults['ts_default_comment_add'];
|
| 685 |
$defaults["ts_{$type}_comment_add_title"] = $defaults['ts_default_comment_add_title'];
|
| 686 |
$defaults["ts_{$type}_comment_add_prefix"] = $defaults['ts_default_comment_add_prefix'];
|
| 687 |
$defaults["ts_{$type}_comment_add_suffix"] = $defaults['ts_default_comment_add_suffix'];
|
| 688 |
$defaults["ts_{$type}_comment_add_disable"] = $defaults['ts_default_comment_add_disable'];
|
| 689 |
$defaults["ts_{$type}_comment_teaser_placement"] = $defaults['ts_default_comment_teaser_placement'];
|
| 690 |
$defaults["ts_{$type}_comment_node"] = $defaults['ts_default_comment_node'];
|
| 691 |
$defaults["ts_{$type}_comment_node_title"] = $defaults['ts_default_comment_node_title'];
|
| 692 |
$defaults["ts_{$type}_comment_node_prefix"] = $defaults['ts_default_comment_node_prefix'];
|
| 693 |
$defaults["ts_{$type}_comment_node_suffix"] = $defaults['ts_default_comment_node_suffix'];
|
| 694 |
}
|
| 695 |
return $defaults;
|
| 696 |
}
|
| 697 |
|
| 698 |
/**
|
| 699 |
* Retrieves the specified theme settings variable
|
| 700 |
*
|
| 701 |
* @param $var
|
| 702 |
* The theme key where the settings have been saved.
|
| 703 |
* @return
|
| 704 |
* An array of settings.
|
| 705 |
*/
|
| 706 |
function _themesettings_get_settings($var) {
|
| 707 |
static $theme_settings = FALSE;
|
| 708 |
global $theme_key;
|
| 709 |
|
| 710 |
// Return the current theme's settings if we already know them
|
| 711 |
if ($var == $theme_key and $theme_settings) {
|
| 712 |
return $theme_settings;
|
| 713 |
}
|
| 714 |
|
| 715 |
// Get the default-content-type settings
|
| 716 |
$settings =& _themesettings_defaults_basic();
|
| 717 |
|
| 718 |
// Get the theme-specific settings
|
| 719 |
$settings = array_merge($settings, variable_get('theme_settings', array()));
|
| 720 |
if ($var != 'theme_settings') {
|
| 721 |
$settings = array_merge($settings, variable_get(str_replace('/', '_', 'theme_'. $var .'_settings'), array()));
|
| 722 |
}
|
| 723 |
|
| 724 |
// Save the current theme's settings
|
| 725 |
if ($var == $theme_key) {
|
| 726 |
$theme_settings = $settings;
|
| 727 |
}
|
| 728 |
|
| 729 |
return $settings;
|
| 730 |
}
|
| 731 |
|
| 732 |
/**
|
| 733 |
* Creates a link with prefix and suffix text
|
| 734 |
*
|
| 735 |
* @param $prefix
|
| 736 |
* The text to prefix the link.
|
| 737 |
* @param $suffix
|
| 738 |
* The text to suffix the link.
|
| 739 |
* @param $text
|
| 740 |
* The text to be enclosed with the anchor tag.
|
| 741 |
* @param $path
|
| 742 |
* The Drupal path being linked to, such as "admin/content/node". Can be an external
|
| 743 |
* or internal URL.
|
| 744 |
* - If you provide the full URL, it will be considered an
|
| 745 |
* external URL.
|
| 746 |
* - If you provide only the path (e.g. "admin/content/node"), it is considered an
|
| 747 |
* internal link. In this case, it must be a system URL as the url() function
|
| 748 |
* will generate the alias.
|
| 749 |
* @param $attributes
|
| 750 |
* An associative array of HTML attributes to apply to the anchor tag.
|
| 751 |
* @param $query
|
| 752 |
* A query string to append to the link.
|
| 753 |
* @param $fragment
|
| 754 |
* A fragment identifier (named anchor) to append to the link.
|
| 755 |
* @param $absolute
|
| 756 |
* Whether to force the output to be an absolute link (beginning with http:).
|
| 757 |
* Useful for links that will be displayed outside the site, such as in an RSS
|
| 758 |
* feed.
|
| 759 |
* @return
|
| 760 |
* an HTML string containing a link to the given path.
|
| 761 |
*/
|
| 762 |
function _themesettings_link($prefix, $suffix, $text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE) {
|
| 763 |
return $prefix
|
| 764 |
. ($text
|
| 765 |
? l($text,
|
| 766 |
$path,
|
| 767 |
$attributes,
|
| 768 |
$query,
|
| 769 |
$fragment,
|
| 770 |
$absolute,
|
| 771 |
TRUE // Allow HTML.
|
| 772 |
)
|
| 773 |
: ''
|
| 774 |
)
|
| 775 |
. $suffix;
|
| 776 |
}
|