[ImageBlock] New feature: Repeat blocks setting.

RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Wed, 2006-03-08 10:59

I have been wanting a certain feature for quite some time now with the imageblock which I now made myself. It would be cool to be able to repeat an imageblock like the recentimage in such a way that if I repeat it once I get to see the two most recent images. Luckily the imageblock code already provided in getting the two latest instead of just the last one twice. But the imageblock code lacked the setting in the admin center to repeat a block.

I've added some code to add this option and I'll describe here how I did it. Perhaps this is an option to include in the next release of this module? I noticed this repeating of the blocks works perfectly for random, recent and most viewed images/albums but it doesn't affect image of the day which does not seem to get repeated, but then again; that is not a bad thing.

Here's how:
In file imageblock\templates\blocks\blocks.inc add the follwing bold code in between "blocks" (line 5 - 21) and "useDefaults" (line 22)

	'blocks' => array(
	    'description' => $gallery->i18n('Image type'),
	    'type' => 'choice',
	    'default' => 'randomImage',
	    'choices' => array(
		'randomImage' => $gallery->i18n('Random image'),
		'recentImage' => $gallery->i18n('Recent image'),
		'viewedImage' => $gallery->i18n('Viewed image'),
		'randomAlbum' => $gallery->i18n('Random album'),
		'recentAlbum' => $gallery->i18n('Recent album'),
		'viewedAlbum' => $gallery->i18n('Viewed album'),
		'dailyImage' => $gallery->i18n('Daily image'),
		'weeklyImage' => $gallery->i18n('Weekly image'),
		'monthlyImage' => $gallery->i18n('Monthly image'),
		'dailyAlbum' => $gallery->i18n('Daily album'),
		'weeklyAlbum' => $gallery->i18n('Weekly album'),
		'monthlyAlbum' => $gallery->i18n('Monthly album'))),
	'repeatBlock' => array(
	    'description' => $gallery->i18n('Repeat this block'),
	    'type' => 'choice',
	    'default' => '1',
	    'choices' => array(
		'1' => $gallery->i18n('no repeat'),
		'2' => $gallery->i18n('1 time'),
		'3' => $gallery->i18n('2 times'),
		'4' => $gallery->i18n('3 times'),
		'5' => $gallery->i18n('4 times'),
		'6' => $gallery->i18n('5 times'),
		'7' => $gallery->i18n('6 times'),
		'8' => $gallery->i18n('7 times'),
		'9' => $gallery->i18n('8 times'),
		'10' => $gallery->i18n('9 times'),
		'12' => $gallery->i18n('11 times'),
		'15' => $gallery->i18n('14 times'),
		'21' => $gallery->i18n('20 times'))),
	'useDefaults' => array(
	    'description' => $gallery->i18n('Use default settings'),
	    'type' => 'boolean',
	    'default' => 'true',
	    'overrides' => array('showHeading', 'showTitle', 'showDate',
				 'showViews', 'showOwner')),

Then in imageblock\templates\blocks\ImageBlock.tpl change the code (at the top) looking like

{g->callback type="imageblock.LoadImageBlock"
	     blocks=$blocks|default:null maxSize=$maxSize|default:null
	     repeatBlock=$repeatBlock|default:null
	     itemId=$itemId|default:null linkTarget=$linkTarget|default:null
	     useDefaults=$useDefaults|default:true
	     showHeading=$showHeading|default:true
	     showTitle=$showTitle|default:true showDate=$showDate|default:true
	     showViews=$showViews|default:false showOwner=$showOwner|default:false}

In such a way that it includes "repeatBlock=$repeatBlock|default:null" (like in the code shown)

