Plugin Directory

Changeset 2377087


Ignore:
Timestamp:
09/08/2020 10:09:08 AM (6 years ago)
Author:
bangnam
Message:

update file bangnam-wp.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bangnam-wp/trunk/bangnam-wp.php

    r2314067 r2377087  
    1111Version: 1.0
    1212*/
    13 defined("ABSPATH") or die("");
     13defined("ABSPATH") or die("BANGNAM_WP_VER");
    1414define("BANGNAM_WP_VER", '1.0.0');
    1515define("BANGNAM_WP_SLUG", 'bangnam-wp');
    16 define("BANGNAM_WP_DIR", __DIR__ );
     16define("BANGNAM_WP_DIR", __DIR__ . '/' );
    1717define("BANGNAM_WP_URL", plugin_dir_url( __FILE__ ) );
    1818require_once "vendor/autoload.php";
    19 $bangnam_options = [];
     19$bangnam_options = [];
     20
    2021global $wpdb;
    2122
     
    3031        }
    3132    }
     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
    3293}
    3394if( !function_exists('bangnam_plugins_init') )
     
    50111}
    51112
    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 )
     113foreach( glob( __DIR__ .'/libs/*/*.php') as $start_file )
    119114{
    120115    require_once $start_file;
     
    132127                    unlink($file);
    133128            }
    134             if( file_exists($dir) && is_dir($dir) )
    135             {
    136                 rmdir($dir);
    137             }
     129            rmdir($dir);
    138130        }
    139131        catch(Exception $e)
     
    175167        }
    176168       
    177         else if( $_action == 'remove' && !empty($_name) )
     169        else if( $_action == 'remove' && $_name && $_wp )
    178170        {
    179171            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' ];
    183175                die( json_encode($rs) );
    184176            }
    185             bangnam_deleteAll( BANGNAM_WP_DIR . '/libs/'.$_name );
     177            bangnam_deleteAll( __DIR__ . '/libs/'.$_name );
    186178            $rs = ['success' => true, 'msg' => 'Gỡ bỏ thư viện thành công!'];
    187179            die( json_encode($rs) );
    188180        }
    189181       
    190         else if( $_action == 'download' && !empty($_name) && !empty($_wp) )
     182        else if( $_action == 'download' && $_name && $_wp )
    191183        {
    192184           
    193             if( is_writable( BANGNAM_WP_DIR . $temp_dir) )
     185            if( is_writable( __DIR__ . get_temp_dir()) )
    194186            {
    195187                $response = wp_remote_get('https://bangnam.com/wp/download/?name='. $_name .'&license='.get_option('bangnam_license').'&wp='.$_wp);
     
    199191                if( $getinfo == "application/zip" )
    200192                {
    201                     file_put_contents( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip', $resp );
     193                    file_put_contents( __DIR__ . get_temp_dir().$_name.'.zip', $resp );
    202194                    $rs = ['success' => true, 'msg' => 'Tải thư viện thành công!'];
    203195                }
     
    209201            else
    210202            {
    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 !'];
    212204            }
    213205        }
     
    216208        {
    217209            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') )
    219211            {
    220212                if( !is_writable( BANGNAM_WP_DIR . '/libs/') )
     
    225217                if( is_dir(BANGNAM_WP_DIR . '/libs/'.$_name ) )
    226218                {
    227                     unlink( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip' );
     219                    unlink( BANGNAM_WP_DIR . get_temp_dir().$_name.'.zip' );
    228220                    $rs = ['success' => false, 'msg' => 'Đã tồn tại thư viện này trên hệ thống!'];
    229221                }
     
    243235                }
    244236                $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/' );
    247239                    $zip->close();
    248240                    $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') )
    250242                    {
    251                         unlink( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip');
     243                        unlink( __DIR__ . get_temp_dir().$_name.'.zip');
    252244                    }
    253245                }
    254246                else
    255247                {
    256                     if( file_exists(BANGNAM_WP_DIR . $temp_dir.$_name.'.zip') )
     248                    if( file_exists(__DIR__ . get_temp_dir().$_name.'.zip') )
    257249                    {
    258                         unlink( BANGNAM_WP_DIR . $temp_dir.$_name.'.zip');
     250                        unlink( __DIR__ . get_temp_dir().$_name.'.zip');
    259251                    }
    260252                    $rs = ['success' => false, 'msg' => 'Giải nén thất bại!'];
     
    279271    {
    280272        $rs = [];
    281         foreach( glob( BANGNAM_WP_DIR . '/libs/*') as $item)
     273        foreach( glob( __DIR__ . '/libs/*') as $item)
    282274        {
    283275            if(file_exists($item.'/manifest.json'))
Note: See TracChangeset for help on using the changeset viewer.