source view: Page.php


<?php



require_once sprintf( '%s/Admin.php', __DIR__ );
require_once sprintf( '%s/Navigation.php', __DIR__ );
require_once sprintf( '%s/User.php', __DIR__ );



class Page
{
  private $footers = array();
  private $headers = array();

  private $nav_parent = null;
  private $overrides  = array(
    color      => false,
    font_color => false,
    title      => false
  );



  public function __construct ()
  {
    $this->nav_parent = Navigation::getDefaultItem();
  }



  public function addFooter ( $footer )
  {
    array_push( $this->footers, $footer );
  }



  public function addHeader ( $header )
  {
    array_push( $this->headers, $header );
  }



  public function getColor ()
  {
    return $this->overrides['color'] ? $this->overrides['color'] : $this->nav_parent->getColor();
  }



  public function getFontColor ()
  {
    return $this->overrides['font_color'] ? $this->overrides['font_color'] : $this->nav_parent->getFontColor();
  }



  public function getTitle ()
  {
    return $this->overrides['title'] ? $this->overrides['title'] : $this->nav_parent->getName();
  }



  public function hasTitle ()
  {
    return $this->overrides['title'] ? true : false;
  }



  public function printPage ()
  {
    $this->printPageHeader();
    $this->printPageContent();
    $this->printPageFooter();
  }



  public function printPageContent ()
  {
    print $this->content;
  }







  public function printPageFooter ()
  {  
?>
        <!-- footer -->
        <div id="footer_div">
<?php
    for ( $i = 0; $i < Navigation::getItemCount(); ++$i )
    {
      $item = Navigation::getItem( $i );
?><div style="border-color:<?php print $item->getColor()->toHex(); ?>;"><a href="/<?php print $item->getURL();?>" target="_top"><?php print $item->getName();?></a></div><?php
    }
?>
          <br />
          <br />
          <span class="copyright">
            &copy; <?php print strtolower( Page::romanDate() ); ?> kyle woodward | 
            <a href="/source-view.php?page=<?php print $_SERVER['PHP_SELF']; ?>" target="new">source</a>
<?php

    if ( Admin::isLoggedIn() )
    {
?>
 | <a href="/blog-login.php?action=logout">logout</a>
<?php
    }

    if ( User::getUserFromSession() )
    {
?>
  | <a href="/user/logout">logout</a>
<?php
    }

?>
          </span>
          <a href="http://profiles.google.com/108677732441037950707" rel="author" style="display:none;">Kyle Woodward</a>
        </div>
      </div>
    </div>
<?php
    if ( !Admin::isLoggedIn() )
    {
      Page::printTracking();
    }
?>
    <script type="text/javascript">
      installBanner( <?php print preg_replace( '/[^0-9\,]+/i', '', $this->getColor()->toRGB() ); ?> );
    </script>
<?php

    // really, we could just use `join` here
    for ( $i = 0; $i < count( $this->footers ); ++$i )
    {
      print $this->footers[$i];
    }

?>
  </body>
</html>
<?php
  }







  public function printPageHeader ()
  {
    require_once sprintf( '%s/../headers.php', __DIR__ );
?>
<!doctype html>
<html>
  <head>
    <link href="/blog.css"  rel="stylesheet" type="text/css" />
    <link href="/style.css" rel="stylesheet" type="text/css" />
    <link rel="apple-touch-icon" sizes="57x57" href="/favicons/apple-touch-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/favicons/apple-touch-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/favicons/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/favicons/apple-touch-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/favicons/apple-touch-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/favicons/apple-touch-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/favicons/apple-touch-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/favicons/apple-touch-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicons/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/favicons/android-chrome-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicons/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicons/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/favicons/manifest.json">
    <link rel="shortcut icon" href="/favicons/favicon.ico">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="msapplication-TileImage" content="/favicons/mstile-144x144.png">
    <meta name="msapplication-config" content="/favicons/browserconfig.xml">
    <meta name="theme-color" content="#ffffff">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta http-equiv="last-modified" content="<?php print date( 'r', filemtime( $_SERVER['SCRIPT_FILENAME'] ) ); ?>" />
    <meta name="viewport" content="width=device-width, user-scalable=no" />
    <script src="/v2/logo/jslogo.js" type="text/javascript"></script>
    <script src="/js/banner.js" type="text/javascript"></script>
    <title>kyle woodward :: <?php print $this->getTitle(); ?></title>
    <style type="text/css">
      div#linkbar-upper a
      {
        color: <?php print $this->getFontColor()->toHex(); ?>;
      }
    </style>
<?php

    for ( $i = 0; $i < count( $this->headers ); ++$i )
    {
      print $this->headers[$i];
    }

?>
  </head>
  <body>
    <!-- main page content -->
    <div id="content_div">
      <!-- page header -->
      <div id="header_div" style="background-color:<?php print $this->getColor()->toHex(); ?>;color:<?php print $this->getFontColor()->toHex(); ?>;">
        <canvas id="logologo" style="height:50px;width:600px;position:relative;" height="50" width="600"></canvas>
<div id="linkbar-upper" style="background-color:<?php print $this->getColor()->toHex(); ?>;"><?php

  $has_printed = false;
  for ( $i = 0; $i < Navigation::getItemCount(); ++$i )
  {
    $nav_item   = Navigation::getItem( $i );
    $class_name = $this->hasTitle() ? 'standard' : ( $this->getTitle() == $nav_item->getName() ? 'active' : 'standard' );

    printf( '<div class="%s"><a href="/%s" target="_top" data:bgcolor="%s">%s</a></div>', $class_name, $nav_item->getURL(), $nav_item->getColor()->toHex(), $nav_item->getName() );
  }

  if ( $this->hasTitle() )
  {
    printf( '<div class="active"><a href="%s" target="_top" data:bgcolor="%s">%s</a></div>', $_SERVER['PHP_SELF'], $this->getColor()->toHex(), $this->getTitle() );
  }

?>
<div id="spacer"></div></div></div><div id="content_actual">
<?php
  }





  public static function printTracking ()
  {
?>
    <script type="text/javascript">
      //<!--[CDATA[
        var gaJsHost = (('https:' == document.location.protocol) ? 'https://ssl.' : 'http://www.');
        document.write(unescape('%3Cscript src="' + gaJsHost + 'google-analytics.com/ga.js" type="text/javascript"%3E%3C/script%3E'));
      //]]-->
    </script>
    <script type="text/javascript">
      //<!--[CDATA[
        var pageTracker = _gat._getTracker('UA-1519445-4');
        pageTracker._initData();
        pageTracker._trackPageview();
      //]]-->
    </script>
<?php
  }



  public static function romanDate ()
  {
    $y = date( 'Y' );

    $R = array(  'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' );
    $N = array( 1000,  900, 500,  400, 100,   90,  50,   40,  10,    9,   5,    4,   1 );

    $i = 0;
    $r = '';
    while ( $y > 0 )
    {
      if ( $y >= $N[$i] )
      {
        $r .= $R[$i];
        $y -= $N[$i];
      }
      else
      {
        $i += 1;
      }
    }

    return $r;
  }



  public function setContent ( $content )
  {
    $this->content = $content;
  }



  public function setParentURL ( $parent_url )
  {
    $this->nav_parent = Navigation::getItemByURL( $parent_url );
    if ( !$this->nav_parent )
    {
      throw new Exception( sprintf( 'Parent URL (%s) is invalid.', $parent_url ) );
    }
  }



  public function setColor ( $color = false )
  {
    $this->overrides['color'] = $color ? $color : false;
  }



  public function setFontColor ( $font_color = false )
  {
    $this->overrides['font_color'] = $font_color ? $font_color : false;
  }



  public function setTitle ( $title = false )
  {
    $this->overrides['title'] = $title ? $title : false;
  }
}





?>