ContentOperations View code

Class for static methods related to content

abstract
since 0.8
package

CMS

license

GPL

Methods

get_instance() : \ContentOperations

Return a reference to the only allowed instance of this singleton object

static
getContentObject() : \getContentObject()

Return a content object for the currently requested page.

Response

\getContentObject()

LoadContentFromSerializedData(array &$data) : \ContentBase

Given an array of content_type and seralized_content, reconstructs a content object. It will handled loading the content type if it hasn't already been loaded.

Expects an associative array with 2 elements: content_type: string A content type name serialized_content: string Serialized form data

Arguments

array $data

Response

\ContentBase

A content object derived from ContentBase

CreateNewContent(mixed $type) : \ContentBase

Creates a new, empty content object of the given type.

if the content type is registered with the system, and the class does not exist, the appropriate filename will be included and then, if possible a new object of the designated type will be instantiated.

Arguments

mixed $type

The type. Either a string, or an instance of CmsContentTypePlaceHolder

Response

\ContentBase

(A valid object derived from ContentBase)

LoadContentFromId(integer $id = null) : mixed

Given a content id, load and return the loaded content object.

Arguments

integer $id

The id of the content object to load

Response

mixed

The loaded content object. If nothing is found, returns void

SmartLoadContentFromAlias(mixed $alias) : \ContentBase|null

Given an id or an alias, return the content object.

Uses various optimization routines to increase performance. This method will generate notices or errors if the input is invalid.

Arguments

mixed $alias

Either an integer id OR a string alias

Response

\ContentBase|null

LoadContentFromAlias(integer $alias, boolean $only_active = false) : \ContentBase

Given a content alias, load and return the loaded content object.

Arguments

integer $alias

The alias of the content object to load

boolean $only_active

If true, only return the object if it's active flag is true. Defaults to false.

Response

\ContentBase

The loaded content object. If nothing is found, returns NULL.

GetDefaultContent() : integer

Returns the id of the content marked as default.

Response

integer

The id of the default content page

register_content_type(\CmsContentTypePlaceHolder $obj) 

Register a new content type

Arguments

\CmsContentTypePlaceHolder $obj

ListContentTypes(boolean $byclassname = false, boolean $allowed = false, boolean $system = FALSE) : array

Returns a hash of valid content types (classes that extend ContentBase) The key is the name of the class that would be saved into the database. The value would be the text returned by the type's FriendlyName() method.

Arguments

boolean $byclassname

optionally return keys as class names.

boolean $allowed

optionally trim the list of content types that are allowed by the site preference.

boolean $system

return only system content types.

Response

array

List of content types registered in the system.

SetAllHierarchyPositions() 

Updates the hierarchy position of all content items.

This is an expensive operation on the database, but must be called once each time one or more content pages are updated if positions have changed in the page structure.

GetLastContentModification() : \unix

Get the date of last content modification

Response

\unix

timestamp representing the last time a content page was modified.

GetAllContentAsHierarchy() : \cms_content_tree

Loads a set of content objects into the cached tree.

deprecated

Response

\cms_content_tree

The cached tree of content

LoadAllContent(boolean $loadprops = FALSE, boolean $inactive = FALSE, boolean $showinmenu = FALSE) 

Load All content in the database into memory Use with caution this can chew up alot of memory on larger sites.

Arguments

boolean $loadprops

Load extended content properties or just the page structure and basic properties

boolean $inactive

Load inactive pages as well

boolean $showinmenu

Load pages marked as show in menu

LoadChildren(integer $id = null, boolean $loadprops = false, boolean $all = false, array $explicit_ids = array()) 

Loads additional, active children into a given tree object.

This is a smart method that determines what needs to be loaded, and adds them to the content cache the idea is to optimize memory by requests.

Arguments

integer $id

The parent of the content objects to load into the tree

boolean $loadprops

If true, load the properties of all loaded content objects

boolean $all

If true, load all content objects, even inactive ones.

array $explicit_ids

(optional) array of explicit content ids to load

SetDefaultContent(integer $id) 

Sets the default content to the given id

Arguments

integer $id

The id to set as default

GetAllContent() : array

Returns an array of all content objects in the system, active or not.

Caution: it is entirely possible that this method (and other similar methods of loading content) will result in a memory outage if there are large amounts of content objects AND/OR large amounts of content properties. Use with caution.

Response

array

The array of content objects

CreateHierarchyDropdown(integer $current = '', integer $value = '', string $name = 'parent_id', boolean $allowcurrent, boolean $use_perms, boolean $ignore_current, boolean $allow_all = false, boolean $for_child = false) : string

Create a hierarchical ordered dropdown of all the content objects in the system for use in the admin and various modules. If $current or $parent variables are passed, care is taken to make sure that children which could cause a loop are hidden, in cases of when you're creating a dropdown for changing a content object's parent.

deprecated

This method was rewritten for 2.0 to use the jquery hierselector plugin to better accommodate larger websites.

Since many parameters are now ignored, A new method needs to be writtent o replace this archaic method... so consider this method to be deprecateed.

Arguments

integer $current

The id of the content object we are working with. Used with allowcurrent to not show children of the current conrent object, or itself.

integer $value

