<commit_before><?php
/**
 * Template Name: Pods - Publications - index
 * Description: The template used for Publications, showing publication info, listing available articles, etc.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */
?><?php
/* URI: TBD */
$PODS_BASEURI_ARTICLES = '/media/objects/articles';
$TRACE_ENABLED = true; // is_user_logged_in();
$TRACE_PREFIX = 'pods-publications';

$publication_slug = get_post_meta($post->ID, 'pod_slug', true);
echo var_trace('pod_slug: ' . $publication_slug, $TRACE_PREFIX, $TRACE_ENABLED);
$pod = new Pod('publication_wrappers', $publication_slug);
$publication_pod = $pod; // TODO refactor code and move generation of list of articles to sub used both in pods-articles and pods-publication
$pod_title = $pod->get_field('name');
$pod_subtitle = $pod->get_field('publication_subtitle');
$pod_issuu_uri = $pod->get_field('issuu_uri');
$pod_cover = $pod->get_field('snapshot.guid');
$pod_abstract = do_shortcode($pod->get_field('abstract'));

// get tiles for heading slider
$heading_slides = array();
echo var_trace($pod->get_field('heading_slides.slug'), $TRACE_PREFIX, $TRACE_ENABLED);
$slider_pod = new Pod('slide', $pod->get_field('heading_slides.slug'));
foreach($slider_pod->get_field('tiles.slug') as $tile_slug) {
  echo var_trace($tile_slug, $TRACE_PREFIX, $TRACE_ENABLED);
  $tile = new Pod('tile', $tile_slug);
  array_push($heading_slides, $tile->get_field('image.guid'));
}

$pod_pdf = $pod->get_field('publication_pdf.guid') ? $pod->get_field('publication_pdf.guid') : $pod->get_field('publication_pdf_uri');
$pod_alt_pdf = $pod->get_field('publication_alt_pdf.guid') ? $pod->get_field('publication_alt_pdf.guid') : $pod->get_field('publication_alt_pdf_uri');
$pod_pdf_lang2 = $pod->get_field('publication_pdf_lang2.guid') ? $pod->get_field('publication_pdf_lang2.guid') : $pod->get_field('publication_pdf_lang2_uri');
$pod_alt_pdf_lang2 = $pod->get_field('publication_alt_pdf_lang2.guid') ? $pod->get_field('publication_alt_pdf_lang2.guid') : $pod->get_field('publication_alt_pdf_lang2_uri');

$publication_authors_list = $pod->get_field('authors');
foreach($publication_authors_list as $publication_author) {
  $publication_authors .= $publication_author['name'] . ' ' . $publication_author['family_name'] . ', ';
}
$publication_authors = substr($publication_authors, 0, -2);
$publication_editors_list = $pod->get_field('editors');
foreach($publication_editors_list as $publication_editor) {
  $publication_editors .= $publication_editor['name'] . ' ' . $publication_editor['family_name'] . ', ';
}
$publication_editors = substr($publication_editors, 0, -2);
$publication_contributors_list = $pod->get_field('contributors');
foreach($publication_contributors_list as $publication_contributor) {
  $publication_contributors .= $publication_contributor['name'] . ' ' . $publication_contributor['family_name'] . ', ';
}
$publication_contributors = substr($publication_contributors, 0, -2);
$publication_catalogue_data = $pod->get_field('catalogue_data');
$publishing_date = $pod->get_field('publishing_date');

$articles_pods = new Pod('article');
$search_params = array();
$search_params['where'] = 'in_publication.id = ' .$pod->get_field('id');
$search_params['orderby'] = 'sequence';
$search_params['limit'] = -1;
$articles_pods->findRecords($search_params);

// get list of publication sections
$publication_sections = array();
foreach(preg_split("/\n/", $publication_pod->get_field('sections')) as $section_line) {
  preg_match("/^(\d+)?\s?(.*)$/", $section_line, $matches);
  if($matches[1]) {
    array_push($publication_sections, array( 'id' => $matches[1], 'title' => $matches[2]));
  }
}
echo var_trace('sections: ' . var_export($publication_sections, true), $TRACE_PREFIX, $TRACE_ENABLED);
              

