-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout_sections_as_folded.php
229 lines (185 loc) · 6.9 KB
/
layout_sections_as_folded.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* layout sections as folded boxes with content
*
* With this layout each section is displayed as a folded box listing up to seven related pages.
*
* @see sections/view.php
*
* @author Bernard Paques
* @author GnapZ
* @author Thierry Pinelli [email]contact@vdp-digital.com[/email]
* @tester Olivier
* @reference
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
*/
Class Layout_sections_as_folded extends Layout_interface {
/**
* list sections
*
* @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;
}
// the maximum number of items per section
if(!defined('MAXIMUM_ITEMS_PER_SECTION'))
define('MAXIMUM_ITEMS_PER_SECTION', 100);
// we return plain text
$text = '';
// process all items in the list
include_once $context['path_to_root'].'comments/comments.php';
include_once $context['path_to_root'].'links/links.php';
include_once $context['path_to_root'].'overlays/overlay.php';
while($item =& SQL::fetch($result)) {
// get the related overlay, if any
$overlay = Overlay::load($item);
// get the main anchor
$anchor =& Anchors::get($item['anchor']);
// one box per section
$box = array('title' => '', 'text' => '');
// box content
$elements = array();
// start the label with family, if any
if($item['family'])
$box['title'] = Skin::strip($item['family'], 30).' - ';
// use the title to label the link
if(is_object($overlay))
$box['title'] .= Codes::beautify_title($overlay->get_text('title', $item));
else
$box['title'] .= Codes::beautify_title($item['title']);
$details = array();
// list related sections, if any
if($items =& Sections::list_by_title_for_anchor('section:'.$item['id'], 0, MAXIMUM_ITEMS_PER_SECTION+1, 'compact')) {
// mention the number of sections in folded title
$details[] = sprintf(i18n::ns('%d section', '%d sections', count($items)), count($items));
// add one link per item
foreach($items as $url => $label) {
$prefix = $suffix = '';
if(is_array($label)) {
$prefix = $label[0];
$suffix = $label[2];
$label = $label[1];
}
$elements[] = $prefix.Skin::build_link($url, $label, 'section').$suffix;
}
}
// info on related articles
if(preg_match('/\barticles_by_([a-z_]+)\b/i', $item['options'], $matches))
$order = $matches[1];
else
$order = 'edition';
$items =& Articles::list_for_anchor_by($order, 'section:'.$item['id'], 0, MAXIMUM_ITEMS_PER_SECTION+1, 'compact');
if(@count($items)) {
// mention the number of items in folded title
$details[] = sprintf(i18n::ns('%d page', '%d pages', count($items)), count($items));
// add one link per item
foreach($items as $url => $label) {
$prefix = $suffix = '';
if(is_array($label)) {
$prefix = $label[0];
$suffix = $label[2];
$label = $label[1];
}
$elements[] = $prefix.Skin::build_link($url, $label, 'article').$suffix;
}
}
// info on related files
if(Sections::has_option('files_by_title', $anchor, $item))
$items = Files::list_by_title_for_anchor('section:'.$item['id'], 0, MAXIMUM_ITEMS_PER_SECTION+1, 'compact');
else
$items = Files::list_by_date_for_anchor('section:'.$item['id'], 0, MAXIMUM_ITEMS_PER_SECTION+1, 'compact');
if($items) {
// mention the number of sections in folded title
$details[] = sprintf(i18n::ns('%d file', '%d files', count($items)), count($items));
// add one link per item
foreach($items as $url => $label) {
if(is_array($label)) {
$prefix = $label[0];
$suffix = $label[2];
$label = $label[1];
}
$elements[] = $prefix.Skin::build_link($url, $label, 'file').$suffix;
}
}
// info on related comments
if($items = Comments::list_by_date_for_anchor('section:'.$item['id'], 0, MAXIMUM_ITEMS_PER_SECTION+1, 'compact', Sections::has_option('comments_as_wall', $anchor, $item))) {
// mention the number of sections in folded title
$details[] = sprintf(i18n::ns('%d comment', '%d comments', count($items)), count($items));
// add one link per item
foreach($items as $url => $label) {
$prefix = $suffix = '';
if(is_array($label)) {
$prefix = $label[0];
$suffix = $label[2];
$label = $label[1];
}
$elements[] = $prefix.Skin::build_link($url, $label, 'comment').$suffix;
}
}
// info on related links
if(Sections::has_option('links_by_title', $anchor, $item))
$items = Links::list_by_title_for_anchor('section:'.$item['id'], 0, MAXIMUM_ITEMS_PER_SECTION+1, 'compact');
else
$items = Links::list_by_date_for_anchor('section:'.$item['id'], 0, MAXIMUM_ITEMS_PER_SECTION+1, 'compact');
if($items) {
// mention the number of sections in folded title
$details[] = sprintf(i18n::ns('%d link', '%d links', count($items)), count($items));
// add one link per item
foreach($items as $url => $label) {
$prefix = $suffix = '';
if(is_array($label)) {
$prefix = $label[0];
$suffix = $label[2];
$label = $label[1];
}
$elements[] = $prefix.Skin::build_link($url, $label).$suffix;
}
}
// signal continuing sections
if(count($elements) > MAXIMUM_ITEMS_PER_SECTION)
$elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('More pages').MORE_IMG, 'basic');
// else allow to view the section anyway
else
$elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the section'), 'shortcut');
// complement title
if(count($details))
$box['title'] .= ' <span class="details">('.join(', ', $details).')</span>';
// insert introduction, if any
if($item['introduction'])
$box['text'] .= Codes::beautify_introduction($item['introduction']);
// make a full list
if(count($elements))
$box['text'] .= '<ul><li>'.implode('</li>'."\n".'<li>', $elements).'</li></ul>'."\n";
// if we have an icon for this section, use it
if(isset($item['thumbnail_url']) && $item['thumbnail_url']) {
// adjust the class
$class= '';
if(isset($context['classes_for_thumbnail_images']))
$class = 'class="'.$context['classes_for_thumbnail_images'].'" ';
// build the complete HTML element
$icon = '<img src="'.$item['thumbnail_url'].'" alt="" title="'.encode_field(Codes::beautify_title($item['title'])).'" '.$class.'/>';
// make it clickable
$link = Skin::build_link(Sections::get_permalink($item), $icon, 'basic');
// put this aside
$box['text'] = '<table class="decorated"><tr>'
.'<td class="image">'.$link.'</td>'
.'<td class="content">'.$box['text'].'</td>'
.'</tr></table>';
}
// always make a box
$text .= Skin::build_box($box['title'], $box['text'], 'folded');
}
// end of processing
SQL::free($result);
return $text;
}
}
?>