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

/classes/Pages/Calendar/EventAdd.php

https://gitlab.com/indybay/indybay-active
PHP | 233 lines | 195 code | 19 blank | 19 comment | 39 complexity | 41e27a53556eb16e4a95dd58199260aa MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. namespace Indybay\Pages\Calendar;
  3. use Indybay\Cache\SpamCache;
  4. use Indybay\DB\ArticleDB;
  5. use Indybay\DB\CalendarDB;
  6. use Indybay\Pages\Article\Publish;
  7. use Indybay\Renderer\Renderer;
  8. /**
  9. * Event add.
  10. */
  11. class EventAdd extends Publish {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function __construct() {
  16. if (isset($_POST['displayed_date_day']) && $_POST['displayed_date_day'] + 0 > 0) {
  17. $day = $_POST['displayed_date_day'];
  18. }
  19. else {
  20. $day = date('d');
  21. }
  22. if (isset($_POST['displayed_date_month']) && $_POST['displayed_date_month'] + 0 > 0) {
  23. $month = $_POST['displayed_date_month'];
  24. }
  25. else {
  26. $month = date('m');
  27. }
  28. if (isset($_POST['displayed_date_year']) && $_POST['displayed_date_year'] + 0 > 0) {
  29. $year = $_POST['displayed_date_year'];
  30. }
  31. else {
  32. $year = date('Y');
  33. }
  34. if (isset($_POST['displayed_date_hour']) && $_POST['displayed_date_hour'] + 0 > 0) {
  35. $hour = $_POST['displayed_date_hour'];
  36. }
  37. else {
  38. $hour = 12;
  39. }
  40. if (isset($_POST['displayed_date_minute']) && $_POST['displayed_date_minute'] + 0 > 0) {
  41. $minute = $_POST['displayed_date_minute'];
  42. }
  43. else {
  44. $minute = 0;
  45. }
  46. $renderer = new Renderer();
  47. $this->tkeys['cal_select_date_displayed_date'] = $renderer->makeDatetimeSelectForm24Hour(
  48. 'displayed_date', 0, 1, $day, $month, $year,
  49. $hour, $minute);
  50. if (isset($_POST['event_type_id']) && $_POST['event_type_id'] + 0 > 0) {
  51. $event_type_id = $_POST['event_type_id'];
  52. }
  53. else {
  54. $event_type_id = 0;
  55. }
  56. if (isset($_POST['event_duration']) && $_POST['event_duration'] + 0 > 0) {
  57. $event_duration = $_POST['event_duration'];
  58. }
  59. else {
  60. $event_duration = 0;
  61. }
  62. $calendar_db_class = new CalendarDB();
  63. $keyword_list = $calendar_db_class->getEventTypeForSelectList();
  64. $this->tkeys['cat_type_select'] = $renderer->makeSelectForm(
  65. 'event_type_id', $keyword_list,
  66. $event_type_id);
  67. $duration_list = [];
  68. $duration_list['0'] = '0:00';
  69. $duration_list['0.25'] = '0:15';
  70. $duration_list['0.5'] = '0:30';
  71. $duration_list['0.75'] = '0:45';
  72. $duration_list['1'] = '1:00';
  73. $duration_list['1.5'] = '1:30';
  74. $duration_list['2'] = '2:00';
  75. $duration_list['2.5'] = '2:30';
  76. $duration_list['3'] = '3:00';
  77. $duration_list['4'] = '4:00';
  78. $duration_list['5'] = '5:00';
  79. $duration_list['6'] = '6:00';
  80. $duration_list['7'] = '7:00';
  81. $duration_list['8'] = '8:00';
  82. $duration_list['9'] = '9:00';
  83. $duration_list['10'] = '10:00';
  84. $duration_list['11'] = '11:00';
  85. $duration_list['12'] = '12:00';
  86. $duration_list['24'] = '24:00';
  87. $this->tkeys['local_select_duration'] = $renderer->makeSelectForm(
  88. 'event_duration', $duration_list,
  89. $event_duration);
  90. }
  91. /**
  92. * {@inheritdoc}
  93. */
  94. public function getParentNewsItemTypeId() {
  95. return NEWS_ITEM_TYPE_ID_EVENT;
  96. }
  97. /**
  98. * {@inheritdoc}
  99. */
  100. public function getChildNewsItemTypeId() {
  101. return NEWS_ITEM_TYPE_ID_COMMENT;
  102. }
  103. /**
  104. * {@inheritdoc}
  105. */
  106. public function printPublishInstructions() {
  107. if (!isset($GLOBALS['db_down']) || $GLOBALS['db_down'] != '1') {
  108. include INCLUDE_PATH . '/article/event-publish-instructions.inc';
  109. }
  110. }
  111. /**
  112. * {@inheritdoc}
  113. */
  114. public function validatePost($posted_fields) {
  115. $ret = 1;
  116. if (empty($this->captcha->valid)) {
  117. $this->addValidationMessage('Please answer the CAPTCHA (anti-spam question) correctly.');
  118. $ret = 0;
  119. }
  120. if (mktime($posted_fields['displayed_date_hour'], $posted_fields['displayed_date_minute'], 0, $posted_fields['displayed_date_month'], $posted_fields['displayed_date_day'], $posted_fields['displayed_date_year']) < $_SERVER['REQUEST_TIME']) {
  121. $this->addValidationMessage('A future event date is required.');
  122. $ret = 0;
  123. }
  124. if (!isset($posted_fields['title1']) || mb_strlen(trim($posted_fields['title1']), 'UTF-8') < 5) {
  125. $this->addValidationMessage('Title is required and it must at least be 5 characters long.');
  126. $ret = 0;
  127. }
  128. // Added validation for event author 12/27/15.
  129. if (!isset($posted_fields['displayed_author_name']) || mb_strlen(trim($posted_fields['displayed_author_name']), 'UTF-8') < 1) {
  130. $this->addValidationMessage('Author name is required.');
  131. $ret = 0;
  132. }
  133. if (!isset($posted_fields['summary']) || mb_strlen($posted_fields['summary'], 'UTF-8') < 1) {
  134. $this->addValidationMessage('Location details are required.');
  135. $ret = 0;
  136. }
  137. $posted_fields['event_duration'] = trim($posted_fields['event_duration']);
  138. if (strrpos($posted_fields['event_duration'], '.') > 0) {
  139. $posted_fields['event_duration'] = substr($posted_fields['event_duration'], 0, strrpos($posted_fields['event_duration'], '.'));
  140. }
  141. if (strlen($posted_fields['event_duration']) < 1 || ($posted_fields['event_duration'] + 0) . ' ' != $posted_fields['event_duration'] . ' ') {
  142. $this->addValidationMessage('Event duration is required and must be entered as a number in decimal format (i.e. 1.5 is an hour and a half).');
  143. $ret = 0;
  144. }
  145. $spam_cache_class = new SpamCache();
  146. $spamvalidatelist = $spam_cache_class->loadValidationStringFile();
  147. $spamvalidatelist = str_replace("\r", '', $spamvalidatelist);
  148. $spamvalidate_array = explode("\n", $spamvalidatelist);
  149. foreach ($spamvalidate_array as $spamstr) {
  150. $spamstr = trim($spamstr);
  151. if ($spamstr == '') {
  152. continue;
  153. }
  154. if (strpos(' ' . $posted_fields['summary'], $spamstr) > 0) {
  155. $this->addValidationMessage("Indybay's Spam Filter Doesnt Allow The String \"" . $spamstr . '" To Be In The Summary or Text Of Posts');
  156. $ret = 0;
  157. }
  158. if (strpos(' ' . $posted_fields['text'], $spamstr) > 0) {
  159. $this->addValidationMessage("Indybay's Spam Filter Doesnt Allow The String \"" . $spamstr . '" To Be In The Summary or Text Of Posts');
  160. $ret = 0;
  161. }
  162. }
  163. return $ret;
  164. }
  165. /**
  166. * {@inheritdoc}
  167. */
  168. public function addAdditionalInfoForPublishSubtypes($news_item_id, $posted_fields) {
  169. $event_type_id = $_POST['event_type_id'];
  170. $calendar_db_class = new CalendarDB();
  171. $calendar_db_class->setOrChangeEventType($news_item_id, $event_type_id);
  172. }
  173. /**
  174. * {@inheritdoc}
  175. */
  176. public function getDuplicate($posted_fields) {
  177. $article_db_class = new ArticleDB();
  178. $possible_dups = $article_db_class->findAllRecentDuplicateNonhiddenVersionsByTitle($posted_fields['title1']);
  179. if (is_array($possible_dups) && count($possible_dups) > 0) {
  180. foreach ($possible_dups as $possible_dup) {
  181. if (!isset($posted_fields['is_summary_html'])) {
  182. $posted_fields['is_summary_html'] = 0;
  183. }
  184. if ($possible_dup['summary'] == $posted_fields['summary']
  185. && $possible_dup['text'] == $posted_fields['text']
  186. && $possible_dup['displayed_author_name'] == $posted_fields['displayed_author_name']
  187. && $possible_dup['related_url'] == $posted_fields['related_url']
  188. && $possible_dup['email'] == $posted_fields['email']
  189. && $possible_dup['is_text_html'] + 0 == $posted_fields['is_text_html'] + 0
  190. && $possible_dup['is_summary_html'] + 0 == $posted_fields['is_summary_html'] + 0
  191. && $possible_dup['event_duration'] + 0 == $posted_fields['event_duration'] + 0
  192. && date('Y', $possible_dup['displayed_timestamp']) + 0 == $posted_fields['displayed_date_year'] + 0
  193. && date('d', $possible_dup['displayed_timestamp']) + 0 == $posted_fields['displayed_date_day'] + 0
  194. && date('m', $possible_dup['displayed_timestamp']) + 0 == $posted_fields['displayed_date_month'] + 0
  195. && date('H', $possible_dup['displayed_timestamp']) + 0 == $posted_fields['displayed_date_hour'] + 0
  196. && date('i', $possible_dup['displayed_timestamp']) + 0 == $posted_fields['displayed_date_minute'] + 0
  197. ) {
  198. return $possible_dup['news_item_id'];
  199. }
  200. }
  201. return 0;
  202. }
  203. else {
  204. return 0;
  205. }
  206. }
  207. }