Select Git revision
PluginRepository.class.php
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
-
David Siegfried authoredDavid Siegfried authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
PluginRepository.class.php 5.00 KiB
<?php
/*
* PluginRepository.class.php - query plugin meta data
*
* Copyright (c) 2008 Elmar Ludwig
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
/**
* Class used to locate plugins available from a plugin repository.
*/
class PluginRepository
{
/**
* list and meta data of available plugins
*/
private $plugins = [];
/**
* Initialize a new PluginRepository and read meta data from
* the given URL or the default list of URLs (if $url is null).
*/
public function __construct($url = null)
{
if (isset($url)) {
$this->readMetadata($url);
} else {
foreach ($GLOBALS['PLUGIN_REPOSITORIES'] as $url) {
$this->readMetadata($url);
}
}
}
/**
* Read plugin meta data from the given URL (using XML format).
* The structure of the XML is:
*
* <plugins>
* <plugin name="DummyPlugin"
* <release
* version="2.0"
* url="http://plugins.example.com/dummy-2.0.zip"
* studipMinVersion="1.4"
* studipMaxVersion="1.9">
* </plugin>
* [...]
* </plugins>
*
* @param string $url given url for plugin
*/
public function readMetadata($url)
{
$cache = StudipCacheFactory::getCache();
$cache_key = 'plugin_metadata/'.$url;
$metadata = $cache->read($cache_key);
if ($metadata === false) {
// Set small timeout for the rare case that the repository is not
// available
$context = get_default_http_stream_context($url);
stream_context_set_option($context, ['http' => [
'timeout' => 5,
]]);
$metadata = @file_get_contents($url, false, $context);