-
Notifications
You must be signed in to change notification settings - Fork 8
/
layout_articles_as_thread.php
143 lines (113 loc) · 4.27 KB
/
layout_articles_as_thread.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
<?php
/**
* layout articles as conversations
*
* This has more than compact, and less than decorated.
*
* @see articles/index.php
* @see articles/articles.php
*
* @author Bernard Paques
* @reference
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
*/
Class Layout_articles_as_thread extends Layout_interface {
/**
* list articles
*
* @param resource the SQL result
* @return array of resulting items, or NULL
*
* @see skins/layout.php
**/
function &layout(&$result) {
global $context;
// we return an array of ($url => $attributes)
$items = array();
// empty list
if(!SQL::count($result))
return $items;
// sanity check
if(!isset($this->layout_variant))
$this->layout_variant = NULL;
// flag articles updated recently
if($context['site_revisit_after'] < 1)
$context['site_revisit_after'] = 2;
$dead_line = gmstrftime('%Y-%m-%d %H:%M:%S', mktime(0,0,0,date("m"),date("d")-$context['site_revisit_after'],date("Y")));
$now = gmstrftime('%Y-%m-%d %H:%M:%S');
// process all items in the list
include_once $context['path_to_root'].'categories/categories.php';
include_once $context['path_to_root'].'comments/comments.php';
include_once $context['path_to_root'].'files/files.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']);
// the url to view this item
$url =& Articles::get_permalink($item);
// reset the rendering engine between items
Codes::initialize($url);
// use the title to label the link
if(is_object($overlay) && is_callable(array($overlay, 'get_live_title')))
$title = $overlay->get_live_title($item);
else
$title = Codes::beautify_title($item['title']);
// initialize variables
$prefix = $suffix = $icon = '';
// flag sticky pages
if(($item['rank'] < 10000) && !preg_match('/(compact|hits|mobile)/', $this->layout_variant))
$prefix .= STICKY_FLAG;
// signal articles to be published
if(($item['publish_date'] <= NULL_DATE) || ($item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')))
$prefix .= DRAFT_FLAG;
// signal restricted and private articles
if($item['active'] == 'N')
$prefix .= PRIVATE_FLAG;
elseif($item['active'] == 'R')
$prefix .= RESTRICTED_FLAG;
// flag articles that are dead, or created or updated very recently
if(($item['expiry_date'] > NULL_DATE) && ($item['expiry_date'] <= $now))
$prefix .= EXPIRED_FLAG;
elseif($item['create_date'] >= $dead_line)
$suffix .= NEW_FLAG;
elseif($item['edit_date'] >= $dead_line)
$suffix .= UPDATED_FLAG;
// rating
if($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating')))
$suffix .= Skin::build_rating_img((int)round($item['rating_sum'] / $item['rating_count']));
// info on related comments
if($count = Comments::count_for_anchor('article:'.$item['id'], TRUE))
$suffix .= ' ('.$count.')';
// details
$details = array();
// info on related files
if($count = Files::count_for_anchor('article:'.$item['id'], TRUE))
$details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count);
// info on related links
if($count = Links::count_for_anchor('article:'.$item['id'], TRUE))
$details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
// flag popular pages
$popular = '';
if($item['hits'] > 300)
$details[] = POPULAR_FLAG;
// signal locked articles
if(isset($item['locked']) && ($item['locked'] == 'Y'))
$details[] = LOCKED_FLAG;
// page editors, except target surfer
if($friends =& Members::list_users_by_posts_for_member('article:'.$item['id'], 0, USERS_LIST_SIZE, 'comma', $this->layout_variant))
$details[] = sprintf(i18n::s('with %s'), Skin::build_list($friends, 'comma'));
// combine in-line details
if(count($details))
$suffix .= ' - <span class="details">'.trim(implode(', ', $details)).'</span>';
// list all components for this item
$items[$url] = array($prefix, $title, $suffix, 'article', $icon);
}
// end of processing
SQL::free($result);
return $items;
}
}
?>