Log in

View Full Version : Basics of a Hack??


pgowder
02-04-2003, 12:02 AM
Can someone explain the structure of a hack.

I have a php file that calls some functions and queries in a different db. I want to be able to display this on my main forum page.

What are the needed statements in the other php?

How do you intergrate it into templates?

Thanks

pgowder
02-06-2003, 07:24 PM
Can anyone help???

Thanks!

Shpookdefied
02-06-2003, 11:01 PM
Well, in all technicality, a hack for vB is just a modification of code from the default, I guess you could say.

You should specify on what your asking, because your questions seem a bit vague.

pgowder
02-07-2003, 11:53 AM
Ok, here's what I'm trying to do.

I use osCommerce as my shopping cart.

I have a php script that pulls a random picture of a product and displays it with a link to "Buy Now".

I use this on the front page of my site. But I would also like to include this on the main page of vBulletin.

How do I include a PHP file?

pgowder
02-10-2003, 05:00 PM
Did that make sense?

Can you help?

pgowder
02-11-2003, 12:12 PM
Anyone?

pgowder
02-15-2003, 11:47 AM
Anyone??? Please help!

Logician
02-18-2003, 08:51 AM
adding

include 'http://www.rul.com/yourscript.php';

to phpinclude template might help..

pgowder
02-18-2003, 11:35 AM
Thanks!

That does print out my php file. But it just includes at the top. How can I specify the include file and have it placed in a certain template?

pgowder
02-18-2003, 11:38 AM
I tried this:

//ob_start();
//require("/home/virtual/powwows.com/var/www/html/ssi/shop.php");
//$file4 = ob_get_contents();
//ob_end_clean();


But I get this error:

Database error in vBulletin 2.2.8:

Invalid SQL: SELECT * FROM usergroup WHERE usergroupid=6
mysql error:

mysql error number:

Date: Tuesday 18th of February 2003 08:35:55 AM
Script: http://www.powwows.com/gathering/gathering/index.php?
Referer: http://www.powwows.com/gathering/admin/index.php?action=head

Logician
02-18-2003, 12:59 PM
2 alternatives:
1- use this in phpinclude template:

$file4=include("/home/virtual/powwows.com/var/www/html/ssi/shop.php");


