Commit 966feeb6 by Scott

Switch to schema.org Question/Answer microdata

parent 1fbcd296
...@@ -264,10 +264,11 @@ ...@@ -264,10 +264,11 @@
$postid=$post['postid']; $postid=$post['postid'];
$isquestion=($post['basetype']=='Q'); $isquestion=($post['basetype']=='Q');
$isanswer=($post['basetype']=='A'); $isanswer=($post['basetype']=='A');
$iscomment=($post['basetype']=='C');
$isbyuser=qa_post_is_by_user($post, $userid, $cookieid); $isbyuser=qa_post_is_by_user($post, $userid, $cookieid);
$anchor=urlencode(qa_anchor($post['basetype'], $postid)); $anchor=urlencode(qa_anchor($post['basetype'], $postid));
$elementid=isset($options['elementid']) ? $options['elementid'] : $anchor; $elementid=isset($options['elementid']) ? $options['elementid'] : $anchor;
$microformats=@$options['microformats']; $microformats=qa_opt('use_microdata');
$isselected=@$options['isselected']; $isselected=@$options['isselected'];
$favoritedview=@$options['favoritedview']; $favoritedview=@$options['favoritedview'];
$favoritemap=$favoritedview ? qa_get_favorite_non_qs_map() : array(); $favoritemap=$favoritedview ? qa_get_favorite_non_qs_map() : array();
...@@ -282,7 +283,12 @@ ...@@ -282,7 +283,12 @@
$fields['classes']=ltrim($fields['classes'].' qa-q-closed'); $fields['classes']=ltrim($fields['classes'].' qa-q-closed');
if ($microformats) { if ($microformats) {
$fields['classes'].=' hentry '.($isquestion ? 'question' : ($isanswer ? ($isselected ? 'answer answer-selected' : 'answer') : 'comment')); if ($isanswer) {
$fields['tags'] .= ' itemprop="suggestedAnswer' . ($isselected ? ' acceptedAnswer' : '') . '" itemscope itemtype="http://schema.org/Answer"';
}
if ($iscomment) {
$fields['tags'] .= ' itemscope itemtype="http://schema.org/Comment"';
}
} }
// Question-specific stuff (title, URL, tags, answer count, category) // Question-specific stuff (title, URL, tags, answer count, category)
...@@ -295,8 +301,9 @@ ...@@ -295,8 +301,9 @@
$post['title']=qa_block_words_replace($post['title'], $options['blockwordspreg']); $post['title']=qa_block_words_replace($post['title'], $options['blockwordspreg']);
$fields['title']=qa_html($post['title']); $fields['title']=qa_html($post['title']);
if ($microformats) if ($microformats) {
$fields['title']='<span class="entry-title">'.$fields['title'].'</span>'; $fields['title'] = '<span itemprop="name">' . $fields['title'] . '</span>';
}
/*if (isset($post['score'])) // useful for setting match thresholds /*if (isset($post['score'])) // useful for setting match thresholds
$fields['title'].=' <small>('.$post['score'].')</small>';*/ $fields['title'].=' <small>('.$post['score'].')</small>';*/
...@@ -369,8 +376,9 @@ ...@@ -369,8 +376,9 @@
'linksnewwindow' => @$options['linksnewwindow'], 'linksnewwindow' => @$options['linksnewwindow'],
)); ));
if ($microformats) if ($microformats) {
$fields['content']='<div class="entry-content">'.$fields['content'].'</div>'; $fields['content'] = '<div itemprop="text">' . $fields['content'] . '</div>';
}
$fields['content']='<a name="'.qa_html($postid).'"></a>'.$fields['content']; $fields['content']='<a name="'.qa_html($postid).'"></a>'.$fields['content'];
// this is for backwards compatibility with any existing links using the old style of anchor // this is for backwards compatibility with any existing links using the old style of anchor
...@@ -417,10 +425,10 @@ ...@@ -417,10 +425,10 @@
// ...with microformats if appropriate // ...with microformats if appropriate
if ($microformats) { if ($microformats) {
$netvoteshtml.='<span class="votes-up"><span class="value-title" title="'.$upvoteshtml.'"></span></span>'. // vote display might be compacted so use meta tag for true count
'<span class="votes-down"><span class="value-title" title="'.$downvoteshtml.'"></span></span>'; $netvoteshtml .= '<meta itemprop="upvoteCount" content="' . qa_html($netvotes) . '">';
$upvoteshtml='<span class="votes-up">'.$upvoteshtml.'</span>'; $upvoteshtml .= '<meta itemprop="upvoteCount" content="' . qa_html($upvotes) . '">';
$downvoteshtml='<span class="votes-down">'.$downvoteshtml.'</span>'; $downvoteshtml .= '<meta itemprop="upvoteCount" content="' . qa_html($downvotes) . '">';
} }
// Pass information on vote viewing // Pass information on vote viewing
...@@ -518,8 +526,10 @@ ...@@ -518,8 +526,10 @@
if (isset($post['created']) && @$options['whenview']) { if (isset($post['created']) && @$options['whenview']) {
$fields['when']=qa_when_to_html($post['created'], @$options['fulldatedays']); $fields['when']=qa_when_to_html($post['created'], @$options['fulldatedays']);
if ($microformats) if ($microformats) {
$fields['when']['data']='<span class="published"><span class="value-title" title="'.gmdate('Y-m-d\TH:i:sO', $post['created']).'">'.$fields['when']['data'].'</span></span>'; $gmdate = gmdate('Y-m-d\TH:i:sO', $post['created']);
$fields['when']['data'] = '<time itemprop="dateCreated" datetime="' . $gmdate . '" title="' . $gmdate . '">' . $fields['when']['data'] . '</time>';
}
} }
if (@$options['whoview']) { if (@$options['whoview']) {
...@@ -595,16 +605,16 @@ ...@@ -595,16 +605,16 @@
if (@$options['whenview']) { if (@$options['whenview']) {
$fields['when_2']=qa_when_to_html($post['updated'], @$options['fulldatedays']); $fields['when_2']=qa_when_to_html($post['updated'], @$options['fulldatedays']);
if ($microformats) if ($microformats) {
$fields['when_2']['data']='<span class="updated"><span class="value-title" title="'.gmdate('Y-m-d\TH:i:sO', $post['updated']).'">'.$fields['when_2']['data'].'</span></span>'; $gmdate = gmdate('Y-m-d\TH:i:sO', $post['updated']);
$fields['when_2']['data'] = '<time itemprop="dateModified" datetime="' . $gmdate . '" title="' . $gmdate . '">' . $fields['when_2']['data'] . '</time>';
}
} }
if (isset($post['lastuserid']) && @$options['whoview']) if (isset($post['lastuserid']) && @$options['whoview'])
$fields['who_2']=qa_who_to_html(isset($userid) && ($post['lastuserid']==$userid), $post['lastuserid'], $usershtml, @$options['ipview'] ? $post['lastip'] : null, false); $fields['who_2']=qa_who_to_html(isset($userid) && ($post['lastuserid']==$userid), $post['lastuserid'], $usershtml, @$options['ipview'] ? $post['lastip'] : null, false);
} }
elseif ($microformats && @$options['whenview']) { // quick fix for incorrect microformats (missing 'updated' class)
$fields['when']['data'] = str_replace('<span class="published">', '<span class="published updated">', $fields['when']['data']);
}
// That's it! // That's it!
......
...@@ -225,8 +225,10 @@ class qa_html_theme_base ...@@ -225,8 +225,10 @@ class qa_html_theme_base
public function html() public function html()
{ {
$attribution = '<!-- Powered by Question2Answer - http://www.question2answer.org/ -->'; $attribution = '<!-- Powered by Question2Answer - http://www.question2answer.org/ -->';
$md = $this->microdata ? ' itemscope itemtype="http://schema.org/QAPage"' : '';
$this->output( $this->output(
'<html>', '<html'.$md.'>',
$attribution $attribution
); );
...@@ -664,8 +666,10 @@ class qa_html_theme_base ...@@ -664,8 +666,10 @@ class qa_html_theme_base
public function main() public function main()
{ {
$content = $this->content; $content = $this->content;
$hidden = !empty($content['hidden']) ? ' qa-main-hidden' : '';
$md = $this->microdata ? ' itemscope itemtype="http://schema.org/Question"' : '';
$this->output('<div class="qa-main'.(@$this->content['hidden'] ? ' qa-main-hidden' : '').'">'); $this->output('<div class="qa-main'.$hidden.'"'.$md.'>');
$this->widgets('main', 'top'); $this->widgets('main', 'top');
...@@ -1702,7 +1706,6 @@ class qa_html_theme_base ...@@ -1702,7 +1706,6 @@ class qa_html_theme_base
if ($post['vote_view'] == 'updown') { if ($post['vote_view'] == 'updown') {
$this->output_split($post['upvotes_view'], 'qa-upvote-count'); $this->output_split($post['upvotes_view'], 'qa-upvote-count');
$this->output_split($post['downvotes_view'], 'qa-downvote-count'); $this->output_split($post['downvotes_view'], 'qa-downvote-count');
} }
else else
$this->output_split($post['netvotes_view'], 'qa-netvote-count'); $this->output_split($post['netvotes_view'], 'qa-netvote-count');
...@@ -2166,6 +2169,10 @@ class qa_html_theme_base ...@@ -2166,6 +2169,10 @@ class qa_html_theme_base
if (!empty($a_list)) { if (!empty($a_list)) {
$this->part_title($a_list); $this->part_title($a_list);
if ($this->microdata) {
$this->output('<meta itemprop="answerCount" content="' . count($a_list['as']) . '">');
}
$this->output('<div class="qa-a-list'.($this->list_vote_disabled($a_list['as']) ? ' qa-a-list-vote-disabled' : '').'" '.@$a_list['tags'].'>', ''); $this->output('<div class="qa-a-list'.($this->list_vote_disabled($a_list['as']) ? ' qa-a-list-vote-disabled' : '').'" '.@$a_list['tags'].'>', '');
$this->a_list_items($a_list['as']); $this->a_list_items($a_list['as']);
$this->output('</div> <!-- END qa-a-list -->', ''); $this->output('</div> <!-- END qa-a-list -->', '');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment