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);
         }
     }
 }