Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Custom Variables for Search Function: Update displayimage.php Links  (Read 4399 times)

0 Members and 1 Guest are viewing this topic.

vfh

  • Coppermine newbie
  • Offline Offline
  • Posts: 7

Gallery: http://theflooringmill.com/coppermine/index.php

I've modified the search function to meet our specific needs, and that included adding custom fields.  I've gotten the thumbnails.php result page to function correctly, including links to the displayimage.php pages.  However, on the displayimage.php page itself I'm having trouble getting links to other images in the search gallery to update properly.

For example: http://theflooringmill.com/coppermine/displayimage.php?album=search&cat=0&pid=167&woods[]=eastern%20white%20pine&woods[]=hard%20maple&type=custom#top_display_media
(sorry, the url tags don't work properly because of the brackets in the GET section)
I haven't been able to get any of the start/previous/next/end links updated to include my custom search variables, and the javascript filmstrip previous/next links no longer update the images either.

As far as I can tell, displayimage.js (http://coppermine.svn.sourceforge.net/viewvc/coppermine/trunk/cpg1.5.x/js/displayimage.js?revision=8197&view=markup) is the source of those links.  I've added my custom variables to the end of the following variables:
  • Line 87: link cache
  • Line 151: next url
  • Line 156: link cache
  • Line 256: prev url
  • Line 259: link cache
A simple javascript alert has me ensured that the links in the link cache are correct, but none of the actual links on the page are the links in the link cache.

I would appreciate any help on how to update these links to include my custom variables.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765
Re: Custom Variables for Search Function: Update displayimage.php Links
« Reply #1 on: April 29, 2011, 06:46:00 pm »

I haven't looked at the code yet because I'm currently short of time. But here some background how the search works. If you click the search button you'll be redirected to the thumbnails.php page. All  (standard) search variables are stored in a cookie and will be read from there on all following pages. Maybe you have to extend that array so your own variables are stored in that cookie, too. Maybe the same applies when reading the cookie. If you need further help/explanations, please let me know.
Logged

vfh

  • Coppermine newbie
  • Offline Offline
  • Posts: 7
Re: Custom Variables for Search Function: Update displayimage.php Links
« Reply #2 on: April 29, 2011, 09:47:09 pm »

Thanks for your quick reply!

I haven't been able to figure out where any cookies are set on the thumbnails page.  Also, in all my exploring, it seems to me that only approved variables are being added anyway (although I could be completely wrong).

Take for example the display_film_strip function (in functions.inc.php line 3157), called from displayimage.php line 491 - it takes 4 parameters and builds a target link (line 3282 directly / line 3311 with a call to theme_display_film_strip - themes.inc.php line 3012 - on line 3061).

I only discovered the above function(s) after I posted my question.  I've done some testing, and modifying these links directly correctly updates the filmstrip links.  However, I'm still not sure how the start/previous/next/end links are being set.  Also, I'd really prefer not to change the number of arguments to the functions (in my testing I just hardcoded in an example) - that would require changing all the function calls, and that is completely undesirable.  Any suggestions on how to proceed?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765

The cookies is set within the function user_save_profile and is read inside the function user_get_profile (both in include/functions.inc.php). As you can see the whole content of $USER will be saved. That array will be filled with content in thumbnail.php:
Code: [Select]
if ($superCage->get->keyExists('search')) {

    // find out if a parameter has been submitted at all
    $allowed = array('title', 'caption', 'keywords', 'filename', 'pic_raw_ip', 'pic_hdr_ip', 'user1', 'user2', 'user3', 'user4', 'type');

    foreach ($allowed as $key) {
        if ($superCage->get->keyExists($key)) {
            $USER['search']['params'][$key] = $superCage->get->getEscaped($key);
        } else {
            unset($USER['search']['params'][$key]);
        }
    }
   
    //here again the use of getRaw, but it will be sanitized in search.inc.php
    $USER['search']['search'] = utf_replace($superCage->get->getRaw('search'));
    $USER['search']['search'] = str_replace('"', '\'', $USER['search']['search']);
    $album = 'search';
}

It might work if you extend/adjust the $allowed array.
Logged

vfh

  • Coppermine newbie
  • Offline Offline
  • Posts: 7

Thanks so much for your time helping me with this.  Unfortunately, extending the $allowed array didn't change the links.  Any other suggestions?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765

You may want to compare the $USER array before it will be written to the cookie and after it will be read from the cookie. I currently don't know which files you modified (besides search.php), so it might help if you attach your modifications as zip file to your next reply
Logged

vfh

  • Coppermine newbie
  • Offline Offline
  • Posts: 7

I've printed the $USER array on both thumbnails.php and displayimage.php, and it seems to be in working order.

See attached for my modified code.

Here is a list of my modifications (I'm pretty sure that some of them are unnecessary - I would change some code, and if it didn't work I'd change some code elsewhere).

search.inc.php
line 55: get GET vars for extraction of custom vars (no longer needed if cookie is set)
lines 84 - 130: extract custom vars and set search SQL accordingly

functions.inc.php
lines 1810 - 1824: get_pic_data: header for thumbnails.php to include custom vars (e.g. "Image search results - whatever")
lines 3296 - 3297: display_film_strip: manually change filmstrip picture links to include custom vars

themes.inc.php
lines 2858 - 2877: theme_display_thumbnails: reconstruct custom vars for GET section of URL
line 2970: theme_display_thumbnails: add custom vars to thumbnail link
lines 3082 - 3083: theme_display_film_strip: manually change filmstrip picture links to include custom vars

search.php
line 38: change number of columns
lines 72 - 153: replace search input with custom search input

thumbnails.php
line 75: add custom vars to $allowed array
lines 85-87: print $USER
lines 190 - 203: header for thumbnails.php to include custom vars (e.g. "Image search results - whatever")

displayimage.php
lines 45 - 51: print $USER
lines 403 - 422: reconstruct custom vars for GET section of URL
line 428: set js var for custom vars

displayimage.js
line 32: get custom vars
line 102 - 103: add custom vars to end of link cache URL and alert via js
line 167: add custom vars to end of next_url link
line 172: add custom vars to end of link cache URL
line 273: add custom vars to end of prev_url link
line 276: add custom vars to end of link cache URL
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765

extending the $allowed array didn't change the links.
The links don't need to change, as all relevant data will be read from the cookie (have a look how the default search works). Your changes in thumbnails.php extends the array as expected. This is an excerpt of the $USER array available at every Coppermine page (e.g. index.php) after you searched something:
Code: [Select]
    [search] => Array
        (
            [params] => Array
                (
                    [keywords] => on
                    [type] => custom
                    [woods] => Array
                        (
                            [0] => butternut
                            [1] => heart pine
                        )

                    [grades] => Array
                        (
                            [0] => prime
                            [1] => quartered
                        )

                    [other] => Array
                        (
                            [0] => stain
                        )

                )

            [search] => yes
        )

I currently haven't tested further, as I don't have matching data in my test gallery. But I assume with the little information that the links should be okay as they are you can complete your modification?
Logged

vfh

  • Coppermine newbie
  • Offline Offline
  • Posts: 7

Oh, okay!  Sorry I didn't understand you earlier.  Everything is working fine now.  Thanks so much!  =)
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765

tag your answer as "solved" by clicking on the little image in your initial posting on your thread.
Thanks.
Logged
Pages: [1]   Go Up
 

Page created in 0.022 seconds with 21 queries.