Просмотр исходного кода

move column parsing into own method and call it only once per request and only for the current page.

Frank Nägler 11 лет назад
Родитель
Сommit
226fed4794
1 измененных файлов с 16 добавлено и 11 удалено
  1. 16 11
      lib/pico.php

+ 16 - 11
lib/pico.php

@@ -60,6 +60,10 @@ class Pico {
 		$meta = $this->read_file_meta($content);
 		$this->run_hooks('file_meta', array(&$meta));
 
+		$this->run_hooks('before_parse_columns', array(&$content, $this->columns));
+		$this->parse_columns($content);
+		$this->run_hooks('after_parse_columns', array(&$content, $this->columns));
+
 		$this->run_hooks('before_parse_content', array(&$content));
 		$content = $this->parse_content($content);
 		$this->run_hooks('after_parse_content', array(&$content));
@@ -131,17 +135,7 @@ class Pico {
 		}
 	}
 
-	/**
-	 * Parses the content using Markdown
-	 *
-	 * @param string $content the raw txt content
-	 * @return string $content the Markdown formatted content
-	 */
-	protected function parse_content($content)
-	{
-		$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
-		$content = str_replace('%base_url%', $this->base_url(), $content);
-
+	protected function parse_columns($content) {
 		// pattern to find {column:xyz} {/column:xyz} column marker
 		$pattern = '#({column:(.*?)})(.+?)({/column:\\2})#ims';
 		preg_match_all($pattern, $content, $matches);
@@ -151,7 +145,18 @@ class Pico {
 			$this->columns[$var] = MarkdownExtra::defaultTransform($matches[3][$counter]);
 			$counter++;
 		}
+	}
 
+	/**
+	 * Parses the content using Markdown
+	 *
+	 * @param string $content the raw txt content
+	 * @return string $content the Markdown formatted content
+	 */
+	protected function parse_content($content)
+	{
+		$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
+		$content = str_replace('%base_url%', $this->base_url(), $content);
 		$content = MarkdownExtra::defaultTransform($content);
 
 		return $content;