Skip to content

Instantly share code, notes, and snippets.

@brunoalano
Created July 29, 2011 22:19
Show Gist options
  • Save brunoalano/1114862 to your computer and use it in GitHub Desktop.
Save brunoalano/1114862 to your computer and use it in GitHub Desktop.
<?php
/**
* @author Bruno Alano
* @website http://brunoalano.com.br
* @project SerieBOSS
*/
// Show all errors
error_reporting(E_ALL);
// MySQL Connect
include_once ('library/edb.class.php');
include_once ('config.php');
$db = new edb($config);
// Template Engine
require_once('library/Smarty.class.php');
$smarty = new Smarty();
$smarty->setTemplateDir('templates');
$smarty->setCompileDir('templates_c');
$smarty->setCacheDir('cache');
$smarty->setConfigDir('configs');
// Setup base url
if ( !defined( 'BASEURL' ) )
define ( 'BASEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' );
// Friendly URLs
// Check if want a page
$pagina = @$_GET['page'];
$topic = @$_GET['title'];
if (!empty($pagina) && empty($topic)) { // If the url is xxx.com/???
$smarty->assign('BASEURL', BASEURL);
$smarty->assign('PAGE', $pagina);
$smarty->assign('mPage', strtolower($pagina)); // Lowercase Page Name (FOR SLUG)
if ($pagina == 'seriados') $cid = 1;
if ($pagina == 'animes') $cid = 2;
$list = $db->q("SELECT * FROM `topics` WHERE `category` = {$cid} ORDER BY slug ASC");
$smarty->assign('list', $list);
$smarty->display('list.tpl');
$smarty->display('footer.tpl');
} else if (!empty($pagina) && !empty($topic)) { // If the url is in xxx.com/???/???
$smarty->assign('BASEURL', BASEURL);
$view = $db->q("SELECT * FROM `topics` WHERE `slug` = '{$topic}' LIMIT 1");
if (sizeof($view) == 0) {
$smarty->display('404.tpl');
$smarty->display('footer.tpl');
} else {
$smarty->assign('view', $view);
$smarty->display('view.tpl');
$smarty->display('footer.tpl');
}
} else { // If has no arguments
// Get Top 3 of Series
$series = $db->q("SELECT * FROM `topics` WHERE `category` = 1 ORDER BY rate ASC LIMIT 3");
$smarty->assign('BASEURL', BASEURL);
$smarty->assign('series', $series);
// Get Top 3 of Animes
$animes = $db->q("SELECT * FROM `topics` WHERE `category` = 2 ORDER BY rate ASC LIMIT 3");
$smarty->assign('animes', $animes);
// Display Page
$smarty->display('index.tpl');
$smarty->display('footer.tpl');
}
function showBaseDir() {
echo BASEURL;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment