Search in mambo/smf-forums/coppermine-gallery

Started by bmwheaven, March 25, 2005, 03:46:38 PM

Previous topic - Next topic

bmwheaven

Quote from: d3v on May 30, 2005, 07:05:22 AM
Is it possible to make this without the dropdown box (Articles/Forum) but rather just one search box that would search both and show results for both on the same page? Thank you.
Might be possible... but don't know how...
Probably with a bot, but don't have the time to find out.
The drop-down works fine for me, don't have enough knowledge bout mambo/smf... sry
Sh*t happens
All the time

rjprince

I've made three searchbots, and am willing to write one for SMF. However, if someone could point me to some SMF development resources, it would save me a lot of time. What I need:

1.) I use Mambo's built-in db functions for accessing the database. I will need a pointer to a quick overview on SMF's. Basically, how is prexif substitution handled, does SMF automatically escape quote characters, etc.? Just one example of a function that makes a db call will probably suffice or the filename and line number of such a function.

2.) The names of the tables and fields to be searched. My first cut would just search posts, not events or calendar items, so I assume subject, thread title, and post content would be the fields I need. If someone can point me to an ERD or a data dictionary, I can find what I need.

3.) How to link to specific posts within a thread - preferably an API function to do so

I'm sure I could figure this out, but I first looked at SMF yesterday. If someone can point me to these items, I have a good shot at getting a version out by the end of the weekend.

Basically, I'm proposing I take advantage of someone else's expertise in SMF so I can use my knowledge of searchbots to get this out quickly.

Thanks!

Orstio

Thanks for taking the time to look into this, Rjprince.

If you download the bridge package, there is a folder called "misc modules".  In it you will find a module called "Related Topics", that searches SMF's messages for items related to the current article.  That should help you with all three of your concerns.  ;)

rjprince

OK, I've got a basic start working. If you want to see it working, check out www. princeclan.org. Type in some search term about Harry Potter - it's the only thread active right now on my site. Technically it's a private forum, so SMF won't let you into the posts, but you can see what the results look like.

There a couple of problems:

1.) I included $db_prefix in the globals declaration, but it didn't have a value. I've hardcoded it for now, but obviously that's undesirable. How does $db_prefix get its value? It's possible search mambots run before the smf code that sets it is run, in which case we might have trouble with this.

2.) Is there a quick rundown on how you all do the date/time fields? I need to know:
    a. if I can sort on the int fields you use as dates to get get correct date ordering and
    b. how to format the date.
Quick pointer to code should be all I need.

3.) Possibly much bigger deal: I'd like the search to respect current permissions. Is there a way in SQL code to select boards based on the current user's permissions? The query for the boards to show would probably

4.) To implement that, I'm assuming I'll need the smf member ID. Again, quick pointer to code that checks to see if anyone is logged in and retrieves the ID would be great.

Again, if you guys don't know this stuff off the top of your head, I can dig for it. But it's always easier to ask the developers.

If all goes well, I'll release this as an early test tomorrow night. 3 and 4 are pretty much showstoppers for me, and 2 is just ugly right now. I will need testers with more substantial numbers of posts and hopefully someone who has mambo and smf in separate databases. So let me know if you want to try it and I'll PM you the link to the code late tomorrow night.

There are 3 display elements in a mambot search results list: title (which is the link to the item - I'm using the subject of the message plus the memberName of the poster), section (the name of the board), and description (the title of the first message in the topic plus the first 200 letters of the post). Suggestions on these elements are welcome.

And please disregard the ugliness. I'll be retheming later. :)

[Unknown]

Quote from: rjprince on July 30, 2005, 12:45:02 AM
1.) I included $db_prefix in the globals declaration, but it didn't have a value. I've hardcoded it for now, but obviously that's undesirable. How does $db_prefix get its value? It's possible search mambots run before the smf code that sets it is run, in which case we might have trouble with this.

I think it may be in the mos_smf.php configuration file... I'm afraid I'm not sure though, and am more responding to your other questions.

Quote2.) Is there a quick rundown on how you all do the date/time fields? I need to know:
    a. if I can sort on the int fields you use as dates to get get correct date ordering and
    b. how to format the date.
Quick pointer to code should be all I need.

They're just unix timestamps.  They're ascending by time (0 = December 31, 1969...) but so are the ids (ID_MSG, etc. start at 1 = earliest and go up by time) which is what I would strongly recommend sorting on (much faster.)

