' .'' // optionally specify feed generator for debugging purposes. .'PHP feed generator by jasm1nii.xyz | Last modified by system at ' . strtoupper(date("h:i:sa")) . ' (GMT' . date('P') . ')' .'' . $feed_title . '' .'' . $feed_subtitle . '' .'' . $blog_url . '' .'' .''; // force libxml to parse all HTML elements, including HTML 5. by default, the extension can only read valid HTML 4. libxml_use_internal_errors(true); // match feed update time with the newest entry. $article_list = glob($blog_entries); $first_article = array_pop($article_list); $first_article_content = file_get_contents($first_article); $first_article_dom = new DOMDocument; $first_article_dom->loadHTML($first_article_content); $feed_updated = $first_article_dom->getElementsByTagName('time'); if (!empty($feed_updated)) { $feed_datetime = $feed_updated[0]->getAttribute('datetime'); if (strlen($feed_datetime) == 10) { echo '' . $feed_datetime . 'T00:00:00' . date('P') .''; } elseif (strlen($feed_datetime) == 25 || strlen($feed_datetime) == 20) { echo '' . $feed_datetime .''; } // if no RFC 3339 timestamp is found, use the file creation date. } else { $first_article_created = filectime($first_article); echo '' . date(DATE_ATOM, $first_article_created) . ''; } // rest of the template. echo '' .'' . $author_name . '' .'' . $author_email . '' .'' . $author_homepage . '' .'' .'' . $feed_icon . '' .'' . $feed_logo . ''; // output entries. $i = 0; foreach (array_reverse(glob($blog_entries)) as $article) { $article_content = file_get_contents($article); $article_dom = new DOMDocument; $article_dom->loadHTML($article_content); echo ''; $x = new DOMXPath($article_dom); // title $title_class = 'p-name'; $title = $x->query("//*[@class='" . $title_class . "']"); if ($title->length > 0) { echo ''. $title[0]->nodeValue . ''; } elseif (!empty($title)) { $title = $article_dom->getElementsByTagName('h2'); echo ''.$title[0]->nodeValue.''; } else { echo $feed_title; } // id echo 'https://jasm1nii.xyz/blog/articles/' . ltrim($article, $blog_root) . ''; // alternate link echo ''; $updated = $article_dom->getElementsByTagName('time'); if (!empty($updated)) { $timestamp = $updated[0]->getAttribute('datetime'); if (strlen($timestamp) == 10) { echo '' . $timestamp . 'T00:00:00' . date('P'). ''; } elseif (strlen($timestamp) == 25 || strlen($timestamp) == 20) { echo '' . $timestamp .''; } } else { $article_created = filectime($article); echo '' . date(DATE_ATOM, $article_created) . ''; } // summary $summary_class = 'p-summary'; $summary = $x->query("//*[@class='" . $summary_class . "']"); if ($summary->length > 0) { echo ''; echo $summary->item(0)->nodeValue; echo ''; } else { echo '' . 'A summary of this content is not available.' . ''; } // content $content_class = 'e-content'; $content = $x->query("//*[@class='" . $content_class . "']"); if ($content->length > 0) { // strip line breaks and output a maximum of 500 characters. echo '' . preg_replace('/\s\s+/', ' ',(substr($content->item(0)->nodeValue,0,500))) . '... (<a href="https://jasm1nii.xyz/blog/articles/' . ltrim($article, $blog_root) . '">read more</a>)' . ''; } elseif (!empty($content)) { $content = $article_dom->getElementsByTagName('article'); echo '' . preg_replace('/\s\s+/', ' ',(substr($content->item(0)->nodeValue,0,500))) . '... (<a href="https://jasm1nii.xyz/blog/articles/' . ltrim($article, $blog_root) . '">read more</a>)' . ''; } else { echo '' . 'Content could not be parsed for previewing - view the original article on the website.' . ''; } echo ''; // add no more than 10 entries. if(++$i > 9) break; } echo ''; $xml_str = ob_get_contents(); ob_end_clean(); file_put_contents($blog_root.'/articles.xml', $xml_str); ?>