Skip to content

Commit

Permalink
Load CSV files individually #16
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Feb 21, 2022
1 parent 8fb301c commit 9e32826
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
6 changes: 4 additions & 2 deletions includes/oik-loader-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ function oik_loader_load_map() {
$csvs = oik_loader_map_block_example_CPT( $csvs );
//echo count( $csvs );
//echo PHP_EOL;
oik_require( "includes/oik-loader-extras.php", "oik-loader" );
$csvs = oik_loader_append_extras( $csvs );

// No need to do this now.
//oik_require( "includes/oik-loader-extras.php", "oik-loader" );
//$csvs = oik_loader_append_extras( $csvs );
return $csvs;
}

Expand Down
53 changes: 47 additions & 6 deletions includes/oik-loader-mu.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,26 @@
}

function oik_loader_mu_loaded() {
$index = oik_loader_mu_build_index();
$plugins = null;
$files = ['oik-loader', 'oik-loader-extras' ];
foreach ($files as $file) {
$plugins = oik_loader_try_file( $file );
if ($plugins) {
break;
}
}
}

/**
* Attempts to determine the plugins to load from the given file.
*
* @param $file
* @return array|null
*/
function oik_loader_try_file( $file ) {
$plugins = null;
$index = oik_loader_mu_build_index( $file );
//$index_extra = oik_loader
//print_r( $index );

if ( $index ) {
Expand All @@ -58,15 +77,21 @@ function oik_loader_mu_loaded() {
}

}
return $plugins;
}

/**
* Builds the lookup index from oik-loader.blog_id.csv
* Builds the lookup index from the oik-loader files
*
* oik-loader.blog_id.csv - automatically defined entries
* oik-loader-extras.blog_id.csv - manually defined entries
*
* @return array|null
*/
function oik_loader_mu_build_index() {
$oik_loader_csv = oik_loader_csv_file();
function oik_loader_mu_build_index( $file='oik-loader') {


$oik_loader_csv = oik_loader_csv_file( $file );
$index = null;
if ( file_exists( $oik_loader_csv) ) {
//echo "File exists";
Expand Down Expand Up @@ -121,12 +146,25 @@ function oik_loader_build_index( $lines ) {
$ID = array_shift( $csv );
$index[ $url] = $csv;
$index[ $ID] = $csv;
oik_loader_map_id( $url, $ID );
}
}
//print_r( $index );
return $index;
}

function oik_loader_map_id( $url, $id=null ) {
static $url_id_map = [];
if ( null !== $id ) {
$url_id_map[ $url ] = $id;
$url_id_map[ $id ] = $url;
}
if ( isset( $url_id_map[ $url ] ) ) {
return $url_id_map[ $url ];
}
return null;
}

/**
* Returns the plugin names for the current post
*
Expand All @@ -153,7 +191,9 @@ function oik_loader_mu_query_plugins( $index, $page ) {
/**
* Implements 'option_active_plugins' filter
*
* Adds the missing plugin(s) to the list of plugins to load
* Adds the missing plugin(s) to the list of plugins to load.
* Note: The plugins are added to the front of the active_plugins array.
*
* This filter may be called multiple times, but we should only need to add our plugins once.
* @TODO Improve performance
*
Expand All @@ -164,7 +204,7 @@ function oik_loader_mu_query_plugins( $index, $page ) {
*/
function oik_loader_option_active_plugins( $active_plugins, $option ) {
//print_r( $active_plugins );
//bw_backtrace();
bw_backtrace();
$load_plugins = oik_loader_load_plugins();
// build plugin dependency list
if ( $load_plugins ) {
Expand All @@ -176,6 +216,7 @@ function oik_loader_option_active_plugins( $active_plugins, $option ) {
//echo "adding $load_plugin";
array_unshift( $active_plugins, $load_plugin );
//$active_plugins[] = $load_plugin;
bw_trace2( $active_plugins, "added $load_plugin", false);
}
}
}
Expand Down

0 comments on commit 9e32826

Please sign in to comment.