Skip to content

Commit

Permalink
Issue #1 - Add plugins box
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Mar 8, 2019
1 parent d7348e5 commit 14624dd
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 6 deletions.
22 changes: 19 additions & 3 deletions includes/oik-loader-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function oik_loader_do_page() {

BW_::oik_menu_header( __( "oik loader", "oik" ), "w95pc" );
BW_::oik_box( null, null, __( 'oik-loader-mu', 'oik' ), "oik_loader_oik_menu_box" );
BW_::oik_box( null, null, __( 'plugins', 'oik-loader'), "oik_loader_plugins_box" );
oik_menu_footer();
bw_flush();
}
Expand Down Expand Up @@ -61,8 +62,10 @@ function oik_loader_oik_menu_box() {
alink( null, admin_url( "admin.php?page=oik_loader&mu=deactivate" ), __( "Click to deactivate MU", "oik-loader" ) );
} else {
p( "Click on the link to install oik-loader-mu logic" );
alink( null, admin_url( "admin.php?page=oik_loader&mu=activate" ), __( "Click to activate MU", "oik-loader" ) );
}
br();
alink( null, admin_url( "admin.php?page=oik_loader&mu=activate" ), __( "Click to activate/update MU", "oik-loader" ) );


$oik_loader_mu_active = oik_loader_query_loader_active();
if ( $oik_loader_mu_active ) {
Expand Down Expand Up @@ -140,10 +143,11 @@ function oik_loader_activate_mu( $activate=true ) {
$target = oik_loader_target_file();
if ( $target ) {
if ( $activate ) {
if ( ! file_exists( $target ) ) {
$source = oik_path( 'includes/oik-loader-mu.php', "oik-loader" );
$source = oik_path( 'includes/oik-loader-mu.php', "oik-loader" );
if ( ! file_exists( $target ) || filemtime( $source) > filemtime( $target )) {
copy( $source, $target );
}

} else {
if ( file_exists( $target ) ) {
unlink( $target );
Expand Down Expand Up @@ -181,3 +185,15 @@ function oik_loader_display_index( $index ) {
function oik_loader_rebuild_index() {
oik_loader_run_oik_loader();
}

function oik_loader_plugins_box() {
oik_require( "includes/oik-loader-plugins.php", "oik-loader");
$csvs = [];
$csvs = oik_loader_map_oik_plugins_CPT( $csvs );

oik_loader_display_oik_plugins( $csvs );


}


9 changes: 6 additions & 3 deletions includes/oik-loader-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ function oik_loader_map() {
}

function oik_loader_get_scheme_host() {

$siteurl = site_url( null, "https");
e( "Site URL: " . $siteurl );
br();
$host = parse_url( $siteurl, PHP_URL_HOST );
$scheme_host = "https://" . $host;
return $scheme_host;
}

function oik_loader_report_siteurl() {
$siteurl = site_url( null, "https");
e( "Site URL: " . $siteurl );
br();
}

function oik_loader_get_hostless_permalink( $post_id, $scheme_host ) {
$permalink = get_permalink( $post_id );
$permalink = str_replace( $scheme_host, "", $permalink );
Expand Down
83 changes: 83 additions & 0 deletions includes/oik-loader-plugins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php


function oik_loader_map_oik_plugins_CPT( $csvs ) {
oik_require( "includes/bw_posts.php" );
$atts = array(
"post_type" => "oik-plugins",
"post_parent" => 0,
"number_posts" => - 1
);
$posts = bw_get_posts( $atts );
$scheme_host = oik_loader_get_scheme_host();
//$csvs = [];
foreach ( $posts as $post ) {
$line = [];
$line[] = oik_loader_get_hostless_permalink( $post->ID, $scheme_host );
$line[] = $post->ID;
$line[] = get_post_meta( $post->ID, '_oikp_name', true );
$csv_line = implode( ",", $line );
$csvs[] = $csv_line . PHP_EOL;
}

return $csvs;
}

function oik_loader_display_oik_plugins( $csvs ) {
//print_r( $csvs );
oik_loader_display_oik_plugins_header();
foreach ( $csvs as $csv ) {
$csv = trim( $csv );
$row = bw_as_array( $csv );
$row[1] = retlink( null, get_edit_post_link( $row[1] ), $row[1] );
$row[] = oik_loader_plugin_status( $row[2]);
bw_tablerow( $row );
}
etag( "tbody" );
etag( "table" );
}

function oik_loader_plugin_status( $plugin_name ) {
//$included_files = get_included_files();
//$status = '?';
//echo "$plugin_name:$status:";
//$plugins = get_option( 'active_plugins', array() );


//) || is_plugin_active_for_network( $plugin );
if ( is_plugin_active_for_network( $plugin_name )) {
$status = "Network active";
} elseif ( is_plugin_active( $plugin_name ) ) {
$status = "Active";

} else {
$status = "&nbsp;";
//print_r( $plugins );
//$in = in_array( $plugin_name, $plugins );
//print_r( $in );

}

return $status;
}



function oik_loader_display_oik_plugins_header() {
if ( "cli" == php_sapi_name() ) {
gob();

echo "Editor | Mandatory? | Level | Opinion | Notes " . PHP_EOL;
echo "------ | ---------- | ----- | ------- | ----- " . PHP_EOL;
} else {
//oik_require( "shortcodes/oik-table.php" );
//oik_require_lib( "bobbforms");
//bw_table_header(
$title_arr = bw_as_array( "URL,ID,Plugin&nbsp;name,Status" );
stag( "table", "bw_table" );
stag( "thead" );
bw_tablerow( $title_arr, "tr", "th" );
etag( "thead" );
stag( "tbody" );
}
}

0 comments on commit 14624dd

Please sign in to comment.