Blog

The “master” class which represents a weblog.  Nearly all functions are performed through this object.  This is the object that handles user security.

Inherits

LnBlogObject

Events

OnInitFired when a blog object is created.
InitCompleteFired after the constructor has run.
OnInsertRun when a new blog is about to be created.
InsertCompleteRun after a new blog object has been saved.
OnUpdateRun when a blog is about to be updated.
UpdateCompleteRun after a blog is successfully updated.
OnDeleteRun before a blog is deleted.
DeleteCompleteRun after a blog is deleted.
OnUpgradeRun before the wrapper upgrade process.
UpgradeCompleteRun when the wrapper upgrade is finished.
OnEntryPreviewRun before populating entry template for preview.
OnArticlePreviewFired before populating article template for preview.
OnEntryErrorFired before populating template when on an error.
OnArticelErrorFired before populating template when on an error.
Summary
BlogThe “master” class which represents a weblog.
Constants
ROOT_IDDefines the magic string that denotes a blog on the server’s document root.
RSS compatibility methods
Functions
isBlogDetermines whether the object represents an existing blog.
writersSet and return the list of users who can add posts to the blog.
readBlogDataRead and write a simple text file with the blog metadata.
writeBlogDataSave the blog data to disk.
getDateRangeGet all blog entries posted between a given range of dates.
getDayGet all the blog entries for a particular day.
getDayCountGet the number of posts made on a given day.
getMonthGet a list of all entries for the specified month.
getMonthCountGet the number of entries in the given month.
getYearLike getMonth, except gets entries for an entire year.
getYearListGet a list of all years in the archive, sorted in reverse chronological order.
getMonthListGet a list of the months for the given year.
getRecentMonthListGet a list of recent months, starting from the current month and going backward.
getURLGet the URL for the blog homepage.
uriGet the URI of the designated resource.
getRecentGet the most recent entries across all months and years.
getNextMaxConvenience function to get “previous entries”.
getEntriesScan entries in reverse chronological order, starting at a given offset, and get a given number of them.
getEntriesByTagGet a list of entries tagged with a given string.
getDraftsGets all the current drafts for this blog.
getArticlesReturns a list of all articles, in no particular order.
getArticleListGet a list of articles with title and permalink.
getEntryRepliesGets all the replies for all entries belonging to this blog, including all comments, trackbacks, and pingbacks.
getEntryCommentsLike getEntryReplies, but only returns BlogComments.
getEntryTrackbacksLike getEntryReplies, but only returns Trackbacks.
getEntryPingbacksLike getEntryReplies, but only returns Pingbacks.
getArticleRepliesLike getEntryReplies, but returns the replies for all Articles, instead of for all BlogEntries.
getArticleCommentsLike getArticleReplies, but only returns BlogComments.
getArticleTrackbacksLike getArticleReplies, but only returns Trackbacks.
getArticleArticlePingbacksLike getArticleReplies, but only returns Pingbacks.
getRepliesLike getEntryReplies and getArticleReplies, but combines both, returning an array of all replies for this blog.
getCommentsLike getReplies, but only for comments.
getTrackbacksLike getReplies, but only for comments.
getPingbacksLike getReplies, but only for comments.
exportVarsExport blog variables to a PHPTemplate class.
getWeblogGets the markup to display for the front page of a weblog.
upgradeWrappersThis is an upgrade function that will create new config and wrapper scripts to upgrade a directory of blog data to the current version.
fixDirectoryPermissionsA quick utility function to fix the borked permissions from not setting the correct umask when creating directories.
insertCreates a new weblog.
updateModify an existing weblog.
deleteRemoves an existing weblog.
updateTagListAdds any new tags to the list of tags used in the current blog.

Constants

ROOT_ID

Defines the magic string that denotes a blog on the server’s document root.  Normally, LnBlog uses the document root-relative path to the blog as the blog identifier, but this is the empty string for the document root.  Therefore, this constant sets a magic value to use.

RSS compatibility methods

