Ejemplo n.º 1
0
 public function selectPagesByParent($categoryId, $parentId)
 {
     $c = new Criteria();
     $categoryId = (int) $categoryId;
     $parentId = (int) $parentId;
     if ($parentId) {
         $c->setExplicitQuery("SELECT * FROM page WHERE category_id = {$categoryId} AND parent_page_id = {$parentId}");
     } else {
         $c->setExplicitQuery("SELECT * FROM page WHERE category_id = {$categoryId} AND parent_page_id IS NULL");
     }
     return DB_PagePeer::instance()->select($c);
 }
Ejemplo n.º 2
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     $themeId = $pl->getParameterValue('theme_id');
     if ($themeId === null) {
         $themeUrl = current($_GET);
         // BAD HACK!!!
         if ($themeUrl) {
             $theme = $this->getExternalTheme($themeUrl);
         } else {
             $page = $runData->getTemp("page");
             if ($page == null) {
                 throw new ProcessException(_("Not working in the preview mode. Not a preview mode? So it might be an error."));
             }
             $theme = $page->getCategory()->getTheme();
         }
     } else {
         $theme = DB_ThemePeer::instance()->selectByPrimaryKey($themeId);
     }
     //$this->themeId = $themeId;
     if ($theme == null || $theme->getAbstract() == true || $theme->getCustom == true && $theme->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("Error selecting theme."));
     }
     $this->theme = $theme;
     $q = "SELECT * from theme WHERE " . "abstract = FALSE  " . "AND (custom = FALSE" . " OR (custom = TRUE AND site_id='" . $site->getSiteId() . "' AND site_id !=1)" . ") " . "ORDER BY custom, sort_index, replace(name, '_', '00000000');";
     $c = new Criteria();
     $c->setExplicitQuery($q);
     $themes = DB_ThemePeer::instance()->select($c);
     $runData->contextAdd("themes", $themes);
     $runData->contextAdd("currentTheme", $theme);
     $runData->contextAdd("noUi", $pl->getParameterValue('noUi'));
 }
Ejemplo n.º 3
0
 public function getFiles()
 {
     $q = "SELECT * FROM file WHERE page_id='" . $this->getPageId() . "' ORDER BY filename, file_id DESC";
     $c = new Criteria();
     $c->setExplicitQuery($q);
     return DB_FilePeer::instance()->select($c);
 }
Ejemplo n.º 4
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $totalAll = (bool) $pl->getParameterValue('totalAll');
     $user = $runData->getUser();
     $c = new Criteria();
     if ($totalAll) {
         $q = "SELECT site.* FROM site, member WHERE member.user_id = '{$user->getUserId()}' AND member.site_id = site.site_id " . "ORDER BY site.name";
         $c->setExplicitQuery($q);
         $ss = DB_SitePeer::instance()->select($c);
         $sites = array();
         foreach ($ss as $s) {
             $sites[$s->getUnixName()] = array('site' => $s);
         }
     } else {
         $q = "SELECT email_list.* FROM email_list, email_list_subscriber, site WHERE email_list_subscriber.user_id = {$user->getUserId()} " . "AND email_list_subscriber.list_id = email_list.list_id AND email_list.site_id = site.site_id " . "ORDER BY site.name, email_list.title";
         $c->setExplicitQuery($q);
         $lists = DB_EmailListPeer::instance()->select($c);
         // sorry  for the DIIIIRTY STYLE!!!
         $sites = array();
         foreach ($lists as $l) {
             $s = DB_SitePeer::instance()->selectByPrimaryKey($l->getSiteId());
             if (!isset($sites[$s->getUnixName()])) {
                 $sites[$s->getUnixName()] = array('site' => $s, 'lists' => array());
             }
             $sites[$s->getUnixName()]['lists'][] = $l;
             $l->setTemp('site', $s);
         }
     }
     $runData->contextAdd('lists', $lists);
     $runData->contextAdd('sites', $sites);
     $runData->contextAdd('totalAll', $totalAll);
     $runData->contextAdd('user', $user);
 }
 public function build($runData)
 {
     $user = $runData->getUser();
     $c = new Criteria();
     $pl = $runData->getParameterList();
     $siteId = $pl->getParameterValue('siteId');
     $all = (bool) $pl->getParameterValue('all');
     $site = DB_SitePeer::instance()->selectByPrimaryKey($siteId);
     if ($all) {
         $q = "SELECT email_list.* FROM email_list WHERE " . "email_list.site_id = '{$site->getSiteId()}' " . "ORDER BY email_list.title";
         $c->setExplicitQuery($q);
         $lists = DB_EmailListPeer::instance()->select($c);
         // check if subscribed
         foreach ($lists as $list) {
             $c2 = new Criteria();
             $c2->add('user_id', $user->getUserId());
             $c2->add('list_id', $list->getListId());
             $sub = DB_EmailListSubscriberPeer::instance()->selectOne($c2);
             if ($sub) {
                 $list->setTemp('subscribed', true);
             }
         }
     } else {
         // only subscribed
         $q = "SELECT email_list.* FROM email_list, email_list_subscriber WHERE email_list_subscriber.user_id = {$user->getUserId()} " . "AND email_list_subscriber.list_id = email_list.list_id AND email_list.site_id = '{$site->getSiteId()}' " . "ORDER BY email_list.title";
         $c->setExplicitQuery($q);
         $lists = DB_EmailListPeer::instance()->select($c);
         foreach ($lists as $list) {
             $list->setTemp('subscribed', true);
         }
     }
     $runData->contextAdd('all', $all);
     $runData->contextAdd('lists', $lists);
     $runData->contextAdd('site', $site);
 }
Ejemplo n.º 6
0
 public function getSourceText()
 {
     if ($this->getDiffSource() == false) {
         $c = new Criteria();
         $c->add("source_id", $this->getSourceId());
         $source = DB_PageSourcePeer::instance()->selectOne($c);
         return $source->getText();
     } else {
         // select last revisions and sources.
         $q = "SELECT page_source.* FROM page_source, page_revision WHERE " . "page_revision.page_id =" . $this->getPageId() . " " . "AND page_revision.revision_id <= " . $this->getRevisionId() . " " . "AND (page_revision.flag_text = TRUE OR page_revision.flag_new = TRUE) " . "AND page_revision.source_id = page_source.source_id " . "ORDER BY page_revision.revision_id DESC " . "LIMIT " . ($this->getSinceFullSource() + 1);
         $c = new Criteria();
         $c->setExplicitQuery($q);
         $sources = DB_PageSourcePeer::instance()->select($c);
         // original source...
         $s = end($sources);
         $s0 = $s->getText();
         $differ = new ODiff();
         while ($s = prev($sources)) {
             $s0 = $differ->patchString($s0, $s->getText());
             if ($differ->getErrors() != null) {
                 return "Error processing the source - please report the problem to the support";
             }
         }
         return trim($s0);
     }
 }
Ejemplo n.º 7
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $root = $pl->getParameterValue("root");
     $showRoot = $pl->getParameterValue("showRoot");
     if (!$root) {
         $page = $runData->getTemp("page");
     } else {
         $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $root);
     }
     if (!$page) {
         $runData->setModuleTemplate("Empty");
         return;
     }
     $depth = $pl->getParameterValue("depth");
     if (!$depth || !is_numeric($depth) || $depth < 1) {
         $depth = 5;
     }
     $tree = array();
     $c = new Criteria();
     $c->add("parent_page_id", $page->getPageId());
     $c->addOrderAscending("COALESCE(title, unix_name)");
     $children = DB_PagePeer::instance()->select($c);
     $descendants = array();
     // select next level of children
     $ch1 = $children;
     $d = 0;
     while ($ch1 != null && count($ch1) > 0 && (!$depth || $d < $depth)) {
         $q = "SELECT * FROM page WHERE parent_page_id IN (";
         $tch = array();
         foreach ($ch1 as $ch) {
             // check if already in the $tch
             if (!array_key_exists($ch->getPageId(), $descendants)) {
                 $tch[] = $ch->getPageId();
                 $descendants[$ch->getParentPageId()][] = $ch;
             } else {
                 $ch->setTemp('circular', true);
                 $descendants[$ch->getParentPageId()][] = $ch;
             }
         }
         if (count($tch) > 0) {
             $q .= implode(',', $tch);
             $q .= ") ORDER BY COALESCE(title, unix_name)";
             $c = new Criteria();
             $c->setExplicitQuery($q);
             $ch2 = DB_PagePeer::instance()->select($c);
             $ch1 = $ch2;
         } else {
             $ch1 = null;
         }
         $d++;
     }
     $runData->contextAdd("root", $page);
     $runData->contextAdd("children", $descendants);
     if ($showRoot) {
         $runData->contextAdd("showRoot", true);
     }
 }
