public function build($runData)
 {
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     if (!$user) {
         $runData->setModuleTemplate("misc/AskToLoginModule");
         return;
     }
     // now get the ivitations!
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->add("user_id", $user->getUserId());
     $c->addOrderDescending("invitation_id");
     $invitations = DB_EmailInvitationPeer::instance()->select($c);
     $runData->contextAdd("invitations", $invitations);
 }
 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);
 }
 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);
 }
 public function resendEmailInvitationEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $invitationId = $pl->getParameterValue("invitationId");
     $message2 = trim($pl->getParameterValue("message"));
     $c = new Criteria();
     $c->add("invitation_id", $invitationId);
     $c->add("site_id", $site->getSiteId());
     $inv = DB_EmailInvitationPeer::instance()->selectOne($c);
     if (!$inv) {
         throw new ProcessException(_("Invitation could not be found."), "no_invitation");
     }
     if ($inv->getAttempts() >= 3) {
         throw new ProcessException(_("You can not send more than 3 copies of the invitation."));
     }
     if ($message2 == "") {
         throw new ProcessException(_('Message should not be empty'));
     }
     if (preg_match(';://;', $message2) || preg_match(';\\.www;i', $message2)) {
         throw new ProcessException(_('The message should not contain any links to websites.'), "bad_message");
     }
     if ($message2 != "" && strlen($message2) > 1000) {
         throw new ProcessException(_('The message seems to be too long. Max 1000 characters are allowed.'), "bad_message");
     }
     $db = Database::connection();
     $db->begin();
     // prepare and send email
     $user = $runData->getUser();
     $profile = $user->getProfile();
     $oe = new OzoneEmail();
     $oe->addAddress($inv->getEmail());
     $oe->setSubject(sprintf(_("[%s] %s invites you to join! (reminder)"), GlobalProperties::$SERVICE_NAME, $user->getNickName()));
     $oe->contextAdd('user', $user);
     $oe->contextAdd('profile', $profile);
     $oe->contextAdd('hash', $inv->getHash());
     $oe->contextAdd("site", $site);
     $oe->contextAdd("message", $inv->getMessage());
     $oe->contextAdd("message2", $message2);
     $oe->contextAdd('name', $inv->getName());
     $oe->setBodyTemplate('MembershipEmailInvitation');
     $res = $oe->send();
     if (!$res) {
         throw new ProcessException("Email to this recipient could not be sent for some reason.");
     }
     $inv->setAttempts($inv->getAttempts() + 1);
     $inv->save();
     $db->commit();
 }
 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);
 }
Exemple #6
0
 /**
  * Marks the site as "deleted" and invalidates all the cache related to the site.
  *
  * @param unknown_type $runData
  */
 public function deleteSiteEvent($runData)
 {
     $site = $runData->getTemp("site");
     $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 delete this site."));
     }
     $db = Database::connection();
     $db->begin();
     $oldUnixName = $site->getUnixName();
     $site->setDeleted(true);
     // remove some data.
     $c = new Criteria();
     $c->add('site_id', $site->getSiteId());
     DB_AnonymousAbuseFlagPeer::instance()->delete($c);
     DB_DomainRedirectPeer::instance()->delete($c);
     DB_EmailInvitationPeer::instance()->delete($c);
     DB_MemberApplicationPeer::instance()->delete($c);
     DB_MemberInvitationPeer::instance()->delete($c);
     // now clear cache!
     $keys = array();
     $keys[] = 'site..' . $site->getUnixName();
     $keys[] = 'site_cd..' . $site->getCustomDomain();
     $mc = OZONE::$memcache;
     foreach ($keys as $k) {
         $mc->delete($k);
     }
     $outdater = new Outdater();
     $outdater->siteEvent('delete', $site);
     $outdater->siteEvent('sitewide_change', $site);
     // change site name!!!
     $site->setUnixName($site->getUnixName() . '..del..' . time());
     $site->save();
     // remove custom domain link
     // rename the files
     @rename(WIKIDOT_ROOT . '/web/files--sites/' . $oldUnixName, WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName());
     // delete custom domain link
     if ($site->getCustomDomain()) {
         @unlink(WIKIDOT_ROOT . '/web/custom--domains/' . $site->getCustomDomain());
         $site->setCustomDomain(null);
     }
     $db->commit();
 }