From 2912445326b986646376681c9f94c5c8cf5aa1c4 Mon Sep 17 00:00:00 2001 From: Kenji ITO Date: Sun, 2 Oct 2016 15:14:39 +0900 Subject: [PATCH] Modified and moved Text_Wiki library under system/classes --- system/classes/Text/Wiki.php | 1035 +++++++++++++++++ system/classes/Text/Wiki/Parse.php | 195 ++++ system/classes/Text/Wiki/Parse/Anchor.php | 60 + system/classes/Text/Wiki/Parse/Blockquote.php | 151 +++ system/classes/Text/Wiki/Parse/Bold.php | 54 + system/classes/Text/Wiki/Parse/Break.php | 46 + system/classes/Text/Wiki/Parse/Center.php | 55 + system/classes/Text/Wiki/Parse/Code.php | 75 ++ system/classes/Text/Wiki/Parse/Colortext.php | 64 + system/classes/Text/Wiki/Parse/Deflist.php | 96 ++ system/classes/Text/Wiki/Parse/Delimiter.php | 58 + system/classes/Text/Wiki/Parse/Embed.php | 79 ++ system/classes/Text/Wiki/Parse/Emphasis.php | 59 + system/classes/Text/Wiki/Parse/Freelink.php | 111 ++ system/classes/Text/Wiki/Parse/Function.php | 132 +++ system/classes/Text/Wiki/Parse/Heading.php | 82 ++ system/classes/Text/Wiki/Parse/Horiz.php | 45 + system/classes/Text/Wiki/Parse/Html.php | 50 + system/classes/Text/Wiki/Parse/Image.php | 112 ++ system/classes/Text/Wiki/Parse/Include.php | 75 ++ system/classes/Text/Wiki/Parse/Interwiki.php | 98 ++ system/classes/Text/Wiki/Parse/Italic.php | 59 + system/classes/Text/Wiki/Parse/List.php | 229 ++++ system/classes/Text/Wiki/Parse/Newline.php | 49 + system/classes/Text/Wiki/Parse/Paragraph.php | 92 ++ system/classes/Text/Wiki/Parse/Phplookup.php | 48 + system/classes/Text/Wiki/Parse/Prefilter.php | 82 ++ system/classes/Text/Wiki/Parse/Raw.php | 49 + system/classes/Text/Wiki/Parse/Revise.php | 111 ++ system/classes/Text/Wiki/Parse/Smiley.php | 155 +++ system/classes/Text/Wiki/Parse/Strong.php | 59 + system/classes/Text/Wiki/Parse/Subscript.php | 54 + .../classes/Text/Wiki/Parse/Superscript.php | 54 + system/classes/Text/Wiki/Parse/Table.php | 187 +++ system/classes/Text/Wiki/Parse/Tighten.php | 32 + system/classes/Text/Wiki/Parse/Toc.php | 97 ++ system/classes/Text/Wiki/Parse/Tt.php | 57 + system/classes/Text/Wiki/Parse/Underline.php | 54 + system/classes/Text/Wiki/Parse/Url.php | 223 ++++ system/classes/Text/Wiki/Parse/Wikilink.php | 161 +++ system/classes/Text/Wiki/Render.php | 164 +++ system/classes/Text/Wiki/Render/Latex.php | 85 ++ .../classes/Text/Wiki/Render/Latex/Anchor.php | 33 + .../Text/Wiki/Render/Latex/Blockquote.php | 36 + .../classes/Text/Wiki/Render/Latex/Bold.php | 28 + system/classes/Text/Wiki/Render/Latex/Box.php | 54 + .../classes/Text/Wiki/Render/Latex/Break.php | 24 + .../classes/Text/Wiki/Render/Latex/Center.php | 33 + .../classes/Text/Wiki/Render/Latex/Code.php | 26 + .../Text/Wiki/Render/Latex/Colortext.php | 58 + .../Text/Wiki/Render/Latex/Deflist.php | 53 + .../Text/Wiki/Render/Latex/Delimiter.php | 25 + .../classes/Text/Wiki/Render/Latex/Embed.php | 23 + .../Text/Wiki/Render/Latex/Emphasis.php | 29 + .../classes/Text/Wiki/Render/Latex/Font.php | 73 ++ .../Text/Wiki/Render/Latex/Freelink.php | 6 + .../Text/Wiki/Render/Latex/Function.php | 23 + .../Text/Wiki/Render/Latex/Heading.php | 33 + .../classes/Text/Wiki/Render/Latex/Horiz.php | 23 + .../classes/Text/Wiki/Render/Latex/Html.php | 25 + .../classes/Text/Wiki/Render/Latex/Image.php | 70 ++ .../Text/Wiki/Render/Latex/Include.php | 8 + .../Text/Wiki/Render/Latex/Interwiki.php | 58 + .../classes/Text/Wiki/Render/Latex/Italic.php | 28 + .../classes/Text/Wiki/Render/Latex/List.php | 76 ++ .../Text/Wiki/Render/Latex/Newline.php | 12 + .../classes/Text/Wiki/Render/Latex/Page.php | 48 + .../Text/Wiki/Render/Latex/Paragraph.php | 31 + .../Text/Wiki/Render/Latex/Phplookup.php | 34 + .../classes/Text/Wiki/Render/Latex/Plugin.php | 49 + .../Text/Wiki/Render/Latex/Prefilter.php | 56 + .../Text/Wiki/Render/Latex/Preformatted.php | 48 + system/classes/Text/Wiki/Render/Latex/Raw.php | 23 + .../classes/Text/Wiki/Render/Latex/Revise.php | 38 + .../classes/Text/Wiki/Render/Latex/Smiley.php | 44 + .../Text/Wiki/Render/Latex/Specialchar.php | 54 + .../classes/Text/Wiki/Render/Latex/Strong.php | 30 + .../Text/Wiki/Render/Latex/Subscript.php | 54 + .../Text/Wiki/Render/Latex/Superscript.php | 31 + .../classes/Text/Wiki/Render/Latex/Table.php | 99 ++ .../Text/Wiki/Render/Latex/Tighten.php | 9 + .../Text/Wiki/Render/Latex/Titlebar.php | 54 + system/classes/Text/Wiki/Render/Latex/Toc.php | 30 + system/classes/Text/Wiki/Render/Latex/Tt.php | 30 + .../Text/Wiki/Render/Latex/Underline.php | 30 + system/classes/Text/Wiki/Render/Latex/Url.php | 41 + .../Text/Wiki/Render/Latex/Wikilink.php | 60 + system/classes/Text/Wiki/Render/Plain.php | 16 + .../classes/Text/Wiki/Render/Plain/Anchor.php | 23 + .../Text/Wiki/Render/Plain/Blockquote.php | 39 + .../classes/Text/Wiki/Render/Plain/Bold.php | 23 + system/classes/Text/Wiki/Render/Plain/Box.php | 48 + .../classes/Text/Wiki/Render/Plain/Break.php | 24 + .../classes/Text/Wiki/Render/Plain/Center.php | 23 + .../classes/Text/Wiki/Render/Plain/Code.php | 24 + .../Text/Wiki/Render/Plain/Colortext.php | 23 + .../Text/Wiki/Render/Plain/Deflist.php | 59 + .../Text/Wiki/Render/Plain/Delimiter.php | 23 + .../classes/Text/Wiki/Render/Plain/Embed.php | 23 + .../Text/Wiki/Render/Plain/Emphasis.php | 23 + .../classes/Text/Wiki/Render/Plain/Font.php | 44 + .../Text/Wiki/Render/Plain/Freelink.php | 23 + .../Text/Wiki/Render/Plain/Function.php | 39 + .../Text/Wiki/Render/Plain/Heading.php | 14 + .../classes/Text/Wiki/Render/Plain/Horiz.php | 23 + .../classes/Text/Wiki/Render/Plain/Html.php | 24 + .../classes/Text/Wiki/Render/Plain/Image.php | 22 + .../Text/Wiki/Render/Plain/Include.php | 8 + .../Text/Wiki/Render/Plain/Interwiki.php | 29 + .../classes/Text/Wiki/Render/Plain/Italic.php | 23 + .../classes/Text/Wiki/Render/Plain/List.php | 68 ++ .../Text/Wiki/Render/Plain/Newline.php | 12 + .../classes/Text/Wiki/Render/Plain/Page.php | 48 + .../Text/Wiki/Render/Plain/Paragraph.php | 31 + .../Text/Wiki/Render/Plain/Phplookup.php | 25 + .../classes/Text/Wiki/Render/Plain/Plugin.php | 49 + .../Text/Wiki/Render/Plain/Prefilter.php | 24 + .../Text/Wiki/Render/Plain/Preformatted.php | 48 + system/classes/Text/Wiki/Render/Plain/Raw.php | 23 + .../classes/Text/Wiki/Render/Plain/Revise.php | 24 + .../classes/Text/Wiki/Render/Plain/Smiley.php | 44 + .../Text/Wiki/Render/Plain/Specialchar.php | 54 + .../classes/Text/Wiki/Render/Plain/Strong.php | 24 + .../Text/Wiki/Render/Plain/Subscript.php | 48 + .../Text/Wiki/Render/Plain/Superscript.php | 23 + .../classes/Text/Wiki/Render/Plain/Table.php | 65 ++ .../Text/Wiki/Render/Plain/Tighten.php | 10 + .../Text/Wiki/Render/Plain/Titlebar.php | 54 + system/classes/Text/Wiki/Render/Plain/Toc.php | 39 + system/classes/Text/Wiki/Render/Plain/Tt.php | 24 + .../Text/Wiki/Render/Plain/Underline.php | 23 + system/classes/Text/Wiki/Render/Plain/Url.php | 29 + .../Text/Wiki/Render/Plain/Wikilink.php | 24 + system/classes/Text/Wiki/Render/Xhtml.php | 96 ++ .../Text/Wiki/Render/Xhtml/Address.php | 43 + .../classes/Text/Wiki/Render/Xhtml/Anchor.php | 52 + .../Text/Wiki/Render/Xhtml/Blockquote.php | 69 ++ .../classes/Text/Wiki/Render/Xhtml/Bold.php | 54 + system/classes/Text/Wiki/Render/Xhtml/Box.php | 58 + .../classes/Text/Wiki/Render/Xhtml/Break.php | 46 + .../classes/Text/Wiki/Render/Xhtml/Center.php | 57 + .../classes/Text/Wiki/Render/Xhtml/Code.php | 123 ++ .../Text/Wiki/Render/Xhtml/Colortext.php | 74 ++ .../Text/Wiki/Render/Xhtml/Deflist.php | 82 ++ .../Text/Wiki/Render/Xhtml/Delimiter.php | 40 + .../classes/Text/Wiki/Render/Xhtml/Embed.php | 40 + .../Text/Wiki/Render/Xhtml/Emphasis.php | 54 + .../classes/Text/Wiki/Render/Xhtml/Font.php | 83 ++ .../Text/Wiki/Render/Xhtml/Freelink.php | 32 + .../Text/Wiki/Render/Xhtml/Function.php | 109 ++ .../Text/Wiki/Render/Xhtml/Heading.php | 96 ++ .../classes/Text/Wiki/Render/Xhtml/Horiz.php | 46 + .../classes/Text/Wiki/Render/Xhtml/Html.php | 40 + .../classes/Text/Wiki/Render/Xhtml/Image.php | 174 +++ .../Text/Wiki/Render/Xhtml/Include.php | 33 + .../Text/Wiki/Render/Xhtml/Interwiki.php | 97 ++ .../classes/Text/Wiki/Render/Xhtml/Italic.php | 54 + .../classes/Text/Wiki/Render/Xhtml/List.php | 164 +++ .../Text/Wiki/Render/Xhtml/Newline.php | 33 + .../classes/Text/Wiki/Render/Xhtml/Page.php | 40 + .../Text/Wiki/Render/Xhtml/Paragraph.php | 57 + .../Text/Wiki/Render/Xhtml/Phplookup.php | 75 ++ .../classes/Text/Wiki/Render/Xhtml/Plugin.php | 41 + .../Text/Wiki/Render/Xhtml/Prefilter.php | 35 + .../Text/Wiki/Render/Xhtml/Preformatted.php | 42 + system/classes/Text/Wiki/Render/Xhtml/Raw.php | 40 + .../classes/Text/Wiki/Render/Xhtml/Revise.php | 63 + .../classes/Text/Wiki/Render/Xhtml/Smiley.php | 72 ++ .../Text/Wiki/Render/Xhtml/Specialchar.php | 53 + .../classes/Text/Wiki/Render/Xhtml/Strong.php | 54 + .../Text/Wiki/Render/Xhtml/Subscript.php | 54 + .../Text/Wiki/Render/Xhtml/Superscript.php | 54 + .../classes/Text/Wiki/Render/Xhtml/Table.php | 135 +++ .../Text/Wiki/Render/Xhtml/Tighten.php | 33 + .../Text/Wiki/Render/Xhtml/Titlebar.php | 52 + system/classes/Text/Wiki/Render/Xhtml/Toc.php | 115 ++ system/classes/Text/Wiki/Render/Xhtml/Tt.php | 54 + .../Text/Wiki/Render/Xhtml/Underline.php | 54 + system/classes/Text/Wiki/Render/Xhtml/Url.php | 127 ++ .../Text/Wiki/Render/Xhtml/Wikilink.php | 173 +++ system/classes/gltext.class.php | 4 +- 181 files changed, 11289 insertions(+), 3 deletions(-) create mode 100644 system/classes/Text/Wiki.php create mode 100644 system/classes/Text/Wiki/Parse.php create mode 100644 system/classes/Text/Wiki/Parse/Anchor.php create mode 100644 system/classes/Text/Wiki/Parse/Blockquote.php create mode 100644 system/classes/Text/Wiki/Parse/Bold.php create mode 100644 system/classes/Text/Wiki/Parse/Break.php create mode 100644 system/classes/Text/Wiki/Parse/Center.php create mode 100644 system/classes/Text/Wiki/Parse/Code.php create mode 100644 system/classes/Text/Wiki/Parse/Colortext.php create mode 100644 system/classes/Text/Wiki/Parse/Deflist.php create mode 100644 system/classes/Text/Wiki/Parse/Delimiter.php create mode 100644 system/classes/Text/Wiki/Parse/Embed.php create mode 100644 system/classes/Text/Wiki/Parse/Emphasis.php create mode 100644 system/classes/Text/Wiki/Parse/Freelink.php create mode 100644 system/classes/Text/Wiki/Parse/Function.php create mode 100644 system/classes/Text/Wiki/Parse/Heading.php create mode 100644 system/classes/Text/Wiki/Parse/Horiz.php create mode 100644 system/classes/Text/Wiki/Parse/Html.php create mode 100644 system/classes/Text/Wiki/Parse/Image.php create mode 100644 system/classes/Text/Wiki/Parse/Include.php create mode 100644 system/classes/Text/Wiki/Parse/Interwiki.php create mode 100644 system/classes/Text/Wiki/Parse/Italic.php create mode 100644 system/classes/Text/Wiki/Parse/List.php create mode 100644 system/classes/Text/Wiki/Parse/Newline.php create mode 100644 system/classes/Text/Wiki/Parse/Paragraph.php create mode 100644 system/classes/Text/Wiki/Parse/Phplookup.php create mode 100644 system/classes/Text/Wiki/Parse/Prefilter.php create mode 100644 system/classes/Text/Wiki/Parse/Raw.php create mode 100644 system/classes/Text/Wiki/Parse/Revise.php create mode 100644 system/classes/Text/Wiki/Parse/Smiley.php create mode 100644 system/classes/Text/Wiki/Parse/Strong.php create mode 100644 system/classes/Text/Wiki/Parse/Subscript.php create mode 100644 system/classes/Text/Wiki/Parse/Superscript.php create mode 100644 system/classes/Text/Wiki/Parse/Table.php create mode 100644 system/classes/Text/Wiki/Parse/Tighten.php create mode 100644 system/classes/Text/Wiki/Parse/Toc.php create mode 100644 system/classes/Text/Wiki/Parse/Tt.php create mode 100644 system/classes/Text/Wiki/Parse/Underline.php create mode 100644 system/classes/Text/Wiki/Parse/Url.php create mode 100644 system/classes/Text/Wiki/Parse/Wikilink.php create mode 100644 system/classes/Text/Wiki/Render.php create mode 100644 system/classes/Text/Wiki/Render/Latex.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Anchor.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Blockquote.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Bold.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Box.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Break.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Center.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Code.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Colortext.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Deflist.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Delimiter.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Embed.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Emphasis.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Font.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Freelink.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Function.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Heading.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Horiz.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Html.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Image.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Include.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Interwiki.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Italic.php create mode 100644 system/classes/Text/Wiki/Render/Latex/List.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Newline.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Page.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Paragraph.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Phplookup.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Plugin.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Prefilter.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Preformatted.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Raw.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Revise.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Smiley.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Specialchar.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Strong.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Subscript.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Superscript.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Table.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Tighten.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Titlebar.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Toc.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Tt.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Underline.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Url.php create mode 100644 system/classes/Text/Wiki/Render/Latex/Wikilink.php create mode 100644 system/classes/Text/Wiki/Render/Plain.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Anchor.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Blockquote.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Bold.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Box.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Break.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Center.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Code.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Colortext.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Deflist.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Delimiter.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Embed.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Emphasis.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Font.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Freelink.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Function.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Heading.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Horiz.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Html.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Image.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Include.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Interwiki.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Italic.php create mode 100644 system/classes/Text/Wiki/Render/Plain/List.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Newline.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Page.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Paragraph.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Phplookup.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Plugin.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Prefilter.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Preformatted.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Raw.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Revise.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Smiley.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Specialchar.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Strong.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Subscript.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Superscript.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Table.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Tighten.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Titlebar.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Toc.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Tt.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Underline.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Url.php create mode 100644 system/classes/Text/Wiki/Render/Plain/Wikilink.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Address.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Anchor.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Blockquote.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Bold.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Box.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Break.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Center.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Code.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Colortext.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Deflist.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Delimiter.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Embed.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Emphasis.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Font.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Freelink.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Function.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Heading.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Horiz.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Html.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Image.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Include.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Interwiki.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Italic.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/List.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Newline.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Page.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Paragraph.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Phplookup.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Plugin.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Prefilter.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Preformatted.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Raw.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Revise.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Smiley.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Specialchar.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Strong.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Subscript.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Superscript.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Table.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Tighten.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Titlebar.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Toc.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Tt.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Underline.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Url.php create mode 100644 system/classes/Text/Wiki/Render/Xhtml/Wikilink.php diff --git a/system/classes/Text/Wiki.php b/system/classes/Text/Wiki.php new file mode 100644 index 000000000..4d2787d63 --- /dev/null +++ b/system/classes/Text/Wiki.php @@ -0,0 +1,1035 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Wiki.php 248433 2007-12-17 16:03:48Z justinpatrin $ + * @link http://pear.php.net/package/Text_Wiki + */ + +require_once __DIR__ . '/Wiki/Parse.php'; +require_once __DIR__ . '/Wiki/Render.php'; + +/** + * Parse structured wiki text and render into arbitrary formats such as XHTML. + * This is the "master" class for handling the management and convenience + * functions to transform Wiki-formatted text. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: 1.2.1 + * @link http://pear.php.net/package/Text_Wiki + */ +class Wiki +{ + /** + * The default list of rules, in order, to apply to the source text. + * + * @var array + */ + public $rules = array( + 'Prefilter', + 'Delimiter', + 'Code', + 'Function', + 'Html', + 'Raw', + 'Include', + 'Embed', + 'Anchor', + 'Heading', + 'Toc', + 'Horiz', + 'Break', + 'Blockquote', + 'List', + 'Deflist', + 'Table', + 'Image', + 'Phplookup', + 'Center', + 'Newline', + 'Paragraph', + 'Url', + 'Freelink', + 'Interwiki', + 'Wikilink', + 'Colortext', + 'Strong', + 'Bold', + 'Emphasis', + 'Italic', + 'Underline', + 'Tt', + 'Superscript', + 'Subscript', + 'Revise', + 'Tighten', + ); + + /** + * The list of rules to not-apply to the source text. + * + * @var array + */ + public $disable = array( + 'Html', + 'Include', + 'Embed', + ); + + /** + * Custom configuration for rules at the parsing stage. + * In this array, the key is the parsing rule name, and the value is + * an array of key-value configuration pairs corresponding to the $conf + * property in the target parsing rule. + * For example: + * + * $parseConf = array( + * 'Include' => array( + * 'base' => '/path/to/scripts/' + * ) + * ); + * + * Note that most default rules do not need any parsing configuration. + * + * @var array + */ + public $parseConf = array(); + + /** + * Custom configuration for rules at the rendering stage. + * Because rendering may be different for each target format, the + * first-level element in this array is always a format name (e.g., + * 'Xhtml'). + * Within that first level element, the subsequent elements match the + * $parseConf format. That is, the sub-key is the rendering rule name, + * and the sub-value is an array of key-value configuration pairs + * corresponding to the $conf property in the target rendering rule. + * + * @var array + */ + public $renderConf = array( + 'Docbook' => array(), + 'Latex' => array(), + 'Pdf' => array(), + 'Plain' => array(), + 'Rtf' => array(), + 'Xhtml' => array(), + ); + + /** + * Custom configuration for the output format itself. + * Even though Text_Wiki will render the tokens from parsed text, + * the format itself may require some configuration. For example, + * RTF needs to know font names and sizes, PDF requires page layout + * information, and DocBook needs a section hierarchy. This array + * matches the $conf property of the the format-level renderer + * (e.g., Text_Wiki_Render_Xhtml). + * In this array, the key is the rendering format name, and the value is + * an array of key-value configuration pairs corresponding to the $conf + * property in the rendering format rule. + * + * @var array + */ + public $formatConf = array( + 'Docbook' => array(), + 'Latex' => array(), + 'Pdf' => array(), + 'Plain' => array(), + 'Rtf' => array(), + 'Xhtml' => array(), + ); + + /** + * The delimiter for token numbers of parsed elements in source text. + * + * @var string + */ + public $delim = "\31"; + + /** + * The tokens generated by rules as the source text is parsed. + * As Text_Wiki applies rule classes to the source text, it will + * replace portions of the text with a delimited token number. This + * is the array of those tokens, representing the replaced text and + * any options set by the parser for that replaced text. + * The tokens array is sequential; each element is itself a sequential + * array where element 0 is the name of the rule that generated the + * token, and element 1 is an associative array where the key is an + * option name and the value is an option value. + * + * @var array + */ + public $tokens = array(); + + /** + * How many tokens generated pro rules. + * Intended to load only necessary render objects + * + * @var array + */ + private $_countRulesTokens = array(); + + /** + * The source text to which rules will be applied. + * This text will be transformed in-place, which means that it will + * change as the rules are applied. + * + * @var string + */ + public $source = ''; + + /** + * The output text + * + * @var string + */ + private $output = ''; + + /** + * Array of rule parsers. + * Text_Wiki creates one instance of every rule that is applied to + * the source text; this array holds those instances. The array key + * is the rule name, and the array value is an instance of the rule + * class. + * + * @var array + */ + private $parseObj = array(); + + /** + * Array of rule renderers. + * Text_Wiki creates one instance of every rule that is applied to + * the source text; this array holds those instances. The array key + * is the rule name, and the array value is an instance of the rule + * class. + * + * @var array + */ + private $renderObj = array(); + + /** + * Array of format renderers. + * + * @var array + */ + private $formatObj = array(); + + /** + * Temporary configuration variable + * + * @var string + */ + private $renderingType = 'normal'; + + /** + * Stack of rendering callbacks + * + * @var array + */ + private $_renderCallbacks = array(); + + /** + * Current output block + * + * @var string + */ + private $_block; + + /** + * A stack of blocks + * + * @param array + */ + private $_blocks = array(); + + /** + * Constructor. + * @usage $wiki = new Wiki(); + * @usage $wiki = new Wiki('Parser', array('Prefilter', 'Delimiter', 'Code', 'Function', + * 'Html', 'Raw', 'Include', 'Embed', 'Anchor', 'Heading', 'Toc', 'Horiz', + * 'Break', 'Blockquote', 'List', 'Deflist', 'Table', 'Image', 'Phplookup', + * 'Center', 'Newline', 'Paragraph', 'Url', 'Freelink', 'Interwiki', 'Wikilink', + * 'Colortext', 'Strong', 'Bold', 'Emphasis', 'Italic', 'Underline', 'Tt', + * 'Superscript', 'Subscript', 'Revise', 'Tighten')); + * Call using a subset of this list. The order of passing rule sets in the + * $rules array is important! + * After calling this, call $single->setParseConf(), setRenderConf() or setFormatConf() + * as usual for a constructed object of this class. + * + * @param array $rules The set of rules to load for this object. Defaults + * to an empty array, which will load the default rule set for this parser. + */ + public function __construct(array $rules = array()) + { + if (count($rules) > 0) { + $this->rules = array(); + + foreach ($rules as $rule) { + $this->rules[] = ucfirst($rule); + } + } + } + + /** + * Set parser configuration for a specific rule and key. + * + * @param string $rule The parse rule to set config for. + * @param array|string $arg1 The full config array to use for the + * parse rule, or a conf key in that array. + * @param string $arg2 The config value for the key. + */ + public function setParseConf($rule, $arg1, $arg2 = null) + { + $rule = ucwords(strtolower($rule)); + + if (!isset($this->parseConf[$rule])) { + $this->parseConf[$rule] = array(); + } + + // if first arg is an array, use it as the entire + // conf array for the rule. otherwise, treat arg1 + // as a key and arg2 as a value for the rule conf. + if (is_array($arg1)) { + $this->parseConf[$rule] = $arg1; + } else { + $this->parseConf[$rule][$arg1] = $arg2; + } + } + + /** + * Get parser configuration for a specific rule and key. + * + * @param string $rule The parse rule to get config for. + * @param string $key A key in the conf array; if null, + * returns the entire conf array. + * @return mixed The whole conf array if no key is specified, + * or the specific conf key value. + */ + public function getParseConf($rule, $key = null) + { + $rule = ucwords(strtolower($rule)); + + // the rule does not exist + if (!isset($this->parseConf[$rule])) { + return null; + } + + // no key requested, return the whole array + if (is_null($key)) { + return $this->parseConf[$rule]; + } + + // does the requested key exist? + if (isset($this->parseConf[$rule][$key])) { + // yes, return that value + return $this->parseConf[$rule][$key]; + } else { + // no + return null; + } + } + + /** + * Set renderer configuration for a specific format, rule, and key. + * + * @param string $format The render format to set config for. + * @param string $rule The render rule to set config for in the format. + * @param array|string $arg1 The config array, or the config key + * within the render rule. + * @param string $arg2 The config value for the key. + */ + public function setRenderConf($format, $rule, $arg1, $arg2 = null) + { + $format = ucwords(strtolower($format)); + $rule = ucwords(strtolower($rule)); + + if (!isset($this->renderConf[$format])) { + $this->renderConf[$format] = array(); + } + + if (!isset($this->renderConf[$format][$rule])) { + $this->renderConf[$format][$rule] = array(); + } + + // if first arg is an array, use it as the entire + // conf array for the render rule. otherwise, treat arg1 + // as a key and arg2 as a value for the render rule conf. + if (is_array($arg1)) { + $this->renderConf[$format][$rule] = $arg1; + } else { + $this->renderConf[$format][$rule][$arg1] = $arg2; + } + } + + /** + * Get renderer configuration for a specific format, rule, and key. + * + * @param string $format The render format to get config for. + * @param string $rule The render format rule to get config for. + * @param string $key A key in the conf array; if null, + * returns the entire conf array. + * @return mixed The whole conf array if no key is specified, + * or the specific conf key value. + */ + public function getRenderConf($format, $rule, $key = null) + { + $format = ucwords(strtolower($format)); + $rule = ucwords(strtolower($rule)); + + if (!isset($this->renderConf[$format]) || + !isset($this->renderConf[$format][$rule]) + ) { + return null; + } + + // no key requested, return the whole array + if (is_null($key)) { + return $this->renderConf[$format][$rule]; + } + + // does the requested key exist? + if (isset($this->renderConf[$format][$rule][$key])) { + // yes, return that value + return $this->renderConf[$format][$rule][$key]; + } else { + // no + return null; + } + } + + /** + * Set format configuration for a specific rule and key. + * + * @param string $format The format to set config for. + * @param string $arg1 The config key within the format. + * @param string $arg2 The config value for the key. + */ + public function setFormatConf($format, $arg1, $arg2 = null) + { + if (!is_array($this->formatConf[$format])) { + $this->formatConf[$format] = array(); + } + + // if first arg is an array, use it as the entire + // conf array for the format. otherwise, treat arg1 + // as a key and arg2 as a value for the format conf. + if (is_array($arg1)) { + $this->formatConf[$format] = $arg1; + } else { + $this->formatConf[$format][$arg1] = $arg2; + } + } + + /** + * Get configuration for a specific format and key. + * + * @param string $format The format to get config for. + * @param mixed $key A key in the conf array; if null, + * returns the entire conf array. + * @return mixed The whole conf array if no key is specified, + * or the specific conf key value. + */ + public function getFormatConf($format, $key = null) + { + // the format does not exist + if (!isset($this->formatConf[$format])) { + return null; + } + + // no key requested, return the whole array + if (is_null($key)) { + return $this->formatConf[$format]; + } + + // does the requested key exist? + if (isset($this->formatConf[$format][$key])) { + // yes, return that value + return $this->formatConf[$format][$key]; + } else { + // no + return null; + } + } + + /** + * Inserts a rule into to the rule set. + * + * @param string $name The name of the rule. Should be different from + * all other keys in the rule set. + * @param string $tgt The rule after which to insert this new rule. By + * default (null) the rule is inserted at the end; if set to '', inserts + * at the beginning. + * @return bool|null + */ + public function insertRule($name, $tgt = null) + { + $name = ucwords(strtolower($name)); + if (!is_null($tgt)) { + $tgt = ucwords(strtolower($tgt)); + } + + // does the rule name to be inserted already exist? + if (in_array($name, $this->rules)) { + // yes, return + return null; + } + + // the target name is not null, and not '', but does not exist + // in the list of rules. this means we're trying to insert after + // a target key, but the target key isn't there. + if (!is_null($tgt) && $tgt != '' && !in_array($tgt, $this->rules)) { + return false; + } + + // if $tgt is null, insert at the end. We know this is at the + // end (instead of resetting an existing rule) becuase we exited + // at the top of this method if the rule was already in place. + if (is_null($tgt)) { + $this->rules[] = $name; + + return true; + } + + // save a copy of the current rules, then reset the rule set + // so we can insert in the proper place later. + // where to insert the rule? + if ($tgt == '') { + // insert at the beginning + array_unshift($this->rules, $name); + + return true; + } + + // insert after the named rule + $tmp = $this->rules; + $this->rules = array(); + + foreach ($tmp as $val) { + $this->rules[] = $val; + if ($val == $tgt) { + $this->rules[] = $name; + } + } + + return true; + } + + /** + * Delete (remove or unset) a rule from the $rules property. + * + * @param string $name The name of the rule to remove. + */ + public function deleteRule($name) + { + $name = ucwords(strtolower($name)); + $key = array_search($name, $this->rules); + + if ($key !== false) { + unset($this->rules[$key]); + } + } + + /** + * Change from one rule to another in-place. + * + * @param string $old The name of the rule to change from. + * @param string $new The name of the rule to change to. + */ + public function changeRule($old, $new) + { + $old = ucwords(strtolower($old)); + $new = ucwords(strtolower($new)); + $key = array_search($old, $this->rules); + + if ($key !== false) { + // delete the new name , case it was already there + $this->deleteRule($new); + $this->rules[$key] = $new; + } + } + + /** + * Enables a rule so that it is applied when parsing. + * + * @param string $name The name of the rule to enable. + */ + public function enableRule($name) + { + $name = ucwords(strtolower($name)); + $key = array_search($name, $this->disable); + + if ($key !== false) { + unset($this->disable[$key]); + } + } + + /** + * Disables a rule so that it is not applied when parsing. + * + * @param string $name The name of the rule to disable. + */ + public function disableRule($name) + { + $name = ucwords(strtolower($name)); + $key = array_search($name, $this->disable); + + if ($key === false) { + $this->disable[] = $name; + } + } + + /** + * Log an error + * + * @param string $message + */ + public function error($message) + { + if (is_callable('COM_errorLog')) { + COM_errorLog($message); + } + } + + /** + * Parses and renders the text passed to it, and returns the results. + * First, the method parses the source text, applying rules to the + * text as it goes. These rules will modify the source text + * in-place, replacing some text with delimited tokens (and + * populating the $this->tokens array as it goes). + * Next, the method renders the in-place tokens into the requested + * output format. + * Finally, the method returns the transformed text. Note that the + * source text is transformed in place; once it is transformed, it is + * no longer the same as the original source text. + * + * @param string $text The source text to which wiki rules should be + * applied, both for parsing and for rendering. + * @param string $format The target output format, typically 'xhtml'. + * If a rule does not support a given format, the output from that + * rule is rule-specific. + * @return string The transformed wiki text. + */ + public function transform($text, $format = 'Xhtml') + { + $this->parse($text); + + return $this->render($format); + } + + /** + * Sets the $_source text property, then parses it in place and + * retains tokens in the $_tokens array property. + * + * @param string $text The source text to which wiki rules should be + * applied, both for parsing and for rendering. + */ + public function parse($text) + { + // set the object property for the source text + $this->source = $text; + + // reset the tokens. + $this->tokens = array(); + $this->_countRulesTokens = array(); + + // apply the parse() method of each requested rule to the source + // text. + foreach ($this->rules as $name) { + // do not parse the rules listed in $disable + if (!in_array($name, $this->disable)) { + // load the parsing object + $this->loadParseObj($name); + + // load may have failed; only parse if + // an object is in the array now + if (is_object($this->parseObj[$name])) { + $this->parseObj[$name]->parse(); + } + } + } + } + + /** + * Renders tokens back into the source text, based on the requested format. + * + * @param string $format The target output format, typically 'xhtml'. + * If a rule does not support a given format, the output from that + * rule is rule-specific. + * @return string The transformed wiki text. + */ + public function render($format = 'Xhtml') + { + // the rendering method we're going to use from each rule + $format = ucwords(strtolower($format)); + + // the eventual output text + $this->output = ''; + + // when passing through the parsed source text, keep track of when + // we are in a delimited section + $in_delim = false; + + // when in a delimited section, capture the token key number + $key = ''; + + // load the format object, or crap out if we can't find it + $result = $this->loadFormatObj($format); + + if (!$result) { + return $this->source; + } + + // pre-rendering activity + if (is_object($this->formatObj[$format])) { + $this->output .= $this->formatObj[$format]->pre(); + } + + // load the render objects + foreach (array_keys($this->_countRulesTokens) as $rule) { + $this->loadRenderObj($format, $rule); + } + + if ($this->renderingType === 'preg') { + $this->output = preg_replace_callback( + '/' . $this->delim . '(\d+)' . $this->delim . '/', + array($this, '_renderToken'), + $this->source); + /* +//Damn strtok()! Why does it "skip" empty parts of the string. It's useless now! + } elseif ($this->renderingType == 'strtok') { + echo '
'.htmlentities($this->source).'
'; + $t = strtok($this->source, $this->delim); + $inToken = true; + $i = 0; + while ($t !== false) { + echo 'Token: '.$i.'
"'.htmlentities($t).'"


