Thoughts Electrique

Posts Tagged ‘Tutorial’

Decentralized categories in OpenCms 7.5

Friday, November 6th, 2009

This feature was presented by Michael Emmerich during the OpenCms Days 2009 and caused a lot of people to grab their pen.

A short background on categories

Categories are a built-in content relation in OpenCms and allow files in the VFS to be assigned one or more topics/keywords/whatever. They can often be used as a replacement feature for siblings which are mostly misunderstood by users without a technical background. For example consider the typical example of a news site. You have a folder structure for your articles which could be the following way:

/articles/2008/12-24-merry-christmas.html
/articles/2009/09-01-new-site.html
/articles/2009/10-02-a-great-article.html

You now want to categorize the articles into topics so you would create another folder structure:

/topic/must-read
/topic/technical

The sibling-way would be to create a sibling (put simply: an automatically updating copy) of the articles in the desired topic folder. While this is a working solution it’s counterintuitive to most users. OpenCms 7 introduced the long awaited Content Relation Engine (CRE) including a default relation called categories. Similar to the sibling solution a category is effectively a folder but instead of creating it anywhere in the filesystem it’s created in the root site (“/”) under /system/categories/. Users can now assign categories to VFS files using the context-menu entry Relations -> Assign Categories. This is a much easier approach although it has one caveat: Categories are globally defined in the /system/ folder and can therefore only be created by users with access to the root site and can not be specified on a per site or even per folder basis. This can cause problems in multisite environments.

Decentralization to the rescue

With OpenCms 7.5 this limitation is finally gone. You can now define categories on a per-site and even per-folder basis. Simply create a folder named _categories in the folder where you want the categories to be available. Then create new folders inside this folder to define categories. The categories are available in the parent folder of the _categories-folder and all subfolders. They also cascade down. Example:

/de/_categories/
/de/_categories/hot-topic
/de/_categories/support
/de/news/_categories/
/de/news/_categories/marketing
/de/news/_categories/development

Inside the /de/ folder the categories hot-topic and support are available. Inside /de/news/ the categories hot-topic, support, marketing and development are available.

This feature should easily help you to get your content structured more nicely. Speaking from experience it is crucial to create an evolveable content structure upfront so your editors as well as visitors and search engines get the most out of your site.

See also:

Updating a broken SME 7.1 Server to version 7.4

Friday, October 23rd, 2009

The SME LogoThe SME Server is a great Linux distribution for small to medium sized businesses. I’ve been doing some emergency sysadmin stuff quite a while ago and encountered the upgrade-hell from 7.1 to version 7.4. Since updating the operating system from 7.1 to 7.4 wasn’t easy I decided to write a quick blog post to save you from tinkering.

(more…)

Installing PHP / PECL ImageMagick extension on 1&1 managed server

Saturday, September 26th, 2009

I once had to install a custom PHP extension on a 1&1 managed server. In this case the company had already purchased a managed server which was running the corporate website. They wanted to install an extranet-like webapplication which needed the ImageMagick PHP extension. In the following post I will outlike how I compiled and installed this extension on the managed server without having administrative access.

(more…)

Setting up XWiki in Tomcat and MySQL

Thursday, September 10th, 2009

I recently set up a new XWiki 2.0 instance (with MySQL) for documentation purposes. Although some of the steps are already described in the XWiki manual I’ll document it here mainly because I keep forgetting things. Also step-by-step tutorials come in handy when you’re in a hurry.

(more…)

Restrict visibility of OpenCms templates to certain folders

Wednesday, June 3rd, 2009

Since I’m currently working on an OpenCms mutli site solution I was looking for a possibility to restrict the available templates of a site. I know this can be done via permissions but the manual implementation of this is rather painful. I’m currently in the process of extending the OpenCms security manager to take care of this but while doing this I found an (to me) unknown feature.

By usage of the property folders.available (you might have to define it first) on a template you can specify a list of comma seperated folders in which the template is available (in the dropdown).

Unfortunately this property works only on file level and can not be inherited via the folder hierarchy. Also it does not provide a secure solution since the template can always be set via the advanced property dialog.

But you never know when a feature could come in handy.

Custom php.ini and URL rewriting in Plesk 9 with fastcgi

Thursday, March 19th, 2009

For a current hosting server I’m using the Plesk control panel 9.0.1 for Ubuntu 8.04. Since version 9 Plesk allows the usage of Postfix as an MTA and PHP via FastCGI. This is very nice and much more secure than the old model using mod_php.

The Problem

One problem with the current Plesk version (as with most Plesk versions :/) is that it has some nasty bugs. For example mod_rewrite doesn’t work with the FastCGI configuration. The problem is that the generated virtual host configuration has a small but important problem. The generated host looks something like this:

<VirtualHost 88.198.164.10:80>
  ServerName   playground.himberger.de:80
  ServerAlias  www.playground.himberger.de

  <IfModule mod_fcgid.c>
    <Files ~ (\.php)>
      SetHandler fcgid-script
      FCGIWrapper /usr/bin/php5-cgi .php
      Options ExecCGI
      allow from all
    </Files>
  </IfModule>
</VirtualHost>

The issue with this configuration is the line “Options ExecCGI“. This line enables the execution of CGI scripts for this particular directory but overrides all the Options set earlier. These are in parts needed for mod_rewrite. To fix this the line should be “Options +ExecCGI“. Sadly changing the configuration doesn’t help because at the next opportunity Plesk will regenerate the config file and your change is gone.

Luckily there is a way around this…

(more…)

Static IPs and default route on 1und1 CentOS 5 Servers

Wednesday, March 11th, 2009

I’ve been experiencing some serverdowns at a client who uses 1und1 CentOS 5 Servers. After some investigation I discovered that cronjobs were still running although the server appeared to be down. Checking the syslogs showed me a bunch of failed DHCP requests which remebered me of the fact that 1und1 uses DHCP to configure the server machines. I don’t think this is a good idea so I changed the setup to static IPs.

Since 1und1 puts every server behind a dedicated firewall the setup is not as easy as you think. I’ll document it here because It may be useful for other people and certainly for myself after a couple of months.

Configure a static IP address

Open the file /etc/sysconfig/network-scripts/ifcfg-eth0 and edit it to look like the following:

DEVICE=eth0
BOOTPROTO=none
TYPE=Ethernet
ONBOOT=yes
HWADDR=$YOURMACADDRESS
NETMASK=255.255.255.255
IPADDR=$YOURIP
GATEWAY=10.255.255.1

Save the file.

Configure static routes

This is the tricky part. Configuring a default gateway using the GATEWAY= setting is not enough. You have to setup the routes yourself. To do so create a new file /etc/sysconfig/network-scripts/route-eth0 with the following contents:

10.255.255.1 dev eth0
default via 10.255.255.1 dev eth0

Now you only have to reload the networking configuration via

service network reload

and you are done!

This post helped me a lot with the solution.

OpenCms Apache integration: The simplest solution

Wednesday, March 11th, 2009

My OpenCms Apache Integration Howto for OpenCms 6 still get’s a lot of visitors. Many things have changed since I first wrote this howto and certainly things are a lot easier now. I always wanted to rewrite the howto but till then I will just publish a short update on how to integrate OpenCms 7 with Apache and to remove the /opencms prefix with the most recent software.

(more…)

Use the power of JSP tag files in OpenCms

Friday, December 12th, 2008

Since version 7 OpenCms is a Servlet 2.4 and JSP 2.0 conforming application. In addition to the improved expression language (EL) JSP 2.0 also brings in the possibility of developing custom tags(actions) using JSP rather than writing Java code. This allows for some pretty neat things and enables you to go one step further towards cleaner view code. I’ve used this in one of my last projects extensively to refactor common code like pagers and link generation. For example:

<cms:include file="/system/modules/com.example.ocms.commons/elements/pager">
  <cms:param name="currentPage">
    <c:out value="${model.currentPage}"/>
  </cms:param>
  <cms:param name="pageCount">
    <c:out value="${model.pageCount}"/>
  </cms:param>
</cms:include>

Became:

<wt:pager model="${model}"/>

Not does it only look cleaner and is much more focused, it also decouples your view more from the underlying CMS solution. Of course you could also develop a custom tag library using Java (which I have done a few times) but using a JSP the advantage that code can be changed on the fly and even from a web designer. You can always refactor your JSP taglib into a Java one if you need to do it. There are some limitations of JSP tag files (like you can’t use scriptlets in the body) but they are easy to get around.

But as always: This is no silver bullet. There are problems with tag files which may not be obvious at the first glance.

(more…)

Better SEO for external links in OpenCms Navigation

Wednesday, November 26th, 2008

The Problem

If you put an external link into the OpenCms navigation the resulting link will target the external link file which then in turns redirects the surfer to the external page. This is bad if you really want to optimize your navigation for search engines, because search engines won’t see the real link inside the navigation.

The solution

You can use the following JSP snippet to get the real URL from a CmsJspNavElement.

// We assume that the variable "link" holds an CmsJspNavElement and
// "cmsa" holds an CmsJspActionElement.

// Prevent external links from beeing a redirect
// therefore extract the real URL out of the file
String fileUri = link.getResourceName();
CmsResource navResource = cmsa.getCmsObject().readResource(fileUri);
if (navResource.getTypeId() == CmsResourceTypePointer.getStaticTypeId()) {
    CmsFile navFile = CmsFile.upgrade(navResource,cmsa.getCmsObject());
    String externalLink = new String(navFile.getContents());
    externalLink = externalLink.trim();
}

Further reading