コード例 #1
0
 public function buildPageUrl()
 {
     $page = DB_PagePeer::instance()->selectByPrimaryKey($this->getPageId());
     $site = DB_SitePeer::instance()->selectByPrimaryKey($page->getSiteId());
     $h = 'http://' . $site->getDomain() . '/' . $page->getUnixName();
     return $h;
 }
コード例 #2
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $range = $pl->getParameterValue("range", "AMODULE");
     $dateStart = new ODate();
     if (!in_array($range, array('24h', '7days', 'month'))) {
         $range = '7days';
     }
     switch ($range) {
         case '24h':
             $dateStart->addSeconds(-60 * 60 * 24);
             break;
         case '7days':
             $dateStart->addSeconds(-60 * 60 * 24 * 7);
             break;
         case 'month':
             $dateStart->addSeconds(-60 * 60 * 24 * 31);
             break;
     }
     $q = "SELECT site.site_id, count(*) AS number_changes FROM site, page_revision WHERE page_revision.date_last_edited > '" . $dateStart->getDate() . "' AND site.visible = TRUE AND site.private = FALSE AND site.deleted = FALSE AND site.site_id != 1 AND page_revision.flag_new_site=FALSE AND page_revision.site_id = site.site_id GROUP BY site.site_id ORDER BY number_changes DESC LIMIT 10";
     $db = Database::connection();
     $res = $db->query($q);
     $all = $res->fetchAll();
     if ($all) {
         foreach ($all as &$a) {
             $a['site'] = DB_SitePeer::instance()->selectByPrimaryKey($a['site_id']);
         }
     }
     $runData->contextAdd("res", $all);
     $runData->contextAdd("range", $range);
 }
コード例 #3
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $tag = $pl->getParameterValue("tag");
     if ($tag === null) {
         $runData->setModuleTemplate("Empty");
         return;
     }
     $lang = $pl->getParameterValue("lang");
     if ($lang && $lang !== "pl" && $lang !== "en") {
         $lang = null;
     }
     // get sites
     $title = $pl->getParameterValue("title");
     $runData->contextAdd("title", $title);
     $c = new Criteria();
     $c->setExplicitFrom("site, site_tag");
     $c->add("site_tag.tag", $tag);
     $c->add("site.visible", true);
     $c->add("site.private", false);
     $c->add("site.deleted", false);
     if ($lang) {
         $c->add("site.language", $lang);
     }
     $c->add("site_tag.site_id", "site.site_id", "=", false);
     $c->addOrderAscending('site.name');
     $sites = DB_SitePeer::instance()->select($c);
     //	$q = "SELECT site.* FROM site, tag WHERE tag.tag = '".db_escape_string($tag")."'
     $runData->contextAdd("tag", $tag);
     $runData->contextAdd("sites", $sites);
     $runData->contextAdd("sitesCount", count($sites));
 }
コード例 #4
0
 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);
 }
コード例 #5
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);
 }
コード例 #6
0
ファイル: CustomDomainScript.php プロジェクト: jbzdak/wikidot
 public function build($runData)
 {
     // check first for standard cookie name
     $user = $runData->getUser();
     $anon = false;
     if (!$user) {
         // check the ie cookie then
         GlobalProperties::$SESSION_COOKIE_NAME = GlobalProperties::$SESSION_COOKIE_NAME_IE;
         $runData->handleSessionStart();
         $user = $runData->getUser();
         $anon = $_COOKIE[GlobalProperties::$SESSION_COOKIE_NAME_IE] == "ANONYMOUS";
     }
     if ($user) {
         $site_id = (int) $runData->getParameterList()->getParameterValue("site_id");
         $site = DB_SitePeer::instance()->selectByPrimaryKey($site_id);
         if ($site && $site->getCustomDomain()) {
             $skey = $runData->generateSessionDomainHash($site->getCustomDomain());
             $proto = $_SERVER["HTTPS"] ? "https" : "http";
             $domain = $site->getCustomDomain();
             $runData->contextAdd("redir", "{$proto}://{$domain}" . CustomDomainLoginFlowController::$controllerUrl . "?" . http_build_query(array("user_id" => $user->getUserId(), "skey" => $skey)));
         }
     } elseif (!$anon) {
         // no session found -- try to redirect to set ie cookie
         $proto = $_SERVER["HTTPS"] ? "https" : "http";
         $runData->contextAdd("redirIE", $proto . '://' . GlobalProperties::$URL_HOST . CustomDomainLoginFlowController::$controllerUrl . '?' . http_build_query(array("url" => $url, "setiecookie" => true)));
     }
 }
