ZapMachine/lib/ZAPDisplay.class.php

91 lines
No EOL
1.8 KiB
PHP
Executable file

<?php
/**
* Class is responsible for starting up ZAP machine
*/
class ZAPDisplay {
/**
* Template file
*/
private $template = 'display';
/**
* Folder string
*/
private $folder = '';
/**
* Words array
*/
private $words = array();
/**
* Content string
*/
private $tpl = '';
/**
* Constructor
*/
public function __construct() {
ob_start();
$this->folder = $this->createFolder();
$this->words = $this->handleWords();
$_SESSION['words'] = $this->words;
$_SESSION['folder'] = $this->folder;
$_SESSION['collages'] = (int) $_POST['collages']; //number of zaps
$_SESSION['width'] = (int) $_POST['width'];
$_SESSION['height'] = (int) $_POST['height'];
$_SESSION['date'] = ZAP_MOMENT;
$ver = ZAP_VERSION;
include getZAPTemplate($this->template);
$this->tpl .= ob_get_clean();
}
/**
* Create folder and return path
* @return string $folder path or throws exception
*/
private function createFolder() {
try {
$folder = ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR
. ZAP_SESSIONS_DIR . DIRECTORY_SEPARATOR . 'zap_' . ZAP_MOMENT;
if (!@mkdir($folder, 0777)) {
throw new Exception('<p>' . ERROR_PREFIX . 'Unable to create base dir: ' . $folder . '</p>');
}
return $folder;
} catch (Exception $e) {
$this->tpl .= $e->getMessage();
return;
}
}
/**
* Create an array based on post data
* @return array $words
*/
private function handleWords() {
$words = array();
$ix = 1;
$postix = sprintf("%02d", $ix);
$wd = 'word' . $postix;
while(!empty($_POST[$wd])) {
array_push($words, $_POST[$wd]);
$ix++;
$postfix = sprintf("%02d", $ix);
$wd = 'word' . $postfix;
}
return $words;
}
/**
* return rendered content
*/
public function getContent() {
return $this->tpl;
}
}
?>