PDA

View Full Version : Coding problem


jagtpf
02-06-2016, 09:47 AM
Hi Guys,

First real attempt at writing ....

I have, in plugins, this working script :

hooked into "postbit_display_complete"

$template_hook['postbit_userinfo_right_after_posts'] .=
'<br><dt>Nominate for Members Choice Award </dt> <dd><a href="testingthread.php"> <img src="images/buttons/memchoice.png" style="width: 26px; height: 26px; border: 0px;" alt="Nominate This Poem for Members Choice Award. Thank you."></a></dd>';

The active icon initiates the .php.

The php creates a new thread in a nominated Forum.

My problem is I can't work out how to 'send' details, such as, ThreadID into the .php and it's driving me nuts as no matter what I try I can't get anything useful to transfer which is an element of my inexperience.

I've tried {vb:raw post.postid} and similar expressions and
. $sessionurl . 'do=newthread&amp;f=' . $forumid .
none of which work.

Question : Am I using an incorrect/inadvisable method with the plugin and, instead, should use a template to display icon and 'send' information to the .php?

warmly

Geoff

MarkFL
02-06-2016, 10:02 AM
What you could do to pass the threadid to your external script is change the anchor tag as follows:

<a href="testingthread.php?threadid=' . $threadinfo['threadid'] . '">

And then in your external script, you can retrieve this parameter with:

$_REQUEST['threadid']

jagtpf
02-07-2016, 06:53 AM
What you could do to pass the threadid to your external script is change the anchor tag as follows:

<a href="testingthread.php?threadid=' . $threadinfo['threadid'] . '">

And then in your external script, you can retrieve this parameter with:

$_REQUEST['threadid']


Thank you Mark - Perhaps my 'missing link'.

--------------- Added 1454836359 at 1454836359 ---------------

' . $threadinfo['threadid'] . '

sadly, this part on the ref returns a blank...

MarkFL
02-07-2016, 03:30 PM
At the beginning of your plugin, add:

global $threadinfo;

Let me know if that works. :)

jagtpf
02-08-2016, 07:07 AM
At the beginning of your plugin, add:

global $threadinfo;

Let me know if that works. :)

Thanks Mark, I'll give that a go, and will report back - though during the weekend in frustration I ditched the plugin and added a section to the "postbit legacy" template - perhaps not as 'convenient' as plugin, but it's partly working. Just need to narrow down what it is I'm sending through to the .php.

--------------- Added 1454923043 at 1454923043 ---------------

global $threadinfo;
$template_hook['postbit_userinfo_right_after_posts'] .=
'<br><dt>Nominate for Members Choice Award </dt> <dd><a href="testingthread.php?threadid=' . '$threadinfo[title]' . '"> <img src="images/buttons/memchoice.png" style="width: 26px; height: 26px; border: 0px;" alt="Nominate This Poem for Members Choice Award. Thank you."></a></dd>';

returns : - http://localhost/poetsl/testingthread.php?threadid=$threadinfo[title]

Dave
02-08-2016, 12:52 PM
That happens because you're not escaping the variable correctly.

The following is the right way:
$template_hook['postbit_userinfo_right_after_posts'] .=
'<br><dt>Nominate for Members Choice Award </dt> <dd><a href="testingthread.php?threadid=' . $threadinfo['title'] . '"> <img src="images/buttons/memchoice.png" style="width: 26px; height: 26px; border: 0px;" alt="Nominate This Poem for Members Choice Award. Thank you."></a></dd>';

jagtpf
02-08-2016, 02:02 PM
That happens because you're not escaping the variable correctly.

The following is the right way:
$template_hook['postbit_userinfo_right_after_posts'] .=
'<br><dt>Nominate for Members Choice Award </dt> <dd><a href="testingthread.php?threadid=' . $threadinfo['title'] . '"> <img src="images/buttons/memchoice.png" style="width: 26px; height: 26px; border: 0px;" alt="Nominate This Poem for Members Choice Award. Thank you."></a></dd>';

Thanks Dave . Always the 'little' things that upset the proverbials !

--------------- Added 1454947523 at 1454947523 ---------------

To get a working work-around I settled on the following .

{vb:raw template_hook.postbit_controls}
<vb:if condition="(in_array($thread['forumid'], array(189,105,104,114,115,109,110,111,113,112,207, 106,116,108,216,225,226,231,247))) AND ($post[postcount] == '1'))">
<a href="testingthread.php?{vb:raw session.sessionurl}do=&amp;p={vb:raw post.postid}" rel="nofollow" title="Nominate This Poem for Members Choice Award"><img src="images/buttons/memchoice.png" style="width: 26px; height: 26px; border: 0px;" alt="Nominate This Poem for Members Choice Award. Thank you." /> &nbsp; </a>
</vb:if>

Placed in "postbit legacy" template .

--------------- Added 1454947988 at 1454947988 ---------------

The accompanying .php file works as expected except it doesn't always trap the "cannot self-nominate" section - but I'll sort it out .

I've also got the layout to address in the newpost, but otherwise the following is working.

I fully appreciate it's probably very 'raw' with stuff that shouldn't be in there and stuff that ought to be added - If anyone can find any glaring issues - please advise. I've bundled together ideas from numerous places and the end result may not be 'tidy' in the eyes of experience - sadly lacking in myself!

Things to change at a later stage when I've had a breather would be a 'better' call-out on the "Cannot Self-Nominate" and a "Thank-you for Nominating" at the end of the routine ....

warmly Geoff



error_reporting(E_ALL & ~E_NOTICE & ~8192);

define('GET_EDIT_TEMPLATES', true);
define('THIS_SCRIPT', 'testingthread');
define('CSRF_PROTECTION', true);

require_once('./global.php');
require_once('./includes/functions_databuild.php');

global $postid;

$_REQUEST['postid'];

$vbulletin->input->clean_array_gpc('p', array(
'$Alto_nom'=> TYPE_STR,
'$Alto_poet' => TYPE_STR,
'$Alto_nomID'=> TYPE_INT,
'$Alto_poetID' => TYPE_INT,
'$Alto_title' => TYPE_STR,
'$Alto_forum' => TYPE_STR,
'$Alto_poemid' => TYPE_INT,
));

$Alto_nom = $postinfo['username']; //Gives name of poet
$Alto_poet = $vbulletin->userinfo['username']; //Gives name of nominator
$Alto_nomID = $postinfo['userid']; //Gives ID of poet
$Alto_poetID = $vbulletin->userinfo['userid']; //Gives ID of nominator
$Alto_title = $threadinfo['title']; //Gives title of poem
$Alto_forum = $foruminfo['title']; // Gives name of Forum
$Alto_poemid = $postinfo['threadid']; //Gives ID of thread

/*Check own poem isn't being nominated !*/
if ($Alto_nomID == $Alto_poetID)
{
echo "Whoops, I'm sorry, you may not nominate your own poem." . "<br><br>" . "Please press back-button on your browser. Thank you";
eval(print_standard_redirect('')); //Return to thread/post
}

/*Set for output to post*/

/*Set the subject */
$Alto_subject = "Nomination for Member's Choice Award";
/*Set the contents*/
$Alto_text = "Poet =" . $Alto_nom . "Poem Title =" . $Alto_title . "Forum = " . $Alto_forum . "Poem Link =" . "" . "http://localhost/poetsl/showthread.php?" . $Alto_poemid . "";

/*Post thread to nominated Forum*/

/*Create a new datamanager for posting*/
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

/*Bits & pieces*/
$forumid = '260'; // ID of Destination Forum (Adjust Accordingly) - Should Equate to "Members' Choice Nominations" (260 on Test)
$userid = $Alto_poetID; // The name of the nominator
$title = $Alto_subject; // Thread subject title
$pagetext = $Alto_text; // Content
$allowsmilie = '0'; // No smilies
$visible = '1'; // Post visible

// Parse, retrieve and process the information we need to post
$foruminfo = fetch_foruminfo($forumid);
$threadinfo = array();
$user = htmlspecialchars_uni( fetch_userinfo($userid) );

$threaddm->set_info('forum', $foruminfo);
$threaddm->set_info('thread', $threadinfo);
$threaddm->setr('forumid', $forumid);
$threaddm->setr('userid', $userid);
$threaddm->setr('pagetext', $pagetext);
$threaddm->setr('title', $title);
$threaddm->set('allowsmilie', $allowsmilie);
$threaddm->set('visible', $visible);

// Lets see what happens if we save the page
$threaddm->pre_save();
if(count($threaddm->errors) < 1) {
// Basically if the page will save without errors then let do it for real this time
$threadid = $threaddm->save();
unset($threaddm);
} else {
// There was errors in the practice run, so lets display them
var_dump ($threaddm->errors);

exit();
}

//$threadid = $threaddm->save();
eval(print_standard_redirect('')); //Return to thread/post

jagtpf
02-09-2016, 02:32 PM
I've followed example suggested in report.php in order to test that the nominee ID is not the same as the thread poster ID - in other words, for my purpose, you can't self nominate.

The coding I have only works on occasion - which is annoying......

Can anyone offer a 'better' way to grab and check the two user IDs as appropriate.

EDIT :

After another look at my code, I think it is working, but I hadn't told it what to do if the condition was TRUE - hence it continued through the rest of the code!
Although it's not echoing the error message.

Dave
02-09-2016, 02:46 PM
I cleaned it up for you. Removed unnecessary definitions of variables and a couple of other things. Note that I didn't test it so I'm not sure if it will actually work like this.

error_reporting(E_ALL & ~E_NOTICE & ~8192);

define('GET_EDIT_TEMPLATES', true);
define('THIS_SCRIPT', 'testingthread');
define('CSRF_PROTECTION', true);

require_once('./global.php');
require_once('./includes/functions_databuild.php');

if(isset($vbulletin->GPC['p']) && ctype_digit($vbulletin->GPC['p']))
{
// Set post, thread and forum info.
$postinfo = fetch_postinfo($vbulletin->GPC['p']);
$threadinfo = fetch_threadinfo($postinfo['threadid']);
$foruminfo = fetch_foruminfo(260);

// Don't allow self voting.
if ($postinfo['userid'] == $vbulletin->userinfo['userid']){
die("Whoops, I'm sorry, you may not nominate your own poem." . "<br><br>" . "Please press back-button on your browser. Thank you");
}

// Subject & Pagetext
$title = "Nomination for Member's Choice Award";
$pagetext = "Poet =" . $postinfo['username'] . "Poem Title =" . $threadinfo['title'] . "Forum = " . $foruminfo['title'] . "Poem Link =" . "" . "http://localhost/poetsl/showthread.php?" . $postinfo['threadid'] . "";

/*Create a new datamanager for posting*/
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$threaddm->set_info('forum', $foruminfo);
$threaddm->set_info('thread', $threadinfo);
$threaddm->setr('forumid', 260);
$threaddm->setr('userid', $vbulletin->userinfo['userid']);
$threaddm->setr('pagetext', $pagetext);
$threaddm->setr('title', $title);
$threaddm->set('allowsmilie', 0);
$threaddm->set('visible', 1);

// Lets see what happens if we save the page
$threaddm->pre_save();
if(count($threaddm->errors) < 1) {
$threadid = $threaddm->save();
unset($threaddm);
} else {
var_dump($threaddm->errors);
exit;
}

//$threadid = $threaddm->save();
eval(print_standard_redirect('')); //Return to thread/post
}else{
die("No post id in URL.");
}

jagtpf
02-09-2016, 03:00 PM
Thank you Dave - much appreciate the work you must have done on this .... Looks a hell lot better than my version.

I still need to double check the conditional which I've just discovered wasn't functioning properly on my original - I guess the routine just carried on regardless ....

'Just' looking to see if there's a 'better' way to advise on 'error' and add a 'thank you' at the end. Probably a javascript addition.

--------------- Added 1455038807 at 1455038807 ---------------

mmm

It's not creating/sending the thread - just returning the final statement "No post id in URL".

Dave
02-09-2016, 04:03 PM
Hmm and the URL contains "&p=somenumber" right?

jagtpf
02-09-2016, 04:11 PM
The url is correct.
The routine has ended with the echo "No post id in URL" ,
and the routine doesn't create a new thread ....

Dave
02-09-2016, 04:12 PM
Not quite sure what you mean.. there's no URL? I mean the address in the browser, not the contents of the page itself.

jagtpf
02-09-2016, 04:16 PM
Not quite sure what you mean.. there's no URL? I mean the address in the browser, not the contents of the page itself.

Yes, sorry, I gathered that after I'd written the message and went and had another look.

jagtpf
02-09-2016, 04:21 PM
as attached so I don't get it wrong - again :o

Dave
02-09-2016, 04:27 PM
Try this version: http://pastebin.com/raw/anqMsD7u

jagtpf
02-09-2016, 04:36 PM
That version returns :

Fatal error: Cannot pass parameter 1 by reference in C:\xampp\htdocs\poetsl\testingthread.php on line 20.

Line 20, according to my check, is " $foruminfo = fetch_foruminfo(260); "

..and 260 exists as the destination Forum.

Sorry, I'll have to log off now - but many thanks for your support and help - much appreciated. Even if things are a little frustrating ....

warmly

Geoff