Tried of the old template system. Ugly. Time for change. Here I've decided to strip away further out of TT and plug into a template engine, that allows me to code much more efficiently, use plugins and really extend data the way I want to. Not to mention, its caching feature on all TPL files.
Take lines and lines of code, and compare that to a single tag, example
Hello, [color=rgb(41, 105, 176)]{$username}[/color]. You have [color=rgb(41, 105, 176)]{$totalinvites}[/color] remaining.
And on and on. Passing variables over to the template engine. Really read about Smarty first. I've converted almost all pages on my site, reducing code and file size by a lot. Its done my design work and rendering a world of difference.
This is [color=rgb(226, 80, 65)]not compatible[/color] with PDO edition, which uses MVC framework and as Smarty claims to work with all of them, I wouldn't recommend it. I can't imagine that is a easy experience.
This mod will replace torrent index, header and footer - leaving all other pages the exact same!
Read about it here - https://www.smarty.net
So I'll log what I've done so far along. It's constantly changing.
First, upload contents of ZIP to root /
Open backend/functions.php and find:
And add under:
We are going to bypass by ignoring this present in backend/functions.php and leave as-is.
require_once("themes/" . $THEME . "/block.php");
require_once("themes/" . $THEME . "/header.php");
Because we are now phasing out stdhead() and stdfoot() effectively removing the forced header/footer of the /theme directory.
For the simplicity of the walkthrough (because its worth it), use this developed index2.php and now you will be phasing out the old torrenttable()
Create as index2.php and copy to root (also included in ZIP):
You have several vars assigned, allowing to easily pull any data out. Torrent index is now independent. Compare that to existing torrent table in functions file (y)
Now create index.tpl and copy this to /templates
Now create footer.tpl and copy this to /templates
Now create header.tpl and copy this to /templates
Lastly, create torrentindex.tpl and copy this to /templates
--
Working and running Live on my site with flying colours. Everything works and the files are all much smaller and less lines by far!
Take lines and lines of code, and compare that to a single tag, example
Hello, [color=rgb(41, 105, 176)]{$username}[/color]. You have [color=rgb(41, 105, 176)]{$totalinvites}[/color] remaining.
$smarty->assign('username', $CURUSER["username"]);And on and on. Passing variables over to the template engine. Really read about Smarty first. I've converted almost all pages on my site, reducing code and file size by a lot. Its done my design work and rendering a world of difference.
This is [color=rgb(226, 80, 65)]not compatible[/color] with PDO edition, which uses MVC framework and as Smarty claims to work with all of them, I wouldn't recommend it. I can't imagine that is a easy experience.
This mod will replace torrent index, header and footer - leaving all other pages the exact same!
Read about it here - https://www.smarty.net
So I'll log what I've done so far along. It's constantly changing.
First, upload contents of ZIP to root /
Open backend/functions.php and find:
require_once(BACKEND."/languages.php");And add under:
// Smarty PHP Compiling Template Engine 3.1.34 (latest dev)
require_once(BACKEND."/Smarty/Smarty.class.php");
$smarty = new Smarty();
$smarty->setTemplateDir('../templates/');
$smarty->setCompileDir('../templates_c/');
$smarty->setConfigDir('../configs/');
$smarty->setCacheDir('../cache/');
We are going to bypass by ignoring this present in backend/functions.php and leave as-is.
require_once("themes/" . $THEME . "/block.php");
require_once("themes/" . $THEME . "/header.php");
Because we are now phasing out stdhead() and stdfoot() effectively removing the forced header/footer of the /theme directory.
For the simplicity of the walkthrough (because its worth it), use this developed index2.php and now you will be phasing out the old torrenttable()
Create as index2.php and copy to root (also included in ZIP):
<?
require_once 'backend/functions.php';
dbconn(true);
// PDO Connection
$db = new PDO("mysql:host={$dbHost};dbname={$dbName};charset=utf8", $dbUsername, $dbPassword);
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$admin = $CURUSER["class"] == 7;
$avatar = $CURUSER["avatar"];
$class = $CURUSER["class"];
$themename = mysql_fetch_assoc(SQL_Query_exec("SELECT uri FROM stylesheets WHERE id='" . ( $CURUSER ? $CURUSER['stylesheet'] : $site_config['default_theme'] ) . "'"));
$theme = $themename['uri'];
$siteurl = $site_config["SITEURL"];
$torrentid = $id;
$userid = $CURUSER["id"];
$date_time = get_date_time(gmtime()-(3600*24));
$usersadded = number_format(get_row_count("users", "WHERE users.added>='$date_time'"));
if (stripos($_SERVER['PHP_SELF'],'index.php')) {
$indexonly = true;
}
// Messages
$mail = $db->prepare("SELECT COUNT(id) FROM messages WHERE receiver = :userid AND unread = 'yes' AND location IN ('in','both') LIMIT 1");
$mail->bindParam(":userid", $userid, PDO::PARAM_INT);
$mail->execute();
$messages = $mail->fetchColumn();
// Conditions
$smarty->assign('loggedin', $CURUSER);
$smarty->assign('admin', $admin);
$smarty->assign('avatar', $avatar);
$smarty->assign('theme', $theme);
$smarty->assign('unreadmail', $messages);
$theme = $site_config['default_theme_name'];
if ($CURUSER){
$lastchance = isset($_GET['lc']);
$maxslot = avail_slots($userid, $class);
$userslots = number_format($maxslot) . "/0";
$userratio = number_format($CURUSER["uploaded"] / $CURUSER["downloaded"], 2);
}
// Spotlight
$spotlight = $db->prepare("SELECT id, name, cover1 FROM torrents ORDER BY added DESC LIMIT 8");
$spotlight->execute();
$spotlight->setFetchMode(PDO::FETCH_ASSOC);
// Languages
$language = $db->prepare("SELECT id, name, uri FROM languages");
$language->execute();
$language->setFetchMode(PDO::FETCH_ASSOC);
// Stylesheets (legacy)
$stylesheet = $db->prepare("SELECT id, name FROM stylesheets");
$stylesheet->execute();
$stylesheet->setFetchMode(PDO::FETCH_ASSOC);
// Torrent Comments
$comments = $db->prepare("SELECT comments.id, comments.text, comments.user, comments.added, users.avatar, signature, username, title, class, uploaded, downloaded, privacy, donated FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = torrents.id ORDER BY comments.id LIMIT 2");
$comments->execute();
$comments->setFetchMode(PDO::FETCH_ASSOC);
// Torrent Table
$results = 13;
$torrenttable = $db->prepare("SELECT torrents.id, torrents.hits, torrents.views, torrents.image1, torrents.anon, torrents.announce, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments AS commentcount, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.image AS cat_pic, categories.parent_cat AS cat_parent, users.username, users.avatar, users.privacy, IF(torrents.numratings < 1, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE visible = 'yes' AND banned = 'no' ORDER BY torrents.added DESC LIMIT :limit");
$torrenttable->bindParam(":limit", $results, PDO::PARAM_INT);
if ($CURUSER)
$db->query("UPDATE users SET last_browse=" . gmtime() . " WHERE id=$CURUSER[id]");
$torrenttable->execute();
$torrenttable->setFetchMode(PDO::FETCH_BOTH);
// Assign
$smarty->assign('username', $CURUSER["username"]);
$smarty->assign('userid', $CURUSER["id"]);
$smarty->assign('avatar', $avatar);
$smarty->assign('url', $siteurl);
$smarty->assign('indexonly', $indexonly);
$smarty->assign('lastchance', $lastchance);
$smarty->assign('torrentid', $torrentid);
$smarty->assign('usersadded', $usersadded);
$smarty->assign('languages', $language);
$smarty->assign('stylesheet', $stylesheet);
$smarty->assign('spotlight', $spotlight);
$smarty->assign('comments', $comments);
$smarty->assign('slots', $userslots);
$smarty->assign('ratio', $userratio);
$smarty->assign('torrenttable', $torrenttable); // torrenttable
// Display
$smarty->display('index.tpl');
?>
You have several vars assigned, allowing to easily pull any data out. Torrent index is now independent. Compare that to existing torrent table in functions file (y)
Now create index.tpl and copy this to /templates
{include file='header.tpl'}
{include file='footer.tpl'}
Now create footer.tpl and copy this to /templates
<!-- HTML footer -->
Now create header.tpl and copy this to /templates
{* MAIN HEADER *}
<!DOCTYPE html>
<html lang="en-US"
itemscope
itemtype="http://schema.org/WebSite"
prefix="og: http://ogp.me/ns#" >
<head>
{include file='header_resource.tpl'}
<style>
{include file='header_extracss.tpl'}
</style>
<script>
{include file='header_javascript.tpl'}
</script>
</head>
<body>
{include file='header_nav.tpl'}
<div class="container-main">
<div class="primary"><!-- *** START PRIMARY *** -->
{if $loggedin}
<!-- logged in HTML -->
{include file='ajax_shoutbox.tpl'}
{/if}
<div class="content-inner">
<!-- Migrate -->
<div class='myTable'>
<div class='myTrow'>
<div class='main'>
<table width='100%' border='0' cellspacing='10' cellpadding='0'>
<tr>
<td valign='top'>
{include file='torrentindex.tpl'}
Lastly, create torrentindex.tpl and copy this to /templates
{* MAIN TORRENT INDEX *}
{foreach $torrenttable as $item}
<a href="{$url}/torrents-details.php?id={$item.id}">
<img src="{$url}/uploads/images/{$item.image1}" />
<span>{$item.added|date_format} by <a href='{$url}/user/?id={$item.owner}'> {$item.username}</a> <img src='{$url}/{$item.avatar}' /></span>
<span>{$item.views}</span>
<span>{$item.hits}</span>
<span>{$item.speed}</span>
<a title="{$item.name}" href="/details/{$item.id}/">{$item.name|truncate:29}</a>
<span>{if $item.rating}{$item.rating} / 5.0{/if}</span>
<span><a href='{$url}/cat/{$item.category}/' title='Browse {$item.category} Torrents'>{$item.cat_name}</a></span>
<span>{$item.size|filesize}</span>
<span>{$item.seeders}</span>
<span>{$item.leechers}</span>
{/foreach}
--
Working and running Live on my site with flying colours. Everything works and the files are all much smaller and less lines by far!