public function build($runData) { $pl = $runData->getParameterList(); $title = $pl->getParameterValue("title"); $description = trim($pl->getParameterValue("description")); $source = trim($pl->getParameterValue("source")); if ($source == null || $source == '') { throw new ProcessException(_("Post is empty."), "post_empty"); } $wt = new WikiTransformation(); $wt->setMode('post'); $body = $wt->processSource($source); $post = new DB_ForumPost(); $post->setText($body); $post->setTitle($title); $post->setDatePosted(new ODate()); // now set user_id, user_string $userId = $runData->getUserId(); if ($userId == null) { $userString = $runData->createIpString(); } if ($userId) { $post->setUserId($userId); } else { $post->setUserId(0); $post->setUserString($userString); } $runData->contextAdd("post", $post); }
public function build($runData) { $userId = $runData->getUserId(); $pl = $runData->getParameterList(); $messageId = $pl->getParameterValue("message_id"); $message = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($messageId); if ($message->getFromUserId() != $userId) { throw new ProcessException(_("Error selecting message."), "no_message"); } $wt = new WikiTransformation(); $wt->setMode('pm'); $message->setBody($wt->processSource($message->getBody())); $runData->contextAdd("message", $message); // get next & previous message $messageId = $message->getMessageId(); $c = new Criteria(); $c->add("from_user_id", $userId); $c->add("message_id", $messageId, ">"); $c->add("flag", 2); $c->addOrderAscending("message_id"); $newerMessage = DB_PrivateMessagePeer::instance()->selectOne($c); $c = new Criteria(); $c->add("from_user_id", $userId); $c->add("message_id", $messageId, "<"); $c->add("flag", 2); $c->addOrderDescending("message_id"); $olderMessage = DB_PrivateMessagePeer::instance()->selectOne($c); $runData->contextAdd("newerMessage", $newerMessage); $runData->contextAdd("olderMessage", $olderMessage); }
public function render($runData) { $sites = $runData->getParameterList()->getParameterValue("sites"); // split sites by ", " $ss = preg_split('/,\\s*/', $sites); $out = ''; $imageUrl = "/common--images/social/"; if ($sites && $sites != "") { foreach ($ss as $siteName) { if ($this->sites[strtolower($siteName)]) { $ss2[] = $this->sites[$siteName]; } } } else { $ss2 = $this->sites; } // render $wikiSite = $runData->getTemp("site"); $page = $runData->getTemp("page"); $pageTitle = $wikiSite->getName(); if ($page) { if ($page->getTitle() != '') { $pageTitle .= ': ' . $page->getTitle(); } $pageName = $page->getUnixName(); } $permalink = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $out = ''; $id = 'social' . rand(1, 100000); $out .= '<span id="' . $id . '">'; foreach ($ss2 as $key => $site) { $url = $site['url']; $url = str_replace('PERMALINK', urlencode($permalink), $url); $url = str_replace('BLOGNAME', urlencode($wikiSite->getName()), $url); $out .= '<a href="' . $url . '" style="margin: 0 2px" title="' . $site['name'] . '" ' . ($site['onclick'] ? ' onclick="' . $site['onclick'] . '"' : ''); if (isset($site['onclick'])) { $out .= ' onclick="' . $site['onclick'] . '" '; } $out .= '>'; $out .= '<img src="' . $imageUrl . $site['favicon'] . '" alt="' . $site['name'] . '"/></a>'; } $out .= '</span>'; // ok, now fix the d.... title $out .= '<script type="text/javascript"> var socialspan = $("' . $id . '"); var els = socialspan.getElementsByTagName("a"); for(var i=0;i<els.length;i++){ els[i].href = els[i].href.replace("TITLE", encodeURIComponent(document.title)); } </script>'; // purify??? $wt = new WikiTransformation(); $out = $wt->purifyHtml($out); return $out; }
public function build($runData) { $revisionId = $runData->getParameterList()->getParameterValue("revision_id"); $revision = DB_PageRevisionPeer::instance()->selectByPrimaryKey($revisionId); if ($revision == null) { throw new ProcessException(_("Revision error"), "revision_error"); } $metadata = $revision->getMetadata(); $source = $revision->getSourceText(); $tr = new WikiTransformation(); $content = $tr->processSource($source); $runData->contextAdd("pageContent", $content); $runData->contextAdd("revision", $revision); $runData->contextAdd("metadata", $metadata); $runData->ajaxResponseAdd("title", $metadata->getTitle()); }
/** * Creates a section mapping between the source code and the compiled code. * Using this mapping one can easily find source lines corresponding to * particular section toc[0-9]+ in the compiled content. */ public static function sectionMapping($source) { // alter all of the headings in the source $s1 = explode("\n", $source); for ($i = 0; $i < count($s1); $i++) { $s1[$i] = preg_replace('/^(\\+{1,6}) (.*)/m', '${1} stoc' . $i, $s1[$i]); } $source = implode("\n", $s1); $totalLines = count($s1); $wt = new WikiTransformation(); // strip the wiki processing $wt->wiki->rules = array('Include', 'Prefilter', 'Delimiter', 'Code', 'Raw', 'Modulepre', 'Module', 'Module654', 'Comment', 'Math', 'Heading'); $compiled = $wt->processSource($source); // now find all the occurences of headings in the compiled content. $pattern = '/<h([1-6]) id="toc([0-9]+)"[^>]*?>(?:\\s*<span>)?\\s*stoc([0-9]+)/'; preg_match_all($pattern, $compiled, &$matches, PREG_SET_ORDER); // array of the form: // key: sequential // value: array(toc_id,level,start, end) - start&end lines of the section $map0 = array(); foreach ($matches as $m) { $map0[] = array('id' => $m[2], 'level' => $m[1], 'start' => $m[3]); } // now fix it and include ends (& levels of course). $map = array(); for ($key = 0; $key < count($map0); $key++) { $m = $map0[$key]; $mlevel = $m['level']; // look for an end $endI = null; for ($i = $key + 1; $i < count($map0); $i++) { if ($map0[$i]['level'] <= $mlevel) { $endI = $map0[$i]['start'] - 1; break; } } if ($endI == null) { $endI = $totalLines - 1; } $mm = array(); $mm['level'] = $m['level']; $mm['start'] = $m['start']; $mm['end'] = $endI; $map[$m['id']] = $mm; } return $map; }
public function build($runData) { $pl = $runData->getParameterList(); $source = $pl->getParameterValue("source"); $subject = $pl->getParameterValue("subject"); $toUserId = $pl->getParameterValue("to_user_id"); $wt = new WikiTransformation(); $wt->setMode('pm'); $result = $wt->processSource($source); $body = $result; $message = new DB_PrivateMessage(); $message->setFromUserId($runData->getUserId()); $message->setToUserId($toUserId); $message->setBody($body); $message->setSubject($subject); $runData->contextAdd("message", $message); }
public function build($runData) { $pl = $runData->getParameterList(); $source = $pl->getParameterValue("source"); $mode = $pl->getParameterValue("mode"); $site = $runData->getTemp("site"); $pageId = $pl->getParameterValue("pageId"); if ($pageId) { $runData->setTemp("pageId", $pageId); $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId); if ($page == null || $page->getSiteId() != $site->getSiteId()) { throw new ProcessException(_("Error selecting the page.")); } $runData->setTemp("page", $page); } $wt = new WikiTransformation(); $wt->setPageUnixName($pl->getParameterValue("page_unix_name")); /* if($mode == "append"){ // combine current source and submitted source $pageId = $pl->getParameterValue("page_id"); $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId); $source = $page->getSource()."\n\n[[div id=\"append-preview-div\"]]\n".$source."\n[[/div]]\n"; } */ /* Get the category and apply the "live template" to the source. */ $pageUnixName = $pl->getParameterValue("page_unix_name"); if (strpos($pageUnixName, ":") != false) { $tmp0 = explode(':', $pageUnixName); $categoryName = $tmp0[0]; } else { $categoryName = "_default"; } $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId()); /* Look for the template (if any). */ if (!preg_match(';(:|^)_;', $pageUnixName)) { $templatePage = DB_PagePeer::instance()->selectByName($site->getSiteId(), ($categoryName == '_default' ? '' : $categoryName . ':') . '_template'); if ($templatePage) { $source = $wt->assemblyTemplate($source, $templatePage->getSource()); } } $result = $wt->processSource($source); $body = $result; $runData->contextAdd("body", $body); $runData->ajaxResponseAdd("title", $pl->getParameterValue("title")); }
public function __construct($initialize = true) { if ($initialize) { self::$internalLinksExist = array(); self::$internalLinksNotExist = array(); self::$externalLinks = array(); $this->resetWiki(); } }
public function build($runData) { $pl = $runData->getParameterList(); $revisionId = $pl->getParameterValue("revisionId"); $site = $runData->getTemp("site"); if ($revisionId == null || !is_numeric($revisionId)) { throw new ProcessException(_("No revision specified."), "no_post"); } $revision = DB_ForumPostRevisionPeer::instance()->selectByPrimaryKey($revisionId); if ($revision == null) { throw new ProcessException(_("No revision specified."), "no_post"); } $runData->ajaxResponseAdd("title", $revision->getTitle()); $source = $revision->getText(); $wt = new WikiTransformation(); $body = $wt->processSource($source); $runData->ajaxResponseAdd("content", $body); $runData->ajaxResponseAdd("postId", $revision->getPostId()); }
public function sendEvent($runData) { $pl = $runData->getParameterList(); $source = $pl->getParameterValue("source"); $subject = $pl->getParameterValue("subject"); if ($subject == null || $subject === '') { $subject = "(No subject)"; } $db = Database::connection(); $db->begin(); $toUserId = $pl->getParameterValue("to_user_id"); // TODO: validation. also check if user exists $toUser = DB_OzoneUserPeer::instance()->selectByPrimaryKey($toUserId); if ($toUser == null) { $message = _("The recipient does not exist."); throw new ProcessException($message, "no_recipient"); } // check if allowed $fromUser = $runData->getUser(); WDPermissionManager::instance()->hasPmPermission($fromUser, $toUser); // compile content $wt = new WikiTransformation(); $wt->setMode('pm'); $body = $wt->processSource($source); $message = new DB_PrivateMessage(); $message->setDate(new ODate()); $message->setFromUserId($runData->getUserId()); $message->setToUserId($toUserId); $message->setSubject($subject); $message->setBody($body); $message->setFlag(0); // 0 for inbox $message->save(); NotificationMaker::instance()->privateMessageNotification($message); //also make a copy for "sent" folder $message->setNew(true); $message->setMessageId(null); $message->setFlag(1); //1 for sent $message->save(); $db->commit(); }
public function renderView() { $wt = new WikiTransformation(); $wt->setMode('pm'); return $wt->processSource($this->field['value']); }
public function build($runData) { $pl = $runData->getParameterList(); $src = $pl->getParameterValue("src", "MODULE"); $limit = $pl->getParameterValue("limit", "MODULE"); $offset = $pl->getParameterValue("offset", "MODULE"); if ($src == null) { throw new ProcessException(_('No feed source specified ("src" element missing).'), "no_source"); } $feedArray = array(); if (strpos($src, ';') !== false) { // multiple sources!!! $itemArray = array(); $urls = preg_split('/;\\s*/', $src); foreach ($urls as $url) { // get the feed!!! try { $mrss = new MagpieFeed(); //TODO: check if $src is a valid address? $rss = $mrss->fetch($url); $items = $rss->items; $feedIdx = array_push($feedArray, $rss) - 1; for ($i = 0; $i < count($items); $i++) { $items[$i]['feed_idx'] = $feedIdx; } $itemArray = array_merge($itemArray, $items); } catch (Exception $e) { throw new ProcessException(sprintf(_('Error processing the feed "%s". The feed can not be accessed or contains errors. '), $url), "feed_failed"); } } // now order by date... $ordertmp = array(); foreach ($itemArray as $key => &$item) { // fix dates $timestamp = MagpieFeed::getUnixTimestamp($item); $ordertmp[$key] = $timestamp; } // sort. arsort($ordertmp, SORT_NUMERIC); $itemArray2 = array(); foreach ($ordertmp as $key => $dummy) { $itemArray2[] = $itemArray[$key]; } $itemArray = $itemArray2; } else { // get the feed!!! try { $mrss = new MagpieFeed(); //TODO: check if $src is a valid address? $rss = $mrss->fetch($src); } catch (Exception $e) { throw new ProcessException(sprintf(_('Error processing the feed "%s". The feed can not be accessed or contains errors. '), $src), "feed_failed"); } $items = $rss->items; $feedIdx = array_push($feedArray, $rss); for ($i = 0; $i < count($items); $i++) { $items[$i]['feedl_idx'] = $feedIdx; } $itemArray = $items; } $this->tmpFeedArray = $feedArray; $format = $pl->getParameterValue("module_body"); if ($format == null || $format == '') { $format = "" . "++ %%linked_title%%\n\n" . "%%date%%\n\n" . "%%description%%"; } // process the format and create the message template $wt = new WikiTransformation(); $wt->setMode("feed"); $template = $wt->processSource($format); // fix template $template = preg_replace('/<p\\s*>\\s*(%%((?:short)|(?:description)|(?:summary)|(?:content)|(?:long)|(?:body))%%)\\s*<\\/\\s*p>/smi', "<div>\\1</div>", $template); $fitems = array(); // formatted items // now for each of the feed items fill the template foreach ($itemArray as $item) { $description = $item['description']; if ($description === null) { $description = $item['summary']; } $full = $item['content']['encoded']; if ($full === null) { $full = $item['atom_content']; } if ($description === null && $full) { // make a shorter version????? TODO! $description = substr(strip_tags($full), 0, 500); } if ($full == null && $description) { $full = $description; } // fix dates $item['timestamp'] = MagpieFeed::getUnixTimestamp($item); if ($item['timestamp'] != '') { $dateString = '<span class="odate">' . $item['timestamp'] . '|%e %b %Y, %H:%M %Z|agohover</span>'; } else { $dateString = ''; } $b = $template; $b = str_ireplace('%%title%%', strip_tags($item['title']), $b); $b = preg_replace('/%%((linked_title)|(title_linked))%%/i', preg_quote_replacement('<a href="' . $item['link'] . '">' . strip_tags($item['title']) . '</a>'), $b); // channel data $channel = $feedArray[$item['feed_idx']]->channel; $b = str_replace('%%channel_title%%', $channel['title'], $b); $b = preg_replace('/(%%linked_channel_title%%)|(%%channel_title_linked%%)/', preg_quote_replacement('<a href="' . $channel['link'] . '">' . htmlspecialchars($channel['title']) . '</a>'), $b); $b = str_ireplace('%%link%%', $item['link'], $b); $b = preg_replace('/%%((short)|(description)|(summary))%%/i', preg_quote_replacement($description), $b); $b = preg_replace('/%%((content)|(long)|(body))%%/i', preg_quote_replacement($full), $b); $b = str_ireplace('%%date%%', $dateString, $b); $b = preg_replace('/%%date\\|(.*?)%%/i', '<span class="odate">' . $item['timestamp'] . '|\\1</span>', $b); // start removing ads block!!! // custom tags try { $this->tmpItem = $item; $b = preg_replace_callback("/%%custom[_ ]([a-zA-Z0-9_:\\/]*)%%/", array(&$this, 'processCustomTag'), $b); } catch (Exception $e) { echo $e->getMessage(); } // some cleanup // remove ids $b = $this->safeString($b); $b = WikiTransformation::purifyHTML($b); if ($channel['title'] == "Slashdot") { // remove ads //$p = ';<p>\s*<a href="http://rss.slashdot.org/~a/[^"]*"><img src="http://rss.slashdot.org/~a/[^"]*" border="0" />\s*</a>\s*' . $p = ';<p>\\s*<a href="http://rss.slashdot.org/~a/[^"]*"><img src="http://rss.slashdot.org/~a/[^"]*" border="0" />\\s*</a>\\s*' . '</p><img src="http://rss.slashdot.org/[^"]*"\\s*/>;smi'; $b = preg_replace($p, '', $b); } $fitems[] = $b; } if ($limit !== null && is_numeric($limit) || $offset !== null && is_numeric($offset)) { if ($offset == null) { $offset = 0; } if ($limit !== null) { $fitems = array_slice($fitems, $offset, $limit); } else { $fitems = array_slice($fitems, $offset); } } $runData->contextAdd("format", $template); $runData->contextAdd("items", $fitems); $runData->contextAdd("src", $src); $runData->contextAdd("rss", $rss); }
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); } }
public function build($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $categoryName = $this->_readParameter(array('category', 'categories'), false); $categoryName = strtolower($categoryName); $order = $this->_readParameter("order", true); $limit = $this->_readParameter("limit", true); $perPage = $this->_readParameter("perPage", true); $skipCurrent = $this->_readParameter('skipCurrent'); if ($skipCurrent && ($skipCurrent == 'yes' || $skipCurrent == 'true')) { $skipCurrent = true; } else { $skipCurrent = false; } $pageUnixName = $runData->getTemp('pageUnixName'); if (!$pageUnixName) { $pageUnixName = $pl->getParameterValue('page_unix_name'); // from preview } $categories = array(); $categoryNames = array(); if ($categoryName != '*') { if (!$categoryName) { /* No category name specified, use the current category! */ if (strpos($pageUnixName, ":") != false) { $tmp0 = explode(':', $pageUnixName); $categoryName = $tmp0[0]; } else { $categoryName = "_default"; } } foreach (preg_split('/[,;\\s]+?/', $categoryName) as $cn) { $category = DB_CategoryPeer::instance()->selectByName($cn, $site->getSiteId()); if ($category) { $categories[] = $category; $categoryNames[] = $category->getName(); } } if (count($categories) == 0) { throw new ProcessException('The requested categories do not (yet) exist.'); } } //if(count($categories) == 0){ // throw new ProcessException(_("The category can not be found.")); //} // now select pages according to the specified criteria $c = new Criteria(); $c->add("site_id", $site->getSiteId()); if (count($categories) > 0) { $ccat = new Criteria(); foreach ($categories as $cat) { $ccat->addOr('category_id', $cat->getCategoryId()); } $c->addCriteriaAnd($ccat); } $c->add('unix_name', '(^|:)_', '!~'); /* Handle magic previousBy/nextBy keywords */ $previousBy = $this->_readParameter('previousBy', true); $nextBy = $this->_readParameter('nextBy', true); if ($previousBy || $nextBy) { if ($refPage = $runData->getTemp('page')) { $refPageId = $refPage->getPageId(); $refPageTitle = $refPage->getTitle() . ' ... ' . $refPage->getUnixName(); if ($previousBy == 'page_id') { $c->add('page_id', $refPageId, '<'); } elseif ($nextBy == 'page_id') { $c->add('page_id', $refPageId, '>'); } elseif ($previousBy == 'title') { $c->add("title || ' ... ' || unix_name", $refPageTitle, '<'); } elseif ($nextBy == 'title') { $c->add("title || ' ... ' || unix_name", $refPageTitle, '>'); } } else { $c->add('page_id', 0); // this should be simply never; } } /* Handle tags! */ $tagString = $this->_readParameter(array('tag', 'tags'), true); if ($tagString) { /* Split tags. */ $tags = preg_split(';[\\s,\\;]+;', $tagString); $tagsAny = array(); $tagsAll = array(); $tagsNone = array(); foreach ($tags as $t) { if (substr($t, 0, 1) == '+') { $tagsAll[] = substr($t, 1); } elseif (substr($t, 0, 1) == '-') { $tagsNone[] = substr($t, 1); } elseif ($t == '=') { /* It means: any tags of the current page. */ if ($runData->getTemp('page')) { $pageId = $runData->getTemp('page')->getPageId(); $co = new Criteria(); $co->add("page_id", $pageId); $co->addOrderAscending("tag"); $tagso = DB_PageTagPeer::instance()->select($co); foreach ($tagso as $to) { $tagsAny[] = $to->getTag(); } if (count($tagsAny) == 0) { /* * If someone uses the '=' tag, the line below guarantees that * only pages that DO have tags and share at least one similar tag with the * current page are listed. */ $tagsAny[] = ' '; } } } else { $tagsAny[] = $t; } } /* * One more condition: if $tagString is equal to "=" only (which means "similar pages by tags), * it is reasonable to drop current page from being displayed. */ if ($tagString == '=') { $skipCurrent = true; } /* Create extra conditions to the SELECT */ /* ANY */ if (count($tagsAny) > 0) { $t = array(); foreach ($tagsAny as $tag0) { $t[] = 'tag = \'' . db_escape_string($tag0) . '\''; } $tagQuery = "SELECT count(*) FROM page_tag " . "WHERE page_tag.page_id=page.page_id " . "AND (" . implode(' OR ', $t) . ")"; $c->add('(' . $tagQuery . ')', 1, '>='); } /* ALL */ if (count($tagsAll) > 0) { $t = array(); foreach ($tagsAll as $tag0) { $t[] = 'tag = \'' . db_escape_string($tag0) . '\''; } $tagQuery = "SELECT count(*) FROM page_tag " . "WHERE page_tag.page_id=page.page_id " . "AND (" . implode(' OR ', $t) . ")"; $c->add('(' . $tagQuery . ')', count($tagsAll)); } /* NONE */ if (count($tagsNone) > 0) { $t = array(); foreach ($tagsNone as $tag0) { $t[] = 'tag = \'' . db_escape_string($tag0) . '\''; } $tagQuery = "SELECT count(*) FROM page_tag " . "WHERE page_tag.page_id=page.page_id " . "AND (" . implode(' OR ', $t) . ")"; $c->add('(' . $tagQuery . ')', 0); } } if ($skipCurrent && $runData->getTemp('page') && $runData->getTemp('page')->getPageId()) { $c->add('page_id', $runData->getTemp('page')->getPageId(), '!='); } /* Handle date ranges. */ $date = $this->_readParameter("date", true); $dateA = array(); if (preg_match(';^[0-9]{4}$;', $date)) { $dateA['year'] = $date; } if (preg_match(';^[0-9]{4}\\.[0-9]{1,2}$;', $date)) { $dateS = explode('.', $date); $dateA['year'] = $dateS[0]; $dateA['month'] = $dateS[1]; } if (isset($dateA['year'])) { $c->add('EXTRACT(YEAR FROM date_created)', $dateA['year']); } if (isset($dateA['month'])) { $c->add('EXTRACT(MONTH FROM date_created)', $dateA['month']); } /* Handle date "last X day(s)/week(s)/month(s)" */ $m = array(); if (preg_match(';^last (?:([1-9][0-9]*) )?(day|week|month)s?$;', $date, $m)) { $dateObj = new ODate(); $n = $m[1]; if (!$n) { $n = 1; } $unit = $m[2]; $convarray = array('day' => 86400, 'week' => 604800, 'month' => 2592000); $dateObj->subtractSeconds($n * $convarray[$unit]); $c->add('date_created', $dateObj, '>'); } /* Handle pagination. */ if (!$perPage || !preg_match(';^[0-9]+$;', $perPage)) { $perPage = 20; } if ($limit && preg_match(';^[0-9]+$;', $limit)) { $c->setLimit($limit); // this limit has no effect on count(*) !!! } else { $limit = null; } $pageNo = $pl->getParameterValue(($this->_parameterUrlPrefix ? $this->_parameterUrlPrefix . '_' : '') . "p"); if ($pageNo == null || !preg_match(';^[0-9]+$;', $pageNo)) { $pageNo = 1; } $co = DB_PagePeer::instance()->selectCount($c); if ($limit) { $co = min(array($co, $limit)); } $totalPages = ceil($co / $perPage); if ($pageNo > $totalPages) { $pageNo = $totalPages; } $offset = ($pageNo - 1) * $perPage; if ($limit) { $newLimit = min(array($perPage, $limit - $offset)); } else { $newLimit = $perPage; } $c->setLimit($newLimit, $offset); $runData->contextAdd("totalPages", $totalPages); $runData->contextAdd("currentPage", $pageNo); $runData->contextAdd("count", $co); $runData->contextAdd("totalPages", $totalPages); $runData->contextAdd('parameterUrlPrefix', $this->_parameterUrlPrefix); /* Pager's base url */ $url = $_SERVER['REQUEST_URI']; if (($url == '' || $url == '/') && isset($pageUnixName)) { $url = '/' . $pageUnixName; } $pref = ''; if ($this->_parameterUrlPrefix) { $pref = $this->_parameterUrlPrefix . '_'; } $url = preg_replace(';(/' . $pref . 'p/[0-9]+)|$;', '/' . $pref . 'p/%d', $url, 1); $runData->contextAdd("pagerUrl", $url); switch ($order) { case 'dateCreatedAsc': $c->addOrderAscending('page_id'); break; case 'dateEditedDesc': $c->addOrderDescending('date_last_edited'); break; case 'dateEditedAsc': $c->addOrderAscending('date_last_edited'); break; case 'titleDesc': $c->addOrderDescending("COALESCE(title, unix_name)"); break; case 'titleAsc': $c->addOrderAscending("COALESCE(title, unix_name)"); break; case 'ratingAsc': $c->addOrderAscending('rate'); break; case 'ratingDesc': $c->addOrderDescending('rate'); break; /* case 'commentsAsc': $c->addJoin('thread_id', 'forum_thread.thread_id', 'LEFT'); $c->addOrderAscending('number_posts'); break; case 'commentsDesc': $c->addOrderDescending('number_posts'); break; */ /* case 'commentsAsc': $c->addJoin('thread_id', 'forum_thread.thread_id', 'LEFT'); $c->addOrderAscending('number_posts'); break; case 'commentsDesc': $c->addOrderDescending('number_posts'); break; */ case 'pageLengthAsc': $c->addJoin('source_id', 'page_source.source_id'); $c->addOrderAscending('char_length(page_source.text)'); break; case 'pageLengthDesc': $c->addJoin('source_id', 'page_source.source_id'); $c->addOrderDescending('char_length(page_source.text)'); break; default: case 'dateCreatedDesc': $c->addOrderDescending('page_id'); break; } $pages = DB_PagePeer::instance()->select($c); /* Process... */ $format = $this->_readParameter("module_body"); if (!$format) { $format = "" . "+ %%linked_title%%\n\n" . _("by") . " %%author%% %%date|%O ago (%e %b %Y, %H:%M %Z)%%\n\n" . "%%short%%"; } //$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); //$template = $format; $items = array(); $separation = $this->_readParameter("separate"); if ($separation == 'no' || $separation == 'false') { $separation = false; } else { $separation = true; } foreach ($pages as $page) { $this->_tmpPage = $page; $title = $page->getTitle(); $source = $page->getSource(); $title = str_replace(array('[', ']'), '', $title); $title = str_replace('%%', "ý", $title); $source = str_replace('%%', "ý", $source); $c = new Criteria(); $c->add('revision_id', $page->getRevisionId()); $lastRevision = DB_PageRevisionPeer::instance()->selectOne($c); //$c = new Criteria(); //$c->add('page_id', $page->getPageId()); //$c->addOrderAscending('revision_id'); //$firstRevision = DB_PageRevisionPeer::instance()->selectOne($c); $b = $format; /* A series of substitutions. */ $b = str_replace("ý", '', $b); /* %%title%% and similar */ $b = str_replace('%%title%%', $title, $b); $b = preg_replace("/%%((linked_title)|(title_linked))%%/i", preg_quote_replacement('[[[' . $page->getUnixName() . ' | ' . $title . ']]]'), $b); /* %%author%% */ if ($page->getOwnerUserId()) { $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($page->getOwnerUserId()); if ($user->getUserId() > 0) { $userString = '[[*user ' . $user->getNickName() . ']]'; } else { $userString = _('Anonymous user'); } } else { $userString = _('Anonymous user'); } $b = str_ireplace("%%author%%", $userString, $b); $b = str_ireplace("%%user%%", $userString, $b); if ($lastRevision->getUserId()) { $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($lastRevision->getUserId()); if ($user->getUserId() > 0) { $userString = '[[*user ' . $user->getNickName() . ']]'; } else { $userString = _('Anonymous user'); } } else { $userString = _('Anonymous user'); } $b = str_ireplace("%%author_edited%%", $userString, $b); $b = str_ireplace("%%user_edited%%", $userString, $b); /* %%date%% */ $b = preg_replace(';%%date(\\|.*?)?%%;', '%%date|' . $page->getDateCreated()->getTimestamp() . '\\1%%', $b); $b = preg_replace(';%%date_edited(\\|.*?)?%%;', '%%date|' . $page->getDateLastEdited()->getTimestamp() . '\\1%%', $b); /* %%content%% */ $b = preg_replace(';%%((body)|(text)|(long)|(content))%%;i', $source, $b); /* %%content{n}%% */ /* Split the content first. */ $this->_tmpSplitSource = preg_split('/^([=]{4,})$/m', $source); $this->_tmpSource = $source; $b = preg_replace_callback(';%%content{([0-9]+)}%%;', array($this, '_handleContentSubstitution'), $b); /* %%short%% */ $b = preg_replace_callback("/%%((description)|(short)|(summary))%%/i", array($this, '_handleSummary'), $b); $b = preg_replace_callback("/%%first_paragraph%%/i", array($this, '_handleFirstParagraph'), $b); /* %%preview%% */ $b = preg_replace_callback("/%%preview(?:\\(([0-9]+)\\))?%%/i", array($this, '_handlePreview'), $b); /* %%rating%% */ $b = str_ireplace('%%rating%%', $page->getRate(), $b); /* %%comments%% */ $b = preg_replace_callback("/%%comments%%/i", array($this, '_handleComementsCount'), $b); /* %%page_unix_name%% */ $b = str_ireplace('%%page_unix_name%%', $page->getUnixName(), $b); /* %%category%% */ if (strpos($page->getUnixName(), ":") != false) { $tmp0 = explode(':', $page->getUnixName()); $categoryName00 = $tmp0[0]; } else { $categoryName00 = "_default"; } $b = str_ireplace('%%category%%', $categoryName00, $b); /* %%link%% */ $b = str_ireplace('%%link%%', 'http://' . $site->getDomain() . '/' . $page->getUnixName(), $b); /* %%tags%% */ $b = preg_replace_callback("/%%tags%%/i", array($this, '_handleTags'), $b); $b = str_replace("ý", '%%', $b); if ($separation) { $wt = new WikiTransformation(); $wt->setMode("list"); $wt->setPage($page); $b = $wt->processSource($b); $b = "<div class=\"list-pages-item\">\n" . $b . "</div>"; //$b = "[[div class=\"list-pages-item\"]]\n".$b."\n[[/div]]"; } $items[] = trim($b); } if (!$separation) { $prependLine = $this->_readParameter('prependLine'); $appendLine = $this->_readParameter('appendLine'); $wt = new WikiTransformation(); $wt->setMode("list"); $glue = "\n"; $itemsContent = $wt->processSource(($prependLine ? $prependLine . "\n" : '') . implode($glue, $items) . ($appendLine ? "\n" . $appendLine : '')); } else { $itemsContent = implode("\n", $items); } /* * If separation is false, we are not separating the items with double-newlines but rather * with a single newline. This allows to create e.g. list of pages by creating a template: * * %%linked_title%% */ /* Fix dates. */ //$dateString = '<span class="odate">'.$thread->getDateStarted()->getTimestamp().'|%e %b %Y, %H:%M %Z|agohover</span>'; $itemsContent = preg_replace_callback(';%%date\\|([0-9]+)(\\|.*?)?%%;', array($this, '_formatDate'), $itemsContent); $runData->contextAdd("items", $items); $runData->contextAdd("itemsContent", $itemsContent); $runData->contextAdd("details", $details); $runData->contextAdd("preview", $preview); /* Also build an URL for the feed. */ $rssTitle = $this->_readParameter(array('rss', 'rssTitle')); if ($rssTitle !== null) { $url = 'http://' . $site->getDomain() . '/feed/pages'; if (count($categoryNames) > 0) { $url .= '/category/' . urlencode(implode(',', $categoryNames)); } if (isset($tags)) { $url .= '/tags/' . urlencode(implode(',', $tags)); } /* * Ignore date in RSS generation. */ /* if (isset($date)) { $url .= '/date/' . urlencode($date); }*/ if ($order) { $url .= '/order/' . urlencode($order); } //$erss = $pl->getParameterValue('rssEmbed'); //if ($erss == 'no' || $erss == 'false') { // $erss = false; //} else { // $erss = true; //} //$srss = $pl->getParameterValue('rssShow'); //if ($srss == 'no' || $srss == 'false') { // $srss = false; //} else { // $srss = true; //} //$trss = $pl->getParameterValue('rssTitle'); //if ($trss) { // $url .= '/t/' . urlencode($trss); //} $url .= '/t/' . urlencode($rssTitle); //if ($erss) { $this->_vars['rssUrl'] = $url; $this->_vars['rssTitle'] = $rssTitle; //} //if ($srss) { $runData->contextAdd('rssUrl', $url); $runData->contextAdd('rssTitle', $rssTitle); //} } }
private function assemblySource($source, $templateSource, $page = null) { $t = new WikiTransformation(false); return $t->assemblyTemplate($source, $templateSource, $page); }
public function build($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $categoryName = $pl->getParameterValue("category"); $order = $pl->getParameterValue("order"); $limit = $pl->getParameterValue("limit"); $perPage = $pl->getParameterValue("perPage"); $categories = array(); $categoryNames = array(); foreach (preg_split('/[,;\\s]+?/', $categoryName) as $cn) { $category = DB_CategoryPeer::instance()->selectByName($cn, $site->getSiteId()); if ($category) { $categories[] = $category; $categoryNames[] = $category->getName(); } } //if(count($categories) == 0){ // throw new ProcessException(_("The category can not be found.")); //} // now select pages according to the specified criteria $c = new Criteria(); $c->add("site_id", $site->getSiteId()); if (count($categories) > 0) { $ccat = new Criteria(); foreach ($categories as $cat) { $ccat->addOr('category_id', $cat->getCategoryId()); } $c->addCriteriaAnd($ccat); } $c->add('unix_name', '(^|:)_', '!~'); /* Handle tags! */ $tagString = $pl->getParameterValue("tag"); if (!$tagString) { $tagString = $pl->getParameterValue("tags"); } if ($tagString) { /* Split tags. */ $tags = preg_split(';[\\s,\\;]+;', $tagString); $tagsAny = array(); $tagsAll = array(); $tagsNone = array(); foreach ($tags as $t) { if (substr($t, 0, 1) == '+') { $tagsAll[] = substr($t, 1); } elseif (substr($t, 0, 1) == '-') { $tagsNone[] = substr($t, 1); } else { $tagsAny[] = $t; } } /* Create extra conditions to the SELECT */ /* ANY */ if (count($tagsAny) > 0) { $t = array(); foreach ($tagsAny as $tag0) { $t[] = 'tag = \'' . db_escape_string($tag0) . '\''; } $tagQuery = "SELECT count(*) FROM page_tag " . "WHERE page_tag.page_id=page.page_id " . "AND (" . implode(' OR ', $t) . ")"; $c->add('(' . $tagQuery . ')', 1, '>='); } /* ALL */ if (count($tagsAll) > 0) { $t = array(); foreach ($tagsAll as $tag0) { $t[] = 'tag = \'' . db_escape_string($tag0) . '\''; } $tagQuery = "SELECT count(*) FROM page_tag " . "WHERE page_tag.page_id=page.page_id " . "AND (" . implode(' OR ', $t) . ")"; $c->add('(' . $tagQuery . ')', count($tagsAll)); } /* NONE */ if (count($tagsNone) > 0) { $t = array(); foreach ($tagsNone as $tag0) { $t[] = 'tag = \'' . db_escape_string($tag0) . '\''; } $tagQuery = "SELECT count(*) FROM page_tag " . "WHERE page_tag.page_id=page.page_id " . "AND (" . implode(' OR ', $t) . ")"; $c->add('(' . $tagQuery . ')', 0); } } /* Handle date ranges. */ $date = $pl->getParameterValue("date"); $dateA = array(); if (preg_match(';^[0-9]{4};', $date)) { $dateA['year'] = $date; } if (preg_match(';^[0-9]{4}\\.[0-9]{1,2};', $date)) { $dateS = explode('.', $date); $dateA['year'] = $dateS[0]; $dateA['month'] = $dateS[1]; } if (isset($dateA['year'])) { $c->add('EXTRACT(YEAR FROM date_created)', $dateA['year']); } if (isset($dateA['month'])) { $c->add('EXTRACT(MONTH FROM date_created)', $dateA['month']); } /* Handle pagination. */ if (!$perPage || !preg_match(';^[0-9]+$;', $perPage)) { $perPage = 20; } if ($limit && preg_match(';^[0-9]+$;', $perPage)) { $c->setLimit($limit); } $pageNo = $pl->getParameterValue("p"); if ($pageNo == null || !preg_match(';^[0-9]+$;', $pageNo)) { $pageNo = 1; } $co = DB_PagePeer::instance()->selectCount($c); $totalPages = ceil($co / $perPage); if ($pageNo > $totalPages) { $pageNo = $totalPages; } $offset = ($pageNo - 1) * $perPage; $c->setLimit($perPage, $offset); $runData->contextAdd("totalPages", $totalPages); $runData->contextAdd("currentPage", $pageNo); $runData->contextAdd("count", $co); $runData->contextAdd("totalPages", $totalPages); /* Pager's base url */ $url = $_SERVER['REQUEST_URI']; $url = preg_replace(';(/p/[0-9]+)|$;', '/p/%d', $url, 1); $runData->contextAdd("pagerUrl", $url); switch ($order) { case 'dateCreatedAsc': $c->addOrderAscending('page_id'); break; case 'dateEditedDesc': $c->addOrderDescending('date_last_edited'); break; case 'dateEditedAsc': $c->addOrderAscending('date_last_edited'); break; case 'titleDesc': $c->addOrderDescending("COALESCE(title, unix_name)"); break; case 'titleAsc': $c->addOrderAscending("COALESCE(title, unix_name)"); break; default: case 'dateCreatedDesc': $c->addOrderDescending('page_id'); break; } $pages = DB_PagePeer::instance()->select($c); /* Process... */ $format = $pl->getParameterValue("module_body"); if (!$format) { $format = "" . "+ %%linked_title%%\n\n" . _("by") . " %%author%% %%date|%O ago (%e %b %Y, %H:%M %Z)%%\n\n" . "%%content%%\n\n%%comments%%"; } //$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); //$template = $format; $items = array(); foreach ($pages as $page) { $title = $page->getTitle(); $source = $page->getSource(); $item = array(); $item['title'] = $page->getTitle(); $item['link'] = "http://" . $site->getDomain() . "/" . $page->getUnixName(); $item['guid'] = $item['link']; $item['date'] = date('r', $page->getDateCreated()->getTimestamp()); $b = ''; /* Create content of the feed. */ $cont = ''; /* get summary for the page. */ $splitSource = preg_split('/^([=]{4,})$/m', $source); if (isset($splitSource[0]) && count($splitSource) > 1) { $cont = $splitSource[0]; } else { /* Try to extract the short version. */ $s = $source; /* 1. Try the first paragraph. */ $m1 = array(); preg_match(";(^.*?)\n\n;", $s, $m1); if (isset($m1[1])) { $p = $m1[1]; $cont = $p; } else { $cont = $s; } } $b .= $cont . "\n\n"; /* %%author%% */ $ownerUserId = $page->getOwnerUserId(); if ($ownerUserId) { $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($ownerUserId); $userString = '[[*user ' . $user->getNickName() . ']]'; } else { $userString = 'Anonymous user'; } $b .= 'by ' . $userString; $wt = new WikiTransformation(); $wt->setMode("list"); $wt->setPage($page); $content = $wt->processSource($b); $d = utf8_encode("þ"); $content = preg_replace("/" . $d . "module \"([a-zA-Z0-9\\/_]+?)\"(.+?)?" . $d . "/", '', $content); $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); $item['content'] = $content; $items[] = $item; } $channel = array(); $channel['title'] = $pl->getParameterValue("t"); //$channel['link'] = "http://".$site->getDomain()."/".$page->getUnixName(); // if($feed->getDescription()){ // $channel['description'] = $feed->getDescription(); // } $runData->contextAdd("channel", $channel); $runData->contextAdd("items", $items); }
public function saveEditPostEvent($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $title = $pl->getParameterValue("title"); $source = $pl->getParameterValue("source"); $threadId = $pl->getParameterValue("threadId"); $postId = $pl->getParameterValue("postId"); $currentRevisionId = $pl->getParameterValue("currentRevisionId"); $user = $runData->getUser(); $userId = $runData->getUserId(); if ($userId == null) { $userString = $runData->createIpString(); } $errors = array(); if (strlen8($title) > 128) { $errors['title'] = _("Post title should not be longer than 128 characters."); } if (strlen($source) > 200000) { $errors['source'] = _("It seems the source is too long."); } elseif ($source == '') { $errors['source'] = _("Post body can not be empty."); } if (count($errors) > 0) { $runData->ajaxResponseAdd("formErrors", $errors); throw new ProcessException("Form errors", "form_errors"); } $db = Database::connection(); $db->begin(); if ($postId == null || !is_numeric($postId)) { throw new ProcessException(_("No such post."), "no_post"); } $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId); if ($post == null || $post->getSiteId() != $site->getSiteId()) { throw new ProcessException(_("No such post."), "no_post"); } $c = new Criteria(); $c->add("thread_id", $post->getThreadId()); $c->add("site_id", $site->getSiteId()); $c->setForUpdate(true); $thread = DB_ForumThreadPeer::instance()->selectOne($c); if ($thread == null || $thread->getSiteId() != $site->getSiteId()) { throw new ProcessException("Thread not found.", "no_thread"); } // check revisions... if ($post->getRevisionId() != $currentRevisionId) { throw new ProcessException(_("The post has been changed meanwhile. Sorry, you can not save it. Please reload the page and start editing again with the current revision... :-("), "no_post"); } $category = $post->getForumThread()->getCategory(); WDPermissionManager::instance()->hasForumPermission('edit_post', $runData->getUser(), $category, null, $post); if ($thread->getBlocked()) { // check if moderator or admin $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->add("user_id", $user->getUserId()); $rel = DB_ModeratorPeer::instance()->selectOne($c); if (!$rel || strpos($rel->getPermissions(), 'f') == false) { $rel = DB_AdminPeer::instance()->selectOne($c); if (!$rel) { throw new WDPermissionException(_("Sorry, this thread is blocked. Nobody can add new posts nor edit existing ones.")); } } } // compile content $wt = new WikiTransformation(); $wt->setMode('post'); $body = $wt->processSource($source); $postRevision = new DB_ForumPostRevision(); $postRevision->obtainPK(); $postRevision->setPostId($post->getPostId()); $postRevision->setText($source); $postRevision->setTitle($title); $postRevision->setDate(new ODate()); $post->setRevisionId($postRevision->getRevisionId()); $post->setRevisionNumber($post->getRevisionNumber() + 1); $post->setText($body); $post->setTitle($title); $post->setDateLastEdited(new ODate()); if ($userId) { $postRevision->setUserId($userId); $post->setEditedUserId($userId); } else { $postRevision->setUserId(0); $post->setEditedUserId(0); $postRevision->setUserString($userString); $post->setEditedUserString($userString); } $post->save(); $postRevision->save(); $o = new Outdater(); $o->forumEvent("post_save", $post); // index thread Indexer::instance()->indexThread($thread); EventLogger::instance()->logSavePost($post); $db->commit(); $runData->ajaxResponseAdd("postId", $post->getPostId()); if (GlobalProperties::$UI_SLEEP) { sleep(1); } }