Browse Source

Installation de plugins depuis le Github Leed Market

Simounet 3 years ago
parent
commit
4a0f936b7e

+ 49 - 9
Plugin.class.php

@@ -132,15 +132,7 @@ class Plugin{
             $logger->appendLogs('Téléchargement du plugin...');
             $pluginBaseFolder = str_replace('/', '', self::FOLDER).'/';
             $tempZipName = $pluginBaseFolder.md5(microtime());
-            $context = stream_context_create(
-                    array (
-                        'http' => array (
-                            'follow_location' => true,
-                            'user_agent' => $_SERVER['HTTP_USER_AGENT']
-                        )
-                    )
-                );
-            file_put_contents($tempZipName,file_get_contents(urldecode($url)), false, $context);
+            file_put_contents($tempZipName,file_get_contents(urldecode($url)), false, self::getContext());
             if(file_exists($tempZipName)){
                 $logger->appendLogs('Plugin téléchargé <span class="label label-success">OK</span>');
                 $logger->appendLogs('Extraction du plugin...');
@@ -195,6 +187,54 @@ class Plugin{
         }
     }
 
+    public function getGithubMarketRepos() {
+        header('Content-Type: application/json');
+        echo json_encode($this->getGithubMarketReposInfos($this->getGithubMarketReposList()));
+    }
+
+    protected function getGithubMarketReposList() {
+        return json_decode(file_get_contents('https://api.github.com/orgs/Leed-market/repos', false, $this->getContext()));
+    }
+
+    protected function getGithubMarketReposInfos($repos) {
+        $infos = array();
+        $installedPluginsNames = $this->getInstalledPluginsNames();
+        foreach($repos as $repo) {
+            $repoName = $repo->name;
+            if(!in_array(strtolower($repoName), $installedPluginsNames)) {
+                $infos[] = array(
+                    'name' => $repoName,
+                    'description' => $repo->description,
+                    'zipUrl' => 'https://github.com/'.$repo->full_name.'/archive/'.$repo->default_branch.'.zip'
+                );
+            }
+        }
+        return $infos;
+    }
+
+    protected function getInstalledPluginsNames() {
+        $names = array();
+        $installedPlugins = self::getAll();
+        if(!$installedPlugins || empty($installedPlugins)) {
+            return $names;
+        }
+        foreach($installedPlugins as $installedPlugin) {
+            $names[] = strtolower($installedPlugin->getName());
+        }
+        return $names;
+    }
+
+    protected static function getContext() {
+        return stream_context_create(
+                array (
+                    'http' => array (
+                        'follow_location' => true,
+                        'user_agent' => $_SERVER['HTTP_USER_AGENT']
+                    )
+                )
+            );
+    }
+
     public static function addHook($hookName, $functionName) {
         $GLOBALS['hooks'][$hookName][] = $functionName;
     }

+ 4 - 0
action.php

@@ -557,6 +557,10 @@ switch ($action){
     case 'installPlugin':
         Plugin::install($_['zip']);
     break;
+    case 'getGithubMarket':
+        $plugin = new Plugin();
+        $plugin->getGithubMarketRepos();
+    break;
 }
 
 

+ 32 - 0
templates/marigolds/js/script.js

@@ -179,6 +179,38 @@ function toggleTab(el){
     if(tab==='market'){
         $('#btnSearchPlugin').trigger("click");
     }
+    if(tab==='installation'){
+        var ghZoneClass = 'gh-leed-market';
+        var ghZone = $('.'+ghZoneClass);
+        if(ghZone.length === 0){
+            ghZone = $('<div class="gh-leed-market">'+_t('LOADING')+'</div>');
+            ghZone.appendTo('[data-zone=installation]');
+        }
+        $.ajax({
+            url: 'action.php?action=getGithubMarket'
+        })
+            .done(function(data) {
+                if(data.length > 0){
+                var tpl = '<h3>'+_t('PLUGINS_INSTALL_FROM_GITHUB_LEED_MARKET')+'</h3>';
+                    tpl += '<ul>';
+                    for(i=0;i<data.length;i++){
+                        var plugin = data[i];
+                        tpl +=
+                        '<li>'+
+                            '<ul>'+
+                                '<li><h4>Nom: </h4>'+plugin.name+'</li>'+
+                                '<li>'+plugin.description+'</li>'+
+                                '<li><button class="btn" onclick="installPlugin(\''+plugin.zipUrl+'\',$(this).parent());">Installer</button></li>'+
+                            '</ul>'+
+                        '</li>';
+                    }
+                    tpl += '</ul>';
+                    ghZone.html(tpl);
+                } else {
+                    ghZone.remove();
+                }
+            });
+    }
 }
 
 function searchPlugin(keyword){

File diff suppressed because it is too large
+ 1 - 0
templates/marigolds/locale/en.json


File diff suppressed because it is too large
+ 1 - 0
templates/marigolds/locale/eo.json


File diff suppressed because it is too large
+ 1 - 0
templates/marigolds/locale/es.json


File diff suppressed because it is too large
+ 1 - 0
templates/marigolds/locale/fr.json