/
layout_categories_as_yahoo.php
195 lines (162 loc) · 6.13 KB
/
layout_categories_as_yahoo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* layout categories as an index page of Yahoo!
*
* With this layout up to three sub-items are listed as well.
* These can be either sub-categories and/or articles, depending of relative availability of both kind of items.
*
* @see categories/categories.php
*
* @author Bernard Paques
* @author GnapZ
* @reference
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
*/
Class Layout_categories_as_yahoo extends Layout_interface {
/**
* list categories
*
* @param resource the SQL result
* @return string the rendered text
*
* @see skins/layout.php
**/
function layout($result) {
global $context;
// empty list
if(!SQL::count($result)) {
$output = array();
return $output;
}
// we return an array of ($url => $attributes)
$items = array();
// process all items in the list
include_once $context['path_to_root'].'comments/comments.php';
include_once $context['path_to_root'].'links/links.php';
while($item = SQL::fetch($result)) {
// url to read the full category
$url =& Categories::get_permalink($item);
// initialize variables
$prefix = $suffix = $icon = '';
// flag categories that are dead, or created or updated very recently
if(($item['expiry_date'] > NULL_DATE) && ($item['expiry_date'] <= $context['now']))
$prefix .= EXPIRED_FLAG;
elseif($item['create_date'] >= $context['fresh'])
$suffix .= NEW_FLAG;
elseif($item['edit_date'] >= $context['fresh'])
$suffix .= UPDATED_FLAG;
// signal restricted and private categories
if($item['active'] == 'N')
$prefix .= PRIVATE_FLAG;
elseif($item['active'] == 'R')
$prefix .= RESTRICTED_FLAG;
// introduction
if($item['introduction'])
$suffix .= ' '.Codes::beautify(trim($item['introduction']));
// details
$details = array();
// count related sub-elements
$related_count = 0;
// info on related categories
$stats = Categories::stat_for_anchor('category:'.$item['id']);
if($stats['count'])
$details[] = sprintf(i18n::ns('%d category', '%d categories', $stats['count']), $stats['count']);
$related_count += $stats['count'];
// info on related sections
if($count = Members::count_sections_for_anchor('category:'.$item['id'])) {
$details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count);
$related_count += $count;
}
// info on related articles
if($count = Members::count_articles_for_anchor('category:'.$item['id'])) {
$details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count);
$related_count += $count;
}
// info on related files
if($count = Files::count_for_anchor('category:'.$item['id'], TRUE)) {
$details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count);
$related_count += $count;
}
// info on related links
if($count = Links::count_for_anchor('category:'.$item['id'], TRUE)) {
$details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
$related_count += $count;
}
// info on related comments
if($count = Comments::count_for_anchor('category:'.$item['id'], TRUE)) {
$details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count);
$related_count += $stats['count'];
}
// info on related users
if($count = Members::count_users_for_anchor('category:'.$item['id']))
$details[] = sprintf(i18n::ns('%d user', '%d users', $count), $count);
// append details to the suffix
if(count($details))
$suffix .= "\n".'<span class="details">('.implode(', ', $details).')</span>';
// add a head list of related links
$details = array();
// add sub-categories on index pages
if($related = Categories::list_by_date_for_anchor('category:'.$item['id'], 0, YAHOO_LIST_SIZE, 'compact')) {
foreach($related as $sub_url => $label) {
$sub_prefix = $sub_suffix = $sub_hover = '';
if(is_array($label)) {
$sub_prefix = $label[0];
$sub_suffix = $label[2];
if(@$label[5])
$sub_hover = $label[5];
$label = $label[1];
}
$details[] = $sub_prefix.Skin::build_link($sub_url, $label, 'basic', $sub_hover).$sub_suffix;
}
}
// add related sections if necessary
if((count($details) < YAHOO_LIST_SIZE) && ($related =& Members::list_sections_by_title_for_anchor('category:'.$item['id'], 0, YAHOO_LIST_SIZE - count($details), 'compact'))) {
foreach($related as $sub_url => $label) {
$sub_prefix = $sub_suffix = $sub_hover = '';
if(is_array($label)) {
$sub_prefix = $label[0];
$sub_suffix = $label[2];
if(@$label[5])
$sub_hover = $label[5];
$label = $label[1];
}
$details[] = $sub_prefix.Skin::build_link($sub_url, $label, 'basic', $sub_hover).$sub_suffix;
}
}
// add related articles if necessary
if((count($details) < YAHOO_LIST_SIZE) && ($related =& Members::list_articles_by_date_for_anchor('category:'.$item['id'], 0, YAHOO_LIST_SIZE - count($details), 'compact'))) {
foreach($related as $sub_url => $label) {
$sub_prefix = $sub_suffix = $sub_hover = '';
if(is_array($label)) {
$sub_prefix = $label[0];
$sub_suffix = $label[2];
if(@$label[5])
$sub_hover = $label[5];
$label = $label[1];
}
$details[] = $sub_prefix.Skin::build_link($sub_url, $label, 'basic', $sub_hover).$sub_suffix;
}
}
// give me more
if(count($details) && ($related_count > YAHOO_LIST_SIZE))
$details[] = Skin::build_link(Categories::get_permalink($item), i18n::s('More').MORE_IMG, 'more', i18n::s('View the category'));
// layout details
if(count($details))
$suffix .= BR."\n» ".'<span class="details">'.implode(', ', $details)."</span>\n";
// put the actual icon in the left column
if(isset($item['thumbnail_url']))
$icon = $item['thumbnail_url'];
// use the title to label the link
$label = Skin::strip($item['title'], 50);
// some hovering title for this category
$hover = i18n::s('View the category');
// list all components for this item
$items[$url] = array($prefix, $label, $suffix, 'category', $icon, $hover);
}
// end of processing
SQL::free($result);
$output = Skin::build_list($items, '2-columns');
return $output;
}
}
?>