Ignoring a topic

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Joe Belmaati
Registered User
Posts: 2110
Joined: Sun Sep 28, 2003 7:35 pm
Location: Denmark

Post by Joe Belmaati » Wed Feb 07, 2007 7:50 pm

RMcGirr83 wrote: just add a simple [ignored] (or whatever) to the end of the topic title
That can be done with one line:

Code: Select all

$topic_title = (in_array($topic_id, $ignored_topics)) ? $topic_title . '[' . $lang['Ignored'] . ']' : $topic_title;
Image

User avatar
drathbun
Former Team Member
Posts: 12204
Joined: Thu Jun 06, 2002 3:51 pm
Location: TOPICS_TABLE
Contact:

Post by drathbun » Wed Feb 07, 2007 7:52 pm

Joe, one minor point / question...

The way the original code was posted, in_array() would not work because the values "in the array" were all TRUE. That's why I used the isset() function in my example.

At least that's the way I read it. :-)
I blog about phpBB: phpBBDoctor blog
Still using phpbb2? So am I! Click below for details
Image

Joe Belmaati
Registered User
Posts: 2110
Joined: Sun Sep 28, 2003 7:35 pm
Location: Denmark

Post by Joe Belmaati » Wed Feb 07, 2007 7:57 pm

That's not how I read it. As the loop is traversed each repition returns a topic_id. It may or may not be in the array.
Image

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Post by RMcGirr83 » Wed Feb 07, 2007 7:57 pm

Always more than one way to skin a cat, eh?

Anyway, Dave if I may, or anyone else, pick your brain a tad more?

I could then apply this within search on newposts, author, etc, etc.? But would have to call the topic_id associated with the post_id in the posts table?

I notice that "view posts since last visit" is called from viewtopic.php (mode == "newest"). Would I then also have to build a similar array and replace as you had given?

If so, correct me if wrong, that will add an additional query to viewtopic. Correct?

Can anyone think of another file where some sort of search is invoked on topics, cuz I sure can't.

I think my brain is frying :lol:

/me is learning...or at least trying to :)

Joe thanks for that as well. ;)

Joe Belmaati
Registered User
Posts: 2110
Joined: Sun Sep 28, 2003 7:35 pm
Location: Denmark

Post by Joe Belmaati » Wed Feb 07, 2007 8:01 pm

All those "posts since last visit" etc come from search.php to the best of my recollection.
Image

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51872
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Post by Brf » Wed Feb 07, 2007 8:07 pm

Code: Select all

$ignoredtopic_ids[$row['ignored_topic_id']] = true; 


So, as Drathbun said, the only thing in the array is a bunch of "true"s.
Therefore you cannot check inarray()
Instead, you would want to check

Code: Select all

isset($ignoredtopic_ids[$topic_id])

User avatar
drathbun
Former Team Member
Posts: 12204
Joined: Thu Jun 06, 2002 3:51 pm
Location: TOPICS_TABLE
Contact:

Post by drathbun » Wed Feb 07, 2007 8:08 pm

Joe Belmaati wrote: That's not how I read it. As the loop is traversed each repition returns a topic_id. It may or may not be in the array.

The original code posted was this:

Code: Select all

// 
// Get ignored topics 
// 
if ( $userdata['session_logged_in'] ) 
{ 
   $sql = "SELECT ignore_topic_id 
      FROM " . IGNORETOPIC_TABLE . " 
      WHERE user_id = " . $userdata['user_id']; 
   if ( !$result = $db->sql_query($sql) ) 
   { 
      message_die(GENERAL_ERROR, 'Error getting ignore listing', '', __LINE__, __FILE__, $sql); 
   } 
   $ignoredtopic_ids = array(); 
   $ignoredtopic_sql = ''; 
   while( $row = $db->sql_fetchrow($result) ) 
   { 
      $ignoredtopic_ids[$row['ignored_topic_id']] = true; 
      $ignoredtopic_sql .= ' , ' . $row['ignored_topic_id']; 
   } 

    if ( $ignoredtopic_sql != '' ) 
    { 
        $ignoredtopic_sql = ' AND topic_id NOT IN (' . substr($ignoredtopic_sql, 2) . ' )'; 
    } 
}
If you ignore :-P the $ignoretopic_sql which I don't think is needed, what you're left with is a simple check that should go at the top of the file to build a list of ignored topic_id values. This array $ignoredtopic_ids is populated with the key being the topic_id and the value being TRUE.

I would use this idea, and then simply replace $topic_title and $message as I posted in my prior post in this topic.
I blog about phpBB: phpBBDoctor blog
Still using phpbb2? So am I! Click below for details
Image

Joe Belmaati
Registered User
Posts: 2110
Joined: Sun Sep 28, 2003 7:35 pm
Location: Denmark

Post by Joe Belmaati » Wed Feb 07, 2007 8:11 pm

OK, I see. I would build the ignored array so that the topic ids are the values - not the keys.

Liked your ignored joke... :D
Image

User avatar
drathbun
Former Team Member
Posts: 12204
Joined: Thu Jun 06, 2002 3:51 pm
Location: TOPICS_TABLE
Contact:

Post by drathbun » Wed Feb 07, 2007 8:21 pm

RMcGirr83 wrote: Anyway, Dave if I may, or anyone else, pick your brain a tad more?

