Changeset 2377087
- Timestamp:
- 09/08/2020 10:09:08 AM (6 years ago)
- File:
-
- 1 edited
-
bangnam-wp/trunk/bangnam-wp.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bangnam-wp/trunk/bangnam-wp.php
r2314067 r2377087 11 11 Version: 1.0 12 12 */ 13 defined("ABSPATH") or die(" ");13 defined("ABSPATH") or die("BANGNAM_WP_VER"); 14 14 define("BANGNAM_WP_VER", '1.0.0'); 15 15 define("BANGNAM_WP_SLUG", 'bangnam-wp'); 16 define("BANGNAM_WP_DIR", __DIR__ );16 define("BANGNAM_WP_DIR", __DIR__ . '/' ); 17 17 define("BANGNAM_WP_URL", plugin_dir_url( __FILE__ ) ); 18 18 require_once "vendor/autoload.php"; 19 $bangnam_options = []; 19 $bangnam_options = []; 20 20 21 global $wpdb; 21 22 … … 30 31 } 31 32 } 33 34 /* check write permission */ 35 if(!is_dir(__DIR__ . get_temp_dir())) 36 { 37 if( is_writable( __DIR__ ) ) 38 { 39 mkdir( __DIR__ . get_temp_dir() ); 40 } 41 else 42 { 43 add_action( 'admin_notices', function(){ 44 ?> 45 <div class="error notice"> 46 <p><?php _e( "Không có quyền ghi thư mục " .realpath( __DIR__ ). " ! Bạn cần chmod thư mục này với quyền 0777." ); ?></p> 47 </div> 48 <?php 49 }); 50 } 51 exit(); 52 } 53 if(!is_dir(__DIR__ . '/libs/')) 54 { 55 if( is_writable( __DIR__ ) ) 56 { 57 mkdir( __DIR__ . '/libs/' ); 58 } 59 else 60 { 61 add_action( 'admin_notices', function(){ 62 ?> 63 <div class="error notice"> 64 <p><?php _e( "Không có quyền ghi thư mục " .realpath( __DIR__ ). " ! Bạn cần chmod thư mục này với quyền 0777." ); ?></p> 65 </div> 66 <?php 67 }); 68 } 69 exit(); 70 } 71 if( !is_writable( __DIR__ . get_temp_dir()) ) 72 { 73 add_action( 'admin_notices', function(){ 74 ?> 75 <div class="error notice"> 76 <p><?php _e( "Không có quyền ghi thư mục " .BANGNAM_WP_DIR. "/tmp ! Bạn cần chmod thư mục này với quyền 0777." ); ?></p> 77 </div> 78 <?php 79 }); 80 exit(); 81 } 82 if( !is_writable( __DIR__ . '/libs/' ) ) 83 { 84 add_action( 'admin_notices', function(){ 85 ?> 86 <div class="error notice"> 87 <p><?php _e( "Không có quyền ghi thư mục " .BANGNAM_WP_DIR. "/libs ! Bạn cần chmod thư mục này với quyền 0777." ); ?></p> 88 </div> 89 <?php 90 }); 91 } 92 32 93 } 33 94 if( !function_exists('bangnam_plugins_init') ) … … 50 111 } 51 112 52 $temp_dir = get_temp_dir(); 53 if( get_temp_dir() != '/tmp/' ) 54 { 55 $temp_dir = '/tmp/'; 56 } 57 58 /* check write permission */ 59 if(!is_dir(BANGNAM_WP_DIR . $temp_dir)) 60 { 61 if( is_writable( BANGNAM_WP_DIR ) ) 62 { 63 mkdir( BANGNAM_WP_DIR . $temp_dir ); 64 } 65 else 66 { 67 add_action( 'admin_notices', function(){ 68 ?> 69 <div class="error notice"> 70 <p><?php _e( "Không có quyền ghi thư mục " .realpath( BANGNAM_WP_DIR ). " ! Bạn cần chmod thư mục này với quyền 0777." ); ?></p> 71 </div> 72 <?php 73 }); 74 } 75 exit(); 76 } 77 if(!is_dir(BANGNAM_WP_DIR . '/libs/')) 78 { 79 if( is_writable( BANGNAM_WP_DIR ) ) 80 { 81 mkdir( BANGNAM_WP_DIR . '/libs/' ); 82 } 83 else 84 { 85 add_action( 'admin_notices', function(){ 86 ?> 87 <div class="error notice"> 88 <p><?php _e( "Không có quyền ghi thư mục " .realpath( BANGNAM_WP_DIR ). " ! Bạn cần chmod thư mục này với quyền 0777." ); ?></p> 89 </div> 90 <?php 91 }); 92 } 93 exit(); 94 } 95 if( !is_writable( BANGNAM_WP_DIR . $temp_dir) ) 96 { 97 add_action( 'admin_notices', function(){ 98 ?> 99 <div class="error notice"> 100 <p><?php _e( "Không có quyền ghi thư mục " .BANGNAM_WP_DIR. "/tmp ! Bạn cần chmod thư mục này với quyền 0777." ); ?></p> 101 </div> 102 <?php 103 }); 104 exit(); 105 } 106 if( !is_writable( BANGNAM_WP_DIR . '/libs/' ) ) 107 { 108 add_action( 'admin_notices', function(){ 109 ?> 110 <div class="error notice"> 111 <p><?php _e( "Không có quyền ghi thư mục " .BANGNAM_WP_DIR. "/libs ! Bạn cần chmod thư mục này với quyền 0777." ); ?></p> 112 </div> 113 <?php 114 }); 115 exit(); 116 } 117 118 foreach( glob( BANGNAM_WP_DIR .'/libs/*/*.php') as $start_file ) 113 foreach( glob( __DIR__ .'/libs/*/*.php') as $start_file ) 119 114 { 120 115 require_once $start_file; … … 132 127 unlink($file); 133 128 } 134 if( file_exists($dir) && is_dir($dir) ) 135 { 136 rmdir($dir); 137 } 129 rmdir($dir); 138 130 } 139 131 catch(Exception $e) … … 175 167 } 176 168 177 else if( $_action == 'remove' && !empty($_name))169 else if( $_action == 'remove' && $_name && $_wp ) 178 170 { 179 171 header('Content-type: text/json'); 180 if( !is_writable( BANGNAM_WP_DIR. '/libs' ) )181 { 182 $rs = ['success' => false, 'msg' => 'Bạn không có quyền xóa trong thư mục ' . BANGNAM_WP_DIR. '/libs' ];172 if( !is_writable( __DIR__ . '/libs' ) ) 173 { 174 $rs = ['success' => false, 'msg' => 'Bạn không có quyền xóa trong thư mục ' . __DIR__ . '/libs' ]; 183 175 die( json_encode($rs) ); 184 176 } 185 bangnam_deleteAll( BANGNAM_WP_DIR. '/libs/'.$_name );177 bangnam_deleteAll( __DIR__ . '/libs/'.$_name ); 186 178 $rs = ['success' => true, 'msg' => 'Gỡ bỏ thư viện thành công!']; 187 179 die( json_encode($rs) ); 188 180 } 189 181 190 else if( $_action == 'download' && !empty($_name) && !empty($_wp))182 else if( $_action == 'download' && $_name && $_wp ) 191 183 { 192 184 193 if( is_writable( BANGNAM_WP_DIR . $temp_dir) )185 if( is_writable( __DIR__ . get_temp_dir()) ) 194 186 { 195 187 $response = wp_remote_get('https://bangnam.com/wp/download/?name='. $_name .'&license='.get_option('bangnam_license').'&wp='.$_wp); … … 199 191 if( $getinfo == "application/zip" ) 200 192 { 201 file_put_contents( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip', $resp );193 file_put_contents( __DIR__ . get_temp_dir().$_name.'.zip', $resp ); 202 194 $rs = ['success' => true, 'msg' => 'Tải thư viện thành công!']; 203 195 } … … 209 201 else 210 202 { 211 $rs = ['success' => false, 'msg' => 'Bạn chưa chmod thư mục '. BANGNAM_WP_DIR. '/tmp/. Vui lòng chmod về 0777 và thử lại !'];203 $rs = ['success' => false, 'msg' => 'Bạn chưa chmod thư mục '.__DIR__ . '/tmp/. Vui lòng chmod về 0777 và thử lại !']; 212 204 } 213 205 } … … 216 208 { 217 209 header('Content-type: text/json'); 218 if( file_exists(BANGNAM_WP_DIR . $temp_dir.$_name.'.zip') )210 if( file_exists(BANGNAM_WP_DIR . get_temp_dir().$_name.'.zip') ) 219 211 { 220 212 if( !is_writable( BANGNAM_WP_DIR . '/libs/') ) … … 225 217 if( is_dir(BANGNAM_WP_DIR . '/libs/'.$_name ) ) 226 218 { 227 unlink( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip' );219 unlink( BANGNAM_WP_DIR . get_temp_dir().$_name.'.zip' ); 228 220 $rs = ['success' => false, 'msg' => 'Đã tồn tại thư viện này trên hệ thống!']; 229 221 } … … 243 235 } 244 236 $zip = new ZipArchive; 245 if ($zip->open( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip' ) === TRUE) {246 $zip->extractTo( BANGNAM_WP_DIR. '/libs/' );237 if ($zip->open( __DIR__ . get_temp_dir().$_name.'.zip' ) === TRUE) { 238 $zip->extractTo( __DIR__ . '/libs/' ); 247 239 $zip->close(); 248 240 $rs = ['success' => true, 'msg' => 'Giải nén thành công!']; 249 if( file_exists( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip') )241 if( file_exists(__DIR__ . get_temp_dir().$_name.'.zip') ) 250 242 { 251 unlink( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip');243 unlink( __DIR__ . get_temp_dir().$_name.'.zip'); 252 244 } 253 245 } 254 246 else 255 247 { 256 if( file_exists( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip') )248 if( file_exists(__DIR__ . get_temp_dir().$_name.'.zip') ) 257 249 { 258 unlink( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip');250 unlink( __DIR__ . get_temp_dir().$_name.'.zip'); 259 251 } 260 252 $rs = ['success' => false, 'msg' => 'Giải nén thất bại!']; … … 279 271 { 280 272 $rs = []; 281 foreach( glob( BANGNAM_WP_DIR. '/libs/*') as $item)273 foreach( glob( __DIR__ . '/libs/*') as $item) 282 274 { 283 275 if(file_exists($item.'/manifest.json'))
Note: See TracChangeset
for help on using the changeset viewer.