/** * Process adding dates * @param \phpbb\event\data $event * @param bool $is_member_or_owner */ protected function process_add_date($event, $is_member_or_owner) { $add_dates = $this->request->variable('add_date', '', true); if (empty($add_dates)) { return array(); } if (!$is_member_or_owner) { return array($this->user->lang('NOT_AUTH_HOOKUP')); } $hookup_errors = array(); $add_dates = array_map("trim", explode("\n", $add_dates)); //replace german date formats $add_dates = preg_replace('#(\\d{1,2})\\. ?(\\d{1,2})\\. ?(\\d{2})[,:]?[,: ]#', '20$3-$2-$1 ', $add_dates); $add_dates = preg_replace('#(\\d{1,2})\\. ?(\\d{1,2})\\. ?(\\d{4})[,:]?[,: ]#', '$3-$2-$1 ', $add_dates); $date_added = false; foreach ($add_dates as $date) { $text_match = preg_match('#\\#(.*)#', $date, $text); //strtotime uses the local (server) timezone, so parse manually and use gmmktime to ignore any timezone if (!preg_match('#(\\d{4})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{2})#', $date) && !$text_match) { $hookup_errors[] = "{$date}: {$this->user->lang['INVALID_DATE']}"; } else { $hookup_continue = true; if ($text_match) { $text = trim($text[1]); $date_time = '0'; } else { $text = null; $date_time = $this->user->get_timestamp_from_format('Y-m-d H:i', $date); if ($date_time < time()) { $hookup_continue = false; $hookup_errors[] = "{$date}: {$this->user->lang['CANNOT_ADD_PAST']}"; } } if ($hookup_continue) { //check for duplicate if (!$this->hookup->add_date($date_time, $text)) { $hookup_errors[] = sprintf($this->user->lang['DATE_ALREADY_ADDED'], $this->user->format_date($date_time, $text)); } else { $date_added = true; } } } } if ($date_added) { // Notification $notify_data = array('user_id' => $this->user->data['user_id'], 'topic_title' => $event['topic_data']['topic_title'], 'topic_id' => $event['topic_id'], 'forum_id' => $event['forum_id']); $this->notification_manager->update_notifications('gn36.hookup.notification.type.date_added', $notify_data); } return $hookup_errors; }
/** * Process adding dates * @param \phpbb\event\data $event * @param bool $is_member_or_owner */ protected function process_add_date($event, $is_member_or_owner) { $add_dates = $this->request->variable('add_date', '', true); if (empty($add_dates)) { return array(); } if (!$is_member_or_owner) { return array($this->user->lang('NOT_AUTH_HOOKUP')); } $hookup_errors = array(); $add_dates = array_map("trim", explode("\n", $add_dates)); //replace german date formats $add_dates = preg_replace('#(\\d{1,2})\\. ?(\\d{1,2})\\. ?(\\d{2})[,:]?[,: ]#', '20$3-$2-$1 ', $add_dates); $add_dates = preg_replace('#(\\d{1,2})\\. ?(\\d{1,2})\\. ?(\\d{4})[,:]?[,: ]#', '$3-$2-$1 ', $add_dates); $date_added = false; foreach ($add_dates as $date) { //strtotime uses the local (server) timezone, so parse manually and use gmmktime to ignore any timezone if (!preg_match('#(\\d{4})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{2})#', $date, $m)) { $hookup_errors[] = "{$date}: {$this->user->lang['INVALID_DATE']}"; } else { $date_time = $this->user->get_timestamp_from_format('Y-m-d H:i', $date); if ($date_time < time()) { $hookup_errors[] = "{$date}: {$this->user->lang['CANNOT_ADD_PAST']}"; } else { //check for duplicate if (!$this->hookup->add_date($date_time)) { $hookup_errors[] = sprintf($this->user->lang['DATE_ALREADY_ADDED'], $this->user->format_date($date_time)); } else { $date_added = true; } } } } if ($date_added) { //notify members about new dates if ($this->messenger == null) { include_once $this->phpbb_root_path . 'includes/functions_messenger.' . $this->phpEx; $this->messenger = new \messenger(); } $messenger = $this->messenger; $notify_users = array(); $notified_userids = array(); // Fetch users to be notified: foreach ($this->hookup->hookup_users as $user_id => $user) { if ($user['notify_status'] == 0) { $notify_users[$user_id] = $user; } } if (!empty($notify_users)) { $sql = 'SELECT u.user_id, u.username, u.user_lang, u.user_email, u.user_jabber, u.user_notify_type FROM ' . USERS_TABLE . ' u WHERE ' . $this->db->sql_in_set('u.user_id', array_keys($notify_users)); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { // TODO: Messenger ersetzen durch notification? // https://www.phpbb.com/community/viewtopic.php?f=461&t=2259916#p13718356 $messenger->template('@gn36_hookup/hookup_dates_added', $row['user_lang']); $messenger->to($row['user_email'], $row['username']); $messenger->im($row['user_jabber'], $row['username']); $messenger->assign_vars(array('USERNAME' => $row['username'], 'TOPIC_TITLE' => $event['topic_data']['topic_title'], 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->phpEx}?f={$event['forum_id']}&t={$event['topic_id']}")); $messenger->send($row['user_notify_type']); $notified_userids[] = $row['user_id']; } $this->db->sql_freeresult($result); $messenger->save_queue(); //set notify status foreach ($notified_userids as $user_id) { $this->hookup->hookup_users[$user_id]['notify_status'] = 1; } } } return $hookup_errors; }