Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
844 views
in Plugins by

Hello! Installed question2answer 1.8.6 and updated CKEditor to 4.16.1. But I get errors when I try to insert an image by dragging and dropping.

 In this case, the picture is uploaded to the server and i can refer to it by the link. 

For some reason, CKEditor cannot get this link from the response. I think this is because this response is for an image to be inserted after clicking the "Send it to the Server" button on the Image tool dialog box. Please, tell me the solution to this problem.

RESPONSE:

<script>window.parent.CKEDITOR.tools.callFunction('', 'http:\/\/eps-1\/\/?qa=blob&qa_blobid=7123883946732752134', '');</script>

ERRORS in console:

"[CKEDITOR] Error code: filetools-response-error." Object { responseText: "<script>window.parent.CKEDITOR.tool…" } ckeditor.js:21:160

"[CKEDITOR] For more information about this error go to https://ckeditor.com/docs/ckeditor4/latest/guide/dev_errors.html#filetools-response-error" ckeditor.js:21:255

Q2A version: 1.8.6

1 Answer

0 votes
by

Hello. I found the solution to this problem myself. In the file "qa-wysiwyg-upload.php" needs to make the following changes:

public function process_request($request)
    {
        $message = '';
        $url = '';

        if (is_array($_FILES) && count($_FILES)) {
            if (qa_opt('wysiwyg_editor_upload_images')) {
                require_once QA_INCLUDE_DIR . 'app/upload.php';

                $onlyImage = qa_get('qa_only_image');
                $upload = qa_upload_file_one(
                    qa_opt('wysiwyg_editor_upload_max_size'),
                    $onlyImage || !qa_opt('wysiwyg_editor_upload_all'),
                    $onlyImage ? 600 : null, // max width if it's an image upload
                    null // no max height
                );

                if (isset($upload['error'])) {
                    $message = $upload['error'];
                } else {
                    $url = $upload['bloburl'];
                }
            } else {
                $message = qa_lang('users/no_permission');
            }
        }
      
  //For drag and drop    
    
      if (qa_js(qa_get('CKEditorFuncNum')) == 1) {
      echo sprintf(
            '<script>window.parent.CKEDITOR.tools.callFunction(%s, %s, %s);</script>',
            qa_js(qa_get('CKEditorFuncNum')),
            qa_js($url),
            qa_js($message)
        );
        
      } else {
       
      $jdat = array (
      'uploaded' => 1,
      'fileName' => $upload['blobid'].".".$upload['format'],
      'url' => $url,
      'error' => $message
      );
      echo json_encode($jdat); }

   
        return null;
    }


I do not know how to get a value for the Uploaded variable, so I left 1 as default. Also I did not find how to display messages when mistaken. But the picture is load with drag and drop and with the Image tool dialog box.

...