collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 691
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

Welcome to SimplePortal.net! You can download SimplePortal from the Downloads Area!

Author Topic: Custom PhP causes website to be rendered in Articles Block  (Read 8225 times)

0 Members and 1 Guest are viewing this topic.

Offline scorcher24

  • Semi Newbie
  • *
  • Posts: 9
  • SMF Version: 2.0.2
  • SP Version: 2.3.5
Custom PhP causes website to be rendered in Articles Block
« on: August 17, 2012, 11:39:33 AM »
Hi.
I got a script in a different folder that has nothing to do with SMF or SP.
It gets messages from an outside source and writes the data to a database, which is not forumsdatabase.
I need to display data from that database in my Portal.
The code itself works, but when I include that file in a custom PHP Block, then the website renders again with error message where the articles are supposed to be.

This is the code from the display file:

Code: [Select]
<?php
// Database Classes
include_once('mysqldatabase.php');
include_once(
'mysqlresultset.php');

//****************************************************
// Config
//****************************************************

// Database
$db_host  "localhost";
$db_uname  "XXXXXX";
$db_dbname  "XXXXXX";
$db_passwd  "XXXXXX";
$show_count 1;

//****************************************************
// End of Config
//****************************************************

//function display_googlecode_webhook()
//{
try
{
// Get Singleton
$db MySqlDatabase::getInstance();

// Connect to Database
$conn $db->connect($db_host$db_uname$db_passwd$db_dbname);

// Get highest ID
$count $db->fetchOne("SELECT COUNT(*) FROM aTable");

// Query the last 2 Commits
$no_of_rows $count $show_count;
$query 'SELECT * from aTable WHERE `id` >= '.$no_of_rows;

// Walk and display results
echo '<div>';
foreach($db->iterate($query) as $row )
{
// Open Table
echo '<table border=0>';
echo '<tbody>';

// Committer
echo '<tr>';
echo '<td>Commited by:</td>';
echo '<td>'.$row->author.'</td>';
echo '</tr>';

// Revision
echo '<tr>';
echo '<td>Revision Nr.:</td>';
echo '<td>'.$row->revision.'</td>';
echo '</tr>';

// URL
echo '<tr>';
echo '<td>Repository URL:</td>';
echo '<td><a href="'.$row->url.'" target="_blank">'.$row->url.'</a></td>';
echo '</tr>';

// Date and Time
echo '<tr>';
echo '<td>Commited on:</td>';
echo '<td>'.$row->datetime.'</td>';
echo '</tr>';

// Commit Message
echo '<tr>';
echo '<th colspan="2">'.nl2br($row->messagetrue).'</th>';
echo '</tr>';

// Close Table
echo '</tbody>';
echo '</table>';

echo '&nbsp;&nbsp;&nbsp;';
}
echo '</div>';
}
catch( Exception $e)
{
echo($e->getMessage());
}
//}

I include this via:
Code: [Select]
include($_SERVER['DOCUMENT_ROOT'] . '/webhook/myfile.php');That causes the error. When I embed it in a function, see the disabled code by comments, include the file in my index.php, and call the function in my custom php block, then it says "Unable to connect to database", despite the login credentials being right.
Can anyone help with that? What would be the proper or at least less hackish way to make this work?
I am a C++ programmer and not very savy with PhP. Any help would be apreciated.

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #1 on: August 17, 2012, 12:02:40 PM »
scorcher24,

You can just use the $boarddir global instead which already contains the absolute path to the main directory.
This code will show an error message if the files are not in your main forum directory.. adjust them with child directories if desired.

Code: [Select]
global $boarddir;

if (!@file_exists($boarddir . '/mysqldatabase.php') && !@file_exists($boarddir. '/mysqlresultset.php'))
{die('<div style="color:black">Files missing</div>');}

@require_once($boarddir . '/mysqldatabase.php');
@require_once($boarddir. '/mysqlresultset.php');

.. you might have to use reverse slashes instead of forward ones like in the example above but try whatever works.

 

Offline scorcher24

  • Semi Newbie
  • *
  • Posts: 9
  • SMF Version: 2.0.2
  • SP Version: 2.3.5
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #2 on: August 17, 2012, 12:14:44 PM »
I moved all necessary files to my board directory, but the problem persists, the website gets rendered in the articles block again.
Or I did not fully understand what you mean.

