authorizenet) { require 'includes/authnetsdk.php'; }
if ($scriptinfo['scriptname'] != 'wsnlinks' && !$action) $action = 'detail';
if (!$id && $linktitle) $id = $db->selectitem('id', 'linkstable', "title='".encodeit(unrewritetitle($linktitle))."' AND deleted=0");
if ($id > 0)
{
$thislink = new onelink('id', $id); // get for frequent later use
if (!$action && $thislink->url == '' && $action != 'sponsor') $action = 'detail'; // if no url, don't try to go to it
if ($todo == 'clearbookmarkedattachments') { $thislink->bookmarkattachments = ''; $thislink->update('bookmarkattachments'); header("Location: ".str_replace("&todo=clearbookmarkedattachments", "", currenturl())); } // redirect to avoid having a refresh re-clear it
if ($thislink->catid > 0)
{
if (!$thislink->cat->canview())
{
if (tweakisset('hidebadrequest')) endwithbadrequest();
else { $template = new template("noaccess.tpl"); require 'end.php'; die(); }
}
}
}
if (!$id && !$orderid && !$catid && !$action) redirect($language->nosuchlink, 'index.php');
if ($switches['linkcalendars'])
{
require 'includes/eventfunctions.php';
if (isset($_REQUEST['monthID']) && $id)
{ // check if we have quantities to update
reset($_REQUEST);
while(list($key, $value) = each($_REQUEST))
{
if (strstr($key, '-') && !strstr($key, 'price'))
{ // db date format: Jun 20, 2011. quantity field names: 2012-10-05
$timestamp = strtotime($key);
$formated = strftime("%b %d, %Y", $timestamp);
if ($db->hascount('calendartable', "date='$formated' AND objectid='{$id}'")) $db->update('calendartable', 'quantity', $value, "date='$formated' AND objectid='{$id}'");
else if ($value != $thislink->defaulteventquantity)
{ // make new event
$e = new event('new', 'new');
$e->quantity = $value;
$e->date = $formated;
$e->objectid = $id;
$e->validated = 1;
$e->starttime = strtotime("$formated 12:00 AM");
$e->endtime = strtotime("$formated 11:59 PM");
$e->add();
}
}
if (strstr($key, '-') && strstr($key, 'price'))
{ // db date format: Jun 20, 2011. price field names: price2012-10-05
$datestuff = str_replace('price', '', $key);
$timestamp = strtotime($datestuff);
$formated = strftime("%b %d, %Y", $timestamp);
if ($db->hascount('calendartable', "date='$formated' AND objectid='{$id}'")) $db->update('calendartable', 'price', $value, "date='$formated' AND objectid='{$id}'");
else if ($value != $thislink->price)
{ // make new event
$e = new event('new', 'new');
$e->price = $value;
if ($_POST[$datestuff]) $e->quantity = $_POST[$datestuff];
else $e->quantity = $thislink->defaulteventquantity;
$e->date = $formated;
$e->objectid = $id;
$e->validated = 1;
$e->starttime = strtotime("$formated 12:00 AM");
$e->endtime = strtotime("$formated 11:59 PM");
$e->add();
}
}
}
}
}
if ($filled)
{
if ($action == 'addtags')
{
if ($thismember->isregistered()) $usedtags = $db->selectcount('tagstable', 'ownerid='.$thismember->id.' AND deleted=0 AND link='.$thislink->id);
else $usedtags = $db->selectcount('tagstable', "ownerip='".realip()."' AND deleted=0 AND link=".$thislink->id);
$newtags = explode(',', str_replace(', ', ',', $newtags));
$n = count($newtags);
for ($x=0; $x<$n; $x++)
{
if (!$thismember->grouplimittags || $usedtags < $thismember->grouplimittags)
{
$t = new tag($newtags[$x], $thislink, $thismember->id);
if ($name != '' && !$db->hascount('tagstable', "name='". encodeit($newtags[$x]) ."' AND link=". $thislink->id)) { $t->add(); $usedtags++; } // only add unique tags
}
}
redirect("", $returnurl, true);
}
elseif ($action == 'deletetag')
{
$tag = urldecode($_GET['tag']);
$t = new tag($tag, $thislink, $thismember->id);
if ($t->candelete()) $t->deletethis();
$returnurl = urldecode($_GET['returnurl']);
redirect("", $returnurl, true);
}
elseif ($action == 'sponsor')
{ // process unpaid sponsorship which can be renewed at will by clicking
$thislink->sponsorend = time() + (86400 * $settings->sponsortime);
$thislink->type = $sponsordata->linktypesarr[0]; // only one level allowed for unpaid sponsorship
$thislink->update('type,sponsorend');
$message = $language->sponsor_done;
$destination = $thislink->detailsurl();
redirect($message, $destination);
}
}
else
{
if ($action == 'preview')
{ // link.php?action=preview
$previewing = true; // flag that doattachments checks
if ($switches['detailcomments']) { if (!$template) $template = new template('detailcomments.tpl'); }
else { if (!$template) $template = new template('details.tpl'); }
$thislink = new onelink('blank', 'blank');
$previewid = 'temp/preview_'.str_replace('.', '', realip()).'.wsn';
$tempdata = explode('[|||]', fileread($previewid));
foreach($tempdata as $td)
{
$parts = explode('[=]', $td);
$key = $parts[0];
$value = $parts[1];
$thislink->$key = $value;
}
if (!$thislink->ownerid) $thislink->ownerid = 0; // so toplist of latest listings by member gets a 0 in it properly
$thislink->objectfieldarray = explode(',', $thislink->objectfields);
expandspecialfields($thislink);
$thislink->codesandsmilies();
$thislink->makecat();
$thislink->parentnames = $thislink->cat->parentnames;
$thislink->parentids = $thislink->cat->parentids;
if ($thislink->id > 0) $cond = "type='link' AND objectid={$thislink->id}";
else $cond = "type='link' AND objectid=0 AND ownerip='".realip()."'";
$thislink->numattachments = $db->selectcount('attachmentstable', $cond);
if ($thislink->numattachments) $thislink->filefield = 1; else $thislink->filefield = 0;
$template->replace('{LINKFILEFIELD}', $thislink->filefield); // no idea why this is necessary here but it is!
if (!$thislink->id) $thislink->id = 0;
if (!$thislink->latitude && !$thislink->longitude)
{
// need to do geofromaddr only if no manual specification. but lat/lon could be filled on preview edit for non-manual specification. how does that logic work? i think it worked itself out now actually since the map always resets itself when the address changes?
$thislink->latitude = 0; $thislink->longitude = 0; $thislink->numcomments = 0; $thislink->pagerank = 0;
if ($switches['map'] && ($thislink->address || ($thislink->zip && tweakisset('geocodezip')))) { $arr = geofromaddr($thislink); $thislink->latitude = $arr[0]; $thislink->longitude = $arr[1]; }
if (!$thislink->latitude) $thislink->latitude = 0;
if (!$thislink->longitude) $thislink->longitude = 0;
}
if ($thislink->feedurl == 'http://') $thislink->feedurl = '';
if ($thislink->url == 'http://') $thislink->url = '';
$template->replacements($thislink);
$com = new comment('blank', 'blank');
$template->replacements($com); // in case it's the detailcomments template
$template->replace($template->extract('', ''), '');
$template->replace('{PAGINATION}', '');
$template->shownav($thislink->navpath(), $thislink->title);
$template->replace(' href=', ' disabled='); // disable links
$pat = preg_quote(''); // but, allow tab/activetab links while changing action=detail to action=preview
$pat = '/'.$pat.'/i';
$template->text = preg_replace($pat, '', $template->text);
$template->replace('disabled="'.$thislink->detailsurl().'"', 'href="link.php?action=preview"');
$template->replace('