| 1 |
<?php |
<?php |
| 2 |
function k2_regions() { |
|
| 3 |
return array( |
// Don't display empty help from node_help(). |
| 4 |
'right' => t('right sidebar'), |
if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") { |
| 5 |
'content' => t('content'), |
$vars['help'] = ''; |
| 6 |
'footer' => t('footer') |
} |
| 7 |
); |
|
| 8 |
} |
// Classes for body element. Allows advanced theming based on context |
| 9 |
|
// (home page, node of certain type, etc.) |
| 10 |
|
$body_classes = array($vars['body_classes']); |
| 11 |
|
if (!$vars['is_front']) { |
| 12 |
|
// Add unique classes for each page and website section |
| 13 |
|
$path = drupal_get_path_alias($_GET['q']); |
| 14 |
|
list($section, ) = explode('/', $path, 2); |
| 15 |
|
$body_classes[] = k2_id_safe('page-' . $path); |
| 16 |
|
$body_classes[] = k2_id_safe('section-' . $section); |
| 17 |
|
if (arg(0) == 'node') { |
| 18 |
|
if (arg(1) == 'add') { |
| 19 |
|
if ($section == 'node') { |
| 20 |
|
array_pop($body_classes); // Remove 'section-node' |
| 21 |
|
} |
| 22 |
|
$body_classes[] = 'section-node-add'; // Add 'section-node-add' |
| 23 |
|
} |
| 24 |
|
elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { |
| 25 |
|
if ($section == 'node') { |
| 26 |
|
array_pop($body_classes); // Remove 'section-node' |
| 27 |
|
} |
| 28 |
|
$body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete' |
| 29 |
|
} |
| 30 |
|
} |
| 31 |
|
} |
| 32 |
|
$vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces |
| 33 |
|
|
| 34 |
/** |
/** |
| 35 |
* Sets the body-tag class attribute. |
* Converts a string to a suitable html ID attribute. |
| 36 |
|
* |
| 37 |
|
* http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a |
| 38 |
|
* valid ID attribute in HTML. This function: |
| 39 |
|
* |
| 40 |
|
* - Ensure an ID starts with an alpha character by optionally adding an 'n'. |
| 41 |
|
* - Replaces any character except A-Z, numbers, and underscores with dashes. |
| 42 |
|
* - Converts entire string to lowercase. |
| 43 |
* |
* |
| 44 |
* Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed. |
* @param $string |
| 45 |
|
* The string |
| 46 |
|
* @return |
| 47 |
|
* The converted string |
| 48 |
*/ |
*/ |
| 49 |
function phptemplate_body_class($sidebar_right) { |
function k2_id_safe($string) { |
| 50 |
if ($sidebar_right != '') { |
// Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores. |
| 51 |
$class = 'sidebar-right'; |
$string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string)); |
| 52 |
} |
// If the first character is not a-z, add 'n' in front. |
| 53 |
|
if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware. |
| 54 |
if (isset($class)) { |
$string = 'id' . $string; |
|
print ' class="'. $class .'"'; |
|
| 55 |
} |
} |
| 56 |
|
return $string; |
| 57 |
} |
} |
| 58 |
|
|
| 59 |
/** |
/** |
| 60 |
* Allow themable wrapping of all comments. |
* Allow themable wrapping of all comments. |
| 61 |
*/ |
*/ |
| 62 |
function phptemplate_comment_wrapper($content, $type = null) { |
function k2_comment_wrapper($content, $type = null) { |
| 63 |
static $node_type; |
static $node_type; |
| 64 |
if (isset($type)) $node_type = $type; |
if (isset($type)) $node_type = $type; |
| 65 |
|
|
| 66 |
if (!$content || $node_type == 'forum') { |
if (!$content || $node_type == 'forum') { |
| 67 |
return '<div id="comments">'. $content . '</div>'; |
return '<span id="comments">'. $content . '</span>'; |
| 68 |
|
} |
| 69 |
|
else { |
| 70 |
|
return '<h4><span id="comments"></span>'. t('Comments') .'</h4><ol id="commentlist">'. $content .'</ol>'; |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
/** |
| 75 |
|
* Override or insert PHPTemplate variables into the comment templates. |
| 76 |
|
* |
| 77 |
|
* @param $vars |
| 78 |
|
* A sequential array of variables to pass to the theme template. |
| 79 |
|
* @param $hook |
| 80 |
|
* The name of the theme function being called ("comment" in this case.) |
| 81 |
|
*/ |
| 82 |
|
function k2_preprocess_comment(&$vars, $hook) { |
| 83 |
|
global $user; |
| 84 |
|
|
| 85 |
|
// We load the node object that the current comment is attached to |
| 86 |
|
$node = node_load($vars['comment']->nid); |
| 87 |
|
// If the author of this comment is equal to the author of the node, we |
| 88 |
|
// set a variable so we can theme this comment uniquely. |
| 89 |
|
$vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE; |
| 90 |
|
|
| 91 |
|
$comment_classes = array(); |
| 92 |
|
|
| 93 |
|
// Odd/even handling |
| 94 |
|
static $comment_odd = TRUE; |
| 95 |
|
$comment_classes[] = $comment_odd ? 'odd' : 'even'; |
| 96 |
|
$comment_odd = !$comment_odd; |
| 97 |
|
|
| 98 |
|
if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) { |
| 99 |
|
$comment_classes[] = 'comment-unpublished'; |
| 100 |
|
$vars['unpublished'] = TRUE; |
| 101 |
} |
} |
| 102 |
else { |
else { |
| 103 |
return '<div id="comments"><h3 class="comments">'. t('Comments') .'</h3>'. $content .'</div>'; |
$vars['unpublished'] = FALSE; |
| 104 |
|
} |
| 105 |
|
if ($vars['author_comment']) { |
| 106 |
|
// Comment is by the node author |
| 107 |
|
$comment_classes[] = 'bypostauthor'; |
| 108 |
|
} |
| 109 |
|
if ($vars['comment']->uid == 0) { |
| 110 |
|
// Comment is by an anonymous user |
| 111 |
|
$comment_classes[] = 'comment-by-anon'; |
| 112 |
|
} |
| 113 |
|
if ($user->uid && $vars['comment']->uid == $user->uid) { |
| 114 |
|
// Comment was posted by current user |
| 115 |
|
$comment_classes[] = 'comment-mine'; |
| 116 |
|
} |
| 117 |
|
$vars['comment_classes'] = implode(' ', $comment_classes); |
| 118 |
|
|
| 119 |
|
// If comment subjects are disabled, don't display 'em |
| 120 |
|
if (variable_get('comment_subject_field', 1) == 0) { |
| 121 |
|
$vars['title'] = ''; |
| 122 |
} |
} |
| 123 |
} |
} |
| 124 |
|
|