Squiz Labs Blog - The latest news from the R&D division of Squiz®

Subscribe to our RSS feeds

Squiz Matrix 4.18.8, 5.0.4.0 & Edit+ 5.0.4 Released

Our latest releases of Squiz Matrix are available today. These releases include the latest version of our 4.18.x branch, as well as a micro releases for Squiz Matrix and Edit+ 5.

Version 4.18.8 is the latest release of our 4.18.x branch, launched late last year. This release contains twenty nine bug fixes.

Squiz Matrix 5.0.4.0 is the latest micro release of Matrix 5, after launching back in April. This release contains twenty five bug fixes.

Edit+ 5.0.4 is the latest micro release of Edit+ for Matrix 5, after launching back in April. This release contains 6 bug fixes.

Please be sure to follow the relevant user guides when updating or installing your system. 


Squiz Matrix Newsletter #482

This week we have four new features to report, including new Form Question functions on the JavaScript API. Continue reading below for more information on all this week's developments.

JS API: New Form Question Functions

Due for release in version 5.1.0.0 

New functions have been added to the JavaScript API to allow you to create, update and remove questions on Custom Forms.

These new functions can be enabled in the new Form Questions section of the Details screen of the JavaScript API. 

The JS API's Form Question Functions

Create Questions

The createQuestion function allows you to create a new question on your Custom Form.

This function takes four parameters:

  • assetid: the ID of the form or form section to create the question on.
  • type_code: the type of question to create (Text, by default).
  • units: the number of questions to create (1, by default).
  • dataCallback: the custom callback function (optional). 

The format of the createQuestion function is shown below: 

function createQuestion(assetid, type_code, units, dataCallback) 

In the example below we are creating two new Country question types under our Form asset (#100).

createQuestion(100, 'Country', 2, function(e){console.log(e);}); 

When using the Enhanced JS API, the above example would be as follows:

js_api.createQuestion({
assetid:100,
type_code:'Country' units:2 dataCallback: function(e){console.log(e);}
}) 

Update Questions

The updateQuestion function allows you to update the field information of an existing question on your Custom Form.

This function takes four parameters:

  • assetid: the ID of the form or form section to update the question on.
  • question_id: the ID of the question to update.
  • field_info: a json object containing the field data to update (the property names being the attributes of the specified question type).
  • dataCallback: the custom callback function (optional).  

The format of the updateQuestion function is shown below:  

function updateQuestion(assetid, question_id, field_info, dataCallback)  

In the example below we are updating a question (q35) under our form asset (#100) with the specified field info.

field_info = {
'cust_required_error': 'This is custom Text',                                                     //text type
'is_required': 1,                                                                                 // boolean type
'default':  '2014-10-10 10:59:39',                                                                // datetime type
'name': 'Date Time Question',                                                                     // text type
'show': show_array,                                                                               // serialise type
'text': 'a:3:{s:1:"d";s:9:"date text";s:1:"m";s:10:"month text";s:1:"y";s:9:"year text";}'        // also serialise type
};

updateQuestion('100', 'q35', field_info, function(e){console.log(e);}) 

When using the Enhanced JS API, the above example would be as follows:

field_info = {
'cust_required_error': 'This is custom Text',                                                     //text type
'is_required': 1,                                                                                 // boolean type
'default':  '2014-10-10 10:59:39',                                                                // datetime type
'name': 'Date Time Question',                                                                     // text type
'show': show_array,                                                                               // serialise type
'text': 'a:3:{s:1:"d";s:9:"date text";s:1:"m";s:10:"month text";s:1:"y";s:9:"year text";}'        // also serialise type
}; js_api.updateQuestion({
assetid:100,
question_id: 'q35',
field_info: field_info,
dataCallback: function(e){console.log(e);}
})  

Remove Questions

The removeQuestion function allows you to remove a question from your Custom Form.

This function takes three parameters:

  • assetid: the ID of the form or form section to remove the question from.
  • question_id: the ID of the question to remove. 
  • dataCallback: the custom callback function (optional).   

The format of the removeQuestion function is shown below:

function removeQuestion(assetid, question_id, dataCallback) 

In the example below, we are removing a question (q35) under our form asset (#100).

removeQuestion('100', 'q35',function(e){console.log(e);}); 

When using the Enhanced JS API, the above example would be as follows:

js_api.removeQuestion({
assetid:100,
question_id: 'q35',
dataCallback: function(e){console.log(e);}
}) 

Update Question Order

The updateQuestionOrder function allows you to update the order of questions on your Custom Form.

This function takes three parameters:

  • assetid: the ID of the form or form section to update the question order of.
  • sort_order: an array containing the new sort order of the questions.
  • dataCallback: the custom callback function (optional).  

The format of the updateQuestionOrder function is shown below: 

function updateQuestionOrder(assetid, sort_order, dataCallback) 

In the example below, we are updating our form (#100) with the specified new sort order.

question_order = ['100:q52', '100:q51', '100:q50', '100:q49''];
updateQuestionOrder(100, question_order, function(e){console.log(e);}) 

When using the Enhanced JS API, the above example would be as follows:

question_order = ['100:q52', '100:q51', '100:q50', '100:q49''];
js_api.updateQuestionOrder({
assetid:100,
sort_order: question_order,
dataCallback: function(e){console.log(e);}
})  

Remove SQ_ACTION=login Parameter After Logging In

Due for release in version 5.1.0.0 

Previously, when logging into Matrix, the system would add a SQ_ACTION=login query parameter to the your URL, like so:

www.site.com?SQ_ACTION=login

While this was generally not an issue, it could cause issues upon refresh, especially when in Edit mode.

The feature adds a new redirect to remove this query parameter when logging into the system, and also the similar SQ_ACTION=logout when logging out of the system. This redirect will preserve any other query strings contained within the URL.

www.site.com?SQ_ACTION=login&var=value ==> www.site.com?var=value 

OAuth: Sync User Attributes

Due for release in version 5.1.0.0 

Squiz Matrix's OAuth Account Manager asset facilitates the integration of OAuth2 authentication within your system, allowing users to login as local system users using, for example, their Facebook or Google accounts.

When configuring the settings of the OAuth Account Manager, you are able to define the user attributes of your OAuth authorised users, using the profile data returned from the API.

These settings, however, did not update these values once they were initially populated. This meant that the values within Matrix could be outdated or out of sync, if updated externally.

This feature introduces a new Sync User Attributes section to combat this issue.

The OAuth Sync User Attributes settings

The Sync User Attributes options will work in a similar manner to the existing populate attributes functionality, except that it will sync user attribute data each time the user logs into Matrix. This will ensure that the profile data in Matrix is consistently updated and current.

JavaScript Processing on Call REST Resource Form & Trigger Actions

Due for release in version 5.1.0.0 

The Call REST Resource form submission and trigger actions within Squiz Matrix allows you to communicate with web services exposing themselves using Representational State Transfer (REST) methods, on the submission of a form or when a trigger is fired.

This feature extends the functionality of these actions, adding new settings to enable JavaScript processing of the response from the REST resource call.

The JavaScript Processing settings

The JavaScript Processing settings work in a similar manner to the existing REST Resource JavaScript asset, allowing you to either select a JS File and/or manually enter JavaScript to determine the content that will be processed.

Additionally, these actions will now store the response of the HTTP request as an array in the Matrix session sandbox, as specified in a new Session Var Name field. Any JavaScript processing that has been configured will overwrite the stored response array.

The REST response information can be printed using the following keyword format (where [session_var_name] is the variable name set):

%globals_session_[session_var_name]% 

You can use array modifiers to specify the information to print from the response array, for example:

%globals_session_[session_var_name]^index:responses^index:0^index:body%

Analysis of Coding Conventions

Coding standards tend to vary between projects. Even projects that use the same written standard can vary in a number of ways as standards tend to leave a lot of room to apply your own coding style in various areas. To get a better idea of what coding styles PHP developers are using, I used PHP_CodeSniffer to analyse and report on a number of big and small public PHP projects hosted on Github.

The result of the analysis is here: http://squizlabs.github.io/PHP_CodeSniffer/analysis/

There are currently 63 projects being analysed, with trend data recorded for about the last 8 months. The report currently lists 42 different coding style conventions ranging from "how many spaces surround the concat operator" to the classic "tabs or spaces for line indent". The coding conventions are listed from most contentious to least contentious. So the ones at the top show the most variations between projects while the ones at the bottom are generally accepted by all projects.

Each coding convention provides a list of projects that use each of the style variations within it. Clicking on any of those projects will take you to a project-specific report showing the coding conventions used within it and how often the same style is followed within the project. So you can take a look at the coding conventions for CakePHP, Drupal, Symfony2 or even PHP_CodeSniffer itself. 

How did you pick the projects to analyse?

A combination of popular PHP projects on Github, projects that I've used, and projects that have received some attention while the report was being built.

Can you include my project in the report?

If it is a public PHP project on Github, I sure can. All the repositories that are being analysed are listed in the repos.json file.

For each one, I need to know the name of the project, the URL (organisation/repository), the path in the project where PHP_CodeSniffer should start analysing code (default: /), any files or directories that should be ignored (default: none), and a list of additional PHP file extensions to check beyond .php and .inc (default: none). Here is an example:

{
    "name": "My Project",
    "url": "squizlabs/my-project",
    "path": "src",
    "ignore": "3rdparty/*,includes/*",
    "extensions": "phtml,module"
}

There are also 63 other examples in the repos.json file to take a look at. Submit a PR or send me a gist on Twitter. If you have no idea what the values should be, get me the Github URL and I'll figure it out for you.

How is the report generated?

From version 2.0.0a2, PHP_CodeSniffer collects metrics about the code it is checking. These are used to determine coding conventions and can be displayed using --report=info. The coding convention report uses a custom PHP_CodeSniffer report that outputs these metrics as a JSON file instead of to the screen. To save a lot of time, a custom coding standard is used to limit checks to just the sniffs that generate the metrics that the report wants to use. Some ugly custom wrapper scripts deal with updating the repostories, keeping trend data for each coding convention, and generating the HTML reports. The whole thing runs through HHVM to make it as fast as possible.


Stay up to date on all PHP_CodeSniffer changes, including new features and releases, by subscribing to the RSS feed or following me on Twitter.


Squiz Matrix Newsletter #481

This week we have a great new feature to report, new Maintenance Mode functions within Squiz Matrix. Continue reading below for more information on all this exciting new development.  

Squiz Matrix Maintenance Mode

Due for release in version 5.1.0.0 

This feature introduces a new Maintenance Mode within Squiz Matrix, that when enabled, will disable the functionality of specified assets on the front-end, instead printing a maintenance message for your users.

The Maintenance Mode configuration settings can be accessed on the System Maintenance screen of your Squiz Matrix system. 

The Maintenance Mode Settings 

The Maintenance Mode settings allow you to enable Maintenance Mode and modify the associated messages that will be displayed to your users.

Additional fields allow you to modify the affected asset types and root nodes, as well as any root nodes to exclude. By default, Maintenance Mode will affect all Asset BuilderAccount Manager, Custom Form and Checkout Page assets and any associated child asset types.

A Notify status is also available, that can be used prior to undergoing maintenance, notifying your users that site functions will soon be deactivated. This can give users the chance to finish their work, submissions, etc.

The Maintenance Mode Enabled Message

This new Maintenance Mode feature has been added to assist in the system upgrade process, where previously, these assets types would have to be manually edited before an upgrade could start. By effectively automating this process, the upgrading of systems should be more efficient and safer.


Squiz Matrix Newsletter #480

This week we have two new features to report, including new spam prevention tools on the Account Manager Page. Continue reading below for more information on all this week's developments.  

Spam Prevention Tools Extended to Account Manager Page

Due for release in version 5.1.0.0 

Back in our v4.16.2 release of Squiz Matrix, we introduced three new spam prevention options on the Custom Form and Asset Builder assets. These tools have now been extended to the Account Manager Page.

  • Google reCAPTCHA: allows you to implement Google's free reCAPTCHA anti-bot service, which also servers to digitize books, newspapers and old time radio shows.
  • Honeypot Question: enables the creation of a honeypot or dummy question. This is used to identify spam bots who fill in the field, that would otherwise be left blank by regular users.
  • Submission Time Threshold: uses the time taken between the form load and form submission to help identify possible spam bots, based on a set minimum time.

Each of these new spam prevention options are available for configuration on the Details screen of Account Manager Page assets.

The Google reCAPTCHA settings on the Account Manager Page 

These new options have been added to compliment the existing spam prevention options available on the Account Manager asset, by providing more accessible anti-spam alternatives. 

Improved Modifier Support on Metadata Field Keywords

Due for release in version 5.1.0.0 

Metadata field keywords allow you to reference the value of a metadata field within another field on the same asset.

%metadata_field_<fieldname>%

While these keywords have always supported the use of keyword modifiers, modifiers did not previously work correctly in cases where the metadata field value contained a keyword replacement. This was due to the modifier being applied before the keyword in the metadata value was replaced.

This feature improves modifier support on these metadata field keywords, to also support modifiers in these cases.

Take the following example: We have a date metadata field with the value %asset_created%. We want to take this value and use it in another metadata field on the asset, modifying the format of the date. The following keyword format will now work correctly:

%metadata_field_date^date_format:Y-m-d%

Squiz Labs

R & D division of Squiz Pty Ltd

Open source web experience management solutions

Squiz Labs is the research and development division of Squiz, the company behind the Squiz Suite of web experience management and development tools.

Our PHP and JavaScript developers are responsible for producing innovative enterprise-quality software while our interface designers and testing team ensure our products both look great and are easy to use.