Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2011, 04:01 PM
CampinCarl CampinCarl is offline
 
Join Date: Apr 2008
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Access $post variables in external php

okay. I'm writing a tiny widget for the post_legacy template that uses a players $post['field5'] (or their steam id for steam) information to make a html widget with they're associated stats. The only problem im running into is that i cant access the $post['field5'] from the php script that gets included in the template with a plugin.

Any help would be great.
Reply With Quote
  #2  
Old 02-26-2011, 04:03 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to post your exact code that your are using in order for us to help you. Please post your plugin code and let us know the hook location you are using and post any template code you have added also and let us know what template. Please post all code in code/php/html tags.
Reply With Quote
  #3  
Old 02-26-2011, 04:20 PM
CampinCarl CampinCarl is offline
 
Join Date: Apr 2008
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay should of done that lol.

This is the PHP (stat_widget.php):
Code:
<head>
	<style>
		#BigBox {  
			color: #fff;
			padding: 4px 4px;
			text-decoration: none;
			-moz-border-radius: 7px; 
			-webkit-border-radius: 7px;
			-moz-box-shadow: 0 1px 3px rgba(0,0,0,0.5);
			-webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.5);
		}
	</style>
</head>

<?php
//SteamID
$steamid=$post['field5'];

//GET GAMEME INFORMATION
define("CLIENT_API_URL", "http://protf2.gameme.com/api");

//GRAB STATS
	$tfpxml = new SimpleXMLElement(file_get_contents(CLIENT_API_URL."/playerinfo/tf/".$steamid));
	if (count($tfpxml->playerinfo[0]->player) > 0) {       
		$tfplayerdata = array();
		$tfplayerdata['name'] = $tfpxml->playerinfo[0]->player[0]->name;
		$tfplayerdata['cc'] = $tfpxml->playerinfo[0]->player[0]->cc;
		$tfplayerdata['clanname'] = $tfpxml->playerinfo[0]->player[0]->clanname;
		$tfplayerdata['id'] = $tfpxml->playerinfo[0]->player[0]->id;
		$tfplayerdata['time'] = $tfpxml->playerinfo[0]->player[0]->time;
		$tfplayerdata['rank'] = $tfpxml->playerinfo[0]->player[0]->rank;
		$tfplayerdata['skill'] = $tfpxml->playerinfo[0]->player[0]->skill;
		$tfplayerdata['kills'] = $tfpxml->playerinfo[0]->player[0]->kills;
		$tfplayerdata['deaths'] = $tfpxml->playerinfo[0]->player[0]->deaths;
		$tfdays= intval($playerdata['time']/60/60/24);
		$tfhours= intval(($playerdata['time']/60/60)-($days*24));
		$tfminutes= intval(($playerdata['time']/60)-($hours*60)-($days*24*60));
		$tfseconds= intval(($playerdata['time'])-($hours*60*60)-($days*24*60*60)-($minutes*60));		
	}
	
//ECHO THE INFO
	IF ($tfplayerdata['id']<>'') {
			echo '<table style="float:right; valign:middle; width:170px;">';
			echo	'<tr></tr>';
			echo	'<tr><td valign="middle" rowspan="2">';
			echo		'<table style="z-index:2; padding:0px; width:50px; position:relative; left:+0px; background: black url(http://zurb.com/images/alert-overlay.png) repeat-x; " id="BigBox">';
			echo			'<tr><td valign="middle" align="center" style="padding: 3px 0px 3px 0px;"><a href="http://protf2.gameme.com/playerinfo/'.$tfplayerdata['id'].'"><img name="TF2 Stats" src="http://forum.specialattack.net/images/icons/tf2.png"/></a></td></tr>';
			echo		'</table>';
			echo	'</td></tr>';
			echo	'<tr><td valign="middle">';
			echo		'<table height="41" style="position:relative; left:-40px; background: gray url(http://zurb.com/images/alert-overlay.png) repeat-x;" id="BigBox">';
			echo			'<tr><td style="text-shadow:1px 1px 1px rgba(0,0,0,0.75);padding: 0px 10px 0px 25px;"><b>Rank: </b>'.$tfplayerdata['rank'].'<br><b>Points: </b>'.$tfplayerdata['skill'].'</td></tr>';
			echo		'</table>';
			echo	'</td></tr>';
			echo '</table>';
	}
?>
This is a snip from the template where I modded it (postbit_legacy)
Code:
				{vb:raw template_hook.postbit_messagearea_start}
				<vb:if condition="$post['title'] OR $show['messageicon']">
                                <vb:if condition="$post['field5']">{vb:raw statswidget}</vb:if>
				<h2 class="title icon">
					<vb:if condition="$show['messageicon']"><img src="{vb:raw post.iconpath}" alt="{vb:raw post.icontitle}" /> </vb:if>{vb:raw post.title}
				</h2>
				</vb:if>
And then this is the plugin: (hook location: global_start)
Code:
ob_start(); 
  require_once('/home/protf2/public_html/stat_widget.php'); 
  $statswidget = ob_get_contents(); 
ob_end_clean(); 
vB_Template::preRegister('postbit_legacy',array('statswidget' => $statswidget));


I used this to create the plugin http://www.vbulletin.com/forum/showt...P-or-HTML-File
Reply With Quote
  #4  
Old 02-26-2011, 05:02 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You cannot have a <head> tag in the code. You are only allowed one <head> tag per page and you are going to cause a problem if you have another.

And, global_start is deprecated - you should not use it. But, besides that, it is at the very beginning of the code when $post is not even defined. If you want to use a $post variable, you need to use a hook that can get this information like a postbit_display_* hook location.
Reply With Quote
  #5  
Old 02-26-2011, 06:15 PM
CampinCarl CampinCarl is offline
 
Join Date: Apr 2008
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

All of that stuff works. And the head tag because the box gets formatted correctly. its just that the data is blank.

I set the hook to postbit_display_complete and it didnt work neither.
Reply With Quote
  #6  
Old 02-26-2011, 06:21 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And the data will remain blank because you cannot access the $post variable at global_start - it doesn't exist there. $post is the information about the user making the post, so you will have several different $post['field5'] on the page - a different one for each $post. global_start (which is deprecated and will disappear in the future and break any products using it) is called once on the page at the beginning. It does not have any $post data available to it.
Reply With Quote
  #7  
Old 02-26-2011, 06:33 PM
CampinCarl CampinCarl is offline
 
Join Date: Apr 2008
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay i lied. It works after i set the correct hook location. But the widget only shows up on the first post of each thread.
Reply With Quote
  #8  
Old 02-26-2011, 07:47 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What hook location did you change to?
Reply With Quote
  #9  
Old 02-26-2011, 07:59 PM
CampinCarl CampinCarl is offline
 
Join Date: Apr 2008
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I set it as postbit_display_complete
Reply With Quote
  #10  
Old 02-26-2011, 08:43 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can we get a link to see this?
Reply With Quote
Reply

Thread Tools
Display Modes

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 08:44 PM.


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.04133 seconds
  • Memory Usage 2,241KB
  • Queries Executed 11 (?)
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
  • (3)bbcode_code
  • (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
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (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_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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete