Example #1
0
 public function processPage($out, $runData)
 {
     if ($this->category != null) {
         $out = preg_replace("/<title>(.+?)<\\/title>/is", "<title>\\1 " . preg_quote_replacement(htmlspecialchars($this->category->getName())) . "</title>", $out);
         $title = '<a href="/forum/c-' . $this->category->getCategoryId() . '/' . htmlspecialchars($this->category->getUnixifiedName()) . '">' . htmlspecialchars($this->category->getName()) . '</a> / ' . _('new thread');
         $out = preg_replace('/<div id="page-title">(.*?)<\\/div>/is', '<div id="page-title">' . preg_quote_replacement($title) . '</div>', $out);
     }
     return $out;
 }
Example #2
0
 public function assemblyTemplate($source, $template, $page = null)
 {
     /* First check if it is a real "live" template. If not, return the original $source. 
      * To be recognized as a live template it mast contain either %%content%% or
      * %%content{X}%% tags. */
     /* Handle ListPages module inside a template -- %%content%% need to be escaped. */
     $template = preg_replace_callback(";^\\[\\[module\\s+ListPages(.*?)\n\\[\\[/module\\]\\];ms", array($this, '_assemblyTemplateHandleListPages'), $template);
     $template = preg_replace_callback(";^\\[\\[module\\s+NextPage(.*?)\n\\[\\[/module\\]\\];ms", array($this, '_assemblyTemplateHandleListPages'), $template);
     $template = preg_replace_callback(";^\\[\\[module\\s+PreviousPage(.*?)\n\\[\\[/module\\]\\];ms", array($this, '_assemblyTemplateHandleListPages'), $template);
     $template = preg_replace_callback(";^\\[\\[module\\s+Feed(.*?)\n\\[\\[/module\\]\\];ms", array($this, '_assemblyTemplateHandleListPages'), $template);
     $template = preg_replace_callback(";^\\[\\[module\\s+FrontForum(.*?)\n\\[\\[/module\\]\\];ms", array($this, '_assemblyTemplateHandleListPages'), $template);
     if (!preg_match(';%%content({[0-9]+})?%%;', $template)) {
         return $source;
     }
     $out = $source;
     $template = preg_replace(';%%content({[0-9]+})?%%;', '%%%\\0%%%', $template);
     $template = preg_replace(';(?<!%)%%[a-z0-9\\(\\)_]+%%(?!%);i', '%%%\\0%%%', $template);
     $template = preg_replace(';(?<!%)%%date(\\|.*?)?%%(?!%);i', '%%%\\0%%%', $template);
     $template = preg_replace(";%ú%(content({[0-9]+}))?%ú%;", "%%\\1%%", $template);
     $template = preg_replace(";%ú%([a-z0-9\\(\\)_]+)%ú%;i", '%%\\1%%', $template);
     $template = preg_replace(";%ú%(date(\\|.*?)?)%ú%;i", '%%\\1%%', $template);
     /* Check if has a ===== delimiter. */
     $split = preg_split(';^={4,}$;sm', $template);
     if (count($split) > 1) {
         $template = trim($split[0]);
     }
     /* If there is $page, try substituting more tags. */
     if ($page) {
         $this->_tmpPage = $page;
         $b = $template;
         $title = $page->getTitle();
         $title = str_replace(array('[', ']'), '', $title);
         //$title = str_replace('%%', "\xFD", $title);
         $b = str_replace('%%%%%title%%%%%', $title, $b);
         $b = preg_replace(";%%%%%((linked_title)|(title_linked))%%%%%;i", preg_quote_replacement('[[[' . $page->getUnixName() . ' | ' . $title . ']]]'), $b);
         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);
         $b = preg_replace(';%%%%%date(\\|.*?)?%%%%%;', '%%%%%date|' . $page->getDateCreated()->getTimestamp() . '\\1%%%%%', $b);
         $b = preg_replace(';%%%%%date_edited(\\|.*?)?%%%%%;', '%%%%%date|' . $page->getDateLastEdited()->getTimestamp() . '\\1%%%%%', $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);
         if (strpos($page->getUnixName(), ":") != false) {
             $tmp0 = explode(':', $page->getUnixName());
             $categoryName00 = $tmp0[0];
         } else {
             $categoryName00 = "_default";
         }
         $b = str_ireplace('%%%%%category%%%%%', $categoryName00, $b);
         /* %%link%% */
         $site = $page->getSite();
         $b = str_ireplace('%%%%%link%%%%%', 'http://' . $site->getDomain() . '/' . $page->getUnixName(), $b);
         /* %%tags%% */
         $b = preg_replace_callback("/%%%%%tags%%%%%/i", array($this, '_handleTags'), $b);
         $b = preg_replace_callback(';%%%%%date\\|([0-9]+)(\\|.*?)?%%%%%;', array($this, '_formatDate'), $b);
         $template = $b;
         //$template = preg_replace(';(%%%%%([a-z0-9\(\)_]+)%%%%%;i', '%%\\1%%', $template);
     }
     $out = str_replace('%%%%%content%%%%%', trim($out), $template);
     /* Handle split sources. */
     $splitSource = preg_split('/^([=]{4,})$/m', $source);
     for ($i = 0; $i < count($splitSource); $i++) {
         $out = str_replace('%%%%%content{' . ($i + 1) . '}%%%%%', trim($splitSource[$i]), $out);
     }
     $out = preg_replace(';%%%%%content({[0-9]+})?%%%%%;', '', $out);
     return $out;
 }
