1.1 * * 2006-12-06 v1.1 Added .php support and title extraction from h1, h2 tags * */ require_once('config.php'); require_once(PATH_INCLUDE . 'header.php'); // Fetch the top #1 site for the leaderboard (if enabled) $leader_link = ''; if($cfg->getVar('link_leader') == 1) { $sql = 'SELECT ' . TBL_LINKS . '.*, ' . TBL_BIDS . '.bid_amount, SUM(' . TBL_BIDS . '.bid_amount) as bid_amount FROM ' . TBL_LINKS . ' LEFT JOIN ' . TBL_BIDS . ' ON ' . TBL_BIDS . '.link_id = ' . TBL_LINKS . '.link_id WHERE bid_amount > 0 GROUP BY link_id ORDER BY bid_amount DESC LIMIT 1'; if(($rs = $db->execute($sql)) && (!$rs->EOF)) { $leader_link = '
' . $rs->fields['link_title'] .'
Link leader at $' . $rs->fields['bid_amount'] . '
'; } } $tpl->assign('leader_link', $leader_link); if(!empty($_REQUEST['id'])) { $tpl->assign('linkstyle', 'link2'); $cats = 'abcdefghijklmnopqrstuvwxyz09'; if($_REQUEST['id'] == '09') { $sql_like = '(link_title LIKE "0%" ' . 'OR link_title LIKE "1%" ' . 'OR link_title LIKE "2%" ' . 'OR link_title LIKE "3%" ' . 'OR link_title LIKE "4%" ' . 'OR link_title LIKE "5%" ' . 'OR link_title LIKE "6%" ' . 'OR link_title LIKE "7%" ' . 'OR link_title LIKE "8%" ' . 'OR link_title LIKE "9%")'; } else { $sql_like = 'link_title LIKE "' . $_REQUEST['id'] . '%"'; } // Check for a link category request if(strpos($cats, $_REQUEST['id']) !== false) { if($_REQUEST['id'] == '09') { $_REQUEST['id'] = '0-9'; } $cat_title = strtoupper($_REQUEST['id']); $tpl->define('heading', '

' . $cat_title . '

', 1); $tpl->parse('heading'); $cfg->setVar('page_title', $cfg->getVar('site_name') . ': Links in ' . $cat_title); $tpl->define('links', 'links.tpl'); $tpl->define_d('link_row', 'links'); $tpl->define_d('nolink_row', 'links'); $tpl->parse('links'); // Get link totals for pages $rs_limit = $cfg->getVar('links_per_page'); $rs_pages = 0; $sql = 'SELECT ' . TBL_LINKS . '.link_id, ' . TBL_BIDS . '.bid_amount, SUM(' . TBL_BIDS . '.bid_amount) as bid_amount FROM ' . TBL_LINKS . ' LEFT JOIN ' . TBL_BIDS . ' ON ' . TBL_BIDS . '.link_id = ' . TBL_LINKS . '.link_id WHERE bid_amount > 0 AND ' . $sql_like . ' GROUP BY link_id ORDER BY bid_amount DESC'; if(($rs = $db->execute($sql)) && (!$rs->EOF)) { $rs_total = $rs->NumRows(); if($rs_total >= $rs_limit) { $rs_pages = ceil($rs_total/$rs_limit); } else { $rs_pages = 1; } } if(!empty($_REQUEST['page'])) { $rs_page = intval($_REQUEST['page']); $rs_offset = $cfg->getVar('links_per_page') * ($rs_page - 1); } else { $rs_page = 1; $rs_offset = 0; } $pager = '' . ''; if($rs_page > 1) { $pager .= ''; if($rs_page == 2) { $pager .= ''; } else { $pager .= ''; } } for($i=1;$i<=$rs_pages;$i++) { if($i == $rs_page) { $pager .= ''; } else { if($i == 1) { $pager .= ''; } else { $pager .= ''; } } } if($rs_pages > $rs_page) { $pager .= ''; $pager .= ''; } $pager .= '
Page ' . $rs_page . ' of ' . $rs_pages . '' . $i . '
'; $sql = 'SELECT ' . TBL_LINKS . '.*, ' . TBL_BIDS . '.bid_amount, SUM(' . TBL_BIDS . '.bid_amount) as bid_amount FROM ' . TBL_LINKS . ' LEFT JOIN ' . TBL_BIDS . ' ON ' . TBL_BIDS . '.link_id = ' . TBL_LINKS . '.link_id WHERE bid_amount > 0 AND ' . $sql_like . ' GROUP BY link_id ORDER BY bid_amount DESC LIMIT ' . $rs_offset . ', ' . $rs_limit; if(($rs = $db->execute($sql)) && (!$rs->EOF)) { while(!$rs->EOF) { $tpl->assign_array_d('link_row', $rs->fields, 1); $tpl->parse_d('link_row'); $rs->MoveNext(); } $tpl->define('pager', $pager, 1); $tpl->parse('pager'); } else { $tpl->parse_d('nolink_row'); } } else { $sql = 'SELECT * FROM ' . TBL_PAGES . ' WHERE pg_safename = "' . $_REQUEST['id'] . '"'; if(($rs = $db->execute($sql)) && (!$rs->EOF)) { $cfg->setVar('page_title', $rs->fields['pg_title']); $rs->fields['pg_contents'] = replaceCommonVars($rs->fields['pg_contents']); $tpl->define('page', $rs->fields['pg_contents'], 1); $tpl->parse('page'); } elseif(file_exists(PATH_CONTENT . $_REQUEST['id'] . '.html')) { $fcontents = read_file(PATH_CONTENT . $_REQUEST['id'] . '.html'); $ftitle = get_middle($fcontents, '

', '

'); if($ftitle) { $cfg->setVar('page_title', $ftitle); } $tpl->define('page', $fcontents, true); $tpl->parse('page'); } elseif(file_exists(PATH_CONTENT . $_REQUEST['id'] . '.php')) { include(PATH_CONTENT . $_REQUEST['id'] . '.php'); } else { $tpl->define('page', 'error404.tpl'); $tpl->parse('page'); } } } elseif(!empty($_REQUEST['link'])) { $tpl->assign('linkstyle', 'link2'); if((!empty($_REQUEST['business'])) && (!empty($_REQUEST['payer_email'])) && (!empty($_REQUEST['payment_gross'])) && (!empty($_REQUEST['payment_date'])) && (!empty($_REQUEST['item_name']))) { $link_id = intval($_REQUEST['link']); if($_REQUEST['business'] == $cfg->getVar('paypal_email')) { $ret_url = $_REQUEST['item_name']; $ret_url = str_replace('Bid for ', '', $ret_url); $ret_url = substr($ret_url, 0, strpos($ret_url, 'on ' . $cfg->getVar('site_name'))); $ret_url = trim($ret_url); $bid_message = '

Thank you for your bid. Your bid has been successfully placed, and a confirmation email has been sent to ' . $_REQUEST['payer_email'] . '. Please review your link status at the following URL:

'; $bid_message .= '

' . $cfg->getVar('site_url') . 'link/' . $link_id . '.html

'; $html = '

Bid Placed