The last step is to change imageblock\classes\ImageBlockHelper.class so that it will repeat the block if needed. To do this you need to add the code below to the function loadImageBlocks

    function loadImageBlocks(&$template, $params) {
	global $gallery;
	list ($ret, $moduleParams) =
	    GalleryCoreApi::fetchAllPluginParameters('module', 'imageblock');
	if ($ret->isError()) {
	    return $ret->wrap(__FILE__, __LINE__);
	}
	if (!isset($params['blocks'])) {
	    $params['blocks'] = 'randomImage';
	}
	if (is_numeric($params['repeatBlock']) && (intval($params['repeatBlock']) > 1)) {
		$blocksSeparator = '';
		$newBlocks = '';
		for ($i = 0 ; $i < intval($params['repeatBlock']) ; $i++ ) {
			$newBlocks .= $blocksSeparator . $params['blocks'];
			$blocksSeparator = '|';
		}
		$params['blocks'] = $newBlocks;
	}

(there is more code in the function, but I didn't change that.)

When you have done all this you will get an extra option for the imageblacks once added to a page asking you hopw many times you want to have an imageblock repeated (it defaults to 1). And you can use CSS to help you out further to put the blocks next to eachother and stuff...

I am sure that my code can be optimized or changed to fit each specific wish but this is a start. So what do you think of it????
______________________
I made a theme for G2, try it :)

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Tue, 2006-03-14 05:33

Looks neat! Submit a patch to http://sf.net/projects/gallery and someone might be able to give a more indepth review and eventually get it into Gallery.

--
http://ckdake.com/

If you found my help useful, please consider donating to Gallery.

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Tue, 2006-03-14 05:34

Oh yeah, it would be neat if the # of times to repeat was a text field and not hard coded in.

--
http://ckdake.com/

If you found my help useful, please consider donating to Gallery.

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Sun, 2006-03-19 22:23
ckdake wrote:
Oh yeah, it would be neat if the # of times to repeat was a text field and not hard coded in.

Would be neat, but to be honest I didn't know how to do that and didn't see an example in other gallery modules, nor in the gallery core code that handles this (perhaps I looked at the wrong place; I was not really that awake when I did this :P)

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Mon, 2006-03-20 03:31

It would just be storing something in a text area and getting it back out of the database. There's probably a lot of examples of that. User quotas perhaps?

--
http://ckdake.com/

If you found my help useful, please consider donating to Gallery.

 
bkandor

Joined: 2006-03-07
Posts: 17
Posted: Fri, 2006-03-24 02:42

Hi,

This is just what I was looking for, but, I applied the changes as shown and now when I go to my domain instead of seeing my drupal homepage, I see the imageblockhelper.class file displayed in the browser instead of my drupal homepage. It's just simply listed as a text file - very strange.

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Sat, 2006-03-25 03:22

bkandor: URL?

you really should post your own thread for support.

--
http://ckdake.com/

If you found my help useful, please consider donating to Gallery.

 
bkandor

Joined: 2006-03-07
Posts: 17
Posted: Mon, 2006-03-27 17:18

Ok, but I had to undo the change immeidiately as I actually couldn't access my drupal homepage anymore - instead I just saw text output of the .class file as mentioned. I triple checked that I had made the edits properly as well.

Thanks,

Kandor

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Fri, 2006-04-14 09:18

I at the moment have noserver installation avaiable to do any work on this feature. But could perhaps anyone tell my if it still works with Gallery 2.1? 

I got a private message with the question how you can put the boxes of the images displayed next to eachother instead of underneath eachother. I couldn't test to see if I got the right code that will work everywhere, but here it is if anyone is interested:

#gsContent .block-imageblock-ImageBlock .one-image a,
#gsContent .block-imageblock-ImageBlock .one-image p,
#gsContent .block-imageblock-ImageBlock .one-image h4, {
    margin-left: 6px;
}

#gsContent .block-imageblock-ImageBlock {
    /* Use whatever image you need */
    background: url(images/tienHeader_bg.gif) top repeat-x;
}

#gsContent .one-image {
    float: left;
    width: 207px;
    padding-bottom: 6px;
}

#gsContent .one-image-block-3 {
    width: 207px;
}

/* I removed the title for up to 12 images, but can be as many or little as you want */
#gsContent .one-image-block-2 h3 span,
#gsContent .one-image-block-3 h3 span,
#gsContent .one-image-block-4 h3 span,
#gsContent .one-image-block-5 h3 span,
#gsContent .one-image-block-6 h3 span,
#gsContent .one-image-block-7 h3 span,
#gsContent .one-image-block-8 h3 span,
#gsContent .one-image-block-9 h3 span,
#gsContent .one-image-block-10 h3 span,
#gsContent .one-image-block-11 h3 span,
#gsContent .one-image-block-12 h3 span {
    display: none;
}

