using_permalinks() ) { global $wp; // If called too early, bail if ( ! isset( $wp->request ) ) { return false; } // Determine path for paginated version of current request if ( false != preg_match( '#' . $wp_rewrite->pagination_base . '/\d+/?$#i', $wp->request ) ) { $path = preg_replace( '#' . $wp_rewrite->pagination_base . '/\d+$#i', $wp_rewrite->pagination_base . '/%d', $wp->request ); } else { $path = $wp->request . '/' . $wp_rewrite->pagination_base . '/%d'; } // Slashes everywhere we need them if ( 0 !== strpos( $path, '/' ) ) $path = '/' . $path; $path = user_trailingslashit( $path ); } else { // Clean up raw $_REQUEST input $path = array_map( 'sanitize_text_field', $_REQUEST ); $path = array_filter( $path ); $path['paged'] = '%d'; $path = add_query_arg( $path, '/' ); } return empty( $path ) ? false : $path; } /** * Return query string for current request, prefixed with '?'. * * @return string */ function _s_backbone_get_request_parameters() { $uri = $_SERVER[ 'REQUEST_URI' ]; $uri = preg_replace( '/^[^?]*(\?.*$)/', '$1', $uri, 1, $count ); if ( $count != 1 ) { return ''; } return $uri; } /******************* < PHP 7.3 include file as dom.php >= PHP 7.3 include file as html_dom.php **********************/ // Read the TIL source from the local file when it's on this server (avoids an HTTP // round-trip per render); fall back to the live URL. Links in the source are // root-relative or absolute, so they resolve correctly wherever embedded. function dw_til_html() { require_once('lib/html_dom.php'); $local = ABSPATH . 'til/index.html'; return file_exists($local) ? file_get_html($local) : file_get_html('https://davidawindham.com/til/index.html'); } function til($limit = 9) { $html = dw_til_html(); if (!$html) return; $i = 0; foreach ($html->find('ul li ul li') as $li) { echo $li; if (++$i == $limit) break; } } function pull_til($limit = 71) { // default matches the Recent Posts column length on page-desk.php $html = dw_til_html(); if (!$html) return; $i = 0; foreach ($html->find('ul li ul li') as $li) { echo $li; if (++$i == $limit) break; } } function pull_til_all() { $html = dw_til_html(); if (!$html) return; foreach ($html->find('ul li ul li') as $li) { echo $li; } } // TIL site tag cloud (Docusaurus, /til/posts/tags/) — rendered inline like the WP // tags so both can share one block. Local file when present; links point to the TIL site. function dw_til_tags_html() { require_once('lib/html_dom.php'); $local = ABSPATH . 'til/posts/tags/index.html'; return file_exists($local) ? file_get_html($local) : file_get_html('https://davidawindham.com/til/posts/tags/'); } function pull_til_tags() { $html = dw_til_tags_html(); if (!$html) return; foreach ($html->find('a[rel=tag]') as $a) { $name = trim(preg_replace('/innertext)); // drop the trailing count if ($name === '') continue; echo '' . esc_html($name) . ', '; } } function bookmarks() { require_once('lib/html_dom.php'); $url = 'https://davidwindham.com/bookmarks/'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.linklist-item-title h2 a') as $li) { if (!empty($html)) { echo $li . '
'; if (++$i == 9) break; } } } function bookmarks_pull($limit = 27) { require_once('lib/html_dom.php'); $url = 'https://davidwindham.com/bookmarks/'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.linklist-item-title h2 a') as $li) { if (!empty($html)) { echo $li . '
'; if (++$i == $limit) break; } } } function bookmarks_all() { require_once('lib/html_dom.php'); $url = 'https://davidwindham.com/bookmarks/'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.linklist-item-title h2 a') as $li) { if (!empty($html)) { echo $li . '
'; } } } /*============================================ Desk block-migration shortcodes Wrap the echoing helpers (and the inline "Recently Edited" loop from page-desk.php) so they can be dropped into block content. ==============================================*/ function dw_til_shortcode() { ob_start(); pull_til(); return ob_get_clean(); } add_shortcode( 'dw_til', 'dw_til_shortcode' ); function dw_bookmarks_shortcode() { ob_start(); bookmarks_pull(); return ob_get_clean(); } add_shortcode( 'dw_bookmarks', 'dw_bookmarks_shortcode' ); function dw_recently_edited_shortcode() { $sticky = get_option( 'sticky_posts' ); if ( empty( $sticky ) ) { return ''; } $posts = get_posts( array( 'post_type' => 'post', 'orderby' => 'modified', 'posts_per_page' => 5, 'post__in' => $sticky, ) ); if ( ! $posts ) { return ''; } $out = ''; return $out; } add_shortcode( 'dw_recently_edited', 'dw_recently_edited_shortcode' ); function now() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/lists/now'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 6) break; } } } function todo() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/lists/todo'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 3) break; } } } function todone() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/lists/todone'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 3) break; } } } function docs() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/docs'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 5) break; } } } function lists() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/lists/'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 5) break; } } } function notes() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/notes/'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 5) break; } } } function playing() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/lists/now/playing'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 3) break; } } } function watching() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/lists/now/watching'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 3) break; } } } function listening() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/lists/now/listening'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 3) break; } } } function reading() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/lists/now/reading'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 3) break; } } } function learning() { require_once('lib/html_dom.php'); $url = 'https://davidawindham.com/til/lists/now/learning'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.markdown ul li') as $li) { if (!empty($html)) { echo $li; if (++$i == 3) break; } } } /********************************/ /************ Code ************/ /********************************/ function code() { require_once('lib/html_dom.php'); $url = 'https://code.davidawindham.com/david?tab=activity'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('.content ul li') as $li) { foreach ($li->find('span.text') as $comment) { if (!empty($html)) { $str = array('href="/', 'light'); $replace = array('href="https://code.davidawindham.com/', ''); //echo str_replace($str,$replace, $li . ' - ' . $commit . ' - ' . $comment . '
'); echo str_replace($str,$replace, $li . '' . $comment . '
'); } } //foreach ($html->find('span.text') as $comment) {} if (++$i == 5) break; } } function commits() { require_once('lib/html_dom.php'); $url = 'https://code.davidawindham.com/david?tab=activity'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('ul li a') as $li) { if (!empty($html)) { $str = array('href="/', 'light'); $replace = array('href="https://code.davidawindham.com/', ''); echo str_replace($str,$replace, date("y/m/d") . ' - ' . $li . '
'); if (++$i == 3) break; } } } function docs_code() { require_once('lib/html_dom.php'); $url = 'https://code.davidawindham.com/david/til/src/main/docs'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('table tr td') as $li) { if (!empty($html)) { //if($i++ == 1) continue; echo str_replace('href="/', 'href="https://code.davidawindham.com/', $li); if(!($i++ % 3)) { echo '
'; } if (++$i == 1) break; } } } function lists_code() { require_once('lib/html_dom.php'); $url = 'https://code.davidawindham.com/david/til/src/main/lists'; $html = file_get_html($url); if (!$html) return; $i = 0; foreach ($html->find('table tr td') as $li) { if (!empty($html)) { //if($i++ == 1) continue; if (++$i == 2) break; echo str_replace('href="/', 'href="https://code.davidawindham.com/', $li); if(!($i++ % 3)) { echo '
'; } } } } //function mastodon() { // require_once('lib/html_dom.php'); // // $url = 'https://universeodon.com/@windhamdavid/with_replies'; // $html = file_get_html($url); // if (!$html) return; // $i = 0; // foreach ($html->find('.status__content__text p') as $li) { // if (!empty($html)) { // echo str_replace('href="/', 'href="https://universeodon.com/', $li . ' '); // if (++$i == 18) break; // } // } //}