_SetArticleId();
$this->_BuildTrailArray();
$this->_SetTitle();
$this->_SetAuthorName();
$this->_SetPage();
$this->_SetAuthorId();
}
function HandlePage()
{
// Determine which function to load
switch($this->_action)
{
case "__captcha":
{
if ($GLOBALS['AL_CFG']['EnableCaptchaCheck']){
$GLOBALS["AL_CLASS_CAPTCHA"]->OutputImage();
}
break;
}
case "viewarticle":
{
$this->ShowArticlePage();
break;
}
case "submitcomment":
{
$this->SaveComment();
break;
}
case "newcomment":
{
$this->NewComment();
break;
}
case "emailarticle":
{
$this->EmailArticle();
break;
}
case "print":
{
$this->PrintArticle();
break;
}
case "favorite":
{
$this->FavoriteArticle();
break;
}
case "read":
{
$this->ReadArticle();
break;
}
case "submitarticle":
{
if($GLOBALS["AL_CLASS_AUTH"]->IsLoggedIn()){
$GLOBALS["HideArticleOptionsPanel"] = true;
$this->SubmitArticle();
}else{
header(sprintf("Location: %s/authors/login",$GLOBALS["AL_CFG"]["siteURL"]));
}
break;
}
case "savearticle":
{
if($GLOBALS["AL_CLASS_AUTH"]->IsLoggedIn()){
$GLOBALS["HideArticleOptionsPanel"] = true;
$this->SaveArticle();
}else{
header(sprintf("Location: %s/authors/login",$GLOBALS["AL_CFG"]["siteURL"]));
}
break;
}
case "savearticle2":
{
if($GLOBALS["AL_CLASS_AUTH"]->IsLoggedIn()){
$GLOBALS["HideArticleOptionsPanel"] = true;
$this->SaveArticle2();
}else{
header(sprintf("Location: %s/authors/login",$GLOBALS["AL_CFG"]["siteURL"]));
}
break;
}
case "addpage":
{
if($GLOBALS["AL_CLASS_AUTH"]->IsLoggedIn()){
$GLOBALS["HideArticleOptionsPanel"] = true;
$this->AddPage();
}else{
header(sprintf("Location: %s/authors/login",$GLOBALS["AL_CFG"]["siteURL"]));
}
break;
}
case "getdownload":
{
$this->GetDownload();
break;
}
case "viewallfavorites":
{
$GLOBALS["HideArticleOptionsPanel"] = true;
$this->ViewAllFavorites();
break;
}
default:
{
$this->ShowArticles();
break;
}
}
}
function GetPage()
{
return $this->_page;
}
function _GetPass(&$CatId)
{
/*
Get a list of all the categories that this question appears in and if they are *ALL* password protected then we will request authorization.
*/
$pass = "";
$numCats = 0;
$numPass = 0;
$query = sprintf("select * from %scategoryassociations inner join %scategories on %scategoryassociations.CategoryId=%scategories.CategoryId where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"],$GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$result = mysql_query($query);
$numCats = mysql_num_rows($result);
// If all categories are password protected then we will require the password
while($row = mysql_fetch_array($result))
{
if($row["catPass"] != "")
{
$numPass++;
$CatId = $row["CategoryID"];
$pass = $row["catPass"];
}
}
if($numCats == $numPass)
{
// The password needs to match at least one of the categories
return $pass;
}
else
return "";
}
function _SetPage()
{
$uri = $_SERVER["REQUEST_URI"];
if(isset($_REQUEST["Page"]))
$this->_page = $_REQUEST["Page"];
if(is_numeric(strpos($uri, "__captcha")))
{
$this->_action = "__captcha";
}elseif(is_numeric(strpos($uri, "/submitcomment")))
{
$this->_action = "submitcomment";
}
else if(is_numeric(strpos($uri, "/newcomment")))
{
$this->_action = "newcomment";
}
else if(is_numeric(strpos($uri, "/articleemail")))
{
$this->_action = "emailarticle";
}
else if(is_numeric(strpos($uri, "/print")))
{
$this->_action = "print";
}
else if(is_numeric(strpos($uri, "/addfav")))
{
$this->_action = "favorite";
}
else if(is_numeric(strpos($uri, "/removefav")))
{
$this->_action = "favorite";
}
else if(is_numeric(strpos($uri, "/addread")))
{
$this->_action = "read";
}
else if(is_numeric(strpos($uri, "/removeread")))
{
$this->_action = "read";
}
else if(is_numeric(strpos($uri, "/submitarticle/do")))
{
$this->_action = "savearticle";
}
else if(is_numeric(strpos($uri, "/submitarticle/textdo")))
{
$this->_action = "savearticle2";
}
else if(is_numeric(strpos($uri, "submitarticle/addpage")))
{
$this->_action = "addpage";
}
else if(is_numeric(strpos($uri, "/submitarticle")))
{
$this->_action = "submitarticle";
}
else if(is_numeric(strpos($uri, "/getdownload")))
{
$this->_action = "getdownload";
}
else if(is_numeric(strpos($uri, "/allfavorites")))
{
$this->_action = "viewallfavorites";
}
else if(eregi("/articles/?$", $uri))
{
$this->_action = "";
}
else
{
$getPage =false;
if(is_numeric(strpos($uri, "/articles/articles"))){
$iPos = strpos($uri, "/articles/articles/");
$iPos += strlen("/articles/articles/");
$uri1 = substr($uri, $iPos, 100);
$getPage =true;
}elseif(is_numeric(strpos($uri, "/articles"))){
$iPos = strpos($uri, "/articles/");
$iPos += strlen("/articles/");
$uri1 = substr($uri, $iPos, 100);
$getPage =true;
}
if($getPage == true){
$arrURI = explode("/", $uri1);
if(sizeof($arrURI) > 1)
$this->_page = $arrURI[1];
$query = sprintf("select count(*) from %sarticlepages where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$this->_pages = mysql_result(mysql_query($query), 0, 0);
$this->_action = "viewarticle";
}
}
if($this->_page == 0)
$this->_page = 1;
}
function GetPages()
{
return $this->_pages;
}
function GetPageId()
{
// Use the article ID and page number to find out the actual page ID
$arrIds = array();
$query = sprintf("select PageID from %sarticlepages where ArticleID='%d' order by SortOrderID", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
$arrIds[] = $row["PageID"];
if(sizeof($arrIds) >= $this->GetPage())
return $arrIds[$this->GetPage()-1];
else
return 0;
}
function _SetArticleId()
{
$uri = $_SERVER["REQUEST_URI"];
if(is_numeric(strpos($uri, "/articles/articles"))){
$iPos = strpos($uri, "/articles/articles/");
$iPos += strlen("/articles/articles/");
$uri1 = substr($uri, $iPos, 100);
}else{
$iPos = strpos($uri, "/articles/");
$iPos += strlen("/articles/");
$uri1 = substr($uri, $iPos, 100);
}
$jPos = strpos($uri1, "/");
$id = substr($uri1, 0, $jPos);
if(is_numeric($id))
$this->_articleId = $id;
else
$this->_articleId = 0;
if(isset($_REQUEST["ArticleId"]))
$this->_articleId = (int)$_REQUEST["ArticleId"];
if(isset($_REQUEST["ContentId"]))
$this->_articleId = (int)$_REQUEST["ContentId"];
}
function GetArticleId($ForceCheck = false)
{
if(!$ForceCheck)
return $this->_articleId;
else
{
$this->_SetArticleId();
return $this->_articleId;
}
}
function GetTitle($ArticleId = 0)
{
if($ArticleId == 0)
{
return $this->_title;
}
else
{
$query = sprintf("select Title from %sarticles where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $ArticleId);
return @mysql_result(@mysql_query($query), 0, 0);
}
}
function _SetTitle()
{
$query = sprintf("select Title from %sarticles where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$this->_title = @mysql_result(@mysql_query($query), 0, 0);
}
function _SetMetaTags()
{
$query = sprintf("select * from %sarticles where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$row = mysql_fetch_array(mysql_query($query));
$metaKeys = trim($row["MetaKeywords"]);
if(!empty($metaKeys)){
$GLOBALS["AL_CFG"]["siteKeywords"] = $row["MetaKeywords"];
}
$metaDesc = trim($row["MetaDesc"]);
if(!empty($metaDesc)){
$GLOBALS["AL_CFG"]["siteDesc"] = $row["MetaDesc"];
}
return true;
}
function GetAuthorName()
{
return $this->_author;
}
function GetArticleType()
{
$query = sprintf("select Type from %sarticles where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
return @mysql_result(@mysql_query($query), 0, 0);
}
function GetArticleLink()
{
$query = sprintf("select ArticleURL from %sarticles where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
return @mysql_result(@mysql_query($query), 0, 0);
}
function GetPageTitle()
{
// Get the title of the selected page
$title = "";
$query = sprintf("select Title from %sarticlepages where PageID='%d' and ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetPageId(), $this->GetArticleId());
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
{
$title = $row["Title"];
}
return $title;
}
function _SetAuthorName()
{
$query = sprintf("select * from %sarticles inner join %susers on %sarticles.AuthorID=%susers.UserID where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
{
$this->_author = sprintf("%s %s", $row["FirstName"], $row["LastName"]);
}
}
function GetAuthorId()
{
return $this->_authorId;
}
function _SetAuthorId()
{
$query = sprintf("select AuthorID from %sarticles where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
{
$this->_authorId = $row["AuthorID"];
}
}
function GetBiography()
{
$query = sprintf("select * from %sarticles inner join %susers on %sarticles.AuthorID=%susers.UserID where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
{
return AL_HELPER::hyperlinkUrls(str_replace('"', '"', $row["Biography"]));
}
}
function GetPublishDate()
{
$date = $GLOBALS["AL_LANG"]["hpNA"];
$query = sprintf("select unix_timestamp(StartDate) as SD from %sarticles where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
{
$date = AL_HELPER::GetRelativeDate($row["SD"]);
}
return $date;
}
function GetAuthorLink()
{
$query = sprintf("select * from %sarticles inner join %susers on %sarticles.AuthorID=%susers.UserID where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$result = mysql_query($query);
$link = "";
if($row = mysql_fetch_array($result))
{
$link = AL_HELPER::AuthorLink($row["AuthorID"], sprintf("%s %s", $row["FirstName"], $row["LastName"]));
}
return $link;
}
function _BuildTrailArray()
{
// Build the arrays that will contain the category names to build the trails
$GLOBALS["ArticleTrails"] = array();
$count = 0;
$query = sprintf("select * from %scategoryassociations where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$catResult = mysql_query($query);
while($catRow = mysql_fetch_array($catResult))
{
$query = sprintf("select * from %scategories where CategoryID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $catRow["CategoryID"]);
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
{
// The root category is valid, try and loop through each category to find the ID of the last category in the set
$parentCat = $row["CategoryID"];
$start = true;
$numCats = 0;
while($parentCat > 0)
{
if($start)
{
$query = sprintf("select * from %scategories inner join %scategoryassociations on %scategories.CategoryID = %scategoryassociations.CategoryID where ArticleID='%d' and %scategories.CategoryID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId(), $GLOBALS["AL_CFG"]["tablePrefix"], $parentCat);
$start = false;
$numCats = mysql_num_rows(mysql_query($query));
}
else
{
if($numCats > 1)
$query = sprintf("select * from %scategories where ParentID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $parentCat);
else
$query = sprintf("select * from %scategories where ParentID=-1", $GLOBALS["AL_CFG"]["tablePrefix"]);
}
$result1 = mysql_query($query);
if($row1 = mysql_fetch_array($result1))
{
$parentCat = $row1["CategoryID"];
$GLOBALS["ArticleTrails"][$count][] = array($row1["CategoryID"], $row1["Name"], $row1["ParentID"]);
}
else
{
// Get the first category
$query = sprintf("select * from %scategories where CategoryID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $GLOBALS["ArticleTrails"][$count][0][0]);
$result2 = mysql_query($query);
if($row2 = mysql_fetch_array($result2))
{
$catId = $row2["ParentID"];
$query = sprintf("select * from %scategories where CategoryID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $catId);
$result3 = mysql_query($query);
if($row3 = mysql_fetch_array($result3))
{
$arrParent = array(array($row3["CategoryID"], $row3["Name"], $row3["ParentID"]));
$GLOBALS["ArticleTrails"][$count] = array_merge_recursive($arrParent, $GLOBALS["ArticleTrails"][$count]);
}
}
$parentCat = 0;
}
}
}
$count++;
}
// Make sure each trail's first category is the parent category
// If the article is in multiple sub-categories of the same root
// category it's harder to pick up the categories so we loop twice
// to make sure they are all fixed up.
for($h = 0; $h < 2; $h++)
{
for($i = 0; $i < sizeof($GLOBALS["ArticleTrails"]); $i++)
{
if($GLOBALS["ArticleTrails"][$i][0][2] > 0)
{
$catId = $GLOBALS["ArticleTrails"][$i][0][2];
$query = sprintf("select * from %scategories where CategoryID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $catId);
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
{
$arrParent = array(array($row["CategoryID"], $row["Name"], $row["ParentID"]));
$GLOBALS["ArticleTrails"][$i] = array_merge_recursive($arrParent, $GLOBALS["ArticleTrails"][$i]);
}
}
}
}
}
function GetContent()
{
// Get the content and then escape the glossary words
$output = "";
if($this->GetArticleType() == 1)
{
$query = sprintf("select Content from %sarticlepages where PageID='%d' and ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetPageId(), $this->GetArticleId());
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
{
$output = $row["Content"];
// Get all glossary words
$arrWords = AL_HELPER::GetGlossaryTerms();
if(sizeof($arrWords) > 0)
{
// Make the replacements
for($i = 0; $i < sizeof($arrWords); $i++)
{
$regex = "#(?![^<]*?>)(?!]*>)\b" . preg_quote($arrWords[$i]["word"]) . "\b(?![^<]*)#si";
$output = preg_replace($regex, $arrWords[$i]["token"], $output, 1);
}
}
if(sizeof($arrWords) > 0)
{
// Make the replacements
for($i = 0; $i < sizeof($arrWords); $i++)
{
// Just replace the first instanse of the token
$title = str_replace("\r\n", " ", str_replace(''', '\\'', str_replace('"', '', $arrWords[$i]["desc"])));
$popup = "" . $arrWords[$i]["word"] . "
" . $title . "'); return false\">" . $arrWords[$i]["word"] . "";
// Replace the rest of the tokens back with the word
$output = str_replace($arrWords[$i]["token"], $popup, $output);
}
}
}
}
else
{
$query = sprintf("select Summary from %sarticles where ArticleID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
$output = $row["Summary"];
}
return $output;
}
function GetPrintContent()
{
// Get the content of all pages and then escape the glossary words
$output = "";
$count = 0;
if($this->GetArticleType() == 1)
{
$query = sprintf("select Title, Content from %sarticlepages where ArticleID='%d' order by SortOrderID asc", $GLOBALS["AL_CFG"]["tablePrefix"], $this->GetArticleId());
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
if(++$count < mysql_num_rows($result))
$output .= sprintf("