Commit 7d44ef4d authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Merge branch 'gallery2'

parents a44ccdca 0dafd98c
$j('#instconf_select_container input[type="radio"][value="0"]').click(function() {
$j('#instconf_images_header').addClass('hidden');
$j('#instconf_images_container').addClass('hidden');
$j('#instconf_folder_header').removeClass('hidden');
$j('#instconf_folder_container').removeClass('hidden');
});
$j('#instconf_select_container input[type="radio"][value="1"]').click(function() {
$j('#instconf_folder_header').addClass('hidden');
$j('#instconf_folder_container').addClass('hidden');
$j('#instconf_images_header').removeClass('hidden');
$j('#instconf_images_container').removeClass('hidden');
});
$j('#instconf_style_container input[type="radio"][value="0"]').click(function () {
$j('#instconf_width').val('75');
});
$j('#instconf_style_container input[type="radio"][value="1"]').click(function () {
$j('#instconf_width').val('400');
});
function Slideshow(id, count) {
var self = this;
this.id = '#slideshow' + id;
this.count = count - 1;
this.current = 0;
this.change = function(to) {
if (to == this.current || to < 0 || to > this.count) {
return false;
}
$j(this.id).height($j(this.id + " img:eq(" + this.current + ")").height());
$j(this.id + " img:eq(" + this.current + ")").fadeOut(500, function() {
self.current = to;
$j(self.id + " img:eq(" + self.current + ")").fadeIn(500);
$j(self.id).height($j(self.id + " img:eq(" + self.current + ")").height());
});
$j(this.id + ' td.control span').removeClass('disabled');
$j(this.id + ' td.control span.first').addClass('hidden');
if (to == 0) {
$j(this.id + ' td.control span.prev').addClass('disabled');
}
else if (to == this.count) {
$j(this.id + ' td.control span.next').addClass('disabled');
$j(this.id + ' td.control span.first').removeClass('hidden');
}
return false;
}
$j(this.id + ' td.control span.next').click(function() {return self.change(self.current + 1);});
$j(this.id + ' td.control span.prev').click(function() {return self.change(self.current - 1);});
$j(this.id + ' td.control span.first').click(function() {return self.change(0);});
// $j(this.id + ' td.control span.last').click(function() {return self.change(self.count);});
$j(this.id + " img").hide();
$j(this.id + " img:eq(" + this.current + ")").show();
$j(this.id + ' td.control span.next').removeClass('disabled');
}
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-gallery
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$string['title'] = 'Image Gallery';
$string['description'] = 'A collection of images from your Files area';
$string['select'] = 'Image Selection';
$string['selectfolder'] = 'Display all images from one of my folders (will include images uploaded later)';
$string['selectimages'] = 'I will choose individual images to display';
$string['width'] = 'Width';
$string['widthdescription'] = 'Specify the width for your images (in pixels). The images will be scaled to this width.';
$string['style'] = 'Style';
$string['stylethumbs'] = 'Thumbnails';
$string['styleslideshow'] = 'Slideshow';
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-slideshow
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
class PluginBlocktypeGallery extends PluginBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.file/gallery');
}
public static function get_description() {
return get_string('description', 'blocktype.file/gallery');
}
public static function get_categories() {
return array('fileimagevideo');
}
public static function get_instance_javascript(BlockInstance $instance) {
$configdata = $instance->get('configdata');
switch ($configdata['style']) {
case 0: // thumbnails
return array();
case 1: // slideshow
return array('js/slideshow.js');
}
}
public static function get_instance_config_javascript() {
return array('js/configform.js');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
$configdata = $instance->get('configdata'); // this will make sure to unserialize it for us
$configdata['viewid'] = $instance->get('view');
$style = isset($configdata['style']) ? intval($configdata['style']) : 0;
switch ($style) {
case 0: // thumbnails
$template = 'thumbnails';
$width = isset($configdata['width']) ? $configdata['width'] : 75;
break;
case 1: // slideshow
$template = 'slideshow';
$width = isset($configdata['width']) ? $configdata['width'] : 400;
break;
}
$artefactids = array();
if (isset($configdata['select']) && $configdata['select'] == 1 && is_array($configdata['artefactids'])) {
$artefactids = $configdata['artefactids'];
}
else if (!empty($configdata['artefactid'])) {
// Get descendents of this folder.
$artefactids = artefact_get_descendants(array(intval($configdata['artefactid'])));
}
// This can be either an image or profileicon. They both implement
// render_self
$images = array();
foreach ($artefactids as $artefactid) {
$image = $instance->get_artefact_instance($artefactid);
if ($image instanceof ArtefactTypeProfileIcon) {
$src = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $artefactid;
$description = $image->get('title');
}
else if ($image instanceof ArtefactTypeImage) {
$src = get_config('wwwroot') . 'artefact/file/download.php?file=' . $artefactid;
$src .= '&view=' . $instance->get('view');
$description = $image->get('description');
}
else {
continue;
}
$src .= '&maxwidth=' . $width;
$images[] = array(
'link' => get_config('wwwroot') . 'view/artefact.php?artefact=' .
$artefactid . '&view=' . $instance->get('view'),
'source' => $src,
'title' => $image->get('title'),
);
}
$smarty = smarty_core();
$smarty->assign('instanceid', $instance->get('id'));
$smarty->assign('count', count($images));
$smarty->assign('images', $images);
$smarty->assign('width', $width);
return $smarty->fetch('blocktype:gallery:' . $template . '.tpl');
}
public static function has_instance_config() {
return true;
}
public static function instance_config_form($instance) {
$configdata = $instance->get('configdata');
safe_require('artefact', 'file');
$instance->set('artefactplugin', 'file');
$user = $instance->get('view_obj')->get('owner');
$select_options = array(
0 => get_string('selectfolder', 'blocktype.file/gallery'),
1 => get_string('selectimages', 'blocktype.file/gallery'),
);
$style_options = array(
0 => get_string('stylethumbs', 'blocktype.file/gallery'),
1 => get_string('styleslideshow', 'blocktype.file/gallery'),
);
if (isset($configdata['select']) && $configdata['select'] == 1) {
$imageids = isset($configdata['artefactids']) ? $configdata['artefactids'] : array();
$imageselector = self::imageselector($instance, $imageids);
$folderselector = self::folderselector($instance, null, 'hidden');
}
else {
$imageselector = self::imageselector($instance, null, 'hidden');
$folderid = !empty($configdata['artefactid']) ? array(intval($configdata['artefactid'])) : null;
$folderselector = self::folderselector($instance, $folderid);
}
return array(
'user' => array(
'type' => 'hidden',
'value' => $user,
),
'select' => array(
'type' => 'radio',
'title' => get_string('select', 'blocktype.file/gallery'),
'options' => $select_options,
'defaultvalue' => (isset($configdata['select'])) ? $configdata['select'] : 0,
'separator' => '<br>',
),
'images' => $imageselector,
'folder' => $folderselector,
'style' => array(
'type' => 'radio',
'title' => get_string('style', 'blocktype.file/gallery'),
'options' => $style_options,
'defaultvalue' => (isset($configdata['style'])) ? $configdata['style'] : 0,
'separator' => '<br>',
),
'width' => array(
'type' => 'text',
'title' => get_string('width', 'blocktype.file/gallery'),
'size' => 3,
'description' => get_string('widthdescription', 'blocktype.file/gallery'),
'rules' => array(
'minvalue' => 16,
'maxvalue' => get_config('imagemaxwidth'),
),
'defaultvalue' => (isset($configdata['width'])) ? $configdata['width'] : '75',
),
);
}
public static function instance_config_save($values) {
if ($values['select'] == 0) {
$values['artefactid'] = $values['folder'];
unset($values['artefactids']);
}
else if ($values['select'] == 1) {
$values['artefactids'] = $values['images'];
unset($values['artefactid']);
}
unset($values['folder']);
unset($values['images']);
return $values;
}
public static function imageselector(&$instance, $default=array(), $class=null) {
$element = ArtefactTypeFileBase::blockconfig_filebrowser_element($instance, $default);
$element['title'] = get_string('Images', 'artefact.file');
$element['name'] = 'images';
if ($class) {
$element['class'] = $class;
}
$element['config']['selectone'] = false;
$element['filters'] = array(
'artefacttype' => array('image'),
);
return $element;
}
public static function folderselector(&$instance, $default=array(), $class=null) {
$element = ArtefactTypeFileBase::blockconfig_filebrowser_element($instance, $default);
$element['title'] = get_string('folder', 'artefact.file');
$element['name'] = 'folder';
if ($class) {
$element['class'] = $class;
}
$element['config']['upload'] = false;
$element['config']['selectone'] = true;
$element['config']['selectfolders'] = true;
$element['filters'] = array(
'artefacttype' => array('folder'),
);
return $element;
}
public static function artefactchooser_element($default=null) {
}
public static function default_copy_type() {
return 'full';
}
}
{if $images}
<div class="slideshow" id="slideshow{$instanceid}">
<table class="images">
<tr>
<td class="control">
<span class="first hidden">&laquo;</span>
<span class="prev disabled">&lsaquo;</span>
</td>
<td>
{foreach from=$images item=image name=images}
<a href="{$image.link}" target="_blank"><img src="{$image.source}" alt="{$image.title}" title="{$image.title}" style="max-width: {$width}px;{if !$dwoo.foreach.images.first} display:none;{/if}"></a>
{/foreach}
</td>
<td class="control">
<span class="next disabled">&rsaquo;</span>
{*<span class="last">&raquo;</span>*}
</td>
</tr>
</table>
</div>
<script type="text/javascript">
var slideshow{$instanceid} = new Slideshow({$instanceid}, {$count});
</script>
{else}
{str tag=noimagesfound section=artefact.file}
{/if}
\ No newline at end of file
<div class="thumbnails">
{foreach from=$images item=image}
<a href="{$image.link}" target="_blank">
<img src="{$image.source}" alt="{$image.title}" title="{$image.title}" />
</a>
{/foreach}
</div>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-file
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010102801;
$config->release = '1.0.0';
......@@ -294,7 +294,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
this.browse_init = function () {
if (self.config.edit || self.config.editmeta) {
forEach(getElementsByTagAndClassName('input', null, 'filelist'), function (elem) {
forEach(getElementsByTagAndClassName('input', null, self.id + '_filelist'), function (elem) {
var name = getNodeAttribute(elem, 'name').match(new RegExp('^' + self.id + "_([a-z]+)\\[(\\d+)\\]$"));
if (name && name[1]) {
if (name[1] == 'edit') {
......@@ -350,10 +350,10 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
forEach(Draggables.drags, function (drag) { drag.destroy(); });
forEach(Droppables.drops, function (drop) { drop.destroy(); });
forEach(getElementsByTagAndClassName('div', 'icon-drag', 'filelist'), function (elem) {
forEach(getElementsByTagAndClassName('div', 'icon-drag', self.id + '_filelist'), function (elem) {
self.make_icon_draggable(elem);
});
forEach(getElementsByTagAndClassName('tr', 'folder', 'filelist'), self.make_row_droppable);
forEach(getElementsByTagAndClassName('tr', 'folder', self.id + '_filelist'), self.make_row_droppable);
}
}
forEach(getElementsByTagAndClassName('a', 'changeowner', self.id + '_upload_browse'), function (elem) {
......@@ -501,7 +501,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
}
this.connect_select_buttons = function () {
forEach(getElementsByTagAndClassName('input', 'select', 'filelist'), function (elem) {
forEach(getElementsByTagAndClassName('input', 'select', self.id + '_filelist'), function (elem) {
var id = elem.name.replace(/.*_select\[(\d+)\]$/, '$1');
if (self.selecteddata[id]) {
addElementClass(elem, 'hidden');
......
......@@ -100,6 +100,7 @@ $string['home'] = 'Home';
$string['htmlremovedmessage'] = 'You are viewing <strong>%s</strong> by <a href="%s">%s</a>. The file displayed below has been filtered to remove malicious content, and is only a rough representation of the original.';
$string['htmlremovedmessagenoowner'] = 'You are viewing <strong>%s</strong>. The file displayed below has been filtered to remove malicious content, and is only a rough representation of the original.';
$string['image'] = 'Image';
$string['Images'] = 'Images';
$string['lastmodified'] = 'Last Modified';
$string['myfiles'] = 'My Files';
$string['Name'] = 'Name';
......
{if !$filelist}
<p>{str tag=nofilesfound section=artefact.file}</p>
{else}
<table id="filelist" class="tablerenderer filelist">
<table id="{$prefix}_filelist" class="tablerenderer filelist">
<thead>
<tr>
<th></th>
......
......@@ -73,6 +73,10 @@ class PluginBlocktypeCreativecommons extends SystemBlocktype {
return true;
}
public static function get_instance_config_javascript() {
return array('js/creativecommons.js');
}
public static function instance_config_save($values) {
$license = 'by';
if (1 == $values['noncommercial']) {
......
......@@ -83,6 +83,15 @@ abstract class PluginBlocktype extends Plugin {
public static abstract function render_instance(BlockInstance $instance, $editing=false);
/**
* This function must be implemented in the subclass if it requires
* javascript. It returns an array of javascript files, either local
* or remote.
*/
public static function get_instance_javascript(BlockInstance $instance) {
return array();
}
/**
* If this blocktype contains artefacts, and uses the artefactchooser
* Pieform element to choose them, this method must return the definition
......@@ -116,6 +125,15 @@ abstract class PluginBlocktype extends Plugin {
throw new SystemException(get_string('blocktypemissingconfigform', 'error', $instance->get('blocktype')));
}
/**
* Thus function must be implemented in the subclass is it has an
* instance config form that requires javascript. It returns an
* array of javascript files, either local or remote.
*/
public static function get_instance_config_javascript(BlockInstance $instance) {
return array();
}
/**
* Blocktype plugins can implement this to perform custom pieform
* validation, should they need it
......@@ -712,6 +730,7 @@ class BlockInstance {
$title = $this->get('title');
}
$elements = array_merge(
array(
'title' => array(
......@@ -815,6 +834,24 @@ class BlockInstance {
}
}
$configjs = call_static_method($blocktypeclass, 'get_instance_config_javascript', $this);
foreach($configjs as &$jsfile) {
if(strpos($jsfile, 'http://') === false) {
if($this->artefactplugin) {
$jsfile = 'artefact/' . $this->artefactplugin . '/blocktype/' .
$this->blocktype . '/' . $jsfile;
}
else {
$jsfile = 'blocktype/' . $this->blocktype . '/' . $jsfile;
}
$jsfile = '$j.getScript("' . get_config('wwwroot') . $jsfile . '");';
}
else {
$jsfile = '$j.getScript("' . $jsfile . '");';
}
}
$js .= implode('', $configjs);
$renderedform = array('html' => $html, 'javascript' => $js);
return $renderedform;
}
......
......@@ -57,8 +57,11 @@ if ($group->public) {
$headers[] = '<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '" />';
}
$javascript = array('paginator', 'jquery');
$javascript = array_merge($javascript, $view->get_blocktype_javascript());
$smarty = smarty(
array(),
$javascript,
$headers,
array(),
array('stylesheets' => array('style/views.css'))
......
......@@ -51,9 +51,11 @@ if ($USER->is_logged_in()) {
require_once(get_config('libroot') . 'view.php');
$view = $USER->get_view_by_type('dashboard');
$javascript = array('paginator', 'jquery');
$javascript = array_merge($javascript, $view->get_blocktype_javascript());
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');
$smarty = smarty(
array('paginator'),
$javascript,
$stylesheets,
array(),
array(
......
This diff is collapsed.
This diff is collapsed.
......@@ -73,7 +73,11 @@ function pieform_renderer_maharatable(Pieform $form, $element) {
$result .= $element['labelhtml'];
$result .= "</th>\n\t</tr>\n";
}
$result .= "\t<tr id=\"{$formname}_{$element['name']}_container\">\n\t\t<td>";
$result .= "\t<tr id=\"{$formname}_{$element['name']}_container\"";
if ($element['class']) {
$result .= ' class="' . Pieform::hsc($element['class']) . '"';
}
$result .= ">\n\t\t<td>";
// Wrap WYSIWYG elements in a table with two cells side by side, one for the element and one for the help icon
if (!empty($element['help']) && $element['type'] == 'wysiwyg') {
......