Posted on 1 Comment

Custom WordPress Permalinks Are Causing 403 or 404 Errors

Wordpress Logo

When settings custom permalink structures in your WordPress settings make sure to

  1. either make .htaccess writeable by your webserver so that when saving your custom structure via the backend WordPress will automatically update your .htaccess too
  2. or manually edit your .htaccess file with the minimal required mod_rewrite rules as shown below, right after setting your custom permalink structure via the backend
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Also, make sure that your RewriteBase setting is correct.

Hint:
In case you experience 403/404 errors after setting your custom permalink structure here is what you can do:

  1. open options table from database and locate the permalink_structure field
  2. clear its value and save the entry
  3. remove the above mod_rewrite content from .htaccess
  4. make .htaccess writeable by your webserver
  5. reload your backend URL (/wp-admin)

This way you can reset your permalink structure to “Default” setting and start over again.

Posted on 2 Comments

Setting Custom Portlet Titles in Liferay

Liferay Logo

Setting custom portlet titles in Liferay can be a little tricky. Changing the title via the portlet configuration in the frontend is easy but when it comes to reading the custom title property programmatically things seem to get a little messy.

Setting the Title

So, first of set your portlet title as usual via the portlet configuration in the frontend. That’s the easy part.

Determining Portle Title Programmatically

Then, in order to determine custom portlet titles use the following code:

ThemeDisplay themeDisplay = ((ThemeDisplay) request
  .getAttribute(WebKeys.THEME_DISPLAY));
String portletId = themeDisplay.getPortletDisplay().getId();
javax.portlet.PortletPreferences portletSetup = PortletPreferencesFactoryUtil
  .getLayoutPortletSetup(themeDisplay.getLayout(), portletId);
String portletCustomTitle = themeDisplay.getPortletDisplay()
  .getTitle();
portletCustomTitle = portletSetup.getValue("portletSetupTitle_"
  + themeDisplay.getLanguageId(), portletCustomTitle);

This code will determine the current portlet’s ID, get its preferences, determine the current namespace and finally retrieve the custom portlet title.

In case you need to read other custom portlet properties simply look up their keys in the database and use the portletSetup.getValue(“yourKey_”, …) option as shown previously.

Posted on Leave a comment

Customizing Date Format in JIRA

Jira Logo

Sometimes you might want (or need) to change the default date-time format set in JIRA. Out of the box the format is set to d/MMM/yy, which translates to for instance 1/Jan/13.

Luckily, this setting can be easily edited through the administration interface under System » General Configuration » Advanced (scroll down the General Configuration page), as shown below:

JIRA -> General Configuration -> Advanced

In order to change the format for dates and date-times you need to look for four options:

JIRA Datetime Format Options

Whereas jira.date.picker.* takes care of settings the format used for date strings, jira.date.time.picker.* sets the desired date-time format. Furthermore, there are two options for each of these settings, one for the client side datepicker (*.javascript.format) and the other for the JAVA formatter (*.java.format).

Matching Formats

Be aware of the fact that changing the way dates and datetime strings are display on the client side must conform to the format used on the server side, i.e. the server must be able to interpret the dates posted. Thus, it is required that the JavaScript and JAVA formats specified in the configuration match.

In case your settings do not match you will get an error such as “Please enter the date in the format “d/MMM/yy” when trying to save dates using the date picker.

Possible combinations for these format specifications can be found on Atlassian’s Configuring date picker formats page.

Look and Feel

Optionally. you can edit the way dates and datetime are displayed to users through the Look and Feel section in the administration interface (System » User Interface » Look and Feel):

JIRA Look and Feel Date Time Formats

Posted on 1 Comment

Setting Custom Timezones in Liferay

Liferay Logo

By default Liferay uses UTC as timezone. In order to set custom timezones you may choose from the following options:

  1. Create an EXT-Plugin
  2. Specify timezone in Tomcat’s setenv script

EXT-Plugin

Create an EXT-plugin (or use your existing one) and put system-ext.properties in extyour-extdocrootWEB-INFext-implsrc using the following setting:

user.timezone=Europe/Vienna

Be sure the deploy and restart Tomcat afterwards. Also, check via the Control Panel in Server Administration / System properies that the timezone attribute has been applied correctly.

Setenv Script

The other option is to set your desired timezone in Tomcat’s setenv script located in tomcat/bin by using the following command:

-Duser.timezone=Europe/Vienna

Depending on your operating system you will need to configure setenv.bat (Windows) or setenv.sh.

Liferay Developer Studio

If you happen to use Liferay Developer Studio you can easily set your desired timezone using the server properties, as shown below:

Posted on 2 Comments

Custom Zend_Form view script

Zend Framework Logo

Sometimes Zend’s built-in form decorators are not flexible enough to achieve customized views. Luckily, Zend provides means to specify custom view scripts. The following example demonstrates how to set and handle such a script.

First and foremost, in your default (action) view script simply output the form as usual:

<div class="formContainer">
  <?php echo $this->form ?>
</div>

Then, in your derived Zend_Form class set your custom view script that takes care of rendering the form the way you need it:

/**
 * Custom Zend_Form view script example.
 * @author matthias.kerstner
 */
class Custom_Form extends Zend_Form {

    public function init() {
        $this->setDecorators(array(array(
                'viewScript',
                array(
                    'viewScript' => '_customForm.phtml',
                    array('formId' => 'CustomForm', 'formClass' => 'customForm')
            ))));

Finally, the custom Zend_Form view script looks like the following. Note that it uses additional parameters that you can specify in Custom_Form.

<?php
$params = $this->element->getDecorator('ViewScript')->getOptions();
$formId = $params[0]['formId'];
$formClass = (isset($params[0]['formClass'])) ? $params[0]['formClass'] : '';
?>

<form id="<?php echo $formId ?>" 
      class="<?php echo $formClass ?>"
      method="<?php echo $this->element->getMethod() ?>" 
      action="<?php echo $this->element->getAction() ?>" 
      enctype="<?php echo $this->element->getEnctype() ?>">

    <?php
    echo $this->element->my_element_1;
    echo $this->element->my_element_2;

    echo $this->element->submit;
    ?>

</form>

Don’t forget to call parent::init(); in any of your derived classes. Using custom view scripts gives you the full power to design your form view, but remember that in contrast to using built-in decorators you need to echo your elements manually in your view script.