コード例 #7
0
 public function cloneSiteEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $siteId = $site->getSiteId();
     WDPermissionManager::instance()->canBecomeAdmin($runData->getUser());
     $name = trim($pl->getParameterValue("name"));
     $unixName = trim($pl->getParameterValue("unixname"));
     $tagline = trim($pl->getParameterValue("tagline"));
     $description = trim($pl->getParameterValue("description"));
     $private = (bool) $pl->getParameterValue("private");
     // validate form data:
     $errors = array();
     if (strlen($name) < 1) {
         $errors['name'] = _("Site name must be present.");
     } elseif (strlen8($name) > 30) {
         $errors['name'] = _("Site name should not be longer than 30 characters.");
     }
     // site unix name *************
     if ($unixName === null || strlen($unixName) < 3) {
         $errors['unixname'] = _("Web address must be present and should be at least 3 characters long.");
     } elseif (strlen($unixName) > 30) {
         $errors['unixname'] = _("Web address name should not be longer than 30 characters.");
     } elseif (preg_match("/^[a-z0-9\\-]+\$/", $unixName) == 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address.');
     } elseif (preg_match("/\\-\\-/", $unixName) !== 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address. Double-dash (--) is not allowed.');
     } else {
         $unixName = WDStringUtils::toUnixName($unixName);
         if (!$runData->getUser()->getSuperAdmin()) {
             //	handle forbidden names
             $forbiddenUnixNames = explode("\n", file_get_contents(WIKIDOT_ROOT . '/conf/forbidden_site_names.conf'));
             foreach ($forbiddenUnixNames as $f) {
                 if (preg_match($f, $unixName) > 0) {
                     $errors['unixname'] = _('For some reason this web address is not allowed or is reserved for future use.');
                 }
             }
         }
         // check if the domain is not taken.
         $c = new Criteria();
         $c->add("unix_name", $unixName);
         $ss = DB_SitePeer::instance()->selectOne($c);
         if ($ss) {
             $errors['unixname'] = _('Sorry, this web address is already used by another site.');
         }
     }
     if (strlen8($tagline) > 50) {
         $errors['tagline'] = _("Tagline should not be longer than 50 characters");
     }
     if (count($errors) > 0) {
         $runData->ajaxResponseAdd("formErrors", $errors);
         throw new ProcessException("Form errors", "form_errors");
     }
     // and now... CREATE THE SITE!!!!!!!!!!!!!!!!
     $siteProps = array('name' => $name, 'subtitle' => $tagline, 'unixname' => $unixName, 'description' => $description, 'private' => $private);
     $dup = new Duplicator();
     $dup->cloneSite($site, $siteProps);
 }
コード例 #8
0
 public function acceptedEmailInvitation($inv, $user)
 {
     $site = DB_SitePeer::instance()->selectByPrimaryKey($inv->getSiteId());
     $not = new DB_AdminNotification();
     $not->setSiteId($site->getSiteId());
     $not->setType("NEW_MEMBER_BY_EMAIL_INVITATION");
     $not->setDate(new ODate());
     $extra = array();
     $extra['user_id'] = $user->getUserId();
     //$extra['urls'] = array(	array('site members','http://'.$site->getDomain().'/admin:manage/start/members-list')
     $not->setExtra($extra);
     $not->save();
 }
コード例 #9
0
ファイル: LoginIframeScreen.php プロジェクト: jbzdak/wikidot
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $url = $pl->getParameterValue('url');
     $siteId = $pl->getParameterValue('siteId');
     if ($siteId && is_numeric($siteId)) {
         $site = DB_SitePeer::instance()->selectByPrimaryKey($siteId);
     }
     if (!$site) {
         throw new ProcessException(_('Invalid site'));
     }
     $runData->setLanguage($site->getLanguage());
     $GLOBALS['lang'] = $site->getLanguage();
     // and for gettext too:
     $lang = $site->getLanguage();
     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);
     $themeId = $pl->getParameterValue('themeId');
     if ($themeId && is_numeric($themeId)) {
         $theme = DB_ThemePeer::instance()->selectByPrimaryKey($themeId);
     }
     if (!$theme) {
         throw new ProcessException(_('Invalid theme'));
     }
     $runData->contextAdd('site', $site);
     $runData->contextAdd('theme', $theme);
     $runData->contextAdd('url', $url);
     $seed = CryptUtils::generateSeed(4);
     // put seed into session!
     $runData->sessionStart();
     $runData->sessionAdd("login_seed", $seed);
     $runData->contextAdd("key", CryptUtils::modulus());
     $runData->contextAdd("seed", $seed);
     // clear welcome cookie?
     if ($pl->getParameterValue("clearwelcome")) {
         $runData->contextAdd('reset', true);
     }
 }
コード例 #10
0
ファイル: NotificationMaker.php プロジェクト: jbzdak/wikidot
 public function newMembershipInvitation($invitation)
 {
     $site = DB_SitePeer::instance()->selectByPrimaryKey($invitation->getSiteId());
     $not = new DB_Notification();
     $not->setUserId($invitation->getUserId());
     $not->setType("new_membership_invitation");
     $extra = array();
     $extra['site_id'] = $site->getSiteId();
     $extra['site_name'] = $site->getName();
     $extra['site_domain'] = $site->getDomain();
     $not->setExtra($extra);
     $not->setDate(new ODate());
     $not->save();
 }
