Search

Hi,

I've been poking around with Symphony for a few days. As a learner by doing, i want to make a portfolio site using Symphony.

Btw, i'm not a pro developer, a night-time geek would be more appropriate, so please don't come too hard, if my concerns are too basic :-) It's actually more of a workflow question and i can't come up with how i can accomplish this:

There will be a page which will display movies of works grouped by year. Movie files will be uploaded to the site with ftp, i don't want to use a file upload field since files may be large. In the section for the page, i don't want to input the file's path by hand.

What i want to do is:

-- Create a section called "Works" with fields like 'title', etc.. and a field called 'path'.

-- Upload a file.

-- Go to Publish>Works, input the info for the new uploaded file, 'path' being just the relative folder name (if i uploaded the file under workspace/uploads/projects/project1 'path' will be project1.

-- The works page should get the title, vs... fields from the section inputs. Then get the 'path' value, and output a link whatever file it finds under the related directory with the right extension.

What i tried is:

-- I came up with a php script that would spit out xml from the contents of the directory (workspace/uploads/projects in this case).

--Created a new ds with a Dynamic XML with a URL pointing the php script.

--Linked that ds to the 'Works' section, so that the page xml would include the upload directory content.

This way, i thought, with some xslt, i can output what i want...but it failed because i couldn't find a way to refresh the php script every time a 'work' is published.

So, what should be the correct way to do this? My approach may be totally wrong, so any suggestions are welcome.

Thank you,

You're almost there, two more steps :-)

You need your Work data source (fetching the entry from the Works section) to output the "path" field as an Output Parameter. So for Project 1, this will make a globally available parameter, named $ds-work (if your data source is called Work) with the value of project1. You can then use this parameter to pass to your PHP script.

Edit your Dynamic XML data source passing this value in the URL. For example:

 {$root}/assets/php/get-directory-contents.php?directory={$ds-work}

Your PHP script will then receive this value, so choosing the correct directory to print.

An alternative solution is to have your PHP script recurse through all subdirectories (thereby giving you a list of all projects and their files). With some careful XPath you could get the right files. So let's say your PHP looked at /workspace/uploads/ and found 3 projects, each with one JPEG file. The XML might look like:

<get-directory-contents>
    <project-1>
        <file name="image1.jpg" />
    </project-1>
    <project-2>
        <file name="image2.jpg" />
    </project-2>
    <project-3>
        <file name="image3.jpg" />
    </project-3>
</get-directory-contents>

In your page XSLT you can then retrieve the files for the current project:

<!-- cache the work 'path' value for readability -->
<xsl:variable name="current-work" select="/data/work/entry/path/@handle" />
<!-- find all 'file' nodes inside the node with the same name as the 'path' -->
<xsl:apply-templates select="/data/get-directory-contents/*[name()=$current-work]/file" />

The downside to this second approach is that the PHP script needs to scan all subdirectories on every page load. For a small number this is fine, but if you have hundreds of projects this would become an obvious performance bottleneck.

Hope one of those is useful...

They are useful, thank you. I'll check these out tonight, and get back here if i bump into something...

But, what do you think about the approach? How would you handle a situation like this? Because, without getting into any complications, i could easily create a text field in the Works section and let the user (this is me!) give the full or relative path to the corresponding file. But i chose to semi-automate the process by getting only the 'path' to the file(s). Or just wait, until Symphony has a file manager/browser :-)

hi again,

it works but there is a problem: When a datasource is set to Dynamic Xml, it caches the results of my php script. So, how will it be possible to refresh the php script when i publish a new "work" item?

thanks,

i think you can set an amount of time for the Dynamic XML to be cached. but I can't completely remember right now.

There's a field on the dymanic XML datasource that lets you set the cache time in minutes. It's at the bottom.

 Update cached result every [        ] minutes

You can set the cache to a low number. However it should cache each individual URL separately, so when you pass a different path parameter on the end of the URL to your PHP script, this will be cached as a different request to another value. Is this not the case?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details