/home/coolpkct/www/websites/cake3.cool.rocks/admin/classes/viewer.php
<?php
/**
 * Part of Showkase web site management package
 *
 * @package Showkase
 * @author Jack Hardie {@link http://www.jhardie.com}
 * @copyright Copyright (c) 2014, SimpleViewer Inc.
 */
defined('SK_ACCESS')||die('<h1>403: Forbidden</h1>');
require_once 'classes'.DIRECTORY_SEPARATOR.'layer.php';
 
/**
 * About page
 *
 * @package Showkase
 */
class Viewer extends Layer
{
  /**
   * @var string page type
  */
  protected $pageType = 'viewer';
  
  /**
   * @var boolean
   */
  protected $supportedPageType = true;
  
  /**
   * @var object instance of Theme
   */
  protected $theme;
  
  /**
  * Constructor
  * Overrides Page constructor
  */
  public function __construct(Theme $theme, $viewerName)
  {
    $this->pageRef = $viewerName;
    $this->theme = $theme;
    $config = skConfig::getInstance();
    $this->themeSet = $this->theme->getThemeSet();
    $themeName = $this->themeSet->getCurrentThemeName();
    $this->pagePathRelSvm  =
        $config->getRelativeContentPath(getcwd()).
        $config->getThemeDataPathRelContent().DIRECTORY_SEPARATOR.
        $themeName.DIRECTORY_SEPARATOR;
    //$iniPath = $this->themeSet->getViewerIniPath($this->pageRef);
    $settingsDirectory = rtrim($this->pagePathRelSvm, '\\/');
    $this->settingsPath = $this->pagePathRelSvm.$viewerName.'.xml';
    if (!file_exists($settingsDirectory)) {
        if (!Filer::skMkdir($settingsDirectory, NEW_DIR_MODE, true)) {
            throw new Exception('Cannot create theme data folder, changes will not be saved.');
        }
    }
    $iniFields = $this->readFieldInis($this->themeSet->getViewerIniPaths($this->pageRef));
    foreach ($iniFields as $name => $field) {
        $this->layerDefaults[$name] = $field->getValue();
    }
    $this->incomingFields = $this->theme->getAccumulatedFields();
    $this->layerFields = $this->mergeFields($iniFields, $this->incomingFields);
    $layerSettings = PageReader::readPageVars($this->settingsPath); 
    $this->loadFields($this->layerFields, $layerSettings);
    $this->accumulatedFields = $this->layerFields + $this->incomingFields;
  }
  
  /**
   * Is this page type a gallery
   *
   * @return boolean
   */
   public function isGallery()
   {
     return false;
   }
   
   /**
     * Get page type
     *
     * @return string
     */
    public function getPageType()
    {
        return 'viewer';
    }
    
    /**
     * get Theme
     *
     * @return object
     */
    public function getTheme()
    {
        return $this->theme;
    }
}