From 77bc692bb7694aa635be1ca3752894e976477ebb Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 15 Aug 2008 13:32:35 +0000 Subject: Central: Moved over to Four Island Templating system Borrowed the Four Island templating system code so as to ease the creation of frontends. index.php and activate.php have already been converted, and install.php will not be converted (because it would be too difficult, and who would want to skin it anyway?) NOTICE: The Four Island Templating system source code is copyrighted by Starla Insigna (c) 2008. All rights reserved. Use of this code in part or in whole apart from the InstaDisc Central Server is a direct violation of copyright law. You have been warned. Refs #25 --- central/trunk/activate.php | 81 +++++++------------ central/trunk/index.php | 24 ++---- central/trunk/template.php | 160 ++++++++++++++++++++++++++++++++++++++ central/trunk/theme/activate.tpl | 62 +++++++++++++++ central/trunk/theme/activated.tpl | 14 ++++ central/trunk/theme/index.tpl | 19 +++++ 6 files changed, 288 insertions(+), 72 deletions(-) create mode 100644 central/trunk/template.php create mode 100644 central/trunk/theme/activate.tpl create mode 100644 central/trunk/theme/activated.tpl create mode 100644 central/trunk/theme/index.tpl (limited to 'central') diff --git a/central/trunk/activate.php b/central/trunk/activate.php index c8d4aa0..7b319b5 100644 --- a/central/trunk/activate.php +++ b/central/trunk/activate.php @@ -3,6 +3,7 @@ /* InstaDisc Server - A Four Island Project */ include('instadisc.php'); +include('template.php'); if (!isset($_GET['submit'])) { @@ -27,21 +28,9 @@ if (!isset($_GET['submit'])) { if (instaDisc_activateAccount($_POST['username'], $_POST['code'])) { -?> - - - <?php echo(instaDisc_getConfig('siteName')); ?> InstaDisc Central Server - - -
-

InstaDisc Activation

- -

Thank you for activating! You've now been signed up for the InstaDisc service. - You will recieve an email with the information to input into your InstaDisc client. -

