Bug Day @ TUGRO Meetup 2012

19 December 2012 Comments Off

TYPO3 is something we speak every minute here at Arxia, but during the 3rd edition of TYPO3 Usergroup Romania Meetup 2012 we had the opportunity to get our hands dirty with some TYPO3 core code.

Inspired by the TYPO3 Bug Day event which used to be a monthly event, the national TYPO3 Romania community reunited the second day of TUGRO Meetup to solve & better understand the release flow of TYPO3 CMS.

We hosted the event at our office with free coffee & Internet for anyone who wished to give a helping hand. The different levels of difficulty of bugs helped us to find a bug for just about anyone, either frontend or backend coding.
But before we dived into code, we had to learn about the legal and infrastructure of the TYPO3 CMS contribution process.
The Contributor License Agreement (CLA) is a license based on Apache CLA, which allows contributors to keep all rights on the code and it allows the TYPO3 Association to handle the distribution & further development of thier code inside the TYPO3 project.

  • TYPO3 CMS 4.x – 6.x = GNU General Public License version 2
  • TYPO3 Neos = GNU General Public License version 3
  • TYPO3 Flow = GNU Lesser General Public License version 3

The CLA document can be downloaded here and after it was filled in, it must be sent via fax to the TYPO3 Association: +41 041 511 00 39. After it was reviewed by the TYPO3 Association, an email notification will be sent informing about the result and, if approved, the account on typo3.org will be marked as contributor.
But from our own experience, signing the CLA document is mandatory only if you plan to contribute to the NEOS project, as for TYPO3 CMS it is recommended, not mandatory.

The TYPO3 code is managed by Gerrit, a web based code review and project management for GIT based projects. TYPO3′s Gerrit interface is located at review.typo3.org and you can use the typo3.org account to login.
A review request can get:

Verified:

  • -1: Fails
  • 0: Have not tested
  • +1: Code works by testing
  • +2: Verification approved

Code Review:

  • +2: Verification approved
  • +1: Could commit, needs more approval
  • 0: No opinion, just adding some comment
  • -1: Please do not commit
  • -2: Veto

Note that “+1″ plus “+1″ does not add to “+2″. The +1 is only a indicator of how many people agree with the change (even anonymous reviewers). Only a core developer can ultimately give a “+2″, approving a change and unlocking the “Submit” button. But more on this can be read here.

Setting up the enviroment can be a bit difficult, but if you are using TortoiseGIT (as we did) and follow the instructions on setting up the enviroment, you will be ready to push things to TYPO3 core in less than 10 minutes!

The following links will help you:
Apache CLA
TYPO3 Release Workflow
TYPO3 Review Workflow
Coding Guidelines
Contribution Walkthrough Tutorials

Once everything is ready, head up to Forge (location where bug reporting is done), based on Redmine, a flexible project management web application written using Ruby on Rails framework, and choose a couple of bugs to solve.

DSC_2290

Solving bugs in TYPO3 turned out to be an easy task given the wide range of problems, a great way to learn more about the TYPO3 core and, of course, for the TYPO3 Romania community meant a great team working exercise!
We are looking forward to turn the Bug Day event into a recurrent event, not only at every TUGRO Meetup, but more often, maybe even monthly with the help of the TYPO3 Romania community.

Author: Tomita Militaru

TUGRO Meetup 2013 – impressions

18 December 2012 Comments Off

The end of the year was marked by the 3rd edition of TYPO3 Usergroup Romania Meetup, the biggest TYPO3 event in Romania. The event had 55 registrations and a brand new website this year. There was also a higher number in presentations and a social event.
But the highlight of this year was the extending of the event to 2 days with the first Bug Day community event. Bug Day was held the second day with volunteer developers that committed to learn more about the TYPO3 workflow, but also solve various TYPO3 bugs.

TUGRO Meetup started at 9 AM with people arriving from different parts of the country. The opening speech was held by Daniel Homorodean, managing director at Arxia.

DSC_2147

He was followed by Bodor László & Molnár Zsolt which showcased their Mobile Applications in TYPO3, presentation that was held also at TYPO3 Camp Mallorca this year! They amazed everyone by presenting an extension that can make a mobile website or an application for platforms iOS, Android, Blackberry or even Windows Phone from within TYPO3 backend.

