| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: MangBoard WP |
| 4 |
* Plugin URI: https://mangboard.com/ |
| 5 |
* Description: MangBoard WP는 Wordpress에서 게시판을 생성/관리 할 수 있는 기능을 제공합니다 |
| 6 |
* Version: 2.3.9 |
| 7 |
* Author: Hometory |
| 8 |
* Author URI: https://www.hometory.com/ |
| 9 |
*/ |
| 10 |
|
| 11 |
if(!function_exists( 'add_filter' )) return; |
| 12 |
define("_MB_", true); |
| 13 |
|
| 14 |
$site_url = site_url(); |
| 15 |
$home_url = home_url(); |
| 16 |
$content_url = content_url(); |
| 17 |
$plugins_url = plugins_url('', __FILE__)."/"; |
| 18 |
|
| 19 |
define("MBW_SITE_URL", $site_url); |
| 20 |
define("MBW_HOME_URL", $home_url); |
| 21 |
$auth_site_url = str_replace(array("http://","https://"), "", MBW_HOME_URL); |
| 22 |
if(strpos($auth_site_url, ':') !== false) $auth_site_url = substr($auth_site_url,0,strpos($auth_site_url, ':')); |
| 23 |
define("MBW_AUTH_SITE_URL", $auth_site_url); |
| 24 |
define("MBW_CONTENT_URL", $content_url); |
| 25 |
define("MBW_PLUGIN_URL", $plugins_url); |
| 26 |
|
| 27 |
define("MBW_PLUGIN_DIR", "mangboard"); |
| 28 |
define("MBW_UPLOAD_PATH", WP_CONTENT_DIR."/uploads/mangboard/"); |
| 29 |
define("MBW_LOG_PATH", WP_CONTENT_DIR."/uploads/mangboard/log/"); |
| 30 |
define("MBW_PLUGIN_PATH", plugin_dir_path(__FILE__)); |
| 31 |
define("MBW_PLUGIN_FILE", __FILE__); |
| 32 |
|
| 33 |
|
| 34 |
define("MBW_SECURE_AUTH_COOKIE", "mb_sec_".md5(MBW_AUTH_SITE_URL)); |
| 35 |
define("MBW_AUTH_COOKIE", "mb_".md5(MBW_AUTH_SITE_URL)); |
| 36 |
define("MBW_SHORTCODE_BOARD", "mb_board"); |
| 37 |
define("MBW_QUERY_LOG", false); //디비 쿼리 로그 설정: 관리자>MangBoard>Log 관리 |
| 38 |
define("MBW_PARAM_LOG", false); //파라미터 로그 설정: /wp-content/uploads/mangboard/log/log_xxxxxx.txt |
| 39 |
|
| 40 |
|
| 41 |
require_once(MBW_PLUGIN_PATH."includes/mb-settings.php"); |
| 42 |
if(empty($mstore)) return; |
| 43 |
|
| 44 |
|
| 45 |
if(!function_exists('mbw_init')){ |
| 46 |
function mbw_init(){ |
| 47 |
mbw_add_trace("mbw_init"); |
| 48 |
if(function_exists('load_plugin_textdomain')){ |
| 49 |
if( mbw_get_option("wp_multi_language") ) { |
| 50 |
load_plugin_textdomain('mangboard', false, MBW_PLUGIN_PATH . '/includes/languages/'); |
| 51 |
} |
| 52 |
} |
| 53 |
mbw_set_params(); |
| 54 |
if(mbw_get_access_token()==""){ |
| 55 |
mbw_generate_access_token(); |
| 56 |
if(mbw_is_login_cookie()) mbw_refresh_auth_cookie(); |
| 57 |
} |
| 58 |
if(get_current_user_id()!=0){ |
| 59 |
if(!mbw_is_login_cookie()){ |
| 60 |
$current_user = wp_get_current_user(); |
| 61 |
if($current_user->ID){ |
| 62 |
mbw_generate_auth_cookie($current_user->user_login,"WP"); |
| 63 |
} |
| 64 |
}else if(!mbw_validate_auth_cookie()){ |
| 65 |
mbw_clear_auth_cookie(); |
| 66 |
$current_user = wp_get_current_user(); |
| 67 |
if($current_user->ID){ |
| 68 |
mbw_generate_auth_cookie($current_user->user_login,"WP"); |
| 69 |
} |
| 70 |
} |
| 71 |
}else if(mbw_is_login_cookie()){ |
| 72 |
if(mbw_validate_auth_cookie()){ |
| 73 |
$cookie = mbw_get_login_cookie(); |
| 74 |
$cookie_elements = explode('|', $cookie); |
| 75 |
list($user_id, $expiration, $hmac, $user_mode, $auth_key) = $cookie_elements; |
| 76 |
mbw_set_wp_user_data($user_id, $user_mode); |
| 77 |
if($user_mode=="WP") mbw_logout("MB",false); |
| 78 |
}else{ |
| 79 |
mbw_clear_auth_cookie(); |
| 80 |
} |
| 81 |
} |
| 82 |
mbw_is_permission_level(); |
| 83 |
if(is_admin() && !empty($_GET["page"])){ |
| 84 |
$page_name = $_GET["page"]; |
| 85 |
if(strpos($page_name, 'mbw_')===0 && strpos($page_name, 'mbw_page')!==0 && $page_name!="mbw_dashboard" && $page_name!="mbw_commerce_dashboard" && $page_name!="mbw_commerce_category"){ |
| 86 |
global $mstore; |
| 87 |
$mstore->set_board_options(mbw_get_admin_board_name()); |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
add_action('init', 'mbw_init', 0); |
| 93 |
|
| 94 |
// 사용자 javascript 파일 호출 |
| 95 |
if(!function_exists('mbw_load_scripts')){ |
| 96 |
function mbw_load_scripts(){ |
| 97 |
global $mb_scripts,$mb_styles; |
| 98 |
$mb_scripts[] = mbw_init_javascript(); |
| 99 |
$mb_styles[] = mbw_init_style(); |
| 100 |
if(mbw_get_trace("mbw_print_scripts")!="" && !empty($mb_scripts)){ |
| 101 |
mbw_print_scripts(); |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
add_action('wp_enqueue_scripts', 'mbw_load_scripts',1); |
| 106 |
add_action('admin_enqueue_scripts', 'mbw_load_scripts',1); |
| 107 |
add_action('login_enqueue_scripts', 'mbw_load_scripts',1); |
| 108 |
add_action('wp_print_scripts', 'mbw_print_scripts',3); |
| 109 |
add_action('wp_footer', 'mbw_print_scripts',1); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
// 관리자 메뉴설정 |
| 114 |
if(!function_exists('mbw_create_board_menu')){ |
| 115 |
function mbw_create_board_menu(){ |
| 116 |
$index = 31; |
| 117 |
while(!empty($GLOBALS['menu'][$index])) $index++; |
| 118 |
add_menu_page('MangBoard', 'MangBoard', 'administrator', 'mbw_dashboard', 'mbw_manage_page', plugins_url(MBW_PLUGIN_DIR.'/assets/images/favicon.png'), $index); |
| 119 |
add_submenu_page('mbw_dashboard', __MW('W_MENU_DASHBOARD'), __MW('W_MENU_DASHBOARD'), 'administrator', 'mbw_dashboard', 'mbw_manage_page'); |
| 120 |
add_submenu_page('mbw_dashboard', __MW('W_MENU_BOARD'), __MW('W_MENU_BOARD'), 'administrator', 'mbw_board_options', 'mbw_manage_board'); |
| 121 |
add_submenu_page('mbw_dashboard', __MW('W_MENU_USER'), __MW('W_MENU_USER'), 'administrator', 'mbw_users', 'mbw_manage_board'); |
| 122 |
add_submenu_page('mbw_dashboard', __MW('W_MENU_OPTION'), __MW('W_MENU_OPTION'), 'administrator', 'mbw_options', 'mbw_manage_board'); |
| 123 |
add_submenu_page('mbw_dashboard', __MW('W_MENU_FILE'), __MW('W_MENU_FILE'), 'administrator', 'mbw_files', 'mbw_manage_board'); |
| 124 |
add_submenu_page('mbw_dashboard', __MW('W_MENU_ANALYTICS'), __MW('W_MENU_ANALYTICS'), 'administrator', 'mbw_analytics', 'mbw_manage_board'); |
| 125 |
add_submenu_page('mbw_dashboard', __MW('W_MENU_REFERER'), __MW('W_MENU_REFERER'), 'administrator', 'mbw_referers', 'mbw_manage_board'); |
| 126 |
add_submenu_page('mbw_dashboard', __MW('W_MENU_LOG'), __MW('W_MENU_LOG'), 'administrator', 'mbw_logs', 'mbw_manage_board'); |
| 127 |
} |
| 128 |
} |
| 129 |
add_action('admin_menu', 'mbw_create_board_menu',31); |
| 130 |
if(!function_exists('mbw_create_board')){ |
| 131 |
function mbw_create_board($args, $content=""){ |
| 132 |
if(!defined('DONOTCACHEPAGE')){ define('DONOTCACHEPAGE', true); } |
| 133 |
mbw_add_trace("mbw_create_board"); |
| 134 |
|
| 135 |
global $mdb,$mstore; |
| 136 |
if(!empty($content)) $args["content"] = $content; |
| 137 |
|
| 138 |
if(!isset($args['name'])){ |
| 139 |
mbw_error_message("MSG_SEARCH_ERROR2", "ShortCode","1000"); |
| 140 |
}else{ |
| 141 |
$args['name'] = mbw_value_filter(trim($args['name']),"name"); |
| 142 |
if(mbw_get_param("board_name")!="" && $args['name']!=mbw_get_param("board_name")){ |
| 143 |
return; |
| 144 |
} |
| 145 |
mbw_set_board_params($args); |
| 146 |
mbw_is_permission_level(); |
| 147 |
} |
| 148 |
|
| 149 |
if(empty($args['echo'])) ob_start(); |
| 150 |
do_action('mbw_create_board_header',$args); |
| 151 |
echo '<div class="clear"></div>'; |
| 152 |
/* |
| 153 |
$theme_name = wp_get_theme(); |
| 154 |
$theme_array = array("Twenty Twenty-Two","Twenty Twenty-Three"); |
| 155 |
if(in_array($theme_name, $theme_array)){ |
| 156 |
if(mbw_get_option("locale")=="ko_KR"){ |
| 157 |
$error_message = '호환성 문제가 있는 � |
| 158 |
�마에서는 게시판 사용이 불가합니다'; |
| 159 |
}else{ |
| 160 |
$error_message = 'This theme is not supported'; |
| 161 |
} |
| 162 |
mbw_error_message($error_message.'<div>['.implode(', ',$theme_array).']</div>',"","1104"); |
| 163 |
} |
| 164 |
*/ |
| 165 |
if(defined('ELEMENTOR_PATH')){ |
| 166 |
global $post; |
| 167 |
if(!empty($post) && !empty($post->ID)){ |
| 168 |
$elementor_edit_mode = get_post_meta( $post->ID, '_elementor_edit_mode' , true); |
| 169 |
if($elementor_edit_mode=="builder"){ |
| 170 |
$elementor_data = get_post_meta( $post->ID, '_elementor_data' , true); |
| 171 |
if(strpos($elementor_data, 'settings":{"editor":"<p>[mb_board') !== false){ |
| 172 |
mbw_error_message('엘리멘터에서 제공하는 "숏코드" 아이� |
| 173 |
�을 이용하여 게시판 숏코드를 � |
| 174 |
력해 주세요<div style="font-size:14px;padding:8px 0 0;">(게시판 추가방법: <a href="https://www.mangboard.com/tip/?vid=47" target="_blank">https://www.mangboard.com/tip/?vid=47</a>)</div>',"","1104"); |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
if(mbw_get_result_data("state")=="error"){ |
| 180 |
echo mbw_echo_error_message(); |
| 181 |
}else{ |
| 182 |
$MangBoard = new MangBoard($mdb,$mstore); |
| 183 |
$MangBoard->get_board_panel($args); |
| 184 |
} |
| 185 |
do_action('mbw_create_board_footer',$args); |
| 186 |
if(empty($args['echo'])) return ob_get_clean(); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
if(!function_exists('mbw_disable_plugin_updates')){ |
| 191 |
function mbw_disable_plugin_updates($value){ |
| 192 |
if(isset($value->response['mangboard/mangboard.php'])){ |
| 193 |
if(get_option("mb_install_product")!="0:0" || get_option("mb_skin_model")!="3:4"){ |
| 194 |
unset($value->response['mangboard/mangboard.php']); |
| 195 |
} |
| 196 |
} |
| 197 |
return $value; |
| 198 |
} |
| 199 |
} |
| 200 |
add_filter('site_transient_update_plugins', 'mbw_disable_plugin_updates'); |
| 201 |
|
| 202 |
if(!function_exists('mbw_check_shortcode')){ |
| 203 |
function mbw_check_shortcode($posts,$query){ |
| 204 |
if(is_admin() && !empty($_GET["page"]) && strpos($_GET["page"], 'mbw_')===0) return $posts; |
| 205 |
else if(empty($posts) || count($posts)!=1 || mbw_get_trace("mbw_head")!="" || !is_singular()) return $posts; |
| 206 |
mbw_add_trace("mbw_check_shortcode"); |
| 207 |
|
| 208 |
if(!empty($posts[0])){ |
| 209 |
$post = $posts[0]; |
| 210 |
if(!empty($_SERVER["REQUEST_URI"]) && $_SERVER["REQUEST_URI"]!="/"){ |
| 211 |
$permalink_structure = get_option('permalink_structure'); |
| 212 |
$request_uri = $_SERVER["REQUEST_URI"]; |
| 213 |
|
| 214 |
if(empty($permalink_structure) || strpos($permalink_structure, '%post_id%')!==false){ |
| 215 |
if(!empty($post->ID) && strpos($request_uri, strval($post->ID))===false){ |
| 216 |
return $posts; |
| 217 |
} |
| 218 |
}else if(strpos($permalink_structure, '%postname%')!==false){ |
| 219 |
if(!empty($post->post_name) && strpos(strtolower($request_uri), strtolower($post->post_name))===false){ |
| 220 |
return $posts; |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
global $mb_board_name; |
| 225 |
if(!empty($post->post_content) && strpos($post->post_content, '['.MBW_SHORTCODE_BOARD." name=") !== false){ |
| 226 |
$post_content = $post->post_content; |
| 227 |
$index1 = strpos($post_content,'['.MBW_SHORTCODE_BOARD." name=")+16; |
| 228 |
$index2 = strpos($post_content,"\"",$index1); |
| 229 |
$board_name = trim(substr($post_content,$index1,$index2-$index1)); |
| 230 |
if(!empty($board_name) && empty($mb_board_name)){ |
| 231 |
$mb_board_name = mbw_value_filter($board_name,"name"); |
| 232 |
mbw_init_board($mb_board_name); |
| 233 |
} |
| 234 |
} |
| 235 |
do_action('mbw_shortcode', $post->post_content); |
| 236 |
if(mbw_get_trace("mbw_is_permission_level")=="") mbw_is_permission_level(); |
| 237 |
} |
| 238 |
return $posts; |
| 239 |
} |
| 240 |
} |
| 241 |
add_shortcode(MBW_SHORTCODE_BOARD, 'mbw_create_board'); |
| 242 |
add_filter('the_posts', 'mbw_check_shortcode',10,2); |
| 243 |
?> |