' . $bid_message; $tpl->define('message', $html, 1); $tpl->parse('message'); } } else { $sql = 'SELECT ' . TBL_LINKS . '.*, SUM(' . TBL_BIDS . '.bid_amount) as bid_amount FROM ' . TBL_LINKS . ' LEFT JOIN ' . TBL_BIDS . ' ON ' . TBL_BIDS . '.link_id = ' . TBL_LINKS . '.link_id WHERE ' . TBL_LINKS . '.link_id = ' . $_REQUEST['link'] . ' GROUP BY link_id'; if(($rs = $db->execute($sql)) && (!$rs->EOF)) { $cfg->setVar('page_title', $cfg->getVar('site_name') . ' - ' . $rs->fields['link_url']); // Display link details $tpl->define('link', 'link.tpl'); $tpl->parse('link'); $last_bid_date = 'Never'; if(empty($rs->fields['bid_amount'])) { $rs->fields['bid_amount'] = 0; } else { $sql = 'SELECT datecreated FROM ' . TBL_BIDS . ' WHERE link_id = ' . $rs->fields['link_id'] . ' ORDER BY bid_amount DESC LIMIT 1'; if(($rs2 = $db->execute($sql)) && (!$rs2->EOF)) { $last_bid_date = date($cfg->getVar('date_format'), dbtime_to_unix($rs2->fields['datecreated'])); } } $rs->fields['datecreated'] = date($cfg->getVar('date_format'), dbtime_to_unix($rs->fields['datecreated'])); $tpl->assign_array($rs->fields, 1); $tpl->assign('last_bid_date', $last_bid_date); if((!empty($_REQUEST['bid'])) && (is_numeric($_REQUEST['bid']))) { $bid_default = intval($_REQUEST['bid']); } else { $bid_default = 1; } // Display form $tos_select = array('agree' => 'I Agree', 'disagree' => 'I Disagree'); $kForm = new kForm(DIR_BASE . 'link/' . $rs->fields['link_id'] . '.html', 'post'); $kForm->addCurrency('Bid Amount', 'amount', $bid_default, 3, 4); // $kForm->addText('Coupon Code (If you have a coupon code, enter it here)', 'coupon_code', '', 15,32); $kForm->addSelect('Please read and agree to the Terms of Service.', 'bid_tos', $tos_select, 'disagree'); $kForm->addHidden('link_id'); $kForm->addRule('amount', 'bid'); $kForm->addRule('bid_tos', 'agree'); if(empty($rs->fields['bid_amount'])) { $kForm->heading = '
Your link has been created but will not be listed until you place a bid!
'; $kForm->title = 'Activate Your Link'; } else { $kForm->heading = 'Your bid will be added on to the current bid for this link.'; $kForm->title = 'Add New Bid'; } $kForm->addHidden('a'); $kForm->addSubmit('Pay Now >>'); if((!empty($_REQUEST['a'])) && ($_REQUEST['a'] == 'submit')) { if(!$kForm->validate($_POST)) { $kForm->renderForm($_POST); } else { $tpl->assign('amount', $_REQUEST['amount']); $tpl->assign('pay_title', $kForm->title); if($cfg->getVar('paypal_ipn_enable') == 1) { $tpl->assign('paypal_ipn_url', $cfg->getVar('site_url') . 'ipn.php'); } $tpl->define('bid', 'bid.tpl'); $tpl->parse('bid'); } } else { $kForm->renderForm(array('link_id' => $_REQUEST['link'], 'amount' => $bid_default, 'a' => 'submit')); } } else { header('Location:' . DIR_BASE); } } } else { $tpl->assign('linkstyle', 'link1'); $cfg->setVar('page_title', $cfg->getVar('site_title')); $tpl->define('heading', '

Top ' . $cfg->getVar('top_count') . ' Links

', 1); $tpl->parse('heading'); $tpl->define('links', 'links.tpl'); $tpl->define_d('link_row', 'links'); $tpl->define_d('nolink_row', 'links'); $tpl->parse('links'); $sql = 'SELECT ' . TBL_LINKS . '.*, ' . TBL_BIDS . '.bid_amount, SUM(' . TBL_BIDS . '.bid_amount) as bid_amount FROM ' . TBL_LINKS . ' LEFT JOIN ' . TBL_BIDS . ' ON ' . TBL_BIDS . '.link_id = ' . TBL_LINKS . '.link_id WHERE bid_amount > 0 GROUP BY link_id ORDER BY bid_amount DESC LIMIT ' . $cfg->getVar('top_count'); if(($rs = $db->execute($sql)) && (!$rs->EOF)) { while(!$rs->EOF) { $tpl->assign_array_d('link_row', $rs->fields, 1); $tpl->parse_d('link_row'); $rs->MoveNext(); } } $html = file_get_contents(PATH_CONTENT . 'index.html'); $tpl->define('buylink', $html, 1); $tpl->parse('buylink'); } require_once(PATH_INCLUDE . 'footer.php'); $tpl->render_all(); ?>