Entry Object

From Dreamwidth Notes
Revision as of 16:59, 6 August 2009 by Yvi (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


The two main objects the Dreamwidth source code uses are Entry and User. The Entry object stores information about a Dreamwidth post. It's definition resides in cgi-bin/LJ/Entry.pm and if you want to create a new object of this type you need to do so by calling LJ::Entry. I will summarize some of the important methods and attributes here.

Creating an Entry object

Function: new

LJ::Entry->new($u, jitemid => $jitemid)

will return an Entry object. So will

LJ::Entry->new($u, ditemid => $ditemid)

provided that $u is the User object of the user this entry belongs to (in the case of communities, this is the community, not the poster) and $jitemid or $ditemid is the ID of an existing entry.

Please note that this can also create a 'zombie-entry' if the ID does not actually exist , so you need to make sure it is the correct one.

Function: new_from_url

Sometimes it is useful to just construct a new Entry object from the URL of the entry. This can be done by calling

LJ::Entry->new($uri)

where $uri is the URL of the entry.

Entry object functions

For the purpose of this section, $entry will always be our Entry object.

Function: ditemid

$entry->ditemid

returns the ditemid of that entry.

Function: jitemid

$entry->jitemid

returns the jitemid of that entry.

Function: user/userid

$entry->user

returns the User object of the account this entry was posted in, which is not necessarily the User object of the account this entry was posted by. For communities, the community's User object is returned.

$entry->userid

just returns the user ID of that user.

Function: poster/posterid

$entry->poster

returns the User object of the account this entry was posted by, which is not necessarily the User object of the account this entry was posted in.

$entry->posterid

just returns the user ID of that user.

Function: reply_url

$entry->reply_url

returns the correct ?mode=reply URL of your entry.

Function: security

$entry->security

returns the security level of the entry as a string. This can be 'public', 'private', or 'usemask', which is members-only/access-locked in some way.

Function: url

$entry->url

returns the permalink (the one without any arguments) to the entry.

However, it can also be passed arguments. The most-often used are:

$entry->url(mode => 'reply')

which returns the link to the ?mode=reply page, just as

$entry->reply_url

does; and

$entry->url( anchor => "comments" )

which returns the link to the #comments anchor.

Function: valid

As it is possible to construct 'zombie-entries' with invalid item IDs, you can check whether an entry actually exists using

$entry->valid

which will return either 1 or 0.