/
feed_lib.php
175 lines (137 loc) · 5.24 KB
/
feed_lib.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
<?php
/**
* @version $Header$
*
* FeedStatus class
*
* @version $Revision$
* @package feed
* @subpackage functions
*/
/**
* feed_get_actions
*/
function feed_get_actions( $pListHash ) {
global $gBitDb;
$whereSql = '';
$bindVars = array();
BitBase::prepGetList( $pListHash );
if( !empty( $pListHash['user_id'] ) ) {
$whereSql = " WHERE lal.user_id = ? ";
$bindVars[] = $pListHash['user_id'];
}else{
$whereSql = "WHERE 1=1 ";
}
$query = "SELECT lal.content_id, lal.user_id, lal.log_message, MAX(lal.last_modified) AS last_modified, uu.login, uu.real_name, uu.email
FROM liberty_action_log lal
INNER JOIN liberty_content lc ON (lc.content_id=lal.content_id)
INNER JOIN users_users uu ON (uu.user_id=lal.user_id)
$whereSql AND lc.content_type_guid != 'feedstatus'
GROUP BY lal.content_id, lal.user_id, uu.login, uu.real_name, uu.email, lal.log_message
ORDER BY MAX(lal.last_modified) DESC";
$res = $gBitDb->query( $query, $bindVars, $pListHash['max_records'] );
$conjugationQuery = "SELECT * FROM feed_conjugation";
$overrides = $gBitDb->getAssoc( $conjugationQuery );
$actions = array();
//loop through directed actions
while ( $action = $res->fetchRow() ){
if( !empty($action['content_id']) ) { //indicates that this isn't a direct action, more of a "status update" ex. "Ronald is pleased with his artwork"
if( $content = LibertyContent::getLibertyObject($action['content_id']) ) {
$contentType = $content->getContentType();
$action['real_log'] = BitUser::getDisplayNameFromHash( empty( $pListHash['no_link_user'] ), $action ).' ';
if(!empty($overrides[strtolower($contentType)])){
$action['real_log'] .= $overrides[$contentType]['conjugation_phrase'];
if($overrides[$contentType]['is_target_linked'] == 'y'){
$action['real_log'] .= ' <a href="'.$content->getDisplayUrl().'">'.$content->getTitle().'</a>';
}
if( !empty( $overrides[$contentType]['feed_icon_url'] ) ) {
$action['feed_icon_url'] = $overrides[$contentType]['feed_icon_url'];
}
}else{
$action['real_log'] .= tra( 'edited' ).' <a href="'.$content->getDisplayUrl().'">'.$content->getTitle().'</a>';
}
} else {
unset( $action ); //invalid content_id
}
if( empty( $action['feed_icon_url'] ) ) {
$action['feed_icon_url'] = FEED_PKG_URL.'icons/pixelmixerbasic/pencil_16.png';
}
$actions[] = $action;
}
}
return $actions;
}
function feed_get_status( $pListHash ){
global $gBitDb;
$whereSql = '';
$bindVars = array();
$statuses = array();
BitBase::prepGetList( $pListHash );
if( !empty( $pListHash['user_id'] ) ) {
$whereSql = " WHERE lal.user_id = ? ";
$bindVars[] = $pListHash['user_id'];
}else{
$whereSql = "WHERE 1=1 ";
}
$query = "SELECT lal.content_id, lal.user_id, lal.log_message, MAX(lal.last_modified) AS last_modified, lc.data, uu.login, uu.real_name, uu.email
FROM liberty_action_log lal
INNER JOIN liberty_content lc ON (lc.content_id=lal.content_id)
INNER JOIN liberty_comments lcs ON (lcs.content_id = lc.content_id)
INNER JOIN users_users uu ON (uu.user_id=lal.user_id)
$whereSql AND lc.content_type_guid = 'feedstatus'
GROUP BY lal.content_id, lal.user_id, uu.login, uu.real_name, uu.email, lal.log_message,lc.data
ORDER BY MAX(lal.last_modified) DESC";
$res = $gBitDb->query( $query, $bindVars, $pListHash['max_records'] );
$user = new BitUser($pListHash['user_id']);
$user->load();
while ( $status = $res->fetchRow() ){
$avatarUrl = $user->getThumbnailUrl();
if(empty($avatarUrl)){
$avatarUrl = USERS_PKG_URI."icons/silhouette.png";
}
$status['feed_icon_url'] = $avatarUrl;
$comment = new LibertyComment(NULL,$status['content_id']);
$replies = $comment->getComments($status['content_id'],null,null,'commentDate_asc');
$status['replies'] = $replies;
foreach ( $status['replies'] as &$reply ){
$replyUser = new BitUser($reply['user_id']);
$replyUser->load();
$replyAvatarUrl = $replyUser->getThumbnailUrl();
if(empty($replyAvatarUrl)){
$replyAvatarUrl = USERS_PKG_URI."icons/silhouette.png";
}
$reply['feed_icon_url'] = $replyAvatarUrl;
}
//after loading up the thumbnails in the prior array layout for ease, we break up the array to split long comment threads
$MAX_SHOWN_REPLIES = 3;
if ( count( $status['replies'] ) > $MAX_SHOWN_REPLIES ){
$maxIteration = count( $status['replies'] ) - $MAX_SHOWN_REPLIES;
$i = 0;
foreach( $status['replies'] as $excess ){
if($i < $maxIteration){
$status['replies_excess'][$excess['content_id']] = $excess; //use content_id to index for consistency with normal replies array
unset($status['replies'][$excess['content_id']]); //remove from the normal replies array
}else{
break;
}
$i++;
}
}
$statuses[] = $status;
}
return $statuses;
}
function feed_get_status_and_actions( $pParamHash ) {
}
function feed_set_status( $pParamHash ){
global $gBitDb;
require_once ('FeedStatus.php');
$status = new FeedStatus();
global $gBitUser;
$pParamHash['root_id'] = $gBitUser->mContentId;
$pParamHash['parent_id'] = $gBitUser->mContentId;
$pParamHash['comment_data'] = $pParamHash['status_message'];
$pParamHash['title'] = substr($pParamHash['status_message'],0,20);
$status->storeComment($pParamHash);
}
?>