Skip to content

Commit

Permalink
placeholderの追加 (#58)
Browse files Browse the repository at this point in the history
プレースホルダーに `post_date`、`post_title_count`、`post_content_count`
の3つを追加してみました。

後者の2つは標準機能が良いか、フックでサイト個別にカスタマイズが良いか微妙な気もしましたが…。
適切でないようでしたらご意見いただけますと有り難いです。

## 投稿日時

`post_date` で投稿の投稿日時を出力。
`post_date:Ymd` のようにフォーマット指定ができる。

```
(例)
`post_date`
 ↓
<meta name="gacommunicator:post_date" content="2023-06-20 17:00:29" />

`post_date:Ymd`
 ↓
<meta name="gacommunicator:post_date:Ymd" content="20230620" />
```

## 投稿タイトルの文字数

`post_title_count` で投稿のタイトルの文字数を出力。
文字数は半角、全角問わず1文字とカウントする。

```
(例)
`post_title_count`
 ↓
<meta name="gacommunicator:post_title_count" content="36" />
```

## 投稿本文の文字数

`post_content_count` で投稿の本文の文字数を出力。
文字数は半角、全角問わず1文字とカウントする。

```
(例)
`post_content_count`
 ↓
<meta name="gacommunicator:post_content_count" content="736" />
```
  • Loading branch information
fumikito authored Feb 9, 2024
2 parents 373a457 + 537e122 commit e52e1cf
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 52 deletions.
Binary file modified languages/ga-communicator-ja.mo
Binary file not shown.
83 changes: 53 additions & 30 deletions languages/ga-communicator-ja.po
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2024-01-11 16:35+0900\n"
"PO-Revision-Date: 2024-01-11 16:38+0900\n"
"POT-Creation-Date: 2024-01-30 14:00+0900\n"
"PO-Revision-Date: 2024-01-30 14:02+0900\n"
"Last-Translator: Takahashi Fumiki <takahashi.fumiki@hametuha.co.jp>\n"
"Language-Team: \n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.3.2\n"
"X-Generator: Poedit 2.4.3\n"
"X-Poedit-Basepath: .\n"

#: assets/js/ga-custom-dimensions.js:52
msgid "Registered Dimension"
msgstr "登録済みディメンション"

#: ga-communicator.php:50
msgid "Composer file is missing. Please run composer install."
msgstr "Composerファイルが見つかりません。composer installを実行してください。"
Expand All @@ -37,6 +41,7 @@ msgstr ""
msgid "data attributes must be valid JSON format."
msgstr "data属性は有効なJSON形式である必要があります。"

#. translators: %1$s is account, %2$s property.
#: src/Kunoichi/GaCommunicator/Api/Dimensions.php:49
#, php-format
msgid "Account and Property is required. (%1$s/%2$s)"
Expand All @@ -63,6 +68,7 @@ msgstr ""
msgid "No results found."
msgstr "結果が見つかりませんでした。"

#. translators: %s is property id.
#: src/Kunoichi/GaCommunicator/Command.php:62
#, php-format
msgid "Getting web properties of %s..."
Expand Down Expand Up @@ -92,16 +98,17 @@ msgstr "設定"
msgid "Sandbox"
msgstr "サンドボックス"

#. translators: %s is document url.
#: src/Kunoichi/GaCommunicator/Screen/Settings.php:124
#, php-format
msgid ""
"Try to interact GA data. Check <a href=\"%s\" target=\"_blank\" "
"rel=\"noopener noreferrer\">the documentation</a> and confirm what you get "
"with your JSON. WP-CLI is also helpful."
"Try to interact GA data. Check <a href=\"%s\" target=\"_blank\" rel="
"\"noopener noreferrer\">the documentation</a> and confirm what you get with "
"your JSON. WP-CLI is also helpful."
msgstr ""
"GAとデータをやり取りしてみてください。<a href=\"%s\" target=\"_blank\" "
"rel=\"noopener noreferrer\">ドキュメント</a>を参照し、JSONで取得できるデータ"
"を確認しましょう。WP-CLIも利用できます。"
"GAとデータをやり取りしてみてください。<a href=\"%s\" target=\"_blank\" rel="
"\"noopener noreferrer\">ドキュメント</a>を参照し、JSONで取得できるデータを確"
"認しましょう。WP-CLIも利用できます。"

#: src/Kunoichi/GaCommunicator/Screen/Settings.php:127
msgid "JSON to API"
Expand Down Expand Up @@ -135,12 +142,13 @@ msgstr "サービスアカウントキー"
msgid "Service account is defined programmatically."
msgstr "サービスアカウントはプログラムで定義済みです。"

#. translators: %s is URL.
#: src/Kunoichi/GaCommunicator/Screen/Settings.php:199
#, php-format
msgid ""
"You can get a service account key in JSON format from Google API Library. "
"For more detail, please check the <a href=\"%s\" target=\"_blank\" "
"rel=\"noopener,noreferrer\">document</a>."
"For more detail, please check the <a href=\"%s\" target=\"_blank\" rel="
"\"noopener,noreferrer\">document</a>."
msgstr ""
"Google APIライブラリのJSON形式サービスアカウントキー。詳細は<a href=\"%s\" "
"target=\"_blank\" rel=\"noopener,noreferrer\">ドキュメント</a>をチェックして"
Expand Down Expand Up @@ -270,12 +278,13 @@ msgstr "置換結果"
msgid "Meta tags"
msgstr "metaタグ"

#. translators: %s is link URL.
#: src/Kunoichi/GaCommunicator/Screen/Settings.php:374
#, php-format
msgid ""
"These tags are rendered as meta tags for Google Tag Manager. See <a "
"href=\"%s\" target=\"_blank\" rel=\"noopener noreferrer\">our wiki</a> for "
"more details."
"These tags are rendered as meta tags for Google Tag Manager. See <a href=\"%s"
"\" target=\"_blank\" rel=\"noopener noreferrer\">our wiki</a> for more "
"details."
msgstr ""
"これらのタグはmetaタグとしてGoogle タグマネージャー用に出力されます。詳細は "
"<a href=\"%s\" target=\"_blank\" rel=\"noopener noreferrer\">Wiki</a> をご覧"
Expand Down Expand Up @@ -356,15 +365,34 @@ msgid "Post type in singular page."
msgstr "シングルページの投稿タイプ。"

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:42
msgid ""
"Single post date. If page is not singular, always empty string. You can also "
"specify the format like <code>%post_date:Y-m-d%</code>."
msgstr ""
"投稿の投稿日時。もしページがシングルページでなければ、空文字になります。"
"<code>%post_date:Y-m-d%</code> のように形式を指定することもできます。"

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:50
msgid ""
"Character count of single post title. If page is not singular, always 0."
msgstr ""
"投稿のタイトル文字数。もしページがシングルページでなければ、0になります。"

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:58
msgid ""
"Character count of single post content. If page is not singular, always 0."
msgstr "投稿の本文文字数。もしページがシングルページでなければ、0になります。"

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:66
msgid "Blog ID."
msgstr "ブログID。"

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:50
#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:74
msgid "If current page is a singular post, return author ID. Else, always 0."
msgstr ""
"現在のページが記事ページなら投稿者IDを返します。それ以外は0になります。"

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:58
#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:82
msgid ""
"On single page, returns CSV value for all assigned terms in any taxonomy "
"like <code>_11_,20_,_30_</code>. Else, always empty string."
Expand All @@ -373,12 +401,12 @@ msgstr ""
"をCSV形式 <code>_11_,20_,_30_</code>で表示します。その他の場合は空文字になり"
"ます。"

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:80
#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:104
msgid "On taxonomy archive page, returns term ID. Else, always 0"
msgstr ""
"タクソノミーアーカイブの場合はタームIDを返します。それ以外では0になります。"

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:92
#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:116
msgid "On taxonomy archive page, returns taxonomy name. Else, always empty."
msgstr ""
"タクソノミーアーカイブの場合はタクソノミー名を返します。それ以外では空文字に"
Expand Down Expand Up @@ -458,14 +486,6 @@ msgstr "これは上記の相対的な日時設定を上書きします。"
msgid "Default"
msgstr "デフォルト"

#: assets/js/ga-custom-dimensions.js:52
msgid "Registered Dimension"
msgstr "登録済みディメンション"

#: assets/js/ga-custom-dimensions.js:62
msgid "Scope"
msgstr "スコープ"

#. Plugin Name of the plugin/theme
msgid "Google Analytics Communicator"
msgstr "Google アナリティクス コミュニケーター"
Expand All @@ -486,6 +506,9 @@ msgstr "株式会社 KUNOICHI"
msgid "https://kunoichiwp.com"
msgstr "https://kunoichiwp.com"

#~ msgid "Scope"
#~ msgstr "スコープ"

#~ msgid "Universal Analytics Account Setting"
#~ msgstr "ユニバーサル・アナリティクス・アカウント設定"

Expand Down Expand Up @@ -1475,8 +1498,8 @@ msgstr "https://kunoichiwp.com"
#, fuzzy
#~ msgid "rel:"
#~ msgstr ""
#~ "スレッドを開始するには、 <a class=\"alert-link\" rel=\"nofollow\" "
#~ "href=\"%s\">ログイン</a>してください。"
#~ "スレッドを開始するには、 <a class=\"alert-link\" rel=\"nofollow\" href="
#~ "\"%s\">ログイン</a>してください。"

#, fuzzy
#~ msgid "identity"
Expand Down Expand Up @@ -1858,8 +1881,8 @@ msgstr "https://kunoichiwp.com"
#, fuzzy
#~ msgid "Blank"
#~ msgstr ""
#~ "お探しの条件に合うものはありませんでした。<br />条件を変更するか、<a "
#~ "href=\"%s\" target=\"_blank\">新規作成</a>してください。"
#~ "お探しの条件に合うものはありませんでした。<br />条件を変更するか、<a href="
#~ "\"%s\" target=\"_blank\">新規作成</a>してください。"

#, fuzzy
#~ msgid "Membership"
Expand Down
61 changes: 39 additions & 22 deletions languages/ga-communicator.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
msgid ""
msgstr ""
"Project-Id-Version: Google Analytics Communicator\n"
"POT-Creation-Date: 2024-01-11 16:35+0900\n"
"POT-Creation-Date: 2024-01-30 14:00+0900\n"
"PO-Revision-Date: 2020-06-12 13:57+0900\n"
"Last-Translator: Takahashi Fumiki <takahashi.fumiki@hametuha.co.jp>\n"
"Language-Team: Takahashi Fumiki <takahashi.fumiki@hametuha.co.jp>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"X-Generator: Poedit 3.3.2\n"
"X-Generator: Poedit 2.4.3\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
"X-Poedit-WPHeader: ga-communicator.php\n"
Expand All @@ -25,6 +25,10 @@ msgstr ""
"X-Poedit-SearchPathExcluded-3: wp\n"
"X-Poedit-SearchPathExcluded-4: tests\n"

#: assets/js/ga-custom-dimensions.js:52
msgid "Registered Dimension"
msgstr ""

#: ga-communicator.php:50
msgid "Composer file is missing. Please run composer install."
msgstr ""
Expand All @@ -45,6 +49,7 @@ msgstr ""
msgid "data attributes must be valid JSON format."
msgstr ""

#. translators: %1$s is account, %2$s property.
#: src/Kunoichi/GaCommunicator/Api/Dimensions.php:49
#, php-format
msgid "Account and Property is required. (%1$s/%2$s)"
Expand All @@ -69,6 +74,7 @@ msgstr ""
msgid "No results found."
msgstr ""

#. translators: %s is property id.
#: src/Kunoichi/GaCommunicator/Command.php:62
#, php-format
msgid "Getting web properties of %s..."
Expand Down Expand Up @@ -98,12 +104,13 @@ msgstr ""
msgid "Sandbox"
msgstr ""

#. translators: %s is document url.
#: src/Kunoichi/GaCommunicator/Screen/Settings.php:124
#, php-format
msgid ""
"Try to interact GA data. Check <a href=\"%s\" target=\"_blank\" "
"rel=\"noopener noreferrer\">the documentation</a> and confirm what you get "
"with your JSON. WP-CLI is also helpful."
"Try to interact GA data. Check <a href=\"%s\" target=\"_blank\" rel="
"\"noopener noreferrer\">the documentation</a> and confirm what you get with "
"your JSON. WP-CLI is also helpful."
msgstr ""

#: src/Kunoichi/GaCommunicator/Screen/Settings.php:127
Expand Down Expand Up @@ -138,12 +145,13 @@ msgstr ""
msgid "Service account is defined programmatically."
msgstr ""

#. translators: %s is URL.
#: src/Kunoichi/GaCommunicator/Screen/Settings.php:199
#, php-format
msgid ""
"You can get a service account key in JSON format from Google API Library. "
"For more detail, please check the <a href=\"%s\" target=\"_blank\" "
"rel=\"noopener,noreferrer\">document</a>."
"For more detail, please check the <a href=\"%s\" target=\"_blank\" rel="
"\"noopener,noreferrer\">document</a>."
msgstr ""

#: src/Kunoichi/GaCommunicator/Screen/Settings.php:208
Expand Down Expand Up @@ -266,12 +274,13 @@ msgstr ""
msgid "Meta tags"
msgstr ""

#. translators: %s is link URL.
#: src/Kunoichi/GaCommunicator/Screen/Settings.php:374
#, php-format
msgid ""
"These tags are rendered as meta tags for Google Tag Manager. See <a "
"href=\"%s\" target=\"_blank\" rel=\"noopener noreferrer\">our wiki</a> for "
"more details."
"These tags are rendered as meta tags for Google Tag Manager. See <a href="
"\"%s\" target=\"_blank\" rel=\"noopener noreferrer\">our wiki</a> for more "
"details."
msgstr ""

#: src/Kunoichi/GaCommunicator/Screen/Settings.php:381
Expand Down Expand Up @@ -349,24 +358,40 @@ msgid "Post type in singular page."
msgstr ""

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:42
msgid "Blog ID."
msgid ""
"Single post date. If page is not singular, always empty string. You can "
"also specify the format like <code>%post_date:Y-m-d%</code>."
msgstr ""

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:50
msgid "If current page is a singular post, return author ID. Else, always 0."
msgid ""
"Character count of single post title. If page is not singular, always 0."
msgstr ""

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:58
msgid ""
"Character count of single post content. If page is not singular, always 0."
msgstr ""

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:66
msgid "Blog ID."
msgstr ""

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:74
msgid "If current page is a singular post, return author ID. Else, always 0."
msgstr ""

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:82
msgid ""
"On single page, returns CSV value for all assigned terms in any taxonomy "
"like <code>_11_,20_,_30_</code>. Else, always empty string."
msgstr ""

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:80
#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:104
msgid "On taxonomy archive page, returns term ID. Else, always 0"
msgstr ""

#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:92
#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:116
msgid "On taxonomy archive page, returns taxonomy name. Else, always empty."
msgstr ""

Expand Down Expand Up @@ -440,14 +465,6 @@ msgstr ""
msgid "Default"
msgstr ""

#: assets/js/ga-custom-dimensions.js:52
msgid "Registered Dimension"
msgstr ""

#: assets/js/ga-custom-dimensions.js:62
msgid "Scope"
msgstr ""

#. Plugin Name of the plugin/theme
msgid "Google Analytics Communicator"
msgstr ""
Expand Down
31 changes: 31 additions & 0 deletions src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ protected function init() {
return is_singular() ? get_queried_object()->post_type : 0;
},
],
[
'name' => 'post_date',
'type' => 'string',
'description' => __( 'Single post date. If page is not singular, always empty string. You can also specify the format like <code>%post_date:Y-m-d%</code>.', 'ga-communicator' ),
'callback' => function ( $format = 'Y-m-d H:i:s' ) {
return is_singular() ? mysql2date( $format, get_queried_object()->post_date ) : '';
},
],
[
'name' => 'post_title_count',
'type' => 'int',
'description' => __( 'Character count of single post title. If page is not singular, always 0.', 'ga-communicator' ),
'callback' => function () {
return is_singular() ? mb_strlen( get_queried_object()->post_title ) : 0;
},
],
[
'name' => 'post_content_count',
'type' => 'int',
'description' => __( 'Character count of single post content. If page is not singular, always 0.', 'ga-communicator' ),
'callback' => function () {
return is_singular() ? mb_strlen( str_replace( [ "\n", "\r" ], '', get_the_content() ) ) : 0;
},
],
[
'name' => 'blog_id',
'type' => 'int',
Expand Down Expand Up @@ -129,6 +153,13 @@ public function get() {
public function replace( $tag ) {
foreach ( $this->place_holders as $place_holder ) {
$tag = str_replace( "%{$place_holder['name']}%", $place_holder['callback'](), $tag );
// Detect placeholder with parameter.
if ( preg_match_all( "/%{$place_holder['name']}:(.*)%/", $tag, $matches ) ) {
foreach ( $matches[0] as $matched_key ) {
list( $placeholder_key, $parameter ) = explode( ':', str_replace( '%', '', $matched_key ), 2 );
$tag = str_replace( $matched_key, $place_holder['callback']( $parameter ), $tag );
}
}
}
return $tag;
}
Expand Down
Loading

0 comments on commit e52e1cf

Please sign in to comment.