To format the date, you can either use PHP's time functions (strtotime(), time(), etc. - it's just seconds so arithmetic is easy) or MySQL's, FROM_UNIXTIME() and UNIX_TIMESTAMP().

It's really not meant to be complicated ;).

Quote3.) Possibly much bigger deal: I'd like the search to respect current permissions. Is there a way in SQL code to select boards based on the current user's permissions? The query for the boards to show would probably

Indeed, this might be more complicated.  You can find the code used in Load.php, search for query_see_board.  As long as the boards table is aliased as "b", this query will check basic permissions for you.  To see if they can reply, etc... is a bit more complicated.

Quote
4.) To implement that, I'm assuming I'll need the smf member ID. Again, quick pointer to code that checks to see if anyone is logged in and retrieves the ID would be great.

Again, yes, this is all stuff that needs SMF.  You might try using SSI.php (which will give you everything you need, and access to $ID_MEMBER, $user_info, allowedTo(), etc.), which may not conflict with things as long as the search you're writing and SMF do not show on the same page at once.

-[Unknown]

Orstio

Quote1.) I included $db_prefix in the globals declaration, but it didn't have a value. I've hardcoded it for now, but obviously that's undesirable. How does $db_prefix get its value? It's possible search mambots run before the smf code that sets it is run, in which case we might have trouble with this.

Grr...This is because Mambo goes through all the bot code first, before reading the template.  You're probably best including $mosConfig_live_site/administrator/components/com_smf/config.smf.php and then including $smf_path/Settings.php.  That should give a definition for $db_prefix.

QuoteQuote
4.) To implement that, I'm assuming I'll need the smf member ID. Again, quick pointer to code that checks to see if anyone is logged in and retrieves the ID would be great.

Again, yes, this is all stuff that needs SMF.  You might try using SSI.php (which will give you everything you need, and access to $ID_MEMBER, $user_info, allowedTo(), etc.), which may not conflict with things as long as the search you're writing and SMF do not show on the same page at once.

I've tried calling SSI.php from a mambot before, and it creates problems.

flirby

Hi All,

I am trying to implement the form / script to get this working and when I try searching the forum I always get the following mambo page error: "The page you are trying to access does not exist.
Please select a page from the main menu. "
But if I enter the action in the case statement (I have added my com_smf id) into the browser it always comes up with the correct search page.

Any clues anyone?  Code below...



<script language="JavaScript">
<!--
function processForm()
{
   f = document.searchform;
   switch (f.searcharea.selectedIndex)
   {
   // mambo
   case 0: f.method='post';
         f.action='index.php?option=search';
         break;
   //smf
   case 1: f.method='post';
         f.action='index.php?option=com_smf&Itemid=631&action=search2';
         f.search.value=f.searchword.value;
         f.option.value="";
         break;
   //coppermine
   case 2: f.method='get';
         f.action='index.php?option=com_wrapper&wrap=cpg_search&album=search&type=full';
         f.search.value=f.searchword.value;
         f.option.value = "com_wrapper";
         f.wrap.value = "cpg_search";
         break;
   }
   f.submit();
}
-->
</script>

rjprince

QuoteTo format the date, you can either use PHP's time functions (strtotime(), time(), etc. - it's just seconds so arithmetic is easy) or MySQL's, FROM_UNIXTIME() and UNIX_TIMESTAMP().

It's really not meant to be complicated  ;).

I'm a recovering Microsoft programmer; patience is needed. That worked fine - Mambo reformats it to Mambo's setting, so consistency is maintained.

QuoteGrr...This is because Mambo goes through all the bot code first, before reading the template.  You're probably best including $mosConfig_live_site/administrator/components/com_smf/config.smf.php and then including $smf_path/Settings.php.  That should give a definition for $db_prefix.

There were serious problems with this. Because SSI.php uses require_once() for settings, including it in the mambot kept SSI.php from loading it. Because the mambot is not running in the global context, this did Bad Things, even when I did the include outside the mambot function.

The only combination I found that works is to change the code required in the template to this:

if (!defined('SMF')){
  require ("administrator/components/com_smf/config.smf.php");
  [b]require($smf_path . "/Settings.php");[/b]
  require ($smf_path."/SSI.php");
}


