/*#################################################################*\ |# Licence Number 03BP-0000-042T-0200 |# ------------------------------------------------------------- #| |# Copyright (c)2009 PHP Link Directory. #| |# http://www.phplinkdirectory.com #| \*#################################################################*/ /** # ################################################################################ # Project: PHP Link Directory # # ********************************************************************** # Copyright (C) 2004-2009 NetCreated, Inc. (http://www.netcreated.com/) # # This software is for use only to those who have purchased a license. # A license must be purchased for EACH installation of the software. # # By using the software you agree to the terms: # # - You may not redistribute, sell or otherwise share this software # in whole or in part without the consent of the the ownership # of PHP Link Directory. Please contact david@david-duval.com # if you need more information. # # - You agree to retain a link back to http://www.phplinkdirectory.com/ # on all pages of your directory in you purchased the $25 version # of the software. # # License holders are entitled to upgrades to the 3.4 branch of the software # as they are made available at http://www.phplinkdirectory.com/ # # In some cases, license holders may be required to agree to changes # in the software license before receiving updates to the software. # ********************************************************************** # # For questions, help, comments, discussion, etc., please join the # PHP Link Directory Forum http://www.phplinkdirectory.com/forum/ # # @link http://www.phplinkdirectory.com/ # @copyright 2004-2009 NetCreated, Inc. (http://www.netcreated.com/) # @projectManager David DuVal # @package PHPLinkDirectory # @version 4.0.0 # ################################################################################ */ require_once 'init.php'; //if required email confirmation add this to sql queries if (EMAIL_CONFIRMATION == 1) { $email_conf = " AND `OWNER_EMAIL_CONFIRMED` = '1' "; } // Check page request, if not valid a http header 404 is sent $http_status = (!empty ($_REQUEST['httpstatus']) ? intval ($_REQUEST['httpstatus']) : request_status()); httpstatus($http_status); $uid = ''; $user_where = ''; // Determine user ID to search for, but only if valid user if (!empty ($_SESSION['phpld']['user']['id'])) { if (get_user_level($_SESSION['phpld']['user']['id']) == 1 || get_user_level($_SESSION['phpld']['user']['id']) == 3 ) { $permission_links_arts = "1 "; $permission_cats = "1 "; $permission_cats_parents = "1 "; $uid = (!empty ($_REQUEST['uid']) && preg_match ('`^[\d]+$`', $_REQUEST['uid']) ? intval ($_REQUEST['uid']) : 0); } else { $uid = (!empty ($_REQUEST['uid']) && preg_match ('`^[\d]+$`', $_REQUEST['uid']) ? intval ($_REQUEST['uid']) : 0); //raluca $permissions = get_user_permissions($_SESSION['phpld']['user']['id']); $permission_links_arts = "`CATEGORY_ID` IN ("; $permission_cats = "`ID` IN ("; $permission_cats_parents = "`PARENT_ID` IN ("; if (count($permissions) >0) { for ($i=0; $i 0 && $uid == $_SESSION['phpld']['user']['id']) { $user_where = " AND `OWNER_ID` = ".$db->qstr($uid); } else unset ($uid); } else { $permission_links_arts = "0 "; $permission_cats = "0 "; $permission_cats_parents = "0 "; } if ($user_level == 1) $tpl->assign('edit_link', 1); // Determine page number and current page index if (ENABLE_REWRITE == 1 && !isset ($_REQUEST['search'])) // Rewrited page links { preg_match ("/page-(\d+)\.htm[l]?([?]?.*)$/", request_uri(), $matches); // Determine current index $page = (!empty($matches[1]) ? intval ($matches[1]) : 1); // Determine page $current_item = PAGER_LPP * $page - PAGER_LPP; unset ($matches); } else // Regular page links { // Determine current index $current_item = (!empty ($_REQUEST['p']) && preg_match ('`^[\d]+$`', $_REQUEST['p']) ? intval ($_REQUEST['p']) : 1); $current_item--; // Determine page $page = ceil ($current_item / PAGER_LPP); } $page = ($page < 1 ? 1 : $page); // Check again for negative page // Remove rewrite page link //$_SERVER['REQUEST_URI'] = preg_replace("/page-(\d+)\.htm[l]?$/", "", $_SERVER['REQUEST_URI']); $pattern = array ("/page-(\d+)\.htm[l]?/", '`([?]|[&])(p=)+[\d]*`', '`([?]|[&])(cat_page=)+[\d]*`', '`([?]|[&])(article_page=)+[\d]*`'); $_SERVER['REQUEST_URI'] = preg_replace ($pattern, '', request_uri()); // Define sorting options define ('DIR_LPP', 20); $sort_cols = array ('P' => 'PAGERANK', 'H' => 'HITS', 'A' => 'TITLE', 'D' => 'DATE_ADDED'); $sort_ord = array ('P' => 'DESC' , 'H' => 'DESC', 'A' => 'ASC' , 'D' => 'DESC' ); // Build limit query //below used to be like this: //$limit = ' LIMIT '.($current_item <= 1 ? '0' : $current_item).', '.PAGER_LPP; $limit = ' LIMIT '.($current_item < 1 ? '0' : $current_item).', '.PAGER_LPP; $getSort = (!empty ($_REQUEST['s']) ? trim ($_REQUEST['s']) : (!empty ($URLvariables['s']) ? $URLvariables['s'] : '')); if (array_key_exists ($getSort, $sort_cols)) $sort = $getSort; else $sort = DEFAULT_SORT; if ((ENABLE_PAGERANK != 1 || SHOW_PAGERANK != 1) && $sort == 'P') $sort = 'H'; //if($db->GetOne("SELECT COUNT(*) FROM `{$tables['category']['name']}` WHERE `SORT_ORDER` <> '1000' AND `PARENT_ID` = '0'")) //{ // $CATEG_FIELD_SORT = 'SORT_ORDER'; // $CATEG_FIELD_SORT_ORDER = 'DESC'; //} //else //{ $CATEG_FIELD_SORT = CATEG_FIELD_SORT; $CATEG_FIELD_SORT_ORDER = CATEG_FIELD_SORT_ORDER; //} //if($db->GetOne("SELECT COUNT(*) FROM `{$tables['category']['name']}` WHERE `SORT_ORDER` <> '1000' AND `PARENT_ID` <> '0'")) //{ // $SUBCATEG_FIELD_SORT = 'SORT_ORDER'; // $SUBCATEG_FIELD_SORT_ORDER = 'DESC'; //} //else //{ $SUBCATEG_FIELD_SORT = SUBCATEG_FIELD_SORT; $SUBCATEG_FIELD_SORT_ORDER = SUBCATEG_FIELD_SORT_ORDER; //} $tpl->assign('sort', $sort); $path = array (); $path[] = array ('ID' => '0', 'TITLE' => _L(SITE_NAME), 'TITLE_URL' => DOC_ROOT, 'DESCRIPTION' => SITE_DESC); // Query to not have feat. links in results if (FTR_ENABLE == 1) $feat_where = "AND (`FEATURED` = '0')"; // Query for not exprired links $expire_where = "AND (`EXPIRY_DATE` >= ".$db->DBDate(time())." OR `EXPIRY_DATE` IS NULL)"; // Option to turn link hits increment On/Off $StopLinkHits = 0; /** * @author Darius Tumas * For link editing we need to know user permisions. * We take them here and assign for variable, which we will provide to smarty. * */ //var_dump($_SESSION['phpld']); //By default user does not have any permission. $ito_user_permission = '0'; //if user is logged... if (isset($_SESSION['phpld']['user']['id'])) { //...from session we take its level $ito_user_permission = $_SESSION['phpld']['user']['level']; $tpl->assign('load_Javascript', 'true'); } if (isset ($_REQUEST['list'])) // Top pages listings { $StopLinkHits = 1; // Disable link hits switch (strtolower ($_REQUEST['list'])) { case 'latestlinks' : case 'latest': $links = $db->CacheGetAll ("SELECT * FROM `{$tables['link']['name']}` WHERE (`STATUS` = '2' OR {$permission_links_arts}){$email_conf} {$expire_where} ORDER BY `DATE_ADDED` DESC LIMIT 0, ".LINKS_TOP); $path[] = array ('ID' => '0', 'TITLE' => _L('Latest Links'), 'TITLE_URL' => '', 'DESCRIPTION' => ''); break; case 'toplinks' : case 'top': $links = $db->CacheGetAll ("SELECT * FROM `{$tables['link']['name']}` WHERE (`STATUS` = '2' OR {$permission_links_arts}) {$email_conf} {$expire_where} ORDER BY `HITS` DESC LIMIT 0, ".LINKS_TOP); $path[] = array ('ID' => '0', 'TITLE' => _L('Top Hits'), 'TITLE_URL' => '', 'DESCRIPTION' => ''); break; case 'latestarticles': $articles = $db->CacheGetAll ("SELECT * FROM `{$tables['article']['name']}` WHERE (`RELEASE_DATE`<= now() OR {$permission_links_arts}) AND (`STATUS` = '2' OR {$permission_links_arts}) {$email_conf} ORDER BY `FEATURED_MAIN` DESC, `FEATURED` DESC, `DATE_ADDED` DESC LIMIT 0, ".LINKS_TOP); $path[] = array ('ID' => '0', 'TITLE' => _L('Latest Articles'), 'TITLE_URL' => '', 'DESCRIPTION' => ''); break; default: http_custom_redirect(DOC_ROOT); break; } $tpl->assign('list', $_REQUEST['list']); } elseif (!empty ($user_where) && !empty ($uid)) // Registered user links listings { if (FTR_ENABLE == 1) { $feat_links = $db->CacheGetAll("SELECT * FROM `{$tables['link']['name']}` WHERE (`STATUS` = '2' OR {$permission_links_arts}) AND `FEATURED` = '1' {$email_conf} {$expire_where} {$user_where} ORDER BY `EXPIRY_DATE` DESC"); } $count = $db->CacheGetOne("SELECT COUNT(*) FROM `{$tables['link']['name']}` WHERE (`STATUS` = '2' OR {$permission_links_arts}) {$email_conf} {$expire_where} {$user_where} ORDER BY `{$sort_cols[$sort]}` {$sort_ord[$sort]}"); $links = $db->CacheGetAll("SELECT * FROM `{$tables['link']['name']}` WHERE (`STATUS` = '2' OR {$permission_links_arts}) {$email_conf} {$feat_where} {$expire_where} {$user_where} ORDER BY `{$sort_cols[$sort]}` {$sort_ord[$sort]}"); $articles = $db->CacheGetAll("SELECT * FROM `{$tables['article']['name']}` WHERE (`RELEASE_DATE`<= now() OR {$permission_links_arts}) AND (`STATUS` = '2' OR {$permission_links_arts}) {$email_conf} {$user_where}"); $tpl->assign('have_search_results', 1); $tpl->assign('uid', $uid); $path[] = array ('ID' => '0', 'TITLE' => _L('Personal links'), 'TITLE_URL' => '', 'DESCRIPTION' => _L('Search results for personal links')); } elseif (!empty ($_REQUEST['search'])) // Search results { require_once 'search.php'; $search_preferences = array (); $search_preferences['Select_Options'] = array ( '`ID`' , '`TITLE`' , '`CACHE_TITLE`' , '`CACHE_URL`' ); $search_preferences['Where_Options'] = array ( "`(`STATUS` = '2' OR {$permission_cats} OR {$permission_cats_parents})" , "`CACHE_TITLE` IS NOT NULL" , "`CACHE_URL` IS NOT NULL" ); $search_preferences['Order_Options'] = array ( "`ID` ASC" , "`PARENT_ID` ASC" , "`TITLE` ASC" , "`CACHE_TITLE` ASC" ); $search_preferences['Search_Location'] = array ( 'TITLE' ); $search_preferences['From_Table'] = $tables['category']['name']; $search_preferences['BooleanSearchActive'] = 0; $CategorySearchResults = search($search_preferences); $tpl->assign('search' , $CategorySearchResults['search']); $tpl->assign('search_terms', $CategorySearchResults['search']); if (empty ($CategorySearchResults['errors']['empty_search'])) { $num_categs_per_page = 5; $categs_page_limit = 3; $CountCategResults = $db->GetOne($CategorySearchResults['SQL_Count_All']); $CountCategResults = (empty ($CountCategResults) || $CountCategResults < 0 ? 0 : intval ($CountCategResults)); if (!empty ($CountCategResults)) { $start_query = (!empty($_REQUEST['cat_page']) && preg_match('`^[\d]+$`', $_REQUEST['cat_page']) ? intval ($_REQUEST['cat_page']) : 1); $ListCategs = $db->GetAll($CategorySearchResults['SQL_Query']." LIMIT ".($start_query <= 1 ? '0' : $start_query).", {$num_categs_per_page}"); // Start category paging SmartyPaginate :: connect('CategoryPaging'); // Connect Paging if ($CountCategResults < 2) { SmartyPaginate :: disconnect('CategoryPaging'); SmartyPaginate :: reset ('CategoryPaging'); } SmartyPaginate :: setPrevText ('['._L('...less') .']' , 'CategoryPaging'); SmartyPaginate :: setNextText ('['._L('more...').']' , 'CategoryPaging'); SmartyPaginate :: setFirstText ('['._L('First').']' , 'CategoryPaging'); SmartyPaginate :: setLastText ('['._L('Last').']' , 'CategoryPaging'); SmartyPaginate :: setTotal ($CountCategResults , 'CategoryPaging'); SmartyPaginate :: setUrlVar ('cat_page' , 'CategoryPaging'); SmartyPaginate :: setUrl ($_SERVER['REQUEST_URI'], 'CategoryPaging'); SmartyPaginate :: setCurrentItem ($start_query , 'CategoryPaging'); SmartyPaginate :: setLimit ($num_categs_per_page , 'CategoryPaging'); SmartyPaginate :: setPageLimit ($categs_page_limit , 'CategoryPaging'); SmartyPaginate :: assign ($tpl , 'CategoryPaging', 'CategoryPaging'); $tpl->assign('list_cat', $ListCategs); if (!empty ($ListCategs)) { $search_cat = $tpl->fetch('category_search.tpl'); $tpl->assign('search_category', $search_cat); } } } // End category search unset ($CategorySearchResults, $search_preferences, $ListCategs, $categs_page_limit, $num_categs_per_page, $start_query, $search_cat); //News search $search_preferences = array (); $search_preferences['Select_Options'] = array ( '`ID`' , '`TITLE`' , '`DESCRIPTION`' , '`URL`' , '`CATEGORY_ID`' ); $search_preferences['Where_Options'] = array ( '' ); $search_preferences['Order_Options'] = array ( "`ID` ASC" , "`TITLE` ASC" , ); $search_preferences['Search_Location'] = array ( 'TITLE' , 'DESCRIPTION', 'URL' ); $search_preferences['From_Table'] = $tables['news']['name']; $search_preferences['BooleanSearchActive'] = 0; $newsSearchResults = search($search_preferences); $tpl->assign('search' , $newsSearchResults['search']); $tpl->assign('search_terms', $newsSearchResults['search']); if (empty ($newsSearchResults['errors']['empty_search'])) { $num_news_per_page = 10; $news_page_limit = 3; $CountNewsResults = $db->GetOne($newsSearchResults['SQL_Count_All']); $CountNewsResults = (empty ($CountNewsResults) || $CountNewsResults < 0 ? 0 : intval ($CountNewsResults)); if (!empty ($CountNewsResults)) { $start_query = (!empty($_REQUEST['article_page']) && preg_match('`^[\d]+$`', $_REQUEST['article_page']) ? intval ($_REQUEST['article_page']) : 1); $ListNews = $db->GetAll($newsSearchResults['SQL_Query']." LIMIT ".($start_query <= 1 ? '0' : $start_query).", {$num_news_per_page}"); // Start article paging SmartyPaginate :: connect('NewsPaging'); // Connect Paging if ($CountNewsResults < 2) { SmartyPaginate :: disconnect('NewsPaging'); SmartyPaginate :: reset ('NewsPaging'); } SmartyPaginate :: setPrevText ('['._L('...less') .']' , 'NewsPaging'); SmartyPaginate :: setNextText ('['._L('more...').']' , 'NewsPaging'); SmartyPaginate :: setFirstText ('['._L('First').']' , 'NewsPaging'); SmartyPaginate :: setLastText ('['._L('Last').']' , 'NewsPaging'); SmartyPaginate :: setTotal ($CountNewsResults , 'NewsPaging'); SmartyPaginate :: setUrlVar ('article_page' , 'NewsPaging'); SmartyPaginate :: setUrl ($_SERVER['REQUEST_URI'], 'NewsPaging'); SmartyPaginate :: setCurrentItem ($start_query , 'NewsPaging'); SmartyPaginate :: setLimit ($num_news_per_page , 'NewsPaging'); SmartyPaginate :: setPageLimit ($news_page_limit , 'NewsPaging'); SmartyPaginate :: assign ($tpl , 'NewsPaging', 'NewsPaging'); $tpl->assign('list_news', $ListNews); if (!empty ($ListNews)) { $search_news = $tpl->fetch('news_search.tpl'); $tpl->assign('search_news', $search_news); } } unset ($NewsResults, $search_preferences); } //Article search $search_preferences = array (); $search_preferences['Select_Options'] = array ( '`ID`' , '`TITLE`' , '`DESCRIPTION`' , '`ARTICLE`' , '`CATEGORY_ID`' ); if (EMAIL_CONFIRMATION == 1) { $search_preferences['Where_Options'] = array ( "(`RELEASE_DATE`<= now() OR {$permission_links_arts}) AND (`STATUS` = '2' OR {$permission_links_arts})" ); } else { $search_preferences['Where_Options'] = array ( "(`RELEASE_DATE`<= now() OR {$permission_links_arts}) AND (`STATUS` = '2' OR {$permission_links_arts})", "`OWNER_EMAIL_CONFIRMED` = '1'" ); } $search_preferences['Order_Options'] = array ( "`ID` ASC" , "`TITLE` ASC" , ); $search_preferences['Search_Location'] = array ( 'TITLE' , 'DESCRIPTION', 'ARTICLE' ); $search_preferences['From_Table'] = $tables['article']['name']; $search_preferences['BooleanSearchActive'] = 0; $ArticleSearchResults = search($search_preferences); $tpl->assign('search' , $ArticleSearchResults['search']); $tpl->assign('search_terms', $ArticleSearchResults['search']); if (empty ($ArticleSearchResults['errors']['empty_search'])) { $num_articles_per_page = 10; $articles_page_limit = 3; $CountArticleResults = $db->GetOne($ArticleSearchResults['SQL_Count_All']); $CountArticleResults = (empty ($CountArticleResults) || $CountArticleResults < 0 ? 0 : intval ($CountArticleResults)); if (!empty ($CountArticleResults)) { $start_query = (!empty($_REQUEST['article_page']) && preg_match('`^[\d]+$`', $_REQUEST['article_page']) ? intval ($_REQUEST['article_page']) : 1); $ListArticles = $db->GetAll($ArticleSearchResults['SQL_Query']." LIMIT ".($start_query <= 1 ? '0' : $start_query).", {$num_articles_per_page}"); // Start article paging SmartyPaginate :: connect('ArticlePaging'); // Connect Paging if ($CountArticleResults < 2) { SmartyPaginate :: disconnect('ArticlePaging'); SmartyPaginate :: reset ('ArticlePaging'); } SmartyPaginate :: setPrevText ('['._L('...less') .']' , 'ArticlePaging'); SmartyPaginate :: setNextText ('['._L('more...').']' , 'ArticlePaging'); SmartyPaginate :: setFirstText ('['._L('First').']' , 'ArticlePaging'); SmartyPaginate :: setLastText ('['._L('Last').']' , 'ArticlePaging'); SmartyPaginate :: setTotal ($CountArticleResults , 'ArticlePaging'); SmartyPaginate :: setUrlVar ('article_page' , 'ArticlePaging'); SmartyPaginate :: setUrl ($_SERVER['REQUEST_URI'], 'ArticlePaging'); SmartyPaginate :: setCurrentItem ($start_query , 'ArticlePaging'); SmartyPaginate :: setLimit ($num_articles_per_page , 'ArticlePaging'); SmartyPaginate :: setPageLimit ($articles_page_limit , 'ArticlePaging'); SmartyPaginate :: assign ($tpl , 'ArticlePaging', 'ArticlePaging'); if (!empty($ListArticles)) { for ($i =0; $i< count($ListArticles); $i++) { $ListArticles[$i]['rights'] = user_needs_approval($_SESSION['phpld']['user']['id'], $ListArticles[$i]['CATEGORY_ID']); $ListArticles[$i]['has_payment'] = article_has_payment($ListArticles[$i]['ID']); } } foreach($ListArticles as $k => $v) $ListArticles[$k]['SEO_URL'] = seo_url($v['ID'], $v['TITLE'], REWRITE_TYPE, REWRITE_EXT, 2); $tpl->assign('list_articles', $ListArticles); if (!empty ($ListArticles)) { $search_article = $tpl->fetch('article_search.tpl'); $tpl->assign('search_article', $search_article); } } } // End article search unset ($ArticleSearchResults, $search_preferences, $ListArticles, $article_page_limit, $num_articles_per_page, $start_query, $search_article); if (FTR_ENABLE) { $search_preferences = array (); $search_preferences['Select_Options'] = array ( '*' ); if (EMAIL_CONFIRMATION == 1) { $search_preferences['Where_Options'] = array ( "(`STATUS` = '2' OR {$permission_links_arts})" , "`FEATURED` = '1'" , "(`EXPIRY_DATE` >= ".$db->DBDate(time())." OR `EXPIRY_DATE` IS NULL)" ); } else { $search_preferences['Where_Options'] = array ( "(`STATUS` = '2' OR {$permission_links_arts})" , "`FEATURED` = '1'" , "(`EXPIRY_DATE` >= ".$db->DBDate(time())." OR `EXPIRY_DATE` IS NULL)", "`OWNER_EMAIL_CONFIRMED` = '1'" ); } $search_preferences['Order_Options'] = array ( "`EXPIRY_DATE` DESC" ); $search_preferences['Search_Location'] = array ( 'URL' , 'TITLE' , 'DESCRIPTION', 'META_DESCRIPTION', 'META_KEYWORDS',