PDA

View Full Version : Adding a Miscellaneous Option on new thread post


glennybee
02-05-2013, 11:46 AM
Hi,

I am looking to add an option to the Miscellaneous Options part of a new thread post.

I have set up my forum so that members can claim authorship via their google plus profile of any threads they create.

I want to add an option to the Miscellaneous Options saying "Claim google authorship of this thread."

And all it needs to do if it is checked, is add a rel="author" tag to the username link on the first post of the thread.

Would i do this with a plugin or what?

Thanks so much in advance

glennybee
02-05-2013, 12:53 PM
ok so this is my first time working with any of this so here is what ive done so far, ive managed to add the checkbox to the additional options by adding this code to the newthread template...


<div>

<label for="cb_authorship"><input type="checkbox" name="authorship" value="1" id="cb_authorship" tabindex="1" $checked[authorship] />Claim google authorship</label>

</div>



I have then added this to the postbitlegacy template...


<if condition="$show['authorship']">
<a class="bigusername" href="member.php?$session[sessionurl]u=$post[userid]" rel="author">$post[musername]</a>
<else />
<a class="bigusername" href="member.php?$session[sessionurl]u=$post[userid]">$post[musername]</a></if>



Again i have no idea if this is right because this is my very first time working with assigning variables and using IF statements etc in PHP

Anyway, is there anything else i need to do for this to work?
Its probably so far off the mark but i just kinda copied some code from the other options nearby and modified them to try and do what i want it to do...

Any help would be greatly appreciated.
Thanks

--------------- Added 1360074380 at 1360074380 ---------------

I take it im not assigning the variable right.

So i need to add some sort of...

if authorship is checked, then set $show[authorship] =true?

Someething along those lines? anyone?

im struggling hehe cheers

--------------- Added 1360079458 at 1360079458 ---------------

So im guessing i need to add a plugin with the code that will find out if cb_authorship was checked, if so, set $show[authorship] to true.

What would the code be for this, and what hook location should i add it to?
thanks in advance

--------------- Added 1360079705 at 1360079705 ---------------

Also i am running vb3.8

kh99
02-05-2013, 03:15 PM
Probably what you need to do is add a column to the thread table of the database to save the value of your "authorship" option. Then I think you can get the thread data manager to save that value for you, but you need a couple of plugins, one to tell the datamanager about that field, and another to call the datamanager "set()" function with your value when the thread is created.

If you look at file includes/class_threadpost.php, search for "class vB_DataManager_Thread_FirstPost" and then scroll down, you'll see an array $validfields which specifies the fields that can be set in this datamanager. If you scroll down more to "function vB_DataManager_Thread_FirstPost", you can see there's a hook when one of those objects is created (which is done when a thread needs to be created or modified). So if you create a plugin using that hook location, you can add your field to the array, like maybe:

$validfields['authorship'] = array(TYPE_UINT, REQ_NO);


then I think it will be set up to save your value for you, and it then it will also automatically be read in as thread info later. (remember, you still need to create the column in the database yourself).


But you still need your value to be set in the datamanager. I think if you look at includes/functions_newpost.php and search for function build_new_post(), there's probably a hook location there you can use to do that (that funciton is called for both new threads and replies, so you'd probably want to check for $type == 'thread' so you're only setting it for threads).

Anyway, I hope that helps enough for you to make progress.

glennybee
02-05-2013, 03:41 PM
I really appreciate your help, ive tried to follow your guide but im totally lost. i think its just way over my head, ive never done any php stuff before so i think i'll need to hand it over to an expert to get it finished.

Really appreciate you taking the time to reply though

--------------- Added 1360082766 at 1360082766 ---------------

do you know where the cb_signature variable gets handled and i could check that out? ---- its cool forget it, im totally lost lol

kh99
02-05-2013, 04:01 PM
OK, sorry about that. I know that's hard to follow if this is your first mod.. If I get a chance, I'll try to put together the plugin parts so you can just make the template changes you talked about (unless you decide to go a different way, then let me know).

glennybee
02-05-2013, 04:27 PM
I think i've made the right changes to the class_dm_threadpost.php file so that it should be able to handle a 'authorship' variable, but didnt know wha tot do from there.

