From 797f2192949f9c4d252c09ae7f32515228253ff8 Mon Sep 17 00:00:00 2001 From: Banana Date: Fri, 30 Nov 2012 16:02:35 +0100 Subject: [PATCH] screenshot creation at edit and add function --- lib/Insipid/Main.pm | 72 +++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/lib/Insipid/Main.pm b/lib/Insipid/Main.pm index 97c0739..12b0049 100755 --- a/lib/Insipid/Main.pm +++ b/lib/Insipid/Main.pm @@ -317,11 +317,18 @@ IFORM update_bookmark(param('id'), $url, $title, $description, $access_level, $tags); } else { add_bookmark($url, $title, $description, $access_level, 0, $tags); - if (param('snapshot')) { - if (param('snapshot') eq 'on') { - $id = get_bookmark_id(param('url')); - do_snapshot($id); - } + } + if (param('snapshot')) { + if (param('snapshot') eq 'on') { + $id = get_bookmark_id(param('url')); + do_snapshot($id); + } + } + + if (param('screenshot')) { + if (param('screenshot') eq 'on') { + $id = get_bookmark_id(param('url')); + my $do = do_screenshot($id); } } @@ -400,12 +407,20 @@ IFORM
$snapshot_params + Public: Return: - +FORM + if($usePhantomjs) { + print "Screenshot:"; + print ""; + } + + print < $extra_params @@ -431,9 +446,8 @@ FORM if (defined(param('create_screenshot')) && param('create_screenshot') eq '1') { print '

Creating screenshot... Please wait...

'; - - my $output = `$phantomjsPath --proxy=10.0.1.11:80 ./lib/screen.js $url $screnshotNameFile`; - if($? == 0) { + my $do = do_screenshot($id); + if($do == 0) { print '

Success !

'; if(-e $screnshotNameFile) { print "

Screenshot available: see it here.

"; @@ -441,20 +455,9 @@ FORM } else { print "

Screenshot creation failed.

"; - if ($? == -1) { - print "failed to execute: $!\n"; - } - elsif ($? & 127) { - printf "child died with signal %d, %s coredump\n", - ($? & 127), ($? & 128) ? 'with' : 'without'; - } - else { - printf "child exited with value %d\n", $? >> 8; - } } } else { - if(-e $screnshotNameFile) { print "

Screenshot available: see it here. Re-Create to refresh.

"; } @@ -565,6 +568,32 @@ BLET ################################################################ +sub do_screenshot { + my ($bookmarkID) = (@_); + + my $phantomjsPath = getconfig('phantomPath'); + + my ($url, $title, $description, $access_level, $md5) = get_bookmark($bookmarkID); + my $screnshotNameFile = "./screenshots/".$md5.".png"; + + #my $output = `$phantomjsPath ./lib/screen.js $url $screnshotNameFile`; + my $output = `$phantomjsPath --proxy=10.0.1.11:80 ./lib/screen.js $url $screnshotNameFile`; + if($? == 0) { + return 0; + } + else { + if ($? == -1) { + return "failed to execute: $!\n"; + } + elsif ($? & 127) { + return printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without'; + } + else { + return printf "child exited with value %d\n", $? >> 8; + } + } +} + sub show_options { # Save options if they were posted. @@ -1314,8 +1343,7 @@ sub update_bookmark { linkcheck_status = '' where (id = ?)"; my $sth = $dbh->prepare($sql); - $sth->execute($url, md5_hex("$url"), $title, $description, $access_level, - $id); + $sth->execute($url, md5_hex("$url"), $title, $description, $access_level,$id); set_tags($id, $tags); } -- 2.39.5