- Add the 'themes' directory
[infrastructure.git] / themes / democratica / template.php
1 <?php
2
3 /*******************************************************************************
4
5 Author:         Christopher Messina
6 Created:        2004-11-02
7 Updated: 2005-02-15
8 Copyright:      (cc) Share alike 2005, some rights reserved.
9
10   Thanks to cxj and moshe in #drupal for their help.
11
12 *******************************************************************************/
13
14 function phptemplate_breadcrumb($breadcrumb) {
15   $breadcrumb[] = drupal_get_title();
16   return "<div class=\"hide\">You are here:</div>\n<ul>\n<li class=\"first\">". implode("</li>\n<li>", $breadcrumb) ."</li>\n</ul>\n";
17 }
18
19 function phptemplate_xml_icon($url) {
20   $dir = base_path() . path_to_theme() . '/images/rss.png';
21   if ($image = theme('image', $dir, t('XML feed'), t('XML feed'))) {
22     return '<div class="xml-icon"><a href="'. $url .'" title="Subscribe to RSS feed">'. $image .'</a></div>';
23   }
24
25
26 function _word_split($text) {
27   global $democratica_word_length;
28   return preg_replace('/([^ ]{'. $democratica_word_length .'})(?=[^ ])/u', '\1-<wbr />', $text[0]);
29 }
30
31 function word_split($text, $max_char = 15) {
32   global $democratica_word_length;
33   $democratica_word_length = $max_char;
34   return substr(preg_replace_callback('/>[^<]+</', '_word_split', '>'. $text .'<'), 1, -1);
35 }
36
37 function phptemplate_comment_thread_min($comment, $threshold, $pid = 0) {
38   if (comment_visible($comment, $threshold)) {
39     $output  = "<dl>\n";
40     $output .= theme('comment_view', $comment, '', 0);
41     $output .= "</dl>\n";
42   }
43   return $output;
44 }
45
46 function phptemplate_comment_thread_max($comment, $threshold, $level = 0) {
47   $output = '';
48   if ($comment->depth) {
49     $output .= "<dl>\n";
50   }
51
52   $output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)), comment_visible($comment, $threshold));
53
54   if ($comment->depth) {
55     $output .= "</dl>\n";
56   }
57   return $output;
58 }
59
60
61 function phptemplate_status_messages() {
62   if ($data = drupal_get_messages()) {
63     $output = '';
64     foreach ($data as $type => $messages) {
65       $output .= "<div class=\"messages $type\">\n";
66         $output .= " <ul>\n";
67         foreach($messages as $message) {
68           $output .= '  <li>'. $message ."</li>\n";
69         }
70         $output .= " </ul>\n";
71       $output .= "</div>\n";
72     }
73     return $output;
74   }
75
76
77 function phptemplate_aggregator_page_item($item) {
78   static $last;
79
80   $date = date('Ymd', $item->timestamp);
81   if ($date != $last) {
82     $last = $date;
83     $output .= '<h2 class="aggregator-date">'. date('F j, Y', $item->timestamp) ."</h2>\n";
84   }
85
86   $output .= "<div class=\"news-item\">\n";
87   $output .= " <h3 class=\"news-item-title\"><a href=\"$item->link\">$item->title</a></h3>\n";
88   if ($item->ftitle && $item->fid) { $output .= '  <div class="news-item-source"> Source: '. l($item->ftitle, "aggregator/sources/$item->fid") .' @ <span class="news-item-date">'. date('H:i', $item->timestamp) ."</span>\n</div>\n"; }
89   $output .= " <div class=\"news-item-body\">\n";
90   if ($item->description) {
91     $output .= "  <div class=\"news-item-description\">$item->description</div>\n";
92   }
93
94   $result = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = %d ORDER BY c.title', $item->iid);
95   $categories = array();
96   while ($category = db_fetch_object($result)) {
97     $categories[] = l($category->title, 'aggregator/categories/'. $category->cid);
98   }
99   if ($categories) {
100     $output .= '  <div class="news-item-categories">'. t('Categories') .': '. implode(', ', $categories) ."</div>\n";
101   }
102
103   $output .= " </div>\n";
104   $output .= "</div>\n";
105
106   return $output;
107
108
109 /*
110 function phptemplate_menu_item($mid) {
111   $menu = menu_get_menu();
112
113   $link_mid = $mid;
114   while ($menu['items'][$link_mid]['type'] & MENU_LINKS_TO_PARENT) {
115     $link_mid = $menu['items'][$link_mid]['pid'];
116   }
117
118   $class = array();
119   $local_tasks = menu_get_local_tasks();
120   if (menu_in_active_trail($mid)) {
121     $class = array('class' => 'current');
122   }
123
124   return l($menu['items'][$mid]['title'],
125            $menu['items'][$link_mid]['path'],
126            array_key_exists('description', $menu['items'][$mid]) ? array_merge($class, array("title" => $menu['items'][$mid]['description'])) : $class);
127
128
129 function phptemplate_menu_local_task($mid, $active) {
130   $local_tasks = menu_get_local_tasks();
131   $pid = menu_get_active_nontask_item();
132   $menu = menu_get_menu();
133   if ($active) {
134     if ($menu['items'][$mid]['children'][0] == menu_get_active_item()) {
135       $output = '<li class="active"><span>'. $menu['items'][$mid]['title'] .'</span>';      
136     }
137     else {
138       $output = '<li class="active">'. theme('menu_item', $mid) ."</li>\n"; 
139     }
140     foreach ($local_tasks[$pid]['children'] as $mid) {
141       if (menu_in_active_trail($mid) && count($local_tasks[$mid]['children']) > 1) {
142         $output .= "<ul class=\"secondary\">\n";
143         foreach ($local_tasks[$mid]['children'] as $cid) {
144           $output .= theme('menu_local_task', $cid, 0);
145         }
146         $output .= "</ul>\n";
147       }
148     }
149     $output .= "</li>\n";
150     return $output;
151   }
152   else {
153     if (menu_in_active_trail($mid)) {
154       return '<li class="active"><span>'. $menu['items'][$mid]['title'] ."</span></li>\n";
155     }
156     else {  
157       return '<li>'. theme('menu_item', $mid) ."</li>\n";
158     }
159   }
160
161
162 function phptemplate_menu_local_tasks() {
163   $local_tasks = menu_get_local_tasks();
164   $pid = menu_get_active_nontask_item();
165   $output = '';
166
167   if (count($local_tasks[$pid]['children'])) {
168     $output .= "<div id=\"local-tasks\">\n";
169     $output .= "  <ul class=\"primary\">\n";
170     foreach ($local_tasks[$pid]['children'] as $mid) {
171       $output .= theme('menu_local_task', $mid, menu_in_active_trail($mid));
172     }
173     $output .= "  </ul>\n";
174     $output .= "</div>\n";
175   }
176   return $output;
177
178 */
179 ?>