コード例 #11
0
 public function activateForumEvent($runData)
 {
     $site = $runData->getTemp("site");
     $db = Database::connection();
     $db->begin();
     // copy forum settings from template
     $c = new Criteria();
     $c->add("unix_name", "template-" . $site->getLanguage());
     $templateSite = DB_SitePeer::instance()->selectOne($c);
     $fs = $templateSite->getForumSettings();
     $fs->setNew(true);
     $fs->setSiteId($site->getSiteId());
     $fs->save();
     // create extra categories? no.
     // copy pages
     $d = new Duplicator();
     $d->setOwner($runData->getUser());
     // copy "forum" category
     $fc = DB_CategoryPeer::instance()->selectByName("forum", $templateSite->getSiteId());
     $d->duplicateCategory($fc, $site);
     // recompile category.
     $od = new Outdater();
     $od->recompileCategory(DB_CategoryPeer::instance()->selectByName("forum", $site->getSiteId()));
     // create a "Hidden" forum group and "Deleted" category
     $group = new DB_ForumGroup();
     $group->setSiteId($site->getSiteId());
     $group->setName("Hidden");
     $group->setVisible(false);
     $group->save();
     $del = new DB_ForumCategory();
     $del->setSiteId($site->getSiteId());
     $del->setName(_("Deleted threads"));
     $del->setDescription(_("Deleted forum discussions should go here."));
     $del->setPermissions("t:;p:;e:;s:");
     $del->setGroupId($group->getGroupId());
     $del->save();
     $category = new DB_ForumCategory();
     $category->setName(_("Per page discussions"));
     $category->setDescription(_("This category groups discussions related to particular pages within this site."));
     $category->setPerPageDiscussion(true);
     $category->setSiteId($site->getSiteId());
     $category->setGroupId($group->getGroupId());
     $category->save();
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
コード例 #12
0
ファイル: DB_Admin.php プロジェクト: jbzdak/wikidot
 public function getSite()
 {
     if (is_array($this->prefetched)) {
         if (in_array('site', $this->prefetched)) {
             if (in_array('site', $this->prefetchedObjects)) {
                 return $this->prefetchedObjects['site'];
             } else {
                 $obj = new DB_Site($this->sourceRow);
                 $obj->setNew(false);
                 $this->prefetchedObjects['site'] = $obj;
                 return $obj;
             }
         }
     }
     return DB_SitePeer::instance()->selectByPrimaryKey($this->getSiteId());
 }
コード例 #13
0
ファイル: ListAllWikisModule.php プロジェクト: jbzdak/wikidot
 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);
 }
コード例 #14
0
ファイル: User.php プロジェクト: jbzdak/wikidot
 /**
  * Get sites of a user. This is a fake one!
  * 
  * @param struct $args
  * @return struct
  */
 public function sites($args)
 {
     $this->parseArgs($args, array("performer", "user"));
     if ($this->performer->getUserId() != $this->user->getUserId()) {
         throw new WDPermissionException("One can only list their own sites");
     }
     $c = new Criteria();
     $c->add("user_id", $this->user->getUserId());
     $memberships = DB_MemberPeer::instance()->selectByCriteria($c);
     $sites = array();
     foreach ($memberships as $membership) {
         $site = DB_SitePeer::instance()->selectByPrimaryKey($membership->getSiteId());
         if (!$site->getDeleted()) {
             $sites[] = $site;
         }
     }
     return $this->repr($sites);
 }
コード例 #15
0
ファイル: AcceptTOSModule.php プロジェクト: jbzdak/wikidot
 public function build($runData)
 {
     $runData->sessionAdd("rstep", -1);
     // get terms of service.
     // also set the crypto things
     $runData->ajaxResponseAdd("key", CryptUtils::modulus());
     // get the TOS content
     $pageName = "legal:terms-of-service";
     $siteName = "www";
     $c = new Criteria();
     $c->add("unix_name", $siteName);
     $site = DB_SitePeer::instance()->selectOne($c);
     $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $pageName);
     // get content
     $content = $page->getCompiled()->getText();
     // remove toc ;-)
     $content = preg_replace(';<table style=".*?id="toc".*?</table>;s', '', $content, 1);
     $content = preg_replace(';<a ([^>]*)>;s', '<a \\1 target="_blank">', $content);
     $runData->contextAdd("tosContent", $content);
 }
コード例 #16
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $userId = $pl->getParameterValue("user_id");
     $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($userId);
     $runData->contextAdd("user", $user);
     $avatarUri = '/common--images/avatars/' . floor($userId / 1000) . '/' . $userId . '/a48.png';
     $runData->contextAdd("avatarUri", $avatarUri);
     // get profile page to include
     $pageName = "profile:" . $user->getUnixName();
     $c = new Criteria();
     $c->add("unix_name", "profiles");
     $site = DB_SitePeer::instance()->selectOne($c);
     $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $pageName);
     if ($page !== null) {
         $compiled = $page->getCompiled();
         $runData->contextAdd("profileContent", $compiled);
         $runData->contextAdd("wikiPage", $page);
     }
     $runData->contextAdd('karmaLevel', $user->getKarmaLevel());
 }
コード例 #17
0
ファイル: NewSiteModule.php プロジェクト: jbzdak/wikidot
 public function build($runData)
 {
     if ($runData->getUser() == null) {
         $runData->contextAdd("notLogged", true);
     } else {
         //
         //
     }
     $pl = $runData->getParameterList();
     $siteUnixName = WDStringUtils::toUnixName($pl->getParameterValue('address'));
     $runData->contextAdd('unixName', $siteUnixName);
     $siteName = str_replace('-', ' ', $siteUnixName);
     $siteName = ucwords($siteName);
     $runData->contextAdd('siteName', $siteName);
     // get template sites
     $c = new Criteria();
     $c->add('unix_name', '^template-', '~');
     $c->addOrderAscending('site_id');
     $templates = DB_SitePeer::instance()->select($c);
     $runData->contextAdd('templates', $templates);
 }
