[WordPress] 外掛分享: Gallery From Regex Matches

WordPress 外掛 Gallery From Regex Matches 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「Gallery From Regex Matches」是 2018-01-07 上架。
  • 目前尚無安裝啟用數,是個很新的外掛。如有要安裝使用,建議多測試確保功能沒問題!
  • 上一次更新是 2019-05-30,距離現在已有 2171 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 4.9.1 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 7.0 以上。
  • 有 1 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

doddo |

外掛標籤

gallery |

內容簡介

這是一個外掛程式,新增了一個短碼:[gallery_from_regex_matches],你需要指定一個正規表示式屬性。程式會在你媒體庫中所有已發佈的影像的描述和標題中尋找匹配,並從這些匹配中建立一個圖庫。

以下是可用的應用範例:

使用方式:[gallery_from_regex_matches regex="lillill" exclude_ids="764"],將會建立所有與「Lillill」相符的圖片的圖庫,但不包含 ID 為 764 的圖片。
如果需要限制匹配結果的數量,也可以在短碼中加入 limit 參數,例如:[gallery_from_regex_matches regex="lillill" exclude_ids="764" limit="10"]。
有時你想搜尋所有「貓」的圖片但排除「catusp」,而你又不想加入文字邊界[[:>:]],這時候可以使用 exclude_regex=catsup,例如:[gallery_from_regex_matches regex="cats" exclude_regex="catsup"]。
此外,你可以使用和 [media] 短碼相同的參數來設定圖庫的樣式,例如:[gallery_from_regex_matches regex="(cat|kitten)" type="square"]。
如果需要使用正規表示式,可以參考MySQL 的正規表示式語法。
有些字元在短碼中不能使用,請參考下方的「注意事項」章節。
這個外掛程式並沒有太多特殊功能,但未來可能會新增功能。

注意事項:

因為程式會將正規表示式作為屬性值嵌入短碼中,而 短碼 API 不允許使用某些在正規表示式中有用的字元,所以有些地方需要注意:

屬性值中不能包含以下字元:
* 方括號:[ ]
* 引號:” ‘
* 大於符號:…]
參照短碼 API 文件,建議使用 HTML 編碼來編碼特殊字元。任何出現在短碼屬性中的使用者輸入都必須進行轉義或去除特殊字元。
如果你需要使用字元集用來描述正規表示式,例如 [a-z],那麼這些字元需要進行編碼。外掛程式接受兩種編碼方式:「html」和「base64」。
目前外掛程式無法協助編碼,但這已列入未來更新的計畫中;因此,現在必須手動進行編碼。
例如:正規表示式 w[0u][0u]ti 可以用以下方式表示:

使用 HTML 編碼:
[gallery_from_regex_matches regex="w[0u][0u]ti" encoding="html"]

使用 Base64 編碼:
[gallery_from_regex_matches regex="d1swdV1bMHVddGk=" encoding="base64"]

在終端機中,可以使用以下指令將一個字串編碼為 Base64:

% echo -n "catsup" | base64
Y2F0c3Vw
% echo -n Y2F0c3Vw | base64 --decode
catsup%

原文外掛簡介

A plugin which adds a shortcode: [gallery_from_regex_matches] in which a regex attribute should be specified. It will then look for matches in the descriptions and titles of all published images in your library, and create a gallery from the matches it finds.

Use for example like this [gallery_from_regex_matches regex="lillill" exclude_ids="764"], and it will generate a gallery of all your pictures of “Lillill”, except the one which has ID 764.
Sometimes it might be advicable to limit the amount of matches. that can be achieved by adding limit to the shortcode. [gallery_from_regex_matches regex="lillill" exclude_ids="764" limit="10"].
Sometimes you want to make a gallery of “cats” but not “catsup”, but you don’t want to add word boundary [[:>:]], in this case you can exclude_regex=catsup. Then it could look something along the line of [gallery_from_regex_matches regex="cats" exclude_regex="catsup"].
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)" type="square"].
The regular expressions follows the MySQL Regexp syntax
Some characters will per default not work inside of the shortcode, see the “Caveats” section.
There are no bells and whistles for this plugin but it could potentionally be added in the futre.

Caveats
Since the regex used by the plugin is specified as an attribute value inside of a shortcode, and the Shortcode Api disallows the use of certain characters which could be a part of a valid, useful regex, there are some things to consider.

Attribute values must never contain the following characters:
* Square braces: [ ]
* Quotes: ” ‘
[ … ]
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.

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”
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’
For example, for regex w[0u][0u]ti can be expressed either:

With HTML encoding:
[gallery_from_regex_matches regex="w[0u][0u]ti" encoding="html"]
With Base64 encoding:
[gallery_from_regex_matches regex="d1swdV1bMHVddGk=" encoding="base64"]
To encode a string to base64, it can be done from the terminal like this:
% echo -n "catsup" | base64
Y2F0c3Vw
% echo -n Y2F0c3Vw | base64 --decode
catsup%

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Gallery From Regex Matches」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.1 | 0.5 | 0.5.1 | 0.6.0 | 0.6.1 | 0.6.2 | 0.6.3 | trunk |

延伸相關外掛(你可能也想知道)

文章
Filter
Apply Filters
Mastodon