public function downloadPackage()
 {
     $this->load->language('tool/package_installer');
     if (!isset($this->session->data['package_info'])) {
         $this->error = $this->language->get('error_package_info_not_exists');
         return false;
     }
     if (!is_writable($this->session->data['package_info']['tmp_dir'])) {
         $this->error = $this->language->get('error_dir_permission') . $this->session->data['package_info']['tmp_dir'];
         return false;
     }
     if ($this->request->get['start'] == 1) {
         $pmanager = new APackageManager();
         $result = $pmanager->getRemoteFile($this->session->data['package_info']['package_url'], true, $this->session->data['package_info']['tmp_dir'] . $this->session->data['package_info']['package_name']);
         if (!$result) {
             $percents = $pmanager->error;
         } else {
             $percents = 100;
         }
     } elseif (isset($this->session->data['curl_handler'])) {
         return curl_getinfo($this->session->data['curl_handler'], CURLINFO_SIZE_DOWNLOAD);
     } else {
         $percents = floor(filesize($this->session->data['package_info']['tmp_dir'] . $this->session->data['package_info']['package_name']) * 100 / $this->session->data['package_info']['package_size']);
     }
     return $percents;
 }
Exemplo n.º 2
0
 public function download()
 {
     // for short code
     $package_info =& $this->session->data['package_info'];
     $extension_key = trim($this->request->post_or_get('extension_key'));
     $disclaimer = false;
     $mp_token = '';
     if (!$extension_key && !$package_info['package_url']) {
         $this->_removeTempFiles();
         $this->redirect($this->_get_begin_href());
     }
     if ($this->request->is_GET()) {
         //reset installer array after redirects
         $this->_removeTempFiles();
         if ($extension_key) {
             //reset array only for requests by key (exclude upload url method)
             $this->session->data['package_info'] = array();
         }
     } elseif ($this->request->is_POST()) {
         if ($this->request->post['disagree'] == 1) {
             $this->_removeTempFiles();
             unset($this->session->data['package_info']);
             $this->redirect($this->html->getSecureURL('extension/extensions/extensions'));
         } else {
             $disclaimer = (int) $this->request->get['disclaimer'];
             // prevent multiple show for disclaimer
             $this->session->data['installer_disclaimer'] = true;
         }
     }
     if ($this->_isCorePackage($extension_key)) {
         $disclaimer = true;
     }
     if (!$disclaimer && !$this->session->data['installer_disclaimer']) {
         $this->view->assign('heading_title', $this->language->get('text_disclaimer_heading'));
         $form = new AForm('ST');
         $form->setForm(array('form_name' => 'Frm'));
         $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'Frm', 'action' => $this->html->getSecureURL('tool/package_installer/download'), 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"'));
         $this->data['form']['hidden'][] = $form->getFieldHtml(array('id' => 'extension_key', 'type' => 'hidden', 'name' => 'extension_key', 'value' => $extension_key));
         $this->data['agreement_text'] = $this->language->get('text_disclaimer');
         $this->data['form']['disagree_button'] = $form->getFieldHtml(array('type' => 'button', 'href' => $this->_get_begin_href(), 'text' => $this->language->get('text_interrupt')));
         $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'text' => $this->language->get('text_agree')));
         $this->data['form']['agree'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'disclaimer', 'value' => '0'));
         $this->view->batchAssign($this->data);
         $this->processTemplate('pages/tool/package_installer_agreement.tpl');
         return null;
     }
     $form = new AForm('ST');
     $form->setForm(array('form_name' => 'retryFrm'));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'retryFrm', 'action' => $this->html->getSecureURL('tool/package_installer/download')));
     $this->data['form']['hidden'][] = $form->getFieldHtml(array('id' => 'extension_key', 'type' => 'hidden', 'name' => 'extension_key', 'value' => $extension_key));
     $this->data['form']['hidden'][] = $form->getFieldHtml(array('id' => 'disclaimer', 'type' => 'hidden', 'name' => 'disclaimer', 'value' => '1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'href' => $this->_get_begin_href(), 'text' => $this->language->get('button_cancel')));
     $this->data['form']['retry'] = $form->getFieldHtml(array('type' => 'button', 'text' => $this->language->get('text_retry')));
     $this->view->assign('text_download_error', $this->language->get('text_download_error'));
     $package_info['extension_key'] = $extension_key;
     $package_info['tmp_dir'] = $this->_get_temp_dir();
     if (!is_writable($package_info['tmp_dir'])) {
         $this->session->data['error'] = $this->language->get('error_dir_permission') . ' ' . $package_info['tmp_dir'];
         unset($this->session->data['package_info']);
         $this->redirect($this->_get_begin_href());
     }
     //do condition for MP
     $this->loadModel('tool/mp_api');
     if ($extension_key) {
         // if prefix for new mp presents
         if (substr($extension_key, 0, 4) == 'acmp') {
             //need to mp token to get download based on key.
             $mp_token = $this->config->get('mp_token');
             if (!$mp_token) {
                 $this->session->data['error'] = sprintf($this->language->get('error_notconnected'), $this->html->getSecureURL('extension/extensions_store'));
                 $this->redirect($this->_get_begin_href());
             }
             $url = $this->model_tool_mp_api->getMPURL() . '?rt=r/account/download/getdownloadbykey';
             // for upgrades of core
         } else {
             $url = "/?option=com_abantecartrepository&format=raw";
         }
         $url .= "&mp_token=" . $mp_token;
         $url .= "&store_id=" . UNIQUE_ID;
         $url .= "&store_url=" . HTTP_SERVER;
         $url .= "&store_version=" . VERSION;
         $url .= "&extension_key=" . $extension_key;
     } else {
         $url = $package_info['package_url'];
     }
     $pmanager = new APackageManager();
     $headers = $pmanager->getRemoteFileHeaders($url);
     if (!$headers) {
         $error_text = $pmanager->error;
         $error_text = empty($error_text) ? 'Unknown error happened.' : $error_text;
         $this->session->data['error'] = $this->language->get('error_mp') . " " . $error_text;
         $this->redirect($this->_get_begin_href());
     }
     //if we have json returned, something went wrong.
     if (preg_match("/application\\/json/", $headers['Content-Type'])) {
         $error = $pmanager->getRemoteFile($url, false);
         $error_text = $error['error'];
         $error_text = empty($error_text) ? 'Unknown error happened.' : $error_text;
         $this->session->data['error'] = $this->language->get('error_mp') . " " . $error_text;
         $this->redirect($this->_get_begin_href());
     } else {
         $package_name = str_replace("attachment; filename=", "", $headers['Content-Disposition']);
         $package_name = str_replace(array('"', ';'), '', $package_name);
         if (!$package_name) {
             $package_name = parse_url($url);
             if (pathinfo($package_name['path'], PATHINFO_EXTENSION)) {
                 $package_name = pathinfo($package_name['path'], PATHINFO_BASENAME);
             } else {
                 $package_name = '';
             }
         }
         if (!$package_name) {
             $this->session->data['error'] = $this->language->get('error_repository');
             $this->redirect($this->_get_begin_href());
         }
     }
     $package_info['package_url'] = $url;
     $package_info['package_name'] = $package_name;
     $package_info['package_size'] = $headers['Content-Length'];
     // if file already downloaded - check size.
     if (file_exists($package_info['tmp_dir'] . $package_name)) {
         $filesize = filesize($package_info['tmp_dir'] . $package_name);
         if ($filesize != $package_info['package_size']) {
             @unlink($package_info['tmp_dir'] . $package_name);
         } else {
             if ($this->request->get['agree'] == '1') {
                 $this->redirect($this->html->getSecureURL('tool/package_installer/agreement'));
             } else {
                 $already_downloaded = true;
                 $this->redirect($this->html->getSecureURL('tool/package_installer/agreement'));
             }
         }
     }
     $this->data['url'] = $this->html->getSecureURL('tool/package_download');
     $this->data['redirect'] = $this->html->getSecureURL('tool/package_installer/agreement');
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('tool/package_installer'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ', 'current' => true));
     $this->data['heading_title'] = $this->language->get('heading_title_download');
     $this->data['loading'] = sprintf($this->language->get('text_loading'), round($package_info['package_size'] / 1024, 1) . 'kb');
     $package_info['install_mode'] = !$package_info['install_mode'] ? 'install' : $package_info['install_mode'];
     if (!$already_downloaded) {
         $this->data['pack_info'] .= str_replace('%file%', $package_name . ' (' . round($package_info['package_size'] / 1024, 1) . 'kb)', $this->language->get('text_preloading'));
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/tool/package_installer_download.tpl');
 }
Exemplo n.º 3
0
 public function download()
 {
     $package_info =& $this->session->data['package_info'];
     // for short code
     $extension_key = $this->request->post['extension_key'] ? $this->request->post['extension_key'] : $this->request->get['extension_key'];
     if (!$extension_key && !$package_info['package_url']) {
         $this->redirect($this->_get_begin_href());
     }
     if ($this->request->server['REQUEST_METHOD'] == 'POST') {
         // if does not agree  with agreement of filesize
         if ($this->request->post['disagree'] == 1) {
             $this->_removeTempFiles();
             unset($this->session->data['package_info']);
             $this->redirect($this->html->getSecureURL('extension/extensions/extensions'));
         } else {
             $disclaimer = (int) $this->request->get['disclaimer'];
             $this->session->data['installer_disclaimer'] = true;
             // prevent multiple show for disclaimer
         }
     }
     if (substr($extension_key, 0, 11) == 'abantecart_') {
         $disclaimer = true;
     }
     if (!$disclaimer && !$this->session->data['installer_disclaimer']) {
         $this->view->assign('heading_title', $this->language->get('text_disclaimer_heading'));
         $this->view->assign('text_disclaimer', $this->language->get('text_disclaimer'));
         $form = new AForm('ST');
         $form->setForm(array('form_name' => 'disclaimerFrm'));
         $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'disclaimerFrm', 'action' => $this->html->getSecureURL('tool/package_installer/download')));
         $this->data['form']['extension_key'] = $form->getFieldHtml(array('id' => 'extension_key', 'type' => 'hidden', 'name' => 'extension_key', 'value' => $extension_key));
         $this->data['form']['disagree_button'] = $form->getFieldHtml(array('type' => 'button', 'text' => $this->language->get('text_disagree'), 'style' => 'button'));
         $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'text' => $this->language->get('text_agree'), 'style' => 'button1'));
         $this->view->batchAssign($this->data);
         $this->processTemplate('pages/tool/package_installer_disclaimer.tpl');
         return;
     }
     $form = new AForm('ST');
     $form->setForm(array('form_name' => 'retryFrm'));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'retryFrm', 'action' => $this->html->getSecureURL('tool/package_installer/download')));
     $this->data['form']['hidden'][] = $form->getFieldHtml(array('id' => 'extension_key', 'type' => 'hidden', 'name' => 'extension_key', 'value' => $extension_key));
     $this->data['form']['hidden'][] = $form->getFieldHtml(array('id' => 'disclaimer', 'type' => 'hidden', 'name' => 'disclaimer', 'value' => '1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'text' => $this->language->get('button_cancel'), 'style' => 'button'));
     $this->data['form']['retry'] = $form->getFieldHtml(array('type' => 'button', 'text' => $this->language->get('text_retry'), 'style' => 'button1'));
     $this->view->assign('text_download_error', $this->language->get('text_download_error'));
     $package_info['extension_key'] = $extension_key;
     $package_info['tmp_dir'] = $this->_get_temp_dir();
     if (!is_writable($package_info['tmp_dir'])) {
         $this->session->data['error'] = $this->language->get('error_dir_permission') . ' ' . $package_info['tmp_dir'];
         unset($this->session->data['package_info']);
         $this->redirect($this->html->getSecureURL('tool/package_installer'));
     }
     //do condition for new and old MPs
     $this->loadModel('tool/mp_api');
     if ($extension_key) {
         if (substr($extension_key, 0, 4) == 'acmp') {
             // if prefix for new mp presents
             $url = $this->model_tool_mp_api->getMPURL() . '?rt=r/account/download/getdownloadbykey';
         } else {
             // for old marketplace
             $url = "/?option=com_abantecartrepository&format=raw";
         }
         $url .= "&store_id=" . UNIQUE_ID;
         $url .= "&store_ip=" . $_SERVER['SERVER_ADDR'];
         $url .= "&store_url=" . HTTP_SERVER;
         $url .= "&store_version=" . VERSION;
         $url .= "&extension_key=" . $extension_key;
     } else {
         $url = $package_info['package_url'];
     }
     $pmanager = new APackageManager();
     $headers = $pmanager->getRemoteFileHeaders($url);
     if (!$headers) {
         $this->session->data['error'] = $pmanager->error;
         $this->redirect($this->_get_begin_href());
     }
     if ($headers['Content-Type'] == 'application/json') {
         $error = $pmanager->getRemoteFile($url, false);
         $this->session->data['error'] = $error['error'];
         $this->redirect($this->_get_begin_href());
     } else {
         $package_name = str_replace("attachment; filename=", "", $headers['Content-Disposition']);
         $package_name = str_replace(array('"', ';'), '', $package_name);
         if (!$package_name) {
             $package_name = parse_url($url);
             if (pathinfo($package_name['path'], PATHINFO_EXTENSION)) {
                 $package_name = pathinfo($package_name['path'], PATHINFO_BASENAME);
             } else {
                 $package_name = '';
             }
         }
         if (!$package_name) {
             $this->session->data['error'] = $this->language->get('error_repository');
             $this->redirect($this->_get_begin_href());
         }
     }
     $package_info['package_url'] = $url;
     $package_info['package_name'] = $package_name;
     $package_info['package_size'] = $headers['Content-Length'];
     // if file already downloaded - check size.
     if (file_exists($package_info['tmp_dir'] . $package_name)) {
         $filesize = filesize($package_info['tmp_dir'] . $package_name);
         if ($filesize != $package_info['package_size']) {
             @unlink($package_info['tmp_dir'] . $package_name);
         } else {
             if ($this->request->get['agree'] == '1') {
                 $this->redirect($this->html->getSecureURL('tool/package_installer/agreement'));
             } else {
                 $already_downloaded = true;
                 $this->redirect($this->html->getSecureURL('tool/package_installer/agreement'));
             }
         }
     }
     $this->data['url'] = $this->html->getSecureURL('tool/package_download');
     $this->data['redirect'] = $this->html->getSecureURL('tool/package_installer/agreement');
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('tool/package_installer'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->data['heading_title'] = $this->language->get('heading_title_download');
     $this->data['loading'] = sprintf($this->language->get('text_loading'), round($package_info['package_size'] / 1024, 1) . 'kb');
     $package_info['install_mode'] = !$package_info['install_mode'] ? 'install' : $package_info['install_mode'];
     if (!$already_downloaded) {
         $this->data['pack_info'] .= str_replace('%file%', $package_name . ' (' . round($package_info['package_size'] / 1024, 1) . 'kb)', $this->language->get('text_preloading'));
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/tool/package_installer_download.tpl');
 }