Adding CKEditor to News Management - saving in DB correctly

Discussion in 'General Support' started by Grinfeld, Mar 27, 2015.

  1. Grinfeld

    Grinfeld Member

    Joined:
    Apr 8, 2012
    Messages:
    66
    Likes Received:
    4
    Hello to all,

    I have added CKEditor to News Management replacing the text area in addnew.tpl (Webid 1.0.3) via the following script:

    <td><textarea name="content[{lang.LANG}]" id="content[{lang.LANG}]" cols="45" rows="20">{lang.CONTENT}</textarea>
    <script>
    // Replace the <textarea id="content[{lang.LANG}]"> with a CKEditor
    // instance, using default configuration.
    CKEDITOR.replace( 'content[{lang.LANG}]' );
    </script>
    </td>

    It works great in News Management. It saves in DB but not in html as I need.
    QUESTION: What code should I add in addnew.php for CKEditor to save in DB correctly?

    Thanks a lot,
    Mario Grinfeld
     
  2. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    62
    you could of just added the CKEditer in the php page that makes the news so your not using a <script> so it would be something like this.

    PHP:
    include $main_path 'ckeditor/ckeditor.php';

    $CKEditor = new CKEditor();
    $CKEditor->basePath $system->SETTINGS['siteurl'] . 'inc/ckeditor/';
    $CKEditor->returnOutput true;
    $CKEditor->config['width'] = 550;
    $CKEditor->config['height'] = 400;

    foreach (
    $LANGUAGES as $k => $language)
    {
        
    $template->assign_block_vars('lang', array(
                
    'LANG' => $language,
                
    'TITLE' => (isset($_POST['title'][$k])) ? $_POST['title'][$k] : '',
                
    'CONTENT' => $CKEditor->editor('content[' $k ']'$_POST['content'][$k]) 
                ));
    }

    so nothing should not need to change in the tpl page and in the viewnews.php just change 1 code

    find this
    PHP:
    'CONT' => nl2br($content)
    replace with
    PHP:
    'CONT' => $content
     
  3. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    I suspect your $_POST['content'][$k] on line 39 in admin/addnew.php is passing through htmLawed

    PHP:
    $_POST['content'][$k] = htmLawed($_POST['content'][$k], $conf);
    This would be filtering and removing all html elements.
    Just blank it out like this
    PHP:
    //$_POST['content'][$k] = htmLawed($_POST['content'][$k], $conf);
    The content passes through mysql_real_escape_string so it is filtered/prepared for the database
    To show it I would try line 63

    PHP:
     'CONTENT' => (isset($_POST['content'][$k])) ? stripslashes($_POST['content'][$k]) : ''
    Or leave as is if that causes problems.
     
  4. Grinfeld

    Grinfeld Member

    Joined:
    Apr 8, 2012
    Messages:
    66
    Likes Received:
    4
    Thank you Jason and Pani for your replies. I tried both. No one is working. I am certainly missing something somewhere... I am attaching two files
    • admin/addnew.php
    • viewnews.php

    Those files are as I have them now in my server working with the addition of CKEditor via the replacement in addnew.tpl as follows:

    HTML:
    <td><textarea name="content[{lang.LANG}]" id="content[{lang.LANG}]" cols="45" rows="20">{lang.CONTENT}</textarea>
                                <script>
                                // Replace the <textarea id="content[{lang.LANG}]"> with a CKEditor
                                // instance, using default configuration.
                                CKEDITOR.replace( 'content[{lang.LANG}]' );
                                </script>
                                </td>
    This way is working but it saves in the Data Base in plain text and not in html code as I need... as a result it displays in browser as html code... if I change manually the text in the DB into html code then it displays OK in the browser.

    I think by looking at the complete files you may be able to advise me. I apreciatte your help,
     

    Attached Files:

    Last edited by a moderator: Mar 29, 2015
  5. nay27uk

    nay27uk Super Moderator Staff Member

    Joined:
    Nov 24, 2009
    Messages:
    5,573
    Likes Received:
    550
    MODERATOR NOTE

    Grinfeld
    could you please put any code you post in the forums relevant CODE TAGS depending on the kind of code being posted?

    If posting PHP code please use the PHP tags
    If posting HTML code like you have in the post above, then please use HTML tags

    To do this when you make a post click on the GO ADVANCED button and then select all of your posted CODE to highlight it and then click on the relevant icon in the editor tool bar (hovering each icon will show a Tool Tip explaining what it does).

    I will edit your above post for you so you can see what it should be posted like, in future could you please use relevant code tags.

    Thanks
     
    Last edited: Mar 29, 2015
  6. Grinfeld

    Grinfeld Member

    Joined:
    Apr 8, 2012
    Messages:
    66
    Likes Received:
    4
    Yes Nay27UK I certainly will. Thank you for the explanation and the editing.
     

Share This Page