本文整理汇总了PHP中Texy类的典型用法代码示例。如果您正苦于以下问题:PHP Texy类的具体用法?PHP Texy怎么用?PHP Texy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Texy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: blockHandler
/**
* User handler for code block
*
* @param TexyHandlerInvocation handler invocation
* @param string block type
* @param string text to highlight
* @param string language
* @param TexyModifier modifier
* @return TexyHtml
*/
function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
{
if ($blocktype !== 'block/code') {
return $invocation->proceed();
}
$lang = strtoupper($lang);
if ($lang == 'JAVASCRIPT') {
$lang = 'JS';
}
$fshl = new fshlParser('HTML_UTF8', P_TAB_INDENT);
if (!$fshl->isLanguage($lang)) {
return $invocation->proceed();
}
$texy = $invocation->getTexy();
$content = Texy::outdent($content);
$content = $fshl->highlightString($lang, $content);
$content = $texy->protect($content, Texy::CONTENT_BLOCK);
$elPre = TexyHtml::el('pre');
if ($modifier) {
$modifier->decorate($texy, $elPre);
}
$elPre->attrs['class'] = strtolower($lang);
$elCode = $elPre->create('code', $content);
return $elPre;
}
示例2: __construct
public function __construct(Texy $texy, HtmlElement $element, $indented)
{
$this->texy = $texy;
$this->element = $element;
$this->indented = (bool) $indented;
$this->patterns = $texy->getBlockPatterns();
}
示例3: createTemplate
protected function createTemplate($class = NULL)
{
$template = parent::createTemplate($class);
$texy = new \Texy();
$texy->encoding = 'utf-8';
$texy->setOutputMode(\Texy::HTML5);
// config as in \TexyConfigurator::safeMode($texy);
$safeTags = array('a' => array('href', 'title'), 'acronym' => array('title'), 'b' => array(), 'br' => array(), 'cite' => array(), 'code' => array(), 'em' => array(), 'i' => array(), 'strong' => array(), 'sub' => array(), 'sup' => array(), 'q' => array(), 'small' => array());
$texy->allowedClasses = \Texy::NONE;
// no class or ID are allowed
$texy->allowedStyles = \Texy::NONE;
// style modifiers are disabled
$texy->allowedTags = $safeTags;
// only some "safe" HTML tags and attributes are allowed
$texy->urlSchemeFilters[\Texy::FILTER_ANCHOR] = '#https?:|ftp:|mailto:#A';
$texy->urlSchemeFilters[\Texy::FILTER_IMAGE] = '#https?:#A';
$texy->allowed['image'] = FALSE;
// disable images
$texy->allowed['link/definition'] = FALSE;
// disable [ref]: URL reference definitions
$texy->allowed['html/comment'] = FALSE;
// disable HTML comments
# zakázaní nadpisů
$texy->allowed['heading/surrounded'] = FALSE;
$texy->allowed['heading/underlined'] = FALSE;
# zalamování textu v odstavcích po enteru
# false => nebude spojovat řádky, vloží místo enteru <br>
# true => řádky po jednom enteru spojí
$texy->mergeLines = false;
$texy->linkModule->forceNoFollow = TRUE;
// force rel="nofollow"
$template->registerHelper('texy', callback($texy, 'process'));
return $template;
}
示例4: commentTexy
public function commentTexy($text)
{
if (!isset($this->commentTexy)) {
$this->commentTexy = $this->texyFactory->createTexyForComment();
}
return $this->commentTexy->process($text);
}
示例5: createTemplate
protected function createTemplate($class = NULL)
{
$template = parent::createTemplate($class);
$texy = new \Texy();
$texy->encoding = 'utf-8';
$texy->setOutputMode(\Texy::HTML5);
// config as in \TexyConfigurator::safeMode($texy);
$safeTags = array('a' => array('href', 'title'), 'acronym' => array('title'), 'b' => array(), 'br' => array(), 'cite' => array(), 'code' => array(), 'em' => array(), 'i' => array(), 'strong' => array(), 'sub' => array(), 'sup' => array(), 'q' => array(), 'small' => array());
$texy->allowedClasses = \Texy::NONE;
// no class or ID are allowed
$texy->allowedStyles = \Texy::NONE;
// style modifiers are disabled
$texy->allowedTags = $safeTags;
// only some "safe" HTML tags and attributes are allowed
$texy->urlSchemeFilters[\Texy::FILTER_ANCHOR] = '#https?:|ftp:|mailto:#A';
$texy->urlSchemeFilters[\Texy::FILTER_IMAGE] = '#https?:#A';
$texy->allowed['image'] = FALSE;
// disable images
$texy->allowed['link/definition'] = FALSE;
// disable [ref]: URL reference definitions
$texy->allowed['html/comment'] = FALSE;
// disable HTML comments
$texy->linkModule->forceNoFollow = TRUE;
// force rel="nofollow"
$template->registerHelper('texy', callback($texy, 'process'));
return $template;
}
示例6: createTemplate
/**
* @param null $class
* @return Nette\Templating\ITemplate
*/
protected function createTemplate($class = NULL)
{
$template = parent::createTemplate($class);
$template->registerHelper('texy', function ($input) {
$texy = new \Texy();
$html = new Nette\Utils\Html();
return $html::el()->setHtml($texy->process($input));
});
$template->registerHelper('vlna', function ($string) {
$string = preg_replace('<([^a-zA-Z0-9])([ksvzaiou])\\s([a-zA-Z0-9]{1,})>i', "\$1\$2 \$3", $string);
// === \xc2\xa0
return $string;
});
$template->registerHelper('dateInWords', function ($time) {
$time = Nette\Utils\DateTime::from($time);
$months = [1 => 'leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'];
return $time->format('j. ') . $months[$time->format('n')] . $time->format(' Y');
});
$template->registerHelper('timeAgoInWords', function ($time) {
$time = Nette\Utils\DateTime::from($time);
$delta = round((time() - $time->getTimestamp()) / 60);
if ($delta == 0) {
return 'před okamžikem';
}
if ($delta == 1) {
return 'před minutou';
}
if ($delta < 45) {
return "před {$delta} minutami";
}
if ($delta < 90) {
return 'před hodinou';
}
if ($delta < 1440) {
return 'před ' . round($delta / 60) . ' hodinami';
}
if ($delta < 2880) {
return 'včera';
}
if ($delta < 43200) {
return 'před ' . round($delta / 1440) . ' dny';
}
if ($delta < 86400) {
return 'před měsícem';
}
if ($delta < 525960) {
return 'před ' . round($delta / 43200) . ' měsíci';
}
if ($delta < 1051920) {
return 'před rokem';
}
return 'před ' . round($delta / 525960) . ' lety';
});
return $template;
}
示例7: prepareTemplate
public static function prepareTemplate(Template $template)
{
$texy = new \Texy();
$latte = $template->getLatte();
$latte->addFilter('texy', function ($text) use($texy) {
return Html::el('')->setHtml($texy->process($text));
});
$latte->addFilter('time', function ($text) {
return date('j.n.Y G:i:s', $text);
});
}
示例8: createTemplate
protected function createTemplate()
{
$template = parent::createTemplate();
$template->addFilter('texy', function ($text) {
$texy = new \Texy();
$texy->setOutputMode(\Texy::HTML4_TRANSITIONAL);
$texy->encoding = 'utf-8';
$texy->allowedTags = array('strong' => \Texy::NONE, 'b' => \Texy::NONE, 'a' => array('href'), 'em' => \Texy::NONE, 'p' => \Texy::NONE);
//$texy->allowedTags = \Texy::NONE;
return $texy->process($text);
});
return $template;
}
示例9: imageHandler
/**
* User handler for images
*
* @param TexyHandlerInvocation handler invocation
* @param TexyImage
* @param TexyLink
* @return TexyHtml|string|FALSE
*/
function imageHandler($invocation, $image, $link)
{
$texy = $invocation->getTexy();
if (substr($image->URL, -4) === '.swf') {
$movie = Texy::prependRoot($image->URL, $texy->imageModule->root);
$dimensions = ($image->width ? 'width="' . $image->width . '" ' : '') . ($image->height ? 'width="' . $image->height . '" ' : '');
$movie = htmlSpecialChars($movie);
$altContent = htmlSpecialChars($image->modifier->title);
// @see http://phpfashion.com/how-to-correctly-insert-a-flash-into-xhtml
$code = '
<!--[if !IE]> -->
<object type="application/x-shockwave-flash" data="' . $movie . '" ' . $dimensions . '>
<!-- <![endif]-->
<!--[if IE]>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' . $dimensions . '
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0">
<param name="movie" value="' . $movie . '" />
<!--><!--dgx-->
<p>' . $altContent . '</p>
</object>
<!-- <![endif]-->
';
return $texy->protect($code, Texy::CONTENT_BLOCK);
}
return $invocation->proceed();
}
示例10: wiki_texy_phraseHandler
function wiki_texy_phraseHandler($invocation, $phrase, $content, $modifier, $link)
{
if (!$link) {
return $invocation->proceed();
}
if (Texy::isRelative($link->URL)) {
$link->URL = '?page=' . urlencode($link->URL);
} elseif (substr($link->URL, 0, 5) === 'wiki:') {
$link->URL = 'http://en.wikipedia.org/wiki/Special:Search?search=' . urlencode(substr($link->URL, 5));
} elseif (substr($link->URL, 0, 4) === 'url:') {
$link->URL = substr($link->URL, 4);
}
return $invocation->proceed();
}
示例11: processNewMessageForm
public function processNewMessageForm(Form $form)
{
$values = $form->getValues();
$recipients = is_array($values->recipients) ? $values->recipients : [$values->recipients];
if (!$this->authorizator->isAllowed($this->user, 'message', 'sent_to_restricted_recipients')) {
$s = $this->messagesFacade->canMessageBeSentTo($values->recipients, $this->restrictedUsers, $this->users);
if ($s === false) {
$form->addError('Nelze odeslat zprávu vybranému příjemci.');
return;
}
}
if ($values['isSendAsAdmin'] == true and !$this->authorizator->isAllowed($this->user, 'message', 'send_as_admin')) {
$form->addError('Nemáte dostatečná oprávnění k akci.');
return;
}
$texy = new \Texy();
$texy->setOutputMode(\Texy::HTML4_TRANSITIONAL);
$texy->encoding = 'utf-8';
$texy->allowedTags = \Texy::ALL;
$text = $texy->process($values->text);
$message = new SentMessage($values->subject, $text, $this->user);
if ($values['isSendAsAdmin']) {
$message->sendByAuthorRole();
}
try {
$this->messagesFacade->sendMessage($message, $recipients);
} catch (MessageLengthException $ml) {
$form->addError('Zprávu nelze uložit, protože je příliš dlouhá.');
return;
} catch (DBALException $e) {
$this->flashMessage('Zpráva nemohla být odeslána. Zkuste akci opakovat později.', 'errror');
$this->redirect('this');
}
$this->presenter->flashMessage('Zpráva byla úspěšně odeslána', 'success');
$this->presenter->redirect('MailBox:sent');
}
示例12: phraseHandler
/**
* @param TexyHandlerInvocation handler invocation
* @param string
* @param string
* @param TexyModifier
* @param TexyLink
* @return TexyHtml|string|FALSE
*/
function phraseHandler($invocation, $phrase, $content, $modifier, $link)
{
// is there link?
if (!$link) {
return $invocation->proceed();
}
if (Texy::isRelative($link->URL)) {
// modifiy link
$link->URL = 'index?page=' . urlencode($link->URL);
} elseif (substr($link->URL, 0, 5) === 'wiki:') {
// modifiy link
$link->URL = 'http://en.wikipedia.org/wiki/Special:Search?search=' . urlencode(substr($link->URL, 5));
}
return $invocation->proceed();
}
示例13: __construct
public function __construct()
{
parent::__construct();
// safe mode
\TexyConfigurator::safeMode($this);
// output
$this->setOutputMode(self::HTML4_TRANSITIONAL);
$this->htmlOutputModule->removeOptional = false;
self::$advertisingNotice = false;
$this->allowed['heading/surrounded'] = false;
$this->allowed['heading/underlined'] = false;
$this->allowed['link/definition'] = false;
$this->allowed['image/definition'] = false;
$this->mergeLines = false;
$this->addHandler('phrase', array(__CLASS__, 'linkHandler'));
}
示例14: patternTag
/**
* Callback for: <tag attr="...">.
*
* @param TexyLineParser
* @param array regexp matches
* @param string pattern name
* @return TexyHtml|string|FALSE
*/
public function patternTag($parser, $matches)
{
list(, $mEnd, $mTag, $mAttr, $mEmpty) = $matches;
// [1] => /
// [2] => tag
// [3] => attributes
// [4] => /
$tx = $this->texy;
$isStart = $mEnd !== '/';
$isEmpty = $mEmpty === '/';
if (!$isEmpty && substr($mAttr, -1) === '/') {
// uvizlo v $mAttr?
$mAttr = substr($mAttr, 0, -1);
$isEmpty = TRUE;
}
// error - can't close empty element
if ($isEmpty && !$isStart) {
return FALSE;
}
// error - end element with atttrs
$mAttr = trim(strtr($mAttr, "\n", ' '));
if ($mAttr && !$isStart) {
return FALSE;
}
$el = TexyHtml::el($mTag);
if ($isStart) {
// parse attributes
$matches2 = NULL;
preg_match_all('#([a-z0-9:-]+)\\s*(?:=\\s*(\'[^\']*\'|"[^"]*"|[^\'"\\s]+))?()#isu', $mAttr, $matches2, PREG_SET_ORDER);
foreach ($matches2 as $m) {
$key = strtolower($m[1]);
$value = $m[2];
if ($value == NULL) {
$el->attrs[$key] = TRUE;
} elseif ($value[0] === '\'' || $value[0] === '"') {
$el->attrs[$key] = Texy::unescapeHtml(substr($value, 1, -1));
} else {
$el->attrs[$key] = Texy::unescapeHtml($value);
}
}
}
$res = $tx->invokeAroundHandlers('htmlTag', $parser, array($el, $isStart, $isEmpty));
if ($res instanceof TexyHtml) {
return $tx->protect($isStart ? $res->startTag() : $res->endTag(), $res->getContentType());
}
return $res;
}
示例15: __construct
public function __construct()
{
parent::__construct();
// output
$this->setOutputMode(self::HTML4_TRANSITIONAL);
$this->htmlOutputModule->removeOptional = false;
self::$advertisingNotice = false;
// safe mode
TexyConfigurator::safeMode($this);
$this->allowed['heading/surrounded'] = false;
$this->allowed['heading/underlined'] = false;
$this->allowed['link/definition'] = false;
$this->allowed['image/definition'] = false;
// spojování textu v odstavcích po enteru
$this->mergeLines = true;
// přidání target="_blank" k odkazům
// $this->addHandler('phrase', array(__CLASS__, 'addTargetHandler'));
}