Example #1
0
    function __construct()
    {
        $rules = array();

        // Smiley rule
        $rules['smileys'] = array(
            'start'    => self::REGEXP,
            'callback' => 'SmileyFormat::smiley'
        );

        // Smiley short notation rule
        $needles = array_keys(Smiley::getShort());
        $needles = array_map('preg_quote', $needles);
        $rules['smileys_short'] = array(
            'start'    => '(>|^|\s)(' . implode('|', $needles) . ')(?=$|<|\s)',
            'callback' => 'SmileyFormat::short'
        );

        parent::__construct($rules);
    }
Example #2
0
 /**
  * Apply markup rules on plain text.
  *
  * @param TextFormat $markup  Markup rules applied on marked-up text.
  * @param string     $text    Marked-up text on which rules are applied.
  *
  * @return string  HTML code computed from marked-up text.
  */
 private static function markupText($markup, $text)
 {
     return symbol(smile($markup->format($text), false));
 }
Example #3
0
function console($message, $EOL = true, $log = true, $level = 1)
{
    if (!defined("DEBUG") or DEBUG >= $level) {
        $message .= $EOL === true ? PHP_EOL : "";
        $time = (ENABLE_ANSI === true ? FORMAT_AQUA . date("H:i:s") . FORMAT_RESET : date("H:i:s")) . " ";
        $replaced = TextFormat::clean(preg_replace('/\\x1b\\[[0-9;]*m/', "", $time . $message));
        if ($log === true and (!defined("LOG") or LOG === true)) {
            logg(date("Y-m-d") . " " . $replaced, "console", false, $level);
        }
        if (ENABLE_ANSI === true) {
            $add = "";
            if (preg_match("/\\[([a-zA-Z0-9]*)\\]/", $message, $matches) > 0) {
                switch ($matches[1]) {
                    case "ERROR":
                    case "SEVERE":
                        $add .= FORMAT_RED;
                        break;
                    case "INTERNAL":
                    case "DEBUG":
                        $add .= FORMAT_GRAY;
                        break;
                    case "WARNING":
                        $add .= FORMAT_YELLOW;
                        break;
                    case "NOTICE":
                        $add .= FORMAT_AQUA;
                        break;
                    default:
                        $add = "";
                        break;
                }
            }
            $message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET);
        } else {
            $message = $replaced;
        }
        echo $message;
    }
}
Example #4
0
 /**
  * Initializes a new StudipFormat instance.
  */
 public function __construct()
 {
     parent::__construct(self::getStudipMarkups());
 }
Example #5
0
 public function setUp()
 {
     $markup = new TextFormat();
     $markup->addMarkup('line', '^--+$', NULL, 'markupLine');
     $markup->addMarkup('heading', '^(!{1,4})([^\\n]+)', NULL, 'markupHeading');
     $markup->addMarkup('bold', '\\*\\*', '\\*\\*', 'markupText');
     $markup->addMarkup('italics', '%%', '%%', 'markupText');
     $markup->addMarkup('underline', '__', '__', 'markupText');
     $markup->addMarkup('verb', '##', '##', 'markupText');
     $markup->addMarkup('big', '\\+\\+', '\\+\\+', 'markupText');
     $markup->addMarkup('small', '--', '--', 'markupText');
     $markup->addMarkup('super', '>>', '>>', 'markupText');
     $markup->addMarkup('sub', '<<', '<<', 'markupText');
     $markup->addMarkup('strike', '\\{-', '-\\}', 'markupText');
     $markup->addMarkup('simple_bold', '(?<=\\s|^)\\*(\\S+)\\*(?=\\s|$)', NULL, 'markupSimple');
     $markup->addMarkup('simple_italics', '(?<=\\s|^)%(\\S+)%(?=\\s|$)', NULL, 'markupSimple');
     $markup->addMarkup('simple_underline', '(?<=\\s|^)_(\\S+)_(?=\\s|$)', NULL, 'markupSimple');
     $markup->addMarkup('simple_verb', '(?<=\\s|^)#(\\S+)#(?=\\s|$)', NULL, 'markupSimple');
     $markup->addMarkup('simple_big', '(?<=\\s|^)\\+(\\S+)\\+(?=\\s|$)', NULL, 'markupSimple');
     $markup->addMarkup('simple_small', '(?<=\\s|^)-(\\S+)-(?=\\s|$)', NULL, 'markupSimple');
     $markup->addMarkup('simple_super', '(?<=\\s|^)>(\\S+)>(?=\\s|$)', NULL, 'markupSimple');
     $markup->addMarkup('simple_sub', '(?<=\\s|^)<(\\S+)<(?=\\s|$)', NULL, 'markupSimple');
     $markup->addMarkup('image', '\\[img(=.*?)?\\](\\S+)', NULL, 'markupImage');
     $markup->addMarkup('table', '(^\\|[^\\n]*\\|[^\\n]*\\n)+', NULL, 'markupTable');
     $markup->addMarkup('list', '(^[=-]+ [^\\n]+\\n)+', NULL, 'markupList');
     $markup->addMarkup('indent', '(^  [^\\n]+\\n)+', NULL, 'markupIndent');
     $markup->addMarkup('nop', '\\[nop\\](.*?)\\[\\/nop\\]', NULL, 'markupNop');
     $markup->addMarkup('pre', '\\[pre\\]', '\\[\\/pre\\]', 'markupPre');
     $markup->addMarkup('code', '\\[code\\](.*?)\\[\\/code\\]', NULL, 'markupCode');
     $markup->addMarkup('quote', '\\[quote(=.*?)?\\]', '\\[\\/quote\\]', 'markupQuote');
     $markup->addMarkup('link', '(\\[.*?\\])?\\b(https?:\\/\\/\\S+)', NULL, 'markupLink');
     $markup->addMarkup('mail', '(\\[.*?\\])?\\b([\\w!#%+.-]+@[[:alnum:].-]+)', NULL, 'markupMail');
     $markup->addMarkup('sum', '\\(:sum\\((\\d+)\\\\(\\d+)\\):\\)', NULL, 'markupSum');
     $this->markup = $markup;
 }
Example #6
0
/**
 * Simplified version of formatReady that handles link formatting only.
 *
 * @param  string $text   Marked-up text.
 * @param  bool   $nl2br  Convert newlines to <br>.
 * @return string         Marked-up text with markup-links converted to
 *                        HTML-links.
 */
function formatLinks($text, $nl2br = TRUE)
{
    $link_markup_rule = StudipFormat::getStudipMarkup('links');
    $markup = new TextFormat();
    $markup->addMarkup('links', $link_markup_rule['start'], $link_markup_rule['end'], $link_markup_rule['callback']);
    if ($nl2br) {
        // fix newlines
        $text = nl2br($text, FALSE);
    }
    return Markup::purify($markup->format(trim($text)));
}