<?php
require 'start.php'; // header stuff
if ($_GET['orderlinks'] == '') $orderlinks = $settings->orderlinks;
if ($mixtypes) $settings->mixrecip = $mixtypes;
if ($settings->skiptocat > 0 && !$catid && !$todo && !$action) { $action = 'displaycat'; $catid = $settings->skiptocat; }
// reconstruct the current url and put it in a cookie, so we can know where to come back to if we go off somewhere soon... but only save it for 15 minutes
if ($settings->dirurl != '') $currenturl = $settings->dirurl .'/index.php';
else $currenturl = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
$currenturl .= '?'. $_SERVER['QUERY_STRING'];
if ($custom == 'yes' && $TID == 'promote')
{
makecookie("sponsorusergroup", $thismember->id, time() + 100000);
$ip = $_SERVER['REMOTE_ADDR'];
$thismember->ip = 'buy '. $ip;
$thismember->update('ip');
$settings->sponsorugitem = str_replace(', ', ',', $settings->sponsorugitem);
$settings->sponsorugcharge = str_replace(', ', ',', $settings->sponsorugcharge);
$settings->sponsorusergroup = str_replace(', ', ',', $settings->sponsorusergroup);
$items = explode(',', $settings->sponsorugitem);
$charges = explode(',', $settings->sponsorugcharge);
$types = explode(',', $settings->sponsorusergroup);
for ($x=1; $x<(sizeof($items) + 1); $x++)
{
$template->replace('{SPONSORITEM'. $x .'}', $items[$x - 1]);
$template->replace('{SPONSORCHARGE'. $x .'}', $charges[$x - 1]);
$template->replace('{SPONSORUSERGROUP'. $x .'}', $types[$x - 1]);
}
}
if ($todo == 'subscribe' && $thismember->id > 0)
{
$thiscategory = new category('id', $catid);
if (!$template) $template = new template("redirect.tpl");
if (strstr($thiscategory->subscribers, '|||'. $thismember->id .'|||'))
$template->replace('{MESSAGE}', $language->subscribecat_unsubscribe);
else
$template->replace('{MESSAGE}', $language->subscribecat_subscribe);
if ($aftersubscribecat == '') $aftersubscribecat = $returnto;
$template->replace('{DESTINATION}', $aftersubscribecat);
$thiscategory->subscribe($thismember->id);
}
else if ($todo == 'ordercats')
{
$ordercats = "ORDER BY $catfield $catascdesc";
}
else if ($todo == 'orderlinks')
{
$orderlinks = "ORDER BY $orderlinks $ascdesc";
if ($settings->orderlinks2 != '') $orderlinks .= str_replace('ORDER BY ', ',', $settings->orderlinks2);
}
if (!$_COOKIE['testcookie'])
{
// test that their browser accepts cookies
makecookie('testcookie', '1', time()+9999999999);
}
if (!$excludetimed)
{
include 'timedactions.php';
}
if ($linkcolumns < 1) $linkcolumns = $settings->linkcols;
if ($catcolumns < 1) $catcolumns = $settings->catcols;
if ($subcatcolumns < 1) $subcatcolumns = $settings->subcatcols;
if ($settings->orderlinks == 'rotating case') { $settings->orderlinks = "ORDER BY case when title >= '". $settings->currentletter ."' then 0 else 1 end, title"; $orderlinks = $settings->orderlinks; }
if (($ascdesc != '') && (!stristr($orderlinks, 'ORDER'))) { $orderlinks = 'ORDER BY '. $orderlinks .' '. $ascdesc; if ($settings->orderlinks2 != '') $orderlinks .= str_replace('ORDER BY ', ',', $settings->orderlinks2); }
if ($orderlinks == '' || substr_count($orderlinks, 'ORDER') > 1)
{ // let user override value
$orderlinks = $settings->orderlinks;
if ($settings->orderlinks2 != '') $orderlinks .= str_replace('ORDER BY ', ',', $settings->orderlinks2);
}
if ($ordercats == '')
{ // let user override value
$ordercats = $settings->ordercats;
}
if ($perpage == '')
{ // let user override value
$perpage = $settings->perpage;
}
$realorder = $orderlinks;
if ($settings->orderlinks2 != '') $realorder .= str_replace('ORDER BY ', ',', $settings->orderlinks2);
// deduce needed widths for table cells
if ($linkcolumns > 0) $linkwidth = 'width="'.(int)(99/$linkcolumns) .'%"';
if ($catcolumns > 0) $catwidth = 'width="'.(int)(99/$catcolumns) .'%"';
if ($subcatcolumns > 0) $subcatwidth = 'width="'.(int)(99/$subcatcolumns) .'%"';
if ($settings->fixedwidth != '') $linkwidth = 'width="'. $settings->fixedwidth .'"';
if ($checkversion == 'docheck')
{
echo "WSN version check... this is $fullscripttitle version ". $version;
}
if ($action == 'getvotingcode')
{
$thislink = new onelink('id', $id);
if (!$template) $template = new template("$templatesdir/showvotecode.tpl");
$template->replace('{DIRURL}', $settings->dirurl);
$template->text = linkreplacements($template->text, $thislink);
}
if (is_numeric($catname)) $catid = $catname;
if ($catname != '' && $catid == '')
{ // determine id based on name and path
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 = sizeof($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 ($startfrom > -1 && $subs[0] != '')
{
$q = $db->select('id', 'categoriestable', "validated=1 AND hide=0 AND name='". $thiscatname ."' AND parentnames='". $parentlist ."'", '', '');
$catid = $db->rowitem($q);
}
else
{
$q = $db->select('id', 'categoriestable', "validated=1 AND hide=0 AND name='$name' AND parent=0", '', '');
$catid = $db->rowitem($q);
}
}
if (($action == 'displaycat') && ($catid > 0))
{
// display all the links in the selected category
if ($page == '') $page = 1;
$thiscategory = new category('id', $catid); // create proper category object
if ($thiscategory->name == '')
{
header("Location: index.php");
die (' ');
}
$thiscategory->countview();
if ($thiscategory->catcols != '') { $subcatcolumns = $thiscategory->catcols; $catcolumns = $thiscategory->catcols; }
if ($thiscategory->linkcols != '') { $linkcolumns = $thiscategory->linkcols; }
if ($thiscategory->mixtypes != '') $settings->mixrecip = $thiscategory->mixtypes;
if ($thiscategory->orderlinks != $settings->orderlinks && $thiscategory->orderlinks != '')
{
$orderlinks = $thiscategory->orderlinks;
if ($settings->orderlinks2 != '') $orderlinks .= str_replace('ORDER BY ', ',', $settings->orderlinks2);
}
if ($thiscategory->custom != '')
{
$custom = $templatesdir .'/'. $thiscategory->custom;
if (!$template) $template = new template($custom);
}
if (!$template) $template = new template('displaylinks.tpl');
$area = $language->title_divider . $thiscategory->name; // supply area for template
$template->replace('{NAVIGATION}', shownav($thiscategory)); // do navigation
// do related categories
$relatedtemplate = templateextract($template->text, '', '');
$template->replace($relatedtemplate, '{RELATEDTEMPLATE}');
$relatedarray = explode('|||', $thiscategory->related);
if (($thiscategory->related == '') || ($thiscategory->related == ' ')) $num = 0;
else $num = sizeof($relatedarray);
for ($x=0; $x<$num; $x++)
{
$rcat = new category('id', $relatedarray[$x]);
$rcompletedtemplate .= categoryreplacements($relatedtemplate, $rcat);
}
$template->replace('{RELATEDTEMPLATE}', $rcompletedtemplate);
// now do subcategories
$numsubcats = $thiscategory->numsubcats();
$subperpage = $settings->catsperpage;
if ($subperpage < 1) $subperpage = 75;
if ($subpage < 1) $subpage = 1;
$start = ($subpage * $subperpage) - $subperpage;
$end = $start + $subperpage;
if ($thiscategory->alias > 0) $ourcatid = $thiscategory->alias; else $ourcatid = $catid;
$subcatsdata = $db->select($settings->categoryfields, 'categoriestable', "parent=$ourcatid AND validated=1 AND hide=0 AND isalbum=0", $ordercats, "LIMIT $start,$subperpage");
$shownsubcats = $db->numrows($subcatsdata);
$template_subcats = templateextract($template->text, '', '');
$subsub = templateextract($template_subcats, '', '');
$template->replace($template_subcats, '{SUBCATEGORIES}'); // replace with marker
$cattypes = explode(',', $settings->cattypes);
$qn = sizeof($cattypes);
for ($qx = 0; $qx < $qn; $qx++)
{ // get templates for each type
if ($cattypes[$qx] != '')
{
$avar = $cattypes[$qx] .'template';
$$avar = templateextract($template_subcats, '', '');
$template_subcats = str_replace($$avar, '{'. $cattypes[$qx] .'MARKER}', $template_subcats);
$cvar = $cattypes[$qx] .'colcount';
$$cvar = 0;
}
}
if ($numsubcats == 0)
{
$template_subcats = '';
if ($settings->catcols != 0) $subcatsbody = '
'; // for standards Nazis
}
else
{
$columncount = 0;
for ($count=0; $count<$shownsubcats; $count++)
{ // display each subcategory
$thissub = new category('row', $db->row($subcatsdata));
if ($thissub->type == '') $thissub->type = $cattypes[0];
if ($settings->mixcategorytypes == 'yes')
{
if ($columncount == 0)
{
if ($settings->catcols != 0) $subcatsbody .= '';
}
else if ($columncount == $subcatcolumns)
{
if ($settings->catcols != 0) $subcatsbody .= ' ';
$columncount = 0;
}
$columncount++;
$subcatsbody .= $template_subcats;
$subcatsbody = str_replace($subsub, $thissub->subcats($subsub), $subcatsbody);
$subcatsbody = str_replace('{NUMBER}', $count + 1, $subcatsbody);
$letter = ord('a') + ($count);
$subcatsbody = str_replace('{LETTER}', chr($letter), $subcatsbody);
$subcatsbody = str_replace('{U_LETTER}', strtoupper(chr($letter)), $subcatsbody);
$subcatsbody = categoryreplacements($subcatsbody, $thissub);
$subcatsbody = categoryreplacements($subcatsbody, $thissub); // to catch cat vars within cat vars
}
else
{
$avar = $thissub->type .'var';
$bvar = $thissub->type .'template';
$cvar = $thissub->type .'colcount';
if ($$cvar == 0)
{
if ($settings->catcols != 0) $$avar .= '';
}
else if ($$cvar == $subcatcolumns)
{
if ($settings->catcols != 0) $$avar .= ' ';
$$cvar = 0;
}
$$cvar++;
$$avar .= $$bvar;
$$avar = str_replace($subsub, $thissub->subcats($subsub), $$avar);
$$avar = str_replace('{NUMBER}', $count + 1, $$avar);
$letter = ord('a') + ($count);
$$avar = str_replace('{LETTER}', chr($letter), $$avar);
$$avar = str_replace('{U_LETTER}', strtoupper(chr($letter)), $$avar);
$$avar = categoryreplacements($$avar, $thissub);
$$avar = categoryreplacements($$avar, $thissub); // to catch cat vars within cat vars
}
}
if ($settings->catcols != 0 && $settings->mixcategorytypes == 'yes') $subcatsbody .= '';
if ($settings->mixcategorytypes != 'yes')
{
for ($qx = 0; $qx < $qn; $qx++)
{ // replace templates for each type
$avar = $cattypes[$qx] .'var';
if ($settings->catcols > 0) $$avar .= '';
$template_subcats = str_replace('{'. $cattypes[$qx] .'MARKER}', $$avar, $template_subcats);
}
$subcatsbody = $template_subcats;
}
}
// begin subcat pagination
$numpages = ceil($numsubcats / $subperpage);
for ($count=1; $count < $subpage; $count++)
$subpreviouspages .= $language->pageselection_left. ''. $count .' '. $language->pageselection_right;
for ($count=$subpage; $count<$numpages; $count++)
{
$next = $count+1;
$subnextpages .= $language->pageselection_left .''. $next .' '. $language->pageselection_right;
}
$template->replace('{SUBPREVIOUS}', $subpreviouspages);
if ($subpreviouspages != '' || $subnextpages != '') $template->replace('{SUBMULTIPAGE}', '1');
else $template->replace('{SUBMULTIPAGE}', '0');
$template->replace('{SUBNEXT}', $subnextpages);
$template->replace('{SUBCURRENTPAGE}', $subpage);
$template->replace('{SUBPAGE}', $subpage);
$template->replace('{SUBPERPAGE}', $subperpage);
// end subcat pagination
// set custom subcat column width
if ($subcatscolumns > 0) $width = (int)(100/$subcatcolumns);
if ($numsubcats < $subcatcolumns)
$subcatsbody = str_replace('{SUBCATWIDTH}', '', $subcatsbody);
else
$subcatsbody = str_replace('{SUBCATWIDTH}', $subcatwidth, $subcatsbody);
//find total number of validated links for this category, then total recip and total non-recip
$total = $thiscategory->linkshere();
$typetotals = explode(',', $settings->linktypes);
$n = sizeof($typetotals);
for ($x=0; $x<$n; $x++)
{
$var = $typetotals[$x] . 'total';
$$var = $thiscategory->typetotal($typetotals[$x]);
$template->replace('{'. strtoupper($var).'}', $$var);
}
if ($total == 0)
{
$template->replace('{LINKSBODY}', '');
$template->replace('{TOTALINCATEGORY}', '0');
}
$start = ($page * $perpage) - $perpage; // have to adjust for starting the numbering at 1
$end = $start + $perpage - 1;
// Begin ulsearch integration area
if ($settings->ulsearch == 'yes' && ($thiscategory->ulsearchquery != '' || $settings->ulsearchdefaultquery != '') && $page == 1)
{
if ($thiscategory->ulsearchquery == '') $thiscategory->ulsearchquery = $settings->ulsearchdefaultquery;
if ($thiscategory->ulsearchmax == '' || $thiscategory->ulsearchmax == 0) $thiscategory->ulsearchmax = $settings->ulsearchcatmax;
$ulresults = doulsearch($thiscategory->ulsearchquery, $thiscategory->ulsearchmax);
$ultemp = templateextract($template->text, '', '');
$cntr = 0;
for ($p=0; $p<$result_number; $p++)
{
$thelink = singleresult($ulresults, $p);
if ($p == 0 && $linkcolumns != 0) $ulcontent = '';
$ulcontent .= linkreplacements($ultemp, $thelink);
$cntr++;
if ($cntr == $linkcolumns) { if ($linkcolumns != 0) $ulcontent .= ' '; $cntr = 0; }
}
if ($ulcontent != '') if ($linkcolumns != 0) $ulcontent .= ' ';
}
$ulcontent = str_replace($pref .'WIDTH}', $linkwidth, $ulcontent);
// End ulsearch integration area
// get all the templates by cycling through the possibilities
// link types will be dropdown option on editing link
// can add/remove through admin panel
$thetypes = strtoupper($settings->linktypes);
$listtypes = explode(',', $thetypes);
$num = sizeof($listtypes);
for ($p=$num; $p>-1; $p--)
{
if (strstr($template->text, ''))
{
$test = templateextract($template->text, '', '');
if ($test != '') { $thedefault = $test; $listdefault = $listtypes[$p]; }
}
}
for ($count=0; $count<$num; $count++)
{
$typex = $listtypes[$count];
$varname = strtolower($typex) . 'linksbodybase';
if (strstr($template->text, "")) $$varname = templateextract($template->text, "", "");
if ($$varname != '') $template->replace($$varname, '{'. $typex .'LINKSBODY}'); // replace with marker
else { $$varname = $thedefault; $template->replace('{'. $listdefault .'LINKSBODY}', '{'. $listdefault .'LINKSBODY} {'. $typex .'LINKSBODY}'); }
$counter = strtolower($typex) .'count';
$$counter = 0;
}
$begin = $start;
$end = $start + $perpage;
$toshow = $perpage;
if ( ($total == 0) || ($start >= $end) )
{
$linksbodybase = '';
if ($start < $end)
{
$template_linksbody = $language->showlinks_empty;
$tmp = explode(',', $settings->linktypes);
$tmp = strtolower($tmp[0]) . 'linksbodybase';
$$tmp = $language->showlinks_empty;
}
}
else
{
if ($settings->sponsorseparate == 'yes' && $settings->sponsoruselink == 'yes')
{
$sponsortypes = str_replace(', ', ',', $settings->sponsorlinktype);
$sponsortypes = explode(',', $sponsortypes);
$t = sizeof($sponsortypes);
for ($x=0; $x<$t; $x++)
{
$thistyperesults = '';
if ($thiscategory->alias > 0) $catid = $thiscategory->alias;
$condition = "catid=$catid AND hide=0 AND validated=1";
if ($settings->condition != '') $condition .= ' AND '. $settings->condition;
$condition .= " AND type = '". $sponsortypes[$x] ."'";
if (strstr($settings->orderlinks, 'case when title >=')) $orderlinks = $settings->orderlinks;
if ($thiscategory->sponsorlinks > 0) $maxsponsorresults = $thiscategory->sponsorlinks; else $maxsponsorresults = $settings->sponsorcatresults;
$linkdata = $db->select($settings->linkfields, 'linkstable', $condition, $orderlinks, 'LIMIT 0,'. $maxsponsorresults);
$v = $db->numrows($linkdata);
// now have all the data for this sponsor type... so, it's time to display it.
$var = $sponsortypes[$x] .'linksbodybase';
$thissponsortemplate = $$var;
$cntr = 0;
for ($a=0; $a<$v; $a++)
{
$thislink = new onelink('row', $db->row($linkdata));
// handle columns and display
if ($a == 0 && $linkcolumns != 0) $thistyperesults = '';
$thistyperesults .= linkreplacements($thissponsortemplate, $thislink);
$cntr++;
if ($cntr == $linkcolumns && $linkcolumns != 0) { $thistyperesults .= ' '; $cntr = 0; }
}
if ($thistyperesults != '' && $linkcolumns != 0) $thistyperesults .= ' ';
$thistyperesults = str_replace($pref .'WIDTH}', $linkwidth, $thistyperesults);
$template->replace('{'. strtoupper($sponsortypes[$x]) .'LINKSBODY}', $thistyperesults);
}
}
if ($settings->mixrecip == 'yes')
{
$reglinksdata = $thiscategory->linkdata();
$columncount = 0;
}
else
{
$reglinksdata = $thiscategory->linkdatabytype();
$columncount = -5000; // get it out of the picture
}
for ($next=$start; ( ($next<$end) && ($next<$total) ); $next++)
{
// get next link
$row = $db->row($reglinksdata);
$thelink = new onelink('row', $row);
$thenum++;
$thelink->number = $thenum;
$typex = strtoupper($thelink->type);
$typel = strtolower($thelink->type);
$counter = $typel . 'count';
$templatename = $typel . 'linksbodybase';
if ($columncount == 0 || ($settings->mixrecip == 'no' && $$counter == 0))
{
if ($next != $start && $linkcolumns != 0) $links = ' '. $$templatename;
else $links = $$templatename;
}
else if ($linkcolumns != 0 && ($columncount == $linkcolumns || ($settings->mixrecip == 'no' && $$counter == $linkcolumns)))
{
$links = ' '. $$templatename;
if ($settings->mixrecip == 'yes') $columncount = 0;
else $$counter = 0;
}
else
{
$links = $$templatename;
}
$columncount++;
$$counter++;
// do replacements for single link
if ($settings->mixrecip == 'yes')
{
$template_linksbody .= linkreplacements($links, $thelink);
}
else
{
$thevar = strtolower($thelink->type) . 'linksbody';
$$thevar .= linkreplacements($links, $thelink);
$$thevar = str_replace($pref .'WIDTH}', $linkwidth, $$thevar);
}
$thetotal++;
}
if ($thetotal<$linkcolumns)
{
if ($settings->mixrecip == 'no') $$thevar = str_replace($pref .'WIDTH}', '', $$thevar);
$template_linksbody = str_replace($pref .'WIDTH}', '', $template_linksbody);
}
else
{
if ($settings->mixrecip == 'no') $$thevar = str_replace($pref .'WIDTH}', $linkwidth, $$thevar);
$template_linksbody = str_replace($pref .'WIDTH}', $linkwidth, $template_linksbody);
}
}
$num = sizeof($listtypes);
// Begin ulsearch integration area
if ($settings->ulsearch == 'yes')
{
$typex = strtoupper($settings->ulsearchlinktype);
if ($settings->linkcols != 0) $ulcontent .= ' ';
$template->replace('{'. $typex .'LINKSBODY}', $ulcontent);
}
// End ulsearch integration area
for ($count=0; $count<$num; $count++)
{
$typex = strtoupper($listtypes[$count]);
$typel = strtolower($typex);
$thevar = $typel . 'linksbody';
if ($settings->mixrecip == 'yes')
{
if ($typex == strtoupper($listdefault))
{
if ($settings->linkcols != 0) $template_linksbody = ''. $template_linksbody .' ';
$template->replace('{'. $typex .'LINKSBODY}', $template_linksbody);
}
else
{
if ($settings->linkcols != 0 && ($thiscategory->linkshere() == 0 || $settings->mixrecip == 'no')) $template->replace('{'. $typex .'LINKSBODY}', ' '); // for standards Nazis when the table is blank
else $template->replace('{'. $typex .'LINKSBODY}', '');
}
}
else
{
$thevar = $typel . 'linksbody';
if ($$thevar == ''&& $settings->linkcols != 0) $$thevar = '';
if (strstr($template->text, '{'. $typex .'LINKSBODY}'))
{
if ($settings->linkcols != 0) $$thevar .= ' ';
$template->replace('{'. $typex . 'LINKSBODY}', $$thevar);
}
// else $template->replace('', $$thevar);
}
}
if ($perpage < 1) $perpage = 1;
if ($settings->apacherewrite == 'yes' || $_GET['html'] == 'yes') $template->text = paginate($template->text, $page, $perpage, $total, 0, 'category', $catid);
else $template->text = paginate($template->text, $page, $perpage, $total);
$template->replace('{REORDER}', $reorder);
$template->replace('{TOTALINCATEGORY}', $total); // total shown in category
$template->replace('{NUMBEROFSUBCATS}', $numsubcats); // total shown in category
$template->replace('{SUBCATEGORIES}', $subcatsbody);
$template->text = categoryreplacements($template->text, $thiscategory);
if (!$thiscategory->canview()) $template = new template("noaccess.tpl");
// Get rid of extraneous link types in template that aren't in settings, to prevent annoying parse errors
$pattern = "";
$pattern = '/'. $pattern .'/i';
preg_match_all($pattern, $template->text, $badtypes);
$template->replace($badtypes[0][0], '');
for ($i=0; $ilinktypes, $badtypes[1][$i]))
{
$problem = $badtypes[1][$i];
$message = "Warning: You have a link type in your template which is not listed in your settings. It is being ignored.";
$message .= "The link type $problem is used in your template, but you only have ". $settings->linktypes ." in your settings. Either add $problem to your settings page or remove it from the template . If you are not the webmaster of this site, please notify the webmaster of this message. ";
if ($debug != 6) echo $message;
$remove = templateextract($template->text, '', $badtypes[0][$i]);
$template->replace($remove, '');
}
}
}
else // no category selected, so display listing of categories
{
$thiscategory = new category('id', '0'); // top level
if (!$template) $template = new template('main.tpl');
$perpage = $settings->catsperpage;
if ($perpage < 1) $perpage = 75;
if ($page < 1 || is_array($page)) $page = 1;
$start = ($page * $perpage) - $perpage;
$end = $start + $perpage;
$catdata = $db->select($settings->categoryfields, 'categoriestable', "parent=0 AND validated=1 AND hide=0 AND isalbum=0", $ordercats, "LIMIT $start,$end");
$numonpage = $db->numrows($catdata);
$totalcats = $thiscategory->numsubcats();
$catsbodybase = templateextract($template->text, '', '');
$subsub = templateextract($catsbodybase, '', '');
$template->replace($catsbodybase, '{CATSBODY}'); // replace with marker
if ($settings->cattypes != '')
{ // formerly strstr($settings->cattypes, ',')
$list = explode(',', $settings->cattypes);
$n = sizeof($list);
for ($q=0; $q<$n; $q++)
{
$var = 'template' . $list[$q];
$$var = templateextract($catsbodybase, '', '');
if ($$var == '') { $tmp = 'template'. $list[0]; $$var = $$tmp; }
$catsbodybase = str_replace($$var, '{'.strtoupper($list[$q]) .'TEMP}', $catsbodybase);
$subvar = $list[$q] . 'subsub';
$$subvar = templateextract($$var, '', '');
$thecount = $list[$q] .'col';
$$thecount = 1;
$tot = $list[$q] .'total';
$$tot = 1;
$avar = $cat->type .'data';
}
for ($currentcat=0; $currentcat<$numonpage; $currentcat++)
{
// get info for this category
$area = $language->title_divider . $language->title_main;
$row = $db->row($catdata);
$cat = new category('row', $row); // the category to list next
if ($cat->type == '') $cat->type = $list[0];
$avar = $cat->type .'data';
$temp = 'template' . $cat->type;
if ($$temp != '') $$avar .= $$temp;
else { $temp = 'template'. $cat->type; $$avar .= $$temp; }
$thecount = $cat->type .'col';
if ($$thecount == 0 && $settings->catcols != 0)
$$avar .= '';
else if ($$thecount == $catcolumns)
{
if ($settings->catcols != 0) $$avar .= ' ';
$$thecount = 0;
}
$$thecount++;
$subvar = $cat->type . 'subsub';
if ($$subvar != '') $$avar = str_replace($$subvar, $cat->subcats($$subvar), $$avar);
$$avar = categoryreplacements($$avar, $cat);
$$avar = categoryreplacements($$avar, $cat); // catch cat vars inside cat vars
$tot = $list[$q] .'total';
$$tot += 1;
$$avar = str_replace('{NUMBER}', $$tot, $$avar);
$letter = ord('a') + ($$tot - 1);
$$avar = str_replace('{LETTER}', chr($letter), $$avar);
$$avar = str_replace('{U_LETTER}', strtoupper(chr($letter)), $$avar);
}
$template_catsbody = $catsbodybase;
$list = explode(',', $settings->cattypes);
$n = sizeof($list);
for ($q=0; $q<$n; $q++)
{
$data = $list[$q] . 'data';
// final
if ($settings->catcols != 0) $$data = ''. $$data .' ';
$template_catsbody = str_replace('{'.strtoupper($list[$q]) .'TEMP}', $$data, $template_catsbody);
}
}
else
{
if ($settings->catcols != 0) $template_catsbody .= '';
$columncount = 1;
for ($currentcat=0; $currentcat<$numonpage; $currentcat++)
{
// get info for this category
$area = $language->title_divider . $language->title_main;
$row = $db->row($catdata);
$cat = new category('row', $row); // the category to list next
// display link to this category
if ($columncount == 0)
{
if ($settings->catcols != 0) $template_catsbody .= ' ';
}
else if ($columncount == $catcolumns)
{
if ($settings->catcols != 0) $template_catsbody .= ' ';
$columncount = 0;
}
$columncount++;
$thiscatbody = categoryreplacements($catsbodybase, $cat);
$thiscatbody = str_replace('{NUMBER}', $currentcat + 1, $thiscatbody);
$template_catsbody .= $thiscatbody;
}
// final
if ($settings->catcols != 0) $template_catsbody .= '';
}
// begin pagination
$template->text = paginate($template->text, $page, $perpage, $totalcats);
$template->replace('{REORDER}', $reorder);
// end pagination
if ($numonpage < $catcolumns)
$template_catsbody = str_replace('{CATWIDTH}', '', $template_catsbody);
else
$template_catsbody = str_replace('{CATWIDTH}', $catwidth, $template_catsbody);
$template->replace('{CATSBODY}', $template_catsbody);
}
// properly select items in cat and links ordering selectors
$template->text = stripslashes($template->text);
$ordering = explode(' ', $ordercats);
// 0: ORDER 1: BY 2: field 3: ASC/DESC
$ourorder = '';
$selectit = ' ';
$template->replace($ourorder, $selectit);
$startord = strpos($template->text, '');
if ($startord)
{
$ourorder = substr($template->text, $startord, 100);
$selectit = str_replace('"'. strtolower($ordering[3]) .'"', '"'. strtolower($ordering[3]) .'" selected', $ourorder);
$template->replace($ourorder, $selectit);
}
if ($action == 'checkowner') $template->text = str_replace('@', ' of ', $settings->email) .', listed '. str_replace('@', ' of ', $settings->accountemail);
$ordering = explode(' ', $realorder);
// 0: order 1: by 2: field 3:ascdesc
$getascdesc = explode(',', $ordering[3]);
$ordering[3] = strtolower($getascdesc[0]);
$ourorder = '';
$selectit = ' ';
$template->replace($ourorder, $selectit);
$startord = strpos($template->text, '');
if ($startord)
{
$ourorder = substr($template->text, $startord, 100);
$selectit = str_replace('"'. $ordering[3] .'"', '"'. $ordering[3] .'" selected', $ourorder);
$template->replace($ourorder, $selectit);
}
$startord = strpos($template->text, '');
if ($startord)
{
$ourorder = substr($template->text, $startord, 100);
$selectit = str_replace('"'. $perpage .'"', '"'. $perpage .'" selected', $ourorder);
$template->replace($ourorder, $selectit);
}
// returnto cookie stuff
if (($action != 'logout') && ($TID != 'blank') && ($action != 'login') && ($action != 'userlogin') && ($action != 'userlogout'))
{
if ($thiscategory)
{
$loc = "index.php?action=displaycat&catid=". $thiscategory->id;
makecookie("returnto", "$loc", time() + 900);
}
else
{
if (($currenturl != '')&&($_SERVER['PHP_SELF'] != '')&&($currenturl != '/?')&&($currenturl != 'http://?')&&($currenturl != 'http:///?'))
makecookie("returnto", "$currenturl", time() + 900);
else
makecookie("returnto", "index.php", time() +900);
}
}
require 'end.php';
?>