<!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>[2649] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Add a bin script to import a WordPress plugin into the directory.</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/2649">2649</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/2649","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-02-29 08:36:48 +0000 (Mon, 29 Feb 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 a bin script to import a WordPress plugin into the directory. This is by no means final, and assumptions may have been made about plugin structures that will need to be supported.

See <a href="http://meta.trac.wordpress.org/ticket/1584">#1584</a></pre>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorybinimportpluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin.php</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassimportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorytoolsclasssvnphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-svn.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorybinimportpluginphp"></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/bin/import-plugin.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/bin/import-plugin.php                           (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin.php     2016-02-29 08:36:48 UTC (rev 2649)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,58 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory;
+
+// This script should only be called in a CLI environment.
+if ( 'cli' != php_sapi_name() ) {
+       die();
+}
+
+$opts = getopt( '', array( 'url:', 'abspath:', 'plugin:' ) );
+
+// Guess the default parameters:
+if ( empty( $opts ) && $argc == 2 ) {
+       $opts['plugin'] = $argv[1];
+       $argv[1] = '--plugin ' . $argv[1];
+}
+if ( empty( $opts['url'] ) ) {
+       $opts['url'] = 'https://wordpress.org/plugins/';
+}
+if ( empty( $opts['abspath'] ) && false !== strpos( __DIR__, 'wp-content' ) ) {
+       $opts['abspath'] = substr( __DIR__, 0, strpos( __DIR__, 'wp-content' ) );
+}
+
+foreach ( array( 'url', 'abspath', 'plugin' ) as $opt ) {
+       if ( empty( $opts[ $opt ] ) ) {
+               fwrite( STDERR, "Missing Parameter: $opt\n" );
+               fwrite( STDERR, "Usage: php {$argv[0]} --plugin hello-dolly --abspath /home/example/public_html --url https://wordpress.org/plugins/\n" );
+               fwrite( STDERR, "--url and --abspath will be guessed if possible.\n" );
+               die();
+       }
+}
+
+// Bootstrap WordPress
+$_SERVER['HTTP_HOST']   = parse_url( $opts['url'], PHP_URL_HOST );
+$_SERVER['REQUEST_URI'] = parse_url( $opts['url'], PHP_URL_PATH );
+
+include rtrim( $opts['abspath'], '/' ) . '/wp-load.php';
+
+if ( ! class_exists( '\WordPressdotorg\Plugin_Directory\Plugin_Directory' ) ) {
+       fwrite( STDERR, "Error! This site doesn't have the Plugin Directory plugin enabled.\n" );
+       if ( defined( 'WPORG_PLUGIN_DIRECTORY_BLOGID' ) ) {
+               fwrite( STDERR, "Run the following command instead:\n" );
+               fwrite( STDERR, "\tphp " . implode( ' ', $argv ) . " --url " . get_site_url( WPORG_PLUGIN_DIRECTORY_BLOGID, '/' ) . "\n" );
+       }
+       die();
+}
+
+$plugin_slug = $opts['plugin'];
+
+echo "Processing Import for $plugin_slug... ";
+try {
+       $importer = new CLI\Import;
+       $importer->import( $plugin_slug );
+       echo "OK\n";
+} catch( \Exception $e ) {
+       echo "Failed.\n";
+       fwrite( STDERR, "Plugin Import Failed: " . $e->getMessage() . "\n" );
+       exit(1);
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin.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_htmlwpcontentpluginsplugindirectorycliclassimportphp"></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/cli/class-import.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/cli/class-import.php                            (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php      2016-02-29 08:36:48 UTC (rev 2649)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,247 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\CLI;
+use WordPressdotorg\Plugin_Directory\Plugin_Directory;
+use WordPressdotorg\Plugin_Directory\Readme_Parser;
+use WordPressdotorg\Plugin_Directory\Tools;
+use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
+use WordPressdotorg\Plugin_Directory\Tools\SVN;
+
+/**
+ * The functionality required to process a plugin import into the Directory.
+ *
+ * This will normally be called on the CLI in response to a plugin commit.
+ *
+ * @package WordPressdotorg\Plugin_Directory\CLI
+ */
+class Import {
+       const PLUGIN_SVN_BASE = 'https://plugins.svn.wordpress.org';
+
+       // Readme fields which get stored in plugin meta
+       var $readme_fields = array(
+               'tested',
+               'requires',
+               'stable_tag',
+               'donate_link',
+               'upgrade_notice',
+               'contributors',
+               'screenshots'
+       );
+
+       // Plugin headers that are stored in plugin meta
+       var $plugin_headers = array(
+               // Header    => meta_key
+               'Name'       => 'header_name',
+               'PluginURI'  => 'header_plugin_uri',
+               'Version'    => 'version',
+               'Author'     => 'header_author',
+               'AuthorURI'  => 'header_author_uri',
+               'TextDomain' => 'header_textdomain'
+       );
+
+       /**
+        * Process an import for a Plugin into the Plugin Directory.
+        *
+        * @param string $plugin_slug The slug of the plugin to import.
+        * @return void.
+        */
+       public function import( $plugin_slug ) {
+               $plugin = Plugin_Directory::get_plugin_post( $plugin_slug );
+               if ( ! $plugin ) {
+// TODO                        throw new \Exception( "Unknown Plugin" );
+               }
+
+               $data = $this->export_and_parse_plugin( $plugin_slug );
+
+               if ( ! $plugin ) {
+                       global $wpdb;
+                       // TODO: During development while the bbPress variant is still running, we'll pull details from it and allow importing of any plugin.
+                       $author = $wpdb->get_var( $wpdb->prepare( 'SELECT topic_poster FROM ' . PLUGINS_TABLE_PREFIX . 'topics WHERE topic_slug = %s', $plugin_slug ) );
+                       if ( ! $author ) {
+                               throw new \Exception( "Unknown Plugin" );
+                       }
+                       $plugin = Plugin_Directory::create_plugin_post( array(
+                               'slug' => $plugin_slug,
+                               'status' => 'publish', // If we're importing it on the CLI, and it didn't exist, assume it's published
+                               'author' => $author
+                       ) );
+               }
+
+               $readme = $data['readme'];
+               $assets = $data['assets'];
+               $headers = $data['plugin_headers'];
+
+               $content = '';
+               foreach ( $readme->sections as $section => $section_content ) {
+                       $content .= "\n\n<!--section={$section}-->\n{$section_content}";
+               }
+
+               $plugin->post_title   = trim( $readme->name );
+               $plugin->post_content = trim( $content );
+               $plugin->post_excerpt = trim( $readme->short_description );
+
+               // Bump last updated if the version has changed.
+               if ( $headers->Version != get_post_meta( $plugin->ID, 'version', true ) ) {
+                       $plugin->post_modified = $plugin->post_modified_gmt = current_time( 'mysql' );
+               }
+
+               wp_update_post( $plugin );
+
+               foreach ( $this->readme_fields as $readme_field ) {
+                       update_post_meta( $plugin->ID, $readme_field, $readme->$readme_field );
+               }
+               foreach ( $this->plugin_headers as $plugin_header => $meta_field ) {
+                       update_post_meta( $plugin->ID, $meta_field, $headers->$plugin_header );
+               }
+
+               update_post_meta( $plugin->ID, 'sections', array_keys( $readme->sections ) );
+               update_post_meta( $plugin->ID, 'assets_screenshots', $assets['screenshot'] );
+               update_post_meta( $plugin->ID, 'assets_icons',       $assets['icon'] );
+               update_post_meta( $plugin->ID, 'assets_banners',     $assets['banner'] );
+
+               // Calculate the 'plugin color' from the average color of the banner if provided. This is used for fallback icons.
+               $banner_average_color = '';
+               if ( $first_banner = reset( $assets['banner'] ) ) {
+                       // The Banners are not stored locally, which is why a URL is used here
+                       $banner_average_color = Tools::get_image_average_color( Template::get_asset_url( $plugin_slug, $first_banner ) );
+               }
+               update_post_meta( $plugin->ID, 'assets_banners_color', $banner_average_color );
+
+       }
+
+       /**
+        * Export a plugin and determine all the information about the current state of the plugin.
+        *
+        * - Creates a /trunk/ export of the plugin.
+        * - Creates a /stable/ export of the stable_tag if specified, falling back to /trunk/.
+        * - Handles readme.md & readme.txt prefering the latter.
+        * - Searches for Screenshots in /$stable/ and in /assets/ (listed remotely).
+        *
+        * @param string $plugin_slug The slug of the plugin to parse.
+        *
+        * @return array {
+        *   'readme', 'trunk_readme', 'tmp_dir', 'plugin_headers', 'assets'
+        * }
+        */
+       protected function export_and_parse_plugin( $plugin_slug ) {
+               $tmp_dir = Filesystem::temp_directory( "process-{$plugin_slug}" );
+
+               $svn_export = SVN::export( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk", $tmp_dir . '/trunk', array( 'ignore-externals' ) );
+               if ( ! $svn_export['result'] || empty( $svn_export['revision'] ) ) {
+                       throw new \Exception( "Could not create SVN export." . implode( ' ', reset( $svn_export['errors'] ) ) );
+               }
+               $trunk_revision = $svn_export['revision'];
+
+               $trunk_readme = $this->find_readme_file( $tmp_dir . '/trunk' );
+               if ( ! $trunk_readme ) {
+                       throw new \Exception( "Could not locate a trunk readme" );
+               }
+               $trunk_readme = new Readme_Parser( $trunk_readme );
+
+               if ( $trunk_readme->stable_tag == 'trunk' || empty( $trunk_readme->stable_tag ) ) {
+                       $readme = $trunk_readme;
+                       $stable = 'trunk';
+                       $stable_revision = $trunk_revision;
+               } else {
+                       // There's a chance that the stable_tag will not actually exist, we have to fallback to trunk in those cases and avoid exiting here.
+                       $stable_tag = preg_replace( '![^a-z0-9-_.]!i', '', $trunk_readme->stable_tag );
+                       $svn_export = SVN::export( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$stable_tag}",  $tmp_dir . '/stable', array( 'ignore-externals' ) );
+
+                       $stable_readme = $svn_export['result'] ? $this->find_readme_file( $tmp_dir . '/stable' ) : false;
+                       if ( $stable_readme ) {
+                               $readme = $stable_readme = new Readme_Parser( $stable_readme );
+                               $stable = 'stable';
+                               $stable_revision = $svn_export['revision'];
+                       } else {
+                               // Trunk is stable!
+                               $readme = $trunk_readme;
+                               $stable = 'trunk';
+                               $stable_revision = $trunk_revision;
+                       }
+               }
+
+               $plugin_headers = $this->find_plugin_headers( "$tmp_dir/$stable" );
+
+               // Now we look in the /assets/ folder for banners, screenshots, and icons.
+               $assets = array( 'screenshot' => array(), 'banner' => array(), 'icon' => array() );
+               $svn_assets_folder = SVN::ls( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/assets/", true /* verbose */ );
+               if ( $svn_assets_folder ) { // /assets/ may not exist.
+                       foreach ( $svn_assets_folder as $asset ) {
+                               // screenshot-0.(png|jpg|jpeg|gif)  ||  icon.svg
+                               if ( ! preg_match( '!^(?P<type>screenshot|banner|icon)(-(?P<resolution>[^\s]+)\.(png|jpg|jpeg|gif)|\.svg)$!i', $asset['filename'], $m ) ) {
+                                       continue;
+                               }
+                               $type = $m['type'];
+                               $filename = $asset['filename'];
+                               $revision = $asset['revision'];
+                               $location = 'assets';
+                               $resolution = $m['resolution'] ?: false;
+                               $assets[ $type ][ $asset['filename'] ] = compact( 'filename', 'revision', 'resolution', 'location' );
+                       }
+               }
+
+               // Find screenshots in the stable plugin folder (but don't overwrite /assets/)
+               foreach ( Filesystem::list_files( "$tmp_dir/$stable/", false /* non-recursive */, '!^screenshot-\d+\.(jpeg|jpg|png|gif)$!' ) as $plugin_screenshot ) {
+                       $filename = basename( $plugin_screenshot );
+                       $screenshot_id = substr( $filename, strpos( $filename, '-' ) + 1 );
+                       $screenshot_id = substr( $screenshot_id, 0, strpos( $screenshot_id, '.' ) );
+
+                       if ( isset( $assets['screenshot'][ $filename ]  ) ) {
+                               // Skip it, it exists within /assets/ already
+                               continue;
+                       }
+
+                       $assets['screenshot'][ $filename ] = array(
+                               'filename' => $filename,
+                               'revision' => $stable_revision,
+                               'resolution' => $screenshot_id,
+                               'location' => 'plugin',
+                       );
+               }
+
+               return compact( 'readme', 'trunk_readme', 'tmp_dir', 'plugin_headers', 'assets' );
+       }
+
+       /**
+        * Find the plugin readme file.
+        *
+        * Looks for either a readme.txt or readme.md file, prioritizing readme.txt.
+        *
+        * @param string $directory The Directory to search for the readme in.
+        *
+        * @return string The plugin readme.txt or readme.md filename.
+        */
+       protected function find_readme_file( $directory ) {
+               $files = Filesystem::list_files( $directory, false /* non-recursive */, '!^readme\.(txt|md)$!i' );
+
+               // prioritize readme.txt
+               foreach ( $files as $f ) {
+                       if ( '.txt' == strtolower( substr( $f, -4 ) ) ) {
+                               return $f;
+                       }
+               }
+
+               return reset( $files );
+       }
+
+       /**
+        * Find the plugin headers for the given directory.
+        *
+        * @param string $directory The directory of the plugin.
+        *
+        * @return object The plugin headers.
+        */
+       protected function find_plugin_headers( $directory ) {
+               $files = Filesystem::list_files( $directory, false, '!\.php$!i' );
+
+               foreach ( $files as $file ) {
+                       $data = get_plugin_data( $file, false, false );
+                       if ( array_filter( $data ) ) {
+                               return (object) $data;
+                       }
+               }
+
+               return false;
+       }
+
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.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_htmlwpcontentpluginsplugindirectorytoolsclasssvnphp"></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/tools/class-svn.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/tools/class-svn.php                             (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-svn.php       2016-02-29 08:36:48 UTC (rev 2649)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,130 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Tools;
+
+/**
+ * Various SVN methods
+ *
+ * @package WordPressdotorg\Plugin_Directory\Tools
+ */
+class SVN {
+
+       /**
+        * Create an SVN Export of a URL to a local directory.
+        *
+        * Note: An exception will be thrown upon SVN error.
+        *
+        * @param string $url         The URL to export.
+        * @param string $destination The local folder to export into.
+        * @param array  $options     A list of options to pass to SVN. Optional.
+        *
+        * @return array {
+        *   @type bool $result   The result of the operation.
+        *   @type int  $revision The revision exported.
+        * }
+        */
+       public static function export( $url, $destination, $options = array() ) {
+               $esc_options = self::parse_esc_parameters( $options );
+
+               $esc_url = escapeshellarg( $url );
+               $esc_destination = escapeshellarg( $destination );
+
+               $output = exec( "svn export $esc_options $esc_url $esc_destination 2>&1" );
+               if ( preg_match( '/Exported revision (?P<revision>\d+)[.]/i', $output, $m ) ) {
+                       $revision = (int) $m['revision'];
+                       $result = true;
+               } else {
+                       $result = false;
+                       $errors = self::parse_svn_errors( $output );
+                       
+               }
+
+               return compact( 'result', 'revision', 'errors' );
+       }
+
+       /**
+        * List the files in a remote SVN destination.
+        *
+        * @param string $url     The URL to export.
+        * @param bool   $verbose Whether to list the files verbosely with extra metadata.
+        *
+        * @return array If non-verbose a list of files, if verbose an array of items containing the filename, date, filesize, author and revision.
+        */
+       public static function ls( $url, $verbose = false ) {
+               $esc_options = '';
+               if ( $verbose ) {
+                       $esc_options = '-v';
+               }
+               $esc_url = escapeshellarg( $url );
+
+               $output = exec( "svn ls $esc_options $esc_url 2>&1" );
+
+               $errors = self::parse_svn_errors( $output );
+               if ( $errors ) {
+                       return false;
+               }
+
+               if ( ! $verbose ) {
+                       return array_filter( array_map( 'trim', explode( "\n", $output ) ) );
+               } else {
+                       // Parse SVN verbose output.
+                       // ^revision author [filesize] date filename$
+                       preg_match_all( '!^\s*(?P<revision>\d+)\s(?P<author>\S+)\s*(?P<filesize>\d+)?\s*(?P<date>.+?)\s*(?P<filename>\S+)\s*$!im', $output, $files, PREG_SET_ORDER );
+
+                       // Remove numeric keys from output
+                       $files = array_map( function( $item ) {
+                               return array_filter( $item, 'is_string', ARRAY_FILTER_USE_KEY );
+                       }, $files );
+
+                       return $files;
+               }
+
+               return false;
+       }
+
+       /**
+        * Parse and escape the provided SVN arguements for usage on the CLI.
+        *
+        * Parameters can be passed as [ param ] or [ param = value ], if the argument is not
+        * prefixed with -, it'll be prefixed with 1 or 2 dashes as appropriate.
+        *
+        * @param array $params The array of parameters provided.
+        *
+        * @return string The parameters formatted and escaped for CLI usage.
+        */
+        protected static function parse_esc_parameters( $params ) {
+               $result = array();
+               foreach ( $params as $key => $value ) {
+                       $no_parameters = is_numeric( $key );
+                       if ( $no_parameters ) {
+                               $key = $value;
+                       }
+                       // Prefix options with `-` or `--` if they're longer than 2 characters
+                       if ( '-' != substr( $key, 0, 1 ) ) {
+                               $key = '-' . ( strlen( $key ) > 2 ? '-' : '' ) . $key;
+                       }
+                       
+                       $result[] = escapeshellarg( $key ) . ( $no_parameters ? '' : '=' . escapeshellarg( $value ) );
+               }
+
+               return implode( ' ', $result );
+       }
+
+       /**
+        * Parses SVN output to detect SVN errors and throw an exception.
+        *
+        * @param string $output The output from SVN.
+        *
+        * @return false|array False if no errors/warnings detected in output, An array of arrays containing warning/error_code/error_message if detected.
+        */
+       protected static function parse_svn_errors( $output ) {
+               if ( preg_match_all( '!^svn: (?P<warning>warning:)?\s*(?<error_code>[EW]\d+):\s*(?P<error_message>.+)$!im', $output, $messages, PREG_SET_ORDER ) ) {
+                       // We only want the string keys - strip out the numeric keys
+                       $messages = array_map( function( $item ) {
+                               return array_filter( $item, 'is_string', ARRAY_FILTER_USE_KEY );
+                       }, $messages );
+                       return $messages;
+               }
+
+               return false;
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-svn.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>