]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LRDD/extlib/XML/XRD/Element/Link.php
Implemented WebFinger and replaced our XRD with PEAR XML_XRD
[quix0rs-gnu-social.git] / plugins / LRDD / extlib / XML / XRD / Element / Link.php
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
14 require_once 'XML/XRD/PropertyAccess.php';
15
16 /**
17  * Link element in a XRD file. Attribute access via object properties.
18  *
19  * Retrieving the title of a link is possible with the getTitle() convenience
20  * method.
21  *
22  * @category XML
23  * @package  XML_XRD
24  * @author   Christian Weiske <cweiske@php.net>
25  * @license  http://www.gnu.org/copyleft/lesser.html LGPL
26  * @version  Release: @package_version@
27  * @link     http://pear.php.net/package/XML_XRD
28  */
29 class XML_XRD_Element_Link extends XML_XRD_PropertyAccess
30 {
31     /**
32      * Link relation
33      *
34      * @var string
35      */
36     public $rel;
37
38     /**
39      * Link type (MIME type)
40      *
41      * @var string
42      */
43     public $type;
44
45     /**
46      * Link URL
47      *
48      * @var string
49      */
50     public $href;
51
52     /**
53      * Link URL template
54      *
55      * @var string
56      */
57     public $template;
58
59     /**
60      * Array of key-value pairs: Key is the language, value the title
61      *
62      * @var array
63      */
64     public $titles = array();
65
66
67
68     /**
69      * Create a new instance and load data from the XML element
70      *
71      * @param string  $relOrXml   string with the relation name/URL
72      * @param string  $href       HREF value
73      * @param string  $type       Type value
74      * @param boolean $isTemplate When set to true, the $href is
75      *                            used as template
76      */
77     public function __construct(
78         $rel = null, $href = null, $type = null, $isTemplate = false
79     ) {
80         $this->rel = $rel;
81         if ($isTemplate) {
82             $this->template = $href;
83         } else {
84             $this->href = $href;
85         }
86         $this->type = $type;
87     }
88
89     /**
90      * Returns the title of the link in the given language.
91      * If the language is not available, the first title without the language
92      * is returned. If no such one exists, the first title is returned.
93      *
94      * @param string $lang 2-letter language name
95      *
96      * @return string|null Link title
97      */
98     public function getTitle($lang = null)
99     {
100         if (count($this->titles) == 0) {
101             return null;
102         }
103
104         if ($lang == null) {
105             return reset($this->titles);
106         }
107
108         if (isset($this->titles[$lang])) {
109             return $this->titles[$lang];
110         }
111         if (isset($this->titles[''])) {
112             return $this->titles[''];
113         }
114
115         //return first
116         return reset($this->titles);
117     }
118 }
119
120 ?>