/** * MainEditPageModel constructor. * @param $title * @param bool $isRequest */ public function __construct($title, $isRequest = false) { parent::__construct($title); if ($isRequest) { $this->id = $_REQUEST['Id']; $this->pageTitle = $_REQUEST['Title']; $this->metaKeywords = $_REQUEST['MetaKeywords']; $this->metaDescription = $_REQUEST['MetaDescription']; $this->body = $_REQUEST['Body']; $this->feedbackType = $_REQUEST['FeedbackType']; $this->menuView = isset($_REQUEST['MenuView']); $this->menuIndex = $_REQUEST['MenuIndex']; $this->homePageWidget = isset($_REQUEST['HomePageWidget']); $this->homePageWidgetIndex = $_REQUEST['HomePageWidgetIndex']; $this->homePageCarousel = isset($_REQUEST['HomePageCarousel']); $this->homePageCarouselIndex = $_REQUEST['HomePageCarouselIndex']; $this->hasPage = isset($_REQUEST['HasPage']); $this->parentId = $_REQUEST['ParentId'] == '' ? null : $_REQUEST['ParentId']; $this->userId = Authentication::getUserEntity()->id; if ($this->menuView && $this->pageTitle == '') { $this->pageTitleValidation = Language::$TITLE_CAN_NOT_BE_EMPTY[Config::$LANGUAGE]; $this->validation = false; } if (!$this->menuView && $this->body == '') { $this->bodyValidation = Language::$BODY_CAN_NOT_BE_EMPTY[Config::$LANGUAGE]; $this->validation = false; } } }
/** * @param $roleNames * @return bool */ public static function hasRoles($roleNames) { $hasRoles = false; if (Authentication::isAuthenticated()) { $userEntity = Authentication::getUserEntity(); for ($i = 0; $i < count($roleNames); $i++) { if (in_array($roleNames[$i], $userEntity->roleNames)) { $hasRoles = true; } } } return $hasRoles; }
/** * @param $commentOnPage * @param $feedbackType */ public static function comment($commentOnPage, $feedbackType) { ?> <div class="panel panel-default comment"> <div class="media-body"> <?php if (Authentication::isAuthenticated() && (Authentication::getUserEntity()->id == $commentOnPage->userId || Authentication::hasRoles(array('manager', 'admin')))) { ?> <a class="delete_comment delete" title="<?php echo Language::$DELETE_COMMENT[Config::$LANGUAGE]; ?> " onclick="deleteComment('<?php echo $commentOnPage->id; ?> ');"> <span class="glyphicon glyphicon-remove"></span> </a> <?php } ?> <?php if ($feedbackType != PageEntity::$FEEDBACK_COMMENTS_AUTH || Authentication::isAuthenticated()) { ?> <a class="reply_comment" id="a_answer_<?php echo $commentOnPage->id; ?> " onclick="showDivAnswer('<?php echo $commentOnPage->id; ?> ');" title="<?php echo Language::$REPLY[Config::$LANGUAGE]; ?> "> <span class="fa fa-reply" aria-hidden="true"></span> </a> <?php } ?> <b><?php echo $commentOnPage->nameForComment; ?> </b> <img src="<?php echo GravatarHelper::getUrl($commentOnPage->nameForGravatar, 16); ?> " alt="<?php echo $commentOnPage->nameForComment; ?> "/> <i><?php echo $commentOnPage->createdDate->format(Language::$DATE_FORMAT[Config::$LANGUAGE]); ?> </i> <p><?php echo $commentOnPage->body; ?> </p> </div> </div> <?php if ($feedbackType != PageEntity::$FEEDBACK_COMMENTS_AUTH || Authentication::isAuthenticated()) { ?> <div class="div_answer" id="div_answer_<?php echo $commentOnPage->id; ?> " style="display:none;"> <textarea id="answer_<?php echo $commentOnPage->id; ?> " class="form-control width_full" row="3"></textarea> <div class="comment_buttons text-right"> <?php if ($feedbackType == PageEntity::$FEEDBACK_COMMENTS_CAPTCHA && !Authentication::isAuthenticated()) { ?> <table class="captcha"> <tr> <td><span class="fa fa-refresh" onclick="refresh(<?php echo $commentOnPage->id; ?> );"></span></td> <td><img id="captcha_<?php echo $commentOnPage->id; ?> " src="/misc/captcha/<?php echo $commentOnPage->id; ?> " class="form-control" alt="captcha"/></td> <td><input id="input_captcha_<?php echo $commentOnPage->id; ?> " type="text" class="form-control" /></td> </tr> </table> <div class="clearfix" /> <?php } ?> <button type="button" class="btn btn-default btn-sm" onclick="submitComment('answer_<?php echo $commentOnPage->id; ?> ', <?php echo $commentOnPage->id; ?> )"><?php echo Language::$ADDED_REPLY[Config::$LANGUAGE]; ?> </button> </div> </div> <?php } ?> <?php }
/** * POST: /main/delete-comment */ public function deleteCommentPost() { $commentId = $_REQUEST['CommentId']; $commentOnPageDAO = new CommentOnPageDAO(); $comment = $commentOnPageDAO->getCommentOnPage($commentId); if (Authentication::isAuthenticated() && (Authentication::getUserEntity()->id == $comment->userId || Authentication::hasRoles(array('manager', 'admin')))) { $commentOnPageDAO->delete($commentId); echo 'success'; } }