/** * prepareData * * @param \Windwalker\Data\Data $data * * @return void */ protected function prepareData($data) { $paths = $data->currentCategory->path; $data->breadcrumbs = BreadcrumbHelper::getBreadcrumbs($paths); if ($data->currentCategory->id != 1) { $this->setTitle($data->currentCategory->title); } // Prepare format foreach ($data->categories as $category) { $category->last_post->user_params = new Registry($category->last_post->user_params); } foreach ($data->topics as $topic) { $topic->last_user_params = new Registry($topic->last_user_params); } $user = User::get(); $data->isWatch = Notification::getNotification('category', $data->currentCategory->id, $user->id)->notNull(); if ($data->currentCategory->id != 1) { $desc = $data->currentCategory->description; $desc = Utf8String::substr(strip_tags($desc), 0, 150); HtmlHeader::addMetadata('description', $desc, true); HtmlHeader::addOpenGraph('og:title', HtmlHeader::getPageTitle(), true); HtmlHeader::addOpenGraph('og:description', $desc, true); HtmlHeader::addOpenGraph('og:image', $data->currentCategory->image, true); } }
/** * prepareData * * @param \Windwalker\Data\Data $data * * @return void */ protected function prepareData($data) { if ($this->layout == 'default') { $paths = $this['topic']->category->path; $data->breadcrumbs = BreadcrumbHelper::getBreadcrumbs($paths); foreach ($data->posts as $post) { $post->raw_body = $post->body; $post->body = Markdown::render($post->body); } $user = User::get(); $data->isWatch = Notification::getNotification('topic', $this['topic']->id, $user->id)->notNull(); $this->setTitle($data->topic->title); } else { $this->setTitle('New Topic'); } $desc = $data->topic->title; if ($data->posts[0]) { $desc = $data->posts[0]->body; $desc = Utf8String::substr(strip_tags($desc), 0, 150); } HtmlHeader::addMetadata('description', $desc, true); HtmlHeader::addOpenGraph('og:title', HtmlHeader::getPageTitle(), true); HtmlHeader::addOpenGraph('og:description', $desc, true); HtmlHeader::getMetadata()->removeOpenGraph('og:image'); }
/** * postSave * * @param Data $data * * @throws ValidFailException */ protected function postSave(Data $data) { $input = array('item' => array('topic_id' => $data->id, 'primary' => 1, 'body' => $data->body)); if (!$this->hmvc($controller = new \Forum\Controller\Post\SaveController(), $input)) { list($url, $msg, $type) = $controller->getRedirect(true); throw new ValidFailException($msg); } $post = $controller->getPost(); $data->last_reply_post = $post->id; // Add Notification Notification::addNotification('topic', $data->id, $data->user_id); }
/** * doSave * * @param Data $data * * @return void * * @throws ValidFailException */ protected function doSave(Data $data) { $user = User::get(); if (!$user->isMember()) { throw new ValidFailException('User not login'); } Notification::removeNotification($data->type, $data->target_id, $user->id); }
/** * sendMail * * @param Record $topic * @param Data $data * * @return void */ protected function sendMail($topic, $data) { $topicNotifies = Notification::getNotifications('topic', $topic->id); $catNotifies = Notification::getNotifications('category', $topic->category_id); $notifications = array_merge($topicNotifies->email, $catNotifies->email); if (!count($notifications)) { return; } $view = $this->getView('Mail'); $view['topic'] = $topic; $view['siteName'] = HtmlHeader::getSiteName(); $view['link'] = $this->getSuccessRedirect($data); $body = $view->setLayout('new-post')->render(); $message = SwiftMailer::newMessage('A new reply for topic: ' . $topic->title)->setBody($body); foreach ($notifications as $notification) { $message->addTo($notification); } SwiftMailer::send($message); }