<commit_before><?php
/**
 * Template Name: Pods - Main frontpages
 * Description: The template used for LSE Cities main frontpage and Urban Age sub-site frontpage
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */
?><?php
/**
 * Pods initialization
 * URI: TBD
 */
$pod_slug = get_post_meta($post->ID, 'pod_slug', true);
$TRACE_PREFIX = 'pods-main-frontpage';
$TRACE_ENABLED = is_user_logged_in();

$TRACE_PODS_MAIN_FRONTPAGE = true;

$TILES_PER_COLUMN = 2;

function get_tile_classes($tile_layout) {
  $element_classes = '';
  
  $xcount = substr($tile_layout, 0, 1);
  $ycount = substr($tile_layout, -1);
  
  switch($xcount) {
    case '1':
      $element_classes .= 'onetile';
      break;
    case '2':
      $element_classes .= 'twotiles';
      break;
    case '3':
      $element_classes .= 'threetiles';
      break;
    case '4':
      $element_classes .= 'fourtiles';
      break;
    case '5':
      $element_classes .= 'fivetiles';
      break;
  }
  
  switch($ycount) {
    case '2':
      $element_classes .= ' tall';
      break;
  }
  
  return $element_classes;
}

function compose_slide($column_spans, $tiles) {
  global $TRACE_PODS_MAIN_FRONTPAGE;
  global $TILES_PER_COLUMN;
  
  if($TRACE_PODS_MAIN_FRONTPAGE) {
    echo '<!-- compose_slide|tiles: ' . var_export($tiles, true) . " -->\n";
  }

  $slide_content = array('columns' => array());
  $tile_index = 0;
  $total_tiles = count($tiles); 
  
  if($TRACE_PODS_MAIN_FRONTPAGE) {
    echo '<!-- column_spans: ' . var_export($column_spans, true) . " -->\n";
  }
  
  foreach($column_spans as $column_span) {
    $tile_count = $column_span * $TILES_PER_COLUMN;
    $slide_column = array('layout' => 'col' . $column_span, 'tiles' => array());
    while($tile_count > 0 and $tile_index <= $total_tiles) {
      if($TRACE_PODS_MAIN_FRONTPAGE) {
        echo '<!-- tile[slug]: ' . var_export($tiles[$tile_index]['slug'], true) . " -->\n";
      }
      $tile = new Pod('tile', $tiles[$tile_index++]['slug']);
      $tile_layout = $tile->get_field('tile_layout.name');
      if($TRACE_PODS_MAIN_FRONTPAGE) {
        echo '<!-- tile[layout]: ' . var_export($tile_layout, true) . " -->\n";
      }
      $this_tile_count = preg_replace('/x/', '*', $tile_layout);
      if($TRACE_PODS_MAIN_FRONTPAGE) {
        echo '<!-- this_tile_count: ' . var_export($this_tile_count, true) . " -->\n";
      }
      eval('$this_tile_count = ' . $this_tile_count . ';');
      $tile_count -= $this_tile_count;
      if($TRACE_PODS_MAIN_FRONTPAGE) {
        echo '<!-- tile_countdown: ' . var_export($tile_count, true) . " -->\n";
      }

      unset($linked_event_month, $linked_event_day, $target_uri);
      
      if($tile->get_field('linked_event.date_start')) {
        $linked_event_date = new DateTime($tile->get_field('linked_event.date_start'));
        var_trace('linked_event_date: ' . var_export($linked_event_date, true), $TRACE_PREFIX, $TRACE_ENABLED);
        $linked_event_month = $linked_event_date->format('M');
        $linked_event_day = $linked_event_date->format('j');
        $linked_event_slug = $tile->get_field('linked_event.slug');
      }
      
      if($tile->get_field('linked_event.slug')) {
        $target_uri = '/media/objects/events/' . $tile->get_field('linked_event.slug');
      } elseif($tile->get_field('target_uri')) {
        $target_uri = $tile->get_field('target_uri');
      }
      
      array_push($slide_column['tiles'],
        array(
          'id' => $tile->get_field('slug'),
          'element_class' => rtrim(get_tile_classes($tile_layout) . ' ' . $tile->get_field('class'), ' '),
          'title' => $tile->get_field('name'),
          'display_title' => $tile->get_field('display_title'),
          'subtitle' => $tile->get_field('tagline'),
          'blurb' => $tile->get_field('blurb'),
          'plain_content' => $tile->get_field('plain_content'),
          'posts_category' => $tile->get_field('posts_category'),
          'target_uri' => $target_uri,
          'image' => $tile->get_field('image.guid'),
          'linked_event' => array(
            'month' => $linked_event_month,
            'day' => $linked_event_day
          )
        )
      );
    }
    array_push($slide_content['columns'], $slide_column);
  }
  return $slide_content;
}

if($TRACE_PODS_MAIN_FRONTPAGE) { error_log('pod_slug: ' . $pod_slug); }
$pod = new Pod('slider', $pod_slug);

