Sfoglia il codice sorgente

Show existing extensions in admin panel (#1708)

* first draft

* display installed extension state

* fixed whitespace vs tabs

* added translation in all languages

* added error checks and log messages

* fixed tabs vs whitespace

* another try in fixing whitespaces

* another try in fixing whitespaces

* improved extension list translations

* using JSON from official extension repo

* improved version compare

* updated translations

* French translation
Kevin Papst 8 anni fa
parent
commit
3902d3f433

+ 37 - 0
app/Controllers/extensionController.php

@@ -25,10 +25,47 @@ class FreshRSS_extension_Controller extends Minz_ActionController {
 			'user' => array(),
 		);
 
+		$this->view->extensions_installed = array();
+
 		$extensions = Minz_ExtensionManager::listExtensions();
 		foreach ($extensions as $ext) {
 			$this->view->extension_list[$ext->getType()][] = $ext;
+			$this->view->extensions_installed[$ext->getEntrypoint()] = $ext->getVersion();
+		}
+
+		$availableExtensions = $this->getAvailableExtensionList();
+		$this->view->available_extensions = $availableExtensions;
+	}
+
+	/**
+	 * fetch extension list from GitHub
+	 */
+	protected function getAvailableExtensionList() {
+		$extensionListUrl = 'https://raw.githubusercontent.com/FreshRSS/Extensions/master/extensions.json';
+		$json = file_get_contents($extensionListUrl);
+
+		// we ran into problems, simply ignore them
+		if ($json === false) {
+			Minz_Log::error('Could not fetch available extension from GitHub');
+			return array();
+		}
+
+		// fetch the list as an array
+		$list = json_decode($json, true);
+		if (empty($list)) {
+			Minz_Log::warning('Failed to convert extension file list');
+			return array();
 		}
+
+		// we could use that for comparing and caching later
+		$version = $list['version'];
+
+		// By now, all the needed data is kept in the main extension file.
+		// In the future we could fetch detail information from the extensions metadata.json, but I tend to stick with
+		// the current implementation for now, unless it becomes too much effort maintain the extension list manually
+		$extensions = $list['extensions'];
+
+		return $extensions;
 	}
 
 	/**

+ 7 - 0
app/i18n/cz/admin.php

@@ -155,6 +155,13 @@ return array(
 			'help' => '0 znamená žádná omezení účtu',
 			'number' => 'Maximální počet účtů',
 		),
+		'community' => 'Available community extensions', // @todo translate
+		'name' => 'Name', // @todo translate
+		'version' => 'Version', // @todo translate
+		'description' => 'Description', // @todo translate
+		'author' => 'Author', // @todo translate
+		'latest' => 'Installed', // @todo translate
+		'update' => 'Update available', // @todo translate
 	),
 	'update' => array(
 		'_' => 'Aktualizace systému',

+ 7 - 0
app/i18n/de/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => 'Erweiterungen',
 		'user' => 'Benutzer-Erweiterungen',
+		'community' => 'Verfügbare Community Erweiterungen',
+		'name' => 'Name',
+		'version' => 'Version',
+		'description' => 'Beschreibungen',
+		'author' => 'Autor',
+		'latest' => 'Installiert',
+		'update' => 'Update verfügbar',
 	),
 	'stats' => array(
 		'_' => 'Statistiken',

+ 7 - 0
app/i18n/en/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => 'Extensions',
 		'user' => 'User extensions',
+		'community' => 'Available community extensions',
+		'name' => 'Name',
+		'version' => 'Version',
+		'description' => 'Description',
+		'author' => 'Author',
+		'latest' => 'Installed',
+		'update' => 'Update available'
 	),
 	'stats' => array(
 		'_' => 'Statistics',

+ 7 - 0
app/i18n/es/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => 'Extensiones',
 		'user' => 'Extensiones de usuario',
+		'community' => 'Available community extensions', // @todo translate
+		'name' => 'Name', // @todo translate
+		'version' => 'Version', // @todo translate
+		'description' => 'Description', // @todo translate
+		'author' => 'Author', // @todo translate
+		'latest' => 'Installed', // @todo translate
+		'update' => 'Update available', // @todo translate
 	),
 	'stats' => array(
 		'_' => 'Estadísticas',

+ 10 - 3
app/i18n/fr/admin.php

@@ -103,15 +103,22 @@ return array(
 	),
 	'extensions' => array(
 		'disabled' => 'Désactivée',
-		'empty_list' => 'Il n’y a aucune extension installée.',
+		'empty_list' => 'Aucune extension installée',
 		'enabled' => 'Activée',
-		'no_configure_view' => 'Cette extension ne peut pas être configurée.',
+		'no_configure_view' => 'Cette extension n’a pas à être configurée',
 		'system' => array(
 			'_' => 'Extensions système',
-			'no_rights' => 'Extension système (vous n’avez aucun droit dessus)',
+			'no_rights' => 'Extensions système (contrôlées par l’administrateur)',
 		),
 		'title' => 'Extensions',
 		'user' => 'Extensions utilisateur',
+		'community' => 'Extensions utilisateur disponibles',
+		'name' => 'Nom',
+		'version' => 'Version',
+		'description' => 'Description',
+		'author' => 'Auteur',
+		'latest' => 'Installée',
+		'update' => 'Mise à jour disponible',
 	),
 	'stats' => array(
 		'_' => 'Statistiques',

+ 7 - 0
app/i18n/it/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => 'Estensioni',
 		'user' => 'Estensioni utente',
+		'community' => 'Available community extensions', // @todo translate
+		'name' => 'Name', // @todo translate
+		'version' => 'Version', // @todo translate
+		'description' => 'Description', // @todo translate
+		'author' => 'Author', // @todo translate
+		'latest' => 'Installed', // @todo translate
+		'update' => 'Update available', // @todo translate
 	),
 	'stats' => array(
 		'_' => 'Statistiche',

+ 7 - 0
app/i18n/kr/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => '확장 기능',
 		'user' => '사용자 확장 기능',
+		'community' => 'Available community extensions', // @todo translate
+		'name' => 'Name', // @todo translate
+		'version' => 'Version', // @todo translate
+		'description' => 'Description', // @todo translate
+		'author' => 'Author', // @todo translate
+		'latest' => 'Installed', // @todo translate
+		'update' => 'Update available', // @todo translate
 	),
 	'stats' => array(
 		'_' => '통계',

+ 7 - 0
app/i18n/nl/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => 'Uitbreidingen',
 		'user' => 'Gebruikersuitbreidingen',
+		'community' => 'Gebruikersuitbreidingen beschikbaar',
+		'name' => 'Naam',
+		'version' => 'Versie',
+		'description' => 'Beschrijving',
+		'author' => 'Auteur',
+		'latest' => 'Geïnstalleerd',
+		'update' => 'Update beschikbaar',
 	),
 	'stats' => array(
 		'_' => 'Statistieken',

+ 7 - 0
app/i18n/pt-br/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => 'Extensões',
 		'user' => 'Extensões do usuário',
+		'community' => 'Available community extensions', // @todo translate
+		'name' => 'Name', // @todo translate
+		'version' => 'Version', // @todo translate
+		'description' => 'Description', // @todo translate
+		'author' => 'Author', // @todo translate
+		'latest' => 'Installed', // @todo translate
+		'update' => 'Update available', // @todo translate
 	),
 	'stats' => array(
 		'_' => 'Estatísticas',

+ 7 - 0
app/i18n/ru/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => 'Расширения',
 		'user' => 'Расширения пользователя',
+		'community' => 'Available community extensions', // @todo translate
+		'name' => 'Name', // @todo translate
+		'version' => 'Version', // @todo translate
+		'description' => 'Description', // @todo translate
+		'author' => 'Author', // @todo translate
+		'latest' => 'Installed', // @todo translate
+		'update' => 'Update available', // @todo translate
 	),
 	'stats' => array(
 		'_' => 'Статистика',

+ 7 - 0
app/i18n/tr/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => 'Eklentiler',
 		'user' => 'Kullanıcı eklentileri',
+		'community' => 'Available community extensions', // @todo translate
+		'name' => 'Name', // @todo translate
+		'version' => 'Version', // @todo translate
+		'description' => 'Description', // @todo translate
+		'author' => 'Author', // @todo translate
+		'latest' => 'Installed', // @todo translate
+		'update' => 'Update available', // @todo translate
 	),
 	'stats' => array(
 		'_' => 'İstatistikler',

+ 7 - 0
app/i18n/zh-cn/admin.php

@@ -112,6 +112,13 @@ return array(
 		),
 		'title' => '扩展',
 		'user' => '用户扩展',
+		'community' => 'Available community extensions', // @todo translate
+		'name' => 'Name', // @todo translate
+		'version' => 'Version', // @todo translate
+		'description' => 'Description', // @todo translate
+		'author' => 'Author', // @todo translate
+		'latest' => 'Installed', // @todo translate
+		'update' => 'Update available', // @todo translate
 	),
 	'stats' => array(
 		'_' => '统计',

+ 35 - 2
app/views/extension/index.phtml

@@ -26,13 +26,46 @@
 		}
 	?>
 	<?php
-		}
+	}
 
-		if (empty($this->extension_list['system']) && empty($this->extension_list['user'])) {
+	if (empty($this->extension_list['system']) && empty($this->extension_list['user'])) {
 	?>
 	<p class="alert alert-warn"><?php echo _t('admin.extensions.empty_list'); ?></p>
 	<?php } ?>
 	</form>
+
+	<?php if (!empty($this->available_extensions)) { ?>
+		<h2><?php echo _t('admin.extensions.community'); ?></h2>
+		<table>
+			<tr>
+				<th><?php echo _t('admin.extensions.name'); ?></th>
+				<th><?php echo _t('admin.extensions.version'); ?></th>
+				<th><?php echo _t('admin.extensions.author'); ?></th>
+				<th><?php echo _t('admin.extensions.description'); ?></th>
+			</tr>
+			<?php foreach ($this->available_extensions as $ext) { ?>
+				<tr>
+					<td><a href="<?php echo $ext['url']; ?>" target="_blank"><?php echo $ext['name']; ?></a></td>
+					<td><?php echo $ext['version']; ?></td>
+					<td><?php echo $ext['author']; ?></td>
+					<td>
+						<?php echo $ext['description']; ?>
+						<?php if (isset($this->extensions_installed[$ext['name']])) { ?>
+							<?php if (version_compare($this->extensions_installed[$ext['name']], $ext['version']) >= 0) { ?>
+								<span class="alert alert-success">
+									<?php echo _t('admin.extensions.latest'); ?>
+								</span>
+							<?php } else  if ($this->extensions_installed[$ext['name']] != $ext['version']) { ?>
+								<span class="alert alert-warn">
+									<?php echo _t('admin.extensions.update'); ?>
+								</span>
+							<?php } ?>
+						<?php } ?>
+					</td>
+				</tr>
+			<?php } ?>
+		</table>
+	<?php } ?>
 </div>
 
 <?php $class = isset($this->extension) ? ' class="active"' : ''; ?>