Tuskfish API V1.1.1
  • Package
  • Class

Packages

  • content
  • core
  • database
  • installation
  • security
  • user
  • utilities

Classes

  • TfArticle
  • TfAudio
  • TfBlock
  • TfBlockHandler
  • TfCollection
  • TfCollectionHandler
  • TfContentHandler
  • TfContentHandlerFactory
  • TfContentObject
  • TfDownload
  • TfImage
  • TfMetadata
  • TfPaginationControl
  • TfRss
  • TfSearchContent
  • TfStatic
  • TfTag
  • TfTagHandler
  • TfTaglinkHandler
  • TfTemplate
  • TfVideo

Traits

  • TfContentTypes

Class TfContentObject

Base class for content objects. Represents a single content object.

There is only one 'archtype' of content object in Tuskfish; it uses a subset of standard Dublin Core metadata fields plus a few more that are common to most content objects. Why? If you look at most common content types - articles, photos, downloads etc. - you will see that for the most part they all use the same fields (title, teaser, description, etc).

By using a single table for content objects with common field names our queries become very simple and much redundancy is avoided. Content subclasses that don't need particular properties unset() them in their constructor.

TfContentObject uses TfLanguage, TfMagicMethods, TfMimetypes

Direct known subclasses

TfArticle, TfAudio, TfBlock, TfCollection, TfDownload, TfImage, TfStatic, TfTag, TfVideo

