forked from YahnisElsts/wp-update-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyCustomServer.php
40 lines (30 loc) · 1.17 KB
/
MyCustomServer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class MyCustomServer extends Wpup_UpdateServer {
public function handleRequest( $query = null, $headers = null ) {
$this->startTime = microtime( true );
$request = $this->initRequest( $query, $headers );
$this->loadPackageFor( $request );
$this->validateRequest( $request );
$this->checkAuthorization( $request );
$this->dispatch( $request );
exit;
}
protected function generateDownloadUrl( Wpup_Package $package ) {
$query = array(
'action' => 'download',
'slug' => $package->slug,
);
$metadata = $package->getMetadata();
return self::addQueryArg( $query, $this->serverUrl ) . '&ver=' . $metadata['version'];
}
protected function actionDownload( Wpup_Request $request ) {
$package = $request->package;
$cacheTime = 3 * 3600; // Set cache headers for 6 hours (3 hours * 3600 seconds)
header( 'Content-Type: application/zip' );
header( 'Content-Disposition: attachment; filename="' . $package->slug . '.zip"' );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Length: ' . $package->getFileSize() );
header( 'Cache-Control: public, max-age=' . $cacheTime );
readfile( $package->getFilename() );
}
}