vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   EQDKP in the postbit (https://vborg.vbsupport.ru/showthread.php?t=160153)

sifo 10-13-2007 05:11 PM

EQDKP in the postbit
 
I am trying to add a field in the postbit to display the users current DKP. I am somewhat of a novice but I have been learning rather quickly. The way my site is set up is that the EQDKP site and the vBulletin forums are separate MYSQL databases.

The way I envision this working is that I create a new User Profile Field through the Admin CP. It is just a string. My users enter their userid from our DKP site into that field. With this string entered into the 'fieldXX' (field6 for my board), I can use that string to index my array and extract the pertinent data to calculate the current DKP.

The code below works properly by itself but I don't have enough knowledge to incorporate it into vBulletin. I'm not sure if this is too much of a bother to even worry about or if it would take just a few lines in the right place - any help would be greatly appreciated.

Code:

<?php

mysql_connect("myserver.net","myusername","mypassword") or die(mysql_error());

mysql_select_db("mydatabase") or die(mysql_error());

// $dkpname is the string that will come from 'fieldXX' which is a user defined profile field to display in the postbit

$yourdkpname = mysql_query("SELECT * FROM eqdkp_members
 WHERE member_name= '$dkpname'") or die(mysql_error());

$data = mysql_fetch_array($yourdkpname);

$yourdkp = $data['member_earned'] - $data['member_spent'] + $data['member_adjustment'];

// $yourdkp is the current dkp that I want to be displayed in the postbit

?>


Analogpoint 10-13-2007 07:49 PM

To test this, just put the code you posted in a plugin that is fired on the global_start hook, then put $yourdkp in your postbit template (or postbit_legacy if that's the one you're using).

But please sanitize your database inputs. Do you know what would happen if someone entered this as their DKP userid?

[sql]joeblow'; drop table eqdkp_members; --[/sql]

At least do this before your query.

PHP Code:

$dkpname mysql_real_escape_string($dkpname); 


sifo 10-15-2007 12:48 AM

I believe I have done everything you suggested. However, $yourdkp doesn't seem to be displaying. I have tried entering a manual value for $yourdkp and bypassed the database query in the plugin and I still don't get a value displayed.

This is what I entered in the postbit:
Code:

<if condition="$post['field6']">Current DKP: $yourdkp<else />Current DKP: N/A</if>
Thanks for your help!

Kiint 10-15-2007 02:02 PM

I haven't really looked at your code, but this is what I use on my site in the profile of each person, I have a page that has this code:

PHP Code:

$result $db->query("SELECT * FROM " TABLE_PREFIX "`eqdkp_items`
                               LEFT JOIN eqdkp_raids ON eqdkp_items.raid_id=eqdkp_raids.raid_id
                               WHERE `item_buyer` = \""
.$chardata[fname]."\"
                               ORDER BY `item_date` DESC"
);
    
$ii $db->num_rows($result);
    while(
$loot $db->fetch_array($result)) {
        
$lootdate date("D, F j, Y, g:i a"$loot[item_date]);
  eval(
'$loothistory .= "' fetch_template('roster_profile_loot') . '";');
 }
    
$db->free_result($result); 

Then a template called 'roster_profile_loot' with the following in it:

HTML Code:

<tr>
 <td class="alt1" align="left">
 <a href="http://www.yoursite.com/eqdkp/viewitem.php?s=&i=$loot[item_id]" target="_blank">$loot[item_name]</a></td>
 <td class="alt2" align="left">
 <a href="http://www.yoursite.com/eqdkp/viewraid.php?s=&r=$loot[raid_id]"  target="_blank">$loot[raid_name]</a></td>
 <td class="alt1" align="left">
 $lootdate
 </td>
</tr>

Hope this helps a little :)

sifo 10-15-2007 03:05 PM

That is definitely something I'd like to try and add in the future. I guess my real sticking point right now is how do I make a variable from a plugin to be passed/available for use in the postbit template?

Thanks again.

Analogpoint 10-15-2007 06:48 PM

Quote:

Originally Posted by sifo (Post 1360795)
That is definitely something I'd like to try and add in the future. I guess my real sticking point right now is how do I make a variable from a plugin to be passed/available for use in the postbit template?

Thanks again.

What hook location is your plugin using?

Both the hook evaluation and template evaluation have to be in the same scope. If either one is in a function, it's not going to work.

If you do this, it'll work:

Plugin code:
Code:

$GLOBALS['somevar'] = 'Hey';
In the template:
Code:

Here's my variable: $GLOBALS[somevar]

sifo 10-16-2007 09:14 AM

I got it to work properly... thanks for all of the help here!

Eikinskjaldi 10-16-2007 01:44 PM

In mysql you can prepend the table with the database name.

In other words, you can use the vbulletin mysql object, you dont have to make another, and you can join, call, whatever across databases.

select db1.table1.field1,db2.table2.field2....

Oll1 12-22-2007 12:58 AM

if you are unable to print out the mysql data from eqdkp - this will work:

in plugin:

PHP Code:

$my_dkp $vbulletin->userinfo[fieldX]; 

(Remember: NO <?php & ?> Tags !!!!!!!)

in template:

PHP Code:

$my_dkp 

works fine for me


All times are GMT. The time now is 01:12 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.01113 seconds
  • Memory Usage 1,751KB
  • 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
  • (4)bbcode_code_printable
  • (1)bbcode_html_printable
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete