Ejemplo n.º 1
0
 public function update()
 {
     $version = $this->request->get['version'];
     $product_id = $this->request->get['product_id'];
     $data = $this->update->downloadUpdate($product_id, $version);
     $path = 'temp-' . md5(mt_rand());
     $file = DIR_UPLOAD . $path . '/upload.zip';
     if (!is_dir(DIR_UPLOAD . $path)) {
         $this->filesystem->mkdir(DIR_UPLOAD . $path);
     }
     $uploaded = is_int(file_put_contents($file, $data)) ? true : false;
     if (!$uploaded) {
         return false;
     }
     // Fire event
     $this->trigger->fire('pre.admin.update.update', $product_id);
     // Force enable maintenance mode
     $maintenance_mode = $this->config->get('maintenance_mode');
     $this->config->set('maintenance_mode', 1);
     $installer = new Installer($this->registry);
     if (!$installer->unzip($file)) {
         return false;
     }
     // Remove Zip
     $this->filesystem->remove($file);
     if ($product_id == 'core') {
         $temp_path = DIR_UPLOAD . $path;
         $install_path = $temp_path . '/install';
         // Load the update script, if available
         if (is_file($install_path . '/update.php')) {
             require_once $install_path . '/update.php';
         }
         // Don't copy the install folder
         $this->filesystem->remove($install_path);
         // Move all files/folders from temp path
         $this->filesystem->mirror($temp_path, DIR_ROOT, null, array('override' => true));
         // Delete the temp path
         $this->filesystem->remove($temp_path);
     } else {
         // Required for ftp & remove extension functions
         $this->request->post['path'] = $path;
         $ftp = $this->load->controller('extension/installer/ftp');
         $remove = $this->load->controller('extension/installer/remove');
         $this->db->query("UPDATE `" . DB_PREFIX . "addon` SET `product_version` = '" . $this->db->escape($version) . "' WHERE `product_id` = '" . (int) $product_id . "'");
     }
     // Restore maintenance mode
     $this->config->set('maintenance_mode', $maintenance_mode);
     // Fire event
     $this->trigger->fire('post.admin.update.update', $product_id);
     return true;
 }
Ejemplo n.º 2
0
 public function downloadLanguage($data)
 {
     $code = $data['lang_code'];
     if ($code == 'en-GB') {
         $this->session->data['lang_name'] = 'English';
         $this->session->data['lang_code'] = 'en';
         $this->session->data['lang_image'] = 'gb.png';
         $this->session->data['lang_directory'] = 'en-GB';
         // Workaround to mutual session ids
         $this->session->data['config_language'] = 'en';
         $this->session->data['config_admin_language'] = 'en';
         return $code;
     }
     $link = 'https://crowdin.com/download/project/arastta/' . $code . '.zip';
     $data = $this->utility->getRemoteData($link);
     if (empty($data)) {
         return false;
     }
     $path = 'temp-' . md5(mt_rand());
     $file = DIR_UPLOAD . $path . '/upload.zip';
     if (!is_dir(DIR_UPLOAD . $path)) {
         $this->filesystem->mkdir(DIR_UPLOAD . $path);
     }
     $uploaded = is_int(file_put_contents($file, $data)) ? true : false;
     if (!$uploaded) {
         return false;
     }
     $installer = new Installer($this->registry);
     if (!$installer->unzip($file)) {
         return false;
     }
     // Remove Zip
     $this->filesystem->remove($file);
     $temp_path = DIR_UPLOAD . $path;
     $json = json_decode(file_get_contents($temp_path . '/install.json'), true);
     $this->session->data['lang_name'] = $json['translation']['name'];
     $this->session->data['lang_code'] = $json['translation']['code'];
     $this->session->data['lang_image'] = $json['translation']['image'];
     $this->session->data['lang_directory'] = $json['translation']['directory'];
     // Workaround to mutual session ids
     $this->session->data['config_language'] = $json['translation']['code'];
     $this->session->data['config_admin_language'] = $json['translation']['code'];
     $lang_dir = $json['translation']['directory'];
     // Move all files/folders from temp path
     $this->filesystem->mirror($temp_path . '/admin', DIR_ADMIN . 'language/' . $lang_dir, null, array('override' => true));
     $this->filesystem->mirror($temp_path . '/catalog', DIR_CATALOG . 'language/' . $lang_dir, null, array('override' => true));
     $this->filesystem->mirror($temp_path . '/install', DIR_INSTALL . 'language/' . $lang_dir, null, array('override' => true));
     // Delete the temp path
     $this->filesystem->remove($temp_path);
     return $lang_dir;
 }
Ejemplo n.º 3
0
 public function unzip()
 {
     $this->load->language('extension/installer');
     $json = array();
     if (!$this->user->hasPermission('modify', 'extension/installer')) {
         $json['error'] = $this->language->get('error_permission');
     }
     // Sanitize the filename
     $file = DIR_UPLOAD . str_replace(array('../', '..\\', '..'), '', $this->request->post['path']) . '/upload.zip';
     if (!file_exists($file)) {
         $json['error'] = $this->language->get('error_file');
     }
     if (!$json) {
         // Fire event
         $this->trigger->fire('pre.admin.extension.unzip', array(&$file));
         $installer = new Installer($this->registry);
         if (!$installer->unzip($file)) {
             $json['error'] = $this->language->get('error_unzip');
         }
         // Remove Zip
         unlink($file);
     }
     $this->response->addHeader('Content-Type: application/json');
     $this->response->setOutput(json_encode($json));
 }