[TYPO3] Shortcuts: RealUrl, CoolUri or sms_directshortcuts?

Andreas Becker ab.becker at web.de
Mon Jun 11 05:20:24 CEST 2007


Hi Sander

I haven't used sms_shortcut by now but have your ead cooluri - Jans
Mastersthese.

http://download.bednarik.org/URITransformer.pdf
Have a look at pages 19ff. Here are the real potentials described of
cooluri. Things I am telling in the Tutorial until now are only about 20%
of it ;-). As I understand it, it is possible to automise the process of
rewriting with the right exprecions in your xml file. Jan gives a lot of
examples in his Masters Thesis.



7 Configuration
7.1 Composing the XML
Unwanted values – defined in removeparts element,
Valuemaps – element valuemaps,
Predefined parts – element predefinedparts,
Pagepath – element pagepath,
Other parts – other, but still parts of the URI, element uriparts ,
Static values – these do not have their own element, but they are part of
the uriparts element
7.2 Whitespace
xs:token
7.3 Datatypes
There are a few elements defined in the configuration, which are a sort of a
datatype.
These elements, or elements following rules of a datatype, can be found all
over the
configuration.
7.4 Boolean datatype
7.5 Regexp and SQL datatypes
7.6 Constraint datatype
7.7 Lookindb datatype
7.8 Part datatype
7.81 Parameter element
7.8.2 Value element
7.8.3 Userfunc element
Sometimes out of all options available none are sufficent. If such thing
happens, we can
define our own function. But user functions can be used only when the cache
is enabled.
Value of this element is the function's name. If the function is a class
method, the
method can be called as classname−>methodname. Two parameters are passed to
this
function, first one is the whole XML element, second one is a value of this
element.
Userfunc element is used in the Typo3 extension, because of Typo3's database
structure,
pagepath needs to be looked up in 3 tables22.
Depending on a location of this element it should return a single value or
an array of
values. This will be discussed later.
function getPageTitle($conf,$value) { ... }
7.8.4 After attribute
7.9 Root element
7.10 Cooluris element
7.11 Uri element
7.11.1 Var element
7.11.2 Part element
7.11.3 Example
Retrieving value from $ SERVER['HTTP HOST'] and $ SERVER['REQUEST URI']
variables.
That means, for an example, from a request URI
http://www.example.com/some/page/ a
value www.example.com/some/page will be retrieved.
<uri>
<var> SERVER</var>
<part>HTTP HOST</part>
<part>REQUEST URI</part>
</uri>
7.12 Savetranslationto element
7.13 Pathseparators element
7.13.1 Separator element
7.13.2 Example
Separating a variable with "." and "/" characters:
<pathseparators>
<separator>.</separator>
<separator>/</separator>
</pathseparators>
7.14 Urlprefix and urlsuffix elements
7.15 Removetrailingslash element
7.16 Cache element
7.16.1 Usecache element
7.16.2 Tablesprefix element
7.16.3 Cacheparams element
7.17 Cool2params subelement
7.17.1 Translateifnotfound element
7.17.2 Oldlinksvalidfor element
7.18 Params2cool subelement
Element referring to parameters to a CoolURI transformation has only one
subelement
so far.
<xs:element name="params2cool">
  <xs:complexType>
   <xs:all>
   <xs:element name="checkforchangeevery" type="xs:unsignedInt"/>
  </ xs:all>
 </xs:complexType>
</xs:element>
7.18.1 Checkforchangeevery element
7.19 Pagenotfound subelement
7.19.1 Status element
A value of this element is a HTTP version and a complete status code with
its definition
as were defined by WWW Consorcium [10]. However, from all those possible
status
variants, only 3 are useful in this situation.
301 Moved Permanently – when redirecting,
303 See Other – when redirecting,
404 Not Found – when sending a message.
7.19.2 Behavior element
7.19.3 Example
Sending 404 status code along with a simple message.
<pagenotfound>
<status>HTTP/1.0 404 Not Found</status>
<behavior type="message"><![CDATA[ <h1>Page not found!</h1> ]]></behavior>
</pagenotfound>
7.20 Cache example
7.21 Removeparts element
Parts of a URI that have to be removed before the URI can be translated to
parameters.
These parts are listed in subelements part of this element. If something is
removed, it
is possible to redirected a request to a URI without the removed parts. This
prevents
duplicities, but can cause circular redirecting. Therefore the redirect has
to be allowed
using the boolean attribute redirect .
<xs:element name="removeparts">
  <xs:complexType>
    <xs:sequence>
    <xs:element ref="part" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="redirect" type="boolean" use="optional" />
  </xs:complexType>
</xs:element>
7.21.1 Part element
7.21.2 Example
Removing index.php from a URI.
<removeparts>
  <part>index.php</part>
</removeparts>
7.22 Valuemaps element
7.22.1 Parameter element
7.22.2 Value element
7.22.3 Example
Value of a parameter lang is an integer identifier of a selected language.
But in a URI the
language should be identified by its standardized code. Zero is a default
value which is
not identified in any way.
<valuemaps>
  <valuemap>
    <parameter>lang</parameter>
    <value key="">0</value>
    <value key="en">1</value>
    <value key="de">2</value>
    <value key="it">3</value>
  </valuemap>
</valuemaps>
7.23 Predefinedparts element
7.23.1 Example
• If a part of a URI is a word hidden, parameter displayhidden is set to 1;
• Parameter n is set to a number that is prefixed in a URI with page-;
• Values that begin with page- are looked up in a database table named
region.
• A parameter which is thrown away
<predefinedparts>
  <part key="hidden">
    <parameter>displayhidden</parameter>
    <value>1</value>
  </part>
  <part key="page−([0−9]+)" regexp="1">
    <parameter>n</parameter>
    <value>$1</value>
    </part>
    <part key="region−(.)" regexp="1">
    <parameter>region</parameter>
    <value>$1</value>
    <lookindb>
      <from>SELECT id FROM region WHERE urlname='$1'</from>
      <to>SELECT urlname FROM region WHERE id=$1</to>
      <translatetoif>
        <match>ˆ[0−9]+$</match>
      </ translatetoif >
    </lookindb>
  </part>
  <part>
  <parameter>throwAway</parameter>
  </part>
</predefinedparts>
7.24 Pagepath element
7.24.1 SQL query for a pagepath lookup
7.24.2 Composing a final value
7.24.3 Required element
7.24.4 Constraining a pagepath
7.24.5 Userfunc element
7.24.6 Example
7.25 Uriparts element
7.25.1 Static attribute
7.25.2 Notrequired attribute
7.25.3 Pagepath attribute
7.25.4 Example
This example requires cache enabled, for an example on pagepath without
cache, look at the
case-studies section.
Here is a parameter newsId looked up in a database and put into a URI:
<uriparts>
  <part>
    <parameter>newsId</parameter>
    <lookindb>
      <to>SELECT title FROM news WHERE id=$1</to>
        <translatetoif>
          <match>ˆ[0−9]+$</match>
        </ translatetoif >
      <urlize>1</urlize>
    </lookindb>
  </part>
</uriparts>
7.26 Partorder element
Order of the URI parts can be set using this element. It has to hold exactly
4 subelements part.
Each of them must contain one value out of these 4:
• pagepath
• uriparts
• valuemaps
• predefinedparts
These values refer to elements of the same name and therefore define a
succession of the parts in
a URI.
<xs:element name="partorder">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="part" type="xs:token" maxOccurs="4" minOccurs="4" />
    </xs:sequence>
  </xs:complexType>
</xs:element>
If this element is not present, the default order is the same as defined by
the following XML.
<partorder>
  <part>pagepath</part>
  <part>uriparts</part>
  <part>valuemaps</part>
  <part>predefinedparts</part>
</partorder>
7.27 Paramorder element

This part has been taken from the Masterthesis Configuration Part. As each
Point is explaned very well - please read there to get furtherinformations.
I only copied some codeexamples to give you an idea about the potential and
the biggest differenes to RealUrl.You will realise that CoolUri will "talk'
normal language which is mainly explaining themselves. Give it a try!

It should be possible to define the language part as a staticpart and either
exclude all other parts which are not belonging to this language from the
URL or direct all calls to your STRICT Language Pages to them:
If language L=1 is called the direct those requests like this
domain/Language/rest/of/url

As You can see on these headers nearly every URL can be designed with it as
you have a lot of datatypes and possibilities to combine everything
according to your needs. Read it and for a specificproblem get in contact
with Jan. He is the one who can tell you immediately if the thing you are
trying to do will work or not. If you need a fast solution that's what I
suggest instead of wasting time in reinventing wheels.
Post a feedback to his extensions.

Read especially perhaps you will need it too:
7.18.1 and 7.23.1
It must be possible to define Shortcut mode = first *available* subpage in
the URL. If value is shortcut then look for the first available subpage.

For right now, I explained in the CoolUri Tutorial only standard uses in a
very simple way.
http://docs.google.com/View?docid=dd33gg45_3f8j96p
I am sorry, but I am sure Jan finds a solution! If so it would be nice to
have it as an example too in our Tutorial. Thanks

Andi


More information about the TYPO3-english mailing list