function rcl_update_addon() { $addon = $_POST['addon']; $need_update = get_option('rcl_addons_need_update'); if (!isset($need_update[$addon])) { return false; } $activeaddons = get_site_option('active_addons_recall'); $url = 'http://wppost.ru/products-files/api/update.php' . '?rcl-addon-action=update'; $data = array('addon' => $addon, 'rcl-key' => get_option('rcl-key'), 'rcl-version' => VER_RCL, 'addon-version' => $need_update[$addon]['version'], 'host' => $_SERVER['SERVER_NAME']); $pathdir = RCL_TAKEPATH . 'update/'; $new_addon = $pathdir . $addon . '.zip'; if (!file_exists($pathdir)) { mkdir($pathdir); chmod($pathdir, 0755); } $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data))); $context = stream_context_create($options); $archive = file_get_contents($url, false, $context); //print_r($archive);exit; if (!$archive) { $log['error'] = __('Unable to retrieve the file from the server!', 'wp-recall'); echo json_encode($log); exit; } $result = json_decode($archive, true); if (is_array($result) && isset($result['error'])) { echo json_encode($result); exit; } file_put_contents($new_addon, $archive); $zip = new ZipArchive(); $res = $zip->open($new_addon); if ($res === TRUE) { for ($i = 0; $i < $zip->numFiles; $i++) { if ($i == 0) { $dirzip = $zip->getNameIndex($i); } if ($zip->getNameIndex($i) == $dirzip . 'info.txt') { $info = true; break; } } if (!$info) { $zip->close(); $log['error'] = __('Update does not have the correct title!', 'wp-recall'); echo json_encode($log); exit; } if (file_exists(RCL_TAKEPATH . 'add-on' . '/')) { if (isset($activeaddons[$addon])) { rcl_deactivate_addon($addon); } $rs = $zip->extractTo(RCL_TAKEPATH . 'add-on' . '/'); if (isset($activeaddons[$addon])) { rcl_activate_addon($addon); } } $zip->close(); unlink($new_addon); $log['success'] = $addon; echo json_encode($log); exit; } else { $log['error'] = __('Unable to open archive!', 'wp-recall'); echo json_encode($log); exit; } }
function update_status_addon_recall_activate() { if (isset($_GET['action-addon'])) { if (!wp_verify_nonce($_GET['_wpnonce'], 'action_addon')) { return false; } global $wpdb, $user_ID, $active_addons; if (!current_user_can('activate_plugins')) { wp_die(__('You cant control polucheniya plugins on this site.', 'wp-recall')); } $paths = array(RCL_TAKEPATH . 'add-on', RCL_PATH . 'add-on'); $addon = $_GET['addon']; if ($_GET['status'] == 'activate') { rcl_activate_addon($addon); wp_redirect(admin_url('admin.php?page=manage-addon-recall&update-addon=activate')); exit; } if ($_GET['status'] == 'deactivate') { rcl_deactivate_addon($addon); wp_redirect(admin_url('admin.php?page=manage-addon-recall&update-addon=deactivate')); exit; } if ($_GET['status'] == 'delete') { rcl_delete_addon($addon); wp_redirect(admin_url('admin.php?page=manage-addon-recall&update-addon=delete')); exit; } } }