_SetCat(); } function _GetCat() { return $this->_catId; } function _GetPass() { $query = sprintf("select catPass from %scategories where CategoryID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->_GetCat()); $result = mysql_query($query); if($row = mysql_fetch_array($result)) { $pass = $row["catPass"]; return $pass; } else { return ""; } } function _SetCat() { // Get the category from the request_uri and work out its ID $path = $_SERVER["REQUEST_URI"]; $path = eregi_replace('\.php[\?]?', '', $path); $iPos = strpos($path, "/categories/") + strlen("/categories/"); $cats = substr($path, $iPos, strlen($path)); $cats = eregi_replace("/$", "", $cats); // Now that we have the categories we need to organize them // into an array and work out the category ID $arrCats = explode("/", $cats); // Replace all bad variables back in for($i = 0; $i < sizeof($arrCats); $i++) { $arrCats[$i] = AL_HELPER::_MakeURLNormal($arrCats[$i]); } //$GLOBALS["CategoryName"] = $arrCats[sizeof($arrCats)-1]; // The first category *MUST* have a parent ID of 0 or it's invalid $query = sprintf("select CategoryID,Name from %scategories where lower(name) = '%s' and ParentID=0", $GLOBALS["AL_CFG"]["tablePrefix"], strtolower($arrCats[0])); $result = mysql_query($query); $GLOBALS["CatTrails"] = array(); if($row = mysql_fetch_array($result)) { $GLOBALS["CatTrails"][] = array($row["CategoryID"], $arrCats[0]); // The root category is valid, try and loop through each category to find the ID of the last category in the set if(sizeof($arrCats) > 1) { $parentCat = $row["CategoryID"]; for($i = 1; $i < sizeof($arrCats); $i++) { $query = sprintf("select * from %scategories where lower(Name)='%s' and ParentID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], mysql_escape_string(strtolower($arrCats[$i])), $parentCat); $result = mysql_query($query); if($row = mysql_fetch_array($result)) { $parentCat = $row["CategoryID"]; $GLOBALS["CatTrails"][] = array($row["CategoryID"], $row["Name"]); $GLOBALS["CategoryName"] = $row["Name"]; } else { continue; } } $this->_catId = $parentCat; } else { $this->_catId = $row["CategoryID"]; $GLOBALS["CategoryName"] = $row["Name"]; } } // Give the category ID a global scope so that it can be accessed from the templates $GLOBALS["CategoryId"] = $this->_GetCat(); } function HandlePage() { // Determine which function to load switch($ToDo) { default: { $this->ShowCategoryPage(); } } } function IncrementViewCount() { $query = sprintf("update %scategories set Visits=Visits+1 where CategoryID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->_GetCat()); @mysql_query($query); } function ShowCategoryPage() { // Is this a password protected category? $pass = $this->_GetPass(); $auth = false; if(isset($_COOKIE["al_cat_pass_" . $this->_GetCat()])) { $result = 0; // Does the cookie password match the password in the database? $cookiePass = $_COOKIE["al_cat_pass_" . $this->_GetCat()]; $query = sprintf("select CategoryID from %scategories where CategoryID='%d' and catPass='%s'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->_GetCat(), $cookiePass); $result = mysql_query($query); // The password is correct, grant access if(mysql_num_rows($result) == 1) $auth = true; } // Is the user attempting to get access to the category? if(isset($_POST["catAuthPass"])) { $formPass = $_POST["catAuthPass"]; $query = sprintf("select count(CategoryID) from %scategories where CategoryID='%d' and catPass='%s'", $GLOBALS["AL_CFG"]["tablePrefix"], $this->_GetCat(), $formPass); $result = mysql_query($query); $row = mysql_fetch_row($result); // The password is correct, grant access if($row[0] == 1) { // Save the authorization to a cookie and grant access setcookie("al_cat_pass_" . $this->_GetCat(), $formPass, time()+3600*24*365, "/"); $auth = true; } } if($pass != "" && $auth == false) { // Load the category password panel $GLOBALS["HidePanels"] = array("ViewCategoryAdvancedPanel"); //$GLOBALS["FormAction"] = str_replace(".php", "", $_SERVER["PHP_SELF"]); $GLOBALS["FormAction"] = str_replace(".php", "", $_SERVER["REQUEST_URI"]); if(isset($_POST["catAuthPass"])) $GLOBALS["CatAuthPass"] = $_POST["catAuthPass"]; else $GLOBALS["CatAuthPass"] = ""; // Do we need to hide the "bad password" message? if(!isset($_POST["catAuthPass"])) $GLOBALS["HideErrorPanel"] = "none"; $GLOBALS["AL_CLASS_TEMPLATE"]->SetPageTitle($GLOBALS["AL_CFG"]["siteName"]); $GLOBALS["AL_CLASS_TEMPLATE"]->SetTemplate("Categories"); echo $GLOBALS["AL_CLASS_TEMPLATE"]->ParseTemplate(); } else { // Increment the number of views for this category $this->IncrementViewCount(); // Load the categories page $GLOBALS["HidePanels"] = array("CategoryAuthPanel"); // Load the home page of the front end $GLOBALS["AL_CLASS_TEMPLATE"]->SetPageTitle($GLOBALS["AL_CFG"]["siteName"]); $GLOBALS["AL_CLASS_TEMPLATE"]->SetTemplate("Categories"); echo $GLOBALS["AL_CLASS_TEMPLATE"]->ParseTemplate(); } } function _SetMetaTags($id=false) { if(!((int)$GLOBALS["CategoryId"] > 0)){ return false; } if($id == false){ $id = $this->_GetCat(); } $query = sprintf("select * from %scategories where CategoryID='%d'", $GLOBALS["AL_CFG"]["tablePrefix"], $id ); $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; } } ?>