瀏覽代碼

Version 1.4.0: Fix Markdown and custom fields

trendschau 4 年之前
父節點
當前提交
0ef48e831a
共有 2 個文件被更改,包括 36 次插入22 次删除
  1. 11 16
      system/Controllers/MetaApiController.php
  2. 25 6
      system/Extensions/ParsedownExtension.php

+ 11 - 16
system/Controllers/MetaApiController.php

@@ -124,7 +124,7 @@ class MetaApiController extends ContentController
 				$metadata[$tabname][$fieldname] = isset($pagemeta[$tabname][$fieldname]) ? $pagemeta[$tabname][$fieldname] : null;
 
 				# special treatment for customfields
-				if(isset($fielddefinitions['type']) && ($fielddefinitions['type'] == 'customfields' ) )
+				if(isset($fielddefinitions['type']) && ($fielddefinitions['type'] == 'customfields' ) && isset($metadata[$tabname][$fieldname]) )
 				{
 					# loop through the customdata
 					foreach($metadata[$tabname][$fieldname] as $key => $value)
@@ -132,17 +132,10 @@ class MetaApiController extends ContentController
 						# and make sure that arrays are transformed back into strings
 						if(isset($value['value']) && is_array($value['value']))
 						{
-							$valuestring = implode('\n',$value['value']);
-							$metadata[$tabname][$fieldname][$key]['value'] = $valuestring;
+							$valuestring = implode(PHP_EOL . '- ', $value['value']);
+							$metadata[$tabname][$fieldname][$key]['value'] = '- ' . $valuestring;
 						}
 					}
-					/*
-					echo 'fielddefinition: <pre>';
-					print_r($fielddefinitions);
-					echo '</pre>metadata: <pre>';
-					print_r($pagemeta[$tabname][$fieldname]);
-					die();
-					*/
 				}
 			}
 		}
@@ -231,20 +224,22 @@ class MetaApiController extends ContentController
 					$errors[$tab][$fieldName] = $result[$fieldName][0];
 				}
 
-				# special treatment for customfields 
+				# special treatment for customfields: if data is array, then lists wil transformed into array. 
 				if($fieldDefinition && isset($fieldDefinition['type']) && ($fieldDefinition['type'] == 'customfields' ) && isset($fieldDefinition['data']) && ($fieldDefinition['data'] == 'array' )  )
 				{
 					foreach($fieldValue as $key => $valuePair)
 					{
 						if(isset($valuePair['value']))
 						{
-							$arrayValues = explode(PHP_EOL,$valuePair['value']);
-							echo '<pre>';
-							print_r($arrayValues);
+							$arrayValues = explode(PHP_EOL . '- ',$valuePair['value']);
+							if(count($arrayValues) > 1)
+							{
+								$arrayValues = array_map(function($item) { return trim($item, '- '); }, $arrayValues);
+								$metaInput[$fieldName][$key]['value'] = $arrayValues;
+							}
 						}
 					}
-					die();
-				}	
+				}
 			}
 		}
 

+ 25 - 6
system/Extensions/ParsedownExtension.php

@@ -775,8 +775,15 @@ class ParsedownExtension extends \ParsedownExtra
             if (isset($CurrentBlock['continuable']))
             {
                 $methodName = 'block' . $CurrentBlock['type'] . 'Continue';
+
+/* fix definition list */
+                if($CurrentBlock['type'] == 'DefinitionList' && isset($CurrentBlock['interrupted']))
+                {
+                    $mdCurrentBlock = $mdCurrentBlock . "\n\n";
+                }
+
                 $Block = $this->$methodName($Line, $CurrentBlock);
-                
+
                 # if this line still belongs to the current multiline block
                 if (isset($Block))
                 {
@@ -795,7 +802,7 @@ class ParsedownExtension extends \ParsedownExtra
 /*new*/                 $mdCurrentBlock = $mdCurrentBlock;
                     }
                 }
-            }
+            }                
 
             # ~
 
@@ -815,11 +822,19 @@ class ParsedownExtension extends \ParsedownExtra
 
             #
             # ~
-
             foreach ($blockTypes as $blockType)
             {
                 $Block = $this->{"block$blockType"}($Line, $CurrentBlock);
-/*new*/         $mdBlock = $line;
+
+/* new */       $mdBlock = $line;
+
+/* dirty fix for tables and definition lists, not sure why this happens */     
+                if ( ($blockType == "Table" OR $blockType == "DefinitionList") && isset($mdCurrentBlock) ) 
+                {
+                   $mdBlock = $mdCurrentBlock . "\n" . $line;
+                }
+/* fix end */
+
                 if (isset($Block))
                 {
                     $Block['type'] = $blockType;
@@ -841,6 +856,7 @@ class ParsedownExtension extends \ParsedownExtra
 
                     $CurrentBlock = $Block;
 /*new*/             $mdCurrentBlock = $mdBlock;
+ 
                     continue 2;
                 }
             }
@@ -885,14 +901,17 @@ class ParsedownExtension extends \ParsedownExtra
         # ~
 
         if (isset($CurrentBlock))
-        {
+        {            
             $Elements[] = $this->extractElement($CurrentBlock);
 /*new*/     $mdElements[] = $mdCurrentBlock;
         }
 
         # ~
+/*        echo '<pre>';
+        print_r($mdElements);
+        die();
 /*new*/ return $mdElements;
-#        return $Elements;
+#       return $Elements;
     }