Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

get_plugin_yaml()

Parameters

ColumnTypeDefaultDescription
$path
$validate true

Location

include/plugin_functions.php lines 117 to 168

Definition

 
function get_plugin_yaml($path$validate=true)
{
    
#We're not using a full YAML structure, so this parsing function will do
    
$plugin_yaml['name'] = basename($path'.yaml');
    
$plugin_yaml['version'] = '0';
    
$plugin_yaml['author'] = '';
    
$plugin_yaml['info_url'] = '';
    
$plugin_yaml['update_url'] = '';
    
$plugin_yaml['config_url'] = '';
    
$plugin_yaml['desc'] = '';
    
$plugin_yaml['default_priority'] = '999';
    
$plugin_yaml['disable_group_select'] = '0';
    
$plugin_yaml['title'] = '';
    
$plugin_yaml['icon'] = '';

    if (!(
file_exists($path) && is_readable($path))) {
        return 
$validate false $plugin_yaml;
    }

    
$yaml_file_ptr fopen($path'r');

    if (
$yaml_file_ptr != false) {
        while ((
$line fgets($yaml_file_ptr)) != '') {
            if (
                
$line[0] != '#' 
                
&& ($pos strpos($line,':')) != false
            
) {
                
# Exclude comments from parsing
                
$plugin_yaml[trim(substr($line,0,$pos))] = trim(substr($line$pos+1));
            }
        }
            
        if (
$plugin_yaml['config_url'] != '' && $plugin_yaml['config_url'][0] == '/') {
            
# Strip leading spaces from the config url
            
$plugin_yaml['config_url'] = trim($plugin_yaml['config_url'], '/');
        }

        
fclose($yaml_file_ptr);

        if (
$validate) {
            if (isset(
$plugin_yaml['name']) && $plugin_yaml['name']==basename($path,'.yaml') && isset($plugin_yaml['version'])) {
                return 
$plugin_yaml;
            } else {
                return 
false;
            }
        }
    } elseif (
$validate) {
        return 
false;
    }

    return 
$plugin_yaml;
}

This article was last updated 5th May 2024 11:05 Europe/London time based on the source file dated 3rd May 2024 14:45 Europe/London time.