Summary
Functions
isBlogDetermines whether the object represents an existing blog.
writersSet and return the list of users who can add posts to the blog.
readBlogDataRead and write a simple text file with the blog metadata.
writeBlogDataSave the blog data to disk.
getDateRangeGet all blog entries posted between a given range of dates.
getDayGet all the blog entries for a particular day.
getDayCountGet the number of posts made on a given day.
getMonthGet a list of all entries for the specified month.
getMonthCountGet the number of entries in the given month.
getYearLike getMonth, except gets entries for an entire year.
getYearListGet a list of all years in the archive, sorted in reverse chronological order.
getMonthListGet a list of the months for the given year.
getRecentMonthListGet a list of recent months, starting from the current month and going backward.
getURLGet the URL for the blog homepage.
uriGet the URI of the designated resource.
getRecentGet the most recent entries across all months and years.
getNextMaxConvenience function to get “previous entries”.
getEntriesScan entries in reverse chronological order, starting at a given offset, and get a given number of them.
getEntriesByTagGet a list of entries tagged with a given string.
getDraftsGets all the current drafts for this blog.
getArticlesReturns a list of all articles, in no particular order.
getArticleListGet a list of articles with title and permalink.
getEntryRepliesGets all the replies for all entries belonging to this blog, including all comments, trackbacks, and pingbacks.
getEntryCommentsLike getEntryReplies, but only returns BlogComments.
getEntryTrackbacksLike getEntryReplies, but only returns Trackbacks.
getEntryPingbacksLike getEntryReplies, but only returns Pingbacks.
getArticleRepliesLike getEntryReplies, but returns the replies for all Articles, instead of for all BlogEntries.
getArticleCommentsLike getArticleReplies, but only returns BlogComments.
getArticleTrackbacksLike getArticleReplies, but only returns Trackbacks.
getArticleArticlePingbacksLike getArticleReplies, but only returns Pingbacks.
getRepliesLike getEntryReplies and getArticleReplies, but combines both, returning an array of all replies for this blog.
getCommentsLike getReplies, but only for comments.
getTrackbacksLike getReplies, but only for comments.
getPingbacksLike getReplies, but only for comments.
exportVarsExport blog variables to a PHPTemplate class.
getWeblogGets the markup to display for the front page of a weblog.
upgradeWrappersThis is an upgrade function that will create new config and wrapper scripts to upgrade a directory of blog data to the current version.
fixDirectoryPermissionsA quick utility function to fix the borked permissions from not setting the correct umask when creating directories.
insertCreates a new weblog.
updateModify an existing weblog.
deleteRemoves an existing weblog.
updateTagListAdds any new tags to the list of tags used in the current blog.

Functions

isBlog

function isBlog($blog = false)

Determines whether the object represents an existing blog.

Returns

True if the blog metadata exists, false otherwise.

writers

function writers($list = false)

Set and return the list of users who can add posts to the blog.

Parameters

listan arrays or comma-delimited stringof user names.

Returns

An array of user names.

readBlogData

function readBlogData()

Read and write a simple text file with the blog metadata.  Format is key = data, each record is a single line, unrecognized keys are ignored.  This is for internal use only.

writeBlogData

function writeBlogData()

Save the blog data to disk.  This is for internal use only.

Returns

False on failure, something else on success.

getDateRange

function getDateRange($end_date,  
$start_date =  '')

Get all blog entries posted between a given range of dates.  Note that the range is inclusive.

Parameters

end_dateA string containing end date of the range in “yyyy-mm-dd” format.  This can also use “yyyy-mm” or “yyyy” format.
start_dateThe optional start date of the range.  If this is omitted, the the end date will be taken as the entirity of the range, whether it is a day, month, or year.

Returns

An array of BlogEntry objects.

getDay

function getDay($year,
$month,
$day)

Get all the blog entries for a particular day.

Parameters

yearThe year you want.
monthThe month you want.
dayThe day you want.

Returns

An array of BlogEntry objects posted on the given date, sorted in reverse chronological order by post time.

getDayCount

function getDayCount($year,
$month,
$day)

Get the number of posts made on a given day.

Parameters

yearThe 4 digit year of the post.
monthThe month of the post.
dayThe day of the post.

Retruns

An integer representing how many posts were made that day.

getMonth

function getMonth($year = false,
$month = false)

Get a list of all entries for the specified month.  If you do not specify a year and month, then the routine will try to get it from the current directory and/or URL.

Parameters

yearOptional year you want.
monthOptional month you want.

Returns

An array of BlogEntry objects posted in the given month, sorted in reverse chronological order by post date.

getMonthCount

function getMonthCount($year = false,
$month = false)

Get the number of entries in the given month.  If no month and year are given, try to get them from the current directory/URL.

Parameters

yearOptional year you want.
monthOptional month you want.

Returns

A non-negative integer representing the number of posts in that month.

getYear

function getYear($year = false)

Like getMonth, except gets entries for an entire year.

Parameters

yearOptional year to get.  If not given, the year will be auto-detected.

Returns

An array of BlogEntry objects posted in the given year, sorted in reverse chronological order by post date.

getYearList

function getYearList()

Get a list of all years in the archive, sorted in reverse chronological order.

Returns

A two-dimensional array.  The first dimension has numeric indexes.  The second has two elements, indexed as “year” and “link”, which hold the 4-digit year and a permalink to the archive of that year respectively.

getMonthList

function getMonthList($year = false)

Get a list of the months for the given year.  If no year is given, try to extract it from the current directory/URL.

Parameters

yearThe year you want.

Returns

