FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » Dynamic forum META description
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
Dynamic forum META description [message #163381] Mon, 25 October 2010 07:45 Go to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
This is what I just did - check for errors please!


In drawmsg.inc.t add the following at the top of the function tmpl_drawmsg

/* being meta descr hack */

	global $thread_meta_desc; // Make the variable global so we can access it from header.tmpl

	if ($obj->root_msg_id == $obj->id) // we only grab the message body from the root message of the thread
	{
		if ($obj->length > 200) // We want our desc to be max 200, seems like a good number
		{
			$thread_meta_desc_full = read_msg_body($obj->foff, $obj->length, $obj->file_id);
			$thread_meta_desc = strip_tags($thread_meta_desc_full);
			$thread_meta_desc = substr($thread_meta_desc, 0, 200);
			if(substr($thread_meta_desc, 0, strrpos($thread_meta_desc, ' '))!='') $thread_meta_desc = substr($thread_meta_desc, 0, strrpos($thread_meta_desc, ' '));
			} else {
			$thread_meta_desc = strip_tags(read_msg_body($obj->foff, $obj->length, $obj->file_id));
		}
	// Lets sanitize the message before we send it to the meta tag
	$thread_meta_desc = htmlspecialchars(strip_tags($thread_meta_desc));
	if(strlen($thread_meta_desc) < 10) $thread_meta_desc = $obj->subject; // if the message is shorter than 10 letters, we output the threads title as description
	}
  /* end meta desc hack */


We also have to tweak header.tmpl just a little, we do it like this:

Replace
<META NAME="description" CONTENT="{GVAR: FORUM_DESCR}">


with
<META NAME="description" CONTENT="{IF: $thread_meta_desc}{VAR: thread_meta_desc}{ELSE}{GVAR: FORUM_DESCR}{END}">


[Updated on: Mon, 25 October 2010 08:17]

Report message to a moderator

Re: Dynamic forum META description [message #163382 is a reply to message #163381] Mon, 25 October 2010 07:47 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
vBulletin for example use 500max chars in their thread description.

Google says it doesn't matter how long the description is:
http://groups.google.com/group/Google_Webmaster_Help-Indexing/browse_thread /thread/7c5dc8cbb5f07dcd

I guess the number could be tweaked, but at least its miles better than to output the static meta descr on all threads


Re: Dynamic forum META description [message #163383 is a reply to message #163382] Mon, 25 October 2010 07:48 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
I am also sure there are better ways to implement this, perhaps with an SQL in the msg.php.t instead, but this one works so I dunno!

Re: Dynamic forum META description [message #163385 is a reply to message #163383] Mon, 25 October 2010 08:29 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
Thinking of it, dont relaly need the if foff > 200 statement, can just let it run on the full body since the substr takes care of it instead

Re: Dynamic forum META description [message #163392 is a reply to message #163385] Mon, 25 October 2010 11:13 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3624
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
remove from buddy list
ignore all messages by this user
I like the idea, but we will have to work on the implementation to ensure we don't read every message from disk twice.
Re: Dynamic forum META description [message #163395 is a reply to message #163392] Mon, 25 October 2010 11:23 Go to previous message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
I think we only read the first message from the disc twice, right?

We read it once in my code above (only reads if $obj->root_msg_id == $obj->id IE only if the message is the first message in a thread)

and

We read it in dramsg.tmpl -> dmsg_normal_message_body with {FUNC: read_msg_body($obj->foff, $obj->length, $obj->file_id)}


could of course move my code down to where dmsg_normal_message_body is created or something, I don't know, I am not a performance expert hehe.

Why I solved it like I did was because the call for the func to get the message body was done in the template and not in the src file


Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: BBcode for H1-H4
Next Topic: Useful function when there are still some ISO-8859 chars in the UTF8 database stored messages
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Oct 20 08:45:10 EDT 2017

Total time taken to generate the page: 0.00788 seconds