TypeSquare Webfonts SAKURA for SAKURA Rental Server - Version 3.1.0

Version Description

Download this release

Release Info

Developer sakurainternet
Plugin Icon 128x128 TypeSquare Webfonts SAKURA for SAKURA Rental Server
Version 3.1.0
Comparing to
See all releases

Code changes from version 3.0.0 to 3.1.0

inc/admin-root.php CHANGED
@@ -1,59 +1,66 @@
1
  <?php
2
- class TypeSquare_Admin_Root extends TypeSquare_Admin_Base {
3
- private static $instance;
4
- private static $text_domain;
5
- private function __construct(){}
6
-
7
-
8
- public static function get_instance() {
9
- if ( ! isset( self::$instance ) ) {
10
- $c = __CLASS__;
11
- self::$instance = new $c();
12
- }
13
- return self::$instance;
14
- }
15
-
16
- public function typesquare_post_metabox() {
17
- $fonts = TypeSquare_ST_Fonts::get_instance();
18
- $param = $fonts->get_fonttheme_params();
19
- if ( 'false' == $param['typesquare_themes']['show_post_form'] || ! $param['typesquare_themes']['show_post_form'] ) {
20
- return;
21
- }
22
- $post_type = array( 'post', 'page' );
23
- foreach ( $post_type as $type ) {
24
- add_meta_box( 'typesquare_post_metabox', __( 'TS Webfonts for SAKURA RS', self::$text_domain ), array( $this, 'typesquare_post_metabox_inside' ), $type, 'advanced', 'low' );
25
- }
26
- }
27
-
28
- public function typesquare_post_metabox_inside() {
29
- $html = '';
30
- $html .= '<p>'. __( 'この記事に適用するフォントを選択してください', self::$text_domain ) . '</p>';
31
-
32
- $html .= $this->_get_post_font_theme_selector();
33
- $html .= '<input type="hidden" name="typesquare_nonce_postmeta" id="typesquare_nonce_postmeta" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
34
- echo $html;
35
- }
36
-
37
- private function _get_post_font_theme_selector() {
38
- $html = '';
39
- $fonts = TypeSquare_ST_Fonts::get_instance();
40
- $all_font_theme = $fonts->load_all_font_data( );
41
- $selected_theme = $fonts->get_selected_post_fonttheme( get_the_ID() );
42
- $option = '';
43
- $option .= "<option value='false'>テーマを設定しない</option>";
44
- foreach ( $all_font_theme as $key => $fonttheme ) {
45
- $fonttheme_name = $this->get_fonts_text( $fonttheme['name'] );
46
- $font_text = $this->_get_fonttheme_text( $fonttheme );
47
- $selected = '';
48
- if ( $key === $selected_theme ) {
49
- $selected = 'selected';
50
- }
51
- $option .= "<option value='{$key}' {$selected}>";
52
- $option .= "{$fonttheme_name} ( {$font_text} )";
53
- $option .= '</option>';
54
- }
55
- $html .= '<h3>'. __( 'フォントテーマから選ぶ', self::$text_domain ) . '</h3>';
56
- $preview = <<<EOM
 
 
 
 
 
 
 
57
  jQuery( document ).ready(function() {
58
  window.onload = function () {
59
  theme_preview_new();
@@ -96,171 +103,176 @@ jQuery( document ).ready(function() {
96
  }
97
  });
98
  EOM;
99
- $html = '<script>';
100
- $html .= $preview;
101
- $html .= '</script>';
102
- $html .= '<div id="choiceThemeNew">';
103
- $html .= "<select name='typesquare_fonttheme[theme]' class='font_theme_select_pre_new'>{$option}</select>";
104
- $html .= '<h3>プレビュー</h3>';
105
- $html .= '<div><p class="title">見出し:<p class="pre_title"></p></p></div>';
106
- $html .= '<div><p class="title">リード:<p class="pre_lead"></p></p></div>';
107
- $html .= '<div><p class="title">本文:<p class="pre_body"></p></p></div>';
108
- $html .= '<div><p class="title">太字:<p class="pre_bold"></p></p></div>';
109
- $html .= '<input type="hidden" id="theme_preview" />';
110
- foreach ($all_font_theme as $fonttheme_key => $fonttheme) {
111
- $html .= "<input type='hidden' id='selected-get-{$fonttheme_key}' value='" . json_encode($fonttheme) . "'>";
112
- }
113
- $html .= '</div>';
114
- return $html;
115
- }
116
-
117
- public function typesquare_save_post( $post_id ) {
118
- if ( ! isset( $_POST['typesquare_nonce_postmeta'] ) ) {
119
- return;
120
- }
121
- //Verify
122
- if ( ! wp_verify_nonce( $_POST['typesquare_nonce_postmeta'], plugin_basename( __FILE__ ) ) ) {
123
- return $post_id;
124
- }
125
- // if auto save
126
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
127
- return $post_id;
128
- }
129
-
130
- // permission check
131
- if ( 'page' == $_POST['post_type'] ) {
132
- if ( ! current_user_can( 'edit_page', $post_id ) ) {
133
- return $post_id;
134
- }
135
- } else {
136
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
137
- return $post_id;
138
- }
139
- }
140
-
141
- // save action
142
- $fonttheme = $_POST['typesquare_fonttheme'];
143
- $current_option = get_post_meta( $post_id, 'typesquare_fonttheme' );
144
- $fonts = TypeSquare_ST_Fonts::get_instance();
145
- if ( isset( $current_option[0] ) ) {
146
- $current = $current_option[0];
147
- } else {
148
- $current = $fonttheme;
149
- }
150
- $font['theme'] = esc_attr( $fonttheme['theme'] );
151
- update_post_meta( $post_id, 'typesquare_fonttheme', $font );
152
- return $post_id;
153
- }
154
-
155
- private function get_fonts_text( $fonts ) {
156
- if ( is_array( $fonts ) ) {
157
- $text_font = '';
158
- foreach ( $fonts as $key => $font ) {
159
- $text_font .= esc_attr( $font );
160
- if ( count( $fonts ) - 1 > $key ) {
161
- $text_font .= ' + ';
162
- }
163
- }
164
- } else {
165
- $text_font = esc_attr( $fonts );
166
- }
167
- return $text_font;
168
- }
169
-
170
- public function typesquare_admin_menu() {
171
- $param = $this->get_auth_params();
172
- $option_name = 'typesquare_auth';
173
- $nonce_key = TypeSquare_ST::OPTION_NAME;
174
- $auth_param = $this->get_auth_params();
175
- echo "<style type='text/css' rel='stylesheet'>";
176
- echo "</style>";
177
- echo "<div class='wrap'>";
178
- echo '<h2>'. __( 'TS Webfonts for SAKURA RS' , self::$text_domain ). '</h2>';
179
- do_action( 'typesquare_add_setting_before' );
180
- echo '<hr />';
181
- echo '<span><h3 class="toggleText toggleAdvanced_font mTop20">'. __( '投稿記事フォント設定', self::$text_domain ). '<span class="advancedTriangle advancedTriangle_font">▼</span></h3></span>';
182
- echo "<div class='ts-custome_form_font hidden'>";
183
- echo $this->_get_post_font_form($auth_param);
184
- echo '</div>';
185
- echo '</div>';
186
-
187
- echo '<hr/>';
188
- echo '<span><h3 class="toggleText toggleAdvanced_site mTop20">'. __('サイトフォント設定', self::$text_domain). '<span class="advancedTriangle advancedTriangle_site">▼</span></h3></span>';
189
- echo "<div class='ts-custome_form_site hidden'>";
190
- echo $this->_get_site_font_form();
191
- echo '</div>';
192
- echo '<hr/>';
193
- echo '<span><h3 class="toggleText toggleAdvanced_article mTop20">'. __('カスタムテーマ編集', self::$text_domain). '<span class="advancedTriangle advancedTriangle_article">▼</span></h3></span>';
194
- echo "<div class='ts-custome_form_article hidden'>";
195
- echo '<div class="ts-custum_block">';
196
- echo $this->_get_font_theme_custom_form();
197
- echo '</div>';
198
- echo '</div>';
199
- do_action( 'typesquare_add_setting_after' );
200
- }
201
-
202
- private function _get_post_font_form($auth_param) {
203
- $html = "<form method='post' action=''>";
204
- $html .= '<p>投稿記事に対するWebフォント適用方法を設定します。</p>';
205
- $html .= '<div class="block_wrap">';
206
- $html .= '<p class="block_title">'. __('投稿記事に適用するフォント設定', self::$text_domain). '</p>';
207
- $html .= '<div class="label_wrapper">';
208
- $html .= '<label class="custum_form_ladio"><input name="fontThemeUseType" type="radio" value="1">指定しない';
209
- $html .= '<p class="setting_read">フォントテーマを適用しません。</p>';
210
- $html .= '</label>';
211
- $html .= '<label class="custum_form_ladio"><input name="fontThemeUseType" type="radio" value="2" class="radio_custum_font_theme">共通テーマ指定';
212
- $html .= '<p class="setting_read">全ての投稿に設定したフォントテーマが適用されます。</p>';
213
- $html .= '</label>';
214
- $html .= $this->_get_font_theme_form();
215
- $html .= '<label class="custum_form_ladio"><input name="fontThemeUseType" type="radio" value="3">個別テーマ指定';
216
- $html .= '<p class="setting_read">投稿ごとに設定したフォントテーマが適用されます。</p>';
217
- $html .= '</label>';
218
- $html .= '<label class="custum_form_ladio"><input name="fontThemeUseType" type="radio" value="4">直接指定(上級者向け)';
219
- $html .= '<p class="setting_read">CSSセレクターを指定して適用するウェブフォントを選べます。</p>';
220
- $html .= '</label>';
221
- $html .= $this->_get_font_target_form();
222
-
223
- $fonts = TypeSquare_ST_Fonts::get_instance();
224
- $fonttheme_params = $fonts->get_fonttheme_params();
225
-
226
- if (empty($auth_param['typesquare_auth']['fontThemeUseType'])) {
227
- if (empty($fonttheme_params['typesquare_themes']['font_theme']) || $fonttheme_params['typesquare_themes']['font_theme'] === "false") {
228
- $html .= '<input type="hidden" id="activeAdvanced_theme" value="1">';
229
- } else {
230
- $html .= '<input type="hidden" id="activeAdvanced_theme" value="2">';
231
- }
232
- } else {
233
- if (!empty($fonttheme_params['typesquare_themes']['font_theme']) && $auth_param['typesquare_auth']['fontThemeUseType'] === "1") {
234
- $html .= '<input type="hidden" id="activeAdvanced_theme" value="2">';
235
- } else {
236
- $html .= '<input type="hidden" id="activeAdvanced_theme" value="' . $auth_param['typesquare_auth']['fontThemeUseType'] . '">';
237
- }
238
- }
239
-
240
- $html .= '</div>';
241
- $html .= '</div>';
242
- $html .= get_submit_button( __( '投稿フォント設定を保存する', self::$text_domain ) );
243
- $html .= '</form>';
244
- return $html;
245
- }
246
-
247
- private function _get_auth_form($auth_param) {
248
- $html = '';
249
- $nonce_key = TypeSquare_ST::OPTION_NAME;
250
- $html .= "<form method='post' action='' id='authForm'>";
251
- $html .= wp_nonce_field( $nonce_key, self::MENU_ID , true , false );
252
- $html .= "<table class='widefat form-table'>";
253
- $html .= '<tbody>';
254
- $param = $this->get_auth_params();
255
- $option_name = 'typesquare_auth';
256
- foreach ( $param['typesquare_auth_keys'] as $key => $title ) {
257
- $html .= "<tr><td>";
258
- $name = "{$option_name}[{$key}]";
259
- $type = 'hidden';
260
- $name = esc_attr( $name );
261
- $id = esc_attr( $key );
262
- $value = "SAKURA";
263
- $html .= "<input
 
 
 
 
 
264
  name='{$name}'
265
  id='{$id}'
266
  value='{$value}'
@@ -269,247 +281,258 @@ EOM;
269
  data-parsley-trigger='change'
270
  class='regular-text code'
271
  />";
272
- $html .= '</td></tr>';
273
- }
274
- $html .= '</tbody>';
275
- $html .= '</div>';
276
- $html .= '</table>';
277
- if ( '' !== $auth_param['typesquare_auth']['typesquare_id'] ) {
278
- $html .= '<div class="block_wrap">';
279
- $html .= "<table class='widefat form-table'>";
280
- $html .= '<tbody>';
281
- $html .= $this->_get_font_fade_form();
282
- $html .= $this->_get_auto_load_font_form();
283
- $html .= $this->_get_apply_to_hidden_form();
284
- $html .= $this->_get_apply_to_pseudo_form();
285
- $html .= '</tbody>';
286
- $html .= "</table>";
287
- $html .= '</div>';
288
- }
289
-
290
- $html .= $this->_update_font_list_form();
291
- $html .= get_submit_button( __( 'TypeSquare設定を保存する', self::$text_domain ) );
292
-
293
- $html .= '</form>';
294
- return $html;
295
- }
296
-
297
- private function _get_ad_area() {
298
- $html = '<script>';
299
- $endpoint = path_join( TS_PLUGIN_URL , 'inc/font.json' );
300
- $html .= "var json_endpoint = '{$endpoint}';";
301
- if ( $font_list ) {
302
- $html .= "var current_font = ". json_encode( $font_list ) .';';
303
- } else {
304
- $html .= "var current_font = false;";
305
- }
306
- $html .= $script;
307
- $html .= '</script>';
308
- $html .= "<div class='ts-ad-area'>";
309
- $messages[] = __( '・ご利用にはTypeSquareの会員登録が必要です (<a href="https://typesquare.com">https://typesquare.com</a>)', self::$text_domain );
310
- $messages[] = __( '・利用プランによっては利用可能な書体数に上限がありますので、上限を超えて設定したフォントは配信されません。', self::$text_domain );
311
- $messages[] = ' '. __( '・無料プラン:1書体', self::$text_domain );
312
- $messages[] = ' '. __( '', self::$text_domain );
313
- $messages[] = ' '. __( '・スタンダードIプラン:3書体', self::$text_domain );
314
- $html .= '<ul>';
315
- $html .= '<li style="padding-bottom: 5px;"><span href="#" class="toggleLimit toggleText">' . __( 'ご利用上の注意', self::$text_domain ). '</span><span class="textMute elimitTriangl" style="float: right;">▼</span></li>';
316
- $html .= '<div id="ts-ad-area-messages" class="ts-hidden">';
317
- foreach ( $messages as $message ) {
318
- $html .= "<li>{$message}</li>";
319
- }
320
- $html .= "<p><a href='https://typesquare.com/ja/service/plan' target='_blank' class='button button-hero'>". __( '→プランを見てみる', self::$text_domain ) . '</a></p>';
321
- $html .= '</div>';
322
- $html .= '</ul>';
323
- $html .= '</div>';
324
- $html .= '<div class="mTop30">';
325
- $html .= '<h3 class="mBottom10">'. __( 'ご利用方法' , self::$text_domain ). '</h3>';
326
- $html .= '<div>'. __( 'TypeSquare Webfontsについての内容を説明しています' , self::$text_domain ). '</div>';
327
- $html .= '<div>'. __( '詳しくは' , self::$text_domain ). "<a href='https://blog.typesquare.com/archives/55354' target='_blank'>". __( 'こちら' , self::$text_domain ). '</a></div>';
328
- $html .= '</div>';
329
-
330
- return $html;
331
- }
332
-
333
- private function _get_font_fade_form() {
334
- $option_name = 'typesquare_fonttheme';
335
- $fonts = TypeSquare_ST_Fonts::get_instance();
336
- $param = $fonts->get_fonttheme_params();
337
- $keys = $param['typesquare_themes_keys'];
338
- $html .= "<tr><th>{$keys['fade_in']}</th><td>";
339
- $value = esc_attr( $param['typesquare_themes']['fade_in'] );
340
- if ( $value ) {
341
- $optional = 'checked';
342
- }
343
-
344
- $html .="<label class='switch__label' ><input name='{$option_name}[fade_in]'type='checkbox' class='switch__input' id='fade_in' value='1' ". checked( $value, true, false ). "/><span class='switch__content'></span><span class='switch__circle'></span></label><span>有効化する</span>";
345
- $html .= '</td></tr>';
346
- if ( $value ) {
347
- $state = 'ts-table-low';
348
- } else {
349
- $state = 'hidden';
350
- }
351
- $html .= "<tr id='hidden_time' class='{$state}'><th>{$keys['fade_time']}</th><td>";
352
- $value = esc_attr( $param['typesquare_themes']['fade_time'] );
353
- $optional = "size='5' maxlength='5'";
354
- $html .= "<input name='{$option_name}[fade_time]' type='text' id='fade_time' value='{$value}' class='code' {$optional}/>";
355
- $html .= __( 'ミリ秒(0〜10000の整数)', self::$text_domain );
356
- $html .= '</td></tr>';
357
-
358
- return $html;
359
- }
360
-
361
- private function _get_font_theme_form() {
362
- $option_name = 'typesquare_fonttheme';
363
- $fonts = TypeSquare_ST_Fonts::get_instance();
364
- $param = $fonts->get_fonttheme_params();
365
- $html = '';
366
- $html .= wp_nonce_field( 'ts_update_font_settings' , 'ts_update_font_settings' , true , false );
367
- $html .= '<div id="choiceTheme" class="font_custum_select">';
368
- $html .= "<select name='{$option_name}[font_theme]' class='font_theme_select_pre'>";
369
- $all_font_theme = $fonts->load_all_font_data();
370
- foreach ( $all_font_theme as $fonttheme_key => $fonttheme ) {
371
- $fonttheme_name = esc_attr( $fonttheme['name'] );
372
- $font_text = $this->_get_fonttheme_text( $fonttheme );
373
- $selected = '';
374
- if ( $fonttheme_key == $param['typesquare_themes']['font_theme']) {
375
- $selected = 'selected';
376
- }
377
- $html .= "<option value='{$fonttheme_key}' {$selected}>";
378
- $html .= "{$fonttheme_name} ( {$font_text} )";
379
- $html .= '</option>';
380
- }
381
- $html .= '</select>';
382
- $html .= '<h3>プレビュー</h3>';
383
- $html .= '<div><p class="title">見出し:<p class="pre_title"></p></p></div>';
384
- $html .= '<div><p class="title">リード:<p class="pre_lead"></p></p></div>';
385
- $html .= '<div><p class="title">本文:<p class="pre_body"></p></p></div>';
386
- $html .= '<div><p class="title">太字:<p class="pre_bold"></p></p></div>';
387
- $html .= '<input type="hidden" id="theme_preview" />';
388
- foreach ($all_font_theme as $fonttheme_key => $fonttheme) {
389
- $html .= "<input type='hidden' id='selected-get-{$fonttheme_key}' value='" . json_encode($fonttheme) . "'>";
390
- }
391
- $html .= wp_nonce_field( 'ts_update_font_settings' , 'ts_update_font_settings' , true , false );
392
-
393
- $value = esc_attr( $param['typesquare_themes']['show_post_form'] ) == "true" ? true : false;
394
- $html .= '</div>';
395
- $html .= '<input type="hidden" name="typesquare_nonce_postmeta" id="typesquare_nonce_postmeta" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
396
- return $html;
397
- }
398
-
399
- private function _get_font_theme_custom_form() {
400
- $option_name = 'typesquare_fonttheme';
401
- $fonts = TypeSquare_ST_Fonts::get_instance();
402
- $param = $fonts->get_fonttheme_params();
403
- if( isset($_POST['typesquare_fonttheme']['font_theme']) && $_POST['typesquare_fonttheme']['font_theme'] !== 'new'){
404
- $param['typesquare_themes']['font_theme'] = $_POST['typesquare_fonttheme']['font_theme'];
405
- }
406
- $html = '';
407
- $html .= "<form method='post' action='' id='custmeFontForm' class='b__font_theme_form'>";
408
- $html .= '<p>お好きなフォントを組み合わせてテーマを作成できます。また、作成したテーマの編集ができます。</p>';
409
- $html .= wp_nonce_field( 'ts_update_font_settings' , 'ts_update_font_settings' , true , false );
410
- $html .= '<div class="font_custum_select">';
411
- $html .= "<select id='fontThemeSelect' name='{$option_name}[font_theme]'>";
412
- $html .= "<option value='new' selected>新しくテーマを作成する</option>";
413
- $coustam_font_theme = $fonts->load_coustam_font_data();
414
- if (!empty($coustam_font_theme)) {
415
- foreach ( $coustam_font_theme as $fonttheme_key => $fonttheme ) {
416
- $fonttheme_name = esc_attr( $fonttheme['name'] );
417
- $font_text = $this->_get_fonttheme_text( $fonttheme );
418
- $selected = '';
419
- $html .= "<option value='{$fonttheme_key}' {$selected}>";
420
- $html .= "{$fonttheme_name} ( {$font_text} )";
421
- $html .= '</option>';
422
- }
423
- }
424
- $html .= '</select>';
425
- if (!empty($coustam_font_theme)) {
426
- foreach ($coustam_font_theme as $fonttheme_key => $fonttheme) {
427
- $html .= "<input type='hidden' id='{$fonttheme_key}' value='" . json_encode($fonttheme) . "'>";
428
- }
429
- }
430
- $html .= '</div>';
431
-
432
- $html .= $this->_get_custome_font_theme_list_form();
433
- $html .= "<table>";
434
- $html .= "<th>";
435
- $html .= get_submit_button( __( 'テーマを保存する', self::$text_domain ), 'primary', 'fontThemeUpdateButton');
436
- $html .= "</th>";
437
- $html .= "<th>";
438
- $style = array("style"=>"margin-top:15px; display:none;");
439
- $html .= get_submit_button( __( 'テーマを削除する', self::$text_domain ), 'delete', 'fontThemeDeleteButton', null, $style);
440
- $html .= "</th>";
441
- $html .= "</table>";
442
- $html .= '<input type="hidden" name="typesquare_nonce_postmeta" id="typesquare_nonce_postmeta" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
443
- $html .= '</form>';
444
- return $html;
445
- }
446
-
447
- private function _get_custome_font_theme_list_form() {
448
- $html = '';
449
- $html .= "<input type='hidden' name='ts_edit_mode' value='new' />";
450
- $html .= '<input type="hidden" id="ts_custome_theme_id" name="typesquare_custom_theme[id]" value="' . uniqid() . '" />';
451
- $html .= "<div id='customeFontThemeForm'>";
452
- $html .= wp_nonce_field( 'ts_update_font_name_setting', 'ts_update_font_name_setting', true , false );
453
- $html .= "<table class='widefat' style='border: 0px'>";
454
- $html .= '<tbody>';
455
- $html .= "<tr><th width='240px' style='padding-left:0;'>テーマタイトル</th><td>";
456
- $html .= "<input type='hidden' id='current_custome_font_name' name='typesquare_custom_theme[name]' value=''/>";
457
- $html .= "<input type='text' id='custome_font_name' name='typesquare_custom_theme[name]' value='' maxlength='16' style='width:50%;' required/>";
458
- $html .= '</td></tr>';
459
- $html .= $this->_get_site_font_form_tr("見出し", "", "typesquare_custom_theme[fonts][title][type]");
460
- $html .= $this->_get_site_font_form_tr("リード", "", "typesquare_custom_theme[fonts][lead][type]");
461
- $html .= $this->_get_site_font_form_tr("本文", "", "typesquare_custom_theme[fonts][text][type]");
462
- $html .= $this->_get_site_font_form_tr("太字", "", "typesquare_custom_theme[fonts][bold][type]");
463
- $html .= '</tbody>';
464
- $html .= '</table>';
465
- $html .= "<div id='ts-react-search-font'></div>";
466
- $html .= "</div>";
467
- $font_list = array();
468
- $html .= $this->_get_script( $font_list );
469
- return $html;
470
- }
471
-
472
- private function _get_site_font_form() {
473
- $fonts = TypeSquare_ST_Fonts::get_instance();
474
- $value = $fonts->get_site_font_setting();
475
- $html = "<form method='post' action='' id='siteFontForm'>";
476
- $html .= '<p>タイトルなど、ウェブサイト共通部分のフォント設定です</p>';
477
- $html .= '<table class="widefat form-table">';
478
- $html .= '<tbody>';
479
- $html .= $this->_get_site_font_form_tr("サイトタイトル", $value['title_fontname'], "title_fontname");
480
- $html .= $this->_get_site_font_form_tr("サイトキャッチコピー", $value['catchcopy_fontname'], "catchcopy_fontname");
481
- $html .= $this->_get_site_font_form_tr("ウィジェットタイトル", $value['widget_title_fontname'], "widget_title_fontname");
482
- $html .= $this->_get_site_font_form_tr("ウィジェット", $value['widget_fontname'], "widget_fontname");
483
- $html .= '</tbody>';
484
- $html .= "</table>";
485
- $html .= get_submit_button( __( 'サイトフォント設定を保存する', self::$text_domain ) );
486
- $html .= wp_nonce_field( 'ts_update_site_font_settings' , 'ts_update_site_font_settings' , true , false );
487
- $html .= '</form>';
488
- return $html;
489
- }
490
-
491
- private function _get_site_font_form_tr ($title, $value, $input_name) {
492
- $html = "<tr><th style='padding-left:0;'><span>{$title}</span></th>";
493
- $html .= '<td class="font_table_td">';
494
- $html .= '<div class="w_font_select">';
495
- $html .= "<input class='fontlist_input' autocomplete='off' value='{$value}' style='font-family: {$value}' placeholder='未設定'/>";
496
- $html .= "<div class='w_fontlist b_def_fontlist'></div>";
497
- $html .= "</div>";
498
- $html .= "</td><input value='{$value}' type='hidden' name='{$input_name}' id='fontlist_select' class='fontlist_select'/></tr>";
499
- return $html;
500
- }
501
-
502
- private function _get_script( $font_list ) {
503
- $vars = "var form_id = '#". self::MENU_FONTTHEME. "';";
504
- $vars .= "var notify_text = '". __( 'フォントを1種類以上選択してください。', self::$text_domain ). "';";
505
- $vars .= "var unique_id ='". uniqid() ."';";
506
- $options = get_option('typesquare_custom_theme');
507
- $vars .= "var option_font_list = ". json_encode( $options ) .";";
508
- $vars .= "var plugin_base = '".wp_create_nonce( plugin_basename( __FILE__ ) )."';";
509
- $fonts = TypeSquare_ST_Fonts::get_instance();
510
- $all_font_theme = $fonts->load_all_font_data( );
511
- $vars .= 'var all_font_list = '. json_encode( $all_font_theme ) .';';
512
- $script = <<<EOM
 
 
 
 
 
 
 
 
 
 
 
513
  {$vars}
514
  jQuery( document ).ready(function() {
515
  jQuery( form_id ).submit(function() {
@@ -529,177 +552,183 @@ jQuery( document ).ready(function() {
529
  });
530
  });
531
  EOM;
532
- $html = '<script>';
533
- $endpoint = path_join( TS_PLUGIN_URL , 'inc/font.json' );
534
- $html .= "var json_endpoint = '{$endpoint}';";
535
- if ( $font_list ) {
536
- $html .= "var current_font = ". json_encode( $font_list ) .';';
537
- } else {
538
- $html .= "var current_font = false;";
539
- }
540
- $html .= $script;
541
- $html .= '</script>';
542
- return $html;
543
- }
544
-
545
- private function _get_fonttheme_text( $fonttheme ) {
546
- $font_text = '';
547
- if ( isset( $fonttheme['fonts']['title'] ) ) {
548
- $font_text .= __( '見出し:', self::$text_domain );
549
- $font_text .= $this->get_fonts_text( $fonttheme['fonts']['title'] );
550
- $font_text .= ',';
551
- }
552
- if ( isset( $fonttheme['fonts']['lead'] ) ) {
553
- $font_text .= __( 'リード:', self::$text_domain );
554
- $font_text .= $this->get_fonts_text( $fonttheme['fonts']['lead'] );
555
- $font_text .= ',';
556
- }
557
- if ( isset( $fonttheme['fonts']['content'] ) ) {
558
- $font_text .= __( '本文:', self::$text_domain );
559
- $font_text .= $this->get_fonts_text( $fonttheme['fonts']['content'] );
560
- $font_text .= ',';
561
- }
562
- if ( isset( $fonttheme['fonts']['text'] ) ) {
563
- $font_text .= __( '本文:', self::$text_domain );
564
- $font_text .= $this->get_fonts_text( $fonttheme['fonts']['text'] );
565
- $font_text .= ',';
566
- }
567
- if ( isset( $fonttheme['fonts']['bold'] ) ) {
568
- $font_text .= __( '太字:', self::$text_domain );
569
- $font_text .= $this->get_fonts_text( $fonttheme['fonts']['bold'] );
570
- }
571
- $font_text = rtrim( $font_text, ',' );
572
- $font_text = str_replace( ",", " / ", $font_text );
573
- return $font_text;
574
- }
575
-
576
- private function _get_font_target_form() {
577
- $fonts = TypeSquare_ST_Fonts::get_instance();
578
- $array_input = $fonts->get_font_pro_setting();
579
- $html = "<div class='b__font_target_form'>";
580
- $html .= "<table class='widefat form-table'>";
581
- $html .= '<thead>';
582
- $html .= "<tr><th style='width: 25%; padding-left: 45px;'>フォント選択</th><th style='width: 75%; padding-left: 14px;'>適用箇所(CSSセレクターで指定)</th></tr>";
583
- $html .= '</thead>';
584
- $html .= "<tbody class='cls_tb'>";
585
-
586
- if( !empty( $array_input )) {
587
- $i = 0;
588
- foreach($array_input as $key => $value){
589
- $i++;
590
- $html .= "<tr id='font_setting'><td>";
591
- $html .= "<div class='cls_delete_btn cls_delete_btn_selected'>×</div>";
592
- $html .= "<input id='fontlist_input' class='fontlist_input' autocomplete='off' value='{$value['fontlist_fontname']}' style='font-family: {$value['fontlist_fontname']}'/>";
593
- $html .= "<div class='w_fontlist b_def_fontlist'></div>";
594
- $html .= "</td>";
595
- $html .= "<td class='add_class_td'><input type='text' class='class_input' value=''/><button type='button' id='add_box' class='add_box'>追加</button>";
596
-
597
- $cls_name = $value['fontlist_cls'];
598
- foreach($cls_name as $cls_value){
599
- $html .= "<p class='add_class_label'>{$cls_value} ×";
600
- $html .= "<input name='fontlist_cls{$i}[]' type='hidden' value='{$cls_value}' />";
601
- $html .= "</p>";
602
- };
603
-
604
- $html .= "</td>";
605
- $html .= "<input value='{$value['fontlist_fontname']}' type='hidden' name='fontlist_fontname{$i}' id='fontlist_select' class='fontlist_select'/>";
606
- $html .= "</tr>";
607
- };
608
- } else {
609
- $html .= "<tr id='font_setting'><td>";
610
- $html .= "<div class='cls_delete_btn cls_delete_btn_selected'>×</div>";
611
- $html .= "<input id='fontlist_input' class='fontlist_input' autocomplete='off' placeholder='未設定'>";
612
- $html .= "<div class='w_fontlist'><ul class='font_select_menu'></ul></div>";
613
- $html .= "</td>";
614
- $html .= "<td class='add_class_td'><input type='text' class='class_input' value=''/><button type='button' id='add_box' class='add_box'>追加</button></td>";
615
- $html .= "<input value='' type='hidden' name='fontlist_fontname1' id='fontlist_select' class='fontlist_select'/>";
616
- $html .= "</tr>";
617
- };
618
-
619
- $html .= "<tr id='addbtn_tr'><td>";
620
- $html .= "<button type='button' id='input_add_btn'>+</button>";
621
- $html .= "</td></tr>";
622
- $html .= '</tbody>';
623
- $html .= '</table>';
624
- $html .= '</div>';
625
- $html .= wp_nonce_field( 'ts_update_font_pro_settings' , 'ts_update_font_pro_settings' , true , false );
626
- return $html;
627
- }
628
-
629
- //フォント自動読み込み設定
630
- private function _get_auto_load_font_form(){
631
- $option_name = 'typesquare_fonttheme';
632
- $fonts = TypeSquare_ST_Fonts::get_instance();
633
- $param = $fonts->get_fonttheme_params();
634
- $keys = $param['typesquare_themes_keys'];
635
- $html .= "<tr><th>{$keys['auto_load_font']}</th><td>";
636
- $value = esc_attr( $param['typesquare_themes']['auto_load_font'] );
637
- if ( $value ) {
638
- $optional = 'checked';
639
- }
640
- $html .="<label class='switch__label'><input name='{$option_name}[auto_load_font]'type='checkbox' class='switch__input' id='auto_load_font' value='1' ". checked( $value, true, false ). "/><span class='switch__content'></span><span class='switch__circle'></span></label><span>有効化する</span>";
641
- $html .= '</td></tr>';
642
-
643
- return $html;
644
- }
645
-
646
- // 疑似要素フォント読込
647
- private function _get_apply_to_pseudo_form() {
648
- $option_name = 'typesquare_fonttheme';
649
- $fonts = TypeSquare_ST_Fonts::get_instance();
650
- $param = $fonts->get_fonttheme_params();
651
- $keys = $param['typesquare_themes_keys'];
652
- $html .= "<tr><th>{$keys['apply_to_pseudo']}</th><td>";
653
- $value = esc_attr( $param['typesquare_themes']['apply_to_pseudo'] );
654
- if ( $value ) {
655
- $optional = 'checked';
656
- }
657
- $html .="<label class='switch__label'><input name='{$option_name}[apply_to_pseudo]'type='checkbox' class='switch__input' id='apply_to_pseudo' value='1' ". checked( $value, true, false ). "/><span class='switch__content'></span><span class='switch__circle'></span></label><span>有効化する</span>";
658
- $html .= '</td></tr>';
659
-
660
- return $html;
661
- }
662
-
663
- // 非表示要素フォント読込
664
- private function _get_apply_to_hidden_form() {
665
- $option_name = 'typesquare_fonttheme';
666
- $fonts = TypeSquare_ST_Fonts::get_instance();
667
- $param = $fonts->get_fonttheme_params();
668
- $keys = $param['typesquare_themes_keys'];
669
- $html .= "<tr><th>{$keys['apply_to_hidden']}</th><td>";
670
- $value = esc_attr( $param['typesquare_themes']['apply_to_hidden'] );
671
- if ( $value ) {
672
- $optional = 'checked';
673
- }
674
- $html .="<label class='switch__label'><input name='{$option_name}[apply_to_hidden]'type='checkbox' class='switch__input' id='apply_to_hidden' value='1' ". checked( $value, true, false ). "/><span class='switch__content'></span><span class='switch__circle'></span></label><span>有効化する</span>";
675
- $html .= '</td></tr>';
676
-
677
- return $html;
678
- }
679
-
680
- private function _update_font_list_form() {
681
- $fonts = TypeSquare_ST_Fonts::get_instance();
682
- $font_file_path = path_join( TS_PLUGIN_PATH , 'inc/font.json' );
683
- $settings_timezone = get_option('timezone_string');
684
- date_default_timezone_set($settings_timezone);
685
- $param = date("y/m/d H:i:s", filemtime($font_file_path));
686
- $html = '';
687
- $html .= '<div class="block_wrap">';
688
- $html .= '<div>';
689
- $html .= '<h3 class="block_title">'. __( 'フォントリストの更新' , self::$text_domain ). '</h3>';
690
- $html .= '</div>';
691
- $html .= "<table class='widefat form-table'>";
692
- $html .= '<thead>';
693
- $html .= "<tr></tr>";
694
- $html .= '</thead>';
695
- $html .= "<tbody>";
696
- $html .= "<tr><td style='width: 1%;' class='fontlist_update'>".get_submit_button( __( 'フォントリスト更新', self::$text_domain ), null, 'updateFontListButton', null)."</td>";
697
- $html .= "<td class='update_msg'>最終更新日: ".$param."</td></tr>";
698
- $html .= '</tbody>';
699
- $html .= '</table>';
700
- $html .= '<input type="hidden" name="update_font_list" id="update_font_list" value="off" />';
701
- $html .= wp_nonce_field( 'ts_update_font_list' , 'ts_update_font_list' , true , false );
702
- $html .= '</div>';
703
- return $html;
704
- }
705
- }
 
 
 
 
 
 
1
  <?php
2
+ class TypeSquare_Admin_Root extends TypeSquare_Admin_Base
3
+ {
4
+ private static $instance;
5
+ private static $text_domain;
6
+ private function __construct()
7
+ {
8
+ }
9
+
10
+
11
+ public static function get_instance()
12
+ {
13
+ if (! isset(self::$instance)) {
14
+ $c = __CLASS__;
15
+ self::$instance = new $c();
16
+ }
17
+ return self::$instance;
18
+ }
19
+
20
+ public function typesquare_post_metabox()
21
+ {
22
+ $fonts = TypeSquare_ST_Fonts::get_instance();
23
+ $param = $fonts->get_fonttheme_params();
24
+ if ('false' == $param['typesquare_themes']['show_post_form'] || ! $param['typesquare_themes']['show_post_form']) {
25
+ return;
26
+ }
27
+ $post_type = array( 'post', 'page' );
28
+ foreach ($post_type as $type) {
29
+ add_meta_box('typesquare_post_metabox', __('TS Webfonts for SAKURA RS', self::$text_domain), array( $this, 'typesquare_post_metabox_inside' ), $type, 'advanced', 'low');
30
+ }
31
+ }
32
+
33
+ public function typesquare_post_metabox_inside()
34
+ {
35
+ $html = '';
36
+ $html .= '<p>'. __('この記事に適用するフォントを選択してください', self::$text_domain) . '</p>';
37
+
38
+ $html .= $this->_get_post_font_theme_selector();
39
+ $html .= '<input type="hidden" name="typesquare_nonce_postmeta" id="typesquare_nonce_postmeta" value="' . wp_create_nonce(plugin_basename(__FILE__)) . '" />';
40
+ echo $html;
41
+ }
42
+
43
+ private function _get_post_font_theme_selector()
44
+ {
45
+ $html = '';
46
+ $fonts = TypeSquare_ST_Fonts::get_instance();
47
+ $all_font_theme = $fonts->load_all_font_data();
48
+ $selected_theme = $fonts->get_selected_post_fonttheme(get_the_ID());
49
+ $option = '';
50
+ $option .= "<option value='false'>テーマを設定しない</option>";
51
+ foreach ($all_font_theme as $key => $fonttheme) {
52
+ $fonttheme_name = $this->get_fonts_text($fonttheme['name']);
53
+ $font_text = $this->_get_fonttheme_text($fonttheme);
54
+ $selected = '';
55
+ if ($key === $selected_theme) {
56
+ $selected = 'selected';
57
+ }
58
+ $option .= "<option value='{$key}' {$selected}>";
59
+ $option .= "{$fonttheme_name} ( {$font_text} )";
60
+ $option .= '</option>';
61
+ }
62
+ $html .= '<h3>'. __('フォントテーマから選ぶ', self::$text_domain) . '</h3>';
63
+ $preview = <<<EOM
64
  jQuery( document ).ready(function() {
65
  window.onload = function () {
66
  theme_preview_new();
103
  }
104
  });
105
  EOM;
106
+ $html = '<script>';
107
+ $html .= $preview;
108
+ $html .= '</script>';
109
+ $html .= '<div id="choiceThemeNew">';
110
+ $html .= "<select name='typesquare_fonttheme[theme]' class='font_theme_select_pre_new'>{$option}</select>";
111
+ $html .= '<h3>プレビュー</h3>';
112
+ $html .= '<div><p class="title">見出し:<p class="pre_title"></p></p></div>';
113
+ $html .= '<div><p class="title">リード:<p class="pre_lead"></p></p></div>';
114
+ $html .= '<div><p class="title">本文:<p class="pre_body"></p></p></div>';
115
+ $html .= '<div><p class="title">太字:<p class="pre_bold"></p></p></div>';
116
+ $html .= '<input type="hidden" id="theme_preview" />';
117
+ foreach ($all_font_theme as $fonttheme_key => $fonttheme) {
118
+ $html .= "<input type='hidden' id='selected-get-{$fonttheme_key}' value='" . json_encode($fonttheme) . "'>";
119
+ }
120
+ $html .= '</div>';
121
+ return $html;
122
+ }
123
+
124
+ public function typesquare_save_post($post_id)
125
+ {
126
+ if (! isset($_POST['typesquare_nonce_postmeta'])) {
127
+ return;
128
+ }
129
+ //Verify
130
+ if (! wp_verify_nonce($_POST['typesquare_nonce_postmeta'], plugin_basename(__FILE__))) {
131
+ return $post_id;
132
+ }
133
+ // if auto save
134
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
135
+ return $post_id;
136
+ }
137
+
138
+ // permission check
139
+ if ('page' == $_POST['post_type']) {
140
+ if (! current_user_can('edit_page', $post_id)) {
141
+ return $post_id;
142
+ }
143
+ } else {
144
+ if (! current_user_can('edit_post', $post_id)) {
145
+ return $post_id;
146
+ }
147
+ }
148
+
149
+ // save action
150
+ $fonttheme = $_POST['typesquare_fonttheme'];
151
+ $current_option = get_post_meta($post_id, 'typesquare_fonttheme');
152
+ $fonts = TypeSquare_ST_Fonts::get_instance();
153
+ if (isset($current_option[0])) {
154
+ $current = $current_option[0];
155
+ } else {
156
+ $current = $fonttheme;
157
+ }
158
+ $font['theme'] = esc_attr($fonttheme['theme']);
159
+ update_post_meta($post_id, 'typesquare_fonttheme', $font);
160
+ return $post_id;
161
+ }
162
+
163
+ private function get_fonts_text($fonts)
164
+ {
165
+ if (is_array($fonts)) {
166
+ $text_font = '';
167
+ foreach ($fonts as $key => $font) {
168
+ $text_font .= esc_attr($font);
169
+ if (count($fonts) - 1 > $key) {
170
+ $text_font .= ' + ';
171
+ }
172
+ }
173
+ } else {
174
+ $text_font = esc_attr($fonts);
175
+ }
176
+ return $text_font;
177
+ }
178
+
179
+ public function typesquare_admin_menu()
180
+ {
181
+ $param = $this->get_auth_params();
182
+ $option_name = 'typesquare_auth';
183
+ $nonce_key = TypeSquare_ST::OPTION_NAME;
184
+ $auth_param = $this->get_auth_params();
185
+ echo "<style type='text/css' rel='stylesheet'>";
186
+ echo "</style>";
187
+ echo "<div class='wrap'>";
188
+ echo '<h2>'. __('TS Webfonts for SAKURA RS', self::$text_domain). '</h2>';
189
+ do_action('typesquare_add_setting_before');
190
+ echo '<hr />';
191
+ echo '<span><h3 class="toggleText toggleAdvanced_font mTop20">'. __('投稿記事フォント設定', self::$text_domain). '<span class="advancedTriangle advancedTriangle_font">▼</span></h3></span>';
192
+ echo "<div class='ts-custome_form_font hidden'>";
193
+ echo $this->_get_post_font_form($auth_param);
194
+ echo '</div>';
195
+ echo '</div>';
196
+
197
+ echo '<hr/>';
198
+ echo '<span><h3 class="toggleText toggleAdvanced_site mTop20">'. __('サイトフォント設定', self::$text_domain). '<span class="advancedTriangle advancedTriangle_site">▼</span></h3></span>';
199
+ echo "<div class='ts-custome_form_site hidden'>";
200
+ echo $this->_get_site_font_form();
201
+ echo '</div>';
202
+ echo '<hr/>';
203
+ echo '<span><h3 class="toggleText toggleAdvanced_article mTop20">'. __('カスタムテーマ編集', self::$text_domain). '<span class="advancedTriangle advancedTriangle_article">▼</span></h3></span>';
204
+ echo "<div class='ts-custome_form_article hidden'>";
205
+ echo '<div class="ts-custum_block">';
206
+ echo $this->_get_font_theme_custom_form();
207
+ echo '</div>';
208
+ echo '</div>';
209
+ do_action('typesquare_add_setting_after');
210
+ }
211
+
212
+ private function _get_post_font_form($auth_param)
213
+ {
214
+ $html = "<form method='post' action=''>";
215
+ $html .= '<p>投稿記事に対するWebフォント適用方法を設定します。</p>';
216
+ $html .= '<div class="block_wrap">';
217
+ $html .= '<p class="block_title">'. __('投稿記事に適用するフォント設定', self::$text_domain). '</p>';
218
+ $html .= '<div class="label_wrapper">';
219
+ $html .= '<label class="custum_form_ladio"><input name="fontThemeUseType" type="radio" value="1">指定しない';
220
+ $html .= '<p class="setting_read">フォントテーマを適用しません。</p>';
221
+ $html .= '</label>';
222
+ $html .= '<label class="custum_form_ladio"><input name="fontThemeUseType" type="radio" value="2" class="radio_custum_font_theme">共通テーマ指定';
223
+ $html .= '<p class="setting_read">全ての投稿に設定したフォントテーマが適用されます。</p>';
224
+ $html .= '</label>';
225
+ $html .= $this->_get_font_theme_form();
226
+ $html .= '<label class="custum_form_ladio"><input name="fontThemeUseType" type="radio" value="3">個別テーマ指定';
227
+ $html .= '<p class="setting_read">投稿ごとに設定したフォントテーマが適用されます。</p>';
228
+ $html .= '</label>';
229
+ $html .= '<label class="custum_form_ladio"><input name="fontThemeUseType" type="radio" value="4">直接指定(上級者向け)';
230
+ $html .= '<p class="setting_read">CSSセレクターを指定して適用するウェブフォントを選べます。</p>';
231
+ $html .= '</label>';
232
+ $html .= $this->_get_font_target_form();
233
+
234
+ $fonts = TypeSquare_ST_Fonts::get_instance();
235
+ $fonttheme_params = $fonts->get_fonttheme_params();
236
+
237
+ if (empty($auth_param['typesquare_auth']['fontThemeUseType'])) {
238
+ if (empty($fonttheme_params['typesquare_themes']['font_theme']) || $fonttheme_params['typesquare_themes']['font_theme'] === "false") {
239
+ $html .= '<input type="hidden" id="activeAdvanced_theme" value="1">';
240
+ } else {
241
+ $html .= '<input type="hidden" id="activeAdvanced_theme" value="2">';
242
+ }
243
+ } else {
244
+ if (!empty($fonttheme_params['typesquare_themes']['font_theme']) && $auth_param['typesquare_auth']['fontThemeUseType'] === "1") {
245
+ $html .= '<input type="hidden" id="activeAdvanced_theme" value="2">';
246
+ } else {
247
+ $html .= '<input type="hidden" id="activeAdvanced_theme" value="' . $auth_param['typesquare_auth']['fontThemeUseType'] . '">';
248
+ }
249
+ }
250
+
251
+ $html .= '</div>';
252
+ $html .= '</div>';
253
+ $html .= get_submit_button(__('投稿フォント設定を保存する', self::$text_domain));
254
+ $html .= '</form>';
255
+ return $html;
256
+ }
257
+
258
+ private function _get_auth_form($auth_param)
259
+ {
260
+ $html = '';
261
+ $nonce_key = TypeSquare_ST::OPTION_NAME;
262
+ $html .= "<form method='post' action='' id='authForm'>";
263
+ $html .= wp_nonce_field($nonce_key, self::MENU_ID, true, false);
264
+ $html .= "<table class='widefat form-table'>";
265
+ $html .= '<tbody>';
266
+ $param = $this->get_auth_params();
267
+ $option_name = 'typesquare_auth';
268
+ foreach ($param['typesquare_auth_keys'] as $key => $title) {
269
+ $html .= "<tr><td>";
270
+ $name = "{$option_name}[{$key}]";
271
+ $type = 'hidden';
272
+ $name = esc_attr($name);
273
+ $id = esc_attr($key);
274
+ $value = "SAKURA";
275
+ $html .= "<input
276
  name='{$name}'
277
  id='{$id}'
278
  value='{$value}'
281
  data-parsley-trigger='change'
282
  class='regular-text code'
283
  />";
284
+ $html .= '</td></tr>';
285
+ }
286
+ $html .= '</tbody>';
287
+ $html .= '</div>';
288
+ $html .= '</table>';
289
+ if ('' !== $auth_param['typesquare_auth']['typesquare_id']) {
290
+ $html .= '<div class="block_wrap">';
291
+ $html .= "<table class='widefat form-table'>";
292
+ $html .= '<tbody>';
293
+ $html .= $this->_get_font_fade_form();
294
+ $html .= $this->_get_auto_load_font_form();
295
+ $html .= $this->_get_apply_to_hidden_form();
296
+ $html .= $this->_get_apply_to_pseudo_form();
297
+ $html .= '</tbody>';
298
+ $html .= "</table>";
299
+ $html .= '</div>';
300
+ }
301
+
302
+ $html .= $this->_update_font_list_form();
303
+ $html .= get_submit_button(__('TypeSquare設定を保存する', self::$text_domain));
304
+
305
+ $html .= '</form>';
306
+ return $html;
307
+ }
308
+
309
+ private function _get_ad_area()
310
+ {
311
+ $html = '<script>';
312
+ $endpoint = path_join(TS_PLUGIN_URL, 'inc/font.json');
313
+ $html .= "var json_endpoint = '{$endpoint}';";
314
+ $html .= "var current_font = false;";
315
+ $html .= $script;
316
+ $html .= '</script>';
317
+ $html .= "<div class='ts-ad-area'>";
318
+ $messages[] = __('・ご利用にはTypeSquareの会員登録が必要です (<a href="https://typesquare.com">https://typesquare.com</a>)', self::$text_domain);
319
+ $messages[] = __('・利用プランによっては利用可能な書体数に上限がありますので、上限を超えて設定したフォントは配信されません。', self::$text_domain);
320
+ $messages[] = ' '. __('・無料プラン:1書体', self::$text_domain);
321
+ $messages[] = ' '. __('', self::$text_domain);
322
+ $messages[] = ' '. __('・スタンダードIプラン:3書体', self::$text_domain);
323
+ $html .= '<ul>';
324
+ $html .= '<li style="padding-bottom: 5px;"><span href="#" class="toggleLimit toggleText">' . __('ご利用上の注意', self::$text_domain). '</span><span class="textMute elimitTriangl" style="float: right;">▼</span></li>';
325
+ $html .= '<div id="ts-ad-area-messages" class="ts-hidden">';
326
+ foreach ($messages as $message) {
327
+ $html .= "<li>{$message}</li>";
328
+ }
329
+ $html .= "<p><a href='https://typesquare.com/ja/service/plan' target='_blank' class='button button-hero'>". __('→プランを見てみる', self::$text_domain) . '</a></p>';
330
+ $html .= '</div>';
331
+ $html .= '</ul>';
332
+ $html .= '</div>';
333
+ $html .= '<div class="mTop30">';
334
+ $html .= '<h3 class="mBottom10">'. __('ご利用方法', self::$text_domain). '</h3>';
335
+ $html .= '<div>'. __('TypeSquare Webfontsについての内容を説明しています', self::$text_domain). '</div>';
336
+ $html .= '<div>'. __('詳しくは', self::$text_domain). "<a href='https://blog.typesquare.com/archives/55354' target='_blank'>". __('こちら', self::$text_domain). '</a></div>';
337
+ $html .= '</div>';
338
+
339
+ return $html;
340
+ }
341
+
342
+ private function _get_font_fade_form()
343
+ {
344
+ $option_name = 'typesquare_fonttheme';
345
+ $fonts = TypeSquare_ST_Fonts::get_instance();
346
+ $param = $fonts->get_fonttheme_params();
347
+ $keys = $param['typesquare_themes_keys'];
348
+ $html = "<tr><th>{$keys['fade_in']}</th><td>";
349
+ $value = esc_attr($param['typesquare_themes']['fade_in']);
350
+ if ($value) {
351
+ $optional = 'checked';
352
+ }
353
+
354
+ $html .="<label class='switch__label' ><input name='{$option_name}[fade_in]'type='checkbox' class='switch__input' id='fade_in' value='1' ". checked($value, true, false). "/><span class='switch__content'></span><span class='switch__circle'></span></label><span>有効化する</span>";
355
+ $html .= '</td></tr>';
356
+ if ($value) {
357
+ $state = 'ts-table-low';
358
+ } else {
359
+ $state = 'hidden';
360
+ }
361
+ $html .= "<tr id='hidden_time' class='{$state}'><th>{$keys['fade_time']}</th><td>";
362
+ $value = esc_attr($param['typesquare_themes']['fade_time']);
363
+ $optional = "size='5' maxlength='5'";
364
+ $html .= "<input name='{$option_name}[fade_time]' type='text' id='fade_time' value='{$value}' class='code' {$optional}/>";
365
+ $html .= __('ミリ秒(0〜10000の整数)', self::$text_domain);
366
+ $html .= '</td></tr>';
367
+
368
+ return $html;
369
+ }
370
+
371
+ private function _get_font_theme_form()
372
+ {
373
+ $option_name = 'typesquare_fonttheme';
374
+ $fonts = TypeSquare_ST_Fonts::get_instance();
375
+ $param = $fonts->get_fonttheme_params();
376
+ $html = '';
377
+ $html .= wp_nonce_field('ts_update_font_settings', 'ts_update_font_settings', true, false);
378
+ $html .= '<div id="choiceTheme" class="font_custum_select">';
379
+ $html .= "<select name='{$option_name}[font_theme]' class='font_theme_select_pre'>";
380
+ $all_font_theme = $fonts->load_all_font_data();
381
+ foreach ($all_font_theme as $fonttheme_key => $fonttheme) {
382
+ $fonttheme_name = esc_attr($fonttheme['name']);
383
+ $font_text = $this->_get_fonttheme_text($fonttheme);
384
+ $selected = '';
385
+ if ($fonttheme_key == $param['typesquare_themes']['font_theme']) {
386
+ $selected = 'selected';
387
+ }
388
+ $html .= "<option value='{$fonttheme_key}' {$selected}>";
389
+ $html .= "{$fonttheme_name} ( {$font_text} )";
390
+ $html .= '</option>';
391
+ }
392
+ $html .= '</select>';
393
+ $html .= '<h3>プレビュー</h3>';
394
+ $html .= '<div><p class="title">見出し:<p class="pre_title"></p></p></div>';
395
+ $html .= '<div><p class="title">リード:<p class="pre_lead"></p></p></div>';
396
+ $html .= '<div><p class="title">本文:<p class="pre_body"></p></p></div>';
397
+ $html .= '<div><p class="title">太字:<p class="pre_bold"></p></p></div>';
398
+ $html .= '<input type="hidden" id="theme_preview" />';
399
+ foreach ($all_font_theme as $fonttheme_key => $fonttheme) {
400
+ $html .= "<input type='hidden' id='selected-get-{$fonttheme_key}' value='" . json_encode($fonttheme) . "'>";
401
+ }
402
+ $html .= wp_nonce_field('ts_update_font_settings', 'ts_update_font_settings', true, false);
403
+
404
+ $value = esc_attr($param['typesquare_themes']['show_post_form']) == "true" ? true : false;
405
+ $html .= '</div>';
406
+ $html .= '<input type="hidden" name="typesquare_nonce_postmeta" id="typesquare_nonce_postmeta" value="' . wp_create_nonce(plugin_basename(__FILE__)) . '" />';
407
+ return $html;
408
+ }
409
+
410
+ private function _get_font_theme_custom_form()
411
+ {
412
+ $option_name = 'typesquare_fonttheme';
413
+ $fonts = TypeSquare_ST_Fonts::get_instance();
414
+ $param = $fonts->get_fonttheme_params();
415
+ if (isset($_POST['typesquare_fonttheme']['font_theme']) && $_POST['typesquare_fonttheme']['font_theme'] !== 'new') {
416
+ $param['typesquare_themes']['font_theme'] = $_POST['typesquare_fonttheme']['font_theme'];
417
+ }
418
+ $html = '';
419
+ $html .= "<form method='post' action='' id='custmeFontForm' class='b__font_theme_form'>";
420
+ $html .= '<p>お好きなフォントを組み合わせてテーマを作成できます。また、作成したテーマの編集ができます。</p>';
421
+ $html .= wp_nonce_field('ts_update_font_settings', 'ts_update_font_settings', true, false);
422
+ $html .= '<div class="font_custum_select">';
423
+ $html .= "<select id='fontThemeSelect' name='{$option_name}[font_theme]'>";
424
+ $html .= "<option value='new' selected>新しくテーマを作成する</option>";
425
+ $coustam_font_theme = $fonts->load_coustam_font_data();
426
+ if (!empty($coustam_font_theme)) {
427
+ foreach ($coustam_font_theme as $fonttheme_key => $fonttheme) {
428
+ $fonttheme_name = esc_attr($fonttheme['name']);
429
+ $font_text = $this->_get_fonttheme_text($fonttheme);
430
+ $selected = '';
431
+ $html .= "<option value='{$fonttheme_key}' {$selected}>";
432
+ $html .= "{$fonttheme_name} ( {$font_text} )";
433
+ $html .= '</option>';
434
+ }
435
+ }
436
+ $html .= '</select>';
437
+ if (!empty($coustam_font_theme)) {
438
+ foreach ($coustam_font_theme as $fonttheme_key => $fonttheme) {
439
+ $html .= "<input type='hidden' id='{$fonttheme_key}' value='" . json_encode($fonttheme) . "'>";
440
+ }
441
+ }
442
+ $html .= '</div>';
443
+
444
+ $html .= $this->_get_custome_font_theme_list_form();
445
+ $html .= "<table>";
446
+ $html .= "<th>";
447
+ $html .= get_submit_button(__('テーマを保存する', self::$text_domain), 'primary', 'fontThemeUpdateButton');
448
+ $html .= "</th>";
449
+ $html .= "<th>";
450
+ $style = array("style"=>"margin-top:15px; display:none;");
451
+ $html .= get_submit_button(__('テーマを削除する', self::$text_domain), 'delete', 'fontThemeDeleteButton', null, $style);
452
+ $html .= "</th>";
453
+ $html .= "</table>";
454
+ $html .= '<input type="hidden" name="typesquare_nonce_postmeta" id="typesquare_nonce_postmeta" value="' . wp_create_nonce(plugin_basename(__FILE__)) . '" />';
455
+ $html .= '</form>';
456
+ return $html;
457
+ }
458
+
459
+ private function _get_custome_font_theme_list_form()
460
+ {
461
+ $html = '';
462
+ $html .= "<input type='hidden' name='ts_edit_mode' value='new' />";
463
+ $html .= '<input type="hidden" id="ts_custome_theme_id" name="typesquare_custom_theme[id]" value="' . uniqid() . '" />';
464
+ $html .= "<div id='customeFontThemeForm'>";
465
+ $html .= wp_nonce_field('ts_update_font_name_setting', 'ts_update_font_name_setting', true, false);
466
+ $html .= "<table class='widefat' style='border: 0px'>";
467
+ $html .= '<tbody>';
468
+ $html .= "<tr><th width='240px' style='padding-left:0;'>テーマタイトル</th><td>";
469
+ $html .= "<input type='hidden' id='current_custome_font_name' name='typesquare_custom_theme[name]' value=''/>";
470
+ $html .= "<input type='text' id='custome_font_name' name='typesquare_custom_theme[name]' value='' maxlength='16' style='width:50%;' required/>";
471
+ $html .= '</td></tr>';
472
+ $html .= $this->_get_site_font_form_tr("見出し", "", "typesquare_custom_theme[fonts][title][type]");
473
+ $html .= $this->_get_site_font_form_tr("リード", "", "typesquare_custom_theme[fonts][lead][type]");
474
+ $html .= $this->_get_site_font_form_tr("本文", "", "typesquare_custom_theme[fonts][text][type]");
475
+ $html .= $this->_get_site_font_form_tr("太字", "", "typesquare_custom_theme[fonts][bold][type]");
476
+ $html .= '</tbody>';
477
+ $html .= '</table>';
478
+ $html .= "<div id='ts-react-search-font'></div>";
479
+ $html .= "</div>";
480
+ $font_list = array();
481
+ $html .= $this->_get_script($font_list);
482
+ return $html;
483
+ }
484
+
485
+ private function _get_site_font_form()
486
+ {
487
+ $fonts = TypeSquare_ST_Fonts::get_instance();
488
+ $value = $fonts->get_site_font_setting();
489
+ $html = "<form method='post' action='' id='siteFontForm'>";
490
+ $html .= '<p>タイトルなど、ウェブサイト共通部分のフォント設定です</p>';
491
+ $html .= '<table class="widefat form-table">';
492
+ $html .= '<tbody>';
493
+ if (is_array($value)) {
494
+ $html .= $this->_get_site_font_form_tr("サイトタイトル", $value['title_fontname'], "title_fontname");
495
+ $html .= $this->_get_site_font_form_tr("サイトキャッチコピー", $value['catchcopy_fontname'], "catchcopy_fontname");
496
+ $html .= $this->_get_site_font_form_tr("ウィジェットタイトル", $value['widget_title_fontname'], "widget_title_fontname");
497
+ $html .= $this->_get_site_font_form_tr("ウィジェット", $value['widget_fontname'], "widget_fontname");
498
+ } else {
499
+ $html .= $this->_get_site_font_form_tr("サイトタイトル", "", "title_fontname");
500
+ $html .= $this->_get_site_font_form_tr("サイトキャッチコピー", "", "catchcopy_fontname");
501
+ $html .= $this->_get_site_font_form_tr("ウィジェットタイトル", "", "widget_title_fontname");
502
+ $html .= $this->_get_site_font_form_tr("ウィジェット", "", "widget_fontname");
503
+ }
504
+ $html .= '</tbody>';
505
+ $html .= "</table>";
506
+ $html .= get_submit_button(__('サイトフォント設定を保存する', self::$text_domain));
507
+ $html .= wp_nonce_field('ts_update_site_font_settings', 'ts_update_site_font_settings', true, false);
508
+ $html .= '</form>';
509
+ return $html;
510
+ }
511
+
512
+ private function _get_site_font_form_tr($title, $value, $input_name)
513
+ {
514
+ $html = "<tr><th style='padding-left:0;'><span>{$title}</span></th>";
515
+ $html .= '<td class="font_table_td">';
516
+ $html .= '<div class="w_font_select">';
517
+ $html .= "<input class='fontlist_input' autocomplete='off' value='{$value}' style='font-family: {$value}' placeholder='未設定'/>";
518
+ $html .= "<div class='w_fontlist b_def_fontlist'></div>";
519
+ $html .= "</div>";
520
+ $html .= "</td><input value='{$value}' type='hidden' name='{$input_name}' id='fontlist_select' class='fontlist_select'/></tr>";
521
+ return $html;
522
+ }
523
+
524
+ private function _get_script($font_list)
525
+ {
526
+ $vars = "var form_id = '#". self::MENU_FONTTHEME. "';";
527
+ $vars .= "var notify_text = '". __('フォントを1種類以上選択してください。', self::$text_domain). "';";
528
+ $vars .= "var unique_id ='". uniqid() ."';";
529
+ $options = get_option('typesquare_custom_theme');
530
+ $vars .= "var option_font_list = ". json_encode($options) .";";
531
+ $vars .= "var plugin_base = '".wp_create_nonce(plugin_basename(__FILE__))."';";
532
+ $fonts = TypeSquare_ST_Fonts::get_instance();
533
+ $all_font_theme = $fonts->load_all_font_data();
534
+ $vars .= 'var all_font_list = '. json_encode($all_font_theme) .';';
535
+ $script = <<<EOM
536
  {$vars}
537
  jQuery( document ).ready(function() {
538
  jQuery( form_id ).submit(function() {
552
  });
553
  });
554
  EOM;
555
+ $html = '<script>';
556
+ $endpoint = path_join(TS_PLUGIN_URL, 'inc/font.json');
557
+ $html .= "var json_endpoint = '{$endpoint}';";
558
+ if ($font_list) {
559
+ $html .= "var current_font = ". json_encode($font_list) .';';
560
+ } else {
561
+ $html .= "var current_font = false;";
562
+ }
563
+ $html .= $script;
564
+ $html .= '</script>';
565
+ return $html;
566
+ }
567
+
568
+ private function _get_fonttheme_text($fonttheme)
569
+ {
570
+ $font_text = '';
571
+ if (isset($fonttheme['fonts']['title'])) {
572
+ $font_text .= __('見出し:', self::$text_domain);
573
+ $font_text .= $this->get_fonts_text($fonttheme['fonts']['title']);
574
+ $font_text .= ',';
575
+ }
576
+ if (isset($fonttheme['fonts']['lead'])) {
577
+ $font_text .= __('リード:', self::$text_domain);
578
+ $font_text .= $this->get_fonts_text($fonttheme['fonts']['lead']);
579
+ $font_text .= ',';
580
+ }
581
+ if (isset($fonttheme['fonts']['content'])) {
582
+ $font_text .= __('本文:', self::$text_domain);
583
+ $font_text .= $this->get_fonts_text($fonttheme['fonts']['content']);
584
+ $font_text .= ',';
585
+ }
586
+ if (isset($fonttheme['fonts']['text'])) {
587
+ $font_text .= __('本文:', self::$text_domain);
588
+ $font_text .= $this->get_fonts_text($fonttheme['fonts']['text']);
589
+ $font_text .= ',';
590
+ }
591
+ if (isset($fonttheme['fonts']['bold'])) {
592
+ $font_text .= __('太字:', self::$text_domain);
593
+ $font_text .= $this->get_fonts_text($fonttheme['fonts']['bold']);
594
+ }
595
+ $font_text = rtrim($font_text, ',');
596
+ $font_text = str_replace(",", " / ", $font_text);
597
+ return $font_text;
598
+ }
599
+
600
+ private function _get_font_target_form()
601
+ {
602
+ $fonts = TypeSquare_ST_Fonts::get_instance();
603
+ $array_input = $fonts->get_font_pro_setting();
604
+ $html = "<div class='b__font_target_form'>";
605
+ $html .= "<table class='widefat form-table'>";
606
+ $html .= '<thead>';
607
+ $html .= "<tr><th style='width: 25%; padding-left: 45px;'>フォント選択</th><th style='width: 75%; padding-left: 14px;'>適用箇所(CSSセレクターで指定)</th></tr>";
608
+ $html .= '</thead>';
609
+ $html .= "<tbody class='cls_tb'>";
610
+
611
+ if (!empty($array_input)) {
612
+ $i = 0;
613
+ foreach ($array_input as $key => $value) {
614
+ $i++;
615
+ $html .= "<tr id='font_setting'><td>";
616
+ $html .= "<div class='cls_delete_btn cls_delete_btn_selected'>×</div>";
617
+ $html .= "<input id='fontlist_input' class='fontlist_input' autocomplete='off' value='{$value['fontlist_fontname']}' style='font-family: {$value['fontlist_fontname']}'/>";
618
+ $html .= "<div class='w_fontlist b_def_fontlist'></div>";
619
+ $html .= "</td>";
620
+ $html .= "<td class='add_class_td'><input type='text' class='class_input' value=''/><button type='button' id='add_box' class='add_box'>追加</button>";
621
+
622
+ $cls_name = $value['fontlist_cls'];
623
+ foreach ($cls_name as $cls_value) {
624
+ $html .= "<p class='add_class_label'>{$cls_value} ×";
625
+ $html .= "<input name='fontlist_cls{$i}[]' type='hidden' value='{$cls_value}' />";
626
+ $html .= "</p>";
627
+ };
628
+
629
+ $html .= "</td>";
630
+ $html .= "<input value='{$value['fontlist_fontname']}' type='hidden' name='fontlist_fontname{$i}' id='fontlist_select' class='fontlist_select'/>";
631
+ $html .= "</tr>";
632
+ };
633
+ } else {
634
+ $html .= "<tr id='font_setting'><td>";
635
+ $html .= "<div class='cls_delete_btn cls_delete_btn_selected'>×</div>";
636
+ $html .= "<input id='fontlist_input' class='fontlist_input' autocomplete='off' placeholder='未設定'>";
637
+ $html .= "<div class='w_fontlist'><ul class='font_select_menu'></ul></div>";
638
+ $html .= "</td>";
639
+ $html .= "<td class='add_class_td'><input type='text' class='class_input' value=''/><button type='button' id='add_box' class='add_box'>追加</button></td>";
640
+ $html .= "<input value='' type='hidden' name='fontlist_fontname1' id='fontlist_select' class='fontlist_select'/>";
641
+ $html .= "</tr>";
642
+ };
643
+
644
+ $html .= "<tr id='addbtn_tr'><td>";
645
+ $html .= "<button type='button' id='input_add_btn'>+</button>";
646
+ $html .= "</td></tr>";
647
+ $html .= '</tbody>';
648
+ $html .= '</table>';
649
+ $html .= '</div>';
650
+ $html .= wp_nonce_field('ts_update_font_pro_settings', 'ts_update_font_pro_settings', true, false);
651
+ return $html;
652
+ }
653
+
654
+ //フォント自動読み込み設定
655
+ private function _get_auto_load_font_form()
656
+ {
657
+ $option_name = 'typesquare_fonttheme';
658
+ $fonts = TypeSquare_ST_Fonts::get_instance();
659
+ $param = $fonts->get_fonttheme_params();
660
+ $keys = $param['typesquare_themes_keys'];
661
+ $html = "<tr><th>{$keys['auto_load_font']}</th><td>";
662
+ $value = esc_attr($param['typesquare_themes']['auto_load_font']);
663
+ if ($value) {
664
+ $optional = 'checked';
665
+ }
666
+ $html .="<label class='switch__label'><input name='{$option_name}[auto_load_font]'type='checkbox' class='switch__input' id='auto_load_font' value='1' ". checked($value, true, false). "/><span class='switch__content'></span><span class='switch__circle'></span></label><span>有効化する</span>";
667
+ $html .= '</td></tr>';
668
+
669
+ return $html;
670
+ }
671
+
672
+ // 疑似要素フォント読込
673
+ private function _get_apply_to_pseudo_form()
674
+ {
675
+ $option_name = 'typesquare_fonttheme';
676
+ $fonts = TypeSquare_ST_Fonts::get_instance();
677
+ $param = $fonts->get_fonttheme_params();
678
+ $keys = $param['typesquare_themes_keys'];
679
+ $html = "<tr><th>{$keys['apply_to_pseudo']}</th><td>";
680
+ $value = esc_attr($param['typesquare_themes']['apply_to_pseudo']);
681
+ if ($value) {
682
+ $optional = 'checked';
683
+ }
684
+ $html .="<label class='switch__label'><input name='{$option_name}[apply_to_pseudo]'type='checkbox' class='switch__input' id='apply_to_pseudo' value='1' ". checked($value, true, false). "/><span class='switch__content'></span><span class='switch__circle'></span></label><span>有効化する</span>";
685
+ $html .= '</td></tr>';
686
+
687
+ return $html;
688
+ }
689
+
690
+ // 非表示要素フォント読込
691
+ private function _get_apply_to_hidden_form()
692
+ {
693
+ $option_name = 'typesquare_fonttheme';
694
+ $fonts = TypeSquare_ST_Fonts::get_instance();
695
+ $param = $fonts->get_fonttheme_params();
696
+ $keys = $param['typesquare_themes_keys'];
697
+ $html = "<tr><th>{$keys['apply_to_hidden']}</th><td>";
698
+ $value = esc_attr($param['typesquare_themes']['apply_to_hidden']);
699
+ if ($value) {
700
+ $optional = 'checked';
701
+ }
702
+ $html .="<label class='switch__label'><input name='{$option_name}[apply_to_hidden]'type='checkbox' class='switch__input' id='apply_to_hidden' value='1' ". checked($value, true, false). "/><span class='switch__content'></span><span class='switch__circle'></span></label><span>有効化する</span>";
703
+ $html .= '</td></tr>';
704
+
705
+ return $html;
706
+ }
707
+
708
+ private function _update_font_list_form()
709
+ {
710
+ $fonts = TypeSquare_ST_Fonts::get_instance();
711
+ $font_file_path = path_join(TS_PLUGIN_PATH, 'inc/font.json');
712
+ $settings_timezone = get_option('timezone_string');
713
+ date_default_timezone_set($settings_timezone);
714
+ $param = date("y/m/d H:i:s", filemtime($font_file_path));
715
+ $html = '';
716
+ $html .= '<div class="block_wrap">';
717
+ $html .= '<div>';
718
+ $html .= '<h3 class="block_title">'. __('フォントリストの更新', self::$text_domain). '</h3>';
719
+ $html .= '</div>';
720
+ $html .= "<table class='widefat form-table'>";
721
+ $html .= '<thead>';
722
+ $html .= "<tr></tr>";
723
+ $html .= '</thead>';
724
+ $html .= "<tbody>";
725
+ $html .= "<tr><td style='width: 1%;' class='fontlist_update'>".get_submit_button(__('フォントリスト更新', self::$text_domain), null, 'updateFontListButton', null)."</td>";
726
+ $html .= "<td class='update_msg'>最終更新日: ".$param."</td></tr>";
727
+ $html .= '</tbody>';
728
+ $html .= '</table>';
729
+ $html .= '<input type="hidden" name="update_font_list" id="update_font_list" value="off" />';
730
+ $html .= wp_nonce_field('ts_update_font_list', 'ts_update_font_list', true, false);
731
+ $html .= '</div>';
732
+ return $html;
733
+ }
734
+ }
inc/assets/css/admin.css CHANGED
@@ -192,10 +192,6 @@ color: #23282d;
192
  bottom: 0;
193
  }
