PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/LRDD/extlib/XML/XRD/Element/Link.php

https://gitlab.com/windigo-gs/windigos-gnu-social
PHP | 120 lines | 38 code | 14 blank | 68 comment | 8 complexity | 0428bd5eb66e480cdd329afce5f6f371 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0
  1. <?php
  2. /**
  3. * Part of XML_XRD
  4. *
  5. * PHP version 5
  6. *
  7. * @category XML
  8. * @package XML_XRD
  9. * @author Christian Weiske <cweiske@php.net>
  10. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  11. * @link http://pear.php.net/package/XML_XRD
  12. */
  13. require_once 'XML/XRD/PropertyAccess.php';
  14. /**
  15. * Link element in a XRD file. Attribute access via object properties.
  16. *
  17. * Retrieving the title of a link is possible with the getTitle() convenience
  18. * method.
  19. *
  20. * @category XML
  21. * @package XML_XRD
  22. * @author Christian Weiske <cweiske@php.net>
  23. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  24. * @version Release: @package_version@
  25. * @link http://pear.php.net/package/XML_XRD
  26. */
  27. class XML_XRD_Element_Link extends XML_XRD_PropertyAccess
  28. {
  29. /**
  30. * Link relation
  31. *
  32. * @var string
  33. */
  34. public $rel;
  35. /**
  36. * Link type (MIME type)
  37. *
  38. * @var string
  39. */
  40. public $type;
  41. /**
  42. * Link URL
  43. *
  44. * @var string
  45. */
  46. public $href;
  47. /**
  48. * Link URL template
  49. *
  50. * @var string
  51. */
  52. public $template;
  53. /**
  54. * Array of key-value pairs: Key is the language, value the title
  55. *
  56. * @var array
  57. */
  58. public $titles = array();
  59. /**
  60. * Create a new instance and load data from the XML element
  61. *
  62. * @param string $relOrXml string with the relation name/URL
  63. * @param string $href HREF value
  64. * @param string $type Type value
  65. * @param boolean $isTemplate When set to true, the $href is
  66. * used as template
  67. */
  68. public function __construct(
  69. $rel = null, $href = null, $type = null, $isTemplate = false
  70. ) {
  71. $this->rel = $rel;
  72. if ($isTemplate) {
  73. $this->template = $href;
  74. } else {
  75. $this->href = $href;
  76. }
  77. $this->type = $type;
  78. }
  79. /**
  80. * Returns the title of the link in the given language.
  81. * If the language is not available, the first title without the language
  82. * is returned. If no such one exists, the first title is returned.
  83. *
  84. * @param string $lang 2-letter language name
  85. *
  86. * @return string|null Link title
  87. */
  88. public function getTitle($lang = null)
  89. {
  90. if (count($this->titles) == 0) {
  91. return null;
  92. }
  93. if ($lang == null) {
  94. return reset($this->titles);
  95. }
  96. if (isset($this->titles[$lang])) {
  97. return $this->titles[$lang];
  98. }
  99. if (isset($this->titles[''])) {
  100. return $this->titles[''];
  101. }
  102. //return first
  103. return reset($this->titles);
  104. }
  105. }
  106. ?>