Changeset 2983 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php
- Timestamp:
- 04/19/2016 08:09:35 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php
r2640 r2983 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\Shortcodes; 3 use WordPressdotorg\Plugin_Directory\Readme_Parser; 3 4 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 4 5 use WordPressdotorg\Plugin_Directory\Tools\Filesystem; … … 122 123 123 124 if ( preg_match( '|[^\d\.]|', $this->plugin['Version'] ) ) { 124 /* translators: %s: style.css*/125 /* translators: %s: Version header */ 125 126 return sprintf( __( 'Version strings can only contain numeric and period characters (like 1.2). Please fix your %s line in your main plugin file and upload the plugin again.', 'wporg-plugins' ), 126 127 '<code>Version:</code>' … … 129 130 130 131 // Prevent duplicate URLs. 131 $plugin_uri = $this->plugin['PluginURI']; 132 $author_uri = $this->plugin['AuthorURI']; 133 if ( ! empty( $plugin_uri ) && ! empty( $author_uri ) && $plugin_uri == $author_uri ) { 132 if ( ! empty( $this->plugin['PluginURI'] ) && ! empty( $this->plugin['AuthorURI'] ) && $this->plugin['PluginURI'] == $this->plugin['AuthorURI'] ) { 134 133 return __( 'Duplicate plugin and author URLs. A plugin URL is a page/site that provides details about this specific plugin. An author URL is a page/site that provides information about the author of the plugin. You aren’t required to provide both, so pick the one that best applies to your URL.', 'wporg-plugins' ); 135 134 } 135 136 $readme = $this->find_readme_file(); 137 if ( empty( $readme ) ) { 138 /* translators: 1: readme.txt, 2: readme.md */ 139 return sprintf( __( 'The zip file must include a file named %1$s or %2$s.', 'wporg-plugins' ), 140 '<code>readme.txt</code>', 141 '<code>readme.md</code>' 142 ); 143 } 144 $readme = new Readme_Parser( $readme ); 136 145 137 146 // Pass it through Plugin Check and see how great this plugin really is. … … 149 158 // Let's save everything and get things wrapped up. 150 159 160 $content = ''; 161 foreach ( $readme->sections as $section => $section_content ) { 162 $content .= "\n\n<!--section={$section}-->\n{$section_content}"; 163 } 164 151 165 // Add a Plugin Directory entry for this plugin. 152 166 $plugin_post = Plugin_Directory::create_plugin_post( array( 153 167 'title' => $this->plugin['Name'], 154 168 'slug' => $this->plugin_slug, 155 'status' => ' pending',169 'status' => 'draft', 156 170 'author' => get_current_user_id(), 157 'description' => $this->plugin['Description'] 171 'content' => $content, 172 'description' => $this->plugin['Description'], 173 'tags' => $readme->tags, 174 'meta' => array( 175 'stable_tag' => $readme->stable_tag, 176 'tested' => $readme->tested, 177 'requires' => $readme->requires, 178 'donate_link' => $readme->donate_link, 179 'version' => $this->plugin['Version'], 180 'header_plugin_uri' => $this->plugin['PluginURI'], 181 'header_author' => $this->plugin['Author'], 182 'header_author_uri' => $this->plugin['AuthorURI'], 183 'header_textdomain' => $this->plugin['TextDomain'], 184 'header_description' => $this->plugin['Description'], 185 'support_resolutions' => 0, 186 ), 158 187 ) ); 159 188 if ( is_wp_error( $plugin_post ) ) { … … 195 224 'new', 196 225 'updated', 226 'about', 227 'admin', 228 'wp-admin', 197 229 ); 198 230 199 231 return in_array( $this->plugin_slug, $reserved_slugs ); 232 } 233 234 /** 235 * Find the plugin readme file. 236 * 237 * Looks for either a readme.txt or readme.md file, prioritizing readme.txt. 238 * 239 * @return string The plugin readme.txt or readme.md filename. 240 */ 241 protected function find_readme_file() { 242 $files = Filesystem::list_files( "{$this->plugin_dir}/{$this->plugin_slug}", false /* non-recursive */, '!^readme\.(txt|md)$!i' ); 243 244 // Prioritize readme.txt 245 foreach ( $files as $file ) { 246 if ( '.txt' === strtolower( substr( $file, -4 ) ) ) { 247 return $file; 248 } 249 } 250 251 return reset( $files ); 200 252 } 201 253
Note: See TracChangeset
for help on using the changeset viewer.