Mantisのプラグインを作ってみる。(コメントへの画像貼り付け機能)その2

前回の続きです。

■改造で作った変換や画像の拡大縮小についての部分

  /**
   * return an href anchor that links to a bug COMMENT page for the given images uploaded
   * @param int $p_image_id
   * @return string
   */
  function string_get_bug_image_link( $match = null ) {
    $p_image_id = empty($match[2]) === false ? $match[2] : null;
    //error_log('$match'.print_r($match,true),3,'/tmp/test.log');
    preg_match('/^,rate(\d+).*/',$match[3],$match_rate);
    $p_image_rate = empty($match_rate[1]) === false ? 'width:'.($match_rate[1] * 0.7).'%;'  : null;
    //error_log('$match_rate:'.print_r($match_rate,true),3,'/tmp/test.log');
  
    $security_param  = form_security_param( 'file_show_inline' );
    $image_link      = <<< _HTML_
  
     
   
_HTML_; return $image_link; } // f string_get_bug_image_link /** * return an href anchor that links to a bug COMMENT page for the given images uploaded * @param int $p_image_id * @return string */ function string_process_image_link( $p_string){ $p_string = preg_replace_callback( '/(^|[^\w])' . preg_quote( '%[', '/' ) . '(\d+)'.preg_quote( ']', '/' ).'(.*)\b/','string_get_bug_image_link',$p_string ); return $p_string ; } // f string_process_image_link

これを追加したときに下記のエラーが出ました。

SYSTEM WARNING: 'preg_replace_callback(): Requires argument 2, 'string_get_bug_image_link', to be a valid callback' in '(略)/mantis/plugins/ImagePasteOnComment/ImagePasteOnComment.php' line 57

どうやらCallbackはクラス内で使うときに書き方があるみたいです。

  function string_process_image_link( $p_string){
    $p_string = preg_replace_callback( '/(^|[^\w])' . preg_quote( '%[', '/' ) . '(\d+)'.preg_quote( ']', '/' ).'(.*)\b/',array($this,'string_get_bug_image_link'),$p_string );
        return $p_string ;
  } // f string_process_image_link

呼び出したい関数名を配列に入れるっていう事らしいです。
参考にしたのは下記のページです。

PHP :: コールバック関数