Skip to content

Commit

Permalink
imported from version 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
MarZab committed Oct 16, 2012
1 parent e7f6bbf commit dc81345
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 82 deletions.
70 changes: 17 additions & 53 deletions src/helper.php
Original file line number Diff line number Diff line change
@@ -1,63 +1,25 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_random_image
* @Author Marko Zabreznik
* @copyright Marko Zabreznik
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

defined('_JEXEC') or die;
// no direct access
defined('_JEXEC') or die('Restricted access');

/**
* Helper for mod_random_image
*
* @package Joomla.Site
* @subpackage mod_random_image
* @since 1.5
*/
class modRandomImageHelper
{
public static function getRandomImage(&$params, $images)
{
$width = $params->get('width');
$height = $params->get('height');

$i = count($images);
$random = mt_rand(0, $i - 1);
$image = $images[$random];
$size = getimagesize(JPATH_BASE . '/' . $image->folder . '/' . $image->name);

if ($width == '') {
$width = 100;
}

if ($size[0] < $width) {
$width = $size[0];
}

$coeff = $size[0] / $size[1];
if ($height == '') {
$height = (int) ($width / $coeff);
} else {
$newheight = min($height, (int) ($width / $coeff));
if ($newheight < $height) {
$height = $newheight;
} else {
$width = $height * $coeff;
}
}

$image->width = $width;
$image->height = $height;
$image->folder = str_replace('\\', '/', $image->folder);

return $image;
}

public static function getImages(&$params, $folder)
static function getImages(&$params, $folder)
{
$type = $params->get('type', 'jpg');
$type = $params->get('type', 'jpg');

$files = array();
$images = array();
Expand Down Expand Up @@ -86,6 +48,8 @@ public static function getImages(&$params, $folder)

$images[$i]->name = $img;
$images[$i]->folder = $folder;
$images[$i]->size = getimagesize(JPATH_BASE . '/' . $images[$i]->folder . '/' . $images[$i]->name);
$images[$i]->folder = str_replace('\\', '/', $images[$i]->folder);
$i++;
}
}
Expand All @@ -94,7 +58,7 @@ public static function getImages(&$params, $folder)

return $images;
}

public static function getFolder(&$params)
{
$folder = $params->get('folder');
Expand Down
44 changes: 30 additions & 14 deletions src/mod_screensave.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_random_image
* @Author Marko Zabreznik
* @copyright Marko Zabreznik
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

defined('_JEXEC') or die;
// no direct access
defined('_JEXEC') or die('Restricted access');

// Include the syndicate functions only once
require_once __DIR__ . '/helper.php';
require_once dirname(__FILE__).'/helper.php';

$link = $params->get('link');

$folder = modRandomImageHelper::getFolder($params);
$images = modRandomImageHelper::getImages($params, $folder);
$folder = modScreensaveHelper::getFolder($params);
$images = modScreensaveHelper::getImages($params, $folder);

if (!count($images)) {
echo JText::_('MOD_RANDOM_IMAGE_NO_IMAGES');
return;
}

$image = modRandomImageHelper::getRandomImage($params, $images);
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
require JModuleHelper::getLayoutPath('mod_random_image', $params->get('layout', 'default'));
$opacity = $params->get('opacity', 100);
$delay = $params->get('delay', 5);
$wait = $params->get('wait', 5);

if ( !is_numeric($opacity) || $opacity<0 || $opacity > 100 )
$opacity = 100;

if ( !is_numeric($delay) || $delay<0 )
$delay = 0;

if ( !is_numeric($wait) || $wait<0 )
$wait = 100;

JHTML::script("rot.js", "modules/mod_screensave/js/screensave.js", false);
require JModuleHelper::getLayoutPath('mod_screensave');
38 changes: 23 additions & 15 deletions src/tmpl/default.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_random_image
* @Author Marko Zabreznik
* @copyright Marko Zabreznik
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

defined('_JEXEC') or die;
// no direct access
defined('_JEXEC') or die('Restricted access');
?>
<div class="random-image<?php echo $moduleclass_sfx ?>">
<?php if ($link) : ?>
<a href="<?php echo $link; ?>">
<?php endif; ?>
<?php echo JHtml::_('image', $image->folder.'/'.$image->name, $image->name, array('width' => $image->width, 'height' => $image->height)); ?>
<?php if ($link) : ?>
</a>
<?php endif; ?>
</div>
<script language="JavaScript">
var screensaver;
window.addEvent('domready', function(){
screensaver = new ScreenSave({
images: JSON.decode('<?php echo json_encode($images); ?>'),
wait: <?php echo $wait; ?>,
delay: <?php echo $delay; ?>,
opacity: <?php echo $opacity/100; ?>,
});
});
</script>
77 changes: 77 additions & 0 deletions src/tmpl/js/screensave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Mod ScreenSave
Marko(at)Zabreznik.net
2011/11/15 22:18
*/

var ScreenSave = new Class({
options: {
images: [],
wait: 60,
delay: 5,
opacity: 100,
},
initialize: function(op){
this.setOptions(op);

this.active = false;
this.imageElement = new Element('img',{'class': 'screensaveImg', 'id': 'screensaveImg'});
this.overlayElement=new Element('div',{'class': 'screensave', 'id': 'screensave'});
this.overlayElement.adopt(this.imageElement);
$(document.body).adopt(this.overlayElement);


var scroolsize = document.getScrollSize();
this.overlayElement.setStyles({
'display': 'none',
'height' : scroolsize.y+'px',
'width': scroolsize.x+'px',
'opacity': this.options.opacity,
'position': 'absolute','top': '0','left': '0','z-index': '90','background': '#000'
});
this.imageElement.setStyles({ 'position': 'absolute' });

this.current = this.options.images.length;

this.delayTimer = $clear(this.delayTimer);
this.waitTimer = this.startSS.bind(this).delay(this.options.wait*1000);
$(document.body).addEvent('mousemove', function(e) {
if (this.active == true)
this.stopSS();
else {
this.waitTimer = $clear(this.waitTimer);
this.waitTimer = this.startSS.bind(this).delay(this.options.wait*1000);
}
}.bindWithEvent(this));
},
startSS: function () {
this.active = true;
this.ShowHideAvancedElements(true);
this.changeImage();
var scroolsize = document.getScrollSize();
this.overlayElement.setStyles({
'display': 'block',
'height' : scroolsize.y+'px',
'width': scroolsize.x+'px'
});
this.delayTimer = this.changeImage.bind(this).periodical(this.options.delay*1000);
},
stopSS: function () {
this.active = false;
this.delayTimer = $clear(this.delayTimer);
this.ShowHideAvancedElements(false);
this.overlayElement.style.display = 'none';
},
changeImage : function () {
this.current = (this.current < this.options.images.length) ? this.current+1 : 0;
this.imageElement.src = this.options.images[this.current].s;
this.imageElement.setStyles({ 'width': this.options.images[this.current].w, 'height': this.options.images[this.current].h });

this.imageElement.style.top = $random(getScrollTop()+20,getScrollTop()+getHeight()-this.imageElement.height-20)+'px';
this.imageElement.style.left= $random(getScrollLeft()+20,getScrollLeft()+getWidth()-this.imageElement.width-20)+'px';
},
ShowHideAvancedElements: function (visible) {
$$("applet", "iframe", "select").visibility = (visible) ? "visible": "hidden";
}
});
ScreenSave.implement(new Options);

0 comments on commit dc81345

Please sign in to comment.