コード例 #18
0
ファイル: WikidotController.php プロジェクト: jbzdak/wikidot
 /**
  * Gets a site from given hostname. This version works for custom domains and upload domain if needed
  *
  * @param string $siteHost the host to check
  * @param bool $customDomains whether to check custom domains 
  * @param bool $uploadDomain whether to check upload domains as well
  * @return DB_Site
  */
 protected function siteFromHost($siteHost, $customDomains = false, $uploadDomain = false)
 {
     $memcache = Ozone::$memcache;
     if ($uploadDomain) {
         $regexp = "/^([a-zA-Z0-9\\-]+)\\.(" . GlobalProperties::$URL_DOMAIN_PREG . "|" . GlobalProperties::$URL_UPLOAD_DOMAIN_PREG . ")\$/";
     } else {
         $regexp = "/^([a-zA-Z0-9\\-]+)\\.(" . GlobalProperties::$URL_DOMAIN_PREG . ")\$/";
     }
     if (preg_match($regexp, $siteHost, $matches) == 1) {
         // select site based on the unix name
         $siteUnixName = $matches[1];
         $mcKey = 'site..' . $siteUnixName;
         $site = $memcache->get($mcKey);
         if ($site == false) {
             $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, 3600);
             }
         }
     }
     // select site based on the custom domain
     if (!$site && $customDomains) {
         $mcKey = 'site_cd..' . $siteHost;
         $site = $memcache->get($mcKey);
         if ($site == false) {
             $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);
             }
         }
     }
     return $site;
 }
コード例 #19
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $user = $runData->getUser();
     $hash = $pl->getParameterValue("hash");
     // get the invitation entry (if any)
     $c = new Criteria();
     $c->add("hash", $hash);
     $c->add("accepted", false);
     $inv = DB_EmailInvitationPeer::instance()->selectOne($c);
     $runData->contextAdd("user", $user);
     if (!$inv) {
         //sorry, no invitation
         return;
     }
     $site = DB_SitePeer::instance()->selectByPrimaryKey($inv->getSiteId());
     $sender = DB_OzoneUserPeer::instance()->selectByPrimaryKey($inv->getUserId());
     $runData->contextAdd("sender", $sender);
     $runData->contextAdd("site", $site);
     $runData->contextAdd("invitation", $inv);
     $runData->contextAdd("hash", $hash);
 }
コード例 #20
0
 public function newWikiEvent($runData)
 {
     $pl = $runData->getParameterList();
     $siteName = $pl->getParameterValue('siteName');
     // validate even more
     $unixName = WDStringUtils::toUnixName($siteName);
     if ($unixName === null || strlen($unixName) < 3) {
         throw new ProcessException(_("Web address must be at least 3 characters long."));
     }
     if (strlen($unixName) > 30) {
         throw new ProcessException(_("Web address name should not be longer than 30 characters."));
     }
     if (preg_match("/^[a-z0-9\\-]+\$/", $unixName) == 0) {
         throw new ProcessException(_('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address.'));
     }
     if (preg_match("/\\-\\-/", $unixName) !== 0) {
         throw new ProcessException(_('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address. Double-dash (--) is not allowed.'));
     }
     $unixName = WDStringUtils::toUnixName($unixName);
     if (!$runData->getUser() || !$runData->getUser()->getSuperAdmin()) {
         //	handle forbidden names
         $forbiddenUnixNames = explode("\n", file_get_contents(WIKIDOT_ROOT . '/conf/forbidden_site_names.conf'));
         foreach ($forbiddenUnixNames as $f) {
             if (preg_match($f, $unixName) > 0) {
                 throw new ProcessException(_('For some reason this web address is not allowed or is reserved for future use.'));
             }
         }
     }
     // check if the domain is not taken.
     $c = new Criteria();
     $c->add("unix_name", $unixName);
     $ss = DB_SitePeer::instance()->selectOne($c);
     if ($ss) {
         throw new ProcessException(_('Sorry, this web address is already used by another wiki.'));
     }
     $runData->ajaxResponseAdd('unixName', $unixName);
 }
