utils.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php
  2. /**
  3. * Filter to Run WP REST API v2 Endpoints and Fix double Slash in rest_url
  4. */
  5. //add_filter( 'rest_url_prefix', function () { return 'wp-json/wp/v2'; } );
  6. //add_filter( 'rest_url_prefix', 'fix_json_endpoint' );
  7. //function fix_json_endpoint (){
  8. // $json_endpoint = 'wp-json/wp/v2';
  9. // return rtrim( $json_endpoint, '/' );
  10. //}
  11. //remove_filter('json_dispatch_request', 'json_v1_compatible_dispatch', 10);
  12. //remove_filter('json_endpoints', 'json_v1_compatible_routes', 1000);
  13. /**
  14. * Build path data for current request.
  15. *
  16. * @return string|bool
  17. */
  18. function _s_backbone_get_request_path() {
  19. global $wp_rewrite;
  20. if ( $wp_rewrite->using_permalinks() ) {
  21. global $wp;
  22. // If called too early, bail
  23. if ( ! isset( $wp->request ) ) {
  24. return false;
  25. }
  26. // Determine path for paginated version of current request
  27. if ( false != preg_match( '#' . $wp_rewrite->pagination_base . '/\d+/?$#i', $wp->request ) ) {
  28. $path = preg_replace( '#' . $wp_rewrite->pagination_base . '/\d+$#i', $wp_rewrite->pagination_base . '/%d', $wp->request );
  29. } else {
  30. $path = $wp->request . '/' . $wp_rewrite->pagination_base . '/%d';
  31. }
  32. // Slashes everywhere we need them
  33. if ( 0 !== strpos( $path, '/' ) )
  34. $path = '/' . $path;
  35. $path = user_trailingslashit( $path );
  36. } else {
  37. // Clean up raw $_REQUEST input
  38. $path = array_map( 'sanitize_text_field', $_REQUEST );
  39. $path = array_filter( $path );
  40. $path['paged'] = '%d';
  41. $path = add_query_arg( $path, '/' );
  42. }
  43. return empty( $path ) ? false : $path;
  44. }
  45. /**
  46. * Return query string for current request, prefixed with '?'.
  47. *
  48. * @return string
  49. */
  50. function _s_backbone_get_request_parameters() {
  51. $uri = $_SERVER[ 'REQUEST_URI' ];
  52. $uri = preg_replace( '/^[^?]*(\?.*$)/', '$1', $uri, 1, $count );
  53. if ( $count != 1 ) {
  54. return '';
  55. }
  56. return $uri;
  57. }
  58. /*******************
  59. < PHP 7.3 include file as dom.php
  60. >= PHP 7.3 include file as html_dom.php
  61. **********************/
  62. function til() {
  63. require_once('lib/html_dom.php');
  64. $url = 'https://davidawindham.com/til/index.html';
  65. $html = file_get_html($url);
  66. $i = 0;
  67. foreach ($html->find('ul li ul li') as $li) {
  68. echo $li;
  69. if (++$i == 9) break;
  70. }
  71. }
  72. function pull_til() {
  73. require_once('lib/html_dom.php');
  74. $url = 'https://davidawindham.com/til/index.html';
  75. $html = file_get_html($url);
  76. $i = 0;
  77. foreach ($html->find('ul li ul li') as $li) {
  78. echo $li;
  79. if (++$i == 43) break;
  80. }
  81. }
  82. function pull_til_all() {
  83. require_once('lib/html_dom.php');
  84. $url = 'https://davidawindham.com/til/index.html';
  85. $html = file_get_html($url);
  86. $i = 0;
  87. foreach ($html->find('ul li ul li') as $li) {
  88. echo $li;
  89. }
  90. }
  91. function bookmarks() {
  92. require_once('lib/html_dom.php');
  93. $url = 'https://davidawindham.com/bookmarks/';
  94. $html = file_get_html($url);
  95. $i = 0;
  96. foreach ($html->find('.linklist-item-title h2 a') as $li) {
  97. if (!empty($html)) {
  98. echo $li . '<br />';
  99. if (++$i == 9) break;
  100. }
  101. }
  102. }
  103. function bookmarks_pull() {
  104. require_once('lib/html_dom.php');
  105. $url = 'https://davidawindham.com/bookmarks/';
  106. $html = file_get_html($url);
  107. $i = 0;
  108. foreach ($html->find('.linklist-item-title h2 a') as $li) {
  109. if (!empty($html)) {
  110. echo $li . '<br />';
  111. if (++$i == 27) break;
  112. }
  113. }
  114. }
  115. function bookmarks_all() {
  116. require_once('lib/html_dom.php');
  117. $url = 'https://davidawindham.com/bookmarks/';
  118. $html = file_get_html($url);
  119. $i = 0;
  120. foreach ($html->find('.linklist-item-title h2 a') as $li) {
  121. if (!empty($html)) {
  122. echo $li . '<br />';
  123. }
  124. }
  125. }
  126. function work() {
  127. require_once('lib/html_dom.php');
  128. $url = 'https://davidawindham.com/til/notes/work';
  129. $html = file_get_html($url);
  130. $i = 0;
  131. foreach ($html->find('.markdown ul li') as $li) {
  132. if (!empty($html)) {
  133. echo $li;
  134. if (++$i == 3) break;
  135. }
  136. }
  137. }
  138. function todo() {
  139. require_once('lib/html_dom.php');
  140. $url = 'https://davidawindham.com/til/lists/todo';
  141. $html = file_get_html($url);
  142. $i = 0;
  143. foreach ($html->find('.markdown ul li') as $li) {
  144. if (!empty($html)) {
  145. echo $li;
  146. if (++$i == 3) break;
  147. }
  148. }
  149. }
  150. function todone() {
  151. require_once('lib/html_dom.php');
  152. $url = 'https://davidawindham.com/til/lists/todone';
  153. $html = file_get_html($url);
  154. $i = 0;
  155. foreach ($html->find('.markdown ul li') as $li) {
  156. if (!empty($html)) {
  157. echo $li;
  158. if (++$i == 3) break;
  159. }
  160. }
  161. }
  162. function docs() {
  163. require_once('lib/html_dom.php');
  164. $url = 'https://davidawindham.com/til/docs';
  165. $html = file_get_html($url);
  166. $i = 0;
  167. foreach ($html->find('.markdown ul li') as $li) {
  168. if (!empty($html)) {
  169. echo $li;
  170. if (++$i == 5) break;
  171. }
  172. }
  173. }
  174. function lists() {
  175. require_once('lib/html_dom.php');
  176. $url = 'https://davidawindham.com/til/lists/';
  177. $html = file_get_html($url);
  178. $i = 0;
  179. foreach ($html->find('.markdown ul li') as $li) {
  180. if (!empty($html)) {
  181. echo $li;
  182. if (++$i == 5) break;
  183. }
  184. }
  185. }
  186. function notes() {
  187. require_once('lib/html_dom.php');
  188. $url = 'https://davidawindham.com/til/notes/';
  189. $html = file_get_html($url);
  190. $i = 0;
  191. foreach ($html->find('.markdown ul li') as $li) {
  192. if (!empty($html)) {
  193. echo $li;
  194. if (++$i == 5) break;
  195. }
  196. }
  197. }
  198. function playing() {
  199. require_once('lib/html_dom.php');
  200. $url = 'https://davidawindham.com/til/lists/now/playing';
  201. $html = file_get_html($url);
  202. $i = 0;
  203. foreach ($html->find('.markdown ul li') as $li) {
  204. if (!empty($html)) {
  205. echo $li;
  206. if (++$i == 3) break;
  207. }
  208. }
  209. }
  210. function watching() {
  211. require_once('lib/html_dom.php');
  212. $url = 'https://davidawindham.com/til/lists/now/watching';
  213. $html = file_get_html($url);
  214. $i = 0;
  215. foreach ($html->find('.markdown ul li') as $li) {
  216. if (!empty($html)) {
  217. echo $li;
  218. if (++$i == 3) break;
  219. }
  220. }
  221. }
  222. function listening() {
  223. require_once('lib/html_dom.php');
  224. $url = 'https://davidawindham.com/til/lists/now/listening';
  225. $html = file_get_html($url);
  226. $i = 0;
  227. foreach ($html->find('.markdown ul li') as $li) {
  228. if (!empty($html)) {
  229. echo $li;
  230. if (++$i == 3) break;
  231. }
  232. }
  233. }
  234. function reading() {
  235. require_once('lib/html_dom.php');
  236. $url = 'https://davidawindham.com/til/lists/now/reading';
  237. $html = file_get_html($url);
  238. $i = 0;
  239. foreach ($html->find('.markdown ul li') as $li) {
  240. if (!empty($html)) {
  241. echo $li;
  242. if (++$i == 3) break;
  243. }
  244. }
  245. }
  246. function learning() {
  247. require_once('lib/html_dom.php');
  248. $url = 'https://davidawindham.com/til/lists/now/learning';
  249. $html = file_get_html($url);
  250. $i = 0;
  251. foreach ($html->find('.markdown ul li') as $li) {
  252. if (!empty($html)) {
  253. echo $li;
  254. if (++$i == 3) break;
  255. }
  256. }
  257. }
  258. /********************************/
  259. /************ Code ************/
  260. /********************************/
  261. function code() {
  262. require_once('lib/html_dom.php');
  263. $url = 'https://code.davidawindham.com/david?tab=activity';
  264. $html = file_get_html($url);
  265. $i = 0;
  266. foreach ($html->find('.content ul li') as $li) {
  267. foreach ($li->find('span.text') as $comment) {
  268. if (!empty($html)) {
  269. $str = array('href="/', 'light');
  270. $replace = array('href="https://code.davidawindham.com/', '');
  271. //echo str_replace($str,$replace, $li . ' - ' . $commit . ' - ' . $comment . '<br>');
  272. echo str_replace($str,$replace, $li . '' . $comment . '<br>');
  273. }
  274. }
  275. //foreach ($html->find('span.text') as $comment) {}
  276. if (++$i == 5) break;
  277. }
  278. }
  279. function commits() {
  280. require_once('lib/html_dom.php');
  281. $url = 'https://code.davidawindham.com/david?tab=activity';
  282. $html = file_get_html($url);
  283. $i = 0;
  284. foreach ($html->find('ul li a') as $li) {
  285. if (!empty($html)) {
  286. $str = array('href="/', 'light');
  287. $replace = array('href="https://code.davidawindham.com/', '');
  288. echo str_replace($str,$replace, date("y/m/d") . ' - ' . $li . '<br>');
  289. if (++$i == 3) break;
  290. }
  291. }
  292. }
  293. function docs_code() {
  294. require_once('lib/html_dom.php');
  295. $url = 'https://code.davidawindham.com/david/til/src/main/docs';
  296. $html = file_get_html($url);
  297. $i = 0;
  298. foreach ($html->find('table tr td') as $li) {
  299. if (!empty($html)) {
  300. //if($i++ == 1) continue;
  301. echo str_replace('href="/', 'href="https://code.davidawindham.com/', $li);
  302. if(!($i++ % 3)) {
  303. echo '<br>';
  304. }
  305. if (++$i == 1) break;
  306. }
  307. }
  308. }
  309. function lists_code() {
  310. require_once('lib/html_dom.php');
  311. $url = 'https://code.davidawindham.com/david/til/src/main/lists';
  312. $html = file_get_html($url);
  313. $i = 0;
  314. foreach ($html->find('table tr td') as $li) {
  315. if (!empty($html)) {
  316. //if($i++ == 1) continue;
  317. if (++$i == 2) break;
  318. echo str_replace('href="/', 'href="https://code.davidawindham.com/', $li);
  319. if(!($i++ % 3)) {
  320. echo '<br>';
  321. }
  322. }
  323. }
  324. }
  325. function photo() {
  326. require_once('lib/html_dom.php');
  327. $url = 'https://photo.davidwindham.com/#16734437965516';
  328. $html = file_get_html($url);
  329. $i = 0;
  330. foreach ($html->find('.photo .overlay h1') as $li) {
  331. if (!empty($html)) {
  332. echo str_replace('href="/', 'href="https://photo.davidawindham.com/', $li . '&nbsp;');
  333. if (++$i == 18) break;
  334. }
  335. }
  336. }
  337. //function mastodon() {
  338. // require_once('lib/html_dom.php');
  339. //
  340. // $url = 'https://universeodon.com/@windhamdavid/with_replies';
  341. // $html = file_get_html($url);
  342. // $i = 0;
  343. // foreach ($html->find('.status__content__text p') as $li) {
  344. // if (!empty($html)) {
  345. // echo str_replace('href="/', 'href="https://universeodon.com/', $li . '&nbsp;');
  346. // if (++$i == 18) break;
  347. // }
  348. // }
  349. //}