Direct link to a file on image

Author Message

Catherine Mollet

Tuesday 15 December 2009 7:10:54 am

Hello,

I would like to change access to pdf on my site (stored in Media library > Files > ...) because first I think it's more user-friendly to have direct access to the file, avoiding intermediary page, and second, I would not like user to see Media library folder structure. It's OK for embeded files, thanks to all posts on this subject on this forum, and for a simple text link, many thanks to http://pwet.fr/blog/creating_a_link_to_download_a_file_with_online_editor_in_ez_publish

BUT I didn't succeed to have a direct link on an image, let's say an image like a banner where you click on you directely download the file without viewing the node. Could anyone help ? Thanks.

Robin Muilwijk

Wednesday 23 December 2009 10:52:57 am

Hi Catherine,

It should not be too dificult to add a hyperlink on an image, or banner. As long as it is an image which is placed in for example a folder summary, description or body of an article, you can use the "Insert/edit link" button on the WYSIWYG editor to apply a hyperlink on the image/banner.

So you add the image first, with the "Insert/edit image" button. You then select that image and use the "Insert/edit link" button and once the "New <link> tag" popup appears make sure to select Http: for the Href option and enter your url you want to link the image to. This can of course be a file like a pdf document.

Hope this helps, Regards Robin

Board member, eZ Publish Community Project Board - Member of the share.ez.no team - Key values: Openness and Innovation.

LinkedIn: http://nl.linkedin.com/in/robinmuilwijk // Twitter: http://twitter.com/i_robin // Skype: robin.muilwijk

Catherine Mollet

Monday 04 January 2010 3:21:17 am

Hi Robin,

Of course, it's not difficult to add a link on an image. But what I want to do is to insert a direct link to the pdf document itself, stored in Media/Files. Such a link to an object opens a new page with the description of the object and a link to the object itself (ie a fullview page). To avoid it, because I think it's not very user-friendly to have to click twice to download a document, and because I wouldn't like users to see in the pathway, for example, that the pdf is within the folder Media/Files/Myfoldername/Nameofthenodeofmydocument. That's why I first overrided file.tpl in embeded-inline folder with

<a href={concat("content/download/", $file.contentobject_id, "/",
$file.id, "/file/",
$file.content.original_filename)|ezurl}>{$object.name|wash("xhtml")}</a>

Then, I used the solution provided on the article "Creating a link to download a file with Online Editor in eZ Publish" on pwet blog (link above, in the first post). Works fine for text links, but not if the link is a link on an image.

Your solution to link with Http: on Href option can not be used because uploaded files are renamed (ezbinaryfile) e.g /var/ezwebin_site/storage/original/application/182daee67677dfc4b6faa0958751d648.pdf. Of course, I could look for actual address of each pdf withwith a ftp client, but then what would be advantage to use a CMS ;-) ?

I hope my question is clearer now.

Robin Muilwijk

Monday 04 January 2010 11:10:33 am

Hi Catherine,

That indeed makes your question more clear, I'll have a look around and see if I can give you a better more to the point answer.

Regards Robin

Board member, eZ Publish Community Project Board - Member of the share.ez.no team - Key values: Openness and Innovation.

LinkedIn: http://nl.linkedin.com/in/robinmuilwijk // Twitter: http://twitter.com/i_robin // Skype: robin.muilwijk

Robin Muilwijk

Monday 04 January 2010 12:37:18 pm

Hi Catherine,

Would the following work? http://share.ez.no/forums/setup-design/linking-to-a-file-for-download

I tried setting it up, but can't get it to work yet, bit of a noob on overrides still. Let me know if you get this to work, it would make a nice short How-To article for the community site.

Regards Robin

p.s. found another one, same idea, hopefully this helps; http://share.ez.no/forums/setup-design/linking-directly-to-a-file

Board member, eZ Publish Community Project Board - Member of the share.ez.no team - Key values: Openness and Innovation.

LinkedIn: http://nl.linkedin.com/in/robinmuilwijk // Twitter: http://twitter.com/i_robin // Skype: robin.muilwijk

Catherine Mollet

Tuesday 05 January 2010 3:05:12 am

Thanks Robin for spending time on my question. If our paths cross at a eZ Day or a J! Day (as it seems that you're involved in it too), I'll buy you a beer, promise !

Solutions you pointed at are the ones I'm already using, and it works fine for direct downloads while inserting objects.
To create a direct download link on a free text, I've created a [link] class with override of content/datatype/view/ezxmltags/link.tpl. This "Download" new class works fine with text, but not with images.

Problem is that, for image, link is defined in embed/image.tpl with href=$link_parameters.href|ezurl. I guess that I have to override embed/image.tpl with something like image_direct_download.tpl, but I don't know how to manage the code inside. Still quite a newbee with eZ... Keep trying, but if you find something first, you're welcome !

Catherine Mollet

Tuesday 05 January 2010 4:03:25 am

Yessss ! I found it. Thanks for inspiration, Robin.

For whose interested in, I adapted http://pwet.fr/blog/creating_a_li...ile_with_online_editor_in_ez_publish with image.tpl. Then, I didn't have to create a image_direct_download.tpl, only override embed/image.tpl with :

{def $n='' $attribute='' $url=false() $protocols=array('http', 'file', 'ftp', 'mailto', 'https')}

<div class="content-view-embed">
<div class="class-image">
    <div class="attribute-image">
    {if is_set( $link_parameters.href )}
    {if $protocols|contains( $link_parameters.href|explode(':')|extract_left(1) )not()}
    {set $n=fetch(content, node, hash(node_path, $link_parameters.href))}
    {if and($n, $n.object.class_identifier|eq('file'))}
    {set $attribute=$n.data_map.file}
    {set $url=concat( '/content/download/', $attribute.contentobject_id, '/', $attribute.id,'/version/', $attribute.version , '/file/', $attribute.content.original_filename|urlencode )}
    {/if}
    {/if}
    {if $url|not()}
    {set $url=$link_parameters.href}
    {/if}
    {attribute_view_gui attribute=$object.data_map.image image_class=$object_parameters.size href=$url|ezurl target=$link_parameters.target border_size=first_set( $object_parameters.border_size, '' ) border_color=first_set( $object_parameters.border_color, '' ) border_style=first_set( $object_parameters.border_style, '' ) margin_size=first_set( $object_parameters.margin_size, '' )}
    {undef $n $attribute $url $protocols}
    {else}
    {attribute_view_gui attribute=$object.data_map.image image_class=$object_parameters.size border_size=first_set( $object_parameters.border_size, '' ) border_color=first_set( $object_parameters.border_color, '' ) border_style=first_set( $object_parameters.border_style, '' ) margin_size=first_set( $object_parameters.margin_size, '' )}
    {/if}
    </div>
</div>
</div>

Step by step, seems I'm getting used with eZ template laguage !

Robin Muilwijk

Tuesday 05 January 2010 4:19:36 am

Hi,

Glad to see you got this fixed. Sometimes bouncing ideas around helps to get to the finish line :)

