-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtonjoo-lotus-bootstraper.php
204 lines (118 loc) · 4.85 KB
/
tonjoo-lotus-bootstraper.php
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
<?php
/*
* Plugin Name: Tonjoo Lotus Framework Bootstraper
* Plugin URI: http://tonjoo.com/
* Description: Lotus Framework Bootsraper
* Version: 1
* Author: @todiadiyatmo
* Author URI: http://todiadiyatmo.com
* License: GPLv2
* Copyright 2013 Tonjoo.com (email : [email protected])
*/
require_once(plugin_dir_path(__FILE__) . 'tonjoo-library.php');
require_once(plugin_dir_path(__FILE__) . 'default-options.php');
require_once(plugin_dir_path(__FILE__) . 'tonjoo-lotus-framework-options.php');
require_once(plugin_dir_path(__FILE__) . 'WordPressHook.php');
add_action( 'wp_loaded','flush_lotus_framework_rules' );
function flush_lotus_framework_rules(){
//skip action if on wp admin
if(is_admin())
return;
$rules = get_option( 'rewrite_rules' );
$options = get_option('lf_settings');
if(!$options)
return;
$options = tonjoo_lf_load_default($options);
global $wpdb;
$post = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}posts where post_name='{$options['frontpage_hook']}' ");
if(!$post){
return;
}
$hook_id = $post->ID;
$slug = $post->post_name ;
if($options['frontpage_hook']!='false'){
// only rewrite rules if it not included
if(isset($rules[''.$slug.'/([^/]*)/?$']))
return;
//rewrite
add_rewrite_tag('%lotus_controller%','([^&]+)');
add_rewrite_tag('%lotus_function%','([^&]+)');
add_rewrite_tag('%lotus_params%','([^&]+)');
add_rewrite_tag('%lotus_params2%','([^&]+)');
add_rewrite_rule(''.$slug.'/([^/]+)/?$','index.php?page_id='.$hook_id.'&lotus_controller=$matches[1]','top');
add_rewrite_rule(''.$slug.'/([^/]+)/?([^/]*)/?$','index.php?page_id='.$hook_id.'&lotus_controller=$matches[1]&lotus_function=$matches[2]','top');
add_rewrite_rule(''.$slug.'/([^/]+)/?([^/]*)/?([^/]*)/?$','index.php?page_id='.$hook_id.'&lotus_controller=$matches[1]&lotus_function=$matches[2]&lotus_params=$matches[3]','top');
add_rewrite_rule(''.$slug.'/([^/]+)/?([^/]*)/?([^/]*)/?([^/]*)/?$','index.php?page_id='.$hook_id.'&lotus_controller=$matches[1]&lotus_function=$matches[2]&lotus_params=$matches[3]&lotus_params2=$matches[4]','top');
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
add_action('init','lotus_boostraper_wp_init');
function tonjoo_lotus_bootstraper_do_backend(){
$controller = isset($_GET['controller']) ? $_GET['controller'] : '';
$method = isset($_GET['method']) ? $_GET['method'] : '';
?>
<!-- Sub menu active script -->
<script type="text/javascript">
var l_current_controller = "<?php echo $controller ?>" ;
var l_current_method = "<?php echo $method ?>" ;
</script>
<?php
//flush the buffer :)
global $LotusBootstraperBackend;
$LotusBootstraperBackend->flushContent();
}
function lotus_boostraper_wp_init(){
//make lotus loader available on all plugin
require_once plugin_dir_path( __FILE__ ) .'lotus/loader.php';
$options = get_option('lf_settings');
$options = tonjoo_lf_load_default($options);
if(!$options)
return;
if(!is_admin()){
global $wpdb;
$post = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}posts where post_name='{$options['frontpage_hook']}' ");
if(!$post)
return;
define('LF_POST_HOOK_ID',$post->ID);
//if current page = hook id , capture the header
if(LF_POST_HOOK_ID==url_to_postid($_SERVER['REQUEST_URI'])){
//first buffer :) , buffer the header
ob_start();
$LotusBootstraper = new LotusBootstraper();
add_action('wp_head',array( $LotusBootstraper,'start'),1);
remove_all_filters('the_content');
//add content hook
add_filter( 'the_content', array( $LotusBootstraper,'getContent'),1 );
}
}
else{
//Backend slug hook
$slug = sanitize_title_with_dashes(trim($options['page_title']));
$page = isset($_GET['page']) ? $_GET['page'] : '';
if(is_admin()&&$slug !=''&&$page==$slug ){
//first buffer :) , buffer the header
ob_start();
global $LotusBootstraperBackend;
$LotusBootstraperBackend = new LotusBootstraper();
$LotusBootstraperBackend->start();
}
}
}
class LotusBootstraper{
var $lf_content;
function start(){
//start lotus framework buffering
ob_start();
require_once plugin_dir_path( __FILE__ ) .'lotus/index.php';
$this->lf_content = ob_get_contents();
ob_end_clean();
}
function getContent($content){
$content = $content.$this->lf_content;
return $content;
}
function flushContent(){
echo $this->lf_content;
}
}