The id of the currently selected content object.

string $name

The html name of the dropdown.

boolean $allowcurrent

Ensures that the current value cannot be selected, or $current and it's childrern. Used to prevent circular deadlocks.

boolean $use_perms

If true, checks authorship permissions on pages and only shows those the current user has authorship of (can edit)

boolean $ignore_current

(ignored as of 2.0) (Before 2.2 this parameter was called ignore_current

boolean $allow_all

If true, show all items, even if the content object doesn't have a valid link. Defaults to false.

boolean $for_child

If true, assume that we want to add a new child and obey the WantsChildren flag of each content page. (new in 2.2).

Response

string

The html dropdown of the hierarchy.

GetDefaultPageID() : integer

Gets the content id of the page marked as default

Response

integer

The id of the default page. false if not found.

GetPageIDFromAlias(string $alias) : integer

Returns the content id given a valid content alias.

Arguments

string $alias

The alias to query

Response

integer

The resulting id. null if not found.

GetPageIDFromHierarchy(string $position) : integer

Returns the content id given a valid hierarchical position.

Arguments

string $position

The position to query

Response

integer

The resulting id. false if not found.

GetPageAliasFromID(integer $id) : string

Returns the content alias given a valid content id.

Arguments

integer $id

The content id to query

Response

string

The resulting content alias. false if not found.

CheckAliasUsed(string $alias, integer $content_id = -1) : boolean

Check if a content alias is used

Arguments

string $alias

The alias to check

integer $content_id

The id of hte current page, if any

Response

boolean

CheckAliasValid(string $alias) : boolean

Check if a potential alias is valid.

Arguments

string $alias

The alias to check

Response

boolean

CheckAliasError(string $alias, integer $content_id = -1) : string

Checks to see if a content alias is valid and not in use.

Arguments

string $alias

The content alias to check

integer $content_id

The id of the current page, for used alias checks on existing pages

Response

string

The error, if any. If there is no error, returns FALSE.

CreateFriendlyHierarchyPosition(string $position) : string

Converts a friendly hierarchy (1.1.1) to an unfriendly hierarchy (00001.00001.00001) for use in the database.

Arguments

string $position

The hierarchy position to convert

Response

string

The unfriendly version of the hierarchy string

CreateUnfriendlyHierarchyPosition(string $position) : string

Converts an unfriendly hierarchy (00001.00001.00001) to a friendly hierarchy (1.1.1) for use in the database.

Arguments

string $position

The hierarchy position to convert

Response

string

The friendly version of the hierarchy string

CheckParentage(integer $test_id, integer $base_id = null) : boolean

Check if the supplied page id is a parent of the specified base page (or the current page)

Arguments

integer $test_id

Page ID to test

integer $base_id

(optional) Page ID to act as the base page. The current page is used if not specified.

Response

boolean

GetOwnedPages(integer $userid) : array

Return a list of pages that the user is owner of.

Arguments

integer $userid

The userid

Response

array

Array of integer page id's

CheckPageOwnership(integer $userid, integer $pageid) : boolean

Test if the user specified owns the specified page

Arguments

integer $userid

integer $pageid

Response

boolean

GetPageAccessForUser(integer $userid) : array<mixed,integer>

Return a list of pages that the user has edit access to.

Arguments

integer $userid

The userid

Response

array<mixed,integer>

Array of page id's

CheckPageAuthorship(integer $userid, integer $contentid) : boolean

Check if the specified user has the ability to edit the specified page id

Arguments

integer $userid

integer $contentid

Response

boolean

CheckPeerAuthorship(integer $userid, integer $contentid) : boolean

Test if the specified user account has edit access to all of the peers of the specified page id

Arguments

integer $userid

integer $contentid

Response

boolean

quickfind_node_by_id(integer $id) : \cms_content_tree

A convenience function to find a hierarchy node given the page id This method will be moved to cms_content_tree at a later date.

Arguments

integer $id

The page id

Response

\cms_content_tree

save_content(\ContentBase $content) 

Save a content object to the database.

This method also will clear caches, and update content heirarchies.

Arguments

\ContentBase $content

delete_content(\ContentBase $content) 

Delete a content object from the database.

This method assumes that the input content object has an id. If it does then the database record will be removed. This method also deletes all associated data, calls hooks, and updates hierarchy positions of other content items as appropriate.

This method does not alter the input content object, so users must exercise caution with the content object after it has been removed.

Arguments

\ContentBase $content

The object to delete.

change_content_order(\ContentBase $content, integer $direction) 

Move a content object up, or down amongst its peers.

This method will also update content hierarchy positions as is a appropriate.

Arguments

\ContentBase $content

The content object to modify

integer $direction

A negative value indicates to move the item up, a positive value indicates to move the item down amongst its peers.

set_default_content(\ContentBase $content) 

Set the content object as the default.

This method does not alter the input content object, it merely modifies the database.

Arguments

\ContentBase $content

calculate_unused_content_alias(\ContentBase $content, string $seed = null) : string

Given a content object, and a seed string, calculate a suitable unsed content alias

Arguments

\ContentBase $content

The content object to use when generating an alias

string $seed

an optional seed string. If not used, look at the content object.

Response

string