PluginProbe
HootKit / trunk
HootKit vtrunk
trunk 2.0.21 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5
hootkit / misc / tools / class-tools.php

class-tools.php in HootKit trunk, at misc/tools/class-tools.php

238 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Tools class
4 * This file is loaded at plugins_loaded@5 for is_admin()
5 *
6 * @since 3.0.0
7 * @package Hootkit
8 */
9
10 namespace HootKit\Mods;
11
12 // If this file is called directly, abort.
13 if ( ! defined( 'ABSPATH' ) ) {
14 die;
15 }
16
17 if ( ! class_exists( '\HootKit\Mods\Tools' ) ) :
18
19 class Tools {
20
21 /**
22 * Class Instance
23 */
24 private static $instance;
25
26 /**
27 * Is this a plugin?
28 */
29 private static $toolsplugin = false;
30
31 /**
32 * Plugin subdirectory
33 */
34 public $dir;
35 public $uri;
36
37 /**
38 * Setup Tools
39 */
40 public function __construct() {
41 // Set directories
42 $this->dir = trailingslashit( hootkit()->dir . 'misc/tools' );
43 $this->uri = trailingslashit( hootkit()->uri . 'misc/tools' );
44 add_action( 'after_setup_theme', array( $this, 'loader' ), 94 );
45 }
46
47 /**
48 * Load if tools is enabled by themes
49 * @since 3.0.0
50 * @access public
51 * @return void
52 */
53 public function loader() {
54
55 /* Get values if Tools is an embedded plugin */
56 $dash = hootkit()->get_config( 'dashboard' );
57 // if registered wphoot theme, sanitizeconfig has already made sure all required values exist
58 // 'tools', 'tabfilter', 'tabaction', hoot_dashboard() => we can reliably use them here.
59 if ( is_array( $dash ) && !empty( $dash[ 'tools' ] ) ) {
60 self::$toolsplugin = array(
61 'pagehook' => hoot_dashboard( 'screen' ),
62 'dashurl' => hoot_dashboard( 'url', array( 'tab' => $dash[ 'tools' ] ) ),
63 'tabfilter' => $dash['tabfilter'],
64 'tabaction' => $dash['tabaction']
65 );
66 }
67
68 if ( self::$toolsplugin ) {
69
70 // Check if tools has been disabled by user
71 $activemiscmods = hootkit()->get_config( 'activemods', 'misc' );
72 $isactive = is_array( $activemiscmods ) && in_array( 'tools', $activemiscmods );
73
74 if ( ! $isactive ) :
75 add_filter( self::$toolsplugin['tabfilter'], array( $this, 'unplug_tabs' ), 90, 2 );
76 else:
77 // Render Content
78 add_filter( self::$toolsplugin['tabfilter'], array( $this, 'plug_tabs' ), 90, 2 );
79 add_action( self::$toolsplugin['tabaction'], array( $this, 'plug_modblock_content' ), 90, 4 );
80 // Add Module
81 if ( is_admin() && current_user_can( 'edit_theme_options' ) ) {
82 require_once( $this->dir . 'import.php' );
83 require_once( $this->dir . 'export.php' );
84 }
85 endif;
86 }
87 }
88
89 /**
90 * Remove Tabs if exist
91 *
92 * @since 3.0.0
93 * @access public
94 * @return void
95 */
96 public function unplug_tabs( $tabsarray, $sanetags ) {
97 $order = !empty( $tabsarray['order'] ) && is_array( $tabsarray['order'] ) ? $tabsarray['order'] : array();
98 $order = array_values( array_diff( $order, array( 'tools' ) ) ); // array_values() to reindex numerically
99 $tabsarray['order'] = $order;
100 if ( isset( $tabsarray['tools'] ) ) unset( $tabsarray['tools'] );
101 return $tabsarray;
102 }
103
104 /**
105 * Load Tabs Content
106 *
107 * @since 3.0.0
108 * @access public
109 * @return void
110 */
111 public function plug_tabs( $tabsarray, $sanetags ) {
112 $order = !empty( $tabsarray['order'] ) && is_array( $tabsarray['order'] ) ? $tabsarray['order'] : array();
113
114 if ( !in_array( 'tools', $order ) ) $order[] = 'tools';
115 $tabsarray['tools'] = array(
116 'label' => __( 'Tools', 'hootkit' ),
117 'inpage' => true,
118 'content' => $this->plug_displayarray( $sanetags ),
119 );
120
121 $tabsarray['order'] = $order;
122 return $tabsarray;
123 }
124
125 /**
126 * Tabs Module Data
127 *
128 * @since 3.0.0
129 * @access public
130 * @return void
131 */
132 public function plug_displayarray( $sanetags ) {
133 $tblocks = array();
134
135 $tblocks[ 'notice' ] = array(
136 'type' => 'notice',
137 'gridtype' => 'gen',
138 'src' => 'action',
139 'action' => 'hootkit_manager_toolsimport_notice',
140 );
141
142 $tblocks[ 'grid-imp' ] = array( 'type' => 'gridconbox' );
143 $tblocks[ 'imp' ] = array(
144 'type' => 'import',
145 'name' => esc_html__( 'Import Customizer Settings', 'hootkit' ),
146 /* Translators: The %s are placeholders for HTML, so the order can't be changed. */
147 'desc' => sprintf( esc_html__( 'Paste your exported code here from another theme/installation, and click the Import button. %1$s%7$s%10$s %3$sWARNING:%4$s All your current customizer settings will be overwritten.%8$s%9$s%5$s(It is recommended to backup your database before making any changes to your site; or at the very least copy and save the customizer settings for current active theme below to a text file on your computer.)%6$s%2$s', 'hootkit' ), '<p class="hootabt-warning">', '</p>', '<strong>', '</strong>', '<em>', '</em>', '<span>', '</span>', '<br />', '<span class="dashicons dashicons-warning"></span>' ),
148 );
149 $tblocks[ 'grid-impend' ] = array( 'type' => 'gridconboxend' );
150
151 $tblocks[ 'grid-exp' ] = array( 'type' => 'gridconbox' );
152 $tblocks[ 'exp' ] = array(
153 'type' => 'export',
154 'name' => esc_html__( 'Export Customizer Settings', 'hootkit' ),
155 /* Translators: The %s are placeholders for HTML, so the order can't be changed. */
156 'desc' => sprintf( esc_html__( 'Copy this code to export Customizer Settings for a particular theme%5$s%1$s%3$s(only wphoot themes are displayed here)%2$s%4$s', 'hootkit' ), '<strong>', '</strong>', '<em>', '</em>', '<br />' ),
157 );
158 $tblocks[ 'grid-expend' ] = array( 'type' => 'gridconboxend' );
159
160 return $tblocks;
161 }
162
163 /**
164 * Extra Tabs Module Block Templates
165 *
166 * @since 3.0.0
167 * @access public
168 * @return void
169 */
170 public function plug_modblock_content( $blockid, $modblock, $sanetags, $tabid ) {
171 if ( empty( $modblock ) || ! is_array( $modblock ) || ! isset( $modblock['type'] ) ) {
172 return;
173 }
174 $sanetags = is_array( $sanetags ) ? $sanetags : array();
175
176 if ( $modblock['type'] === 'import' ) {
177 if ( !empty( $modblock['name'] ) || !empty( $modblock['desc'] ) ) :
178 ?><div class="hootabt-blocktext"><?php
179 if ( !empty( $modblock['name'] ) )
180 echo '<h4 class="hootabt-blocktitle">' . wp_kses_post( $modblock['name'] ) . '</h4>';
181 if ( !empty( $modblock['desc'] ) )
182 echo '<div class="hootabt-blockdesc">' . wp_kses_post( $modblock['desc'] ) . '</div>';
183 ?></div><?php
184 endif;
185 if ( ! current_user_can( 'edit_theme_options' ) ) :
186 echo '<p class="hootabt-notice hootabt-notice--error"><span class="dashicons dashicons-warning"></span> ' . esc_html__( 'You do not have sufficient permissions to access these options. Please contact the site administrator', 'hootkit' ) . '</p>';
187 else:
188 do_action( 'hootkit_manager_toolsimport', $sanetags, self::$toolsplugin );
189 endif;
190 }
191
192 if ( $modblock['type'] === 'export' ) {
193 if ( !empty( $modblock['name'] ) || !empty( $modblock['desc'] ) ) :
194 ?><div class="hootabt-blocktext"><?php
195 if ( !empty( $modblock['name'] ) )
196 echo '<h4 class="hootabt-blocktitle">' . wp_kses_post( $modblock['name'] ) . '</h4>';
197 if ( !empty( $modblock['desc'] ) )
198 echo '<div class="hootabt-blockdesc">' . wp_kses_post( $modblock['desc'] ) . '</div>';
199 ?></div><?php
200 endif;
201 if ( ! current_user_can( 'edit_theme_options' ) ) :
202 echo '<p class="hootabt-notice hootabt-notice--error"><span class="dashicons dashicons-warning"></span> ' . esc_html__( 'You do not have sufficient permissions to access these options. Please contact the site administrator', 'hootkit' ) . '</p>';
203 else:
204 do_action( 'hootkit_manager_toolsexport', $sanetags, self::$toolsplugin );
205 endif;
206 }
207 }
208
209 /**
210 * Returns the instance
211 * @since 3.0.0
212 * @access public
213 * @return object
214 */
215 public static function get_instance() {
216 if ( ! isset( self::$instance ) ) {
217 self::$instance = new self();
218 }
219 return self::$instance;
220 }
221
222 }
223
224 /**
225 * Gets the instance of the class. This function is useful for quickly grabbing data
226 * used throughout the plugin.
227 * @since 3.0.0
228 * @access public
229 * @return object
230 */
231 function hootkittools() {
232 return Tools::get_instance();
233 }
234
235 // Lets roll!
236 hootkittools();
237
238 endif;