194
 
195
- .toplevel_page_typesquare-admin-menu li:nth-child(4) {
196
- display: none;
197
- }
198
-
199
  .tableBorder {
200
  border-top: 1px solid #ddd!important;
201
  border-bottom: 1px solid #ddd!important;
192
  bottom: 0;
193
  }
194
 
 
 
 
 
195
  .tableBorder {
196
  border-top: 1px solid #ddd!important;
197
  border-bottom: 1px solid #ddd!important;
inc/class/class.font.data.php CHANGED
@@ -1,345 +1,373 @@
1
  <?php
2
 
3
- require_once( dirname( __FILE__ ).'/class.fonttheme.php' );
4
- class TypeSquare_ST_Fonts {
5
- private static $instance;
6
- private static $text_domain;
7
-
8
- private function __construct() {
9
- self::$text_domain = TypeSquare_ST::text_domain();
10
- }
11
-
12
- public static function get_instance() {
13
- if ( ! isset( self::$instance ) ) {
14
- $c = __CLASS__;
15
- self::$instance = new $c();
16
- }
17
- return self::$instance;
18
- }
19
-
20
- public function load_all_font_data() {
21
- $font_theme = TypeSquare_ST_Fonttheme::get_instance();
 
 
 
 
22
  $font_data = $font_theme->get_fonttheme();
23
- if ($font_data['fonttheme']) {
24
  return $font_data['fonttheme'];
25
  }
26
- return $font_data;
27
- }
28
-
29
- public function load_coustam_font_data() {
30
- $font_theme = TypeSquare_ST_Fonttheme::get_instance();
31
- $font_data = $font_theme->get_custom_fonttheme();
32
- return $font_data;
33
- }
34
-
35
- public function load_font_data( $theme = '' ) {
36
- if ( '' === $theme || false == $theme || 'false' == $theme ) {
37
- $theme = $this->get_selected_fonttheme();
38
- $theme = $theme['font_theme'];
39
- if ( '' === $theme || false == $theme || 'false' == $theme ) {
40
- return false;
41
- }
42
- }
43
- $font_data = $this->load_all_font_data( );
44
- if ( isset( $font_data[ $theme ] ) ) {
45
- return $font_data[ $theme ]['fonts'];
46
- } else {
47
- return false;
48
- }
49
- }
50
-
51
- public function get_selected_fonttheme() {
52
- $fonththeme = $this->get_fonttheme_params();
53
- return $fonththeme['typesquare_themes'];
54
- }
55
-
56
- public function get_selected_post_fonttheme( $post_id ) {
57
- $meta = get_post_meta( $post_id , 'typesquare_fonttheme' , true );
58
- if ( isset( $meta['theme'] ) ) {
59
- $theme = $meta['theme'];
60
- } elseif ( isset( $meta['fonts'] ) ) {
61
- $theme = '';
62
- } else {
63
- $theme = $meta;
64
- }
65
- /*
66
- if ( '' == $theme || 'false' == $theme ) {
67
- $theme = $this->get_selected_fonttheme();
68
- $theme = $theme['font_theme'];
69
- }
70
- */
71
- return $theme;
72
- }
73
-
74
- public function get_fadein_time() {
75
- $param = $this->get_fonttheme_options();
76
- if ( isset( $param['fade_in'] ) && $param['fade_in'] ) {
77
- $fade_time = $param['fade_time'];
78
- } else {
79
- $fade_time = false;
80
- }
81
- return $fade_time;
82
- }
83
-
84
- public function get_auto_load_font() {
85
- $param = $this->get_fonttheme_options();
86
- if ( isset( $param['auto_load_font'] ) ) {
87
- $auto_load_font = $param['auto_load_font'];
88
- } else {
89
- $auto_load_font = false;
90
- }
91
- return $auto_load_font;
92
- }
93
-
94
- public function get_apply_to_pseudo() {
95
- $param = $this->get_fonttheme_options();
96
- if ( isset( $param['apply_to_pseudo'] ) ) {
97
- $apply_to_pseudo = $param['apply_to_pseudo'];
98
- } else {
99
- $apply_to_pseudo = false;
100
- }
101
- return $apply_to_pseudo;
102
- }
103
-
104
-
105
- public function get_apply_to_hidden() {
106
- $param = $this->get_fonttheme_options();
107
- if ( isset( $param['apply_to_hidden'] ) ) {
108
- $apply_to_hidden = $param['apply_to_hidden'];
109
- } else {
110
- $apply_to_hidden = false;
111
- }
112
- return $apply_to_hidden;
113
- }
114
-
115
- public function get_fonttheme_keys() {
116
- return array(
117
- 'font_theme' => __( 'フォントテーマ', self::$text_domain ),
118
- 'title_target' => __( '見出しタグ', self::$text_domain ),
119
- 'lead_target' => __( 'リードタグ', self::$text_domain ),
120
- 'text_target' => __( '本文タグ', self::$text_domain ),
121
- 'bold_target' => __( '強調タグ', self::$text_domain ),
122
- 'fade_in' => __( 'フェードイン', self::$text_domain ),
123
- 'fade_time' => __( 'フェード時間', self::$text_domain ),
124
- 'auto_load_font' => __( 'フォント自動読み込み', self::$text_domain ),
125
- 'script_onload' => __( 'ロード時動作', self::$text_domain ),
126
- 'apply_to_pseudo' => __( '疑似要素フォント読込', self::$text_domain ),
127
- 'apply_to_hidden' => __( '非表示要素フォント読込', self::$text_domain ),
128
- 'show_post_form' => __( '記事ごとにフォントを設定', self::$text_domain ),
129
- );
130
- }
131
-
132
- public function get_fonttheme_options() {
133
- // タイトル
134
- $title_base = "h1,h2,h3,h1:lang(ja),h2:lang(ja),h3:lang(ja),.entry-title:lang(ja)";
135
- //$title_comment = "#comments h2.comments-title:lang(ja)";
136
- //$title_comment_button = "#comments .comment-reply-link:lang(ja)";
137
- // リード
138
- $lead_base = "h4,h5,h6,h4:lang(ja),h5:lang(ja),h6:lang(ja)";
139
-
140
- $lead_page_header = "div.entry-meta span:lang(ja)";
141
- $lead_page_footer = "footer.entry-footer span:lang(ja)";
142
- // テキスト
143
- $text_base = ".hentry,.entry-content p,.post-inner.entry-content p";
144
- $text_comment = "#comments div:lang(ja)";
145
- // 強調
146
- $bold_base = "strong,b";
147
- $bold_comment = "#comments .comment-author .fn:lang(ja)";
148
-
149
- $default_param = array(
150
- 'font_theme' => false,
151
- 'title_target' => "{$title_base}",
152
- 'lead_target' => "{$lead_base},{$lead_page_header},{$lead_page_footer}",
153
- 'text_target' => "{$text_base},{$text_comment}",
154
- 'bold_target' => "{$bold_base},{$bold_comment}",
155
- 'fade_in' => true,
156
- 'fade_time' => 0,
157
- 'auto_load_font' => false,
158
- 'script_onload' => false,
159
- 'apply_to_pseudo' => true,
160
- 'apply_to_hidden' => false,
161
- 'show_post_form' => false,
162
- );
163
-
164
- $option_name = 'typesquare_fonttheme';
165
- $param = get_option( $option_name );
166
-
167
- if ( isset( $param['fonts'] ) ) {
168
- unset( $param['fonts'] );
169
- }
170
- if ( ! isset( $param['show_post_form'] ) ) {
171
- $param['show_post_form'] = false;
172
- }
173
- if ( ! $param ) {
174
- $param = $default_param;
175
- } else {
176
- foreach ( $default_param as $key => $value ) {
177
- if ( ! isset( $param[ $key ] ) ) {
178
- $param[ $key ] = $value;
179
- }
180
- }
181
- }
182
- // paramの中に選択したフォントのvalue値は入っている
183
- return $param;
184
- }
185
-
186
- public function get_fonttheme_params() {
187
- $param['typesquare_themes'] = $this->get_fonttheme_options();
188
- $param['typesquare_themes_keys'] = $this->get_fonttheme_keys();
189
- return $param;
190
- }
191
-
192
- public function update_font_setting() {
193
- if ( ! isset( $_POST['typesquare_custom_theme'])) {
194
- return;
195
- }
196
-
197
- $options = get_option( 'typesquare_custom_theme' );
198
- $options = $this->parse_font_setting_param( $options, $_POST['typesquare_custom_theme'] );
199
-
200
- if(isset($options['theme']['']['id'])){
201
- $this->update_font_theme_setting();
202
- }else{
203
- update_option( 'typesquare_custom_theme', $options );
204
- }
205
- $result = __( 'フォントテーマの設定に成功しました。', self::$text_domain );
206
- $this->show_result( $result );
207
- }
208
-
209
- public function delete_custom_theme() {
210
- if ( ! isset( $_POST['typesquare_custom_theme'] ) ) {
211
- return;
212
- }
213
- $options = get_option( 'typesquare_custom_theme' );
214
- $id = $_POST['typesquare_custom_theme']['id'];
215
- unset( $options['theme'][ $id ] );
216
- unset( $options['fonts'][ $id ] );
217
- update_option( 'typesquare_custom_theme', $options );
218
- $result = __( 'フォントテーマの削除に成功しました。', self::$text_domain );
219
- $this->show_result( $result );
220
- }
221
-
222
- public function show_result( $result ) {
223
- $html = "<div class='notice updated'><ul>";
224
- $html .= "<li>{$result}</li>";
225
- $html .= '</ul></div>';
226
- echo $html;
227
- }
228
-
229
- public function parse_font_setting_param( $current, $param ) {
230
- $name = esc_attr( $param['name'] );
231
- $id = (string) esc_attr( $param['id'] );
232
- $current['theme'][ $id ]['name'] = $name;
233
- $current['theme'][ $id ]['id'] = $id;
234
- foreach ( $param['fonts'] as $type => $font ) {
235
- $type = esc_attr( $type );
236
- foreach ( $font as $key => $value ) {
237
- if ( 'false' == $value ) {
238
- unset( $current['theme'][ $id ]['fonts'][ $type ] );
239
- unset( $current['fonts'][ $id ][ $type ] );
240
- continue;
241
- }
242
- $key = (string) esc_attr( $key );
243
- $current['fonts'][ $id ][ $type ][ $key ] = esc_attr( $value );
244
- $current['theme'][ $id ]['fonts'][ $type ] = esc_attr( $value );
245
- }
246
- }
247
- return $current;
248
- }
249
-
250
- public function update_typesquare_settings() {
251
- if ( ! isset( $_POST['typesquare_fonttheme'] )) {
252
- return;
253
- }
254
- $options = get_option( 'typesquare_fonttheme' );
255
- foreach ( $_POST['typesquare_fonttheme'] as $key => $target ) {
256
- $key = esc_attr( $key );
257
- $options[ $key ] = esc_attr( $target );
258
- }
259
- if ( isset( $_POST['typesquare_fonttheme']['fade_time'] ) ) {
260
- if ( ! isset( $_POST['typesquare_fonttheme']['fade_in'] ) ) {
261
- $options['fade_in'] = false;
262
- }
263
- }
264
- if ( ! isset( $_POST['typesquare_fonttheme']['auto_load_font'] ) ) {
265
- $options['auto_load_font'] = false;
266
- }
267
-
268
- if ( ! isset( $_POST['typesquare_fonttheme']['apply_to_pseudo'] ) ) {
269
- $options['apply_to_pseudo'] = false;
270
- }
271
-
272
- if ( ! isset( $_POST['typesquare_fonttheme']['apply_to_hidden'] ) ) {
273
- $options['apply_to_hidden'] = false;
274
- }
275
- update_option( 'typesquare_fonttheme', $options );
276
- }
277
-
278
- public function disable_font_theme_setting() {
279
- if ( ! isset( $_POST['typesquare_fonttheme'] )) {
280
- return;
281
- }
282
- $options = get_option( 'typesquare_fonttheme' );
283
- $options['font_theme'] = false;
284
- update_option( 'typesquare_fonttheme', $options );
285
- }
286
-
287
- public function update_font_theme_setting() {
288
- if ( ! isset( $_POST['typesquare_fonttheme'] )) {
289
- return;
290
- }
291
- $options = get_option( 'typesquare_fonttheme' );
292
- foreach ( $_POST['typesquare_fonttheme'] as $key => $target ) {
293
- $key = esc_attr( $key );
294
- $options[ $key ] = esc_attr( $target );
295
- }
296
- update_option( 'typesquare_fonttheme', $options );
297
- }
298
-
299
- public function update_show_post_form($status) {
300
- $options = get_option( 'typesquare_fonttheme' );
301
- $options['show_post_form'] = $status;
302
- update_option( 'typesquare_fonttheme', $options );
303
- }
304
-
305
- public function get_site_font_setting () {
306
- return get_option( 'typesquare_site_font_setting');
307
- }
308
-
309
- public function update_site_font_setting () {
310
- $options = array(
311
- "title_fontname" => isset($_POST["title_fontname"]) ? $_POST["title_fontname"] : "",
312
- "catchcopy_fontname" => isset($_POST["catchcopy_fontname"]) ? $_POST["catchcopy_fontname"] : "",
313
- "widget_title_fontname" => isset($_POST["widget_title_fontname"]) ? $_POST["widget_title_fontname"] : "",
314
- "widget_fontname" => isset($_POST["widget_fontname"]) ? $_POST["widget_fontname"] : "",
315
- );
316
- update_option( 'typesquare_site_font_setting', $options );
317
- }
318
-
319
- public function get_font_pro_setting () {
320
- return get_option( 'typesquare_pro_setting');
321
- }
322
-
323
- public function update_font_pro_setting () {
324
- $options = array();
325
- for ($i=1; $i < 20; $i++) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  if (isset($_POST["fontlist_fontname${i}"]) && !empty($_POST["fontlist_fontname${i}"] && !empty($_POST["fontlist_cls${i}"]))) {
327
  array_push($options, array(
328
  "fontlist_fontname" => $_POST["fontlist_fontname${i}"],
329
  "fontlist_cls" => $_POST["fontlist_cls${i}"],
330
  ));
331
  }
332
- }
333
- update_option( 'typesquare_pro_setting', $options );
334
- }
335
-
336
- public function get_selected_font( $type ) {
337
- $font = false;
338
- $param = $this->get_fonttheme_options();
339
- if ( ! isset( $param['fonts'] ) || ! isset( $param['fonts'][ $type ] ) ) {
340
- return $font;
341
- }
342
- $font = $param['fonts'][ $type ]['font'];
343
- return $font;
344
- }
345
- }
 