300036_444327422281970_1198377975_n

Alina Fleser came with a solution for record lists in backend which can get big & complex, a custom extension that makes editing & search records a quick & easy task. Before the first coffee break Daniel challenged people into an open discussion about different business tactics web agencies in Romania use to increase revenue.

Alina Fleser

After everyone had a cup of coffee and a bit of socializing, we went on with another interesting presentation about BDD, Behat & TYPO3 by Tiberiu Contiu.

480729_444327458948633_1799461842_n

Tips & tricks in TYPO3 was next with examples of the new typoscript objects in TYPO3 versions 4.6 & 4.7 by Adrian Mot.

Adrian Mot

All that typoscript code made everyone hungry, so we had lunch at venue’s restaurant, plenty of free food!

Fluid Websites by Bodor László showed how we can make modern websites with FLUID templates all packaged in one TYPO3 extension, making it easier to distribute TYPO3 templates.

66046_444327552281957_91740648_n

Next up we had an introduction into TYPO3 & social networks, more specifically login with Facebook, Twitter & Linkedin, speaker Vasile Loghin.

Vasile Loghin

Speaking of social networking, Photogram was unveiled at the event, a TYPO3 extension that uses the Instagram API to showcase content from the photo sharing platform by Tomita Militaru

Tomita Militaru

Daniel Homorodean closed the event with an open discussion about the opportunity to have T3CON East-Europe 2013 in Romania and a call for volunteers in the TYPO3 Romania community to achieve this big event next year.

A social event was held at a local pub late in the night, but not too late as the following morning people were expected at Bug Day. More on that in the following article.

Santa’s Helpers: Operation Share and Care

5 December 2012 Comments Off

We believe in the importance of giving back to the community and creating positive changes by helping others. Mother Teresa said it best: “do small things with great love.” We consider ourselves to be proactive and believe that love makes life better. That being said, this year we have partnered up with World Vision and delivered Christmas joy to twenty four children in need.

DSC08986

Do you remember the feeling of excitement and surprise, waking up on Christmas as a kid to unwrap the super cool gifts? It was an amazing feeling wasn’t it? Unfortunately there are many underprivileged kids out there, who can only dream to experience this joy on Christmas day. This year we have changed that for all 24 children from the small and poor village Ticu-Colonie, about 50 km away from our location in Cluj-Napoca.

DSCF3864

The kids singing and sneak picking to Santa's full bag

With the support of the great people from World Vision activating in the village, the children wrote colorful letters to Santa, containing their “wish-list” for Christmas (the little-ones were filmed – as they are too small to write), and Santa answered each letter in part, with the help of his little elves – us. Answering the letters was quite cool, but not by far as great as dressing up one of our colleagues as Santa and delivering the presents.

The surprise factor was the incredible show prepared by the children for our visit. It was over an hour of Christmas plays, carols, songs and poems. It was unbelievable how much work and effort the little children put into this, just like real artists.

DSCF3962

Few of our colleagues and the man of the day - Santa (aka Alex)

We wish we could put into words the gratitude in their eyes when Santa offered each one of them the gift they dreamt of for Christmas; and oh, their smiling faces when they met Santa – priceless!

Author: Ramona Isai

Arxia sponsors the 3rd TYPO3 Usergroup Romania Meetup

13 November 2012 Comments Off

meetup

The Romanian TYPO3 community organizes the already traditional annual TYPO3 Usergroup Meetup. This is already the 3rd edition and it will take place as usual in December (8-9 December 2012). Arxia will be sponsoring this event as it did with the previous events.

What is different from the earlier editions is that the community decided to have a Bug Day on the second day of the Meetup,. Bug Day (inspired from TYPO3 Bug Day) is a community event for people pasionated about TYPO3 who gather for one day together to solve as many TYPO3 core bugs as possible. Each participant is free to work on a bug he chooses to or he can join teams to solve bigger / complex bugs. Arxia will host this bugday at its headquarters and will provide free coffee, internet connection and computers for those who need it.

There isn’t yet a definitive schedule but the Usergroup Meetup this year has a brand new website and for more information regarding the schedule we recommend that you keep an eye on that website.

Anyone interested in going to this Usergroup Meetup must register on the event’s website.

For more information you can contact Bodor László (bodor@arxia.com) who will be glad to offer you more details on any question you might have regarding this event.

Introducing our new TextWizzard jQuery plugin

31 October 2012 Comments Off

Today we are presenting you one of our newest developments. But just before we tell you what is about, we would like to ask a few questions.

Were you ever in a situation, where reading an article on a website was difficult because of  the contrast between the background color and the color of the text ?

Or maybe you read texts in languages other then your own and a few words were unknown to you ? What did you do ? Copy the word or sentence and paste it into Google Translate?

Or maybe you wanted to share a sentence or two from a text from a webpage through various social media channels like Facebook or Twitter ?

Well as you probably guessed it by now, the textWizzard jQuery plugin is about these features. When your visitors select a text on your website a small toolbox will appear that will allow them to :

- see a magnified text with changeable colors of the text and background

- for better contrast the users can select from a large scale of predefined color combos for text and background

- share to Facebook and Twitter the selected text

- send via mail the selected text

- hear the selected text as the plugin has text to speech abilities, if your users want to hear the text and not read it

- last but not least, they can translate any text on fly to one of the languages available : Albanian, Arabic, Bulgarian, Chinese, Croatian, Czech, Danish, Dutch, Estonian, French, Italian, Latin, Maltese, Finnish, German, Greek, Hebrew, Hindi, Hungarian, Indonesian, Japanese, Latvian, Norwegian, Polish, Portuguese, Romanian, Russian, Serbian, Spanish, Sweedish, Slovenian, Slovak, Thai, Turkish, Ukrainian, Vietnamese

- With this “all in one” approach, the textWizzard plugin offers the visitors of your site a better user experience, and the sites that use this script are more accessible to the public.

In the screenshots below you can see our plugin in action, before the popup window is activated and after it appears as an overlay on the content.

screen4

The original text and the plugin activated below (blue background)

screen3

The color combos

screen2

The translation tool

For the time being the textWizzard plugin is available for a licensing fee, for more informations don’t hesitate to contact us.

How to configure a TYPO3 website for Arabic language

25 September 2012 Comments Off

With TYPO3 we can have multiple languages in the backend and the different editors can use the backend modules and add frontend content in their language of choice. There is no problem in having an international team of editors which can edit and add content in lots of languages. As the TYPO3 community grows also the number of language packs is growing.

One of the available language packs is Arabic, which has a few interesting aspects and that’s why we will discuss it a little bit. One of the challenges in this case is that the texts in Arabic are right to left (RTL) instead of left to right (LTR).

Now let’s see how can we configure TYPO3 to allow this kind of content setup.

Available online tutorials offer as a solution for multilanguage site installation an extension called csh_XX where XX means a shortening for language name. But these methods are deprecated now and there are better solutions for this.

TYPO3 has a really advanced module to configure backend languages for each user using “Extension Manager”.For TYPO3 4.5 versions or older there is a section called “Translation Handling” and starting with TYPO3 4.6 the section is named “Language Pack”.There are more than 50 language packs and the number is growing.

BACKEND

Install and configure TYPO3 with desired language pack can be made using following steps:

1. Go to → “Extension Manager” → “Translation Handling” or “Language Pack”

2. Select your language pack

3. Press “Update from repository”

Each user can set his own backend language using “User settings” module.

Installing Arabic language pack or any language pack doesn’t come with a 100% translation of the text. There are labels of modules which doesn’t have a completely translation or literally translation.

· Workspace

· News Admin – tt_news

· Extension Manager

· Reports

· Scheduler

· Typoscript Help

· About Modules

Also, there are modules which hasn’t been translated completely, modules translated only partial and some of them without translation.

Modules with incomplete translation:

· Template

· News Admin

· User settings

· User Admin

· Extension Manager

· Configuration

· Log

· Indexing

· Reports

· Scheduler

Backend translations are available mostly for editors modules and functionalities.

FRONTEND

In order to create a website in arabic (non-latin) it is required that encoding to be UTF-8, not latin ANSI. We will have non-latin characters.

How to configure UTF-8 in TYPO3

1. System files

In order to configure encoding to be UTF-8 you will have to add following lines of code using localconf.php file or using Install Tool from Typo3.

// For backend charset

$TYPO3_CONF_VARS['BE']['forceCharset'] = ‘utf-8′;

$TYPO3_CONF_VARS['SYS']['setDBinit'] = ‘SET NAMES utf8;’;

$TYPO3_CONF_VARS['SYS']['multiplyDBfieldSize'] = ’3′;

Where:

-forceCharset as utf-8 it brings config.renderCharset and metaCharset set utf-8 by default utf-8.

-multiplyDBfieldSize is used to multiply the dimension of the fields in DB if you want to use an UTF-8 encoding.It is recommended to use „3” for non-latin languages as arabic or chinese.

-SET NAMES utf8 is equivalent to three SQL statements:

SET character_set_client = utf8;

SET character_set_results = utf8;

SET character_set_connection = utf8;

2.Apache

There is a configuration for Apache to specify the charset when browser is displaying a page for example.There are 2 methods to do that:

· .htaccess – safer.

· httpd.conf – faster.

AddDefaultCharset utf-8

3.PHP

In php.ini file you have to add the following line of code in order that all stand-alone script to use utf-8 charset.

default_charset = "utf-8"

4. TypoScript

There are some Typoscript configurations wich has to be done in order to use non-latin languages for pages, by default.

config.language = ar

config.locale_all = ar_AR.utf-8

config.htmlTag_langKey = ar-AR

[browser = msie]

config.htmlTag_setParams = xmlns="http://www.w3.org/1999/xhtml" xmlns:v=urn:schemas- microsoft-com:vml xml:lang="ar"

LIMITATIONS

There are some limitations when dislaying the text in non-lating language on page using TYPO3.

1.Right to left direction

First of all, for each paragraph of text it is necessary to set direction of the text from right to left using attribute dir in HTML (dir=”RTL”) , where RTL means Right To Left.

In TYPO3, build-in RTE (rtehmltarea) offer for editors possibility to set direction of text in a visual way. This option is available only when RTE is configured correctly to display this button. For example in Demo mode this button is displayed. Setting RTE to work in “Demo” mode can be done from “Extension Manager” , at extension configuration section.

Result: Text direction buttons (LTR and RTL)

clip_image003 clip_image004

Also, if you want to modify „dir” attribute for <html> tag you have to make an RTL configuration using Typoscript for root page template.

config.htmlTag_dir = rtl

2.Text alignment

By default, in html, text is aligned from left to right. If there is no configuration about alignment mode, then for a 2 lines text you can see that the second line isn’t properly align so you can read from right to left and that’s why there comes the need of setting rtl attribute.

3.RealURL

Using a non-latin language in TYPO3 brings some limitations when you have to work with RealURL. When you have to access some pages with title with non-latin text, it is impossible because URLs can’t contain characters other than latin. There are two ways to avoid such things.

a) enableAllUnicodeLetters

Usually, realURL makes the conversion of non-ASCII characters to their ASCII equivalent, allowing only characters like A-Z,a-z,0-9 and minus in URL segment. That cause problem to non-latin languages and this option allow URLs to encode incompatible characters into URL entities instead ignoring them completely. That method, usually slows down realURL and it is recommended using caching in RealURL to improve performances.

Setting enableAllUnicodeLetters as true can be done from realurl autoconf, info „init” array:

PATH : ~/typo3conf/realurl_autoconf.php

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']=array (
‘_DEFAULT’ =>
array (
‘init’ =>
array (

‘enableAllUnicodeLetters’ => true,

‘doNotRawUrlEncodeParameterNames’ => true,

……

b) Speaking URL path segment

A much easier method is to use an speaking path for RealURL to replace that non-latin title text. The disadvantage is that it needs for each page an individual speaking path and there is no more a conversion of page title to new non-latin language.

Title of the page will be the same in header and in menu(in non-latin language) and only URL will be modified with the speaking path.

4.Powermail

Using powermail extension in Arabic language brings with it some errors when, for example, you want to create a Powermail Form. When you install a new instance of Typo3, database is automatically created on latin charset, not in utf-8 and when you will create a form and add a field in Arabic language, characters won’t be displayed and won’t be saved properly. Each character will be replaced with “?” and when you will hit the save button will return an error like:

These Fields are not properly updated in database: (title) Probaly language mismatch with field Types”

If all fields needs to be saved properly and non-latin text to be displayed properly, it is needed that all powermail tables and database „Character” to be set as utf-8 and „Collatae” as utf8_general_ci.

ALTER DATABASE `databaseName` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

ALTER TABLE `tableName` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

and tables were:

· tx_powermail_domain_model_answers

· tx_powermail_domain_model_fields

· tx_powermail_domain_model_forms

· tx_powermail_domain_model_mails

· tx_powermail_domain_model_pages

CONCLUSION

As a conclusion we can say that it is not so difficult to create a website in a non-latin language (in this case Arabic) using TYPO3.There are some configurations which need to be adjusted in order to have a properly saved text into the database and a properly displayed text into frontend.As we can see, we only have to add some configurations into TYPO3 filesystem and configure Typoscript to have Arabic language for frontend pages.

It is not mandatory that Apache and PHP to be set as utf-8.It is most likely that a developer will not have access to core files from Apache and PHP and it is enough to configure database as utf-8 from Install Tool(or editing config file) and frontend from Typoscript.

Of course, there are some limitations and problems for some extensionsbut these can be fixed as we described for RealURL and Powermail.

The conclusion is: YES, it is not hard to develop a website in Arabic or any other non-latin language that requires right to left writing. There are resources and solutions for the problems that appear in these situations and the TYPO3 Enterprise CMS can be used universally by people from all over the world.

A glimpse on TYPO3camp Mallorca

18 September 2012 § 2

t3c_mallorca_200x60Between 14-16 September 2012 in the beautiful city of Palma de Mallorca took place the first international TYPO3camp. Arxia supported this event by sponsoring it and sending a team of 5 developers to attend at the different sessions which covered a broad range of topics. The 115 participants were from different places of Europe like: Germany, Romania, Poland, Spain, Denmark, The Netherlands.

The event started on Friday – the 14th of September with a Warmup party in Marchica which allowed people to get to know each other.  The next day kickstarted at Hotel Catalonia Majorica with the opening session and after that the planning session took place. For those not familiar with the barcamp format this means that everyone interested in holding a session can propose one and the participants can express their interest or not in that particular session.

schedule

Our team proposed a session called Mobile Apps from TYPO3 which is about an extension that allows the generation of mobile applications from inside TYPO3. There was quite some interest in this session so we went on and presented what we have done so far. The session was held by László Bodor and Zsolt Molnár (in picture below) and its available for download or you can view it on Slideshare.

laci&zsolt

Of course there were lots of other interesting sessions like: Zen coding, TYPO3 6.0, TYPO3 Scheduler, Scrum + Kanban, Make your website fly, TYPO3 & E-commerce.

The day ended with a social event at Diablito with lots of beer and wine and some pizzas for the participants. As you might imagine it this was a long night so the next day on Sunday the camp started a little bit later then announced.

The second day of the camp featured also some quite good sessions like: The past, present and future of CMS, BE Editors, TYPO3.org. This day ended slightly earlier then the previous as some people had airplanes to catch in the evening.

Overall TYPO3camp Mallorca was a very fine event, the organizers made everything possible that everyone feels good, have fun and learn something. Let’s hope that next year there will be an even bigger international TYPO3camp with participants from even more countries.

CASE STUDY : IdentityZ.com – a social network

5 September 2012 Comments Off

In the recent years, the Social Networks revolution changed the way we gather, interact and exchange information, and the online Communities thrive, bringing new value to organizations and products. We all know models of success, and we all use frequently at least several social networks.

Yet, each community is different, each organization has its specific, which derives from the special nature of the needs and opportunities that its members seek to be fulfilled.

Considering the launch of a new Social Network, it is imperative to find innovative ways to bring additional value for its members to be, because the members have to be attracted to the new community, they have to be engaged, encouraged to interact and to stay active permanently. The challenges are conceptual (find new, better ways to fit the needs of the requirements of the members), but also technical (incorporate the newest technical trends, find the most performant technical solutions). Bellow you will find the story of this endeavour, from our perspective, as web agency.

Main requirements

  • 1. Create a web platform which can be scaled when needed
  • 2. Define the architecture of a web application which allows the user to manage a lot of content types: profiles, contacts, albums, images, videos, documents, blog posts, comments, messages on the wall, personal messages, etc.
  • 3. Permanently improve the user experience on the site
  • 4. Simplify the functionality as much as possible to be easier to use

Technical challenges and solutions

  • 1. The application is implemented using Zend Framework
  • 2. Different uploads
    • – to allow the user to upload more video types all the videos were converted to flv in background and displayed them using a flash player
    • - multiple image upload using flash
    • - “on the fly” image upload
  • 3. The privileges management for the content elements and profiles
    We had to figure out a system which allows the user to share the same content element on more profiles and to share his/her profile with other users. When a profile is been shared, all the content elements present in that profile have to be shared as well with the owner of the second profile. The user has the possibility to change the shared profile with another user any time he/she wants by dragging the user from one profile column and dropping to another. The operations regarding the granting/revoking of privileges are handled in the background.
  • 4. Infinite scroll for all the available contents: wall messages, images from albums, albums list, blog posts
  • 5. Profile image upload and crop
    The user can upload the profile image using the so called “on the fly” image upload and then he/she will be able to position the image in the square as he/she wishes and can crop the desire parts of the picture using the pre-defined crop zones by drag & drop.
    Upon save three kinds of images will be cropped:

    • - one for the profile’s header
    • – one for the Home page
    • – one for the image that will be displayed on: comments, wall messages, search results

    We use ImageMagick for all the image operations: resize, crop, rotate.

  • 6. Search
    The main search combines the site’s contacts (public profiles) with a Facebook search (using Facebook Api), having the posibility to invite the Facebook contacts to the IdentityZ website.
  • 7. Drag & drop
    One of the biggest challenge regarding the user interface was the drag & drop functionality. In order to improve the user experience on the site, drag & drop is introduced on different elements: pictures, contacts, files, mails.

    • – the user can drag & drop attachments to the messages sent to other users
    • – the user can choose which identity is showed to another user from his/her contacts, this can be done using drag & drop to change the column where the contact is displayed
    • – the cover of a blog post can be set by drag & dropping the desired image
    • – mails and files and contacts can be moved to another profile by switching profile columns

    See the images for examples.

  • 8. Facebook and Twitter profiles
    These profile types will ask the user to provide the Facebook / Twitter account info and in order to retrieve all the contacts to the IdentityZ profile. After the profile activation the profile’s owner will be able to publish messages on the Facebook wall / Twitter directly from the IdentityZ account.
  • 9. Wall & news
    The wall contains all the messages generated by the system when another user takes and action to that profile: comment on blog post, comment an image, tag a picture, create an album, create a blog post and so on.
    The news collect all the messages generated for the logged in user and his/her contacts.

There are many more interesting features of the system, which are available at identityz.com. And stay tuned, more will come, to enhance even further the experience of the users.

The challenging nature of the user interface and the high level of complexity behind this social network infused us a dose of deadline related panic, but, at the same time, creating the site was a lot of fun and indeed an interesting job.

A social network system is always an opportunity to try new concepts and strive to meet up with the latest trends. An active system of this nature is always evolving and transforming, not just through the contribution of its community, but also with new concepts, new functionality and continuous improvements in the usability and performance of the features. Our aim is to actively continue to deliver the best solutions to the system, and apply the lessons that we have learned in order to bring extra value to our customers, in all the projects that we make.

Arxia supports TYPO3Camp Mallorca

13 August 2012 Comments Off

TYPO3camp Mallorca 14/09/12-16/09/12 Between the 14th and 16th of September the first ever international TYPO3Camp will take place  in Palma de Mallorca.  This way the island of Mallorca will be the capital of the TYPO3 world for a few days. The event aims to attract TYPO3 developers and companies for 2.5 days of  learning, networking, socializing and connecting.

This is a significant event in the TYPO3 community and as such Arxia supports this event as a sponsor because we believe in giving back to the community that helps us deliver great projects using TYPO3.

But that’s not all. Arxia will also dispatch a a 5 people team to TYPO3Camp Mallorca. The team will consist of TYPO3 and frontend developers who will represent Arxia at this important event.

You can read more about the event on its official website.

FLOW3 and JSON-RPC, a happy couple?

9 July 2012 Comments Off

A highly AJAX-ified web application tends to get more difficult to maintain as it grows, both on client and server side. If in the JavaScript part of the application one can use libraries that simplify use of XMLHTTP requests, on the server side things go not so well. On a MVC framework each request gets served by a controller action, practically a method of a controller object. So, in the case of a large, AJAX-ified web application you’ll find yourself writing tens of controller methods to serve AJAX requests, a lot of them being little CRUD operations.

Analyzing AJAX requests that come to the server-side of a web application we could identify the following types:

· CRUD (Create, Read, Update, Delete) operations (e.g. create a comment, read a news counter, update votes count on an item, delete a comment). These requests usually expect scalar values or confirmation messages. These operations are sometimes designed in a RESTful manner, leveraging the architectural style of HTTP.

· Partial page content (partial refresh) requests. These are those requests for HTML code to insert in some container element in the DOM. These requests are usually served by directly rendering a partial view and outputting contents. This approach has the disadvantage that any exceptions thrown while serving the request end up displayed in the page, if not handled properly on the server and in the client code.

In a RESTful approach the error state of the request is returned by the HTTP status code . Status codes can also be used in refeshing partial page content (the 4xx codes). But status codes were not meant for expressing application specific errors, moreover HTTP status codes are reserved by software vendors for specific use and basing an application error handling mechanism on a volatile set of unused status codes is not desirable.

To enable properly error handling we often use a JSON response of the form { “success” : true|false, “message”: “…” , html: “…..” } for AJAX requests that request HTML content and something similar for CRUD operation requests. This way error situations are made known to the client-side script and suitable decisions can be made, like displaying the error message in a dialog. We consider this a step further in creating a transparent interface between the client-side and the server-side, but there is place for better.

JSON-RPC  standard seems to be a candidate for a better standard in AJAX communication. JSON-RPC is a RPC protocol that uses JSON-encoded messages . It is “a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing” , as its proposers say. Some of the obvious advantages of using JSON-RPC are:

  • · simple standard, has been around for some time now, so almost everybody has heard of it
  • · application specific error handling (code, message and data)
  • · it permits request batches (sending a batch of operations at a time can reduce the number of simultaneous AJAX requests).
  • Now that we set on using JSON-RPC, we wanted to be able to use its advantages in a FLOW3 web application. For this purpose we created a package that can be used to provide JSON-RPC operation calls for any number of exposed service providing classes, for any of the application’s packages. The package consists of our own JSON-RPC implementation in PHP and it is capable of exposing service classes methods through a single controller action method. The actual class serving the requests (serviceProvider) is specified in the FLOW3 routes config file.

    Here is an example of configuring such a route (from Routes.yaml):

    name: ‘Arithmetic service’

    uriPattern: ‘arithmetic’

    defaults:

    ‘@package’: ‘Arxia.Rpc’

    ‘@controller’: ‘JsonRpc’

    # the action that serves JSON-RPC requests

    ‘@action’: ‘serve’

    # the format of the response is json

    ‘@format’: ‘json’

    # service provider is the class whose methods are exposed, here arithmetic operations

    ‘serviceProvider’: ‘\Arxia\Calculator\Service\Arithmetic’

    It is important to note that one can have as many service providers as one wants in his applications, even in different packages and expose them using the Arxia.Rpc package’s JsonRpcController class. So installing the generic Arxia.Rpc package one has JSON-RPC support for any other package, by defining a route for each of the uses.

    Looking at the integration example briefly described above we saw that FLOW3 and JSON-RPC really make a happy couple and we believe that embracing JSON-RPC as the standard of making AJAX requests throughout a dynamic, greatly AJAX-ified web application provides a better application structure, better error handling, better understanding of existing code and application flow, better team members communication and, as a result of all these, better productivity. Sure there are other approaches with their pros and cons, but the aforementioned advantages makes JSON-RPC a candidate in a large application in the future, as the standard of AJAX communication.

    Sources can be downloaded from here

    Author: Dan Homorodean