$slides = $pod->get_field('slides');
?><?php get_header(); ?>

<div role="main">

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class('lc-article lc-slider-page'); ?>>
	<header class="entry-header">
		<!-- <h1 class="entry-title"><?php echo $pod->get_field('name'); ?></h1> -->
    <?php
      $tagline = $pod->get_field('tagline');
      if($tagline) : ?>
      <h2><?php echo $tagline; ?></h2>
    <?php endif; ?>
	</header><!-- .entry-header -->

	<div class="entry-content">

    <div class='row' id='core'>
      <article class='twelvecol'>
<div class="flexslider">
  <?php if($TRACE_PODS_MAIN_FRONTPAGE): ?>
  <!--
  <?php var_export($slides, false); ?>
  -->
  <?php endif; ?>
              <ul class="slides">
                <?php foreach($slides as $current_slide): ?>
                <?php
                  $current_slide_pod = new Pod('slide', $current_slide['slug']);
                  $slide_layout = $current_slide_pod->get_field('slide_layout.slug');
                  $tiles = $current_slide_pod->get_field('tiles', 'displayorder ASC');
                ?>
<!-- <?php if($TRACE_PODS_MAIN_FRONTPAGE) { echo 'tiles => ' . var_export($tiles, true) . "\n\n" . 'slide_layout => ' . var_export($slide_layout, true); }?> -->
				<?php
                  switch($slide_layout) {
                    case 'two-two-one':
                      $slide_content = compose_slide(array(2, 2, 1), $tiles);
                                           
                      if($TRACE_PODS_MAIN_FRONTPAGE) { echo '<!-- slide_content_array: ' . var_export($slide_content, true) . " -->\n"; }
                      break;
                    default:
                      break;
                  }
                ?>
                <li>
                  <div class="slide-inner row">
                    <?php foreach($slide_content['columns'] as $slide_column): ?>
                      <div class="<?php echo $slide_column['layout']; ?>">
                        <?php foreach($slide_column['tiles'] as $tile): ?>
                          <div class="tile <?php echo $tile['element_class']; ?>" id="slidetile-<?php echo $tile['id']; ?>">
                            <?php if($slide_column['target_uri']): ?>
                            <a href="<?php echo $target_uri; ?>">
                            <?php endif; ?>
                            <?php if($tile['image']): ?>
                              <div class="crop">
                                <img src="<?php echo $tile['image']; ?>" alt="" />
                              </div>
                            <?php endif; ?>
                            <?php if($tile['plain_content']): ?><commit_msg>updated tracing<commit_after><?php
/**
 * Template Name: Pods - Main frontpages
 * Description: The template used for LSE Cities main frontpage and Urban Age sub-site frontpage
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */
?><?php
/**
 * Pods initialization
 * URI: TBD
 */
$pod_slug = get_post_meta($post->ID, 'pod_slug', true);
$TRACE_PREFIX = 'pods-main-frontpage';
$TRACE_ENABLED = is_user_logged_in();

$TILES_PER_COLUMN = 2;

function get_tile_classes($tile_layout) {
  $element_classes = '';
  
  $xcount = substr($tile_layout, 0, 1);
  $ycount = substr($tile_layout, -1);
  
  switch($xcount) {
    case '1':
      $element_classes .= 'onetile';
      break;
    case '2':
      $element_classes .= 'twotiles';
      break;
    case '3':
      $element_classes .= 'threetiles';
      break;
    case '4':
      $element_classes .= 'fourtiles';
      break;
    case '5':
      $element_classes .= 'fivetiles';
      break;
  }
  
  switch($ycount) {
    case '2':
      $element_classes .= ' tall';
      break;
  }
  
  return $element_classes;
}

