From 5d3e1971edc6ab314947c42f32e2d3df3444404f Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sat, 2 Sep 2023 01:25:27 -0600 Subject: Removed feeds and micropub support --- .htaccess | 10 ---- lib/functions.php | 138 -------------------------------------------- snippets/footer.snippet.php | 2 - snippets/header.snippet.php | 7 --- templates/postform.inc.php | 2 - templates/single.inc.php | 7 --- 6 files changed, 166 deletions(-) diff --git a/.htaccess b/.htaccess index c63c0cd..adaefdc 100644 --- a/.htaccess +++ b/.htaccess @@ -1,9 +1,3 @@ -AddCharset UTF-8 .xml -AddCharset UTF-8 .json - -AddType application/atom+xml .xml -AddType application/json .json - Order allow,deny @@ -18,10 +12,6 @@ AddType application/json .json RewriteEngine On RewriteBase / -# friendly URLs -RewriteRule ^feed/json/?$ feed/feed.json [L] -RewriteRule ^feed/atom/?$ feed/feed.xml [L] - RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php [L] diff --git a/lib/functions.php b/lib/functions.php index 608d473..70bbe17 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -459,144 +459,6 @@ function filter_tags($html) { return strip_tags($html, $allowed); } -/* function that pings the official micro.blog endpoint for feed refreshes */ -function ping_microblog() { - global $config; - $ping_url = 'https://micro.blog/ping'; - $feed_url = $config['url'].'/feed/json'; - - $ch = curl_init($ping_url); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, 'url='.urlencode($feed_url)); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_NOBODY, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - $response = curl_exec($ch); - $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - return ($status == 200) ? true : false; -} - -function rebuild_feeds($amount=10) { - - $posts = db_select_posts(NOW+60, $amount, 'desc'); - - rebuild_json_feed($posts); - rebuild_atom_feed($posts); -} - -function rebuild_json_feed($posts=[]) { - global $config; - - if (!file_exists(ROOT.DS.'feed')) { - mkdir(ROOT.DS.'feed', 0755); - } - - $filename = ROOT.DS.'feed'.DS.'feed.json'; - - $feed = array( - 'version' => 'https://jsonfeed.org/version/1', - 'title' => 'status updates by '.$config['microblog_account'], - 'description' => '', - 'home_page_url' => $config['url'], - 'feed_url' => $config['url'].'/feed/feed.json', - 'user_comment' => '', - 'favicon' => '', - 'author' => array('name' => $config['microblog_account']), - 'items' => array() - ); - - $post_ids = array_column($posts, 'id'); - $attached_files = db_get_attached_files($post_ids); - - foreach($posts as $post) { - - // $attachments = db_get_attached_files($post['id']); - $attachments = !empty($attached_files[$post['id']]) ? $attached_files[$post['id']] : []; - $post_attachments = []; - if(!empty($attachments)) { - foreach ($attachments as $a) { - $post_attachments[] = [ - 'url' => $config['url'] .'/'. get_file_path($a), - 'mime_type' => $a['file_mime_type'], - 'size_in_bytes' => $a['file_size'] - ]; - } - } - - $post_images = array_filter($post_attachments, function($v) { - return strpos($v['mime_type'], 'image') === 0; - }); - - $feed['items'][] = array( - 'id' => ($post['post_guid'] ? 'urn:uuid:'.$post['post_guid'] : $config['url'].'/'.$post['id']), - 'url' => $config['url'].'/'.$post['id'], - 'title' => '', - 'content_html' => $post['post_content'], - 'date_published' => gmdate('Y-m-d\TH:i:s\Z', $post['post_timestamp']), - 'image' => !empty($post_images) ? $post_images[0]['url'] : '', - 'attachments' => $post_attachments - ); - } - - if(file_put_contents($filename, json_encode($feed, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES))) { - return true; - } else return false; -} - -function rebuild_atom_feed($posts=[]) { - global $config; - - if (!file_exists(ROOT.DS.'feed')) { - mkdir(ROOT.DS.'feed', 0755); - } - - $filename = ROOT.DS.'feed'.DS.'feed.xml'; - - $feed = ''.NL; - $feed .= ''.NL; - $feed .= ''.$config['microblog_account'].''.NL; - $feed .= 'status updates by '.$config['microblog_account'].''.NL; - $feed .= ''.$config['url'].''.NL; - $feed .= ''.gmdate('Y-m-d\TH:i:s\Z').''.NL; - - $post_ids = array_column($posts, 'id'); - $attached_files = db_get_attached_files($post_ids); - - foreach($posts as $post) { - - $post_images = !empty($attached_files[$post['id']]) ? $attached_files[$post['id']] : []; - - $published = gmdate('Y-m-d\TH:i:s\Z', $post['post_timestamp']); - $updated = ($post['post_edited'] > $post['post_timestamp']) ? gmdate('Y-m-d\TH:i:s\Z', $post['post_edited']) : $published; - - $feed .= ''.NL; - $feed .= ''.date('Y-m-d H:i', $post['post_timestamp']).''.NL; - $feed .= ''.NL; - $feed .= ''.($post['post_guid'] ? 'urn:uuid:'.$post['post_guid'] : $config['url'].'/'.$post['id']).''.NL; - $feed .= ''.$updated.''.NL; - $feed .= ''.$published.''.NL; - - if(!empty($post_images)) { - // todo: render attached images - $feed .= ''.$post['post_content'].''.NL; - } else { - $feed .= ''.$post['post_content'].''.NL; - } - - $feed .= ''.NL; - } - - $feed .= ''; - - if(file_put_contents($filename, $feed)) { - return true; - } else return false; -} - function uuidv4($data = null) { // https://stackoverflow.com/a/15875555/3625228 $data = $data ?? openssl_random_pseudo_bytes(16); diff --git a/snippets/footer.snippet.php b/snippets/footer.snippet.php index e595781..397c2fb 100644 --- a/snippets/footer.snippet.php +++ b/snippets/footer.snippet.php @@ -1,8 +1,6 @@