<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[3081] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Add an initial set of scripts to build & serve ZIP files.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/3081">3081</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/3081","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-05-05 07:18:13 +0000 (Thu, 05 May 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Plugin Directory: Add an initial set of scripts to build & serve ZIP files.
See <a href="http://meta.trac.wordpress.org/ticket/505">#505</a> - The new directory doesn't build ZIPs for branches.
See <a href="http://meta.trac.wordpress.org/ticket/1578">#1578</a></pre>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorydownloadhandlerphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/download-handler.php</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryzipclassbuilderphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryzipclassservephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-serve.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorydownloadhandlerphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/download-handler.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/download-handler.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/download-handler.php 2016-05-05 07:18:13 UTC (rev 3081)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,17 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory;
+
+/*
+ * This is a stand alone script, it operates with the expectation that the
+ * global `$wpdb` is available and the object cache is configured.
+ *
+ * Examples of URLs which are accepted:
+ * - downloads.wordpress.org/plugin/hello-dolly.zip (trunk)
+ * - downloads.wordpress.org/plugin/hello-dolly.latest-stable.zip
+ * - downloads.wordpress.org/plugin/hello-dolly.3.2.1.zip
+ */
+
+include __DIR__ . '/class-autoloader.php';
+Autoloader\register_class_path( __NAMESPACE__, __DIR__ );
+
+$serve = new Zip\Serve();
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/download-handler.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryzipclassbuilderphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php 2016-05-05 07:18:13 UTC (rev 3081)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,200 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Zip;
+use WordPressdotorg\Plugin_Directory\Tools\SVN;
+use Exception;
+
+/**
+ * Generates a ZIP file for a Plugin.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Zip
+ */
+class Builder {
+
+ /**
+ * The base directory for the ZIP files.
+ * Zip files will be stored in a sub-directory, such as:
+ * /tmp/plugin-zipfiles/hello-dolly/hello-dolly.zip
+ */
+ const ZIP_DIR = '/tmp/plugin-zipfiles';
+ const SVN_URL = 'https://plugins.svn.wordpress.org';
+
+ public $zip_file = '';
+ public $md5_file = '';
+ protected $tmp_build_file = '';
+ protected $tmp_build_dir = '';
+
+
+ /**
+ * Generate a ZIP for a provided Plugin Version.
+ *
+ * @param string $plugin_slug The Plugin slug
+ * @param string $version The version to build (tag, or trunk)
+ */
+ public function __construct( $slug, $version ) {
+ if ( ! is_dir( self::ZIP_DIR ) ) {
+ mkdir( self::ZIP_DIR, 0777, true );
+ chmod( self::ZIP_DIR, 0777 );
+ }
+ if ( ! is_dir( self::ZIP_DIR . '/' . $slug ) ) {
+ mkdir( self::ZIP_DIR . '/' . $slug, 0777, true );
+ chmod( self::ZIP_DIR . '/' . $slug, 0777 );
+ }
+
+ $this->slug = $slug;
+ $this->version = $version;
+
+ if ( 'trunk' == $this->version ) {
+ $this->zip_file = self::ZIP_DIR . "/{$this->slug}/{$this->slug}.zip";
+ } else {
+ $this->zip_file = self::ZIP_DIR . "/{$this->slug}/{$this->slug}.{$this->version}.zip";
+ }
+ $this->md5_file = $this->zip_file . '.md5';
+
+ }
+
+ /**
+ * Generate a ZIP for the plugin + version
+ */
+ public function build() {
+ try {
+ // The name must have at least 1 `.` in it for CLI `zip` not to complain.
+ $this->tmp_build_file = tempnam( dirname( $this->zip_file ), "tmp-{$this->slug}.{$this->version}" );
+ $this->tmp_build_dir = $this->tmp_build_file . '-files';
+ mkdir( $this->tmp_build_dir, 0777, true );
+
+ $this->export_plugin();
+ $this->fix_directory_dates();
+ $this->generate_zip();
+ $this->move_into_place();
+ $this->generate_md5();
+
+ $this->cleanup();
+
+ return true;
+ } catch( Exception $e ) {
+ $this->cleanup();
+ throw $e;
+ }/* finally { // PHP 5.5+, meta.svn is limited to PHP 5.4 code still.
+ $this->cleanup();
+ }*/
+ }
+
+ /**
+ * Creates an Export of the plugin and redies it for ZIP creation by removing invalid data.
+ */
+ protected function export_plugin() {
+ if ( 'trunk' == $this->version ) {
+ $svn_url = self::SVN_URL . "/{$this->slug}/trunk/";
+ } else {
+ $svn_url = self::SVN_URL . "/{$this->slug}/tags/{$this->version}/";
+ }
+ $build_dir = "{$this->tmp_build_dir}/{$this->slug}/";
+
+ $res = SVN::export( $svn_url, $build_dir );
+ if ( ! $res['result'] ) {
+ throw new Exception( __METHOD__ . ': ' . $res['errors'][0]['error_message'], 404 );
+ }
+
+ // Verify that the specified plugin zip will contain files.
+ if ( ! array_diff( scandir( $this->tmp_build_dir ), array( '.', '..' ) ) ) {
+ throw new Exception( ___METHOD__ . ': No files exist in the plugin directory', 404 );
+ }
+
+ // Cleanup any symlinks that shouldn't be there
+ exec( sprintf(
+ 'find %s -type l -print0 | xargs -r0 rm',
+ escapeshellarg( $build_dir )
+ ) );
+
+ return true;
+ }
+
+ /**
+ * Corrects the directory dates to match the latest modified file in the plugin export.
+ *
+ * When svn exports a directory, the file entries will reflect their last modified date
+ * however directories are created with their modified date set to the current date.
+ *
+ * This causes issues for ZIPs being built as we can't guarantee that two zips built
+ * from the same source files at different times will have the same checksums.
+ */
+ protected function fix_directory_dates() {
+ // Find all files, output their modified dates, sort reverse numerically, grab the timestamp from the first entry
+ $latest_file_modified_timestamp = exec( sprintf(
+ "find %s -type f -printf '%%T@\n' | sort -nr | head -c 10",
+ escapeshellarg( $this->tmp_build_dir )
+ ) );
+ if ( ! $latest_file_modified_timestamp ) {
+ throw new Exception( _METHOD__ . ': Unable to locate the latest modified files timestamp.', 503 );
+ }
+
+ exec( sprintf(
+ 'find %s -type d -exec touch -m -t %s {} \;',
+ escapeshellarg( $this->tmp_build_dir ),
+ escapeshellarg( date( 'ymdHi.s', $latest_file_modified_timestamp ) )
+ ) );
+ }
+
+ /**
+ * Generates the actual ZIP file we've painstakingly created the files for.
+ */
+ protected function generate_zip() {
+ // We have to remove the temporary 0-byte file first as zip will complain about not being able to find the zip structures.
+ unlink( $this->tmp_build_file );
+ exec( $cmd = sprintf(
+ 'cd %s && find %s -print0 | sort -z | xargs -0 zip -Xu %s 2>&1',
+ escapeshellarg( $this->tmp_build_dir ),
+ escapeshellarg( $this->slug ),
+ escapeshellarg( $this->tmp_build_file )
+ ), $zip_build_output, $return_value );
+
+ if ( $return_value ) {
+ throw new Exception( __METHOD__ . ': ZIP generation failed, return code: ' . $return_value, 503 );
+ }
+ }
+
+ /**
+ * Moves the completed ZIP into it's real-life location.
+ */
+ function move_into_place() {
+ exec( sprintf(
+ 'mv -f %s %s',
+ $this->tmp_build_file,
+ $this->zip_file
+ ), $output, $return_value );
+
+ if ( $return_value ) {
+ throw new Exception( __METHOD__ . ': Could not move ZIP into place.', 503 );
+ }
+ }
+
+ /**
+ * Generates the MD5 for the ZIP file used for serving.
+ *
+ * This can also be used for generating a package signature in the future.
+ */
+ function generate_md5() {
+ exec( sprintf(
+ "md5sum %s | head -c 32 > %s",
+ escapeshellarg( $this->zip_file ),
+ escapeshellarg( $this->md5_file )
+ ), $output, $return_code );
+
+ if ( $return_code ) {
+ throw new Exception( __METHOD__ . ': Failed to create file checksum.', 503 );
+ }
+ }
+
+ /**
+ * Cleans up any temporary directories created by the ZIP Builder.
+ */
+ protected function cleanup() {
+ if ( $this->tmp_build_file && file_exists( $this->tmp_build_file ) ) {
+ unlink( $this->tmp_build_file );
+ }
+ if ( $this->tmp_build_dir ) {
+ exec( sprintf( 'rm -rf %s', escapeshellarg( $this->tmp_build_dir ) ) );
+ }
+ }
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryzipclassservephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-serve.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-serve.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-serve.php 2016-05-05 07:18:13 UTC (rev 3081)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,213 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Zip;
+use Exception;
+
+/**
+ * Serves a Zip file.
+ *
+ * This class is designed to be used outside of WordPress.
+ * That's why we use $wpdb and cache functions directly in some functions.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Zip
+ */
+class Serve {
+
+ const ZIP_DIR = '/tmp/plugin-zipfiles';
+
+ public function __construct() {
+ try {
+ $request = $this->determine_request();
+
+ // Serve & perhaps build if need be
+ $files = $this->get_files( $request );
+ if ( ! file_exists( $files['zip'] ) ) {
+ $builder = new Builder( $request['slug'], $request['version'] );
+ $builder->build();
+ clearstatcache();
+ }
+
+ $this->serve_zip( $files, $request );
+
+ if ( $request['args']['stats'] ) {
+ $this->record_stats( $request );
+ }
+
+ } catch ( Exception $e ) {
+ $this->error( $e->getCode() );
+ }
+
+ }
+
+ /**
+ * Parse the Request URI to determine what we need to serve.
+ *
+ * @return array An array containing the vital details for the ZIP request.
+ */
+ protected function determine_request() {
+ $zip = basename( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );
+
+ $slug = false;
+ $version = 'trunk';
+
+ if ( ! preg_match( "!^(?P<slug>[a-z0-9-]+)(.(?P<version>.+))?.zip$!i", $zip, $m ) ) {
+ throw new Exception( __METHOD__ . ": Invalid URL" );
+ }
+
+ $slug = strtolower( $m['slug'] );
+ if ( isset( $m['version'] ) ) {
+ $version = $m['version'];
+ }
+
+ if ( 'latest-stable' == $version ) {
+ $version = $this->get_stable_tag( $slug );
+ }
+
+ $args = array(
+ 'stats' => true,
+ );
+ if ( isset( $_GET['stats'] ) ) {
+ $args['stats'] = (bool) $_GET['stats'];
+ } elseif ( isset( $_GET['nostats'] ) ) {
+ $args['stats'] = !empty( $_GET['nostats'] );
+ }
+
+ return compact( 'zip', 'slug', 'version', 'args' );
+ }
+
+ /**
+ * Retrieve the stable_tag for a given plugin from Cache or the Database.
+ *
+ * @param string $plugin_slug The plugin slug
+ * @return string The stable_tag on success, Exception thrown on failure.
+ */
+ protected function get_stable_tag( $plugin_slug ) {
+ global $wpdb;
+
+ $post_id = $this->get_post_id( $plugin_slug );
+
+ // Determine the stable_tag
+ $meta = wp_cache_get( $post_id, 'post_meta' );
+ $version = false;
+ if ( isset( $meta['stable_tag'][0] ) ) {
+ $version = $meta['stable_tag'][0];
+ }
+ if ( ! $version ) {
+ $version = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'stable_tag' LIMIT 1", $post_id ) );
+ }
+ if ( ! $version ) {
+ throw new Exception( __METHOD__ . ": A version for $plugin_slug cannot be determined.", 404 );
+ }
+
+ return $version;
+ }
+
+ /**
+ * Retrieve the post_id for a Plugin slug.
+ *
+ * This function uses the Object Cache and $wpdb directly to avoid
+ * a dependency upon WordPress.
+ *
+ * @param string $plugin_slug The plugin slug.
+ * @return int The post_id for the plugin. Exception thrown on failure.
+ */
+ protected function get_post_id( $plugin_slug ) {
+ global $wpdb;
+
+ $post_id = wp_cache_get( $plugin_slug, 'plugin-slugs' );
+ if ( false === $post_id ) {
+ $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID from $wpdb->posts WHERE post_type = 'plugin' AND post_name = %s", $plugin_slug ) );
+ wp_cache_add( $plugin_slug, $post_id, 'plugin-slugs' );
+ }
+
+ if ( ! $post_id ) {
+ throw new Exception( __METHOD__ . ": A post_id for $plugin_slug cannot be determined.", 404 );
+ }
+
+ return $post_id;
+ }
+
+ /**
+ * Returns the files to use for the request.
+ *
+ * @param array $request The request object for the request.
+ * @return array An array containing the files to use for the request, 'zip' and 'md5'.
+ */
+ protected function get_files( $request ) {
+ if ( empty( $request['version'] ) || 'trunk' == $request['version'] ) {
+ $zip = self::ZIP_DIR . "/{$request['slug']}/{$request['slug']}.zip";
+ } else {
+ $zip = self::ZIP_DIR . "/{$request['slug']}/{$request['slug']}.{$request['version']}.zip";
+ }
+ $md5 = $zip . '.md5';
+
+ return compact( 'zip', 'md5' );
+ }
+
+ /**
+ * Output a ZIP file with all headers.
+ *
+ * @param array $files {
+ * Array of files for the request.
+ *
+ * @type string $zip The Zip file to serve.
+ * @type string $md5 The MD5 file to use for the Content-MD5 header. Optional.
+ * }
+ * @param array $request The request array for the request.
+ */
+ protected function serve_zip( $files, $request ) {
+ header( 'Content-Type: application/zip' );
+ header( 'Content-Disposition: attachment; filename=' . basename( $files['zip'] ) );
+ if ( !empty( $files['md5'] ) && ( $md5 = file_get_contents( $files['md5'] ) ) ) {
+ header( 'Content-MD5: ' . $md5 );
+ }
+
+ // TODO: Accel Redirect allows for ZIP files to be cached on the LB's
+ // header('X-Accel-Redirect: ' . $accel_redirect );
+
+ header( 'Content-Length: ' . filesize( $files['zip'] ) );
+ readfile( $files['zip'] );
+ }
+
+ /**
+ * Record some download stats for Plugin Downloads.
+ *
+ * TODO: This should really be async log parsing..
+ *
+ * @param array $request The request array.
+ */
+ protected function record_stats( $request ) {
+ global $wpdb;
+
+ $stats = array(
+ 'plugin_slug' => $request['slug'],
+ 'client_ip' => $_SERVER['REMOTE_ADDR'],
+ 'client_host' => gethostbyaddr( $_SERVER['REMOTE_ADDR'] ),
+ 'user_agent' => $_SERVER['HTTP_USER_AGENT']
+ );
+ // $wpdb->insert( stats_table, $stats );
+ // TODO: This is stored in bbPress tables still.
+ // $post_id = $this->get_post_id( $request['slug'] );
+ // $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value = meta_value + 1 WHERE post_id = %d AND meta_key = 'downloads'", $post_id ) );
+ }
+
+ /**
+ * Quit with an Error code.
+ *
+ * @param int $code The HTTP Error code, 404 or 503.
+ */
+ protected function error( $code = 404 ) {
+ $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
+ $protocol .= ' ';
+ switch ( $code ) {
+ case 503:
+ header( $protocol . '503 Service Unavailable' );
+ die( '503 Service Unavailable' );
+
+ default:
+ case 404:
+ header( $protocol . '404 File not found' );
+ die( '404 File not found' );
+ }
+ }
+
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-serve.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>