Ejemplo n.º 8
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $siteId = $site->getSiteId();
     $q = "SELECT *, count(*) AS number_links FROM page, page_link " . "WHERE page.site_id = '{$siteId}' AND page_link.to_page_id=page.page_id " . "GROUP BY (page.page_id) " . "ORDER BY COALESCE(page.title, page.unix_name)";
     $q = "SELECT * FROM page " . "WHERE page.site_id = '{$siteId}'" . "AND (SELECT count(*) FROM page_link WHERE page_link.to_page_id = page.page_id) = 0 " . "ORDER BY COALESCE(page.title, page.unix_name)";
     $c = new Criteria();
     $c->setExplicitQuery($q);
     $pages = DB_PagePeer::instance()->select($c);
     $runData->contextAdd("pages", $pages);
 }
Ejemplo n.º 9
0
 public function build($runData)
 {
     $user = $runData->getUser();
     $runData->contextAdd("user", $user);
     $pl = $runData->getParameterList();
     // get watched pages for this user
     $c = new Criteria();
     $q = "SELECT page.* FROM watched_page, page " . "WHERE watched_page.user_id='" . $user->getUserId() . "' " . "AND watched_page.page_id=page.page_id";
     $c->setExplicitQuery($q);
     $pages = DB_PagePeer::instance()->select($c);
     $runData->contextAdd("pages", $pages);
     $runData->contextAdd("pagesCount", count($pages));
 }
Ejemplo n.º 10
0
 public function build($runData)
 {
     $page = $runData->getTemp("page");
     if (!$page) {
         return;
     }
     $pageId = $page->getPageId();
     // create a very custom query ;-)
     $c = new Criteria();
     $q = "SELECT page_id, title, unix_name FROM page_link, page " . "WHERE page_link.to_page_id='" . db_escape_string($pageId) . "' " . "AND page_link.from_page_id=page.page_id ORDER BY COALESCE(title, unix_name)";
     $c->setExplicitQuery($q);
     $pages = DB_PagePeer::instance()->select($c);
     $runData->contextAdd("pages", $pages);
 }
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $runData->contextAdd("site", $site);
     $runData->contextAdd("settings", $site->getSettings());
     $runData->contextAdd("superSettings", $site->getSuperSettings());
     // get the viewers
     $c = new Criteria();
     $q = "SELECT ozone_user.* FROM ozone_user, site_viewer WHERE site_viewer.site_id='" . $site->getSiteId() . "' " . "AND ozone_user.user_id = site_viewer.user_id ORDER BY ozone_user.nick_name";
     $c->setExplicitQuery($q);
     $viewers = DB_OzoneUserPeer::instance()->select($c);
     $runData->contextAdd("viewers", $viewers);
     $runData->contextAdd("settings", $site->getSettings());
 }
Ejemplo n.º 12
0
 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);
 }
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $showAll = (bool) $runData->getParameterList()->getParameterValue("showAll");
     // get  invitations
     $c = new Criteria();
     if (!$showAll) {
         $q = "SELECT * FROM email_invitation, admin " . "WHERE admin.site_id='" . $site->getSiteId() . "' " . "AND email_invitation.site_id='" . $site->getSiteId() . "' " . "AND admin.user_id = email_invitation.user_id ORDER BY invitation_id DESC";
         $c->setExplicitQuery($q);
     } else {
         $c->add("site_id", $site->getSiteId());
         $c->addOrderDescending("invitation_id");
     }
     $invitations = DB_EmailInvitationPeer::instance()->select($c);
     $runData->contextAdd("invitations", $invitations);
     $runData->contextAdd("showAll", $showAll);
 }
