Created
February 7, 2016 02:05
-
-
Save gh640/0163e30e7ab1e2b1764f to your computer and use it in GitHub Desktop.
Drupal 7 でノードの body で使われているフォーマットをカウントする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * node の body のフォーマットをカウントする | |
| * | |
| * 対象はあくまでも body だけなので他のフィールドでの使用有無はわからないため要注意 | |
| * | |
| * 出力サンプル: | |
| * array( | |
| * 'full_html' => 21, | |
| * 'plain_text' => 1, | |
| * ) | |
| * | |
| * @param string $lang 対象言語。 | |
| */ | |
| function node_count_body_format($lang = LANGUAGE_NONE) { | |
| // 状態が「掲載」のノードをすべて読み込む | |
| $all_nodes = node_load_multiple(array(), array('status' => 1)); | |
| // フォーマットのカウントを以下の形で集計する | |
| // キー: full_html | |
| // 値: 43 | |
| $format_count = array(); | |
| foreach ($all_nodes as $nid => $node) { | |
| if (!empty($node->body[$lang][0]['format'])) { | |
| $format = $node->body[$lang][0]['format']; | |
| if (in_array($format, array_keys($format_count))) { | |
| $format_count[$format] += 1; | |
| } | |
| else { | |
| $format_count[$format] = 1; | |
| } | |
| } | |
| } | |
| return $format_count; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment