Difference between revisions of "Entry Object"
(some more functions added) |
(it's/its :)) |
||
Line 1: | Line 1: | ||
[[Category: Development]] | [[Category: Development]] | ||
− | The two main objects the Dreamwidth source code uses are Entry and User. The Entry object stores information about a Dreamwidth post. | + | The two main objects the Dreamwidth source code uses are Entry and User. The Entry object stores information about a Dreamwidth post. Its 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= | =Creating an Entry object= |
Latest revision as of 19:34, 6 August 2009
The two main objects the Dreamwidth source code uses are Entry and User. The Entry object stores information about a Dreamwidth post. Its 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, including custom access filters.
Function: subject_html
$entry->subject_html
returns the entry's subject as a string with HTML tags.
Function: subject_text
$entry->subject_html
returns the entry's subject as a plain-text string.
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: userpic
$entry->userpic
returns a LJ::Userpic object for this post, or undef if it was posted without an icon selected.
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.
Function: visible_to
If you want to check whether an entry is visible to a user $remote, where $remote is an User object, you can do this with
$entry->visible_to($remote)
which will return either 1 or 0.
Deleting an Entry Object
If you want to delete an entry, you can do this by calling
LJ::Entry->delete_entry($u, $jitemid)
This can only be done using the jitemid of the entry, not with the ditemid. The function return 1 if it succeeded, else it returns 0.