Advertisement:

Author Topic: Search in public profile  (Read 3680 times)

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Search in public profile
« on: November 11, 2017, 10:00:25 pm »
Hi,
i wanna put a text-box in user-public-profile.php to Search in just that public profile's items (theme bender)
just search the items and list them on user-public-profile.php page.
simple search is enough. no need to have filters.
please help me to do this
Thanks


« Last Edit: March 08, 2019, 11:45:08 am by Sophia_OS »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search in public profile
« Reply #1 on: November 14, 2017, 10:15:16 pm »
Hi.
You could make an input field that onclick submit redirects to:

 yoursite.com/search/sOrder,dt_pub_date/iOrderType,desc/user,1/pattern,key_word

1 from above is the item_id.
key_word is the searched patern for 1 word.
for 2 or more words, add the words with + : word1+word2+..


But the count of the results doen't work and the pagination also doesn't work.

EDIT.
I've looked into the code and the search by user seems to be implemented but I couldn't figure out why the pagination and item results count doesn't work .

If these 2 issues could be resolved, then with a simple uri check , a message could be displayed into the search page that the results are from the user-id/username.
« Last Edit: November 14, 2017, 11:06:44 pm by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search in public profile
« Reply #2 on: November 14, 2017, 11:10:07 pm »
I found the issue:
EDIT I didn't.
yoursite.com/search/sOrder,dt_pub_date/iOrderType,desc/suser,1/pattern,key_word

I think these 2 issues are related with this https://forums.osclass.org/development/admin-items-filter-by-email-not-showing-pagination-modern-theme-3-7-1/
« Last Edit: November 15, 2017, 12:01:14 am by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search in public profile
« Reply #3 on: November 15, 2017, 09:27:17 pm »
EDITED to resolve page being transfered to the new url in search page.
So, if you make the mod suggested by Teseo (for solving the pagination and results count issues) here:
https://forums.osclass.org/development/admin-items-filter-by-email-not-showing-pagination-modern-theme-3-7-1/msg157903/#msg157903

A solution would be (with permalinks enabled! ):

1. oc-content/themes/bender/search.php

Add mention that the results are from user's items + link

Put: edited REQUEST_URI - > 'REQUEST_URI'

Code: [Select]
<?php osc_current_web_theme_path('header.php') ; ?>
<?php if(strpos($_SERVER['REQUEST_URI'], 'user,') !== false)
{
$rest substr($_SERVER['REQUEST_URI'], (strpos($_SERVER['REQUEST_URI'], 'user,')+5)  );
preg_match('/\d+/'$rest$matches);
$usr User::newInstance()->findByPrimaryKey($matches[0]);
echo 
'Results from <a href="'.osc_user_public_profile_url($matches[0]).'">' $usr['s_name'] . '</a> items:';  //replace the english words if needed.
}
?>

     <div class="list-header">
     
     
instead of:

Code: [Select]
<?php osc_current_web_theme_path('header.php') ; ?>
     <div class="list-header">


2.oc-content/themes/bender/user-public-profile.php

put:

