Jul 05, 2009, 08:45 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Donate to MODx: Donations
Pages: [1]   Go Down
  Print  
Author Topic: [Snippet] FlexSearchForm. Modified to hide private docs and add weblink feature.  (Read 4718 times)
0 Members and 1 Guest are viewing this topic.
steph
Member
**
Posts: 85


WWW
« on: Apr 30, 2006, 07:09 PM »

Update 05//02/2007: Fixed two problems whereby php complained that a function was being declared twice or didn't exist.

Update 11/07/2006: I've replaced the attached zip file with 3 new ones - a zip, a gzip and a txt - because people were having problems unzipping the original.

Hi all.

I've modified the FlexSearchForm snippet to support the following:

  • Access control, i.e. hide private documents if the user doesn't have permission to view them. This functionality uses code lifted from the MODx getDocumentObject method in document.parser.class.inc.php.
  • Added better support for weblinks.

The new parameters are as follows:

&useWeblink - [ true | false ] If true and the doc is of type 'reference', link to the doc's weblink (it's 'content' field) rather than to the doc itself. Defaults to false.

&weblinkClass - [ string ] CSS class for a weblink's anchor. Defaults to "weblink".

Note that the code I modified was that of MadeMyDay's (posted on the MODx forums at http://modxcms.com/forums/index.php/topic,2762.0.html) which added support for showing an extract of the context with highlighted search terms. The display of content extracts makes it particularly important to prevent private documents being listed to those without permission to view them.

Steph

* FlexSearchFormMindspillDotNet.php.txt (20.01 KB - downloaded 191 times.)
« Last Edit: Feb 05, 2007, 05:45 PM by steph » Logged

0ad
Full Member
***
Posts: 110


« Reply #1 on: Jul 06, 2006, 08:15 AM »

Hi

Thanks for sharing, but the zip seems to corrupt when i download it, is it a problem for anyone else?

Cheers

0
Logged

Please consider the research and evidence of the Scholars for 9/11 Truth at http://www.st911.org
steph
Member
**
Posts: 85


WWW
« Reply #2 on: Jul 06, 2006, 09:23 AM »

Just tried downloading and unzipping. Worked fine for me. Can you try a different zip program?
Logged

0ad
Full Member
***
Posts: 110


« Reply #3 on: Jul 06, 2006, 09:58 AM »

no joy for me with winrar or winxp's own zip uncompress thing, i'll PM you my email address.

cheers

0
Logged

Please consider the research and evidence of the Scholars for 9/11 Truth at http://www.st911.org
rodsor
Jr. Member
*
Posts: 5



« Reply #4 on: Jul 09, 2006, 07:30 AM »

Same error with me. I´m using 7-zip.
Logged
doze
Coding Team
*
Posts: 3,662


....Boom!


« Reply #5 on: Jul 09, 2006, 04:26 PM »

Opens ok with winrar though..
Logged

New MODx wiki! Please help up with documentation efforts! || Old Wiki
rodsor
Jr. Member
*
Posts: 5



« Reply #6 on: Jul 10, 2006, 12:07 PM »

Doze, can you post the snippet code here? I still can´t open the file...

Thx.
Logged
steph
Member
**
Posts: 85


WWW
« Reply #7 on: Jul 11, 2006, 03:37 AM »

Done. See original post.
Logged

rodsor
Jr. Member
*
Posts: 5



« Reply #8 on: Jul 12, 2006, 06:15 AM »

Thanks guys. Now I can view the snippet (only the txt). But after changing the snippet code, the following error ocurrs:

Fatal error: Cannot redeclare preparesearchcontent() (previously declared in C:\Apache2\htdocs\manager\includes\document.parser.class.inc.php(705) : eval()'d code:466) in C:\Apache2\htdocs\manager\includes\document.parser.class.inc.php(705) : eval()'d code on line 475

How to correct this?
« Last Edit: Jul 12, 2006, 06:20 AM by rodsor » Logged
steph
Member
**
Posts: 85


WWW
« Reply #9 on: Jul 12, 2006, 06:56 AM »

Function PrepareSearchContent is being declared (aka defined) twice. Are you using two different versions of the FlexSearchForm at the same time?
Logged

rodsor
Jr. Member
*
Posts: 5



« Reply #10 on: Jul 12, 2006, 07:26 AM »

No, I only replaced the original code of snippet with this, on original installation.
Logged
steph
Member
**
Posts: 85


WWW
« Reply #11 on: Jul 12, 2006, 09:11 AM »

As mentioned in my original post I modified MadeMyDay's version, which added the PrepareSearchContent function.
Quote
Note that the code I modified was that of MadeMyDay's (posted on the MODx forums at http://modxcms.com/forums/index.php/topic,2762.0.html) which added support for showing an extract of the context with highlighted search terms
Perhaps you'll find an answer on that thread.

Either way, you're declaring the function twice, so look through the snippets you use to find out which ones define it.
Logged

steph
Member
**
Posts: 85


WWW
« Reply #12 on: Feb 05, 2007, 05:39 PM »

 Grin It's been a while, but I've just hit this problem again and I know the proper solution now. I was right in saying that the snippet was being referenced twice, but that was a dumb thing to say because a search snippet is often referenced twice - perhaps once in a menu and once in the content of the results page. The solution is to check whether the function exists before declaring it. So, for every function, surround it with a function_exists call, like so:

Code:
if (!function_exists('TheFunction')) {
    function TheFunction {
    ...
    }
}

I've posted about it here too: http://modxcms.com/forums/index.php?PHPSESSID=7cbbcac1ace4d6f9ab1b016372362893&topic=9332.msg%25msg_id%25

Also, after migrating my site to a different server, which uses a different version of PHP, I found that you can't get away with declaring the functions at the end of the file without generating the following error:

Code:
Call to undefined function

The solution seemed to be to move the function declarations to the top. Note that whilst this solved the problem, I tried rolling back to reproduce the exact error, but it still seems to work despite using the old version. I've been getting odd caching behaviour ever since migrating so who knows?!

I've updated the download links in my first post to reflect the latest version I have.
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF | SMF © 2006-2008, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!