summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes6
-rw-r--r--demos/quickstart/protected/application.xml1
-rw-r--r--demos/quickstart/protected/comments/CommentList.php55
-rw-r--r--demos/quickstart/protected/comments/CommentList.tpl84
-rw-r--r--demos/quickstart/protected/comments/QuickStartComments.php175
-rw-r--r--demos/quickstart/protected/comments/comments.dbbin0 -> 6144 bytes
-rw-r--r--demos/quickstart/protected/controls/Layout.tpl1
-rw-r--r--demos/quickstart/protected/pages/Comments.page46
-rw-r--r--demos/quickstart/protected/pages/Comments.php76
-rw-r--r--demos/quickstart/themes/PradoSoft/style.css126
10 files changed, 570 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
index 89f9a3f5..d9e0f7f9 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -130,6 +130,10 @@ demos/quickstart/index.php -text
demos/quickstart/index2.php -text
demos/quickstart/protected/.htaccess -text
demos/quickstart/protected/application.xml -text
+demos/quickstart/protected/comments/CommentList.php -text
+demos/quickstart/protected/comments/CommentList.tpl -text
+demos/quickstart/protected/comments/QuickStartComments.php -text
+demos/quickstart/protected/comments/comments.db -text
demos/quickstart/protected/controls/DocLink.php -text
demos/quickstart/protected/controls/Layout.php -text
demos/quickstart/protected/controls/Layout.tpl -text
@@ -233,6 +237,8 @@ demos/quickstart/protected/pages/Advanced/mastercontent.gif -text
demos/quickstart/protected/pages/Advanced/mastercontent.vsd -text
demos/quickstart/protected/pages/Advanced/pcrelation.gif -text
demos/quickstart/protected/pages/Advanced/pcrelation.vsd -text
+demos/quickstart/protected/pages/Comments.page -text
+demos/quickstart/protected/pages/Comments.php -text
demos/quickstart/protected/pages/Configurations/AppConfig.page -text
demos/quickstart/protected/pages/Configurations/Overview.page -text
demos/quickstart/protected/pages/Configurations/PageConfig.page -text
diff --git a/demos/quickstart/protected/application.xml b/demos/quickstart/protected/application.xml
index fed0ec22..7ed4a749 100644
--- a/demos/quickstart/protected/application.xml
+++ b/demos/quickstart/protected/application.xml
@@ -19,6 +19,7 @@
</modules>
<paths>
<using namespace="Application.controls.*" />
+ <using namespace="Application.comments.*" />
</paths>
<services>
<service id="page" class="TPageService" DefaultPage="GettingStarted.Introduction" />
diff --git a/demos/quickstart/protected/comments/CommentList.php b/demos/quickstart/protected/comments/CommentList.php
new file mode 100644
index 00000000..7ea5be6b
--- /dev/null
+++ b/demos/quickstart/protected/comments/CommentList.php
@@ -0,0 +1,55 @@
+<?php
+
+Prado::using('System.I18N.*');
+
+/**
+ * CommentList class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version : $ Sat May 27 17:53:15 AZOST 2006 $
+ * @package Demo.Quickstart.comments
+ * @since 3.0
+ */
+class CommentList extends TTemplateControl
+{
+ private $_exclude = array('Comments', 'GettingStarted.Introduction');
+
+ private $_quickstart;
+
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+
+ $this->_quickstart = new QuickStartComments();
+
+ $page = $this->getService()->getRequestedPagePath();
+
+ $this->listComments($page);
+ }
+
+ protected function listComments($page)
+ {
+ $this->comments->setDataSource($this->_quickstart->getComments($page));
+ $this->comments->dataBind();
+ }
+
+ public function addComment_Clicked($sender, $param)
+ {
+ $page = $this->getService()->getRequestedPagePath();
+ $this->_quickstart->addNewComment($page,
+ $this->email->getText(), $this->content->getText());
+ $this->multiView1->setActiveViewIndex(1);
+ $this->listComments($page);
+ }
+
+ public function setVisible($value)
+ {
+ $page = $this->getService()->getRequestedPagePath();
+ if(in_array($page, $this->_exclude))
+ parent::setVisible(false);
+ else
+ parent::setVisible($value);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/quickstart/protected/comments/CommentList.tpl b/demos/quickstart/protected/comments/CommentList.tpl
new file mode 100644
index 00000000..7ea7b870
--- /dev/null
+++ b/demos/quickstart/protected/comments/CommentList.tpl
@@ -0,0 +1,84 @@
+<div id="comments">
+
+<com:TRepeater ID="comments">
+ <prop:HeaderTemplate>
+ <h2 class="comment_header">Comments</h2>
+ </prop:HeaderTemplate>
+ <prop:ItemTemplate>
+ <div class="comment_item comment_item<%# $this->ItemIndex%2 %>">
+ <span class="number" id="comment_<%# $this->ItemIndex+1 %>"><%# $this->ItemIndex+1 %></span>
+ <span class="email">
+ <%# str_replace(array('@','.'),array(' at ',' dot '), strtoupper($this->DataItem['email'])) %>
+ </span>
+ <span class="date">
+ <com:TDateFormat Value=<%# intval($this->DataItem['date_added']) %> />
+ </span>
+ <div class="comment">
+ <com:TSafeHtml>
+ <%# $this->DataItem['comment'] %>
+ </com:TSafeHtml>
+ </div>
+ </div>
+ </prop:ItemTemplate>
+</com:TRepeater>
+
+<com:TMultiView ID="multiView1" ActiveViewIndex="0">
+ <com:TView ID="view1">
+ <div class="add_comments">
+ <h3>Add your comment</h3>
+ <p>Add comments and notes that can solve or clarify a particular problem or task.
+ Please use the forum to ask questions. You may be HTML in your comment.</p>
+ <div class="comment_email">
+ <com:TLabel ID="email_label" Text="Email:" ForControl="email"/>
+ <com:TTextBox ID="email" />
+ <com:TRequiredFieldValidator
+ ControlToValidate="email"
+ Display="Dynamic"
+ ErrorMessage="An email address is required." />
+ <com:TEmailAddressValidator
+ ControlToValidate="email"
+ CheckMXRecord="false"
+ Display="Dynamic"
+ ErrorMessage="Please provide your email address."/>
+ </div>
+ <div class="comment_content">
+ <com:TLabel ID="content_label" Text="Comment:" ForControl="content"/>
+ <com:TTextBox ID="content" TextMode="MultiLine"/>
+ <div class="please_add">
+ <com:TRequiredFieldValidator
+ ControlToValidate="content"
+ Display="Dynamic"
+ ErrorMessage="Please add your comment." />
+ </div>
+ </div>
+ <com:TPlaceHolder Visible=<%= strlen($this->content->Text) %> >
+ <div class="comment_preview">
+ <h3 style="margin:0">Preview comment</h3>
+ <div class="comment">
+ <com:TSafeHtml>
+ <%= $this->content->Text %>
+ </com:TSafeHtml>
+ </div>
+ </div>
+ </com:TPlaceHolder>
+ <div class="add_comment">
+ <com:TButton ID="previewComment" Text="Preview Comment" />
+ <com:TButton ID="addComment" Text="Add Comment" OnClick="addComment_Clicked"/>
+ </div>
+ </div>
+ </com:TView>
+ <com:TView ID="view2">
+ <div class="comment_added">
+ <div class="thank">Thank you, your comment is quequed for moderation.</div>
+ <div class="comment_preview">
+ <h3 style="margin:0">Preview comment</h3>
+ <div class="comment">
+ <com:TSafeHtml>
+ <%= $this->content->Text %>
+ </com:TSafeHtml>
+ </div>
+ </div>
+ </div>
+ </com:TView>
+</com:TMultiView>
+</div> \ No newline at end of file
diff --git a/demos/quickstart/protected/comments/QuickStartComments.php b/demos/quickstart/protected/comments/QuickStartComments.php
new file mode 100644
index 00000000..c138bd94
--- /dev/null
+++ b/demos/quickstart/protected/comments/QuickStartComments.php
@@ -0,0 +1,175 @@
+<?php
+
+/**
+ * QuickStartComments class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version : $ Sat May 27 16:49:19 AZOST 2006 $
+ * @package Demos.QuickStart.comments
+ * @since 3.0
+ */
+class QuickStartComments
+{
+ /**
+ * @var string sqlite database source.
+ */
+ private $_database;
+ /**
+ * @var sqlite connection.
+ */
+ private $_connection;
+
+ /**
+ * Sets the sqlite comment database file.
+ */
+ public function __construct()
+ {
+ $this->_database = realpath(dirname(__FILE__).'/comments.db');
+ }
+
+ /**
+ * Closed the database connection.
+ */
+ public function __destruct()
+ {
+ if(!is_null($this->_connection))
+ sqlite_close($this->_connection);
+ }
+
+ /**
+ * @return resource sqlite database connection.
+ */
+ protected function getConnection()
+ {
+ if(is_null($this->_connection))
+ $this->_connection = sqlite_open($this->_database);
+ return $this->_connection;
+ }
+
+ /**
+ * Quote database input data.
+ */
+ protected function quote($value)
+ {
+ return sqlite_escape_string($value);
+ }
+
+ /**
+ * Executes an sqlite query.
+ * @param string SQL
+ * @return mixed query results.
+ */
+ protected function query($sql)
+ {
+ return sqlite_query($this->getConnection(), $sql);
+ }
+
+ /**
+ * Returns a row from the sqlite result.
+ * @param resource sqlite result
+ * @return array database record.
+ */
+ protected function fetch($resource)
+ {
+ if($resource !== false)
+ return sqlite_fetch_array($resource);
+ else
+ return false;
+ }
+
+ /**
+ * Fetch all the records for given SQL query.
+ * @param string SQL query.
+ * @return array result set.
+ */
+ protected function fetchAll($sql)
+ {
+ $rs = $this->query($sql);
+ $rows = array();
+ while($row = $this->fetch($rs))
+ $rows[] = $row;
+ return $rows;
+ }
+
+ /**
+ * Returns all the comments for a given page.
+ * @param string specific page comments
+ * @return array list of comments
+ */
+ public function getComments($pageID)
+ {
+ $page = $this->quote($pageID);
+ $sql = "SELECT * FROM comments WHERE page=\"$page\" AND approved = 1 ORDER BY date_added ASC";
+ return $this->fetchAll($sql);
+ }
+
+ /**
+ * Adds a new comment for moderation.
+ * @param string ID of the page to comment belongs
+ * @param string email address of the commenter
+ * @param string comment contents
+ */
+ public function addNewComment($pageID, $email, $comment)
+ {
+ $page = $this->quote($pageID);
+ $email = $this->quote($email);
+ $comment = $this->quote($comment);
+ $date_added = time();
+ $sql = <<<EOD
+ INSERT INTO comments(page, email, comment, date_added)
+ VALUES ("$page", "$email", "$comment", "$date_added")
+EOD;
+ return $this->query($sql);
+ }
+
+ /**
+ * Update an existing comment.
+ * @param string comment ID
+ * @param string page ID
+ * @param string email address
+ * @param string updated comment.
+ */
+ public function updateComment($commentID, $page, $email, $content)
+ {
+ $ID = intval($commentID);
+ $email = $this->quote($email);
+ $comment = $this->quote($content);
+ $page = $this->quote($page);
+ $sql = <<<EOD
+ UPDATE comments SET
+ email = "$email", comment = "$comment", page = "$page"
+ WHERE id = $ID;
+EOD;
+ $this->query($sql);
+ }
+
+ /**
+ * Delete a comment.
+ * @param string comment ID
+ */
+ public function deleteComment($commentID)
+ {
+ $ID = intval($commentID);
+ $this->query("DELETE FROM comments WHERE id=$ID");
+ }
+
+ /**
+ * @return array all the quequed comments.
+ */
+ public function getQuequedComments()
+ {
+ return $this->fetchAll("SELECT * FROM comments WHERE approved != 1");
+ }
+
+ /**
+ * Approve a quequed comment.
+ * @param string comment ID.
+ */
+ public function approveComment($commentID)
+ {
+ $ID = intval($commentID);
+ $this->query("UPDATE comments SET approved = 1 WHERE id=$ID");
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/quickstart/protected/comments/comments.db b/demos/quickstart/protected/comments/comments.db
new file mode 100644
index 00000000..b81d7123
--- /dev/null
+++ b/demos/quickstart/protected/comments/comments.db
Binary files differ
diff --git a/demos/quickstart/protected/controls/Layout.tpl b/demos/quickstart/protected/controls/Layout.tpl
index 6fbd1380..d4a6a7e5 100644
--- a/demos/quickstart/protected/controls/Layout.tpl
+++ b/demos/quickstart/protected/controls/Layout.tpl
@@ -32,6 +32,7 @@
<div id="content">
<com:TContentPlaceHolder ID="body" />
</div>
+<com:CommentList Visible="true" />
</td>
</tr>
</table>
diff --git a/demos/quickstart/protected/pages/Comments.page b/demos/quickstart/protected/pages/Comments.page
new file mode 100644
index 00000000..32c7bcae
--- /dev/null
+++ b/demos/quickstart/protected/pages/Comments.page
@@ -0,0 +1,46 @@
+<com:TContent ID="body">
+ <com:TDataList
+ ID="comments"
+ DataKeyField="id"
+ OnEditCommand="editComment"
+ OnCancelCommand="cancelEdit"
+ OnUpdateCommand="updateComment"
+ OnDeleteCommand="deleteComment"
+ OnSelectedIndexChanged="approveComment"
+ ItemStyle.BackColor="#BFCFFF"
+ AlternatingItemStyle.BackColor="#E6ECFF"
+ EditItemStyle.BackColor="lightgreen">
+
+ <prop:HeaderTemplate>
+ Comments awaiting approval
+ </prop:HeaderTemplate>
+
+ <prop:ItemTemplate>
+ <span class="page"><%# $this->DataItem['page'] %></span>
+ <span class="date">
+ <com:TDateFormat Value=<%# intval($this->DataItem['date_added']) %> />
+ </span>
+ <span class="email">
+ <%# $this->DataItem['email'] %>
+ </span>
+ <div class="comment">
+ <com:TSafeHtml>
+ <%# $this->DataItem['comment']%>
+ </com:TSafeHtml>
+ </div>
+ <com:TLinkButton Text="Edit" CommandName="edit" />
+ <com:TLinkButton Text="Delete" CommandName="delete"
+ Attributes.onclick="if(!confirm('Are you sure?')) return false;" />
+ <com:TLinkButton Text="Approve" CommandName="select" />
+ </prop:ItemTemplate>
+
+ <prop:EditItemTemplate>
+ <com:TTextBox ID="email" Text=<%# $this->DataItem['email'] %> />
+ <com:TTextBox ID="page" Text=<%# $this->DataItem['page'] %> />
+ <com:TTextBox ID="content" Text=<%# $this->DataItem['comment'] %> TextMode="MultiLine"/>
+ <com:TLinkButton Text="Save" CommandName="update" />
+ <com:TLinkButton Text="Cancel" CommandName="cancel" />
+ </prop:EditItemTemplate>
+
+ </com:TDataList>
+</com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Comments.php b/demos/quickstart/protected/pages/Comments.php
new file mode 100644
index 00000000..7af70ece
--- /dev/null
+++ b/demos/quickstart/protected/pages/Comments.php
@@ -0,0 +1,76 @@
+<?php
+
+Prado::using('System.I18N.*');
+
+/**
+ * Comments class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version : $ Sat May 27 20:23:00 AZOST 2006 $
+ * @package Demo.Quickstart
+ * @since 3.0
+ */
+class Comments extends TPage
+{
+ private $_quickstart;
+
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ $this->_quickstart = new QuickStartComments;
+ if(!$this->getIsPostBack())
+ $this->refreshData();
+ }
+
+ protected function refreshData()
+ {
+ $this->comments->setDataSource($this->_quickstart->getQuequedComments());
+ $this->comments->dataBind();
+ }
+
+ public function approveComment($sender, $param)
+ {
+ $ID = $this->comments->DataKeys[$this->comments->SelectedItemIndex];
+ $this->_quickstart->approveComment($ID);
+ $this->refreshData();
+ $this->comments->SelectedItemIndex=-1;
+ }
+
+ public function editComment($sender, $param)
+ {
+ $this->comments->SelectedItemIndex=-1;
+ $this->comments->EditItemIndex=$param->Item->ItemIndex;
+ $this->refreshData();
+ }
+
+ public function cancelEdit($sender, $param)
+ {
+ $this->comments->SelectedItemIndex=-1;
+ $this->comments->EditItemIndex=-1;
+ $this->refreshData();
+ }
+
+ public function deleteComment($sender, $param)
+ {
+ $ID = $this->comments->DataKeys[$param->Item->ItemIndex];
+ $this->_quickstart->deleteComment($ID);
+ $this->comments->SelectedItemIndex=-1;
+ $this->comments->EditItemIndex=-1;
+ $this->refreshData();
+ }
+
+ public function updateComment($sender, $param)
+ {
+ $item=$param->Item;
+ $this->_quickstart->updateComment(
+ $this->comments->DataKeys[$item->ItemIndex],
+ $item->page->Text,
+ $item->email->Text,
+ $item->content->Text);
+
+ $this->comments->EditItemIndex=-1;
+ $this->refreshData();
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/quickstart/themes/PradoSoft/style.css b/demos/quickstart/themes/PradoSoft/style.css
index 0fed7813..d0c3b0be 100644
--- a/demos/quickstart/themes/PradoSoft/style.css
+++ b/demos/quickstart/themes/PradoSoft/style.css
@@ -379,4 +379,130 @@ dd
{
text-align: center;
margin: 30px;
+}
+
+/** Comments **/
+#comments
+{
+ margin: 10px;
+}
+
+.comment_header
+{
+ border-bottom: 1px solid silver;
+}
+
+.comment_item
+{
+ padding: 10px;
+ border: 1px solid silver;
+ margin: 0 10px 10px 10px;
+}
+
+.comment_item .number
+{
+ float: right;
+ font-size: 1.5em;
+ font-weight: bold;
+ color: silver;
+}
+
+.comment_item1
+{
+ background-color: #EDEDED;
+}
+
+.comment_item .email
+{
+ font-weight: bold;
+ display: block;
+}
+
+.comment_item .date
+{
+ font-size: 0.85em;
+ display: block;
+ border-bottom: 1px dotted silver;
+}
+
+.comment_item .comment
+{
+ padding: 10px;
+}
+
+.add_comments
+{
+ margin-top: 2em;
+}
+
+.add_comments .comment_email
+{
+ margin-bottom: 5px;
+}
+
+.add_comments .comment_email input
+{
+ width: 25em;
+}
+
+.add_comments .comment_content textarea
+{
+ width: 75%;
+ height: 200px;
+ padding: 5px;
+}
+
+.add_comments .comment_email label, .add_comments .comment_content label
+{
+ width: 8em;
+ float: left;
+ text-align: right;
+ padding-right: 5px;
+}
+
+.add_comments .add_comment
+{
+ padding-left: 8.2em;
+ padding-top: 0.5em;
+}
+
+.add_comments .please_add
+{
+ padding-left: 8.2em;
+}
+
+.add_comments h3, .comment_added h3
+{
+ border-bottom: 1px solid silver;
+}
+
+.comment_preview
+{
+ margin: 10px;
+ padding: 10px;
+ border: 1px solid silver;
+}
+
+.comment_preview .comment
+{
+ padding: 10px;
+}
+
+.comment_added
+{
+ margin-top: 3em;
+ border-top: 1px dotted silver;
+ padding: 10px;
+}
+
+.comment_added .comment
+{
+ padding: 10px;
+ margin-top: 10px;
+}
+
+.comment_added .thank
+{
+ background-color: #ffffcc;
+ padding: 20px;
} \ No newline at end of file