<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://microformats.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jfm1991</id>
	<title>Microformats Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://microformats.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jfm1991"/>
	<link rel="alternate" type="text/html" href="https://microformats.org/wiki/Special:Contributions/Jfm1991"/>
	<updated>2026-05-10T03:48:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.38.4</generator>
	<entry>
		<id>https://microformats.org/wiki/index.php?title=representative-hcard-parsing&amp;diff=64546</id>
		<title>representative-hcard-parsing</title>
		<link rel="alternate" type="text/html" href="https://microformats.org/wiki/index.php?title=representative-hcard-parsing&amp;diff=64546"/>
		<updated>2014-09-21T15:13:54Z</updated>

		<summary type="html">&lt;p&gt;Jfm1991: /* see also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;entry-title&amp;gt;representative hCard parsing&amp;lt;/entry-title&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Assuming you are already using code that properly implements [[hcard-parsing]], this page documents how to determine a [[representative hCard]] for a page using the current [[representative-hcard-brainstorming]] proposal.&lt;br /&gt;
&lt;br /&gt;
== representative hCard algorithm ==&lt;br /&gt;
After [[microformats2-parsing|parsing]] the page:&lt;br /&gt;
# '''url uid source.''' The first hCard found which has a &amp;quot;url&amp;quot; property whose value is the url of the page (source) and is also a &amp;quot;uid&amp;quot; property for the hCard, is the representative hCard for the page. &lt;br /&gt;
# '''url and rel me.''' If the previous step didn't find a representative hCard, then the first hCard with a &amp;quot;url&amp;quot; property that also has the &amp;lt;code&amp;gt;rel=&amp;quot;me&amp;quot;&amp;lt;/code&amp;gt; relation is the representative hCard for the page.&lt;br /&gt;
&lt;br /&gt;
== open source implementations ==&lt;br /&gt;
The below open source implementations of '''representative hCard parsing''' have been contributed inline and are thus in the public domain per [[Microformats_Wiki:Copyrights]].&lt;br /&gt;
&lt;br /&gt;
=== Draft hKit (PHP5) code ===&lt;br /&gt;
I - ([[User:TomMorris|Tom]]) - have been working on implementing represenative hCard parsing in PHP so that a user can simply type in a URL pointing to a page with an hCard on it, and have their name and some details automatically filled in the form. The code below implements the following:&lt;br /&gt;
# If there is only one hCard on a page, it uses that.&lt;br /&gt;
# If there is more than one hCard on a page, it looks through to see if any of the cards have UID or URL fields that match the URL it searches, then selects that one if one exists.&lt;br /&gt;
&lt;br /&gt;
It's experimental and quite 'alpha', so I'd suggest you test it and make adjustments as necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// example hKit code to extract a representative hCard&lt;br /&gt;
// tom morris &amp;lt;http://tommorris.org&amp;gt;&lt;br /&gt;
// public domain 2007&lt;br /&gt;
&lt;br /&gt;
// An hCard could have more than one url, so we use a multi-dimensional array search. - Sarven Capadisli&lt;br /&gt;
&lt;br /&gt;
// From http://nl2.php.net/manual/en/function.array-search.php#80692&lt;br /&gt;
function multidimArrayLocate($array, $text){&lt;br /&gt;
  foreach($array as $key =&amp;gt; $arrayValue){&lt;br /&gt;
    if (is_array($arrayValue)){&lt;br /&gt;
      if ($key == $text) $arrayResult[$key] = $arrayValue;&lt;br /&gt;
      $temp[$key] = multidimArrayLocate($arrayValue, $text);&lt;br /&gt;
      if ($temp[$key]) $arrayResult[$key] = $temp[$key];&lt;br /&gt;
    }&lt;br /&gt;
    else{&lt;br /&gt;
      if ($key == $text) $arrayResult[$key] = $arrayValue;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return $arrayResult;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
include(&amp;quot;hkit.class.php&amp;quot;);&lt;br /&gt;
$hkit = new hKit;&lt;br /&gt;
$result = $hkit-&amp;gt;getByURL('hcard', $HTTP_GET_VARS['url']);&lt;br /&gt;
if (count($result) != 0) {&lt;br /&gt;
  if (count($result) == 1) {&lt;br /&gt;
    $repcard = $result[0];&lt;br /&gt;
  } else {&lt;br /&gt;
    foreach ($result as $card) {&lt;br /&gt;
      if (multidimArrayLocate($card, $HTTP_GET_VARS['url']) == true || $card['uid'] == $HTTP_GET_VARS['url']) {&lt;br /&gt;
        $repcard = $card;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
print_r($repcard);&lt;br /&gt;
?&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== jQuery (JavaScript) code ===&lt;br /&gt;
The following JavaScript code follows the [[representative-hcard-brainstorming#current_proposal|current proposal for finding a representative hCard]]. It requires the [http://jquery.com/ jQuery] library, however, it can be easily switched over to another library.&lt;br /&gt;
&lt;br /&gt;
* If a vCard has a &amp;lt;code&amp;gt;class=&amp;quot;url&amp;quot;&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;class=&amp;quot;uid&amp;quot;&amp;lt;/code&amp;gt; with an href value same as the source URI (current document), then that vCard is a representative hCard candidate, otherwise;&lt;br /&gt;
* If a vCard has a &amp;lt;code&amp;gt;class=&amp;quot;url&amp;quot;&amp;lt;/code&amp;gt; and a &amp;lt;code&amp;gt;rel=&amp;quot;me&amp;quot;&amp;lt;/code&amp;gt; on the same element, then that vCard is a representative hCard candidate, otherwise;&lt;br /&gt;
* There is no representative hCard.&lt;br /&gt;
* Grab the first hCard from the list of candidates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
/***&lt;br /&gt;
    Note: Extracts representative hCard&lt;br /&gt;
    Author: Sarven Capadisli http://csarven.ca/&lt;br /&gt;
    License: Public Domain 2009-06-04&lt;br /&gt;
*/&lt;br /&gt;
var sourceURI = window.location.href;&lt;br /&gt;
var rep_hCard = new Array();&lt;br /&gt;
&lt;br /&gt;
function rep_hCard_uidurlsource() {&lt;br /&gt;
    $('.vcard .uid[href='+sourceURI+']').each(function() {&lt;br /&gt;
        $(this).each(function() {&lt;br /&gt;
            if ($(this).closest('.vcard').find('.url[href='+sourceURI+']').length &amp;gt; 0) {&lt;br /&gt;
                rep_hCard.push($(this).closest('.vcard')[0]);&lt;br /&gt;
            }&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
    return (rep_hCard.length &amp;gt; 0) ? true : false;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function rep_hCard_urlme() {&lt;br /&gt;
    $('.vcard .url[rel=me]').each(function() {&lt;br /&gt;
        rep_hCard.push($(this).closest('.vcard')[0]);&lt;br /&gt;
    });&lt;br /&gt;
    return (rep_hCard.length &amp;gt; 0) ? true : false;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if (rep_hCard_uidurlsource() || rep_hCard_urlme()) {&lt;br /&gt;
    rep_hCard = $($(rep_hCard)[0]); &lt;br /&gt;
    rep_hCard_url = (rep_hCard.find('.uid').length &amp;gt; 0) ? rep_hCard.find('.uid')[0].href : rep_hCard.find('.url[rel=me]')[0].href;&lt;br /&gt;
    hCard_fn = $('.fn', rep_hCard).text();&lt;br /&gt;
    hCard_photo_src = ($('.photo', rep_hCard).length &amp;gt; 0) ? $('.photo', rep_hCard)[0].src : '';&lt;br /&gt;
}&lt;br /&gt;
else {&lt;br /&gt;
    //no representative hCard&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
--[[User:Csarven|Sarven Capadisli]] 04:24, 4 June 2009 (UTC)&lt;br /&gt;
&lt;br /&gt;
get off my phone fuckers&lt;/div&gt;</summary>
		<author><name>Jfm1991</name></author>
	</entry>
</feed>