Skip to content

Commit

Permalink
Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Apr 1, 2010
1 parent f765f7f commit 84af124
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
22 changes: 14 additions & 8 deletions data/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ Posts:
PostId: 236
NoteCount: 3688
Timestamp: 1163014020
Tags:
- wisdom
Quote: It does not matter how slow you go so long as you do not stop.
Source: Wisdom of <a href="http://en.wikipedia.org/wiki/Confucius">Confucius</a>
Reblog:
ReblogParentName: demo
ReblogParentTitle: Demo
ReblogParentURL: http://demo.tumblr.com/
Root:
ReblogRootName: staff
ReblogRootTitle: Tumblr Staff
ReblogRootURL: http://staff.tumblr.com/
- Type: Photo
Permalink: http://demo.tumblr.com/post/459265350/passing-through-times-square-by-mareen-fischinger
PostId: 459265350
NoteCount: 49
Tags:
- Mareen Fischinger
- New York City
- Times Square
Timestamp: 1163013960
PhotoURL-500: "http://29.media.tumblr.com/tumblr_kzjlfiTnfe1qz4rgho1_500.jpg"
PhotoURL-400: "http://29.media.tumblr.com/tumblr_kzjlfiTnfe1qz4rgho1_400.jpg"
Expand Down Expand Up @@ -57,6 +55,14 @@ Posts:
Permalink: http://demo.tumblr.com/post/459260683/allison-weiss-fingers-crossed
PostId: 459260683
NoteCount: 85
Reblog:
ReblogParentName: allisonweiss
ReblogParentTitle: A DAY IN THE LIFE OF ALLISON WEISS
ReblogParentURL: http://allisonweiss.tumblr.com/
# Root:
# ReblogRootName: staff
# ReblogRootTitle: Tumblr Staff
# ReblogRootURL: http://staff.tumblr.com/
Caption: '<p><strong><a href="#" title="http://allisonweiss.tumblr.com/">Allison Weiss</a> —</strong> Fingers Crossed</p>'
PlayCount: 18307
AlbumArtURL: http://16.media.tumblr.com/tumblr_ksc4i2SkVU1qz8ouqo1_r2_cover.jpg
Expand Down
33 changes: 30 additions & 3 deletions parser/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,22 @@ public function prepare_post($post, $markup) {
$block = $this->render_variable('Permalink', $post, $block);
$block = $this->render_variable('PostId', $post, $block);
$block = $this->render_post_date($post, $block);
if ($post['Reblog']) {
$block = $this->render_reblog_info($post, $block);
}
if ($post['Tags']) {
$block = $this->render_tags_for_post($post, $block);
}

if ($post['NoteCount']) {
$block = $this->render_variable('NoteCount', $post, $block);
$block = $this->render_block('NoteCount', $block);
$block = preg_replace('/{NoteCountWithLabel}/', $post['NoteCount']." notes", $block);
} else {
$block = $this->strip_block('NoteCount',$block);
}

if ($post['Reblog']) {
$block = $this->render_reblog_info($post, $block);
}

$block = $this->render_block('More', $block);
return $block;
}
Expand Down Expand Up @@ -209,6 +215,27 @@ protected function render_post_date($post, $block) {
return $html;
}

protected function render_tags_for_post($post, $block) {
$html = $block;
$tags = $post['Tags'];
$has_tag_block = preg_match_all($this->block_pattern('Tags'), $html, $matcher);
$tag_group = '';
if ($has_tag_block) {
foreach ($tags as $tag) {
$safe_tag = preg_replace('/\s/','_',strtolower($tag));
foreach ($matcher[2] as $tag_block) {
$tag_block = preg_replace('/{Tag}/', $tag, $tag_block);
$tag_block = preg_replace('/{URLSafeTag}/', $safe_tag, $tag_block);
$tag_block = preg_replace('/{TagURL}|{TagURLChrono}/', "tagged/".$safe_tag, $tag_block);
$tag_group .= $tag_block;
}
}
}
$html = $this->render_block('HasTags', $html);
$html = preg_replace($this->block_pattern('Tags'), $tag_group, $html);
return $html;
}

protected function render_reblog_info($post, $block) {
$html = $block;
$reblog = $post['Reblog'];
Expand Down

0 comments on commit 84af124

Please sign in to comment.