dirurl);
if (!$counters->totalsubcats) { $counters->totalsubcats = $db->selectcount('categoriestable', 'validated=1 AND deleted=0 AND hide=0 AND isalbum=0'); $counters->update('totalsubcats'); }
if ($scriptinfo['scriptname'] != 'wsnforum') $settings->deletedmarkers = 'no'; // eliminate markers for deleted links
if (isset($mixtypes)) $settings->mixrecip = $mixtypes;
if ($settings->skiptocat > 0 && !$catid && !$todo && !$action) { fakerequest('action', 'displaycat'); fakerequest('catid', $settings->skiptocat); }
if (!is_numeric($settings->skiptocat) && $settings->skiptocat != '' && !$catid && !$todo && !$action)
{
if ($settings->skiptocat == 'albums.php?action=list' && $settings->apacherewrite == 'yes') $settings->skiptocat = $settings->rewritealbumindex;
redirect302($settings->skiptocat);
}
if ($todo == 'subscribe' && $thismember->id > 0)
{
$thiscategory = new category('id', $catid);
if (strstr($thiscategory->subscribers, '|||'. $thismember->id .'|||')) $message = $language->subscribecat_unsubscribe;
else $message = $language->subscribecat_subscribe;
$dest = objectreplacements($redirects['aftersubscribecat'], $thiscategory);
$thiscategory->subscribe($thismember->id);
redirect($message, $dest);
}
if ($todo == 'ordercats' && $catfield && $catascdesc) $ordercats = "ORDER BY $catfield $catascdesc";
if (!$ordercats) $ordercats = $settings->ordercats;
if ($settings->ordercats2 != '') $ordercats .= str_replace('ORDER BY ', ',', $settings->ordercats2); // incorp secondary
if (!isset($catcolumns) || $catcolumns < 1) $catcolumns = $settings->catcols;
if (!isset($subcatcolumns) || $subcatcolumns < 1) $subcatcolumns = $settings->subcatcols;
if (!$_COOKIE['testcookie']) makecookie('testcookie', rand(1, 99), 86400*365*9); // test that their browser accepts cookies... and set captcha salt
if (!isset($linkcolumns) || $linkcolumns < 1) $linkcolumns = $settings->linkcols;
if ($settings->orderlinks == 'rotating case') $settings->orderlinks = "ORDER BY case when title >= '". $settings->currentletter ."' then 0 else 1 end, title";
if ((isset($ascdesc) && $ascdesc != '') && (!stristr($ordercats, 'ORDER')))
{
$ordercats = 'ORDER BY '. $ordercats .' '. $ascdesc;
if ($settings->ordercats2 != '') $ordercats .= str_replace('ORDER BY ', ',', $settings->ordercats2);
}
if ($ordercats == '')
{ // let user override value
$ordercats = $settings->ordercats;
if ($settings->ordercats2 != '') $ordercats .= str_replace('ORDER BY ', ',', $settings->ordercats2);
}
if (isset($checkversion)) echo "{$scriptinfo['fullscripttitle']} version check... this is ". $scriptinfo['version'];
if (isset($catname))
{
$catname = rtrim($catname, '/');
if (is_numeric($catname)) $catid = $catname;
}
if ($settings->rewritesubdomains == 'yes')
{ // get first category out of subdomain and move it into front of catname
$subdomain = '';
$pieces = explode('.', $_SERVER['HTTP_HOST']);
if (count($pieces) >= 3 && $pieces[0] != 'www') $subdomain = $pieces[0];
if ($subdomain)
{ // confirmed that a category was passed in subdomain
$_REQUEST['rewritten'] = 1; $_GET['rewritten'] = 1; $rewritten = 1; // in case this is checked anywhere
if ($catname) $catname = $subdomain.'/'.$catname;
else
{
if (!tweakisset('subdomainsections') || ($subdomain != 'downloads' && $subdomain != 'publishers' && $subdomain != 'screenshots'))
{
$catname = $subdomain;
fakerequest('action', 'displaycat');
}
}
}
}
if (!$catid && !$catname && $action == 'displaycat') unset($action); // the rewrite rule for categories ends with a ? so it can match with an empty catname value on some servers (such as aussiegardening.com.au). this adjusts for that scenario by making sure we don't try to load an unspecified category, and that we show the expected index page.
if (isset($catname) && $catname != '' && $catid == '')
{ // determine id based on name and path
$flags['doingcategoryrewrite'] = true;
if ($settings->skiptocat > 0)
{
$cz = new category('id', $settings->skiptocat);
$catname = urlencode(addspaces($cz->name)) .'/'. $catname;
}
$name = urldecode(trim($catname, '/'));
$name = addspaces($name);
// extract subdirectories
$subs = explode('/', $name);
$o = safecount($subs);
$startfrom = $o-2;
$thiscatname = $subs[$o - 1];
if (is_numeric($subs[$o-1]))
{
$page = $subs[$o-1];
$startfrom = $o-3;
$thiscatname = $subs[$o - 2];
$name = str_replace('/'. $page, '', $name);
}
for ($x=$startfrom; $x>-1; $x--)
{
$parentlist .= '|||'. $subs[$x];
}
$parentlist .= '|||';
if ($settings->rewriteampersand == 'and')
{ // prevents error of category named "greater portland & casco bay" becoming "greater portl& & casco bay"
$altthiscatname = str_replace(" and ", " & ", $thiscatname); // to catch literal 'and's
$altparentlist = str_replace(" and ", " & ", $parentlist); // to catch literal 'and's
}
else
{
$altthiscatname = str_replace($settings->rewriteampersand, '&', $thiscatname); // to catch literal 'and's
$altparentlist = str_replace($settings->rewriteampersand, '&', $parentlist); // to catch literal 'and's
}
if ($startfrom > -1 && $subs[0] != '')
{
// problem: ' isn't passed in url, but is in. solution: messy mysql-only stuff.
$where = "validated=1 AND deleted=0 AND (REPLACE(name, ''', '') = '". $thiscatname ."' OR REPLACE(name, ''', '') = '". $altthiscatname ."') AND (REPLACE(parentnames, ''', '') = '". $parentlist ."' OR REPLACE(parentnames, ''', '') = '". $altparentlist ."')";
$q = $db->select('id', 'categoriestable', $where, '', '');
$n = $db->numrows($q);
if ($n) $catid = $db->rowitem($q);
else
{ // if it's not a top level, find it elsewhere. this is necessary for unconventional rewrite schemes like snoopy.com.au (which has second level categories as subdomains)
$where = "validated=1 AND deleted=0 AND (REPLACE(name, ''', '') = '$thiscatname' OR REPLACE(name, ''', '') = '$altthiscatname')";
$catid = $db->selectitem('id', 'categoriestable', $where);
}
}
else
{
$where = "validated=1 AND deleted=0 AND (REPLACE(name, ''', '') = '$name' OR REPLACE(name, ''', '') = '$altthiscatname') AND parent=0";
$q = $db->select('id', 'categoriestable', $where, '', '');
$n = $db->numrows($q);
if ($n) $catid = $db->rowitem($q);
else
{ // if it's not a top level, find it elsewhere. this is necessary for unconventional rewrite schemes like snoopy.com.au (which has second level categories as subdomains)
$where = "validated=1 AND deleted=0 AND (REPLACE(name, ''', '') = '$name' OR REPLACE(name, ''', '') = '$altname')";
$catid = $db->selectitem('id', 'categoriestable', $where);
}
}
$flags['doingcategoryrewrite'] = false;
}
if ($action == 'displaycat' && !$catid) endwithbadrequest();
if ($action == 'displaycat' && $catid > 0)
{ // display desired category
$thiscategory = new category('id', $catid); // create proper category object
if ($thiscategory->isalbum)
{ // have to handle albums here because with url rewriting they'll come to index.php
require_once 'includes/displayalbum.php';
}
else
{
require_once 'includes/displaycat.php';
}
}
else
{ // no category selected, so display listing of top level categories
require_once 'includes/displaytop.php';
}
// properly select items in cat and links ordering selectors
$ordering = explode(' ', $ordercats);
// 0: ORDER 1: BY 2: field 3: ASC/DESC
$ourorder = '