Conditional Content

Using the URL feature to verify a file is present

6 months 4 weeks ago #73804

Richard Owden's Avatar Richard Owden

Hi.
The code below works but only to a point.

{show access=niceuserinfo:id}<a href="/documents/client-{niceuserinfo:id}/client-{niceuserinfo:id}-terms-of-engagement-signed.pdf" download="{niceuserinfo:name} Signed Terms of Engagement">Signed Terms of Engagement</a>{/show}
It was entered as:
{show access="643"}<a href="/documents/client-{niceuserinfo:id}/client-{niceuserinfo:id}-terms-of-engagement-signed.pdf" download="{niceuserinfo:name} Signed Terms of Engagement">Signed Terms of Engagement</a>{/show}
and after it had been proven to work the "643" was changed to niceuserinfo:id.
This version works OK after the amendment - the code works for any logged in client and their file, if there, can be downloaded sucessfully.
The problem comes when the file for the client has not been uploaded to the website server yet - at which point a 404 error occurs.
It is possible to use the URL feature of the plugin (in addition to the 'access="643"') to check the file's URL is valid? Then show the file download code if it is and display a {show else} section to cover any absence of the file?
If it is possble, how should the URL to verify be entered?
Thank you.
Richard

6 months 4 weeks ago #73805

Peter van Westen's Avatar Peter van Westen Admin

You would have to use the custom php check to see if the file exists or not.
Use the Conditional Content editor button to get the correct syntax for the tag.

6 months 4 weeks ago #73806

Peter van Westen's Avatar Peter van Westen Admin

PS: The access attribute refers to the access level. It looks like you are using it to check for user ids. That won't work.

6 months 4 weeks ago #73807

Richard Owden's Avatar Richard Owden

My bad. I put the wrong tag in the code when I transferred it. The working code has 'users' not 'access'. Oops. :)

6 months 4 weeks ago #73809

Peter van Westen's Avatar Peter van Westen Admin

But won't that always return true?
niceuserinfo:id will output the id of the current user.
If you let Conditional Content check if that is the current user, then it is always true.

If you want to only allow this for logged in users, simply hide it for guests.
Or do something like:

{show php="return !empty($user->id) && is_file(JPATH_SITE . '/documents/client-' . $user->id . '/client-' . $user->id . '-terms-of-engagement-signed.pdf');"}

6 months 4 weeks ago #73813

Richard Owden's Avatar Richard Owden

Hi.
Being a real novice with PHP (sorry but I am!), I have put together a simpler (me friendly) solution.
I have set up a user group for each of the 5 upload documents I have and am using Conditional Content to only show the download url if the user is in the correct group.
OK so I have to remember to set the user group flag when I upload a document.
I will return to this when I have more time though...
Thanks again for the swift and helpful support.
Richard