PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/customize.php

https://gitlab.com/kishikeisuke/estatesale
PHP | 252 lines | 193 code | 44 blank | 15 comment | 7 complexity | 8612ac9582338a836aebd524fd0d0a13 MD5 | raw file
  1. <?php
  2. /**
  3. * WpTHK WordPress Theme - free/libre wordpress platform
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * @copyright Copyright (C) 2015 Thought is free.
  11. * @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
  12. * @author LunaNuko
  13. * @link http://thk.kanzae.net/
  14. * @translators rakeem( http://rakeem.jp/ )
  15. */
  16. class wpthk_customize {
  17. private $_active = '';
  18. private $_page = '';
  19. private $_tabs = array();
  20. public function __construct() {
  21. }
  22. public function wpthk_custom_form() {
  23. $this->_page = isset( $_GET['page'] ) ? $_GET['page'] : 'wpthk';
  24. echo '<div class="wrap narrow">';
  25. if( $this->_page === 'wpthk' ) {
  26. $this->_active = isset( $_GET['active'] ) ? $_GET['active'] : 'header';
  27. $this->_tabs = array(
  28. 'header' => 'Head ' . __( 'tag', 'wpthk' ),
  29. 'title' => 'Title ' . __( 'tag', 'wpthk' ),
  30. 'optimize' => __( 'Compression and optimization', 'wpthk' ),
  31. 'style' => 'CSS',
  32. 'script' => 'Javascript',
  33. 'search' => __( 'Search', 'wpthk' ),
  34. 'adsense' => __( 'Advertisement', 'wpthk' ),
  35. 'others' => __( 'Others', 'wpthk' ),
  36. 'htaccess' => __( 'htaccess for speed boost', 'wpthk' ),
  37. 'backup' => __( 'Backup', 'wpthk' ),
  38. 'reset' => __( 'Reset', 'wpthk' ),
  39. 'version' => __( 'Version', 'wpthk' ),
  40. );
  41. echo '<h2 class="wpthk-customize-title">', esc_html( str_replace( array( '<h2>', '</h2>' ), '', get_admin_page_title() ) ),
  42. '<spna class="wpthk-title-button-block"><span class="wpthk-title-button"><a href="', esc_url( admin_url( 'customize.php?return=/wp-admin/admin.php?page=' . $this->_page . '&wpthk=custom' ) ) ,'" ',
  43. 'class="button button-primary">', __( 'Customizing the Appearance', 'wpthk' ), '</a></span>',
  44. '<span class="wpthk-title-button"><a href="', esc_url( admin_url( 'admin.php?page=wpthk_sns' ) ) ,'" ',
  45. 'class="button button-primary">SNS ' . __( 'Counter', 'wpthk' ) . '</a></span></span></h2>';
  46. }
  47. elseif( $this->_page === 'wpthk_sns' ) {
  48. $this->_active = isset( $_GET['active'] ) ? $_GET['active'] : 'sns_post';
  49. $this->_tabs = array(
  50. 'sns_post' => __( 'Post page', 'wpthk' ),
  51. 'sns_page' => __( 'Static page', 'wpthk' ),
  52. 'sns_home' => __( 'Top page', 'wpthk' ),
  53. 'sns_setting' => __( 'Settings', 'wpthk' ),
  54. );
  55. echo '<h2>SNS ' . __( 'Counter', 'wpthk' ) . ' ' . __( 'Cache', 'wpthk' ) . ' ' . __( 'Control', 'wpthk' ) . '</h2>';
  56. }
  57. else {
  58. $this->_active = isset( $_GET['active'] ) ? $_GET['active'] : 'edit_style';
  59. $this->_tabs = array(
  60. 'edit_style' => 'style.css',
  61. 'edit_script' => 'Javascript',
  62. 'edit_header' => 'Head ' . __( 'tag', 'wpthk' ),
  63. 'edit_footer' => __( 'Footer', 'wpthk' ),
  64. 'edit_functions' => 'functions.php',
  65. );
  66. echo '<h2>' . __( 'Child Theme Editor', 'wpthk' ) . '</h2>';
  67. }
  68. echo '<h2 class="nav-tab-wrapper">';
  69. foreach( $this->_tabs as $key => $val ) {
  70. register_setting( $key, $key, 'esc_attr' );
  71. echo '<a href="', esc_url( admin_url( 'admin.php?page=' . $this->_page . '&active=' . $key ) ) ,'" ',
  72. 'class="nav-tab', $this->_active === $key ? ' nav-tab-active' : '', '">', esc_html( $val ), '</a>';
  73. }
  74. echo '</h2>';
  75. settings_errors( 'wpthk-custom' );
  76. $form = false;
  77. if(
  78. $this->_active !== 'backup' &&
  79. $this->_active !== 'htaccess' &&
  80. $this->_active !== 'version' &&
  81. $this->_active !== 'sns_post' &&
  82. $this->_active !== 'sns_page' &&
  83. $this->_active !== 'sns_home'
  84. ) $form = true;
  85. // options.php は経由しないので、nonce のチェックは check_admin_referer でやる
  86. if( $form === true ) echo '<form id="wpthk-customize" method="post" action="">';
  87. $func = '_' . $this->_active . '_section';
  88. if( method_exists( $this, $func ) === true ) {
  89. $this->$func();
  90. }
  91. else {
  92. $this->_empty_section();
  93. }
  94. settings_fields( $this->_active );
  95. ob_start();
  96. do_settings_sections( $this->_active );
  97. $settings = ob_get_clean();
  98. $settings = str_replace( '<h2>', '<fieldset class="wpthk-field"><legend><h2 class="wpthk-field-title">', $settings );
  99. $settings = str_replace( '</h2>', '</h2></legend>', $settings );
  100. echo $settings;
  101. if( $_GET['page'] === 'wpthk_edit' ) {
  102. submit_button( '', 'primary', 'edit_save', true, array( 'disabled' => 1 ) );
  103. echo '</form>';
  104. }
  105. elseif( $form === true ) {
  106. submit_button( '', 'primary', 'save', true, array( 'disabled' => 1 ) );
  107. echo '</form>';
  108. }
  109. ?>
  110. </div>
  111. <script>
  112. jQuery(document).ready(function($) {
  113. $('#wpthk-customize').bind('keyup change', function() {
  114. $("#save").prop("disabled", false);
  115. });
  116. $('.wpthk-field-title').click(function() {
  117. $(this).parent().nextAll().toggle();
  118. });
  119. });
  120. </script>
  121. <?php
  122. }
  123. public function sections( $args ) {
  124. get_template_part( 'inc/sections/' . $args['id'] );
  125. echo '</fieldset>';
  126. }
  127. private function _header_section() {
  128. $suffix = get_locale() === 'ja' ? ' 関連' : '';
  129. add_settings_section( 'seo', 'SEO' . $suffix, array( $this, 'sections' ), $this->_active );
  130. add_settings_section( 'ogp', 'OGP' . $suffix, array( $this, 'sections' ), $this->_active );
  131. }
  132. private function _title_section() {
  133. add_settings_section( 'title', sprintf( __( 'Setting of %s', 'wpthk' ), 'Title ' . __( 'tag', 'wpthk' ) ), array( $this, 'sections' ), $this->_active );
  134. }
  135. private function _optimize_section() {
  136. add_settings_section( 'optimize-html', __( 'Compression of HTML', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  137. add_settings_section( 'optimize-css', __( 'Optimization of CSS', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  138. add_settings_section( 'optimize-script', __( 'Optimization of Javascript', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  139. }
  140. private function _style_section() {
  141. add_settings_section( 'mode-select', __( 'Mode select', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  142. add_settings_section( 'css-to-style', __( 'Direct output of external CSS', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  143. add_settings_section( 'child-css', __( 'CSS of child theme', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  144. add_settings_section( 'fontawesome', __( 'CSS of icon fonts', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  145. add_settings_section( 'widget-css', __( 'CSS of widgets', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  146. }
  147. private function _script_section() {
  148. add_settings_section( 'jquery', 'jQuery', array( $this, 'sections' ), $this->_active );
  149. add_settings_section( 'bootstrap', 'Bootstrap ' . __( 'Plugins', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  150. add_settings_section( 'script', __( 'Other setting of Javascript', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  151. }
  152. private function _search_section() {
  153. add_settings_section( 'search', sprintf( __( 'Setting of %s', 'wpthk' ), __( 'Search Widget', 'wpthk' ) ), array( $this, 'sections' ), $this->_active );
  154. }
  155. private function _adsense_section() {
  156. add_settings_section( 'adsense', __( 'Advertisement', 'wpthk' ) . ' ( ' . __( 'Adsense', 'wpthk' ) . ' )', array( $this, 'sections' ), $this->_active );
  157. }
  158. private function _others_section() {
  159. add_settings_section( 'others', sprintf( __( 'Setting of %s', 'wpthk' ), __( 'Others', 'wpthk' ) ), array( $this, 'sections' ), $this->_active );
  160. }
  161. private function _htaccess_section() {
  162. add_settings_section( 'htaccess', __( 'htaccess for speed boost', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  163. }
  164. private function _backup_section() {
  165. add_settings_section( 'backup', __( 'Back up WpTHK', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  166. add_settings_section( 'restore', __( 'Restore WpTHK', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  167. }
  168. private function _reset_section() {
  169. add_settings_section( 'all_clear', __( 'RESET all the customizations of WpTHK', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  170. add_settings_section( 'sns-cache-cleanup', __( 'Clean up of SNS count cache', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  171. }
  172. private function _version_section() {
  173. add_settings_section( 'version', '', array( $this, 'sections' ), $this->_active );
  174. }
  175. private function _sns_setting_section() {
  176. add_settings_section( 'sns-cache-setting', sprintf( __( 'Setting of %s', 'wpthk' ), __( 'cache', 'wpthk' ) ), array( $this, 'sections' ), $this->_active );
  177. add_settings_section( 'sns-cache-cleanup', __( 'Clean up of SNS count cache', 'wpthk' ), array( $this, 'sections' ), $this->_active );
  178. }
  179. private function _sns_post_section() {
  180. get_template_part( 'inc/sns-count-view' );
  181. $cache_view = new cache_control();
  182. add_settings_section( 'sns-cache-list', '', array( $cache_view, 'sns_cache_list' ), $this->_active );
  183. }
  184. private function _sns_page_section() {
  185. $this->_sns_post_section();
  186. }
  187. private function _sns_home_section() {
  188. $this->_sns_post_section();
  189. }
  190. private function _edit_style_section() {
  191. get_template_part( 'inc/theme-editor' );
  192. }
  193. private function _edit_script_section() {
  194. $this->_edit_style_section();
  195. }
  196. private function _edit_header_section() {
  197. $this->_edit_style_section();
  198. }
  199. private function _edit_footer_section() {
  200. $this->_edit_style_section();
  201. }
  202. private function _edit_functions_section() {
  203. $this->_edit_style_section();
  204. }
  205. private function _empty_section() {
  206. return;
  207. }
  208. }