public function build($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $tag = $pl->getParameterValue("tag");
     if ($tag === null) {
         $runData->setModuleTemplate("Empty");
         return '';
     }
     // get pages
     $categoryName = $pl->getParameterValue("category");
     if ($categoryName) {
         $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId());
         if ($category == null) {
             return '';
         }
         $runData->contextAdd("category", $category);
     }
     $c = new Criteria();
     $c->setExplicitFrom("page, page_tag");
     $c->add("page_tag.tag", $tag);
     $c->add("page_tag.site_id", $site->getSiteId());
     $c->add("page_tag.page_id", "page.page_id", "=", false);
     if ($category) {
         $c->add("page.category_id", $category->getCategoryId());
     }
     $c->addOrderAscending('COALESCE(page.title, page.unix_name)');
     $pages = DB_PagePeer::instance()->select($c);
     //	$q = "SELECT site.* FROM site, tag WHERE tag.tag = '".db_escape_string($tag")."'
     $runData->contextAdd("tag", $tag);
     $runData->contextAdd("pages", $pages);
     $runData->contextAdd("pageCount", count($pages));
     $runData->contextAdd("pageUnixName", $runData->getTemp("page")->getUnixName());
 }
Example #2
0
 public function getCategory()
 {
     $categoryId = $this->getCategoryId();
     $siteId = $this->getSiteId();
     $category = DB_CategoryPeer::instance()->selectById($categoryId, $siteId);
     return $category;
 }
Example #3
0
 public function build($runData)
 {
     $page = $runData->getTemp("page");
     if ($page) {
         $rate = $page->getRate();
     } else {
         $pl = $runData->getParameterList();
         $pageId = $pl->getParameterValue("pageId");
         if ($pageId) {
             $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId);
             $rate = $page->getRate();
         } else {
             $rate = 0;
         }
     }
     // get the category too
     if (!$page) {
         $site = $runData->getTemp("site");
         $category = DB_CategoryPeer::instance()->selectByName('_default', $site->getSiteId());
     } else {
         $category = $runData->getTemp("category");
         if (!$category) {
             $category = DB_CategoryPeer::instance()->selectByPrimaryKey($page->getCategoryId());
         }
     }
     $type = $category->getRatingType();
     $runData->contextAdd("type", $type);
     $runData->contextAdd("rate", $rate);
 }
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $runData->contextAdd("site", $site);
     // select templates
     $templatesCategory = DB_CategoryPeer::instance()->selectByName("template", $site->getSiteId());
     if ($templatesCategory == null) {
         $runData->contextAdd("noTemplates", true);
         return;
     }
     $c = new Criteria();
     $c->add("category_id", $templatesCategory->getCategoryId());
     $c->addOrderAscending("title");
     $templates = DB_PagePeer::instance()->select($c);
     $runData->contextAdd("templates", $templates);
     // get all categories for the site
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->addOrderAscending("replace(name, '_', '00000000')");
     $categories = DB_CategoryPeer::instance()->select($c);
     $runData->contextAdd("categories", $categories);
     // also prepare categories to put into javascript...
     $cats2 = array();
     foreach ($categories as $category) {
         $cats2[] = $category->getFieldValuesArray();
     }
     $runData->ajaxResponseAdd("categories", $cats2);
 }
Example #5
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     // get all categories
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->addOrderAscending("replace(name, '_', '00000000')");
     $categories = DB_CategoryPeer::instance()->select($c);
     $runData->contextAdd("categories", $categories);
 }
Example #6
0
 /**
  * Get categories from a site
  * 
  * Argument array keys:
  *  site: site to get categories from
  * 
  * @param struct $args
  * @return struct
  */
 public function categories($args)
 {
     $this->parseArgs($args, array("performer", "site"));
     WDPermissionManager::instance()->canAccessSite($this->performer, $this->site);
     $c = new Criteria();
     $c->add("site_id", $this->site->getSiteId());
     $ret = array();
     foreach (DB_CategoryPeer::instance()->selectByCriteria($c) as $category) {
         $ret[] = $this->repr($category);
     }
     return $ret;
 }
Example #7
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $categoryName = $pl->getParameterValue("category", "MODULE", "AMODULE");
     $details = $pl->getParameterValue("details", "MODULE", "AMODULE");
     $preview = $pl->getParameterValue("preview", "MODULE", "AMODULE");
     $order = $pl->getParameterValue("order", "MODULE", "AMODULE");
     $limit = $pl->getParameterValue("limit", "MODULE", "AMODULE");
     if ($categoryName !== null) {
         $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId());
         if ($category == null) {
             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 ($category) {
         $c->add("category_id", $category->getCategoryId());
     }
     switch ($order) {
         case 'dateCreatedDesc':
             $c->addOrderDescending('page_id');
             break;
         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;
         default:
             $c->addOrderAscending("COALESCE(title, unix_name)");
     }
     if ($limit && is_numeric($limit) && $limit > 0) {
         $c->setLimit($limit);
     }
     $pages = DB_PagePeer::instance()->select($c);
     // by default cathegorize by first letter...
     $runData->contextAdd("pages", $pages);
     $runData->contextAdd("details", $details);
     $runData->contextAdd("preview", $preview);
 }
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $runData->contextAdd("site", $site);
     // get all categories for the site
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->addOrderAscending("replace(name, '_', '00000000')");
     $categories = DB_CategoryPeer::instance()->select($c);
     $runData->contextAdd("categories", $categories);
     // also prepare categories to put into javascript...
     $cats2 = array();
     foreach ($categories as $category) {
         $arr = $category->getFieldValuesArray();
         // change themes to conform to variants structure
         if ($arr['theme_id']) {
             $theme = DB_ThemePeer::instance()->selectByPrimaryKey($category->getThemeId());
             if ($theme->getVariantOfThemeId() != null) {
                 $arr['theme_id'] = $theme->getVariantOfThemeId();
                 $arr['variant_theme_id'] = $theme->getThemeId();
                 $arr['theme_external_url'] = $category->getThemeExternalUrl();
             }
         }
         $cats2[] = $arr;
     }
     $runData->ajaxResponseAdd("categories", $cats2);
     // now select themes
     $c = new Criteria();
     /*$c->add("custom", false);
     		$c->add("abstract", false);
     		$c->addOrderAscending("name");*/
     $q = "SELECT * from theme WHERE " . "abstract = FALSE AND variant_of_theme_id IS NULL " . "AND (custom = FALSE" . " OR (custom = TRUE AND site_id='" . $site->getSiteId() . "')" . ") " . "ORDER BY custom, sort_index, replace(name, '_', '00000000');";
     $c->setExplicitQuery($q);
     $themes = DB_ThemePeer::instance()->select($c);
     $runData->contextAdd("themes", $themes);
     // get theme variants too
     $c = new Criteria();
     $q = "SELECT * FROM theme WHERE variant_of_theme_id IS NOT NULL ORDER BY name";
     $c->setExplicitQuery($q);
     $variants = DB_ThemePeer::instance()->select($c);
     $variantsArray = array();
     foreach ($variants as $v) {
         $variantsArray[$v->getVariantOfThemeId()][] = $v;
     }
     $runData->contextAdd("variantsArray", $variantsArray);
 }
