Custom Module

nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Wed, 2005-08-31 05:35

edit:Here are some of my experiences in creating my module, hopefully you will find some of the information here useful.

Currently I am trying to use gallery2 to make a gallery for serving my content in a custom manner.

Looking though the code i have added a few hacks to the core module to do some of the things I require
eg:-

    -renaming files on upload
    -processing gallery items before download

Now I have come to a halt in my development, this is what I want to do:-

    1. Have certain meta data associated with a file depending on the mime type or extension of a file (like custom fields but only for certain mime/extension).

    2. Have gallery items that do not have any file, i.e. just meta data (e.g. just a url)

    3. Be able to edit these values on a per item basis, similare to the edit photo panel.

    4. These items would display in a custom way, be edited in a custom way and downloaded in a custom way aswell.

    5. I would also like to create a sub album when a jpg file is uploaded of the same name. (eg upload "123.jpg" would createa an album called "123_files" in the album the jpg is in.)

Through reading these forums and documentation I feel that what I will need is a module and some derived types. Any recommendations on where to start would be greatly appreciated (tutorials, examples etc), also some pointers on what type would be what i would want to derive from.

I do have some php experience but a lot of the workings in gallery2 seem very foreign to me.

Thanks in advance :D[/]

[/]

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Wed, 2005-08-31 23:19

What you're proposing could solve somthing for me too. I'm looking for a better way of integrating audio files, so that a meta-data playlist file is created when an audio file is uploaded.

So for example:
1. I upload test.wma
2. Gallery puts test.wma in the filesystem, but also creates test.wax from a template, and stores this in the database in the same way as a thumbnail.
3. Then the user has the option to 'click here to download' or 'click here to play this audio now'

Will this kind of scenarios be included in your plans or are you mainly aiming at images?

I'll help if I can, but I think I'm more of a newbie than you, as I'm still on the basics of PHP, and have only found G2 a couple of days ago!

Thanks
Steve

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Fri, 2005-09-02 00:48

Ok, so I have started on this, I have extended a GalleryItem, should probably be a GalleryPhotoItem for the jpg's.
I can't seem to work out how to make all the jpgs in the gallery become one of my items rather than a normal photo item? Actually there is a lot I can't work out but this would get me headed in the right direction I would imagine

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Mon, 2005-09-05 06:35

created a MyImage class as follows:-

class MyImage_core extends GalleryPhotoItem

this has 3 extra fields, an int and 2 bools.
I have generated the database and inc files using gmake all in the classes directory, all seems to be ok here.

But, I still dont know how to make all jpg's in the gallery an instance of this item.

Any help would be greatly appreciated.

Thanks again.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-09-05 19:14

you need a row in your table for every id in g2_PhotoItem that is a jpg (check mime type in g2_DataItem).. then you can change g_entityType in g2_Entity to MyImage for all those entities.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-09-05 19:16

oh, and to make newly uploaded jpgs use your type I think you need to register your class with the factory.. see performFactoryRegistrations in modules/core/CoreModuleExtras.inc where it registers GalleryPhotoItem for image/*.. register your for image/jpeg

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Tue, 2005-09-06 02:44

Looking in CoreModuleExtras.inc i think i have extracted the right calls

//MyModule/module.inc
function performFactoryRegistrations()
{
	$myMimeArray = array('image/jpeg', 'image/jpg');

	$ret = GalleryCoreApi::registerFactoryImplementation(
		'GalleryPhotoItem', 'MyPhotoItem', 'MyPhotoItem',
		'modules/MyModule/classes/MyPhotoItem.class', 'MyModule', $myMimeArray);

	if ($ret->isError())
	{
		return $ret->wrap(__FILE__, __LINE__);
	}
}

Does this go in my module.inc? That where i have it now but I don't seem to get any of my items

I have uploaded a jpg to the server but i do not seem to get my custom view

//MyModule/Classes/MyPhotoItem.class
function render($format, $params)
{
	global $gallery;

	switch($format)
	{
	case 'HTML':
		return "<H1>Hello, World!</H1>";
	default:
		return "<H1>Goodbye, World!</H1>";
	}
}

Do I need to unregisterFactoryImplementations or should mine overwrite the existing one?

I am not going to worry about

mindless wrote:
you need a row in your table for every id in g2_PhotoItem that is a jpg (check mime type in g2_DataItem).. then you can change g_entityType in g2_Entity to MyImage for all those entities

as my database does not contain much except development test things atm.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Tue, 2005-09-06 02:49

Oh yeah and this is what is in my Debug tree

7: (galleryalbumitem)   [browse] 
	28: (galleryalbumitem)   [browse] 
		363: (galleryalbumitem)   [browse] 
			411: (galleryphotoitem)   [browse] id  411  
				creationTimestamp  1125974364  
				isLinkable  1  
				linkId   
				modificationTimestamp  1125974365  
				serialNumber  1  
				entityType  GalleryPhotoItem  
				onLoadHandlers   
				parentId  363  
				pathComponent  1125974364081874300.JPG  
				canContainChildren  0  
				description  Broken  
				keywords  Broken  
				ownerId  6  
				summary  Broken  
				title  broken  
				viewedSinceTimestamp  1125974364  
				originationTimestamp  1125974364  
				mimeType  image/jpeg  
				size  11906  
				width  378  
				height  170

Thanks again for your help mindless, hopefully with a little help from you I will be able to make the gallery and site live by next week.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2005-09-06 03:04

add performFactoryRegistrations to setCallbacks for your module and bump the module version.. see other module.inc files for examples. just image/jpeg will do.. jpg and jpeg and jpe extension all use that. image/jpg isn't a mime type in G2..

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Tue, 2005-09-06 04:17

No result with that, the debug tree looks the same and displays normally aswell...this is what i did, the comments in the code section explain the changes.

//changed image/jpg to image/pjpeg
$myMimeArray = array('image/jpeg', 'image/pjpeg');

is actually what i was aiming for, don't know what i did there.

function MyModule()
{
	global $gallery;
	$this->setId('MyModule');
	$this->setName('MyModule');
	$this->setDescription($gallery->i18n('My module.'));
	//changed from 0.9.0
	$this->setVersion('0.9.1');
	$this->setGroup('test', $this->translate('Test'));
	//added performFactoryRegistrations
	$this->setCallbacks('getSiteAdminViews|performFactoryRegistrations');
	$this->setRequiredCoreApi(array(6, 0));
	$this->setRequiredModuleApi(array(2, 0));
}

Is the render() function what i should be using to see my results aswell?

Also, do i need to fill out some entity type in the MyPhotoItem class (perhaps in the create function)?

Looking at the embedded audio play example by stephen I don't see any major differences except that he has registered his class in CoreModuleExtras.inc

	$regs[] = array('GalleryEntity', 'GalleryAudioItem', 'class', array('audio/mpeg', 'audio/x-ms-wma', 'audio/x-pn-realaudio'));

I don't think that this would be necessary, wouldn't this defeat the purpose of a module?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2005-09-06 23:53

correct, you should definitely register the class in your module, not in core.

oops, I should have looked at the code before my last reply.. performFactoryRegistrations is always called.. didn't need that in the setCallbacks list.

the first param to registerFactoryImplementation should be 'GalleryItem' not 'GalleryPhotoItem'. G2 looks for a GalleryItem implementation that supports the mime type of the uploaded file.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Mon, 2005-09-12 03:37

Thanks for all your help, a couple of questions about locking when using get and set members.

1. Do I need to lock and unlock to use the get methods?

2. Is this how I should be using the locking mechanism?

list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($itemID);

$item->setA(true);
$item->setB(false);
$item->setC(200);
$item->save()

$ret = GalleryCoreApi::releaseLocks($lockId);
 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-09-12 04:41

1. no.. you only need to lock if you're going to save changes.
2. the if ($ret->isError()) checks are missing, and save() returns an error status.. but basically, yes.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Tue, 2005-09-13 04:13

Cheers for that... I had taken all the ret->isError stuff for the post, that's why $item->save ended up without the semi-colon.

I thought I had it all working but now I have another question about using the inc & tpl system in gallery2. How did I accept

//this doesn't look right to me, half of my text has been hidden or something.
//all good fixed it by using & gt ; and & lt ;
<input type="file" size="60" name="{g->formVar var="form[action][pngFile]"}">

I have tried a couple of things in my code

function handleRequest($form, &$item, &$preferred)
{
	if (isset($form['action']['save']))
	{
		$pngName = $form['action']['pngFile'];
		//$pngName = $form['action']['pngFile']['tmp_name'];
	}
}

any hint or pointer to some code that does this would be very helpful, not only do I want the tmp_name I would also like the name size and other fields usually found in the $_FILES variable

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2005-09-13 06:06

there are several examples.. how about modules/thumbnail/CustomThumbnailOption.inc, handleRequestAfterEdit.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Tue, 2005-09-13 08:01

Cheers, just what i was looking for

/* Set the form's encoding type since we're uploading binary files */
if ($template->hasVariable('ItemAdmin'))
{
	$ItemAdmin =& $template->getVariableByReference('ItemAdmin');
	$ItemAdmin['enctype'] = 'multipart/form-data';
}
else
{
	$ItemAdmin = array('enctype' => 'multipart/form-data');
	$template->setVariable('ItemAdmin', $ItemAdmin);
}
 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Wed, 2005-09-14 07:36

This is how the download works at the moment.

//photo.tpl
<a href="{g->url arg1="view=core.DownloadItem" arg2="itemId=`$theme.item.id`"}">

I want to be able to call my own download in MyModule, I think that I need to do something in the module.inc either with performFactoryRegistrations or something similar.

//modules/MyModule/MyPhoto.tpl
<a href="{g->url arg1="view=myModule.DownloadItem" arg2="itemId=`$theme.item.id`"}">

obviously something like this would required an assocaited file

$urlGenerator =& $gallery->getUrlGenerator();
$urlGenerator->generateUrl(array('view' => 'MyModule.DownloadItem',
	'itemId' => $item->getId(),
	'serialNumber' => $item->getSerialNumber()));

but this is in the photo.tpl which is in the core...

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2005-09-15 03:52

i don't really understand what you're asking now.. yes, you can use mymodule.DownloadItem in g->url or generateUrl() if you have a DownloadItem.inc in your modules/mymodule dir that defines class DownloadItemView. nothing needs to be registered.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Fri, 2005-09-16 00:21
Quote:
i don't really understand what you're asking now.. yes, you can use mymodule.DownloadItem in g->url or generateUrl() if you have a DownloadItem.inc in your modules/mymodule dir that defines class DownloadItemView. nothing needs to be registered.

So what you are saying is that I just put a DownloadItem.inc in my MyModule directory that contains something like

class MyDownloadItem extends DownloadItemView
{
	...
}

and gallery2 will pick this up?

What files would i find this DownloadItemView interface in?
/modules/core/classes/GalleryView.class

do i need to anything in module.inc?

Is there anywhere I can find a list of these classes perhaps with a description of what they are for?
http://dev.gallery2.org/modules/GalleryAPI/apidoc/GalleryCore/Classes/GalleryView.html

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-09-16 04:01

i was thinking DownloadItemView extends GalleryView.. but i suppose you could extend DownloadItemView if you rename your view (DownloadItemView can't extend DownloadItemView), and you need some functionality of core.DownloadItem.
correct, you don't need anything in module.inc to define a view.. if you make a link to mymodule.something it looks for something.inc in modules/mymodule and that file should define somethingView.
browsing through core/classes (esp GalleryCoreApi.class) and looking at the apidoc is the best reference.. there's bits of other info on codex.gallery2.org.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Fri, 2005-09-16 05:04

the thing is in the matrix theme there are calls to core.ShowItem and core.DownloadItem which I would like to call class, templates etc in MyModule rather than in the core.

I have made a DownloadItem.inc in modules/MyModule but it seems from what you are saying is that this will only get called if referenced by

<a href="{g->url arg1="view=myModule.DownloadItem" arg2="itemId=`$theme.item.id`"}">

ideally I would like this to be called by

<a href="{g->url arg1="view=core.DownloadItem" arg2="itemId=`$theme.item.id`"}">

which appears all throughout the photo.tpl in the matrix theme.

Is there anyway I can override core.DownloadItem for a certain file type such as MyPhotoItem.class?

BTW there seems to be issues when posting html in a code block...

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-09-16 18:08

sorry, i really have no idea what you're trying to do.
you could write an urlgenerator that changes core.Download/ShowItem to your module, but currently you can only use 1 url generator, so they you couldn't use rewrite. you can always hack core code instead if you like, but that makes upgrades hard.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Mon, 2005-09-19 01:20

ok, i justed edited the tpl files in the theme, seems to work ok, not as clean as I would like but if you can't change it via the module, i guess this will do.

On another note, am I only allowed to register 1 galleryItem per module, I have 1 item that works correctly that extends the GalleryPhotoItem but I am now trying to add 2 more that extend the GalleryDataItem, these register fine (no errors on install or activate) but then when I try to view an album containing one of these items I get an error

Error (ERROR_MISSING_OBJECT) : My2ndItem
in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 2270 (gallerystatus::error) 
in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 329 (mysqldatabasestorage::_describeentitymembers) 
in modules/core/classes/GalleryStorage.class at line 118 (mysqldatabasestorage::loadentities) 
in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 82 (gallerystorage::loadentities) 
in modules/core/classes/GalleryCoreApi.class at line 2173 (galleryentityhelper_simple::loadentitiesbyid) 
in modules/core/classes/GalleryTheme.class at line 1058 (gallerycoreapi::loadentitiesbyid) 
in modules/core/classes/GalleryTheme.class at line 870 (matrixtheme::loadcommontemplatedata) 
in modules/core/classes/GalleryView.class at line 285 (matrixtheme::loadtemplate) 
in main.php at line 286 (showitemview::doloadtemplate) 
in main.php at line 87
in main.php at line 80
System Information 
Gallery version  2.0-rc-2  
PHP version  4.3.11 apache  
Webserver  Apache/1.3.33 (Unix) PHP/4.3.11 mod_perl/1.29  
Database  mysql 3.23.56  
Toolkits  ImageMagick, Gd  
Operating system  FreeBSD administrator1.securesites.net 4.7-RELEASE-p28 FreeBSD 4.7-RELEASE-p28 #40: Fr i386  
Browser  Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; {EED8B589-CB1A-46E5-8B85-239267419BE4}; SV1; .NET CLR 1.1.4322)  

by the looks of this error my item isn't in the database or something similar.

Maybe this is my fault, I don't know if this is legal but basically what i did was create a new mime type for my item, 'application/My2ndItem'

//module.inc
	$ret = GalleryCoreApi::registerFactoryImplementation(
		'GalleryItem', 'My2ndItem', 'My2ndItem',
		'modules/Vista/classes/My2ndItem.class', 'MyModule', array('application/My2ndItem'));
	if ($ret->isError())
	{
		return $ret->wrap(__FILE__, __LINE__);
	}

and I create it from a 'ItemEditPlugin' page like this

//EditMyPhotoItem.inc
	list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($Name, basename($Name), "My2ndItem", "My2ndItem", "My2ndItem" . $Name, "application/My2ndItem", $item->getFilesAlbumID());
	if ($ret->isError())
	{
		GalleryCoreApi::releaseLocks($lockId);
		return array($ret->wrap(__FILE__, __LINE__), null);
	}

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-09-19 10:37

just a small note: module directory names should be lower case. vista and not Vista.
could you please use g 2.0, the databasestorage.class file changed since rc2 a little, or at least an error on line 2270 doesn't make sense in 2.0.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Tue, 2005-09-20 04:15
function _describeEntityMembers($entityName) {
global $gallery;

if (empty($this->_entityInfoCache[$entityName])) {
	if (class_exists($entityName)) {
	$entity = new $entityName();
	} else {
	list ($ret, $entity) =
		GalleryCoreApi::newFactoryInstance('GalleryEntity', $entityName);
	if ($ret->isError()) {
		return array($ret->wrap(__FILE__, __LINE__), null);
	}
	}
	if (!isset($entity)) {
	return array(GalleryStatus::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__,
2270>>						$entityName), null);
	}
	$this->_entityInfoCache[$entityName] = $entity->getPersistentMemberInfo();
}

Is it possible my database is corrupt? can I flush the entire database and rebuild it?

I'm know from some of my hacking around I may have broken it...

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Tue, 2005-09-20 06:02

Changed every modules/Vista/
to modules/vista/

This is with a fresh install of the gallery2 from cvs

Error Detail - 
Error (ERROR_MISSING_OBJECT) : My2ndItem
in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 2264 (gallerystatus::error) 
in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 329 (mysqldatabasestorage::_describeentitymembers) 
in modules/core/classes/GalleryStorage.class at line 118 (mysqldatabasestorage::loadentities) 
in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 82 (gallerystorage::loadentities) 
in modules/core/classes/GalleryCoreApi.class at line 2186 (galleryentityhelper_simple::loadentitiesbyid) 
in modules/core/classes/GalleryTheme.class at line 1058 (gallerycoreapi::loadentitiesbyid) 
in modules/core/classes/GalleryTheme.class at line 870 (matrixtheme::loadcommontemplatedata) 
in modules/core/classes/GalleryView.class at line 285 (matrixtheme::loadtemplate) 
in main.php at line 290 (showitemview::doloadtemplate) 
in main.php at line 87
in main.php at line 80
System Information 
Gallery version  2.0  
PHP version  4.3.11 apache  
Webserver  Apache/1.3.33 (Unix) PHP/4.3.11 mod_perl/1.29  
Database  mysql 3.23.56  
Toolkits  ImageMagick, Gd  
Operating system  FreeBSD administrator1.securesites.net 4.7-RELEASE-p28 FreeBSD 4.7-RELEASE-p28 #40: Fr i386  
Browser  Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; {EED8B589-CB1A-46E5-8B85-239267419BE4}; SV1; .NET CLR 1.1.4322)  
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 09:11

