| 1 |
<?php
|
| 2 |
/* $Id: template.php,v 1.3 2006/06/23 21:22:50 rkerr Exp $ */
|
| 3 |
|
| 4 |
// custom navigation links
|
| 5 |
function mollio_nav($parent, $items = array(), $main_class = '') {
|
| 6 |
$i = 0;
|
| 7 |
$class = '';
|
| 8 |
$wrapper_prefix = '<li>';
|
| 9 |
$wrapper_suffix = '</li>';
|
| 10 |
$output = '';
|
| 11 |
|
| 12 |
if (count($items) > 0) {
|
| 13 |
$output .= "<ul>";
|
| 14 |
foreach ($items as $item) {
|
| 15 |
$class = '';
|
| 16 |
if ($i == 0) {
|
| 17 |
$class = 'first';
|
| 18 |
}
|
| 19 |
elseif ($i == count($items) - 1) {
|
| 20 |
$class = 'last';
|
| 21 |
}
|
| 22 |
|
| 23 |
if (strstr($item, 'class="active"') !== FALSE) {
|
| 24 |
$class .= ($class ? ' ' : '') . 'active';
|
| 25 |
$main_class .= ($main_class != '' ? ' ' : '') . 'active';
|
| 26 |
$parent = str_replace('<a href=', '<a class="active" href=', $parent);
|
| 27 |
}
|
| 28 |
|
| 29 |
$class = ' class="' . $class . '"';
|
| 30 |
$output .= '<li' . $class . '>' . $item . '</li>';
|
| 31 |
$i++;
|
| 32 |
}
|
| 33 |
$output .= "</ul>";
|
| 34 |
}
|
| 35 |
else {
|
| 36 |
if (strstr($parent, 'class="active"') !== FALSE) {
|
| 37 |
$main_class .= ($main_class != '' ? ' ' : '') . 'active';
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
$wrapper_prefix = '<li class="' . $main_class . '">';
|
| 42 |
$output = $wrapper_prefix . $parent . $output . $wrapper_postfix;
|
| 43 |
return $output;
|
| 44 |
}
|
| 45 |
|
| 46 |
// custom implementation of theme_list
|
| 47 |
function mollio_list($items, $type = 'ul') {
|
| 48 |
$i = 0;
|
| 49 |
$class = '';
|
| 50 |
$output = '';
|
| 51 |
$type = strtolower($type);
|
| 52 |
if ($type != 'ol' && $type != 'dl') {
|
| 53 |
$type = 'ul';
|
| 54 |
}
|
| 55 |
$output .= "<$type>";
|
| 56 |
foreach ($items as $item) {
|
| 57 |
$class = '';
|
| 58 |
if ($i == 0) {
|
| 59 |
$class = 'first';
|
| 60 |
}
|
| 61 |
elseif ($i == count($items) - 1) {
|
| 62 |
$class = 'last';
|
| 63 |
}
|
| 64 |
|
| 65 |
if (strstr($item, 'class="active"') !== FALSE) {
|
| 66 |
$class .= ($class?' ':'') . 'active';
|
| 67 |
}
|
| 68 |
|
| 69 |
$class = ' class="' . $class . '"';
|
| 70 |
$output .= '<li' . $class . '>' . $item . '</li>';
|
| 71 |
$i++;
|
| 72 |
}
|
| 73 |
$output .= "</$type>";
|
| 74 |
return $output;
|
| 75 |
}
|
| 76 |
|
| 77 |
// custom breadcrumbs
|
| 78 |
function mollio_breadcrumb($breadcrumb) {
|
| 79 |
$sep = ' / ';
|
| 80 |
if (count($breadcrumb) > 0) {
|
| 81 |
return implode($breadcrumb, $sep) . $sep;
|
| 82 |
}
|
| 83 |
else {
|
| 84 |
return t("Home");
|
| 85 |
}
|
| 86 |
}
|
| 87 |
|
| 88 |
// custom menu output
|
| 89 |
// menu_in_active_trail($mid)
|
| 90 |
function mollio_menu_tree($pid = 1) {
|
| 91 |
if ($tree = menu_tree($pid)) {
|
| 92 |
if ($pid == variable_get('menu_primary_menu', 1)) {
|
| 93 |
return "<ul class=\"menu\">\n" . $tree . "</ul>\n";
|
| 94 |
}
|
| 95 |
elseif ($pid == variable_get('menu_secondary_menu', 2)) {
|
| 96 |
return "<ul id=\"nav\">\n" . $tree . "</ul>\n";
|
| 97 |
}
|
| 98 |
else {
|
| 99 |
return "<ul>\n" . $tree . "</ul>\n";
|
| 100 |
}
|
| 101 |
}
|
| 102 |
}
|
| 103 |
|
| 104 |
function mollio_menu_item($mid, $children = '', $leaf = TRUE) {
|
| 105 |
$class = '';
|
| 106 |
$elipses = '';
|
| 107 |
|
| 108 |
if (strstr($children, 'class="active"') !== FALSE || strstr(menu_item_link($mid), 'class="active"') !== FALSE) {
|
| 109 |
$class = ' class="active"';
|
| 110 |
}
|
| 111 |
|
| 112 |
if (!$leaf) {
|
| 113 |
$elipses = '...';
|
| 114 |
}
|
| 115 |
|
| 116 |
return '<li' . $class. '>'. str_replace('</a>', "$elipses</a>", menu_item_link($mid)) . $children . "</li>\n";
|
| 117 |
}
|
| 118 |
|
| 119 |
function mollio_menu_item_link($item, $link_item) {
|
| 120 |
$attrs = array();
|
| 121 |
if (isset($item['description'])) {
|
| 122 |
$attrs = array('title' => $item['description']);
|
| 123 |
}
|
| 124 |
return l($item['title'], $link_item['path'], $attrs);
|
| 125 |
}
|
| 126 |
|
| 127 |
// custom pager output
|
| 128 |
function mollio_pager($tags = array(), $limit = 10, $element = 0, $parameters = array()) {
|
| 129 |
global $pager_total;
|
| 130 |
$output = '';
|
| 131 |
|
| 132 |
if ($pager_total[$element] > 1) {
|
| 133 |
$output .= '<div class="pagination">';
|
| 134 |
$output .= '<p>';
|
| 135 |
//$output .= theme('pager_first', ($tags[0] ? $tags[0] : t('First')), $limit, $element, $parameters);
|
| 136 |
$output .= theme('pager_previous', ($tags[1] ? $tags[1] : t('Previous')), $limit, $element, 1, $parameters);
|
| 137 |
$output .= theme('pager_list', $limit, $element, ($tags[2] ? $tags[2] : 9 ), '', $parameters);
|
| 138 |
$output .= theme('pager_next', ($tags[3] ? $tags[3] : t('Next')), $limit, $element, 1, $parameters);
|
| 139 |
$output .= theme('pager_last', ($tags[4] ? $tags[4] : t('Last')), $limit, $element, $parameters);
|
| 140 |
$output .= '</p>';
|
| 141 |
|
| 142 |
$output .= '<h4>';
|
| 143 |
$current = intval($pager_total[$element]);
|
| 144 |
//$current_page = $element . ', ' . $current . '/' . $limit;
|
| 145 |
$current_page = floor($current / $limit) + 1;
|
| 146 |
$total_pages = ceil($pager_total[$element] / $limit) + 1;
|
| 147 |
//$output .= sprintf('%d of %d', $current_page, $total_pages);
|
| 148 |
$output .= $current_page . ' of ' . $total_pages;
|
| 149 |
$output .= '</h4>';
|
| 150 |
$output .= '</div>';
|
| 151 |
|
| 152 |
return $output;
|
| 153 |
}
|
| 154 |
}
|
| 155 |
|
| 156 |
function mollio_pager_first($text, $limit, $element = 0, $parameters = array()) {
|
| 157 |
global $pager_page_array;
|
| 158 |
$output = '';
|
| 159 |
if ($pager_page_array[$element] > 0) {
|
| 160 |
$output = theme('pager_link', $text, pager_load_array(0, $element, $pager_page_array), $element, $parameters, array('class' => 'pager-first'));
|
| 161 |
}
|
| 162 |
return $output;
|
| 163 |
}
|
| 164 |
|
| 165 |
function mollio_pager_last($text, $limit, $element = 0, $parameters = array()) {
|
| 166 |
global $pager_page_array, $pager_total;
|
| 167 |
$output = '';
|
| 168 |
if ($pager_page_array[$element] < ($pager_total[$element] - 1)) {
|
| 169 |
$output = theme('pager_link', $text, pager_load_array($pager_total[$element] - 1, $element, $pager_page_array), $element, $parameters, array('class' => 'pager-last'));
|
| 170 |
}
|
| 171 |
return $output;
|
| 172 |
}
|
| 173 |
|
| 174 |
function mollio_pager_list($limit, $element = 0, $quantity = 5, $text = '', $parameters = array()) {
|
| 175 |
global $pager_page_array, $pager_total;
|
| 176 |
|
| 177 |
$output = '<span class="pager-list">';
|
| 178 |
|
| 179 |
// Calculate various markers within this pager piece:
|
| 180 |
$pager_middle = ceil($quantity / 2);
|
| 181 |
$pager_current = $pager_page_array[$element] + 1;
|
| 182 |
$pager_first = $pager_current - $pager_middle + 1;
|
| 183 |
$pager_last = $pager_current + $quantity - $pager_middle;
|
| 184 |
$pager_max = $pager_total[$element];
|
| 185 |
// End of marker calculations.
|
| 186 |
|
| 187 |
// Prepare for generation loop.
|
| 188 |
$i = $pager_first;
|
| 189 |
if ($pager_last > $pager_max) {
|
| 190 |
// Adjust "center" if at end of query.
|
| 191 |
$i = $i + ($pager_max - $pager_last);
|
| 192 |
$pager_last = $pager_max;
|
| 193 |
}
|
| 194 |
if ($i <= 0) {
|
| 195 |
// Adjust "center" if at start of query.
|
| 196 |
$pager_last = $pager_last + (1 - $i);
|
| 197 |
$i = 1;
|
| 198 |
}
|
| 199 |
// End of generation loop preparation.
|
| 200 |
|
| 201 |
// When there is more than one page, create the pager list.
|
| 202 |
if ($i != $pager_max) {
|
| 203 |
$output .= $text;
|
| 204 |
if ($i > 1) {
|
| 205 |
$output .= '<span class="pager-ellipsis">…</span>';
|
| 206 |
}
|
| 207 |
|
| 208 |
// Now generate the actual pager piece.
|
| 209 |
for (; $i <= $pager_last && $i <= $pager_max; $i++) {
|
| 210 |
if ($i < $pager_current) {
|
| 211 |
$output .= theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters);
|
| 212 |
}
|
| 213 |
if ($i == $pager_current) {
|
| 214 |
$output .= '<strong class="pager-current">'. $i .'</strong>';
|
| 215 |
}
|
| 216 |
if ($i > $pager_current) {
|
| 217 |
$output .= theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters);
|
| 218 |
}
|
| 219 |
}
|
| 220 |
|
| 221 |
if ($i < $pager_max) {
|
| 222 |
$output .= '<span class="pager-ellipsis">…</span>';
|
| 223 |
}
|
| 224 |
}
|
| 225 |
$output .= '</span>';
|
| 226 |
|
| 227 |
return $output;
|
| 228 |
}
|
| 229 |
|
| 230 |
function mollio_pager_next($text, $limit, $element = 0, $interval = 1, $parameters = array()) {
|
| 231 |
global $pager_page_array, $pager_total;
|
| 232 |
$output = '';
|
| 233 |
|
| 234 |
// If we are anywhere but the last page
|
| 235 |
if ($pager_page_array[$element] < ($pager_total[$element] - 1)) {
|
| 236 |
$page_new = pager_load_array($pager_page_array[$element] + $interval, $element, $pager_page_array);
|
| 237 |
// If the next page is the last page, mark the link as such.
|
| 238 |
if ($page_new[$element] == ($pager_total[$element] - 1)) {
|
| 239 |
$output = theme('pager_last', $text, $limit, $element, $parameters);
|
| 240 |
}
|
| 241 |
// The next page is not the last page.
|
| 242 |
else {
|
| 243 |
$output = theme('pager_link', $text, $page_new, $element, $parameters, array('class' => 'pager-next'));
|
| 244 |
}
|
| 245 |
}
|
| 246 |
|
| 247 |
return $output;
|
| 248 |
}
|
| 249 |
|
| 250 |
function mollio_pager_previous($text, $limit, $element = 0, $interval = 1, $parameters = array()) {
|
| 251 |
global $pager_page_array;
|
| 252 |
$output = '';
|
| 253 |
|
| 254 |
// If we are anywhere but the first page
|
| 255 |
if ($pager_page_array[$element] > 0) {
|
| 256 |
$page_new = pager_load_array($pager_page_array[$element] - $interval, $element, $pager_page_array);
|
| 257 |
|
| 258 |
// If the previous page is the first page, mark the link as such.
|
| 259 |
if ($page_new[$element] == 0) {
|
| 260 |
$output = theme('pager_first', $text, $limit, $element, $parameters);
|
| 261 |
}
|
| 262 |
// The previous page is not the first page.
|
| 263 |
else {
|
| 264 |
$output = theme('pager_link', $text, $page_new, $element, $parameters, array('class' => 'pager-previous'));
|
| 265 |
}
|
| 266 |
}
|
| 267 |
|
| 268 |
return $output;
|
| 269 |
}
|
| 270 |
|
| 271 |
function mollio_pager_link($text, $page_new, $element, $parameters = array(), $attributes = array()) {
|
| 272 |
$page = isset($_GET['page']) ? $_GET['page'] : '';
|
| 273 |
if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
|
| 274 |
$parameters['page'] = $new_page;
|
| 275 |
}
|
| 276 |
|
| 277 |
$query = array();
|
| 278 |
if (count($parameters)) {
|
| 279 |
$query[] = drupal_query_string_encode($parameters, array());
|
| 280 |
}
|
| 281 |
$querystring = pager_get_querystring();
|
| 282 |
if ($querystring != '') {
|
| 283 |
$query[] = $querystring;
|
| 284 |
}
|
| 285 |
|
| 286 |
// Set each pager link title
|
| 287 |
if (!isset($attributes['title'])) {
|
| 288 |
static $titles = null;
|
| 289 |
if (!isset($titles)) {
|
| 290 |
$titles = array(
|
| 291 |
t('« first') => t('Go to first page'),
|
| 292 |
t('‹ previous') => t('Go to previous page'),
|
| 293 |
t('next ›') => t('Go to next page'),
|
| 294 |
t('last »') => t('Go to last page'),
|
| 295 |
);
|
| 296 |
}
|
| 297 |
if (isset($titles[$text])) {
|
| 298 |
$attributes['title'] = $titles[$text];
|
| 299 |
}
|
| 300 |
else if (is_numeric($text)) {
|
| 301 |
$attributes['title'] = t('Go to page %number', array('%number' => $text));
|
| 302 |
}
|
| 303 |
}
|
| 304 |
|
| 305 |
return '<strong>' . l($text, $_GET['q'], $attributes, count($query) ? implode('&', $query) : NULL) . '</strong>';
|
| 306 |
}
|
| 307 |
|
| 308 |
// custom form elements
|
| 309 |
function mollio_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {
|
| 310 |
$output = '';
|
| 311 |
$required = $required ? '<span class="req">*</span>' : '';
|
| 312 |
|
| 313 |
if ($title) {
|
| 314 |
if ($id) {
|
| 315 |
$output .= "<label for=\"$id\"><b>$required$title:</b>";
|
| 316 |
}
|
| 317 |
else {
|
| 318 |
$output .= "<label><b>$required$title:</b>";
|
| 319 |
}
|
| 320 |
}
|
| 321 |
|
| 322 |
$output .= $value . "<br />\n";
|
| 323 |
|
| 324 |
if ($title) {
|
| 325 |
$output .= '</label>' . "\n";
|
| 326 |
}
|
| 327 |
|
| 328 |
if ($description) {
|
| 329 |
$output .= "<div class=\"description\">$description</div>\n";
|
| 330 |
}
|
| 331 |
|
| 332 |
return $output;
|
| 333 |
}
|
| 334 |
|
| 335 |
// custom search results
|
| 336 |
function mollio_search_item($item, $type) {
|
| 337 |
$output = '';
|
| 338 |
|
| 339 |
if (module_hook($type, 'search_item')) {
|
| 340 |
$output = module_invoke($type, 'search_item', $item);
|
| 341 |
}
|
| 342 |
else {
|
| 343 |
$output .= '<dd>' . "\n";
|
| 344 |
$output .= ' <dl>' . "\n";
|
| 345 |
$output .= ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']) .'</a></dt>' . "\n";
|
| 346 |
$output .= ' <dd class="desc">' . $item['snippet'] . '</dd>' . "\n";
|
| 347 |
if ($item['type']) {
|
| 348 |
$output .= ' <dd class="filetype">' . $item['type'] . '</dd>' . "\n";
|
| 349 |
}
|
| 350 |
if ($item['date']) {
|
| 351 |
$output .= ' <dd class="date">' . format_date($item['date'], 'small') . '</dd>' . "\n";
|
| 352 |
}
|
| 353 |
|
| 354 |
$info = array();
|
| 355 |
if ($item['user']) {
|
| 356 |
$info[] = $item['user'];
|
| 357 |
}
|
| 358 |
if (is_array($item['extra'])) {
|
| 359 |
$info = array_merge($info, $item['extra']);
|
| 360 |
}
|
| 361 |
$output .= ' <dd>'. implode(' - ', $info) .'</dd>' . "\n";
|
| 362 |
$output .= ' </dl>' . "\n";
|
| 363 |
$output .= '</dd>' . "\n";
|
| 364 |
}
|
| 365 |
|
| 366 |
return $output;
|
| 367 |
}
|
| 368 |
|
| 369 |
?>
|