diff --git a/main/inc/lib/fckeditor/fckeditor.php b/main/inc/lib/fckeditor/fckeditor.php index 994ff85e02..a6df8b14e7 100644 --- a/main/inc/lib/fckeditor/fckeditor.php +++ b/main/inc/lib/fckeditor/fckeditor.php @@ -546,17 +546,84 @@ class FCKeditor else $bFirst = false ; + /* if ( $sValue === true ) $sParams .= $this->EncodeConfig( $sKey ) . '=true' ; else if ( $sValue === false ) $sParams .= $this->EncodeConfig( $sKey ) . '=false' ; else $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ; + */ + + if ( is_string( $sValue ) ) { + $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ; + } else { + $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $this->to_js( $sValue ) ) ; + } } return $sParams ; } + /** + * Encode characters that may break the configuration string + * generated by GetConfigFieldString(). + * + * @access protected + * @param string $valueToEncode + * @return string + */ + public function EncodeConfig( $valueToEncode ) + { + $chars = array( + '&' => '%26', + '=' => '%3D', + '"' => '%22' ) ; + + return strtr( $valueToEncode, $chars ) ; + } + + /** + * Converts a PHP variable into its Javascript equivalent. + * The code of this method has been "borrowed" from the funcion drupal_to_js() within the Drupal CMS. + * @param mixed $var The variable to be converted into Javascript syntax + * @return string Returns a string + * Note: This function is similar to json_encode(), in addition it produces HTML-safe strings, i.e. with <, > and & escaped. + * @link http://drupal.org/ + */ + public function to_js( $var ) { + switch ( gettype( $var ) ) { + case 'boolean' : + return $var ? 'true' : 'false' ; // Lowercase necessary! + case 'integer' : + case 'double' : + return (string) $var ; + case 'resource' : + case 'string' : + return '"' . str_replace( array( "\r", "\n", "<", ">", "&" ), array( '\r', '\n', '\x3c', '\x3e', '\x26' ), addslashes( $var ) ) . '"' ; + case 'array' : + // Arrays in JSON can't be associative. If the array is empty or if it + // has sequential whole number keys starting with 0, it's not associative + // so we can go ahead and convert it as an array. + if ( empty( $var ) || array_keys( $var ) === range( 0, sizeof( $var ) - 1 ) ) { + $output = array() ; + foreach ( $var as $v ) { + $output[] = $this->to_js( $v ) ; + } + return '[ ' . implode( ', ', $output ) . ' ]' ; + } + // Otherwise, fall through to convert the array as an object. + case 'object' : + $output = array() ; + foreach ( $var as $k => $v ) { + $output[] = $this->to_js( strval( $k ) ) . ': ' . $this->to_js( $v ) ; + } + return '{ ' . implode(', ', $output) . ' }' ; + default: + return 'null' ; + } + } + /* * Checks whether a given url exists. * @@ -565,7 +632,6 @@ class FCKeditor * * @author Ivan Tcholakov, FEB-2009 */ - private function url_exists($url, $timeout = 30) { $parsed = parse_url($url); @@ -595,22 +661,4 @@ class FCKeditor @fclose($fp); return $file_exists; } - - /** - * Encode characters that may break the configuration string - * generated by GetConfigFieldString(). - * - * @access protected - * @param string $valueToEncode - * @return string - */ - public function EncodeConfig( $valueToEncode ) - { - $chars = array( - '&' => '%26', - '=' => '%3D', - '"' => '%22' ) ; - - return strtr( $valueToEncode, $chars ) ; - } }