From 16bb238518e19cd11d7882e377799e3c158e2c48 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 30 Jun 2010 18:42:50 +0000 Subject: [PATCH] added: bbcode files: core/bbcodeparser.h core/bbcodeparser.cpp git-svn-id: svn://ttmath.org/publicrep/winix/trunk@615 e52654a7-88a9-db11-a3e9-0013d4bc506e --- confparser/confparser.cpp | 2 +- core/Makefile.dep | 1 + core/Makefile.o.dep | 2 +- core/bbcodeparser.cpp | 566 ++++++++++++++++++++++++++++++++++++++ core/bbcodeparser.h | 95 +++++++ core/htmlfilter.cpp | 110 +++++--- core/htmlfilter.h | 34 ++- core/misc.cpp | 2 +- core/mountparser.cpp | 2 +- core/request.cpp | 5 +- core/request.h | 1 + static/layout1/winix.css | 71 +++++ templates/Makefile.dep | 2 +- templates/item.cpp | 22 +- templates/templates.cpp | 1 + templates/templates.h | 3 +- 16 files changed, 850 insertions(+), 69 deletions(-) create mode 100755 core/bbcodeparser.cpp create mode 100755 core/bbcodeparser.h diff --git a/confparser/confparser.cpp b/confparser/confparser.cpp index e0d04e5..a35d0ca 100755 --- a/confparser/confparser.cpp +++ b/confparser/confparser.cpp @@ -183,7 +183,7 @@ return lastc; bool ConfParser::IsWhite(int c) { - if( c==' ' || c=='\t' || c==13 ) + if( c==' ' || c=='\t' || c==13 || c==160 ) return true; return false; diff --git a/core/Makefile.dep b/core/Makefile.dep index 694af39..2a774e9 100755 --- a/core/Makefile.dep +++ b/core/Makefile.dep @@ -1,6 +1,7 @@ # DO NOT DELETE acceptbaseparser.o: acceptbaseparser.h +bbcodeparser.o: bbcodeparser.h htmlfilter.h compress.o: compress.h log.h config.o: config.h ../confparser/confparser.h log.h data.h dirs.h item.h config.o: dircontainer.h users.h user.h ugcontainer.h groups.h group.h diff --git a/core/Makefile.o.dep b/core/Makefile.o.dep index af48d6d..776f1b9 100755 --- a/core/Makefile.o.dep +++ b/core/Makefile.o.dep @@ -1 +1 @@ -o = acceptbaseparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o function.o functioncodeparser.o functionparser.o functions.o groups.o htmlfilter.o httpsimpleparser.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o sessionparser.o users.o +o = acceptbaseparser.o bbcodeparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o function.o functioncodeparser.o functionparser.o functions.o groups.o htmlfilter.o httpsimpleparser.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o sessionparser.o users.o diff --git a/core/bbcodeparser.cpp b/core/bbcodeparser.cpp new file mode 100755 index 0000000..056727f --- /dev/null +++ b/core/bbcodeparser.cpp @@ -0,0 +1,566 @@ +/* + * This file is a part of Winix + * and is not publicly distributed + * + * Copyright (c) 2008-2010, Tomasz Sowa + * All rights reserved. + * + */ + +#include "bbcodeparser.h" + + + + + +bool BBCODEParser::IsValidCharForName(int c) +{ + if( (c>='a' && c<='z') || + (c>='A' && c<='Z') || + c=='*' || c=='_') + return true; + +return false; +} + + +bool BBCODEParser::IsOpeningTagMark() +{ + return (*pchar == '['); +} + + +// there are no commentaries in bbcode +bool BBCODEParser::IsOpeningCommentaryTagMark() +{ + return false; +} + + +bool BBCODEParser::SkipCommentaryTagIfExists() +{ + return false; +} + + +bool BBCODEParser::IsClosingTagMark() +{ + return (*pchar == ']'); +} + + +bool BBCODEParser::IsClosingXmlSimpleTagMark() +{ + return false; +} + + + +// one enter will generate one
+// two enters or more will generate only two br (

) +void BBCODEParser::PutNormalText(const char * str, const char * end) +{ +int br_len; + + if( *pchar == 0 ) + { + // trimming last white characters at end of the user text + while( str= 2 ) + { + if( pstack[stack_len-1].type == Item::opening && + pstack[stack_len-2].type == Item::opening && + IsNameEqual("*", pstack[stack_len-1].name) && + IsNameEqual("*", pstack[stack_len-2].name) ) + { + // removing the last [*] from the stack + // was put automatically + PopStack(); + } + } +} + + + + +/* + bbcode format: + [bbcodetag=value]some text[/bbcodetag] + the value can be quoted, e.g. + [bbcodetag="value"]some text[/bbcodetag], or + [bbcodetag='value']some text[/bbcodetag] + + the third string below (in tags table) is 'html_argument' from Tags, + it can contain a special character % followed by a string which means: + %1 - "value" escaped as for html + %2 - "some text" escaped as for html + %u1 - "value" trimmed and escaped as for url-es + %u2 - "some text" trimmed and escaped as for url-es + %% - one % + + if you are using %2 or %u2 then "some text" is not treated as bbcode, e.g. + [bbcodetag=value]some [b]text[/b][/bbcodetag] will produce: + some [b]text[/b] (the inner tags [b][/b] were not parsed) + + also when using %2 or %u2 the closing bbcode tag is skipped + (if you want this tag then you can put it in 'html_argument') + + and when using u (%u1 or %u2) the argument is trimmed from whitespaces and new lines + at the beginning and at the end + (because otherwise a space would be changed to %20 and this were probably not what you really wanted) +*/ +const BBCODEParser::Tags * BBCODEParser::FindTag(const char * tag) +{ + static Tags tags[] = { + {"*", "li", ">", false}, + {"b", "em", ">", true}, + {"i", "span", " class=\"bbitalic\">", true}, + {"u", "span", " class=\"bbunderline\">", true}, + {"s", "span", " class=\"bbstrike\">", true}, + {"code", "code", " class=\"bbcode\">", false}, + {"list", "ul", " class=\"bblist\">", false}, + {"color", "span", " class=\"bbcol%1\">", true}, + {"url", "a", " href=\"%u1\">", true}, + {"img", "img", " alt=\"%1\" src=\"%u2\">", true}, + {"quote", "div", " class=\"bbquote\">\n%1
\n", false}, + }; + + size_t i; + size_t len = sizeof(tags) / sizeof(Tags); + + for(i=0 ; i='a' && c<='z') || + (c>='A' && c<='Z') || + (c>='0' && c<='9') || + (c=='_' || c=='?' || c=='.' || c==',' || c=='/' || c=='-' || + c=='+' || c=='*' || c=='(' || c==')' || c=='=' || c==':') + ) + { + (*out_string) += c; + } + else + { + char buffer[20]; + sprintf(buffer, "%02X", c); + + (*out_string) += '%'; + (*out_string) += buffer; + } +} + + +void BBCODEParser::PrintEscape(int c, bool change_quote) +{ + if( c == '<' ) + { + (*out_string) += "<"; + } + else + if( c == '>' ) + { + (*out_string) += ">"; + } + else + if( c == '&' ) + { + (*out_string) += "&"; + } + else + if( c == '\"' && change_quote ) + { + (*out_string) += """; + } + else + { + (*out_string) += c; + } +} + + +void BBCODEParser::PrintArgumentEncode(const char * start, const char * end) +{ + PrintArgumentCheckQuotes(start, end); + TrimWhiteWithNewLines(start, end); + + for( ; starthtml_tag, tag_name) == 0 ) + { + if( condition ) + { + PutClosingTag(tag); + (*out_string) += '\n'; + } + + condition = true; + } +} + + +void BBCODEParser::CheckOpeningTag(const Tags * tag) +{ + bool has_list_tag = has_open_ul_tag || has_open_ol_tag; + + CheckOpeningTag(tag, "li", has_open_li_tag); + CheckOpeningTag(tag, "ul", has_open_ul_tag); + CheckOpeningTag(tag, "ol", has_open_ol_tag); + + if( has_open_li_tag && !has_list_tag ) + { + (*out_string) += "
    \n"; + has_open_ul_tag = true; + } +} + + + + + +void BBCODEParser::PrintEscape(const char * start, const char * end, bool change_quote) +{ + for( ; start < end ; ++start) + PrintEscape(*start, change_quote); +} + + + +void BBCODEParser::PrintEncode(const char * start, const char * end) +{ + for( ; start < end ; ++start) + PrintEncode(*start); +} + + + +void BBCODEParser::PutOpeningTagFromEzc(const char * start, const char * end) +{ + // this can be a tag from Ezc templates system + (*out_string) += '['; + (*out_string) += LastItem().name; + + if( start != end ) + { + (*out_string) += ' '; + PrintEscape(start, end); + } + + (*out_string) += ']'; +} + + + + + +void BBCODEParser::PutHtmlArgument1(const char * arg_start, const char * arg_end, bool has_u) +{ + if( has_u ) + PrintArgumentEncode(arg_start, arg_end); + else + PrintArgumentEscape(arg_start, arg_end); +} + + + +void BBCODEParser::TrimWhiteWithNewLines(const char * & start, const char * & end) +{ + while( start < end && (IsWhite(*start) || *start==10) ) + ++start; + + while( start < end && (IsWhite(*(end-1)) || *(end-1)==10) ) + --end; +} + + + +void BBCODEParser::PutHtmlArgument2(const Tags * tag, bool has_u) +{ +const char * start = pchar; +const char * end = pchar; +bool first_tag_removed = false; + + while( *pchar != 0 ) + { + if( IsOpeningTagMark() ) + { + if( IsClosingTagForLastItem() ) + { + // the last tag is skipped when using patterns with %2 or %u2 + + PopStack(); // removing opening tag from the stack + first_tag_removed = true; + break; + } + } + else + { + pchar += 1; + end = pchar; + } + } + + if( !first_tag_removed ) + PopStack(); // user has forgotten to close the tag + + if( has_u ) + { + TrimWhiteWithNewLines(start, end); + PrintEncode(start, end); + } + else + { + PrintEscape(start, end); + } +} + + + +void BBCODEParser::PutHtmlArgument(const Tags * tag, const char * arg_start, const char * arg_end) +{ +const char * pattern = tag->html_argument; +bool has_u; + + while( *pattern ) + { + if( *pattern == '%' ) + { + ++pattern; + has_u = false; + + if( *pattern == 'u' ) + { + ++pattern; + has_u = true; + } + + if( *pattern == '1' ) + { + ++pattern; + PutHtmlArgument1(arg_start, arg_end, has_u); + } + else + if( *pattern == '2' ) + { + ++pattern; + PutHtmlArgument2(tag, has_u); + } + else + if( *pattern == '%' ) + { + (*out_string) += '%'; + ++pattern; + } + // else unrecognized, will be printed next time as a normal character + } + else + { + (*out_string) += *pattern; + ++pattern; + } + } +} + + +void BBCODEParser::PutOpeningTagFromBBCode(const Tags * tag, const char * start, const char * end) +{ + CheckOpeningTag(tag); + PutOpeningTagMark(); + (*out_string) += tag->html_tag; + PutHtmlArgument(tag, start, end); + + if( !tag->inline_tag ) + { + (*out_string) += "\n"; + SkipWhiteLines(); + } +} + + +void BBCODEParser::PutOpeningTag(const char * start, const char * end) +{ + const Tags * tag = FindTag(LastItem().name); + + if( !tag ) + { + PutOpeningTagFromEzc(start, end); + } + else + { + PutOpeningTagFromBBCode(tag, start, end); + } +} + + +void BBCODEParser::PutClosingTag(const Tags * tag) +{ + if( !tag ) + return; // skipping the tag + + PutOpeningTagMark(); + (*out_string) += '/'; + (*out_string) += tag->html_tag; + PutClosingTagMark(); + + if( !tag->inline_tag ) + { + (*out_string) += "\n"; + SkipWhiteLines(); + } + + if( strcmp(tag->html_tag, "li") == 0 ) + has_open_li_tag = false; + + if( strcmp(tag->html_tag, "ol") == 0 ) + has_open_ol_tag = false; + + if( strcmp(tag->html_tag, "ul") == 0 ) + has_open_ul_tag = false; +} + + +void BBCODEParser::PutClosingTag(const char * tag_name) +{ + const Tags * tag = FindTag(tag_name); + PutClosingTag(tag); +} + + + +void BBCODEParser::Init() +{ + has_open_li_tag = false; + has_open_ol_tag = false; + has_open_ul_tag = false; + + SkipWhiteLines(); +} + + +void BBCODEParser::Deinit() +{ + if( has_open_li_tag ) + (*out_string) += "\n"; + + if( has_open_ol_tag ) + (*out_string) += "\n"; + + if( has_open_ul_tag ) + (*out_string) += "
\n"; +} diff --git a/core/bbcodeparser.h b/core/bbcodeparser.h new file mode 100755 index 0000000..8349e50 --- /dev/null +++ b/core/bbcodeparser.h @@ -0,0 +1,95 @@ +/* + * This file is a part of Winix + * and is not publicly distributed + * + * Copyright (c) 2008-2010, Tomasz Sowa + * All rights reserved. + * + */ + +#ifndef headerfilecmslucorebbcodeparser +#define headerfilecmslucorebbcodeparser + +#include "htmlfilter.h" + + +class BBCODEParser : public HTMLFilter +{ + + //using HTMLFilter::pchar; + + + struct Tags + { +/* + const char * bbcode; + const char * html_tag; + const char * html_arg_prefix; + const char * html_arg_postfix; + const char * additional_html_tag_prefix; + const char * additional_html_tag_postfix; + bool inline_tag; +*/ + const char * bbcode; + const char * html_tag; + const char * html_argument; // with closing '>' + bool inline_tag; + }; + + virtual bool IsValidCharForName(int c); + + virtual bool IsOpeningTagMark(); + virtual bool IsOpeningCommentaryTagMark(); + virtual bool SkipCommentaryTagIfExists(); + virtual bool IsClosingTagMark(); + virtual bool IsClosingXmlSimpleTagMark(); + + + void PutHtmlArgument1(const char * arg_start, const char * arg_end, bool has_u); + void PutHtmlArgument2(const Tags * tag, bool has_u); + void PutHtmlArgument(const Tags * tag, const char * arg_start, const char * arg_end); + + void PutOpeningTagFromEzc(const char * start, const char * end); + void PutOpeningTagFromBBCode(const Tags * tag, const char * start, const char * end); + + virtual void PutOpeningTag(const char * start, const char * end); + virtual void PutClosingTag(const char * tag); + + const Tags * FindTag(const char * tag); + void PrintArgumentCheckQuotes(const char * & start, const char * & end); + + + void PrintEscape(int c, bool change_quote = false); + void PrintEncode(int c); + + void PrintEscape(const char * start, const char * end, bool change_quote = false); + void PrintEncode(const char * start, const char * end); + + void PrintArgumentEncode(const char * start, const char * end); + void PrintArgumentEscape(const char * start, const char * end); + + virtual void ReadNormalTextSkipWhite(const char * & start, const char * & last_non_white); + virtual void PutNormalText(const char * str, const char * end); + virtual void PutNormalTextTrim(const char * str, const char * end); + + virtual void CheckExceptions(); + + virtual void Init(); + virtual void Deinit(); + + void PutClosingTag(const Tags * tag); + + + void CheckOpeningTag(const Tags * tag, const char * tag_name, bool & condition); + void CheckOpeningTag(const Tags * tag); + + void TrimWhiteWithNewLines(const char * & start, const char * & end); + + bool has_open_ol_tag; // has open html
    tag + bool has_open_ul_tag; // has open html
      tag + bool has_open_li_tag; // has open html
    • tag + + +}; + +#endif diff --git a/core/htmlfilter.cpp b/core/htmlfilter.cpp index 16a0ada..7adb771 100755 --- a/core/htmlfilter.cpp +++ b/core/htmlfilter.cpp @@ -70,6 +70,7 @@ HTMLFilter::HTMLFilter() break_after = 0; lang = lang_none; orphan_mode = orphan_nbsp; + safe_mode = false; } @@ -130,6 +131,12 @@ void HTMLFilter::CheckOrphans(HTMLFilter::Lang lang_, HTMLFilter::OrphanMode mod } +void HTMLFilter::SafeMode(bool safe_mode_) +{ + safe_mode = safe_mode_; +} + + HTMLFilter::Item & HTMLFilter::GetItem(size_t i) { @@ -182,7 +189,7 @@ bool HTMLFilter::IsWhite(int c) { // dont use c==10 here - if( c==' ' || c=='\t' || c==13 ) + if( c==' ' || c=='\t' || c==13 || c==160 ) return true; return false; @@ -645,10 +652,38 @@ void HTMLFilter::PutTagName(const char * name) } +bool HTMLFilter::IsTagSafe(const char * tag) +{ + if( !safe_mode ) + return true; + + static const char * unsafe_tags[] = { + "script", "iframe", "frame", "frameset", + "applet", "head", "meta", "html", "link", "body" + }; + + size_t len = sizeof(unsafe_tags) / sizeof(const char*); + size_t i; + + for(i=0 ; i 1 ) - PutTabs(stack_len-1); - } - - PutOpeningTag(start, end); + if( stack_len > 1 ) + PutTabs(stack_len-1); } + + PutOpeningTag(start, end); } @@ -902,40 +935,40 @@ const char * start = pchar; if( *pchar == 0 ) return false; + if( !PushStack() ) + return false; + // we have '<' pchar += 1; SkipWhite(); - if( PushStack() ) - { - if( *pchar == '/' ) // we have a closing tag - { - pchar += 1; - SkipWhite(); - LastItem().type = Item::closing; - } - - ReadItemName(); + if( *pchar == '/' ) // we have a closing tag + { + pchar += 1; SkipWhite(); - start = pchar; // arguments start here - - if( LastItem().type != Item::closing ) - LastItem().type = (LastItem().name[0] == '!') ? Item::special : Item::opening; - - const char * end = SkipItemCheckXmlSimple(); - PrintItem(start, end); - CheckNewLine(); - LastItem().new_line = last_new_line; - - return true; + LastItem().type = Item::closing; } - - pchar = start; -return false; + ReadItemName(); + SkipWhite(); + start = pchar; // arguments start here + + if( LastItem().type != Item::closing ) + LastItem().type = (LastItem().name[0] == '!') ? Item::special : Item::opening; + + const char * end = SkipItemCheckXmlSimple(); + + if( LastItem().type != Item::closing ) + PrintItem(start, end); + + CheckNewLine(); + LastItem().new_line = last_new_line; + +return true; } + int HTMLFilter::ToLower(int c) { if( c>='A' && c<='Z' ) @@ -998,8 +1031,11 @@ void HTMLFilter::CheckExceptions() return; } + // in safe_mode the script tag is ignored + if( !safe_mode && IsLastTag("script") ) + PutLastTagWithClosingTag(); - if( IsLastTag("script") || IsLastTag("pre") || IsLastTag("textarea") ) + if( IsLastTag("pre") || IsLastTag("textarea") ) PutLastTagWithClosingTag(); } diff --git a/core/htmlfilter.h b/core/htmlfilter.h index 57be5cd..753cdb4 100755 --- a/core/htmlfilter.h +++ b/core/htmlfilter.h @@ -48,6 +48,7 @@ class HTMLFilter { public: + // for checking orphans enum Lang { @@ -59,27 +60,29 @@ public: enum OrphanMode { - orphan_nbsp, - orphan_nbspace + orphan_nbsp, // putting " " string + orphan_160space // putting 160 ascii code }; - HTMLFilter(); HTMLFilter(const HTMLFilter & f); HTMLFilter & operator=(const HTMLFilter & f); ~HTMLFilter(); + // main methods used for filtering void Filter(const char * in, std::string & out); void Filter(const std::string & in, std::string & out); + // insert a white space into long lines // only between html tags // skipped in such tags: script, pre, textarea // break_after - after how many characters insert a space (0 - off) void BreakLines(size_t break_after_); + // trimming white characters (with new lines) // at the beginning, at the end and in the middle of a string // only between html tags @@ -88,17 +91,24 @@ public: // false by default void TrimWhite(bool trim); + // first tabs in a tree // default: 2 (spaces) // set 0 to turn off void InsertTabs(size_t tabsize); + // check 'orphans' for the specicic language - // if an orphans is detected then the non-break space ( ) will be put - // default disable: lang_none + // if an orphan is detected then the non-break space (" " or ascii 160 code) will be put + // default disable (lang_none) void CheckOrphans(Lang lang_, OrphanMode mode = orphan_nbsp); + // skipping some unsafe tags + // (script, iframe, frame, frameset, applet, head, meta, html, link, body, ...) + void SafeMode(bool safe_mode_); + + protected: @@ -126,7 +136,7 @@ protected: // only this method have direct access to the output string // you can easily change the output from a std::string to something else - void Put(const char * str, const char * end); + virtual void Put(const char * str, const char * end); Item & GetItem(size_t i); @@ -136,8 +146,7 @@ protected: bool IsNameEqual(const char * name1, const char * name2); bool IsNameEqual(const char * name1, const char * name2, size_t len); bool IsLastTag(const char * name); - -public: // !! + bool IsTagSafe(const char * tag); int CheckOrphan(const char * str, const char * end, const char * orphan); bool CheckOrphanTable(const char * str, const char * end, const char ** table, size_t o1, size_t o2); @@ -162,11 +171,11 @@ public: // !! bool PushStack(); virtual bool IsValidCharForName(int c); void CheckNewLine(); - void CheckExceptions(); + virtual void CheckExceptions(); void CheckStackPrintRest(); void AddForgottenTags(); void CheckClosingTags(); - void ReadNormalTextSkipWhite(const char * & start, const char * & last_non_white); + virtual void ReadNormalTextSkipWhite(const char * & start, const char * & last_non_white); void ReadNormalText(); bool PrintRest(); void PrintItem(const char * start, const char * end); @@ -178,8 +187,8 @@ public: // !! size_t PutNormalTextTrimFillBuffer(const char * & str, const char * & end); size_t PutNormalTextFillBuffer(const char * & str, const char * & end); - void PutNormalText(const char * str, const char * end); - void PutNormalTextTrim(const char * str, const char * end); + virtual void PutNormalText(const char * str, const char * end); + virtual void PutNormalTextTrim(const char * str, const char * end); void PutLastTagWithClosingTag(); virtual void PutOpeningTagMark(); virtual void PutClosingTagMark(); @@ -203,6 +212,7 @@ public: // !! size_t tab_size; Lang lang; // current language for checking orphans OrphanMode orphan_mode; + bool safe_mode; // skipping some unsafe tags }; diff --git a/core/misc.cpp b/core/misc.cpp index 8800a48..35815c2 100755 --- a/core/misc.cpp +++ b/core/misc.cpp @@ -389,7 +389,7 @@ return buffer; bool IsWhite(int s) { - if( s==' ' || s=='\t' || s==13 ) + if( s==' ' || s=='\t' || s==13 || s==160 ) return true; return false; diff --git a/core/mountparser.cpp b/core/mountparser.cpp index 590528f..65b9037 100755 --- a/core/mountparser.cpp +++ b/core/mountparser.cpp @@ -15,7 +15,7 @@ bool MountParser::IsWhite(int c) { - if( c==' ' || c=='\t' || c==13 ) + if( c==' ' || c=='\t' || c==13 || c==160 ) return true; return false; diff --git a/core/request.cpp b/core/request.cpp index 4056fd5..60d5ee8 100755 --- a/core/request.cpp +++ b/core/request.cpp @@ -485,7 +485,7 @@ void Request::SendPage(bool compressing, const std::string & source_ref) html_filter.TrimWhite(true); html_filter.BreakLines(60); html_filter.InsertTabs(2); - html_filter.CheckOrphans(HTMLFilter::lang_pl, HTMLFilter::orphan_nbspace); + html_filter.CheckOrphans(HTMLFilter::lang_pl, HTMLFilter::orphan_160space); html_filter.Filter(*source, clean_html); source = &clean_html; @@ -926,7 +926,8 @@ bool Request::CanUseHtml(long user_id) bool Request::CanUseBBCode(long user_id) { - return CanUse(user_id, "allow_bbcode"); + // logged users can use bbcode + return (user_id != -1); } diff --git a/core/request.h b/core/request.h index 6cdb085..eff5c41 100755 --- a/core/request.h +++ b/core/request.h @@ -28,6 +28,7 @@ #include "ticket.h" + struct Request { // request id diff --git a/static/layout1/winix.css b/static/layout1/winix.css index 1c6e967..5736a4e 100755 --- a/static/layout1/winix.css +++ b/static/layout1/winix.css @@ -678,3 +678,74 @@ img.catimage { max-width: 600px; } + +/* + from bbcode +*/ + +span.bbitalic { +font-style: italic; +} + + +span.bbunderline { +text-decoration: underline; +} + + +span.bbstrike { +text-decoration: line-through; +} + + +div.bbquote { +display: block; +padding: 0.5em; +margin: 0.5em 0 1em 0; +border: 1px solid #C3C3C3; +background: #F0F0F0; +} + +div.bbquote span.bbquotewho { +font-size: 0.8em; +color: #BABABA; +} + +code.bbcode { + +} + + +ul.bblist { +margin-left: 2em; +} + + +ul.bblist li { +list-style-type: disc; +} + +span.bbcolyellow { +color: yellow; +} + +span.bbcolred { +color: red; +} + +span.bbcolgreen { +color: green; +} + +span.bbcolblue { +color: blue; +} + +span.bbcolbrown { +color: brown; +} + +span.bbcolblack { +color: black; +} + diff --git a/templates/Makefile.dep b/templates/Makefile.dep index 1ba1771..a362ee2 100755 --- a/templates/Makefile.dep +++ b/templates/Makefile.dep @@ -55,7 +55,7 @@ item.o: ../core/request.h ../core/requesttypes.h ../core/session.h item.o: ../core/plugindata.h ../core/thread.h ../core/compress.h item.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h item.o: ../core/htmlfilter.h ../core/postmultiparser.h ../core/ticket.h -item.o: ../core/misc.h +item.o: ../core/misc.h ../core/bbcodeparser.h last.o: templates.h patterncacher.h ../core/item.h misc.h localefilter.h last.o: ../core/locale.h ../confparser/confparser.h ckeditorgetparser.h last.o: ../core/httpsimpleparser.h ../core/log.h indexpatterns.h diff --git a/templates/item.cpp b/templates/item.cpp index 4d8d256..d27ffac 100755 --- a/templates/item.cpp +++ b/templates/item.cpp @@ -12,12 +12,15 @@ #include "../core/data.h" #include "../core/request.h" #include "../core/misc.h" +#include "../core/bbcodeparser.h" namespace TemplatesFunctions { +static BBCODEParser bbcode_parser; + @@ -114,20 +117,19 @@ void item_print_content(std::ostringstream & out, const std::string & content, I HtmlEscapeFormTxt(out, content); } else - if( content_type == Item::ct_html ) + if( content_type == Item::ct_html || content_type == Item::ct_raw ) { out << content; } else if( content_type == Item::ct_bbcode ) { - //out << content; // !! tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a - out << "bbcode is not implemented yet"; - } - else - if( content_type == Item::ct_raw ) - { - out << content; + static std::string out_temp; + out_temp.clear(); + out_temp.reserve(content.size()*2); + + bbcode_parser.Filter(content.c_str(), out_temp); + out << out_temp; } } @@ -523,8 +525,6 @@ void item_tab_date_creation_nice(Info & i) { tm * ptm = &request.item_table[item_index].date_creation; TemplatesMisc::print_date_nice(i, ptm); - - i.out << ""; } } @@ -536,8 +536,6 @@ void item_tab_date_modification_nice(Info & i) { tm * ptm = &request.item_table[item_index].date_modification; TemplatesMisc::print_date_nice(i, ptm); - - i.out << ""; } } diff --git a/templates/templates.cpp b/templates/templates.cpp index 04fc774..a4e37f6 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -28,6 +28,7 @@ Locale locale; LocaleFilter locale_filter; CKEditorGetParser ckeditor_getparser; + const std::string empty; // used by GenerateRunRaw() diff --git a/templates/templates.h b/templates/templates.h index a3bb336..b0681f0 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -21,6 +21,7 @@ + namespace TemplatesFunctions { using Ezc::Info; @@ -74,7 +75,7 @@ namespace TemplatesFunctions extern Locale locale; extern Ezc::Functions functions; extern CKEditorGetParser ckeditor_getparser; - + /* sys