コード例 #1
0
ファイル: TPL.php プロジェクト: pscheit/psc-cms
 public static function miniMarkup($string)
 {
     $text = HTML::esc($string);
     if (mb_strpos($text, '[p]') === FALSE) {
         $text = nl2br($text);
     }
     $search = array('[p]', '[pf]', '[/p]', '[/a]', '[br]', '[green]', '[/green]', '[b]', '[/b]');
     $repl = array('<p>', '<p class="first">', '</p>', '</a>', '<br />', '<span class="green">', '</span>', '<strong>', '</strong>');
     foreach (array('nobr', 'ul', 'li', 'strong') as $tag) {
         $search[] = '[' . $tag . ']';
         $search[] = '[/' . $tag . ']';
         $repl[] = '<' . $tag . '>';
         $repl[] = '</' . $tag . '>';
     }
     $search[] = '[headline]';
     $search[] = '[/headline]';
     $repl[] = '<h2>';
     $repl[] = '</h2>';
     //$search[] = '<code>';
     //$search[] = '</code>';
     //$repl[] = '<textarea readonly="readonly">';
     //$repl[] = '</textarea>';
     $text = str_replace($search, $repl, $text);
     $text = self::replaceLinksMarkup($text);
     $text = self::replaceBUIMarkup($text);
     return $text;
 }
コード例 #2
0
ファイル: FrameworkPage.php プロジェクト: pscheit/psc-cms
 public function setTitleForProject(Project $project)
 {
     $config = $project->getConfiguration();
     $title = $config->get('project.title', 'Psc - CMS');
     $title .= ' ' . $config->get('version');
     $this->setTitle(HTML::tag('title', HTML::esc($title)));
 }
コード例 #3
0
ファイル: Page.php プロジェクト: pscheit/psc-cms
 public function setTitleString($title)
 {
     $this->title = new Tag('title', HTML::esc($title));
     return $this;
 }
コード例 #4
0
ファイル: HTML.php プロジェクト: pscheit/psc-cms
 public static function esc($value)
 {
     return \Psc\HTML\HTML::esc($value);
 }
コード例 #5
0
 /**
  * @param array $htmlSnippets see Webforge\CMS\Navigation\NestedSetConverter::toHTMLList()
  */
 public function getHTML($locale, array $htmlSnippets = array(), NestedSetConverter $converter = NULL, \Closure $qbHook = NULL)
 {
     $that = $this;
     $htmlSnippets = array_merge(array('rootOpen' => function ($root) {
         return '<ul id="nav">';
     }, 'nodeDecorator' => function ($node) use($that, $locale) {
         $url = $that->getUrl($node, $locale);
         $html = '<li><a href="' . $url . '">';
         if ($node->getDepth() === 0 && $node->getImage() != NULL) {
             $html .= '<img src="' . \Psc\HTML\HTML::escAttr($node->getImage()) . '" alt="' . \Psc\HTML\HTML::escAttr($node->getTitle($locale)) . '" />';
         }
         $html .= \Psc\HTML\HTML::esc($node->getTitle($locale));
         $html .= '</a>';
         return $html;
     }), $htmlSnippets);
     $qb = $this->childrenQueryBuilder(NULL, $qbHook ?: $this->getDefaultQueryBuilderHook());
     $query = $qb->getQuery();
     $nodes = $query->getResult();
     $converter = $converter ?: new NestedSetConverter();
     return $converter->toHTMLList($nodes, $htmlSnippets);
 }
コード例 #6
0
ファイル: Text.php プロジェクト: pscheit/psc-cms
 public static function reformat($html, $withPFirst = TRUE)
 {
     /* compile regex */
     $blockElements = array('h1', 'h2', 'h3', 'div', 'h3', 'table', 'tr', 'td', 'ol', 'li', 'ul', 'pre', 'p');
     $blemRx = '(?:' . implode('|', $blockElements) . ')';
     $blemStartRx = '<' . $blemRx . '[^>]*(?<!\\/)>';
     // ignores self-closing
     $blemEndRx = '<\\/' . $blemRx . '[^>]*>';
     $blemBothRx = '<\\/?' . $blemRx . '[^>]*>';
     $debug = FALSE;
     $log = NULL;
     $log .= 'Starte mit Text: "' . $html . '"<br />' . "\n";
     $level = 0;
     $pOpen = FALSE;
     $matching = NULL;
     $ret = NULL;
     $firstP = $withPFirst;
     $x = 0;
     while ($html != '' && $x <= 100000000) {
         $x++;
         $log .= "level: " . $level . ":  ";
         /* $html abschneiden (schritt) */
         if (isset($matching)) {
             $html = mb_substr($html, mb_strlen($matching));
             $ret .= $matching;
             $matching = NULL;
         }
         /* normaler text */
         $match = array();
         if (Preg::match($html, '/^([^\\n<>]+)/', $match) > 0) {
             /* p öffnen, wenn es nicht offen ist */
             if ($level == 0 && !$pOpen) {
                 $pOpen = TRUE;
                 $log .= "open p<br />\n";
                 if ($firstP && mb_strlen(trim($ret)) == 0) {
                     $ret .= '<p class="first">';
                     $firstP = FALSE;
                 } else {
                     $ret .= '<p>';
                 }
             }
             $matching = $match[1];
             $log .= "text(" . mb_strlen($matching) . "): " . str_replace(array("\n", "\r"), array("-n-\n", "-r-\r"), $matching) . "<br />\n";
             continue;
         }
         /* absatz */
         $match = array();
         if (S::startsWith($html, "\n\n")) {
             $matching = "\n\n";
             if ($level == 0 && $pOpen) {
                 $log .= "Absatz (close p)<br />\n";
                 $pOpen = FALSE;
                 $ret .= '</p>';
                 //$ret .= "\n"; // da matching hinzugefügt wird
             }
             continue;
         }
         /* zeilenumbruch  */
         if (S::startsWith($html, "\n")) {
             $matching = "\n";
             $log .= "\\n gefunden<br />\n";
             /* wir machen ein <br /> aus dem \n, wenn wir im p modus sind */
             if ($pOpen) {
                 $ret .= '<br />';
                 $log .= "in br umwandeln<br />\n";
             }
             continue;
         }
         /* prüfen auf html tags (block start, block end, inline tag */
         $match = array();
         if (Preg::match($html, '/^<(\\/)?([^\\s>]+)((?>[^>])*)>/', $match) > 0) {
             list($full, $op, $tagName, $rest) = $match;
             if (in_array($tagName, $blockElements)) {
                 $matching = $full;
                 if ($op != '/') {
                     /* block element start */
                     if ($pOpen) {
                         $ret .= '</p>';
                         $log .= "close p<br />\n";
                         $pOpen = FALSE;
                     }
                     $log .= "block level(" . $level . ") start : '" . $matching . "'<br />\n";
                     $level++;
                 } else {
                     /* block element end */
                     $log .= "block level(" . $level . ") end: '" . $matching . "'<br />\n";
                     $level--;
                 }
             } else {
                 /* html tag (kein block element) */
                 $matching = $full;
                 /* p öffnen, wenn es nicht offen ist */
                 if ($level == 0 && !$pOpen) {
                     $pOpen = TRUE;
                     $log .= "open p<br />\n";
                     if ($firstP && mb_strlen(trim($ret)) == 0) {
                         $ret .= '<p class="first">';
                         $firstP = FALSE;
                     } else {
                         $ret .= '<p>';
                     }
                 }
                 $log .= "inline-tag: '" . $matching . "'<br />\n";
             }
             continue;
         }
         /* kein fall hat gegriffen, wir verkürzen um 1 Zeichen */
         $matching = HTML::esc(mb_substr($html, 0, 1));
         $log .= "zeichen: " . $matching . "<br />\n";
     }
     /* letztes <p> schließen */
     if ($pOpen) {
         $ret .= '</p>' . "\n";
     }
     if ($debug) {
         print $log;
     }
     return $ret;
 }
コード例 #7
0
ファイル: Tag.php プロジェクト: pscheit/psc-cms
 public function html()
 {
     /* js chains */
     if ($this->getOption('closeTag', TRUE) == TRUE) {
         foreach ($this->jsChain as $code) {
             jQuery::chain($this, $code);
         }
         $this->jsChain = array();
     }
     $tagIndent = (int) $this->getOption('tag.indent', 0);
     $indent = max((int) $this->getOption('indent', 0), (int) $this->getOption('content.indent', 0));
     if ($this->tag == 'textarea' || $this->tag == 'pre') {
         $indent = $tagIndent = 0;
     }
     $html = '<' . HTML::esc($this->tag) . $this->htmlAttributes();
     if ($this->getOption('selfClosing', FALSE)) {
         /* self closing element ohne inhalt */
         $html .= ' />' . ($this->getOption('br.selfClosing', FALSE) ? "\n" : NULL);
     } elseif ($this->getOption('onlyOpen', FALSE)) {
         /* nur open-tag schließen, kein content, kein schließendes tag */
         $html .= '>' . ($this->getOption('br.onlyOpen', FALSE) ? "\n" : NULL);
     } else {
         /* open-tag schließen, content, schließendes tag */
         $html .= '>' . ($this->getOption('br.openTag', FALSE) ? "\n" : NULL) . ($this->getOption('br.beforeContent', FALSE) ? "\n" : NULL) . ($indent > 0 ? S::indent($this->htmlContent(), $indent) : $this->htmlContent()) . ($this->getOption('br.afterContent', FALSE) ? "\n" : NULL);
         if ($this->getOption('closeTag', TRUE)) {
             $html .= '</' . HTML::esc($this->tag) . '>' . ($this->getOption('br.closeTag', FALSE) ? "\n" : NULL);
         }
     }
     if ($tagIndent > 0) {
         $html = S::indent($html, $tagIndent, "\n");
     } else {
         $html;
     }
     if (isset($this->template)) {
         $contentsArray = array_merge($this->convertContent(), $this->convertTemplateContent());
         $contentsArray['self'] = $html;
         $html = str_replace(array_map(create_function('$a', 'return "%".$a."%"; '), array_keys($contentsArray)), array_values($contentsArray), $this->template);
     }
     return $html;
 }
コード例 #8
0
ファイル: Errors.php プロジェクト: pscheit/psc-cms
 /**
  */
 public function addExInner(\Psc\Exception $e)
 {
     $msg = $e->errorMessage;
     $ei = $e->getPrevious();
     $devInfo = NULL;
     if (DEV) {
         $devInfo = 'InnerException: <br />';
         $file = mb_substr($ei->getFile(), mb_strlen(BASE_DIR));
         // relativ machen weil kürzer
         $devInfo .= get_class($ei) . ' message: ' . nl2br(HTML::esc($ei->getMessage())) . ' in {base}' . DIRECTORY_SEPARATOR . $file . ':' . $ei->getLine() . '<br />';
         $devInfo .= 'Stack trace: <br />';
         $devInfo .= nl2br($ei->getTraceAsString());
     }
     return $this->add($msg, $e->errorStatus, $devInfo);
 }