HTMLエディタで画像を挿入しようとすると$httpsrequiredがundefined

HTMLエディタで画像を挿入しようとすると$httpsrequiredがundefined

by Tatsuya Shirai -
Number of replies: 2

 いつからこのエラーが出るようになったのか,多分,2009/06/10頃のバージョンからだと思います.

 添付ファイルのように$httpsrequiredがUndefinedであるというエラーが出ます.

 lib/editor/htmlarea/popups/insert_image.phpに,以下のコードが追加されています.

    if ($httpsrequired or (!empty($_SERVER['HTTPS']) and $_SERVER['HTTPS'] != 'off')) {
        $url = preg_replace('|https?://[^/]+|', '', $CFG->wwwroot).'/lib/editor/htmlarea/';
    } else {
        $url = $CFG->wwwroot.'/lib/editor/htmlarea/';
    }

この頭のところの$httpsrequiredですね.これが宣言されていない.その結果,$urlが空になってしまい,その後の処理に不具合が発生します.

 自分自身は画像の挿入をまったく使わないので気付きませんでした.

 対策ですが...moodlelib.php中のfunction httpsrequired()で,グローバル変数$HTTPSPAGEREQUIREDを設定しています.一つはこれを利用する手ですね.lib/weblib.php,filelib.php, moodlelib.php, ajax/ajaxlib.php, mod/forum/lib.php中の関数ではこのグローバル変数を利用している箇所がいつくかあります.
 それに対して,lib/editor/htmlarea中,特にhtmlarea.phpでは,

    $httpsrequired = optional_param('httpsrequired', 0, PARAM_BOOL); //flag indicating editor on page with required https

でパラメータとして受け取り,

    if ($httpsrequired or (!empty($_SERVER['HTTPS']) and $_SERVER['HTTPS'] != 'off')) {
        $url = preg_replace('|https?://[^/]+|', '', $CFG->wwwroot).'/lib/editor/htmlarea/';
    } else {
        $url = $CFG->wwwroot.'/lib/editor/htmlarea/';
    }

このように処理に利用しています.って,このコード,今回問題になっているinsert_image.phpと全く同じですね.うーん,

        // this is an ugly hack to allow partial operation of editor on pages that require https when loginhttps enabled
        // please note that some popups still show nonsecurre items and fullscreen may not function properly in IE

あまつえ同じ2009/06/10のバージョンで上記警告のコメントを削除している.このパラメータで渡すという方法を良しとしたということでしょうか?

Attachment httpsrequired.jpg
Maximum rating: -
In reply to Tatsuya Shirai

Re: HTMLエディタで画像を挿入しようとすると$httpsrequiredがundefined

by Tatsuya Shirai -

 function httpsrequired()は,ログイン時にのみhttpsを用いるかどうかをチェックするためのものですので,ここでhttpsrequired()を実行して$HTTPSPAGEREUIREDを参照するのは不適切ですね.

 設定されて呼ばれるかどうか不明なパラメータであるoptional_param('httpsrequired', 0, PARAM_BOOL)を挿入してエラーが発生しないようにするのが無難でしょうか.
 もしフルにhttpsを利用する環境であるならば,多分,$_SERVER['HTTPS']が設定されているのでしょう.

 そのように考え,lib/editor/htmlarea/popups/insert_image.phpに,以下のような修正を施しました.

 <?php // $Id: insert_image.php,v 1.9.8.2 2009/06/09 04:58:39 jonathanharker Exp $

    require("../../../../config.php");

    $id = optional_param('id', SITEID, PARAM_INT);
// (Debug025): HTMLエディタで画像の挿入が正常に行えないバグの修正 (2009/08/19)
// (Debug025): ここから追加
    $httpsrequired = optional_param('httpsrequired', 0, PARAM_BOOL); //flag indicating editor on page with required https
// (Debug025): ここまで追加

    require_login($id);
    require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id));

    @header('Content-Type: text/html; charset=utf-8');

    if ($httpsrequired or (!empty($_SERVER['HTTPS']) and $_SERVER['HTTPS'] != 'off')) {
        $url = preg_replace('|https?://[^/]+|', '', $CFG->wwwroot).'/lib/editor/htmlarea/';
    } else {
        $url = $CFG->wwwroot.'/lib/editor/htmlarea/';
    }

これからTrackerに報告します.