Package: content
Copyright: Simon Wilkinson 2013+ (https://tuskfish.biz)
License: GNU General Public License (GPL) V2
Author: Simon Wilkinson simon@isengard.biz
Version: Release: 1.0
Since: 1.0
Uses: trait TfLanguage to obtain a list of available translations.
Uses: trait TfMagicMethods Prevents direct setting of properties / unlisted properties.
Uses: trait TfMimetypes Access a list of known / acceptable file mimetypes.
Properties: TfValidator $validator Instance of the Tuskfish data validator class.
Properties: int $id Auto-increment, set by database.
Properties: string $type Content object type eg. TfArticle etc. [ALPHA]
Properties: string $title The name of this content.
Properties: string $teaser A short (one paragraph) summary or abstract for this content. [HTML]
Properties: string $description The full article or description of the content. [HTML]
Properties: string $media An associated download/audio/video file. [FILEPATH OR URL]
Properties: string $format Mimetype
Properties: string $fileSize Specify in bytes.
Properties: string $creator Author.
Properties: string image An associated image file, eg. a screenshot a good way to handle it. [FILEPATH OR URL]
Properties: string $caption Caption of the image file.
Properties: string $date Date of publication expressed as a string.
Properties: int $parent A source work or collection of which this content is part.
Properties: string $language Future proofing.
Properties: int $rights Intellectual property rights scheme or license under which the work is distributed.
Properties: string $publisher The entity responsible for distributing this work.
Properties: array $tags Tag IDs associated with this object; not persistent (stored as taglinks in taglinks table).
Properties: int $online Toggle object on or offline.
Properties: int $submissionTime Timestamp representing submission time.
Properties: int $lastUpdated Timestamp representing last time this object was updated.
Properties: int $expiresOn Timestamp indicating the expiry date for this object.
Properties: int $counter Number of times this content was viewed or downloaded.
Properties: string $metaTitle Set a custom page title for this content.
Properties: string $metaDescription Set a custom page meta description for this content.
Properties: string $seo SEO-friendly string; it will be appended to the URL for this content.
Properties: string $handler Handler for this object (not persistent).
Properties: string $template The template that should be used to display this object (not persistent).
Properties: string $module The module that handles this content type (not persistent).
Properties: string $icon The vector icon that represents this object type (not persistent).
Located at trust_path/modules/content/class/TfContentObject.php

Methods summary

public
# __construct( TfValidator $validator )

Constructor.

Constructor.

Parameters

$validator
An instance of the Tuskfish data validator class.
public array
# convertObjectToArray( )

Converts a content object to an array suitable for insert/update calls to the database.

Converts a content object to an array suitable for insert/update calls to the database.

Note that the returned array observes the PARENT object's getPropertyWhitelist() as a restriction on the setting of keys. This whitelist explicitly excludes the handler, template and module properties as these are part of the class definition and are not stored in the database. Calling the parent's property whitelist ensures that properties that are unset by child classes are zeroed (this is important when an object is changed to a different subclass, as the properties used may differ).

Returns

array
Array of object property/values.
public string|null
# escapeForXss( string $property, boolean $escapeHtml = false )

Escapes object properties for output to browser.

Escapes object properties for output to browser.

Use this method to retrieve object properties when you want to send them to the browser. They will be automatically escaped with htmlspecialchars() to mitigate cross-site scripting attacks.

Note that the method excludes the teaser and description fields by default, which are returned unescaped; these are dedicated HTML fields that have been input-validated with the HTMLPurifier library, and so should be safe. However, when editing these fields it is necessary to escape them in order to prevent TinyMCE deleting them, as the '&' part of entity encoding also needs to be escaped when in a textarea for some highly annoying reason.

Parameters

$property
Name of property.
$escapeHtml
Whether to escape HTML fields (teaser, description).

Returns

string|null

Human readable value escaped for display or null if property does not exist.

public string
# getCachedImage( integer $width = 0, integer $height = 0 )

Resizes and caches an associated image and returns a URL to the cached copy.

Resizes and caches an associated image and returns a URL to the cached copy.

Allows arbitrary sized thumbnails to be produced from the object's image property. These are saved in the cache for future lookups. Image proportions are always preserved, so if both width and height are specified, the larger dimension will take precedence for resizing and the other will be ignored.

Usually, you want to produce an image of a specific width or (less commonly) height to meet a template/presentation requirement.

Parameters

$width
Width of the cached image output.
$height
Height of the cached image output.

Returns

string
$url URL to the cached image.
public array
# getListOfAllowedAudioMimetypes( )

Returns an array of audio mimetypes that are permitted for content objects.

Returns an array of audio mimetypes that are permitted for content objects.

Note that ogg audio files should use the .oga extension, although the legacy .ogg extension is still acceptable, although it must no longer be used for video files.

Returns

array
Array of permitted audio mimetypes in file extension => mimetype format.
public array
# getListOfAllowedImageMimetypes( )

Returns an array of image mimetypes that are permitted for content objects.

Returns an array of image mimetypes that are permitted for content objects.

Returns

array
Array of permitted image mimetypes in file extension => mimetype format.
public array
# getListOfAllowedVideoMimetypes( )

Returns an array of video mimetypes that are permitted for upload.

Returns an array of video mimetypes that are permitted for upload.

Note that ogg video files must use the .ogv file extension. Please do not use .ogg for video files as this practice has been deprecated in favour of .ogv. While .ogg is still in wide use it is now presumed to refer to audio files only.

Returns

array
Array of permitted video mimetypes in file extension => mimetype format.
public array
# getListOfRights( )

Returns a list of intellectual property rights licenses for the content submission form.

Returns a list of intellectual property rights licenses for the content submission form.

In the interests of brevity and sanity, a comprehensive list is not provided. Add entries that you want to use to the array below. Be aware that deleting entries that are in use by your content objects will cause errors.

Returns

array
Array of copyright licenses.
public array
# getListOfZeroedProperties( )

Returns an array of base object properties that are not used by this subclass.

Returns an array of base object properties that are not used by this subclass.

This list is also used in update calls to the database to ensure that unused columns are cleared and reset with default values.

Returns

array
public array
# getPropertyWhitelist( )

Returns a whitelist of object properties whose values are allowed be set.

Returns a whitelist of object properties whose values are allowed be set.

This function is used to build a list of $allowedVars for a content object. Child classes use this list to unset properties they do not use. Properties that are not resident in the database are also unset here (handler, template, module and icon).

Returns

array
Array of object properties as keys.
public string
# getUrl( string $customPage = '' )

Generates a URL to access this object in single view mode.

Generates a URL to access this object in single view mode.

URL can point relative to either the home page (index.php, or other custom content stream page defined by modifying TFISH_PERMALINK_URL in config.php) or to an arbitrary page in the web root. For example, you could rename index.php to 'blog.php' to free up the index page for a landing page (this requires you to append the name of the new page to the TFISH_PERMALINK_URL constant).

You can set up an articles.php page to display only TfArticle objects. The subclass-specific pages are found in the trust_path/extras folder. Just drop them into your site root to use them.

Parameters

$customPage
Use an arbitrary target page or the home page (index.php).

Returns

string
URL to view this object.
public boolean
# isValidMedia( )

Determine if the media file (mime) type is valid for this content type.

Determine if the media file (mime) type is valid for this content type.

Used in templates to determine whether a media file should be displayed or not. For example, if you attach a video file to an audio content object, the inline player will not be displayed (because it will not work).

Returns

boolean
True if media mimetype is valid for this content type, otherwise false.
public
# loadPropertiesFromArray( array $dirtyInput, boolean $liveUrls = true )

Populates the properties of the object from external (untrusted) data source.

Populates the properties of the object from external (untrusted) data source.

Note that the supplied data is internally validated by __set().

Parameters

$dirtyInput
Usually raw form $_REQUEST data.
$liveUrls
Convert base url to TFISH_LINK (true) or TFISH_LINK to base url (false).
protected string
# makeDataHumanReadable( string $cleanProperty )

Converts properties to human readable form in preparation for output.

Converts properties to human readable form in preparation for output.

This method is overridden in child subclasses, to allow for the possibility of handling additional properties. The overrides refer back to this parent method for handling base (standard) properties of this parent class.

Parameters

$cleanProperty
$property Name of property.

Returns

string
Property formatted to human readable form for output.
public
# __set( string $property, mixed $value )

Intercept direct setting of properties to permit data validation.

Intercept direct setting of properties to permit data validation.

It is best to set properties using the relevant setter method directly, as it is more efficient. However, due to use of PDO::FETCH_CLASS to automate instantiation of objects directly from the database, it is also necessary to allow them to be set via a magic method call.

Parameters

$property
Name of property.
$value
Value of property.
public
# setCaption( string $caption )

Set the caption that will accompany the image property.

Set the caption that will accompany the image property.

Parameters

$caption
Caption describing image.
public
# setCounter( integer $counter )

Set the view/download counter for this object.

Set the view/download counter for this object.

Parameters

$counter
Counter value.
public
# setCreator( string $creator )

Set the creator of this object.

Set the creator of this object.

Parameters

$creator
Name of the creator.
public
# setDate( string $date )

Set the publication date of this object expressed as a string.

Set the publication date of this object expressed as a string.

Parameters

$date
Publication date.
public
# setDescription( string $description )

Set the description of this object (HTML field).

Set the description of this object (HTML field).

Parameters

$description
Description in HTML.
public
# setExpiresOn( integer $expiresOn )

Set the expirty time for this content object (timestamp).

Set the expirty time for this content object (timestamp).

Parameters

$expiresOn
Timestamp.
public
# setFileSize( integer $fileSize )

Set the file size for the media attachment to this object.

Set the file size for the media attachment to this object.

Parameters

$fileSize
Filesize in bytes.
public
# setFormat( string $format )

Set the format (mimetype) for the media attachment to this object.

Set the format (mimetype) for the media attachment to this object.

Mimetypes must be official/correct as they are used in headers to initiate streaming of media files.

Parameters

$format
Mimetype.
public
# setHandler( string $handler )

Set the handler class for this content type.

Set the handler class for this content type.

For most content subclasses this will be the general TfishContentHandler. However, some subclasses use their own handler subclass (eg. TfishTagHandler and TfishCollection handler).

Parameters

$handler
Handler name (alphabetical characters only).f
public
# setIcon( string $icon )

Set the icon for this content object.

Set the icon for this content object.

This is a HTML field.

Parameters

$icon
Icon expressed as a FontAwesome tag, eg. ''
public
# setId( integer $id )

Set the ID for this object.

Set the ID for this object.

Parameters

$id
ID of this object.
public
# setImage( string $image )

Set the image for this content object.

Set the image for this content object.

Parameters

$image
Filename of the image.
public
# setLanguage( string $language )

Set the language of this content object.

Set the language of this content object.

Parameters

$language
ISO_639-1 two-letter language code.
public
# setLastUpdated( integer $lastUpdated )

Set the last updated time for this content object (timestamp).

Set the last updated time for this content object (timestamp).

Parameters

$lastUpdated
Timestamp.
public
# setMedia( string $media )

Set the media attachment for this content object.

Set the media attachment for this content object.

Parameters

$media
Filename of the media attachment.
public
# setMetaDescription( string $metaDescription )

Set the meta description for this content object.

Set the meta description for this content object.

Parameters

$metaDescription
Meta description of this object.
public
# setMetaTitle( string $metaTitle )

Set the meta title for this object.

Set the meta title for this object.

Parameters

$metaTitle
Meta title for this object.
public
# setModule( string $module )

Set the module for this content object.

Set the module for this content object.

Usually handled by the object's constructor.

Parameters

$module
Module name.
public
# setOnline( integer $online )

Set this content object as online (1) or offline (0).

Set this content object as online (1) or offline (0).

Offline objects are not displayed on the front end or returned in search results.

Parameters

$online
Online (1) or offline (0).
public
# setParent( integer $parent )

Set the ID of the parent for this object (must be a collection).

Set the ID of the parent for this object (must be a collection).

Parent ID must be different to content ID (cannot declare self as parent).

Parameters

$parent
ID of parent object.
public
# setPublisher( string $publisher )

Set the publisher of this content object.

Set the publisher of this content object.

Parameters

$publisher
Name of the publisher.
public
# setRights( integer $rights )

Set the intellectual property rights for this content object.

Set the intellectual property rights for this content object.

See getListOfRights() for the available licenses, which you can customise to suit yourself.

Parameters

$rights
ID of a copyright license.
public
# setSeo( string $seo )

Set the SEO-friendly search string for this content object.

Set the SEO-friendly search string for this content object.

The SEO string will be appended to the URL for this object.

Parameters

$seo
Dash-separated-title-of-this-object.
public
# setSubmissionTime( integer $submissionTime )

Set the submission time for this content object (timestamp).

Set the submission time for this content object (timestamp).

Parameters

$submissionTime
Timestamp.
public
# setTags( array $tags )

Set the tags associated with this content object.

Set the tags associated with this content object.

Parameters

$tags
IDs of associated tags.
public
# setTeaser( string $teaser )

Set the teaser (short form description) for this content object.(HTML).

Set the teaser (short form description) for this content object.(HTML).

Parameters

$teaser
Teaser (in HTML).
public
# setTemplate( string $template )

Set the template file for displaying this content object.

Set the template file for displaying this content object.

The equivalent HTML template file must be present in the active theme.

Parameters

$template
Template filename without extension, eg. 'article'.
public
# setTitle( string $title )

Set the title of this content object.

Set the title of this content object.

Parameters

$title
Title of this object.
public
# setType( string $type )

Set the content type for this object.

Set the content type for this object.

Type must be the name of a content subclass.

Parameters

$type
Class name for this content object.
public
# updateLastUpdated( )

Reset the last updated time for this content object (timestamp).

Reset the last updated time for this content object (timestamp).

Methods used from TfLanguage

getListOfLanguages()

Methods used from TfMagicMethods

__get(), __isset(), __unset()

Methods used from TfMimetypes

getListOfPermittedUploadMimetypes()

Properties summary

protected $validator
#
protected string $id
# ''
protected string $type
# ''
protected string $title
# ''
protected string $teaser
# ''
protected string $description
# ''
protected string $media
# ''
protected string $format
# ''
protected string $fileSize
# ''
protected string $creator
# ''
protected string $image
# ''
protected string $caption
# ''
protected string $date
# ''
protected string $parent
# ''
protected string $language
# ''
protected string $rights
# ''
protected string $publisher
# ''
protected string $tags
# ''
protected string $online
# ''
protected string $submissionTime
# ''
protected string $lastUpdated
# ''
protected string $expiresOn
# ''
protected string $counter
# ''
protected string $metaTitle
# ''
protected string $metaDescription
# ''
protected string $seo
# ''
protected string $handler
# ''
protected string $template
# ''
protected string $module
# ''
protected string $icon
# ''
Tuskfish API V1.1.1 API documentation generated by ApiGen