[Typo3-dev] Approval for a lean real URL solution

Peter Russ peter.russ at 4dfx.de
Thu Sep 2 00:55:40 CEST 2004


First of all I have to apologize: To implement some kind of real URL you 
need more than 4 lines of code. It's 20!
I would highly appreciate if someone could provide the .htaccess. I'm to 
tired for now.

To find the required changes look for the block:
//ADDED PRS 01092004 BEGIN
.
.
.
//ADDED PRS 01092004 END

At this point, (day one : hour  5) this are the requirements to get this 
done:

Requirements
------------
1. This only works for single domains, i.e. one domain <-> one Typo3 DB.
The limitation is due to the fact that Typo3 supports only 1 publishing 
directory at the moment.
2. This solution gives you all the benefits of improved performance, 
when publishing static content.
3. The total alias length is limited to 255 signs, a-z or A-Z or 0-9 or 
_-/. But can be adjusted to your needs!
4. The first sign should be an alphanum or _. There is no check at the 
moment!
5.simulateStaticDocuments_addTitle=0 because we will create the title 
from the alias
6. Off course: only with simulate static documents. Otherwise it makes 
no sense.
7. NO <base ref=>
8. Input for alias at the moment only by hand!

This is a prove of concept and should help to come to a conclusion.
This approval realize the proposal publish at 
http://typo3.org/documentation/mailing-lists/dev-list-archive/thread/61731/?tx_maillisttofaq_pi1%5Bsword%5D=extend%20real%20url&tx_maillisttofaq_pi1%5Banswered_only%5D=0&tx_maillisttofaq_pi1%5Bmode%5D=1
(whow what a nice URL. Where have all the md5s gone, long time passing...).

So at this step I decide to implement it that way:
1)No extension of any class as this is not sufficient. Ther is to much 
overhead.
2)No hook as we would be always the second winner and it would take to 
much time to get it in the right places.
3)I could publish a patch. But as long as there is no access control on 
the TER this is a security risk.
4)So I just describe what to change or add in which file and where.
5)If the server is installed properly only an admin should be able to 
apply the changes.

And then we can discuss how to proceed.
No here comes

THE SOLUTION
----------------------
BUT PLEASE BEFORE YOU APLLY ANY CHANGES MAKE COPIES OF THE FILES WE 
TOUCH! FROM NOW ON EVERY ACTION YOU TAKE IS ON YOUR OWN RISK.

1. Step: File: typo3/sysext/cms/ext_tables.php
search for:
		 'alias' => Array (
			'label' => 'LLL:EXT:cms/locallang_tca.php:pages.alias',
			'config' => Array (
				'type' => 'input',
				'size' => '10',
				'max' => '20',
				'eval' => 'nospace,alphanum_x,lower,unique'
			)
		),
and just add after that section mention above or replace:
//ADDED PRS 01092004 BEGIN
		 'alias' => Array (
			'label' => 'LLL:EXT:cms/locallang_tca.php:pages.alias',
			'config' => Array (
				'type' => 'input',
				'size' => '10',
				'max' => '255', // should discuss if this is sufficient!!!
				'eval' => 'nospace,alphanum_dir,lower,unique'
			)
		),
//ADDED PRS 01092004 END


2. Step: Now we adjust the page-table manually using phpMyAdmin by 
running the sql:
ALTER TABLE `pages` CHANGE `alias` `alias` VARCHAR(255)  NOT NULL


3. Step: Next we fix the table definition at typo3/sysext/cms/ext_tables.sql
#
# Table structure for table 'pages'
#
and change the value from
   alias varchar(20) DEFAULT '' NOT NULL,
to
   alias varchar(255) DEFAULT '' NOT NULL,


Sorry for that but I can't figure out how to reload the basic tables 
definition without ruin the whole content of your homepage. So I decide 
to do it manually. It more save at this time.