1
  <?php
2
 
3
+ require_once(dirname(__FILE__).'/class.fonttheme.php');
4
+ class TypeSquare_ST_Fonts
5
+ {
6
+ private static $instance;
7
+ private static $text_domain;
8
+
9
+ private function __construct()
10
+ {
11
+ self::$text_domain = TypeSquare_ST::text_domain();
12
+ }
13
+
14
+ public static function get_instance()
15
+ {
16
+ if (! isset(self::$instance)) {
17
+ $c = __CLASS__;
18
+ self::$instance = new $c();
19
+ }
20
+ return self::$instance;
21
+ }
22
+
23
+ public function load_all_font_data()
24
+ {
25
+ $font_theme = TypeSquare_ST_Fonttheme::get_instance();
26
  $font_data = $font_theme->get_fonttheme();
27
+ if (isset($font_data['fonttheme'])) {
28
  return $font_data['fonttheme'];
29
  }
30
+ return $font_data;
31
+ }
32
+
33
+ public function load_coustam_font_data()
34
+ {
35
+ $font_theme = TypeSquare_ST_Fonttheme::get_instance();
36
+ $font_data = $font_theme->get_custom_fonttheme();
37
+ return $font_data;
38
+ }
39
+
40
+ public function load_font_data($theme = '')
41
+ {
42
+ if ('' === $theme || false == $theme || 'false' == $theme) {
43
+ $theme = $this->get_selected_fonttheme();
44
+ $theme = $theme['font_theme'];
45
+ if ('' === $theme || false == $theme || 'false' == $theme) {
46
+ return false;
47
+ }
48
+ }
49
+ $font_data = $this->load_all_font_data();
50
+ if (isset($font_data[ $theme ])) {
51
+ return $font_data[ $theme ]['fonts'];
52
+ } else {
53
+ return false;
54
+ }
55
+ }
56
+
57
+ public function get_selected_fonttheme()
58
+ {
59
+ $fonththeme = $this->get_fonttheme_params();
60
+ return $fonththeme['typesquare_themes'];
61
+ }
62
+
63
+ public function get_selected_post_fonttheme($post_id)
64
+ {
65
+ $meta = get_post_meta($post_id, 'typesquare_fonttheme', true);
66
+ if (isset($meta['theme'])) {
67
+ $theme = $meta['theme'];
68
+ } elseif (isset($meta['fonts'])) {
69
+ $theme = '';
70
+ } else {
71
+ $theme = $meta;
72
+ }
73
+ /*
74
+ if ( '' == $theme || 'false' == $theme ) {
75
+ $theme = $this->get_selected_fonttheme();
76
+ $theme = $theme['font_theme'];
77
+ }
78
+ */
79
+ return $theme;
80
+ }
81
+
82
+ public function get_fadein_time()
83
+ {
84
+ $param = $this->get_fonttheme_options();
85
+ if (isset($param['fade_in']) && $param['fade_in']) {
86
+ $fade_time = $param['fade_time'];
87
+ } else {
88
+ $fade_time = false;
89
+ }
90
+ return $fade_time;
91
+ }
92
+
93
+ public function get_auto_load_font()
94
+ {
95
+ $param = $this->get_fonttheme_options();
96
+ if (isset($param['auto_load_font'])) {
97
+ $auto_load_font = $param['auto_load_font'];
98
+ } else {
99
+ $auto_load_font = false;
100
+ }
101
+ return $auto_load_font;
102
+ }
103
+
104
+ public function get_apply_to_pseudo()
105
+ {
106
+ $param = $this->get_fonttheme_options();
107
+ if (isset($param['apply_to_pseudo'])) {
108
+ $apply_to_pseudo = $param['apply_to_pseudo'];
109
+ } else {
110
+ $apply_to_pseudo = false;
111
+ }
112
+ return $apply_to_pseudo;
113
+ }
114
+
115
+
116
+ public function get_apply_to_hidden()
117
+ {
118
+ $param = $this->get_fonttheme_options();
119
+ if (isset($param['apply_to_hidden'])) {
120
+ $apply_to_hidden = $param['apply_to_hidden'];
121
+ } else {
122
+ $apply_to_hidden = false;
123
+ }
124
+ return $apply_to_hidden;
125
+ }
126
+
127
+ public function get_fonttheme_keys()
128
+ {
129
+ return array(
130
+ 'font_theme' => __('フォントテーマ', self::$text_domain),
131
+ 'title_target' => __('見出しタグ', self::$text_domain),
132
+ 'lead_target' => __('リードタグ', self::$text_domain),
133
+ 'text_target' => __('本文タグ', self::$text_domain),
134
+ 'bold_target' => __('強調タグ', self::$text_domain),
135
+ 'fade_in' => __('フェードイン', self::$text_domain),
136
+ 'fade_time' => __('フェード時間', self::$text_domain),
137
+ 'auto_load_font' => __('フォント自動読み込み', self::$text_domain),
138
+ 'script_onload' => __('ロード時動作', self::$text_domain),
139
+ 'apply_to_pseudo' => __('疑似要素フォント読込', self::$text_domain),
140
+ 'apply_to_hidden' => __('非表示要素フォント読込', self::$text_domain),
141
+ 'show_post_form' => __('記事ごとにフォントを設定', self::$text_domain),
142
+ );
143
+ }
144
+
145
+ public function get_fonttheme_options()
146
+ {
147
+ // タイトル
148
+ $title_base = "h1,h2,h3,h1:lang(ja),h2:lang(ja),h3:lang(ja),.entry-title:lang(ja)";
149
+ //$title_comment = "#comments h2.comments-title:lang(ja)";
150
+ //$title_comment_button = "#comments .comment-reply-link:lang(ja)";
151
+ // リード
152
+ $lead_base = "h4,h5,h6,h4:lang(ja),h5:lang(ja),h6:lang(ja)";
153
+
154
+ $lead_page_header = "div.entry-meta span:lang(ja)";
155
+ $lead_page_footer = "footer.entry-footer span:lang(ja)";
156
+ // テキスト
157
+ $text_base = ".hentry,.entry-content p,.post-inner.entry-content p";
158
+ $text_comment = "#comments div:lang(ja)";
159
+ // 強調
160
+ $bold_base = "strong,b";
161
+ $bold_comment = "#comments .comment-author .fn:lang(ja)";
162
+
163
+ $default_param = array(
164
+ 'font_theme' => false,
165
+ 'title_target' => "{$title_base}",
166
+ 'lead_target' => "{$lead_base},{$lead_page_header},{$lead_page_footer}",
167
+ 'text_target' => "{$text_base},{$text_comment}",
168
+ 'bold_target' => "{$bold_base},{$bold_comment}",
169
+ 'fade_in' => true,
170
+ 'fade_time' => 0,
171
+ 'auto_load_font' => false,
172
+ 'script_onload' => false,
173
+ 'apply_to_pseudo' => true,
174
+ 'apply_to_hidden' => false,
175
+ 'show_post_form' => false,
176
+ );
177
+
178
+ $option_name = 'typesquare_fonttheme';
179
+ $param = get_option($option_name);
180
+
181
+ if (isset($param['fonts'])) {
182
+ unset($param['fonts']);
183
+ }
184
+ if (! isset($param['show_post_form'])) {
185
+ $param['show_post_form'] = false;
186
+ }
187
+ if (! $param) {
188
+ $param = $default_param;
189
+ } else {
190
+ foreach ($default_param as $key => $value) {
191
+ if (! isset($param[ $key ])) {
192
+ $param[ $key ] = $value;
193
+ }
194
+ }
195
+ }
196
+ // paramの中に選択したフォントのvalue値は入っている
197
+ return $param;
198
+ }
199
+
200
+ public function get_fonttheme_params()
201
+ {
202
+ $param['typesquare_themes'] = $this->get_fonttheme_options();
203
+ $param['typesquare_themes_keys'] = $this->get_fonttheme_keys();
204
+ return $param;
205
+ }
206
+
207
+ public function update_font_setting()
208
+ {
209
+ if (! isset($_POST['typesquare_custom_theme'])) {
210
+ return;
211
+ }
212
+
213
+ $options = get_option('typesquare_custom_theme');
214
+ $options = $this->parse_font_setting_param($options, $_POST['typesquare_custom_theme']);
215
+
216
+ if (isset($options['theme']['']['id'])) {
217
+ $this->update_font_theme_setting();
218
+ } else {
219
+ update_option('typesquare_custom_theme', $options);
220
+ }
221
+ $result = __('フォントテーマの設定に成功しました。', self::$text_domain);
222
+ $this->show_result($result);
223
+ }
224
+
225
+ public function delete_custom_theme()
226
+ {
227
+ if (! isset($_POST['typesquare_custom_theme'])) {
228
+ return;
229
+ }
230
+ $options = get_option('typesquare_custom_theme');
231
+ $id = $_POST['typesquare_custom_theme']['id'];
232
+ unset($options['theme'][ $id ]);
233
+ unset($options['fonts'][ $id ]);
234
+ update_option('typesquare_custom_theme', $options);
235
+ $result = __('フォントテーマの削除に成功しました。', self::$text_domain);
236
+ $this->show_result($result);
237
+ }
238
+
239
+ public function show_result($result)
240
+ {
241
+ $html = "<div class='notice updated'><ul>";
242
+ $html .= "<li>{$result}</li>";
243
+ $html .= '</ul></div>';
244
+ echo $html;
245
+ }
246
+
247
+ public function parse_font_setting_param($current, $param)
248
+ {
249
+ $name = esc_attr($param['name']);
250
+ $id = (string) esc_attr($param['id']);
251
+ $current['theme'][ $id ]['name'] = $name;
252
+ $current['theme'][ $id ]['id'] = $id;
253
+ foreach ($param['fonts'] as $type => $font) {
254
+ $type = esc_attr($type);
255
+ foreach ($font as $key => $value) {
256
+ if ('false' == $value) {
257
+ unset($current['theme'][ $id ]['fonts'][ $type ]);
258
+ unset($current['fonts'][ $id ][ $type ]);
259
+ continue;
260
+ }
261
+ $key = (string) esc_attr($key);
262
+ $current['fonts'][ $id ][ $type ][ $key ] = esc_attr($value);
263
+ $current['theme'][ $id ]['fonts'][ $type ] = esc_attr($value);
264
+ }
265
+ }
266
+ return $current;
267
+ }
268
+
269
+ public function update_typesquare_settings()
270
+ {
271
+ if (! isset($_POST['typesquare_fonttheme'])) {
272
+ return;
273
+ }
274
+ $options = get_option('typesquare_fonttheme');
275
+ foreach ($_POST['typesquare_fonttheme'] as $key => $target) {
276
+ $key = esc_attr($key);
277
+ $options[ $key ] = esc_attr($target);
278
+ }
279
+ if (isset($_POST['typesquare_fonttheme']['fade_time'])) {
280
+ if (! isset($_POST['typesquare_fonttheme']['fade_in'])) {
281
+ $options['fade_in'] = false;
282
+ }
283
+ }
284
+ if (! isset($_POST['typesquare_fonttheme']['auto_load_font'])) {
285
+ $options['auto_load_font'] = false;
286
+ }
287
+
288
+ if (! isset($_POST['typesquare_fonttheme']['apply_to_pseudo'])) {
289
+ $options['apply_to_pseudo'] = false;
290
+ }
291
+
292
+ if (! isset($_POST['typesquare_fonttheme']['apply_to_hidden'])) {
293
+ $options['apply_to_hidden'] = false;
294
+ }
295
+ update_option('typesquare_fonttheme', $options);
296
+ }
297
+
298
+ public function disable_font_theme_setting()
299
+ {
300
+ if (! isset($_POST['typesquare_fonttheme'])) {
301
+ return;
302
+ }
303
+ $options = get_option('typesquare_fonttheme');
304
+ $options['font_theme'] = false;
305
+ update_option('typesquare_fonttheme', $options);
306
+ }
307
+
308
+ public function update_font_theme_setting()
309
+ {
310
+ if (! isset($_POST['typesquare_fonttheme'])) {
311
+ return;
312
+ }
313
+ $options = get_option('typesquare_fonttheme');
314
+ foreach ($_POST['typesquare_fonttheme'] as $key => $target) {
315
+ $key = esc_attr($key);
316
+ $options[ $key ] = esc_attr($target);
317
+ }
318
+ update_option('typesquare_fonttheme', $options);
319
+ }
320
+
321
+ public function update_show_post_form($status)
322
+ {
323
+ $options = get_option('typesquare_fonttheme');
324
+ $options['show_post_form'] = $status;
325
+ update_option('typesquare_fonttheme', $options);
326
+ }
327
+
328
+ public function get_site_font_setting()
329
+ {
330
+ return get_option('typesquare_site_font_setting');
331
+ }
332
+
333
+ public function update_site_font_setting()
334
+ {
335
+ $options = array(
336
+ "title_fontname" => isset($_POST["title_fontname"]) ? $_POST["title_fontname"] : "",
337
+ "catchcopy_fontname" => isset($_POST["catchcopy_fontname"]) ? $_POST["catchcopy_fontname"] : "",
338
+ "widget_title_fontname" => isset($_POST["widget_title_fontname"]) ? $_POST["widget_title_fontname"] : "",
339
+ "widget_fontname" => isset($_POST["widget_fontname"]) ? $_POST["widget_fontname"] : "",
340
+ );
341
+ update_option('typesquare_site_font_setting', $options);
342
+ }
343
+
344
+ public function get_font_pro_setting()
345
+ {
346
+ return get_option('typesquare_pro_setting');
347
+ }
348
+
349
+ public function update_font_pro_setting()
350
+ {
351
+ $options = array();
352
+ for ($i=1; $i < 20; $i++) {
353
  if (isset($_POST["fontlist_fontname${i}"]) && !empty($_POST["fontlist_fontname${i}"] && !empty($_POST["fontlist_cls${i}"]))) {
354
  array_push($options, array(
355
  "fontlist_fontname" => $_POST["fontlist_fontname${i}"],
356
  "fontlist_cls" => $_POST["fontlist_cls${i}"],
357
  ));
358
  }
359
+ }
360
+ update_option('typesquare_pro_setting', $options);
361
+ }
362
+
363
+ public function get_selected_font($type)
364
+ {
365
+ $font = false;
366
+ $param = $this->get_fonttheme_options();
367
+ if (! isset($param['fonts']) || ! isset($param['fonts'][ $type ])) {
368
+ return $font;
369
+ }
370
+ $font = $param['fonts'][ $type ]['font'];
371
+ return $font;
372
+ }
373
+ }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: sakurainternet
3
  Donate link:
