/**
  * The render method for the login page type. When on a login page type, this is given the login action as determined by the page type. Can be either null (default), 'password_forgotten', or 'password_reset' (or any other string of which a template "$sLoginType_action_$sAction" exists).
  *
  */
 public function renderFrontend($sAction = 'login')
 {
     $aOptions = @unserialize($this->getData());
     $sLoginType = isset($aOptions[self::MODE_SELECT_KEY]) ? $aOptions[self::MODE_SELECT_KEY] : 'login';
     $this->oUser = Session::getSession()->getUser();
     if ($this->oUser) {
         $sAction = 'logout';
     }
     $oTemplate = $this->constructTemplate($sLoginType);
     if ($oTemplate->hasIdentifier('function_template')) {
         $oFunctionTemplate = null;
         try {
             $oFunctionTemplate = $this->constructTemplate("{$sLoginType}_action_{$sAction}");
         } catch (Exception $e) {
             //Fallback to the default function template for the specified action
             $oFunctionTemplate = $this->constructTemplate("login_action_{$sAction}");
         }
         $oTemplate->replaceIdentifier('function_template', $oFunctionTemplate, null, Template::LEAVE_IDENTIFIERS);
     }
     if ($this->oUser && $this->oPage) {
         $oPage = $this->oPage;
         if (Session::getSession()->hasAttribute('login_referrer_page')) {
             $oPage = Session::getSession()->getAttribute('login_referrer_page');
             Session::getSession()->resetAttribute('login_referrer_page');
         }
         if (!$this->oPage->getIsProtected() || Session::getSession()->getUser()->mayViewPage($this->oPage)) {
             $oTemplate->replaceIdentifier('fullname', Session::getSession()->getUser()->getFullName());
             $oTemplate->replaceIdentifier('name', Session::getSession()->getUser()->getUsername());
             $oTemplate->replaceIdentifier('action', LinkUtil::link(FrontendManager::$CURRENT_NAVIGATION_ITEM->getLink(), null, array('logout' => 'true')));
         } else {
             $oFlash = Flash::getFlash();
             $oFlash->addMessage('login.logged_in_no_access');
         }
     }
     $oTemplate->replaceIdentifier('login_title', TranslationPeer::getString($sAction == 'password_forgotten' ? 'wns.login.password_reset' : 'wns.login'));
     $sOrigin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : LinkUtil::linkToSelf();
     $oTemplate->replaceIdentifier('origin', $sOrigin);
     if ($sAction !== 'logout') {
         $oLoginPage = $this->oPage ? $this->oPage->getLoginPage() : null;
         $sLink = null;
         if ($oLoginPage === null) {
             $sLink = LinkUtil::link('', 'LoginManager');
         } else {
             $sLink = LinkUtil::link($oLoginPage->getFullPathArray());
         }
         $oTemplate->replaceIdentifier('action', $sLink);
     }
     if ($sAction === 'login') {
         $oLoginPage = $this->oPage ? $this->oPage->getLoginPage() : null;
         $sLink = null;
         if ($oLoginPage === null) {
             $sLink = LinkUtil::link(array(), 'LoginManager', array('password_forgotten' => 'true'));
         } else {
             $sLink = LinkUtil::link($oLoginPage->getFullPathArray(), null, array('password_forgotten' => 'true'));
         }
         $oTemplate->replaceIdentifier('password_forgotten_action', $sLink);
     }
     return $oTemplate;
 }
 /**
  * Create internal links.
  * The identifier value signifies the destination. It can be either a path or one of the following special values: “to_self”, “host_only”, “base_href”.
  * The following additional parameters are allowed: “is_absolute”, “page”, “ignore_request”, “manager”
  * Implicitly, the value of is_absolute determines the type of absolute link generated.
  * A value of “false” will not generate absolute links.
  * Using “auto” will determine server-side whether to use http or https for protocol.
  * Setting is_absolute to “http” or “https” will set the protocol accordingly.
  * Any other value (including “true”) will generate a protocol-relative URL (starting with //), meaning the reference is determined on the client-side.
  * Creating a “base_href” link will always make it absolute and not explicitly setting “is_absolute” will default to “auto” (instead of “true” as is the case with all other link types).
  */
 public function writeLink($oTemplateIdentifier)
 {
     $sDestination = $oTemplateIdentifier->getValue();
     $aParameters = $oTemplateIdentifier->getParameters();
     $bIsAbsolute = false;
     $bAbsoluteType = $oTemplateIdentifier->getParameter('is_absolute');
     if ($bAbsoluteType === 'http' || $bAbsoluteType === 'false') {
         $bAbsoluteType = false;
     } else {
         if ($bAbsoluteType === 'https' || $bAbsoluteType === 'true') {
             $bAbsoluteType = true;
         } else {
             if ($bAbsoluteType === 'auto') {
                 $bAbsoluteType = LinkUtil::isSSL();
             } else {
                 if ($oTemplateIdentifier->hasParameter('is_absolute')) {
                     $bAbsoluteType = null;
                 } else {
                     $bAbsoluteType = 'default';
                 }
             }
         }
     }
     unset($aParameters['is_absolute']);
     if ($sDestination === "to_self") {
         $bIgnoreRequest = $oTemplateIdentifier->getParameter('ignore_request') === 'true';
         unset($aParameters['ignore_request']);
         $sDestination = LinkUtil::linkToSelf(null, $aParameters, $bIgnoreRequest);
     } else {
         if ($sDestination === "host_only") {
             return LinkUtil::absoluteLink('');
         } else {
             if ($sDestination === "base_href") {
                 $sDestination = MAIN_DIR_FE_PHP;
                 $bIsAbsolute = true;
                 if (!$oTemplateIdentifier->hasParameter('is_absolute')) {
                     $bAbsoluteType = LinkUtil::isSSL();
                 }
             } elseif ($sPage = $oTemplateIdentifier->getParameter('page')) {
                 $oPage = PageQuery::create()->findOneByIdentifier($sPage);
                 if ($oPage === null) {
                     $oPage = PageQuery::create()->findOneByName($sPage);
                 }
                 $sManager = 'FrontendManager';
                 if ($oTemplateIdentifier->hasParameter('manager')) {
                     $sManager = $oTemplateIdentifier->getParameter('manager');
                 }
                 if ($oPage) {
                     $sDestination = LinkUtil::link($oPage->getLink(), $sManager);
                 }
             } else {
                 $sManager = null;
                 if ($oTemplateIdentifier->hasParameter('manager')) {
                     unset($aParameters['manager']);
                     $sManager = $oTemplateIdentifier->getParameter('manager');
                 }
                 $sDestination = LinkUtil::link($sDestination, $sManager, $aParameters);
             }
         }
     }
     return LinkUtil::absoluteLink($sDestination, null, $bAbsoluteType, !$bIsAbsolute);
 }
