示例#1
0
 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);
         //}
     }
 }
示例#2
0
 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);
 }
示例#3
0
 /**
  * This is the place where pages are compiled!
  *
  * @param Db_Page $page
  */
 private function recompilePage($page)
 {
     // compiled content not up to date. recompile!
     $source = $page->getSource();
     $c = new Criteria();
     $c->add("page_id", $page->getPageId());
     $compiled = DB_PageCompiledPeer::instance()->selectOne($c);
     /* Find out if the category is using any templates. */
     if (!preg_match(';(:|^)_;', $page->getUnixName())) {
         $category = $page->getCategory();
         $categoryName = $category->getName();
         $templatePage = DB_PagePeer::instance()->selectByName($page->getSiteId(), ($categoryName == '_default' ? '' : $categoryName . ':') . '_template');
         if ($templatePage) {
             $source = $this->assemblySource($source, $templatePage->getSource(), $page);
         }
     }
     $wt = new WikiTransformation();
     $wt->setPage($page);
     $result = $wt->processSource($source);
     $compiled->setText($result);
     $compiled->setDateCompiled(new ODate());
     $compiled->save();
     $linksExist = $wt->wiki->vars['internalLinksExist'];
     $linksNotExist = $wt->wiki->vars['internalLinksNotExist'];
     $inclusions = $wt->wiki->vars['inclusions'];
     $inclusionsNotExist = $wt->wiki->vars['inclusionsNotExist'];
     $externalLinks = $wt->wiki->vars['externalLinks'];
     $this->vars['linksExist'] = $linksExist;
     $this->vars['linksNotExist'] = $linksNotExist;
     $this->vars['inclusions'] = $inclusions;
     $this->vars['inclusionsNotExist'] = $inclusionsNotExist;
     $this->vars['externalLinks'] = $externalLinks;
 }