浏览代码

Add md support for plugins. The readme file must be README.md in order to load the markdown conversion.

jmontoyaa 8 年之前
父节点
当前提交
dfa2039616
共有 3 个文件被更改,包括 66 次插入20 次删除
  1. 29 14
      main/admin/settings.lib.php
  2. 28 0
      main/inc/ajax/plugin.ajax.php
  3. 9 6
      plugin/vchamilo/README.md

+ 29 - 14
main/admin/settings.lib.php

@@ -190,6 +190,21 @@ function handle_plugins()
                     ]
                 );
             }
+
+            $readmeFile = api_get_path(SYS_PLUGIN_PATH).$plugin.'/README.md';
+            if (file_exists($readmeFile)) {
+                echo Display::url(
+                    "<em class='fa fa-file-text-o'></em> README.md",
+                    api_get_path(WEB_AJAX_PATH).'plugin.ajax.php?a=md_to_html&plugin='.$plugin,
+                    [
+                        'class' => 'btn btn-default ajax',
+                        'data-title' => $plugin_info['title'],
+                        'data-size' => 'lg',
+                        '_target' => '_blank'
+                    ]
+                );
+            }
+
             echo '</div>';
             echo '</td></tr>';
         }
@@ -379,29 +394,29 @@ function handle_stylesheets()
             }
         }
     }
-    
+
     $logoForm = new FormValidator(
         'logo_upload',
         'post',
         'settings.php?category=Stylesheets#tabs-2'
     );
-    
+
     $logoForm->addHtml(Display::return_message(sprintf(get_lang('TheLogoMustBeSizeXAndFormatY'), '250 x 70', 'PNG'), 'info'));
-    
+
     $dir = api_get_path(SYS_PUBLIC_PATH).'css/themes/' . $selected . '/images/';
     $url = api_get_path(WEB_CSS_PATH).'themes/' . $selected . '/images/';
     $logoFileName = 'header-logo.png';
     $newLogoFileName = 'header-logo-custom.png';
-    
+
     if (is_file($dir.$newLogoFileName)) {
-        $logoForm->addLabel(get_lang('CurrentLogo'), '<img id="header-logo-custom" src="'. $url . $newLogoFileName .'?'. time() . '">'); 
+        $logoForm->addLabel(get_lang('CurrentLogo'), '<img id="header-logo-custom" src="'. $url . $newLogoFileName .'?'. time() . '">');
     } else {
         $logoForm->addLabel(get_lang('CurrentLogo'), '<img id="header-logo-custom" src="'. $url . $logoFileName .'?'. time() . '">');
     }
-    
+
     $logoForm->addFile('new_logo', get_lang('UpdateLogo'));
     $allowedFileTypes = ['png'];
-    
+
     if (isset($_POST['logo_reset'])) {
         if (is_file($dir.$newLogoFileName)) {
             unlink($dir.$newLogoFileName);
@@ -411,12 +426,12 @@ function handle_stylesheets()
             . '</script>';
         }
     } elseif (isset($_POST['logo_upload'])) {
-        
+
         $logoForm->addRule('new_logo', get_lang('InvalidExtension').' ('.implode(',', $allowedFileTypes).')', 'filetype', $allowedFileTypes);
         $logoForm->addRule('new_logo', get_lang('ThisFieldIsRequired'), 'required');
-        
+
         if ($logoForm->validate()) {
-            
+
             $imageInfo = getimagesize($_FILES['new_logo']['tmp_name']);
             $width = $imageInfo[0];
             $height = $imageInfo[1];
@@ -424,7 +439,7 @@ function handle_stylesheets()
                 if (is_file($dir.$newLogoFileName)) {
                     unlink($dir.$newLogoFileName);
                 }
-                
+
                 $status = move_uploaded_file($_FILES['new_logo']['tmp_name'], $dir.$newLogoFileName);
 
                 if ($status) {
@@ -449,12 +464,12 @@ function handle_stylesheets()
         ];
 
         $form_change->addGroup($group);
-        
+
         $logoGroup = [
             $logoForm->addButtonUpload(get_lang('Upload'), 'logo_upload', true),
             $logoForm->addButtonCancel(get_lang('Reset'), 'logo_reset', true)
         ];
-        
+
         $logoForm->addGroup($logoGroup);
 
         if ($show_upload_form) {
@@ -470,7 +485,7 @@ function handle_stylesheets()
         } else {
             $form_change->display();
         }
-        
+
         //Little hack to update the logo image in update form when submiting
         if (isset($_POST['logo_reset'])) {
             echo '<script>'

+ 28 - 0
main/inc/ajax/plugin.ajax.php

@@ -0,0 +1,28 @@
+<?php
+/* For licensing terms, see /license.txt */
+use \Michelf\MarkdownExtra;
+
+/**
+ * Responses to AJAX calls
+ */
+
+require_once '../global.inc.php';
+
+$action = $_REQUEST['a'];
+
+switch ($action) {
+    case 'md_to_html':
+        $plugin = isset($_GET['plugin']) ? $_GET['plugin'] : '';
+        $appPlugin = new AppPlugin();
+        $pluginList = $appPlugin->get_installed_plugins();
+        $html = '';
+        if (in_array($plugin, $pluginList)) {
+            $file = api_get_path(SYS_PLUGIN_PATH).$plugin.'/README.md';
+            if (file_exists($file)) {
+                $content = file_get_contents($file);
+                $html = MarkdownExtra::defaultTransform($content);
+            }
+        }
+        echo $html;
+        break;
+}

+ 9 - 6
plugin/vchamilo/readme.txt → plugin/vchamilo/README.md

@@ -1,5 +1,5 @@
 Virtual Chamilo
-##############################
+===================
 
 Author : Valery Fremaux (valery.fremaux@gmail.com), Julio Montoya
 
@@ -7,14 +7,14 @@ Virtual chamilo is a feature that allows running several chamilo instances shari
 code base.
 
 Version features
-##############################
+===================
 This is a yet prototypal version that is not full featured in back-office tools.
 At the moment, the setup of virtual clones still is a technical operation and has no
 middle-office GUI. Development is in progress to offer a sufficient medium-level
 administrability of the process.
 
 How to setup :
-##############################
+===================
 
 You need :
 
@@ -52,12 +52,14 @@ as the chamilo instance domain name.
 the effective "configuration.php" information.
 - an appropriate multiroot home root setup in the local chamilo instance
 
-# Prerequisites for VChamilo working nice
+Prerequisites for VChamilo working nice
+-------------
 
 Multiple URL access must be enabled :
-
+```
 # in <chamiloroot>/main/inc/config/configuration.php
 $_configuration['multiple_access_urls'] = true;
+```
 
 In the administration, you will need configure an adequate home root definition for the instance finding
 the dedicated home directory. You just need editing the http://localhost default host, and give the real domain
@@ -65,7 +67,8 @@ name you are using.
 
 Check you have the <chamilo>/home/<instancedomain> clone of the standard home directory.
 
-# Important note about file system permissions
+Important note about file system permissions
+-------------
 
 Vchamilos will use several side-directories apart from the standard installation (dedicated courses,
 dedicated home page). Check you set the adequate filesystem permissions (usually let the server write