Commit fe93bcc3 authored by Jordi Boggiano's avatar Jordi Boggiano Committed by Penny Leach

integrating dwoo into mahara, includes many small templates changes, smarty...

integrating dwoo into mahara, includes many small templates changes, smarty plugins ported to dwoo syntax as well as the custom mahara resource types ported to dwoo templates
Signed-off-by: default avatarJordi Boggiano <j.boggiano@seld.be>
parent 7220012b
......@@ -19,7 +19,7 @@
<th>{str tag=Date section=artefact.file}</th>
</tr>
{if $folder != '/'}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
<td><img src="{$rootpath}static/file/theme/default/static/images/folder.gif" alt="{str tag=Folder section=artefact.file}"></td>
<td><a href="../index.html">{str tag=parentfolder section=artefact.file}</a></td>
<td>{str tag=parentfolder section=artefact.file}</td>
......@@ -28,7 +28,7 @@
</tr>
{/if}
{foreach from=$folders item=folder}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
<td><img src="{$rootpath}static/file/theme/default/static/images/folder.gif" alt="{str tag=Folder section=artefact.file}"></td>
<td><a href="{$folder.path|rawurlencode|escape}/index.html">{$folder.title|escape}</a></td>
<td>{$folder.description|escape}</td>
......@@ -37,7 +37,7 @@
</tr>
{/foreach}
{foreach from=$files item=file}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
<td><img src="{$rootpath}static/file/theme/default/static/images/file.gif" alt="{str tag=File section=artefact.file}"></td>
<td><a href="{$file.path|rawurlencode|escape}">{$file.title|escape}</a></td>
<td>{$file.description|escape}</td>
......
......@@ -15,7 +15,7 @@
<tbody>
{foreach from=$filelist item=file}
{if !$publishing || !$file->permissions || $file->can_republish}{assign var=publishable value=1}{else}{assign var=publishable value=0}{/if}
<tr id="file:{$file->id}" class="r{cycle values=0,1} directory-item{if $file->isparent} parentfolder{/if}{if $file->artefacttype == 'folder'} folder{/if}{if !empty($highlight) && $highlight == $file->id} highlight-file{/if}{if $edit == $file->id} hidden{/if}{if !$publishable && $file->artefacttype != 'folder'} disabled{/if}" {if !$publishable && $file->artefacttype != 'folder'} title="{str tag=notpublishable section=artefact.file}"{/if}>
<tr id="file:{$file->id}" class="r{cycle values='0,1'} directory-item{if $file->isparent} parentfolder{/if}{if $file->artefacttype == 'folder'} folder{/if}{if !empty($highlight) && $highlight == $file->id} highlight-file{/if}{if $edit == $file->id} hidden{/if}{if !$publishable && $file->artefacttype != 'folder'} disabled{/if}" {if !$publishable && $file->artefacttype != 'folder'} title="{str tag=notpublishable section=artefact.file}"{/if}>
<td>
{if $editable}
<div{if !$file->isparent} class="icon-drag" id="drag:{$file->id}"{/if}>
......
......@@ -11,7 +11,7 @@
<tbody>
{foreach from=$selectedlist item=file}
{assign var=displaytitle value=$file->title|str_shorten_text:34|escape}
<tr class="r{cycle values=0,1}{if !empty($highlight) && $highlight == $file->id} highlight-file{/if}">
<tr class="r{cycle values='0,1'}{if !empty($highlight) && $highlight == $file->id} highlight-file{/if}">
<td>
<img src="{if $file->artefacttype == 'image'}{$WWWROOT}artefact/file/download.php?file={$file->id}&size=20x20{else}{theme_url filename=images/`$file->artefacttype`.gif}{/if}">
</td>
......
......@@ -18,7 +18,7 @@
</thead>
<tbody>
{foreach from=$rows item=row}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
<td>{$row->date|escape}</td>
<td><div class="jstitle">{$row->title|escape}</div><div class="jsdescription">{$row->description|escape}</div></td>
</tr>
......
......@@ -18,7 +18,7 @@
</thead>
<tbody>
{foreach from=$rows item=row}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
<td>{$row->date|escape}</td>
<td><div class="jstitle">{$row->title|escape}</div><div class="jsdescription">{$row->description|escape}</div></td>
</tr>
......
......@@ -19,7 +19,7 @@
</thead>
<tbody>
{foreach from=$rows item=row}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
<td>{$row->startdate|escape}</td>
<td>{$row->enddate|escape}</td>
<td><div class="jstitle">{$row->qualification|escape}</div><div class="jsdescription">{$row->qualdescription|escape}</div></td>
......
......@@ -19,7 +19,7 @@
</thead>
<tbody>
{foreach from=$rows item=row}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
<td>{$row->startdate|escape}</td>
<td>{$row->enddate|escape}</td>
<td><div class="jstitle">{$row->jobtitle|escape}: {$row->employer|escape}</div>
......
......@@ -19,7 +19,7 @@
</thead>
<tbody>
{foreach from=$rows item=row}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
<td>{$row->startdate|escape}</td>
<td>{$row->enddate|escape}</td>
<td><div class="jstitle">{$row->title|escape}</div><div class="jsdescription">{$row->description|escape}</div></td>
......
......@@ -4,7 +4,7 @@
{foreach from=$friends item=row}
<tr>
{foreach from=$row item=friend}
<td class="r{cycle values=0,1} friendcell">
<td class="r{cycle values='0,1'} friendcell">
<a href="{$WWWROOT}user/view.php?id={$friend}">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxwidth=60&amp;maxheight=60&amp;id={$friend}" alt="">
</a>
......
......@@ -2,7 +2,7 @@
<table id="usergroupstable" class="fullwidth">
{foreach from=$USERGROUPS item=item}
<tr>
<td class="r{cycle values=0,1}">
<td class="r{cycle values='0,1'}">
<h4><a href="{$WWWROOT}group/view.php?id={$item->id}">{$item->name|escape}</a> - {$item->roledisplay|escape}</h4>
{if $item->description}
{$item->description}
......
......@@ -2,7 +2,7 @@
<table id="userviewstable">
{foreach from=$VIEWS item=item name=view}
<tr>
<td class="r{cycle values=0,1}">
<td class="r{cycle values='0,1'}">
<h4><a href="{$WWWROOT}view/view.php?id={$item->id}">{$item->title|escape}</a></h4>
{if $item->description}
<div>{$item->description}</div>
......
......@@ -22,7 +22,7 @@
<th></th>
</tr>
{foreach from=$forums item=forum}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
<td>
{if $admin}
<div class="fr btn-spacer s">
......
......@@ -2,7 +2,7 @@
{if $sticky}
<tr class="stickytopic">
{else}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values='0,1'}">
{/if}
<td>
{if $topic->closed}<img src="{$closedicon|escape}" alt="{str tag="Closed" section="interaction.forum"}">{/if}
......
<?php
// loading all dependencies
require 'Dwoo_Template_Mahara.php';
require 'Dwoo_Template_Mahara_Artefact.php';
require 'Dwoo_Template_Mahara_Blocktype.php';
require 'Dwoo_Template_Mahara_Export.php';
require 'Dwoo_Template_Mahara_Interaction.php';
/**
* implements some of the Smarty interface to support old code
* using Smarty and sets up the Dwoo object to work with Mahara
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class Dwoo_Mahara extends Dwoo {
/**
* stores the data in the dwoo object, smarty style
*
* @var array
*/
protected $_data;
/**
* stores the templates directories
*
* @var array
*/
protected $includePath;
/**
* stores the template delimiters since some code relies on that
*/
public $left_delimiter = '{';
public $right_delimiter = '}';
public function __construct() {
global $THEME;
// make sure cache/compile paths exist
check_dir_exists(get_config('dataroot') . 'dwoo/compile/' . $THEME->basename);
check_dir_exists(get_config('dataroot') . 'dwoo/cache/' . $THEME->basename);
// set paths
$this->template_dir = $THEME->templatedirs;
$compileDir = get_config('dataroot') . 'dwoo/compile/' . $THEME->basename;
$cacheDir = get_config('dataroot') . 'dwoo/cache/' . $THEME->basename;
parent::__construct($compileDir, $cacheDir);
// add plugins dir to the loader
$this->getLoader()->addDirectory(get_config('libroot') . 'dwoo/mahara/plugins/');
// adds mahara resources and compiler factory
$this->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
$this->addResource('artefact', 'Dwoo_Template_Mahara_Artefact', array($this, 'compilerFactory'));
$this->addResource('blocktype', 'Dwoo_Template_Mahara_Blocktype', array($this, 'compilerFactory'));
$this->addResource('export', 'Dwoo_Template_Mahara_Export', array($this, 'compilerFactory'));
$this->addResource('interaction', 'Dwoo_Template_Mahara_Interaction', array($this, 'compilerFactory'));
// set base data
$theme_list = array();
$themepaths = themepaths();
foreach ($themepaths['mahara'] as $themepath) {
$theme_list[$themepath] = $THEME->get_url($themepath);
}
$this->_data = array(
'THEME' => $THEME,
'WWWROOT' => get_config('wwwroot'),
'THEMELIST' => json_encode($theme_list),
);
}
/**
* implements smarty api to assign data
*/
public function assign($key, $value) {
$this->_data[$key] = $value;
}
/**
* implements smarty api to assign data
*/
public function assign_by_ref($key, &$value) {
$this->_data[$key] =& $value;
}
/**
* implements smarty api to read data
*/
public function get_template_vars($name = null) {
if (!$name) {
return $this->_data;
} elseif (isset($this->_data[$name])) {
return $this->_data[$name];
}
}
/**
* implements smarty api to render and display a template
*/
public function display($file) {
echo $this->fetch($file);
}
/**
* implements smarty api to render and return a template's ouptut
*/
public function fetch($file) {
$class = 'Dwoo_Template_File';
if (strpos($file, ':') !== false) {
$name = explode(':', $file, 2);
$class = 'Dwoo_Template_Mahara_'.$name[0];
$file = $name[1];
}
return $this->get(new $class($file, null, null, null, $this->template_dir), $this->_data);
}
/**
* returns a compiler object when one is required
*
* @return Dwoo_Compiler
*/
public function compilerFactory() {
$compiler = Dwoo_Compiler::compilerFactory();
$compiler->setDelimiters($this->left_delimiter, $this->right_delimiter);
//$compiler->setAutoEscape(true);
return $compiler;
}
}
?>
\ No newline at end of file
<?php
/**
* base resource class for all mahara types, it calls for file name resolution if required
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class Dwoo_Template_Mahara extends Dwoo_Template_File
{
public function __construct($file, $cacheTime = null, $cacheId = null, $compileId = null, $includePath = null)
{
global $THEME;
$name = explode(':', $file, 2);
// this is a mahara special resource, resolving path
if (count($name) == 2) {
list($file, $includePath) = $this->resolveFileName($name, $includePath);
}
parent::__construct($file, null, null, null, $includePath);
}
}
?>
\ No newline at end of file
<?php
/**
* implements the Artefact resource type for custom plugins
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class Dwoo_Template_Mahara_Artefact extends Dwoo_Template_Mahara
{
protected function resolveFileName(array $name, array $includePath)
{
global $THEME;
$plugin_name = $name[0];
$plugin_path = $name[1];
$basedir = get_config('docroot') . 'artefact/' . $plugin_name . '/theme/';
foreach ($THEME->inheritance as $theme) {
$filename = $basedir . $theme . '/' . $plugin_path;
if (is_readable($filename)) {
array_unshift($includePath, $basedir . $theme . '/');
return array($plugin_path, $includePath);
}
}
throw new MaharaException('Artefact template could not be found : '.implode(':', $name));
}
}
?>
\ No newline at end of file
<?php
/**
* implements the Blocktype resource type for custom plugins
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class Dwoo_Template_Mahara_Blocktype extends Dwoo_Template_Mahara
{
protected static $_filePaths = array();
protected function resolveFileName(array $name, array $includePath)
{
global $THEME;
if (!isset(self::$_filePaths[$name[0]][$name[1]])) {
$artefactplugin = get_field('blocktype_installed', 'artefactplugin', 'name', $name[0]);
$template_path = $name[1];
$basedir = get_config('docroot');
if ($artefactplugin) {
$basedir .= 'artefact/' . $artefactplugin . '/blocktype/' . $name[0] . '/theme/';
}
else {
$basedir .= 'blocktype/' . $name[0] . '/theme/';
}
foreach ($THEME->inheritance as $theme) {
$filename = $basedir . $theme . '/' . $template_path;
if (is_readable($filename)) {
array_unshift($includePath, $basedir . $theme . '/');
return self::$_filePaths[$name[0]][$name[1]] = array($template_path, $includePath);
}
}
self::$_filePaths[$name[0]][$name[1]] = false;
}
if (!self::$_filePaths[$name[0]][$name[1]]) {
throw new MaharaException('Blocktype template could not be found : '.implode(':', $name));
}
return self::$_filePaths[$name[0]][$name[1]];
}
}
?>
\ No newline at end of file
<?php
/**
* implements the Export resource type
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class Dwoo_Template_Mahara_Export extends Dwoo_Template_Mahara
{
protected static $_filePaths = array();
protected function resolveFileName(array $name, array $includePath)
{
global $THEME;
if (!isset(self::$_filePaths[$name[0]][$name[1]])) {
$plugin = $name[0];
$template_path = $name[1];
$basedir = get_config('docroot');
$pluginbits = explode('/', $plugin);
if (count($pluginbits) == 2) {
$basedir .= 'artefact/' . $pluginbits[1] . '/export/' . $pluginbits[0] . '/theme/';
}
else {
$basedir .= 'export/' . $plugin . '/theme/';
}
foreach ($THEME->inheritance as $theme) {
$filename = $basedir . $theme . '/' . $template_path;
if (is_readable($filename)) {
array_unshift($includePath, $basedir . $theme . '/');
return self::$_filePaths[$name[0]][$name[1]] = array($template_path, $includePath);
}
}
self::$_filePaths[$name[0]][$name[1]] = false;
}
if (!self::$_filePaths[$name[0]][$name[1]]) {
throw new MaharaException('Blocktype template could not be found : '.implode(':', $name));
}
return self::$_filePaths[$name[0]][$name[1]];
}
}
?>
\ No newline at end of file
<?php
/**
* implements the Interaction resource type
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class Dwoo_Template_Mahara_Interaction extends Dwoo_Template_Mahara
{
protected function resolveFileName(array $name, array $includePath)
{
global $THEME;
$plugin_name = $name[0];
$plugin_path = $name[1];
$basedir = get_config('docroot') . 'interaction/' . $plugin_name . '/theme/';
foreach ($THEME->inheritance as $theme) {
$filename = $basedir . $theme . '/' . $plugin_path;
if (is_readable($filename)) {
array_unshift($includePath, $basedir . $theme . '/');
return array($plugin_path, $includePath);
}
}
throw new MaharaException('Artefact template could not be found : '.implode(':', $name));
}
}
?>
\ No newline at end of file
<?php
/**
* Dwoo {contextualhelp} function plugin
*
* Type: function<br>
* Date: June 22, 2006<br>
* Purpose: Provide inline contextual help for arbitrary sections
* @author Catalyst IT Ltd
* @version 1.0
* @return HTML snippet for help icon
*/
function Dwoo_Plugin_contextualhelp(Dwoo $dwoo, $plugintype, $pluginname, $form = null, $element = null, $section = null, $assign = null) {
$ret = call_user_func_array('get_help_icon', array(
$plugintype, $pluginname, $form, $element, null, $section));
// If there is an 'assign' parameter, place it into that instead.
if ($assign) {
$dwoo->assignInScope($ret, $assign);
return;
}
return $ret;
}
?>
<?php
/**
* Dwoo {display_name} function plugin
*
* Type: function<br>
* Date: June 22, 2006<br>
* Purpose: Display a user's name according to mahara rules
* @author Catalyst IT Ltd
* @version 1.0
*/
function Dwoo_Plugin_display_name(Dwoo $dwoo, $user) {
if (!is_object($user)) {
return '';
}
return display_name($user);
}
?>
<?php
/**
* Dwoo {loadquota} function plugin
*
* Type: function<br>
* Name: loadquota<br>
* Date: June 22, 2006<br>
* Purpose: Set quota related variables for the quota template
* @author Catalyst IT Ltd
* @version 1.0
* @return Nothing
*/
function Dwoo_Function_loadquota(Dwoo $dwoo) {
global $USER;
if (!$USER->is_logged_in()) {
return;
}
$quota = $USER->get('quota');
$quotaused = $USER->get('quotaused');
if ($quota >= 1048576) {
$quota_message = get_string('quotausage', 'mahara', sprintf('%0.1fMB', $USER->get('quotaused') / 1048576), sprintf('%0.1fMB', $quota / 1048567));
}
else if ($quota >= 1024) {
$quota_message = get_string('quotausage', 'mahara', sprintf('%0.1fKB', $USER->get('quotaused') / 1024), sprintf('%0.1fKB', $quota / 1024));
}
else {
$quota_message = get_string('quotausage', 'mahara', sprintf('%d bytes', $USER->get('quotaused')), sprintf('%d bytes', $quota));
}
$dwoo->assignInScope($quota_message, 'QUOTA_MESSAGE');
if ($quota == 0) {
$dwoo->assignInScope(100, 'QUOTA_PERCENTAGE');
} else {
$dwoo->assignInScope(round($quotaused / $quota * 100), 'QUOTA_PERCENTAGE');
}
}
?>
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Creates pagination links for a table
* appends an 'offset=n' parameter to the url to get the url for a different page
* @param integer $limit number of items per page
* @param integer $offset offset of first data item on this page
* @param integer $count total number of items
* @param string $url where to get results from
* @return string
*
* THIS IS DEPRECATED. The build_pagelinks function in lib/mahara.php should be
* used instead.
* One place this is being used is the admin user search. Hopefully that can be
* converted away soon.
*/
function smarty_function_mahara_pagelinks($params, &$smarty) {
$id = substr(md5(microtime()), 0, 4);
$output = '<div class="pagination" id="' . $id . '">';
$params['offsetname'] = (isset($params['offsetname'])) ? $params['offsetname'] : 'offset';
$params['offset'] = param_integer($params['offsetname'], 0);
$params['firsttext'] = (isset($params['firsttext'])) ? $params['firsttext'] : get_string('first');
$params['previoustext'] = (isset($params['previoustext'])) ? $params['previoustext'] : get_string('previous');
$params['nexttext'] = (isset($params['nexttext'])) ? $params['nexttext'] : get_string('next');
$params['lasttext'] = (isset($params['lasttext'])) ? $params['lasttext'] : get_string('last');
if (!isset($params['numbersincludefirstlast'])) {
$params['numbersincludefirstlast'] = true;
}
if (!isset($params['numbersincludeprevnext'])) {
$params['numbersincludeprevnext'] = true;
}
if ($params['limit'] <= $params['count']) {
$pages = ceil($params['count'] / $params['limit']);
$page = $params['offset'] / $params['limit'];
$last = $pages - 1;
$next = min($last, $page + 1);
$prev = max(0, $page - 1);
// Build a list of what pagenumbers will be put between the previous/next links
$pagenumbers = array();
if ($params['numbersincludefirstlast']) {
$pagenumbers[] = 0;
}
if ($params['numbersincludeprevnext']) {
$pagenumbers[] = $prev;
}
$pagenumbers[] = $page;
if ($params['numbersincludeprevnext']) {
$pagenumbers[] = $next;
}
if ($params['numbersincludefirstlast']) {
$pagenumbers[] = $last;
}
$pagenumbers = array_unique($pagenumbers);