Example #9
0
 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 build($runData)
 {
     $site = $runData->getTemp("site");
     $fsettings = $site->getForumSettings();
     if (!$fsettings) {
         throw new ProcessException(_("Forum not activated (yet)."));
     }
     $runData->contextAdd("site", $site);
     // get all categories for the site
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->addOrderAscending("replace(name, '_', '00000000')");
     $categories = DB_CategoryPeer::instance()->select($c);
     $runData->contextAdd("categories", $categories);
     // also prepare categories to put into javascript...
     $cats2 = array();
     foreach ($categories as $category) {
         $cats2[] = $category->getFieldValuesArray();
     }
     $runData->ajaxResponseAdd("categories", $cats2);
 }
Example #11
0
 private function _getOrCreateCategory($site, $categoryName)
 {
     $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId(), false);
     if ($category == null) {
         // create the category - just clone the default category!!!
         $category = DB_CategoryPeer::instance()->selectByName("_default", $site->getSiteId(), false);
         $category->setCategoryId(null);
         $category->setNew(true);
         $category->setName($categoryName);
         // fill with some important things - we assume the _default category exists!!! IT REALLY SHOULD!!!
         $category->setPerPageDiscussion(null);
         //default value
         // set default permissions theme and license
         $category->setPermissionsDefault(true);
         $category->setThemeDefault(true);
         $category->setLicenseDefault(true);
         $category->setNavDefault(true);
         $category->save();
     }
     return $category;
 }
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $runData->contextAdd("site", $site);
     // get all categories for the site
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->addOrderAscending("replace(name, '_', '00000000')");
     $categories = DB_CategoryPeer::instance()->select($c);
     $runData->contextAdd("categories", $categories);
     // also prepare categories to put into javascript...
     $cats2 = array();
     foreach ($categories as $category) {
         $cats2[] = $category->getFieldValuesArray();
     }
     $runData->ajaxResponseAdd("categories", $cats2);
     // now select themes
     $c = new Criteria();
     $c->addOrderAscending("name");
     $themes = DB_ThemePeer::instance()->select($c);
     $runData->contextAdd("themes", $themes);
 }
Example #13
0
 public function deletePage($page, $site = null)
 {
     // I hope everything here is within a TRANSACTION!!!
     if (!$page) {
         return;
     }
     if (!$site) {
         $site = DB_SitePeer::instance()->selectByPrimaryKey($page->getSiteId());
     }
     // delete the sources and metadatas
     $db = Database::connection();
     // get descandants first
     $rec = 0;
     $c = new Criteria();
     $c->add("parent_page_id", $page->getPageId());
     $pages = DB_PagePeer::instance()->select($c);
     // ok, these are direct children. need to clear the perent_page_id field
     $descs = array();
     while ($pages !== null && count($pages) > 0 && $rec < 10) {
         $p2 = array();
         foreach ($pages as $p) {
             $c = new Criteria();
             $c->add("parent_page_id", $p->getPageId());
             $ptmp = DB_PagePeer::instance()->select($c);
             $p2 = array_merge($p2, $ptmp);
             if ($rec === 0) {
                 $p->setParentPageId(null);
                 $p->save();
                 // clear metadata
                 $m = $p->getMetadata();
                 $m->setParentPageId(null);
                 $m->save();
             }
         }
         $descs = array_merge($descs, $pages, $p2);
         $pages = $p2;
         $rec++;
     }
     $category = $page->getCategory();
     // sources
     $q = "DELETE FROM page_source WHERE source_id IN (SELECT page_revision.source_id FROM page_revision WHERE page_id='" . $page->getPageId() . "')";
     $db->query($q);
     //metadatas
     $q = "DELETE FROM page_metadata WHERE metadata_id IN (SELECT page_revision.metadata_id FROM page_revision WHERE page_id='" . $page->getPageId() . "')";
     $db->query($q);
     // delete the page too
     $q = "DELETE FROM page WHERE page_id='" . $page->getPageId() . "'";
     $db->query($q);
     // remove from cache too.
     $outdater = new Outdater();
     $outdater->pageEvent('delete', $page->getUnixName());
     // outdate descs too
     foreach ($descs as $desc) {
         $outdater->outdatePageCache($desc);
     }
     // delete the category if empty
     if ($category->getName() != "_default") {
         $c = new Criteria();
         $c->add("category_id", $category->getCategoryId());
         $count = DB_PagePeer::instance()->selectCount($c);
         if ($count == 0) {
             // delete the category
             DB_CategoryPeer::instance()->delete($c);
             $outdater->categoryEvent('delete', $category, $site);
         }
     }
     // remove FILES (if any)
     $path = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName() . "/files/" . $page->getUnixName();
     exec('rm -r ' . escapeshellarg($path) . ' &> /dev/null');
     //
 }
Example #14
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);
 }
Example #15
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);
         //}
     }
 }
Example #16
0
 private function handleTemplateChange($page)
 {
     if (is_string($page)) {
         if (strpos($page, ":") != false) {
             $tmp0 = explode(':', $page);
             $categoryName = $tmp0[0];
         } else {
             $categoryName = "_default";
         }
         if (preg_match(';_template$;', $page)) {
             $site = $GLOBALS['site'];
             $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId(), false);
             $this->recompileCategory($category);
         }
     } elseif (preg_match(';_template$;', $page->getUnixName())) {
         $category = $page->getCategory();
         $this->recompileCategory($category);
     }
 }