and use $file4 in any template you want
BUT
in this case you must hack your shop.php too and make sure it RETURNs its output like a function (otherwise you'll get value "1" from the script instead of code itself)

2- Add your

include("/home/virtual/powwows.com/var/www/html/ssi/shop.php");
to another template and change its parsing inside vb with this line:

eval(gettemplate('templatename',0,0));


Well you'll still have problems pasting the content in the location you like via this method because this line might immediately start HTML output so I suggest go with first solution..

Alternatively you can dump your shop.php script and create a in-vb code which will randomly get an item from database which is certainly the best solution if your shop.php is not performing other complicated tasks..

pgowder
02-18-2003, 01:37 PM
Originally posted by Logician

Alternatively you can dump your shop.php script and create a in-vb code which will randomly get an item from database which is certainly the best solution if your shop.php is not performing other complicated tasks..

No, it just selects a record at random.

How do you create this script in vb code?

Dominick
02-19-2003, 07:54 PM
the real basics

global php in forum root is where you would call all globally available functions.

function.php would call functions specific to a template

IE the eval statements that usually have a gettemplate command attached

pgowder
02-19-2003, 07:59 PM
Ok, so here's one of the places I get confused.

What goes in the template and what goes in a seperate php file.

Here is the source of the php that I'm trying to use in vb.


<table width="95%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="14"><img src="http://www.powwows.com/images/tables/blue/sTable_TopLeft.gif" width="14" height="10" alt=""></td>
<td background="http://www.powwows.com/images/tables/blue/sTable_Top.gif"><img src="http://www.powwows.com/images/tables/blue/sTable_Top.gif" width="20" height="10" alt=""></td>
<td width="14"><img src="http://www.powwows.com/images/tables/blue/sTable_TopRight.gif" width="14" height="10" alt=""></td>
</tr>

<tr>
<td width="14" background="http://www.powwows.com/images/tables/blue/sTable_Left.gif" bgcolor="#000066"><img src="http://www.powwows.com/images/tables/blue/sTable_Left.gif" width="14" height="20" alt=""></td>
<td valign="top" align="center" bgcolor="#000066"><a href="http://www.powwows.com/shop"><font face=Verdana size="-1" color="#ffff00"><b>Pow Wow Shop</b></font></font></td>
<td width="14" background="http://www.powwows.com/images/tables/blue/sTable_Right.gif" bgcolor="#000066"><img src="http://www.powwows.com/images/tables/blue/sTable_Right.gif" width="14" height="20" alt=""></td>
</tr>

<tr>
<td width="14" background="http://www.powwows.com/images/tables/white/sTable_Left.gif"><img src="http://www.powwows.com/images/tables/white/sTable_Left.gif" width="14" height="20" alt=""></td>
<td bgcolor="#FFFFFF" algin="center">
<center>
<br>

<?php

$db_server = "localhost"; //database server
$db_user = ""; //database user
$db_pass = ""; //database password
$db_name = ""; //database name
$domain_name = "www.powwows.com";
$catalog_folder_name = "shop";
$site_title = "PowWows.com";
$image_width = "100";
$image_height = "100";
$num_products = "18";
$prod_col = "3";
$table_width = "95";
$table_align = "center";
$table_cspace = "0";
$table_cpadd = "0";
$product_price_show = "0";
$product_image_show = "1";
$product_info_link_show = "1";
$product_buy_link_show = "1";
$product_name_show = "1";

?>

<?php

// create connection
$connection = mysql_connect("$db_server","$db_user","$db_pass")
or die("Couldn't make connection.");

// select database
$db = mysql_select_db("$db_name", $connection)
or die("Couldn't select database.");

// create SQL statement
$sql = 'SELECT * FROM `products` WHERE products_status = \'1\' AND products_image != \'ARRAY\' ORDER BY RAND( ) LIMIT 1';
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute quasery.");

// format results by row
$row = mysql_fetch_array($sql_result);

$products_id = $row["products_id"];
$products_price = $row["products_price"];
$products_model = $row["products_model"];
$products_image = $row["products_image"];

$sql2 = "SELECT `products_name` FROM `products_description` WHERE products_id = '$products_id' LIMIT 1";
$sql2_result = mysql_query($sql2,$connection)
or die("Couldn't execute query.");
$row2 = mysql_fetch_array($sql2_result);

$products_name = $row2["products_name"];
$products_image_replace = str_replace("./", "/", $products_image);
$products_price_replace = str_replace(".0000", "", $products_price);

if ($product_info_link_show == "1") {
echo "<a href=\"http://$domain_name/$catalog_folder_name/product_info.php?products_id=$products_id\" style=\"text-decoration: none\">";
}
if ($product_image_show == "1") {
echo "<img src=\"http://$domain_name/$catalog_folder_name/images/$products_image_replace\" width=\"$image_width\" border=\"0\"><br>";
}
echo "<font face=\"Verdana\" size=\"-2\" color=\"#000066\"><b>";
if ($product_name_show == "1") {
echo "$products_name";
}
if ($product_price_show == "1") {
echo "&nbsp; \$$products_price_replace";
}
echo "</b></font>";
if ($product_info_link_show == "1") {
echo "</a>";
}
//if ($product_buy_link_show == "1") {
//echo "<br><a href=\"http://$domain_name/$catalog_folder_name/product_info.php?products_id=$products_id\"><font face=\"Verdana, Tahoma\" size=\"-1\" color=\"#000000\"><b>Buy Now</b></font></a></td>";
//}
?>
</td>
<td width="14" background="http://www.powwows.com/images/tables/white/sTable_Right.gif" bgcolor="#ffffff"><img src="http://www.powwows.com/images/tables/white/sTable_Right.gif" width="14" height="20" alt=""></td>
</tr>


<tr>
<td width="14" background="http://www.powwows.com/images/tables/blue/sTable_Left.gif" bgcolor="#000066"><img src="http://www.powwows.com/images/tables/blue/sTable_Left.gif" width="14" height="20" alt=""></td>
<td valign="top" align="center" bgcolor="#000066">
<?
if ($product_buy_link_show == "1") {
echo "<a href=\"http://$domain_name/$catalog_folder_name/product_info.php?products_id=$products_id\"><font face=\"Verdana, Tahoma\" size=\"-1\" color=\"#ffff00\"><b>Buy Now</b></font></a></td>";
}
?>
</td>
<td width="14" background="http://www.powwows.com/images/tables/blue/sTable_Right.gif" bgcolor="#000066"><img src="http://www.powwows.com/images/tables/blue/sTable_Right.gif" width="14" height="20" alt=""></td>
</tr>



<?
// free resources and close connection
mysql_free_result($sql_result);
mysql_close($connection);
?>
</center>



<tr>
<td width="14"><img src="http://www.powwows.com/images/tables/blue/sTable_BottomLeft.gif" width="14" height="10" alt=""></td>
<td background="http://www.powwows.com/images/tables/blue/sTable_Bottom.gif"><img src="http://www.powwows.com/images/tables/blue/sTable_Bottom.gif" width="20" height="10" alt=""></td>
<td width="14"><img src="http://www.powwows.com/images/tables/blue/sTable_BottomRight.gif" width="14" height="10" alt=""></td>
</tr>
</table>
</center>

Dean C
02-20-2003, 08:30 AM
Instead of having html called by the php file. Create a template in the admin cp and call it by using this function:


eval("dooutput(\"".gettemplate('templatename')."\");");


Use templates in all sorts of places where you have if statements and replace the html in the if statements with a template call. Then place the html in the template.

Then any html you want outputted on one page call the template right at the end of the php file. And you can use the variable you assigned earlier in the script to put it on the page.

E.g.


<?

if ($bbuserinfo[posts]>10) {
eval("\$minposts = \"".gettemplate('minposts')."\";");
}

eval("dooutput(\"".gettemplate('mainhtml')."\");");

?>


Your main template:


<!-- this will be the mainhtml template as it will be called straight away -->
<b>Hello User</b><br />
<!-- Min posts bit -->
$minposts


Now minposts has been called before the final template so you can use the variable to call the minposts template. If the user has less than 80 posts it will output the template 'minposts'. Else it won't.

Just as the script does :)

- miSt