Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2016, 09:47 AM
jagtpf jagtpf is offline
 
Join Date: Mar 2015
Location: Scotland
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 02-06-2016, 10:02 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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'
Reply With Quote
  #3  
Old 02-07-2016, 06:53 AM
jagtpf jagtpf is offline
 
Join Date: Mar 2015
Location: Scotland
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
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...
Reply With Quote
  #4  
Old 02-07-2016, 03:30 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

At the beginning of your plugin, add:

PHP Code:
global $threadinfo
Let me know if that works.
Reply With Quote
Благодарность от:
Lynne
  #5  
Old 02-08-2016, 07:07 AM
jagtpf jagtpf is offline
 
Join Date: Mar 2015
Location: Scotland
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
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]
Reply With Quote
  #6  
Old 02-08-2016, 12:52 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>'
Reply With Quote
Благодарность от:
jagtpf
  #7  
Old 02-08-2016, 02:02 PM
jagtpf jagtpf is offline
 
Join Date: Mar 2015
Location: Scotland
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dave View Post
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 
Reply With Quote
  #8  
Old 02-09-2016, 02:32 PM
jagtpf jagtpf is offline
 
Join Date: Mar 2015
Location: Scotland
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 02-09-2016, 02:46 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.");

Reply With Quote
  #10  
Old 02-09-2016, 03:00 PM
jagtpf jagtpf is offline
 
Join Date: Mar 2015
Location: Scotland
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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".
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:56 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.07494 seconds
  • Memory Usage 2,372KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_html
  • (13)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (2)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete