Exemplo n.º 1
0
 /**
  * @return string
  */
 public function transform()
 {
     /** @var $site SMSSite */
     $site = $this->getDIServiceObject('APF\\extensions\\apfelsms', 'Site');
     $siteTitle = StringAssistant::escapeSpecialCharacters($site->getWebsiteTitle());
     $currentPage = $site->getCurrentPage();
     if ($currentPage === null) {
         $pageTitle = $siteTitle;
     } else {
         /** @var $currentPage SMSPage */
         $pageTitle = $currentPage->getNavTitle();
     }
     $pageTitle = StringAssistant::escapeSpecialCharacters($pageTitle);
     return str_replace(['{PAGETITLE}', '{SITETITLE}'], [$pageTitle, $siteTitle], self::$titleTemplate);
 }
Exemplo n.º 2
0
 public function transform()
 {
     /** @var $SMSM SMSManager */
     $SMSM = $this->getDIServiceObject('APF\\extensions\\apfelsms', 'Manager');
     $page = $SMSM->getSite()->getCurrentPage();
     $pageId = $this->getAttribute('pageId');
     if (!empty($pageId)) {
         try {
             $page = $SMSM->getPage($pageId);
         } catch (SMSException $e) {
             return 'Untitled';
             // no title could be found (no valid ID)
         }
     }
     return StringAssistant::escapeSpecialCharacters($page->getTitle());
 }
Exemplo n.º 3
0
 /**
  * Generates a string that can be used as captcha competition.
  *
  * @param int $length Length of the string.
  *
  * @return string Captcha string.
  *
  * @author Christian Achatz
  * @version
  * Version 0.1, 28.12.2007<br />
  */
 public static function generateCaptchaString($length)
 {
     // shuffles random numbers
     srand(StringAssistant::generateSeed());
     $characterBase = 'ABCDEFGHJKLMNPRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
     $captchaString = (string) '';
     while (strlen($captchaString) < $length) {
         $captchaString .= substr($characterBase, rand() % strlen($characterBase), 1);
     }
     return $captchaString;
 }
Exemplo n.º 4
0
 /**
  * @param SMSPage[] $navPages
  * @param $depth
  *
  * @return string
  * @version v0.1
  *          v0.2 (15.05.2013) Added support to keep certain request parameters in url
  */
 protected function buildMenuEntries(array $navPages, $depth)
 {
     $lastCount = count($navPages);
     $count = 0;
     $buffer = '';
     $url = $this->getUrlPrototype();
     foreach ($navPages as $navPage) {
         $count++;
         $linkURL = $navPage->getLink(clone $url);
         $linkTitle = $navPage->getNavTitle();
         $linkText = $linkTitle;
         $linkClasses = '';
         if ($count == 1) {
             $linkClasses .= 'first ';
         }
         if ($count == $lastCount) {
             $linkClasses .= 'last ';
         }
         if ($navPage->isActive()) {
             $linkClasses .= 'active ';
         }
         if ($navPage->isCurrentPage()) {
             $linkClasses .= 'current ';
         }
         $children = $navPage->getChildren();
         if (($depth > 1 || $this->autoDepth && $navPage->isActive()) && count($children) > 0) {
             // cull entries which not should be displayed
             $subEntries = $this->cullEntries($children);
             if (count($subEntries) > 0) {
                 $template = $this->getTemplate('navEntryWithSubs');
                 if ($this->autoDepth) {
                     $newDepth = 1;
                 } else {
                     $newDepth = $depth - 1;
                 }
                 // recursive for subEntries
                 $template->setPlaceHolder('subEntries', $this->buildMenuEntries($subEntries, $newDepth));
             } else {
                 $template = $this->getTemplate('navEntry');
             }
         } else {
             $template = $this->getTemplate('navEntry');
         }
         $template->setPlaceHolder('URL', StringAssistant::escapeSpecialCharacters($linkURL));
         $template->setPlaceHolder('TITLE', StringAssistant::escapeSpecialCharacters($linkTitle));
         $template->setPlaceHolder('CLASSES', $linkClasses);
         $template->setPlaceHolder('TEXT', StringAssistant::escapeSpecialCharacters($linkText));
         $buffer .= $template->transformTemplate();
     }
     return $buffer;
 }
 public function transformContent()
 {
     /** @var $SMSM SMSManager */
     $SMSM = $this->getDIServiceObject('APF\\extensions\\apfelsms', 'Manager');
     $this->SMSM = $SMSM;
     $doc = $this->getDocument();
     $basePageId = $doc->getAttribute('SMSBreadcrumbNavBasePageId');
     ////
     // fetch base page
     if (!empty($basePageId)) {
         $basePage = $this->SMSM->getPage($basePageId);
     } else {
         $basePage = $this->SMSM->getSite()->getStartPage();
     }
     $currentPage = $this->SMSM->getSite()->getCurrentPage();
     $basePageLevel = $basePage->getLevel();
     $basePageId = $basePage->getId();
     ////
     // collect all breadcrumbs
     /** @var $reverseCrumbArray \APF\extensions\apfelsms\biz\pages\SMSPage[] */
     $reverseCrumbArray = [];
     $crumb = $currentPage;
     do {
         // Ignore origanisation-/system-nodes (hidden nodes without title)
         $crumbNavTitle = $crumb->getNavTitle();
         if (!($crumb->isHidden() && empty($crumbNavTitle))) {
             $reverseCrumbArray[] = $crumb;
         }
         $oldCrumb = $crumb;
         $crumb = $oldCrumb->getParent();
     } while ($crumb !== null && $basePageLevel <= $oldCrumb->getLevel() && $crumb->getId() != $basePageId);
     // add the base page, if not same as current page
     if ($currentPage->getId() != $basePageId) {
         $reverseCrumbArray[] = $basePage;
     }
     /** @var $crumbArray \APF\extensions\apfelsms\biz\pages\SMSPage[] */
     $crumbArray = array_reverse($reverseCrumbArray);
     ////
     // build breadcrumbs
     $buffer = '';
     $lastKey = count($crumbArray) - 1;
     $url = $this->getUrlPrototype();
     foreach ($crumbArray as $key => $crumb) {
         $template = $this->getTemplate('breadcrumb');
         $linkURL = $crumb->getLink(clone $url);
         $linkText = $crumb->getNavTitle();
         if ($crumb->getId() == $basePageId) {
             // allow custom title for basePage
             $linkText = $doc->getAttribute('SMSBreadcrumbNavBasePageIdTitle', $crumb->getNavTitle());
         }
         if (empty($linkText)) {
             $linkText = $crumb->getId();
         }
         $linkTitle = $linkText;
         $linkClasses = ' level_' . $crumb->getLevel();
         if ($key == $lastKey) {
             $linkClasses .= ' last active current';
         }
         if ($key == 0) {
             $linkClasses .= ' first';
         }
         $template->setPlaceHolder('URL', StringAssistant::escapeSpecialCharacters($linkURL));
         $template->setPlaceHolder('TITLE', StringAssistant::escapeSpecialCharacters($linkTitle));
         $template->setPlaceHolder('TEXT', StringAssistant::escapeSpecialCharacters($linkText));
         $template->setPlaceHolder('CLASSES', $linkClasses);
         $buffer .= $template->transformTemplate();
     }
     $containerTemplate = $this->getTemplate('breadcrumbNavigationContainer');
     $containerTemplate->setPlaceHolder('breadcrumbs', $buffer);
     $containerTemplate->transformOnPlace();
 }
Exemplo n.º 6
0
 public function transform()
 {
     /** @var $SMSS SMSSite */
     $SMSS = $this->getDIServiceObject('APF\\extensions\\apfelsms', 'Site');
     return StringAssistant::escapeSpecialCharacters($SMSS->getWebsiteTitle());
 }
Exemplo n.º 7
0
 /**
  * Implements the onAfterAppend method from the ui_element class.
  *
  * @author Christian Achatz, Stephan Spiess
  * @version
  * Version 0.1, 20.06.2008<br />
  * Version 0.2, 10.11.2008 (Added the "clearonerror" attribute. If set to "true", the field is cleared on error.)<br />
  * Version 0.3, 04.01.2010 (Added the text_id attribute)<br />
  * Version 0.4, 29.10.2012 (Bug-fix: attribute valmarkerclass is now applied to the inner form field to allow css field validation on error)<br />
  */
 public function onParseTime()
 {
     // create text field
     $this->textField = new TextFieldTag();
     $this->textField->setObjectId(XmlParser::generateUniqID());
     // prepare the text field
     $textClass = $this->getAttribute('text_class');
     if ($textClass !== null) {
         $this->textField->setAttribute('class', $textClass);
     }
     $textStyle = $this->getAttribute('text_style');
     if ($textStyle !== null) {
         $this->textField->setAttribute('style', $textStyle);
     }
     $textId = $this->getAttribute('text_id');
     if ($textId !== null) {
         $this->textField->setAttribute('id', $textId);
     }
     // apply validation marker css class to provide validation markup capabilities
     $errorClass = $this->getAttribute(AbstractFormValidator::$CUSTOM_MARKER_CLASS_ATTRIBUTE);
     if ($errorClass !== null) {
         $this->textField->setAttribute(AbstractFormValidator::$CUSTOM_MARKER_CLASS_ATTRIBUTE, $errorClass);
     }
     $this->textFieldName = md5($this->getParentObject()->getAttribute('name') . '_captcha');
     $this->textField->setAttribute('name', $this->textFieldName);
     $this->textField->setAttribute('maxlength', '5');
     // apply the onParseTime method to guarantee native APF environment
     $this->textField->setLanguage($this->language);
     $this->textField->setContext($this->context);
     $this->textField->onParseTime();
     // apply the onAfterAppend method to guarantee native APF environment
     $this->textField->setParentObject($this->getParentObject());
     $this->textField->onAfterAppend();
     // get the captcha string from session
     $session = $this->getRequest()->getSession(ShowCaptchaImageAction::SESSION_NAMESPACE);
     $this->captchaString = $session->load($this->textFieldName);
     $session->save($this->textFieldName, StringAssistant::generateCaptchaString(5));
 }
