TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 488
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 98
  • Total: 98

PHP code

Started by AnimeUK, September 11, 2008, 12:35:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AnimeUK

my forum is a subdomain of my actual domain.

Is it possible to get the code from a PHP block from my forum to appear on the actual site?

(instead of it being in a block at ...forum.anysite.com, I'd like it placed at anysite.com (but still doing the job it was doing at the forum.)

The site was built using a supplied tool, which has a WYSIWYG editor. It allows only Javascript, CSS and HTML. I tried to copy the code directly from the block at the forum to the editor, but all it did was show the text of the code.

Any code heroes able to help me with this?

Thanks :)

JPDeni

A lot would depend on the code. If you're using any variables that are defined by SMF or TP, the code won't work outside of that environment. But if you're not, it might.

Create a new file in a plain text editor. Paste your php code into that file. At the beginning of the file, on its own line, add


<?php


At the end of the file, on its own line, add


?>


Save it as anyfile.php and upload it to your webspace. Access the file by going to

http://www.anysite.com/anyfile.php

AnimeUK

The actual code looks like lots SMF/TP variables are in use:


global $db_prefix, $modSettings, $scripturl;
echo '

<a href="', $scripturl ,'?action=profile;u=', $context['user']['id'] ,';sa=pictures;add">Add Profile Photo</a> |  <a href="', $scripturl ,'?action=profile;u=', $context['user']['id'] ,';sa=pictures">My Profile Photos</a>
';
$sql = db_query ('SELECT p.ID_PICTURE, p.ID_MEMBER, p.title, p.time, p.filename, m.realName
FROM ' . $db_prefix . 'profile_pictures AS p, ' . $db_prefix . 'members AS m
WHERE p.ID_MEMBER = m.ID_MEMBER
ORDER BY p.time DESC
LIMIT 5', __FILE__, __LINE__);


$data = array();
while ($row = mysql_fetch_assoc ($sql)) {
$data[] = array (
'title' => $row['title'],
'thumb' => $modSettings['profile_pictures_url'] . '/' . $row['ID_MEMBER'] . '_' . $row['time'] . '_thumb.' . substr (strrchr ($row['filename'], '.'), 1),
'url' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . ';sa=pictures;view=' . $row['ID_PICTURE'],
'time' => timeformat ($row['time']),
'user' => $row['realName'],
'profile' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
);
}


echo '
<table ALIGN="center">
<tr>';
foreach ($data as $picture)
{
echo '
<td><center>
<a href="', $picture['url'] ,'"><img src="' . $picture['thumb'] . '" alt="" /></a>
</center></td>';
}
echo '
</tr>
</table>';



I added the opening and closing <?php, ?> commands, but am unsure of how to get the page to show the same output as on the forum.

Would this code need rewriting from scratch, specifically for the website?

JPDeni

You will not be able to use that code on a separate web page.

I've never done this, but what you might be able to do is to copy the code into a function and paste it into SSI.php, which is in your main forum directory. Then you could call it from there.

I'm not sure what your code does, but I see references to some profile photos, so I'll use that for the name of the function.

Add this at the top of your code:


function profile_photo {


and this at the end of your code


}


Paste it into SSI.php.

On your web page, which must have a .php extension, start with the line:


<?php

require('forum/SSI.php');

?>



Then make your html page however you want. In the place where you want to display the result of your function, use


<?php profile_photo(); flush(); ?>


The rest of your page can be plain html, but you must use a .php extension.

I think this will work. I've never really done it before.

This is actually more of an SMF question than a TP question, but since I think you got the code from someone here, I think it's okay to answer it. If this doesn't work, though, I think your best bet would be to go to SMF where people are who have more experience with this sort of thing.

This website is proudly hosted on Crocweb Cloud Website Hosting.