Пример #1
0
 public function update($product_id = '')
 {
     include_once ROOT . DS . 'includes' . DS . 'functions.php';
     $dg = new dg();
     $path_info = dirname(ROOT) . DS . 'addons' . DS . 'install' . DS . $product_id . '.json';
     if ($product_id != '' && file_exists($path_info)) {
         $content = file_get_contents($path_info);
         if ($content != false) {
             $addon = json_decode($content);
             $args = array('woo_sl_action' => 'plugin_update', 'licence_key' => $addon->key, 'product_unique_id' => $product_id, 'domain' => $_SERVER['HTTP_HOST']);
             $result = $dg->sendPostData($this->api_url, $args);
             if ($result != false && $result != '') {
                 $content = json_decode($result);
                 if (isset($content[0]) && isset($content[0]->status) && isset($content[0]->message) && $content[0]->status == 'success') {
                     if (isset($content[0]->message->package)) {
                         $addon->version = $content[0]->message->new_version;
                         $addon->date = $content[0]->message->date;
                         // download and upzip file
                         $file = $dg->openURL($content[0]->message->package);
                         $zip = new ZipArchive();
                         $path = dirname(dirname(ROOT));
                         $path_file = $path . DS . 'addon.zip';
                         if ($dg->WriteFile($path_file, $file) && $zip->open($path_file) == true) {
                             $zip->extractTo($path);
                             $zip->close();
                             unlink($path_file);
                             $dg->WriteFile($path_info, json_encode($addon));
                         }
                     }
                 }
             }
         }
     }
     $dg->redirect('index.php/addon/installed');
 }