Cross-siteaccess internal links in eZ Publish

Among the many advantages of hosting multiple sites on the same eZ Publish installation is the ability to create internal links. eznode:// and ezobject:// links preserve the accuracy of the generated URL links even when content is moved around or renamed within any of the sites. (Of course, you can also use such links even when you host only one site.) However, out of the box, eZ Publish is not siteaccess-aware when generating cross-siteaccess links. For example, if your site sitea.com is contained within the subtree /sitea and your site siteb.com is contained within the subtree /siteb, internal links from sitea.com to siteb.com would end up linking to "sitea.com/siteb/article" instead of "siteb.com/article". While the user can be redirected with rewrite rules, it still creates a confusing user experience. Here's a simple solution jointly developed with another eZ Partner Granite Horizon that results in generated links that are siteaccess-aware.

In this solution, we will create a custom template operator called prefixurl, which will convert cross-siteaccess links to include their correct domain names, before final processing with the ezurl() operator.

First you'll have to override the default link.tpl template (look in templates/content/datatype/view/ezxmltags in the standard design), which is used for links in eZ XML blocks and looks a bit like this:

<a href={$href|ezurl}[...]

Force the link to be passed through the prefixurl first, which will handle any cross-siteaccess links:

<a href={$href|prefixurl()|ezurl()}
 

Before looking at the prefixurl operator, let's look at some helper INI settings that will help the operator map the full domain names where relevant.

In settings/override/site.ini.append.php, we have our path prefix mapping:

 
[SiteSettings]
PathPrefixURLMap[]
PathPrefixURLMap[sitea]=http://www.sitea.com
PathPrefixURLMap[siteb]=http://www.siteb.com
 

And now the important part of the template operator prefixurl (for a basic intro to developing template operators, see this article):

switch ( $operatorName )
{
    case 'prefixurl':
    {
        $siteINI = eZINI::instance();
        $pathPrefixURLMap = $siteINI->variable( 'SiteSettings', 'PathPrefixURLMap' );
        $pathPrefix = $siteINI->variable( 'SiteAccessSettings', 'PathPrefix' );
 
        // Do not match the siteaccess you are currently in
        unset( $pathPrefixURLMap[ $pathPrefix ] ); 
 
        foreach( $pathPrefixURLMap as $prefix => $pathURL )
        {
            if ( 0 == strncmp( $prefix, $operatorValue, strlen( $prefix ) ) )
            {
                $operatorValue = str_replace( $prefix, $pathURL, $operatorValue );
                break;
            }
        }
        break;
    }
}
 

And that's it!

Since the PathPrefixURLMap keys and values are likely to already exist in each of your siteaccesses' PathPrefix and SiteURL settings, you could write an alternative template operator solution that loops through each siteaccess's settings and that doesn't require extra INI settings. However, this means quite a bit of extra code and processing. Therefore, for sites with less than, say, a dozen siteaccesses, the work of adding and maintaining the redundant INI settings is probably worth it.

Got a solution that is more efficient? Let us know in the comments!

Comments

blog comments powered by Disqus

Contact

604-637-6396
hiATmugo.ca

#414-207 W. Hastings St
Vancouver, BC
Canada


RSS icon Twitter icon

We have been using this team for editing, consulting, support and training services in North America for the last 3 years and we still do. The team has shown their expert knowledge of our systems, and is responsive and dedicated. The services they provide include expert consulting on eZ Publish towards large, high-traffic enterprise customers.

CEO Aleksander Farstad , eZ Systems

I relied on Mugo for the development of two complex web applications, and I was extremely impressed with their accurate estimates, consistent and timely delivery of production code, and commitment. They have the rare blend of business knowledge and deep technical expertise, and they excel at listening to business requirements and translating those requirements into intelligent and reliable software products. They are able to work on all aspects of software solutions -- front end/UI, core code, modules and extensions, application integration, and infrastructure -- and they are extremely capable in all of those areas. I highly recommend Mugo to anyone in need of a competent and dependable technology partner.

Co-Founder Graham Tillotson, Tandem, Chicago

Mugo maintains and develops new features for the Rasmussen Reports website, www.rasmussenreports.com. We are impressed with how efficiently they deliver high quality solutions that exactly fit our needs. The Mugo team understands the complexity of our high traffic website and was able to improve our site's overall performance, as well as its search engine rating. For our site's subscribers, Mugo quickly and efficiently developed many new features for our Premium Section.

The Mugo team is great to work with, and I look forward to a long and productive relationship.

Stephen W Smith, Interim CEO, Rasmussen Reports

If you ask me what is the first thing you think of about the Mugo team, I would say that they listen.

For a customer, the worst thing is to work with a partner that doesn't listen to you. That doesn't understand your points. That simply doesn't listen and try to help you.

Daniel Iribarren, ClearCap

Mugo Web is not another service provider. They are your partners.
One of the things I really like about the Mugo team is that they care about my project and myself. That is why I call them my partners.

Daniel Iribarren, ClearCap

Mugo Web is not just a group of geeks. They are a team of highly knowledgeable technology and business people.
They understand that they are helping you to design solutions to satisfy or solve business problems. And not every developer is able to deliver that. I have worked with more than 10 different let's says production centers and what they delivered to me was geek stuff. Not business solutions.
Mugo Web will help you to use geek stuff to solve business problems.

Daniel Iribarren, ClearCap

It's been a pleasure working with Mugo Web. They are fast, efficient and always helpful. They respond positively to questions and offer great solutions to technical problems.

Susan Wright, Director of Operations, Toronto Arts Council and Foundation

We've been extremely pleased with the work Mugo has done for us. They have been responsive and understanding in dealing with the complexities of our needs.

Wendy Prugh, Program Manager, The Christian Science Monitor

The team members we work with at Mugo have demonstrated a high caliber of competency in the work they do, and it instills great confidence in us to know that we have such quality professionals in our corner. Their consistent delivery has helped us develop a fluid system for enacting change and improvements on our website. We certainly look forward to continuing this relationship!

Wendy Prugh, Program Manager, The Christian Science Monitor

Thank you very much Mugo Web for the website work you've done for our company. You valued & respected our time. You produced quality work. You paid attention to detail and understood the JPLradio concept. Most importantly, we appreciate the good business ethic of our contact person your company provided. For that, I/we thank you.

Troy B. Williams, Founder & Program Director, Just Positive Lyrics Radio.com

We thoroughly enjoy our working relationship with Mugo Web. They are customer-focused, take the time to listen, give good solid advice with our best interests in mind, and have a quick turnaround time. We've had a number of compliments on the new website, which looks goods, functions well, and performs solidly.

Paul O'Sullivan, IT Specialist, New Society Publishers

Tweets

  • eZ Flow pull request merged: allowing custom attributes on manual blocks; new custom attribute select type: https://t.co/YlLvWHV9 #ezpublish
    Posted at Fri Feb 03 15:35:51 +0000 2012
  • Switched from Facebook comments to Disqus on our blog; Disqus is much nicer to work with; example with ported comments: http://t.co/oj41cd2K
    Posted at Thu Feb 02 17:14:29 +0000 2012
  • Exact image resizing in eZ Publish with custom image filters http://t.co/RbRqZS7I #ezpublish
    Posted at Wed Feb 01 15:40:21 +0000 2012
  • RT @gggeek: The ultimate content staging extension for #eZPublish is open to contributions. http://t.co/STg5DxNF
    Posted at Tue Jan 31 15:00:47 +0000 2012

Follow Mugo on Twitter