Ejemplo n.º 14
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $categoryId = $pl->getParameterValue("c");
     $pageNumber = $pl->getParameterValue("p");
     if ($pageNumber == null || !is_numeric($pageNumber) || $pageNumber < 1) {
         $pageNumber = 1;
     }
     $sort = $pl->getParameterValue("sort");
     // the criteria is: have >= 20 edits.
     // first - count them all
     //$q =
     $c = new Criteria();
     $q = "SELECT site.* FROM site WHERE  site.visible = TRUE AND site.private = FALSE AND site.deleted = FALSE AND site.site_id != 1 AND (SELECT count(*) FROM page WHERE page.site_id = site.site_id) > 15 ORDER BY site.name";
     $c->setExplicitQuery($q);
     $sites = DB_SitePeer::instance()->select($c);
     $runData->contextAdd("sites", $sites);
 }
Ejemplo n.º 15
0
 public function build($runData)
 {
     $pageId = $runData->getParameterList()->getParameterValue("page_id");
     if (!$pageId || !is_numeric($pageId)) {
         throw new ProcessException(_("The page can not be found or does not exist."), "no_page");
     }
     // create a very custom query ;-)
     $c = new Criteria();
     $q = "SELECT page_id, title, unix_name FROM page_link, page " . "WHERE page_link.to_page_id='" . db_escape_string($pageId) . "' " . "AND page_link.from_page_id=page.page_id 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_id='" . db_escape_string($pageId) . "' " . "AND page_inclusion.including_page_id=page.page_id ORDER BY COALESCE(title, unix_name)";
     $c->setExplicitQuery($q);
     $pagesI = DB_PagePeer::instance()->select($c);
     $runData->contextAdd("pagesI", $pagesI);
     $runData->contextAdd("pages", $pages);
     $runData->contextAdd("pagesCount", count($pages));
 }
Ejemplo n.º 16
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     // get recent forum threads
     $pl = $runData->getParameterList();
     $limit = $pl->getParameterValue("limit", "MODULE");
     if ($limit == null || !is_numeric($limit) || $limit < 1 || $limit > 300) {
         $limit = 5;
     }
     $date = new ODate();
     $date->addSeconds(-60 * 60 * 24 * 7);
     // 7 days
     $q = "SELECT forum_thread.thread_id, count(*) AS count FROM forum_thread, forum_post " . "WHERE forum_thread.site_id='" . $site->getSiteId() . "' " . "AND forum_thread.thread_id = forum_post.thread_id " . "AND forum_post.date_posted > '" . $date->getDate() . "' " . "GROUP BY forum_thread.thread_id ORDER BY count DESC LIMIT " . db_escape_string($limit);
     $c = new Criteria();
     $c->setExplicitQuery($q);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     foreach ($threads as &$thread) {
         $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($thread->getThreadId());
     }
     $runData->contextAdd("threads", $threads);
 }
Ejemplo n.º 17
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $lang = $pl->getParameterValue("lang");
     if ($lang && $lang !== "pl" && $lang !== "en") {
         $lang = null;
     }
     $c = new Criteria();
     /*
     		$c->add("flag_new_site", false);
     		$c->add("page.site_id", 1, '!=');
     		$c->addJoin("page_id", "page.page_id");
     		$c->addOrderDescending("page_revision.revision_id");
     		$c->setLimit(30);
     
     		$revs = DB_PageRevisionPeer::instance()->select($c);
     		
     		// check for duplications
     		$revs2 = array();
     		
     		foreach($revs as $r){
     			$pageId = $r->getPageId();
     			if($revs2[$pageId] == null){
     				$revs2[$pageId] = $r;	
     			}	
     		}
     		
     		$revs2 = array_slice($revs2, 0, 10);
     		
     		$runData->contextAdd("revisions", $revs2);
     */
     $q = "SELECT page.* FROM page, page_revision, site WHERE " . "page_revision.flag_new_site = FALSE " . "AND site.visible = TRUE AND site.private = FALSE \n\t\t\t\tAND site.deleted = FALSE ";
     if ($lang) {
         $q .= "AND site.language = '" . db_escape_string($lang) . "' ";
     }
     $q .= "AND page.site_id != 1" . "AND page.revision_id = page_revision.revision_id " . "AND page.site_id = site.site_id " . "ORDER BY page.revision_id DESC LIMIT 10";
     $c->setExplicitQuery($q);
     $pages = DB_PagePeer::instance()->select($c);
     $runData->contextAdd("pages", $pages);
 }