I changed the source code of my file to what you suggested at the beginning and the block to:
Code: [Select]
global $boarddir;
@require_once($boarddir .  '/thefile.php');


Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #3 on: August 17, 2012, 12:22:29 PM »
I moved all necessary files to my board directory, but the problem persists, the website gets rendered in the articles block again.
Or I did not fully understand what you mean.

I changed the source code of my file to what you suggested at the beginning and the block to:
Code: [Select]
global $boarddir;
@require_once($boarddir .  '/thefile.php');

That should load the file. You can use that webhook folder you want to store it in as I didn't notice it in your example.
Code: [Select]
global $boarddir;
@require_once($boarddir .  '/webhook/thefile.php');


I don't know what your php code is in the file for specifics.. if it contains all its code in functions you will need to execute one/some of them to run the code.

also get rid of the php start tag at the beginning of your php block code as it is unnecessary.
same with the php end tag but I don't see it in the code anyhow.
omit
Code: [Select]
<?php
« Last Edit: August 17, 2012, 12:25:57 PM by Underdog »

Offline scorcher24

  • Semi Newbie
  • *
  • Posts: 9
  • SMF Version: 2.0.2
  • SP Version: 2.3.5
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #4 on: August 17, 2012, 12:31:28 PM »
When I get rid of the start tag, then the php code gets displayed in the block.

The content of "theFile.php" is in the OP.

When the code is executed directly, the website gets rendered in the articles block, when I enclose it in a function, my script cannot connect to the database. I don't why though.

edit: Okay solved the issue with the failed database connection, thats a scope problem. After solving this, I get the other problem..

Here is the website, I left it in the bad state for now:
http://nightlight2d.de/
Tell me when I can disable the block please :D
« Last Edit: August 17, 2012, 12:38:03 PM by scorcher24 »

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #5 on: August 17, 2012, 12:52:46 PM »
When I get rid of the start tag, then the php code gets displayed in the block.

The content of "theFile.php" is in the OP.

When the code is executed directly, the website gets rendered in the articles block, when I enclose it in a function, my script cannot connect to the database. I don't why though.

edit: Okay solved the issue with the failed database connection, thats a scope problem. After solving this, I get the other problem..

Here is the website, I left it in the bad state for now:
http://nightlight2d.de/
Tell me when I can disable the block please :D

You do not need to keep it enabled.. just need to say it says database error.

Since the php code from the file executed then you know it is loading the file properly.
If you want it to execute with control you put it inside of a function & then call the function when necessary.
If removing the php tag allowed the file to load then it was probably causing an issue prior when it was in place because you want it to execute that file .. that is why your code require/include it.

Is this supposed to get data from an external database or from your own?
For your own you use the smf built-in function of $smcFunc to accomplish db manipulation.

Offline scorcher24

  • Semi Newbie
  • *
  • Posts: 9
  • SMF Version: 2.0.2
  • SP Version: 2.3.5
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #6 on: August 17, 2012, 01:18:15 PM »
@Database
It is my own webserver, but a different database. I thought it might be wise to keep it seperated since it is basically unsecure data.
Someone might spoof the google webhook protocol and abuse it to hack my site.

@$smcFunc
Could you show me how to setup a file so I can use all functions from SMF?
I was unable to find any step-by-step-tutorial on how to write your own plugins.
If you have one, please link me, that would be very appreciated.
At least I could use it for the output code. Would just need to copy the code to the db of the forums.

But as said, the problem is not the database. The problem is that the website is rendered twice and one time in a block.. it is caused by the executed code from my script. Including it does not cause it. I mean, what can cause it that smf is repeating the whole html of the site again? It is there including the doc type.

Code: [Select]
<?php

global $boarddir;

if (!@
file_exists($boarddir '/mysqldatabase.php') && !@file_exists($boarddir'/mysqlresultset.php'))
{
    echo(
'<div style="color:black">Files missing</div>');
}

@require_once(
$boarddir '/mysqldatabase.php');
@require_once(
$boarddir'/mysqlresultset.php');

