Projet

Général

Profil

Anomalie #1498 » 01-inkscape2rsvg.diff

François Poulain, 09/07/2014 13:54

Voir les différences:

include/config.php
);
// Command used to convert SVG files into images, optional unless you
// want to use this feature. Be sure to have at least inkscape v0.44
define ( INKSCAPE_COMMAND, '/usr/bin/inkscape' );
// want to use this feature.
define ( SVGCONVERT_COMMAND, '/usr/bin/rsvg' );
/*
include/config.php.template
// Command used to convert SVG files into images, optional unless you
// want to use this feature.
define ( INKSCAPE_COMMAND, '{$inkscape_path}' );
define ( SVGCONVERT_COMMAND, '{$rsvg_path}' );
// Uncomment if you need LDAP
// define ( LDAP_HOST, 'localhost' );
include/inst.php
function inst_test_inkscape ()
function inst_test_rsvg ()
{
global $_SESSION;
if ( ! $_SESSION [ 'inkscape_path' ] )
exec ( 'inkscape --version 2>&1', $output, $retval );
if ( ! $_SESSION [ 'rsvg_path' ] )
exec ( 'rsvg --version 2>&1', $output, $retval );
else
exec ( $_SESSION [ 'inkscape_path' ] . '/inkscape --version 2>&1',
exec ( $_SESSION [ 'rsvg_path' ] . '/rsvg --version 2>&1',
$output, $retval );
preg_match ( '/inkscape ([0-9]*)\.([0-9]*)/i', $output [ 0 ], $matches );
return ( $matches [ 1 ] > 0 || $matches [ 2 ] >= 44 );
return ( $retval == 0);
}
function inst_configure_inkscape ( )
function inst_configure_rsvg ( )
{
exec ( 'inkscape --version 2>&1', $output, $retval );
preg_match ( '/inkscape ([0-9\.]*)/i', $output [ 0 ], $matches );
if ( $matches [ 1 ] )
$data [ 'inkscape_version' ] = $matches [ 1 ];
exec ( 'rsvg --version 2>&1', $output, $retval );
if ( $retval == 0 )
$data [ 'rsvg_version' ] = $output;
else
$data [ 'inkscape_version' ] = '<b>none!</b>';
$data [ 'rsvg_version' ] = '<b>none!</b>';
$data [ 'path' ] = $_ENV [ 'PATH' ];
my_smarty ( "installer/configure-inkscape.tpl", $data );
// FIXME: seems no more available
// my_smarty ( "installer/configure-inkscape.tpl", $data );
}
function inst_do_configure_inkscape ( $args )
function inst_do_configure_rsvg ( $args )
{
global $_SESSION;
$_SESSION [ 'inkscape_path' ] = $args [ 'inkscape_path' ];
if ( inst_test_inkscape ( ) )
$_SESSION [ 'rsvg_path' ] = $args [ 'rsvg_path' ];
if ( inst_test_rsvg ( ) )
{
header ("Location: installer.php");
exit;
}
else
{
inst_croak ( "Unable to find inkscape in " . $args [ 'inkscape_path' ] );
inst_croak ( "Unable to find rsvg in " . $args [ 'rsvg_path' ] );
}
}
......
$base_url = 'http://' . $_SERVER [ 'HTTP_HOST' ] . $_SERVER [ 'SCRIPT_NAME' ];
$base_url = preg_replace ( '/[^\/]*.php/', '', $base_url );
if ( $_SESSION [ 'inkscape_path' ] )
$inkscape = $_SESSION [ 'inkscape_path' ] . '/inkscape';
if ( $_SESSION [ 'rsvg_path' ] )
$rsvg = $_SESSION [ 'rsvg_path' ] . '/rsvg';
else
$inkscape = 'inkscape';
$rsvg = 'rsvg';
$data = Array ( 'db_host' => $_SESSION [ 'db_host' ],
'db_name' => $_SESSION [ 'db_name' ],
......
'base_dir' => $base_dir,
'base_url' => $base_url,
'smarty_path' => $_SESSION [ 'smarty_path' ],
'inkscape_path' => $inkscape,
'rsvg_path' => $rsvg,
'mail_bot' => $_SESSION [ 'mail_bot' ] );
// Generate config file
include/svg.php
if ( $format == 'pdf' )
{
system ( INKSCAPE_COMMAND . " -z --export-pdf=/tmp/$id.pdf --export-width=640 /tmp/$id.svg 2>/dev/null > /dev/null" );
system ( SVGCONVERT_COMMAND . " --width 640 -f pdf /tmp/$id.svg /tmp/$id.pdf 2>/dev/null> /dev/null" );
header ( "Content-type: application/pdf\n\n" );
print file_get_contents ( "/tmp/$id.pdf" );
@unlink ( "/tmp/$id.pdf" );
......
}
else if ( $format != 'svg' )
{
system ( INKSCAPE_COMMAND . " -z --export-png=/tmp/$id.png --export-width=640 /tmp/$id.svg 2>/tmp/plop > /tmp/plop2");
system ( SVGCONVERT_COMMAND . " --width 640 -f png /tmp/$id.svg /tmp/$id.png 2>/dev/null> /dev/null" );
header ( "Content-type: image/png\n\n" );
print file_get_contents ( "/tmp/$id.png" );
@unlink ( "/tmp/$id.png" );
installer.php
{
my_smarty ( "installer/create-admin.tpl", Array ( 'title' => 'Configure administrator' ) );
}
else if ( $action == 'configure_inkscape' )
else if ( $action == 'configure_rsvg' )
{
inst_configure_inkscape ();
inst_configure_rsvg ();
}
else if ( $action == 'do_configure_inkscape' )
else if ( $action == 'do_configure_rsvg' )
{
inst_do_configure_inkscape ( $_GET );
inst_do_configure_rsvg ( $_GET );
}
else if ( $action == 'create_admin' )
{
......
'nok_string' => '<li><a href="?action=configure_admin"><div class="error">Administrator not created.</div></a></li>',
'test_func' => 'inst_test_admin' ),
Array ( 'ok_string' => '<li><div class="notice">Inkscape detected (for map generation).</div></li>',
'nok_string' => '<li><a href="?action=configure_inkscape"><div class="warning">Inkscape not detected (maps will not be generated correctly).</div></a></li>',
'test_func' => 'inst_test_inkscape',
Array ( 'ok_string' => '<li><div class="notice">Rsvg detected (for map generation).</div></li>',
'nok_string' => '<li><a href="?action=configure_rsvg"><div class="warning">Rsvg not detected (maps will not be generated correctly).</div></a></li>',
'test_func' => 'inst_test_rsvg',
'not_mandatory' => 1 ),
Array ( 'ok_string' => '<li><div class="notice">Configuration file created</div></li>',
(1-1/3)