Example #3
0
 public function processPage($out, $runData)
 {
     $site = $runData->getTemp("site");
     $link = '/feed/forum/threads.xml';
     $title = $site->getName() . " - " . _("new forum threads");
     $out = preg_replace("/<\\/head>/", '<link rel="alternate" type="application/rss+xml" title="' . preg_quote_replacement(htmlspecialchars($title)) . '" href="' . $link . '"/></head>', $out, 1);
     $link = '/feed/forum/posts.xml';
     $title = $site->getName() . " - new forum posts";
     $out = preg_replace("/<\\/head>/", '<link rel="alternate" type="application/rss+xml" title="' . preg_quote_replacement(htmlspecialchars($title)) . '" href="' . $link . '"/></head>', $out, 1);
     return $out;
 }
Example #4
0
 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);
 }
Example #5
0
 public function processPage($out, $runData)
 {
     // modify title of the page
     if ($this->threadTitle) {
         $pageTitle = $this->categoryName . ': ' . $this->threadTitle;
         $runData->getTemp("page")->setTitle($pageTitle);
         $out = preg_replace("/<title>(?:.+?)<\\/title>/is", "<title>" . preg_quote_replacement(htmlspecialchars($pageTitle)) . "</title>", $out);
     }
     if (!$this->tpage) {
         $ptitle = htmlspecialchars($this->threadTitle);
     } else {
         $ptitle = '<a href="/' . $this->tpage->getUnixName() . '">' . htmlspecialchars($this->tpage->getTitle()) . '</a> / ' . _('discussion') . '</h1>';
     }
     $out = preg_replace("/<div id=\"page-title\">(?:.*?)<\\/div>/is", "<div id=\"page-title\">" . preg_quote_replacement($ptitle) . "</div>", $out);
     // add rss feed info
     $link = '/feed/forum/t-' . $this->threadId . '.xml';
     $out = preg_replace("/<\\/head>/", '<link rel="alternate" type="application/rss+xml" title="' . _('Posts in the discussion thread') . ' &quot;' . htmlspecialchars($this->threadTitle) . '&quot;" href="' . $link . '"/></head>', $out, 1);
     return $out;
 }
Example #6
0
 public function processPage($out, $runData)
 {
     if ($this->vars['feedUrl']) {
         $out = preg_replace("/<\\/head>/", '<link rel="alternate" type="application/rss+xml" title="' . preg_quote_replacement(htmlspecialchars($this->vars['feedTitle'])) . '" href="' . $this->vars['feedUrl'] . '"/></head>', $out, 1);
     }
     return $out;
 }
Example #7
0
 public function processPage($out, $runData)
 {
     $pl = $runData->getParameterList();
     $pl->getParameterValue('t');
     if ($this->_vars['rssUrl']) {
         $rssTitle = $this->_vars['rssTitle'];
         if (!$rssTitle) {
             $rssTitle = _('Page RSS Feed');
         }
         $out = preg_replace("/<\\/head>/", '<link rel="alternate" type="application/rss+xml" title="' . preg_quote_replacement(htmlspecialchars($rssTitle)) . '" href="' . $this->_vars['rssUrl'] . '"/></head>', $out, 1);
     }
     return $out;
 }
 public function processPage($out, $runData)
 {
     if ($this->categoryName != null) {
         $pageTitle = $this->categoryName;
         $runData->getTemp("page")->setTitle($pageTitle);
         // DANGEROUS!!! DO NOT SAVE THE PAGE AFTER THIS!!!
         $out = preg_replace("/<title>(.+?)<\\/title>/is", "<title>\\1 " . preg_quote_replacement(htmlspecialchars($pageTitle)) . "</title>", $out, 1);
         $out = preg_replace("/<div id=\"page-title\">(.*?)<\\/div>/is", "<div id=\"page-title\">" . htmlspecialchars($this->categoryName) . "</div>", $out, 1);
         // feeds!
         $link = '/feed/forum/cp-' . $this->categoryId . '.xml';
         $out = preg_replace("/<\\/head>/", '<link rel="alternate" type="application/rss+xml" title="' . _('Posts in the forum category') . ' &quot;' . preg_quote_replacement(htmlspecialchars($this->categoryName)) . '&quot;" href="' . $link . '"/></head>', $out, 1);
         $link = '/feed/forum/ct-' . $this->categoryId . '.xml';
         $out = preg_replace("/<\\/head>/", '<link rel="alternate" type="application/rss+xml" title="' . _('Threads in the forum category') . ' &quot;' . preg_quote_replacement(htmlspecialchars($this->categoryName)) . '&quot;" href="' . $link . '"/></head>', $out, 1);
     }
     return $out;
 }