コード例 #21
0
 public function acceptEmailInvitationEvent($runData)
 {
     $pl = $runData->getParameterList();
     $user = $runData->getUser();
     $hash = $pl->getParameterValue("hash");
     // get the invitation entry (if any)
     $c = new Criteria();
     $c->add("hash", $hash);
     $c->add("accepted", false);
     $inv = DB_EmailInvitationPeer::instance()->selectOne($c);
     $runData->contextAdd("user", $user);
     if (!$inv) {
         throw new ProcessException(_("Sorry, no invitation can be found."));
     }
     $site = DB_SitePeer::instance()->selectByPrimaryKey($inv->getSiteId());
     // check if not a member already
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("site_id", $site->getSiteId());
     $mem = DB_MemberPeer::instance()->selectOne($c);
     if ($mem) {
         throw new ProcessException(_("It seems you already are a member of this site! Congratulations anyway ;-)"));
     }
     // check if not > max _members
     if ($site->getPrivate()) {
         $settings = $site->getSettings();
         $maxMembers = $settings->getMaxPrivateMembers();
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $cmem = DB_MemberPeer::instance()->selectCount($c);
         if ($cmem >= $maxMembers) {
             throw new ProcessException(sprintf(_('Sorry, at the moment max %d member limit apply for private Wikis. The Site would have to be upgraded to allow more members.'), $maxMembers));
         }
     }
     // all should be fine at this point - add to members
     $db = Database::connection();
     $db->begin();
     $mem = new DB_Member();
     $mem->setDateJoined(new ODate());
     $mem->setSiteId($site->getSiteId());
     $mem->setUserId($user->getUserId());
     $mem->save();
     $ml = new DB_MembershipLink();
     $ml->setUserId($user->getUserId());
     $ml->setSiteId($site->getSiteId());
     $ml->setDate(new ODate());
     $ml->setType('EMAIL_INVITATION');
     $ml->setByUserId($inv->getUserId());
     $ml->save();
     // add to contacts?
     $sender = DB_OzoneUserPeer::instance()->selectByPrimaryKey($inv->getUserId());
     if ($inv->getToContacts() && $sender->getUserId() != $user->getUserId()) {
         try {
             // check if contact already exists
             $c = new Criteria();
             $c->add("user_id", $user->getUserId());
             $c->add("target_user_id", $sender->getUserId());
             $con0 = DB_ContactPeer::instance()->selectOne($c);
             if (!$con0) {
                 $con = new DB_Contact();
                 $con->setUserId($user->getUserId());
                 $con->setTargetUserId($sender->getUserId());
                 $con->save();
             }
         } catch (Exception $e) {
         }
         try {
             // check if contact already exists
             $c = new Criteria();
             $c->add("user_id", $sender->getUserId());
             $c->add("target_user_id", $user->getUserId());
             $con0 = DB_ContactPeer::instance()->selectOne($c);
             if (!$con0) {
                 $con = new DB_Contact();
                 $con->setUserId($sender->getUserId());
                 $con->setTargetUserId($user->getUserId());
                 $con->save();
             }
         } catch (Exception $e) {
         }
     }
     // set accepted
     $inv->setAccepted(true);
     $inv->save();
     // create a notification
     AdminNotificationMaker::instance()->acceptedEmailInvitation($inv, $user);
     $db->commit();
     $runData->contextAdd("site", $site);
 }
コード例 #22
0
ファイル: DB_File.php プロジェクト: jbzdak/wikidot
 public function getFileURI()
 {
     $page = DB_PagePeer::instance()->selectByPrimaryKey($this->getPageId());
     $site = DB_SitePeer::instance()->selectByPrimaryKey($this->getSiteId());
     return 'http://' . $site->getDomain() . "/local--files/" . $page->getUnixName() . "/" . $this->getFilename();
 }
コード例 #23
0
ファイル: DB_ForumThread.php プロジェクト: jbzdak/wikidot
 public function getSite()
 {
     return DB_SitePeer::instance()->selectByPrimaryKey($this->getSiteId());
 }
コード例 #24
0
ファイル: Deleter.php プロジェクト: jbzdak/wikidot
 public function deleteSite($site)
 {
     if (!$site) {
         return;
     }
     // get all pages and delete each one
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $pages = DB_PagePeer::instance()->select($c);
     foreach ($pages as $page) {
         $this->deletePage($page);
     }
     // delete forum? no. will be autodeleted based on the database constrains.
     // need to delete post revisions
     $db = Database::connection();
     $q = "DELETE FROM forum_post_revision WHERE forum_post_id IN (SELECT post_id FROM forum_post WHERE site_id= {$site->getSiteId()}";
     $db->query($q);
     //delete the site itself
     $outdater = new Outdater();
     $outdater->siteEvent('delete', $site);
     DB_SitePeer::instance()->deleteByPrimaryKey($site->getSiteId());
 }
コード例 #25
0
 public function restoreSiteEvent($runData)
 {
     $pl = $runData->getParameterList();
     $siteId = $pl->getParameterValue('siteId');
     $unixName = trim($pl->getParameterValue('unixName'));
     $c = new Criteria();
     $c->add('site_id', $siteId);
     $c->add('deleted', true);
     $site = DB_SitePeer::instance()->selectOne($c);
     if (!$site) {
         throw new ProcessException(_('Error selecting a site to restore.'));
     }
     // check if allowed
     $user = $runData->getUser();
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("site_id", $site->getSiteId());
     $c->add("founder", true);
     $rel = DB_AdminPeer::instance()->selectOne($c);
     if (!$rel) {
         throw new ProcessException(_("Sorry, you have no permissions to restore this site."));
     }
     $db = Database::connection();
     $db->begin();
     // validate unix name
     $errors = array();
     if ($unixName === null || strlen($unixName) < 3 || strlen(WDStringUtils::toUnixName($unixName)) < 3) {
         $errors['unixname'] = _("Web address must be present and should be at least 3 characters long.");
     } elseif (strlen($unixName) > 30) {
         $errors['unixname'] = _("Web address name should not be longer than 30 characters.");
     } elseif (preg_match("/^[a-z0-9\\-]+\$/", $unixName) == 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address.');
     } elseif (preg_match("/\\-\\-/", $unixName) !== 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address. Double-dash (--) is not allowed.');
     } else {
         $unixName = WDStringUtils::toUnixName($unixName);
         if (!$runData->getUser()->getSuperAdmin()) {
             //	handle forbidden names
             $forbiddenUnixNames = explode("\n", file_get_contents(WIKIDOT_ROOT . '/conf/forbidden_site_names.conf'));
             foreach ($forbiddenUnixNames as $f) {
                 if (preg_match($f, $unixName) > 0) {
                     $errors['unixname'] = _('For some reason this web address is not allowed or is reserved for future use.');
                 }
             }
         }
         // check if the domain is not taken.
         $c = new Criteria();
         $c->add("unix_name", $unixName);
         $ss = DB_SitePeer::instance()->selectOne($c);
         if ($ss) {
             $errors['unixname'] = _('Sorry, this web address is already used by another site.');
         }
     }
     if (isset($errors['unixname'])) {
         throw new ProcessException($errors['unixname']);
     }
     $oldUnixName = $site->getUnixName();
     $oldLocalPath = $site->getLocalFilesPath();
     $site->setUnixName($unixName);
     // 	rename the files
     mkdirfull(dirname($site->getLocalFilesPath()));
     @rename($oldLocalPath, $site->getLocalFilesPath());
     $site->setDeleted(false);
     $site->setCustomDomain(null);
     $site->save();
     $db->commit();
     $runData->ajaxResponseAdd('unixName', $site->getUnixName());
 }
