<?php header('Content-type: text/html; charset=utf-8'); ?>

<?php

  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

  // load viewer library

  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';

  $dirsToCheck = array('/home/client/public_html/','','../','../../','../../../');

  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}

  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }



  list($newsRecords, $newsMetaData) = getRecords(array(

    'tableName'   => 'news',

    'perPage'     => '4',

    'loadUploads' => true,

    'allowSearch' => false,

  ));



  list($page_headersRecords, $page_headersMetaData) = getRecords(array(

    'tableName'   => 'page_headers',

    'where'       => "`num` = '1'",

    'loadUploads' => true,

    'allowSearch' => false,

    'limit'       => '1',

  ));



  /* Usage: <?php echo maxWords($record['content'], 11); ?> */

  function maxWords($textOrHtml, $maxWords) {

    $text = strip_tags($textOrHtml);

    $words = preg_split("/\s+/", $text, $maxWords+1);

    $totalWords = $words;

    if (count($words) > $maxWords) { unset($words[$maxWords]); }

    $output = join(' ', $words);

    return $output;

  }



  /* Usage: <?php echo maxWordsP($record['content'], 11); ?> */

  function maxWordsP($textOrHtml, $maxWordsP) {

    $text=str_replace("<p>","*P*",$textOrHtml);

    $text= str_replace("</p>","*/P*",$text);

    $text = strip_tags($text);

    $words = preg_split("/\s+/", $text, $maxWordsP+1);

    $totalWords = $words;

    if (count($words) > $maxWordsP) { unset($words[$maxWordsP]); }

    $output = join(' ', $words);

    $output=str_replace("*P*","<p>",$output);

    $output=str_replace("*/P*","</p>",$output);

    $output.="</p>";

    return $output;

  }



?><!DOCTYPE html>

<!--[if IE 9]><html class="lt-ie10" lang="en" > <![endif]-->

<html class="no-js" lang="en" >

  <head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>News</title>

    <script src="bower_components/modernizr/modernizr.js"></script>

    <link rel="stylesheet" href="stylesheets/app.css" />

    <link rel="stylesheet" href="fonts/fonts.css" />

    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

    <script src="bower_components/modernizr/modernizr.js"></script>

  </head>

  <body>

  <?php $_REQUEST['currentPage'] = "http://www.domain.com/news"; ?>

  <?php include('inc/nav.php'); ?>

  <?php foreach ($page_headersRecords as $record): ?>

      <?php foreach ($record['image'] as $index => $upload): ?>

          <img src="<?php echo $upload['urlPath'] ?>" alt="<?php echo htmlencode($page_headersRecords['title']) ?>" />

      <?php endforeach ?>

  <?php endforeach ?>

  <div class="divide20">&nbsp;</div>

    <div class="row">

      <div class="small-12 columns text-right">

    <div class="paging">

      <?php if ($newsMetaData['prevPage']): ?>

        <a href="<?php echo $newsMetaData['prevPageLink'] ?>"><i class="fa fa-arrow-circle-left fa-2x"></i></a>

       <?php else: ?>

        <i class="greyed-out fa fa-arrow-circle-left fa-2x"></i>

      <?php endif ?>

          <?php if ($newsMetaData['nextPage']): ?>

            <a href="<?php echo $newsMetaData['nextPageLink'] ?>"><i class="fa fa-arrow-circle-right fa-2x"></i></a>

          <?php else: ?>

            <i class="greyed-out fa fa-arrow-circle-right fa-2x"></i>

          <?php endif ?>

          <br />

        </div>

      </div>

      <!-- /column -->

    </div>

    <!-- / row -->

    <div class="row">

      <div class="small-12 medium-10 large-10 medium-offset-1 columns end">

      <h2 class="ftitle2 fblue ftitle-u">News</h2>

        <?php foreach ($newsRecords as $record): ?>

        <div class="news-item">

          <div class="data ftitle2">

            <strong><?php echo date("M", strtotime($record['date'])) ?></strong>

            <span><?php echo date("d", strtotime($record['date'])) ?></span>

          </div>

          <div class="info">

            <h3 class="ftitle"><?php echo htmlencode($record['title']) ?></h3>

            <?php foreach ($record['image'] as $index => $upload): ?>

              <div class="news-pic">

              <img data-interchange="[<?php echo $upload['urlPath'] ?>, (small)], [<?php echo $upload['thumbUrlPath2'] ?>, (medium)], [<?php echo $upload['thumbUrlPath'] ?>, (large)]">

              <noscript><img src="<?php echo $upload['thumbUrlPath'] ?>"></noscript>

              </div>

            <?php endforeach ?>

            <div class="summary"><?php echo ($record['content']); ?></div>

          </div>

        </div>

        <div class="divide20">&nbsp;</div>

        <?php endforeach ?>

      </div>

      <!-- /column -->

    </div>

    <!-- / row -->

    <div class="row">

      <div class="small-12 medium-2 large-2 columns">

        &nbsp;

      </div>

      <!-- /column -->

      <div class="small-12 medium-8 large-8 columns text-right">

        <div class="paging">

          <?php if ($newsMetaData['prevPage']): ?>

            <a href="<?php echo $newsMetaData['prevPageLink'] ?>"><i class="fa fa-arrow-circle-left fa-2x"></i></a>

          <?php else: ?>

            <i class="greyed-out fa fa-arrow-circle-left fa-2x"></i>

          <?php endif ?>

          <?php if ($newsMetaData['nextPage']): ?>

            <a href="<?php echo $newsMetaData['nextPageLink'] ?>"><i class="fa fa-arrow-circle-right fa-2x"></i></a>

          <?php else: ?>

            <i class="greyed-out fa fa-arrow-circle-right fa-2x"></i>

          <?php endif ?>

          <br />

        </div>

      </div>

      <!-- /column -->

      <div class="small-12 medium-2 large-2 columns">

      </div>

      <!-- /column -->

    </div>

    <!-- / row -->

    <div class="divide60">&nbsp;</div>

  <?php include('inc/footer.php'); ?>

    <script src="bower_components/jquery/dist/jquery.min.js"></script>

    <script src="bower_components/foundation/js/foundation.min.js"></script>

    <script src="js/app.js"></script>


    <script>

      $(document).foundation();

    </script>



  </body>

</html>

