Advertisement
johnburn

Decoded for: joaquin@waraxe.us

May 23rd, 2011
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.17 KB | None | 0 0
  1. <?php
  2. if (!class_exists('ubam_oto')) {
  3.     class ubam_oto {
  4.         var $optionsName = 'ubam_oto_options';
  5.         var $localizationDomain = "ubam_oto";
  6.         var $thispluginurl = '';
  7.         var $thispluginpath = '';
  8.         var $options = array();
  9.         function ubam_oto() {
  10.             $locale = get_locale();
  11.             $mo = dirname(__FILE__) . "/languages/" . $this->localizationDomain . "-" . $locale . ".mo";
  12.             load_textdomain($this->localizationDomain, $mo);
  13.             $this->thispluginurl = PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__)) . '/';
  14.             $this->thispluginpath = PLUGIN_PATH . '/' . dirname(plugin_basename(__FILE__)) . '/';
  15.             $this->getOptions();
  16.             add_action("admin_menu", array(&$this, "admin_menu_link"));
  17.             add_action("init", array(&$this, "ubam_oto_handler"));
  18.         }
  19.         function getOptions() {
  20.             if (!$theOptions = get_option($this->optionsName)) {
  21.                 $theOptions = array('default' => 'options');
  22.                 update_option($this->optionsName, $theOptions);
  23.             }
  24.             $this->options = $theOptions;
  25.         }
  26.         function saveAdminOptions() {
  27.             return update_option($this->optionsName, $this->options);
  28.         }
  29.         function admin_menu_link() {
  30.             add_options_page('One-Time Offer', 'One-Time Offer', 'manage_options', 'one-time-offer.php', array(&$this, 'admin_options_page'));
  31.             add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'filter_plugin_actions'), 10, 2);
  32.         }
  33.         function filter_plugin_actions($links, $file) {
  34.             $settings_link = '<a href="options-general.php?page=' . basename(__FILE__) . '">' . __('Settings') . '</a>';
  35.             array_unshift($links, $settings_link);
  36.             return $links;
  37.         }
  38.         function ubam_oto_handler() {
  39.             global $wpdb;
  40.             if ($_GET['uo-offer']) {
  41.                 $offer_query = "SELECT * from {$wpdb->prefix}ubam_oto_offers where offer = '{$_GET['uo-offer']}'";
  42.                 $offer_result = $wpdb->get_row($offer_query);
  43.                 if (!$offer_result) {
  44.                     wp_redirect(get_option('siteurl'));
  45.                 } else {
  46.                     $offer_start_time = $offer_result->offer_start_date;
  47.                     if (!empty($offer_start_time) && $offer_start_time > time()) {
  48.                         wp_redirect(get_option('siteurl'));
  49.                     } else {
  50.                         $offer = $_GET['uo-offer'];
  51.                         $expired_page = $offer_result->offer_expired_page;
  52.                         $offer_page = $offer_result->offer_page;
  53.                         $offer_cookie = $offer_result->offer_cookie;
  54.                         $passwd = $offer_result->offer_passwd;
  55.                         $offer_end_time = $offer_result->offer_end_date;
  56.                         if ($offer_result->offer_time == 0) {
  57.                             $offer_time = 0;
  58.                         } else {
  59.                             $time_multiplier = 1;
  60.                             switch ($offer_result->offer_period) {
  61.                                 case 'W':
  62.                                     $time_multiplier*= 7;
  63.                                 case 'D':
  64.                                     $time_multiplier*= 24;
  65.                                 case 'H':
  66.                                     $time_multiplier*= 60;
  67.                                 case 'M':
  68.                                     $time_multiplier*= 60;
  69.                             }
  70.                             $offer_time = $offer_result->offer_time * $time_multiplier;
  71.                         }
  72.                         $cookie_expires = time() + (60 * 60 * 24 * 30);
  73.                         $unique_ip = trim(getenv('HTTP_X_FORWARDED_FOR'));
  74.                         $uv_id = $unique_ip;
  75.                         if (!ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $unique_ip)) {
  76.                             $unique_ip = $_SERVER['REMOTE_ADDR'];
  77.                             $uv_id = $unique_ip;
  78.                         }
  79.                         if (ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $unique_ip)) {
  80.                             @$uv_id = gethostbyaddr($unique_ip);
  81.                         }
  82.                         $query = "SELECT * FROM {$wpdb->prefix}ubam_oto_uniques WHERE uv_id='$uv_id' and offer = '$offer'";
  83.                         $unique_result = $wpdb->get_row($query);
  84.                         $the_time = time();
  85.                         if ((($unique_result && (empty($unique_result->offer_expires) || $unique_result->offer_expires < $the_time)) || (isset($_COOKIE[$offer_cookie]) && $_COOKIE[$offer_cookie] < $the_time) || (!empty($offer_end_time) && $offer_end_time < $the_time)) && (empty($passwd) || !isset($_GET['pw']) || $_GET['pw'] != $passwd)) {
  86.                             $output_page = $this->getPageUrl($expired_page);
  87.                         } else {
  88.                             if (isset($_GET['pw']) && !empty($passwd) && $_GET['pw'] == $passwd) {
  89.                                 $offer_expires = $the_time + $offer_time;
  90.                             } elseif (!empty($unique_result->offer_expires)) {
  91.                                 $offer_expires = $unique_result->offer_expires;
  92.                             } elseif (isset($_COOKIE[$offer_cookie])) {
  93.                                 $offer_expires = $_COOKIE[$offer_cookie];
  94.                             } else {
  95.                                 $offer_expires = $the_time + $offer_time;
  96.                             }
  97.                             if (!isset($_COOKIE[$offer_cookie])) {
  98.                                 setcookie($offer_cookie, $offer_expires, $cookie_expires);
  99.                                 header("Cache-Control: no-cache, no-store, must-revalidate");
  100.                                 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  101.                                 header("Pragma: no-cache");
  102.                                 header("CacheControl: no-cache");
  103.                             }
  104.                             $output_page = $this->getPageUrl($offer_page);
  105.                             if (!$unique_result) {
  106.                                 $query = "REPLACE INTO {$wpdb->prefix}ubam_oto_uniques ( offer, uv_id, offer_expires ) VALUES ( '$offer', '$uv_id', $offer_expires )";
  107.                                 $result = $wpdb->query($query);
  108.                             }
  109.                         }
  110.                         $outpage = @wp_remote_fopen($output_page);
  111.                         $backcolor = 'white';
  112.                         $forecolor = 'black';
  113.                         $outpage = str_replace('[OTO_USER_HOSTNAME]', $uv_id, $outpage);
  114.                         $iTimerCount = 0;
  115.                         $timer_format = '';
  116.                         while (preg_match('/\[OTO-TIMER(.*?)\]/i', $outpage, $matches) && iTimerCount < 10) {
  117.                             $span_out = "<span id='ubam-oto-cntdwn$iTimerCount'></span>";
  118.                             if (empty($timer_format) && count($matches) > 1 && strpos($matches[1], '%%') !== false) $timer_format = $matches[1];
  119.                             $outpage = substr_replace($outpage, $span_out, strpos($outpage, $matches[0]), strlen($matches[0]));
  120.                             $iTimerCount++;
  121.                         }
  122.                         if (empty($timer_format)) $timer_format = "%%D%% Day(s) -  %%H%%:%%M%%:%%S%%";
  123.                         if ($iTimerCount > 0) {
  124.                             $js_out = '<script language="JavaScript">' . 'TargetDate = "' . date("m/d/Y h:i:s A TO", $offer_expires) . '";' . 'BackColor = "white";' . 'ForeColor = "black";' . 'CountActive = true;' . 'CountStepper = -1;' . 'LeadingZero = true;' . 'DisplayFormat = "' . $timer_format . '";' . 'RedirectTo = "' . get_option('siteurl') . "?uo-offer=$offer" . '";' . 'NumOtoTimers = ' . $iTimerCount . ';' . 'FinishMessage = "It is finally here!";' . '</script>' . '<script language="JavaScript" src="' . WP_PLUGIN_URL . '/ubam_one_time_offer/countdown.js"></script>';
  125.                             $outpage = preg_replace('/<\/body>/i', $js_out . "</body>", $outpage, 1);
  126.                         }
  127.                         echo $outpage;
  128.                         exit;
  129.                     }
  130.                 }
  131.             }
  132.         }
  133.         function parse_attributes($attrib_string) {
  134.             $regex = '@([^\s=]+)\s*=\s*(\'[^<\']*\'|"[^<"]*"|\S*)@';
  135.             preg_match_all($regex, $attrib_string, $matches);
  136.             $attr = array();
  137.             for ($i = 0;$i < count($matches[0]);$i++) {
  138.                 if (!empty($matches[0][$i]) && !empty($matches[1][$i])) {
  139.                     if (preg_match("/^'(.*)'$/", $matches[2][$i], $vmatch)) {
  140.                         $value = $vmatch[1];
  141.                     } else if (preg_match('/^"(.*)"$/', $matches[2][$i], $vmatch)) {
  142.                         $value = $vmatch[1];
  143.                     } else {
  144.                         $value = $matches[2][$i];
  145.                     }
  146.                     $key = strtolower($matches[1][$i]);
  147.                     $attr[$key] = $value;
  148.                 }
  149.             }
  150.             return $attr;
  151.         }
  152.         function admin_options_page() {
  153.             global $wpdb;
  154.             if ($_POST['action'] == 'edit') {
  155.                 $editmode = true;
  156.                 $eoffer = $wpdb->get_row("SELECT * from {$wpdb->prefix}ubam_oto_offers WHERE offer_id={$_POST['offerid']}"); ?><div class="wrap">
  157.                 <h2>One Time Offer Manager for WordPress</h2> <?php require_once (OTOMGR_TEMPLATE_DIR . "offer-entry.htm");
  158.             } else {
  159.                 if ($_POST['action'] == 'delete') {
  160.                     $wpdb->show_errors();
  161.                     $delete_results = $wpdb->query("DELETE FROM {$wpdb->prefix}ubam_oto_offers WHERE offer_id={$_POST['offerid']}");
  162.                     $wpdb->hide_errors();
  163.                     if ($delete_results === false) {
  164.                         echo '<div class="updated"><p><strong><span style="color: red;">**ERROR**</span></strong> Unable to delete the offer.</p></div>';
  165.                     } else {
  166.                         $wpdb->show_errors();
  167.                         $delete_results = $wpdb->query("DELETE FROM {$wpdb->prefix}ubam_oto_uniques WHERE offer='{$_POST['offer']}'");
  168.                         $wpdb->hide_errors();
  169.                         echo '<div class="updated"><p>Success! Offer has been deleted.</p></div>';
  170.                     }
  171.                 }
  172.                 if ($_POST['ubam_oto_add_offer']) {
  173.                     $insert_query = "REPLACE INTO {$wpdb->prefix}ubam_oto_offers " . "       (offer, offer_time, offer_period, " . "        offer_page, offer_expired_page, " . "        offer_cookie, offer_passwd, " . "        offer_start_date, offer_end_date) " . "VALUES ('{$_POST['ubam_oto_offer']}', {$_POST['ubam_oto_offer_time']}, '{$_POST['ubam_oto_offer_period']}', " . "        '{$_POST['ubam_oto_offer_page']}', '{$_POST['ubam_oto_offer_expired_page']}', " . "        '{$_POST['ubam_oto_offer_cookie']}', '{$_POST['ubam_oto_offer_passwd']}', " . "       " . (!strtotime($_POST['ubam_oto_offer_start_date']) ? 'NULL' : strtotime($_POST['ubam_oto_offer_start_date'])) . ", " . "       " . (!strtotime($_POST['ubam_oto_offer_end_date']) ? 'NULL' : strtotime($_POST['ubam_oto_offer_end_date'])) . ") ";
  174.                     $wpdb->show_errors();
  175.                     $insert_results = $wpdb->query($insert_query);
  176.                     $wpdb->hide_errors();
  177.                     if ($insert_results === false) {
  178.                         echo '<div class="updated"><p><strong><span style="color: red;">**ERROR**</span></strong> Unable to save new offer.</p></div>';
  179.                     } else {
  180.                         echo '<div class="updated"><p>Success! Offer has been added to the database.</p></div>';
  181.                     }
  182.                 }
  183.                 if ($_POST['ubam_oto_update_offer']) {
  184.                     $update_query = "UPDATE {$wpdb->prefix}ubam_oto_offers " . "   SET offer = '{$_POST['ubam_oto_offer']}' " . "     , offer_time = '{$_POST['ubam_oto_offer_time']}' " . "     , offer_period = '{$_POST['ubam_oto_offer_period']}' " . "     , offer_page = '{$_POST['ubam_oto_offer_page']}' " . "     , offer_expired_page = '{$_POST['ubam_oto_offer_expired_page']}' " . "     , offer_cookie = '{$_POST['ubam_oto_offer_cookie']}' " . "     , offer_passwd = '{$_POST['ubam_oto_offer_passwd']}' " . "     , offer_start_date = " . (!strtotime($_POST['ubam_oto_offer_start_date']) ? 'NULL' : strtotime($_POST['ubam_oto_offer_start_date'])) . "     , offer_end_date = " . (!strtotime($_POST['ubam_oto_offer_end_date']) ? 'NULL' : strtotime($_POST['ubam_oto_offer_end_date'])) . " WHERE offer_id = {$_POST['offerid']} ";
  185.                     $wpdb->show_errors();
  186.                     $update_results = $wpdb->query($update_query);
  187.                     $wpdb->hide_errors();
  188.                     if ($update_results === false) {
  189.                         echo '<div class="updated"><p><strong><span style="color: red;">**ERROR**</span></strong> Unable to save changes.</p></div>';
  190.                     } else {
  191.                         echo '<div class="updated"><p>Success! Offer has been successfully changed.</p></div>';
  192.                     }
  193.                 }
  194.                 $wpdb->show_errors();
  195.                 $offerlist = $wpdb->get_results("SELECT * from {$wpdb->prefix}ubam_oto_offers ORDER BY offer", ARRAY_A);
  196.                 $wpdb->hide_errors();
  197.                 if (!is_array($offerlist)) $offerlist = array();
  198.                 $admin_link_prefix = 'options-general.php?page=';
  199.                 include_once (OTOMGR_TEMPLATE_DIR . "options-page.htm");
  200.             }
  201.         }
  202.         function getPageUrl($page) {
  203.             global $wpdb;
  204.             if (eregi('http://', $page) || eregi('https://', $page)) return $page;
  205.             $post_ID = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$page' and post_type in ('page', 'post')");
  206.             return get_permalink($post_ID);
  207.         }
  208.     }
  209. }
  210. function ubam_oto_load_css_and_js() {
  211. }
  212. if (preg_match("/one-time-offer/i", $_REQUEST['page'])) {
  213.     add_action('admin_head', 'ubam_oto_load_css_and_js');
  214. }
  215. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement