/[drupal]/contributions/modules/ed_classified/ed_classified_themefuncs.inc
ViewVC logotype

Contents of /contributions/modules/ed_classified/ed_classified_themefuncs.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sun Sep 13 03:06:58 2009 UTC (2 months, 2 weeks ago) by milesgillham
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +4 -4 lines
File MIME type: text/x-php
stable checkin
1 <?php
2 // $Id: ed_classified_themefuncs.inc,v 1.2 2009/09/03 02:58:11 milesgillham Exp $
3
4 /**
5 $ @file
6 * Simple text-based classified ads module.
7 * Michael Curry, Exodus Development, Inc.
8 * exodusdev@gmail.com
9 * for more information, please visit http://exodusdev.com/drupal/modules/classified.module
10 * Copyright (c) 2006, 2007 Exodus Development, Inc. All Rights Reserved.
11 * Licensed under the terms of the GNU Public License (GPL) version 2. Please see LICENSE.txt for
12 * license terms. Possession and use of this code signifies acceptance of license
13 * terms.
14 */
15
16
17 /**
18 * Drupal 6 hook_theme() registration function
19 */
20
21 function ed_classified_theme() {
22 return array(
23 'ed_classified_body' => array('arguments' => array('node')),
24 'ed_classified_teaser' => array('arguments' => array('node')),
25 'ed_classified_ending_date' => array('arguments' => array('ad_expiration_date')),
26 'ed_classified_ads_block' => array('arguments' => array('ads', 'display_timestamp' => TRUE, 'display_counter' => FALSE, 'display_ad_category' => FALSE)),
27 'ed_classified_taxonomy' => array('arguments' => array('cats' => NULL, 'ads' => NULL)),
28 'ed_classified_adcount' => array('arguments' => array('count' => NULL)),
29 'ed_classified_taxonomy_catlist' => array('arguments' => array('cats' => NULL)),
30 'ed_classified_category_list_row' => array('arguments' => array('cat' => NULL, 'row_count' => NULL)),
31 'ed_classified_taxonomy_ads' => array('arguments' => array('ads' => NULL)),
32 'ed_classified_category_list_ad_row' => array('arguments' => array('ad' => NULL, 'rowcount' => NULL)),
33 'ed_classified_category_name' => array('arguments' => array('cat' => NULL)),
34 'ed_classified_category_description' => array('arguments' => array('cat' => NULL)),
35 'ed_classified_ads_stats' => array(),
36 );
37 }
38
39 /**
40 * Theme an ads block
41 *
42 */
43 function theme_ed_classified_ads_block($ads, $display_timestamp=TRUE, $display_counter=FALSE, $display_ad_category=FALSE) {
44 module_load_include('inc', 'ed_classified', 'ed_classified_utils');
45 // var_dump($ads);
46 $content = '';
47 foreach ($ads as $x) {
48 $content .= '<li class="classified-ad-item">'. l($x->title, drupal_get_path_alias('node/'. $x->nid), array('attributes' => array('title' => check_markup($x->teaser))));
49 if ($display_ad_category) {
50 $term = _ed_classified_get_primary_category($x);
51 if ($term) {
52 $content .= ' <span class=\'classified-block-ad-term\'>'. l("($term->name)", _ed_classified_make_category_path($term->tid)) .'</span>'; // TODO: themeable function
53 }
54 }
55 if ($display_timestamp) {
56 $content .= ' <span class=\'classified-block-ad-age\'>('. format_interval(REQUEST_TIME - $x->timestamp, 2) . t(' ago') .') </span>';
57 }
58 if ($display_counter) {
59 $content .= ' <span class=\'classified-block-ad-count\'>('. $x->counter .') </span>';
60 }
61 if (node_last_viewed($x->nid) < $x->changed)
62 $content .= theme_mark();
63 $content .= '</li>';
64 }
65 if (!empty($content)) {
66 $content = '<div class="classified-ad-block item-list"><ul>'. $content;
67 $content .= '</ul></div>';
68 }
69 return $content;
70 }
71
72 /**
73 * Theme a classified ads taxonomy browser page
74 */
75
76 function theme_ed_classified_taxonomy($cats, $ads) {
77 module_load_include('inc', 'ed_classified', 'ed_classified_utils');
78
79 $content = '';
80 if (user_access('create classified ads')) {
81 $content .= '<div class="classified-category-link-add">'. l(t('Create a new ad'), drupal_get_path_alias("node/add/". EDI_CLASSIFIED_PATH_NAME)) ."</div>\n";
82 }
83
84 if (count($cats)) {
85 $content .= theme('ed_classified_taxonomy_catlist', $cats);
86 }
87
88 if (count($ads)) {
89 $content .= theme('ed_classified_taxonomy_ads', $ads);
90 }
91
92 if ($pager = theme('pager', NULL, _ed_classified_variable_get('ads_per_page', 10), 0)) {
93 $content .= $pager;
94 }
95
96 if (count($ads) + count($cats) == 0) {
97 $content .= theme('ed_classified_category_adcount', 0);
98 }
99
100 return $content;
101 }
102
103 function theme_ed_classified_category_adcount($count) {
104 return '<p class="classified-count">'. format_plural($count, 'There is @count ad in this category', 'There are @count ads in this category') ."</p>\n";
105 }
106
107 function theme_ed_classified_taxonomy_catlist($cats) {
108 $row_count = 0;
109 $content .= '<ul class="classified-category-list">';
110 foreach ($cats as $cat) {
111 $content .= theme('ed_classified_category_list_row', $cat, $row_count);
112 $row_count ++;
113 }
114 $content .= "</ul>\n";
115 return $content;
116 }
117
118 function theme_ed_classified_category_list_row($cat, $row_count) {
119 $content = '';
120 $row_style = ($row_count % 2 == 0) ? 'even' : 'odd';
121 $content .= "<li class ='$row_style' >";
122 // 'preview' (was thumbnail of latest image)
123 // if ($cat->count)
124 // $content.= l('foo', _ed_classified_make_category_path($cat->tid), array('html' => TRUE));
125 $content .= theme('ed_classified_category_name', $cat);
126 // Removed the description from below the name, instead it is integrated with the name
127 // (i.e. it appears as a title in there)
128 //if(trim($cat->description) != '') {
129 // $content .= theme('ed_classified_category_description', $cat);
130 //}
131 // TODO: get preview list
132 if ($cat->latest) {
133 $content .= '<div class=\'title\'>'. t('Latest ad: ') . l($cat->latest->title, drupal_get_path_alias('node/'. $cat->latest->nid)) .'</div>';
134 $content .= '<div class=\'created\'>'. t('Created on ') . format_date($cat->latest->created) .' ('. format_interval(REQUEST_TIME - $cat->latest->created) . t(' ago') .')</div>';
135 }
136 $content .= '<div class="status">';
137
138 $content .= theme('ed_classified_category_adcount', $cat->count);
139 if ($cat->latest->changed) {
140 $content .= t(' Last updated: !date', array('!date' => format_date($cat->latest->changed)));
141 }
142
143 $content .="</div>\n"; // class="status"
144 $content .= "</li>\n";
145 return $content;
146 }
147
148 function theme_ed_classified_taxonomy_ads($ads) {
149 $content .= '<ul class="classified-ad-list">';
150 $rowcount = 0;
151 foreach ($ads as $ad) {
152 $content .= theme('ed_classified_category_list_ad_row', $ad, $rowcount);
153 $rowcount++;
154 }
155 $content .= "</ul>\n";
156 return $content;
157 }
158
159 function theme_ed_classified_category_list_ad_row($ad, $rowcount) {
160 module_load_include('inc', 'ed_classified', 'ed_classified_utils');
161 $content .= '<li';
162 if ($ad->sticky) {
163 $content .= ' class="sticky"';
164 }
165 $content .= ">\n";
166 $content .= '<h3>'. l($ad->title, drupal_get_path_alias('node/'. $ad->nid),
167 array('attributes' => array('title' => 'Description here!'))) ."</h3>";
168 if (_ed_classified_variable_get('show_body_in_ad_list', EDI_CLASSIFIED_VAR_DEF_SHOW_BODY_IN_AD_LIST)) {
169 $content .= '<div class=\'classified-description\'>'. check_markup($ad->body, $ad->format, FALSE) .'</div>';
170 if (theme_get_setting('toggle_node_info_'. $ad->type)) {
171 $content .= '<div class="classified-author">'. t('Posted by: !name', array('!name' => theme('username', $ad))) ."</div>\n";
172 if ($ad->created > 0) {
173 $content .= '<div class="classified-date">'. t('Created on ') . format_date($ad->created) ."</div>\n";
174 }
175 $expires = ed_classified_get_ad_expiration($ad);
176 if ($expires > 0) {
177 $content .= '<div class="classified-date">'. theme('ed_classified_ending_date', $expires) ."</div>\n";
178 }
179 }
180 }
181 $content .= "</li>\n";
182 return $content;
183 }
184
185 function theme_ed_classified_category_name($cat) {
186 module_load_include('inc', 'ed_classified', 'ed_classified_utils');
187 return '<div class=\'classified-cat-name\'>'. l($cat->name, _ed_classified_make_category_path($cat->tid),
188 array('attributes' => array('title' => $cat->description))) ."</div>\n";
189 }
190
191 function theme_ed_classified_category_description($cat) {
192 return '<div class="classified-description">'. check_plain($cat->description) ."</div>\n";
193 }
194
195 function theme_ed_classified_ads_stats() {
196 $content = '';
197 $today = ed_classified_get_adcount_for_time_range(REQUEST_TIME-86400, REQUEST_TIME, TRUE); // 86400 = # seconds in a day
198 $total = ed_classified_get_adcount(TRUE);
199 if ($today >0 || $total > 0) {
200 $stats = array('!adcount' => $total, '!ads_today' => $today);
201 $content = '<div class="classified-ad-block item-list"><ul>';
202 $content .= '<li>'. t('!adcount ads total.', $stats) .'</li>'; // todo: format_plural() http://api.drupal.org/api/HEAD/function/format_plural
203 $content .= '<li>'. t('!ads_today ads in last 24 hours.', $stats) .'</li>'; // todo: format_plural()
204 $content .= '</ul></div>';
205 }
206 return $content;
207 }
208
209 function theme_ed_classified_teaser($node) {
210 return '<div class=\'classified-teaser\'>'. check_markup($node->teaser, $node->format, FALSE) .'</div><br/>'. theme('ed_classified_ending_date', $node->expires_on);
211 }
212
213 function theme_ed_classified_body($node) {
214 return '<div class=\'classified-body\'>'. check_markup($node->body, $node->format, FALSE) .'</div><br/>'. theme('ed_classified_ending_date', $node->expires_on);
215 }
216
217 /**
218 * Get a formatted div with a readable, friendly ad expiration date.
219 */
220 function theme_ed_classified_ending_date($ad_expiration_date) {
221 module_load_include('inc', 'ed_classified', 'ed_classified_utils');
222 $class = 'classified-expiration-info'; // standard expiration formatting
223 $str = _ed_classified_get_ending_date_string($ad_expiration_date);
224 // set style for ending soon
225 if (_ed_classified_ad_expires_soon($ad_expiration_date)) {
226 $class = 'classified-expiration-expires_soon'; // TODO: crappy name, fix this
227 }
228 if (_ed_classified_ad_expired_already($ad_expiration_date)) {
229 $class = 'classified-expiration-expired'; // TODO: crappy name, fix this
230 }
231 return "<span class='$class'>". $str .'</span>';
232 }
233

  ViewVC Help
Powered by ViewVC 1.1.2