Example #17
0
    $nrev->save();
    $ncomp = new DB_PageCompiled();
    $ncomp->setPageId($npage->getPageId());
    $ncomp->setDateCompiled($now);
    $ncomp->save();
}
Ozone::init();
$db = Database::connection();
$db->begin();
$od = new Outdater();
$od->recompileWholeSite(DB_SitePeer::instance()->selectByPrimaryKey(1));
$db->commit();
$db->begin();
$c = new Criteria();
$c->add("name", "auth");
$c->add("site_id", 1);
if (DB_CategoryPeer::instance()->selectOne($c)) {
    die("The auth category already exists!\n\n");
}
$ncat = DB_CategoryPeer::instance()->selectByPrimaryKey(1);
$ncat->setNew(true);
$ncat->setCategoryId(null);
$ncat->setName("auth");
$ncat->save();
addAPage($ncat, "auth:login", "[[module LoginModule]]", "Log in");
addAPage($ncat, "auth:newaccount", "[[module CreateAccount]]", "Create account - step 1");
addAPage($ncat, "auth:newaccount2", "[[module CreateAccount2]]", "Create account - step 2");
addAPage($ncat, "auth:newaccount3", "[[module CreateAccount3]]", "Create account - step 3");
$od->recompileWholeSite(DB_SitePeer::instance()->selectByPrimaryKey(1));
$db->commit();
echo "Successfully added the new auth pages!\n\n(Don't worry if Segmentation fault occurs BELOW)\n\n";
Example #18
0
 public function renamePageEvent($runData)
 {
     $pl = $runData->getParameterList();
     $pageId = $pl->getParameterValue("page_id");
     $newName = trim($pl->getParameterValue("new_name"));
     $newName = WDStringUtils::toUnixName($newName);
     // purify! (for sure)
     $fixDeps = $pl->getParameterValue('fixdeps');
     $site = $runData->getTemp("site");
     if ($newName == null || $newName == '') {
         throw new ProcessException(_("Destination page name should be given."), "no_new_name");
     }
     $db = Database::connection();
     $db->begin();
     $c = new Criteria();
     $c->add("page_id", $pageId);
     $c->setForUpdate(true);
     $page = DB_PagePeer::instance()->selectOne($c);
     if ($page == null || $page->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("Error getting page information."), "no_page");
     }
     if ($newName == $page->getUnixName()) {
         throw new ProcessException(_("The current and new names are the same."), "page_exists");
     }
     // check for permissions again
     $category = $page->getCategory();
     $user = $runData->getUser();
     WDPermissionManager::instance()->hasPagePermission('move', $user, $category, $page);
     // check if the new page exists or not.
     $conflictPage = DB_PagePeer::instance()->selectByName($site->getSiteId(), $newName);
     if ($conflictPage != null) {
         throw new ProcessException(_("The destination page already exists."), "page_exists");
     }
     $oldName = $page->getUnixName();
     // check if new page exists!
     // check for locks first
     DB_PageEditLockPeer::instance()->deleteOutdated($pageId);
     $c = new Criteria();
     $c->add("page_id", $page->getPageId());
     if ($pl->getParameterValue("force") === "yes") {
         DB_PageEditLockPeer::instance()->delete($c);
     }
     $locks = DB_PageEditLockPeer::instance()->select($c);
     if (count($locks) > 0) {
         $runData->ajaxResponseAdd("locks", true);
         $runData->contextAdd("locks", $locks);
         $runData->setModuleTemplate("rename/PageLockedWin");
         $db->rollback();
         return;
     }
     // success so far...
     // create new revision, new metadata and alter the page object too.
     $oldMetadata = $page->getMetadata();
     $metadata = clone $oldMetadata;
     $metadata->setNew(true);
     $metadata->setMetadataId(null);
     $metadata->setUnixName($newName);
     $metadata->save();
     $oldRevision = $page->getCurrentRevision();
     $revision = new DB_PageRevision();
     $revision->setSiteId($site->getSiteId());
     $revision->setPageId($page->getPageId());
     // copy source id
     $revision->setSourceId($oldRevision->getSourceId());
     $revision->setSinceFullSource($oldRevision->getSinceFullSource());
     $revision->setDiffSource($oldRevision->getDiffSource());
     $revision->setMetadataId($metadata->getMetadataId());
     $revision->setFlagRename(true);
     $revision->setRevisionNumber($oldRevision->getRevisionNumber() + 1);
     $revision->setComments(_("Page name changed") . ": \"{$oldName}\" " . _("to") . " \"{$newName}\".");
     $userId = $runData->getUserId();
     if ($userId == null) {
         $userString = $runData->createIpString();
     }
     if ($userId) {
         $revision->setUserId($userId);
         $page->setLastEditUserId($userId);
     } else {
         $revision->setUserId(0);
         $page->setLastEditUserId(0);
         $revision->setUserString($userString);
         $page->setLastEditUserString($userString);
     }
     $now = new ODate();
     $revision->setDateLastEdited($now);
     $revision->save();
     // alter the page info
     $page->setRevisionId($revision->getRevisionId());
     $page->setDateLastEdited($now);
     $page->setUnixName($newName);
     $page->setRevisionNumber($revision->getRevisionNumber());
     // handle the categories
     // extract category name
     if (strpos($newName, ':') != false) {
         // ok, there is category!
         $exp = explode(':', $newName);
         $categoryName = $exp[0];
     } else {
         // no category name, "_default" assumed
         $categoryName = "_default";
     }
     if (strpos($oldName, ':') != false) {
         // ok, there is category!
         $exp = explode(':', $oldName);
         $oldCategoryName = $exp[0];
     } else {
         // no category name, "_default" assumed
         $oldCategoryName = "_default";
     }
     $page->save();
     $outdater = new Outdater();
     if ($categoryName !== $oldCategoryName) {
         // check if new category exists. if not - create it!
         $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId(), false);
         if ($category == null) {
             // create the category - just clone the default category!!!
             $category = DB_CategoryPeer::instance()->selectByName("_default", $site->getSiteId(), false);
             $category->setName($categoryName);
             // fill with some important things - we assume the _default category exists!!! IT REALLY SHOULD!!!
             $category->setCategoryId(null);
             $category->setNew(true);
             // this will make it INSERT, not UPDATE on save()
             $category->setPermissionsDefault(true);
             $category->setThemeDefault(true);
             $category->setLicenseDefault(true);
             $category->setNavDefault(true);
             $category->save();
         } else {
             //also check if one has permissions to create new pages in
             // the new category!!!
             try {
                 WDPermissionManager::instance()->hasPagePermission('create', $user, $category);
             } catch (Exception $e) {
                 throw new ProcessException(_("You are not allowed to create new pages in the destination category") . " \"" . $category->getName() . "\".", "not_allowed");
             }
         }
         $page->setCategoryId($category->getCategoryId());
         $page->save();
         // also see if the old category is empty - if yes - delete it!
         if ($oldCategoryName != "_default") {
             $category = DB_CategoryPeer::instance()->selectByName($oldCategoryName, $site->getSiteId(), false);
             $c = new Criteria();
             $c->add("category_id", $category->getCategoryId());
             $count = DB_PagePeer::instance()->selectCount($c);
             if ($count == 0) {
                 // delete the category
                 DB_CategoryPeer::instance()->delete($c);
                 $outdater->categoryEvent('delete', $category, $site);
             }
         }
     }
     // outdate party!
     $outdater->pageEvent("rename", $page, $oldName);
     // index page
     // move files too
     $oldDir = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName() . "/files/" . $oldName;
     $newDir = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName() . "/files/" . $newName;
     if (file_exists($oldDir)) {
         if (rename($oldDir, $newDir) == false) {
             throw new ProcessException(_("Error moving attached files."), "error_files");
         }
     }
     $oldRDir = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName() . "/resized-images/" . $oldName;
     $newRDir = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName() . "/resized-images/" . $newName;
     if (file_exists($oldRDir)) {
         if (rename($oldRDir, $newRDir) == false) {
             throw new ProcessException(_("Error moving attached (resized) files."), "error_files");
         }
     }
     // try to fix dependencies
     if ($fixDeps && preg_match('/^[0-9]+(,[0-9]+)*$/', $fixDeps)) {
         $fixPageIds = explode(',', $fixDeps);
         foreach ($fixPageIds as $pageId) {
             $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId);
             if ($page == null || $page->getSiteId() !== $site->getSiteId()) {
                 continue;
             }
             // check for any locks
             $c = new Criteria();
             $c->add("page_id", $pageId);
             $lock = DB_PageEditLockPeer::instance()->selectOne($c);
             if ($lock) {
                 continue;
             }
             $fixer = new DependencyFixer($page, $oldName, $newName);
             $fixer->setUser($user);
             $fixer->fixLinks();
             $od = new Outdater();
             $od->pageEvent('source_changed', $page);
         }
     }
     // check any dependency left
     $c = new Criteria();
     $q = "SELECT page_id, title, unix_name FROM page_link, page " . "WHERE page_link.to_page_name='" . db_escape_string($oldName) . "' " . "AND page_link.from_page_id=page.page_id AND page.site_id={$site->getSiteId()} ORDER BY COALESCE(title, unix_name)";
     $c->setExplicitQuery($q);
     $pages = DB_PagePeer::instance()->select($c);
     $q = "SELECT page_id, title, unix_name FROM page, page_inclusion " . "WHERE page_inclusion.included_page_name='" . db_escape_string($oldName) . "' " . "AND page_inclusion.including_page_id=page.page_id AND page.site_id={$site->getSiteId()} ORDER BY COALESCE(title, unix_name)";
     $c->setExplicitQuery($q);
     $pagesI = DB_PagePeer::instance()->select($c);
     if (count($pages) > 0 || count($pagesI) > 0) {
         $runData->setModuleTemplate("rename/LeftDepsModule");
         $runData->contextAdd("pagesI", $pagesI);
         $runData->contextAdd("pages", $pages);
         $runData->ajaxResponseAdd("leftDeps", true);
     }
     $runData->ajaxResponseAdd("newName", $newName);
     EventLogger::instance()->logPageRename($page, $oldName);
     $db->commit();
     sleep(0.5);
 }