yep, now it's missing since you already registered it with performFactoryRegistraction. you need to uninstall (read: not just deactivate) the module and install it again.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Tue, 2005-09-20 09:24

I don't think it's missing, its in my database, I created a new object using addItemToAlbum.

I am now using a clean install and database, and have installed and activate my module.

My1stItem object creates an album called objectname_files and an object in that album of type My2ndItem

Looking at the database the only thing a can see that is missing is g2_AccessSubscriberMap entry for the g_id of the item in my database.

Is it possible that there is a problem with adding more than 1

GalleryCoreApi::registerFactoryImplementation('GalleryItem',...

or should I be adding all of my items in an array or something?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 09:41
Quote:
Is it possible that there is a problem with adding more than 1

i hope you have this registerFactoryImplementation only in your performFactoryRegistrations function and nowhere else. and no, you can register multiple implementations, but they have to differ somehow. registering the same class twice, does that make sense?

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Tue, 2005-09-20 23:54

Does the error make sense to you with the new line numbers?

This is im my performFactoryRegistrations and they are not called anywhere else, this also contain a couple of 'ItemEditPlugin' registrations


$ret = GalleryCoreApi::registerFactoryImplementation(
		'GalleryItem', 'My2ndItem', 'My2ndItem',
		'modules/mymodule/classes/My2ndItem.class', 'mymodule', array('application/my2nditem'));
	if ($ret->isError())
	{
		return $ret->wrap(__FILE__, __LINE__);
	}
		$ret = GalleryCoreApi::registerFactoryImplementation(
		'GalleryItem', 'My3rdItem', 'My3rdItem',
		'modules/mymodule/classes/My3rdItem.class', 'mymodule', array('application/my3rditem'));
	if ($ret->isError())
	{
		return $ret->wrap(__FILE__, __LINE__);
	}
		$myMimeArray = array('image/jpeg', 'image/pjpeg');
		$ret = GalleryCoreApi::registerFactoryImplementation(
		'GalleryItem', 'My1stItem', 'My1stItem',
		'modules/mymodule/classes/My1stItem.class', 'mymodule', $myMimeArray);
	if ($ret->isError())
	{
		return $ret->wrap(__FILE__, __LINE__);
	}

Looking in the database at g2_factoryMap i noticed items like GalleryMovieItem, GalleryPhotoItem, GalleryUnknownItem etc are listed twice once with a g_classType of GalleryEntity and once as a GalleryItem

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 00:01

in DatabaseStorage.class, please add var_dump($entityName); var_dump($entity); exit; right before

return array(GalleryStatus::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__,
$entityName), null);

