<?php 
/*#################################################################*\
|# Licence Number 0DT7-0122-0NW1-0210
|# -------------------------------------------------------------   #|
|# Copyright (c)2010 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 <david@david-duval.com>
# @package        PHPLinkDirectory
# @version        4.0.0
# ################################################################################
*/

/**
 * Get all information of a category by providing it's ID
 * @param integet Category ID
 * @return array An array with all informations of a category
 */
function getCategoryByID($cid=0)
{
   global $db, $tables;

   $cid = (preg_match ('`^[\d]+$`', $cid) ? intval ($cid) : 0);

   if (empty ($cid))
      return false;
   else
      $output = $db->GetRow("SELECT * FROM `{$tables['category']['name']}` WHERE `ID` = ".$db->qstr($cid));

   if (!is_array ($output) || empty ($output))
      return false;

   return $output;
}

function getPageByID($id)
{
   global $db, $tables;

   if (empty ($id))
      return false;
   else
      $output = $db->GetRow("SELECT * FROM `{$tables['page']['name']}` WHERE `ID` = ".$db->qstr($id));

   if (!is_array ($output) || empty ($output))
      return false;

   return $output;
}


/**
 * Get title of a category by providing it's ID
 * @param integet Category ID
 * @return string Title of category
 */
function getCategoryTitleByID($cid=0)
{
   global $db, $tables;

   $cid = (preg_match ('`^[\d]+$`', $cid) ? intval ($cid) : 0);

   if (empty ($cid))
      return false;
   else
      $output = $db->GetOne("SELECT `TITLE` FROM `{$tables['category']['name']}` WHERE `ID` = ".$db->qstr($cid));

   if (empty ($output))
      return false;

   return $output;
}

/**
 * Get all information of a link by providing it's ID
 * @param integet Link ID
 * @return array An array with all informations of a link
 */
function getLinkByID($lid=0)
{
   global $db, $tables;

   $lid = (preg_match ('`^[\d]+$`', $lid) ? intval ($lid) : 0);

   if (empty ($lid))
      return false;
   else
      $output = $db->GetRow("SELECT * FROM `{$tables['link']['name']}` WHERE `ID` = ".$db->qstr($lid));

   if (!is_array ($output) || empty ($output))
      return false;

   return $output;
}

/**
 * Get all information of an article by providing its ID
 * @param integer Article ID
 * @return array An array with all informations of an article
 */
function getArticleByID($aid=0)
{
   global $db, $tables;

   $aid = (preg_match ('`^[\d]+$`', $aid) ? intval ($aid) : 0);

   if (empty ($aid))
      return false;
   else
      $output = $db->GetRow("SELECT * FROM `{$tables['article']['name']}` WHERE `ID` = ".$db->qstr($aid));

   if (!is_array ($output) || empty ($output))
      return false;

   return $output;
}

function addCategPathToLinks($links)
{
   global $db, $tables;

   if (is_array ($links) && !empty ($links))
   {
      foreach ($links as $key => $link)
      {
         $categCache = $db->GetRow("SELECT `CACHE_TITLE`, `CACHE_URL` FROM {$tables['category']['name']} WHERE `ID` = ".$db->qstr($link['CATEGORY_ID']));

         //Build category URL
         $links[$key]['CATEGORY_URL']   = (!empty ($categCache['CACHE_URL']) ? $categCache['CACHE_URL'] : buildCategUrl($link['CATEGORY_ID']));
         //Build category title
         $links[$key]['CATEGORY_TITLE'] = (!empty ($categCache['CACHE_TITLE']) ? $categCache['CACHE_TITLE'] : buildCategUrlTitle($link['CATEGORY_ID']));
         //Free memory
         unset ($link, $categCache);
      }
   }

   return $links;
}

?>