vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Coding problem (https://vborg.vbsupport.ru/showthread.php?t=321729)

jagtpf 02-06-2016 09:47 AM

Coding problem
 
Hi Guys,

First real attempt at writing ....

I have, in plugins, this working script :

hooked into "postbit_display_complete"

PHP Code:

$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:

PHP Code:

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

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

PHP Code:

$_REQUEST['threadid'


jagtpf 02-07-2016 06:53 AM

Quote:

Originally Posted by MarkFL (Post 2564329)
What you could do to pass the threadid to your external script is change the anchor tag as follows:

PHP Code:

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

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

PHP Code:

$_REQUEST['threadid'



Thank you Mark - Perhaps my 'missing link'.

--------------- Added [DATE]1454836359[/DATE] at [TIME]1454836359[/TIME] ---------------

PHP Code:

' . $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:

PHP Code:

global $threadinfo

Let me know if that works. :)

jagtpf 02-08-2016 07:07 AM

Quote:

Originally Posted by MarkFL (Post 2564411)
At the beginning of your plugin, add:

PHP Code:

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 [DATE]1454923043[/DATE] at [TIME]1454923043[/TIME] ---------------

PHP Code:

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:
PHP Code:

$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

Quote:

Originally Posted by Dave (Post 2564451)
That happens because you're not escaping the variable correctly.

The following is the right way:
PHP Code:

$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 [DATE]1454947523[/DATE] at [TIME]1454947523[/TIME] ---------------

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

HTML Code:

                                        {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 [DATE]1454947988[/DATE] at [TIME]1454947988[/TIME] ---------------

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

PHP Code:


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 =" "[URL]" "http://localhost/poetsl/showthread.php?" .  $Alto_poemid "[/URL]";
    
/*Post thread to nominated Forum*/

/*Create a new datamanager for posting*/
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_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_unifetch_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.

PHP Code:

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 =" "[url]" "http://localhost/poetsl/showthread.php?" .  $postinfo['threadid'] . "[/url]"

    
/*Create a new datamanager for posting*/ 
    
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_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 [DATE]1455038807[/DATE] at [TIME]1455038807[/TIME] ---------------

mmm

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


All times are GMT. The time now is 04:25 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01312 seconds
  • Memory Usage 1,855KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (13)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete