Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/libraries/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ public function getParentType() {
}

public function getUser() {
if (is_null($this->user_id)) return null;
return new User($this->user_id);
return User::findUserById($this->user_id);
}

public function getUserId() {
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ public function getURI() {
}

public function getUser() {
if (is_null($this->user_id)) return null;
return new User($this->user_id);
return User::findUserById($this->user_id);
}

public function getUserId() {
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/NewsPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ public function getURI() {
}

public function getUser() {
if (is_null($this->user_id)) return null;
return new User($this->user_id);
return User::findUserById($this->user_id);
}

public function getUserId() {
Expand Down
6 changes: 1 addition & 5 deletions src/libraries/Packet.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,7 @@ public function getUsedBy() {
}

public function getUser() {
if ( is_null( $this->user_id )) {
return null;
}

return new User( $this->user_id );
return User::findUserById($this->user_id);
}

public function getUserId() {
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ public function getUpdatedDateTime() {
}

public function getUser() {
if (is_null($this->user_id)) return null;
return new User($this->user_id);
return User::findUserById($this->user_id);
}

public function getUserId() {
Expand Down
10 changes: 10 additions & 0 deletions src/libraries/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ public function getAcl($acl) {
return ($this->options_bitmask & $acl);
}

public static function findUserById($user_id) {
if (is_null($user_id)) return null;

try {
return new User($user_id);
} catch (UserNotFoundException $e) {
return null;
}
}

public static function &getAllUsers(
$order = null, $limit = null, $index = null
) {
Expand Down
45 changes: 45 additions & 0 deletions src/templates/Comment/Section.inc.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace BNETDocs\Templates\Comment;

use \BNETDocs\Libraries\Comment;
use \BNETDocs\Libraries\User;

use \CarlBennett\MVC\Libraries\Common;


?>
<header><a name="comments">Comments</a></header>
<section>
<?php if (!$comments) { ?>
<p class="center"><em>no one has commented yet.</em></p>
<?php } else {
$c_edit_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_MODIFY));
$c_delete_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_DELETE));
?>
<table class="comments"><tbody>
<?php foreach ($comments as $c) {
$c_id = $c->getId();
$c_user = $c->getUser();
$c_user_id = $c->getUserId();

$c_edit_visible = ($c_user_id == $logged_in_id || $c_edit_visible_master);
$c_delete_visible = ($c_user_id == $logged_in_id || $c_delete_visible_master);
?>
<tr><td><?php if ($c_user) { ?><a href="<?php echo $c_user->getURI(); ?>"><img class="avatar" src="<?php echo $c_user->getAvatarURI(22); ?>"/> <?php echo filter_var($c_user->getName(), FILTER_SANITIZE_STRING); ?></a><?php } else { ?>Anonymous<?php } ?><br/><time class="comment_timestamp" datetime="<?php echo $c->getCreatedDateTime()->format("c"); ?>"><?php echo $c->getCreatedDateTime()->format("D M j, Y g:ia T"); ?></time><?php if ($c_delete_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/delete?id=" . urlencode($c_id)); ?>">Delete</a><?php } if ($c_edit_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/edit?id=" . urlencode($c_id)); ?>">Edit</a><?php } ?></td><td><?php echo $c->getContent(true); ?></td></tr>
<?php } ?>
</tbody></table>
<?php } ?>
</section>
<?php if ($logged_in) { ?>
<section>
<hr/>
<form method="POST" action="<?php echo Common::relativeUrlToAbsolute("/comment/create"); ?>">
<input type="hidden" name="parent_type" value="<?php echo $comment_parent_type; ?>"/>
<input type="hidden" name="parent_id" value="<?php echo $object_id; ?>"/>
<p class="center"><label for="comment-content">Comment on this post:</label></p>
<p class="center"><textarea id="comment-content" name="content" cols="80" rows="5"></textarea></p>
<p class="center"><input type="submit" value="Comment"/></p>
</form>
</section>
<?php } ?>
56 changes: 11 additions & 45 deletions src/templates/Document/View.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ if ($object) {
$object->getContent(true), FILTER_SANITIZE_STRING
)), "\n", 300);

$user_name = $object->getUser()->getName();
$user_id = $object->getUserId();
$user_url = $object->getUser()->getURI();
$user_avatar = $object->getUser()->getAvatarURI(22);
$user = $object->getUser();

}