Example #19
0
 public function finalizeEvent($runData, $skipEvcode = false)
 {
     // get the form data
     $pl = $runData->getParameterList();
     if (!$skipEvcode) {
         $evcode = $pl->getParameterValue("evcode", "AMODULE");
         //check if the email vercode is correct
         $evcode2 = $runData->sessionGet('evcode');
         if ($evcode !== $evcode2) {
             throw new ProcessException(_("Invalid email verification code."), "invalid_code");
         }
     }
     $data = $runData->sessionGet("ca_data");
     $name = $data['name'];
     $email = $data['email'];
     $password = $data['password'];
     $lang = $data['language'];
     $db = Database::connection();
     $db->begin();
     // check again if email and nick are not duplicate!
     $c = new Criteria();
     $c->add("lower(email)", strtolower($email));
     $u = DB_OzoneUserPeer::instance()->selectOne($c);
     if ($u != null) {
         $runData->resetSession();
         throw new ProcessException(_("A user with this email already exists. Must have been created meanwhile... " . "Unfortunately you have to repeat the whole procedure. :-("), "user_exists");
     }
     $unixified = WDStringUtils::toUnixName($name);
     $c = new Criteria();
     $c->add("unix_name", $unixified);
     $u = DB_OzoneUserPeer::instance()->selectOne($c);
     if ($u != null) {
         $runData->resetSession();
         throw new ProcessException(_("A user with this name (or very similar) already exists. Must have been created meanwhile... " . "Unfortunately you have to repeat the whole procedure. :-("), "user_exists");
     }
     // add new user!!!
     $nuser = new DB_OzoneUser();
     /* email as the username!!! */
     $nuser->setName($email);
     $nuser->setEmail($email);
     $nuser->setPassword(md5($password));
     $nuser->setNickName($name);
     $nuser->setUnixName($unixified);
     $nuser->setLanguage($lang);
     $date = new ODate();
     $nuser->setRegisteredDate($date);
     $nuser->setLastLogin($date);
     $nuser->save();
     // profile
     $profile = new DB_Profile();
     $profile->setUserId($nuser->getUserId());
     $profile->save();
     $us = new DB_UserSettings();
     $us->setUserId($nuser->getUserId());
     $us->save();
     // profile page
     $c = new Criteria();
     $c->add("unix_name", "profiles");
     $nsite = DB_SitePeer::instance()->selectOne($c);
     $ncategory = DB_CategoryPeer::instance()->selectByName('profile', $nsite->getSiteId());
     $dup = new Duplicator();
     $dup->setOwner($nuser);
     $dup->duplicatePage(DB_PagePeer::instance()->selectByName($nsite->getSiteId(), 'template:profile'), $nsite, $ncategory, 'profile:' . $nuser->getUnixName());
     $page = DB_PagePeer::instance()->selectByName($nsite->getSiteId(), 'profile:' . $nuser->getUnixName());
     $ou = new Outdater();
     $ou->pageEvent('new_page', $page);
     $db->commit();
     /* Handle originalUrl. */
     $originalUrl = $runData->sessionGet('loginOriginalUrl');
     if ($originalUrl) {
         $runData->ajaxResponseAdd('originalUrl', $originalUrl);
         if ($runData->sessionGet('loginOriginalUrlForce')) {
             $runData->ajaxResponseAdd('originalUrlForce', true);
         }
     }
     // reset session etc.
     $runData->resetSession();
     $runData->getSession()->setUserId($nuser->getUserId());
     setcookie("welcome", $nuser->getUserId(), time() + 10000000, "/", GlobalProperties::$SESSION_COOKIE_DOMAIN);
     setcookie(GlobalProperties::$SESSION_COOKIE_NAME_IE, $runData->getSessionId(), null, "/");
 }
