/** * Send this message * @since Version 3.3 * @version 3.3 * @return boolean */ public function send() { $this->validate(); $data = array("privmsgs_type" => PRIVMSGS_UNREAD_MAIL, "privmsgs_subject" => $this->subject, "privmsgs_from_userid" => $this->from_user_id, "privmsgs_to_userid" => $this->to_user_id, "privmsgs_date" => time(), "privmsgs_ip" => encode_ip($_SERVER['REMOTE_ADDR']), "privmsgs_enable_bbcode" => $this->enable_bbcode, "privmsgs_enable_html" => $this->enable_html, "privmsgs_enable_smilies" => $this->enable_smilies, "privmsgs_attach_sig" => $this->enable_signature, "object_id" => $this->object_id); $this->db->insert("nuke_bbprivmsgs", $data); $pm_id = $this->db->lastInsertId(); $this->id = $pm_id; $data = array("privmsgs_text_id" => $pm_id, "privmsgs_bbcode_uid" => $this->bbcode_uid, "privmsgs_text" => function_exists("prepare_submit") ? prepare_submit($this->body) : $this->body); $rs = $this->db->insert("nuke_bbprivmsgs_text", $data); /** * If the recipient doesn't want to be notified of a new message then return out */ if ($this->Recipient->notify_privmsg != 1) { return; } /** * Send a push notification */ $Push = new Notification(); $Push->transport = Notifications::TRANSPORT_PUSH; $Push->subject = sprintf("[Private Messages] New message from %s", $this->Author->username); $Push->body = sprintf("%s has sent you a new private message in the conversation titled \"%s\"", $this->Author->username, $this->subject); $Push->setActionUrl(sprintf("/messages/conversation/%d", $this->id))->addRecipient($this->Recipient->id, $this->Recipient->username, $this->Recipient->username); $Push->commit()->dispatch(); /** * Template settings */ $Smarty = AppCore::getSmarty(); $Smarty->assign("server_addr", "www.railpage.com.au"); $Smarty->assign("message_id", $this->id); $Smarty->assign("pm_from_username", $this->Author->username); $Smarty->assign("userdata_username", $this->Recipient->username); /** * Create a user notification */ $Notification = new Notification(); $Notification->transport = Notifications::TRANSPORT_EMAIL; $Notification->status = Notifications::STATUS_QUEUED; $Notification->subject = sprintf("[Private Messages] New message from %s", $this->Author->username); $Notification->addRecipient($this->Recipient->id, $this->Recipient->username, $this->Recipient->contact_email); $tpl = $Smarty->ResolveTemplate("template.generic"); $email = array("subject" => sprintf("New message from %s", $this->Author->username), "subtitle" => "Private Messages", "body" => nl2br(sprintf("Hi %s,\n\n<a href='http://www.railpage.com.au%s?utm_medium&email&utm_source=private-messages&utm_campain=user-%d'>%s</a> has sent you a new <a href='http://www.railpage.com.au/messages/conversation/%d?utm_medium=email&utm_source=private-messages&utm_campaign=user-%d#%d'>private message</a> in the conversation titled <em>%s</em>.", $this->Recipient->username, $this->Author->url->url, $this->Author->id, $this->Author->username, $this->id, $this->Author->id, $this->id, $this->subject))); $Smarty->Assign("email", $email); $Notification->body = $Smarty->fetch($tpl); $Notification->commit(); }
/** * Send this message * @since Version 3.3 * @version 3.3 * @return boolean */ public function send() { $this->validate(); $data = array("privmsgs_type" => PRIVMSGS_UNREAD_MAIL, "privmsgs_subject" => $this->subject, "privmsgs_from_userid" => $this->from_user_id, "privmsgs_to_userid" => $this->to_user_id, "privmsgs_date" => time(), "privmsgs_ip" => encode_ip($_SERVER['REMOTE_ADDR']), "privmsgs_enable_bbcode" => $this->enable_bbcode, "privmsgs_enable_html" => $this->enable_html, "privmsgs_enable_smilies" => $this->enable_smilies, "privmsgs_attach_sig" => $this->enable_signature, "object_id" => $this->object_id); if ($this->db->insert("nuke_bbprivmsgs", $data)) { $pm_id = $this->db->lastInsertId(); $data = array("privmsgs_text_id" => $pm_id, "privmsgs_bbcode_uid" => $this->bbcode_uid, "privmsgs_text" => prepare_submit($this->body)); $rs = $this->db->insert("nuke_bbprivmsgs_text", $data); } if ($rs) { // Send an email to the recipient if their settings say so try { $ThisUser = new User($this->to_user_id); if ($ThisUser->notify_privmsg == 1) { try { // Send the confirmation email //require_once('vendor/pear-pear.swiftmailer.org/Swift/lib/swift_init.php'); global $smarty, $User; $smarty->assign("server_addr", "www.railpage.com.au"); $smarty->assign("message_id", $pm_id); $smarty->assign("pm_from_username", $User->username); $smarty->assign("userdata_username", $ThisUser->username); $html = $smarty->fetch(dirname(dirname(dirname(dirname(__DIR__)))) . DS . "content" . DS . "email_pm.tpl"); $crlf = "\n"; $message = Swift_Message::newInstance()->setSubject("New private message on Railpage")->setFrom(array("*****@*****.**" => "Railpage"))->setTo(array($ThisUser->contact_email => $ThisUser->username))->setBody($html, 'text/html'); // Mail transport $transport = Swift_SmtpTransport::newInstance($this->Config->SMTP->host, $this->Config->SMTP->port, $this->Config->SMTP->TLS = true ? "tls" : NULL)->setUsername($this->Config->SMTP->username)->setPassword($this->Config->SMTP->password); $mailer = Swift_Mailer::newInstance($transport); $result = $mailer->send($message); } catch (Exception $e) { printArray($e->getMessage()); die; } } } catch (Exception $e) { echo $e->getMessage(); } return true; } else { throw new Exception($this->db->error); return false; } }
/** * Commit changes to a story * @since Version 3.4 * @return boolean */ public function commit() { $this->validate(); // Format the article blurb try { $this->blurb = prepare_submit($this->blurb); } catch (Exception $e) { global $Error; $Error->save($e); } // Format the article body try { $this->body = prepare_submit($this->body); } catch (Exception $e) { global $Error; $Error->save($e); } if ($this->Topic instanceof \Railpage\Forums\Thread) { $this->topic_id = $this->Topic->id; } $dataArray = array(); $dataArray['approved'] = $this->approved; $dataArray['title'] = $this->title; $dataArray['hometext'] = $this->blurb->__toString(); $dataArray['bodytext'] = $this->body->__toString(); $dataArray['ForumThreadID'] = $this->topic_id; $dataArray['source'] = $this->source; $dataArray['user_id'] = $this->user_id; $dataArray['staff_id'] = empty($this->staff_user_id) ? 0 : $this->staff_user_id; $dataArray['geo_lat'] = empty($this->lat) ? 0 : $this->lat; $dataArray['geo_lon'] = empty($this->lon) ? 0 : $this->lon; $dataArray['sent_to_fb'] = (bool) $this->sent_to_fb; $dataArray['time'] = $this->date->format("Y-m-d H:i:s"); $dataArray['slug'] = $this->createSlug(); $dataArray['topic'] = $this->Topic->id; if ($this->featured_image !== false) { $dataArray['featured_image'] = $this->featured_image; } if (!empty($this->username)) { $dataArray['informant'] = $this->username; } /** * Save changes */ if (!empty($this->id) && $this->id > 0) { $where = array("sid = ?" => $this->id); $this->db->update("nuke_stories", $dataArray, $where); } else { $this->db->insert("nuke_stories", $dataArray); $this->id = $this->db->lastInsertId(); } /** * Update Memcached */ $this->makeJSON(); return true; }
/** * Commit changes to a story * @since Version 3.4 * @return boolean */ public function commit() { $this->validate(); if (function_exists("prepare_submit")) { // Format the article blurb try { if (!empty($this->blurb)) { $this->blurb = prepare_submit($this->blurb); } if (!empty($this->lead)) { $this->lead = prepare_submit($this->lead); } } catch (Exception $e) { Debug::SaveError($e); } // Format the article body try { if (!empty($this->body)) { $this->body = prepare_submit($this->body); } if (!empty($this->paragraphs)) { $this->paragraphs = prepare_submit($this->paragraphs); } } catch (Exception $e) { Debug::SaveError($e); } } if ($this->Topic instanceof \Railpage\Forums\Thread) { $this->topic_id = $this->Topic->id; } $dataArray = array(); if (filter_var($this->id, FILTER_VALIDATE_INT)) { $this->Memcached->delete($this->mckey); $this->Memcached->delete(sprintf("json:railpage.news.article=%d", $this->id)); $this->Redis->delete(sprintf("railpage:news.article=%s", $this->id)); $this->Redis->delete(sprintf("railpage:news.article=%s", $this->slug)); $this->Memcached->delete(sprintf(self::CACHE_KEY_FORMAT_LEAD, $this->id)); $this->Memcached->delete(sprintf(self::CACHE_KEY_FORMAT_PARAGRAPHS, $this->id)); } $dataArray['approved'] = $this->approved; $dataArray['title'] = $this->title; $dataArray['hometext'] = is_object($this->blurb) ? $this->blurb->__toString() : $this->blurb; $dataArray['bodytext'] = is_object($this->body) ? $this->body->__toString() : $this->body; $dataArray['lead'] = $this->lead; $dataArray['paragraphs'] = $this->paragraphs; $dataArray['ForumThreadID'] = $this->topic_id; $dataArray['source'] = $this->source; $dataArray['user_id'] = $this->Author instanceof User ? $this->Author->id : $this->user_id; $dataArray['staff_id'] = empty($this->staff_user_id) ? 0 : $this->staff_user_id; $dataArray['geo_lat'] = empty($this->lat) ? 0 : $this->lat; $dataArray['geo_lon'] = empty($this->lon) ? 0 : $this->lon; $dataArray['sent_to_fb'] = (bool) $this->sent_to_fb; $dataArray['time'] = $this->date->format("Y-m-d H:i:s"); $dataArray['slug'] = empty($this->slug) ? $this->createSlug() : $this->slug; $dataArray['topic'] = $this->Topic->id; $dataArray['unique_id'] = $this->unique_id; $dataArray['queued'] = $this->queued; if ($this->featured_image !== false) { $dataArray['featured_image'] = $this->featured_image; } if (!empty($this->username) || $this->Author instanceof User) { $dataArray['informant'] = $this->Author instanceof User ? $this->Author->username : $this->username; } foreach ($dataArray as $key => $val) { $dataArray[$key] = trim($val); } /** * Save changes */ if (!empty($this->id) && $this->id > 0) { $where = array("sid = ?" => $this->id); $this->db->update("nuke_stories", $dataArray, $where); } else { $this->db->insert("nuke_stories", $dataArray); $this->id = $this->db->lastInsertId(); } /** * Update Memcached */ $this->makeJSON(); /** * Update our URLs */ $this->makeURLs(); return true; }