One note though: I think after I posted the code in the topicstart I made some changes so that each image got added an extra classname like "one-image-block-2" so that I could remove the header. You might need to figure out how I did that ;) I think it was something like this in /templates/imageBlock.tpl:

{assign var="blockCount" value=0}
{foreach from=$ImageBlockData.blocks item=block}
{assign var="blockCount" value="`$blockCount+1`"}
<div class="one-image one-image-block-{$blockCount}">
  {if !empty($block.title)}
    <h3><span>{g->text text=$block.title}</span></h3>

______________________
I made a theme for G2, try it :)

 
Radianation
Radianation's picture

Joined: 2005-11-14
Posts: 14
Posted: Sat, 2006-05-13 03:01

Didn't do anything different for me?

 
qwenc
qwenc's picture

Joined: 2006-01-02
Posts: 7
Posted: Sat, 2006-05-13 03:37

Radianation, I have been trying to install this mod as well. I added the code listed abve and it worked as far as giving me several addidtional new images but I am still having problems formating the layout. Where did you place the formating code? maybe you will save me a few minutes of heartburn. I am stillworking on the problem and will post any results I find... thanks for any help you can offer.

Quinton

Gallery version = 2.0.4 core 1.0.0.4
PHP version = 4.4.2 cgi
Webserver = Apache/1.3.33 (Unix)
Database = mysql 4.0.25-standard-log
Toolkits = Gd, NetPBM, ArchiveUpload
Operating system = Linux Hosted by 1and1

 
Radianation
Radianation's picture

Joined: 2005-11-14
Posts: 14
Posted: Sun, 2006-05-14 06:28

Yeah, good question. I'm new to modding Gallery2. I just followed the steps above and I notice nothing different. I'm using the matrix template.

 
Neonai

Joined: 2006-06-09
Posts: 1
Posted: Fri, 2006-06-09 06:27

RwD, In advance excuse for my English. Probably given updating does not work in version 2,1,1. Or my English is not so good what to understand this simple instruction :) or, as a variant, the instruction not full enough ;)

After the made changes in files of gallery, in an administrative part there was an opportunity to change quantity, but at change nothing occurs. The image as was one so one and remains :(

Gallery version = 2.1.1 core 1.1.0.1
PHP version = 5.1.4 apache
Webserver = Apache/1.3.34 (Win32) PHP/5.1.4
Database = mysql 4.1.18-nt, lock.system=database
Toolkits = Exif, ArchiveUpload, NetPBM, Thumbnail
Acel = full/3600, none/900
Operating system = Windows NT PRIME-RDM-NET 5.0 build 2195
Theme = classic
Local = ru_RU
Browser = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MRA 4.6 (build 01425))

 
ojay
ojay's picture

Joined: 2006-06-02
Posts: 11
Posted: Wed, 2006-07-26 23:46

Hi,

is it possible to view the images of imageblock horizontal??

thx for your help!

ojay

 
ronwaste

Joined: 2006-08-20
Posts: 10
Posted: Tue, 2006-08-22 22:29

Same Questen here i need the block horizontal :)

 
denniskarpes

Joined: 2006-07-06
Posts: 3
Posted: Mon, 2006-09-04 10:34

Hi tnx for this feature, It works great. Only I don't want to let the ImageBlock repeating the Block Title. This is beacuse it's in a "foreach" statement.

Is there somebody who knows how to display the ImageBlock.Title only once? Or is there an other variable wich can display the ImageBlock.Title?

Gallery version = 2.1.1 core 1.1.0.1

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2006-09-21 18:30

code based on this idea now in svn, thanks RwD!
I also resolved the heading issue mentioned just above^ now you'll get a single plural heading when multiple are used (eg. Random Images).

 
skidpics

Joined: 2007-11-06
Posts: 43
Posted: Tue, 2007-11-06 15:02

Any reply yet on the Horizontal fix for this?

I need random, recent images on my site, but with one column - the whole image block defeats the purpose unless you just need it for the sidebar...

-- Skidpics