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
The “master” class which represents a weblog.
Determines whether the object represents an existing blog.
Set and return the list of users who can add posts to the blog.
Read and write a simple text file with the blog metadata.
Save the blog data to disk.
Get all the blog entries for a particular day.
Get the number of posts made on a given day.
Get a list of all entries for the specified month.
Get the number of entries in the given month.
Get a list of all years in the archive, sorted in reverse chronological order.
Get a list of the months for the given year.
Get a list of recent months, starting from the current month and going backward.
Get the URL for the blog homepage.
Get the URI of the designated resource.
Get the most recent entries across all months and years.
Convenience function to get “previous entries”.
Scan entries in reverse chronological order, starting at a given offset, and get a given number of them.
Get a list of entries tagged with a given string.
Returns a list of all articles, in no particular order.
Get a list of articles with title and permalink.
Export blog variables to a PHPTemplate class.
Gets the markup to display for the front page of a weblog.
This is an upgrade function that will create new config and wrapper scripts to upgrade a directory of blog data to the current version.
A quick utility function to fix the borked permissions from not setting the correct umask when creating directories.
Creates a new weblog.
Modify an existing weblog.
Removes an existing weblog.
Adds any new tags to the list of tags used in the current blog.

Functions

isBlog

function isBlog()

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.

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.

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.  The parameters are expected to be strings of the form “key=val”.  Note that not all types of URI accept parameters.

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,  
$offset = )

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

Parameters

numberThe number of entries to return.  If set to -1, then returns all entries.
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 me !;!/an 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.

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.

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 ()

Removes an existing weblog.

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()
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 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 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,  
$offset = )
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 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 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 ()
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.