Browse Source

NEW Show by default README.md file found into root dir of ext module.

Laurent Destailleur 8 years ago
parent
commit
b5e646daa0

+ 1 - 1
htdocs/admin/modulehelp.php

@@ -338,7 +338,7 @@ if ($mode == 'desc')
     $text.='<br>';
 
     $moduledesclong=$objMod->getDescLong();
-    if ($moduledesclong) $text.='<br><hr><br>'.$moduledesclong.'<br>';
+    if ($moduledesclong) $text.='<br><hr><div class="moduledesclong">'.$moduledesclong.'<div>';
 }
 
 if ($mode == 'feature')

+ 14 - 4
htdocs/core/lib/parsemd.lib.php

@@ -24,12 +24,22 @@
 /**
  * Function to parse MD content into HTML
  *
- * @param	string	  $content			MD content
- * @param   string    $parser           'parsedown' or 'nl2br'
- * @return	string                      Parsed content
+ * @param	string	  $content			    MD content
+ * @param   string    $parser               'parsedown' or 'nl2br'
+ * @param   string    $replaceimagepath     Replace path to image with another path. Exemple: ('doc/'=>'xxx/aaa/')
+ * @return	string                          Parsed content
  */
-function dolMd2Html($content, $parser='parsedown')
+function dolMd2Html($content, $parser='parsedown',$replaceimagepath=null)
 {
+    if (is_array($replaceimagepath))
+    {
+        foreach($replaceimagepath as $key => $val)
+        {
+            $keytoreplace = ']('.$key;
+            $valafter = ']('.$val;
+            $content = preg_replace('/'.preg_quote($keytoreplace,'/').'/m', $valafter, $content);
+        }
+    }
     if ($parser == 'parsedown')
     {
         include DOL_DOCUMENT_ROOT.'/includes/parsedown/Parsedown.php';

+ 50 - 8
htdocs/core/modules/DolibarrModules.class.php

@@ -582,26 +582,68 @@ class DolibarrModules           // Can not be abstract, because we need to insta
     }
 
     /**
-     * Gives the translated module description if translation exists in admin.lang or the default module description
+     * Gives the long description of a module. First check README-la_LA.md then README.md
+     * If not markdown files found, it return translated value of the key ->descriptionlong.
      *
-     * @return  string  Translated module description
+     * @return  string  Long description of a module
      */
     function getDescLong()
     {
         global $langs;
         $langs->load("admin");
         
-        if (empty($this->descriptionlong)) return '';
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
+
+        $filefound= false;
         
-        // If module description translation does not exist using its unique id, we can use its name to find translation
-        if (is_array($this->langfiles))
+        // Define path to file README.md. 
+        // First check README-la_LA.md then README.md
+        $pathoffile = dol_buildpath(strtolower($this->name).'/README-'.$langs->defaultlang.'.md', 0);
+        if (dol_is_file($pathoffile))
         {
-            foreach($this->langfiles as $val)
+            $filefound = true;
+        }
+        if (! $filefound)
+        {
+            $pathoffile = dol_buildpath(strtolower($this->name).'/README.md', 0);
+            if (dol_is_file($pathoffile))
             {
-                if ($val) $langs->load($val);
+                $filefound = true;
             }
         }
-        return $langs->trans($this->descriptionlong);
+        
+        if ($filefound)     // Mostly for external modules
+        {
+            $content = file_get_contents($pathoffile);
+    
+            if ((float) DOL_VERSION >= 6.0)
+            {
+                @include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
+                $content = dolMd2Html($content, 'parsedown', array('doc/'=>dol_buildpath('cabinetmed/doc/', 1)));
+            }
+            else
+            {
+                $content = nl2br($content);
+            }
+        }
+        else                // Mostly for internal modules
+        {
+            if (! empty($this->descriptionlong))
+            {
+                if (is_array($this->langfiles))
+                {
+                    foreach($this->langfiles as $val)
+                    {
+                        if ($val) $langs->load($val);
+                    }
+                }
+            
+                $content = $langs->trans($this->descriptionlong);
+            }
+        }
+    
+        return $content;
     }
     
     /**

+ 7 - 0
htdocs/theme/eldy/style.css.php

@@ -632,6 +632,13 @@ div.myavailability {
 	margin-bottom: 12px;
 }
 
+/* For the long description of module */
+.moduledesclong p img, .moduledesclong p a img {
+    max-width: 90% !important;
+    height: auto !important;
+}
+
+
 /* DOL_XXX for future usage (when left menu has been removed). If we do not use datatable */
 /*.table-responsive {
     width: calc(100% - 330px);

+ 7 - 0
htdocs/theme/md/style.css.php

@@ -640,6 +640,13 @@ div.myavailability {
 	margin-bottom: 12px;
 }
 
+/* For the long description of module */
+.moduledesclong p img,.moduledesclong p a img {
+    max-width: 90% !important;
+    height: auto !important;
+}
+
+
 /* DOL_XXX for future usage (when left menu has been removed). If we do not use datatable */
 /*.table-responsive {
     width: calc(100% - 330px);