function 
display_googlecode_webhook()
{
//****************************************************
// Config
//****************************************************

// Database
$db_host  "localhost";
$db_uname  "XXXX";
$db_dbname  "XXXX";
$db_passwd  "XXXX";
$show_count   1;

//****************************************************
// End of Config
//****************************************************
try
{
// Get Singleton
$db MySqlDatabase::getInstance();

// Connect to Database
$conn $db->connect($db_host$db_uname$db_passwd$db_dbname);

// Get highest ID
$count $db->fetchOne("SELECT COUNT(*) FROM myTable");

// Query the last 2 Commits
$no_of_rows $count - ( $show_count );
$query 'SELECT * from myTable WHERE `id` >= '.$no_of_rows;

// Walk and display results
//echo '<div>';
foreach($db->iterate($query) as $row )
{
// Open Table
echo '<table border=0>';
echo '<tbody>';

// Committer
echo '<tr>';
echo '<td>Commited by:</td>';
echo '<td>'.$row->author.'</td>';
echo '</tr>';

// Revision
echo '<tr>';
echo '<td>Revision Nr.:</td>';
echo '<td>'.$row->revision.'</td>';
echo '</tr>';

// URL
echo '<tr>';
echo '<td>Repository URL:</td>';
echo '<td><a href="'.$row->url.'" target="_blank">'.$row->url.'</a></td>';
echo '</tr>';

// Date and Time
echo '<tr>';
echo '<td>Commited on:</td>';
echo '<td>'.$row->datetime.'</td>';
echo '</tr>';

// Commit Message
echo '<tr>';
echo '<th colspan="2">'.nl2br($row->messagetrue).'</th>';
echo '</tr>';

// Close Table
echo '</tbody>';
echo '</table>';

echo '&nbsp;&nbsp;&nbsp;';
}
//echo '</div>';
}
catch( Exception $e)
{
echo($e->getMessage());
}
}


« Last Edit: August 17, 2012, 01:54:17 PM by scorcher24 »

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #7 on: August 17, 2012, 06:51:42 PM »
@Database
It is my own webserver, but a different database. I thought it might be wise to keep it seperated since it is basically unsecure data.
Someone might spoof the google webhook protocol and abuse it to hack my site.

@$smcFunc
Could you show me how to setup a file so I can use all functions from SMF?
I was unable to find any step-by-step-tutorial on how to write your own plugins.
If you have one, please link me, that would be very appreciated.
At least I could use it for the output code. Would just need to copy the code to the db of the forums.

But as said, the problem is not the database. The problem is that the website is rendered twice and one time in a block.. it is caused by the executed code from my script. Including it does not cause it. I mean, what can cause it that smf is repeating the whole html of the site again? It is there including the doc type.


I only mentioned the smf function (global $smcFunc) for dealing with your own database.
No it would not make much sense to read the data from the other db & then write to to yours (not if I understand that you just want to display some data) .. that is not what I meant at all.
You state that connecting to the external db is not an issue although one of your previous attachments shows a database error which would seem otherwise.. but if you are sure you're connecting to the external db then we move on from that. 

PHP blocks/pages:

Blocks & pages (in your case ... php type specifically) are being displayed on an existing configured html page.  The only thing you would display (echo) is what is between the body tags of this code you are referring to.

If the code you posted here is the only code that is being displayed (echo) it is just a simple table being displayed.
« Last Edit: August 17, 2012, 06:58:11 PM by Underdog »

Offline scorcher24

  • Semi Newbie
  • *
  • Posts: 9
  • SMF Version: 2.0.2
  • SP Version: 2.3.5
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #8 on: August 17, 2012, 06:59:23 PM »
I don't understand what you try to tell me.
Can't you be more specific?

From what I understand how a custom php block _should_ work, is that the code from that custom block is executed when that block is to be rendered. The only thing my code echo's is a table within a div. So I _really_ don't see how that can happen that the site is echo'd 2x when I call my function in the block or execute the code there directly.

Can't anyone give a specific answer how I can solve that issue?

edit, regarding your edit:
Quote
If the code you posted here is the only code that is being displayed (echo) it is just a simple table being displayed.
Yes, it is the only code and it is just a table. Thats why I am so clueless how my script can cause this.

edit 2:
Got a step forward. In the second version of my homepage which is displayed in the article block, this error message is found:
Quote
Table 'db1.smf_sp_articles' doesn't exist
File: /var/www/myUserName/html/Sources/PortalBlocks.php
Line: 2396