I'll see if I can convert this information in a step-by-step guide, make it available as a how-to/article for other community members. Thanks for the feedback on how you got it to work.

Regards Robin

p.s. I'll hold you to that beer if we ever meet during a community day, always nice to share experiences

Board member, eZ Publish Community Project Board - Member of the share.ez.no team - Key values: Openness and Innovation.

LinkedIn: http://nl.linkedin.com/in/robinmuilwijk // Twitter: http://twitter.com/i_robin // Skype: robin.muilwijk

Russell Michell

Monday 04 April 2011 6:45:18 pm

Hi Catherine,

I know it was a long time ago, but I just wanted to say thanks for your solution which helped me in a similar situation.

What I wanted to was to be able to use the normal 'insert link' dialogue in ezoe to create a direct link to images *and* files, in the same way you would for linking to another content object.

In my case, I simply overrided link.tpl with the following code. If the content class of the linked-object is 'image' or 'file', a link to its loction in the var dir is created. Otherwise, links stay the same.

{def
    $dl_n=''
    $dl_attribute=''
    $dl_url=''
    $dl_protocols=array('http', 'file', 'ftp', 'mailto', 'https')
}

{if is_set( $href )}
    {if $dl_protocols|contains( $href|explode(':')|extract_left(1) )not()}
        {set $dl_n=fetch(content, node, hash(node_path, $href))}
        {if $dl_n}
            {if or($dl_n.object.class_identifier|eq('image'),$dl_n.object.class_identifier|eq('file'))}
                {if $dl_n.object.class_identifier|eq('image')}
                    {set $dl_attribute=$dl_n.data_map.image}
                    {set $dl_url=concat('/',$dl_attribute.content.original.url)}
                {else}
                    {set $dl_attribute=$dl_n.data_map.file}
                    {set $dl_url=concat( '/content/download/',  $dl_attribute.contentobject_id, '/',  $dl_attribute.id,'/version/',  $dl_attribute.version , '/file/',  $dl_attribute.content.original_filename|urlencode )}
                {/if}
            {/if}
        {/if}
    {/if}
{/if}

<a href={if eq($dl_url|count_chars(),0)|not()}{$dl_url}{else}{$href|ezurl()}{/if} {if $id} id="{$id}"{/if}{if $title} title="{$title}"{/if}{if $target} target="{$target}"{/if}{if $classification} class="{$classification|wash}"{/if}{if and(is_set( $hreflang ), $hreflang)} hreflang="{$hreflang|wash}"{/if}>{$content}</a>

{undef $dl_n $dl_attribute $dl_url $dl_protocols}

Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom

Believe nothing, consider everything.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 00:58:55
Script start
Timing: Jan 18 2025 00:58:55
Module start 'layout'
Timing: Jan 18 2025 00:58:55
Module start 'content'
Timing: Jan 18 2025 00:58:56
Module end 'content'
Timing: Jan 18 2025 00:58:56
Script end

Main resources:

Total runtime0.8439 sec
Peak memory usage4,096.0000 KB
Database Queries78

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 587.9141152.6250
Module start 'layout' 0.00500.0025 740.539139.4609
Module start 'content' 0.00750.8348 780.0000673.2031
Module end 'content' 0.84220.0017 1,453.203128.1641
Script end 0.8439  1,481.3672 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.3557160.0002
Check MTime0.00130.1511160.0001
Mysql Total
Database connection0.00080.095510.0008
Mysqli_queries0.761490.2171780.0098
Looping result0.00070.0853760.0000
Template Total0.816296.720.4081
Template load0.00190.227120.0010
Template processing0.814396.490220.4071
Template load and register function0.00030.030710.0003
states
state_id_array0.00090.107410.0009
state_identifier_array0.00090.109420.0005
Override
Cache load0.00170.2034570.0000
Sytem overhead
Fetch class attribute can translate value0.00060.065730.0002
Fetch class attribute name0.00130.1582110.0001
XML
Image XML parsing0.01011.196730.0034
class_abstraction
Instantiating content class attribute0.00000.0041140.0000
General
dbfile0.01031.2156240.0004
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 35
 Number of unique templates used: 9

Time used to render debug report: 0.0001 secs