Example #20
0
 public function savePageRateSettingsEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $siteId = $site->getSiteId();
     $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
     $cats0 = $json->decode($pl->getParameterValue("categories"));
     $db = Database::connection();
     $db->begin();
     $outdater = new Outdater();
     foreach ($cats0 as $category) {
         $categoryId = $category['category_id'];
         $c = new Criteria();
         $c->add("category_id", $categoryId);
         $c->add("site_id", $siteId);
         // for sure ;-)
         $dCategory = DB_CategoryPeer::instance()->selectOne($c);
         // now compare
         $changed = false;
         if ($category['rating'] !== $dCategory->getRating()) {
             $dCategory->setRating($category['rating']);
             $changed = true;
         }
         if ($changed) {
             $dCategory->save();
             // outdate category too
             $outdater->categoryEvent("category_save", $dCategory);
         }
     }
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
Example #21
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     // get some cool parameters
     $maxFontSize = $pl->getParameterValue("maxFontSize", "MODULE");
     $minFontSize = $pl->getParameterValue("minFontSize", "MODULE");
     $minColor = $pl->getParameterValue("minColor", "MODULE");
     $maxColor = $pl->getParameterValue("maxColor", "MODULE");
     $target = $pl->getParameterValue("target", "MODULE");
     $limit = $pl->getParameterValue("limit", "MODULE");
     $categoryName = $pl->getParameterValue("category", "MODULE");
     if (!$target) {
         $target = "/system:page-tags/tag/";
     } else {
         $target = preg_replace('/^\\/?/', '/', $target);
         $target = preg_replace('/\\/?$/', '/', $target);
         $target .= 'tag/';
     }
     // check for font sizes
     if ($maxFontSize && $minFontSize) {
         preg_match('/^([0-9]+)(%|em|px)$/', $maxFontSize, $matches);
         $fsformat = $matches[2];
         if ($fsformat == null) {
             throw new ProcessException(_("Unsupported format for font size. Use px, em or %."));
         }
         $sizeBig = $matches[1];
         preg_match('/^([0-9]+)(%|em|px)$/', $minFontSize, $matches);
         if ($fsformat != $matches[2]) {
             throw new ProcessException(_("Format for minFontSize and maxFontSize must be the same (px, em or %)."));
         }
         $sizeSmall = $matches[1];
     } else {
         $sizeSmall = 100;
         // percent
         $sizeBig = 300;
         // percent
         $fsformat = "%";
     }
     // get colors
     if ($maxColor && $minColor) {
         if (!preg_match('/^[0-9]+,[0-9]+,[0-9]+$/', $maxColor) || !preg_match('/^[0-9]+,[0-9]+,[0-9]+$/', $minColor)) {
             throw new ProcessException(_('Unsupported color format. ' . 'Use "RRR,GGG,BBB" for Red,Green,Blue each within 0-255 range.'));
         }
         $colorSmall = explode(',', $minColor);
         $colorBig = explode(',', $maxColor);
     } else {
         $colorSmall = array(128, 128, 192);
         $colorBig = array(64, 64, 128);
     }
     if ($limit && is_numeric($limit) && $limit > 0) {
     } else {
         $limit = 50;
     }
     $site = $runData->getTemp("site");
     if ($categoryName) {
         $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId());
         if ($category == null) {
             throw new ProcessException(sprintf(_('Category "%s" can not be found.'), $categoryName));
         }
     }
     $db = Database::connection();
     //select tags
     if ($category == null) {
         $q = "SELECT * FROM (SELECT tag, COUNT(*) AS weight FROM page_tag  WHERE site_id='" . $site->getSiteId() . "' GROUP BY tag ORDER BY weight DESC LIMIT {$limit}) AS foo ORDER BY tag";
     } else {
         $q = "SELECT * FROM (SELECT tag, COUNT(*) AS weight FROM page_tag, page  WHERE page_tag.site_id='" . $site->getSiteId() . "' " . " AND page.category_id='" . $category->getCategoryId() . "' " . " AND page.page_id = page_tag.page_id " . "GROUP BY tag ORDER BY weight DESC LIMIT {$limit}) AS foo ORDER BY tag";
         $runData->contextAdd("category", $category);
     }
     $res = $db->query($q);
     $tags = $res->fetchAll();
     $minWeight = 10000000;
     $maxWeight = 0;
     if (!$tags) {
         return;
     }
     foreach ($tags as $tag) {
         if ($tag['weight'] > $maxWeight) {
             $maxWeight = $tag['weight'];
         }
         if ($tag['weight'] < $minWeight) {
             $minWeight = $tag['weight'];
         }
     }
     $weightRange = $maxWeight - $minWeight;
     // now set color and font size for each of the tags.
     foreach ($tags as &$tag) {
         if ($weightRange == 0) {
             $a = 0;
         } else {
             $a = ($tag['weight'] - $minWeight) / $weightRange;
         }
         $fontSize = round($sizeSmall + ($sizeBig - $sizeSmall) * $a);
         // hadle colors... woooo! excited!
         $color = array();
         $color['r'] = round($colorSmall[0] + ($colorBig[0] - $colorSmall[0]) * $a);
         $color['g'] = round($colorSmall[1] + ($colorBig[1] - $colorSmall[1]) * $a);
         $color['b'] = round($colorSmall[2] + ($colorBig[2] - $colorSmall[2]) * $a);
         $tag['size'] = $fontSize . $fsformat;
         $tag['color'] = $color;
     }
     $runData->contextAdd("tags", $tags);
     $runData->contextAdd("href", $target);
 }
    public function render($runData)
    {
        // quickly check - show or not.
        $pl = $runData->getParameterList();
        $pageName = $runData->getTemp("pageUnixName");
        $page = $runData->getTemp("page");
        //$pl->getParameterValue("page", "MODULE");
        // get category name and get the category by name.
        // this should be enchanced to use memcache later
        // to get category to avoid db connection.
        // extract category name
        if (strpos($pageName, ':') != false) {
            // ok, there is category!
            $exp = explode(':', $pageName);
            $categoryName = $exp[0];
        } else {
            $categoryName = "_default";
        }
        $site = $runData->getTemp("site");
        $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId());
        $user = $runData->getUser();
        $pm = new WDPermissionManager();
        $pm->setThrowExceptions(false);
        $pm->setCheckIpBlocks(false);
        // to avoid database connection.
        if (!$pm->hasPagePermission('options', $user, $category, $pageName, $site)) {
            return '';
        }
        $showDiscuss = $pl->getParameterValue("showDiscuss");
        if ($showDiscuss) {
            $threadId = $pl->getParameterValue("threadId");
            $pageUnixName = $pl->getParameterValue("pageUnixName");
        }
        $showRate = $category->getRatingEnabledEff();
        // now a nasty part - make it inline such that
        // the Smarty engine does need to be initialized.
        // nasty way but saves a LOT of time with caching enabled.
        $otext = '';
        if ($page) {
            $otext .= '<div id="page-info">' . _('page_revision') . ': ' . $page->getRevisionNumber() . ', ' . _('last_edited') . ': <span class="odate">' . $page->getDateLastEdited()->getTimestamp() . '|%e %b %Y, %H:%M %Z (%O ' . _('ago') . ')</span>' . '</div>';
        }
        $otext .= '
<div id="page-options-bottom"  class="page-options-bottom">
	<a href="javascript:;" id="edit-button">' . _('edit') . '</a>';
        if ($showRate && $page) {
            $otext .= '<a href="javascript:;" id="pagerate-button">' . _('rate') . ' (<span id="prw54355">' . ($page->getRate() > 0 ? '+' : '') . $page->getRate() . '</span>)</a>';
        }
        $otext .= '<a href="javascript:;" id="tags-button">' . _('tags') . '</a>';
        if ($showDiscuss && $page) {
            if ($threadId) {
                $no = $page->getTemp("numberPosts");
                $otext .= '<a href="/forum/t-' . $threadId . '/' . $pageUnixName . '"  id="discuss-button">' . _('discuss') . ' (' . $no . ')</a>';
            } else {
                $otext .= '<a href="javascript:;" id="discuss-button" onclick="WIKIDOT.page.listeners.createPageDiscussion(event)">' . _('discuss') . '</a> ';
            }
        }
        $otext .= '
	<a href="javascript:;" id="history-button">' . _('history') . '</a> 
	<a href="javascript:;" id="files-button">' . _('files') . '</a> ' . '<a href="javascript:;" id="print-button">' . _('print') . '</a> ' . '<a href="javascript:;" id="site-tools-button">' . _('site tools') . '</a>';
        if ($site->getPrivate()) {
        }
        $otext .= '<a href="javascript:;" id="more-options-button">+&nbsp;' . _('options') . '</a> 
