cluster_search_ui/commit
Extended image and thumbnail code to cater for local hosted files.
author | Chris Dijkshoorn |
---|---|
Sun Dec 21 13:57:15 2014 +0100 | |
committer | Chris Dijkshoorn |
Sun Dec 21 13:57:15 2014 +0100 | |
commit | 17c86bb2248c727ef51c2fcc4c6641b807ee0483 |
tree | cc0b76e2e87805ef0f8b77fafcfbdc0ba2e5241f |
parent | a389728d23633e56cf6dc5294d5d1989a90f683a |
Diff style: patch stat
diff --git a/lib/cluster_search_ui/enrichment.pl b/lib/cluster_search_ui/enrichment.pl index 82f3c9a..4710e7e 100644 --- a/lib/cluster_search_ui/enrichment.pl +++ b/lib/cluster_search_ui/enrichment.pl @@ -86,29 +86,54 @@ enrich_item(Uri, EnrichedItem) :- debug(enrich_item, 'Uri: ~p ThumbnailUrl: ~p Link: ~p Title: ~p', [Uri,ThumbnailUrl,Link,Title]). -%% thumbnail_url(+Uri, -ImageUrl) +%% thumbnail_url(+Uri, -ThumbUrl) % % * Check if image is present, if so, return request url. % * If the image is not present, check if present at url. % * If not present in cache, database and at url, send image stub. -thumbnail_url(Uri, ImageUrl) :- - rdf(Aggregation, edm:aggregatedCHO, Uri), - rdf(Aggregation, edm:isShownBy, Image), - url_cached(Image, file(_)), - !, - concat('cache/fit?uri=', Image, RequestUrl), - http_absolute_location(root(RequestUrl), ImageUrl, []). +thumbnail_url(Uri, ThumbUrl) :- + check_cache_shown(Uri, Image), !, + thumb_link(Image, ThumbUrl). +thumbnail_url(Uri, ThumbUrl) :- + check_server_shown(Uri, Image), !, + thumb_link(Image, ThumbUrl). +thumbnail_url(Uri, ThumbUrl) :- + check_cache_view(Uri, Image), !, + thumb_link(Image, ThumbUrl). +thumbnail_url(Uri, ThumbUrl) :- + check_server_view(Uri, Image), !, + thumb_link(Image, ThumbUrl). +thumbnail_url(_, Stub) :- http_absolute_location(img('stub.png'), Stub, []). -thumbnail_url(Uri, ImageUrl) :- - rdf(Aggregation, edm:aggregatedCHO, Uri), +check_cache_shown(Uri, Image) :- + rdf(Aggregation, edm:aggregatedCHO, Uri), + rdf(Aggregation, edm:isShownBy, Image), + url_cached(Image, file(_)). +check_cache_view(Uri, Image) :- + rdf(Aggregation, edm:aggregatedCHO, Uri), + rdf(Aggregation, edm:hasView, Image0), + check_if_local(Image0, Image), + url_cached(Image, file(_)). +check_server_shown(Uri, Image) :- + rdf(Aggregation, edm:aggregatedCHO, Uri), rdf(Aggregation, edm:isShownBy, Image), https_header_response(Image, Status), - Status == 200, - !, - concat('cache/fit?uri=', Image, RequestUrl), - http_absolute_location(root(RequestUrl), ImageUrl, []). + Status == 200. +check_server_view(Uri, Image) :- + rdf(Aggregation, edm:aggregatedCHO, Uri), + rdf(Aggregation, edm:hasView, Image0), + check_if_local(Image0, Image), + https_header_response(Image, Status), + Status == 200. -thumbnail_url(_, Stub) :- http_absolute_location(img('stub.png'), Stub, []). +thumb_link(Image, ThumbUrl) :- + concat('cache/fit?uri=', Image, RequestUrl), + http_absolute_location(root(RequestUrl), ThumbUrl, []). + +check_if_local(Image, ImageUrl) :- + not(concat('http', _, Image)), + http_absolute_uri(img(Image), ImageUrl). +check_if_local(ImageUrl, ImageUrl). %% https_header_response(+URL, -Status) % diff --git a/lib/cluster_search_ui/web_ui_dcg.pl b/lib/cluster_search_ui/web_ui_dcg.pl index 07d895d..165fb22 100644 --- a/lib/cluster_search_ui/web_ui_dcg.pl +++ b/lib/cluster_search_ui/web_ui_dcg.pl @@ -101,26 +101,51 @@ get_carousel_items(CarouselItems) :- % * Check if image is present, if so, return request url. % * If the image is not present, check if present at url. % isShownBy triple. -% * If not present in cache, database and at +% * If not present in cache, database and at % server, send image stub. image_url(Uri, ImageUrl) :- - rdf(Aggregation, edm:aggregatedCHO, Uri), - rdf(Aggregation, edm:isShownBy, Image), - url_cached(Image, file(_)), - !, - concat('cache/original?uri=', Image, RequestUrl), - http_absolute_location(root(RequestUrl), ImageUrl, []). - + check_cache_shown(Uri, Image), !, + image_link(Image, ImageUrl). +image_url(Uri, ImageUrl) :- + check_server_shown(Uri, Image), !, + image_link(Image, ImageUrl). image_url(Uri, ImageUrl) :- - rdf(Aggregation, edm:aggregatedCHO, Uri), + check_cache_view(Uri, Image), !, + image_link(Image, ImageUrl). +image_url(Uri, ImageUrl) :- + check_server_view(Uri, Image), !, + image_link(Image, ImageUrl). +image_url(_, Stub) :- http_absolute_location(img('stub_vertical.png'), Stub, []). + +check_cache_shown(Uri, Image) :- + rdf(Aggregation, edm:aggregatedCHO, Uri), + rdf(Aggregation, edm:isShownBy, Image), + url_cached(Image, file(_)). +check_cache_view(Uri, Image) :- + rdf(Aggregation, edm:aggregatedCHO, Uri), + rdf(Aggregation, edm:hasView, Image0), + check_if_local(Image0, Image), + url_cached(Image, file(_)). +check_server_shown(Uri, Image) :- + rdf(Aggregation, edm:aggregatedCHO, Uri), rdf(Aggregation, edm:isShownBy, Image), https_header_response(Image, Status), - Status == 200, - !, - concat('cache/original?uri=', Image, RequestUrl), - http_absolute_location(root(RequestUrl), ImageUrl, []). + Status == 200. +check_server_view(Uri, Image) :- + rdf(Aggregation, edm:aggregatedCHO, Uri), + rdf(Aggregation, edm:hasView, Image0), + check_if_local(Image0, Image), + https_header_response(Image, Status), + Status == 200. + +image_link(Image, ThumbUrl) :- + concat('cache/original?uri=', Image, RequestUrl), + http_absolute_location(root(RequestUrl), ThumbUrl, []). -image_url(_, Stub) :- http_absolute_location(img('stub.png'), Stub, []). +check_if_local(Image, ImageUrl) :- + not(concat('http', _, Image)), + http_absolute_uri(img(Image), ImageUrl). +check_if_local(ImageUrl, ImageUrl). %% https_header_response(+URL, -Status) %