So apparently the database handler is somehow connecting to db1, which is the database for the data I display in the custom block.
The forum is on db2.
« Last Edit: August 17, 2012, 07:03:21 PM by scorcher24 »

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #9 on: August 17, 2012, 07:22:46 PM »
I don't understand what you try to tell me.
Can't you be more specific?

From what I understand how a custom php block _should_ work, is that the code from that custom block is executed when that block is to be rendered. The only thing my code echo's is a table within a div. So I _really_ don't see how that can happen that the site is echo'd 2x when I call my function in the block or execute the code there directly.

Can't anyone give a specific answer how I can solve that issue?

edit, regarding your edit:
Quote
If the code you posted here is the only code that is being displayed (echo) it is just a simple table being displayed.
Yes, it is the only code and it is just a table. Thats why I am so clueless how my script can cause this.

It is difficult for me to understand some of what your saying.. I thought you were previously stating that you were echoing doctype & extra html data so I was trying to advise you not to.

If the page is displaying extra html in error imo you are echoing it somewhere so look to where this could occur...

Do the php files that are being loaded have echo to display any data such as this?

You are also getting data from the external db & then displaying it.. perhaps that data has the unwanted html.  A possible solution is to extract the data into an array prior to displaying it and then filter the array to only display the data you wish.  (ie. message?)


Offline scorcher24

  • Semi Newbie
  • *
  • Posts: 9
  • SMF Version: 2.0.2
  • SP Version: 2.3.5
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #10 on: August 17, 2012, 07:30:14 PM »
No, the FRONTPAGE is outputted twice INCLUDING the DOCTYPE if you look at the source of the rendered html page.
The frontpage just repeats itself in the article block where the articles are supposed to be.
All I say is: It is the complete page that is repeated in the article block...

Look at this screen:
http://i.imgur.com/8JPTn.png

HTML Source:
http://i.imgur.com/653XB.png

My data I get from the database just contains a date, my name, a revision url and a commit message. The testdata just contains "blub" as message. So this can't be the issue.

edit:
I solved it. The issue was that the database that contains the data is different from the database that hosts my forum.
Despite the fact that I used my own database class, it seem to have disconnected the forums database from it's backend.
« Last Edit: August 17, 2012, 07:44:18 PM by scorcher24 »

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #11 on: August 17, 2012, 07:56:02 PM »
No, the FRONTPAGE is outputted twice INCLUDING the DOCTYPE if you look at the source of the rendered html page.
The frontpage just repeats itself in the article block where the articles are supposed to be.
All I say is: It is the complete page that is repeated in the article block...

Look at this screen:
http://i.imgur.com/8JPTn.png

HTML Source:
http://i.imgur.com/653XB.png

My data I get from the database just contains a date, my name, a revision url and a commit message. The testdata just contains "blub" as message. So this can't be the issue.

edit:
I solved it. The issue was that the database that contains the data is different from the database that hosts my forum.
Despite the fact that I used my own database class, it seem to have disconnected the forums database from it's backend.

OK.. I understand your final issue now.
Is it resolved?  Did you get it working as you wish?

There is also a database disconnect command that may resolve the issue if it persists (disconnect from external db).




Offline scorcher24

  • Semi Newbie
  • *
  • Posts: 9
  • SMF Version: 2.0.2
  • SP Version: 2.3.5
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #12 on: August 17, 2012, 07:59:07 PM »
Yes, it works how I want it to work.
I had to copy the table over to db2 though and use that database.
I just hope my script does not get hacked, but normally it should be bulletproof since google is sending a secret key and I check for the hashes etc. Oh well, no risk no fun :D.


Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #13 on: August 17, 2012, 08:59:13 PM »
Yes, it works how I want it to work.
I had to copy the table over to db2 though and use that database.
I just hope my script does not get hacked, but normally it should be bulletproof since google is sending a secret key and I check for the hashes etc. Oh well, no risk no fun :D.

Glad to hear you got it working.
If you're going to use the same db as the forum you can do it differently with $smcFunc.
If it is so, show me the code you are using now (xing out anything for security).