コード例 #26
0
 public function process()
 {
     global $timeStart;
     // 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("AJAX module request processing started, logger initialized");
     Ozone::init();
     $runData = new RunData();
     /* processing an AJAX request! */
     $runData->setAjaxMode(true);
     $runData->init();
     // extra return array - just for ajax handling
     $runData->ajaxResponseAdd("status", "ok");
     Ozone::setRunData($runData);
     $logger->debug("RunData object created and initialized");
     try {
         // check security token
         if ($_COOKIE['wikidot_token7'] == null || $_COOKIE['wikidot_token7'] !== $runData->getParameterList()->getParameterValue('wikidot_token7', 'AMODULE')) {
             throw new ProcessException("no", "wrong_token7");
         }
         //remove token from parameter list!!!
         $runData->getParameterList()->delParameter('wikidot_token7');
         $callbackIndex = $runData->getParameterList()->getParameterValue('callbackIndex');
         $runData->getParameterList()->delParameter('callbackIndex');
         // 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!
             // the memcache block is to avoid database connection if possible
             $mcKey = 'site..' . $siteUnixName;
             $site = $memcache->get($mcKey);
             if ($site == false) {
                 $c = new Criteria();
                 $c->add("unix_name", $siteUnixName);
                 $c->add("site.deleted", false);
                 $site = DB_SitePeer::instance()->selectOne($c);
                 $memcache->set($mcKey, $site, 0, 3600);
             }
         } else {
             // select site based on the custom domain
             $mcKey = 'site_cd..' . $siteHost;
             $site = $memcache->get($mcKey);
             if ($site == false) {
                 $c = new Criteria();
                 $c->add("custom_domain", $siteHost);
                 $c->add("site.deleted", false);
                 $site = DB_SitePeer::instance()->selectOne($c);
                 $memcache->set($mcKey, $site, 0, 3600);
             }
             GlobalProperties::$SESSION_COOKIE_DOMAIN = '.' . $siteHost;
         }
         if (!$site) {
             throw new ProcessException(_('The requested site does not exist.'));
         }
         $runData->setTemp("site", $site);
         //nasty global thing...
         $GLOBALS['siteId'] = $site->getSiteId();
         $GLOBALS['site'] = $site;
         // set language
         $runData->setLanguage($site->getLanguage());
         $GLOBALS['lang'] = $site->getLanguage();
         // and for gettext too:
         $lang = $site->getLanguage();
         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, issue an errorr
                 throw new ProcessException(_("Secure access is not enabled for this Wiki."));
             } 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':
                     throw new ProcessException(_("Nonsecure access is not enabled for this Wiki."));
                     break;
             }
         }
         // handle session at the begging of procession
         $runData->handleSessionStart();
         // PRIVATE SITES: check if the site is private and if the user is its member
         if ($site->getPrivate()) {
             // check if not allow anyway
             $template = $runData->getModuleTemplate();
             $actionClass = $runData->getAction();
             $proceed = in_array($actionClass, array('', 'LoginAction', 'MembershipApplyAction', 'CreateAccountAction', 'PasswordRecoveryAction')) && ($template == '' || $template == 'Empty' || preg_match(';^createaccount/;', $template) || preg_match(';^login/;', $template) || preg_match(';^membership/;', $template) || preg_match(';^passwordrecovery/;', $template));
             if (!$proceed) {
                 $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) {
                     throw new ProcessException(_('This Site is private and accessible only to its members.'));
                 }
             }
         }
         $template = $runData->getModuleTemplate();
         $classFile = $runData->getModuleClassPath();
         $className = $runData->getModuleClassName();
         $logger->debug("processing template: " . $runData->getModuleTemplate() . ", class: {$className}");
         require_once $classFile;
         $module = new $className();
         // module security check
         if (!$module->isAllowed($runData)) {
             throw new WDPermissionException(_("Not allowed."));
         }
         Ozone::initSmarty();
         $logger->debug("OZONE initialized");
         $logger->info("Ozone engines successfully initialized");
         // PROCESS ACTION
         $actionClass = $runData->getAction();
         $logger->debug("processing action {$actionClass}");
         $runData->setTemp("jsInclude", array());
         $runData->setTemp("cssInclude", array());
         if ($actionClass) {
             require_once PathManager::actionClass($actionClass);
             $tmpa1 = explode('/', $actionClass);
             $actionClassStripped = end($tmpa1);
             $action = new $actionClassStripped();
             $classFile = $runData->getModuleClassPath();
             if (!$action->isAllowed($runData)) {
                 throw new WDPermissionException("Not allowed.");
             }
             $actionEvent = $runData->getActionEvent();
             /*try{*/
             if ($actionEvent != null) {
                 $action->{$actionEvent}($runData);
                 $logger->debug("processing action: {$actionClass}, event: {$actionEvent}");
             } else {
                 $logger->debug("processing action: {$actionClass}");
                 $action->perform($runData);
             }
         }
         // end action process
         // check if template has been changed by the module. if so...
         if ($template != $runData->getModuleTemplate()) {
             $classFile = $runData->getModuleClassPath();
             $className = $runData->getModuleClassName();
             $logger->debug("processing template: " . $runData->getModuleTemplate() . ", class: {$className}");
             require_once $classFile;
             $module = new $className();
         }
         $module->setTemplate($template);
         $rendered = $module->render($runData);
         $jsInclude = $runData->getTemp("jsInclude");
         $jsInclude = array_merge($jsInclude, $module->getExtraJs());
         $runData->setTemp("jsInclude", $jsInclude);
         $cssInclude = $runData->getTemp("cssInclude");
         $cssInclude = array_merge($cssInclude, $module->getExtraCss());
         $runData->setTemp("cssInclude", $cssInclude);
     } catch (ProcessException $e) {
         $db = Database::connection();
         $db->rollback();
         $runData->ajaxResponseAdd("message", $e->getMessage());
         $runData->ajaxResponseAdd("status", $e->getStatus());
         $runData->setModuleTemplate(null);
         $template = null;
     } catch (WDPermissionException $e) {
         $db = Database::connection();
         $db->rollback();
         $runData->ajaxResponseAdd("message", $e->getMessage());
         $runData->ajaxResponseAdd("status", "no_permission");
         $runData->setModuleTemplate(null);
         $template = null;
     } catch (Exception $e) {
         $db = Database::connection();
         $db->rollback();
         $runData->ajaxResponseAdd("message", _("An error occured while processing the request.") . ' ' . $e->getMessage());
         $runData->ajaxResponseAdd("status", "not_ok");
         $runData->setModuleTemplate(null);
         $template = null;
         // LOG ERROR TOO!!!
         $logger = OzoneLogger::instance();
         $logger->error("Exception caught while processing ajax module:\n\n" . $e->__toString());
     }
     $rVars = $runData->getAjaxResponse();
     if ($rendered != null) {
         // process modules...
         $moduleProcessor = new ModuleProcessor($runData);
         $out = $moduleProcessor->process($rendered);
         $rVars['body'] = $out;
         // check the javascript files for inclusion
     }
     if ($template != null && $template != "Empty") {
         $jsInclude = $runData->getTemp("jsInclude");
         if ($module->getIncludeDefaultJs()) {
             $file = WIKIDOT_ROOT . '/' . GlobalProperties::$MODULES_JS_PATH . '/' . $template . '.js';
             if (file_exists($file)) {
                 $url = GlobalProperties::$MODULES_JS_URL . '/' . $template . '.js';
                 $incl = $url;
                 $jsInclude[] = $incl;
             }
         }
         $rVars['jsInclude'] = $jsInclude;
         $cssInclude = $runData->getTemp("cssInclude");
         if ($module->getIncludeDefaultCss()) {
             $file = WIKIDOT_ROOT . '/' . GlobalProperties::$MODULES_CSS_PATH . '/' . $template . '.css';
             if (file_exists($file)) {
                 $url = GlobalProperties::$MODULES_CSS_URL . '/' . $template . '.css';
                 $incl = $url;
                 $cssInclude[] = $incl;
             }
         }
         $rVars['cssInclude'] = $cssInclude;
     }
     // specify (copy) jscallback. ugly, right? ;-)
     $rVars['callbackIndex'] = $callbackIndex;
     $json = new JSONService();
     $out = $json->encode($rVars);
     $runData->handleSessionEnd();
     echo $out;
 }