4
  Tags: font
5
  Requires at least: 4.3.1
6
- Tested up to: 5.5.1
7
- Stable tag: 3.0.0
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -68,7 +68,7 @@ UD新ゴ R/UD新ゴ M/UD新ゴ コンデンス90 L/UD新ゴ コンデン
68
 
69
  == Frequently asked questions ==
70
 
71
- よくある質問については、さくらのレンタルサーバの[サポートサイト](https://help.sakura.ad.jp/hc/ja/articles/206091582)をご確認ください。
72
 
73
  == Screenshots ==
74
  1. screenshot-1.png
@@ -94,6 +94,9 @@ UD新ゴ R/UD新ゴ M/UD新ゴ コンデンス90 L/UD新ゴ コンデン
94
 
95
  3.0.0:追加3書体を利用できる機能を追加し、ユーザビリティも改善いたしました
96
 
 
 
 
97
  == Upgrade notice ==
98
 
99
- == Arbitrary section 1 ==
3
  Donate link:
4
  Tags: font
5
  Requires at least: 4.3.1
6
+ Tested up to: 5.8.0
7
+ Stable tag: 3.1.0
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
68
 
69
  == Frequently asked questions ==
70
 
71
+ よくある質問については、さくらのレンタルサーバの[サポートサイト](https://help.sakura.ad.jp/360000210142/)をご確認ください。
72
 
73
  == Screenshots ==
74
  1. screenshot-1.png
94
 
95
  3.0.0:追加3書体を利用できる機能を追加し、ユーザビリティも改善いたしました
96
 
97
+ 3.1.0:PHP8に対応しました。リュウミンが選択できない場合があるバグを修正
98
+
99
+
100
  == Upgrade notice ==
101
 
102
+ == Arbitrary section 1 ==
screenshot-1.jpg DELETED
Binary file
ts-webfonts-for-sakura.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: TS Webfonts for SAKURA RS
4
- Version: 3.0.0
5
  Description: さくらのレンタルサーバで株式会社モリサワ提供のWebフォント33書体が無料で利用できるプラグインです。
6
  Author: SAKURA Internet Inc.
7
  Author URI: http://www.sakura.ne.jp/
@@ -10,337 +10,357 @@ Text Domain: ts-webfonts-for-sakura
10
  Domain Path: /languages
11
  */
12
 
13
- require_once( dirname( __FILE__ ).'/typesquare-admin.php' );
14
- require_once( dirname( __FILE__ ).'/inc/class/class.font.data.php' );
15
- require_once( dirname( __FILE__ ).'/inc/class/class.auth.php' );
16
- require_once( dirname( __FILE__ ).'/inc/class/class.api.php' );
17
- define( 'TS_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
18
- define( 'TS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
19
  $ts = TypeSquare_ST::get_instance();
20
  $ts->add_hook();
21
  $admin = TypeSquare_Admin::get_instance();
22
  $admin->add_hook();
23
 
24
- class TypeSquare_ST {
25
- private static $instance;
26
- private $styles = false;
27
- const OPTION_NAME = 'ts_settings';
28
- private function __construct(){}
29
-
30
- public static function get_instance() {
31
- if ( ! isset( self::$instance ) ) {
32
- $c = __CLASS__;
33
- self::$instance = new $c();
34
- }
35
- return self::$instance;
36
- }
37
-
38
- public function add_hook() {
39
- add_action( 'wp_enqueue_scripts' , array( $this, 'load_scripts' ) , 0 , 3 );
40
- add_action( 'wp_head' , array( $this, 'load_font_styles' ) );
41
- add_action( 'pre_get_posts', array( $this, 'get_archive_font_styles' ) );
42
- }
43
-
44
- public static function version() {
45
- static $version;
46
-
47
- if ( ! $version ) {
48
- $data = get_file_data( __FILE__ , array( 'version' => 'Version' ) );
49
- $version = $data['version'];
50
- }
51
- return $version;
52
- }
53
-
54
- public static function text_domain() {
55
- static $text_domain;
56
-
57
- if ( ! $text_domain ) {
58
- $data = get_file_data( __FILE__ , array( 'text_domain' => 'Text Domain' ) );
59
- $text_domain = $data['text_domain'];
60
- }
61
- return $text_domain;
62
- }
63
-
64
- public function load_scripts() {
65
- $query = '';
66
- $uid = str_replace( '%', '%25', $this->get_user_id() );
67
- $version = $this->version();
68
- $fonts = TypeSquare_ST_Fonts::get_instance();
69
- $fade_in = $fonts->get_fadein_time();
70
- $auto_load_font = $fonts->get_auto_load_font();
71
- $apply_to_pseudo = $fonts->get_apply_to_pseudo();
72
- $apply_to_hidden = $fonts->get_apply_to_hidden();
73
-
74
- if ( false !== $fade_in ) {
75
- $query .= "&fadein={$fade_in}";
76
- } else {
77
- $query .= "&fadein=-1";
78
- }
79
-
80
- if ( false !== $auto_load_font ) {
81
- $query .= "&auto_load_font=true";
82
- }
83
-
84
- if ( false === $apply_to_pseudo ) {
85
- $query .= "&apply_to_pseudo=false";
86
- }
87
-
88
- if ( false !== $apply_to_hidden ) {
89
- $query .= "&apply_to_hidden=true";
90
- }
91
-
92
- if ( false !== $uid ) {
93
- wp_register_script( 'typesquare_std', "//webfonts.sakura.ne.jp/js/sakurav2.js?$query", array( 'jquery' ), $version, false );
94
- wp_enqueue_script( 'typesquare_std' );
95
- }
96
- }
97
-
98
- private function get_user_id() {
99
- $auth = TypeSquare_ST_Auth::get_instance();
100
- $param = $auth->get_auth_status();
101
- return $param['typesquare_id'];
102
- }
103
-
104
- private function get_fonts( $type = false, $post_font_data = false, $fonts = false ) {
105
- $font_class = TypeSquare_ST_Fonts::get_instance();
106
- $selected_font = $font_class->get_selected_font( $type );
107
-
108
- if ( $selected_font ) {
109
- $fonts = $selected_font;
110
- }
111
- if ( $post_font_data ) {
112
- if ( isset( $post_font_data[ $type ] ) ) {
113
- $fonts = $post_font_data[ $type ]['font'];
114
- }
115
- }
116
- if ( is_array( $fonts ) ) {
117
- $text_font = '';
118
- foreach ( $fonts as $key => $font ) {
119
- $text_font .= '"'. esc_attr( $font ). '"';
120
- if ( count( $fonts ) - 1 > $key ) {
121
- $text_font .= ',';
122
- }
123
- }
124
- } else {
125
- $text_font = '"'. esc_attr( $fonts ). '"';
126
- }
127
- return $text_font;
128
- }
129
-
130
- public function load_font_styles() {
131
- if ( is_archive() || is_home() ) {
132
- if ( $this->styles ) {
133
- echo $this->styles;
134
- }
135
- return;
136
- }
137
- $auth = TypeSquare_ST_Auth::get_instance();
138
- $param = $auth->get_auth_status();
139
- if ( '' === $param['typesquare_id'] ) {
140
- return;
141
- }
142
-
143
- $site_style = $this->_get_site_font_styles();
144
- if (!empty($site_style)) {
145
- echo "<style type='text/css'>{$site_style}</style>\n";
146
- }
147
-
148
- $fonts = TypeSquare_ST_Fonts::get_instance();
149
- $font_pro_settings = $fonts->get_font_pro_setting();
150
- if ($font_pro_settings && $param['fontThemeUseType'] == 4) {
151
- $style = $this->_get_pro_font_styles( $font_pro_settings );
152
- } else {
153
- $fonttheme = $fonts->get_selected_fonttheme();
154
- if ( ! isset( $fonttheme ) && ! $fonttheme ) {
155
- return;
156
- }
157
- $use_font = $fonts->load_font_data( $fonttheme['font_theme'] );
158
- if ( is_singular() ) {
159
- $param = $fonts->get_fonttheme_params();
160
- if ( isset( $param['typesquare_themes']['show_post_form'] ) && 'false' != $param['typesquare_themes']['show_post_form'] ) {
161
- $post_theme = $fonts->get_selected_post_fonttheme( get_the_ID() );
162
- $post_theme = $fonts->load_font_data( $post_theme );
163
- if ( $post_theme ) {
164
- $use_font = $post_theme;
165
- }
166
- }
167
- }
168
- $style = $this->_get_font_styles( $use_font, $fonttheme );
169
- }
170
-
171
- if ( $style ) {
172
- $html = "<style type='text/css'>{$style}</style>";
173
- echo $html;
174
- }
175
- }
176
-
177
- public function get_archive_font_styles( $query ) {
178
- if ( is_admin() || ! $query->is_main_query() || is_singular() ) {
179
- return;
180
- }
181
- $auth = TypeSquare_ST_Auth::get_instance();
182
- $param = $auth->get_auth_status();
183
- if ( '' === $param['typesquare_id'] ) {
184
- return;
185
- }
186
-
187
- $fonts = TypeSquare_ST_Fonts::get_instance();
188
-
189
- $this->styles = "";
190
- $site_style = $this->_get_site_font_styles();
191
- if (!empty($site_style)) {
192
- $this->styles = "<style type='text/css'>{$site_style}</style>";
193
- }
194
-
195
- $fonttheme = $fonts->get_selected_fonttheme();
196
- if ( ! isset( $fonttheme ) && ! $fonttheme ) {
197
- return;
198
- }
199
- $font_param = $fonts->get_fonttheme_params();
200
- $use_font = $fonts->load_font_data( $fonttheme['font_theme'] );
201
- $font_pro_settings = $fonts->get_font_pro_setting();
202
  if ($font_pro_settings && $param['fontThemeUseType'] == 4) {
203
- $style = $this->_get_pro_font_styles($font_pro_settings);
204
- $this->styles .= "<style type='text/css'>{$style}</style>";
205
- return;
206
- }
207
-
208
- if ( ! $query->query ) {
209
- $query->query = apply_filters( 'ts-default-query', array(
210
- 'post_type' => 'post',
211
- ) );
212
- }
213
-
214
- $the_query = new WP_Query( $query->query );
215
- $style = "";
216
- while ( $the_query->have_posts() ) : $the_query->the_post();
217
- $id = get_the_ID();
218
- if ( isset( $font_param['typesquare_themes']['show_post_form'] ) && 'false' != $font_param['typesquare_themes']['show_post_form'] ) {
219
- $post_theme = $fonts->get_selected_post_fonttheme( $id );
220
- $post_theme = $fonts->load_font_data( $post_theme );
221
- if ( $post_theme ) {
222
- $use_font = $post_theme;
223
- }
224
- }
225
- $style .= $this->_get_font_styles( $use_font, $fonttheme, $id );
226
- endwhile;
227
-
228
- if ( $style ) {
229
- $this->styles .= "<style type='text/css'>{$style}</style>";
230
- }
231
- }
232
-
233
- private function _merge_post_id_to_target( $post_key, $target_text ) {
234
- $target_list = explode( ',', $target_text );
235
- $merged_target = false;
236
- foreach ( $target_list as $target ) {
237
- if ( '.hentry' == $target ) {
238
- $merged_target .= "{$post_key}{$target},";
239
- } else {
240
- $merged_target .= "{$post_key} {$target},";
241
- }
242
- }
243
- $merged_target = rtrim( $merged_target, ',' );
244
- return $merged_target;
245
- }
246
-
247
- private function _get_font_styles( $use_font, $fonttheme, $post_id = false, $post_font_data = false ) {
248
- $style = '';
249
- if ( $post_id ) {
250
- $post_key = '#post-'. $post_id;
251
- $title_target = $this->_merge_post_id_to_target( $post_key, esc_attr( $fonttheme['title_target'] ) );
252
- $lead_target = $this->_merge_post_id_to_target( $post_key, esc_attr( $fonttheme['lead_target'] ) );
253
- $text_target = $this->_merge_post_id_to_target( $post_key, esc_attr( $fonttheme['text_target'] ) );
254
- $bold_target = $this->_merge_post_id_to_target( $post_key, esc_attr( $fonttheme['bold_target'] ) );
255
- } else {
256
- $title_target = esc_attr( $fonttheme['title_target'] );
257
- $lead_target = esc_attr( $fonttheme['lead_target'] );
258
- $text_target = esc_attr( $fonttheme['text_target'] );
259
- $bold_target = esc_attr( $fonttheme['bold_target'] );
260
- }
261
-
262
- $title_font = $lead_font = $text_font = $bold_font = false;
263
- if ( isset( $use_font['title'] ) ) {
264
- $title_font = $this->get_fonts( 'title' , $post_font_data, $use_font['title'] );
265
- }
266
- if ( isset( $use_font['lead'] ) ) {
267
- $lead_font = $this->get_fonts( 'lead' , $post_font_data, $use_font['lead'] );
268
- }
269
- if ( ! isset( $use_font['content'] ) && isset( $use_font['text'] ) ) {
270
- $use_font['content'] = $use_font['text'];
271
- }
272
- if ( isset( $use_font['content'] ) ) {
273
- $text_font = $this->get_fonts( 'text' , $post_font_data, $use_font['content'] );
274
- }
275
- if ( isset( $use_font['bold'] ) ) {
276
- $bold_font = $this->get_fonts( 'bold' , $post_font_data, $use_font['bold'] );
277
- }
278
-
279
- if ( $title_target && $title_font ) {
280
- $style .= "{$title_target}{ font-family: {$title_font};}";
281
- }
282
- if ( $lead_target && $lead_font ) {
283
- $style .= "{$lead_target}{ font-family: {$lead_font};}";
284
- }
285
- if ( $text_target && $text_font ) {
286
- $style .= "{$text_target}{ font-family: {$text_font};}";
287
-
288
- }
289
- if ( $bold_target && $bold_font ) {
290
- $style .= "{$bold_target}{ font-family: {$bold_font};}";
291
- }
292
-
293
- return $style;
294
- }
295
-
296
- private function _get_site_font_styles () {
297
- $fonts = TypeSquare_ST_Fonts::get_instance();
298
- $site_font_settings = $fonts->get_site_font_setting();
299
- $title_fontname = $site_font_settings['title_fontname'];
300
- $catchcopy_fontname = $site_font_settings['catchcopy_fontname'];
301
- $widget_title_fontname = $site_font_settings['widget_title_fontname'];
302
- $widget_fontname = $site_font_settings['widget_fontname'];
303
- $style = '';
304
- if ( $title_fontname ) {
305
- $title_target = ".site-branding .site-title a:lang(ja),.site-title";
306
- $style .= "{$title_target}{ font-family: '{$title_fontname}';}";
307
- }
308
- if ( $catchcopy_fontname ) {
309
- $catchcopy_target = ".site-description:lang(ja)";
310
- $style .= "{$catchcopy_target}{ font-family: '{$catchcopy_fontname}';}";
311
- }
312
- if ( $widget_title_fontname) {
313
- $widget_title_target = "section.widget h2:lang(ja),.widget-title";
314
- $style .= "{$widget_title_target}{ font-family: '{$widget_title_fontname}';}";
315
-
316
- }
317
- if ( $widget_fontname ) {
318
- $widget_target = "section.widget ul li:lang(ja),.widget-content ul li";
319
- $style .= "{$widget_target}{ font-family: '{$widget_fontname}';}";
320
- }
321
-
322
- return $style;
323
- }
324
-
325
- private function _get_pro_font_styles ($font_pro_settings, $post_id = false) {
326
- $style = '';
327
- foreach ($font_pro_settings as $font_pro_setting) {
328
- foreach ($font_pro_setting['fontlist_cls'] as $fontlist_cls) {
329
- $target = esc_attr($fontlist_cls);
330
- if ($post_id) {
331
- $post_key = '#post-'. $post_id;
332
- if ( '.hentry' == $target ) {
333
- $target = "{$post_key}{$target}";
334
- } else {
335
- $target = "{$post_key} {$target}";
336
- }
337
- }
338
- $fontf_amily = $font_pro_setting['fontlist_fontname'];
339
- $style .= "{$target}{ font-family: '{$fontf_amily}';}";
340
- }
341
- }
342
- return $style;
343
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  }
345
 
346
  // クラシックエディタにフォントリスト追加
@@ -354,24 +374,22 @@ class TypeSquare_ST {
354
  // return $plugins;
355
  // } );
356
 
357
- add_filter( 'mce_buttons', function ( $buttons ) {
358
- $auth = TypeSquare_ST_Auth::get_instance();
359
- $param = $auth->get_auth_status();
360
- if ( '' === $param['typesquare_id'] ) {
361
- return;
362
- }
363
- $buttons[] = 'fontfamily_button';
364
- return $buttons;
365
- } );
366
-
367
- register_uninstall_hook( __FILE__, 'ts_uninstall' );
368
- function ts_uninstall() {
369
- delete_option( 'typesquare_auth' );
370
- delete_option( 'typesquare_fonttheme' );
371
- delete_option( 'typesquare_custom_theme' );
372
- delete_option( 'typesquare_pro_setting' );
373
- delete_option( 'typesquare_site_font_setting' );
374
- return;
375
- }
376
-
377
-
1
  <?php
2
  /*
3
  Plugin Name: TS Webfonts for SAKURA RS
4
+ Version: 3.1.0
5
  Description: さくらのレンタルサーバで株式会社モリサワ提供のWebフォント33書体が無料で利用できるプラグインです。
6
  Author: SAKURA Internet Inc.
7
  Author URI: http://www.sakura.ne.jp/
10
  Domain Path: /languages
11
  */
12
 
13
+ require_once(dirname(__FILE__).'/typesquare-admin.php');
14
+ require_once(dirname(__FILE__).'/inc/class/class.font.data.php');
15
+ require_once(dirname(__FILE__).'/inc/class/class.auth.php');
16
+ require_once(dirname(__FILE__).'/inc/class/class.api.php');
17
+ define('TS_PLUGIN_PATH', plugin_dir_path(__FILE__));
18
+ define('TS_PLUGIN_URL', plugin_dir_url(__FILE__));
19
  $ts = TypeSquare_ST::get_instance();
20
  $ts->add_hook();
21
  $admin = TypeSquare_Admin::get_instance();
22
  $admin->add_hook();
23
 
24
+ class TypeSquare_ST
25
+ {
26
+ private static $instance;
27
+ private $styles = false;
28
+ const OPTION_NAME = 'ts_settings';
29
+ private function __construct()
30
+ {
31
+ }
32
+
33
+ public static function get_instance()
34
+ {
35
+ if (! isset(self::$instance)) {
36
+ $c = __CLASS__;
37
+ self::$instance = new $c();
38
+ }
39
+ return self::$instance;
40
+ }
41
+
42
+ public function add_hook()
43
+ {
44
+ add_action('wp_enqueue_scripts', array( $this, 'load_scripts' ), 0, 3);
45
+ add_action('wp_head', array( $this, 'load_font_styles' ));
46
+ add_action('pre_get_posts', array( $this, 'get_archive_font_styles' ));
47
+ }
48
+
49
+ public static function version()
50
+ {
51
+ static $version;
52
+
53
+ if (! $version) {
54
+ $data = get_file_data(__FILE__, array( 'version' => 'Version' ));
55
+ $version = $data['version'];
56
+ }
57
+ return $version;
58
+ }
59
+
60
+ public static function text_domain()
61
+ {
62
+ static $text_domain;
63
+
64
+ if (! $text_domain) {
65
+ $data = get_file_data(__FILE__, array( 'text_domain' => 'Text Domain' ));
66
+ $text_domain = $data['text_domain'];
67
+ }
68
+ return $text_domain;
69
+ }
70
+
71
+ public function load_scripts()
72
+ {
73
+ $query = '';
74
+ $uid = str_replace('%', '%25', $this->get_user_id());
75
+ $version = $this->version();
76
+ $fonts = TypeSquare_ST_Fonts::get_instance();
77
+ $fade_in = $fonts->get_fadein_time();
78
+ $auto_load_font = $fonts->get_auto_load_font();
79
+ $apply_to_pseudo = $fonts->get_apply_to_pseudo();
80
+ $apply_to_hidden = $fonts->get_apply_to_hidden();
81
+
82
+ if (false !== $fade_in) {
83
+ $query .= "&fadein={$fade_in}";
84
+ } else {
85
+ $query .= "&fadein=-1";
86
+ }
87
+
88
+ if (false !== $auto_load_font) {
89
+ $query .= "&auto_load_font=true";
90
+ }
91
+
92
+ if (false === $apply_to_pseudo) {
93
+ $query .= "&apply_to_pseudo=false";
94
+ }
95
+
96
+ if (false !== $apply_to_hidden) {
97
+ $query .= "&apply_to_hidden=true";
98
+ }
99
+
100
+ if (false !== $uid) {
101
+ wp_register_script('typesquare_std', "//webfonts.sakura.ne.jp/js/sakurav3.js?$query", array( 'jquery' ), $version, false);
102
+ wp_enqueue_script('typesquare_std');
103
+ }
104
+ }
105
+
106
+ private function get_user_id()
107
+ {
108
+ $auth = TypeSquare_ST_Auth::get_instance();
109
+ $param = $auth->get_auth_status();
110
+ return $param['typesquare_id'];
111
+ }
112
+
113
+ private function get_fonts($type = false, $post_font_data = false, $fonts = false)
114
+ {
115
+ $font_class = TypeSquare_ST_Fonts::get_instance();
116
+ $selected_font = $font_class->get_selected_font($type);
117
+
118
+ if ($selected_font) {
119
+ $fonts = $selected_font;
120
+ }
121
+ if ($post_font_data) {
122
+ if (isset($post_font_data[ $type ])) {
123
+ $fonts = $post_font_data[ $type ]['font'];
124
+ }
125
+ }
126
+ if (is_array($fonts)) {
127
+ $text_font = '';
128
+ foreach ($fonts as $key => $font) {
129
+ $text_font .= '"'. esc_attr($font). '"';
130
+ if (count($fonts) - 1 > $key) {
131
+ $text_font .= ',';
132
+ }
133
+ }
134
+ } else {
135
+ $text_font = '"'. esc_attr($fonts). '"';
136
+ }
137
+ return $text_font;
138
+ }
139
+
140
+ public function load_font_styles()
141
+ {
142
+ if (is_archive() || is_home()) {
143
+ if ($this->styles) {
144
+ echo $this->styles;
145
+ }
146
+ return;
147
+ }
148
+ $auth = TypeSquare_ST_Auth::get_instance();
149
+ $param = $auth->get_auth_status();
150
+ if ('' === $param['typesquare_id']) {
151
+ return;
152
+ }
153
+
154
+ $site_style = $this->_get_site_font_styles();
155
+ if (!empty($site_style)) {
156
+ echo "<style type='text/css'>{$site_style}</style>\n";
157
+ }
158
+
159
+ $fonts = TypeSquare_ST_Fonts::get_instance();
160
+ $font_pro_settings = $fonts->get_font_pro_setting();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  if ($font_pro_settings && $param['fontThemeUseType'] == 4) {
162
+ $style = $this->_get_pro_font_styles($font_pro_settings);
163
+ } else {
164
+ $fonttheme = $fonts->get_selected_fonttheme();
165
+ if (! isset($fonttheme) && ! $fonttheme) {
166
+ return;
167
+ }
168
+ $use_font = $fonts->load_font_data($fonttheme['font_theme']);
169
+ if (is_singular()) {
170
+ $param = $fonts->get_fonttheme_params();
171
+ if (isset($param['typesquare_themes']['show_post_form']) && 'false' != $param['typesquare_themes']['show_post_form']) {
172
+ $post_theme = $fonts->get_selected_post_fonttheme(get_the_ID());
173
+ $post_theme = $fonts->load_font_data($post_theme);
174
+ if ($post_theme) {
175
+ $use_font = $post_theme;
176
+ }
177
+ }
178
+ }
179
+ $style = $this->_get_font_styles($use_font, $fonttheme);
180
+ }
181
+
182
+ if ($style) {
183
+ $html = "<style type='text/css'>{$style}</style>";
184
+ echo $html;
185
+ }
186
+ }
187
+
188
+ public function get_archive_font_styles($query)
189
+ {
190
+ if (is_admin() || ! $query->is_main_query() || is_singular()) {
191
+ return;
192
+ }
193
+ $auth = TypeSquare_ST_Auth::get_instance();
194
+ $param = $auth->get_auth_status();
195
+ if ('' === $param['typesquare_id']) {
196
+ return;
197
+ }
198
+
199
+ $fonts = TypeSquare_ST_Fonts::get_instance();
200
+
201
+ $this->styles = "";
202
+ $site_style = $this->_get_site_font_styles();
203
+ if (!empty($site_style)) {
204
+ $this->styles = "<style type='text/css'>{$site_style}</style>";
205
+ }
206
+
207
+ $fonttheme = $fonts->get_selected_fonttheme();
208
+ if (! isset($fonttheme) && ! $fonttheme) {
209
+ return;
210
+ }
211
+ $font_param = $fonts->get_fonttheme_params();
212
+ $use_font = $fonts->load_font_data($fonttheme['font_theme']);
213
+ $font_pro_settings = $fonts->get_font_pro_setting();
214
+ if ($font_pro_settings && $param['fontThemeUseType'] == 4) {
215
+ $style = $this->_get_pro_font_styles($font_pro_settings);
216
+ $this->styles .= "<style type='text/css'>{$style}</style>";
217
+ return;
218
+ }
219
+
220
+ if (! $query->query) {
221
+ $query->query = apply_filters('ts-default-query', array(
222
+ 'post_type' => 'post',
223
+ ));
224
+ }
225
+
226
+ $the_query = new WP_Query($query->query);
227
+ $style = "";
228
+ while ($the_query->have_posts()) : $the_query->the_post();
229
+ $id = get_the_ID();
230
+ if (isset($font_param['typesquare_themes']['show_post_form']) && 'false' != $font_param['typesquare_themes']['show_post_form']) {
231
+ $post_theme = $fonts->get_selected_post_fonttheme($id);
232
+ $post_theme = $fonts->load_font_data($post_theme);
233
+ if ($post_theme) {
234
+ $use_font = $post_theme;
235
+ }
236
+ }
237
+ $style .= $this->_get_font_styles($use_font, $fonttheme, $id);
238
+ endwhile;
239
+
240
+ if ($style) {
241
+ $this->styles .= "<style type='text/css'>{$style}</style>";
242
+ }
243
+ }
244
+
245
+ private function _merge_post_id_to_target($post_key, $target_text)
246
+ {
247
+ $target_list = explode(',', $target_text);
248
+ $merged_target = false;
249
+ foreach ($target_list as $target) {
250
+ if ('.hentry' == $target) {
251
+ $merged_target .= "{$post_key}{$target},";
252
+ } else {
253
+ $merged_target .= "{$post_key} {$target},";
254
+ }
255
+ }
256
+ $merged_target = rtrim($merged_target, ',');
257
+ return $merged_target;
258
+ }
259
+
260
+ private function _get_font_styles($use_font, $fonttheme, $post_id = false, $post_font_data = false)
261
+ {
262
+ $style = '';
263
+ if ($post_id) {
264
+ $post_key = '#post-'. $post_id;
265
+ $title_target = $this->_merge_post_id_to_target($post_key, esc_attr($fonttheme['title_target']));
266
+ $lead_target = $this->_merge_post_id_to_target($post_key, esc_attr($fonttheme['lead_target']));
267
+ $text_target = $this->_merge_post_id_to_target($post_key, esc_attr($fonttheme['text_target']));
268
+ $bold_target = $this->_merge_post_id_to_target($post_key, esc_attr($fonttheme['bold_target']));
269
+ } else {
270
+ $title_target = esc_attr($fonttheme['title_target']);
271
+ $lead_target = esc_attr($fonttheme['lead_target']);
272
+ $text_target = esc_attr($fonttheme['text_target']);
273
+ $bold_target = esc_attr($fonttheme['bold_target']);
274
+ }
275
+
276
+ $title_font = $lead_font = $text_font = $bold_font = false;
277
+ if (isset($use_font['title'])) {
278
+ $title_font = $this->get_fonts('title', $post_font_data, $use_font['title']);
279
+ }
280
+ if (isset($use_font['lead'])) {
281
+ $lead_font = $this->get_fonts('lead', $post_font_data, $use_font['lead']);
282
+ }
283
+ if (! isset($use_font['content']) && isset($use_font['text'])) {
284
+ $use_font['content'] = $use_font['text'];
285
+ }
286
+ if (isset($use_font['content'])) {
287
+ $text_font = $this->get_fonts('text', $post_font_data, $use_font['content']);
288
+ }
289
+ if (isset($use_font['bold'])) {
290
+ $bold_font = $this->get_fonts('bold', $post_font_data, $use_font['bold']);
291
+ }
292
+
293
+ if ($title_target && $title_font) {
294
+ $style .= "{$title_target}{ font-family: {$title_font};}";
295
+ }
296
+ if ($lead_target && $lead_font) {
297
+ $style .= "{$lead_target}{ font-family: {$lead_font};}";
298
+ }
299
+ if ($text_target && $text_font) {
300
+ $style .= "{$text_target}{ font-family: {$text_font};}";
301
+ }
302
+ if ($bold_target && $bold_font) {
303
+ $style .= "{$bold_target}{ font-family: {$bold_font};}";
304
+ }
305
+
306
+ return $style;
307
+ }
308
+
309
+ private function _get_site_font_styles()
310
+ {
311
+ $fonts = TypeSquare_ST_Fonts::get_instance();
312
+ $site_font_settings = $fonts->get_site_font_setting();
313
+ $title_fontname = '';
314
+ $catchcopy_fontname = '';
315
+ $widget_title_fontname = '';
316
+ $widget_fontname = '';
317
+ if (is_array($site_font_settings)) {
318
+ $title_fontname = $site_font_settings['title_fontname'];
319
+ $catchcopy_fontname = $site_font_settings['catchcopy_fontname'];
320
+ $widget_title_fontname = $site_font_settings['widget_title_fontname'];
321
+ $widget_fontname = $site_font_settings['widget_fontname'];
322
+ }
323
+ $style = '';
324
+ if ($title_fontname) {
325
+ $title_target = ".site-branding .site-title a:lang(ja),.site-title";
326
+ $style .= "{$title_target}{ font-family: '{$title_fontname}';}";
327
+ }
328
+ if ($catchcopy_fontname) {
329
+ $catchcopy_target = ".site-description:lang(ja)";
330
+ $style .= "{$catchcopy_target}{ font-family: '{$catchcopy_fontname}';}";
331
+ }
332
+ if ($widget_title_fontname) {
333
+ $widget_title_target = "section.widget h2:lang(ja),.widget-title";
334
+ $style .= "{$widget_title_target}{ font-family: '{$widget_title_fontname}';}";
335
+ }
336
+ if ($widget_fontname) {
337
+ $widget_target = "section.widget ul li:lang(ja),.widget-content ul li";
338
+ $style .= "{$widget_target}{ font-family: '{$widget_fontname}';}";
339
+ }
340
+
341
+ return $style;
342
+ }
343
+
344
+ private function _get_pro_font_styles($font_pro_settings, $post_id = false)
345
+ {
346
+ $style = '';
347
+ foreach ($font_pro_settings as $font_pro_setting) {
348
+ foreach ($font_pro_setting['fontlist_cls'] as $fontlist_cls) {
349
+ $target = esc_attr($fontlist_cls);
350
+ if ($post_id) {
351
+ $post_key = '#post-'. $post_id;
352
+ if ('.hentry' == $target) {
353
+ $target = "{$post_key}{$target}";
354
+ } else {
355
+ $target = "{$post_key} {$target}";
356
+ }
357
+ }
358
+ $fontf_amily = $font_pro_setting['fontlist_fontname'];
359
+ $style .= "{$target}{ font-family: '{$fontf_amily}';}";
360
+ }
361
+ }
362
+ return $style;
363
+ }
364
  }
365
 
366
  // クラシックエディタにフォントリスト追加
374
  // return $plugins;
375
  // } );
376
 
377
+ add_filter('mce_buttons', function ($buttons) {
378
+ $auth = TypeSquare_ST_Auth::get_instance();
379
+ $param = $auth->get_auth_status();
380
+ if ('' !== $param['typesquare_id']) {
381
+ $buttons[] = 'fontfamily_button';
382
+ }
383
+ return $buttons;
384
+ });
385
+
386
+ register_uninstall_hook(__FILE__, 'ts_uninstall');
387
+ function ts_uninstall()
388
+ {
389
+ delete_option('typesquare_auth');
390
+ delete_option('typesquare_fonttheme');
391
+ delete_option('typesquare_custom_theme');
392
+ delete_option('typesquare_pro_setting');
393
+ delete_option('typesquare_site_font_setting');
394
+ return;
395
+ }