Source for file globals.php
Documentation is available at globals.php
* Helper functions that are always available in Omeka. As global functions,
* these should be used as little as possible in the application code
* Retrieve an option from the Omeka database.
* If the returned value represents an object or array, it must be unserialized
* by the caller before use. For example,
* <code>$object = unserialize(get_option('plugin_object'))</code>.
* Set an option in the Omeka database.
* Note that objects and arrays must be serialized before being saved.
$db->exec("REPLACE INTO $db->Option (name, value) VALUES (?, ?)", array($name, $value));
//Now update the options hash so that any subsequent requests have it available
$options[$name] =
$value;
* Delete an option from the database.
$db->query($sql, array($name));
if (isset
($options[$name])) {
* Generate a URL slug from a piece of text.
* Trims whitespace, replaces some prohibited characters with hyphens, and
* converts the resulting string to lowercase.
//Replace prohibited characters in the title with - 's
$prohibited =
array(':', '/', ' ', '.', '#');
* Retrieve one column of a multidimensional array as an array.
* @param string|integer$col
function pluck($col, $array)
foreach ($array as $k =>
$row) {
* Retrieve the User record associated with the currently logged in user.
* @return User|nullNull if no user is logged in.
* Retrieve the database object.
* Log a message with 'DEBUG' priority.
* This will do nothing if logging is not enabled via config.ini's log.errors
$logger =
$context->getLogger();
* Called during startup to strip out slashes from the request superglobals in
* order to avoid problems with PHP's magic_quotes setting.
* Does not need to be called elsewhere in the application.
function stripslashes_deep($value)
* Declare a plugin hook implementation within a plugin.
* @param mixed $callback Any valid PHP callback.
get_plugin_broker()->addHook($hook, $callback);
* Declare the point of execution for a specific plugin hook.
* All plugin implementations of a given hook will be executed when this is called.
* The first argument corresponds to the string name of the hook. Subsequent
* arguments will be passed to the plugin hook implementations.
* <code>fire_plugin_hook('after_save_item', $item, $arg2); //would call the plugin hook
* 'after_save_item' with those 2 arguments.</code>
* @param string $hookName
function fire_plugin_hook()
if ($pluginBroker =
get_plugin_broker()) {
* Retrieve the output of fire_plugin_hook() as a string.
* This is invoked in the same way as fire_plugin_hook().
* @uses fire_plugin_hook()
* Retrieve the output of a specific plugin's hook as a string.
* This is like get_plugin_hook_output() but only calls the hook within the
* @param string $pluginName
* @param string $hookName
* @param [any number of further arguments]
// Get the plugin name (1st arg) and hook name (2nd arg).
// Get the specific hook.
$pluginBroker =
get_plugin_broker();
$hookNameSpecific =
$pluginBroker->getHook($pluginName, $hookName);
// Return null if the specific hook doesn't exist.
if (!$hookNameSpecific) {
// Buffer and return any output originating from the hook.
* @return Omeka_Plugin_Broker|null
function get_plugin_broker()
if (Zend_Registry::isRegistered('pluginbroker')) {
return Zend_Registry::get('pluginbroker');
* Retrieves specified descriptive info for a plugin from its ini file.
* @param string $pluginDirName The directory name of the plugin
* @param string $iniKeyName The name of the key in the ini file
* @return null | string The value of the specified plugin key. If the key does not exist, it returns null
return $pluginBroker->getPluginIniValue($pluginDirName, $iniKeyName);
* Declare a function that will be used to display files with a given MIME type.
* @uses Omeka_Plugin_Broker::addMediaAdapter() See for info on arguments and
get_plugin_broker()->addMediaAdapter($mimeTypes, $callback, $options);
* Apply a set of plugin filters to a given value.
* The first two arguments represent the name of the filter and the value to
* filter, and all subsequent arguments are passed to the individual filter
* @uses Omeka_Plugin_Filters::applyFilters()
* @param string|array$filterName
* @param mixed $valueToFilter
if ($pluginBroker =
get_plugin_broker()) {
return $pluginBroker->applyFilters($filterName, $valueToFilter, $extraOptions);
// If the plugin broker is not enabled for this request (possibly for testing), return the original value.
* Declare a filter implementation.
* @param string|array$filterName
* @param callback $callback
* @param integer $priority Optional Defaults to 10.
function add_filter($filterName, $callback, $priority =
10)
if ($pluginBroker =
get_plugin_broker()) {
$pluginBroker->addFilter($filterName, $callback, $priority);
* Retrieve the ACL object.
* Determine whether or not the script is being executed through the
* administrative interface.
* Can be used to branch behavior based on whether or not the admin theme is
* being accessed, but should not be relied upon in place of using the ACL for
* controlling access to scripts.
* Insert a new item into the Omeka database.
* * @param array $itemMetadata Optional Set of metadata options for configuring the
* item. Array which can include the following properties:
* <li>'public' (boolean)</li>
* <li>'featured' (boolean)</li>
* <li>'collection_id' (integer)</li>
* <li>'item_type_id' (integer)</li>
* <li>'item_type_name' (string)</li>
* <li>'tags' (string, comma-delimited)</li>
* <li>'tag_entity' (Entity, optional and only checked if 'tags' is given)</li>
* <li>'overwriteElementTexts' (boolean) -- determines whether or not to
* overwrite existing element texts. If true, this will loop through the
* element texts provided in $elementTexts, and it will update existing
* records where possible. All texts that are not yet in the DB will be
* added in the usual manner. False by default.</li>
* @param array $elementTexts Optional Array of element texts to assign to the item.
* This follows the format:
* [element set name] => array(
* [element name] => array(
* array('text' => [string], 'html' => [false|true]),
* array('text' => [string], 'html' => [false|true])
* [element name] => array(
* array('text' => [string], 'html' => [false|true]),
* array('text' => [string], 'html' => [false|true])
* [element set name] => array(
* [element name] => array(
* array('text' => [string], 'html' => [false|true]),
* array('text' => [string], 'html' => [false|true])
* [element name] => array(
* array('text' => [string], 'html' => [false|true]),
* array('text' => [string], 'html' => [false|true])
* See ActsAsElementText::addElementTextsByArray() for more info.
* @param array $fileMetadata Optional Set of metadata options that allow one or more
* files to be associated with the item. Includes the following options:
* <li>'file_transfer_type' (string = 'Url|Filesystem|Upload' or
* Omeka_File_Transfer_Adapter_Interface). Corresponds to the
* $transferStrategy argument for addFiles().</li>
* <li>'file_ingest_options' OPTIONAL (array of possible options to pass
* modify the behavior of the ingest script). Corresponds to the $options
* argument for addFiles().</li>
* <li>'files' (array or string) Represents information indicating the file
* to ingest. Corresponds to the $files argument for addFiles().</li>
* @uses ItemBuilder For more information on arguments and usage.
* @see ActsAsElementText::addElementTextsByArray()
function insert_item($metadata =
array(), $elementTexts =
array(), $fileMetadata =
array())
// Passing null means this will create a new item.
$builder =
new ItemBuilder($metadata, $elementTexts, $fileMetadata);
return $builder->build();
* @uses ItemBuilder::addFiles() See for information on arguments and notes
* @param Item|integer$item
* @param string|Omeka_File_Ingest_Abstract$transferStrategy
* @param array $options Optional
// TODO: Maybe this should be a separate helper class.
$helper =
new ItemBuilder(array(), array(), array(), $item);
return $helper->addFiles($transferStrategy, $files, $options);
* @param Item|int$item Either an Item object or the ID for the item.
* @param array $metadata Set of options that can be passed to the item.
* @param array $elementTexts
* @param array $fileMetadata
function update_item($item, $metadata =
array(), $elementTexts =
array(), $fileMetadata =
array())
$builder =
new ItemBuilder($metadata, $elementTexts, $fileMetadata, $item);
return $builder->build();
* Insert a new item type.
* @param array $metadata Follows the format:
* 'description'=> [string]
* @param array $elementInfos An array containing element data. Each entry follows
* one or more of the following formats:
* <li>An array containing element metadata</li>
* <li>A string containing the element name</li>
* 'name' => [(string) name, required],
* 'description' => [(string) description, optional],
* 'record_type' => [(string) record type name, optional],
* 'data_type' => [(string) data type name, optional],
* 'order' => [(int) order, optional],
* 'record_type_id' => [(int) record type id, optional],
* 'data_type_id' => [(int) data type id, optional]
* [(string) element name],
return $builder->build();
* @param array $metadata Follows the format:
* 'description'=> [string],
* 'public' => [true|false],
* 'featured' => [true|false]
* 'collectors' => [array of entities, entity ids, or entity property arrays]
* You can specify collectors in several ways.
* You can provide an array of entity properties:
* insert_collection(array('collectors'=>array(
* array('first_name' => $entityFirstName1,
* 'middle_name' => $entityMiddleName1,
* 'last_name' => $entityLastName1,
* array('first_name' => $entityFirstName2,
* 'middle_name' => $entityMiddleName2,
* 'last_name' => $entityLastName2,
* Alternatively, you can use an array of entity objects or entity ids.
* insert_collection(array('collectors'=>array($entity1, $entity2, ...));
* insert_collection(array('collectors'=>array($entityId1, $entityId2, ...));
* Also you can mix the parameters:
* insert_collection(array('collectors'=>array(
* array('first_name' => $entityFirstName1,
* 'middle_name' => $entityMiddleName1,
* 'last_name' => $entityLastName1,
return $builder->build();
* Insert an element set and its elements into the database.
* @param string|array$elementSetMetadata Element set information.
* [(string) element set name]
* 'name' => [(string) element set name, required, unique],
* 'description' => [(string) element set description, optional]
* @param array $elements An array containing element data. Follows one of more
* of the following formats:
* <li>An array containing element metadata</li>
* <li>A string of the element name</li>
* 'name' => [(string) name, required],
* 'description' => [(string) description, optional],
* 'record_type' => [(string) record type name, optional],
* 'data_type' => [(string) data type name, optional],
* 'record_type_id' => [(int) record type id, optional],
* 'data_type_id' => [(int) data type id, optional]
* [(string) element name]
return $builder->build();
* Releases an object from memory.
* Use this fuction after you are done using an Omeka model object to prevent
* memory leaks. Required because PHP 5.2 does not do garbage collection on
* Return either the value or, if it's empty, output the default.
return !empty($value) ?
$value :
$default;
* Returns whether a value is true or not.
* If the value is a string and its lowercased value is 'true' or '1', it returns true.
* If the value is an integer and equal to 1, then it returns true.
* Otherwise it returns false.
return ($value ==
'1' ||
$value ==
'true');
Documentation generated on Thu, 15 Oct 2009 15:37:57 -0400 by phpDocumentor 1.4.2