Search

For the Symphony site I'm working on at the moment I needed to pull out the full URL at separate parameters, so I made a sketchy little custom DS to do so. I thought others might be interested in using the code — bear in mind I'm still pretty new to Symphony and I'm far from a PHP guru so if there's an easier way to do this please let me know.

All you need to do is create a new datasource in Symphony named 'A: Request URI' and then override that code with the following:

<?php

    Class datasourcea_request_uri extends Datasource {

        function about(){
            return array(
                     'name' => 'A: Request URI',
                     'author' => array(
                            'name' => 'Max Wheeler',
                            'website' => 'http://icelab.com.au',
                            'email' => 'max@icelab.com.au'),
                     'version' => '1.0',
                     'release-date' => '2008-01-26T12:08:46+00:00');    
        }

        function allowEditorToParse(){
            return false;
        }

        function grab(&$param_pool) {

          /* Figure out how many segments are in the root url
           * I.e., http://blah.com/something/[symphony-here] has 2
           * Remove http:// from the start of the URI
           */
          $root = explode("/", preg_replace('/^(http|ftp|news)s?:\/+/i', '', URL));
          $root_segments = count($root);

          // Start the output
      $output = new XMLElement('request-uri');
      $path = $_SERVER['REQUEST_URI'];
      $request_uri = split("/",  $path);

      foreach($request_uri as $key => $segment) {
        if($key >= $root_segments && $segment != '') {
            $param_pool['url-segment-' . ($key-$root_segments+1)] = $segment;
          $s = new XMLElement('segment', $segment);
          $output->appendChild($s);
        }
      }
            return $output;
        }
    }

?>

You can name the DS whatever you want, you'll just have to change the class name to match. I.e., if you name it 'Banana Man' the first line in the code above should become Class databanana_man extends Datasource {. The reason I've called it 'A: Request URI' is so it gets called before all the other datasources and allows me to use the outputted parameters to filter by.

I vaguely remember someone mentioning that something similar to this was planned for r6, so it may become unnecessary soon.

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