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.