I dont know if im over complicating it, and maybe theres an easier way, not sure.

kh99
02-05-2013, 04:43 PM
OK, well, to answer your question about how the signature option gets handled: if you look at script newthread.php and look for this section (around line 97):

// ############################### start post thread ###############################
if ($_POST['do'] == 'postthread')
{


you can see below that there's a call to $vbulletin->input->clean_array_gpc), that gets the values from the form that was submitted and puts them in the $vbulletin->GPC[] array. So you'd want to add your authorship field to that list. Then if you look below that, what's happening in general is that the form values from $vbulletin->GPC[] are being transfered to the $newpost array, so you'd want to take your authorship value and do that (probably it would just be $newpost['authorship'] = $vbulletin->GPC['authorship']).

Now if you go back to looking at build_new_post() in functions_newpost.php, you can see the values from the $post parameter (which is just the $newpost from before) are being transfered to the datamanager. So you'd want to add something like:

if ($type == 'thread' AND isset($post['authorship']))
{
$dataman->set('authorship', $post['authorship']);
}



I think that should do it. If you do all that then I think you should be able to check $threadinfo['authorship'] in an <if> tag in the template.

BTW, I don't think you're making it complicated - it's quite a bit to figure out from scratch. (And it's not the only way to do it, obviously). Also I'm assuming you're not trying to use plugins but are changing the files? That's OK, using plugins does sometimes make it harder to figure out how to get things done, and since vb3 isn't being updated any more (or at least rarely), it doesn't make much difference.

glennybee
02-05-2013, 05:04 PM
when i add... $newpost['authorship'] = $vbulletin->GPC['authorship']

to newthread.php, i get this error when tryingto submit a new thread

Parse error: syntax error, unexpected T_VARIABLE in /home/buckyuk/public_html/moneymakingexperts.org/newthread.php on line 195

--------------- Added 1360087598 at 1360087598 ---------------

am i adding it to the wrong section of newthread.php... line 192?

kh99
02-05-2013, 05:07 PM
That looks like a good place. You might just need a semicolon at the end of that line.

glennybee
02-05-2013, 05:30 PM
ok now im getting this error when i hit submit new thread.

Fatal error: Call to a member function set() on a non-object in /home/buckyuk/public_html/moneymakingexperts.org/includes/functions_newpost.php on line 321

I added the code you gave from line 319 to 322

if ($type == 'thread' AND isset($post['authorship']))
{
$dataman->set('authorship', $post['authorship']);
}

kh99
02-05-2013, 05:34 PM
I don't understand why that would happen. It looks like everything's right. Maybe try this: find this code (around line 305):

// create data manager
if ($type == 'thread')
{
$dataman =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$dataman->set('prefixid', $post['prefixid']);
}



Then add your set call in there, like this:

// create data manager
if ($type == 'thread')
{
$dataman =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$dataman->set('prefixid', $post['prefixid']);
$dataman->set('authorship', $post['authorship']);
}

glennybee
02-05-2013, 05:40 PM
I think we're getting closer... database error now

Database error in vBulletin 3.8.7:

Invalid SQL:
INSERT INTO post
(authorship, showsignature, allowsmilie, username, userid, title, pagetext, iconid, visible, dateline, ipaddress, attach, threadid)
VALUES
(1, 1, 1, 'MME\'s Alan', 3, 'checked box test', 'testing checked box', 0, 1, 1360089531, '', 0, 463);

MySQL Error : Unknown column 'authorship' in 'field list'
Error Number : 1054
Request Date : Tuesday, February 5th 2013 @ 12:38:51 PM
Error Date : Tuesday, February 5th 2013 @ 12:38:51 PM
Script : http://www.moneymakingexperts.org/newthread.php?do=postthread&f=12
Referrer : http://www.moneymakingexperts.org/newthread.php?do=newthread&f=12
IP Address : 94.171.60.130
Username : MME's Alan
Classname : vB_Database_MySQLi
MySQL Version : 5.5.23-55

