3 homepage: http://arc.semsol.org/
4 license: http://arc.semsol.org/license
6 class: ARC2 microformats Extractor
7 author: Benjamin Nowack
11 ARC2::inc('ARC2_PoshRdfExtractor');
13 class ARC2_MicroformatsExtractor extends ARC2_PoshRdfExtractor {
15 function __construct($a = '', &$caller) {
16 parent::__construct($a, $caller);
19 function ARC2_MicroformatsExtractor($a = '', &$caller) {
20 $this->__construct($a, $caller);
25 $this->terms = $this->getTerms();
26 $this->ns_prefix = 'mf';
27 $this->a['ns']['mf'] = 'http://poshrdf.org/ns/mf#';
28 $this->caller->detected_formats['posh-rdf'] = 1;
33 function preProcessNode($n) {
35 /* remove existing poshRDF hooks */
36 if (!is_array($n['a'])) $n['a'] = array();
37 $n['a']['class'] = isset($n['a']['class']) ? preg_replace('/\s?rdf\-(s|p|o|o-xml)/', '', $n['a']['class']): '';
38 if (!isset($n['a']['rel'])) $n['a']['rel'] = '';
39 /* inject poshRDF hooks */
40 foreach ($this->terms as $term => $infos) {
41 if ((!in_array('rel', $infos) && $this->hasClass($n, $term)) || $this->hasRel($n, $term)) {
42 if ($this->v('scope', '', $infos)) $infos[] = 'p';
43 foreach (array('s', 'p', 'o', 'o-xml') as $type) {
44 if (in_array($type, $infos)) {
45 $n['a']['class'] .= ' rdf-' . $type;
46 $n['a']['class'] = preg_replace('/(^|\s)' . $term . '(\s|$)/s', '\\1mf-' . $term . '\\2', $n['a']['class']);
47 $n['a']['rel'] = preg_replace('/(^|\s)' . $term . '(\s|$)/s', '\\1mf-' . $term . '\\2', $n['a']['rel']);
52 $n['a']['class m'] = split(' ', $n['a']['class']);
53 $n['a']['rel m'] = split(' ', $n['a']['rel']);
57 function getPredicates($n, $ns) {
58 $ns = array('mf' => $ns['mf']);
59 return parent::getPredicates($n, $ns);
62 function tweakObject($o, $p, $ct) {
63 $ns = $ct['ns']['mf'];
64 /* rel-tag, skill => extract from URL */
65 if (in_array($p, array($ns . 'tag', $ns . 'skill'))) {
66 $o = preg_replace('/^.*\/([^\/]+)/', '\\1', trim($o, '/'));
67 $o = urldecode(rawurldecode($o));
75 /* no need to define 'p' if scope is not empty */
77 'acquaintance' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
78 'additional-name' => array('o', 'scope' => array('n')),
79 'adr' => array('s', 'o', 'scope' => array('_doc', 'vcard')),
80 'affiliation' => array('s', 'o', 'scope' => array('hresume')),
81 'author' => array('s', 'o', 'scope' => array('hentry')),
82 'bday' => array('o', 'scope' => array('vcard')),
83 'bio' => array('o', 'scope' => array('vcard')),
84 'best' => array('o', 'scope' => array('hreview')),
85 'bookmark' => array('o', 'scope' => array('_doc', 'hentry', 'hreview')),
86 'class' => array('o', 'scope' => array('vcard', 'vevent')),
87 'category' => array('o', 's', 'scope' => array('vcard', 'vevent')),
88 'child' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
89 'co-resident' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
90 'co-worker' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
91 'colleague' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
92 'contact' => array('o', 'scope' => array('_doc', 'hresume', 'hentry')),
93 'country-name' => array('o', 'scope' => array('adr')),
94 'crush' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
95 'date' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
96 'description' => array('o', 'scope' => array('vevent', 'hreview', 'xfolkentry')),
97 'directory' => array('o', 'rel', 'scope' => array('_doc', 'hfeed', 'hentry', 'hreview')),
98 'dtend' => array('o', 'scope' => array('vevent')),
99 'dtreviewed' => array('o', 'scope' => array('hreview')),
100 'dtstamp' => array('o', 'scope' => array('vevent')),
101 'dtstart' => array('o', 'scope' => array('vevent')),
102 'duration' => array('o', 'scope' => array('vevent')),
103 'education' => array('s', 'o', 'scope' => array('hresume')),
104 'email' => array('s', 'o', 'scope' => array('vcard')),
105 'entry-title' => array('o', 'scope' => array('hentry')),
106 'entry-content' => array('o-xml', 'scope' => array('hentry')),
107 'entry-summary' => array('o', 'scope' => array('hentry')),
108 'experience' => array('s', 'o', 'scope' => array('hresume')),
109 'extended-address' => array('o', 'scope' => array('adr')),
110 'family-name' => array('o', 'scope' => array('n')),
111 'fn' => array('o', 'plain', 'scope' => array('vcard', 'item')),
112 'friend' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
113 'geo' => array('s', 'scope' => array('_doc', 'vcard', 'vevent')),
114 'given-name' => array('o', 'scope' => array('n')),
115 'hentry' => array('s', 'o', 'scope' => array('_doc', 'hfeed')),
116 'hfeed' => array('s', 'scope' => array('_doc')),
117 'honorific-prefix' => array('o', 'scope' => array('n')),
118 'honorific-suffix' => array('o', 'scope' => array('n')),
119 'hresume' => array('s', 'scope' => array('_doc')),
120 'hreview' => array('s', 'scope' => array('_doc')),
121 'item' => array('s', 'scope' => array('hreview')),
122 'key' => array('o', 'scope' => array('vcard')),
123 'kin' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
124 'label' => array('o', 'scope' => array('vcard')),
125 'last-modified' => array('o', 'scope' => array('vevent')),
126 'latitude' => array('o', 'scope' => array('geo')),
127 'license' => array('o', 'rel', 'scope' => array('_doc', 'hfeed', 'hentry', 'hreview')),
128 'locality' => array('o', 'scope' => array('adr')),
129 'location' => array('o', 'scope' => array('vevent')),
130 'logo' => array('o', 'scope' => array('vcard')),
131 'longitude' => array('o', 'scope' => array('geo')),
132 'mailer' => array('o', 'scope' => array('vcard')),
133 'me' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
134 'met' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
135 'muse' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
136 'n' => array('s', 'o', 'scope' => array('vcard')),
137 'neighbor' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
138 'nickname' => array('o', 'plain', 'scope' => array('vcard')),
139 'nofollow' => array('o', 'rel', 'scope' => array('_doc')),
140 'note' => array('o', 'scope' => array('vcard')),
141 'org' => array('o', 'xplain', 'scope' => array('vcard')),
142 'parent' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
143 'permalink' => array('o', 'scope' => array('hreview')),
144 'photo' => array('o', 'scope' => array('vcard', 'item')),
145 'post-office-box' => array('o', 'scope' => array('adr')),
146 'postal-code' => array('o', 'scope' => array('adr')),
147 'publication' => array('s', 'o', 'scope' => array('hresume')),
148 'published' => array('o', 'scope' => array('hentry')),
149 'rating' => array('o', 'scope' => array('hreview')),
150 'region' => array('o', 'scope' => array('adr')),
151 'rev' => array('o', 'scope' => array('vcard')),
152 'reviewer' => array('s', 'o', 'scope' => array('hreview')),
153 'role' => array('o', 'plain', 'scope' => array('vcard')),
154 'sibling' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
155 'skill' => array('o', 'scope' => array('hresume')),
156 'sort-string' => array('o', 'scope' => array('vcard')),
157 'sound' => array('o', 'scope' => array('vcard')),
158 'spouse' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
159 'status' => array('o', 'plain', 'scope' => array('vevent')),
160 'street-address' => array('o', 'scope' => array('adr')),
161 'summary' => array('o', 'scope' => array('vevent', 'hreview', 'hresume')),
162 'sweetheart' => array('o', 'rel', 'scope' => array('_doc', 'hentry')),
163 'tag' => array('o', 'rel', 'scope' => array('_doc', 'category', 'hfeed', 'hentry', 'skill', 'hreview', 'xfolkentry')),
164 'taggedlink' => array('o', 'scope' => array('xfolkentry')),
165 'title' => array('o', 'scope' => array('vcard')),
166 'type' => array('o', 'scope' => array('adr', 'email', 'hreview', 'tel')),
167 'tz' => array('o', 'scope' => array('vcard')),
168 'uid' => array('o', 'scope' => array('vcard', 'vevent')),
169 'updated' => array('o', 'scope' => array('hentry')),
170 'url' => array('o', 'scope' => array('vcard', 'vevent', 'item')),
171 'value' => array('o', 'scope' => array('email', 'adr', 'tel')),
172 'vcard' => array('s', 'scope' => array('author', 'reviewer', 'affiliation', 'contact')),
173 'version' => array('o', 'scope' => array('hreview')),
174 'vevent' => array('s', 'scope' => array('_doc')),
175 'worst' => array('o', 'scope' => array('hreview')),
176 'xfolkentry' => array('s', 'scope' => array('_doc')),