?><?php get_header(); ?>

<div role="main">
  <?php if ( have_posts() ) : the_post(); endif; ?>
  <div id="post-<?php the_ID(); ?>" <?php post_class('lc-article lc-publication'); ?>>
    <div class='ninecol' id='contentarea'>
      <div class='top-content'>
        <?php if(count($heading_slides)) : ?>
        <header class='heading-image'>
          <div class='flexslider wireframe'>
            <ul class='slides'>
              <?php foreach($heading_slides as $slide): ?>
              <li><img src='<?php echo $slide; ?>' /></li>
              <?php endforeach; ?>
            </ul>
          </div>
        </header>
        <?php endif; ?>
        
        <article class='wireframe eightcol row'>
          <header class='entry-header'>
            <h1><?php echo $pod_title; ?></h1>
            <?php if($pod_subtitle): ?><h2><?php echo $pod_subtitle; ?></h2><?php endif ; ?>
          </header>
          <div class='entry-content article-text'>
            <?php echo $pod->get_field('blurb'); ?>
          </div>
          <?php if(count($publication_sections) > 1): ?>
          <section class='publication-sections'>
            <h1>Browse content</h1>
            <ul>
              <?php foreach($publication_sections as $section): ?>
              <li><a href="#publication-section-<?php echo $section['title']; ?>"><?php echo $section['title']; ?></a></li>
              <?php endforeach; ?>
            </ul>
          </section>
          <?php endif; ?>
          <?php get_template_part('snippet-socialmedia-share'); ?>
        </article>
        <aside class='wireframe fourcol last entry-meta' id='keyfacts'>
          <div class='cover-thumbnail'><img src="<?php echo $pod_cover; ?>" /></div>
          <ul>
            <?php if($pod_pdf) : ?>
            <li><a class="downloadthis pdf button" href="<?php echo $pod_pdf; ?>">Download PDF</a></li>
            <?php endif ; ?>
            <?php if($pod_issuu_uri) : ?>
            <li><a class="issuu button" href="<?php echo $pod_issuu_uri; ?>">Online browser</a></li>
            <?php endif ; ?>
          </ul>
          <dl>
          <?php if($publication_authors): ?>
            <dt>Authors</dt>
            <dd><?php echo $publication_authors; ?></dd>
          <?php endif; ?>
          <?php if($publication_editors): ?>
            <dt>Editors</dt>
            <dd><?php echo $publication_editors; ?></dd>
          <?php endif; ?>
          <?php if($publication_contributors): ?>
            <dt>Contributors</dt>
            <dd><?php echo $publication_contributors; ?></dd>
          <?php endif; ?>
          <?php if($publishing_date): ?>
            <dt>Publication date</dt>
            <dd><?php echo $publishing_date; ?></dd>
          <?php endif; ?>
          <?php if($publication_catalogue_data): ?>
            <dt>Catalogue data</dt>
            <dd><?php echo $publication_catalogue_data; ?></dd>
          <?php endif; ?>         
          </dl>
        </aside><!-- #keyfacts -->
      </div><!-- .top-content -->
      <div class='extra-content row'>
          <?php echo var_trace(var_export($pod->get_field('reviews_category.term_id'), true), $TRACE_PREFIX, $TRACE_ENABLED); ?>
          <?php if($pod->get_field('reviews_category.term_id')): ?>
          <section class="row" id="wp-posts-reviews">
            <header><h1>Reviews</h1></header>
            <?php
              $wp_posts_reviews = get_posts(array('category' => $pod->get_field('reviews_category.term_id'), 'numberposts' => 10));
              if(count($wp_posts_reviews)): ?>
              <dl class="posts">
              <?php
              foreach($wp_posts_reviews as $post):
                setup_postdata($post); ?>
                <dt><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dt>
                <dd><?php the_date(); ?></dd>
            <?php endforeach; ?>
              </dl><!-- .posts -->
            <?php endif; ?>
          </section><!-- #wp-posts-reviews -->
          <?php endif; ?><commit_msg>do not display section if no posts are available<commit_after><?php
/**
 * Template Name: Pods - Publications - index
 * Description: The template used for Publications, showing publication info, listing available articles, etc.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */
?><?php
/* URI: TBD */
$PODS_BASEURI_ARTICLES = '/media/objects/articles';
$TRACE_ENABLED = true; // is_user_logged_in();
$TRACE_PREFIX = 'pods-publications';

$publication_slug = get_post_meta($post->ID, 'pod_slug', true);
echo var_trace('pod_slug: ' . $publication_slug, $TRACE_PREFIX, $TRACE_ENABLED);
$pod = new Pod('publication_wrappers', $publication_slug);
$publication_pod = $pod; // TODO refactor code and move generation of list of articles to sub used both in pods-articles and pods-publication
$pod_title = $pod->get_field('name');
$pod_subtitle = $pod->get_field('publication_subtitle');
$pod_issuu_uri = $pod->get_field('issuu_uri');
$pod_cover = $pod->get_field('snapshot.guid');
$pod_abstract = do_shortcode($pod->get_field('abstract'));

// get tiles for heading slider
$heading_slides = array();
echo var_trace($pod->get_field('heading_slides.slug'), $TRACE_PREFIX, $TRACE_ENABLED);
$slider_pod = new Pod('slide', $pod->get_field('heading_slides.slug'));
foreach($slider_pod->get_field('tiles.slug') as $tile_slug) {
  echo var_trace($tile_slug, $TRACE_PREFIX, $TRACE_ENABLED);
  $tile = new Pod('tile', $tile_slug);
  array_push($heading_slides, $tile->get_field('image.guid'));
}

$pod_pdf = $pod->get_field('publication_pdf.guid') ? $pod->get_field('publication_pdf.guid') : $pod->get_field('publication_pdf_uri');
$pod_alt_pdf = $pod->get_field('publication_alt_pdf.guid') ? $pod->get_field('publication_alt_pdf.guid') : $pod->get_field('publication_alt_pdf_uri');
$pod_pdf_lang2 = $pod->get_field('publication_pdf_lang2.guid') ? $pod->get_field('publication_pdf_lang2.guid') : $pod->get_field('publication_pdf_lang2_uri');
$pod_alt_pdf_lang2 = $pod->get_field('publication_alt_pdf_lang2.guid') ? $pod->get_field('publication_alt_pdf_lang2.guid') : $pod->get_field('publication_alt_pdf_lang2_uri');

$publication_authors_list = $pod->get_field('authors');
foreach($publication_authors_list as $publication_author) {
  $publication_authors .= $publication_author['name'] . ' ' . $publication_author['family_name'] . ', ';
}
$publication_authors = substr($publication_authors, 0, -2);
$publication_editors_list = $pod->get_field('editors');
foreach($publication_editors_list as $publication_editor) {
  $publication_editors .= $publication_editor['name'] . ' ' . $publication_editor['family_name'] . ', ';
}
$publication_editors = substr($publication_editors, 0, -2);
$publication_contributors_list = $pod->get_field('contributors');
foreach($publication_contributors_list as $publication_contributor) {
  $publication_contributors .= $publication_contributor['name'] . ' ' . $publication_contributor['family_name'] . ', ';
}
$publication_contributors = substr($publication_contributors, 0, -2);
$publication_catalogue_data = $pod->get_field('catalogue_data');
$publishing_date = $pod->get_field('publishing_date');

$articles_pods = new Pod('article');
$search_params = array();
$search_params['where'] = 'in_publication.id = ' .$pod->get_field('id');
$search_params['orderby'] = 'sequence';
$search_params['limit'] = -1;
$articles_pods->findRecords($search_params);

// get list of publication sections
$publication_sections = array();
foreach(preg_split("/\n/", $publication_pod->get_field('sections')) as $section_line) {
  preg_match("/^(\d+)?\s?(.*)$/", $section_line, $matches);
  if($matches[1]) {
    array_push($publication_sections, array( 'id' => $matches[1], 'title' => $matches[2]));
  }
}
echo var_trace('sections: ' . var_export($publication_sections, true), $TRACE_PREFIX, $TRACE_ENABLED);
              

?><?php get_header(); ?>

