<?php

namespace templates;

require_once 'twig.php';


/********************************************************
 * RENDER A SINGLE TEMPLATE
 *******************************************************/


// Template for SPDX licenses
function spdx_license ($uri)
{
    global $twig;
    
    $data = \sparql\describe ($uri);
    
    return $twig->render (
        'spdx-license.twig',
        [ 'data' => $data ]
    );
}

// Template for FSD software
function fsd_software ($uri)
{
    global $twig;
    
    $frame = [
        '@context' => [
            'fsd-p' => 'http://directory.fsf.org/wiki/Special:URIResolver/Property-3A',
            'fsd-c' => 'http://directory.fsf.org/wiki/Special:URIResolver/Category-3A',
            'rdfs'  => 'http://www.w3.org/2000/01/rdf-schema#',
            'swivt' => 'http://semantic-mediawiki.org/swivt/1.0#'
        ],
        '@type' => [ 'swivt:Subject', 'fsd-c:Entry' ]
    ];
    
    $data = \sparql\describe ($uri);
    $data = \sparql\apply_frame ($data, $frame) ['@graph'][0];
    
    return $twig->render (
        'fsd.twig',
        [ 'data' => $data ]
    );
}


/********************************************************
 * RENDER ENTIRE PAGE
 *******************************************************/


function render_html ($node, $uri, $tags)
{
    global $twig;
    $html = '';
    
    if ($tags['spdx-license'])
        $html .= spdx_license ($uri);
    
    if ($tags['fsd'])
        $html .= fsd_software ($uri);
    
    return $twig->render (
        'node.twig',
        [ 'node' => $node, 'content' => $html ]
    );
}





