PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/broken-link-checker/modules/parsers/url_field.php

https://bitbucket.org/lgorence/quickpress
PHP | 98 lines | 36 code | 14 blank | 48 comment | 4 complexity | c735439dd657d69a46c34c78fd5aa048 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /*
  3. Plugin Name: URL fields
  4. Description: Parses data fields that contain a single, plaintext URL.
  5. Version: 1.0
  6. Author: Janis Elsts
  7. ModuleID: url_field
  8. ModuleCategory: parser
  9. ModuleClassName: blcUrlField
  10. ModuleContext: on-demand
  11. ModuleLazyInit: true
  12. ModuleAlwaysActive: true
  13. ModuleHidden: true
  14. */
  15. /**
  16. * A "parser" for data fields that contain a single, plaintext URL.
  17. *
  18. * Intended for parsing stuff like bookmarks and comment author links.
  19. *
  20. * @package Broken Link Checker
  21. * @access public
  22. */
  23. class blcUrlField extends blcParser {
  24. var $supported_formats = array('url_field');
  25. /**
  26. * "Parse" an URL into an instance.
  27. *
  28. * @param string $content The entire content is expected to be a single plaintext URL.
  29. * @param string $base_url The base URL to use for normalizing relative URLs. If ommitted, the blog's root URL will be used.
  30. * @param string $default_link_text
  31. * @return array An array of new blcLinkInstance objects.
  32. */
  33. function parse($content, $base_url = '', $default_link_text = ''){
  34. $instances = array();
  35. $url = $raw_url = trim($content);
  36. //Attempt to parse the URL
  37. $parts = @parse_url($url);
  38. if(!$parts) {
  39. return $instances; //Ignore invalid URLs
  40. };
  41. if ( !isset($parts['scheme']) ){
  42. //No sheme - likely a relative URL. Turn it into an absolute one.
  43. $url = $this->relative2absolute($url, $base_url);
  44. //Skip invalid URLs (again)
  45. if ( !$url || (strlen($url)<6) ) {
  46. return $instances;
  47. }
  48. }
  49. //The URL is okay, create and populate a new link instance.
  50. $instance = new blcLinkInstance();
  51. $instance->set_parser($this);
  52. $instance->raw_url = $raw_url;
  53. $instance->link_text = $default_link_text;
  54. $link_obj = new blcLink($url); //Creates or loads the link
  55. $instance->set_link($link_obj);
  56. $instances[] = $instance;
  57. return $instances;
  58. }
  59. /**
  60. * Change one URL to another (just returns the new URL).
  61. *
  62. * @param string $content The old URL.
  63. * @param string $new_url The new URL.
  64. * @param string $old_url Ignored.
  65. * @param string $old_raw_url Ignored.
  66. *
  67. * @return array|WP_Error
  68. */
  69. function edit($content, $new_url, $old_url, $old_raw_url){
  70. return array(
  71. 'content' => $new_url,
  72. 'raw_url' => $new_url,
  73. );
  74. }
  75. /**
  76. * For URL fields, "unlinking" simply means blanking the field.
  77. * (However, invididual link containers may implement a different logic for those fields.)
  78. */
  79. function unlink($content, $url, $raw_url){
  80. return '';
  81. }
  82. }
  83. ?>