<div role="main">
  <?php if ( have_posts() ) : the_post(); endif; ?>
  <div id="post-<?php the_ID(); ?>" <?php post_class('lc-article lc-publication'); ?>>
    <div class='ninecol' id='contentarea'>
      <div class='top-content'>
        <?php if(count($heading_slides)) : ?>
        <header class='heading-image'>
          <div class='flexslider wireframe'>
            <ul class='slides'>
              <?php foreach($heading_slides as $slide): ?>
              <li><img src='<?php echo $slide; ?>' /></li>
              <?php endforeach; ?>
            </ul>
          </div>
        </header>
        <?php endif; ?>
        
        <article class='wireframe eightcol row'>
          <header class='entry-header'>
            <h1><?php echo $pod_title; ?></h1>
            <?php if($pod_subtitle): ?><h2><?php echo $pod_subtitle; ?></h2><?php endif ; ?>
          </header>
          <div class='entry-content article-text'>
            <?php echo $pod->get_field('blurb'); ?>
          </div>
          <?php if(count($publication_sections) > 1): ?>
          <section class='publication-sections'>
            <h1>Browse content</h1>
            <ul>
              <?php foreach($publication_sections as $section): ?>
              <li><a href="#publication-section-<?php echo $section['title']; ?>"><?php echo $section['title']; ?></a></li>
              <?php endforeach; ?>
            </ul>
          </section>
          <?php endif; ?>
          <?php get_template_part('snippet-socialmedia-share'); ?>
        </article>
        <aside class='wireframe fourcol last entry-meta' id='keyfacts'>
          <div class='cover-thumbnail'><img src="<?php echo $pod_cover; ?>" /></div>
          <ul>
            <?php if($pod_pdf) : ?>
            <li><a class="downloadthis pdf button" href="<?php echo $pod_pdf; ?>">Download PDF</a></li>
            <?php endif ; ?>
            <?php if($pod_issuu_uri) : ?>
            <li><a class="issuu button" href="<?php echo $pod_issuu_uri; ?>">Online browser</a></li>
            <?php endif ; ?>
          </ul>
          <dl>
          <?php if($publication_authors): ?>
            <dt>Authors</dt>
            <dd><?php echo $publication_authors; ?></dd>
          <?php endif; ?>
          <?php if($publication_editors): ?>
            <dt>Editors</dt>
            <dd><?php echo $publication_editors; ?></dd>
          <?php endif; ?>
          <?php if($publication_contributors): ?>
            <dt>Contributors</dt>
            <dd><?php echo $publication_contributors; ?></dd>
          <?php endif; ?>
          <?php if($publishing_date): ?>
            <dt>Publication date</dt>
            <dd><?php echo $publishing_date; ?></dd>
          <?php endif; ?>
          <?php if($publication_catalogue_data): ?>
            <dt>Catalogue data</dt>
            <dd><?php echo $publication_catalogue_data; ?></dd>
          <?php endif; ?>         
          </dl>
        </aside><!-- #keyfacts -->
      </div><!-- .top-content -->
      <div class='extra-content row'>
          <?php echo var_trace(var_export($pod->get_field('reviews_category.term_id'), true), $TRACE_PREFIX, $TRACE_ENABLED); ?>
          <?php if($pod->get_field('reviews_category.term_id')):
                  $wp_posts_reviews = get_posts(array('category' => $pod->get_field('reviews_category.term_id'), 'numberposts' => 10));
                  if(count($wp_posts_reviews)): ?>
          <section class="row" id="wp-posts-reviews">
            <header><h1>Reviews</h1></header>
              <dl class="posts">
              <?php
              foreach($wp_posts_reviews as $post):
                setup_postdata($post); ?>
                <dt><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dt>
                <dd><?php the_date(); ?></dd>
              <?php endforeach; ?>
              </dl><!-- .posts -->
          </section><!-- #wp-posts-reviews -->
            <?php endif; ?>
          <?php endif; ?>
{'fraction_non_alphanumeric': 0.18269966828272519, 'fraction_numerical': 0.003955090584332738, 'mean_word_length': 3.3486823855755894, 'pattern_counts': {'":': 0, '<': 292, '<?xml version=': 0, '>': 370, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '470977', 'n_tokens_mistral': 5076, 'n_tokens_neox': 5057, 'n_words': 893}