Skip to content

Commit

Permalink
Add virtual fields for templates, parts and patterns counts #11
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Jan 23, 2022
1 parent 1e7ef92 commit c3d080f
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 15 deletions.
54 changes: 40 additions & 14 deletions includes/class-oik-themes-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,29 +588,55 @@ function get_template_part_dir( $slug ) {
return $dir;
}

function list_template_files( $slug ) {

$theme_dir=get_theme_root();
$theme_dir.='/';
$theme_dir.=$slug;
$theme_dir.='/';
$theme_dir.=$this->get_template_dir( $slug );
$files =$this->get_file_list( $theme_dir, '*.html' );
return $files;
}


function display_templates($post, $slug) {
$additional_content = '';
$theme_dir = get_theme_root();
$theme_dir .= '/';
$theme_dir .= $slug;
$theme_dir .= '/';
$theme_dir .= $this->get_template_dir( $slug );
$files = $this->get_file_list($theme_dir, '*.html');
$files = $this->list_template_files( $slug );
e( sprintf( _n( '%$1s template', '%1$s templates', 'oik-themes'), count( $files ) ) );
$additional_content .= $this->accordion($files, 'templates');
return $additional_content;
}

function display_template_parts($post, $slug) {

function count_template_files( $slug ) {
$files = $this->list_template_files( $slug );
$count = count( $files );
return $count;

}

function count_parts_files( $slug ) {
$files = $this->list_parts_files( $slug );
$count = count( $files );
return $count;
}

function list_parts_files( $slug ) {
$theme_dir = get_theme_root();
$theme_dir = get_theme_root();
$theme_dir .= '/';
$theme_dir .= $slug;
$theme_dir .= '/';
$theme_dir .= $this->get_template_part_dir( $slug );
$files = $this->get_file_list($theme_dir, '*.html');
return $files;
}


function display_template_parts($post, $slug) {
$additional_content = "";
$theme_dir = get_theme_root();
$theme_dir = get_theme_root();
$theme_dir .= '/';
$theme_dir .= $slug;
$theme_dir .= '/';
$theme_dir .= $this->get_template_part_dir( $slug );
$files = $this->get_file_list($theme_dir, '*.html');
$files = $this->list_parts_files( $slug );
e( sprintf( _n( '%$1s template part', '%1$s template parts', 'oik-themes'), count( $files ) ) );
//printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
$additional_content .= $this->accordion($files, 'parts');
Expand Down
45 changes: 45 additions & 0 deletions includes/oik-themes-virtual-counts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

function oikth_templates_count( $args = null ) {
$templates_count = '?';
$id = bw_current_post_id();
//$post = get_post( $id );
$theme = get_post_meta( $id, '_oikth_slug', true );
if ( $theme ) {
oik_require( "includes/class-oik-themes-content.php", "oik-themes" );
$oik_themes_content=new OIK_themes_content();
$templates_count = $oik_themes_content->count_template_files( $theme );
}
return $templates_count;
}

function oikth_parts_count( $args = null ) {
$parts_count = '?';
$id = bw_current_post_id();
//$post = get_post( $id );
$theme = get_post_meta( $id, '_oikth_slug', true );
if ( $theme ) {
oik_require( "includes/class-oik-themes-content.php", "oik-themes" );
$oik_themes_content=new OIK_themes_content();
$parts_count = $oik_themes_content->count_parts_files( $theme );
}
return $parts_count;

}

function oikth_patterns_count( $args = null ) {

$patterns_count = '?';
$id = bw_current_post_id();
//$post = get_post( $id );
$theme = get_post_meta( $id, '_oikth_slug', true );
if ( $theme ) {
if ( function_exists( 'oik_patterns_loaded')) {
oik_require( 'libs/class-oik-patterns-import.php', 'oik-patterns' );
$oik_patterns_import=new OIK_patterns_import( $theme );
$patterns_count =$oik_patterns_import->count_patterns();
}
}
return $patterns_count;

}
46 changes: 45 additions & 1 deletion oik-themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function oikth_template_redirect() {
* Implement the "oik_fields_loaded" action for oik themes server
*/
function oikth_init( ) {
oik_register_oik_count_fields();
oik_register_oik_theme();
oik_register_oik_themeversion();
oik_register_oik_themiumversion();
Expand Down Expand Up @@ -180,7 +181,9 @@ function oik_register_oik_theme() {
bw_register_field( "_oikth_demo", "URL", "Live demonstration" );
bw_register_field( "_oikth_template", "noderef", "Template", array( '#type' => 'oik-themes', '#optional' => true ) ); // Parent theme name

/** Currently we support two different systems for delivering themium themes: WooCommerce and Easy Digital Downloads


/** Currently we support two different systems for delivering themium themes: WooCommerce and Easy Digital Downloads
* The Purchasable product should be completed for each themium oik theme (and Other themium theme? )
*/
$purchasable_product_type = array();
Expand All @@ -196,6 +199,9 @@ function oik_register_oik_theme() {
bw_register_field_for_object_type( "_oikth_prod", $post_type );
bw_register_field_for_object_type( "_oikth_demo", $post_type );
bw_register_field_for_object_type( "_oikth_template", $post_type );
bw_register_field_for_object_type( "_oikth_templates_count", $post_type );
bw_register_field_for_object_type( "_oikth_parts_count", $post_type );
bw_register_field_for_object_type( "_oikth_patterns_count", $post_type );

bw_register_field_for_object_type( "_oikp_git", $post_type );
oikth_columns_and_titles( $post_type );
Expand Down Expand Up @@ -649,3 +655,41 @@ function oikth_activation() {
$depends = "oik-plugins:1.16.0,oik-fields:1.50.0,oik:3.2.1";
oik_plugin_lazy_activation( __FILE__, $depends, "oik_plugin_plugin_inactive" );
}

/**
* Registers the virtual fields for counts.
*
* Note: Plugins can deliver patterns as well. eg core.
*/
function oik_register_oik_count_fields() {
$templates_args = array( "#callback" => "oikth_templates_count"
, "#parms" => null
, "#plugin" => 'oik-themes'
, "#file" => "includes/oik-themes-virtual-counts.php"
, "#form" => false
, "#hint" => "virtual field"
//, '#theme_null' => false // set this to false when it's not needed in Information
);
bw_register_field( '_oikth_templates_count', 'virtual', 'Templates delivered', $templates_args);

$parts_args = array( "#callback" => "oikth_parts_count"
, "#parms" => null
, "#plugin" => 'oik-themes'
, "#file" => "includes/oik-themes-virtual-counts.php"
, "#form" => false
, "#hint" => "virtual field"
//, '#theme_null' => false // set this to false when it's not needed in Information
);
bw_register_field( '_oikth_parts_count', 'virtual', 'Template parts delivered', $parts_args );

$patterns_args = array( "#callback" => "oikth_patterns_count"
, "#parms" => null
, "#plugin" => 'oik-themes'
, "#file" => "includes/oik-themes-virtual-counts.php"
, "#form" => false
, "#hint" => "virtual field"
//, '#theme_null' => false // set this to false when it's not needed in Information
);
bw_register_field( '_oikth_patterns_count', 'virtual', 'Patterns delivered', $patterns_args );

}

0 comments on commit c3d080f

Please sign in to comment.