Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

prepareTags()

Description

Utility function which allows annotation tags to be prepared (i.e make sure they are all valid nodes)
before creating associations between annotations and tags


IMPORTANT: a tag should have the same structure as a node

Parameters

ColumnTypeDefaultDescription
$dirty_tags array Original array of tags. These can be (in)valid tags/ new tags.

Return

array

Location

include/annotation_functions.php lines 508 to 580

Definition

 
function prepareTags(array $dirty_tags)
    {
    if(
=== count($dirty_tags))
        {
        return array();
        }

    global 
$annotate_fields;

    
$clean_tags = array();

    foreach(
$dirty_tags as $dirty_tag)
        {
        
// Check minimum required information for a node
        
if(!isset($dirty_tag['resource_type_field'])
            || 
>= $dirty_tag['resource_type_field']
            || !
in_array($dirty_tag['resource_type_field'], $annotate_fields)
        )
            {
            continue;
            }

        if (!isset(
$dirty_tag['name']) || '' == $dirty_tag['name'])
            {
            continue;
            }

        
// No access to field? Next...
        
if(!metadata_field_view_access($dirty_tag['resource_type_field']))
            {
            continue;
            }

        
// New node?
        
if(is_null($dirty_tag['ref']) || (is_string($dirty_tag['ref']) && '' == $dirty_tag['ref']))
            {
            
$dirty_field_data get_resource_type_field($dirty_tag['resource_type_field']);

            
// Only dynamic keywords lists are allowed to create new options from annotations if permission allows it
            
if(
                !(
                    
FIELD_TYPE_DYNAMIC_KEYWORDS_LIST == $dirty_field_data['type'
                    && !
checkperm("bdk{$dirty_tag['resource_type_field']}")
                )
            )
                {
                continue;
                }

            
// Create new node but avoid duplicates
            
$new_node_id set_node(null$dirty_tag['resource_type_field'], $dirty_tag['name'], nullnull);
            if(
false !== $new_node_id && is_numeric($new_node_id))
                {
                
$dirty_tag['ref'] = $new_node_id;

                
$clean_tags[] = $dirty_tag;
                }

            continue;
            }

        
// Existing tags
        
$found_node = array();
        if (
            
get_node((int) $dirty_tag['ref'], $found_node)
           && 
$found_node['resource_type_field'] == $dirty_tag['resource_type_field'
        ) {
                
$clean_tags[] = $found_node;
            }
        }

    return 
$clean_tags;
    }

This article was last updated 4th December 2024 09:05 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.