Here are the list of functions: ref. http://www.simplemachines.org/community/index.php?topic=224166.0
Everyone has their own preference. I prefer to use my own sub routines & use straight mysql commands so I use $smcFunc['db_query'] which allows for that.
 
« Last Edit: August 17, 2012, 09:17:33 PM by Underdog »

Offline scorcher24

  • Semi Newbie
  • *
  • Posts: 9
  • SMF Version: 2.0.2
  • SP Version: 2.3.5
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #14 on: August 17, 2012, 09:18:55 PM »
Hey, thats the final and cleaned up code:
Code: [Select]
<?php
@require_once('mysqldatabase.php');
@require_once(
'mysqlresultset.php');


function 
display_googlecode_webhook()
{
@require_once('settings.php');

try
{
// Get Singleton
$db MySqlDatabase::getInstance();

// Connect to Database
$conn $db->connect($db_host$db_uname$db_passwd$db_dbnamefalse);

// Query
$query 'SELECT * from '.$table_name.' ORDER BY id DESC LIMIT ' $show_count;

// Walk and display results
foreach($db->iterate($query) as $row )
{
// Open Left Table
echo '<table border="0" align="left">';
echo '<tbody>';

// Committer
echo '<tr>';
echo '<td>Commited by:</td>';
echo '<td>'.$row->author.'</td>';
echo '</tr>';

// Revision
echo '<tr>';
echo '<td>Revision Nr.:</td>';
echo '<td>'.$row->revision.'</td>';
echo '</tr>';

// URL
echo '<tr>';
echo '<td>Repository URL:</td>';
echo '<td><a href="'.$row->url.'" target="_blank">'.$row->url.'</a></td>';
echo '</tr>';

// Date and Time
echo '<tr>';
echo '<td>Commited on:</td>';
echo '<td>'.$row->datetime.'</td>';
echo '</tr>';

// Close Table
echo '</tbody>';
echo '</table>';

// Open Right Table
echo '<table border="0" align="right">';
echo '<tbody>';

// Commit Message
echo '<tr>';
echo '<td>'.nl2br($row->messagetrue).'</td>';
echo '</tr>';

// Close Table
echo '</tbody>';
echo '</table>';
}
}
catch( Exception $e)
{
echo($e->getMessage());
}
}



Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: Custom PhP causes website to be rendered in Articles Block
« Reply #15 on: August 17, 2012, 09:49:29 PM »
Code: [Select]
<?php

@require_once('mysqldatabase.php');
@require_once(
'mysqlresultset.php');


function 
display_googlecode_webhook()
{
global $smcFunc;
@require_once('settings.php');

try
{
// Query
$query $smcFunc['db_query']('''SELECT * FROM {db_prefix}'.$table_name.' ORDER BY id DESC LIMIT {int:count}',array('count' => $show_count));

// Walk and display results
while ($row $smcFunc['db_fetch_assoc']($query))
{
// Open Left Table
echo '<table border="0" align="left">';
echo '<tbody>';

// Committer
echo '<tr>';
echo '<td>Commited by:</td>';
echo '<td>'.$row['author'].'</td>';
echo '</tr>';

// Revision
echo '<tr>';
echo '<td>Revision Nr.:</td>';
echo '<td>'.$row['revision'].'</td>';
echo '</tr>';

// URL
echo '<tr>';
echo '<td>Repository URL:</td>';
echo '<td><a href="'.$row['url'].'" target="_blank">'.$row['url'].'</a></td>';
echo '</tr>';

// Date and Time
echo '<tr>';
echo '<td>Commited on:</td>';
echo '<td>'.$row['datetime'].'</td>';
echo '</tr>';

// Close Table
echo '</tbody>';
echo '</table>';

// Open Right Table
echo '<table border="0" align="right">';
echo '<tbody>';

// Commit Message
echo '<tr>';
echo '<td>'.nl2br($row['message'], true).'</td>';
echo '</tr>';

// Close Table
echo '</tbody>';
echo '</table>';
}

$smcFunc['db_free_result']($query);
}
catch( Exception $e)
{
echo($e->getMessage());
}

}

?>


I can not test it atm unless I make some bogus db entries.
$show_count & $table_name defined prior to that query within the function I assume? need to be
« Last Edit: August 17, 2012, 10:31:56 PM by Underdog »