A two-dimensional array.  The first dimension is numerically indexed, with elements sorted in reverse chronological order.  The second dimension has three elements, indexed as “year”, “month”, and “link”.  These hold, respectively, the year you specified, the 2-digit month, and a permalink to the archive for that month.

getRecentMonthList

function getRecentMonthList($nummonths = 12)

Get a list of recent months, starting from the current month and going backward.  This is essentially a wrapper around getMonthList.

Parameters

nummonthsOptional number of months to return.  The default is 12.  If set to zero or less, then all months will be retreived.

Returns

An array of the most recent months in the same format used by getMonthList.  The total length of the first dimension of the array should be nummonths long.

getURL

function getURL($full_uri = true)

Get the URL for the blog homepage.

Parameters

full_uriOptional boolean for whether or not to return a full URI or a root-relative one.  Default is true.

Returns

A string holding the URI to the blog root directory.

uri

function uri($type)

Get the URI of the designated resource.

Parameters

typeThe type of URI to get, e.g. permalink, edit link, etc.
data parametersAll other parameters after the first are interpreted as additional data for the URL query string.  The exact meaning of each parameter depends on the URL type.

Returns

A string with the permalink.

getRecent

function getRecent($num_entries = false)

Get the most recent entries across all months and years.

Parameters

num_entriesOptional number of entries to return.  The default is to use the <max_entries> property of the blog.  If -1 is passed, then all entries in the blog will be returned.

Returns

An array of BlogEntry objects.

getNextMax

function getNextMax($num_entries = false)

Convenience function to get “previous entries”.  Returns a list of entries starting after the the end of the blog’s <max_entires> property.

Parameters

num_entriesThe optional number or entries to return.  The default is to use the blog’s <max_entries> property.

Returns

An array of BlogEntry objects.

getEntries

function getEntries($number = -1,
$offset = 0)

Scan entries in reverse chronological order, starting at a given offset, and get a given number of them.

Parameters

numberOptional number of entries to return.  If set to a negative number, then returns all entries will be returned.  The default value is -1.
offsetOptional number of entries from the beginning of the list to skip.  The default is 0, i.e. start at the beginning.

Returns

An array of BlogEntry objects.

getEntriesByTag

function getEntriesByTag($taglist,  
$limit = 0,
$match_all = false)

Get a list of entries tagged with a given string.

Parameter

taglistAn array of tags to search for.
limitMaximum number of entries to return.  The default is zero, which means return all matching entries.
match_allOptional boolean that determines whether the entry must have every tag in taglist to match.  The default is false.

Returns

An array of entry objects, in reverse chronological order by post date.

getDrafts

function getDrafts()

Gets all the current drafts for this blog.

Returns

An array of BlogEntry objects.

getArticles

function getArticles()

Returns a list of all articles, in no particular order.

Returns

An array of Article objects.

getArticleList

function getArticleList($number = false,
$sticky_only = true)

Get a list of articles with title and permalink.

Parameters

numberOptional number of articles to return.  Default is all.
sticky_onlyOptionally return only “sticky” articles.  Default is true.

Returns

A two-dimensional array.  The first is numerically indexed.  The second is two elements indexed as “title” and “link”.  These represent the title of the article and the permalink to it respectively.

getEntryReplies

function getEntryReplies()

Gets all the replies for all entries belonging to this blog, including all comments, trackbacks, and pingbacks.

Returns

An array of objects, including BlogComment, Trackback, and Pingback objects.  The sorting of this list is dependent on the data storage implementation for the blog.

getEntryComments

function getEntryComments()

Like getEntryReplies, but only returns BlogComments.

getEntryTrackbacks

function getEntryTrackbacks()

Like getEntryReplies, but only returns Trackbacks.

getEntryPingbacks

function getEntryPingbacks()

Like getEntryReplies, but only returns Pingbacks.

getArticleReplies

function getArticleReplies()

Like getEntryReplies, but returns the replies for all Articles, instead of for all BlogEntries.

getArticleComments

function getArticleComments()

Like getArticleReplies, but only returns BlogComments.

getArticleTrackbacks

function getArticleTrackbacks()

Like getArticleReplies, but only returns Trackbacks.

getArticleArticlePingbacks

Like getArticleReplies, but only returns Pingbacks.

getReplies

function getReplies()

Like getEntryReplies and getArticleReplies, but combines both, returning an array of all replies for this blog.

getComments

function getComments()

Like getReplies, but only for comments.

getTrackbacks

function getTrackbacks()

Like getReplies, but only for comments.

getPingbacks

function getPingbacks()

Like getReplies, but only for comments.

exportVars

function exportVars(&$tpl)

Export blog variables to a PHPTemplate class.  This is for internal use only.

Parameters

tplThe PHPTemplate to populate.

getWeblog

function getWeblog ()

Gets the markup to display for the front page of a weblog.

Returns

