Update requirements for json_encode()

Algebraist - October 29, 2009 - 17:10
Project:Image Browser
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Algebraist
Status:needs work
Description

I've installed and configured Imagebrowser to use the WYSIWYG-API with FCK-Editor 2.6.5 on drupal 6.14. Everything works fine, except the final step. I created a new input format that uses only the Image Browser Filter. Than I configured the FCKEditor Profile to show only the button for the image browser.

So I can create a new page and choose my new input format. The FCK comes up with the imagebrowser button. I hit the button and the imagebrowser shows up with my images. I can choose an image and set all options. But finally when I hit 'Insert', nothing happens, the image browser stays open and no image is inserted. 'Cancel', 'Close' and 'Delete' do what they are supposed to do, but 'Insert' does not work.

#1

Starnox - October 29, 2009 - 23:12

Getting any javascript errors?

#2

ppcc - October 30, 2009 - 07:11

Hi

See this thread:

http://drupal.org/node/564822

#3

Algebraist - October 30, 2009 - 11:13

That is a good hint! Currently I'm using PHP5.1, so this might be the cause. I will update my PHP and report if it fixes this issue.

#4

Algebraist - October 30, 2009 - 14:05
Status:active» fixed

Yes, that solves it. I updated my php to 5.2.6 and now it works like a charme.
So I think the requirements in README.txt should claim that only PHP >= 5.2 is supoorted (json_encode() is available).

#5

Starnox - October 30, 2009 - 17:26
Title:'Insert' does not work» Update requirements for json_encode()
Status:fixed» needs work

Thanks for flagging this. I might write a custom json_encode() to do the job.

#6

scroogie - November 1, 2009 - 13:33

This is from the php.net documentation page of json_encode, a substitute:

<?php
if (!function_exists('json_encode'))
{
  function
json_encode($a=false)
  {
    if (
is_null($a)) return 'null';
    if (
$a === false) return 'false';
    if (
$a === true) return 'true';
    if (
is_scalar($a))
    {
      if (
is_float($a))
      {
       
// Always use "." for floats.
       
return floatval(str_replace(",", ".", strval($a)));
      }

      if (
is_string($a))
      {
        static
$jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
        return
'"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
      }
      else
        return
$a;
    }
   
$isList = true;
    for (
$i = 0, reset($a); $i < count($a); $i++, next($a))
    {
      if (
key($a) !== $i)
      {
       
$isList = false;
        break;
      }
    }
   
$result = array();
    if (
$isList)
    {
      foreach (
$a as $v) $result[] = json_encode($v);
      return
'[' . join(',', $result) . ']';
    }
    else
    {
      foreach (
$a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
      return
'{' . join(',', $result) . '}';
    }
  }
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.