Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Created September 30, 2015 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronpk/f8711b886011033d7dda to your computer and use it in GitHub Desktop.
Save aaronpk/f8711b886011033d7dda to your computer and use it in GitHub Desktop.
<?php
if($this->get('content')) {
// If the post has a "content" property with a non-empty value, use its first non-empty value as the content
$content = $this->get('content');
} else if($this->get('summary')) {
// Else if the post has a "summary" property with a non-empty value, use its first non-empty value as the content
$content = $this->get('summary');
} else {
// Else it is a note post
return 'note';
}
// If the post has no "name" property, or has a "name" property with an empty string value (or no value), then it is a note post.
if(!$this->get('name')) {
return 'note';
}
// Take the first value of the "name" property
$name = $this->get('name');
if(is_array($name))
$name = $name[0];
// Trim all leading/trailing whitespace
$name = trim($name);
// Collapse all sequences of internal whitespace to a single space (0x20) character each
$name = preg_replace('/\s+/', ' ', $name);
// Do the same with the first value of the "content" property
if(is_array($content))
$content = $content[0];
$content = trim($content);
$content = preg_replace('/\s+/m', ' ', $content);
// If this processed "name" property value is NOT a prefix of the processed "content" property, then it is an article post.
if(strpos($content, $name) === false) {
return 'article';
}
return 'note';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment