' .'' // 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 ($title->length == 0) { $title = $article_dom->getElementsByTagName('title'); echo ''.$title[0]->nodeValue.''; } else { echo $feed_title; } // id echo '' . $blog_directory_url . '/' . ltrim($article, $blog_root) . ''; // alternate link echo ''; // date updated $updated_class = 'dt-updated'; $updated = $x->query("//*[@class='" . $updated_class . "']"); if ($updated->length > 0) { $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 .''; } } if ($updated->length == 0) { $updated = $article_dom->getElementsByTagName('time'); $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 = filemtime($article); echo '' . date(DATE_ATOM, $article_created) . ''; } } // date published $published_class = 'dt-published'; $published = $x->query("//*[@class='" . $published_class . "']"); if ($published->length > 0) { $timestamp = $published[0]->getAttribute('datetime'); if (strlen($timestamp) == 10) { echo '' . $timestamp . 'T00:00:00' . date('P'). ''; } elseif (strlen($timestamp) == 25 || strlen($timestamp) == 20) { echo '' . $timestamp .''; } } if ($published->length == 0) { $published = $article_dom->getElementsByTagName('time'); $timestamp = $published[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 ''; } elseif($summary->length == 0) { $summary = get_meta_tags($article)['description']; echo ''; echo $summary; 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))) . '... (read more on the original page)' . ''; } elseif (!empty($content)) { $content = $article_dom->getElementsByTagName('article'); echo '' . preg_replace('/\s\s+/', ' ',(substr($content->item(0)->nodeValue,0,500))) . '... (read more on the original page)' . ''; } else { echo '' . 'Content could not be parsed as a preview - view the original article on the website.' . ''; } echo ''; if(++$i > ($max_entries-1)) break; } echo ''; $xml_str = ob_get_contents(); ob_end_clean(); file_put_contents($blog_root . DIRECTORY_SEPARATOR . $file, $xml_str); echo strtoupper(date("h:i:sa")) . ' - Feed successfully generated in ' . realpath($blog_root) . DIRECTORY_SEPARATOR . $file; echo '
Validate your feed at https://validator.w3.org/feed/'; ?>