</div>
<div id="page-options-bottom-2" class="page-options-bottom" style="display:none">
	<a href="javascript:;" id="edit-sections-button">' . _('edit sections') . '</a>
	<a href="javascript:;" id="edit-append-button">' . _('append') . '</a>
	<a href="javascript:;" id="backlinks-button">' . _('backlinks') . '</a> 
	<a href="javascript:;" id="view-source-button">' . _('view source') . '</a> 
	<a href="javascript:;" id="parent-page-button">' . _('parent') . '</a> 
	<a href="javascript:;" id="page-block-button">' . _('block') . '</a> 	
	<a href="javascript:;" id="rename-move-button">' . _('rename') . '</a> 
	<a href="javascript:;" id="delete-button">' . _('delete') . '</a> 
</div>
<div id="page-options-area-bottom">
</div>
';
        return $otext;
    }
Example #23
0
 public function renderEdit()
 {
     $m = array();
     $path = array();
     $v = $this->field['value'];
     $path = array();
     if (preg_match($this->rule, $v, $m)) {
         $parts = explode(']]]', $v);
         foreach ($parts as $part) {
             $m = array();
             if (preg_match(':^[^[]*\\[\\[\\[([^|]*)([|]|$):', $part, $m)) {
                 $path[] = WDStringUtils::toUnixName($m[1]);
             }
         }
     }
     $path[] = '';
     $selects = array();
     $c = new Criteria();
     $c->add('name', $this->field['category']);
     if ($category = DB_CategoryPeer::instance()->selectOne($c)) {
         $categoryId = $category->getCategoryId();
         $pages = array();
         $parentId = null;
         foreach ($path as $part) {
             $select = "<select>";
             $select .= '<option value=""></option>';
             $pages = $this->selectPagesByParent($categoryId, $parentId);
             $parentId = null;
             foreach ($pages as $page) {
                 $unixName = htmlspecialchars($page->getUnixName());
                 $title = htmlspecialchars($page->getTitleOrUnixName());
                 $selected = "";
                 if ($unixName == $part) {
                     $selected = ' selected="selected"';
                     $parentId = $page->getPageId();
                 }
                 $select .= "<option value=\"{$unixName}\"{$selected}>{$title}</option>";
             }
             $select .= '<option value="+" style="border-top: 1px solid #666; font-weight: bold">Create new</option>';
             $select .= '</select>';
             $selects[] = $select;
             if (!$parentId) {
                 break;
             }
         }
     }
     $selectsEnd = '';
     $selectsNo = count($selects);
     for ($i = 1; $i < count($selects); $i++) {
         $selectsEnd .= '</span>';
     }
     return '<div class="field-pagepath-chooser">' . '<input class="value" type="hidden" name="field_' . $this->field['name'] . '" value="' . $this->hvalue() . '"/>' . '<input class="category" type="hidden" value="' . $this->field['category'] . '"/>' . '<input class="new_page_parent" type="hidden" name="newpageparent_' . $this->field['name'] . '" value=""/>' . '<input class="new_page_title" type="hidden" name="newpagetitle_' . $this->field['name'] . '" value=""/>' . '<span>' . implode("<span> / ", $selects) . '<span></span>' . $selectsEnd . '</span>' . '</div>';
     /*
     in the end we get something like this:
         <div class="field-pagepath-choser">
             <input type="hidden" value="" name=""/>
             <span>
                 <select> <option/> <option/> ... </select> <span>
                     / <select> <option/> <option/> ... </select> <span>
                         / <select> <option/> <option/> ... </select> <span>
                             / <select> <option/> <option/> ... </select> <span>
                             </span>
                         </span>
                     </span>
                 </span>
             </span>
         </div>
     */
 }
