[ImageBlock] New feature: Repeat blocks setting.
RwD
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:
'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???? |
|
Posts: 2258
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.
Posts: 2258
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.
Posts: 383
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)
Posts: 2258
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.
Posts: 17
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.
Posts: 2258
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.
Posts: 17
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
Posts: 383
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:
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:
______________________
I made a theme for G2, try it
Posts: 14
Didn't do anything different for me?
Posts: 7
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
Posts: 14
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.
Posts: 1
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))
Posts: 11
Hi,
is it possible to view the images of imageblock horizontal??
thx for your help!
ojay
Posts: 10
Same Questen here i need the block horizontal
Posts: 3
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
Posts: 8601
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).
Posts: 43
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