public function privateMessageNotification($message) { $fromUser = $message->getFromUser(); $not = new DB_Notification(); $not->setUserId($message->getToUserId()); $not->setType("new_private_message"); $body = 'You have a new private message in your <a href="http://' . GlobalProperties::$URL_HOST . '/account:you/start/messages">Inbox</a>!<br/>'; $body .= "From: " . WDRenderUtils::renderUser($fromUser) . "<br/>"; $body .= 'Subject: <a href="http://' . GlobalProperties::$URL_HOST . '/account:you/start/messages/inboxmessage/' . $message->getMessageId() . '">' . htmlspecialchars($message->getSubject()) . '</a><br/>'; $body .= 'Preview (first few words): '; $body .= $message->getPreview(); $not->setDate(new ODate()); $extra = array(); $extra['message_id'] = $message->getMessageId(); $extra['from_user_id'] = $message->getFromUserId(); $extra['subject'] = $message->getSubject(); $extra['preview'] = $message->getPreview(); //$extra['urls'] = array( array('read the message','http://www.wikidot.com/account:you/start/messages/inboxmessage/'.$message->getMessageId()), /* * format for urls is: * 0 - anchor * 1 - href * 2 - onclick */ $not->setExtra($extra); $not->save(); }
/** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { $userName = $options['userName']; $unixName = WDStringUtils::toUnixName($userName); $c = new Criteria(); $c->add("unix_name", $unixName); $user = DB_OzoneUserPeer::instance()->selectOne($c); if ($user == null) { return '<span class="error-inline">' . sprintf(_('User <em>%s</em> can not be found.'), $userName) . '</span>'; } else { $o = array(); if ($options['image']) { $o['image'] = true; } return WDRenderUtils::renderUser($user, $o); } }
public function getBody() { if (parent::getBody() != "") { return parent::getBody(); } $type = $this->getType(); $extra = $this->getExtra(); $lang = OZONE::getRunData()->getLanguage(); switch ($type) { case 'new_private_message': $fromUser = DB_OzoneUserPeer::instance()->selectByPrimaryKey($extra['from_user_id']); $body = _('You have a new private message in your <a href="http://' . GlobalProperties::$URL_HOST . '/account:you/start/messages">Inbox</a>.') . '<br/>'; $body .= _("From") . ": " . WDRenderUtils::renderUser($fromUser) . "<br/>"; $body .= _('Subject') . ': <a href="http://' . GlobalProperties::$URL_HOST . '/account:you/start/messages/inboxmessage/' . $extra['message_id'] . '">' . htmlspecialchars($extra['subject']) . '</a><br/>'; $body .= _('Preview (first few words)') . ': ' . $extra['preview']; break; case 'new_membership_invitation': $body = _('You have received an invitation to join members of the site') . ' <a href="http://' . $extra['site_domain'] . '">"' . htmlspecialchars($extra['site_name']) . '"</a>.'; break; case 'removed_from_members': $body = _('You have been removed from members of the site') . ' <a href="http://' . $extra['site_domain'] . '">"' . htmlspecialchars($extra['site_name']) . '"</a>.'; break; case 'added_to_moderators': $body = _('You have been added to moderators of the site') . ' <a href="http://' . $extra['site_domain'] . '">"' . htmlspecialchars($extra['site_name']) . '"</a>.'; break; case 'removed_from_moderators': $body = _('You have been removed from moderators of the site') . ' <a href="http://' . $extra['site_domain'] . '">"' . htmlspecialchars($extra['site_name']) . '"</a>.'; break; case 'added_to_administrators': $body = _('You have been added to administrators of the site') . ' <a href="http://' . $extra['site_domain'] . '">"' . htmlspecialchars($extra['site_name']) . '"</a>.'; break; case 'removed_from_administrators': $body = _('You have been removed from administrators of the site') . ' <a href="http://' . $extra['site_domain'] . '">"' . htmlspecialchars($extra['site_name']) . '"</a>.'; break; case 'membership_application_accepted': $body = _('Your membership application to the site') . ' <a href="http://' . $extra['site_domain'] . '">"' . htmlspecialchars($extra['site_name']) . '"</a>.' . 'has been accepted. You are now a member of this site.'; break; case 'membership_application_declined': $body = _('Your membership application to the site') . ' <a href="http://' . $extra['site_domain'] . '">"' . htmlspecialchars($extra['site_name']) . '"</a>.' . 'has been declined.'; break; } return $body; }
public function build($runData) { $user = $runData->getTemp("user"); $userId = $user->getUserId(); // set language for the user $lang = $user->getLanguage(); $runData->setLanguage($lang); $GLOBALS['lang'] = $lang; // and for gettext too: switch ($lang) { case 'pl': $glang = "pl_PL"; break; case 'en': $glang = "en_US"; break; } putenv("LANG={$glang}"); putenv("LANGUAGE={$glang}"); setlocale(LC_ALL, $glang . '.UTF-8'); // now just get watched page changes for the user... $c = new Criteria(); $c->addJoin("page_id", "page.page_id"); $c->addJoin("page_id", "watched_page.page_id"); $c->addJoin("user_id", "ozone_user.user_id"); $c->add("watched_page.user_id", $user->getUserId()); $c->addOrderDescending("page_revision.revision_id"); $c->setLimit(30); $revisions = DB_PageRevisionPeer::instance()->select($c); $channel['title'] = _('Wikidot.com watched pages changes for user') . ' "' . $user->getNickName() . '"'; $channel['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/watched-changes"; $items = array(); foreach ($revisions as $rev) { $page = $rev->getPage(); $site = $page->getSite(); $item = array(); $item['title'] = '"' . $page->getTitleOrUnixName() . '" ' . _('on site') . ' "' . $site->getName() . '"'; $item['link'] = 'http://' . $site->getDomain() . '/' . $page->getUnixName(); $desc = ''; $flags = array(); if ($rev->getFlagText()) { $flags[] = _("source change"); } if ($rev->getFlagTitle()) { $flags[] = _("title change"); } if ($rev->getFlagFile()) { $flags[] = _("file action"); } if ($rev->getFlagRename()) { $flags[] = _("page move/rename"); } if ($rev->getFlagMeta()) { $flags[] = _("metadata changed"); } if ($rev->getFlagNew()) { $flags[] = _("new page"); } $desc .= _('Site') . ': <a href="http://' . $site->getDomain() . '">' . htmlspecialchars($site->getName()) . '</a><br/>'; $desc .= _('Page') . ': <a href="http://' . $site->getDomain() . '/' . $page->getUnixName() . '">' . htmlspecialchars($page->getTitle()) . '</a> (' . $page->getUnixName() . ')<br/>'; $desc .= _('Current revision number') . ': ' . $rev->getRevisionNumber() . '<br/>'; $desc .= _('Date changed') . ': ' . date('r', $rev->getDateLastEdited()->getTimestamp()) . '<br/>'; $desc .= _('Change type') . ': ' . implode(', ', $flags) . '<br/>'; if ($rev->getComments()) { $desc .= _('Change comments') . ': ' . htmlspecialchars($rev->getComments()) . '<br/>'; } $desc .= _('By') . ': ' . WDRenderUtils::renderUser($rev->getUserOrString()) . '<br/>'; $desc .= '<br/>' . _('Page content preview') . ': <br/>' . $page->getPreview(); $item['description'] = $desc; $item['content'] = $desc; $item['guid'] = $channel['link'] . "#revision-" . $rev->getRevisionId(); $item['date'] = date('r', $rev->getDateLastEdited()->getTimestamp()); $content = ''; $items[] = $item; } $runData->contextAdd("channel", $channel); $runData->contextAdd("items", $items); }
public function getBody() { if (parent::getBody() != "") { return parent::getBody(); } $type = $this->getType(); $extra = $this->getExtra(); $lang = OZONE::getRunData()->getLanguage(); switch ($type) { case 'NEW_MEMBER_APPLICATION': $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($extra['from_user_id']); $body = sprintf(_('There is a new member application from user %s.'), WDRenderUtils::renderUser($user)); break; case 'INVITATION_ACCEPTED': $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($extra['user_id']); $body = sprintf(_('The user %s has accepted the invitation and is now a member of the site.'), WDRenderUtils::renderUser($user)); break; case 'INVITATION_DECLINED': $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($extra['user_id']); $body = sprintf(_('The user %s has not accepted the invitation.'), WDRenderUtils::renderUser($user)); break; case 'NEW_MEMBER_BY_PASSWORD': $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($extra['user_id']); $body = sprintf(_('A new member joined the site: %s - by providing a valid membership password.'), WDRenderUtils::renderUser($user)); break; case 'NEW_MEMBER_BY_EMAIL_INVITATION': $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($extra['user_id']); $body = sprintf(_('A new user (%s) accepted the invitation and is now a member of the Site.'), WDRenderUtils::renderUser($user)); break; case 'MEMBER_RESIGNED': $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($extra['user_id']); $body = sprintf(_('The user %s is no longer a site member. Resigned.'), WDRenderUtils::renderUser($user)); break; case 'MODERATOR_RESIGNED': $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($extra['user_id']); $body = sprintf(_('The user %s resigned from being a moderator of this site.'), WDRenderUtils::renderUser($user)); break; case 'ADMIN_RESIGNED': $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($extra['user_id']); $body = sprintf(_('The user %s resigned from being an administrator of this site.'), WDRenderUtils::renderUser($user)); break; } return $body; }
public function build($runData) { $user = $runData->getTemp("user"); $userId = $user->getUserId(); // set language for the user $lang = $user->getLanguage(); $runData->setLanguage($lang); $GLOBALS['lang'] = $lang; // and for gettext too: switch ($lang) { case 'pl': $glang = "pl_PL"; break; case 'en': $glang = "en_US"; break; } putenv("LANG={$glang}"); putenv("LANGUAGE={$glang}"); setlocale(LC_ALL, $glang . '.UTF-8'); // now just get watched page changes for the user... $c = new Criteria(); $c->addJoin("thread_id", "forum_thread.thread_id"); $c->addJoin("thread_id", "watched_forum_thread.thread_id"); $c->addJoin("user_id", "ozone_user.user_id"); $c->add("watched_forum_thread.user_id", $user->getUserId()); $c->addOrderDescending("post_id"); $c->setLimit(30); $posts = DB_ForumPostPeer::instance()->select($c); $channel['title'] = _('Wikidot.com watched forum discussions for user') . ' "' . $user->getNickName() . '"'; $channel['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/watched-forum"; $items = array(); foreach ($posts as $post) { $thread = $post->getForumThread(); $site = $post->getSite(); $item = array(); $item['title'] = $post->getTitle() . ' (' . _('on site') . ' "' . htmlspecialchars($site->getName()) . '")'; $item['link'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '#post-' . $post->getPostId(); $item['guid'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '#post-' . $post->getPostId(); $item['date'] = date('r', $post->getDatePosted()->getTimestamp()); $content = $post->getText(); $content = preg_replace(';(<.*?)(src|href)="/([^"]+)"([^>]*>);si', '\\1\\2="http://' . $site->getDomain() . '/\\3"\\4', $content); $content = preg_replace(';<script\\s+[^>]+>.*?</script>;is', '', $content); $content = preg_replace(';(<[^>]*\\s+)on[a-z]+="[^"]+"([^>]*>);si', '\\1 \\2', $content); // add extra info. $content .= '<br/><hr/>'; $content .= _('Site') . ': <a href="http://' . $site->getDomain() . '">' . htmlspecialchars($site->getName()) . '</a><br/>'; $content .= _('Forum category') . ': <a href="http://' . $site->getDomain() . '/forum/c-' . $thread->getCategoryId() . '">' . htmlspecialchars($thread->getForumCategory()->getName()) . '</a><br/>'; $content .= _('Forum thread') . ': <a href="http://' . $site->getDomain() . '/forum/t-' . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '">' . htmlspecialchars($thread->getTitle()) . '</a><br/>'; $content .= _('Author of the post') . ': ' . WDRenderUtils::renderUser($post->getUserOrString()) . '<br/>'; $item['content'] = $content; if ($post->getUserId() > 0) { $item['authorUserId'] = $post->getUserId(); $user = $post->getUser(); $item['author'] = $user->getNickName(); } else { $item['author'] = $post->getUserString(); } $items[] = $item; } $runData->contextAdd("channel", $channel); $runData->contextAdd("items", $items); }
public function build($runData) { $site = $runData->getTemp("site"); $c = new Criteria(); $c->addJoin("page_id", "page.page_id"); $c->addJoin("user_id", "ozone_user.user_id"); $c->add("page.site_id", $site->getSiteId()); $c->addOrderDescending("page_revision.revision_id"); $c->setLimit(30); $revisions = DB_PageRevisionPeer::instance()->select($c); $channel['title'] = _('Recent page changes from site') . ' "' . htmlspecialchars($site->getName()) . '" (a Wikidot site)'; $channel['link'] = "http://" . $site->getDomain(); $items = array(); foreach ($revisions as $rev) { $page = $rev->getPage(); $item = array(); $item['link'] = 'http://' . $site->getDomain() . '/' . $page->getUnixName(); $desc = ''; $flags = array(); if ($rev->getFlagText()) { $flags[] = _("source change"); } if ($rev->getFlagTitle()) { $flags[] = _("title change"); } if ($rev->getFlagFile()) { $flags[] = _("file action"); } if ($rev->getFlagRename()) { $flags[] = _("page move/rename"); } if ($rev->getFlagMeta()) { $flags[] = _("metadata changed"); } if ($rev->getFlagNew()) { $flags[] = _("new page"); } $item['title'] = '"' . $page->getTitleOrUnixName() . '" - ' . implode(', ', $flags); $desc = ''; $desc .= _('Page') . ': <a href="http://' . $site->getDomain() . '/' . $page->getUnixName() . '">' . htmlspecialchars($page->getTitle()) . '</a> (' . $page->getUnixName() . ')<br/>'; $desc .= _('Current revision number') . ': ' . $rev->getRevisionNumber() . '<br/>'; $desc .= _('Date changed') . ': ' . date('r', $rev->getDateLastEdited()->getTimestamp()) . '<br/>'; $desc .= _('Change type') . ': ' . implode(', ', $flags) . '<br/>'; if ($rev->getComments()) { $desc .= _('Change comments') . ': ' . htmlspecialchars($rev->getComments()) . '<br/>'; } $desc .= _('By') . ': ' . WDRenderUtils::renderUser($rev->getUserOrString()) . '<br/>'; $desc .= '<br/>' . _('Page content preview') . ': <br/>' . $page->getPreview(); $item['description'] = $desc; $item['content'] = $desc; $item['guid'] = $item['link'] . "#revision-" . $rev->getRevisionId(); $item['date'] = date('r', $rev->getDateLastEdited()->getTimestamp()); $content = ''; $items[] = $item; } $runData->contextAdd("channel", $channel); $runData->contextAdd("items", $items); }
public function build($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $categoryIds = $pl->getParameterValue("category"); $limit = $pl->getParameterValue("limit"); $offset = $pl->getParameterValue("offset"); if ($limit == null) { $limit = 20; } if ($categoryIds === null) { throw new ProcessException(_('No forum category has been specified. Please use attribute category="id" where id is the index number of the category.'), "no_category"); } if (strlen($categoryIds) > 90) { throw new ProcessException(_("Category string too long."), "max_categories"); } $cats = preg_split('/[,;] ?/', $categoryIds); $ccat = new Criteria(); $categories = array(); if (count($cats) > 20) { throw new ProcessException(_("Maximum number of categories exceeded."), "max_categories"); } foreach ($cats as $categoryId) { if ($categoryId === null || !is_numeric($categoryId)) { throw new ProcessException(_('Problem parsing attribute "category".'), "no_category"); } $category = DB_ForumCategoryPeer::instance()->selectByPrimaryKey($categoryId); if ($category == null) { throw new ProcessException(_('Requested forum category does not exist.'), "no_category"); } if ($category->getSiteId() !== $site->getSiteId()) { $fSite = DB_SitePeer::instance()->selectByPrimaryKey($category->getSiteId()); if ($fSite->getPrivate()) { throw new ProcessException(_('The requested category belongs to a private site.'), "no_category"); } } $category->setTemp("group", $category->getForumGroup()); $categories[$category->getCategoryId()] = $category; $ccat->addOr("category_id", $category->getCategoryId()); } $c = new Criteria(); $c->addCriteriaAnd($ccat); $c->addOrderDescending("thread_id"); $c->setLimit($limit, $offset); $threads = DB_ForumThreadPeer::instance()->select($c); $format = $pl->getParameterValue("module_body"); if ($format == null || $format == '') { $format = "" . "+ %%linked_title%%\n\n" . _("by") . " %%author%% %%date|%O ago (%e %b %Y, %H:%M %Z)%%\n\n" . "%%content%%\n\n%%comments%% | " . _("category") . ": %%category%%"; } // process the format and create the message template $wt = new WikiTransformation(); $wt->setMode("feed"); $template = $wt->processSource($format); $template = preg_replace('/<p\\s*>\\s*(%%((?:short)|(?:description)|(?:summary)|(?:content)|(?:long)|(?:body)|(?:text))%%)\\s*<\\/\\s*p>/smi', "<div>\\1</div>", $template); $items = array(); foreach ($threads as $thread) { $post = $thread->getFirstPost(); if (!$post) { continue; } $b = $template; $b = str_ireplace("%%title%%", htmlspecialchars($thread->getTitle()), $b); $b = preg_replace("/%%((linked_title)|(title_linked))%%/i", preg_quote_replacement('<a href="/forum/t-' . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '">' . htmlspecialchars($thread->getTitle()) . '</a>'), $b); $b = str_ireplace("%%author%%", WDRenderUtils::renderUser($thread->getUserOrString(), array("image" => true)), $b); $dateString = '<span class="odate">' . $thread->getDateStarted()->getTimestamp() . '|%e %b %Y, %H:%M %Z|agohover</span>'; $b = str_ireplace('%%date%%', $dateString, $b); $b = preg_replace('/%%date\\|(.*?)%%/i', '<span class="odate">' . preg_quote_replacement($thread->getDateStarted()->getTimestamp()) . '|\\1</span>', $b); $b = str_ireplace("%%comments%%", '<a href="/forum/t-' . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '">' . _('Comments') . ': ' . ($thread->getNumberPosts() - 1) . '</a>', $b); $b = str_ireplace("%%link%%", '/forum/t-' . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle(), $b); $category = $categories[$thread->getCategoryId()]; $b = str_ireplace("%%category%%", '<a href="/forum/c-' . $category->getCategoryId() . '/' . $category->getUnixifiedName() . '">' . htmlspecialchars($category->getTemp("group")->getName() . " / " . $category->getName()) . '</a>', $b); $b = preg_replace("/%%((description)|(short)|(summary))%%/i", preg_quote_replacement(htmlspecialchars($thread->getDescription())), $b); $b = preg_replace("/%%((body)|(text)|(long)|(content))%%/i", preg_quote_replacement($post->getText()), $b); $items[] = $b; } $runData->contextAdd("items", $items); // post a feed??? $flabel = WDStringUtils::toUnixName($pl->getParameterValue("feed")); $page = $runData->getTemp("page"); if ($flabel && $page) { $ftitle = trim($pl->getParameterValue("feedTitle")); if ($ftitle == '') { $ftitle = $site->getName() . " feed"; } $fdescription = $pl->getParameterValue("feedDescription"); $fcats = trim($categoryIds); $parmhash = crc32($ftitle . " " . $fcats); // first check the memcache!!! to avoid db connection. // get the feed object $c = new Criteria(); $c->add("page_id", $page->getPageId()); $c->add("label", $flabel); $feed = DB_FrontForumFeedPeer::instance()->selectOne($c); if ($feed == null) { // create the feed $feed = new DB_FrontForumFeed(); $feed->setLabel($flabel); $feed->setTitle($ftitle); $feed->setCategories($fcats); $feed->setPageId($page->getPageId()); $feed->setDescription($fdescription); $feed->setSiteId($site->getSiteId()); $feed->save(); } else { // check hash if ($feed->getParmhash() != $parmhash) { $feed->setTitle($ftitle); $feed->setCategories($fcats); $feed->setDescription($fdescription); $feed->save(); } } // and the feed url is: $feedUrl = "/feed/front/" . $page->getUnixName() . "/" . $flabel . ".xml"; $this->vars['feedUrl'] = $feedUrl; $this->vars['feedTitle'] = $ftitle; $this->vars['feedLabel'] = $flabel; // put a link into text $runData->contextAdd("feedUri", $feedUrl); } }
/** * Wikidot - free wiki collaboration software * Copyright (c) 2008, Wikidot Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * For more information about licensing visit: * http://www.wikidot.org/license * * @category Wikidot * @package Wikidot * @version $Id$ * @copyright Copyright (c) 2008, Wikidot Inc. * @license http://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License */ function smarty_function_printuser($params, &$smarty) { $user = $params['user']; return WDRenderUtils::renderUser($user, $params); }