Commit 3f821e53 authored by Rebecca Blundell's avatar Rebecca Blundell Committed by Robert Lyon
Browse files

Bug 1773892: Upgrade Dwoo for PHP 7.2

Upgraded to 1.3.7

Issues:

Needed to change calls to class names to not use underscores
Changed calls to the Dwoo/$dwoo class to Core/$core
discovered that wrong file path wass being called for the dataroot
changes to use namespaces instead of requires
Changed Mahara plugins to camelcase naming.

Dwoo now uses composer to autoload files and
composer needs to cache the paths to classes before Dwoo will run.

behatnotneeded

Change-Id: Ia6b7f41c96fe5695a1ed94476e21eca5a9f1c9ee
parent f76a72f3
### Composer template
composer.phar
composer.json
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
### PHPUnit Tests
/tests/temp/cache/
/tests/temp/compiled/
\ No newline at end of file
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
\ No newline at end of file
......@@ -2,10 +2,49 @@ Dwoo in Mahara
======================
Website: http://www.dwoo.org/
Version: 1.2.0
Version: 1.3.7
This library is used for all the templating.
Changes:
* Make dwoo PHP7 compatable by fixing dynamic property references
Move lib/Dwoo from the downloaded plugin to htdocs/lib/dwoo/Dwoo
replace the CHANGELOG, README and LICENSE.md files with the new ones.
We don't need .gitlab-ci.yml or travis.yml.
You can delete the rest of the plugin (/tests, lib/cache/, lib/compiled).
Copy the mahara directory from the previous version to htdocs/lib/dwoo/mahara.
We pushed the composer autoloaded files in the /vendor directory and git ignored the
composer.json. This was as a workaround to stop the Makefile needing to do the composer
autoload, which it failed to do on Jenkins and wasn't easy to resolve.
So to upgrade dwoo, you'll either need to resolve the composer issue or do what
we did:
add this to the composer.json:
"autoload": {
"psr-4": {
"Mahara\\": "dwoo/mahara/"
}
}
We don't need to autoload the tests file (we deleted it) or to require phpunit or PHP,
so you can remove those bits from the composer.json.
To recompile the classpaths:
cd htdocs/lib/dwoo
composer dump-autoload -o
Then remove the hashes from the auto-generated /vendor files: E.g.
ComposerAutoloaderInit26e38f1cfb40040c9ff6097c09aee6d7::getLoader();
becomes ComposerAutoloaderInit::getLoader();
I found a bug in /Dwoo/Template/Str.php
This looks like a check for Windows OS, but 0 in strpos is a position,
so it runs if WIN is not in position 0. I changed it to false to stop
the following error on upgrade:
Unable to chmod /var/lib/maharadata/1704stable/dwoo/compile/raw/var/ to 511:
Array, referer: http://mahara/admin/upgrade.php
line 524: if (strpos(PHP_OS, 'WIN') !== 0 && $baseDir !== null) {}
replaced with:
if (strpos(PHP_OS, 'WIN') !== false && $baseDir !== null) {
\ No newline at end of file
-----------------------------------------------------------------------------
-- WHAT IS DWOO? readme - version 1.1.0
-----------------------------------------------------------------------------
Dwoo is a PHP5 Template Engine that was started in early 2008. The idea came
Dwoo
====
[![Latest Stable Version](https://poser.pugx.org/dwoo/dwoo/v/stable?format=flat-square)](https://packagist.org/packages/dwoo/dwoo)
[![Total Downloads](https://poser.pugx.org/dwoo/dwoo/downloads?format=flat-square)](https://packagist.org/packages/dwoo/dwoo)
[![License](https://poser.pugx.org/dwoo/dwoo/license?format=flat-square)](https://packagist.org/packages/dwoo/dwoo)
[![Build Status](https://travis-ci.org/dwoo-project/dwoo.svg?branch=master)](https://travis-ci.org/dwoo-project/dwoo)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/dwoo-project/dwoo/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dwoo-project/dwoo/?branch=master)
[![Gitter](https://badges.gitter.im/dwoo_project/support.svg)](https://gitter.im/dwoo_project/support?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Dwoo is a PHP5/PHP7 Template Engine that was started in early 2008. The idea came
from the fact that Smarty, a well known template engine, is getting older and
older. It carries the weight of it's age, having old features that are
inconsistent compared to newer ones, being written for PHP4 its Object
......@@ -13,67 +19,77 @@ So far it has proven to be faster than Smarty in many areas, and it provides
a compatibility layer to allow developers that have been using Smarty for
years to switch their application over to Dwoo progressively.
-----------------------------------------------------------------------------
-- DOCUMENTATION
-----------------------------------------------------------------------------
Dwoo's website to get the latest version is at http://dwoo.org/
> Dwoo **1.3.x** is compatible from **PHP 5.3.x** to **PHP 7.x**
The wiki/documentation pages are available at http://wiki.dwoo.org/
Documentation
=============
Dwoo's website to get the latest version is at http://dwoo.org/
The wiki/documentation pages are available at http://dwoo.org/documentation/
-----------------------------------------------------------------------------
-- LICENSE
-----------------------------------------------------------------------------
Dwoo is released under the Modified BSD license.
See the LICENSE file included in the archive or go to the URL below to obtain
a copy.
Requirements
------------
* PHP >= **5.3**
* PHP >= **7.0**
* [Multibyte String](http://php.net/manual/en/book.mbstring.php)
http://dwoo.org/LICENSE
License
=======
Dwoo is released under the [GNU LESSER GENERAL PUBLIC LICENSE V3](./LICENSE.md) license.
-----------------------------------------------------------------------------
-- QUICK START - RUNNING DWOO
-----------------------------------------------------------------------------
/***************************** Basic Example *******************************/
// Include the main class (it should handle the rest on its own)
include 'path/to/dwooAutoload.php';
Quick start - Running Dwoo
==========================
Basic Example
-------------
```php
<?php
// Include Composer autoloader
require __DIR__ . '/vendor/autoload.php';
// Create the controller, this is reusable
$dwoo = new Dwoo();
$dwoo = new Dwoo\Core();
// Load a template file (name it as you please), this is reusable
// if you want to render multiple times the same template with different data
$tpl = new Dwoo_Template_File('path/to/index.tpl');
$tpl = new Dwoo\Template\File('path/to/index.tpl');
// Create a data set, if you don't like this you can directly input an
// associative array in $dwoo->output()
$data = new Dwoo_Data();
// associative array in $dwoo->get()
$data = new Dwoo\Data();
// Fill it with some data
$data->assign('foo', 'BAR');
$data->assign('bar', 'BAZ');
// Outputs the result ...
$dwoo->output($tpl, $data);
echo $dwoo->get($tpl, $data);
// ... or get it to use it somewhere else
$dwoo->get($tpl, $data);
```
/***************************** Loop Example *******************************/
Loop Example
------------
```php
<?php
// To loop over multiple articles of a blog for instance, if you have a
// template file representing an article, you could do the following :
include 'path/to/dwooAutoload.php';
require __DIR__ . '/vendor/autoload.php';
$dwoo = new Dwoo();
$tpl = new Dwoo_Template_File('path/to/article.tpl');
$dwoo = new Dwoo\Core();
$tpl = new Dwoo\Template\File('path/to/article.tpl');
$pageContent = '';
$articles = array();
// Loop over articles that have been retrieved from the DB
foreach($articles as $article) {
// Either associate variables one by one
$data = new Dwoo_Data();
$data->assign('title', $article['title'];
$data = new Dwoo\Data();
$data->assign('title', $article['title']);
$data->assign('content', $article['content']);
$pageContent .= $dwoo->get($tpl, $data);
// Or use the article directly (which is a lot easier in this case)
$pageContent .= $dwoo->get($tpl, $article);
}
\ No newline at end of file
}
```
\ No newline at end of file
{
"name": "dwoo/dwoo",
"license": "LGPL",
"type": "library",
"description": "Dwoo is a PHP5/PHP7 template engine which is (almost) fully compatible with Smarty templates and plugins, but is written from scratch for PHP5, and adds many features.",
"authors": [
{
"name": "David Sanchez",
"email": "david38sanchez@gmail.com"
}
],
"autoload": {
"psr-4": {
"Mahara\\": "dwoo/mahara/",
"Dwoo\\": "dwoo/Dwoo/"
}
},
"require": {
"php": "^5.3|^7.0"
}
}
This diff is collapsed.
<?php
/**
* micro-class that extends Dwoo_Core for compatibility purposes
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.1.0
* @date 2010-02-28
* @package Dwoo
* @see Dwoo_Core
*/
class Dwoo extends Dwoo_Core
{
}
\ No newline at end of file
<?php
/**
* Dwoo adapter for Agavi
*
* Install instructions :
* - download dwoo from dwoo.org and unzip it somewhere in your agavi app
* - add a renderer to your output_types.xml as such :
* <renderer name="dwoo" class="DwooRenderer">
* <parameter name="assigns">
* <parameter name="routing">ro</parameter>
* <parameter name="request">rq</parameter>
* <parameter name="controller">ct</parameter>
* <parameter name="user">us</parameter>
* <parameter name="translation_manager">tm</parameter>
* <parameter name="request_data">rd</parameter>
* </parameter>
* <parameter name="extract_vars">true</parameter>
* <parameters name="plugin_dir">
* <parameter>%core.lib_dir%/dwoo_plugins</parameter>
* <parameter>%core.lib_dir%/other_dwoo_plugins</parameter>
* </parameters>
* </renderer>
*
* - add dwoo's directory to your include path or include dwooAutoload.php yourself
* either through agavi's autoload.xml (with name="Dwoo") or through your index.php
*
* Notes:
* - you can copy the /Dwoo/Adapters/Agavi/dwoo_plugins directory to your agavi app's
* lib directory, or change the plugin_dir parameter in the output_types.xml file.
* these plugins are agavi-specific helpers that shortens the syntax to call common
* agavi helpers (i18n, routing, ..)
* - in the previous versions of this adapter, only a single value could be passed to
* plugin_dir parameter; now you can pass several plugin directories (see example)
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the
* use of this software.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.1.1
* @date 2010-04-06
* @package Dwoo
*/
class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer
{
/**
* @constant string The directory inside the cache dir where templates will
* be stored in compiled form.
*/
const COMPILE_DIR = 'templates';
/**
* @constant string The subdirectory inside the compile dir where templates
* will be stored in compiled form.
*/
const COMPILE_SUBDIR = 'dwoo';
/**
* @constant string The directory inside the cache dir where cached content
* will be stored.
*/
const CACHE_DIR = 'dwoo';
/**
* @var Dwoo Dwoo template engine.
*/
protected $dwoo = null;
/**
* @var string A string with the default template file extension,
* including the dot.
*/
protected $defaultExtension = '.html';
/**
* stores the (optional) plugin directories to add to the Dwoo_Loader
*/
protected $plugin_dir = null;
/**
* Pre-serialization callback.
*
* Excludes the Dwoo instance to prevent excessive serialization load.
*/
public function __sleep()
{
$keys = parent::__sleep();
unset($keys[array_search('dwoo', $keys)]);
return $keys;
}
/**
* Initialize this Renderer.
*
* @param AgaviContext The current application context.
* @param array An associative array of initialization parameters.
*/
public function initialize(AgaviContext $context, array $parameters = array())
{
parent::initialize($context, $parameters);
$this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir);
}
/**
* provides a custom compiler to the dwoo renderer with optional settings
* you can set in the agavi output_types.xml config file
*
* @return Dwoo_Compiler
*/
public function compilerFactory()
{
if (class_exists('Dwoo_Compiler', false) === false) {
include DWOO_DIRECTORY . 'Dwoo/Compiler.php';
}
$compiler = Dwoo_Compiler::compilerFactory();
$compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false));
return $compiler;
}
/**
* Grab a cleaned up dwoo instance.
*
* @return Dwoo A Dwoo instance.
*/
protected function getEngine()
{
if($this->dwoo) {
return $this->dwoo;
}
// this triggers Agavi autoload
if(!class_exists('Dwoo')) {
if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) {
// file was dropped with the entire dwoo package
require dirname(__FILE__).'/../../../dwooAutoload.php';
} else {
// assume the dwoo package is in the include path
require 'dwooAutoload.php';
}
}
$parentMode = fileperms(AgaviConfig::get('core.cache_dir'));
$compileDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::COMPILE_DIR . DIRECTORY_SEPARATOR . self::COMPILE_SUBDIR;
AgaviToolkit::mkdir($compileDir, $parentMode, true);
$cacheDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_DIR;
AgaviToolkit::mkdir($cacheDir, $parentMode, true);
$this->dwoo = new Dwoo_Core($compileDir, $cacheDir);
if (!empty($this->plugin_dir)) {
foreach ((array) $this->plugin_dir as $dir) {
$this->dwoo->getLoader()->addDirectory($dir);
}
}
$this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
return $this->dwoo;
}
/**
* Render the presentation and return the result.
*
* @param AgaviTemplateLayer The template layer to render.
* @param array The template variables.
* @param array The slots.
* @param array Associative array of additional assigns.
*
* @return string A rendered result.
*/
public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array())
{
$engine = $this->getEngine();
$data = array();
if($this->extractVars) {
$data = $attributes;
} else {
$data[$this->varName] = &$attributes;
}
$data[$this->slotsVarName] =& $slots;
foreach($this->assigns as $key => $getter) {
$data[$key] = $this->getContext()->$getter();
}
foreach($moreAssigns as $key => &$value) {
if(isset($this->moreAssignNames[$key])) {
$key = $this->moreAssignNames[$key];
}
$data[$key] =& $value;
}
return $engine->get($layer->getResourceStreamIdentifier(), $data);
}
}
\ No newline at end of file
// ------------------------
// Install notes :
// ------------------------
- drop dwoo's directory in app/lib/renderer (create if needed)
- add a renderer to app/config/output_types.xml as such :
<renderer name="dwoo" class="DwooRenderer">
<parameter name="assigns">
<