const DEFAULT_EXTENSIONS_REPOSITORY = 'https://civicrm.org/extdir/ver={ver}|cms={uf}';
/**
- * @param string $repoUrl URL of the remote repository
- * @param string $indexPath relative path of the 'index' file within the repository
- * @param string $cacheDir local path in which to cache files
+ * @param string $repoUrl
+ * URL of the remote repository.
+ * @param string $indexPath
+ * Relative path of the 'index' file within the repository.
+ * @param string $cacheDir
+ * Local path in which to cache files.
*/
public function __construct($repoUrl, $indexPath, $cacheDir) {
$this->repoUrl = $repoUrl;
$this->cacheDir = $cacheDir;
$this->indexPath = $indexPath;
- if ($cacheDir && !file_exists($cacheDir) && is_dir(dirname($cacheDir)) && is_writeable(dirname($cacheDir))) {
+ if ($cacheDir && !file_exists($cacheDir) && is_dir(dirname($cacheDir)) && is_writable(dirname($cacheDir))) {
CRM_Utils_File::createDir($cacheDir, FALSE);
}
}
return $this->repoUrl;
}
+ /**
+ * Refresh the cache of remotely-available extensions.
+ */
public function refresh() {
$file = $this->getTsPath();
if (file_exists($file)) {
/**
* Determine whether downloading is supported
*
- * @return array list of error messages; empty if OK
+ * @return array
+ * List of error messages; empty if OK.
*/
public function checkRequirements() {
if (!$this->isEnabled()) {
$errors = array();
- if (!$this->cacheDir || !is_dir($this->cacheDir) || !is_writeable($this->cacheDir)) {
+ if (!$this->cacheDir || !is_dir($this->cacheDir) || !is_writable($this->cacheDir)) {
$civicrmDestination = urlencode(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'));
$url = CRM_Utils_System::url('civicrm/admin/setting/path', "reset=1&civicrmDestination=${civicrmDestination}");
$errors[] = array(
1 => $this->cacheDir,
2 => $url,
)
- )
+ ),
);
}
/**
* Get a list of all available extensions
*
- * @return array ($key => CRM_Extension_Info)
+ * @return array
+ * ($key => CRM_Extension_Info)
*/
public function getExtensions() {
if (!$this->isEnabled() || count($this->checkRequirements())) {
/**
* Get a description of a particular extension
*
- * @param $key
+ * @param string $key
+ * Fully-qualified extension name.
*
* @return CRM_Extension_Info|NULL
*/
$exts = $this->getExtensions();
if (array_key_exists($key, $exts)) {
return $exts[$key];
- } else {
+ }
+ else {
// throw new CRM_Extension_Exception("Unknown remote extension: $key");
return NULL;
}
* @throws CRM_Extension_Exception_ParseException
*/
private function _discoverRemote() {
- $tsPath = $this->getTsPath();
+ $tsPath = $this->getTsPath();
$timestamp = FALSE;
if (file_exists($tsPath)) {
* @return array
*/
private function grabCachedKeyList() {
- $result = array();
+ $result = array();
$cachedPath = $this->cacheDir . DIRECTORY_SEPARATOR;
- $files = scandir($cachedPath);
+ $files = scandir($cachedPath);
foreach ($files as $dc => $fname) {
if (substr($fname, -4) == '.xml') {
$result[] = array('key' => substr($fname, 0, -4));
ini_set('allow_url_fopen', 1);
}
- if(FALSE === $this->getRepositoryUrl()) {
+ if (FALSE === $this->getRepositoryUrl()) {
// don't check if the user has configured civi not to check an external
// url for extensions. See CRM-10575.
CRM_Core_Session::setStatus(ts('Not checking remote URL for extensions since ext_repo_url is set to false.'), ts('Check Settings'), 'alert');
list ($status, $extdir) = CRM_Utils_HttpClient::singleton()->get($this->getRepositoryUrl() . $this->indexPath);
if ($extdir === FALSE || $status !== CRM_Utils_HttpClient::STATUS_OK) {
CRM_Core_Session::setStatus(ts('The CiviCRM public extensions directory at %1 could not be contacted - please check your webserver can make external HTTP requests or contact CiviCRM team on <a href="http://forum.civicrm.org/">CiviCRM forum</a>.<br />', array(1 => $this->getRepositoryUrl())), ts('Connection Error'), 'error');
- } else {
+ }
+ else {
$lines = explode("\n", $extdir);
foreach ($lines as $ln) {
// CRM-13141 There may not be any compatible extensions available for the requested CiviCRM version + CMS. If so, $extdir is empty so just return a notification.
if (empty($exts)) {
$config = CRM_Core_Config::singleton();
- CRM_Core_Session::setStatus(ts('There are currently no extensions on the CiviCRM public extension directory which are compatible with version %2 (<a href="%1">requested extensions from here</a>). If you want to install an extension which is not marked as compatible, you may be able to <a href="%3">download and install extensions manually</a> (depending on access to your web server).<br />', array(1 => $this->getRepositoryUrl(), 2 => $config->civiVersion, 3 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Extensions')), ts('No Extensions Available for this Version'), 'info');
+ CRM_Core_Session::setStatus(ts('There are currently no extensions on the CiviCRM public extension directory which are compatible with version %2 (<a href="%1">requested extensions from here</a>). If you want to install an extension which is not marked as compatible, you may be able to <a href="%3">download and install extensions manually</a> (depending on access to your web server).<br />', array(
+ 1 => $this->getRepositoryUrl(),
+ 2 => $config->civiVersion,
+ 3 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Extensions',
+ )), ts('No Extensions Available for this Version'), 'info');
}
ini_restore('allow_url_fopen');
* Given the key, retrieves the info XML from a remote server
* and stores locally, returning the contents.
*
- * @access public
+ * @param string $key
+ * Extension key.
+ * @param bool $cached
+ * Whether to use cached data.
*
- * @param string $key extension key
- * @param boolean $cached whether to use cached data
- *
- * @return contents of info.xml, or null if info.xml cannot be retrieved or parsed
+ * @return string
+ * Contents of info.xml, or null if info.xml cannot be retrieved or parsed.
*/
private function grabRemoteInfoFile($key, $cached = FALSE) {
$filename = $this->cacheDir . DIRECTORY_SEPARATOR . $key . '.xml';
- $url = $this->getRepositoryUrl() . '/' . $key . '.xml';
+ $url = $this->getRepositoryUrl() . '/' . $key . '.xml';
if (!$cached || !file_exists($filename)) {
$fetchStatus = CRM_Utils_HttpClient::singleton()->fetch($url, $filename);
* @return string
*/
private function getTsPath() {
- return $this->cacheDir . DIRECTORY_SEPARATOR . 'timestamp.txt';
+ return $this->cacheDir . DIRECTORY_SEPARATOR . 'timestamp.txt';
}
/**
* A dummy function required for suppressing download errors
*/
public static function downloadError($errorNumber, $errorString) {
- return;
}
}
public $relUrls = FALSE;
/**
- * @param string $baseDir local path to the container
- * @param string $baseUrl public URL of the container
+ * @param string $baseDir
+ * Local path to the container.
+ * @param string $baseUrl
+ * Public URL of the container.
* @param CRM_Utils_Cache_Interface $cache
- * @param string $cacheKey unique name for this container
+ * Cache in which to store extension metadata.
+ * @param string $cacheKey
+ * Unique name for this container.
*/
public function __construct($baseDir, $baseUrl, CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) {
$this->cache = $cache;
* {@inheritdoc}
*/
public function getResUrl($key) {
- if (! $this->baseUrl) {
+ if (!$this->baseUrl) {
CRM_Core_Session::setStatus(
ts('Failed to determine URL for extension (%1). Please update <a href="%2">Resource URLs</a>.',
array(
/**
* Determine the relative path of an extension directory
*
- * @param $key
+ * @param string $key
+ * Extension name.
*
* @throws CRM_Extension_Exception_MissingException
* @return string
/**
* Scan $basedir for a list of extension-keys
*
- * @return array($key => $relPath)
+ * @return array
+ * ($key => $relPath)
*/
protected function getRelPaths() {
if (!is_array($this->relPaths)) {
$relPath = CRM_Utils_File::relativize(dirname($infoPath), $this->baseDir);
try {
$info = CRM_Extension_Info::loadFromFile($infoPath);
- } catch (CRM_Extension_Exception_ParseException $e) {
+ }
+ catch (CRM_Extension_Exception_ParseException $e) {
CRM_Core_Session::setStatus(ts('Parse error in extension: %1', array(
1 => $e->getMessage(),
)), '', 'error');
/**
* Determine the relative path of an extension directory
*
- * @param $key
+ * @param string $key
+ * Extension name.
*
* @throws CRM_Extension_Exception_MissingException
* @return string
/**
* Scan $basedir for a list of extension-keys
*
- * @return array($key => $relUrl)
+ * @return array
+ * ($key => $relUrl)
*/
protected function getRelUrls() {
if (DIRECTORY_SEPARATOR == '/') {
* Note: Treat as private. This is only public to facilitate testing.
*
* @param string $dirSep
- * @param array $relPaths ($key => $relPath)
- * @return array($key => $relUrl)
+ * Directory separator ("/" or "\").
+ * @param array $relPaths
+ * Array($key => $relPath).
+ * @return array
+ * Array($key => $relUrl).
*/
public static function convertPathsToUrls($dirSep, $relPaths) {
$relUrls = array();