コード例 #27
0
ファイル: NewSiteAction.php プロジェクト: jbzdak/wikidot
 public function createSiteEvent($runData)
 {
     WDPermissionManager::instance()->canBecomeAdmin($runData->getUser());
     $pl = $runData->getParameterList();
     $name = trim($pl->getParameterValue("name"));
     $unixName = trim($pl->getParameterValue("unixname"));
     $tagline = trim($pl->getParameterValue("tagline"));
     $templateId = $pl->getParameterValue("template");
     $private = (bool) $pl->getParameterValue("private");
     // validate form data:
     $errors = array();
     if (strlen($name) < 1) {
         $errors['name'] = _("Site name must be present.");
     } elseif (strlen8($name) > 30) {
         $errors['name'] = _("Site name should not be longer than 30 characters.");
     }
     // site unix name *************
     if ($unixName === null || strlen($unixName) < 3) {
         $errors['unixname'] = _("Web address must be present and should be at least 3 characters long.");
     } elseif (strlen($unixName) > 30) {
         $errors['unixname'] = _("Web address name should not be longer than 30 characters.");
     } elseif (preg_match("/^[a-z0-9\\-]+\$/", $unixName) == 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address.');
     } elseif (preg_match("/\\-\\-/", $unixName) !== 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address. Double-dash (--) is not allowed.');
     } else {
         $unixName = WDStringUtils::toUnixName($unixName);
         if (!$runData->getUser()->getSuperAdmin()) {
             //	handle forbidden names
             $forbiddenUnixNames = explode("\n", file_get_contents(WIKIDOT_ROOT . '/conf/forbidden_site_names.conf'));
             foreach ($forbiddenUnixNames as $f) {
                 if (preg_match($f, $unixName) > 0) {
                     $errors['unixname'] = _('For some reason this web address is not allowed or is reserved for future use.');
                 }
             }
         }
         // check if the domain is not taken.
         $c = new Criteria();
         $c->add("unix_name", $unixName);
         $ss = DB_SitePeer::instance()->selectOne($c);
         if ($ss) {
             $errors['unixname'] = _('Sorry, this web address is already used by another site.');
         }
     }
     // template
     if (!$templateId) {
         $errors['template'] = _('Please choose a template for your site');
     }
     if (strlen8($tagline) > 50) {
         $errors['tagline'] = _("Tagline should not be longer than 50 characters");
     }
     // TOS
     if (!$pl->getParameterValue("tos")) {
         $errors['tos'] = _("Please read and agree to the Terms of Service.");
     }
     if (count($errors) > 0) {
         $runData->ajaxResponseAdd("formErrors", $errors);
         throw new ProcessException("Form errors", "form_errors");
     }
     // and now... CREATE THE SITE!!!!!!!!!!!!!!!!
     $dup = new Duplicator();
     $dup->setOwner($runData->getUser());
     $db = Database::connection();
     $db->begin();
     $templateSite = DB_SitePeer::instance()->selectByPrimaryKey($templateId);
     if (!preg_match(';^template\\-;', $templateSite->getUnixName())) {
         throw new ProcessException('Error');
     }
     $site = new DB_Site();
     $site->setName($name);
     $site->setSubtitle($tagline);
     $site->setUnixName($unixName);
     $site->setLanguage($templateSite->getLanguage());
     $site->setDateCreated(new ODate());
     $site->setPrivate($private);
     if ($private) {
         // change file flag too
         $flagDir = WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName() . '/flags';
         $flagFile = $flagDir . '/private';
         mkdirfull($flagDir);
         //just to make sure
         if (!file_exists($flagFile)) {
             file_put_contents($flagFile, "private");
         }
     }
     $site->save();
     $dup->addExcludedCategory("forum");
     // should be initialized independently
     $dup->addExcludedCategory("profile");
     $dup->duplicateSite($templateSite, $site);
     // index the site too
     $ind = Indexer::instance();
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $pages = DB_PagePeer::instance()->select($c);
     foreach ($pages as $p) {
         $ind->indexPage($p);
     }
     $db->commit();
     // clear captcha code
     $runData->sessionDel("captchaCode");
     $runData->ajaxResponseAdd("siteUnixName", $unixName);
 }
