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.
Hey Jason,
I am wondering if I could have permission to fork your code OR enhance it with a pull request. I wanted to add some more ways to search for posts and this seems like a great start to what I had in mind. Your thoughts?
Bryce
I have a small translation issue with this component: https://www.opensource-socialnetwork.org/discussion/view/3549/search-posts-cannot-find-the-locale-for-view-post
nice job =)
Hey Bryce,
Yep, It's good to go!
Any more development on this to fix issues, I would love to have this component
Next: You can't always be sure your site is accessed from a logged in user. Log off and try
https://yoursite.com/search?type=posts
and most likely you'll get a crash
You'd better make use of if(ossn_isLoggedin()) { ....
Another step ahead, yes!
Still irritating:
$count_options = array("search_type" => true, "description" => $query, "count" => true);
What is it good for?
Hi Z-Man,
Thanks for the help with this. Moving the friends part into !isadmin of course only saves time and resources for admin users, but still a good call. Thank you for helping me understand the pagination a bit better. I have uploaded V1.3 ;)
Best,
Jason
Aside from that you should think about moving your friends part completely inside the !ossn_isAdminLoggedin() condition to avoid unnecessary queries if the admin is logged in. Actually I don't think this is the final solution anyway because it's missing all public records.
(Sorry, but I was unable to post the complete stuff all in one.)
if(ossn_loggedin_user()->guid){
//bof build array of friends user id's
$user = new OssnUser;
$friends = $user->getFriends(ossn_loggedin_user()->guid);
//add self user id so we can find self's posts too
$fuid_list = array(ossn_loggedin_user()->guid);
// suppress PHP warning if we have no friends !
if ($friends) {
foreach($friends as $friend){
$fuid_list[] = $friend->guid;
}
}
//eof build array of friends user id's
$wall = new OssnWall;
$query = input('q');
$search_options = array("search_type" => true, "description" => $query);
//if not admin user add where caluse to limit reach
if(!ossn_isAdminLoggedin()){
$search_options['wheres'] = 'owner_guid IN ('.implode(",",$fuid_list) .')';
}
// since we use 2 different (admin/no admin) record queries now, we can't stay with only 1 count query any longer
// $count_options = array("search_type" => true, "description" => $query, "count" => true);
// get posts
$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);
// $data = $posts; no idea for what reason we need an extra array here ?
$found['users'] = $posts;
// $found['count'] = $count; no idea why this is passed to the view.php ? there's no 'count' being use in the code
$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');
}