-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathossn_com.php
More file actions
110 lines (100 loc) · 3.21 KB
/
ossn_com.php
File metadata and controls
110 lines (100 loc) · 3.21 KB
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
<?php
/**
* Open Source Social Network
*
* @package (softlab24.com).ossn
* @author OSSN Core Team <info@softlab24.com>
* @copyright (C) SOFTLAB24 LIMITED
* @license Open Source Social Network License (OSSN LICENSE) http://www.opensource-socialnetwork.org/licence
* @link https://www.opensource-socialnetwork.org/
*/
define('__SEARCH_POSTS__', ossn_route()->com . 'SearchPosts/');
/**
* Initialize Component
*
* @return void;
* @access private
*/
function com_search_posts_init() {
ossn_extend_view('css/ossn.default', 'css/searchposts');
ossn_add_hook('search', 'type:posts', 'com_posts_search_handler');
ossn_register_callback('page', 'load:search', 'com_posts_search_link');
}
/**
* Online member search page handler
*
* @return mixdata;
* @access private
*/
function com_posts_search_handler($hook, $type, $return, $params) {
//only return possible result if user is logged in
if(ossn_isLoggedin()) {
$user = new OssnUser();
$friends = $user->getFriends(ossn_loggedin_user()->guid, array(
'page_limit' => false,
));
//add self user id so we can find self's posts too
$fuid_list = array(
ossn_loggedin_user()->guid,
);
if($friends) {
foreach ($friends as $friend) {
$fuid_list[] = $friend->guid;
}
}
$user_guid_loggedin = ossn_loggedin_user()->guid;
$friend_guids = implode(',', $fuid_list);
$wall = new OssnWall();
$query = input('q');
$subquery = "SELECT relation_from FROM ossn_relationships WHERE(type='group:join:approve' AND relation_to={$user_guid_loggedin})";
$search_options = array(
'search_type' => true,
'description' => $query,
'entities_pairs' => array(
array(
//emd0
'name' => 'access',
'value' => true,
'wheres' => '(1=1)',
),
array(
//emd1
'name' => 'poster_guid',
'value' => true,
'wheres' => "( (emd0.value=2) OR (emd0.value=3 AND [this].value IN({$friend_guids})) OR (emd0.value=1 AND o.type='group' AND o.owner_guid IN({$subquery}) ))",
),
),
);
if(ossn_isAdminLoggedin()){
//unconditional search
unset($search_options['entities_pairs']);
}
$posts = $wall->GetPosts($search_options);
// take currently in use query - plus count option in order to return the number of records found
$search_options['count'] = true;
// get count
$count = $wall->GetPosts($search_options);
$found['users'] = $posts;
$search = ossn_plugin_view('searchposts/search/view', $found);
$search .= ossn_view_pagination($count);
if(empty($posts)) {
return ossn_print('ossn:search:no:result');
}
return $search;
} else {
return ossn_print('ossn:search:no:result');
}
}
/**
* Add 'Posts' link on search page
*
* @return void;
* @access private
*/
function com_posts_search_link($event, $type, $params) {
$url = OssnPagination::constructUrlArgs(array(
'type',
));
ossn_register_menu_link('posts', 'com:searchposts:posts', "search?type=posts{$url}", 'search');
}
ossn_register_callback('ossn', 'init', 'com_search_posts_init');