Changeset 754

Show
Ignore:
Timestamp:
12/28/07 21:58:46 (11 months ago)
Author:
michiel
Message:

introduce input formats for the admin backend.
Right now only BBCode and HTML are supported.
The setting for WYSIWYG is not implemented correctly yet.

Had to move around some functions for this.

Re #105

Location:
team/michiel/input_formats
Files:
5 added
4 modified

Legend:

Unmodified
Added
Removed
  • team/michiel/input_formats/common/mvblog.php

    r753 r754  
    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        /** 
  • team/michiel/input_formats/common/mvblog_admin.php

    r736 r754  
    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)); 
     
    12951296                <script language="javascript" type="text/javascript" src="../tiny_mce/tiny_mce_gzip.js"></script> 
    12961297                <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                 }); 
     1298                        tinyMCE_GZ.init({ 
     1299                                plugins    : "spellchecker,inlinepopups,table,advhr,advimage,advlink,flash,paste,noneditable,contextmenu<?php echo ($post["postformat"] == "BBC")?",bbcode":""; ?>", 
     1300                                themes     : "advanced", 
     1301                                languages  : "en", 
     1302                                disk_cache : true, 
     1303                                debug      : false 
     1304                        }); 
    13041305                </script> 
    1305                 <script language="javascript" type="text/javascript" src="../common/tinymce_conf.js"></script> 
     1306                <?php 
     1307                switch ($post["postformat"]) { 
     1308                case "HTML" : 
     1309                        echo "<script language=\"javascript\" type=\"text/javascript\" src=\"../common/tinymce_conf.js\"></script>\n"; 
     1310                        break; 
     1311                case "BBC" : 
     1312                        echo "<script language=\"javascript\" type=\"text/javascript\" src=\"../common/tinymce_bbcode_conf.js\"></script>\n"; 
     1313                        break; 
     1314                } 
     1315                ?> 
     1316                <script language="javascript" type="text/javascript" src="../common/tinymce_filemanager.js"></script> 
    13061317                <form name="blogpost" method="post" action="index.php"> 
    13071318                <input type="hidden" name="action" value="save_post" /> 
    13081319                <input type="hidden" name="post[id]" value="<?php echo $post["id"]; ?>" /> 
     1320                <input type="hidden" name="post[postformat]" value="<?php echo $post["postformat"]; ?>" /> 
    13091321                <div class="log_post"> 
    13101322                        <div class="log_post_head"> 
     
    13261338                        </div> 
    13271339                        <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> 
     1340                                <textarea id="editor_area" name="post[body]" rows="30" cols="50" style="width: 100%"><?php echo stripslashes($post["body"]); ?></textarea> 
    13291341                                <?php 
    1330  
     1342                                echo "<a href=\"#\" onclick=\"tinyMCE.execCommand('mceToggleEditor', false, 'editor_area');\">".gettext("Toggle WYSIWYG mode")."</a>"; 
     1343                                echo "<br />"; 
    13311344                                echo gettext("to limit this post on the frontpage, enter ##BREAKPOINT## in your post."); 
    13321345                                ?> 
     
    14401453                        $query .= sprintf(" WHERE id = %d", $post["id"]); 
    14411454                } else { 
    1442                         $query  = sprintf("INSERT INTO articles (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
     1455                        $query  = sprintf("INSERT INTO articles (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
    14431456                                $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") 
     1457                                $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") 
    14451458                        ); 
    1446                         $query .= sprintf("VALUES ('%s', '%s', %d, '%s', %d, %d, %d, %d, %d, %d, '%s', %d, %d)", 
     1459                        $query .= sprintf("VALUES ('%s', '%s', %d, '%s', %d, %d, %d, %d, %d, %d, '%s', %d, %d, '%s')", 
    14471460                                preg_quote(strip_tags($post["title"]), "'"), 
    14481461                                preg_quote($this->_strip_tags($post["body"]), "'"), 
     
    14521465                                $post["active"], $post["public"], (array_key_exists("aside", $post))?$post["aside"]:0, $post["mail_comments"], 0, 
    14531466                                preg_quote($post["tb_uri"], "'"), (array_key_exists("allowanoncomments", $post))?$post["allowanoncomments"]:0, 
    1454                                 (array_key_exists("dossier_id", $post))?$post["dossier_id"]:0 
     1467                                (array_key_exists("dossier_id", $post))?$post["dossier_id"]:0, 
     1468                                $post["postformat"] 
    14551469                        ); 
    14561470                } 
     
    17851799                                                </td> 
    17861800                                        </tr><tr> 
     1801                                                <td><?php echo gettext("default markup format"); ?></td> 
     1802                                                <td> 
     1803                                                        <select name="settings[defaultpostformat]"> 
     1804                                                                <option value="HTML"<?php if ($settings["defaultpostformat"] == "HTML") echo " selected=\"selected\""; ?>>HTML</option> 
     1805                                                                <option value="BBC"<?php if ($settings["defaultpostformat"] == "BBC") echo " selected=\"selected\""; ?>>BBCode</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> 
  • team/michiel/input_formats/common/mvblog_common.php

    r726 r754  
    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         * 
     410         * @param string $body The raw body data 
     411         * @param string $format The body format. 
     412         * @return string the formatted body. 
     413         */ 
     414        public function parse_body($body, $format) { 
     415                switch ($format) { 
     416                case "BBC": 
     417                        $body = $this->parse_bbcode($body); 
     418                        break; 
     419                } 
     420                //fix leftovers from old editor 
     421                $body = $this->strip_invalid_xml(stripslashes($body)); 
     422                return $body; 
     423        } 
     424        /* }}} */ 
     425        /* parse_bbcode($data) {{{ */ 
     426        /** 
     427         * Parse a string and intepret bbcode 
     428         * @license LGPL 
     429         * @author Justin Palmer 
     430         * @url http://www.isolated-disigns.net/core 
     431         * @author Ferry Boender 
     432         * 
     433         * @param string $data The raw string to do bbcode substitution on 
     434         * @return string the string with bbcode tags substituded 
     435         */ 
     436        public function parse_bbcode($data) { 
     437                #     AUTHOR:  JUSTIN PALMER 
     438                #     WEBSITE:  HTTP://WWW.ISOLATED-DESIGNS.NET/CORE 
     439                #     LICENSE: GNU LESSER GENERAL PUBLIC LICENSE http://www.gnu.org/copyleft/lesser.html 
     440                #     MODIFIED: Ferry Boender: optimized and function to strip bbcode 
     441                /* Strip useless newlines so [code] will appear correct */ 
     442                $string = str_replace("\r", "", $data); 
     443                $string = str_replace("\n", "<br />", $string); 
     444 
     445                $patterns = array( 
     446                        '`\[ul\](.+?)\[/ul\]`is', 
     447                        '`\[li\](.+?)\[/li\]`is', 
     448                        '`\[quote\](.+?)\[/quote\]`is', 
     449                        '`\[indent](.+?)\[/indent\]`is', 
     450                        '`\[code](.+?)\[/code\]`is', 
     451                        '`\[b\](.+?)\[/b\]`is', 
     452                        '`\[i\](.+?)\[/i\]`is', 
     453                        '`\[u\](.+?)\[/u\]`is', 
     454                        '`\[strike\](.+?)\[/strike\]`is', 
     455                        '`\[color=#([0-9]{6})\](.+?)\[/color\]`is', 
     456                        '`\[email\](.+?)\[/email\]`is', 
     457                        '`\[img\](.+?)\[/img\]`is', 
     458                        '`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si', 
     459                        '`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si', 
     460                        '`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si', 
     461                        '`\[flash=([0-9]+),([0-9]+)\](.+?)\[/flash\]`is', 
     462                        '`\[size=([1-6]+)\](.+?)\[/size\]`is' 
     463                ); 
     464 
     465                $replaces =  array( 
     466                        '<ul>\1</ul>', 
     467                        '<li class="noblock">\1</li>', 
     468                        '<span class="quote">\1</span>', 
     469                        '<pre>\\1</pre>', 
     470                        '<pre class="code">\\1</pre>', 
     471                        '<strong>\\1</strong>', 
     472                        '<em>\\1</em>', 
     473                        '<span style="border-bottom: 1px dotted">\\1</span>', 
     474                        '<strike>\\1</strike>', 
     475                        '<span style="color:#\1;">\2</span>', 
     476                        '<a href="mailto:\1">\1</a>', 
     477                        '<img src="\1" alt="" style="border:0px;" />', 
     478                        '<a href="\1\2">\6</a>', 
     479                        '<a href="\1\2">\1\2</a>', 
     480                        '<a href="http://\1">\1</a>', 
     481                        '<object width="\1" height="\2"><param name="movie" value="\3" /><embed src="\3" width="\1" height="\2"></embed></object>', 
     482                        '<h\1>\2</h\1>' 
     483                ); 
     484 
     485                $prev_string = ""; 
     486                while ($prev_string != $string) { 
     487                        $prev_string = $string; 
     488                        $string = preg_replace($patterns, $replaces , $string); 
     489                } 
     490                return(stripslashes($string)); 
     491        } 
     492        /* }}} */ 
    389493        /* data getters */ 
    390494        /* _get_settings {{{ */ 
     
    408512                $settings["dbversion"]         = 0; 
    409513                $settings["show_cat_icons"]    = 0; 
     514                $settings["defaultpostformat"] = "HTML"; 
     515                $settings["wysiwyg"]           = 0; 
    410516 
    411517                while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { 
     
    744850                        while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { 
    745851                                if (array_key_exists("replace_references", $options) && $options["replace_references"] == 1) { 
    746                                         $row["body"] = $this->replace_num_ref($row["body"]); 
    747                                         $row["body"] = $this->replace_dossier_ref($row["body"]); 
     852                                        $row["body_formatted"] = $this->replace_num_ref($row["body"]); 
     853                                        $row["body_formatted"] = $this->replace_dossier_ref($row["body_formatted"]); 
     854                                } else { 
     855                                        $row["body_formatted"] = $row["body"]; 
    748856                                } 
     857                                // parse body according to postformat 
     858                                $row["body_formatted"] = $this->parse_body($row["body_formatted"], $row["postformat"]); 
    749859                                $posts["posts"][$i] = $row; 
    750860                                $i++; 
  • team/michiel/input_formats/common/tinymce_conf.js

    r736 r754  
    11tinyMCE.init({ 
    2         mode                               : "exact", 
     2        mode                               : "none", 
    33        elements                           : "editor_area", 
    44        theme                              : "advanced", 
     
    2424        height                             : "420" 
    2525}); 
    26  
    27 function ajaxfilemanager(field_name, url, type, win) { 
    28         var ajaxfilemanagerurl = "../../../tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php"; 
    29         switch (type) { 
    30                 case "image": 
    31                         ajaxfilemanagerurl += "?type=img"; 
    32                         break; 
    33                 case "media": 
    34                         ajaxfilemanagerurl += "?type=media"; 
    35                         break; 
    36                 case "flash": //for older versions of tinymce 
    37                         ajaxfilemanagerurl += "?type=media"; 
    38                         break; 
    39                 case "file": 
    40                         ajaxfilemanagerurl += "?type=files"; 
    41                         break; 
    42                 default: 
    43                         return false; 
    44         } 
    45         var fileBrowserWindow = new Array(); 
    46         fileBrowserWindow["file"]           = ajaxfilemanagerurl; 
    47         fileBrowserWindow["title"]          = "TinyMCE Ajax File Manager"; 
    48         fileBrowserWindow["width"]          = "782"; 
    49         fileBrowserWindow["height"]         = "440"; 
    50         fileBrowserWindow["close_previous"] = "no"; 
    51         tinyMCE.openWindow(fileBrowserWindow, { 
    52                 window    : win, 
    53                 input     : field_name, 
    54                 resizable : "yes", 
    55                 inline    : "yes", 
    56                 editor_id : tinyMCE.getWindowArg("editor_id") 
    57         }); 
    58  
    59         return false; 
    60 } 
    61