*/
class block_community_renderer extends plugin_renderer_base {
- public function __construct(moodle_page $page, $target) {
- parent::__construct($page, $target);
- $this->page->requires->css('/lib/gallery/assets/skins/sam/gallery-lightbox-skin.css');
- }
-
/**
* Display a list of courses
* @param array $courses
$table = new html_table();
- $table->head = array(get_string('coursename', 'block_community'),
-
+ $table->head = array(
+ get_string('coursename', 'block_community'),
get_string('coursedesc', 'block_community'),
- get_string('screenshots', 'block_community'),
+ get_string('screenshots', 'block_community'),
get_string('courselang', 'block_community'),
- get_string('operation', 'block_community'));
-
+ get_string('operation', 'block_community')
+ );
$table->align = array('center', 'left', 'center', 'left', 'center');
$table->size = array('20%', '45%', '5%', '5%', '5%');
if (empty($courses)) {
- if (isset($courses)) {
- $renderedhtml .= get_string('nocourse', 'block_community');
- }
+ $renderedhtml .= get_string('nocourse', 'block_community');
} else {
$table->width = '100%';
// add a row to the table
$screenshothtml = '';
if (!empty($course->screenshotsids)) {
-
- //include gallery lightbox js
- $this->page->requires->js('/lib/gallery/gallery-lightbox-min.js');
-
+ $images = array();
+ $baseurl = new moodle_url($huburl.'/local/hub/webservice/download.php', array('courseid' => $course->id, 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
for ($i = 1; $i <= $course->screenshotsids; $i = $i + 1) {
- if ($i == 1) {
- $params = array('courseid' => $course->id,
- 'filetype' => HUB_SCREENSHOT_FILE_TYPE, 'screenshotnumber' => $i);
- $imgurl = new moodle_url($huburl . "/local/hub/webservice/download.php", $params);
- } else {
- //empty image
- $imgurl = new moodle_url($CFG->wwwroot . "/pix/spacer.gif");
- }
- $ascreenshothtml = html_writer::empty_tag('img', array('src' => $imgurl, 'alt' => $course->fullname));
- $originalparams = array('courseid' => $course->id,
- 'filetype' => HUB_SCREENSHOT_FILE_TYPE, 'screenshotnumber' => $i, 'imagewidth' => 'original');
- $originalimgurl = new moodle_url($huburl . "/local/hub/webservice/download.php", $originalparams);
- $screenshothtml .= html_writer::tag('a', $ascreenshothtml,
- array('rel' => 'lightbox[' . $course->shortname . ']', 'title' => $course->fullname,
- 'href' => $originalimgurl));
+ $params['screenshotnumber'] = $i;
+ $images[] = array(
+ 'thumburl' => new moodle_url($baseurl, array('screenshotnumber' => $i)),
+ 'imageurl' => new moodle_url($baseurl, array('screenshotnumber' => $i, 'imagewidth' => 'original')),
+ 'title' => $course->fullname,
+ 'alt' => $course->fullname
+ );
}
-
- // run the JS
- $js = "Y.use(\"gallery-lightbox\", function (Y) { Y.Lightbox.init(); });";
- $this->page->requires->js_init_code($js, true);
+ $screenshothtml = $this->output->render(new image_gallery($images, $course->shortname));
}
-
- $cells = array($coursenamehtml, $deschtml, $screenshothtml, $language, $addbuttonhtml);
-
-
- $row = new html_table_row($cells);
-
- $table->data[] = $row;
+ $table->data[] = array($coursenamehtml, $deschtml, $screenshothtml, $language, $addbuttonhtml);
}
$renderedhtml .= html_writer::table($table);
}
return $renderedhtml;
}
-}
\ No newline at end of file
+}
#page-blocks-community-communitycourse .prioritisetr {background-color: #ffd4ff;}
#page-blocks-community-communitycourse .additionaldesc {font-size: 80%; color: #aa6666;}
#page-blocks-community-communitycourse .additionaladmindesc {font-size: 80%; color: #6666ff;}
-#page-blocks-community-communitycourse .blockdescription {font-size: 80%; color: #555555;}
\ No newline at end of file
+#page-blocks-community-communitycourse .blockdescription {font-size: 80%; color: #555555;}
+
+.path-blocks-community .image_gallery a.imagelink {display:none;}
+.path-blocks-community .image_gallery a#imagelink1 {display:inline;}
\ No newline at end of file
M.yui.loader.modules[modname] = modules[modname];
}
};
-
+/**
+ * The gallery version to use when loading YUI modules from the gallery.
+ * Will be changed every time when using local galleries.
+ */
+M.yui.galleryversion = '2010.04.21-21-51';
/**
* Various utility functions
return ($itema > $itemb) ? +1 : -1;
}
}
+
+/**
+ * Image gallery component
+ *
+ * This is the image gallery component that can be used to display several images
+ * and if JavaScript is enabled uses the gallery-lightbox YUI module to display
+ * them within a lightbox with appropriate controls and such.
+ *
+ * Lib / YUI Module location: lib/gallery/20100601/
+ *
+ * @copyright 2010 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ */
+class image_gallery implements renderable {
+
+ /**
+ * Used to ensure we only initialise the lightbox once... it is shared
+ * @var bool
+ */
+ protected static $jsinit = false;
+ /**
+ * An array of images
+ * @var array
+ */
+ public $images = array();
+ /**
+ * The grouping to apply in the lightbox
+ * @var string
+ */
+ public $grouping = null;
+
+ /**
+ * Constructs an image gallery component
+ * @param array $images
+ * @param string $grouping
+ */
+ public function __construct(array $images=null, $grouping=null) {
+ $this->grouping = $grouping;
+ if (is_array($images)) {
+ foreach ($images as $image) {
+ $image = (array)$image;
+ if (!array_key_exists('imageurl', $image)) {
+ throw new coding_exception('Image gallery images must specify a url for every image');
+ }
+ if (!array_key_exists('thumburl', $image)) {
+ throw new coding_exception('Image gallery images must specify a url for every image');
+ }
+ if (!array_key_exists('title', $image)) {
+ throw new coding_exception('Image gallery images must specify a title for every image');
+ }
+ if (!array_key_exists('alt', $image)) {
+ $image['alt'] = null;
+ }
+ if (!array_key_exists('attributes', $image)) {
+ $image['attributes'] = null;
+ }
+ $this->add_image($image['thumburl'], $image['imageurl'], $image['title'], $image['alt'], $image['attributes']);
+ }
+ }
+ }
+ /**
+ * Adds an image to the gallery
+ *
+ * @param moodle_url|string $thumburl
+ * @param moodle_url|string $imageurl
+ * @param string $title
+ * @param string $alt
+ * @param array $attributes
+ */
+ public function add_image($thumburl, $imageurl, $title, $alt=null, array $attributes=null) {
+ $image = new stdClass;
+ $image->link = array('id'=>'imagelink'.(count($this->images)+1), 'class'=>'imagelink');
+ $image->thumb = array('id'=>'imagethumb'.(count($this->images)+1), 'class'=>'imagethumb');
+ if (is_array($attributes)) {
+ $image->link = $attributes;
+ }
+ $image->link['href'] = new moodle_url($imageurl);
+ $image->link['title'] = $title;
+ $image->link['rel'] = 'lightbox';
+ if ($this->grouping !== null) {
+ $image->link['rel'] .= "[{$this->grouping}]";
+ }
+
+ $image->thumb['src'] = new moodle_url($thumburl);
+ $image->thumb['alt'] = $alt;
+
+ $this->images[] = $image;
+ }
+}
\ No newline at end of file
// Return the sub menu
return $content;
}
+
+ /**
+ * Renders the image_gallery component and initialises its JavaScript
+ *
+ * @param image_gallery $imagegallery
+ * @return string
+ */
+ protected function render_image_gallery(image_gallery $imagegallery) {
+ $this->page->requires->js_gallery_module(array('gallery-lightbox','gallery-lightbox-skin'), '2010.04.08-12-35', 'Y.Lightbox.init');
+ if (count($imagegallery->images) == 0) {
+ return '';
+ }
+ $content = html_writer::start_tag('div', array('class'=>'image_gallery'));
+ foreach ($imagegallery->images as $image) {
+ $content .= html_writer::tag('a', html_writer::empty_tag('img', $image->thumb), $image->link);
+ }
+ $content .= html_writer::end_tag('div');
+ return $content;
+ }
}
$this->M_yui_loader->filter = ($this->yui3loader->filter == YUI_DEBUG) ? 'debug' : '';
$this->M_yui_loader->insertBefore = 'firstthemesheet';
$this->M_yui_loader->modules = array();
+ if (empty($CFG->useexternalyui) || true) {
+ $this->M_yui_loader->groups = array(
+ 'local' => array(
+ 'name' => 'gallery',
+ 'base' => $CFG->wwwroot.'/lib/yui/gallery/',
+ 'comboBase' => $this->yui3loader->comboBase,
+ 'combine' => $this->yui3loader->combine,
+ 'filter' => $this->M_yui_loader->filter,
+ 'ext' => false,
+ 'root' => 'gallery/',
+ 'patterns' => array(
+ 'gallery-' => array(
+ 'group' => 'gallery',
+ 'configFn' => '@GALLERYCONFIGFN@',
+ ),
+ 'root' => 'gallery'
+ ),
+ )
+ );
+ }
$this->add_yui2_modules(); // adds loading info for all YUI2 modules
$this->js_module($this->find_module('core_filepicker'));
$this->js_module($this->find_module('core_dock'));
$this->jscalls[$where][] = array($function, $arguments, $delay);
}
+ /**
+ * Adds a call to make use of a YUI gallery module.
+ *
+ * This function adds code to the page footer that will tell a YUI instance to
+ * use the requested gallery module(s) and then call the desired function.
+ *
+ * @todo Once YUI support loading skins from the gallery the if to use
+ * external yui libs should be fixed so that it calls;
+ *
+ * @param string|array $modules One or more gallery modules to require
+ * @param string $version
+ * @param string $function
+ * @param array $arguments
+ * @param bool $ondomready
+ */
+ public function js_gallery_module($modules, $version, $function, array $arguments = null, $ondomready = false) {
+ global $CFG;
+ if (!is_array($modules)) {
+ $modules = array($modules);
+ }
+ if (empty($CFG->useexternalyui) || true) {
+ // We need to set the M.yui.galleryversion to the correct version
+ $jscode = 'M.yui.galleryversion='.json_encode($version).';';
+ } else {
+ // Set Y's config.gallery to the version
+ $jscode = 'Y.config.gallery='.json_encode($version).';';
+ }
+ $jscode .= 'Y.use('.join(',', array_map('json_encode', $modules)).',function() {'.js_writer::function_call($function, $arguments).'})';
+ if ($ondomready) {
+ $jscode = "Y.on('domready', function() { $jscode });";
+ }
+ $this->jsinitcode[] = $jscode;
+ }
+
/**
* Ensure that the specified JavaScript function is called from an inline script
* from page footer.
// note: in JavaScript just use "YUI(M.yui.loader).use('overlay', function(Y) { .... });"
// this needs to be done before including any other script
$js = "var M = {}; M.yui = {}; ";
- $js .= js_writer::set_variable('M.yui.loader', $this->M_yui_loader, false) . "\n";
+ $js .= "var galleryConfigFn = function(me) {var p = me.path,v=M.yui.galleryversion,f;if(/-skin/.test(me.name)) {me.type = 'css';var p = p.replace(/\-skin/, '').replace(/\.js/, '.css').split('/'), f = p.pop().replace(/\-skin(\-(min|debug))/, '');p.splice(p.length,0,v,'assets','skins','sam', f);} else {var p = p.split('/'), f = p.pop();p.splice(p.length,0,v, f);};me.path = p.join('/');}; ";
+ $js .= str_replace('"@GALLERYCONFIGFN@"', 'galleryConfigFn', js_writer::set_variable('M.yui.loader', $this->M_yui_loader, false) . "\n");
$js .= js_writer::set_variable('M.cfg', $this->M_cfg, false);
$output .= html_writer::script($js);
<version></version>
<licenseversion>2.1+</licenseversion>
</library>
+ <library>
+ <location>gallery</location>
+ <name>Gallery Lightbox</name>
+ <license>BSD</license>
+ <version>2010.04.21-21-51</version>
+ <licenseversion></licenseversion>
+ </library>
<library>
<location>geoip</location>
<name>GeoIP</name>
--- /dev/null
+Copyright (c) 2009, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+
+Redistribution and use of this software in source and binary forms, with or
+without modification, are permitted provided that the following conditions are
+met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of Yahoo! Inc. nor the names of its contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission of Yahoo! Inc.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+http://developer.yahoo.net/yui/license.html
--- /dev/null
+Description of import of gallery-lightbox YUI3 module.
+
+Author:
+ Andrew Bialecki
+
+Gallery url:
+ http://yuilibrary.com/gallery/show/lightbox
+
+License:
+ YUI BSD http://developer.yahoo.com/yui/license.html
+
+Available from:
+ http://projects.sophomoredev.com/yui-gallery-lightbox
+
+Downloaded from:
+ http://github.com/downloads/bialecki/yui3-gallery/gallery-lightbox.zip
+
+Information:
+ A port of the lightbox 2 project [http://www.huddletogether.com/projects/lightbox2/]
+
+
+1\ Version gallery-2010.04.08-12-35
+ * Copied downloaded files to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/.
+ * Did not make any changes to downloaded files.
+ * Integrated into Moodle via image_gallery component in lib/outputcomponents.php.
\ No newline at end of file
continue;
}
$version = $bits[0];
- if ($version != $CFG->yui3version and $version != $CFG->yui2version) {
+ if ($version != $CFG->yui3version and $version != $CFG->yui2version and $version != 'gallery') {
$content .= "\n// Wrong yui version $part!\n";
continue;
}
$filecontent = file_get_contents($contentfile);
if ($mimetype === 'text/css') {
- // search for all images in yui2 CSS and serve them through the yui_image.php script
- $filecontent = preg_replace('/([a-z_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/$1.$2', $filecontent);
+ if ($version == 'gallery') {
+ // search for all images in gallery module CSS and serve them through the yui_image.php script
+ $filecontent = preg_replace('/([a-z_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/'.$bits[1].'/'.$bits[2].'/$1.$2', $filecontent);
+ } else {
+ // search for all images in yui2 CSS and serve them through the yui_image.php script
+ $filecontent = preg_replace('/([a-z_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/$1.$2', $filecontent);
+ }
}
$content .= $filecontent;
$path = min_optional_param('file', '', 'SAFEPATH');
$parts = explode('/', $path);
-if (count($parts) != 2) {
- yui_image_not_found();
-}
-list($version, $image) = $parts;
-
-if ($version == $CFG->yui3version) {
- $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui3version/build/assets/skins/sam/$image";
-} else if ($version == $CFG->yui2version) {
- $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui2version/build/assets/skins/sam/$image";
+$version = array_shift($parts);
+
+if ($version =='gallery' && count($parts)==3) {
+ list($module, $version, $image) = $parts;
+ $imagepath = "$CFG->dirroot/lib/yui/gallery/$module/$version/assets/skins/sam/$image";
+} else if (count($parts) == 1 && ($version == $CFG->yui3version || $version == $CFG->yui2version)) {
+ list($image) = $parts;
+ if ($version == $CFG->yui3version) {
+ $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui3version/build/assets/skins/sam/$image";
+ } else {
+ $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui2version/build/assets/skins/sam/$image";
+ }
} else {
yui_image_not_found();
}