} else { if (isset($type) && $type == 'agency') { echo '<a class="bsaProItem__url" href="' . $agency_form . (strpos($agency_form, '?') ? '&' : '?') . 'bsa_pro_id=' . $ad['id'] . '&bsa_pro_url=1" target="_blank">'; } else { echo '<a class="bsaProItem__url" href="' . get_site_url() . (strpos(get_site_url(), '?') ? '&' : '?') . 'bsa_pro_id=' . $ad['id'] . '&bsa_pro_url=1" target="_blank">'; } } } else { echo '<a href="#">'; } echo '<div class="bsaProItemInner" style="background-color:' . bsa_space($sid, 'ad_bg') . '">'; // -- START -- ITEM INNER echo '<div class="bsaProItemInner__thumb">'; // -- START -- ITEM THUMB echo '<div class="bsaProItemInner__thumbBg" style="background-color:' . bsa_space($sid, 'ad_extra_color_1') . '"></div>'; echo '<div class="bsaProItemInner__img" style="background-image: url('' . bsa_crop_tool($crop, !isset($sid) && !isset($_POST['bsa_ad_id']) || isset($example) ? $ad['img'] : bsa_upload_url() . $ad['img'], 400, 300) . '')"></div>'; // -- ITEM -- IMG echo '</div>'; // -- END -- ITEM THUMB echo '<div class="bsaProItemInner__copy">'; // -- START -- ITEM COPY echo '<div class="bsaProItemInner__copyInner">'; // -- START -- ITEM COPY INNER if ($ad['url'] != '' && $ad['url'] != '#') { echo '<span class="bsaProItemInner__url" style="color:' . bsa_space($sid, 'ad_url_color') . '">http://' . $url['host'] . '</span>'; // -- ITEM -- URL } echo '<span class="bsaProItemInner__line"></span>'; // -- ITEM -- LINE echo '<h3 class="bsaProItemInner__title" style="color:' . bsa_space($sid, 'ad_title_color') . '">' . $ad['title'] . '</h3>'; // -- ITEM -- TITLE
if (count($getLastAds) > 0) { foreach ($getLastAds as $key => $entry) { if ($key % 2) { $alternate = ''; } else { $alternate = 'alternate'; } ?> <tr class="<?php echo $alternate; ?> "> <td class="bsaAdminImg"> <img class="bsaAdminThumb" src="<?php echo $entry['img'] != '' ? bsa_upload_url() . $entry['img'] : plugins_url('/bsa-pro-scripteo/frontend/img/example.png'); ?> "> </td> <td class="post-title page-title column-title"> <strong><a href="<?php echo $entry['url']; ?> "><?php echo $entry['title']; ?> </a></strong> <?php echo $entry['description'] != '' ? $entry['description'] : ''; ?> <?php
function bsaAddNewAd() { $plugin_id = 'bsa_pro_plugin_'; if ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["bsaProAction"] == 'updateAd') { if (isset($_SESSION['bsa_ad_' . $_GET['ad_id']])) { unset($_SESSION['bsa_ad_' . $_GET['ad_id']]); // Reset cache } // validate form foreach (explode(',', str_replace('desc', 'description', $_POST['inputs_required'])) as $input) { $error = FALSE; if ($input == 'img') { if ($_FILES['img']["name"] == '') { $error = FALSE; // img not required for updateAd Action } } else { if ($_POST[$input] == '') { $error = TRUE; } } if ($error == TRUE) { echo ' <div class="updated settings-error"> <p><strong>Ad not saved.</strong> The ' . str_replace(',', ', ', str_replace('desc', 'description', $_POST['inputs_required'])) . ' fields are required!</p> </div>'; return; } } if ($_POST["buyer_email"] != '') { // if isset img $uploadName = strtolower($_FILES["img"]["name"]); if ($uploadName) { $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $uploadName); $extension = end($temp); $fileName = NULL; if (($_FILES["img"]["type"] == "image/gif" || $_FILES["img"]["type"] == "image/jpeg" || $_FILES["img"]["type"] == "image/jpg" || $_FILES["img"]["type"] == "image/pjpeg" || $_FILES["img"]["type"] == "image/x-png" || $_FILES["img"]["type"] == "image/png") && $_FILES["img"]["error"] == 0 && in_array($extension, $allowedExts)) { $fileName = time() . '-' . $uploadName; $path = bsa_upload_url('basedir') . $fileName; $thumbLoc = $_FILES["img"]["tmp_name"]; list($width, $height) = getimagesize($thumbLoc); $maxSize = get_option($plugin_id . 'thumb_size'); $maxWidth = get_option($plugin_id . 'thumb_w'); $maxHeight = get_option($plugin_id . 'thumb_h'); if ($_FILES["img"]["size"] > $maxSize * 1024 or $width > $maxWidth or $height > $maxHeight) { echo ' <div class="updated settings-error"> <p><strong>Ad not saved.</strong> Images was too high.</p> </div>'; return; } else { // save img move_uploaded_file($thumbLoc, $path); } } else { echo ' <div class="updated settings-error"> <p><strong>Ad not saved.</strong> Type of image invalid.</p> </div> '; return; } } else { $fileName = NULL; } $limit = bsa_ad($_GET['ad_id'], 'ad_limit'); if (isset($_POST["increase_limit"]) && $_POST["increase_limit"] != '') { if ($_POST["increase_limit"] > 0 || $_POST["increase_limit"] < 0) { // increase / decrease limit if (bsa_ad($_GET['ad_id'], 'ad_model') == 'cpd') { $time = time(); $increase = $_POST["increase_limit"] * 24 * 60 * 60; $diff = $limit - $time; $increase_limit = $diff <= 0 ? $time + $increase : $limit + $increase; } else { $increase_limit = $limit + $_POST["increase_limit"]; } } else { $increase_limit = bsa_ad($_GET['ad_id'], 'ad_limit'); } } else { $increase_limit = null; } // var_dump(stripslashes( wp_filter_post_kses( addslashes( $_POST["html"] ) ) )); if (bsa_role() == 'user') { $status = get_option('bsa_pro_plugin_auto_accept') == 'no' ? 'pending' : null; $increase_limit = null; } else { $status = null; } $capping = $_POST["capping"] > 0 ? number_format($_POST["capping"], 0, '', '') : 0; $model = new BSA_PRO_Model(); $model->updateAd($_GET['ad_id'], $_POST["buyer_email"], $_POST["title"], $_POST["description"], $_POST["url"], $fileName, stripslashes($_POST["html"]), $capping, $increase_limit, $status); unset($_SESSION['bsa_ad_' . $_GET['ad_id']]); // Reset cache echo ' <div class="updated settings-error"> <p><strong>Success!</strong> Ad saved.</p> </div>'; } else { echo ' <div class="updated settings-error"> <p><strong>Ad not saved.</strong> The buyer email field is required!</p> </div>'; } } elseif ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["bsaProAction"] == 'addNewAd') { // validate form foreach (explode(',', str_replace('desc', 'description', $_POST['inputs_required'])) as $input) { $error = FALSE; if ($input == 'img') { if ($_FILES['img']["name"] == '') { $error = TRUE; } } else { if ($_POST[$input] == '') { $error = TRUE; } } if ($error == TRUE) { echo ' <div class="updated settings-error"> <p><strong>Ad not saved.</strong> The ' . str_replace(',', ', ', str_replace('desc', 'description', $_POST['inputs_required'])) . ' fields are required!</p> </div>'; return; } } if (isset($_POST["buyer_email"]) && $_POST["buyer_email"] != '' && isset($_POST["space_id"]) && $_POST["space_id"] != '' && isset($_POST["ad_model"]) && $_POST["ad_model"] != '' && isset($_POST["ad_limit_" . $_POST["ad_model"]]) && $_POST["ad_limit_" . $_POST["ad_model"]] != '') { // if isset img if ($_FILES['img']["name"]) { $allowedExts = array("gif", "jpeg", "jpg", "png", "GIF", "JPEG", "JPG", "PNG"); $temp = explode(".", $_FILES["img"]["name"]); $extension = end($temp); $fileName = NULL; if (($_FILES["img"]["type"] == "image/gif" || $_FILES["img"]["type"] == "image/jpeg" || $_FILES["img"]["type"] == "image/jpg" || $_FILES["img"]["type"] == "image/pjpeg" || $_FILES["img"]["type"] == "image/x-png" || $_FILES["img"]["type"] == "image/png") && $_FILES["img"]["error"] == 0 && in_array($extension, $allowedExts)) { $fileName = time() . '-' . $_FILES["img"]["name"]; $path = bsa_upload_url('basedir') . $fileName; $thumbLoc = $_FILES["img"]["tmp_name"]; list($width, $height) = getimagesize($thumbLoc); $maxSize = get_option($plugin_id . 'thumb_size'); $maxWidth = get_option($plugin_id . 'thumb_w'); $maxHeight = get_option($plugin_id . 'thumb_h'); if ($_FILES["img"]["size"] > $maxSize * 1024 or $width > $maxWidth or $height > $maxHeight) { echo ' <div class="updated settings-error"> <p><strong>Ad not saved.</strong> Images was too high.</p> </div>'; return; } else { // save img move_uploaded_file($thumbLoc, $path); } } else { echo ' <div class="updated settings-error"> <p><strong>Ad not saved.</strong> Type of image invalid.</p> </div> '; return; } } else { $fileName = ''; } // set limit for cpd - change days to timestamp if ($_POST["ad_model"] == 'cpd') { $ad_limit = time() + $_POST["ad_limit_" . $_POST["ad_model"]] * 24 * 60 * 60; } else { $ad_limit = $_POST["ad_limit_" . $_POST["ad_model"]]; } $model = new BSA_PRO_Model(); if (bsa_role() == 'user') { $status = get_option('bsa_pro_plugin_auto_accept') == 'no' ? 'pending' : 'active'; } else { $status = 'active'; } $capping = $_POST["capping"] > 0 ? number_format($_POST["capping"], 0, '', '') : 0; $model->addNewAd(NULL, $_POST["space_id"], $_POST["buyer_email"], $_POST["title"], $_POST["description"], $_POST["url"], $fileName, stripslashes($_POST["html"]), $capping, $_POST["ad_model"], $ad_limit, 0.0, 2, $status); // paid 2 - Added via Admin Panel $_SESSION['bsa_ad_status'] = 'ad_added'; echo ' <div class="updated settings-error"> <p><strong>Success!</strong> Ad saved.</p> </div>'; } else { echo ' <div class="updated settings-error"> <p><strong>Ad not saved.</strong> The buyer email, space id, billing model fields are required!</p> </div>'; } } }
public function getForm($agency = null, $sid = null) { $plugin_id = 'bsa_pro_plugin_'; if ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["bsaProAction"] == 'buyNewAd') { // validate form foreach (explode(',', str_replace('desc', 'description', $_POST['inputs_required'])) as $input) { $error = FALSE; if ($input == 'img') { if ($_FILES['img']["name"] == '') { $error = TRUE; } } else { if ($_POST[$input] == '') { $error = TRUE; } } if ($error == TRUE) { return 'fieldsRequired'; // return error if some input empty } } if (isset($_POST["buyer_email"]) && $_POST["buyer_email"] != '' && isset($_POST["space_id"]) && $_POST["space_id"] != '' && isset($_POST["ad_model"]) && $_POST["ad_model"] != '' && isset($_POST["ad_limit_" . $_POST["ad_model"]]) && $_POST["ad_limit_" . $_POST["ad_model"]] != '') { $decode_dates = json_decode($this->getUnavailableDates(), true); if (bsa_space($_POST["space_id"], 'max_items') == 1 && get_option('bsa_pro_plugin_calendar') == 'yes' && isset($_POST['calendar']) && in_array($_POST['calendar'], $decode_dates[$_POST["space_id"]]) === true) { return 'fieldsRequired'; // return error if empty calendar input } $val = false; $val = apply_filters("bsa-pro-getFormValidation", $val, $_POST["ad_model"]); if ($_POST["ad_model"] == 'cpc' || $_POST["ad_model"] == 'cpm' || $_POST["ad_model"] == 'cpd' || $val) { // if isset img if ($_FILES['img']["name"]) { $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["img"]["name"]); $extension = end($temp); $fileName = NULL; if (($_FILES["img"]["type"] == "image/gif" || $_FILES["img"]["type"] == "image/jpeg" || $_FILES["img"]["type"] == "image/jpg" || $_FILES["img"]["type"] == "image/pjpeg" || $_FILES["img"]["type"] == "image/x-png" || $_FILES["img"]["type"] == "image/png") && $_FILES["img"]["error"] == 0 && in_array($extension, $allowedExts)) { $fileName = time() . '-' . $_FILES["img"]["name"]; $path = bsa_upload_url('basedir') . $fileName; $thumbLoc = $_FILES["img"]["tmp_name"]; list($width, $height) = getimagesize($thumbLoc); $maxSize = get_option($plugin_id . 'thumb_size'); $maxWidth = get_option($plugin_id . 'thumb_w'); $maxHeight = get_option($plugin_id . 'thumb_h'); if ($_FILES["img"]["size"] > $maxSize * 1024 or $width > $maxWidth or $height > $maxHeight) { return 'invalidSizeFile'; // return error if to big } else { // save img move_uploaded_file($thumbLoc, $path); } } else { return 'invalidFile'; // return error if type of img incorrect } } else { $fileName = ''; } // set limit for cpd - change days to timestamp if ($_POST["ad_model"] == 'cpd') { $ad_limit = time() + $_POST["ad_limit_" . $_POST["ad_model"]] * 24 * 60 * 60; } else { $ad_limit = $_POST["ad_limit_" . $_POST["ad_model"]]; } // valid contracts $contract = NULL; if (bsa_space($_POST["space_id"], $_POST["ad_model"] . '_contract_1') == $_POST["ad_limit_" . $_POST["ad_model"]]) { $contract = '1'; } elseif (bsa_space($_POST["space_id"], $_POST["ad_model"] . '_contract_2') == $_POST["ad_limit_" . $_POST["ad_model"]]) { $contract = '2'; } elseif (bsa_space($_POST["space_id"], $_POST["ad_model"] . '_contract_3') == $_POST["ad_limit_" . $_POST["ad_model"]]) { $contract = '3'; } $contract = apply_filters("bsa-pro-setContract", $contract, $_POST); $validation = true; $validation = apply_filters("bsa-pro-addAdValidation", $validation, $_POST); if ($contract !== NULL && $validation) { $price = bsa_space($_POST["space_id"], $_POST["ad_model"] . '_price') * ($_POST["ad_limit_" . $_POST["ad_model"]] / bsa_space($_POST["space_id"], $_POST["ad_model"] . '_contract_1')); if ($contract > 1) { $discount = bsa_space($_POST["space_id"], 'discount_' . $contract) > 0 ? $price * (bsa_space($_POST["space_id"], 'discount_' . $contract) / 100) : 0; } else { $discount = 0; } $cost = $price - $discount; $cost = apply_filters("bsa-pro-setCost", $cost, $_POST, $contract); $paid = 0; $paid = apply_filters("bsa-pro-setPaid", $paid, $_POST, $contract); if (isset($cost)) { // insert new Ad $this->wpdb->insert($this->getTableName('ads'), array('id' => NULL, 'space_id' => isset($_POST["space_id"]) ? $_POST["space_id"] : NULL, 'buyer_email' => isset($_POST["buyer_email"]) ? $_POST["buyer_email"] : NULL, 'title' => isset($_POST["title"]) ? stripslashes($_POST["title"]) : NULL, 'description' => isset($_POST["description"]) ? stripslashes($_POST["description"]) : NULL, 'url' => isset($_POST["url"]) ? $_POST["url"] : NULL, 'img' => $fileName, 'html' => isset($_POST["html"]) ? $_POST["html"] : NULL, 'ad_model' => isset($_POST["ad_model"]) ? $_POST["ad_model"] : NULL, 'ad_limit' => $ad_limit, 'cost' => $cost, 'paid' => bsa_space($_POST["space_id"], 'discount_' . $contract) == 100 ? 1 : 0, 'status' => 'pending'), array()); $ad_id = $this->wpdb->insert_id; // insert new referral if cookie if (isset($_COOKIE['bsaProAffiliate']) && bsa_space($_POST["space_id"], 'discount_' . $contract) < 100) { $cookie = $_COOKIE['bsaProAffiliate'] > 0 && get_current_user_id() != $_COOKIE['bsaProAffiliate'] ? $_COOKIE['bsaProAffiliate'] : 0; $commission_rate = get_option('bsa_pro_plugin_ap_commission') > 0 && get_option('bsa_pro_plugin_ap_commission') < 100 ? get_option('bsa_pro_plugin_ap_commission') : 10; $this->wpdb->insert($this->getTableName('referrals'), array('id' => null, 'ref_id' => $cookie, 'order_id' => $ad_id, 'withdrawal_id' => null, 'buyer' => isset($_POST["buyer_email"]) ? $_POST["buyer_email"] : '-', 'action_time' => time(), 'order_amount' => $cost, 'commission_rate' => $commission_rate, 'commission' => $cost - ($cost - $cost * $commission_rate / 100), 'order_status' => 'not_paid', 'status' => 'not_paid'), array()); } // add cron task if the user select a delay time if (isset($_POST["calendar"]) and $_POST["calendar"] != '' and preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $_POST["calendar"], $matches)) { if (checkdate($matches[2], $matches[3], $matches[1])) { $str_time = strtotime($_POST["calendar"]); $current_time = time(); if ($str_time > $current_time) { $this->wpdb->insert($this->getTableName('cron'), array('id' => NULL, 'item_id' => $ad_id, 'item_type' => 'ad', 'action_type' => 'active', 'start_time' => $str_time, 'when_repeat' => 0, 'status' => 'pending'), array()); wp_schedule_single_event($str_time, 'bsa_cron_jobs'); } } } $getAgencyForm = get_option('bsa_pro_plugin_agency_ordering_form_url'); $getOrderForm = get_option('bsa_pro_plugin_ordering_form_url'); if ($agency == 'agency' && $sid != null) { $_SESSION['bsa_payment_url'] = $getAgencyForm . (strpos($getAgencyForm, '?') !== false ? '&' : '?') . 'site_id=' . $sid . '&oid=' . $ad_id; } else { $_SESSION['bsa_payment_url'] = $getOrderForm . (strpos($getOrderForm, '?') !== false ? '&' : '?') . 'oid=' . $ad_id; } return 'successAdded'; // return success } else { return 'invalidParams'; // return error if some params invalid ( cost or ad_limit ) } } else { return 'invalidParams'; // return error if some params invalid ( cost or ad_limit ) } } else { return 'invalidParams'; // return error if some params invalid ( cost or ad_limit ) } } else { return 'fieldsRequired'; // return error if some input empty } } return ''; }
} } } else { echo ' <div class="bsaProContainer bsa-pro-col-3"> <h3 style="font-size: 20px; text-align: center;">' . get_option($bsaTrans . 'agency_title_form') . '</h3> <div class="bsaProItems bsaGridGutter"> '; ?> <?php foreach ($model->getSites('agency_form', 'active') as $site) { if ($model->countSpaces('agency_form', $site["id"]) > 0) { $agency_form = get_option('bsa_pro_plugin_agency_ordering_form_url'); echo ' <div class="bsaProItem bsaSite bsaHidden animated fadeIn" data-animation="fadeIn" style="' . ($site["thumb"] != '' ? 'background-image: url('' . bsa_upload_url() . $site["thumb"] : '') . '');"> <div class="bsaSiteInner"> <div class="bsaSiteInnerBg"></div> <h3> <a href="' . $agency_form . (strpos($agency_form, '?') ? '&' : '?') . 'site_id=' . $site["id"] . '">' . $site["title"] . '</a> <small>' . $site["url"] . '</small> </h3> <div class="bsaSiteActions"> <div class="bsaSiteAction bsaSiteActionLeft"><a href="' . $site["url"] . '" target="_blank">' . get_option($bsaTrans . 'agency_visit_site') . '</a></div> <div class="bsaSiteAction bsaSiteActionRight"><a href="' . $agency_form . (strpos($agency_form, '?') ? '&' : '?') . 'site_id=' . $site["id"] . '">' . get_option($bsaTrans . 'agency_buy_ad') . '</a></div> </div> </div> </div> '; } }