diff --git a/blocks/community/renderer.php b/blocks/community/renderer.php index 67052e5ca81..b9a8eb84d8d 100644 --- a/blocks/community/renderer.php +++ b/blocks/community/renderer.php @@ -30,11 +30,6 @@ */ 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 @@ -49,22 +44,20 @@ class block_community_renderer extends plugin_renderer_base { $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%'; @@ -167,43 +160,24 @@ class block_community_renderer extends plugin_renderer_base { // 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 +} diff --git a/blocks/community/styles.css b/blocks/community/styles.css index e93ea130b66..9a5fc3649bb 100644 --- a/blocks/community/styles.css +++ b/blocks/community/styles.css @@ -23,4 +23,7 @@ #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 diff --git a/lib/javascript-static.js b/lib/javascript-static.js index e1faaa423b4..3a346ac304c 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -10,7 +10,11 @@ M.yui.add_module = function(modules) { 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 diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index a5ecf656050..413c5238650 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -2379,3 +2379,93 @@ class custom_menu extends custom_menu_item { 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 diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 64097780ae5..2aa6fc23888 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2599,6 +2599,25 @@ NONJS; // 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; + } } diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index 119d53e4c0c..49fc35ca27d 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -150,6 +150,26 @@ class page_requirements_manager { $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')); @@ -565,6 +585,40 @@ class page_requirements_manager { $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. @@ -875,7 +929,8 @@ class page_requirements_manager { // 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); diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 03b364308b4..7d447fec553 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -49,6 +49,13 @@ 2.1+ + + gallery + Gallery Lightbox + BSD + 2010.04.21-21-51 + + geoip GeoIP diff --git a/lib/gallery/assets/gallery-lightbox-core.css b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/gallery-lightbox-core.css similarity index 100% rename from lib/gallery/assets/gallery-lightbox-core.css rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/gallery-lightbox-core.css diff --git a/lib/gallery/assets/skins/sam/closelabel.gif b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/closelabel.gif similarity index 100% rename from lib/gallery/assets/skins/sam/closelabel.gif rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/closelabel.gif diff --git a/lib/gallery/assets/skins/sam/gallery-lightbox-skin.css b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/gallery-lightbox-skin.css similarity index 100% rename from lib/gallery/assets/skins/sam/gallery-lightbox-skin.css rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/gallery-lightbox-skin.css diff --git a/lib/gallery/assets/skins/sam/gallery-lightbox.css b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/gallery-lightbox.css similarity index 100% rename from lib/gallery/assets/skins/sam/gallery-lightbox.css rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/gallery-lightbox.css diff --git a/lib/gallery/assets/skins/sam/loading.gif b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/loading.gif similarity index 100% rename from lib/gallery/assets/skins/sam/loading.gif rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/loading.gif diff --git a/lib/gallery/assets/skins/sam/nextlabel.gif b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/nextlabel.gif similarity index 100% rename from lib/gallery/assets/skins/sam/nextlabel.gif rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/nextlabel.gif diff --git a/lib/gallery/assets/skins/sam/prevlabel.gif b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/prevlabel.gif similarity index 100% rename from lib/gallery/assets/skins/sam/prevlabel.gif rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/assets/skins/sam/prevlabel.gif diff --git a/lib/gallery/gallery-lightbox-debug.js b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/gallery-lightbox-debug.js similarity index 100% rename from lib/gallery/gallery-lightbox-debug.js rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/gallery-lightbox-debug.js diff --git a/lib/gallery/gallery-lightbox-min.js b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/gallery-lightbox-min.js similarity index 100% rename from lib/gallery/gallery-lightbox-min.js rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/gallery-lightbox-min.js diff --git a/lib/gallery/gallery-lightbox.js b/lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/gallery-lightbox.js similarity index 100% rename from lib/gallery/gallery-lightbox.js rename to lib/yui/gallery/gallery-lightbox/2010.04.08-12-35/gallery-lightbox.js diff --git a/lib/yui/gallery/gallery-lightbox/license.txt b/lib/yui/gallery/gallery-lightbox/license.txt new file mode 100644 index 00000000000..32012336bbc --- /dev/null +++ b/lib/yui/gallery/gallery-lightbox/license.txt @@ -0,0 +1,31 @@ +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 diff --git a/lib/yui/gallery/gallery-lightbox/readme_moodle.txt b/lib/yui/gallery/gallery-lightbox/readme_moodle.txt new file mode 100644 index 00000000000..6273d63b6a7 --- /dev/null +++ b/lib/yui/gallery/gallery-lightbox/readme_moodle.txt @@ -0,0 +1,25 @@ +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 diff --git a/theme/yui_combo.php b/theme/yui_combo.php index 5306c9c5be3..877fd150ecf 100644 --- a/theme/yui_combo.php +++ b/theme/yui_combo.php @@ -58,7 +58,7 @@ foreach ($parts as $part) { 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; } @@ -70,8 +70,13 @@ foreach ($parts as $part) { $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; diff --git a/theme/yui_image.php b/theme/yui_image.php index 7a625b862d0..9eb51c3c1f1 100644 --- a/theme/yui_image.php +++ b/theme/yui_image.php @@ -31,15 +31,18 @@ require('../config.php'); // this stops immediately at the beginning of lib/setu $path = min_optional_param('file', '', 'SAFEPATH'); $parts = explode('/', $path); -if (count($parts) != 2) { - yui_image_not_found(); -} -list($version, $image) = $parts; +$version = array_shift($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"; +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(); }