Changeset 757

Show
Ignore:
Timestamp:
12/29/07 16:36:29 (11 months ago)
Author:
michiel
Message:

Introduce input formats.
Supported right now: HTML, BBCode and MediaWiki?.

Re #105

Location:
trunk
Files:
205 added
1 removed
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/common/mvblog.php

    r751 r757  
    271271                                                <?php } ?> 
    272272                                                        <?php 
    273                                                         $text = $this->strip_invalid_xml(stripslashes($row["body"])); 
    274                                                         $text = $this->plugman->run_hooks("text_output", $text); 
     273                                                        $text = $this->plugman->run_hooks("text_output", $row["body_formatted"]); 
    275274                                                        if ($this->limit_text($text)) { 
    276275                                                                echo $text; 
     
    335334                        <?php 
    336335                } 
    337         } 
    338         /* }}} */ 
    339         /* strip_invalid_xml() {{{ */ 
    340         /** 
    341          * strip some stuff leftover from old editor 
    342          * 
    343          * @param string $data the text to process 
    344          * @return string the text with invalid xml stripped 
    345          */ 
    346         public function strip_invalid_xml($data) { 
    347                 $data = preg_replace("/ ref=\"[^\"].*\"/si", "", $data); 
    348                 return $data; 
    349336        } 
    350337        /* }}} */ 
     
    702689        } 
    703690        /* }}} */ 
    704         /* parse_bbcode($data) {{{ */ 
    705         /** 
    706          * Parse a string and intepret bbcode 
    707          * @license LGPL 
    708          * @author Justin Palmer 
    709          * @url http://www.isolated-disigns.net/core 
    710          * @author Ferry Boender 
    711          * 
    712          * @param string $data The raw string to do bbcode substitution on 
    713          * @return string the string with bbcode tags substituded 
    714          */ 
    715         public function parse_bbcode($data) { 
    716                 #     AUTHOR:  JUSTIN PALMER 
    717                 #     WEBSITE:  HTTP://WWW.ISOLATED-DESIGNS.NET/CORE 
    718                 #     LICENSE: GNU LESSER GENERAL PUBLIC LICENSE http://www.gnu.org/copyleft/lesser.html 
    719                 #     MODIFIED: Ferry Boender: optimized and function to strip bbcode 
    720                 /* Strip useless newlines so [code] will appear correct */ 
    721                 $string = str_replace("\r", "", $data); 
    722                 $string = str_replace("\n", "<br />", $string); 
    723  
    724                 $patterns = array( 
    725                         '`\[ul\](.+?)\[/ul\]`is', 
    726                         '`\[li\](.+?)\[/li\]`is', 
    727                         '`\[quote\](.+?)\[/quote\]`is', 
    728                         '`\[indent](.+?)\[/indent\]`is', 
    729                         '`\[code](.+?)\[/code\]`is', 
    730                         '`\[b\](.+?)\[/b\]`is', 
    731                         '`\[i\](.+?)\[/i\]`is', 
    732                         '`\[u\](.+?)\[/u\]`is', 
    733                         '`\[strike\](.+?)\[/strike\]`is', 
    734                         '`\[color=#([0-9]{6})\](.+?)\[/color\]`is', 
    735                         '`\[email\](.+?)\[/email\]`is', 
    736                         '`\[img\](.+?)\[/img\]`is', 
    737                         '`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si', 
    738                         '`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si', 
    739                         '`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si', 
    740                         '`\[flash=([0-9]+),([0-9]+)\](.+?)\[/flash\]`is', 
    741                         '`\[size=([1-6]+)\](.+?)\[/size\]`is' 
    742                 ); 
    743  
    744                 $replaces =  array( 
    745                         '<ul>\1</ul>', 
    746                         '<li class="noblock">\1</li>', 
    747                         '<span class="quote">\1</span>', 
    748                         '<pre>\\1</pre>', 
    749                         '<pre class="code">\\1</pre>', 
    750                         '<strong>\\1</strong>', 
    751                         '<em>\\1</em>', 
    752                         '<span style="border-bottom: 1px dotted">\\1</span>', 
    753                         '<strike>\\1</strike>', 
    754                         '<span style="color:#\1;">\2</span>', 
    755                         '<a href="mailto:\1">\1</a>', 
    756                         '<img src="\1" alt="" style="border:0px;" />', 
    757                         '<a href="\1\2">\6</a>', 
    758                         '<a href="\1\2">\1\2</a>', 
    759                         '<a href="http://\1">\1</a>', 
    760                         '<object width="\1" height="\2"><param name="movie" value="\3" /><embed src="\3" width="\1" height="\2"></embed></object>', 
    761                         '<h\1>\2</h\1>' 
    762                 ); 
    763  
    764                 $prev_string = ""; 
    765                 while ($prev_string != $string) { 
    766                         $prev_string = $string; 
    767                         $string = preg_replace($patterns, $replaces , $string); 
    768                 } 
    769                 return(stripslashes($string)); 
    770         } 
    771         /* }}} */ 
    772691        /* blog_show_login() {{{ */ 
    773692        /** 
  • trunk/common/mvblog_admin.php

    r735 r757  
    12231223                                <div class="log_post_body"> 
    12241224                                        <div class="log_post_normal"> 
    1225                                                 <?php echo stripslashes($row["body"]); ?> 
     1225                                                <?php echo $row["body_formatted"]; ?> 
    12261226                                        </div> 
    12271227                                </div> 
     
    12761276                        $post["mail_comments"]     = 1; 
    12771277                        $post["allowanoncomments"] = ($this->settings["allowanoncomments"])?1:0; 
     1278                        $post["postformat"]        = $this->settings["defaultpostformat"]; 
    12781279                } else { 
    12791280                        $res =& $this->db->query(sprintf("SELECT * FROM articles WHERE id = %d", $id)); 
     
    12921293                //put all known dossiers in $this->dossiers array 
    12931294                $this->_get_dossiers(); 
     1295                //only HTML and BBCODE can be handled by tinymce 
     1296                if (in_array($post["postformat"], array("HTML", "BBC")) && $this->settings["wysiwyg"]) 
     1297                        $autoload = 1; 
     1298                else 
     1299                        $autoload = 0; 
    12941300                ?> 
    12951301                <script language="javascript" type="text/javascript" src="../tiny_mce/tiny_mce_gzip.js"></script> 
    12961302                <script language="javascript" type="text/javascript"> 
    1297                 tinyMCE_GZ.init({ 
    1298                         plugins    : "spellchecker,inlinepopups,table,advhr,advimage,advlink,flash,paste,noneditable,contextmenu", 
    1299                         themes     : "advanced", 
    1300                         languages  : "en", 
    1301                         disk_cache : true, 
    1302                         debug      : false 
    1303                 }); 
     1303                        tinyMCE_GZ.init({ 
     1304                                plugins    : "spellchecker,inlinepopups,table,advhr,advimage,advlink,flash,paste,noneditable,contextmenu<?php echo ($post["postformat"] == "BBC")?",bbcode":""; ?>", 
     1305                                themes     : "advanced", 
     1306                                languages  : "en", 
     1307                                disk_cache : true, 
     1308                                debug      : false 
     1309                        }); 
    13041310                </script> 
    1305                 <script language="javascript" type="text/javascript" src="../common/tinymce_conf.js"></script> 
     1311                <?php 
     1312                echo sprintf("<script language=\"javascript\" type=\"text/javascript\" src=\"../common/tinymce_conf.js.php?mode=%s&autoload=%d\"></script>\n", 
     1313                        $post["postformat"], $autoload); 
     1314                ?> 
     1315                <script language="javascript" type="text/javascript" src="../common/tinymce_filemanager.js"></script> 
    13061316                <form name="blogpost" method="post" action="index.php"> 
    13071317                <input type="hidden" name="action" value="save_post" /> 
    13081318                <input type="hidden" name="post[id]" value="<?php echo $post["id"]; ?>" /> 
     1319                <input type="hidden" name="post[postformat]" value="<?php echo $post["postformat"]; ?>" /> 
    13091320                <div class="log_post"> 
    13101321                        <div class="log_post_head"> 
     
    13261337                        </div> 
    13271338                        <div class="log_post_body"> 
    1328                                 <textarea id="editor_area" name="post[body]" rows="10" cols="50" style="width: 100%"><?php echo stripslashes($post["body"]); ?></textarea> 
     1339                                <textarea id="editor_area" name="post[body]" rows="30" cols="50" style="width: 100%"><?php echo stripslashes($post["body"]); ?></textarea> 
    13291340                                <?php 
    1330  
     1341                                echo "<a href=\"#\" onclick=\"tinyMCE.execCommand('mceToggleEditor', false, 'editor_area');\">".gettext("Toggle WYSIWYG mode")."</a>"; 
     1342                                echo "<br />"; 
    13311343                                echo gettext("to limit this post on the frontpage, enter ##BREAKPOINT## in your post."); 
    13321344                                ?> 
     
    14401452                        $query .= sprintf(" WHERE id = %d", $post["id"]); 
    14411453                } else { 
    1442                         $query  = sprintf("INSERT INTO articles (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
     1454                        $query  = sprintf("INSERT INTO articles (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
    14431455                                $this->db_quote("title"), $this->db_quote("body"), $this->db_quote("authors_id"), $this->db_quote("categories_ids"), $this->db_quote("date"), $this->db_quote("active"), 
    1444                                 $this->db_quote("public"), $this->db_quote("aside"), $this->db_quote("mail_comments"), $this->db_quote("ping_sent"), $this->db_quote("tb_uri"), $this->db_quote("allowanoncomments"), $this->db_quote("dossier_id") 
     1456                                $this->db_quote("public"), $this->db_quote("aside"), $this->db_quote("mail_comments"), $this->db_quote("ping_sent"), $this->db_quote("tb_uri"), $this->db_quote("allowanoncomments"), $this->db_quote("dossier_id"), $this->db_quote("postformat") 
    14451457                        ); 
    1446                         $query .= sprintf("VALUES ('%s', '%s', %d, '%s', %d, %d, %d, %d, %d, %d, '%s', %d, %d)", 
     1458                        $query .= sprintf("VALUES ('%s', '%s', %d, '%s', %d, %d, %d, %d, %d, %d, '%s', %d, %d, '%s')", 
    14471459                                preg_quote(strip_tags($post["title"]), "'"), 
    14481460                                preg_quote($this->_strip_tags($post["body"]), "'"), 
     
    14521464                                $post["active"], $post["public"], (array_key_exists("aside", $post))?$post["aside"]:0, $post["mail_comments"], 0, 
    14531465                                preg_quote($post["tb_uri"], "'"), (array_key_exists("allowanoncomments", $post))?$post["allowanoncomments"]:0, 
    1454                                 (array_key_exists("dossier_id", $post))?$post["dossier_id"]:0 
     1466                                (array_key_exists("dossier_id", $post))?$post["dossier_id"]:0, 
     1467                                $post["postformat"] 
    14551468                        ); 
    14561469                } 
     
    17851798                                                </td> 
    17861799                                        </tr><tr> 
     1800                                                <td><?php echo gettext("default markup format"); ?></td> 
     1801                                                <td> 
     1802                                                        <select name="settings[defaultpostformat]"> 
     1803                                                                <option value="HTML"<?php if ($settings["defaultpostformat"] == "HTML") echo " selected=\"selected\""; ?>>HTML</option> 
     1804                                                                <option value="BBC"<?php if ($settings["defaultpostformat"] == "BBC") echo " selected=\"selected\""; ?>>BBCode</option> 
     1805                                                                <option value="MW"<?php if ($settings["defaultpostformat"] == "MW") echo " selected=\"selected\""; ?>>MediaWiki</option> 
     1806                                                        </select> 
     1807                                                </td> 
     1808                                        </tr><tr> 
     1809                                                <td><?php echo gettext("use WYSIWYG editor"); ?></td> 
     1810                                                <td> 
     1811                                                        <select name="settings[wysiwyg]"> 
     1812                                                                <option value="0"><?php echo gettext("no"); ?></option> 
     1813                                                                <option value="1"<?php if ($settings["wysiwyg"] == 1) echo " selected=\"selected\""; ?>><?php echo gettext("yes"); ?></option> 
     1814                                                        </select> 
     1815                                                </td> 
     1816                                        </tr><tr> 
    17871817                                                <td colspan="2">&nbsp;</td> 
    17881818                                        </tr><tr> 
  • trunk/common/mvblog_common.php

    r724 r757  
    387387        } 
    388388        /* }}} */ 
     389        /* strip_invalid_xml() {{{ */ 
     390        /** 
     391         * strip some stuff leftover from old editor 
     392         * 
     393         * @param string $data the text to process 
     394         * @return string the text with invalid xml stripped 
     395         */ 
     396        public function strip_invalid_xml($data) { 
     397                $data = preg_replace("/ ref=\"[^\"].*\"/si", "", $data); 
     398                return $data; 
     399        } 
     400        /* }}} */ 
     401        /* format parses */ 
     402        /* parse_body {{{ */ 
     403        /** 
     404         * Parse the body based on postformat. 
     405         * 
     406         * Supported formats with their processor: 
     407         * - BBC: bbcode - uses internal bbcode parser 
     408         * - HTML: html sourcecode - no processing is done 
     409         * - MW: MediaWiki sourcecode - uses PEAR::Text_Wiki_Mediawiki 
     410         * 
     411         * @param string $body The raw body data 
     412         * @param string $format The body format. 
     413         * @return string the formatted body. 
     414         */ 
     415        public function parse_body($body, $format) { 
     416                switch ($format) { 
     417                case "BBC": 
     418                        $body = $this->parse_bbcode($body); 
     419                        break; 
     420                case "MW": 
     421