-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanche-wordpress.php
More file actions
263 lines (218 loc) · 8.83 KB
/
planche-wordpress.php
File metadata and controls
263 lines (218 loc) · 8.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* Plugin Name: Planche for wordPress
* Plugin URI: https://github.com/plancheproject/planche/
* Description: The MySQL GUI tool planche for wordpress
* Version: 1.0.0
* Author: Jeong Ju Won(2jw0718@gmail.com)
* License: GPLv2 or later
*/
define('PLANCHE_DEBUG', @file_get_contents(__DIR__."/.debug") == 'true');
add_action('init', 'planche_wp_post_type', 0);
add_action('admin_menu', 'planche_menu');
add_action('admin_menu', 'planche_cors_option');
// add_action('admin_menu', 'planche_settings');
add_action('wp_ajax_planche_wp_tunneling', 'planche_wp_tunneling');
add_action('wp_ajax_nopriv_planche_wp_tunneling', 'planche_wp_need_login');
add_filter('user_can_richedit', 'disable_wysiwyg_for_bookmark');
register_activation_hook( __FILE__, 'planche_activate' );
function disable_wysiwyg_for_bookmark($default) {
global $post;
if ('bookmarksql' == get_post_type($post))
return false;
return $default;
}
function planche_activate(){
$user_id = get_current_user_id();
$option = 'planche-config-'.$user_id;
$config = get_option($option);
if(!$config){
$config = array();
$config['autoLoadConnectionWindow'] = false;
$config['hosts'] = array(array(
"index" => '0',
"hostName" => "This wordpress",
"tunnelingURL" => "tunneling/wordpress.php",
"requestType" => "jsonp",
"host" => DB_HOST,
"user" => DB_USER,
"pass" => DB_PASSWORD,
"charset" => DB_CHARSET,
"db" => DB_NAME,
"port" => "3306",
"dbms" => "mysql",
"autoConnection"=> true
));
$config['noIndexing'] = array(
'information_schema',
'performance_schema',
'mysql'
);
add_option($option, json_encode($config));
}
}
function register_mysettings()
{
register_setting('planche-option-group', 'planche-cors');
// register_setting('planche-option-group', 'planche-settings');
}
function planche_wp_need_login()
{
require_once 'includes/Planche.php';
require_once 'includes/PlancheWPDB.php';
$Planche = new Planche();
$Planche->error('You need to login as administrator.');
exit;
}
function planche_menu()
{
add_menu_page('Planche', 'Planche', 'manage_options', 'planche', 'planche_view', 'dashicons-list-view', 39);
}
function planche_cors_option()
{
add_action('admin_init', 'register_mysettings');
add_submenu_page('planche', 'Planche Cors Domain Setting', 'Cors Domain Setting', 'manage_options', 'planche-cors', 'planche_cors_setting_page');
}
function planche_settings()
{
// add_action('admin_init', 'register_mysettings');
add_submenu_page('planche', 'Planche Settings', 'Planche Settings', 'manage_options', 'planche-settings', 'planche_settings_page');
}
function planche_view()
{
?>
<style>
#planche-wp-container {
padding:100px;
text-align:center;
}
</style>
<div id="planche-wp-container">
<div id="planche-wp-intro" style="width: 100%;height: 100%">
<div><img src="<?php echo plugin_dir_url(__FILE__)?>resources/images/logo.jpg"/></div>
<div style="text-align:left;border:1px solid #000000;padding:10px;margin:20px">
<h1>Your tunneling URL is : </h1>
<h2><span class="dashicons dashicons-external"></span> Absolute</h2> <?php echo plugin_dir_url(__FILE__);?>tunneling/wordpress.php
<h2><span class="dashicons dashicons-external"></span> Relative</h2> tunneling/wordpress.php
</div>
<div>
<input type="button" id="btn-run-planche" class="button button-primary" value="Run planche"/>
</div>
</div>
</div>
<script>
(function($) {
$("#btn-run-planche").click(function(){
var win = window.open('<?php echo plugin_dir_url(__FILE__)?>index.html', 'Planche', '_blacnk');
win.focus();
});
})(jQuery);
</script>
<?php
}
function planche_wp_post_type()
{
$labels = array(
'name' => _x('Bookmark SQLs', 'Post Type General Name', 'text_domain'),
'singular_name' => _x('Bookmark SQL', 'Post Type Singular Name', 'text_domain'),
'menu_name' => __('Planche Bookmark', 'text_domain'),
'name_admin_bar' => __('Bookmark SQL', 'text_domain'),
'parent_item_colon' => __('Parent Item:', 'text_domain'),
'all_items' => __('All Bookmark SQLs', 'text_domain'),
'add_new_item' => __('Add New Bookmark SQL', 'text_domain'),
'add_new' => __('Add New', 'text_domain'),
'new_item' => __('New Bookmark SQL', 'text_domain'),
'edit_item' => __('Edit Bookmark SQL', 'text_domain'),
'update_item' => __('Update Bookmark SQL', 'text_domain'),
'view_item' => __('View Bookmark SQL', 'text_domain'),
'search_items' => __('Search Bookmark SQL', 'text_domain'),
'not_found' => __('Not found', 'text_domain'),
'not_found_in_trash' => __('Not found in Trash', 'text_domain'),
);
$args = array(
'label' => __('Bookmark SQL', 'text_domain'),
'description' => __('Planche Bookmark SQL', 'text_domain'),
'labels' => $labels,
'supports' => array(),
'taxonomies' => array(),
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 40,
'menu_icon' => 'dashicons-star-empty',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type('Bookmark SQL', $args);
}
/** Render the settings / options page in the admin dashboard */
function planche_cors_setting_page()
{
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
?>
<div class="wrap">
<h2>Planche CORS Domain Settings</h2>
<p>You may enter one or more comma-separated domains to allow access to this site using the CORS standard for
authorizing cross site requests.</p>
<p>To allow <em>any</em> site to access yours via CORS put a *, though explicitly listing domains is a better
practice for production sites.</p>
<form method="post" action="options.php">
<table class="form-table">
<tr valign="top">
<th scope="row">Allowed domains</th>
<td><textarea name="planche-cors" style="width:100%" rows="5" placeholder="http://other.wordpressdoamin.xxx"/><?php echo get_option('planche-cors');
?></textarea>
</tr>
</table>
<?php
settings_fields('planche-option-group');
do_settings_sections('planche-option-group');
submit_button();
?>
</form>
</div>
<?php
}
/** Render the settings / options page in the admin dashboard */
function planche_settings_page()
{
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
$user_id = get_current_user_id();
$option_id = 'planche-config-'.$user_id;
$config = json_decode(get_option( $option_id ));
$exclude = isset($config->noIndexing) ? $config->noIndexing : $config->withoutIndexing;
?>
<div class="wrap">
<h2>Planche Settings</h2>
<form method="post" action="options.php">
<h3>No indexing databases</h3>
<input type="hidden" name="noIndexings" />
<?php
foreach($exclude as $idx => $db){
?><div><img src="<?php echo plugin_dir_url(__FILE__)?>resources/images/icon_database.png"/><?php echo $db?></div><?php
}
?>
<h3>Automatically open the Connections window </h3>
<input type="radio" name="autoLoadConnectionWindow" value="true"<?php checked( $config->autoLoadConnectionWindow ); ?> /> Yes
<input type="radio" name="autoLoadConnectionWindow" value="false"<?php checked( !$config->autoLoadConnectionWindow ); ?> /> No
<?php
settings_fields('planche-option-group');
do_settings_sections('planche-option-group');
submit_button();
?>
</form>
</div>
<?php
}
?>