A string holding the HTML to display.

upgradeWrappers

function upgradeWrappers ()

This is an upgrade function that will create new config and wrapper scripts to upgrade a directory of blog data to the current version.  The data files should always work unmodified, so they do not need to be upgraded.  This should not be required too often, if all goes well.

Precondition

It is assumed that this function will only be run from the package installation directory.

Returns

True on success, false on failure.

fixDirectoryPermissions

function fixDirectoryPermissions($start_dir = false)

A quick utility function to fix the borked permissions from not setting the correct umask when creating directories.  This resulted in directories that I couldn’t alter via FTP.

Parameters

start_dirThe directory to fix.  Defaults to the blog root.

Returns

True on success, false otherwise.

insert

function insert ($path = false)

Creates a new weblog.

Parameters

pathThe path to the blog root.  Defaults to the current directory.

Returns

True on success, false otherwise.

update

function update ()

Modify an existing weblog.

Returns

True on success, false otherwise.

delete

function delete ($keep_history =  null)

Removes an existing weblog.

Parameters

keep_historyIf set to true, only delete the blog data file, making this a non-blog directory, rather than totally destroy the data.  If not set, defaults to KEEP_EDIT_HISTORY constant.

Returns

True on success, false on failure.

updateTagList

function updateTagList($tags)

Adds any new tags to the list of tags used in the current blog.

Parameters

tagsAn array of strings holding the tags to be added.  Duplicates are removed.

Returns

True on success, false on failure.

function isBlog($blog = false)
Determines whether the object represents an existing blog.
function writers($list = false)
Set and return the list of users who can add posts to the blog.
function readBlogData()
Read and write a simple text file with the blog metadata.
function writeBlogData()
Save the blog data to disk.
function getDateRange($end_date,  
$start_date =  '')
Get all blog entries posted between a given range of dates.
function getDay($year,
$month,
$day)
Get all the blog entries for a particular day.
function getDayCount($year,
$month,
$day)
Get the number of posts made on a given day.
function getMonth($year = false,
$month = false)
Get a list of all entries for the specified month.
function getMonthCount($year = false,
$month = false)
Get the number of entries in the given month.
function getYear($year = false)
Like getMonth, except gets entries for an entire year.
function getYearList()
Get a list of all years in the archive, sorted in reverse chronological order.
function getMonthList($year = false)
Get a list of the months for the given year.
function getRecentMonthList($nummonths = 12)
Get a list of recent months, starting from the current month and going backward.
function getURL($full_uri = true)
Get the URL for the blog homepage.
function uri($type)
Get the URI of the designated resource.
function getRecent($num_entries = false)
Get the most recent entries across all months and years.
function getNextMax($num_entries = false)
Convenience function to get “previous entries”.
function getEntries($number = -1,
$offset = 0)
Scan entries in reverse chronological order, starting at a given offset, and get a given number of them.
function getEntriesByTag($taglist,  
$limit = 0,
$match_all = false)
Get a list of entries tagged with a given string.
function getDrafts()
Gets all the current drafts for this blog.
function getArticles()
Returns a list of all articles, in no particular order.
function getArticleList($number = false,
$sticky_only = true)
Get a list of articles with title and permalink.
function getEntryReplies()
Gets all the replies for all entries belonging to this blog, including all comments, trackbacks, and pingbacks.
function getEntryComments()
Like getEntryReplies, but only returns BlogComments.
function getEntryTrackbacks()
Like getEntryReplies, but only returns Trackbacks.
function getEntryPingbacks()
Like getEntryReplies, but only returns Pingbacks.
function getArticleReplies()
Like getEntryReplies, but returns the replies for all Articles, instead of for all BlogEntries.
function getArticleComments()
Like getArticleReplies, but only returns BlogComments.
function getArticleTrackbacks()
Like getArticleReplies, but only returns Trackbacks.
function getReplies()
Like getEntryReplies and getArticleReplies, but combines both, returning an array of all replies for this blog.
function getComments()
Like getReplies, but only for comments.
function getTrackbacks()
Like getReplies, but only for comments.
function getPingbacks()
Like getReplies, but only for comments.
function exportVars(&$tpl)
Export blog variables to a PHPTemplate class.
function getWeblog ()
Gets the markup to display for the front page of a weblog.
function upgradeWrappers ()
This is an upgrade function that will create new config and wrapper scripts to upgrade a directory of blog data to the current version.
function fixDirectoryPermissions($start_dir = false)
A quick utility function to fix the borked permissions from not setting the correct umask when creating directories.
function insert ($path = false)
Creates a new weblog.
function update ()
Modify an existing weblog.
function delete ($keep_history =  null)
Removes an existing weblog.
function updateTagList($tags)
Adds any new tags to the list of tags used in the current blog.
A base object which is event-aware, i.e.
Close