kh99
02-05-2013, 05:48 PM
OK, now you have to create the column in your database. Do you have phpMyAdmin? Go to the database, click on the thread table then the structure tab, then look for the "Add 1 column(s)" line below the list of columns, and click "go". Then put in 'authorship' for the name and probably select tinyint from the type list. I don't think you need to set any of the other fields.

glennybee
02-05-2013, 05:50 PM
So from looking at this i need to add the column "authorship" to the "post" database in mysql...

Off to figure out how to do that haha

kh99
02-05-2013, 05:52 PM
Actually I think you want to add it to "thread", right? (If you only want it selected for each thread and not for every post).

glennybee
02-05-2013, 05:55 PM
cheers mate, ive added it to the post table, as this seemed to be where the other columns were that were named in the error, should it be the thread table?

Its working now, but its not working hehe.

Think it must be just a bit of tweaking in the postbit legacy template now

--------------- Added 1360090631 at 1360090631 ---------------

the thread table just contains all the data for the threads, its the post table that has the showsignature columns etc.
It will only be an option on the first thread post so i think its ok...

--------------- Added 1360090719 at 1360090719 ---------------

I think its just this bit of code now in the postbit_legacy template...

<if condition="$show['authorship']">

How can i tell this, if authorship is '1'??

--------------- Added 1360091099 at 1360091099 ---------------

I think ive got it... changed the $show to $post...

--------------- Added 1360091218 at 1360091218 ---------------

this is the result...

authorship box checked...

http://www.google.com/webmasters/tools/richsnippets?url=http%3A%2F%2Fwww.moneymakingexper ts.org%2Ff12%2Fauthor-box-checked-465%2F&html=

not checked...

http://www.google.com/webmasters/tools/richsnippets?url=http%3A%2F%2Fwww.moneymakingexper ts.org%2Ff12%2Fnot-checked-466%2F&html=

I owe you a beer mate... whats you paypal and i'll send you a small token of my appreciation

kh99
02-05-2013, 06:09 PM
Yeah, if you put it in post and it's working that's OK. If it's only for the first post you really should have put it in thread, but the only issue is that it takes up a bit more database space.

I'm kind of surprised that it's working because I think the default when you add fields to the Thread_firstpost datamanager is to have them be thread table fields. But again, as long as it's working for you, it doesn't matter.

glennybee
02-05-2013, 06:13 PM
Yeah its working so im mega happy.

I just need to add the option to edit thread, this might be a bit more complicated if editing a post that isnt the first post of the thread.

Do you think i should add it to the thread table then? if i done that, surely the code weve added is adding the variable to the post table, how would we tell it to add it to the thread table?

--------------- Added 1360091710 at 1360091710 ---------------

Maybe i just need to add a if postid=1 variable to the if statement on the newthread template where it displays the check box option to claim authorship

--------------- Added 1360092034 at 1360092034 ---------------

hhmmm i had added this code to the editpost template thinking that would have cracked it, but the option isnt showing up with this if statement.

Any ideas

<if condition="$post[postcount] == 1"><div><label for="authorship"><input type="checkbox" name="authorship" value="1" id="authorship" tabindex="1" $checked[authorship] />Claim google authorship</label></div></if>

--------------- Added 1360094899 at 1360094899 ---------------

I know you have helped me immensly, im just trying to tidy up these loose ends.

I'm trying to add it to the edit post page, ive added the same code as i did in the postbit_legacy, but when i check the box to claim authorship, it doesnt set the authorship field in the post table to '1'.

Any ideas?

Let me know your paypal email and i will send you something as a small token of my appreciation for helping me with that.

--------------- Added 1360098744 at 1360098744 ---------------

Ive added the 2 lines i need to in editpost.php, the same as i did in newthred.php, but cant find where i should be doing this dataman part.

kh99
02-05-2013, 10:20 PM
Sorry, I had to be away for a while. Anyway, the dataman part is in the editpost.php file, starting around line 176. It's a little different than creating a new post - it's doesn't have that extra layer of call to build_new_post(). It just goes from $vbulletin->GPC[] right to setting the dataman fields. (Well, actually it sets a $edit array then sets the dataman from that, but it's all in the same file).

glennybee
02-06-2013, 04:45 PM
Yay!! sorted, all working good!

Again... thanks a million