' .'' // optionally specify feed generator for debugging purposes. .'PHP feed generator by jasm1nii.xyz | last modified by the 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'); $f = 0; foreach ($feed_updated as $feed_updated_text) { $feed_datetime = $feed_updated_text->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(++$f > 0) break; } // if no RFC 3339 timestamp is found, use the file creation date. if (empty($feed_updated)) { $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 ''; // title $title = $article_dom->getElementsByTagName('h2'); foreach ($title as $title_text) { echo ''.$title_text->nodeValue.''; } // id echo 'https://jasm1nii.xyz/blog/articles/' . ltrim($article, $blog_root) . ''; // alternate link echo ''; $updated = $article_dom->getElementsByTagName('time'); $a = 0; foreach ($updated as $updated_text) { $timestamp = $updated_text->getAttribute('datetime'); if (strlen($timestamp) == 10) { echo '' . $timestamp . 'T00:00:00' . date('P'). ''; } elseif (strlen($timestamp) == 25 || strlen($timestamp) == 20) { echo '' . $timestamp .''; } if(++$a > 0) break; } // if no RFC 3339 timestamp is found, use the file creation date. if (empty($updated)) { $article_created = filectime($article); echo '' . date(DATE_ATOM, $article_created) . ''; } // summary $x = new DOMXPath($article_dom); $summary_class = 'p-summary'; $summary = $x->query("//*[@class='" . $summary_class . "']"); if ($summary->length > 0) { echo ''; echo $summary->item(0)->nodeValue; echo ''; } // 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>)' . ''; } else { // fallback for older markup $content_class = 'entry'; $content = $x->query("//*[@class='" . $content_class . "']"); if ($content->length >= 0) { echo '' . 'whoops - this page contains markup that can't be parsed for feed-reader friendliness. read more 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); ?>