right after if (!isset($entity)) {
on line 2263.
what do you get there.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Wed, 2005-09-21 00:12

string(10) "HVistaItem" NULL

HVista is the name of my class not My2ndItem but you get the idea, don't really want to post my actual code to give away anything

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 00:15

HVistaItem, did you ever register such a entity type? perhaps some time ago?

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Wed, 2005-09-21 00:17

I am working with a fresh install, i have registered my module once

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Wed, 2005-09-21 00:19
Quote:
Looking in the database at g2_factoryMap i noticed items like GalleryMovieItem, GalleryPhotoItem, GalleryUnknownItem etc are listed twice once with a g_classType of GalleryEntity and once as a GalleryItem

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 00:22

read the modules/core/CoreModuleExtras.inc function performFactoryImplementations as an example.
it's 2.23h AM here, i'm off, and for chats, we have irf.freenode.net #gallery

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Wed, 2005-09-21 01:02
$ret = GalleryCoreApi::registerFactoryImplementation('GalleryItem', 'My3rdItem', 'My3rdItem',
	'modules/mymodule/classes/My3rdItem.class', 'mymodule', array('application/my3rditem'));
if ($ret->isError())
{
	return $ret->wrap(__FILE__, __LINE__);
}

GalleryItem needs to have a corresponding GalleryEntity.
I don't know why it worked for my original item but once I had more than one GalleryItem it was causing problems

$ret = GalleryCoreApi::registerFactoryImplementation('GalleryEntity', 'My3rdItem', 'My3rdItem',
	'modules/mymodule/classes/My3rdItem.class', 'mymodule', null);
if ($ret->isError())
{
	return $ret->wrap(__FILE__, __LINE__);
}
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 10:04

yep, makes sense.
when you add an item to g2 by upload, ite uses
GalleryCoreApi::newItemByMimeType($mimeType);
which uses GalleryCoreApi::newFactoryInstanceByHint('GalleryItem',
array($mimeType, substr($mimeType, 0, strpos($mimeType, '/')) . '/*'));

so that's why you need to register a GalleryItem. item -> data type / mime type

and when showing a page with this item, it uses GalleryCoreApi::loadEntitiesById() and as the name says, it loads an entity.
in the databasestorage.class, it does newFactoryInstance('GalleryEntity', $entityName);
which is why you need it to register as entity too. entity -> entity name

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Thu, 2005-09-22 01:12

when I add an item to an album using

	list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($FileName, basename($FileName), "test", $FileName, "test - " . $FileName , "application/my2nditem", $item->getFilesAlbumID());

the file is not directly copied to the album folder, it also has the . in the filename changed to an underscore_

$item->fetchPath();

will have to do for now but its really annoying losing the extension esp on download
Is there any way to stop this?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-22 09:36

hmm, don't know why it does that. maybe it doesn't detect the extension?
why do you use your own GalleryCoreApi::addItemToAlbum call and don't try it with the add item methods?
or is this in a unit test of yours?

@ g2 naming conventions / coding guidelines:
variable and function names are in camelCase. so the first letter of a function or variable is always lower-case, $fileName and not $FileName.
abbreviations and acronyms are treated like a normal word, it's getFilesAlbumId and not getFilesAlbumID, it's getRssFeed and not getRSSFeed. etc.
class names are the same, just with the difference that they start with a capital letter.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Fri, 2005-09-23 04:35
valiant wrote:
hmm, don't know why it does that. maybe it doesn't detect the extension?
why do you use your own GalleryCoreApi::addItemToAlbum call and don't try it with the add item methods?
or is this in a unit test of yours?

This is a standard API call and it does exactly what i want.
What I do is have an uploaded item that has an ItemEditPlugin, I generate another file of my own type using the $platform->fopen fwrite, fseek, fclose etc, then I add this file to an album associated with the uploaded jpg.

valiant wrote:
@ g2 naming conventions / coding guidelines:
variable and function names are in camelCase. so the first letter of a function or variable is always lower-case, $fileName and not $FileName.
abbreviations and acronyms are treated like a normal word, it's getFilesAlbumId and not getFilesAlbumID, it's getRssFeed and not getRSSFeed. etc.
class names are the same, just with the difference that they start with a capital letter.

to tell you the truth thats not my actual variable name, but i'll keep that in mind. I'm suprised you didn't have a go at the { brace being on its own line aswell. I guess it's just my preffered style ;).

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-09-23 12:35

weird things you do there :) why do you need fseek? you kept your questions very general, what are you actually doing? :)

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Mon, 2005-09-26 00:43

i need fseek because the fwrite functions in PHP do not behave the same way as they do in C, in PHP the write will end after the length of a string in a variable while in C you can specify a number of bytes to write. Perhaps there is another version of the fwrite that does this but my way works ok anyway...

Something along these lines

	$platform->fwrite($fileHandle, $varOne, 255);
	$Pos += 255;
	$platform->fseek($fileHandle, intval($Pos),SEEK_SET);

	$platform->fwrite($fileHandle, $varTwo, 255);
	$Pos += 255;
	$platform->fseek($fileHandle, intval($Pos),SEEK_SET);

	settype($varThree, "int");
	$platform->fwrite($fileHandle, pack("S",$varThree), 2);
	$Pos += 2;
	$platform->fseek($fileHandle, intval($Pos),SEEK_SET);

Can't really tell you what I'm doing exactly but the basics are that you can upload files in one format and download them in another...

Don't worry I'll post the link when the site goes live...

here's the start http://www.360desktop.com