Changeset 1802320
- Timestamp:
- 01/13/2018 12:16:53 PM (8 years ago)
- Location:
- gallery-from-regex-matches/trunk
- Files:
-
- 2 edited
-
gallery-from-regex-matches.php (modified) (6 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gallery-from-regex-matches/trunk/gallery-from-regex-matches.php
r1800844 r1802320 2 2 Plugin Name: Gallery From Regex Matches 3 3 Plugin URI: https://wordpress.org/plugins/gallery-from-regex-matches/ 4 Version: 0.5 4 Version: 0.5.1 5 5 License: GPL2 6 6 Description: Maintain a gallery by including all published images in your library which match a regex (in name, title or description). … … 17 17 /** 18 18 * Callback from the gallery_from_regex_matches shortcode. calls gallery_shortcode end echos the output to create a gallery. 19 * 20 * @since 0.5.1 Added the $encoding argument. 19 21 * @since 0.0.1 20 22 * … … 24 26 * @type string $regex Regular expression to match against all published attachents, matches gets added to gallery. 25 27 * @type string $exclude_ids A comma-separated list of IDs of attachments filter out if matched by the regex. 28 * @type string $encoding If the regex field is encoded (to escape special characters), this value specifies appropriate encoding. 26 29 * @see gallery_shortcode for the rest of the valid $attr values, 27 30 * } … … 39 42 40 43 if (!empty($attr['regex'])){ 44 $regex = $attr['regex']; 45 46 // Handle the cases in which the regex is encoded. 47 if (!empty($attr['encoding'])){ 48 if ($attr['encoding'] === 'html'){ 49 $regex = html_entity_decode($regex, ENT_QUOTES, 'UTF-8'); 50 } elseif ($attr['encoding'] === 'base64') { 51 $regex = base64_decode($regex); 52 } 53 } 54 41 55 if (!empty($attr['ids'])){ 42 56 // handle that later … … 52 66 $search_fields = Array($image->post_name, $image->post_excerpt, $image->post_title); 53 67 54 if (preg_grep($attr['regex'], $search_fields) 55 and !in_array($image->ID, $exclude_ids)){ 68 if (preg_grep($regex, $search_fields) and !in_array($image->ID, $exclude_ids)){ 56 69 array_push($ids, $image->ID); 57 70 } … … 65 78 unset($attr['regex']); 66 79 unset($attr['exclude_ids']); 80 unset($attr['encoding']); 67 81 68 82 echo (gallery_shortcode($attr)); -
gallery-from-regex-matches/trunk/readme.txt
r1801309 r1802320 5 5 Requires PHP: 7.0 6 6 Tested up to: 4.9.1 7 Stable tag: 0.5 7 Stable tag: 0.5.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 17 17 * Use for example like this `[gallery_from_regex_matches regex="/lillill/i" exclude_ids="764"]`, and it will generate a gallery of all your pictures of "Lillill", except the one which has ID 764. 18 18 * The same params (except for `ids`) as for the `[media]` shortcode can be used (as this plugin calls that shortcodes callback function (`gallery_shortcode()`) to generate the gallery), so if you want to specify a particular type (style) of gallery from for example your cat pictures , this might do the trick: `[gallery_from_regex_matches regex="/(cat|kitten)/i" type="square"]`. 19 * The regular expressions follows the [PHP pcre pattern syntax](http://php.net/manual/en/reference.pcre.pattern.syntax.php) 20 * Some characters will per default not work inside of the shortcode, see the "Caveats" section. 19 21 * There are no bells and whistles for this plugin but it could potentionally be added in the futre. 20 22 23 == Caveats == 24 25 Since the regex used by the plugin is specified as an attribute value inside of a shortcode, and the [Shortcode Api](https://codex.wordpress.org/Shortcode_API) disallows the use of certain characters which could be a part of a valid, useful regex, there are some things to consider. 26 27 28 > Attribute values must never contain the following characters: 29 > * Square braces: [ ] 30 > * Quotes: " ' 31 > 32 > [ ... ] 33 > The recommended method of escaping special characters in shortcode attributes is HTML encoding. Most importantly, any user input appearing in a shortcode attribute must be escaped or stripped of special characters. 34 35 * if in the regex you need to macth a character set `[a-z]`, then (following the shortcode Api documentation guidline), they need to be encoded. There are two encodings which the plugin accepts: "html" and "base64" 36 * Currently there is no way to encode these things with help of the plugin, although it is planned for a future release, so the regexes must be encoded manually for now' 37 For example, for regex `/w[0u][0u]t/i` can be expressed either: 38 39 1. With HTML encoding: `[gallery_from_regex_matches regex="/w[0u][0u]t/i" encoding="html"]` 40 2. With Base64 encoding: `[gallery_from_regex_matches regex="L3dbMHVdWzB1XXQvaQ==" encoding="base64"]` 21 41 22 42 == Installation == … … 27 47 == Changelog == 28 48 49 = 0.5.1 = 50 * Add possibility of decoding encoded regexes, so that special characters which would collide with the Shortcode Api can still be used in them. 51 29 52 = 0.5 = 30 53 * Search also title field
Note: See TracChangeset
for help on using the changeset viewer.