Location: PHPKode > scripts > Yet Another Link Directory > yald2/directory.php
<?php
/******************************************************************************
* This file is part of Yet Another Link Directory.                            *
*                                                                             *
* Yet Another Link Directory is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or           *
* (at your option) any later version.                                         *
*                                                                             *
* Yet Another Link Directory is distributed in the hope that it will be       *
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of      *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
* GNU General Public License for more details.                                *
*                                                                             *
* You should have received a copy of the GNU General Public License           *
* along with Yet Another Link Directory; if not, write to the Free Software   *
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
******************************************************************************/

require('inc/config.php');
require('inc/functions.php');
require('inc/pages.class.php');
require('inc/smarty/Smarty.class.php');

mysql_connect($mysql['host'],$mysql['username'],$mysql['password']);
mysql_select_db($mysql['db']);

session_start();

$settings = getSettings();

$template = new Smarty();
$template->template_dir = $settings['template_dir'].'/'.$settings['default_template'].'/';

$compile_dir = $settings['template_c_dir'].'/';
$template->compile_dir = $compile_dir;
$template->compile_id = $settings['default_template'];

if(isset($_SESSION['yald_admin_logged_in'])){
	$is_administrator = true;
} else {
	$is_administrator = false;
}

$paginator = new MyPagina($settings['links_per_page']);

//----------------------------------------------------------------------------

$yald_head = '';

if(isset($_GET['jump'])){
	header('Location: '.linkUrl($_GET['jump']));
	$query = 'UPDATE '.$settings['links_table'].' SET clicks = clicks + 1 WHERE id = "'.mysql_escape_string($_GET['jump']).'"';
	mysql_query($query);
	exit;
}

if($is_administrator){
	if(isset($_GET['deletelink'])){
		$category = linkCategory($_GET['deletelink']);
		linkRemove($_GET['deletelink']);
		logEvent('del_link','0',urldecode($_GET['url']));
		header('Location: '.$_GET['redir']);
	}
}

if(!empty($_GET['search']) && $_GET['search'] != ' '){
	$templatefile = 'search.html';

	$template->assign('search_query',htmlentities($_GET['search']));

	$links = search($_GET['search']);

	//$nav = '<a href="'.$_SERVER['PHP_SELF'].'">Top</a>'.$settings['nav_separator'].'Search';
	$nav[] = array('name'=>'Top','url'=>$settings['index_file']);
	$nav[] = array('name'=>'Search','url'=>'');
	$page_title = 'Directory Search';
} else {
	$templatefile = 'directory.html';

	if($settings['url_type'] == '2' && isset($_GET['viewcat'])){
		$catname_get = explode('/',$_GET['catname']);
		$urlcatname = $catname_get[0];
		if($settings['use_pagination']==true){
			if(!empty($catname_get[1]) && is_numeric($catname_get[1])){
				$_REQUEST['page'] = $catname_get[1];
			} else {
				$_REQUEST['page'] = '';
			}
		}
	} elseif($settings['url_type'] == '3' && isset($_GET['viewcat'])){
		$urlcatname = '';
		$path = trim($_GET['viewcat'],' /');
		if($settings['use_pagination']==true){
			$pathparts = explode('/',$path);
			$last = $pathparts[count($pathparts)-1];
			//die($last);
			if(!empty($last) && eregi('page([1-9]*)\.html',$last,$matches)){
				$_REQUEST['page'] = $matches[1];
				unset($pathparts[count($pathparts)-1]);
				$path = implode('/',$pathparts);
			} else {
				$_REQUEST['page'] = '';
			}

			$_GET['viewcat'] = catIdByPath($path);

		} else {
			$_GET['viewcat'] = catIdByPath($_GET['viewcat']);
		}
	} else {
		$urlcatname = '';
	}

	if(isset($_GET['viewcat']) && categoryExists($_GET['viewcat'],$urlcatname) && $_GET['viewcat'] != '1'){
		$category = $_GET['viewcat'];
		$nav[] = array('name'=>'Top','url'=>$settings['index_file']);

		$nav = array_merge($nav,categoryPath($category));

		$query = 'SELECT name,path FROM `'.$settings['categories_table'].'` WHERE id="'.mysql_safe($_GET['viewcat']).'"';
		$result = mysql_query($query);
		$row = mysql_fetch_array($result);

		if($settings['use_pagination']==true){
			$paginator->catpath = $row['path'];
			$paginator->catid = $_GET['viewcat'];
			$paginator->catname = $row['name'];
		}

		$categoryname = $row['name'];
		$page_title = $categoryname;
		$nav[] = array('name'=>htmlentities($categoryname),'url'=>'');

	} else {
		$category = '1';
		$categoryname = null;
		$nav[] = array('name'=>'Top','url'=>'');
		$page_title = 'Top';
	}
	$yald_body = '';

	if($category == '1'){
		$template->assign('categories',listCategories('1'));
		$template->assign('is_root',true);
		if($settings['disp_latest']){
			$template->assign('latest_links',latestLinks());
		}
		$haslinks = false;
		$links = null;
	} else {
		if(subCat($category)){
			$template->assign('categories',listCategories($category));
			$yald_body .= '<br /><br />';
		}
		$yald_body .= '<b>'.htmlentities(categoryName($category)).':</b><br />';


		$links = listLinks($category);

		//pagination
		if($settings['use_pagination']==true){
			$page_nav = $paginator->navigation(" | ", ""); // the navigation links (define a CSS class selector for the current link)
			$current_records = $paginator->page_info("to"); // information about the number of records on page ("to" is the text between the number)
			$total_recs = $paginator->get_total_rows(); // the total number of records
			$template->assign('page_navigation',$page_nav);
			$template->assign('current_links_page',$current_records);
			$template->assign('total_links',$total_recs);
		}

		$template->assign('is_root',false);
	}

	if($settings['url_type']=='1'){
		$template->assign('suggest_url',dirname($_SERVER['PHP_SELF']).'/suggest.php?category='.$category);
		$template->assign('generic_path',dirname($_SERVER['PHP_SELF']).'/');
	} else {
		$template->assign('suggest_url',$settings['mod_rewrite_url'].'suggest.php?category='.$category);
		$template->assign('generic_path',$settings['mod_rewrite_url']);
	}
	
	$template->assign('category_name',htmlentities($categoryname));
}

/*$template = str_replace(array('@TITLE@','@NAV_TRAIL@','@YALD_BODY@','@PHPSELF@','@YALD_HEAD@','@ADMIN@','@HOME_URL@'),
array(,$nav,$yald_body,$_SERVER['PHP_SELF'],$yald_head,$admin,$settings['home_link']),$template);*/

$template->assign('links',$links);
$template->assign('use_pagination',$settings['use_pagination']);
$template->assign('actual_dir_path',dirname($settings['actual_path']));
$template->assign('title',htmlentities($page_title));
$template->assign('sitetitle',htmlentities($settings['site_title']));
$template->assign('nav_trail',$nav);
$template->assign('index_file',$settings['index_file']);
//$template->assign('yald_body',$yald_body);
$template->assign('phpself',$_SERVER['PHP_SELF']);
$template->assign('template_path',$settings['template_dir'].'/'.$settings['default_template']);

$template->assign('is_administrator',$is_administrator);
$template->assign('home_url',$settings['home_link']);
$template->assign('display_admin_link',$settings['display_admin_link']);

$template->display($templatefile);
//print $template;
?>
Return current item: Yet Another Link Directory