This new line will add the settings whether they have been loaded or not; SSI won't load it again, so everyone is happy. We'll just have to include this modification to the template in the mambot instructions and, possibly, in the readme for installing the bridge itself once the mambot is release-ready.

I didn't tackle the security issue yet. Since SSI definitely does not like to be included in the Mambots, this may not be possible. I may have to extract the loadUserSettings() and some of the settings from SSI - something that will be horrible to maintain. I'll think more on this later.

Thanks for your help. I'll get back to this tonight and hopefully post an initial version.

[Unknown]

Quote from: Orstio on July 30, 2005, 06:23:22 AM
Grr...This is because Mambo goes through all the bot code first, before reading the template.  You're probably best including $mosConfig_live_site/administrator/components/com_smf/config.smf.php and then including $smf_path/Settings.php.  That should give a definition for $db_prefix.

That won't quite work because Settings.php is included with include_once(), you'd have to global everything.

Quote
I've tried calling SSI.php from a mambot before, and it creates problems.

I see; I didn't realize they were all loaded before anything else, that's definitely a problem.

If you include SSI.php, you will have $user_info['query_see_board'] at your disposal, from that function.

-[Unknown]

Orstio

QuoteThis new line will add the settings whether they have been loaded or not; SSI won't load it again, so everyone is happy. We'll just have to include this modification to the template in the mambot instructions and, possibly, in the readme for installing the bridge itself once the mambot is release-ready.

I've actually been toying with a method of eliminating the Mambo template code fix altogether.  It wouldn't modify Mambo at all, and would allow people to switch templates without having to add the code into each template they try.

There is a small race condition issue I have to work out with it first, and then it will be released with the next version.  I can modify that to what you have suggested to eliminate any problems with your bot (and possibly in the discussbot as well.)  ;)

rjprince

#30
OK, I've gotten somewhere,  but I want to run this by you all because it may be a security issue.

Because the mambots are run when they are, I cannot access SSI. I've tried almost every combination of require/include I could think of and am pretty sure it's not meant to be.

So, I took the loadUserSettings function from Load.php and cut it down to just what I needed. It works on my site, but one thing concerned me. The function references $modSettings['integrate_verify_user'], modSettings['integrate_verify_user'], !empty($modSettings['disableCheckUA']. As best I can tell, none of these are set by the time the mambot is called.

Does this pose a security risk?

If not, the rest is straightforward. Once I have the  value of ID_MEMBER, do I need to check anything besides is_activated to see if that user is allowed to see these boards?

I've duplicated a bit of business logic, something I hate doing for mods, but it's pretty clean once these questions are answered. I don't anticipate too much of a problem keeping it in synch with SMF and the bridge as they are upgraded, but it won't be as easy as it could have been had SSI worked.

For reference, here's the query I'm using to conduct the search.

SELECT CONCAT(m.subject, ' by ', u.memberName) AS title,
FROM_UNIXTIME(m.posterTime, '%Y-%m-%d %H:%i:%s') as created,
  CONCAT('In topic "', tm.subject, ':" ', LEFT(m.body, 200), IF(CHAR_LENGTH(m.body) > 200, '...', '')) as text,
b.name as section,
CONCAT('/index.php?option=com_smf&Itemid=83&', 'topic=', m.ID_TOPIC, '.msg', m.ID_MSG, '#msg', m.ID_MSG) AS href,
'2' AS browsernav
FROM smf_pc_messages as m INNER JOIN smf_pc_topics as t ON m.ID_TOPIC = t.ID_TOPIC
INNER JOIN smf_pc_messages as tm ON t.ID_FIRST_MSG = tm.ID_MSG
INNER JOIN smf_pc_boards as b ON t.ID_BOARD = b.ID_BOARD
INNER JOIN smf_pc_members as u ON m.ID_MEMBER = u.ID_MEMBER
WHERE ( (m.subject LIKE '%Neville%' OR m.body LIKE '%Neville%')
OR (m.subject LIKE '%Herb%' OR m.body LIKE '%Herb%') )
AND (FIND_IN_SET(9, b.memberGroups) OR
FIND_IN_SET(4, b.memberGroups) OR
FIND_IN_SET(13, b.memberGroups) OR
FIND_IN_SET(17, b.memberGroups) OR
FIND_IN_SET(19, b.memberGroups) OR
FIND_IN_SET(23, b.memberGroups))
ORDER BY m.ID_TOPIC DESC


I will ask that someone familiar with good security practices in smf take a look at the mambot before general release.

Orstio

[Unknown] would be best to ask about the security.

I have a request, however:  Can you change the "&"s in the URLs to "&amp;" ?  I'd like to use this, but I want to maintain my XHTML compliance.  ;)

rjprince

Done. It should be noted that I copied and pasted that line from the related items misc mambot.  :P

[Unknown]

Quote from: rjprince on July 30, 2005, 05:30:55 PM
So, I took the loadUserSettings function from Load.php and cut it down to just what I needed. It works on my site, but one thing concerned me. The function references $modSettings['integrate_verify_user'], modSettings['integrate_verify_user'], !empty($modSettings['disableCheckUA']. As best I can tell, none of these are set by the time the mambot is called.

Those three are all usually-not-set settings.  The first and second can be reasonably assumed to either be Mambo, or not set.  The third will almost never be set, and is just an option in case anyone has problems.  So far, no security risk that I see.

Quote
I've duplicated a bit of business logic, something I hate doing for mods, but it's pretty clean once these questions are answered. I don't anticipate too much of a problem keeping it in synch with SMF and the bridge as they are upgraded, but it won't be as easy as it could have been had SSI worked.

I agree it would be nicer if SSI.php worked.  Technically speaking, nothing in the license allows you to copy out the code, but I think we can let it slide for now as long as you acknowledge somewhere in the file it's in that some code came from SMF - is that okay?

SELECT CONCAT(m.subject, ' by ', u.memberName) AS title,
FROM_UNIXTIME(m.posterTime, '%Y-%m-%d %H:%i:%s') as created,
  CONCAT('In topic "', tm.subject, ':" ', LEFT(m.body, 200), IF(CHAR_LENGTH(m.body) > 200, '...', '')) as text,
b.name as section,
CONCAT('/index.php?option=com_smf&Itemid=83&', 'topic=', m.ID_TOPIC, '.msg', m.ID_MSG, '#msg', m.ID_MSG) AS href,
'2' AS browsernav
FROM smf_pc_messages as m INNER JOIN smf_pc_topics as t ON m.ID_TOPIC = t.ID_TOPIC
INNER JOIN smf_pc_messages as tm ON t.ID_FIRST_MSG = tm.ID_MSG
INNER JOIN smf_pc_boards as b ON t.ID_BOARD = b.ID_BOARD
INNER JOIN smf_pc_members as u ON m.ID_MEMBER = u.ID_MEMBER
WHERE ( (m.subject LIKE '%Neville%' OR m.body LIKE '%Neville%')
OR (m.subject LIKE '%Herb%' OR m.body LIKE '%Herb%') )
AND (FIND_IN_SET(9, b.memberGroups) OR
FIND_IN_SET(4, b.memberGroups) OR
FIND_IN_SET(13, b.memberGroups) OR
FIND_IN_SET(17, b.memberGroups) OR
FIND_IN_SET(19, b.memberGroups) OR
FIND_IN_SET(23, b.memberGroups))
ORDER BY m.ID_TOPIC DESC


Assuming you use the query_see_board there, and have some way of obtaining the db_prefix (and that neither of those are insecure) this looks fine.  I'll assume that you are escaping the search string, yes?

At one point in the future, perhaps when we've resolved some other issues (like the SSI one), it may be a good idea to use FULLTEXT and some other things for the searching.

Let me ask you this: if you change both require_once's of Settings.php to require's (SSI.php and index.php) does everything work fine to use it?

-[Unknown]

rjprince

#34
QuoteTechnically speaking, nothing in the license allows you to copy out the code, but I think we can let it slide for now as long as you acknowledge somewhere in the file it's in that some code came from SMF - is that okay?

Sorry about that. I'll add a comment to that section. My intent is to get this working and then turn it over to you guys, but the mambot section is taken from a GPL piece of code.

It would not be hard to rewrite that section if you wish to include it as part of the distribution.

Here's the comment I added in the derived function:

// The code in this function is derived from function loadUserSettings() in source/Load.php.
// Used by permission of [Unknown] at http://www.simplemachines.org/community/.
// Use of Simple Machines Forum is subject to the license agreement with which it is distributed.
/******************************************************************************
* Load.php                                                                    *
*******************************************************************************
* SMF: Simple Machines Forum                                                  *
* Open-Source Project Inspired by Zef Hemel ([email protected])                *
* =========================================================================== *
* Software Version:           SMF 1.1 Beta 3 Public                           *
* Software by:                Simple Machines (http://www.simplemachines.org) *
* Copyright 2001-2005 by:     Lewis Media (http://www.lewismedia.com)         *
* Support, News, Updates at:  http://www.simplemachines.org                   *
*******************************************************************************
* This program is free software; you may redistribute it and/or modify it     *
* under the terms of the provided license as published by Lewis Media.        *
*                                                                             *
* This program is distributed in the hope that it is and will be useful,      *
* but WITHOUT ANY WARRANTIES; without even any implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                        *
*                                                                             *
* See the "license.txt" file for details of the Simple Machines license.      *
* The latest version can always be found at http://www.simplemachines.org.    *
******************************************************************************/


QuoteI'll assume that you are escaping the search string, yes?

Yes. I use mambo's database functions, which handle escaping. To test, I've done several searches with single quotes in them. It actually overescapes.

QuoteAt one point in the future, perhaps when we've resolved some other issues (like the SSI one), it may be a good idea to use FULLTEXT and some other things for the searching.

I'd love to, but my host doesn't support it yet. Hopefully by the time this comes up, I will and then I'll update it.

QuoteLet me ask you this: if you change both require_once's of Settings.php to require's (SSI.php and index.php) does everything work fine to use it?

Yes, it seems to. I didn't test that thoroughly, because the method I'm using worked without requiring a change to a core file.

rjprince

#35
Here's version 0.1 of a searchbot for smf.

BE SURE TO READ THE POST TWO SPOTS BELOW FOR INSTRUCTIONS FOR MODIFYING YOUR TEMPLATE TO USE THE MAMBOT!

Simply install it in the mambo admin mambot screens. Be sure to publish it and make the change described two posts below to your template's index.php file. It's an all-forum search of the message text and body. It respects user permissions. It is not meant to duplicate advanced search in smf, but to allow an integrated search function with mambo. In mambo, search results are grouped by content type; to move forums up or down in that list, change the order of the searchbot in mambo admin.

Please test. I especially need tests across multiple forums, with varied permissions by user. Try to crash it with bad search strings.

Comments on output would be appreciated - specifically, what should be the link text, the section header, and the description.

If anyone is using different databases, I need that checked as well. And people who didn't install mambo in the root and smf in the "forum" directory, along with combinations of SEF on and off.

Please post comments and suggestions here.

Orstio

 :(

It kills the Who's Online 2 module:

QuoteWarning: main(/QueryString.php): failed to open stream: No such file or directory in /home/everythi/public_html/components/com_smf/SSI.php on line 55

rjprince

#37
THIS POST ONLY APPLIES TO THE MAMBO SEARCHBOT MENTIONED TWO POSTS ABOVE. IT IS NOT GENERAL ADVICE FOR ANYTHING ELSE.

You need to update the code in the index.php file for your active template:

global $sc, $context;

if (!defined('SMF')){
  require ("administrator/components/com_smf/config.smf.php");
  // ADD THE LINE BELOW
  require ($smf_path . "/Settings.php");
  require_once ($smf_path."/SSI.php");
}

$sc = &$context['session_id'];
$_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];

mysql_select_db($mosConfig_db);


Everything but the comment line and the line below should already be there. You're just adding the line " require ($smf_path . "/Settings.php");"


I mentioned this above but forgot to add this to the instructions. I'll edit that post.

Orstio

Thanks, I completely forgot about that.

I am actually not using the code in the header of the template (I mentioned a different method earlier), but I did get this working very well.

Great work!  :D

djpillo

#39
can someone help me....because i CANT DO it....agggggggggg

I have Copermine Bride SMF and a SMF bridge Mambo.
I have do a WRAP in Manbo to COpermine.

This is that i do:(rjprince post)

1) i install the SMF.SEARCH in  "Mambots"
2) I edit the "index.php" of my template:; require ($smf_path . "/Settings.php"); (when rjprince  say)

What i am doing wrong?

Thanks
SORRY FOR MY ENGLISH
---------------------------------------------------------------------------------
EDIT

I HAVE DO ITTTTTTTTTTTTTTTTTTTTTTTT!!! jeejejeje SORRY
i have been lost to PUBLISH the smf.search!!!!

Now it work fine.

Can Someone say me how do for COpermine?
Thanks

Advertisement: