Posts for 2015

Whilst migrating another site there was a requirement for converting RTF files containing lots of code examples into Markdown. The version of Markdown shipped with Stacey 3.0.0 CMS appears to be incapable of handling large code blocks.

There are two versions of Markdown available from Michel Fortin's site, Classic and Latest. To minimise the hosting requirements for the site being migrated the Classic release was chosen which appears to handle large code blocks with ease.

To update the version of the Markdown parser within Stacey simply copy the 'Classic' markdown-parser-inc.php file to the /app/parsers folder.

    The Stacey 3.0.0 CMS ships with quite an old version of Twig that is missing many useful functions.

    Whilst developing the blog template used by this site it was necessary to bring in the split filter to Stacey's copy of Twig.

    To achieve this the following sites are required:

    • Open the /app/parsers/Twig/Extension/Core.php file
    • Locate the getFilters() function and extend the array helpers to include the 'split' formatter, i.e.
    // array helpers
    'join'    => new Twig_Filter_Function('twig_join_filter'),
    'reverse' => new Twig_Filter_Function('twig_reverse_filter'),
    'split'   => new Twig_Filter_Function('twig_split_filter', array('needs_environment' => true)),
    'length'  => new Twig_Filter_Function('twig_length_filter', array('needs_environment' => true)),
    'sort'    => new Twig_Filter_Function('twig_sort_filter'),
    'merge'   => new Twig_Filter_Function('twig_array_merge'),
    • Add the following function to the end of the file:
     * Splits the string into an array.
     * <pre>
     *  {{ "one,two,three"|split(',') }}
     *  {# returns [one, two, three] #}
     *  {{ "one,two,three,four,five"|split(',', 3) }}
     *  {# returns [one, two, "three,four,five"] #}
     *  {{ "123"|split('') }}
     *  {# returns [1, 2, 3] #}
     *  {{ "aabbcc"|split('', 2) }}
     *  {# returns [aa, bb, cc] #}
     * </pre>
     * @param string  $value     A string
     * @param string  $delimiter The delimiter
     * @param int     $limit     The limit
     * @return array The split string as an array
    function twig_split_filter(Twig_Environment $env, $value, $delimiter, $limit = null)
        if (!empty($delimiter)) {
            return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
        if (!function_exists('mb_get_info') || null === $charset = $env->getCharset()) {
            return str_split($value, null === $limit ? 1 : $limit);
        if ($limit <= 1) {
            return preg_split('/(?<!^)(?!$)/u', $value);
        $length = mb_strlen($value, $charset);
        if ($length < $limit) {
            return array($value);
        $r = array();
        for ($i = 0; $i < $length; $i += $limit) {
            $r[] = mb_substr($value, $i, $limit, $charset);
        return $r;

      With the move away from Flatpress as a blogging engine the issue of support for user comments arises.

      Several avenues present themselves:

      • Develop my own commenting system
      • Integrate an existing self hosted commenting system
      • Utilise one of the on-line systems that are available

      Developing my own commenting system could be a lot of work... so lets discount that for now!

      There are several self hosted commenting systems available. A lot of the scripts do no provide support for "moderation" - an important feature in the fight against spam. Those that do seem to all require database support of some form. So this option also appears to be out of consideration for now.

      Of the available 3rd party commenting systems, it makes sense to go with what appears to be the market leader - especially after the collapse of several providers. Hence the decision to go with Disqus.

      Now all that is required is to migrate the existing comments...