コード例 #28
0
ファイル: Base.php プロジェクト: jbzdak/wikidot
 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");
 }
コード例 #29
0
ファイル: update-2008-08-19.php プロジェクト: jbzdak/wikidot
    $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";
コード例 #30
0
ファイル: AbuseFlagAction.php プロジェクト: jbzdak/wikidot
 public function flagUserEvent($runData)
 {
     $pl = $runData->getParameterList();
     $toFlag = $pl->getParameterValue("flag");
     $targetUserId = $pl->getParameterValue("targetUserId");
     if ($targetUserId == null || $targetUserId == '' || !is_numeric($targetUserId)) {
         throw new ProcessException(_("Error processing the request."), "no_target_user");
     }
     $targetUser = DB_OzoneUserPeer::instance()->selectByPrimaryKey($targetUserId);
     if ($targetUser == null) {
         throw new ProcessException(_("Error processing the request."), "no_target_user");
     }
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     $db = Database::connection();
     $db->begin();
     if ($toFlag) {
         // flag the user
         // check if not flagged already
         $c = new Criteria();
         $c->add("user_id", $user->getUserId());
         $c->add("target_user_id", $targetUser->getUserId());
         $flag = DB_UserAbuseFlagPeer::instance()->selectOne($c);
         if ($flag == null) {
             $siteId = $site->getSiteId();
             // get the host if any
             $host = $pl->getParameterValue("host");
             if ($host) {
                 if (preg_match("/^([a-zA-Z0-9\\-]+)\\." . GlobalProperties::$URL_DOMAIN_PREG . "\$/", $host, $matches) == 1) {
                     $siteUnixName = $matches[1];
                     $c = new Criteria();
                     $c->add("unix_name", $siteUnixName);
                     $siter = DB_SitePeer::instance()->selectOne($c);
                 } else {
                     $c = new Criteria();
                     $c->add("custom_domain", $host);
                     $siter = DB_SitePeer::instance()->selectOne($c);
                 }
                 if ($siter !== null) {
                     $siteId = $siter->getSiteId();
                 }
             }
             $flag = new DB_UserAbuseFlag();
             $flag->setUserId($user->getUserId());
             $flag->setSiteId($siteId);
             $flag->setTargetUserId($targetUser->getUserId());
             $flag->save();
             EventLogger::instance()->logFlagUser($targetUser);
         }
     } else {
         // unflag
         $c = new Criteria();
         $c->add("user_id", $user->getUserId());
         $c->add("target_user_id", $targetUser->getUserId());
         DB_UserAbuseFlagPeer::instance()->delete($c);
         EventLogger::instance()->logUnflagUser($targetUser);
     }
     $db->commit();
 }