eZ Publish Feedback Form Template

This template makes a feedback form a little easier to use. It sets up the from and the subject out of the submitted content, and puts the message in as text.


{set-block scope=global variable=cache_ttl}0{/set-block}
{set-block scope=global variable=$email_receiver}{$object.data_map.recipient.content}{/set-block}
{foreach $collection.attributes as $a}
{switch match=$a.contentclass_attribute_name}
{case match='Subject'}
{set-block scope=global variable=$subject}[Website] {$a.content|wash}{/set-block}
{/case}
{case match='Message'}
{attribute_result_gui view=info attribute=$a}
{/case}
{case match='Email'}
{set-block scope=global variable=$email_sender}{$a.content|wash}{/set-block}
{/case}
{/switch}
{/foreach}

Be sure to adjust your attribute names if necessary.

Using .htaccess to Report Delivery Time

The question was whether the number of rewrite rules in .htaccess would have a significant impact on performance.

With the following set of rewrite rules:

Options +FollowSymLinks -Indexes
<IfModule mod_php5.c>
        php_value magic_quotes_gpc 0
        php_value magic_quotes_runtime 0
        php_value allow_call_time_pass_reference 0
</IfModule>
DirectoryIndex index.php
<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^cms/index\.php/plain_admin$ http://domain.com/admin [R=3
01,L]
        RewriteRule ^cms/index\.php/plain(.*) $1 [R=301,L]
        RewriteRule ^media.* - [L]
        RewriteRule ^custom.* - [L]
        RewriteRule content/treemenu/? /index_treemenu.php [L]
        RewriteRule ^var/[^/]+/cache/public/.* - [L]
        RewriteRule ^var/storage/.* - [L]
        RewriteRule ^var/[^/]+/storage/.* - [L]
        RewriteRule ^var/cache/texttoimage/.* - [L]
        RewriteRule ^var/[^/]+/cache/texttoimage/.* - [L]
        RewriteRule ^design/[^/]+/(stylesheets|images|javascript)/.* - [L]
        RewriteRule ^share/icons/.* - [L]
        RewriteRule ^extension/[^/]+/design/[^/]+/(stylesheets|images|javascripts?)/.* - [L]
        RewriteRule ^packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.* - [L]
        RewriteRule ^packages/styles/.+/thumbnail/.* - [L]
        RewriteRule ^/favicon\.ico - [L]
        RewriteRule ^/robots\.txt - [L]
        # Uncomment the following lines when using popup style debug.
        # RewriteRule ^/var/cache/debug\.html.* - [L]
        # RewriteRule ^/var/[^/]+/cache/debug\.html.* - [L]

        RewriteCond %{HTTP_HOST} ^webdav\..*
        RewriteRule ^(.*) /webdav.php [L]

        RewriteRule .* index.php
</IfModule>

The results were:

Received: t=1267660375832889 Duration: D=273652
Received: t=1267660761803171 Duration: D=297682
Received: t=1267660779066518 Duration: D=272959
Received: t=1267660804103095 Duration: D=292675
Received: t=1267660821137470 Duration: D=256268

This set of rewrite rules:

Options +FollowSymLinks -Indexes
<IfModule mod_php5.c>
        php_value magic_quotes_gpc 0
        php_value magic_quotes_runtime 0
        php_value allow_call_time_pass_reference 0
</IfModule>
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^media.* - [L]
RewriteRule ^custom.* - [L]
RewriteRule !(\.(gif|jpe?g?|png|css|swf|mp4|js|html?)|var(.+)storage.pdf(.+)\.pdf)$ index.php
</IfModule>

Yielded these results:

Received: t=1267660624947466 Duration: D=279933
Received: t=1267660660237894 Duration: D=289207
Received: t=1267660681578539 Duration: D=327192
Received: t=1267660701894745 Duration: D=254252
Received: t=1267660719493366 Duration: D=262131

This was a very informal test, just to see if there were any glaring differences, as you can see, the results were reasonably close.

CSV export out of eZ Publish

A team member requested a list of users and email addresses from an eZ publish site, and I remembered seeing a file called ezcsvexport.com under php/bin.

After a few tries, I found the following sequence of commands worked really well.

CSV_EXPORT_BASE=~/tools/export
cd ~/public_html/ez
/usr/local/bin/php -C bin/php/ezcsvexport.php 12 –storage-dir=$CSV_EXPORT_BASE -smsite -q -l export -p password 2> /dev/null
rm $CSV_EXPORT_BASE/*.png 2> /dev/null
rm $CSV_EXPORT_BASE/*.jpg 2> /dev/null
rm $CSV_EXPORT_BASE/*.gif 2> /dev/null
rm $CSV_EXPORT_BASE/*.bmp 2> /dev/null
sed “s/\([^\;]*\);\([^\;]*\);[^\|]*[\|]\(\|[^\|]*\)[\|].*$/\1,\2,\3/” $CSV_EXPORT_BASE/user.csv | grep -v ‘;’ | grep ‘@’ | mail email@domain.com -s “eZ Guest Accounts”

This created a file called user.csv, which was delimited with semicolons and included all the information. The account information (username, email, etc) was serialized, meaning separated with vertical bars or piping characters. I used sed to replace the semicolons with commas, and find the second element of the user account data (the email address). Some people had added signatures, so one grep command was used to get only those lines with @s in them, since that indicates an email address. Finally the whole thing was piped through mail and sent to the requestor.

The export script saved me a lot of time.

eZ Publish RewriteRule to redirect a URI match site to hostname

The old site had eZ publish installed in a directory called cms, and running in URI match mode. These redirect rules allow people who have bookmarks and favorites to the old site to reach the correct pages in the new site.


RewriteRule cms/index\.php/plain_admin$ http://stkathryns.org/new [R=301,L]
RewriteRule cms/index\.php/plain(.*) /$1 [R=301,L]
RewriteRule cms/index\.php$ / [R=301,L]

Zend Framework - Building Forms without writing XHTML

This block of text, from the link above, describes a form input for a username element.

#
; username element
user.login.elements.username.type = "text"
user.login.elements.username.options.validators.alnum.validator = "alnum"
user.login.elements.username.options.validators.regex.validator = "regex"
user.login.elements.username.options.validators.regex.options.pattern = "/^[a-z]/i"
user.login.elements.username.options.validators.strlen.validator = "StringLength"
user.login.elements.username.options.validators.strlen.options.min = "6"
user.login.elements.username.options.validators.strlen.options.max = "20"
user.login.elements.username.options.required = true
user.login.elements.username.options.filters.lower.filter = "StringToLower"

This is the code in the Form which uses the .ini settings:

      $config = new Zend_Config_Ini($configFile, 'development');
      $form   = new Zend_Form($config->user->login);

And the entire form is displayed with:

      <?php echo $this->form ?>

With the routine, repetitive, and time-consuming exercise of writing XHTML eliminated, you can focus on the business logic, and build applications lightening fast.

You retain complete control of the output, decorators are used to apply the XHTML to the form elements. You can create one decorator for the entire system, and your whole application will have a consistent interface.