Markdown::autoCheckBlogProps PHP Method

autoCheckBlogProps() private method

自动获取未填写的属性
private autoCheckBlogProps ( $blogProp )
    private function autoCheckBlogProps($blogProp)
    {
        $content = $blogProp['content'];
        if (empty($blogProp['title'])) {
            $pattern = '/<h1>(.*?)<\\/h1>/i';
            preg_match($pattern, $content, $matches);
            if (isset($matches[1])) {
                $blogProp['title'] = trim($matches[1]);
            } else {
                $pattern = '/<h2>(.*?)<\\/h2>/si';
                preg_match($pattern, $content, $matches);
                if (isset($matches[1])) {
                    $blogProp['title'] = trim($matches[1]);
                }
            }
        }
        if (empty($blogProp['summary'])) {
            $pattern = "/<p>(.{50,600})<\\/p>/i";
            preg_match($pattern, $content, $matches);
            if (isset($matches[1])) {
                $blogProp['summary'] = trim($matches[1]);
            }
            if (empty($blogProp['summary'])) {
                $blogProp['summary'] = $blogProp['title'];
            }
        }
        if (empty($blogProp['images'])) {
            $pattern = '/<img.*?src="(.*?)".*?>/i';
            preg_match_all($pattern, $content, $matches);
            if (isset($matches[1])) {
                $blogProp['images'] = $matches[1];
            }
        }
        if (empty($blogProp['author'])) {
            $blogProp['author'] = "admin";
        }
        return $blogProp;
    }