Search Posts Download 1.4

us Jason Denang 3 months 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.

Comments
us Bansh33 - Replied 2 months ago

nice job =)

us Jason Denang Replied 2 months ago

Hey Bryce,
Yep, It's good to go!

us Bryce alvord Replied 2 months ago

Any more development on this to fix issues, I would love to have this component

German ~Z~ Man Replied 3 months ago

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()) { ....

German ~Z~ Man Replied 3 months ago

Another step ahead, yes!
Still irritating:

$count_options = array("search_type" => true, "description" => $query, "count" => true);

What is it good for?

us Jason Denang Replied 3 months ago

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

German ~Z~ Man Replied 3 months ago

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.)

German ~Z~ Man Replied 3 months ago
  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');
        }
German ~Z~ Man Replied 3 months ago

Hi Jason,

great improvement on privacy in 1.2, but still issues with the pagination if a 'normal' user is logged in.
If you have a look into some classes you'll find that throughout Ossn adding a count=true to a query will return the number of records found instead of the data itself. But of course it always depends on the base query how many records will be returned.
That said, you can not use the admin base query for counting all the time, but you need to adapt it to your different rules when a normal user is logged in.
Otherwise you'll get a lot of pagination tabs at the bottom but no postings behind. So the corrected code should look something like this ...

us Jason Denang Replied 3 months ago

Hi Z-Man,
I can not believe I did that. I checked the zip that I made last night and it did in fact contain the core search file. That is too funny. I have zipped and uploaded the correct fileset. LMAO!

Best,
Jason

Component

Developer: Jason
License ossnv3
Type: Communication
Ossn Version: 5.x
Latest Version: 1.4
Last Updated 3 months ago
Repository Url View Repository

Versions