Пример #1
0
for ($x = 0; $x < count($notes); $x++) {
    $ratio = $preview_width / $notes[$x]['preview_width'];
    $notes[$x]['width'] = $ratio * $notes[$x]['width'];
    $notes[$x]['height'] = $ratio * $notes[$x]['height'];
    $notes[$x]['top_pos'] = $ratio * $notes[$x]['top_pos'];
    $notes[$x]['left_pos'] = $ratio * $notes[$x]['left_pos'];
    $notes[$x]['note'] = str_replace(chr(13) . chr(10), '<br />\\n', $notes[$x]['note']);
    $notes[$x]['note'] = str_replace(chr(13), '<br />\\n', $notes[$x]['note']);
    $notes[$x]['note'] = str_replace(chr(10), '<br />\\n', $notes[$x]['note']);
    if (!$annotate_show_author) {
        $notes[$x]['note'] = substr(strstr($notes[$x]['note'], ": "), 2);
    }
    if ($x > 0) {
        $json .= ",";
    }
    $json .= "{";
    $json .= '"top":' . round($notes[$x]['top_pos']) . ', ';
    $json .= '"left":' . round($notes[$x]['left_pos']) . ', ';
    $json .= '"width":' . round($notes[$x]['width']) . ', ';
    $json .= '"height":' . round($notes[$x]['height']) . ', ';
    $json .= '"text":"' . config_encode($notes[$x]['note']) . '", ';
    $json .= '"id":"' . $notes[$x]['note_id'] . '", ';
    if (isset($userref) && ($notes[$x]['user'] == $userref || in_array($usergroup, $annotate_admin_edit_access))) {
        $json .= '"editable":true';
    } else {
        $json .= '"editable":false';
    }
    $json .= "}";
}
$json .= "]";
echo $json;
Пример #2
0
/**
 * A subset json_encode function that only works on $config arrays but has none
 * of the version-to-version variability and other "unusual" behavior of PHP's.
 * implementation.
 *
 * @param $config mixed a configuration variables array. This *must* be an array
 *      whose elements are UTF-8 encoded strings, booleans, numbers or arrays
 *      of such elements and whose keys are either numbers or UTF-8 encoded
 *      strings.
 * @return json encoded version of $config or null if $config is beyond our
 *         capabilities to encode
 */
function config_json_encode($config)
    {
    $i=0;
    $simple_keys = true;
    foreach ($config as $name => $value)
        {
        if (!is_numeric($name) || ($name != $i++))
            {
            $simple_keys = false;
            break;
            }
        }
    $output = $simple_keys?'[':'{';
    foreach ($config as $name => $value)
        {
        if (!$simple_keys)
            {
            $output .= '"' . config_encode($name) . '":';
            }
        if (is_string($value))
            {
            $output .= '"' . config_encode($value) . '"';
            }
        elseif (is_bool($value))
            {
            $output .= $value?'true':'false';
            }
        elseif (is_numeric($value))
            {
            $output .= strval($value);
            }
        elseif (is_array($value))
            {
            $output .= config_json_encode($value);
            }
        else
            {
            return NULL; // Give up; beyond our capabilities
            }
        $output .= ', ';
        }
    if (substr($output, -2) == ', ')
        {
        $output = substr($output, 0, -2);
        }
    return $output . ($simple_keys?']':'}');
    }