Expand Down Expand Up @@ -73,52 +70,21 @@ require("./header.inc.phtml");
<?php } else { ?>
<span class="float-right"><time datetime="<?php echo $object->getCreatedDateTime()->format('c'); ?>"><?php echo $object->getCreatedDateTime()->format("l, F j, Y"); ?></time></span>
<?php } ?>
<?php if ($user_id !== null) { ?>
<span><a href="<?php echo $user_url; ?>"><img class="avatar" src="<?php echo $user_avatar; ?>"/> <?php echo filter_var($user_name, FILTER_SANITIZE_STRING); ?></a></span>
<?php if ($user !== null) { ?>
<span><a href="<?php echo $user->getURI(); ?>"><img class="avatar" src="<?php echo $user->getAvatarURI(22); ?>"/> <?php echo filter_var($user->getName(), FILTER_SANITIZE_STRING); ?></a></span>
<?php } ?>
</footer>
</article>
<article>
<header><a name="comments">Comments</a></header>
<section>
<?php if (!$comments) { ?>
<p class="center"><em>no one has commented yet.</em></p>
<?php } else {
$c_edit_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_MODIFY));
$c_delete_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_DELETE));
?>
<table class="comments"><tbody>
<?php foreach ($comments as $c) {
$c_id = $c->getId();
$c_user = $c->getUser();
$c_user_name = $c_user->getName();
$c_user_id = $c->getUserId();
$c_user_url = $c_user->getURI();
$c_user_avatar = $c_user->getAvatarURI(22);

$c_edit_visible = ($c_user_id == $logged_in_id || $c_edit_visible_master);
$c_delete_visible = ($c_user_id == $logged_in_id || $c_delete_visible_master);
?>
<tr><td><a href="<?php echo $c_user_url; ?>"><img class="avatar" src="<?php echo $c_user_avatar; ?>"/> <?php echo filter_var($c_user_name, FILTER_SANITIZE_STRING); ?></a><br/><time class="comment_timestamp" datetime="<?php echo $c->getCreatedDateTime()->format("c"); ?>"><?php echo $c->getCreatedDateTime()->format("D M j, Y g:ia T"); ?></time><?php if ($c_delete_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/delete?id=" . urlencode($c_id)); ?>">Delete</a><?php } if ($c_edit_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/edit?id=" . urlencode($c_id)); ?>">Edit</a><?php } ?></td><td><?php echo $c->getContent(true); ?></td></tr>
<?php } ?>
</tbody></table>
<?php } ?>
</section>
<?php if ($logged_in) { ?>
<section>
<hr/>
<form method="POST" action="<?php echo Common::relativeUrlToAbsolute("/comment/create"); ?>">
<input type="hidden" name="parent_type" value="<?php echo Comment::PARENT_TYPE_DOCUMENT; ?>"/>
<input type="hidden" name="parent_id" value="<?php echo $object_id; ?>"/>
<p class="center"><label for="comment-content">Comment on this post:</label></p>
<p class="center"><textarea id="comment-content" name="content" cols="80" rows="5"></textarea></p>
<p class="center"><input type="submit" value="Comment"/></p>
</form>
</section>
<?php } ?>
<?php } else { ?>
<?php

$comment_parent_type = Comment::PARENT_TYPE_DOCUMENT;
require("./Comment/Section.inc.phtml");

} else { ?>
<header class="red"><?php echo filter_var($title, FILTER_SANITIZE_STRING); ?></header>
<section class="red"><?php echo filter_var($description, FILTER_SANITIZE_STRING); ?></section>
<?php } ?>
</article>
<?php require("./footer.inc.phtml"); ?>

require("./footer.inc.phtml"); ?>
44 changes: 6 additions & 38 deletions src/templates/News/View.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -86,44 +86,12 @@ require("./header.inc.phtml");
</footer>
</article>
<article>
<header><a name="comments">Comments</a></header>
<section>
<?php if (!$comments) { ?>
<p class="center"><em>no one has commented yet.</em></p>
<?php } else {
$c_edit_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_MODIFY));
$c_delete_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_DELETE));
?>
<table class="comments"><tbody>
<?php foreach ($comments as $c) {
$c_id = $c->getId();
$c_user = $c->getUser();
$c_user_name = $c_user->getName();
$c_user_id = $c->getUserId();
$c_user_url = $c_user->getURI();
$c_user_avatar = $c_user->getAvatarURI(22);

$c_edit_visible = ($c_user_id == $logged_in_id || $c_edit_visible_master);
$c_delete_visible = ($c_user_id == $logged_in_id || $c_delete_visible_master);
?>
<tr><td><a href="<?php echo $c_user_url; ?>"><img class="avatar" src="<?php echo $c_user_avatar; ?>"/> <?php echo filter_var($c_user_name, FILTER_SANITIZE_STRING); ?></a><br/><time class="comment_timestamp" datetime="<?php echo $c->getCreatedDateTime()->format("c"); ?>"><?php echo $c->getCreatedDateTime()->format("D M j, Y g:ia T"); ?></time><?php if ($c_delete_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/delete?id=" . urlencode($c_id)); ?>">Delete</a><?php } if ($c_edit_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/edit?id=" . urlencode($c_id)); ?>">Edit</a><?php } ?></td><td><?php echo $c->getContent(true); ?></td></tr>
<?php } ?>
</tbody></table>
<?php } ?>
</section>
<?php if ($logged_in) { ?>
<section>
<hr/>
<form method="POST" action="<?php echo Common::relativeUrlToAbsolute("/comment/create"); ?>">
<input type="hidden" name="parent_type" value="<?php echo Comment::PARENT_TYPE_NEWS_POST; ?>"/>
<input type="hidden" name="parent_id" value="<?php echo $object_id; ?>"/>
<p class="center"><label for="comment-content">Comment on this post:</label></p>
<p class="center"><textarea id="comment-content" name="content" cols="80" rows="5"></textarea></p>
<p class="center"><input type="submit" value="Comment"/></p>
</form>
</section>
<?php } ?>
<?php } else { ?>
<?php

$comment_parent_type = Comment::PARENT_TYPE_NEWS_POST;
require("./Comment/Section.inc.phtml");

} else { ?>
<header class="red"><?php echo filter_var($title, FILTER_SANITIZE_STRING); ?></header>
<section class="red"><?php echo filter_var($description, FILTER_SANITIZE_STRING); ?></section>
<?php } ?>
Expand Down
44 changes: 6 additions & 38 deletions src/templates/Packet/View.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -120,44 +120,12 @@ require("./header.inc.phtml");
</footer>
</article>
<article>
<header><a name="comments">Comments</a></header>
<section>
<?php if (!$comments) { ?>
<p class="center"><em>no one has commented yet.</em></p>
<?php } else {
$c_edit_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_MODIFY));
$c_delete_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_DELETE));
?>
<table class="comments"><tbody>
<?php foreach ($comments as $c) {
$c_id = $c->getId();
$c_user = $c->getUser();
$c_user_name = $c_user->getName();
$c_user_id = $c->getUserId();
$c_user_url = $c_user->getURI();
$c_user_avatar = $c_user->getAvatarURI(22);

$c_edit_visible = ($c_user_id == $logged_in_id || $c_edit_visible_master);
$c_delete_visible = ($c_user_id == $logged_in_id || $c_delete_visible_master);
?>
<tr><td><a href="<?php echo $c_user_url; ?>"><img class="avatar" src="<?php echo $c_user_avatar; ?>"/> <?php echo filter_var($c_user_name, FILTER_SANITIZE_STRING); ?></a><br/><time class="comment_timestamp" datetime="<?php echo $c->getCreatedDateTime()->format("c"); ?>"><?php echo $c->getCreatedDateTime()->format("D M j, Y g:ia T"); ?></time><?php if ($c_delete_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/delete?id=" . urlencode($c_id)); ?>">Delete</a><?php } if ($c_edit_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/edit?id=" . urlencode($c_id)); ?>">Edit</a><?php } ?></td><td><?php echo $c->getContent(true); ?></td></tr>
<?php } ?>
</tbody></table>
<?php } ?>
</section>
<?php if ($logged_in) { ?>
<section>
<hr/>
<form method="POST" action="<?php echo Common::relativeUrlToAbsolute("/comment/create"); ?>">
<input type="hidden" name="parent_type" value="<?php echo Comment::PARENT_TYPE_PACKET; ?>"/>
<input type="hidden" name="parent_id" value="<?php echo $object_id; ?>"/>
<p class="center"><label for="comment-content">Comment on this post:</label></p>
<p class="center"><textarea id="comment-content" name="content" cols="80" rows="5"></textarea></p>
<p class="center"><input type="submit" value="Comment"/></p>
</form>
</section>
<?php } ?>
<?php } else { ?>
<?php

$comment_parent_type = Comment::PARENT_TYPE_PACKET;
require("./Comment/Section.inc.phtml");

} else { ?>
<header class="red"><?php echo filter_var($title, FILTER_SANITIZE_STRING); ?></header>
<section class="red"><?php echo filter_var($description, FILTER_SANITIZE_STRING); ?></section>
<?php } ?>
Expand Down