]> git.mjollnir.org Git - s9y.git/commitdiff
Proper placing
authorgarvinhicking <garvinhicking>
Tue, 14 Nov 2006 09:23:16 +0000 (09:23 +0000)
committergarvinhicking <garvinhicking>
Tue, 14 Nov 2006 09:23:16 +0000 (09:23 +0000)
docs/NEWS
include/functions_images.inc.php
index.php
plugins/serendipity_event_nl2br/UTF-8/lang_de.inc.php
plugins/serendipity_event_nl2br/lang_de.inc.php
plugins/serendipity_event_nl2br/lang_en.inc.php
plugins/serendipity_event_nl2br/serendipity_event_nl2br.php
templates/default/admin/media_upload.tpl [new file with mode: 0644]

index 011d9bcb48622f43f93cf8749e87855aa86cadf4..2d5e15cbdafd9351ff03e1846360513238eec84b 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,10 @@
 Version 1.1 ()
 ------------------------------------------------------------------------
 
+    * Enhanced nl2br plugin so that it will NOT put breaks into pre-
+      defined tags like <pre>, <code> etc. Not enabled by default.
+      Thanks to Brendon K from the forums!
+
     * Portuguese translation update by Angel
 
     * Added functionality to reply to comments in the admin interface
index 420962dedc81734d6b18aeeaa92f0a26e0c8c037..98eb861fe8a81f9a9dc29ed9bf45b30f1422f414 100644 (file)
@@ -610,7 +610,7 @@ function serendipity_makeThumbnail($file, $directory = '', $size = false, $thumb
 
 
     $infile  = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $file;
-#    echo 'From: ' . $infile . '<br />';
+    echo 'From: ' . $infile . '<br />';
     if ($is_temporary) {
         $temppath = dirname($thumbname);
         if (!is_dir($temppath)) {
@@ -621,7 +621,7 @@ function serendipity_makeThumbnail($file, $directory = '', $size = false, $thumb
         $outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $f . '.' . $thumbname . '.' . $suf;
     }
     $serendipity['last_outfile'] = $outfile;
-#    echo 'To: ' . $outfile . '<br />';
+    echo 'To: ' . $outfile . '<br />';
 
     $fdim    = @serendipity_getimagesize($infile, '', $suf);
     if (isset($fdim['noimage'])) {
index a96437e6c020845664550fb7ec3221a585077f60..1c4916515a4aed8d31983ce20ac9fe751dd056b4 100644 (file)
--- a/index.php
+++ b/index.php
@@ -18,14 +18,15 @@ if ($global_debug) {
 // rules to handle archives.
 header('HTTP/1.0 200');
 
-if ($serendipity['expose_s9y']) {
-    header('X-Blog: Serendipity'); // Used for installer detection
-}
-
 // Session are needed to also remember an autologin user on the frontend
 ob_start();
 include('serendipity_config.inc.php');
 header('Content-Type: text/html; charset='. LANG_CHARSET);
+
+if ($serendipity['expose_s9y']) {
+    header('X-Blog: Serendipity'); // Used for installer detection
+}
+    
 if ($serendipity['CacheControl']) {
     if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2')) {
         header('Cache-Control: no-cache, pre-check=0, post-check=0');
index ba776fbe9f4567fbb83d384c2b7cf8bc6756ea13..9ae1b613875a4da93e43c391897198e052a32f3a 100644 (file)
@@ -1,4 +1,6 @@
 <?php # $Id$
 
-        @define('PLUGIN_EVENT_NL2BR_NAME',     'Textformatierung: NL2BR');
-        @define('PLUGIN_EVENT_NL2BR_DESC',     'Konvertiert Zeilenumbrüche zu HTML');
+@define('PLUGIN_EVENT_NL2BR_NAME',     'Textformatierung: NL2BR');
+@define('PLUGIN_EVENT_NL2BR_DESC',     'Konvertiert Zeilenumbrüche zu HTML');
+@define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS', 'Eine Liste von HTML-Tags, innerhalb derer keine Umbrüche konvertiert werden');
+@define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC', 'Konfigurationsvorschlag: "code,pre,geshi,textarea". Trennen Sie mehrere HTML-Tags mit Komma. Hinweis: Die eingegebenen Tags sind reguläre Ausdrücke!');
\ No newline at end of file
index 71d9a5ba14c2f0f464f8140497bb8464299d1060..a01b871ee6688ed8da10a3c09a21f448d9a047f3 100644 (file)
@@ -1,4 +1,6 @@
 <?php # $Id$
 
-        @define('PLUGIN_EVENT_NL2BR_NAME',     'Textformatierung: NL2BR');
-        @define('PLUGIN_EVENT_NL2BR_DESC',     'Konvertiert Zeilenumbrüche zu HTML');
+@define('PLUGIN_EVENT_NL2BR_NAME',     'Textformatierung: NL2BR');
+@define('PLUGIN_EVENT_NL2BR_DESC',     'Konvertiert Zeilenumbrüche zu HTML');
+@define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS', 'Eine Liste von HTML-Tags, innerhalb derer keine Umbrüche konvertiert werden');
+@define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC', 'Konfigurationsvorschlag: "code,pre,geshi,textarea". Trennen Sie mehrere HTML-Tags mit Komma. Hinweis: Die eingegebenen Tags sind reguläre Ausdrücke!');
\ No newline at end of file
index 39983962f427cd3734a1cc9349853e7178f86d02..d7dad42fbdfe5e5cc952825ec7b01c5497951012 100644 (file)
@@ -8,5 +8,6 @@
 
 @define('PLUGIN_EVENT_NL2BR_NAME',     'Markup: NL2BR');
 @define('PLUGIN_EVENT_NL2BR_DESC',     'Convert newlines to BR tags');
-
+@define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS', 'A list of HTML-tags where no breaks shall be converted');
+@define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC', 'Suggestion: "code,pre,geshi,textarea". Seperate multiple tags with a comma. Hint: The entered tags are evaluated as regular expressions.');
 ?>
index 60db21e4aa6bf3330e14e8f6332a1067331dd21a..8fe2e0111cd33ff8894e4394651df529741fafcc 100644 (file)
@@ -20,7 +20,7 @@ class serendipity_event_nl2br extends serendipity_event
         $propbag->add('description',   PLUGIN_EVENT_NL2BR_DESC);
         $propbag->add('stackable',     false);
         $propbag->add('author',        'Serendipity Team');
-        $propbag->add('version',       '1.3');
+        $propbag->add('version',       '1.5');
         $propbag->add('requirements',  array(
             'serendipity' => '0.8',
             'smarty'      => '2.6.7',
@@ -50,6 +50,7 @@ class serendipity_event_nl2br extends serendipity_event
         );
 
         $conf_array = array();
+        $conf_array[] = 'isolate';
         foreach($this->markup_elements as $element) {
             $conf_array[] = $element['name'];
         }
@@ -71,28 +72,75 @@ class serendipity_event_nl2br extends serendipity_event
 
     function introspect_config_item($name, &$propbag)
     {
-        $propbag->add('type',        'boolean');
-        $propbag->add('name',        constant($name));
-        $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
-        $propbag->add('default', 'true');
+        switch($name) {
+            case 'isolate':
+                $propbag->add('type',        'string');
+                $propbag->add('name',        PLUGIN_EVENT_NL2BR_ISOLATE_TAGS);
+                $propbag->add('description', PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC);
+                $propbag->add('default',     '');
+                break;
+
+            default:
+                $propbag->add('type',        'boolean');
+                $propbag->add('name',        constant($name));
+                $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
+                $propbag->add('default', 'true');
+        }
         return true;
     }
 
+    function isolate($src, $regexp = NULL) {
+        if($regexp) return preg_replace_callback($regexp, array($this, 'isolate'), $src);
+        global $_buf;
+        $_buf[] = $src[0];
+        return "\\001" . (count($_buf) - 1);
+    }
+
+    function restore($text) {
+        global $_buf;
+        return preg_replace('~\\001(\\d+)~e', '$_buf[$1]', $text);
+    }
+
     function event_hook($event, &$bag, &$eventData) {
         global $serendipity;
+        static $isolate = null;
+        global $_buf;
 
         $hooks = &$bag->get('event_hooks');
 
         if (isset($hooks[$event])) {
             switch($event) {
               case 'frontend_display':
+                if ($isolate === null) {
+                    $isolate = $this->get_config('isolate');
+                    $tags    = (array)explode(',', $isolate);
+                    $isolate = array();
+                    foreach($tags AS $tag) {
+                        $tag = trim($tag);
+                        if (!empty($tag)) {
+                            $isolate[] = $tag;
+                        }
+                    }
+                    if (count($isolate) < 1) {
+                        $isolate = false;
+                    }
+                }
 
                 foreach ($this->markup_elements as $temp) {
                     if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) &&
+                            !$eventData['properties']['ep_disable_markup_' . $this->instance] &&
+                            !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance]) &&
                             !$eventData['properties']['ep_no_nl2br'] &&
-                            !isset($serendipity['POST']['properties']['no_nl2br'])) {
+                            !isset($serendipity['POST']['properties']['ep_no_nl2br'])) {
+
                         $element = $temp['element'];
+                        if ($isolate) {
+                            $eventData[$element] = $this->isolate($eventData[$element], '~[<\\[](' . implode('|', $isolate) . ').*?[>\\]].*?[<\\[]/\\1[>\\]]~si');
+                        }
                         $eventData[$element] = nl2br($eventData[$element]);
+                        if ($isolate) {
+                            $eventData[$element] = $this->restore($eventData[$element]);
+                        }
                     }
                 }
                 return true;
diff --git a/templates/default/admin/media_upload.tpl b/templates/default/admin/media_upload.tpl
new file mode 100644 (file)
index 0000000..99fcd6d
--- /dev/null
@@ -0,0 +1,263 @@
+<div class="image_add_form">{$CONST.ADD_MEDIA_BLAHBLAH}</div>
+
+<script type="text/javascript">
+// Function prototype inspired by http://molily.de/javascript-nodelist
+function showNodes(n) {ldelim}
+    var html;
+    html = '<!--nodeset--><li>';
+
+    switch (n.nodeType) {ldelim}
+        case 1:
+            html += 'Type is <em>' + n.nodeName + '<\/em>';
+            if (n.hasChildNodes()) {ldelim}
+                ausgabe += ' - childNodes: ' + n.childNodes.length;
+            {rdelim}
+            break;
+
+        case 3:
+            var nval = n.nodeValue.replace(/</g, '&lt;').replace(/\n/g, '\\n');
+            html += 'Content: <strong>' + nval + '<\/strong>';
+            break;
+
+        case 8:
+            var nval = n.nodeValue.replace(/</g, '&lt;').replace(/\n/g, '\\n');
+            html += 'Hidden: <em>' + nval + '<\/em>';
+            break;
+
+        default:
+            html += 'Type is ' + n.nodeType + ', Content is <strong>' + n.nodeValue + '<\/strong>';
+    }
+
+    if (n.hasChildNodes()) {ldelim}
+        html += '\n<ol>\n';
+        for (i=0; i < n.childNodes.length; i++) {ldelim}
+            j = n.childNodes[i];
+            html += showNodes(j);
+        {rdelim}
+        html += '</ol>\n';
+    {rdelim}
+    html += '</li>\n';
+
+    return html;
+{rdelim}
+
+function getfilename(value) {ldelim}
+    re = /^.+[\/\\]+?(.+)$/;
+    return value.replace(re, "$1");
+{rdelim}
+
+isFileUpload = true;
+function hideForeign() {ldelim}
+    document.getElementById('foreign_upload').style.display = 'none';
+    document.getElementById('imageurl').value = '';
+    isFileUpload = false;
+{rdelim}
+
+var fieldcount = 1;
+function addField() {ldelim}
+    fieldcount++;
+
+    fields = document.getElementById('upload_template').cloneNode(true);
+    fields.id = 'upload_form_' + fieldcount;
+    fields.style.display = 'block';
+
+    // Get the DOM outline be uncommenting this:
+    //document.getElementById('debug').innerHTML = showNodes(fields);
+
+    // garvin: This gets a bit weird. Opera, Mozilla and IE all have their own numbering.
+    // We cannot operate on "ID" basis, since a unique ID is not yet set before instancing.
+    if (fields.childNodes[0].nodeValue == null) {ldelim}
+        // This is Internet Explorer, it does not have a linebreak as first element.
+        userfile       = fields.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0];
+        targetfilename = fields.childNodes[0].childNodes[0].childNodes[2].childNodes[1].childNodes[0];
+        targetdir      = fields.childNodes[0].childNodes[0].childNodes[3].childNodes[1].childNodes[0];
+        columncount    = fields.childNodes[1].childNodes[0];
+    {rdelim} else {ldelim}
+        // We have a browser which has \n's as their own nodes. Don't ask me. Now let's check if it's Opera or Mozilla.
+        if (fields.childNodes[1].childNodes[0].nodeValue == null) {ldelim}
+            // This is Opera.
+            userfile       = fields.childNodes[1].childNodes[0].childNodes[0].childNodes[1].childNodes[0];
+            targetfilename = fields.childNodes[1].childNodes[0].childNodes[2].childNodes[1].childNodes[0];
+            targetdir      = fields.childNodes[1].childNodes[0].childNodes[3].childNodes[1].childNodes[0];
+            columncount    = fields.childNodes[3].childNodes[0];
+        {rdelim} else if (fields.childNodes[1].childNodes[1].childNodes[0].childNodes[3] == null) {ldelim}
+               // This is Safari.
+            userfile       = fields.childNodes[1].childNodes[1].childNodes[0].childNodes[1].childNodes[0];
+            targetfilename = fields.childNodes[1].childNodes[1].childNodes[2].childNodes[1].childNodes[0];
+            targetdir      = fields.childNodes[1].childNodes[1].childNodes[3].childNodes[1].childNodes[0];
+            columncount    = fields.childNodes[3].childNodes[0];
+        {rdelim} else {ldelim}
+            // This is Mozilla.
+            userfile       = fields.childNodes[1].childNodes[1].childNodes[0].childNodes[3].childNodes[0];
+            targetfilename = fields.childNodes[1].childNodes[1].childNodes[4].childNodes[3].childNodes[0];
+            targetdir      = fields.childNodes[1].childNodes[1].childNodes[6].childNodes[3].childNodes[0];
+            columncount    = fields.childNodes[3].childNodes[0];
+        {rdelim}
+    {rdelim}
+
+    userfile.id   = 'userfile_' + fieldcount;
+    userfile.name = 'serendipity[userfile][' + fieldcount + ']';
+
+    targetfilename.id   = 'target_filename_' + fieldcount;
+    targetfilename.name = 'serendipity[target_filename][' + fieldcount + ']';
+
+    targetdir.id   = 'target_directory_' + fieldcount;
+    targetdir.name = 'serendipity[target_directory][' + fieldcount + ']';
+
+    columncount.id   = 'column_count_' + fieldcount;
+    columncount.name = 'serendipity[column_count][' + fieldcount + ']';
+
+    iNode = document.getElementById('upload_form');
+    iNode.parentNode.insertBefore(fields, iNode);
+
+    document.getElementById(targetdir.id).selectedIndex = document.getElementById('target_directory_' + (fieldcount - 1)).selectedIndex;
+{rdelim}
+
+var inputStorage = new Array();
+function checkInputs() {ldelim}
+    for (i = 1; i <= fieldcount; i++) {ldelim}
+        if (!inputStorage[i]) {ldelim}
+            fillInput(i, i);
+        {rdelim} else if (inputStorage[i] == document.getElementById('target_filename_' + i).value) {ldelim}
+            fillInput(i, i);
+        {rdelim}
+    {rdelim}
+
+{rdelim}
+
+function debugFields() {ldelim}
+    for (i = 1; i <= fieldcount; i++) {ldelim}
+        debugField('target_filename_' + i);
+        debugField('userfile_' + i);
+    {rdelim}
+{rdelim}
+
+function rememberOptions() {ldelim}
+    td     = document.getElementById('target_directory_2');
+    td_val = td.options[td.selectedIndex].value;
+    SetCookie("addmedia_directory", td_val);
+{rdelim}
+
+function debugField(id) {ldelim}
+    alert(id + ': ' + document.getElementById(id).value);
+{rdelim}
+
+function fillInput(source, target) {ldelim}
+    useDuplicate = false;
+
+    // First field is a special value for foreign URLs instead of uploaded files
+    if (source == 1 && document.getElementById('imageurl').value != "") {ldelim}
+        sourceval = getfilename(document.getElementById('imageurl').value);
+        useDuplicate = true;
+    {rdelim} else {ldelim}
+        sourceval = getfilename(document.getElementById('userfile_' + source).value);
+    {rdelim}
+
+    if (sourceval.length > 0) {ldelim}
+        document.getElementById('target_filename_' + target).value = sourceval;
+        inputStorage[target] = sourceval;
+    {rdelim}
+
+    // Display filename in duplicate form as well!
+    if (useDuplicate) {ldelim}
+        tkey = target + 1;
+
+        if (!inputStorage[tkey] || inputStorage[tkey] == document.getElementById('target_filename_' + tkey).value) {ldelim}
+            document.getElementById('target_filename_' + (target+1)).value = sourceval;
+            inputStorage[target + 1] = '~~~';
+        {rdelim}
+    {rdelim}
+{rdelim}
+</script>
+
+<form target="_blank" action="?" method="POST" id="uploadform" enctype="multipart/form-data" onsubmit="rememberOptions()">
+    <div>
+        {if $media.max_file_size}
+        <input type="hidden" name="MAX_FILE_SIZE" value="{$max_file_size}" />
+        {/if}
+        {$media.token}
+        <input type="hidden" name="serendipity[action]"      value="admin" />
+        <input type="hidden" name="serendipity[adminModule]" value="images" />
+        <input type="hidden" name="serendipity[adminAction]" value="add" />
+        {$media.form_hidden}
+        <table id="foreign_upload" class="image_add_foreign">
+            <tr>
+                <td nowrap="nowrap">{$CONST.ENTER_MEDIA_URL}</td>
+                <td><input type="text" id="imageurl" name="serendipity[imageurl]"
+                         onchange="checkInputs()"
+                          value=""
+                           size="40" /></td>
+            </tr>
+            <tr>
+                <td nowrap="nowrap">{$CONST.ENTER_MEDIA_URL_METHOD}</td>
+                <td>
+                    <select name="serendipity[imageimporttype]">
+                        <option value="image">{$CONST.FETCH_METHOD_IMAGE}</option>
+                        <option value="hotlink">{$CONST.FETCH_METHOD_HOTLINK}</option>
+                    </select>
+                </td>
+            </tr>
+
+            <tr>
+                <td align="center" colspan="2"><b> - {$CONST.WORD_OR} - </b></td>
+            </tr>
+        </table>
+
+        <!-- WARNING: Do not change spacing or breaks below. If you do, the JavaScript childNodes need to be edited. Newlines count as nodes! -->
+        <div id="upload_template">
+        <table style="margin-top: 35px" id="upload_table" class="image_add_local">
+            <tr>
+                <td nowrap='nowrap'>{$CONST.ENTER_MEDIA_UPLOAD}</td>
+                <td><input id="userfile_1" name="serendipity[userfile][1]"
+                         onchange="checkInputs();"
+                           type="file" /></td>
+            </tr>
+
+            <tr>
+                <td align="center" colspan="2"><br /></td>
+            </tr>
+
+            <tr>
+                <td>{$CONST.SAVE_FILE_AS}</td>
+                <td><input type="text" id="target_filename_1" name="serendipity[target_filename][1]" value="" size="40" /></td>
+            </tr>
+
+            <tr>
+                <td>{$CONST.STORE_IN_DIRECTORY}</td>
+                <td><select id="target_directory_1" name="serendipity[target_directory][1]">
+                    <option value="">{$CONST.BASE_DIRECTORY}</option>
+                    {foreach from=$media.folders item="folder"}
+                    <option {if $media.only_path == $folder.relpath}selected="selected"{/if} value="{$folder.relpath}">{'&nbsp;'|@str_repeat:$folder.depth*2} {$folder.name}</option>
+                    {/foreach}
+                    </select>
+                </td>
+            </tr>
+       </table>
+       <div id="ccounter"><input type="hidden" name="serendipity[column_count][1]" id="column_count_1" value="true" /></div>
+       </div>
+
+       <div id="debug">
+       </div>
+
+       <script type="text/javascript">
+            document.getElementById('upload_template').style.display  = 'none';
+            document.write('<span id="upload_form"><' + '/span>');
+            addField();
+       </script>
+
+        {serendipity_hookPlugin hook="backend_image_addform" hookAll=true}
+
+        <div style="text-align: center; margin-top: 15px; margin-bottom: 15px">
+            <script type="text/javascript">
+                document.write('<input class="serendipityPrettyButton" type="button" value="{$CONST.IMAGE_MORE_INPUT}" onclick="hideForeign(); addField()"' + '/><br' + '/>');
+            </script>
+            <input type="hidden" name="serendipity[all_authors]" value="true" checked="checked" id="all_authors" />
+            <br />
+            <input onclick="checkInputs();" type="submit" value="{$CONST.GO}" class="serendipityPrettyButton" />
+            - {$CONST.WORD_OR} -
+            <input onclick="checkInputs();" name="go_properties" type="submit" value="{$CONST.GO_ADD_PROPERTIES|@escape}" class="serendipityPrettyButton" />
+        </div>
+    </div>
+    <div class="image_add_note">{$CONST.ADD_MEDIA_BLAHBLAH_NOTE}</div>
+</form>
+