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

get_plugin_yaml()

Parameters

ColumnTypeDefaultDescription
$plugin
$validate true
$translate true

Location

include/plugin_functions.php lines 118 to 198

Definition

 
function get_plugin_yaml($plugin$validate=true$translate=true)
{

    
# We're not using a full YAML structure, so this parsing function will do
    
$plugin_yaml['name'] = $plugin;
    
$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'] = '';
    
$plugin_yaml['icon-colour'] = '';
    
    
// Validate plugin name (prevent path traversal when getting .yaml)
    
if (!ctype_alnum(str_replace(["_","-"],"",$plugin))) { return $validate false $plugin_yaml;}

    
// Find plugin YAML
    
$path get_plugin_path($plugin) . "/" $plugin ".yaml";
    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;
    }

    
// Handle translations for base plugins
    
global $language,$languages,$lang;
    if (
$translate && $language!="en" && $language!="")
        {
        
// Include relevant language file and use the translations instead, if set.
        
if (!array_key_exists($language,$languages)) {exit("Invalid language");} // Prevent path traversal
        
$plugin_lang_file=__DIR__ "/../plugins/" $plugin_yaml["name"] . "/languages/" $language ".php";
        if (
file_exists($plugin_lang_file))
            {
            include_once 
$plugin_lang_file;
            if (isset(
$lang["plugin-" $plugin_yaml["name"] . "-title"]))
                {
                
// Append the translated title so the English title is still visible, this is so it's still possible to find the relevant plugin
                // in the Knowledge Base (until we have Knowledge Base translations down the line)
                
$plugin_yaml["title"].=" (" . ($lang["plugin-" $plugin_yaml["name"] . "-title"] ?? $plugin_yaml["title"]) . ")";
                }
            
$plugin_yaml["desc"]= $lang["plugin-" $plugin_yaml["name"] . "-desc"]  ?? $plugin_yaml["desc"];
            }
        
$param="plugin-category-" strtolower(str_replace(" ","-",$plugin_yaml["category"] ?? ""));
        
$plugin_yaml["category"]= $lang[$param] ?? $plugin_yaml["category"] ?? "";
        }

    return 
$plugin_yaml;
}

This article was last updated 5th December 2024 07:35 Europe/London time based on the source file dated 29th November 2024 10:35 Europe/London time.