public static function while_wall_products($category = array()) { if ($GLOBALS['me']) { global $db; $categories = \site\utils::validate_user_data($category); $where = $limit = $orderby = array(); /** make or not seo links */ $seo_link = defined('SEO_LINKS') && SEO_LINKS ? true : false; list($seo_link_product, $seo_link_store, $seo_link_reviews) = array(\query\main::get_option('seo_link_product'), \query\main::get_option('seo_link_store'), \query\main::get_option('seo_link_reviews')); if (isset($categories['max'])) { if (!empty($categories['max'])) { $limit[] = $categories['max']; } } else { $page = !empty($_GET['page']) ? (int) $_GET['page'] : 1; $per_page = isset($categories['per_page']) ? (int) $categories['per_page'] : \query\main::get_option('items_per_page'); $offset = isset($page) && $page > 1 ? ($page - 1) * $per_page : 0; $limit[] = $offset; $limit[] = $per_page; } /* WHERE / ORDER BY */ $where[] = 'f.user = "******" AND p.visible > 0 AND s.visible > 0'; if (isset($categories['firstchar']) && preg_match('/(^[\\p{L}]{1}$|^0-9$)/', $categories['firstchar'])) { $where[] = 's.name REGEXP "^' . (is_numeric($categories['firstchar'][0]) ? '[0-9]' : \site\utils::dbp($categories['firstchar'])) . '"'; } if (isset($categories['orderby'])) { $order = array_map('trim', explode(',', strtolower($categories['orderby']))); foreach ($order as $v) { switch ($v) { case 'rand': $orderby[] = 'RAND()'; break; case 'date': $orderby[] = 'p.date'; break; case 'date desc': $orderby[] = 'p.date DESC'; break; } } } /* */ $stmt = $db->stmt_init(); $stmt->prepare("SELECT p.id, p.feedID, p.user, p.store, p.category, p.popular, p.title, p.link, p.description, p.tags, p.image, p.price, p.old_price, p.currency, p.visible, p.views, p.start, p.expiration, p.cashback, p.paid_until, p.date, (SELECT COUNT(*) FROM " . DB_TABLE_PREFIX . "reviews WHERE store = s.id AND valid > 0) as votes, (SELECT AVG(stars) FROM " . DB_TABLE_PREFIX . "reviews WHERE store = s.id AND valid > 0) as rating, s.image, s.id, s.name, s.link, s.category FROM " . DB_TABLE_PREFIX . "products p LEFT JOIN " . DB_TABLE_PREFIX . "favorite f ON (f.store = p.store) LEFT JOIN " . DB_TABLE_PREFIX . "stores s ON (s.id = f.store)" . (empty($where) ? '' : ' WHERE ' . implode(' AND ', $where)) . (empty($orderby) ? '' : ' ORDER BY ' . implode(', ', array_filter($orderby))) . (empty($limit) ? '' : ' LIMIT ' . implode(',', $limit))); $stmt->execute(); $stmt->bind_result($id, $feed_id, $user, $store, $cat, $popular, $title, $link, $description, $tags, $image, $price, $old_price, $currency, $visible, $views, $start, $expiration, $cashback, $paid_until, $date, $reviews, $stars, $store_img, $store_id, $store_name, $store_link, $store_cat); $data = array(); while ($stmt->fetch()) { $data[] = (object) array('ID' => $id, 'feedID' => $feed_id, 'userID' => $user, 'storeID' => $store, 'catID' => $cat, 'title' => htmlspecialchars($title), 'url' => filter_var($link, FILTER_VALIDATE_URL) ? htmlspecialchars($link) : htmlspecialchars($store_link), 'description' => $description, 'tags' => htmlspecialchars($tags), 'image' => htmlspecialchars($image), 'price' => $price, 'old_price' => $old_price > 0 && $old_price > $price ? $old_price : 0, 'currency' => htmlspecialchars($currency), 'visible' => $visible, 'views' => $views, 'start_date' => $start, 'is_running' => strtotime($start) < time() && strtotime($expiration) > time() ? true : false, 'expiration_date' => $expiration, 'cashback' => $cashback, 'is_started' => strtotime($start) > time() ? false : true, 'is_expired' => strtotime($expiration) > time() ? false : true, 'paid_until' => $paid_until, 'date' => $date, 'reviews' => $reviews, 'stars' => $stars, 'store_img' => htmlspecialchars($store_img), 'storeID' => $store_id, 'store_catID' => $store_cat, 'store_name' => htmlspecialchars($store_name), 'store_url' => htmlspecialchars($store_link), 'link' => $seo_link ? \site\utils::make_seo_link($seo_link_product, $title, $id) : $GLOBALS['siteURL'] . '?product=' . $id, 'store_link' => $seo_link ? \site\utils::make_seo_link($seo_link_store, $store_name, $store_id) : $GLOBALS['siteURL'] . '?store=' . $store_id, 'store_reviews_link' => $seo_link ? \site\utils::make_seo_link($seo_link_reviews, $store_name, $store_id) : $GLOBALS['siteURL'] . '?reviews=' . $store_id); } $stmt->close(); return $data; } else { return array(); } }
function tlink($place, $q = array(), $backTo = '') { $seo_link = defined('SEO_LINKS') && SEO_LINKS ? true : false; $page = ''; if (preg_match('/([a-z0-9-_.]+)[\\/]([a-z0-9-_.]+)/i', $place, $sl)) { list($place, $page) = array($sl[1], $sl[2]); } if (!empty($backTo)) { if ($backTo == 'this') { $backTo = $_SERVER['REQUEST_URI']; } $q = !empty($q) ? $q . '&backto=' . $backTo : 'backto=' . $backTo; } switch ($place) { case 'index': return $GLOBALS['siteURL']; break; case 'page': return $seo_link ? $GLOBALS['siteURL'] . (!empty($q['seo']) ? $q['seo'] : '') : $GLOBALS['siteURL'] . (!empty($q['notseo']) ? '?' . $q['notseo'] : ''); break; case 'user': return $seo_link ? \site\utils::make_seo_link(\query\main::get_option('seo_link_user')) . $page . '.html' . (!empty($q) ? '?' . (string) $q : '') : $GLOBALS['siteURL'] . '?user='******'&' . (string) $q : ''); break; case 'stores': return $seo_link ? \site\utils::make_seo_link(\query\main::get_option('seo_link_stores')) . (!empty($q) ? '?' . (string) $q : '') : $GLOBALS['siteURL'] . '?stores' . (!empty($q) ? '&' . (string) $q : ''); break; case 'search': return $seo_link ? \site\utils::make_seo_link(\query\main::get_option('seo_link_search')) : $GLOBALS['siteURL']; break; case 'ajax': return $seo_link ? \site\utils::make_seo_link('ajax') . $page . (!empty($q) ? '?' . (string) $q : '') : $GLOBALS['siteURL'] . '?ajax=' . strtok($page, '.') . (!empty($q) ? '&' . (string) $q : ''); break; case 'plugin': return $seo_link ? \site\utils::make_seo_link(\query\main::get_option('seo_link_plugin')) . $page . (!empty($q) ? '?' . (string) $q : '') : $GLOBALS['siteURL'] . '?plugin=' . strtok($page, '.') . (!empty($q) ? '&' . (string) $q : ''); break; case 'tpage': return $seo_link ? $GLOBALS['siteURL'] . $page . '.html' . (!empty($q) ? '?' . (string) $q : '') : $GLOBALS['siteURL'] . '?tpage=' . $page . (!empty($q) ? '&' . (string) $q : ''); break; case 'pay': return $GLOBALS['siteURL'] . 'payment.php' . (!empty($q) ? '?' . (string) $q : ''); break; } }
$coupons = array(); while ($stmt->fetch()) { $coupon_link = $seo_link ? \site\utils::make_seo_link($seo_link_coupon, $c_title, $c_id) : $GLOBALS['siteURL'] . '?id=' . $c_id; $store_link = $seo_link ? \site\utils::make_seo_link($seo_link_store, $s_name, $s_id) : $GLOBALS['siteURL'] . '?store=' . $s_id; $c_expiration = str_replace(' 00:00:00', '', $c_expiration); //build coupon html $coupons['c_' . $c_id] = str_replace(array('{_BANNER_URL_}', '{_BANNER_IMAGE_}', '{_STORE_URL_}', '{_STORE_NAME_}', '{_ITEM_URL_}', '{_ITEM_NAME_}', '{_EXPIRE_TEXT_}'), array($coupon_link, $s_image, $store_link, $s_name, $coupon_link, $c_title, 'Expires on ' . $c_expiration), $template_favitem); } //list product $search_products = "SELECT p.id, p.title, p.link, p.description, p.tags, p.image, p.currency, p.price, p.old_price, s.name, s.link, s.id, p.expiration FROM " . DB_TABLE_PREFIX . "products p LEFT JOIN " . DB_TABLE_PREFIX . "stores s ON (s.id = p.store) WHERE p.visible > 0 AND s.visible > 0 AND p.expiration > '" . $now . "' and p.store = " . $store; $stmt->prepare($search_products); $stmt->execute(); $stmt->bind_result($p_id, $p_title, $p_link, $p_description, $p_tags, $p_image, $p_currency, $p_price, $p_old_price, $s_name, $s_link, $s_id, $p_expiration); while ($stmt->fetch()) { $product_link = $seo_link ? \site\utils::make_seo_link($seo_link_product, $p_title, $p_id) : $GLOBALS['siteURL'] . '?product=' . $p_id; $store_link = $seo_link ? \site\utils::make_seo_link($seo_link_store, $s_name, $s_id) : $GLOBALS['siteURL'] . '?store=' . $s_id; $p_expiration = str_replace(' 00:00:00', '', $p_expiration); //build coupon html $coupons['p_' . $p_id] = str_replace(array('{_BANNER_URL_}', '{_BANNER_IMAGE_}', '{_STORE_URL_}', '{_STORE_NAME_}', '{_ITEM_URL_}', '{_ITEM_NAME_}', '{_EXPIRE_TEXT_}', '{_NOW_PRICE_}', '{_OLD_PRICE_}'), array($product_link, $p_image, $store_link, $s_name, $product_link, $p_title, 'Expires on ' . $p_expiration, $p_currency . $p_price, $p_currency . $p_old_price), $template_favsale); } $coupondata[$store] = $coupons; } foreach ($coupondata[$store] as $coupon_content) { $strfav .= $coupon_content; } } if ($strfav == '') { $strnofav = $template_nofav; } else { $strfav = str_replace($fav_anchor, $strfav, $template_fav); }