Example #24
0
 public function render($runData)
 {
     // get site
     $site = $runData->getTemp("site");
     $runData->contextAdd("site", $site);
     $this->handleNotifications($runData);
     $pl = $runData->getParameterList();
     $wikiPage = $pl->getParameterValue("wiki_page");
     $privateAccessGranted = true;
     // check if the site is private
     if ($site->getPrivate()) {
         $user = $runData->getUser();
         if ($user && !$user->getSuperAdmin() && !$user->getSuperModerator()) {
             // check if member
             $c = new Criteria();
             $c->add("site_id", $site->getSiteId());
             $c->add("user_id", $user->getUserId());
             $mem = DB_MemberPeer::instance()->selectOne($c);
             if (!$mem) {
                 // check if a viewer
                 $c = new Criteria();
                 $c->add("site_id", $site->getSiteId());
                 $c->add("user_id", $user->getUserId());
                 $vi = DB_SiteViewerPeer::instance()->selectOne($c);
                 if (!$vi) {
                     $user = null;
                 }
             }
         }
         if ($user == null) {
             $wikiPage = $site->getSettings()->getPrivateLandingPage();
             $privateAccessGranted = false;
         }
     }
     if ($wikiPage == "") {
         $wikiPage = $site->getDefaultPage();
     }
     $wikiPage = WDStringUtils::toUnixName($wikiPage);
     $runData->setTemp("pageUnixName", $wikiPage);
     $memcache = Ozone::$memcache;
     if ($runData->getAction() == null && $runData->getRequestMethod() == "GET" && $privateAccessGranted) {
         // try to get content from the memorycache server
         $mcKey = 'page..' . $site->getUnixName() . '..' . $wikiPage;
         if (strpos($wikiPage, ":") != false) {
             $tmp0 = explode(':', $wikiPage);
             $categoryName = $tmp0[0];
         } else {
             $categoryName = "_default";
         }
         $aKey = 'category_lc..' . $site->getUnixName() . '..' . $categoryName;
         $changeTime = $memcache->get($aKey);
         $cachedPage = $memcache->get($mcKey);
         if ($cachedPage !== false && $changeTime && $changeTime <= $cachedPage['timestamp']) {
             $runData->setTemp("page", $cachedPage['page']);
             $GLOBALS['page'] = $cachedPage['page'];
             $out = $cachedPage['content'];
             if ($this->vars['notificationsDialog']) {
                 $out = preg_replace(';<div id="account-notifications-dummy" style="display:none"></div>;', '<div id="notifications-dialog" style="display:none">' . $this->vars['notificationsDialog'] . '</div>', $out, 1);
             }
             return $out;
         } else {
             $storeLater = true;
         }
     }
     $runData->contextAdd("wikiPageName", $wikiPage);
     $settings = $site->getSettings();
     // get wiki page from the database
     $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $wikiPage);
     if ($page == null) {
         $runData->contextAdd("pageNotExists", true);
         // get category based on suggested page name
         if (strpos($wikiPage, ":") != false) {
             $tmp0 = explode(':', $wikiPage);
             $categoryName = $tmp0[0];
         } else {
             $categoryName = "_default";
         }
         $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId());
         if ($category == null) {
             $category = DB_CategoryPeer::instance()->selectByName('_default', $site->getSiteId());
         }
         $runData->setTemp("category", $category);
     } else {
         // page exists!!! wooo!!!
         $runData->setTemp("page", $page);
         $GLOBALS['page'] = $page;
         $compiled = $page->getCompiled();
         $runData->contextAdd("wikiPage", $page);
         $runData->contextAdd("pageContent", $compiled->getText());
         $category = $page->getCategory();
         $runData->setTemp("category", $category);
         // show options?
         $showPageOptions = true;
         $runData->contextAdd("showPageoptions", $showPageOptions);
         // get the tags
         $c = new Criteria();
         $c->add("page_id", $page->getPageId());
         $c->addOrderAscending("tag");
         $tags = DB_PageTagPeer::instance()->select($c);
         $t2 = array();
         foreach ($tags as $t) {
             $t2[] = $t->getTag();
         }
         $runData->contextAdd("tags", $t2);
         // has discussion?
         if ($page->getThreadId() !== null) {
             $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($page->getThreadId());
             if ($thread == null) {
                 $page->setThreadId(null);
                 $page->save();
             } else {
                 $page->setTemp("numberPosts", $thread->getNumberPosts());
             }
         }
         // look for parent pages (and prepare breadcrumbs)
         if ($page->getParentPageId()) {
             $breadcrumbs = array();
             $ppage = DB_PagePeer::instance()->selectByPrimaryKey($page->getParentPageId());
             array_unshift($breadcrumbs, $ppage);
             $bcount = 0;
             while ($ppage->getParentPageId() && $bcount <= 4) {
                 $ppage = DB_PagePeer::instance()->selectByPrimaryKey($ppage->getParentPageId());
                 array_unshift($breadcrumbs, $ppage);
                 $bcount++;
             }
             $runData->contextAdd("breadcrumbs", $breadcrumbs);
         }
     }
     $runData->contextAdd("category", $category);
     // GET THEME for the category
     $theme = $category->getTheme();
     $runData->contextAdd("theme", $theme);
     // GET LICENSE for the category
     $licenseText = $category->getLicenseText();
     $runData->contextAdd("licenseText", $licenseText);
     // show nav elements?
     if ($privateAccessGranted || !$settings->getHideNavigationUnauthorized()) {
         if ($theme->getUseSideBar()) {
             $sideBar1 = $category->getSidePage();
             if ($sideBar1 !== null) {
                 $sideBar1Compiled = $sideBar1->getCompiled();
                 $ccc = $sideBar1Compiled->getText();
                 $ccc = preg_replace('/id="[^"]*"/', '', $ccc);
                 $runData->contextAdd("sideBar1Content", $ccc);
             }
         }
         if ($theme->getUseTopBar()) {
             $topBar = $category->getTopPage();
             if ($topBar !== null) {
                 $topBarCompiled = $topBar->getCompiled();
                 $ccc = $topBarCompiled->getText();
                 $ccc = preg_replace('/id="[^"]*"/', '', $ccc);
                 $runData->contextAdd("topBarContent", $ccc);
             }
         }
     }
     // OpenID stuff now !!!
     if ($settings->getOpenidEnabled() && $page) {
         // find a page
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         if ($_SERVER['REQUEST_URI'] == "/") {
             $c->add("page_id", null);
         } else {
             $c->add("page_id", $page->getPageId());
         }
         $oentry = DB_OpenidEntryPeer::instance()->selectOne($c);
         if ($oentry) {
             $openId = array();
             $openId['enabled'] = true;
             $openId['identity'] = $oentry->getUrl();
             $openId['server'] = $oentry->getServerUrl();
             $runData->contextAdd("openId", $openId);
         }
     }
     // check wether to include a special JS file for custom domains or a special JS file for private files
     //if (preg_match('/^([a-zA-Z0-9\-]+)\.' . GlobalProperties::$URL_DOMAIN_PREG . '$/',$_SERVER["HTTP_HOST"], $matches) !==1) {
     //	$runData->contextAdd("useCustomDomainScript", true);
     //}
     $smarty = Ozone::getSmarty();
     // put context into context
     $context = $runData->getContext();
     if ($context !== null) {
         foreach ($context as $key => $value) {
             $smarty->assign($key, $value);
         }
     }
     $templateFile = PathManager::screenTemplate("wiki/WikiScreen");
     $screenContent = $smarty->fetch($templateFile);
     $smarty->assign("screen_placeholder", $screenContent);
     $layoutFile = PathManager::layoutTemplate("WikiLayout");
     $out = $smarty->fetch($layoutFile);
     if ($storeLater) {
         $now = time();
         if (!$changeTime) {
             $memcache->set($aKey, $now, 0, 864000);
         }
         $memcache->set($mcKey, array("page" => $page, "content" => $out, "timestamp" => $now), 0, 864000);
     }
     if ($this->vars['notificationsDialog']) {
         $out = preg_replace(';<div id="account-notifications-dummy" style="display:none"></div>;', '<div id="notifications-dialog" style="display:none">' . $this->vars['notificationsDialog'] . '</div>', $out, 1);
     }
     return $out;
 }
Example #25
0
 /**
  * Dumps everything.
  */
 public function dumpSite($site)
 {
     $dump = array();
     $superSettings = $site->getSuperSettings();
     $settings = $site->getSettings();
     $fs = $site->getForumSettings();
     $dump['superSettings'] = $superSettings;
     $dump['settings'] = $settings;
     $dump['forumSettings'] = $fs;
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $categories = DB_CategoryPeer::instance()->select($c);
     $dump['categories'] = $categories;
     $dump['pages'] = array();
     foreach ($categories as $cat) {
         $c = new Criteria();
         $c->add("category_id", $cat->getCategoryId());
         $pages = DB_PagePeer::instance()->select($c);
         foreach ($pages as &$p) {
             $p->setTemp("source", $p->getSource());
             $p->setTemp("meta", $p->getMetadata());
         }
         $dump['pages'][$cat->getCategoryId()] = $pages;
     }
     return $dump;
 }
Example #26
0
 protected function _parseCategory($site, $category)
 {
     if (is_int($category)) {
         // int = ID
         $category = DB_SitePeer::instance()->selectByPrimaryKey($category);
     } elseif (is_string($category)) {
         if ($site) {
             $c = new Criteria();
             $c->add("name", WDStringUtils::toUnixName($category));
             $c->add("site_id", $site->getSiteId());
             $category = DB_CategoryPeer::instance()->selectOne($c);
         }
     }
     if ($category instanceof DB_Category) {
         return $category;
     }
     throw new Wikidot_Facade_Exception_WrongArguments("Category does not exist");
 }
