Thoughts Electrique

Archive for November, 2008

JavaScript void links in OpenCms 6.2.3 WYSIWYG

Friday, November 28th, 2008

Just a quick note: There was a long standing problem regarding the FCKEditor (HTML editor) in OpenCms 6.2.X using Firefox 3. Adding links always produced an URL like javascript:void(0)/*1241321*/. Since most customers are already on OpenCms 7 this is not such a big problem but recently I had to look for a fix. It turned out the bug was quite popular and there is quite an easy workaround.

Open the file /system/workplace/resources/editors/fckeditor/editor/js/fckeditorcode_gecko_2.js in OpenCms and replace the text:

FCK.ExecuteNamedCommand('CreateLink',B);var C=document.evaluate

with:

FCK.ExecuteNamedCommand('CreateLink',B);var C=this.EditorDocument.evaluate

Publish the file and this should be it. Don’t forget to empty your browser cache afterwards (don’t just press CTRL+F5) otherwise you will still get the old file.

Of course this is not a real fix, but if you have to get rid of the problem fast. This can help.

Update: In OpenCms 6.2.3 the file is called fckeditorcode_gecko.js not fckeditorcode_gecko_2.js.

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

Runkit with PHP on Linux (Debian Etch)

Sunday, November 23rd, 2008

The forbidden fruit

I recently discovered runkit for PHP and thought it could be a solution for a few problems I ran into during my work on various projects.

At heart runkit allows you do to stuff with PHP you shouldn’t, but eventually want to, do. In my case this is basically Sandboxing and redefining (even PHP-internal) functions. It really adds some cool stuff to your PHP toolbox. Have a look at the function reference for the complete list.

Sadly enough the runkit PECL package does not work on Debian Etch (because Etch uses PHP 5.2.0+) so I had to build the package myself. Read on to find out how to build and install runkit on Debian etch and things to keep in mind when using runkit.

Important: If you are unsure of using runkit have a look at The sections The Caveat and Final Remarks before you walk through the hassle of installing it.

(more…)

Google Analytics with OpenCms

Wednesday, November 19th, 2008

Avoid the wrong track

For a while I have been using Google Analytics for my website statistics (additionally to AWStats) and I really like the reports (Note: Yahoo! now has a competing product out there called “Yahoo! Web Analytics” which I might check out in the future). I’ve also installed various tracking software (like etracker - which is a German service) on different CMS solutions at customer sites.

Nearly all services offer some copy&paste code to throw into your HTML/JSP/PHP/Whatever, but if you’re using a CMS system things might be a bit more complicated. In most CMS systems you have two different kinds of traffic: Visitor generated and editor generated. Editors browse the site while checking their changes or proofreading text in the offline area (unpublished content). You most likely don’t want to have this traffic screw up your statistics, so it makes sense to filter out the traffic. Mostly a simple if(…)-clause is all that’s needed to achieve this. Here is my solution for OpenCms:

<%@ page session="false" %>
<%@ page import="org.opencms.jsp.*,org.opencms.file.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  CmsJspActionElement cmsa = new CmsJspActionElement(pageContext,request,response);
  CmsUser currentUser = cmsa.getRequestContext().currentUser();
  boolean displayAnalytics = currentUser.isGuestUser() || currentUser.isWebuser();
  pageContext.setAttribute("displayAnalytics",new Boolean(displayAnalytics));
%>
<c:if test="${displayAnalytics}">
  <!-- Your Google Analytics JavaScript goes here -->
</c:if>

Of course you can easily create a JSP from this and include it in your template.

Hello World

Wednesday, November 19th, 2008

Hi there,

finally I have decided to join the trend and start blogging. There are several reasons why I chose do so. The two main ones are:

  • I want to publish information in a more informal way. I have many ideas regarding small articles and code-snippets which may be useful for other people and are very useful for myself because I keep forgetting stuff.
  • I started working as a freelance software developer and since I’m mostly working at home this means no more (or much less) office chat. I hope this blog is a way to keep in touch with old (and new) colleagues and customers to inform them of what I’m working on right now. Hopefully it will spur some discussion.

There’s really not much more to say. We’ll see how this blog will develop. I must admit I’m very exited about it.

I hope you have fun reading this blog.

Best regards,
Sebastian