function compose_slide($column_spans, $tiles) {
  global $TRACE_ENABLED;
  global $TILES_PER_COLUMN;
  
  if($TRACE_ENABLED) {
    echo '<!-- compose_slide|tiles: ' . var_export($tiles, true) . " -->\n";
  }

  $slide_content = array('columns' => array());
  $tile_index = 0;
  $total_tiles = count($tiles); 
  
  if($TRACE_ENABLED) {
    echo '<!-- column_spans: ' . var_export($column_spans, true) . " -->\n";
  }
  
  foreach($column_spans as $column_span) {
    $tile_count = $column_span * $TILES_PER_COLUMN;
    $slide_column = array('layout' => 'col' . $column_span, 'tiles' => array());
    while($tile_count > 0 and $tile_index <= $total_tiles) {
      if($TRACE_ENABLED) {
        echo '<!-- tile[slug]: ' . var_export($tiles[$tile_index]['slug'], true) . " -->\n";
      }
      $tile = new Pod('tile', $tiles[$tile_index++]['slug']);
      $tile_layout = $tile->get_field('tile_layout.name');
      if($TRACE_ENABLED) {
        echo '<!-- tile[layout]: ' . var_export($tile_layout, true) . " -->\n";
      }
      $this_tile_count = preg_replace('/x/', '*', $tile_layout);
      if($TRACE_ENABLED) {
        echo '<!-- this_tile_count: ' . var_export($this_tile_count, true) . " -->\n";
      }
      eval('$this_tile_count = ' . $this_tile_count . ';');
      $tile_count -= $this_tile_count;
      if($TRACE_ENABLED) {
        echo '<!-- tile_countdown: ' . var_export($tile_count, true) . " -->\n";
      }

      unset($linked_event_month, $linked_event_day, $target_uri);
      
      if($tile->get_field('linked_event.date_start')) {
        $linked_event_date = new DateTime($tile->get_field('linked_event.date_start'));
        var_trace('linked_event_date: ' . var_export($linked_event_date, true), $TRACE_PREFIX, $TRACE_ENABLED);
        $linked_event_month = $linked_event_date->format('M');
        $linked_event_day = $linked_event_date->format('j');
        $linked_event_slug = $tile->get_field('linked_event.slug');
      }
      
      if($tile->get_field('linked_event.slug')) {
        $target_uri = '/media/objects/events/' . $tile->get_field('linked_event.slug');
      } elseif($tile->get_field('target_uri')) {
        $target_uri = $tile->get_field('target_uri');
      }
      
      array_push($slide_column['tiles'],
        array(
          'id' => $tile->get_field('slug'),
          'element_class' => rtrim(get_tile_classes($tile_layout) . ' ' . $tile->get_field('class'), ' '),
          'title' => $tile->get_field('name'),
          'display_title' => $tile->get_field('display_title'),
          'subtitle' => $tile->get_field('tagline'),
          'blurb' => $tile->get_field('blurb'),
          'plain_content' => $tile->get_field('plain_content'),
          'posts_category' => $tile->get_field('posts_category'),
          'target_uri' => $target_uri,
          'image' => $tile->get_field('image.guid'),
          'linked_event' => array(
            'month' => $linked_event_month,
            'day' => $linked_event_day
          )
        )
      );
    }
    array_push($slide_content['columns'], $slide_column);
  }
  return $slide_content;
}

if($TRACE_ENABLED) { error_log('pod_slug: ' . $pod_slug); }
$pod = new Pod('slider', $pod_slug);

$slides = $pod->get_field('slides');
?><?php get_header(); ?>

<div role="main">

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class('lc-article lc-slider-page'); ?>>
	<header class="entry-header">
		<!-- <h1 class="entry-title"><?php echo $pod->get_field('name'); ?></h1> -->
    <?php
      $tagline = $pod->get_field('tagline');
      if($tagline) : ?>
      <h2><?php echo $tagline; ?></h2>
    <?php endif; ?>
	</header><!-- .entry-header -->

	<div class="entry-content">

    <div class='row' id='core'>
      <article class='twelvecol'>
<div class="flexslider">
  <?php if($TRACE_ENABLED): ?>
  <!--
  <?php var_export($slides, false); ?>
  -->
  <?php endif; ?>
              <ul class="slides">
                <?php foreach($slides as $current_slide): ?>
                <?php
                  $current_slide_pod = new Pod('slide', $current_slide['slug']);
                  $slide_layout = $current_slide_pod->get_field('slide_layout.slug');
                  $tiles = $current_slide_pod->get_field('tiles', 'displayorder ASC');
                ?>
<!-- <?php if($TRACE_ENABLED) { echo 'tiles => ' . var_export($tiles, true) . "\n\n" . 'slide_layout => ' . var_export($slide_layout, true); }?> -->
				<?php
                  switch($slide_layout) {
                    case 'two-two-one':
                      $slide_content = compose_slide(array(2, 2, 1), $tiles);
                                           
                      if($TRACE_ENABLED) { echo '<!-- slide_content_array: ' . var_export($slide_content, true) . " -->\n"; }
                      break;
                    default:
                      break;
                  }
                ?>
                <li>
                  <div class="slide-inner row">
                    <?php foreach($slide_content['columns'] as $slide_column): ?>
                      <div class="<?php echo $slide_column['layout']; ?>">
                        <?php foreach($slide_column['tiles'] as $tile): ?>
                          <div class="tile <?php echo $tile['element_class']; ?>" id="slidetile-<?php echo $tile['id']; ?>">
                            <?php if($slide_column['target_uri']): ?>
                            <a href="<?php echo $target_uri; ?>">
                            <?php endif; ?>
                            <?php if($tile['image']): ?>
                              <div class="crop">
                                <img src="<?php echo $tile['image']; ?>" alt="" />
                              </div>
                            <?php endif; ?>
                            <?php if($tile['plain_content']): ?>
{'fraction_non_alphanumeric': 0.1823005093378608, 'fraction_numerical': 0.0029711375212224107, 'mean_word_length': 2.3263529411764705, 'pattern_counts': {'":': 0, '<': 127, '<?xml version=': 0, '>': 213, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '82360', 'n_tokens_mistral': 4659, 'n_tokens_neox': 4650, 'n_words': 755}