Example #27
0
 public function getRatingString()
 {
     $ppd = $this->getRating();
     if (strpos($ppd, 'e') === false && strpos($ppd, 'd') === false && $this->getName() !== '_default') {
         $dc = DB_CategoryPeer::instance()->selectByName('_default', $this->getSiteId());
         $ppd = $dc->getRating();
     }
     if ($ppd === null) {
         $ppd = 'd';
     }
     return $ppd;
 }
Example #28
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $this->_pl = $pl;
     $site = $runData->getTemp("site");
     $categoryName = $this->_readParameter(array('category', 'categories'), false);
     $categoryName = strtolower($categoryName);
     $startPage = $this->_readParameter(array('startPage', 'targetPage'));
     if (!$startPage) {
         /* Get curent page. */
         $startPage = $runData->getTemp('pageUnixName');
         if (!$startPage) {
             $startPage = $pl->getParameterValue('page_unix_name');
             // from preview
         }
     }
     $categories = array();
     $categoryNames = array();
     if ($categoryName != '*') {
         if (!$categoryName) {
             /* No category name specified, use the current category! */
             $pageUnixName = $runData->getTemp('pageUnixName');
             if (!$pageUnixName) {
                 $pageUnixName = $pl->getParameterValue('page_unix_name');
                 // from preview
             }
             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."));
     //}
     $attrUrlPrefix = $pl->getParameterValue('urlAttrPrefix');
     // 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 = $this->_readParameter(array('tag', 'tags'), true);
     //var_dump($tagString);
     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;
             }
         }
         /* 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);
         }
     }
     $c->addGroupBy('datestring');
     $db = Database::connection();
     $corig = clone $c;
     $c->setExplicitFields("EXTRACT(YEAR FROM date_created)::varchar || '.' || EXTRACT(MONTH FROM date_created)::varchar as datestring, count(*) as c");
     //$c->addOrderDescending("regexp_replace(datestring, '\.[0-9]+$', '')::integer");
     //$c->addOrderDescending("regexp_replace(datestring, '^[0-9]+\.', '')::integer");
     $q = DB_PagePeer::instance()->criteriaToQuery($c);
     $r = $db->query($q);
     $r = $r->fetchAll();
     if ($r === false) {
         $r = array();
     }
     $postCount = array();
     if ($lang == 'pl') {
         $locale = 'pl_PL';
     }
     setlocale(LC_TIME, $locale);
     foreach ($r as $mo) {
         $spl = explode('.', $mo['datestring']);
         $year = $spl[0];
         $month = $spl[1];
         $postCount[$year]['months'][$month]['count'] = $mo['c'];
         /* Month names. */
         $lang = $site->getLanguage();
         $locale = 'en_US';
         $postCount[$year]['months'][$month]['name'] = strftime('%B', mktime(6, 6, 6, $month, 6, $year));
     }
     //$c = clone($corig);
     $c->setExplicitFields("EXTRACT(YEAR FROM date_created)::varchar as datestring, count(*) as c");
     $q = DB_PagePeer::instance()->criteriaToQuery($c);
     $r = $db->query($q);
     $r = $r->fetchAll();
     if ($r === false) {
         $r = array();
     }
     foreach ($r as $mo) {
         $postCount[$mo['datestring']]['count'] = $mo['c'];
     }
     /* Order the results. */
     /* Order years. */
     krsort($postCount, SORT_NUMERIC);
     foreach ($postCount as &$year) {
         krsort($year['months'], SORT_NUMERIC);
     }
     $uprefix = '';
     if ($attrUrlPrefix) {
         $uprefix = $attrUrlPrefix . '_';
     }
     /* Get current (selected) date (if any). */
     $date = $this->_pl->getParameterValue($uprefix . "date", "GET");
     $dateA = array();
     if (preg_match(';^[0-9]{4}$;', $date)) {
         $dateA['year'] = $date;
         if (isset($postCount[$date])) {
             $postCount[$date]['selected'] = true;
         }
     }
     if (preg_match(';^[0-9]{4}\\.[0-9]{1,2}$;', $date)) {
         $dateS = explode('.', $date);
         $dateA['year'] = $dateS[0];
         $dateA['month'] = $dateS[1];
         if (isset($postCount[$dateA['year']]['months'][$dateA['month']])) {
             $postCount[$dateA['year']]['months'][$dateA['month']]['selected'] = true;
         }
     }
     $runData->contextAdd('postCount', $postCount);
     $startUrlBase = '/' . $startPage;
     if ($tagString) {
         $startUrlBase .= '/' . $uprefix . 'tag/' . urldecode($tagString);
     }
     $startUrlBase .= '/' . $uprefix . 'date/';
     $runData->contextAdd('startUrlBase', $startUrlBase);
     //var_dump($postCount);
     $runData->contextAdd('attrUrlPrefix', $attrUrlPrefix);
     return;
 }
Example #29
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     $limit = $pl->getParameterValue("limit", "MODULE");
     if ($limit === null || !is_numeric($limit) || $limit < 1 || $limit > 300) {
         $limit = 10;
     }
     $order = $pl->getParameterValue("order");
     $minRating = $pl->getParameterValue("minRating");
     if ($minRating !== null && !is_numeric($minRating)) {
         $minRating = null;
     }
     $maxRating = $pl->getParameterValue("maxRating");
     if ($maxRating !== null && !is_numeric($maxRating)) {
         $maxRating = null;
     }
     $showComments = $pl->getParameterValue("comments", "MODULE");
     $categoryName = $pl->getParameterValue("category", "MODULE", "AMODULE");
     if ($categoryName !== null) {
         $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId());
         if ($category == null) {
             throw new ProcessException(_("The category can not be found."));
         }
     }
     $c = new Criteria();
     if ($category) {
         $c->add("category_id", $category->getCategoryId());
     }
     $c->add("site_id", $site->getSiteId());
     if ($minRating !== null) {
         $c->add("rate", $minRating, '>=');
     }
     if ($maxRating !== null) {
         $c->add("rate", $maxRating, '<=');
     }
     switch ($order) {
         case 'date-created-asc':
             $c->addOrderAscending("date_created");
             break;
         case 'date-created-desc':
             $c->addOrderDescending("date_created");
             break;
         case 'rate-asc':
             $c->addOrderAscending("rate");
             break;
         case 'rating-asc':
             $c->addOrderAscending("rate");
             break;
         default:
             $c->addOrderDescending("rate");
             break;
     }
     $c->addOrderAscending("COALESCE(title, unix_name)");
     if ($limit) {
         $c->setLimit($limit);
     }
     $pages = DB_PagePeer::instance()->select($c);
     if ($showComments) {
         foreach ($pages as &$page) {
             if ($page->getThreadId()) {
                 $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($page->getThreadId());
                 $noc = $thread->getNumberPosts();
             } else {
                 $noc = 0;
             }
             $page->setTemp("numberComments", $noc);
         }
     }
     $runData->contextAdd("pages", $pages);
 }