Me and everyone else :-)
I could then apply this within search on newposts, author, etc, etc.? But would have to call the topic_id associated with the post_id in the posts table?

No, that's the beauty of the solution... it's called at the end during the output query.

If you look at the way search works, there are two phases. Phase 1 gets the topics or posts that match your criteria and store them in $searchset. Then Phase 2 gets the topic/posts from that array and retrieves the actual search results. So since you're - based on your comments - going to allow topics to return but replace the content with "ignored" you don't have to do anything but modify the actual search output.

Leave the input alone. It's much easier, and no worries about pagination as someone else mentioned earlier.
If so, correct me if wrong, that will add an additional query to viewtopic. Correct?

viewtopic? When did we start talking about viewtopic? :-) I thought we were talking about search.php.
Can anyone think of another file where some sort of search is invoked on topics, cuz I sure can't.

search.php does all of the "canned" searches like "new posts" and "unanswered" and "my posts" and so on. It also does the keyword searches.
I blog about phpBB: phpBBDoctor blog
Still using phpbb2? So am I! Click below for details
Image

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Post by RMcGirr83 » Wed Feb 07, 2007 8:53 pm

Joe Belmaati wrote: All those "posts since last visit" etc come from search.php to the best of my recollection.


Correct you are....I was looking at the page after the search was done (newest post is called then from viewtopic) :roll:

See told ya...nOOb :lol:

Dave, though your ignore joke was "okay" I think you should stick with php ;)

aka...don't quit your day job!! :p

BTW, here's my new code

Code: Select all

//
// Get ignored topics
//
if ( $userdata['session_logged_in'] )
{
   $sql = "SELECT ignore_topic_id
      FROM " . IGNORETOPIC_TABLE . "
      WHERE user_id = " . $userdata['user_id'];
   if ( !$result = $db->sql_query($sql) )
   {
      message_die(GENERAL_ERROR, 'Error getting ignore listing', '', __LINE__, __FILE__, $sql);
   }
   $ignoredtopic_ids = array();
   while( $row = $db->sql_fetchrow($result) )
   {
      $ignoredtopic_ids[$row['ignore_topic_id']] = true;
   }
}
and I have found these instances of $topic_title

Code: Select all

$topic_title = $searchset[$i]['topic_title'];

Code: Select all

					if ( count($orig_word) )
					{
						$topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
						$post_subject = ( $searchset[$i]['post_subject'] != "" ) ? preg_replace($orig_word, $replacement_word, $searchset[$i]['post_subject']) : $topic_title;

Code: Select all

$post_subject = ( $searchset[$i]['post_subject'] != '' ) ? $searchset[$i]['post_subject'] : $topic_title;

Code: Select all

'TOPIC_TITLE' => $topic_title,

Code: Select all

				if ( count($orig_word) )
				{
					$topic_title = preg_replace($orig_word, $replacement_word, $searchset[$i]['topic_title']);
				}

Code: Select all

'TOPIC_TITLE' => $topic_title,
but alas after putting this

Code: Select all

             if (isset($ignoredtopic_ids[$search_set[$i]['topic_id']]))
             {
                $message = $searchset[$i]['post_text'] . '[' . $lang['Ignored'] . ']';
                $topic_title = $searchset[$i]['topic_title'] . '[' . $lang['Ignored'] . ']';
             }
after this

Code: Select all

			$message = $searchset[$i]['post_text'];
			$topic_title = $searchset[$i]['topic_title'];
She aint working...and yes I defined $lang['Ignored'] in lang_main.php.

:?

BTW, please excuse this post...didn't know how else to post this.

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Post by RMcGirr83 » Wed Feb 07, 2007 9:01 pm

never mind...Dave gave me a typo. :lol:

Thanks a ton guys!! Works to a tee. ;)

User avatar
drathbun
Former Team Member
Posts: 12204
Joined: Thu Jun 06, 2002 3:51 pm
Location: TOPICS_TABLE
Contact:

Post by drathbun » Wed Feb 07, 2007 9:04 pm

RMcGirr83 wrote: never mind...Dave gave me a typo. :lol:

Thanks a ton guys!! Works to a tee. ;)

I didn't give you a typo, I gave you some sample code. :-P

And.... this is my day job! :shock:

(just don't tell my actual boss)
I blog about phpBB: phpBBDoctor blog
Still using phpbb2? So am I! Click below for details
Image

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Post by RMcGirr83 » Wed Feb 07, 2007 9:14 pm

In my best "Sargeant Shultz" voice
I see nothing, I hear nothing!!

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51872
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Post by Brf » Wed Feb 07, 2007 9:21 pm

Sample code with a typo in it :wink:
drathbun wrote: Just after that, simply check something like this:

Code: Select all

			if (isset($ignore_topid_ics[$search_set[$i]['topic_id]]))
			{


Two typos actually.

User avatar
drathbun
Former Team Member
Posts: 12204
Joined: Thu Jun 06, 2002 3:51 pm
Location: TOPICS_TABLE
Contact:

Post by drathbun » Wed Feb 07, 2007 11:09 pm

Brf wrote: Two typos actually.

meh, was typing quickly :-P
I blog about phpBB: phpBBDoctor blog
Still using phpbb2? So am I! Click below for details
Image

Post Reply

Return to “[2.0.x] MOD Writers Discussion”