Arsalan Shah
7 years ago
This component allows users to search for text that was used in a post that was written to the wall or to a group. Adds a "view post" button to each returned result. Adds a "Posts" link to the search menu.
2.3
Updated to make it work on latest version $arsalanshah
Know issue
Melo lobo
Replied 4 years ago
Good morning Michael
the SearchPost component is ready. it works correctly, it allows the search in all posts of the website without displaying the 'friends only' posts of members who are not friends. Can you show me where I can upload it to Github? I just created an account there and really the many buttons and links make me dizzy, I don't know where to go
Melo lobo
Replied 4 years ago
ah, I didn't know that it could cause conflict.. I'm going as you told me
Michael Zülsdorff
Replied 4 years ago
Without having a closer look into it:
Adding something to other component's or even core's classes is a no-go :))
This would introduce dependencies nobody wants to fight with.
So, implement it as a new SearchPost class, extending what you need (OssnWall or maybe OssnObject) like
class SearchPosts extends OssnObject { .....
Melo lobo
Replied 4 years ago
PART 2
$options = array_merge($default, $params);
$attrs = ossn_call_hook('wall', 'getFriendsPosts', $extra_param, $options);
$default_public = array(
'type' => 'user',
'subtype' => 'wall',
'order_by' => 'o.guid DESC',
'entities_pairs' => array(
array(
'name' => 'access',
'value' => true,
'wheres' => '(1=1)',
),
array(
'name' => 'poster_guid',
'value' => true,
'wheres' => "((emd0.value=2) OR (emd0.value=3 AND [this].value IN({$friend_guids})))",
),
),
);
$extra_param_public = array(
'friends_guids' => $friend_guids,
'user' => $user,
);
$options_public = array_merge($default_public, $params);
$attrs_public = ossn_call_hook('wall', 'getPublicPosts', $extra_param_public, $options_public);
$attrs = array_merge($attrs, $attrs_public);
return $this->searchObject_posts($attrs);
}
return false;
}
Melo lobo
Replied 4 years ago
As I'm not experienced in Github I'm going to split the SearchPosts() function here in two parts (a bit extreme solution and sorry to have damaged the page by this kind of distributed comments). the SearchPosts() function to add in OssnWall/Classes.
PART1
public function SearchPosts($params = array()){
$user = ossn_loggedin_user();
if(isset($user->guid) && !empty($user->guid)){
$friends = $user->getFriends();
//operator not supported for strings #999
$friend_guids = array();
if($friends){
foreach ($friends as $friend){
$friend_guids[] = $friend->guid;
}
}
$friend_guids[] = $user->guid;
$admins = ossn_get_admin_users();
if($admins){
foreach ($admins as $item){
if(!in_array($item->guid, $friend_guids)){
$friend_guids[] = $item->guid;
}
}
}
$friend_guids = implode(',', $friend_guids);
$default = array(
'type' => 'user',
'subtype' => 'wall',
'order_by' => 'o.guid DESC',
'entities_pairs' => array(
array(
'name' => 'access',
'value' => true,
'wheres' => '(1=1)',
),
array(
'name' => 'poster_guid',
'value' => true,
'wheres' => "((emd0.value=2 OR emd0.value=3) AND [this].value IN({$friend_guids}))",
),
),
);
$extra_param = array(
'friends_guids' => $friend_guids,
'user' => $user,
);
Michael Zülsdorff
Replied 4 years ago
yes, this forum isn't really meant for posting longer program code - I'd suggest to put the complete component onto Github instead.
Melo lobo
Replied 4 years ago
I try to share the function SearchPosts($params = array()) but the site answers me 'Can't apply comment I don't know how to share it. in reality the SearchPosts() function is a mix of the two already existing functions getFriendsPosts() and getPublicPosts()
Melo lobo
Replied 4 years ago
I think I found a solution but that requires your approval of course. I modified the ossn_com file as follows:
$wall = new OssnWall;
$query = input('q');
$search_options = array("search_type" => true, "description" => $query, 'type' => 'user',
'distinct' => true);
//if not admin user add where caluse to limit reach
if(!ossn_isAdminLoggedin()){
$posts = $wall->SearchPosts($search_options);
$search_options['count'] = true;
$count = $wall->SearchPosts($search_options);
}else{
$posts = $wall->getAllPosts(array('search_type' => true,
'description' => $query,
'type' => 'user',
'distinct' => true));
$count = $wall->getAllPosts(array(
'search_type' => true,
'description' => $query,
'type' => 'user',
'distinct' => true,
'count' => true,
));
}
$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;
Melo lobo
Replied 4 years ago
I will do my best. If I find a reliable solution, I will not hesitate to share it
Michael Zülsdorff
Replied 4 years ago
Melo,
I might be wrong, but it seems that Jason discontinued working on this component. So could YOU provide a fix perhaps?