Exemplo n.º 8
0
 public function transform()
 {
     $pageId = $this->getAttribute('pid');
     $attList = null;
     if (empty($pageId)) {
         $pageId = $this->getAttribute('id');
         $attList = array_diff(self::$attributeList, ['id']);
         // remove id from attribute list
     }
     if (empty($pageId)) {
         throw new InvalidArgumentException('No page id defined', E_USER_ERROR);
     }
     /** @var $SMSM SMSManager */
     $SMSM = $this->getDIServiceObject('APF\\extensions\\apfelsms', 'Manager');
     ////
     // evaluate magic page ids
     $magicPageIds = ['__current', '__referer', '__start', '__parent', '__next', '__prev'];
     if (in_array($pageId, $magicPageIds)) {
         switch ($pageId) {
             case '__current':
                 // current page
                 $pageId = $SMSM->getSite()->getCurrentPageId();
                 break;
             case '__referer':
                 // previous visited page
                 // get http referer
                 if ($this->getRequest()->getReferrer() === null) {
                     // fallback on current page
                     $pageId = $SMSM->getSite()->getCurrentPageId();
                     break;
                 }
                 $pageRequestParamName = $SMSM->getPageRequestParamName();
                 $referrerUrl = Url::fromReferrer(true);
                 $currentUrl = Url::fromCurrent(true);
                 // protection against url xss
                 if ($referrerUrl->getHost() == $currentUrl->getHost()) {
                     $pageId = $referrerUrl->getQueryParameter($pageRequestParamName);
                 }
                 if (empty($pageId)) {
                     // safety fallback on current page
                     $pageId = $SMSM->getSite()->getCurrentPageId();
                 }
                 // test for valid page id
                 try {
                     $SMSM->getPage($pageId);
                 } catch (SMSException $e) {
                     $pageId = $SMSM->getSite()->getCurrentPageId();
                 }
                 break;
             case '__start':
                 $pageId = $SMSM->getSite()->getStartPageId();
                 break;
             case '__parent':
                 $currentPage = $SMSM->getSite()->getCurrentPage();
                 $parentPage = $currentPage->getParent();
                 if ($parentPage === null) {
                     $pageId = $SMSM->getSite()->getStartPageId();
                 } else {
                     $pageId = $parentPage->getId();
                 }
                 break;
             case '__next':
             case '__prev':
                 $currentPage = $SMSM->getSite()->getCurrentPage();
                 $siblings = $currentPage->getSiblings(true);
                 if (empty($siblings)) {
                     return '';
                 }
                 /** @var SMSPage[] $visibleSiblings */
                 $visibleSiblings = [];
                 foreach ($siblings as $sibling) {
                     if ($sibling->isHidden()) {
                         continue;
                     }
                     $visibleSiblings[] = $sibling;
                 }
                 $currentIndex = null;
                 $currentId = $currentPage->getId();
                 foreach ($visibleSiblings as $index => $sibling) {
                     if ($sibling->getId() == $currentId) {
                         $currentIndex = $index;
                         break;
                     }
                 }
                 if ($pageId == '__next') {
                     $summand = 1;
                 } else {
                     $summand = -1;
                 }
                 $index = $currentIndex + $summand;
                 if (!isset($visibleSiblings[$index])) {
                     return '';
                 }
                 $pageId = $visibleSiblings[$index]->getId();
                 break;
         }
     }
     // fetch page object
     try {
         $page = $SMSM->getPage($pageId);
     } catch (SMSException $e) {
         // fallback on 404 error page (not found)
         $page = $SMSM->getSite()->get404Page();
     }
     // prepare URL generation
     $url = Url::fromCurrent();
     $url->resetQuery();
     // add anchor to url when set
     $anchor = $this->getAttribute('anchor');
     if (!empty($anchor)) {
         $url->setAnchor($anchor);
     }
     $content = $this->getContent();
     if (empty($content)) {
         $content = StringAssistant::escapeSpecialCharacters($page->getNavTitle());
     }
     $this->setAttribute('title', $this->getAttribute('title', $page->getTitle()));
     $this->setAttribute('href', $page->getLink($url));
     // is there an modified attribute list (without id attribute) ?
     if (!is_array($attList)) {
         $attList = self::$attributeList;
     }
     return str_replace(['{ATTR}', '{TEXT}'], [$this->getAttributesAsString($this->attributes, $attList), $content], self::$template);
 }