MyBB Community Forums

Full Version: Capitalize thread titles and posts' first letter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hi,

I made a small plugin which capitalizes the first letter of a post or a thread's title and it works very nicely, but I just noticed that there are a lot more places which I need to capitalize as well, such as the search results page, subscribed threads, breadcrumb, quotes, edit post pages, etc. Probably even more places which I might not even know of.

So I started thinking and maybe it would be better if I capitalized the thread title and the post in the database, instead of doing it on specific pages. That would save me a lot of time because I only have to update things once and the plugin would be a lot simpler. And I know how to do it, I just need opinions on what works best.

But my question is, which method do you think is the best? This is not directed just at the developers though, but forum admins as well, because with the current method I'm using, if I edit a post it is not capitalized. If I updated it in the database, however, it would be. Which method makes most sense for you?

Thanks!
Well, I was looking at that thread and I was looking what I could suggest as a small hack and I stumbled on the same problem. When you do it when it gets saved into the database, it only works for newly created threads/posts and not for older threads unless you edit them. But doing it when outputting, is a lot of work and it's possible that there aren't hooks available in some places to alter the subject (don't know that for sure though). Both have their upsides and their downsides, like every dilemma. Smile
I was considering something like this to update existing threads:

$update_array = array(
     "subject" => ucfirst($thread['subject']),
);
$db->update_query("threads", $update_array, "WHERE subject = '".intval($thread['subject'])."'");

And do the same thing for posts. Haven't tested it yet though, there could be something wrong, but theoretically it looks like it would work.
Look at the hooks in inc/datahandlers/post.php . Those are better as your callback will also be called when inserting/update threads not via the standard forms in MyBB.
Also, it would be ok if it would also work for index.
Yes, I've been looking into those hooks but I can't seem to get it working. I've tried doing the changes directly in the core and it works, not with the plugin though. I'm using the following code, with the datahandler_post_insert_thread and datahandler_post_insert_thread_post hooks.

function mflucdb_threads()
{
	$this->thread_insert_data = array(
		"subject" => $db->escape_string(ucfirst($thread['subject'])),
	);
}

function mflucdb_posts()
{
	$this->post_insert_data = array(
		"subject" => $db->escape_string(ucfirst($thread['subject'])),
		"message" => $db->escape_string(ucfirst($thread['message'])),
	);
}

What am I doing wrong?
You need to declare the object as your function parameter:
function mflucdb_threads($this)
{
//...
}

function mflucdb_posts($this)
{
//...
}

The hook passes the $this variable to the callbacks.
I have tried that before with no luck. It still doesn't capitalize the first letter as it should. And while creating the new thread it outputs an error message in the friendly redirection page: http://i.imgur.com/eL9Wm.png

This happened before declaring the object as the function parameter.
Check if the callback function in the add_hook() function has the same name as the function. I could be a small typo.

[EDIT]
If you can't figure it out. You can PM the full code and I will see if I can find what is going on.
This plugin will be legendary when it's finished. Big Grin
Pages: 1 2 3