- - -add('SITENAME', instaDisc_getConfig('siteName')); + $template->display(); } else { addError($numOfErrors, $errors, '', 'The email could not be sent'); showForm($_POST['username'], $_POST['code'], $errors); @@ -54,46 +43,30 @@ if (!isset($_GET['submit'])) function showForm($username, $code, $errors) { -?> - - - <?php echo(instaDisc_getConfig('siteName')); ?> InstaDisc Central Server - - - -
-

InstaDisc Activation

- -

If you've already registered and an activation email has been sent to your address, please fill in the form below. -

- -
-add('SITENAME', instaDisc_getConfig('siteName')); + if (isset($errors[1])) { -?>
Uh oh! Validation errors!

-

    adds('ERROR', array('ex'=>'1')); + foreach ($errors as $name => $value) { -?>
  1. adds('ERRORS', array( 'NAME' => $name, + 'MSG' => $value['msg'])); } -?>
-
User Details -
- - -
-
- - -
-
-
- - -
add('USERNAME_ERR', ifErrors($errors, 'username')); + $template->add('CODE_ERR', ifErrors($errors, 'code')); + + doErrors($template, $errors, 'username'); + doErrors($template, $errors, 'code'); + + $template->add('USERNAME', $username); + $template->add('CODE', $code); + + $template->display(); } function ifErrors($errors, $id) @@ -102,19 +75,21 @@ function ifErrors($errors, $id) { if ($value['field'] == $id) { - echo(' error'); - return; + return ' error'; } } + + return ''; } -function doErrors($errors, $id) +function doErrors($template, $errors, $id) { foreach ($errors as $name => $value) { if ($value['field'] == $id) { -?>

*

adds(strtoupper($id) . '_ERRS', array( 'NAME' => $name, + 'VALUE' => $value['msg'])); } } } diff --git a/central/trunk/index.php b/central/trunk/index.php index ce71def..1ef9c9d 100644 --- a/central/trunk/index.php +++ b/central/trunk/index.php @@ -3,24 +3,10 @@ /* InstaDisc Server - A Four Island Project */ include('instadisc.php'); +include('template.php'); -?> - - - Four Island InstaDisc Central Server - - -
-

InstaDisc

+$template = new FITemplate('index'); +$template->add('SITENAME', instaDisc_getConfig('siteName')); +$template->display(); -

Welcome to 's InstaDisc Central Server! -

InstaDisc is a wonderful productivity-increasing notification program. For more information about the project itself, see - its project site.

An InstaDisc "Central Server" is where you can - register for the InstaDisc service. There are many Central Servers around the world, you generally pick the one that is - closest to you. If you would like to choose 's, why not register now? -

Register -
Login -
Activation page -

- - +?> diff --git a/central/trunk/template.php b/central/trunk/template.php new file mode 100644 index 0000000..b4ec16b --- /dev/null +++ b/central/trunk/template.php @@ -0,0 +1,160 @@ +file = $tfn; + } else { + throw new Exception($tfn . ' does not exist'); + } + } + + function add($name, $value) + { + $this->tags[$name] = $value; + } + + function adds($tagarr) + { + foreach ($tagarr as $name => $value) + { + $this->add($name,$value); + } + } + + function adds_block($block, $tagarr) + { + if (!isset($this->blocks[$block])) + { + $this->blocks[$block] = array('count' => 1); + } + foreach ($tagarr as $name => $value) + { + $this->blocks[$block][$this->blocks[$block]['count']][$name] = $value; + } + $this->blocks[$block]['count']++; + } + + function add_ref($id, $block, $tagarr) + { + $this->adds_block($block,$tagarr); + $this->refs[$id] = &$this->blocks[$block][$this->blocks[$block]['count']-1];//'$this->blocks[\'' . $block . '\'][' . ($this->blocks[$block]['count']-1) . ']'; + } + + function adds_ref($id, $tagarr) + { + foreach ($tagarr as $name => $value) + { + $this->refs[$id][$name] = $value; + } + } + + function adds_ref_sub($id, $block, $tagarr) + { + if (!isset($this->refs[$id][$block])) + { + $this->refs[$id][$block] = array('count' => 1); + } + foreach ($tagarr as $name => $value) + { + $this->refs[$id][$block][$this->refs[$id][$block]['count']][$name] = $value; + } + $this->refs[$id][$block]['count']++; + } + + function display() + { + $template = file_get_contents($this->file); + while (preg_match('//',$template) == 1) + { + preg_match('//',$template,$mat); + $fname = $mat[1]; + $itmp = new FITemplate($fname); + $template = str_replace('',file_get_contents($itmp->file),$template); + } + if (isset($this->tags)) + { + foreach ($this->tags as $name => $value) + { + $template = str_replace('',$value,$template); + } + } + if (isset($this->blocks)) + { + foreach ($this->blocks as $bname => $block) + { + $this->parseBlock($template, $bname, $block); + } + } + while (preg_match('//',$template) == 1) + { + preg_match('//',$template,$mat); + $bname = $mat[1]; + $start = strpos($template,''); + $end = strpos($template,''); + $template = str_replace(substr($template,$start,$end-$start+strlen($bname)+11),'',$template); + } + $template = preg_replace('//','',$template); + echo($template); + } + + function parseBlock(&$template, $bname, $block) + { + while (strpos($template,'') !== FALSE) + { + $start = strpos($template,''); + $end = strpos($template,''); + $gencont = substr($template,$start+strlen($bname)+13,$end-$start-strlen($bname)-13); + $blockcont = ''; + foreach ($block as $lname => $blocktags) + { + if ($lname != 'count') + { + $scrcont = $gencont; + foreach ($blocktags as $name => $value) + { + if (!is_array($value)) + { + $scrcont = str_replace('',$value,$scrcont); + } else { + $this->parseBlock($scrcont, $bname . '.' . $name, $value); + } + } + $blockcont .= $scrcont; + } + } + $template = str_replace(substr($template,$start,$end-$start+strlen($bname)+11),$blockcont,$template); + } + } + +} + +?> diff --git a/central/trunk/theme/activate.tpl b/central/trunk/theme/activate.tpl new file mode 100644 index 0000000..caf8da6 --- /dev/null +++ b/central/trunk/theme/activate.tpl @@ -0,0 +1,62 @@ + + + <!--SITENAME--> InstaDisc Central Server + + + + +
+

InstaDisc Activation

+ +

If you've already registered and an activation email has been sent to your address, please fill in the form below. +

+ +
+ + +
Uh oh! Validation errors!

+

    + + + +
  1. + + + +
+
+ + +
+ User Details + +
+ +

* + +

+ + + + +
+ +
+ +

* + +

+ + + + +
+
+ +
+ + +
+
+ + diff --git a/central/trunk/theme/activated.tpl b/central/trunk/theme/activated.tpl new file mode 100644 index 0000000..43c716f --- /dev/null +++ b/central/trunk/theme/activated.tpl @@ -0,0 +1,14 @@ + + + <!--SITENAME--> InstaDisc Central Server + + +
+

InstaDisc Activation

+ +

Thank you for activating! You've now been signed up for the InstaDisc service. + You will recieve an email with the information to input into your InstaDisc client. +

+ + + diff --git a/central/trunk/theme/index.tpl b/central/trunk/theme/index.tpl new file mode 100644 index 0000000..789928b --- /dev/null +++ b/central/trunk/theme/index.tpl @@ -0,0 +1,19 @@ + + + <!--SITENAME--> InstaDisc Central Server + + +
+

InstaDisc

+ +

Welcome to 's InstaDisc Central Server! +

InstaDisc is a wonderful productivity-increasing notification program. For more information about the project itself, see + its project site.

An InstaDisc "Central Server" is where you can + register for the InstaDisc service. There are many Central Servers around the world, you generally pick the one that is + closest to you. If you would like to choose 's, why not register now? +

Register +
Login +
Activation page +

+ + -- cgit 1.4.1