No we have to define the new type ' alphanum_dir'. This has to be donon 
two places:
4.Step: t3lib/jsfunc.evalfield.js
Look for: function evalFunc_caseSwitch(type,inVal)
and change it that way:
	switch (type)	{
		case "alpha":
		case "num":
		case "alphanum":
//ADDED PRS 01092004 BEGIN
	        case "alphanum_dir":
//ADDED PRS 01092004 END
		case "alphanum_x":
			for (var a=0;a<theVal.length;a++)	{
				var theChar = theVal.substr(a,1);
				var special = (theChar=='_'||theChar=='-');
				var alpha = (theChar>='a'&&theChar<='z') || 
(theChar>='A'&&theChar<='Z');
				var num = (theChar>='0' && theChar<='9');
				switch(type)	{
//ADDED PRS 01092004 BEGIN
					case "alphanum_dir":
						special = (theChar=='/' || special); break;
//ADDED PRS 01092004 END
					case "alphanum":	special=0;		break;
					case "alpha":	num=0; special=0;		break;
					case "num":	alpha=0; special=0;		break;
				}
				if (alpha || num || theChar==' ' || special)	{
					newString+=theChar;
				}
			}
		break;
		case "is_in":

5.Step: t3lib/class.t3lib_tcemain.php:
Look for:
		case 'alphanum_x':
			$value = ereg_replace('[^a-zA-Z0-9_-]','',$value);
			break;

and add just after that:

//ADDED PRS 01092004 BEGIN
		case 'alphanum_dir':
		              $value = ereg_replace('[^a-zA-Z0-9_/]','',$value);
			break;
//ADDED PRS 01092004 END

Finally the last change that took more code than planned. But there we 
get a REAL directory structure under publish_dir, i.e. if your <alias > 
is  for a page is
                                <company/future/plans>
then you will get
                          <publish_dir>/company/future/plans.html
Nice to mantain, isn't it?

Why not to add language support to the alias?
			<de/unternehmen/zukunft/plaene>
;-)

6.Step: tslib/publish.php
Look for:
// ***************************
// Publishing, writing files
// ***************************

and add the changes:

$publishDir = $TYPO3_CONF_VARS['FE']['publish_dir'];
if ($publishDir && @is_dir($publishDir))	{
	$publishDir = ereg_replace('/*$','',$publishDir).'/';
	debug('Publishing in: '.$publishDir,1);
	reset($temp_publish_array);
	while(list($key,$val)=each($temp_publish_array))	{
//ADDED PRS 01092004 BEGIN
                 $_fdfx_dir_array=explode("/",$key);
                 if (($_fdfx_counter=count($_fdfx_dir_array))>1)
                 {
                 // we expect that either <something.html> or
                 // <path/to/something.html> is arraving here
                 // so count of exploded string is either 1 or larger.
                 // if it is larger then we have a path to check or create
                         $_fdfx_path=$publishDir;
                         // as last element should be <something.html> 
we have to deduct 1!
                         for 
($_fdfx_i=0;$_fdfx_i<$_fdfx_counter-1;$_fdfx_i++)
                         {
                                 $_fdfx_path 
.=$_fdfx_dir_array[$_fdfx_i].'/';
                                 if (! is_dir($_fdfx_path))
                                 {
                                         //cretate the directory
                                         t3lib_div::mkdir($_fdfx_path);
                                 }
                         }
                 }
//ADDED PRS 01092004 END
		$file = $publishDir.$key;
		t3lib_div::writeFile($file,$val[2]);
		debug('Writing: '.$file,1);
	}
//	debug($temp_publish_array);


As a Javascript file was changed it might be helpfull to delete the 
browser cache as MS IE is sometimes very kindish. You should also delete 
the Tpo3 cache.

Missing is the .htaccess. But this will not be a nightmare.

Enjoy.

Regs. Peter

P.S:
1)Multilingual is only a question of passing the parameter OR just a 
different <alias>
2)Multidomain could be implemented if multi publish_dir would be 
supported. But for the first approach it was sufficient for me to 
demonstrate that the concept is working.
3)Also w/o an adjustment to .htaccess you will see that your alias will 
work!
4) No we would need more comfort to get alias generated automatically.




More information about the TYPO3-dev mailing list