Ejemplo n.º 18
0
 public function build($runData)
 {
     $user = $runData->getUser();
     $runData->contextAdd("user", $user);
     $pl = $runData->getParameterList();
     // get watched threads for this user
     $c = new Criteria();
     /*$c->add("watched_forum_thread.user_id", $user->getUserId());
     		$c->addJoin("thread_id", "forum_thread.thread_id");
     		$c->addOrderAscending("watched_id");
     		*/
     /*
     $c->setExplicitFrom("forum_thread, watched_forum_thread");
     $c->add("watched_forum_thread.user_id", $user->getUserId());
     $c->
     */
     $q = "SELECT forum_thread.* FROM watched_forum_thread, forum_thread " . "WHERE watched_forum_thread.user_id='" . $user->getUserId() . "' " . "AND watched_forum_thread.thread_id=forum_thread.thread_id";
     $c->setExplicitQuery($q);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     $runData->contextAdd("threads", $threads);
     $runData->contextAdd("threadsCount", count($threads));
 }
 public function build($runData)
 {
     $site = $runData->getTemp('site');
     $pl = $runData->getParameterList();
     $listId = $pl->getParameterValue("listId");
     $db = Database::connection();
     $db->begin();
     // get the list
     $c = new Criteria();
     $c->add('site_id', $site->getSiteId());
     $c->add('list_id', $listId);
     $list = DB_EmailListPeer::instance()->selectOne($c);
     if (!$list) {
         throw new ProcessException('The requested list  cannot be found.');
     }
     // get all subscribers
     $q = "SELECT ozone_user.* FROM email_list_subscriber, ozone_user WHERE " . "email_list_subscriber.list_id = '{$list->getListId()}' AND email_list_subscriber.user_id = ozone_user.user_id " . "ORDER BY ozone_user.nick_name";
     $c = new Criteria();
     $c->setExplicitQuery($q);
     $users = DB_OzoneUserPeer::instance()->select($c);
     $runData->contextAdd('users', $users);
     $runData->contextAdd('list', $list);
     $runData->contextAdd('site', $site);
 }
Ejemplo n.º 20
0
 public function build($runData)
 {
     $pageId = $runData->getParameterList()->getParameterValue("page_id");
     // create a very custom query ;-)
     $c = new Criteria();
     $q = "SELECT page_id, title, unix_name FROM page_link, page " . "WHERE page_link.to_page_id='" . db_escape_string($pageId) . "' " . "AND page_link.from_page_id=page.page_id 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_id='" . db_escape_string($pageId) . "' " . "AND page_inclusion.including_page_id=page.page_id ORDER BY COALESCE(title, unix_name)";
     $c = new Criteria();
     $c->setExplicitQuery($q);
     $pagesI = DB_PagePeer::instance()->select($c);
     $merged = array();
     foreach ($pages as $key => $p) {
         $merged[$p->getPageId()] = $p;
     }
     foreach ($pagesI as $key => $p) {
         $merged[$p->getPageId()] = $p;
     }
     $runData->contextAdd("pages", $pages);
     $runData->contextAdd("pagesI", $pagesI);
     $runData->contextAdd("merged", $merged);
     $runData->contextAdd("pagesCount", count($pages));
 }
