function add_license() { if (!$this->check_ajax()) { die(json_encode((object) array('R' => 'ERR', 'MSG' => __('Service not available.', 'pop')))); } $license_key = isset($_REQUEST['license_key']) && trim($_REQUEST['license_key']) != '' ? $_REQUEST['license_key'] : false; if (false === $license_key) { die(json_encode((object) array('R' => 'ERR', 'MSG' => __('Missing parameter', 'pop')))); } $options = $this->get_options(); $options['license_keys'] = isset($options['license_keys']) && is_array($options['license_keys']) && count($options['license_keys']) > 0 ? $options['license_keys'] : array(); //--check existing if (count($options['license_keys']) > 0) { foreach ($options['license_keys'] as $l) { if (@$l->license_key == $license_key) { die(json_encode((object) array('R' => 'ERR', 'MSG' => __('License already added.', 'pop')))); } } } $url = sprintf('%s?content_service=verify_license_key&license_key=%s&plugin_code=%s', $this->api_url, urlencode($license_key), urlencode($this->plugin_code)); //$url = sprintf('http://plugins.righthere.com/?content_service=verify_license_key&license_key=%s&plugin_code=%s',urlencode($license_key),urlencode($this->plugin_code)); //$url = sprintf('http://plugins.albertolau.com/?content_service=verify_license_key&license_key=%s&plugin_code=%s',urlencode($license_key),urlencode($this->plugin_code)); if (!class_exists('righthere_service')) { require_once 'class.righthere_service.php'; } $rh = new righthere_service(); $r = $rh->rh_service($url); //file_put_contents( ABSPATH.'theme.log', $url."\n".print_r($r,true)); if (false !== $r) { if ($r->R == 'OK') { if (!in_array($r->LICENSE->item_type, array('plugin', 'theme'))) { if (count($options['license_keys']) == 0) { die(json_encode((object) array('R' => 'ERR', 'MSG' => __('Please add a main license key before adding an addon license key.', 'pop')))); } } $options['license_keys'][] = $r->LICENSE; $this->update_option($this->options_varname, $options); die(json_encode($r)); } else { if ($r->R == 'ERR') { die(json_encode($r)); } else { die(json_encode((object) array('R' => 'ERR', 'MSG' => __('Service not available.', 'pop') . '(1)'))); } } } die(json_encode((object) array('R' => 'ERR', 'MSG' => __('Service not available.', 'pop') . '(2)' . @$r->last_error_str))); }
function pop_notifications() { $url = sprintf('http://plugins.righthere.com/?rh_latest_version=%s&site_url=%s&license_key=%s', $this->notification->plugin_code, urlencode(site_url('/')), urlencode($this->get_license_key())); if ($this->theme) { $url .= "&theme=1"; } if (!class_exists('righthere_service')) { require_once 'class.righthere_service.php'; } $rh = new righthere_service(); $r = $rh->rh_service($url); if (false !== $r) { if (!$this->theme) { if (is_object($r) && property_exists($r, 'version')) { if ($r->version > $this->notification->plugin_version) { $message = sprintf("<div class=\"updated fade\"><p><strong>%s</strong></p></div>", $this->notification->message); $response = (object) array('R' => 'OK', 'MSG' => sprintf($message, $r->version, $r->url)); die(json_encode($response)); } else { die(json_encode((object) array('R' => 'ERR', 'MSG' => 'Plugin is latest version.'))); } } else { die(json_encode((object) array('R' => 'ERR', 'MSG' => 'Invalid response format.'))); } } } die(json_encode((object) array('R' => 'ERR', 'MSG' => 'Notification service is not available.'))); }
function download_bundle() { if (!is_super_admin() && current_user_can('rh_demo')) { die(json_encode(array('R' => 'ERR', 'MSG' => __('No access. You dont have permission to perform this action.', 'pop')))); } if (count($this->license_keys) == 0) { $this->send_error(__('Please register the product before downloading content.', 'pop')); } $url = sprintf('%s?content_service=get_bundle&id=%s&site_url=%s', $this->api_url, intval($_REQUEST['id']), urlencode(site_url('/'))); foreach ($this->get_license_keys() as $key) { $url .= sprintf("&key[]=%s", trim($key)); } if (!class_exists('righthere_service')) { require_once 'class.righthere_service.php'; } $rh = new righthere_service(); $response = $rh->rh_service($url); if (false === $response) { $this->send_error(__('Service is unavailable, please try again later.', 'pop')); } else { //handle import of content. if ($response->R == 'OK') { if ($response->DC->type == 'bundle') { global $userdata; require_once 'class.al_importer.php'; $dc = base64_decode($response->DC->content); $e = new al_importer(array('post_author' => $userdata->ID, 'post_author_rewrite' => true)); $bundle = $e->decode_bundle($dc); $result = $e->import_bundle($bundle); if (false === $result) { $this->send_error("Import error:" . $e->last_error); } else { $this->add_downloaded_id(intval($_REQUEST['id'])); $r = (object) array("R" => "OK", "MSG" => __("Content downloaded and installed.", 'pop')); $this->send_response($r); } } elseif ($response->DC->type == 'pop') { require_once 'class.pop_importer.php'; $plugin_id = $this->plugin_id; $options_varname = $this->options_varname; $resources_path = $this->resources_path; if (isset($_REQUEST['plugin_code']) && !empty($_REQUEST['plugin_code'])) { foreach ($this->plugin_codes as $c => $t) { if ($t->plugin_code == $_REQUEST['plugin_code']) { $plugin_id = $t->plugin_id; $options_varname = $t->options_varname; $resources_path = $t->resources_path; break; } } } $e = new pop_importer(array('plugin_id' => $plugin_id, 'options_varname' => $options_varname, 'resources_path' => $resources_path, 'tdom' => 'pop', 'alt_temp' => $this->alt_temp, 'multisite' => $this->multisite)); $result = $e->import_options_from_code($response); if (false === $result) { $this->send_error("Import error:" . $e->last_error); } else { $this->add_downloaded_id(intval($_REQUEST['id'])); $r = (object) array("R" => "OK", "MSG" => __("Content downloaded and installed.", 'pop')); $this->send_response($r); } } else { $this->send_error(__('Unhandled content type, update plugin or theme to latest version.', 'pop')); } } else { $this->send_error($response->MSG, $response->ERRCODE); } } }
function download_bundle() { error_reporting(0); if (count($this->license_keys) == 0) { $this->send_error(__('Please register the product before downloading content.', $this->tdom)); } $url = sprintf('%s?content_service=get_bundle&id=%s&site_url=%s', $this->api_url, intval($_REQUEST['id']), urlencode(site_url('/'))); foreach ($this->get_license_keys() as $key) { $url .= sprintf("&key[]=%s", $key); } if (!class_exists('righthere_service')) { require_once 'class.righthere_service.php'; } $rh = new righthere_service(); $response = $rh->rh_service($url); if (false === $response) { $this->send_error(__('Service is unavailable, please try again later.', $this->tdom)); } else { //handle import of content. if ($response->R == 'OK') { if ($response->DC->type == 'bundle') { global $userdata; require_once 'class.al_importer.php'; $dc = base64_decode($response->DC->content); $e = new al_importer(array('post_author' => $userdata->ID, 'post_author_rewrite' => true)); $bundle = $e->decode_bundle($dc); $result = $e->import_bundle($bundle); if (false === $result) { $this->send_error("Import error:" . $e->last_error); } else { $this->add_downloaded_id(intval($_REQUEST['id'])); $r = (object) array("R" => "OK", "MSG" => __("Content downloaded and installed.", $this->tdom)); $this->send_response($r); } } else { $this->send_error(__('Unhandled content type, update plugin or theme to latest version.', $this->tdom)); } } else { $this->send_error($response->MSG, $response->ERRCODE); } } }
function debug_righthere_service() { global $rhc_plugin; $api_url = 'secondary' == $rhc_plugin->get_option('righthere_api_url', '', true) ? 'http://plugins.albertolau.com/' : 'http://plugins.righthere.com/'; $url = sprintf('%s?content_service=get_status&site_url=%s', $api_url, urlencode(site_url('/'))); $output = array(); $output[] = sprintf("Contacting %s...", $api_url); if (!class_exists('righthere_service')) { require_once 'class.righthere_service.php'; } $rh = new righthere_service(); $response = $rh->rh_service($url); if ('OK' == $response->R) { $output[] = __('Connection with RightHere service successful.', 'rhc'); } else { $msg = sprintf(__('Network error: %s'), $rh->last_error_str); $output[] = sprintf("<textarea cols=70 rows=5 >%s</textarea>", $msg); } //f9cbbeed9aa00d99a69ce52268d493e0 return implode('<br>', $output); }
function _pop_notifications() { $transient = strtolower(sprintf('pop_notifications_%s', $this->notification->plugin_code)); $url = sprintf('%s/?rh_latest_version=%s&site_url=%s&license_key=%s', $this->api_url, $this->notification->plugin_code, urlencode(site_url('/')), urlencode($this->get_license_key())); if ($this->theme) { $url .= "&theme=1"; } if (!class_exists('righthere_service')) { require_once 'class.righthere_service.php'; } if (false === ($r = get_transient($transient))) { $rh = new righthere_service(); $r = $rh->rh_service($url); set_transient($transient, $r, 1800); } if (false === $this->pluginfile) { $update_url = false === $this->pluginslug ? $r->url : admin_url('/update-core.php?force-check=1'); } else { $update_url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $this->pluginfile), 'upgrade-plugin_' . $this->pluginfile); } if (false !== $r) { if (!$this->theme) { if (is_object($r) && property_exists($r, 'version')) { if ($r->version > $this->notification->plugin_version) { $this->handle_update_check($r->version, $this->notification->plugin_version); $message = sprintf("<div class=\"updated fade\"><p><strong>%s</strong></p></div>", $this->notification->message); $response = (object) array('R' => 'OK', 'MSG' => sprintf($message, $r->version, $update_url)); return $response; } else { return (object) array('R' => 'ERR', 'MSG' => __('Plugin is latest version.', 'pop')); } } else { return (object) array('R' => 'ERR', 'MSG' => __('Invalid response format.', 'pop')); } } } return (object) array('R' => 'ERR', 'MSG' => __('Notification service is not available.', 'pop')); }