PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/webroot/updates/concrete5.6.0.2/concrete/core/controllers/blocks/guestbook.php

https://bitbucket.org/microwebedu/registratie_carem
PHP | 289 lines | 194 code | 39 blank | 56 comment | 28 complexity | 05f1041990de6484a46fb9299c0558d0 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. /**
  4. * Controller for the guestbook block, which allows site owners to add comments onto any concrete page.
  5. *
  6. * @package Blocks
  7. * @subpackage Guestbook
  8. * @author Ryan Tyler <ryan@concrete5.org>
  9. * @author Andrew Embler <andrew@concrete5.org>
  10. * @copyright Copyright (c) 2003-2012 Concrete5. (http://www.concrete5.org)
  11. * @license http://www.concrete5.org/license/ MIT License
  12. *
  13. */
  14. class Concrete5_Controller_Block_Guestbook extends BlockController {
  15. protected $btTable = 'btGuestBook';
  16. protected $btInterfaceWidth = "350";
  17. protected $btInterfaceHeight = "480";
  18. protected $btWrapperClass = 'ccm-ui';
  19. protected $btExportPageColumns = array('cID');
  20. protected $btIncludeAll = true; // This has to be on otherwise duplicate() kills the entries.
  21. protected $btExportTables = array('btGuestBook', 'btGuestBookEntries');
  22. /**
  23. * Used for localization. If we want to localize the name/description we have to include this
  24. */
  25. public function getBlockTypeDescription() {
  26. return t("Adds blog-style comments (a guestbook) to your page.");
  27. }
  28. public function getBlockTypeName() {
  29. return t("Guestbook / Comments");
  30. }
  31. function delete() {
  32. $ip = Loader::helper('validation/ip');
  33. if (!$ip->check()) {
  34. $this->set('invalidIP', $ip->getErrorMessage());
  35. return;
  36. }
  37. $c = Page::getCurrentPage();
  38. $E = new GuestBookBlockEntry($this->bID, $c->getCollectionID());
  39. $bo = $this->getBlockObject();
  40. $E->removeAllEntries( $c->getCollectionID() );
  41. parent::delete();
  42. }
  43. /**
  44. * returns the title
  45. * @return string $title
  46. */
  47. function getTitle() {
  48. return $this->title;
  49. }
  50. /**
  51. * returns wether or not to require approval
  52. * @return bool
  53. */
  54. function getRequireApproval() {
  55. return $this->requireApproval;
  56. }
  57. /**
  58. * returns the bool to display the form
  59. * @return bool
  60. */
  61. function getDisplayGuestBookForm() {
  62. return $this->displayGuestBookForm;
  63. }
  64. /**
  65. * Handles the form post for adding a new guest book entry
  66. *
  67. */
  68. function action_form_save_entry() {
  69. $ip = Loader::helper('validation/ip');
  70. if (!$ip->check()) {
  71. $this->set('invalidIP', $ip->getErrorMessage());
  72. return;
  73. }
  74. // get the cID from the block Object
  75. $bo = $this->getBlockObject();
  76. $c = Page::getCurrentPage();
  77. $cID = $c->getCollectionID();
  78. $v = Loader::helper('validation/strings');
  79. $errors = array();
  80. $u = new User();
  81. $uID = intval( $u->getUserID() );
  82. if($this->authenticationRequired && !$u->isLoggedIn()){
  83. $errors['notLogged'] = '- '.t("Your session has expired. Please log back in.");
  84. }elseif(!$this->authenticationRequired){
  85. if(!$v->email($_POST['email'])) {
  86. $errors['email'] = '- '.t("Invalid Email Address");
  87. }
  88. if(!$v->notempty($_POST['name'])) {
  89. $errors['name'] = '- '.t("Name is required");
  90. }
  91. }
  92. // check captcha if activated
  93. if ($this->displayCaptcha) {
  94. $captcha = Loader::helper('validation/captcha');
  95. if (!$captcha->check()) {
  96. $errors['captcha'] = '- '.t("Incorrect captcha code");
  97. }
  98. }
  99. if(!$v->notempty($_POST['commentText'])) {
  100. $errors['commentText'] = '- '.t("a comment is required");
  101. }
  102. if(count($errors)){
  103. $txt = Loader::helper('text');
  104. $E = new GuestBookBlockEntry($this->bID, $c->getCollectionID());
  105. $E->user_name = $txt->entities($_POST['name']).'';
  106. $E->user_email = $txt->entities($_POST['email']).'';
  107. $E->commentText = $txt->entities($_POST['commentText']);
  108. $E->uID = $uID;
  109. $E->entryID = ($_POST['entryID']?$_POST['entryID']:NULL);
  110. $this->set('response', t('Please correct the following errors:') );
  111. $this->set('errors',$errors);
  112. $this->set('Entry',$E);
  113. } else {
  114. $antispam = Loader::helper('validation/antispam');
  115. if (!$antispam->check($_POST['commentText'], 'guestbook_block', array('email' => $_POST['email']))) {
  116. $this->requireApproval = true;
  117. }
  118. $E = new GuestBookBlockEntry($this->bID, $c->getCollectionID());
  119. if($_POST['entryID']) { // update
  120. $bp = $this->getPermissionObject();
  121. if($bp->canWrite()) {
  122. $E->updateEntry($_POST['entryID'], $_POST['commentText'], $_POST['name'], $_POST['email'], $uID );
  123. $this->set('response', t('The comment has been saved') );
  124. } else {
  125. $this->set('response', t('An Error occured while saving the comment') );
  126. return true;
  127. }
  128. } else { // add
  129. $E->addEntry($_POST['commentText'], $_POST['name'], $_POST['email'], (!$this->requireApproval), $cID, $uID );
  130. if ($this->requireApproval) {
  131. $this->set('response', t('Thanks! Your comment has been received. It will require approval before it appears.'));
  132. } else {
  133. $this->set('response', t('Thanks! Your comment has been posted.') );
  134. }
  135. }
  136. $stringsHelper = Loader::helper('validation/strings');
  137. if( $stringsHelper->email($this->notifyEmail) ){
  138. $c = Page::getCurrentPage();
  139. if(intval($uID)>0){
  140. Loader::model('userinfo');
  141. $ui = UserInfo::getByID($uID);
  142. $fromEmail=$ui->getUserEmail();
  143. $fromName=$ui->getUserName();
  144. }else{
  145. $fromEmail=$_POST['email'];
  146. $fromName=$_POST['name'];
  147. }
  148. $mh = Loader::helper('mail');
  149. $mh->to( $this->notifyEmail );
  150. $mh->addParameter('guestbookURL', Loader::helper('navigation')->getLinkToCollection($c, true));
  151. $mh->addParameter('comment', $_POST['commentText'] );
  152. $mh->from($fromEmail,$fromName);
  153. $mh->load('block_guestbook_notification');
  154. $mh->setSubject( t('Guestbook Comment Notification') );
  155. //echo $mh->body.'<br>';
  156. @$mh->sendMail();
  157. }
  158. }
  159. return true;
  160. }
  161. /**
  162. * gets a list of all guestbook entries for the current block
  163. *
  164. * @param string $order ASC|DESC
  165. * @return array
  166. */
  167. function getEntries($order = "ASC") {
  168. $bo = $this->getBlockObject();
  169. $c = Page::getCurrentPage();
  170. return GuestBookBlockEntry::getAll($this->bID, $c->getCollectionID(), $order);
  171. }
  172. /**
  173. * Loads a guestbook entry and sets the $Entry GuestBookBlockEntry object instance for use by the view
  174. *
  175. * @return bool
  176. */
  177. function action_loadEntry() {
  178. $Entry = new GuestBookBlockEntry($this->bID);
  179. $Entry->loadData($_GET['entryID']);
  180. $this->set('Entry',$Entry);
  181. return true;
  182. }
  183. /**
  184. * deltes a given Entry, sets the response message for use in the view
  185. *
  186. */
  187. function action_removeEntry() {
  188. $ip = Loader::helper('validation/ip');
  189. if (!$ip->check()) {
  190. $this->set('invalidIP', $ip->getErrorMessage());
  191. return;
  192. }
  193. $bp = $this->getPermissionObject();
  194. if($bp->canWrite()) {
  195. $Entry = new GuestBookBlockEntry($this->bID);
  196. $Entry->removeEntry($_GET['entryID']);
  197. $this->set('response', t('The comment has been removed.') );
  198. }
  199. }
  200. /**
  201. * deltes a given Entry, sets the response message for use in the view
  202. *
  203. */
  204. function action_approveEntry() {
  205. $ip = Loader::helper('validation/ip');
  206. if (!$ip->check()) {
  207. $this->set('invalidIP', $ip->getErrorMessage());
  208. return;
  209. }
  210. $bp = $this->getPermissionObject();
  211. if($bp->canWrite()) {
  212. $Entry = new GuestBookBlockEntry($this->bID);
  213. $Entry->approveEntry($_GET['entryID']);
  214. $this->set('response', t('The comment has been approved.') );
  215. }
  216. }
  217. /**
  218. * deltes a given Entry, sets the response message for use in the view
  219. *
  220. */
  221. function action_unApproveEntry() {
  222. $ip = Loader::helper('validation/ip');
  223. if (!$ip->check()) {
  224. $this->set('invalidIP', $ip->getErrorMessage());
  225. return;
  226. }
  227. $bp = $this->getPermissionObject();
  228. if($bp->canWrite()) {
  229. $Entry = new GuestBookBlockEntry($this->bID);
  230. $Entry->unApproveEntry($_GET['entryID']);
  231. $this->set('response', t('The comment has been unapproved.') );
  232. }
  233. }
  234. public function getEntryCount($cID = NULL) {
  235. $ca = new Cache();
  236. $cID = (isset($cID)?$cID:$this->cID);
  237. $count = $ca->get('GuestBookCount',$cID."-".$this->bID);
  238. if(!isset($count) || $count === false) {
  239. $db = Loader::db();
  240. $q = 'SELECT count(bID) as count
  241. FROM btGuestBookEntries
  242. WHERE bID = ?
  243. AND cID = ?
  244. AND approved=1';
  245. $v = array($this->bID, $cID);
  246. $count = $db->getOne($q,$v);
  247. }
  248. return $count;
  249. }
  250. } // end class def