Code: [Select]
    <?php echo nl2br(osc_user_info()); ?>
    <?php if( osc_count_items() > ) { ?>
        <div class="main-search" style="display:block;position:relative;width:100% !important;">
            <div class="cell">
                <input class="input-text" placeholder="Search in user's items" id="inputuisearch" type='text' />
            </div>
            <div class="cell">
              <button onclick="fus();" class="ui-button ui-button-big"><?php _e("Search"'bender');?></button>
            </div>
        </div>

    <script>
    document.getElementById("inputuisearch").addEventListener("keydown", function (e) {
    if (e.keyCode === 13) {  //checks whether the pressed key is "Enter"
        fus();
    }
    });
    function fus() {
    var uisearch = $("#inputuisearch").val();
    if(uisearch.indexOf(" ") > 0){
    var arrsearch = uisearch.split(" ");
    uisearch = arrsearch.join("+");
    }
    var uriuisearch="/search/pattern," + uisearch + "/user," + <?php echo osc_user_id();?> ;
    window.location=<?php echo '"'; echo (isset($_SERVER['HTTPS']) ? 'https' 'http') . "://" $_SERVER['HTTP_HOST']; echo '"';?> + uriuisearch;
    }
    </script>
    <div class="similar_ads">
   
instead of

Code: [Select]
    <?php echo nl2br(osc_user_info()); ?>
    <?php if( osc_count_items() > ) { ?>
    <div class="similar_ads">

It may be necesary to style a litle the above code or bender's code in order to look 100% ok.
« Last Edit: December 11, 2017, 01:41:42 pm by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search in public profile
« Reply #4 on: November 15, 2017, 09:37:24 pm »
EDITED to solve the page being transfered to the new url in search page
And if you want the search bar in user-items.php (when user is logged in):

/oc-content/themes/bender/user-items.php

put:

Code: [Select]
    <?php if(osc_count_items() == 0) { ?>
        <p class="empty" ><?php _e('No listings have been added yet''bender'); ?></p>
    <?php } else { ?>
   
    <div class="main-search" style="display:block;position:relative;width:100% !important;">
        <div class="cell">
            <input class="input-text" placeholder="Search into my published items" id="inputuisearch" type='text' />
        </div>
        <div class="cell">
          <button onclick="fus();" class="ui-button ui-button-big"><?php _e("Search"'bender');?></button>
        </div>
    </div>

    <script>
    document.getElementById("inputuisearch").addEventListener("keydown", function (e) {
    if (e.keyCode === 13) {  //checks whether the pressed key is "Enter"
        fus();
    }
    });
    function fus() {
    var uisearch = $("#inputuisearch").val();
    if(uisearch.indexOf(" ") > 0){
    var arrsearch = uisearch.split(" ");
    uisearch = arrsearch.join("+");
    }
    var uriuisearch="/search/pattern," + uisearch + "/user," + <?php echo osc_user_id();?> ;
    window.location=<?php echo '"'; echo (isset($_SERVER['HTTPS']) ? 'https' 'http') . "://" $_SERVER['HTTP_HOST']; echo '"';?> + uriuisearch;
    }
    </script>
   
        <div class="actions">


instead of:
Code: [Select]
    <?php if(osc_count_items() == 0) { ?>
        <p class="empty" ><?php _e('No listings have been added yet''bender'); ?></p>
    <?php } else { ?>
        <div class="actions">

EDIT:

Or if you want the search results to be shown in new window (On "enter" some browsers block the popup....but on click it's working fine):

Put:

    var uriuisearch=<?php echo '"'; echo (isset($_SERVER['HTTPS']) ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST']; echo '"';?> + "/search/pattern," + uisearch + "/user," + <?php echo osc_user_id();?> ;
    window.open( uriuisearch , '_blank');


Instead of:
Code: [Select]
    var uriuisearch="/search/pattern," + uisearch + "/user," + <?php echo osc_user_id();?> ;
    window.location=<?php echo '"'; echo (isset($_SERVER['HTTPS']) ? 'https' 'http') . "://" $_SERVER['HTTP_HOST']; echo '"';?> + uriuisearch;
« Last Edit: December 11, 2017, 01:42:07 pm by marius-ciclistu »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search in public profile
« Reply #5 on: November 19, 2017, 02:32:02 am »
thank you @marius-ciclistu
but it didn't work for me
by the way my theme is modern

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search in public profile
« Reply #6 on: November 19, 2017, 10:39:58 am »
Then you must adapt the code for modern. I tested it. It workes fine. Thank you for the ideea.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search in public profile
« Reply #7 on: November 20, 2017, 02:17:54 am »
Then you must adapt the code for modern. I tested it. It workes fine. Thank you for the ideea.


@marius-ciclistu
Please help me to do for modern theme too

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search in public profile
« Reply #8 on: November 20, 2017, 10:15:35 am »
I don't have modern...can yoy atach an archive with your modern php files that I mentioned in my solution?

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search in public profile
« Reply #9 on: November 20, 2017, 06:45:51 pm »
Or just checking:

1.Do you have permalinks enabled?

2.How does the url look like when you view the results of a search into your site?

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search in public profile
« Reply #10 on: November 22, 2017, 03:21:03 am »
@marius-ciclistu

1.Do you have permalinks enabled? YES

2.How does the url look like when you view the results of a search into your site?
mysite.com/search/pattern,test+search/sOrder,dt_pub_date/iOrderType,desc/country,US/region,357397/city,257456/category,3

3.Modern theme:
https://market.osclass.org/themes/general/modern_77

Thank you Marius

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search in public profile
« Reply #11 on: November 22, 2017, 11:05:26 am »
2. I'm interested in the url not the looks.
Search something in your site and paste the uri here(without http://yoursite.com in front).

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search in public profile
« Reply #12 on: November 23, 2017, 02:24:45 am »
2. I'm interested in the url not the looks.
Search something in your site and paste the uri here(without http://yoursite.com in front).

I searched "test search" and select usa, california, los Angeles for location:

mysite.com/search/pattern,test+search/sOrder,dt_pub_date/iOrderType,desc/country,US/region,357397/city,257456/category,3

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search in public profile
« Reply #13 on: November 23, 2017, 11:40:55 am »
Seems ok.

Remember to make Teseo's mod in the core if you are using 3.7.x.

Now, for modern:

Edit
search.php

find

Code: [Select]
            <div id="main">
replace with

Code: [Select]
            <div id="main">
<?php if(strpos($_SERVER['REQUEST_URI'], 'user,') !== false)
{
$rest substr($_SERVER['REQUEST_URI'], (strpos($_SERVER['REQUEST_URI'], 'user,')+5)  );
preg_match('/\d+/'$rest$matches);
$usr User::newInstance()->findByPrimaryKey($matches[0]);
echo 
'Results from <a href="'.osc_user_public_profile_url($matches[0]).'">' $usr['s_name'] . '</a> items:';  //replace the english words if needed.
}
?>


edit user-public-profile.php


find

                <div id="description" class="latest_ads">

replace it with

Code: [Select]
        <div class="main" style="display:block;position:relative;width:100% !important;">

                <input  placeholder="Search in user's items" id="inputuisearch" type='text' />

            <div>
              <button onclick="fus();" class="button"><?php _e("Search"'bender');?></button>
            </div>
        </div>

    <script>
    document.getElementById("inputuisearch").addEventListener("keydown", function (e) {
    if (e.keyCode === 13) {  //checks whether the pressed key is "Enter"
        fus();
    }
    });
    function fus() {
    var uisearch = $("#inputuisearch").val();
    if(uisearch.indexOf(" ") > 0){
    var arrsearch = uisearch.split(" ");
    uisearch = arrsearch.join("+");
    }
    var uriuisearch="/search/pattern," + uisearch + "/user," + <?php echo osc_user_id();?> ;
    window.location.pathname=uriuisearch;
    }
    </script>
                <div id="description" class="latest_ads">

PS.
I did not test to see how it looks in modern.
« Last Edit: November 23, 2017, 11:44:05 am by marius-ciclistu »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search in public profile
« Reply #14 on: November 24, 2017, 07:14:16 am »
Thank you very much marius

there is two problems:

1 - when you Search in "user-public-profile.php", you redirect to "search.php" and see the user's items in search list, which is good. but again when you search for something else in search.php, it searches in that user's items not in all the website. what can i do to search in all users if i search again? basically i just want to search in users item when i search in public-profile, and when i'm in search.php it searchs in all users.

2 - when you Search in "user-public-profile.php", you redirect to "search.php" and see the user's item in search list, but it shows just one page. it does not show all the results in pagination. it jut show first page.

Note: can i see the result of search in the same page in "user-public-profile.php" where all the user's items are listed? this would be very good

Thanks