Ejemplo n.º 21
0
 public function sendEmailInvitationsEvent($runData)
 {
     $pl = $runData->getParameterList();
     $user = $runData->getUser();
     $site = $runData->getTemp("site");
     $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
     $addresses = $json->decode($pl->getParameterValue("addresses"));
     $message = $pl->getParameterValue("message");
     // check if data is valid
     if (count($addresses) > 200) {
         throw new ProcessException(_("You should not send more than 200 invitations at once."));
     }
     foreach ($addresses as $address) {
         $email = trim($address[0]);
         $name = trim($address[1]);
         if (!preg_match("/^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)+\$/", $email) || strlen($email) > 70 || strlen($email) == 0) {
             throw new ProcessException(sprintf(_('Email "%s" is not valid.'), htmlspecialchars($email)), "bad_email");
         }
         if (preg_match(';://;', $name) || preg_match(';\\.www;i', $name) || strlen8($name) > 50 || strlen8($name) == 0) {
             throw new ProcessException(sprintf(_('Recipient\'s name "%s" is not valid.'), htmlspecialchars($name)), "bad_name");
         }
         //check if "email" is not already a member of this site...
         $q = " SELECT * FROM member, ozone_user WHERE member.site_id='" . $site->getSiteId() . "' AND ozone_user.name='" . db_escape_string($email) . "' AND member.user_id = ozone_user.user_id LIMIT 1";
         $c = new Criteria();
         $c->setExplicitQuery($q);
         $m = DB_MemberPeer::instance()->selectOne($c);
         if ($m) {
             throw new ProcessException(sprintf(_('User with the email address "%s" is already a member of this Site. Remove him from the list and send invitations again.'), htmlspecialchars($email)), 'aleady_member');
         }
         // check if not sent already to this address.
         $c = new Criteria();
         $c->add("email", $email);
         $c->add("site_id", $site->getSiteId());
         $ii = DB_EmailInvitationPeer::instance()->selectOne($c);
         if ($ii) {
             throw new ProcessException(sprintf(_('User with the email address "%s" has been already invited to this Site. Remove him from the list and send invitations again. If you want to resend an invitation please rather look at the history of sent invitations.'), htmlspecialchars($email)), 'aleady_member');
         }
     }
     if (preg_match(';://;', $message) || preg_match(';www\\.;i', $message)) {
         throw new ProcessException(_('The message should not contain any links to websites.'), "bad_message");
     }
     if ($message != "" && strlen($message) > 1000) {
         throw new ProcessException(_('The message seems to be too long. Max 1000 characters are allowed.'), "bad_message");
     }
     // now prepare invitation and send!
     $db = Database::connection();
     foreach ($addresses as $address) {
         $email = trim($address[0]);
         $name = trim($address[1]);
         $db->begin();
         // each invitation makes a separate transaction
         $hash = substr(md5($name . $email) . time(), 0, 20);
         $inv = new DB_EmailInvitation();
         $inv->setHash($hash);
         $inv->setEmail($email);
         $inv->setName($name);
         $inv->setUserId($user->getUserId());
         $inv->setSiteId($site->getSiteId());
         $inv->setMessage($message);
         $inv->setDate(new ODate());
         if ($address[2]) {
             $inv->setToContacts(true);
         }
         // prepare and send email
         $profile = $user->getProfile();
         $oe = new OzoneEmail();
         $oe->addAddress($email);
         $oe->setSubject(sprintf(_("[%s] %s invites you to join!"), GlobalProperties::$SERVICE_NAME, $user->getNickName()));
         $oe->contextAdd('user', $user);
         $oe->contextAdd('profile', $profile);
         $oe->contextAdd('hash', $hash);
         $oe->contextAdd("site", $site);
         $oe->contextAdd("message", $message);
         $oe->contextAdd('name', $name);
         $oe->setBodyTemplate('MembershipEmailInvitation');
         if (!$oe->Send()) {
             $inv->setDelivered(false);
         } else {
             $inv->setDelivered(true);
         }
         $inv->save();
         $db->commit();
     }
 }
