-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* renamed TexyModule::$default -> $syntax * fixed bug TexyPhraseModule::$linksAllowed * TexyScriptModule - added {{texy: nofollow }} * class TexyConfigurator moved to own file
- Loading branch information
Showing
48 changed files
with
6,661 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Syntax highlighting in Texy! | ||
Syntax highlighting in Texy! | ||
**************************** | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Texy! formatter (http://texy.info/) | ||
* | ||
* Copyright (c) 2004-2007 David Grudl aka -dgx- <[email protected]> | ||
* | ||
* @version $Revision$ $Date$ | ||
* @package Texy | ||
*/ | ||
|
||
|
||
// security - include texy.php, not this file | ||
if (!class_exists('Texy')) die(); | ||
|
||
|
||
|
||
// Regular expression patterns | ||
|
||
// Unicode character classes | ||
define('TEXY_CHAR', 'A-Za-z\x{C0}-\x{2FF}\x{370}-\x{1EFF}'); | ||
|
||
// marking meta-characters | ||
// any mark: \x14-\x1F | ||
// CONTENT_MARKUP mark: \x17-\x1F | ||
// CONTENT_REPLACED mark: \x16-\x1F | ||
// CONTENT_TEXTUAL mark: \x15-\x1F | ||
// CONTENT_BLOCK mark: \x14-\x1F | ||
define('TEXY_MARK', "\x14-\x1F"); | ||
|
||
|
||
// modifier .(title)[class]{style} | ||
define('TEXY_MODIFIER', '(?: *(?<= |^)\\.((?:\\([^)\\n]+\\)|\\[[^\\]\\n]+\\]|\\{[^}\\n]+\\}){1,3}?))'); | ||
|
||
// modifier .(title)[class]{style}<> | ||
define('TEXY_MODIFIER_H', '(?: *(?<= |^)\\.((?:\\([^)\\n]+\\)|\\[[^\\]\\n]+\\]|\\{[^}\\n]+\\}|<>|>|=|<){1,4}?))'); | ||
|
||
// modifier .(title)[class]{style}<>^ | ||
define('TEXY_MODIFIER_HV', '(?: *(?<= |^)\\.((?:\\([^)\\n]+\\)|\\[[^\\]\\n]+\\]|\\{[^}\\n]+\\}|<>|>|=|<|\\^|\\-|\\_){1,5}?))'); | ||
|
||
|
||
|
||
// images [* urls .(title)[class]{style} >] | ||
define('TEXY_IMAGE', '\[\*([^\n'.TEXY_MARK.']+)'.TEXY_MODIFIER.'? *(\*|>|<)\]'); | ||
|
||
|
||
// links | ||
define('TEXY_LINK_URL', '(?:\[[^\]\n]+\]|(?!\[)[^\s'.TEXY_MARK.']*?[^:);,.!?\s'.TEXY_MARK.'])'); // any url (nekonèí :).,!? | ||
define('TEXY_LINK', '(?::('.TEXY_LINK_URL.'))'); // any link | ||
define('TEXY_LINK_N', '(?::('.TEXY_LINK_URL.'|:))'); // any link (also unstated) | ||
define('TEXY_EMAIL', '[a-z0-9.+_-]+@[a-z0-9.+_-]+\.[a-z]{2,}'); // [email protected] | ||
define('TEXY_URLSCHEME', '[a-z][a-z0-9+.-]*:'); // http: | mailto: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Texy! formatter (http://texy.info/) | ||
* | ||
* Copyright (c) 2004-2007 David Grudl aka -dgx- <[email protected]> | ||
* | ||
* @version $Revision$ $Date$ | ||
* @package Texy | ||
*/ | ||
|
||
// security - include texy.php, not this file | ||
if (!class_exists('Texy')) die(); | ||
|
||
|
||
|
||
$GLOBALS['TexyConfigurator::$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(), | ||
); /* class static property */ | ||
|
||
|
||
/** | ||
* Texy basic configurators | ||
* | ||
* <code> | ||
* $texy = new Texy(); | ||
* TexyConfigurator::safeMode($texy); | ||
* </code> | ||
*/ | ||
class TexyConfigurator | ||
{ | ||
/** | ||
* Configure Texy! for web comments and other usages, where input text may insert attacker | ||
* | ||
* @param Texy object to configure | ||
* @return void | ||
*/ | ||
function safeMode(/*Texy*/ $texy) /* static */ | ||
{ | ||
$texy->allowedClasses = TEXY_NONE; // no class or ID are allowed | ||
$texy->allowedStyles = TEXY_NONE; // style modifiers are disabled | ||
$texy->allowedTags = $GLOBALS['TexyConfigurator::$safeTags']; // only some "safe" HTML tags and attributes are allowed | ||
$texy->urlSchemeFilters['a'] = '#https?:|ftp:|mailto:#A'; | ||
$texy->urlSchemeFilters['i'] = '#https?:#A'; | ||
$texy->urlSchemeFilters['c'] = '#http:#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" | ||
} | ||
|
||
|
||
|
||
/** | ||
* Switch Texy! configuration to the (default) trust mode | ||
* | ||
* @param Texy object to configure | ||
* @return void | ||
*/ | ||
function trustMode(/*Texy*/ $texy) /* static */ | ||
{ | ||
trigger_error('trustMode() is deprecated. Trust configuration is by default.', E_USER_WARNING); | ||
|
||
$texy->allowedClasses = TEXY_ALL; // classes and id are allowed | ||
$texy->allowedStyles = TEXY_ALL; // inline styles are allowed | ||
$texy->allowedTags = array(); // all valid HTML tags | ||
foreach ($GLOBALS['TexyHtmlCleaner::$dtd']as $tag => $dtd) | ||
$texy->allowedTags[$tag] = is_array($dtd[0]) ? array_keys($dtd[0]) : $dtd[0]; | ||
$texy->urlSchemeFilters = NULL; // disable URL scheme filter | ||
$texy->allowed['image'] = TRUE; // enable images | ||
$texy->allowed['link/definition'] = TRUE; // enable [ref]: URL reference definitions | ||
$texy->allowed['html/comment'] = TRUE; // enable HTML comments | ||
$texy->linkModule->forceNoFollow = FALSE; // disable automatic rel="nofollow" | ||
} | ||
|
||
|
||
|
||
/** | ||
* Disable all links | ||
* | ||
* @param Texy object to configure | ||
* @return void | ||
*/ | ||
function disableLinks($texy) | ||
{ | ||
$texy->allowed['link/reference'] = FALSE; | ||
$texy->allowed['link/email'] = FALSE; | ||
$texy->allowed['link/url'] = FALSE; | ||
$texy->allowed['link/definition'] = FALSE; | ||
$texy->phraseModule->linksAllowed = FALSE; | ||
|
||
if (is_array($texy->allowedTags)) | ||
unset($texy->allowedTags['a']); | ||
// TODO: else... | ||
} | ||
|
||
|
||
/** | ||
* Disable all images | ||
* | ||
* @param Texy object to configure | ||
* @return void | ||
*/ | ||
function disableImages($texy) | ||
{ | ||
$texy->allowed['image'] = FALSE; | ||
$texy->allowed['figure'] = FALSE; | ||
$texy->allowed['image/definition'] = FALSE; | ||
|
||
if (is_array($texy->allowedTags)) | ||
unset($texy->allowedTags['img'], $texy->allowedTags['object'], $texy->allowedTags['embed'], $texy->allowedTags['applet']); | ||
// TODO: else... | ||
} | ||
} |
Oops, something went wrong.