PDA

View Full Version : How do I Convert Custom Modules to VBA 4



rwoscott
03-09-2010, 10:08 PM
I had a few custom modules that worked fine, on the older version of vba, but now I have no idea how to update them to work with the new VB/vba.

Here is my php code, (butchered trying different things)
The include fixturesmall.php returns $fixture[0] thru [5], as an html row of code/data.

<?php

$collapseobj_fixture = $vbcollapse['collapseobj_fixture'];
$collapseimg_fixture = $vbcollapse['collapseimg_fixture'];

include_once('fixturesmall.php');

$templater = vB_Template::create('adv_portal_fixture');
//$templater->register('fixture[0]', $fixture[0]);

// eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('adv_portal_fixture') . '";');
$home[$mods['modid']]['content'] = $templater->render();

?>

Here is my adv_portal_fixture template

<div class="blockrow">
<!-- Your code here -->

<!-- <table border="0"> -->
$fixture[0]
$fixture[1]
$fixture[2]
$fixture[3]
$fixture[4]
<!-- </table> -->
<!-- Custom Code End -->
</div>


I'm no expert on php and would like some assistance with this.
I've looked at the supplied modules, but it's all foreign to me. :(
I'm also guesing it has something to do with the new $templater render stuff.

Brian
03-10-2010, 01:14 PM
This should be all you need to call the template and set the variables:

$templater = vB_Template::create('adv_portal_fixture');
$templater->register('fixture', $fixture);
$home[$mods['modid']]['content'] = $templater->render();

Then in your template, you need to use {vb:raw fixture.0} {vb:raw fixture.1} etc.

Our Sponsors
 

rwoscott
03-11-2010, 09:57 PM
No Luck Brian.

This is my PHP page.

<?php

$collapseobj_fixture = $vbcollapse['collapseobj_fixture'];
$collapseimg_fixture = $vbcollapse['collapseimg_fixture'];

include_once('fixturesmall.php');

$templater = vB_Template::create('adv_portal_fixture');
$templater->register('fixture', $fixture);
$home[$mods['modid']]['content'] = $templater->render();

?>

and this is my adv_portal_fixture


<div class="blockrow">
<!-- Your code here -->

<table border="0">
{vb:raw fixture.0}
{vb:raw fixture.1}
{vb:raw fixture.2}
{vb:raw fixture.3}
{vb:raw fixture.4}
</table>
<!-- Custom Code End -->
</div>

Brian
03-12-2010, 11:53 AM
You may not be able to use array keys in vB templates anymore... Can you post the contents of your fixturesmall.php file here?

Our Sponsors
 

rwoscott
03-12-2010, 10:50 PM
Here you go.


<?php

$PATH = $_SERVER['DOCUMENT_ROOT']; #get server path to webshare

$path=$PATH.'/forum/modules/fixture/fixture.txt';

$file = fopen($path, "r");
$today = date("d-M-Y");
$total = 0;

$fixture[0] = "";
$fixture[1] = "";
$fixture[2] = "";
$fixture[3] = "";
$fixture[4] = "";
?>

<?php
while(!feof($file))
{
$data = fgets($file);
$data_split = split("\t", $data); #break up the data into $data_split array, split where the tabs are

#assign the first item of $data_split to $fname, etc

// $rnd=substr($data_split[0],0,1);
$rnd=$data_split[0];
$date=$data_split[1];
$time=$data_split[2];
$team=$data_split[3];
$ha=$data_split[4];
$venue=$data_split[5];
$day=$data_split[6];

if (strtotime($date) >= strtotime($today))
{
if ($total > 5)
{break;}
#now print for viewing:
$ddate = date('d\/m', strtotime($date));
if($total & 1) {
$fixture[$total] = "<tr class=\"alt1\"><td><span class=\"smallfont\"><b>$rnd</b></span></td><td><span class=\"smallfont\"> $ddate</span></td><td><span class=\"smallfont\"> $team</span></td><td><span class=\"smallfont\"> $venue</span></td></tr>";
}
else {
$fixture[$total] = "<tr class=\"alt2\"><td><span class=\"smallfont\"><b>$rnd</b></span></td><td><span class=\"smallfont\"> $ddate</span></td><td><span class=\"smallfont\"> $team</span></td><td><span class=\"smallfont\"> $venue</span></td></tr>";
}
// echo $fixture[$total];
$total++;
}
}
fclose($file)
?>


EDIT:
Also this may help, it is the source of the html page for the fixture.

<div class="collapse" style="padding-bottom: 2px;">
<h2 class="blockhead">
<strong>&raquo; <a href="../?pageid=aflfixture">Swans Fixture</a></strong>

</h2>


<div class="vba_module">
<div class="blockbody" id="module20">


<!-- <table border="0" width="100%" cellpadding="1" cellspacing="0"> -->
<!-- </table> -->



</div>
</div>
</div>


The commented out table tags, were removed from the above fixturesmall.php when I posted it to save any confusion.

It appears to not be getting into the template still!?!?!?

Brian
03-13-2010, 01:10 PM
Try using this for your PHP file instead and see if you get any better results:

<?php

$PATH = $_SERVER['DOCUMENT_ROOT']; #get server path to webshare

$path=$PATH.'/forum/modules/fixture/fixture.txt';

$file = fopen($path, "r");
$today = date("d-M-Y");
$total = 0;

$fixture['0'] = "";
$fixture['1'] = "";
$fixture['2'] = "";
$fixture['3'] = "";
$fixture['4'] = "";
?>

<?php
while(!feof($file))
{
$data = fgets($file);
$data_split = split("\t", $data); #break up the data into $data_split array, split where the tabs are

#assign the first item of $data_split to $fname, etc

// $rnd=substr($data_split[0],0,1);
$rnd=$data_split[0];
$date=$data_split[1];
$time=$data_split[2];
$team=$data_split[3];
$ha=$data_split[4];
$venue=$data_split[5];
$day=$data_split[6];

if (strtotime($date) >= strtotime($today))
{
if ($total > 5)
{break;}
#now print for viewing:
$ddate = date('d\/m', strtotime($date));
if($total & 1) {
$fixture["$total"] = "<tr class=\"alt1\"><td><span class=\"smallfont\"><b>$rnd</b></span></td><td><span class=\"smallfont\"> $ddate</span></td><td><span class=\"smallfont\"> $team</span></td><td><span class=\"smallfont\"> $venue</span></td></tr>";
}
else {
$fixture["$total"] = "<tr class=\"alt2\"><td><span class=\"smallfont\"><b>$rnd</b></span></td><td><span class=\"smallfont\"> $ddate</span></td><td><span class=\"smallfont\"> $team</span></td><td><span class=\"smallfont\"> $venue</span></td></tr>";
}
// echo $fixture[$total];
$total++;
}
}
fclose($file)
?>

rwoscott
03-13-2010, 08:43 PM
Try using this for your PHP file instead and see if you get any better results:

<?php

$PATH = $_SERVER['DOCUMENT_ROOT']; #get server path to webshare

$path=$PATH.'/forum/modules/fixture/fixture.txt';

$file = fopen($path, "r");
$today = date("d-M-Y");
$total = 0;

$fixture['0'] = "";
$fixture['1'] = "";
$fixture['2'] = "";
$fixture['3'] = "";
$fixture['4'] = "";
?>

<?php
while(!feof($file))
{
$data = fgets($file);
$data_split = split("\t", $data); #break up the data into $data_split array, split where the tabs are

#assign the first item of $data_split to $fname, etc

// $rnd=substr($data_split[0],0,1);
$rnd=$data_split[0];
$date=$data_split[1];
$time=$data_split[2];
$team=$data_split[3];
$ha=$data_split[4];
$venue=$data_split[5];
$day=$data_split[6];

if (strtotime($date) >= strtotime($today))
{
if ($total > 5)
{break;}
#now print for viewing:
$ddate = date('d\/m', strtotime($date));
if($total & 1) {
$fixture["$total"] = "<tr class=\"alt1\"><td><span class=\"smallfont\"><b>$rnd</b></span></td><td><span class=\"smallfont\"> $ddate</span></td><td><span class=\"smallfont\"> $team</span></td><td><span class=\"smallfont\"> $venue</span></td></tr>";
}
else {
$fixture["$total"] = "<tr class=\"alt2\"><td><span class=\"smallfont\"><b>$rnd</b></span></td><td><span class=\"smallfont\"> $ddate</span></td><td><span class=\"smallfont\"> $team</span></td><td><span class=\"smallfont\"> $venue</span></td></tr>";
}
// echo $fixture[$total];
$total++;
}
}
fclose($file)
?>

Tried and no result Brian.
In fact, it looks the same as the one I already had, unless there is a very subtle difference??

rwoscott
03-21-2010, 06:16 PM
I can't say too much intelligent about your code. Your intended uses for it are interesting, particularly the code comparing feature.If you want to programmatically insert some VBA into a project, you can do it more easily than pasting in a bunch of lines of code. You can insert a module from a file on disk into the project. Put your favorite functions into such a module, and keep it in a handy directory.

Care to elaborate a bit more, as I'm not sure what you are referring to.
Mind you my php skills are purely from reading a book. very basic.

The purpose of this module, is to show the next 5 games, off the footy fixture.


ED:
PS, I got this to work, but without using the module template. I wrote the details out from the php code.

Brian
03-22-2010, 12:32 PM
The guy above was either a spammer, or someone who's really in the wrong place (his post sounds more like he's talking about Visual Basic instead of anything to do with vBadvanced).