diff --git a/Savant_Plugins.php b/Savant_Plugins.php index ac621a0dc53d331e1137fca894cdc694a260a751..07e9a5f3dd3598d389b482cdd1ebc7c67e4e482d 100644 --- a/Savant_Plugins.php +++ b/Savant_Plugins.php @@ -20,16 +20,26 @@ class Savant3_Plugin_displayRegion extends Savant3_Plugin $this->Savant->assign($object); if (in_array('ArrayAccess', class_implements($object))) { foreach ($object->toArray() as $key=>$var) { - $this->$key = $var; + $this->Savant->$key = $var; } } + if ($object instanceof Exception) { + $this->Savant->code = $object->getCode(); + $this->Savant->line = $object->getLine(); + $this->Savant->file = $object->getFile(); + $this->Savant->message = $object->getMessage(); + $this->Savant->trace = $object->getTrace(); + } $this->Savant->display($this->determineTemplate(get_class($object))); } function determineTemplate($class_name) { - $class_name = str_replace('UNL_WDN_', '', $class_name); - $class_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name); + if (strpos($class_name, 'Exception') !== false) { + return 'templates/Exception.tpl.php'; + } + $class_name = str_replace(array('UNL_WDN_', '_'), + array('', DIRECTORY_SEPARATOR), $class_name); $templatefile = 'templates/'.$class_name . '.tpl.php'; return $templatefile; } @@ -55,9 +65,16 @@ class Savant3_Plugin_fetchRegion extends Savant3_Plugin_displayRegion $this->Savant->assign($object); if (in_array('ArrayAccess', class_implements($object))) { foreach ($object->toArray() as $key=>$var) { - $this->$key = $var; + $this->Savant->$key = $var; } } + if ($object instanceof Exception) { + $this->Savant->code = $object->getCode(); + $this->Savant->line = $object->getLine(); + $this->Savant->file = $object->getFile(); + $this->Savant->message = $object->getMessage(); + $this->Savant->trace = $object->getTrace(); + } return $this->Savant->fetch($this->determineTemplate(get_class($object))); } } diff --git a/UNL/WDN/Comment.php b/UNL/WDN/Comment.php index 9a016c651330ac3045e7cfc9758a759db7336b58..83d20b0486679646c8e8ef51f1e0e60e1c688949 100644 --- a/UNL/WDN/Comment.php +++ b/UNL/WDN/Comment.php @@ -4,7 +4,16 @@ */ class UNL_WDN_Comment extends Doctrine_Record { - function __construct() + + public static function addComment($data) + { + $comment = new self(); + $comment->fromArray($data); + $comment->save(); + return $comment; + } + + function preSave() { if (isset($_SERVER['HTTP_REFERER'])) { // Set defaults @@ -12,19 +21,16 @@ class UNL_WDN_Comment extends Doctrine_Record $this->page_address = $_SERVER['HTTP_REFERER']; $this->ip = $_SERVER['REMOTE_ADDR']; $this->user_agent = $_SERVER['HTTP_USER_AGENT']; - } else { - //throw new Exception('No referrer is not allowed.'); } } - public static function addComment($data) - { - - } - public function setTableDefinition() { - $this->hasColumn('id', 'int', 11, array('primary' => true)); + $this->setTableName('comment'); + $this->hasColumn('id', 'integer', 11, array('unsigned' => 0, + 'primary' => true, + 'notnull' => true, + 'autoincrement' => true)); $this->hasColumn('name', 'string'); $this->hasColumn('email', 'int'); $this->hasColumn('page_address', 'int'); @@ -51,8 +57,7 @@ class UNL_WDN_Comment extends Doctrine_Record $this->submitdatetime = date('Y-m-d H:i:s'); if ($this->referrer_address != 'http://www1.unl.edu/comments/' && $this->referrer_address != 'http://www.unl.edu/unlpub/comments.shtml') { - $r = parent::insert(); - if ($r && !empty($this->page_address)) { + if (!empty($this->page_address)) { //send email to developer. $devs = @file_get_contents('http://www1.unl.edu/wdn/registry/?output=true&u='.urlencode($this->page_address)); if ($devs) { @@ -69,7 +74,6 @@ class UNL_WDN_Comment extends Doctrine_Record $this->sendToDevelopers('brett.bieber@gmail.com'); } } - return $r; } else { return false; } diff --git a/UNL/WDN/Comment/ThankYou.php b/UNL/WDN/Comment/ThankYou.php new file mode 100644 index 0000000000000000000000000000000000000000..6d38f634cb862a357c1fb54bc0b3fa39ca0912f4 --- /dev/null +++ b/UNL/WDN/Comment/ThankYou.php @@ -0,0 +1,8 @@ +<?php + +class UNL_WDN_Comment_ThankYou +{ + +} + +?> \ No newline at end of file diff --git a/UNL/WDN/CommentSystem.php b/UNL/WDN/CommentSystem.php index 367035c7e4cc336f83c97d985ed15e72d6fbb760..1628b936302d60bfaeb487470be865d467815b95 100644 --- a/UNL/WDN/CommentSystem.php +++ b/UNL/WDN/CommentSystem.php @@ -16,13 +16,16 @@ class UNL_WDN_CommentSystem $this->handlePost(); } else { switch ($this->options['view']) { + case 'thanks': + $this->output = new UNL_WDN_Comment_ThankYou(); + break; default: $this->output = new UNL_WDN_Comment_Form(new UNL_WDN_Comment()); break; } } } catch (Exception $e) { - $this->output = $e; + throw $e; } } @@ -38,7 +41,7 @@ class UNL_WDN_CommentSystem function handlePost() { $comment = UNL_WDN_Comment::addComment($_POST); - $this->redirect('/'); + $this->redirect('thanks/'); } function redirect($url) diff --git a/sample.htaccess b/sample.htaccess new file mode 100644 index 0000000000000000000000000000000000000000..485e81c6cd22c6db13dfa9352b1fe2db0d21fa0a --- /dev/null +++ b/sample.htaccess @@ -0,0 +1,6 @@ +RewriteEngine On + +RewriteBase /workspace/UNL_WDN_Comments/ + +# thank you rewrite +RewriteRule ^thanks/$ ?view=thanks [L] \ No newline at end of file diff --git a/templates/Comment/ThankYou.tpl.php b/templates/Comment/ThankYou.tpl.php new file mode 100644 index 0000000000000000000000000000000000000000..f20da1d28e994aa18a57780449cad51c1bb93ff6 --- /dev/null +++ b/templates/Comment/ThankYou.tpl.php @@ -0,0 +1 @@ +<h1>Thanks!</h1> \ No newline at end of file diff --git a/templates/Exception.tpl.php b/templates/Exception.tpl.php new file mode 100644 index 0000000000000000000000000000000000000000..33cc2895b9fd41eab320ac85c50aaf3ead23fd75 --- /dev/null +++ b/templates/Exception.tpl.php @@ -0,0 +1,11 @@ +<h1>Exception!</h1> +Sorry, an error occurred within the system. +<?php +echo 'Error number '.$this->code; +echo $this->message; +echo '<pre>'; +//print_r($this->trace); +if (isset($this->source)) { + $this->displayRegion($this->source); +} +?> \ No newline at end of file