Viewing File: /usr/local/cpanel/whostmgr/docroot/cgi/softaculous/conf/mods/wp/extendify/post_install.php

<?php

    $_work_dir = $globals['path'] . '/conf/mods/' . $software['softname'] . '/' . $plugin;
    $_package_settings = json_decode( file_get_contents( $_work_dir . '/settings.json' ) , true);
    $_max_attempts = 5;

    function _nc_download_data( $_url , $_tm = 0 ) {
      $ch = curl_init();
      curl_setopt( $ch, CURLOPT_URL , $_url );
      curl_setopt( $ch, CURLOPT_VERBOSE , 0 );
      curl_setopt( $ch, CURLOPT_RETURNTRANSFER , 1 );
      curl_setopt( $ch, CURLOPT_AUTOREFERER , false );
      curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
      curl_setopt( $ch, CURLOPT_HEADER , 0 );
      curl_setopt( $ch, CURLOPT_TIMEOUT , $_tm );
      $_result = curl_exec( $ch );
      $_response = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
      curl_close( $ch );
      return( [$_response, $_result] );
    }

    function _nc_cleanup( $_files ) {
      foreach ( $_files as $_file ) {
        unlink( $_file );
      }
    }

    function _nc_get_wp_package_info( $_url ) {
      list( $_response, $_data ) = _nc_download_data( $_url, 5 );
      if ( $_response == 200 ) {
        return json_decode( $_data );
      } else {
        return false;
      }
    }

    function _nc_download_file( $_url, $_dst ) {
      global $error;
      list( $_response , $_data ) = _nc_download_data( $_url , 20 );
      if ( $_response == 200 ) {
         if ( !$_fp = fopen( $_dst, 'wb' ) ) {
            $error[] = 'Cannot open file ' . $_dst;
            return false;
         }
         if ( fwrite( $_fp , $_data ) === false ) {
            $error[] = 'Cannot write to file ' . $_dst;
            return false;
         }
         fclose( $_fp );
         return true;
      } else {
        return false;
      }
    }

    function _nc_activate( $_item, $_type ) {
      global $__settings;
      switch( $_type ) {
      case 'plugin':
        $__settings['active_plugins'][] = $_item . '/' . $_item . '.php';
        break;
      case 'theme':
        $_themes_options = ['template' , 'stylesheet'];
        foreach ( $_themes_options as $_themes_option ) {
          $query = "UPDATE " . $__settings['dbprefix'] . "options SET option_value = '" . $_item . "' WHERE option_name = '" . $_themes_option . "';";
          $result = sdb_query( $query , $__settings['softdbhost'] , $__settings['softdbuser'] , $__settings['softdbpass'] , $__settings['softdb'] );
        }
        break;
      }
    }

    foreach ( $_package_settings as $_addon_key => $_addon_settings ) {
      if ( in_array( $_addon_settings['type'], ['plugin', 'theme'] ) ) {
         $_nc_file_install = $_work_dir.'/'.$_addon_key.'.zip';
         if ( isset( $_addon_settings['version'] ) && !empty( $_addon_settings['version'] ) ) {
            $_package_info = _nc_get_wp_package_info( 'https://api.wordpress.org/' . $_addon_settings['type'] . 's/info/1.2/?action=' . $_addon_settings['type'] . '_information&request[slug]=' . $_addon_key );
            if ( preg_match( '/[0-9\.]+/', $_package_info->version ) ) {
               if ( version_compare( $_package_info->version , $_addon_settings['version'] ) ) {
                  $_nc_file = basename( $_package_info->download_link );
                  if ( file_exists( $_work_dir . '/' . $_nc_file) && filesize( $_work_dir . '/' . $_nc_file ) ) {
                     $_nc_file_install = $_work_dir . '/' . $_nc_file;
                  } elseif ( file_exists( $_SERVER['TMPDIR']. '/' . $_nc_file ) && filesize( $_work_dir . '/' . $_nc_file ) ) {
                     $_nc_file_install = $_SERVER['TMPDIR'] . '/' . $_nc_file;
                  } else {
                     $_download_attempt = 0;
                     while ( !filesize( $_SERVER['TMPDIR'] . '/' . $_nc_file ) && $_download_attempt <= $_max_attempts ) {
                       _nc_download_file( $_package_info->download_link , $_SERVER['TMPDIR'] . '/' . $_nc_file );
                       $_download_attempt++;
                     }
                     if ( filesize( $_SERVER['TMPDIR'] . '/' . $_nc_file ) ) {
                        $_nc_file_install = $_SERVER['TMPDIR'] . '/' . $_nc_file;
                        $_nc_downloaded_files[] = $_nc_file_install;
                     }
                  }
               }
            }
         }
         if ( sunzip( $_nc_file_install , $__settings['softpath'] . '/wp-content/' . $_addon_settings['type'] . 's/' ) ) {
            _nc_activate( $_addon_key , $_addon_settings['type'] );
         } else {
            $error[] = 'Could not unzip the files of the ' . $_addon_settings['type'] . ' ' . $_addon_key;
         }
         unset( $_nc_file_install );
      }
    }
    _nc_cleanup( $_nc_downloaded_files );
?>
Back to Directory File Manager