Ejemplo n.º 22
0
 private function checkIpBlocked($ipString, $site)
 {
     $c = new Criteria();
     $ips = explode("|", $ipString);
     $q = "SELECT * FROM ip_block WHERE site_id='" . $site->getSiteId() . "' " . "AND (ip <<= '" . db_escape_string($ips[0]) . "' ";
     if ($ips[1]) {
         $q .= "OR ip <<= '" . db_escape_string($ips[1]) . "'";
     }
     $q .= ")";
     $c->setExplicitQuery($q);
     $blocks = DB_IpBlockPeer::instance()->select($c);
     return $blocks;
 }
Ejemplo n.º 23
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);
 }
Ejemplo n.º 24
0
 public function process()
 {
     global $timeStart;
     // quick fix to prevent recursive RSS access by Wikidot itself.
     if (strpos($_SERVER['HTTP_USER_AGENT'], 'MagpieRSS') !== false) {
         exit;
     }
     // initialize logging service
     $logger = OzoneLogger::instance();
     $loggerFileOutput = new OzoneLoggerFileOutput();
     $loggerFileOutput->setLogFileName(WIKIDOT_ROOT . "/logs/ozone.log");
     $logger->addLoggerOutput($loggerFileOutput);
     $logger->setDebugLevel(GlobalProperties::$LOGGER_LEVEL);
     $logger->debug("request processing started, logger initialized");
     Ozone::init();
     $runData = new RunData();
     $runData->init();
     Ozone::setRunData($runData);
     $logger->debug("RunData object created and initialized");
     // check if site (wiki) exists!
     $siteHost = $_SERVER["HTTP_HOST"];
     $memcache = Ozone::$memcache;
     if (preg_match("/^([a-zA-Z0-9\\-]+)\\." . GlobalProperties::$URL_DOMAIN_PREG . "\$/", $siteHost, $matches) == 1) {
         $siteUnixName = $matches[1];
         // select site based on the unix name
         // check memcached first!
         $mcKey = 'site..' . $siteUnixName;
         $site = $memcache->get($mcKey);
         if (!$site) {
             $c = new Criteria();
             $c->add("unix_name", $siteUnixName);
             $c->add("site.deleted", false);
             $site = DB_SitePeer::instance()->selectOne($c);
             if ($site) {
                 $memcache->set($mcKey, $site, 0, 864000);
             }
         }
     } else {
         // select site based on the custom domain
         $mcKey = 'site_cd..' . $siteHost;
         $site = $memcache->get($mcKey);
         if (!$site) {
             $c = new Criteria();
             $c->add("custom_domain", $siteHost);
             $c->add("site.deleted", false);
             $site = DB_SitePeer::instance()->selectOne($c);
             if ($site) {
                 $memcache->set($mcKey, $site, 0, 3600);
             }
         }
         if (!$site) {
             // check for redirects
             $c = new Criteria();
             $q = "SELECT site.* FROM site, domain_redirect WHERE domain_redirect.url='" . db_escape_string($siteHost) . "' " . "AND site.deleted = false AND site.site_id = domain_redirect.site_id LIMIT 1";
             $c->setExplicitQuery($q);
             $site = DB_SitePeer::instance()->selectOne($c);
             if ($site) {
                 $newUrl = 'http://' . $site->getDomain() . $_SERVER['REQUEST_URI'];
                 header("HTTP/1.1 301 Moved Permanently");
                 header("Location: " . $newUrl);
                 exit;
             }
         }
         GlobalProperties::$SESSION_COOKIE_DOMAIN = '.' . $siteHost;
     }
     if (!$site) {
         $content = file_get_contents(WIKIDOT_ROOT . "/files/site_not_exists.html");
         echo $content;
         return $content;
     }
     $runData->setTemp("site", $site);
     //nasty global thing...
     $GLOBALS['siteId'] = $site->getSiteId();
     $GLOBALS['site'] = $site;
     // set language
     $lang = $site->getLanguage();
     $runData->setLanguage($lang);
     $GLOBALS['lang'] = $lang;
     // and for gettext too:
     switch ($lang) {
         case 'pl':
             $glang = "pl_PL";
             break;
         case 'en':
             $glang = "en_US";
             break;
     }
     putenv("LANG={$glang}");
     putenv("LANGUAGE={$glang}");
     setlocale(LC_ALL, $glang . '.UTF-8');
     // Set the text domain as 'messages'
     $gdomain = 'messages';
     bindtextdomain($gdomain, WIKIDOT_ROOT . '/locale');
     textdomain($gdomain);
     $settings = $site->getSettings();
     // handle SSL
     $sslMode = $settings->getSslMode();
     if ($_SERVER['HTTPS']) {
         if (!$sslMode) {
             // not enabled, redirect to http:
             header("HTTP/1.1 301 Moved Permanently");
             header("Location: " . 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI']);
             exit;
         } elseif ($sslMode == "ssl_only_paranoid") {
             // use secure authentication cookie
             // i.e. change authentication scheme
             GlobalProperties::$SESSION_COOKIE_NAME = "WIKIDOT_SESSION_SECURE_ID";
             GlobalProperties::$SESSION_COOKIE_SECURE = true;
         }
     } else {
         // page accessed via http (nonsecure)
         switch ($sslMode) {
             case 'ssl':
                 //enabled, but nonsecure allowed too.
                 break;
             case 'ssl_only_paranoid':
             case 'ssl_only':
                 header("HTTP/1.1 301 Moved Permanently");
                 header("Location: " . 'https://' . $_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI']);
                 exit;
                 break;
         }
     }
     // handle session at the begging of procession
     $runData->handleSessionStart();
     $template = $runData->getScreenTemplate();
     $classFile = $runData->getScreenClassPath();
     $className = $runData->getScreenClassName();
     $logger->debug("processing template: " . $runData->getScreenTemplate() . ", class: {$className}");
     require_once $classFile;
     $screen = new $className();
     $logger->debug("OZONE initialized");
     $logger->info("Ozone engines successfully initialized");
     $rendered = $screen->render($runData);
     if ($rendered != null) {
         $runData->setTemp("jsInclude", array());
         // process modules...
         $moduleProcessor = new ModuleProcessor($runData);
         //$moduleProcessor->setJavascriptInline(true); // embed associated javascript files in <script> tags
         $moduleProcessor->setCssInline(true);
         $rendered = $moduleProcessor->process($rendered);
         $jss = $runData->getTemp("jsInclude");
         $jss = array_unique($jss);
         $incl = '';
         foreach ($jss as $js) {
             $incl .= '<script type="text/javascript" src="' . $js . '"></script>';
         }
         $rendered = preg_replace(';</head>;', $incl . '</head>', $rendered);
     }
     $runData->handleSessionEnd();
     // one more thing - some url will need to be rewritten if using HTTPS
     if ($_SERVER['HTTPS']) {
         // ?
         // scripts
         $rendered = preg_replace(';<script(.*?)src="http://' . GlobalProperties::$URL_HOST_PREG . '(.*?)</script>;s', '<script\\1src="https://' . GlobalProperties::$URL_HOST . '\\2</script>', $rendered);
         $rendered = preg_replace(';<link(.*?)href="http://' . GlobalProperties::$URL_HOST_PREG . '(.*?)/>;s', '<link\\1href="https://' . GlobalProperties::$URL_HOST . '\\2/>', $rendered);
         $rendered = preg_replace(';(<img\\s+.*?src=")http(://' . GlobalProperties::$URL_HOST_PREG . '(.*?)/>);s', '\\1https\\2', $rendered);
         do {
             $renderedOld = $rendered;
             $rendered = preg_replace(';(<style\\s+[^>]*>.*?@import url\\()http(://' . GlobalProperties::$URL_HOST_PREG . '.*?</style>);si', '\\1https\\2', $rendered);
         } while ($renderedOld != $rendered);
     }
     if (GlobalProperties::$SEARCH_HIGHLIGHT) {
         $rendered = Wikidot_Search_Highlighter::highlightIfSuitable($rendered, $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
     }
     echo str_replace("%%%CURRENT_TIMESTAMP%%%", time(), $rendered);
     return $rendered;
 }