<commit_before><?php
namespace Chamilo\Libraries\Format\Utilities;

/**
 * $Id: resource_manager.class.php 128 2009-11-09 13:13:20Z vanpouckesven $
 * 
 * @package common
 */
/**
 * Manages resources, ensuring that they are only loaded when necessary.
 * Currently only relevant for JavaScript and CSS
 * files.
 * 
 * @author <NAME>
 * @package common
 */
class ResourceManager
{

    private static $instance;

    private $resources;

    private function __construct()
    {
        $this->resources = array();
    }

    public function get_resources()
    {
        return $this->resources;
    }

    public function resource_loaded($path)
    {
        // return false;
        return in_array($path, $this->resources);
    }

    public function get_resource_html($path)
    {
        if ($this->resource_loaded($path))
        {
            return '';
        }
        else
        {
            $this->resources[] = $path;
            return $this->_get_resource_html($path);
        }
    }

    private function _get_resource_html($path)
    {
        $matches = array();
        preg_match('/[^.]*$/', $path, $matches);
        $extension = $matches[0];
        switch (strtolower($extension))
        {
            case 'css' :
                return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars($path) . '"/>';
            case 'js' :
                return '<script type="text/javascript" src="' . htmlspecialchars($path) . '"></script>';
            default :
                die('Unknown resource type: ' . $path);
        }
    }

    /**
     *
     * @return ResourceManager
     */
    public static function get_instance()
    {
        if (! isset(self :: $instance))<commit_msg>[ResourceManagement] Added a timestamp to the loaded resources<commit_after><?php
namespace Chamilo\Libraries\Format\Utilities;

/**
 * $Id: resource_manager.class.php 128 2009-11-09 13:13:20Z vanpouckesven $
 * 
 * @package common
 */
use Chamilo\Libraries\File\Path;

/**
 * Manages resources, ensuring that they are only loaded when necessary.
 * Currently only relevant for JavaScript and CSS
 * files.
 * 
 * @author <NAME>
 * @package common
 */
class ResourceManager
{

    private static $instance;

    private $resources;

    private function __construct()
    {
        $this->resources = array();
    }

    public function get_resources()
    {
        return $this->resources;
    }

    public function resource_loaded($path)
    {
        // return false;
        return in_array($path, $this->resources);
    }

    public function get_resource_html($path)
    {
        if ($this->resource_loaded($path))
        {
            return '';
        }
        else
        {
            $this->resources[] = $path;
            return $this->_get_resource_html($path);
        }
    }

    private function _get_resource_html($path)
    {
        $pathUtil = Path::getInstance();

        $webPath = $pathUtil->getBasePath(true);
        $basePath = $pathUtil->getBasePath();

        $systemPath = str_replace($webPath, $basePath, $path);
        $modificationTime = filemtime($systemPath);

        $matches = array();
        preg_match('/[^.]*$/', $path, $matches);
        $extension = $matches[0];
        switch (strtolower($extension))
        {
            case 'css' :
                return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars($path) . '?' . $modificationTime . '"/>';
            case 'js' :
                return '<script type="text/javascript" src="' . htmlspecialchars($path) . '?' . $modificationTime . '"></script>';
            default :
                die('Unknown resource type: ' . $path);
        }
    }

    /**
     *
     * @return ResourceManager
     */
    public static function get_instance()
    {
        if (! isset(self :: $instance))
{'fraction_non_alphanumeric': 0.13921415560759823, 'fraction_numerical': 0.00936768149882904, 'mean_word_length': 2.1201298701298703, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6984947', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1073, 'n_words': 244}