'; + if ($inToken) { + //$this->output .= $this->renderObj[$this->tokens[$t][0]]->token($this->tokens[$t][1]); + } else { + $this->output .= $t; + } + $inToken = !$inToken; + $t = strtok($this->delim); + ++$i; + } + */ + } else { + // pass through the parsed source text character by character + $this->_block = ''; + $tokenStack = array(); + $k = strlen($this->source); + + for ($i = 0; $i < $k; $i++) { + // the current character + $char = $this->source{$i}; + + // are already in a delimited section? + if ($in_delim) { + // yes; are we ending the section? + if ($char == $this->delim) { + if (count($this->_renderCallbacks) === 0) { + $this->output .= $this->_block; + $this->_block = ''; + } + + if (isset($opts['type'])) { + if ($opts['type'] === 'start') { + array_push($tokenStack, $rule); + } elseif ($opts['type'] === 'end') { + if ($tokenStack[count($tokenStack) - 1] != $rule) { + return $this->error('Unbalanced tokens, check your syntax'); + } else { + array_pop($tokenStack); + } + } + } + + // yes, get the replacement text for the delimited + // token number and unset the flag. + $key = (int) $key; + $rule = $this->tokens[$key][0]; + $opts = $this->tokens[$key][1]; + $this->_block .= $this->renderObj[$rule]->token($opts); + $in_delim = false; + } else { + // no, add to the delimited token key number + $key .= $char; + } + } else { + // not currently in a delimited section. + // are we starting into a delimited section? + if ($char == $this->delim) { + // yes, reset the previous key and + // set the flag. + $key = ''; + $in_delim = true; + } else { + // no, add to the output as-is + $this->_block .= $char; + } + } + } + } + + if (count($this->_renderCallbacks)) { + return $this->error('Render callbacks left over after processing finished'); + } + /* + while (count($this->_renderCallbacks)) { + $this->popRenderCallback(); + } + */ + if (strlen($this->_block)) { + $this->output .= $this->_block; + $this->_block = ''; + } + + // post-rendering activity + if (is_object($this->formatObj[$format])) { + $this->output .= $this->formatObj[$format]->post(); + } + + // return the rendered source text. + return $this->output; + } + + /** + * Renders a token, for use only as an internal callback + * + * @param array $matches from preg_rpelace_callback, [1] is the token number + * @return string The rendered text for the token + */ + private function _renderToken($matches) + { + return $this->renderObj[$this->tokens[$matches[1]][0]]->token($this->tokens[$matches[1]][1]); + } + + public function registerRenderCallback($callback) + { + $this->_blocks[] = $this->_block; + $this->_block = ''; + $this->_renderCallbacks[] = $callback; + } + + public function popRenderCallback() + { + if (count($this->_renderCallbacks) == 0) { + $this->error('Render callback popped when no render callbacks in stack'); + } else { + $callback = array_pop($this->_renderCallbacks); + $this->_block = call_user_func($callback, $this->_block); + + if (count($this->_blocks)) { + $parentBlock = array_pop($this->_blocks); + $this->_block = $parentBlock . $this->_block; + } + if (count($this->_renderCallbacks) == 0) { + $this->output .= $this->_block; + $this->_block = ''; + } + } + } + + /** + * Returns the parsed source text with delimited token placeholders. + * + * @return string The parsed source text. + */ + public function getSource() + { + return $this->source; + } + + /** + * Returns tokens that have been parsed out of the source text. + * + * @param array $rules If an array of rule names is passed, only return + * tokens matching these rule names. If no array is passed, return all + * tokens. + * @return array An array of tokens. + */ + public function getTokens(array $rules = array()) + { + if (count($rules) === 0) { + return $this->tokens; + } else { + $result = array(); + + foreach ($this->tokens as $key => $val) { + if (in_array($val[0], $rules)) { + $result[$key] = $val; + } + } + + return $result; + } + } + + /** + * Add a token to the Text_Wiki tokens array, and return a delimited + * token number. + * + * @param string $rule + * @param array $options An associative array of options for the new + * token array element. The keys and values are specific to the + * rule, and may or may not be common to other rule options. Typical + * options keys are 'text' and 'type' but may include others. + * @param boolean $id_only If true, return only the token number, not + * a delimited token string. + * @return string|int By default, return the number of the + * newly-created token array element with a delimiter prefix and + * suffix; however, if $id_only is set to true, return only the token + * number (no delimiters). + */ + public function addToken($rule, array $options = array(), $id_only = false) + { + // increment the token ID number. note that if you parse + // multiple times with the same Text_Wiki object, the ID number + // will not reset to zero. + static $id; + + if (!isset($id)) { + $id = 0; + } else { + $id++; + } + + // add the token + $this->tokens[$id] = array( + 0 => $rule, + 1 => $options, + ); + + if (!isset($this->_countRulesTokens[$rule])) { + $this->_countRulesTokens[$rule] = 1; + } else { + ++$this->_countRulesTokens[$rule]; + } + + // return a value + if ($id_only) { + // return the last token number + return $id; + } else { + // return the token number with delimiters + return $this->delim . $id . $this->delim; + } + } + + /** + * Set or re-set a token with specific information, overwriting any + * previous rule name and rule options. + * + * @param int $id The token number to reset. + * @param int $rule The rule name to use. + * @param array $options An associative array of options for the + * token array element. The keys and values are specific to the + * rule, and may or may not be common to other rule options. Typical + * options keys are 'text' and 'type' but may include others. + */ + public function setToken($id, $rule, $options = array()) + { + $oldRule = $this->tokens[$id][0]; + + // reset the token + $this->tokens[$id] = array( + 0 => $rule, + 1 => $options, + ); + + if ($rule != $oldRule) { + if (!($this->_countRulesTokens[$oldRule]--)) { + unset($this->_countRulesTokens[$oldRule]); + } + if (!isset($this->_countRulesTokens[$rule])) { + $this->_countRulesTokens[$rule] = 1; + } else { + ++$this->_countRulesTokens[$rule]; + } + } + } + + /** + * Load a rule parser class file. + * + * @param string $rule + */ + public function loadParseObj($rule) + { + $rule = ucwords(strtolower($rule)); + $file = __DIR__ . '/Wiki/Parse/' . $rule . '.php'; + $class = __NAMESPACE__ . "\\Wiki\\Text_Wiki_Parse_{$rule}"; + + if (file_exists($file)) { + // found the class + include_once $file; + $this->parseObj[$rule] = new $class($this); + } else { + // can't find the class + $this->parseObj[$rule] = null; + + // can't find the class + $this->error("Parse rule '{$rule}' not found"); + } + } + + /** + * Load a rule-render class file. + * + * @param string $format + * @param string $rule + */ + public function loadRenderObj($format, $rule) + { + $format = ucwords(strtolower($format)); + $rule = ucwords(strtolower($rule)); + $file = __DIR__ . '/Wiki/Render/' . $format . '/' . $rule . '.php'; + $class = __NAMESPACE__ . "\\Wiki\\Text_Wiki_Render_{$format}_{$rule}"; + + if (file_exists($file)) { + // found the class + include_once $file; + $this->renderObj[$rule] = new $class($this); + } else { + // can't find the class + $this->error("Render rule '{$rule}' in format '{$format}' not found"); + } + } + + /** + * Load a format-render class file. + * + * @param string $format + * @return bool + */ + public function loadFormatObj($format) + { + $format = ucwords(strtolower($format)); + $file = __DIR__ . '/Wiki/Render/' . $format . '.php'; + $class = __NAMESPACE__ . "\\Wiki\\Text_Wiki_Render_{$format}"; + + if (file_exists($file)) { + // found the class + include_once $file; + $this->formatObj[$format] = new $class($this); + + return true; + } else { + // can't find the class + $this->error("Rendering format class '{$class}' not found"); + + return false; + } + } +} diff --git a/system/classes/Text/Wiki/Parse.php b/system/classes/Text/Wiki/Parse.php new file mode 100644 index 000000000..6da3c061a --- /dev/null +++ b/system/classes/Text/Wiki/Parse.php @@ -0,0 +1,195 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Parse.php 191781 2005-07-29 08:57:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * Baseline rule class for extension into a "real" parser component. + * Text_Wiki_Rule classes do not stand on their own; they are called by a + * Text_Wiki object, typcially in the transform() method. Each rule class + * performs three main activities: parse, process, and render. + * The parse() method takes a regex and applies it to the whole block of + * source text at one time. Each match is sent as $matches to the + * process() method. + * The process() method acts on the matched text from the source, and + * then processes the source text is some way. This may mean the + * creation of a delimited token using addToken(). In every case, the + * process() method returns the text that should replace the matched text + * from parse(). + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Parse +{ + /** + * Configuration options for this parser rule. + * + * @var string + */ + public $conf = array(); + + /** + * Regular expression to find matching text for this rule. + * + * @var string + * @see parse() + */ + public $regex = null; + + /** + * The name of this rule for new token array elements. + * + * @var string + */ + public $rule = null; + + /** + * A reference to the calling Text_Wiki object. + * This is needed so that each rule has access to the same source + * text, token set, URLs, interwiki maps, page names, etc. + * + * @var object + */ + public $wiki = null; + + /** + * Constructor for this parser rule. + * + * @param Wiki $obj The calling "parent" Text_Wiki object. + */ + public function __construct(Wiki $obj) + { + // set the reference to the calling Text_Wiki object; + // this allows us access to the shared source text, token + // array, etc. + $this->wiki = $obj; + + // set the name of this rule; generally used when adding + // to the tokens array. strip off the Text_Wiki_Parse_ portion. + $tmp = str_ireplace('Geeklog\\Text\\Wiki\\Text_Wiki_Parse_', '', get_class($this)); + $this->rule = ucwords(strtolower($tmp)); + + // override config options for the rule if specified + if (isset($this->wiki->parseConf[$this->rule]) && + is_array($this->wiki->parseConf[$this->rule]) + ) { + $this->conf = array_merge( + $this->conf, + $this->wiki->parseConf[$this->rule] + ); + } + } + + /** + * Abstrct method to parse source text for matches. + * Applies the rule's regular expression to the source text, passes + * every match to the process() method, and replaces the matched text + * with the results of the processing. + * + * @see Text_Wiki_Parse::process() + */ + public function parse() + { + $this->wiki->source = preg_replace_callback( + $this->regex, + array($this, 'process'), + $this->wiki->source + ); + } + + /** + * Abstract method to generate replacements for matched text. + * + * @param array $matches An array of matches from the parse() method + * as generated by preg_replace_callback. $matches[0] is the full + * matched string, $matches[1] is the first matched pattern, + * $matches[2] is the second matched pattern, and so on. + * @return string The processed text replacement; defaults to the + * full matched string (i.e., no changes to the text). + * @see Text_Wiki_Parse::parse() + */ + public function process(&$matches) + { + return $matches[0]; + } + + /** + * Simple method to safely get configuration key values. + * + * @param string $key The configuration key. + * @param mixed $default If the key does not exist, return this value + * instead. + * @return mixed The configuration key value (if it exists) or the + * default value (if not). + */ + public function getConf($key, $default = null) + { + if (isset($this->conf[$key])) { + return $this->conf[$key]; + } else { + return $default; + } + } + + /** + * Extract 'attribute="value"' portions of wiki markup. + * This kind of markup is typically used only in macros, but is useful + * anywhere. + * The syntax is pretty strict; there can be no spaces between the + * option name, the equals, and the first double-quote; the value + * must be surrounded by double-quotes. You can escape characters in + * the value with a backslash, and the backslash will be stripped for + * you. + * + * @param string $text The "attributes" portion of markup. + * @return array An associative array of key-value pairs where the + * key is the option name and the value is the option value. + */ + public function getAttrs($text) + { + // find the =" sections; + $tmp = explode('="', trim($text)); + + // basic setup + $k = count($tmp) - 1; + $attrs = array(); + $key = null; + + // loop through the sections + foreach ($tmp as $i => $val) { + // first element is always the first key + if ($i == 0) { + $key = trim($val); + continue; + } + + // find the last double-quote in the value. + // the part to the left is the value for the last key, + // the part to the right is the next key name + $pos = strrpos($val, '"'); + $attrs[$key] = stripslashes(substr($val, 0, $pos)); + $key = trim(substr($val, $pos + 1)); + + } + + return $attrs; + } +} diff --git a/system/classes/Text/Wiki/Parse/Anchor.php b/system/classes/Text/Wiki/Parse/Anchor.php new file mode 100644 index 000000000..207573f52 --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Anchor.php @@ -0,0 +1,60 @@ + + * @author Paul M. Jones + * @license LGPL + * @version $Id: Anchor.php 180591 2005-02-23 17:38:29Z pmjones $ + */ + +/** + * This class implements a Text_Wiki_Parse to add an anchor target name + * in the wiki page. + * + * @author Manuel Holtgrewe + * @author Paul M. Jones + * @category Text + * @package Text_Wiki + */ +class Text_Wiki_Parse_Anchor extends Text_Wiki_Parse +{ + /** + * The regular expression used to find source text matching this + * rule. Looks like a macro: [[# anchor_name]] + * + * @var string + */ + public $regex = '/(\[\[# )([-_A-Za-z0-9.]+?)( .+)?(\]\])/i'; + + /** + * Generates a token entry for the matched text. Token options are: + * 'text' => The full matched text, not including the tags. + * + * @param array &$matches The array of matches from parse(). + * @return string A delimited token number to be used as a placeholder in the source text. + */ + public function process(&$matches) + { + $name = $matches[2]; + $text = $matches[3]; + + $start = $this->wiki->addToken( + $this->rule, + array('type' => 'start', 'name' => $name) + ); + + $end = $this->wiki->addToken( + $this->rule, + array('type' => 'end', 'name' => $name) + ); + + // done, place the script output directly in the source + return $start . trim($text) . $end; + } +} diff --git a/system/classes/Text/Wiki/Parse/Blockquote.php b/system/classes/Text/Wiki/Parse/Blockquote.php new file mode 100644 index 000000000..0cdceeda0 --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Blockquote.php @@ -0,0 +1,151 @@ + + * @license LGPL + * @version $Id: Blockquote.php 222150 2006-10-21 05:56:28Z justinpatrin $ + */ + +/** + * Parse for block-quoted text. + * Find source text marked as a blockquote, identified by any number of + * greater-than signs '>' at the start of the line, followed by a space, + * and then the quote text; each '>' indicates an additional level of + * quoting. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + */ +class Text_Wiki_Parse_Blockquote extends Text_Wiki_Parse +{ + /** + * Regex for parsing the source text. + * + * @var string + * @see parse() + */ + public $regex = '/\n((\>).*\n)(?!(\>))/Us'; + + /** + * Generates a replacement for the matched text. + * Token options are: + * 'type' => + * 'start' : the start of a blockquote + * 'end' : the end of a blockquote + * 'level' => the indent level (0 for the first level, 1 for the + * second, etc) + * + * @param array &$matches The array of matches from parse(). + * @return string A series of text and delimited tokens marking the different + * list text and list elements. + */ + + public function process(&$matches) + { + // the replacement text we will return to parse() + $return = "\n"; + + // the list of post-processing matches + $list = array(); + + // $matches[1] is the text matched as a list set by parse(); + // create an array called $list that contains a new set of + // matches for the various list-item elements. + preg_match_all( + '=^(\>+) (.*\n)=Ums', + $matches[1], + $list, + PREG_SET_ORDER + ); + + $curLevel = 0; + + // loop through each list-item element. + foreach ($list as $key => $val) { + // $val[0] is the full matched list-item line + // $val[1] is the number of initial '>' chars (indent level) + // $val[2] is the quote text + + // we number levels starting at 1, not zero + $level = strlen($val[1]); + + // add a level to the list? + while ($level > $curLevel) { + // the current indent level is greater than the number + // of stack elements, so we must be starting a new + // level. push the new level onto the stack with a + // dummy value (boolean true)... + ++$curLevel; + + //$return .= "\n"; + + // ...and add a start token to the return. + $return .= $this->wiki->addToken( + $this->rule, + array( + 'type' => 'start', + 'level' => $curLevel, + ) + ); + + //$return .= "\n\n"; + } + + // remove a level? + while ($curLevel > $level) { + // as long as the stack count is greater than the + // current indent level, we need to end list types. + // continue adding end-list tokens until the stack count + // and the indent level are the same. + + //$return .= "\n\n"; + + $return .= $this->wiki->addToken( + $this->rule, + array( + 'type' => 'end', + 'level' => $curLevel, + ) + ); + + //$return .= "\n"; + --$curLevel; + } + + // add the line text. + $return .= $val[2]; + } + + // the last char of the matched pattern must be \n but we don't + // want this to be inside the tokens + $return = substr($return, 0, -1); + + // the last line may have been indented. go through the stack + // and create end-tokens until the stack is empty. + //$return .= "\n"; + + while ($curLevel > 0) { + $return .= $this->wiki->addToken( + $this->rule, + array( + 'type' => 'end', + 'level' => $curLevel, + ) + ); + --$curLevel; + } + + // put back the trailing \n + $return .= "\n"; + + // we're done! send back the replacement text. + return $return; + } +} diff --git a/system/classes/Text/Wiki/Parse/Bold.php b/system/classes/Text/Wiki/Parse/Bold.php new file mode 100644 index 000000000..83790f12a --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Bold.php @@ -0,0 +1,54 @@ + + * @license LGPL + * @version $Id: Bold.php 180591 2005-02-23 17:38:29Z pmjones $ + */ + +/** + * Parses for bold text. + * This class implements a Text_Wiki_Rule to find source text marked for + * strong emphasis (bold) as defined by text surrounded by three + * single-quotes. On parsing, the text itself is left in place, but the + * starting and ending instances of three single-quotes are replaced with + * tokens. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + */ +class Text_Wiki_Parse_Bold extends Text_Wiki_Parse +{ + /** + * The regular expression used to parse the source text and find + * matches conforming to this rule. Used by the parse() method. + * + * @var string + * @see parse() + */ + public $regex = "/'''(()|[^'].*)'''/U"; + + /** + * Generates a replacement for the matched text. Token options are: + * 'type' => ['start'|'end'] The starting or ending point of the + * emphasized text. The text itself is left in the source. + * + * @param array &$matches The array of matches from parse(). + * @return string A pair of delimited tokens to be used as a placeholder in + * the source text surrounding the text to be emphasized. + */ + public function process(&$matches) + { + $start = $this->wiki->addToken($this->rule, array('type' => 'start')); + $end = $this->wiki->addToken($this->rule, array('type' => 'end')); + + return $start . $matches[1] . $end; + } +} diff --git a/system/classes/Text/Wiki/Parse/Break.php b/system/classes/Text/Wiki/Parse/Break.php new file mode 100644 index 000000000..4a9715950 --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Break.php @@ -0,0 +1,46 @@ + + * @license LGPL + * @version $Id: Break.php 180591 2005-02-23 17:38:29Z pmjones $ + */ + +/** + * Parses for explicit line breaks. + * This class implements a Text_Wiki_Parse to mark forced line breaks in the + * source text. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + */ +class Text_Wiki_Parse_Break extends Text_Wiki_Parse +{ + /** + * The regular expression used to parse the source text and find + * matches conforming to this rule. Used by the parse() method. + * + * @var string + * @see parse() + */ + public $regex = '/ _\n/'; + + /** + * Generates a replacement token for the matched text. + * + * @param array &$matches The array of matches from parse(). + * @return string A delimited token to be used as a placeholder in + * the source text. + */ + public function process(&$matches) + { + return $this->wiki->addToken($this->rule); + } +} diff --git a/system/classes/Text/Wiki/Parse/Center.php b/system/classes/Text/Wiki/Parse/Center.php new file mode 100644 index 000000000..cb453a3a3 --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Center.php @@ -0,0 +1,55 @@ + + * @license LGPL + * @version $Id: Center.php 180591 2005-02-23 17:38:29Z pmjones $ + */ + +/** + * Parses for centered lines of text. + * This class implements a Text_Wiki_Parse to find lines marked for centering. + * The line must start with "= " (i.e., an equal-sign followed by a space). + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + */ +class Text_Wiki_Parse_Center extends Text_Wiki_Parse +{ + /** + * The regular expression used to find source text matching this + * rule. + * + * @var string + */ + public $regex = '/\n\= (.*?)\n/'; + + /** + * Generates a token entry for the matched text. + * + * @param array &$matches The array of matches from parse(). + * @return string A delimited token number to be used as a placeholder in + * the source text. + */ + public function process(&$matches) + { + $start = $this->wiki->addToken( + $this->rule, + array('type' => 'start') + ); + + $end = $this->wiki->addToken( + $this->rule, + array('type' => 'end') + ); + + return "\n" . $start . $matches[1] . $end . "\n"; + } +} diff --git a/system/classes/Text/Wiki/Parse/Code.php b/system/classes/Text/Wiki/Parse/Code.php new file mode 100644 index 000000000..d1a3b0a20 --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Code.php @@ -0,0 +1,75 @@ + + * @license LGPL + * @version $Id: Code.php 237313 2007-06-09 23:11:25Z justinpatrin $ + */ + +/** + * Parses for text marked as a code example block. + * This class implements a Text_Wiki_Parse to find sections marked as code + * examples. Blocks are marked as the string on a line by itself, + * followed by the inline code example, and terminated with the string + * on a line by itself. The code example is run through the + * native PHP highlight_string() function to colorize it, then surrounded + * with
...
tags when rendered as XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + */ +class Text_Wiki_Parse_Code extends Text_Wiki_Parse +{ + /** + * The regular expression used to find source text matching this + * rule. + * + * @var string + */ + /* var $regex = '/^(\)\n(.+)\n(\<\/code\>)(\s|$)/Umsi';*/ + public $regex = ';^]*)?>((?:(?R)|.*?)*)\n(\s|$);msi'; + + /** + * Generates a token entry for the matched text. Token options are: + * 'text' => The full matched text, not including the tags. + * + * @param array &$matches The array of matches from parse(). + * @return string A delimited token number to be used as a placeholder in + * the source text. + */ + public function process(&$matches) + { + // are there additional attribute arguments? + $args = trim($matches[1]); + + if ($args == '') { + $options = array( + 'text' => $matches[2], + 'attr' => array('type' => ''), + ); + } else { + // get the attributes... + $attr = $this->getAttrs($args); + + // ... and make sure we have a 'type' + if (!isset($attr['type'])) { + $attr['type'] = ''; + } + + // retain the options + $options = array( + 'text' => $matches[2], + 'attr' => $attr, + ); + } + + return $this->wiki->addToken($this->rule, $options) . $matches[3]; + } +} diff --git a/system/classes/Text/Wiki/Parse/Colortext.php b/system/classes/Text/Wiki/Parse/Colortext.php new file mode 100644 index 000000000..14e9524a0 --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Colortext.php @@ -0,0 +1,64 @@ + + * @license LGPL + * @version $Id: Colortext.php 180591 2005-02-23 17:38:29Z pmjones $ + */ + +/** + * Parses for colorized text. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + */ +class Text_Wiki_Parse_Colortext extends Text_Wiki_Parse +{ + /** + * The regular expression used to parse the source text and find + * matches conforming to this rule. Used by the parse() method. + * + * @var string + * @see parse() + */ + public $regex = "/\#\#(.+?)\|(.+?)\#\#/"; + + /** + * Generates a replacement for the matched text. Token options are: + * 'type' => ['start'|'end'] The starting or ending point of the + * emphasized text. The text itself is left in the source. + * 'color' => the color indicator + * + * @param array &$matches The array of matches from parse(). + * @return string A pair of delimited tokens to be used as a + * placeholder in the source text surrounding the text to be + * emphasized. + */ + public function process(&$matches) + { + $start = $this->wiki->addToken( + $this->rule, + array( + 'type' => 'start', + 'color' => $matches[1], + ) + ); + + $end = $this->wiki->addToken( + $this->rule, + array( + 'type' => 'end', + 'color' => $matches[1], + ) + ); + + return $start . $matches[2] . $end; + } +} diff --git a/system/classes/Text/Wiki/Parse/Deflist.php b/system/classes/Text/Wiki/Parse/Deflist.php new file mode 100644 index 000000000..06b9bba1f --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Deflist.php @@ -0,0 +1,96 @@ + + * @license LGPL + * @version $Id: Deflist.php 180591 2005-02-23 17:38:29Z pmjones $ + */ + +/** + * Parses for definition lists. + * This class implements a Text_Wiki_Parse to find source text marked as a + * definition list. In short, if a line starts with ':' then it is a + * definition list item; another ':' on the same line indicates the end + * of the definition term and the beginning of the definition narrative. + * The list items must be on sequential lines (no blank lines between + * them) -- a blank line indicates the beginning of a new list. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + */ +class Text_Wiki_Parse_Deflist extends Text_Wiki_Parse +{ + /** + * The regular expression used to parse the source text and find + * matches conforming to this rule. Used by the parse() method. + * + * @var string + * @see parse() + */ + public $regex = '/\n((: ).*\n)(?!(: |\n))/Us'; + + /** + * Generates a replacement for the matched text. Token options are: + * 'type' => + * 'list_start' : the start of a definition list + * 'list_end' : the end of a definition list + * 'term_start' : the start of a definition term + * 'term_end' : the end of a definition term + * 'narr_start' : the start of definition narrative + * 'narr_end' : the end of definition narrative + * 'unknown' : unknown type of definition portion + * + * @param array &$matches The array of matches from parse(). + * @return string A series of text and delimited tokens marking the different + * list text and list elements. + */ + public function process(&$matches) + { + // the replacement text we will return to parse() + $return = ''; + + // the list of post-processing matches + $list = array(); + + // start the deflist + $options = array('type' => 'list_start'); + $return .= $this->wiki->addToken($this->rule, $options); + + // $matches[1] is the text matched as a list set by parse(); + // create an array called $list that contains a new set of + // matches for the various definition-list elements. + preg_match_all( + '/^(: )(.*)?( : )(.*)?$/Ums', + $matches[1], + $list, + PREG_SET_ORDER + ); + + // add each term and narrative + foreach ($list as $key => $val) { + $return .= ( + $this->wiki->addToken($this->rule, array('type' => 'term_start')) . + trim($val[2]) . + $this->wiki->addToken($this->rule, array('type' => 'term_end')) . + $this->wiki->addToken($this->rule, array('type' => 'narr_start')) . + trim($val[4]) . + $this->wiki->addToken($this->rule, array('type' => 'narr_end')) + ); + } + + + // end the deflist + $options = array('type' => 'list_end'); + $return .= $this->wiki->addToken($this->rule, $options); + + // done! + return "\n" . $return . "\n\n"; + } +} diff --git a/system/classes/Text/Wiki/Parse/Delimiter.php b/system/classes/Text/Wiki/Parse/Delimiter.php new file mode 100644 index 000000000..0b6a98e18 --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Delimiter.php @@ -0,0 +1,58 @@ + + * @license LGPL + * @version $Id: Delimiter.php 180591 2005-02-23 17:38:29Z pmjones $ + */ + +use Geeklog\Text\Wiki; + +/** + * Parses for Text_Wiki delimiter characters already in the source text. + * This class implements a Text_Wiki_Parse to find instances of the delimiter + * character already embedded in the source text; it extracts them and replaces + * them with a delimited token, then renders them as the delimiter itself + * when the target format is XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + */ +class Text_Wiki_Parse_Delimiter extends Text_Wiki_Parse +{ + /** + * Constructor. Overrides the Text_Wiki_Parse constructor so that we + * can set the $regex property dynamically (we need to include the + * Text_Wiki $delim character. + * + * @param Wiki &$obj The calling "parent" Text_Wiki object. + */ + public function __construct($obj) + { + parent::__construct($obj); + $this->regex = '/' . $this->wiki->delim . '/'; + } + + /** + * Generates a token entry for the matched text. Token options are: + * 'text' => The full matched text. + * + * @param array &$matches The array of matches from parse(). + * @return string A delimited token number to be used as a placeholder in + * the source text. + */ + public function process(&$matches) + { + return $this->wiki->addToken( + $this->rule, + array('text' => $this->wiki->delim) + ); + } +} diff --git a/system/classes/Text/Wiki/Parse/Embed.php b/system/classes/Text/Wiki/Parse/Embed.php new file mode 100644 index 000000000..0cc427a39 --- /dev/null +++ b/system/classes/Text/Wiki/Parse/Embed.php @@ -0,0 +1,79 @@ + + * @license LGPL + * @version $Id: Embed.php 180591 2005-02-23 17:38:29Z pmjones $ + */ + +/** + * Embeds the results of a PHP script at render-time. + * This class implements a Text_Wiki_Parse to embed the contents of a URL + * inside the page at render-time. Typically used to get script output. + * This differs from the 'include' rule, which incorporates results at + * parse-time; 'embed' output does not get parsed by Text_Wiki, while + * 'include' ouput does. + * This rule is inherently not secure; it allows cross-site scripting to + * occur if the embedded output has +'; + } + } else { + $js = ''; + } + + return $js . ' +
+'; + case 'endContent': + return ' +
+'; + } + + return null; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Horiz.php b/system/classes/Text/Wiki/Render/Xhtml/Horiz.php new file mode 100644 index 000000000..f6d41ff6f --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Horiz.php @@ -0,0 +1,46 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Horiz.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders an horizontal bar in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Horiz extends Text_Wiki_Render +{ + public $conf = array( + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + $css = $this->formatConf(' class="%s"', 'css'); + + return "\n"; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Html.php b/system/classes/Text/Wiki/Render/Xhtml/Html.php new file mode 100644 index 000000000..b4b80d08d --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Html.php @@ -0,0 +1,40 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Html.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders preformated html in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Html extends Text_Wiki_Render +{ + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + return $options['text']; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Image.php b/system/classes/Text/Wiki/Render/Xhtml/Image.php new file mode 100644 index 000000000..0f1a2da2c --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Image.php @@ -0,0 +1,174 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Image.php 231923 2007-03-15 15:04:50Z justinpatrin $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class inserts an image in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Image extends Text_Wiki_Render +{ + public $conf = array( + 'base' => '/', + 'url_base' => null, + 'css' => null, + 'css_link' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + // note the image source + $src = $options['src']; + + // is the source a local file or URL? + if (strpos($src, '://') === false) { + // the source refers to a local file. + // add the URL base to it. + $src = $this->getConf('base', '/') . $src; + } + + // stephane@metacites.net + // is the image clickable? + if (isset($options['attr']['link'])) { + // yes, the image is clickable. + // are we linked to a URL or a wiki page? + if (strpos($options['attr']['link'], '://')) { + // it's a URL, prefix the URL base + $href = $this->getConf('url_base') . $options['attr']['link']; + } else { + // it's a WikiPage; assume it exists. + /** @todo This needs to honor sprintf wikilinks (pmjones) */ + /** @todo This needs to honor interwiki (pmjones) */ + /** @todo This needs to honor freelinks (pmjones) */ + $href = $this->wiki->getRenderConf('xhtml', 'wikilink', 'view_url') . + $options['attr']['link']; + } + } else { + // image is not clickable. + $href = null; + } + + // unset so it won't show up as an attribute + unset($options['attr']['link']); + + // stephane@metacites.net -- 25/07/2004 + // use CSS for all alignment + if (isset($options['attr']['align'])) { + // make sure we have a style attribute + if (!isset($options['attr']['style'])) { + // no style, set up a blank one + $options['attr']['style'] = ''; + } else { + // style exists, add a space + $options['attr']['style'] .= ' '; + } + + if ($options['attr']['align'] === 'center') { + // add a "center" style to the existing style. + $options['attr']['style'] .= 'display: block; margin-left: auto; margin-right: auto;'; + } else { + // add a float style to the existing style + $options['attr']['style'] .= 'float: ' . $options['attr']['align']; + } + + // unset so it won't show up as an attribute + unset($options['attr']['align']); + } + + // stephane@metacites.net -- 25/07/2004 + // try to guess width and height + if (!isset($options['attr']['width']) && + !isset($options['attr']['height']) + ) { + // does the source refer to a local file or a URL? + if (strpos($src, '://')) { + // is a URL link + $imageFile = $src; + } elseif ($src[0] === '.') { + // reg at dav-muz dot net -- 2005-03-07 + // is a local file on relative path. + $imageFile = $src; # ...don't do anything because it's perfect! + } else { + // is a local file on absolute path. + $imageFile = $_SERVER['DOCUMENT_ROOT'] . $src; + } + + // attempt to get the image size + $imageSize = @getimagesize($imageFile); + + if (is_array($imageSize)) { + $options['attr']['width'] = $imageSize[0]; + $options['attr']['height'] = $imageSize[1]; + } + } + + // start the HTML output + $output = 'formatConf(' class="%s"', 'css'); + + // add the attributes to the output, and be sure to + // track whether or not we find an "alt" attribute + $alt = false; + foreach ($options['attr'] as $key => $val) { + // track the 'alt' attribute + if (strtolower($key) === 'alt') { + $alt = true; + } + + // the 'class' attribute overrides the CSS class conf + if (strtolower($key) === 'class') { + $css = null; + } + + $key = $this->textEncode($key); + $val = $this->textEncode($val); + $output .= " {$key}=\"{$val}\""; + } + + // always add an "alt" attribute per Stephane Solliec + if (!$alt) { + $alt = $this->textEncode(basename($options['src'])); + $output .= " alt=\"{$alt}\""; + } + + // end the image tag with the automatic CSS class (if any) + $output .= "{$css} />"; + + // was the image clickable? + if ($href) { + // yes, add the href and return + $href = $this->textEncode($href); + $css = $this->formatConf(' class="%s"', 'css_link'); + $output = "{$output}"; + } + + return $output; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Include.php b/system/classes/Text/Wiki/Render/Xhtml/Include.php new file mode 100644 index 000000000..e8864ecf8 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Include.php @@ -0,0 +1,33 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Include.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders included maekup in XHTML. (empty) + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Include extends Text_Wiki_Render +{ + public function token() + { + return ''; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Interwiki.php b/system/classes/Text/Wiki/Render/Xhtml/Interwiki.php new file mode 100644 index 000000000..badeedfb0 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Interwiki.php @@ -0,0 +1,97 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Interwiki.php 231896 2007-03-15 00:08:47Z justinpatrin $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders inter wikis links in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Interwiki extends Text_Wiki_Render +{ + public $conf = array( + 'sites' => array( + 'MeatBall' => 'http://www.usemod.com/cgi-bin/mb.pl?%s', + 'Advogato' => 'http://advogato.org/%s', + 'Wiki' => 'http://c2.com/cgi/wiki?%s', + ), + 'target' => '_blank', + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + $text = $options['text']; + + if (isset($options['url'])) { + // calculated by the parser (e.g. Mediawiki) + $href = $options['url']; + } else { + $site = $options['site']; + // toggg 2006/02/05 page name must be url encoded (e.g. may contain spaces) + $page = $this->urlEncode($options['page']); + + if (isset($this->conf['sites'][$site])) { + $href = $this->conf['sites'][$site]; + } else { + return $text; + } + + // old form where page is at end, + // or new form with %s placeholder for sprintf()? + if (strpos($href, '%s') === false) { + // use the old form + $href = $href . $page; + } else { + // use the new form + $href = sprintf($href, $page); + } + } + + // allow for alternative targets + $target = $this->getConf('target'); + + // build base link + $css = $this->formatConf(' class="%s"', 'css'); + $text = $this->textEncode($text); + $output = "textEncode($target); + $output .= " onclick=\"window.open(this.href, '$target');"; + $output .= " return false;\""; + } + + $output .= ">$text"; + + return $output; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Italic.php b/system/classes/Text/Wiki/Render/Xhtml/Italic.php new file mode 100644 index 000000000..d263e4a64 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Italic.php @@ -0,0 +1,54 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Italic.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders italic text in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Italic extends Text_Wiki_Render +{ + public $conf = array( + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + if ($options['type'] === 'start') { + $css = $this->formatConf(' class="%s"', 'css'); + + return ""; + } + + if ($options['type'] === 'end') { + return ''; + } + + return null; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/List.php b/system/classes/Text/Wiki/Render/Xhtml/List.php new file mode 100644 index 000000000..8764e6655 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/List.php @@ -0,0 +1,164 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: List.php 200073 2005-11-06 10:38:25Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders bullet and ordered lists in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_List extends Text_Wiki_Render +{ + public $conf = array( + 'css_ol' => null, + 'css_ol_li' => null, + 'css_ul' => null, + 'css_ul_li' => null, + ); + + /** + * Renders a token into text matching the requested format. + * This rendering method is syntactically and semantically compliant + * with XHTML 1.1 in that sub-lists are part of the previous list item. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + // make nice variables (type, level, count) + $type = ''; + $level = ''; + $count = ''; + extract($options); + + // set up indenting so that the results look nice; we do this + // in two steps to avoid str_pad mathematics. ;-) + $pad = str_pad('', $level, "\t"); + $pad = str_replace("\t", ' ', $pad); + + switch ($type) { + case 'bullet_list_start': + // build the base HTML + $css = $this->formatConf(' class="%s"', 'css_ul'); + $html = ""; + + /* + // if this is the opening block for the list, + // put an extra newline in front of it so the + // output looks nice. + if ($level == 0) { + $html = "\n$html"; + } + */ + + // done! + return $html; + break; + + case 'bullet_list_end': + // build the base HTML + $html = "\n{$pad}"; + + // if this is the closing block for the list, + // put extra newlines after it so the output + // looks nice. + if ($level == 0) { + $html .= "\n\n"; + } + + // done! + return $html; + break; + + case 'number_list_start': + if (isset($format)) { + $format = ' type="' . $format . '"'; + } else { + $format = ''; + } + + // build the base HTML + $css = $this->formatConf(' class="%s"', 'css_ol'); + $html = ""; + + /* + // if this is the opening block for the list, + // put an extra newline in front of it so the + // output looks nice. + if ($level == 0) { + $html = "\n$html"; + } + */ + + // done! + return $html; + break; + + case 'number_list_end': + // build the base HTML + $html = "\n{$pad}"; + + // if this is the closing block for the list, + // put extra newlines after it so the output + // looks nice. + if ($level == 0) { + $html .= "\n\n"; + } + + // done! + return $html; + break; + + case 'bullet_item_start': + case 'number_item_start': + // pick the proper CSS class + if ($type == 'bullet_item_start') { + $css = $this->formatConf(' class="%s"', 'css_ul_li'); + } else { + $css = $this->formatConf(' class="%s"', 'css_ol_li'); + } + + // build the base HTML + $html = "\n{$pad}"; + + // for the very first item in the list, do nothing. + // but for additional items, be sure to close the + // previous item. + if ($count > 0) { + $html = "{$html}"; + } + + // done! + return $html; + break; + + case 'bullet_item_end': + case 'number_item_end': + default: + // ignore item endings and all other types. + // item endings are taken care of by the other types + // depending on their place in the list. + return ''; + break; + } + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Newline.php b/system/classes/Text/Wiki/Render/Xhtml/Newline.php new file mode 100644 index 000000000..67ff71b94 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Newline.php @@ -0,0 +1,33 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Newline.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders new lines in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Newline extends Text_Wiki_Render +{ + public function token($options) + { + return "
\n"; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Page.php b/system/classes/Text/Wiki/Render/Xhtml/Page.php new file mode 100644 index 000000000..9fae4d09b --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Page.php @@ -0,0 +1,40 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Page.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders page markers in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Page extends Text_Wiki_Render +{ + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + return 'PAGE MARKER HERE*&^%$#^$%*PAGEMARKERHERE'; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Paragraph.php b/system/classes/Text/Wiki/Render/Xhtml/Paragraph.php new file mode 100644 index 000000000..8e74f1955 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Paragraph.php @@ -0,0 +1,57 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Paragraph.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders paragraphs in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Paragraph extends Text_Wiki_Render +{ + public $conf = array( + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + $type = ''; + extract($options); //type + + if ($type === 'start') { + $css = $this->formatConf(' class="%s"', 'css'); + + return ""; + } + + if ($type === 'end') { + return "

\n\n"; + } + + return null; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Phplookup.php b/system/classes/Text/Wiki/Render/Xhtml/Phplookup.php new file mode 100644 index 000000000..d280478ef --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Phplookup.php @@ -0,0 +1,75 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Phplookup.php 231896 2007-03-15 00:08:47Z justinpatrin $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders a link to php functions description in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Phplookup extends Text_Wiki_Render +{ + public $conf = array( + 'target' => '_blank', + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + $text = trim($options['text']); + $css = $this->formatConf(' class="%s"', 'css'); + + // start the html + $output = "getConf('target', ''); + if ($target && $target != '_self') { + // use a "popup" window. this is XHTML compliant, suggested by + // Aaron Kalin. uses the $target as the new window name. + $target = $this->textEncode($target); + $output .= " onclick=\"window.open(this.href, '$target');"; + $output .= " return false;\""; + } + + // take off the final parens for functions + if (substr($text, -2) == '()') { + $q = substr($text, 0, -2); + } else { + $q = $text; + } + + // toggg 2006/02/05 page name must be url encoded (e.g. may contain spaces) + $q = $this->urlEncode($q); + $text = $this->textEncode($text); + + // finish and return + $output .= " href=\"http://php.net/{$q}\">{$text}"; + + return $output; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Plugin.php b/system/classes/Text/Wiki/Render/Xhtml/Plugin.php new file mode 100644 index 000000000..34fe8ac9a --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Plugin.php @@ -0,0 +1,41 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Plugin.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders wiki plugins in XHTML. (empty) + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Plugin extends Text_Wiki_Render +{ + /** + * Renders a token into text matching the requested format. + * Plugins produce wiki markup so are processed by parsing, no tokens produced + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + return ''; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Prefilter.php b/system/classes/Text/Wiki/Render/Xhtml/Prefilter.php new file mode 100644 index 000000000..c60b227dd --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Prefilter.php @@ -0,0 +1,35 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Prefilter.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class implements a Text_Wiki_Render_Xhtml to "pre-filter" source text so + * that line endings are consistently \n, lines ending in a backslash \ + * are concatenated with the next line, and tabs are converted to spaces. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Prefilter extends Text_Wiki_Render +{ + public function token() + { + return ''; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Preformatted.php b/system/classes/Text/Wiki/Render/Xhtml/Preformatted.php new file mode 100644 index 000000000..69d2945ff --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Preformatted.php @@ -0,0 +1,42 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Preformatted.php 229275 2007-02-07 13:40:44Z mic $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders preformated text in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Preformatted extends Text_Wiki_Render +{ + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + $text = $this->textEncode($options['text']); + + return '
' . $text . '
'; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Raw.php b/system/classes/Text/Wiki/Render/Xhtml/Raw.php new file mode 100644 index 000000000..a73d25565 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Raw.php @@ -0,0 +1,40 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Raw.php 214538 2006-06-09 21:32:24Z justinpatrin $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders not processed blocks in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Raw extends Text_Wiki_Render +{ + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + return $this->textEncode($options['text']); + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Revise.php b/system/classes/Text/Wiki/Render/Xhtml/Revise.php new file mode 100644 index 000000000..ff9e20579 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Revise.php @@ -0,0 +1,63 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Revise.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders revision marks in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Revise extends Text_Wiki_Render +{ + public $conf = array( + 'css_ins' => null, + 'css_del' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + if ($options['type'] === 'del_start') { + $css = $this->formatConf(' class="%s"', 'css_del'); + + return ""; + } + + if ($options['type'] === 'del_end') { + return ""; + } + + if ($options['type'] === 'ins_start') { + $css = $this->formatConf(' class="%s"', 'css_ins'); + + return ""; + } + + if ($options['type'] === 'ins_end') { + return ""; + } + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Smiley.php b/system/classes/Text/Wiki/Render/Xhtml/Smiley.php new file mode 100644 index 000000000..9e6f9648a --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Smiley.php @@ -0,0 +1,72 @@ + + * @copyright 2005 bertrand Gugger + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Smiley.php 206940 2006-02-10 23:07:03Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * Smiley rule Xhtml render class + * + * @category Text + * @package Text_Wiki + * @author Bertrand Gugger + * @copyright 2005 bertrand Gugger + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + * @see Wiki::Text_Wiki_Render() + */ +class Text_Wiki_Render_Xhtml_Smiley extends Text_Wiki_Render +{ + /** + * Configuration keys for this rule + * 'prefix' => the path to smileys images inclusive file name prefix, + * starts with '/' ==> abolute reference + * if no file names prefix but some folder, terminates with '/' + * 'extension' => the file extension (inclusive '.'), e.g. : + * if prefix 'smileys/icon_' and extension '.gif' + * ':)' whose name is 'smile' will give relative file 'smileys/icon_smile.gif' + * if prefix '/image/smileys/' and extension '.png': absolute '/image/smileys/smile.gif' + * 'css' => optional style applied to smileys + * + * @var array 'config-key' => mixed config-value + */ + public $conf = array( + 'prefix' => 'images/smiles/icon_', + 'extension' => '.gif', + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * process the Smileys + * + * @param array $options The "options" portion of the token (second element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + $imageFile = $this->getConf('prefix') . $options['name'] . $this->getConf('extension'); + + // attempt to get the image size + $imageSize = @getimagesize($imageFile); + + // return the HTML output + return '' . $options['desc'] . 'formatConf(' class="%s"', 'css') . ' />'; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Specialchar.php b/system/classes/Text/Wiki/Render/Xhtml/Specialchar.php new file mode 100644 index 000000000..596815d5c --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Specialchar.php @@ -0,0 +1,53 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Specialchar.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders special characters in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_SpecialChar extends Text_Wiki_Render +{ + public $types = array( + '~bs~' => '\', + '~hs~' => ' ', + '~amp~' => '&', + '~ldq~' => '“', + '~rdq~' => '”', + '~lsq~' => '‘', + '~rsq~' => '’', + '~c~' => '©', + '~--~' => '—', + '" -- "' => '—', + '" -- "' => '—', + '~lt~' => '<', + '~gt~' => '>', + ); + + public function token($options) + { + if (isset($this->types[$options['char']])) { + return $this->types[$options['char']]; + } else { + return '&#' . substr($options['char'], 1, -1) . ';'; + } + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Strong.php b/system/classes/Text/Wiki/Render/Xhtml/Strong.php new file mode 100644 index 000000000..6df31e027 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Strong.php @@ -0,0 +1,54 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Strong.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders text marked as strong in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Strong extends Text_Wiki_Render +{ + public $conf = array( + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + if ($options['type'] === 'start') { + $css = $this->formatConf(' class="%s"', 'css'); + + return ""; + } + + if ($options['type'] === 'end') { + return ''; + } + + return null; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Subscript.php b/system/classes/Text/Wiki/Render/Xhtml/Subscript.php new file mode 100644 index 000000000..d757e6e14 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Subscript.php @@ -0,0 +1,54 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Subscript.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders subscript text in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Subscript extends Text_Wiki_Render +{ + public $conf = array( + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + if ($options['type'] === 'start') { + $css = $this->formatConf(' class="%s"', 'css'); + + return ""; + } + + if ($options['type'] === 'end') { + return ''; + } + + return null; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Superscript.php b/system/classes/Text/Wiki/Render/Xhtml/Superscript.php new file mode 100644 index 000000000..46af1c69d --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Superscript.php @@ -0,0 +1,54 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Superscript.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders superscript text in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Superscript extends Text_Wiki_Render +{ + public $conf = array( + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + if ($options['type'] === 'start') { + $css = $this->formatConf(' class="%s"', 'css'); + + return ""; + } + + if ($options['type'] === 'end') { + return ''; + } + + return null; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Table.php b/system/classes/Text/Wiki/Render/Xhtml/Table.php new file mode 100644 index 000000000..0b639df1a --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Table.php @@ -0,0 +1,135 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Table.php 202250 2005-12-06 15:29:29Z ritzmo $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders tables in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Table extends Text_Wiki_Render +{ + public $conf = array( + 'css_table' => null, + 'css_caption' => null, + 'css_tr' => null, + 'css_th' => null, + 'css_td' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + // make nice variable names (type, attr, span) + $span = $rowspan = 1; + $type = ''; + $attr = ''; + extract($options); + + // free format + $format = isset($format) ? ' ' . $format : ''; + $pad = ' '; + + switch ($type) { + case 'table_start': + $css = $this->formatConf(' class="%s"', 'css_table'); + + return "\n\n\n"; + break; + + case 'table_end': + return "\n\n"; + break; + + case 'caption_start': + $css = $this->formatConf(' class="%s"', 'css_caption'); + + return "\n"; + break; + + case 'caption_end': + return "\n"; + break; + + case 'row_start': + $css = $this->formatConf(' class="%s"', 'css_tr'); + + return "{$pad}\n"; + break; + + case 'row_end': + return "{$pad}\n"; + break; + + case 'cell_start': + // base html + $html = $pad . $pad; + + // is this a TH or TD cell? + if ($attr === 'header') { + // start a header cell + $css = $this->formatConf(' class="%s"', 'css_th'); + $html .= "formatConf(' class="%s"', 'css_td'); + $html .= " 1) { + $html .= " colspan=\"{$span}\""; + } + + // add the row span + if ($rowspan > 1) { + $html .= " rowspan=\"{$rowspan}\""; + } + + // add alignment + if ($attr != 'header' && $attr != '') { + $html .= " style=\"text-align: {$attr};\""; + } + + // done! + $html .= "{$format}>"; + + return $html; + break; + + case 'cell_end': + if ($attr === 'header') { + return "\n"; + } else { + return "\n"; + } + break; + + default: + return ''; + } + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Tighten.php b/system/classes/Text/Wiki/Render/Xhtml/Tighten.php new file mode 100644 index 000000000..6211aea2f --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Tighten.php @@ -0,0 +1,33 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Tighten.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class makes the tightening in XHTML. (empty) + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Tighten extends Text_Wiki_Render +{ + public function token() + { + return ''; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Titlebar.php b/system/classes/Text/Wiki/Render/Xhtml/Titlebar.php new file mode 100644 index 000000000..6912e4dc7 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Titlebar.php @@ -0,0 +1,52 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Titlebar.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders a title bar in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Titlebar extends Text_Wiki_Render +{ + public $conf = array( + 'css' => 'titlebar', + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + if ($options['type'] === 'start') { + $css = $this->formatConf(' class="%s"', 'css'); + + return ""; + } + + if ($options['type'] === 'end') { + return ''; + } + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Toc.php b/system/classes/Text/Wiki/Render/Xhtml/Toc.php new file mode 100644 index 000000000..c67f5bd80 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Toc.php @@ -0,0 +1,115 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Toc.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class inserts a table of content in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Toc extends Text_Wiki_Render +{ + public $conf = array( + 'css_list' => null, + 'css_item' => null, + 'title' => 'Table of Contents', + 'div_id' => 'toc', + 'collapse' => true, + ); + + public $min = 2; + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + // type, id, level, count, attr + $type = ''; + $id = ''; + $level = ''; + extract($options); + + switch ($type) { + case 'list_start': + $css = $this->getConf('css_list'); + $html = ''; + + // collapse div within a table? + if ($this->getConf('collapse')) { + $html .= ''; + $html .= "
\n"; + } + + // add the div, class, and id + $html .= 'getConf('div_id'); + if ($div_id) { + $html .= " id=\"{$div_id}\""; + } + + // add the title, and done + $html .= '>'; + $html .= $this->getConf('title'); + + return $html; + break; + + case 'list_end': + if ($this->getConf('collapse')) { + return "\n\n
\n\n"; + } else { + return "\n\n\n"; + } + break; + + case 'item_start': + $html = "\n\tgetConf('css_item'); + + if ($css) { + $html .= " class=\"{$css}\""; + } + + $pad = ($level - $this->min); + $html .= " style=\"margin-left: {$pad}em;\">"; + + $html .= ""; + + return $html; + break; + + case 'item_end': + return ""; + break; + } + + return null; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Tt.php b/system/classes/Text/Wiki/Render/Xhtml/Tt.php new file mode 100644 index 000000000..6d0fecc21 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Tt.php @@ -0,0 +1,54 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Tt.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders monospaced text in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Tt extends Text_Wiki_Render +{ + public $conf = array( + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + if ($options['type'] === 'start') { + $css = $this->formatConf(' class="%s"', 'css'); + + return ""; + } + + if ($options['type'] === 'end') { + return ''; + } + + return null; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Underline.php b/system/classes/Text/Wiki/Render/Xhtml/Underline.php new file mode 100644 index 000000000..3485d0bd9 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Underline.php @@ -0,0 +1,54 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Underline.php 191862 2005-07-30 08:03:29Z toggg $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders underlined text in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Underline extends Text_Wiki_Render +{ + public $conf = array( + 'css' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + if ($options['type'] === 'start') { + $css = $this->formatConf(' class="%s"', 'css'); + + return ""; + } + + if ($options['type'] === 'end') { + return ''; + } + + return null; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Url.php b/system/classes/Text/Wiki/Render/Xhtml/Url.php new file mode 100644 index 000000000..76e909585 --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Url.php @@ -0,0 +1,127 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Url.php 236400 2007-05-26 17:15:41Z mic $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders URL links in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Url extends Text_Wiki_Render +{ + public $conf = array( + 'target' => '_blank', + 'images' => true, + 'img_ext' => array('jpg', 'jpeg', 'gif', 'png'), + 'css_inline' => null, + 'css_footnote' => null, + 'css_descr' => null, + 'css_img' => null, + ); + + /** + * Renders a token into text matching the requested format. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + // create local variables from the options array (text, + // href, type) + $href = ''; + $type = ''; + $text = ''; + extract($options); + + // find the rightmost dot and determine the filename + // extension. + $pos = strrpos($href, '.'); + $ext = strtolower(substr($href, $pos + 1)); + $href = $this->textEncode($href); + + // does the filename extension indicate an image file? + if ($this->getConf('images') && + in_array($ext, $this->getConf('img_ext', array())) + ) { + // create alt text for the image + if (!isset($text) || $text == '') { + $text = basename($href); + $text = $this->textEncode($text); + } + + // generate an image tag + $css = $this->formatConf(' class="%s"', 'css_img'); + $start = ""; + } else { + // should we build a target clause? + if ($href{0} === '#' || + strtolower(substr($href, 0, 7)) === 'mailto:' + ) { + // targets not allowed for on-page anchors + // and mailto: links. + $target = ''; + } else { + // allow targets on non-anchor non-mailto links + $target = $this->getConf('target'); + } + + // generate a regular link (not an image) + $text = $this->textEncode($text); + $css = $this->formatConf(' class="%s"', "css_{$type}"); + $start = "textEncode($target); + $start .= " onclick=\"window.open(this.href, '$target');"; + $start .= " return false;\""; + } + + if (isset($name)) { + $start .= " id=\"{$name}\""; + } + + // finish up output + $start .= ">"; + $end = ""; + + // make numbered references look like footnotes when no + // CSS class specified, make them superscript by default + if ($type == 'footnote' && !$css) { + $start = '' . $start; + $end = $end . ''; + } + } + + if ($options['type'] === 'start') { + $output = $start; + } else if ($options['type'] === 'end') { + $output = $end; + } else { + $output = $start . $text . $end; + } + + return $output; + } +} diff --git a/system/classes/Text/Wiki/Render/Xhtml/Wikilink.php b/system/classes/Text/Wiki/Render/Xhtml/Wikilink.php new file mode 100644 index 000000000..f0231e6ab --- /dev/null +++ b/system/classes/Text/Wiki/Render/Xhtml/Wikilink.php @@ -0,0 +1,173 @@ + + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Wikilink.php 224670 2006-12-08 21:25:24Z justinpatrin $ + * @link http://pear.php.net/package/Text_Wiki + */ + +/** + * This class renders wiki links in XHTML. + * + * @category Text + * @package Text_Wiki + * @author Paul M. Jones + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Text_Wiki + */ +class Text_Wiki_Render_Xhtml_Wikilink extends Text_Wiki_Render +{ + public $conf = array( + 'pages' => array(), // set to null or false to turn off page checks + 'view_url' => 'http://example.com/index.php?page=%s', + 'new_url' => 'http://example.com/new.php?page=%s', + 'new_text' => '?', + 'new_text_pos' => 'after', // 'before', 'after', or null/false + 'css' => null, + 'css_new' => null, + 'exists_callback' => null // call_user_func() callback + ); + + /** + * Renders a token into XHTML. + * + * @param array $options The "options" portion of the token (second + * element). + * @return string The text rendered from the token options. + */ + public function token($options) + { + // make nice variable names (page, anchor, text) + $page = ''; + $anchor = ''; + $text = ''; + $output = ''; + extract($options); + + // is there a "page existence" callback? + // we need to access it directly instead of through + // getConf() because we'll need a reference (for + // object instance method callbacks). + if (isset($this->conf['exists_callback'])) { + $callback = $this->conf['exists_callback']; + } else { + $callback = false; + } + + if ($callback) { + // use the callback function + $exists = call_user_func($callback, $page); + } else { + // no callback, go to the naive page array. + $list = $this->getConf('pages'); + + if (is_array($list)) { + // yes, check against the page list + $exists = in_array($page, $list); + } else { + // no, assume it exists + $exists = true; + } + } + + $anchor = '#' . $this->urlEncode(substr($anchor, 1)); + + // does the page exist? + if ($exists) { + // PAGE EXISTS. + + // link to the page view, but we have to build + // the HREF. we support both the old form where + // the page always comes at the end, and the new + // form that uses %s for sprintf() + $href = $this->getConf('view_url'); + + if (strpos($href, '%s') === false) { + // use the old form (page-at-end) + $href = $href . $this->urlEncode($page) . $anchor; + } else { + // use the new form (sprintf format string) + $href = sprintf($href, $this->urlEncode($page)) . $anchor; + } + + // get the CSS class and generate output + $css = ' class="' . $this->textEncode($this->getConf('css')) . '"'; + $start = ''; + $end = ''; + } else { + // PAGE DOES NOT EXIST. + + // link to a create-page url, but only if new_url is set + $href = $this->getConf('new_url', null); + + // set the proper HREF + if (!$href || trim($href) == '') { + // no useful href, return the text as it is + //TODO: This is no longer used, need to look closer into this branch + $output = $text; + } else { + // yes, link to the new-page href, but we have to build + // it. we support both the old form where + // the page always comes at the end, and the new + // form that uses sprintf() + if (strpos($href, '%s') === false) { + // use the old form + $href = $href . $this->urlEncode($page); + } else { + // use the new form + $href = sprintf($href, $this->urlEncode($page)); + } + } + + // get the appropriate CSS class and new-link text + $css = ' class="' . $this->textEncode($this->getConf('css_new')) . '"'; + $new = $this->getConf('new_text'); + + // what kind of linking are we doing? + $pos = $this->getConf('new_text_pos'); + if (!$pos || !$new) { + // no position (or no new_text), use css only on the page name + + $start = ''; + $end = ''; + } elseif ($pos === 'before') { + // use the new_text BEFORE the page name + $start = '' . $this->textEncode($new) . ''; + $end = ''; + } else { + // default, use the new_text link AFTER the page name + $start = ''; + $end = '' . $this->textEncode($new) . ''; + } + } + + if (!strlen($text)) { + $start .= $this->textEncode($page); + } + + if (isset($type)) { + switch ($type) { + case 'start': + $output = $start; + break; + + case 'end': + $output = $end; + break; + } + } else { + $output = $start . $this->textEncode($text) . $end; + } + + return $output; + } +} diff --git a/system/classes/gltext.class.php b/system/classes/gltext.class.php index 90ab97942..1ef80b17e 100644 --- a/system/classes/gltext.class.php +++ b/system/classes/gltext.class.php @@ -275,9 +275,7 @@ public static function renderWikiText($wikitext) return $wikitext; } - require_once 'Text/Wiki.php'; - - $wiki = new Text_Wiki(); + $wiki = new Geeklog\Text\Wiki(); $wiki->setFormatConf('Xhtml', 'translate', HTML_SPECIALCHARS); $wiki->setRenderConf('Xhtml', 'charset', COM_getCharset()); $wiki->disableRule('wikilink');