PluginProbe ʕ •ᴥ•ʔ
SEO SIMPLE PACK / trunk
SEO SIMPLE PACK vtrunk
1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 2.0.0 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.4.0 2.4.1 2.4.2 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.3.0 3.3.1 3.4.0 3.5.0 3.5.1 3.5.2 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2
seo-simple-pack / class / data.php
seo-simple-pack / class Last commit date
trait 1 year ago __branch.php 5 years ago activate.php 1 year ago data.php 1 year ago hooks.php 1 year ago menu.php 1 year ago metabox.php 1 year ago output.php 1 year ago output_helper.php 1 year ago update_action.php 3 years ago utility.php 1 year ago
data.php
275 lines
1 <?php
2
3 class SSP_Data {
4
5 /**
6 * 外部からのインスタンス化を防ぐ
7 */
8 private function __construct() {}
9
10 /**
11 * 使用するDBの名前
12 */
13 const DB_NAME = [
14 'installed' => 'ssp_installed',
15 'notification' => 'ssp_notification',
16 'settings' => 'ssp_settings',
17 'ogp' => 'ssp_ogp',
18 ];
19
20 /**
21 * DB[ssp_settings]用変数
22 */
23 public static $settings = null;
24
25 /**
26 * DB[spp_ogp]用変数
27 */
28 public static $ogp = null;
29
30 /**
31 * サイト基本�
32
33 */
34 public static $site_title = '';
35 public static $site_catch_phrase = '';
36
37 /**
38 * �
39 �通テキスト
40 */
41 public static $texts = '';
42
43 /**
44 * 設定のデフォルト値
45 */
46 public static $default_settings = []; // 基本設定のデフォルト値
47 public static $default_ogp_settings = []; // OGP設定のデフォルト値
48 public static $default_pt_settings = []; // カスタム投稿のフォーマット形式
49 public static $default_tax_settings = []; // カスタムタクソノミーのフォーマット形式
50
51 /**
52 * カスタム投稿タイプ・カスタムタクソノミーを保持しておくための変数。
53 * 形式: [ 'name' => 'label' ]
54 */
55 public static $custom_post_types = [];
56 public static $custom_taxonomies = [];
57
58 /**
59 * nonce
60 */
61 const NONCE_ACTION = 'ssp_nonce_action';
62 const NONCE_NAME = 'ssp_nonce_name';
63
64 /**
65 * 区切り文字リスト
66 */
67 const SEPARATORS = [
68 'dash' => '-',
69 'line' => '|',
70 'tilde' => '~',
71 ];
72
73
74 /**
75 * Set Data
76 */
77 public static function init() {
78
79 // �
80 �通の翻訳用テキスト
81 self::$texts = [
82 'quoted_title' => __( '"%s"', 'seo-simple-pack' ),
83 'quoted_archive_title' => __( '"%s" archive page', 'seo-simple-pack' ),
84 'is_snippet' => __( 'This content is treated as %s.', 'seo-simple-pack' ), // この�
85 容は %s として扱われます。
86 'title_of' => __( 'Title tag of %s', 'seo-simple-pack' ), // %sのタイトルタグ
87 'description_of' => __( 'Description of %s', 'seo-simple-pack' ), // %sのディスクリプション
88 'keyword_of' => __( 'Keywords of %s', 'seo-simple-pack' ),
89 'title_tag' => __( 'Title tag format', 'seo-simple-pack' ), // タイトルタグの形式
90 'description_tag' => __( 'Description format', 'seo-simple-pack' ), // ディスクリプションの形式
91 'use' => __( 'Use %s', 'seo-simple-pack' ), // %sを使用する
92 'nouse' => __( 'Do not use %s', 'seo-simple-pack' ), // を使用しない
93 'noindex' => __( 'Do not index %s', 'seo-simple-pack' ), // sをインデックスさせない
94 'noindex_help' => __( 'If you select "Yes", the default output will be <code>noindex</code>.', 'seo-simple-pack' ),
95 'default_output' => __( 'The default setting of %2$s to be output to %1$s.', 'seo-simple-pack' ),
96 'input' => __( 'Please enter %s.', 'seo-simple-pack' ),
97 'reflect' => __( 'It will be reflected in %s.', 'seo-simple-pack' ),
98 'archive_desc' => __( 'This is the archive page for %s.', 'seo-simple-pack' ),
99 ];
100
101 // 設定のデフォルト値をセット
102 self::set_default();
103
104 // インストール済みバージョン�
105 報を取得
106 $installed_version = get_option( self::DB_NAME['installed'] );
107
108 if ( false === $installed_version ) {
109 // インストール時に実行する処理
110 self::setup_at_installed();
111
112 } elseif ( SSP_VERSION !== $installed_version ) {
113 // バージョン更新時に実行する処理
114 \LOOS\SSP\Update_Action::setup_at_updated( $installed_version );
115 }
116
117 // データセット
118 self::setup_data();
119 }
120
121
122 /**
123 * デフォルト値をセット
124 */
125 public static function set_default() {
126 self::$default_settings = [
127 'home_title' => '%_site_title_% %_sep_% %_tagline_%',
128 'home_desc' => '',
129 'home_keyword' => '',
130 'reuse_keyword' => '1',
131 'separator' => 'line',
132 'webmaster_bing' => '',
133 'webmaster_google' => '',
134 'webmaster_baidu' => '',
135 'webmaster_yandex' => '',
136 'google_analytics_type' => 'gtag',
137 'google_analytics_id' => '',
138 'google_g_id' => '',
139 'google_ua_id' => '',
140 'post_noindex' => false,
141 'post_title' => '%_page_title_% %_sep_% %_site_title_%',
142 'post_desc' => '%_page_contents_%',
143 'page_noindex' => false,
144 'page_title' => '%_page_title_% %_sep_% %_site_title_%',
145 'page_desc' => '%_page_contents_%',
146 'attachment_disable' => true,
147 'attachment_noindex' => true,
148 'attachment_title' => '%_page_title_% %_sep_% %_site_title_%',
149 'attachment_desc' => '%_page_contents_%',
150 'cat_noindex' => false,
151 'cat_title' => '%_term_name_% %_sep_% %_site_title_%',
152 'cat_desc' => '%_term_description_%',
153 'tag_noindex' => false,
154 'tag_title' => '%_term_name_% %_sep_% %_site_title_%',
155 'tag_desc' => '%_term_description_%',
156 'post_format_disable' => false,
157 'post_format_noindex' => true,
158 'post_format_title' => '%_term_name_% %_sep_% %_site_title_%',
159 'post_format_desc' => '',
160 'author_disable' => false,
161 'author_noindex' => true,
162 'author_title' => '%_author_name_% %_sep_% %_site_title_%',
163 'author_desc' => sprintf( self::$texts['archive_desc'], '%_author_name_%' ),
164 'date_noindex' => true,
165 'date_title' => '%_date_% %_sep_% %_site_title_%',
166 'date_desc' => sprintf( self::$texts['archive_desc'], '%_date_%' ),
167 'pt_archive_noindex' => true,
168 'pt_archive_title' => '%_post_type_% %_sep_% %_site_title_%',
169 'pt_archive_desc' => sprintf( self::$texts['archive_desc'], '%_post_type_%' ),
170 '404_title' => '404: ' . __( 'Page not found', 'seo-simple-pack' ) . ' %_sep_% %_site_title_%',
171 'search_title' => __( 'Searched:', 'seo-simple-pack' ) . ' %_search_phrase_% %_sep_% %_site_title_%',
172 'feed_noindex' => false,
173 ];
174
175 self::$default_ogp_settings = [
176 'og_image' => '',
177 'fb_active' => true,
178 'fb_url' => '',
179 'fb_app_id' => '',
180 'fb_admins' => '',
181 'tw_active' => true,
182 'tw_account' => '',
183 'tw_card' => 'summary',
184 ];
185
186 /**
187 * カスタム投稿のフォーマット形式
188 */
189 self::$default_pt_settings = [
190 'noindex' => false,
191 'title' => '%_page_title_% %_sep_% %_site_title_%',
192 'desc' => '%_page_contents_%',
193 ];
194
195 /**
196 * カスタムタクソノミーのフォーマット形式
197 */
198 self::$default_tax_settings = [
199 'noindex' => true,
200 'title' => '%_term_name_% %_sep_% %_site_title_%',
201 'desc' => '%_term_description_%',
202 ];
203 }
204
205 /**
206 * データを変数にセット
207 */
208 public static function setup_data() {
209 // サイト基本�
210 報取得
211 self::$site_title = get_option( 'blogname' );
212 self::$site_catch_phrase = get_option( 'blogdescription' );
213
214 // 一般設定データ
215 $saved_settings = get_option( self::DB_NAME['settings'] ) ?: [];
216 self::$settings = array_merge( self::$default_settings, $saved_settings );
217
218 // OGP設定
219 $saved_ogp_settings = get_option( self::DB_NAME['ogp'] ) ?: [];
220 self::$ogp = array_merge( self::$default_ogp_settings, $saved_ogp_settings );
221 }
222
223
224 /**
225 * 設定値の取得
226 */
227 public static function get( $db_name, $key ) {
228 if ( 'settings' === $db_name ) {
229 $data = self::$settings;
230 } elseif ( 'ogp' === $db_name ) {
231 $data = self::$ogp;
232 } else {
233 return;
234 }
235
236 if ( isset( $data[ $key ] ) ) {
237 return $data[ $key ];
238 } else {
239 return false;
240 }
241 }
242
243
244 /**
245 * インストール時に実行する処理
246 */
247 public static function setup_at_installed() {
248
249 update_option( self::DB_NAME['installed'], SSP_VERSION );
250 // update_option( SSP_Data::DB_NAME[ 'notification' ], 'hide' );
251
252 // デフォルト設定を保存
253 update_option( self::DB_NAME['settings'], self::$default_settings );
254 update_option( self::DB_NAME['ogp'], self::$default_ogp_settings );
255 }
256
257
258 /**
259 * 設定保存時の処理ではなく、コードによる更新
260 * $db_name: 'settings' or 'ogp'
261 */
262 public static function update_data( $db_name, $new_data, $delete_data = [] ) {
263
264 $now_data = get_option( self::DB_NAME[ $db_name ] ) ?: [];
265 $new_data = array_merge( $now_data, $new_data );
266
267 // 不要になったデータを削除
268 foreach ( $delete_data as $key ) {
269 if ( isset( $new_data[ $key ] ) ) unset( $new_data[ $key ] );
270 }
271
272 update_option( self::DB_NAME[ $db_name ], $new_data );
273 }
274 }
275