Exemple #3
0
 public static function sendResetMail($oUser, $bShowUserName = false, $sLinkBase = null, $bForceReset = false)
 {
     UserPeer::ignoreRights(true);
     $oUser->setPasswordRecoverHint(PasswordHash::generateHint());
     $oUser->save();
     $oEmailTemplate = new Template('e_mail_pw_recover', array(DIRNAME_TEMPLATES, 'login'));
     $oEmailTemplate->replaceIdentifier('full_name', $oUser->getFullName());
     $oEmailTemplate->replaceIdentifier('first_name', $oUser->getFirstName());
     $oEmailTemplate->replaceIdentifier('last_name', $oUser->getLastName());
     $oEmailTemplate->replaceIdentifier('username', $oUser->getUsername());
     if ($bShowUserName) {
         $oEmailTemplate->replaceIdentifier('username_info', TranslationPeer::getString('wns.login.password_reset.your_username') . ': ' . $oUser->getUsername());
     }
     $sInfoTextKey = 'wns.login.password_recover_email_text2';
     if ($bForceReset) {
         $sInfoTextKey = 'wns.login.password_recover_email_text2_force';
     }
     $oEmailTemplate->replaceIdentifier('ignore_or_reset_info', TranslationPeer::getString($sInfoTextKey));
     if ($sLinkBase === null) {
         if (Manager::$CURRENT_MANAGER instanceof FrontendManager) {
             // We’re most likely on a login page: link to self should be ok
             $sLinkBase = LinkUtil::linkToSelf(null, null, true);
         } else {
             // Use the login manager
             $sLinkBase = LinkUtil::link(array(), 'LoginManager');
         }
     }
     $aParams = array('recover_hint' => md5($oUser->getPasswordRecoverHint()), 'recover_username' => $oUser->getUsername());
     if (Session::getSession()->hasAttribute('login_referrer')) {
         $aParams['recover_referrer'] = Session::getSession()->getAttribute('login_referrer');
     }
     $sLink = "http://" . $_SERVER['HTTP_HOST'] . $sLinkBase . LinkUtil::prepareLinkParameters($aParams);
     $oEmailTemplate->replaceIdentifier('new_pw_url', $sLink);
     $oEmail = new EMail(TranslationPeer::getString('wns.login.password_recover_email_subject'), $oEmailTemplate);
     $sSenderAddress = LinkUtil::getDomainHolderEmail('cms');
     $oEmail->setSender(Settings::getSetting('domain_holder', 'name', 'rapila on ' . $_SERVER['HTTP_HOST']), $sSenderAddress);
     $oEmail->addRecipient($oUser->getEmail(), $oUser->getFullName());
     $oEmail->send();
 }
 public function renderForm($oTemplate, $iFormId)
 {
     foreach ($this->aFormObjects as $oFormObject) {
         $oTemplate->replaceIdentifierMultiple('form_objects', $oFormObject->renderFormObject($iFormId));
     }
     $oValidationObject = new FormObject('hidden', 'form_action', 'form_frontend_module_' . $iFormId, $this);
     $oTemplate->replaceIdentifierMultiple('form_objects', $oValidationObject->renderFormObject($iFormId));
     $oOriginObject = new FormObject('hidden', 'origin', LinkUtil::linkToSelf(), $this);
     $oTemplate->replaceIdentifierMultiple('form_objects', $oOriginObject->renderFormObject($iFormId));
     foreach ($this->aFormOptions as $sOptionName => $sOptionValue) {
         $oTemplate->replaceIdentifier('option', $sOptionValue, $sOptionName);
     }
     $oTemplate->replaceIdentifier('method', $this->getRequestMethod());
 }
 public function renderDetail(Documentation $oDocumentation = null)
 {
     if (self::$DOCUMENTATION_PARTS == null) {
         self::$DOCUMENTATION_PARTS = DocumentationPartQuery::create()->filterByDocumentationId($oDocumentation->getId())->filterByIsPublished(true)->orderBySort()->find();
     }
     if ($oDocumentation) {
         $sName = $oDocumentation->getName();
         $sEmbedUrl = $oDocumentation->getYoutubeUrl();
         $sDescription = RichtextUtil::parseStorageForFrontendOutput(stream_get_contents($oDocumentation->getDescription()));
     } else {
         $sName = TranslationPeer::getString('documentations.uncategorized');
         $sEmbedUrl = null;
         $sDescription = null;
     }
     $oTemplate = $this->constructTemplate('documentation');
     // render video if exists
     if ($sEmbedUrl != null) {
         $this->embedVideo($oTemplate, $sEmbedUrl);
     }
     $oTemplate->replaceIdentifier('documentation_name', $sName);
     $oTemplate->replaceIdentifier('description', $sDescription);
     // render parts
     $oPartTmpl = $this->constructTemplate('part');
     $sLinkToSelf = LinkUtil::linkToSelf();
     $bRequiresQuicklinks = count(self::$DOCUMENTATION_PARTS) > 1;
     $oPartLinkPrototype = $this->constructTemplate('part_link');
     foreach (self::$DOCUMENTATION_PARTS as $sKey => $mPart) {
         if ($mPart === true) {
             $mPart = DocumentationPartQuery::create()->filterByKey($sKey)->findOne();
         }
         $bIsOverview = false;
         if ($mPart instanceof DocumentationPart) {
             //Internal documentation
             $sBody = RichtextUtil::parseStorageForFrontendOutput(stream_get_contents($mPart->getBody()));
             $sLinkText = $mPart->getName();
             $sTitle = $mPart->getTitle();
             $sImageUrl = null;
             if ($mPart->getDocument()) {
                 $sImageUrl = $mPart->getDocument()->getDisplayUrl();
                 if (RichtextUtil::$USE_ABSOLUTE_LINKS) {
                     $sImageUrl = LinkUtil::absoluteLink($sImageUrl);
                 }
             }
             $sKey = $mPart->getKey();
             $bIsOverview = $mPart->getIsOverview();
             $sExternalLink = null;
         } else {
             //External documentation
             $aData = DocumentationProviderTypeModule::dataForPart($sKey, Session::language());
             $sBody = new Template($aData['content'], null, true);
             $sLinkText = $aData['title'];
             $sTitle = null;
             $sImageUrl = null;
             $sExternalLink = $aData['url'];
         }
         // Add quick links
         if ($bRequiresQuicklinks) {
             $oPartLink = clone $oPartLinkPrototype;
             $oPartLink->replaceIdentifier('href', $sLinkToSelf . '#' . $sKey);
             $oPartLink->replaceIdentifier('link_text', $sLinkText);
             if ($sTitle != null) {
                 $oPartLink->replaceIdentifier('title', $sTitle);
             }
             $oTemplate->replaceIdentifierMultiple('part_links', $oPartLink, null, Template::NO_NEW_CONTEXT);
         }
         // Add documentation part
         $oPartTemplate = clone $oPartTmpl;
         $oPartTemplate->replaceIdentifier('name', $sLinkText);
         $oPartTemplate->replaceIdentifier('anchor', $sKey);
         $oPartTemplate->replaceIdentifier('href_top', $sLinkToSelf . "#top_of_page");
         $oPartTemplate->replaceIdentifier('external_link', $sExternalLink);
         if ($sImageUrl) {
             $oPartTemplate->replaceIdentifier('image', TagWriter::quickTag('img', array('class' => !$bIsOverview ? 'image_float' : "image_fullwidth", 'src' => $sImageUrl, 'alt' => 'Bildschirmfoto von ' . $sLinkText)));
             $oPartTemplate->replaceIdentifier('margin_left_class', $bIsOverview ? '' : ' margin_left_class');
         }
         $oPartTemplate->replaceIdentifier('content', $sBody);
         $oTemplate->replaceIdentifierMultiple('part', $oPartTemplate);
     }
     return $oTemplate;
 }