Skip to content

Commit

Permalink
Ensure template code (if set) is not run if the corresponding templat…
Browse files Browse the repository at this point in the history
…e file exists
  • Loading branch information
sc0ttkclark committed Nov 17, 2024
1 parent 37672cd commit 9dad299
Showing 1 changed file with 50 additions and 44 deletions.
94 changes: 50 additions & 44 deletions components/Templates/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ public static function template( $template_name, $code = null, $obj = null, $dep
return '';
}

$has_code_override = ! empty( $code );

/** @var Pods $obj */

$template = array(
Expand Down Expand Up @@ -623,7 +625,18 @@ public static function template( $template_name, $code = null, $obj = null, $dep

ob_start();

if ( ! empty( $code ) ) {
// @todo If the template exists, uses that, otherwise use the $code.

$template_file = null;

if ( $template_name == trim( preg_replace( '/[^a-zA-Z0-9_\-\/]/', '', $template_name ), ' /-' ) ) {
$default_templates = self::get_templates_for_pod_template( $template, $obj );
$template_files_info = self::get_template_files_info( $default_templates );

$template_file = array_key_first( $template_files_info );
}

if ( $has_code_override || ( ! $template_file && ! empty( $code ) ) ) {
// Only detail templates need $this->id
if ( empty( $obj->id ) ) {
$obj->reset();
Expand Down Expand Up @@ -657,58 +670,51 @@ public static function template( $template_name, $code = null, $obj = null, $dep
echo self::do_template( $code, $obj, true );
}
}
} elseif ( $template_name == trim( preg_replace( '/[^a-zA-Z0-9_\-\/]/', '', $template_name ), ' /-' ) ) {
$default_templates = self::get_templates_for_pod_template( $template, $obj );
$template_files_info = self::get_template_files_info( $default_templates );

$template_file = array_key_first( $template_files_info );

if ( $template_file ) {
if ( $template_files_info[ $template_file ]['MagicTags'] ) {
$process_magic_tags = true;
}

if ( empty( $obj->id ) ) {
while ( $obj->fetch() ) {
$info['item_id'] = $obj->id();

// Ensure the post is not password protected.
if (
$check_access
&& (
pods_access_bypass_post_with_password( $info )
|| pods_access_bypass_private_post( $info )
)
) {
continue;
}

$template_output = pods_template_part( $template_file, compact( array_keys( get_defined_vars() ) ), true );

if ( $process_magic_tags ) {
$template_output = self::do_template( $template_output, $obj );
}
} elseif ( $template_file ) {
if ( $template_files_info[ $template_file ]['MagicTags'] ) {
$process_magic_tags = true;
}

echo $template_output;
}
} else {
if ( empty( $obj->id ) ) {
while ( $obj->fetch() ) {
$info['item_id'] = $obj->id();

// Ensure the post is not password protected.
if (
! $check_access
|| (
! pods_access_bypass_post_with_password( $info )
&& ! pods_access_bypass_private_post( $info )
$check_access
&& (
pods_access_bypass_post_with_password( $info )
|| pods_access_bypass_private_post( $info )
)
) {
$template_output = pods_template_part( $template_file, compact( array_keys( get_defined_vars() ) ), true );
continue;
}

if ( $process_magic_tags ) {
$template_output = self::do_template( $template_output, $obj );
}
$template_output = pods_template_part( $template_file, compact( array_keys( get_defined_vars() ) ), true );

echo $template_output;
if ( $process_magic_tags ) {
$template_output = self::do_template( $template_output, $obj );
}

echo $template_output;
}
} else {
$info['item_id'] = $obj->id();

if (
! $check_access
|| (
! pods_access_bypass_post_with_password( $info )
&& ! pods_access_bypass_private_post( $info )
)
) {
$template_output = pods_template_part( $template_file, compact( array_keys( get_defined_vars() ) ), true );

if ( $process_magic_tags ) {
$template_output = self::do_template( $template_output, $obj );
}

echo $template_output;
}
}
}//end if
Expand Down

0 comments on commit 9dad299

Please sign in to comment.