-
-
Save aaronpk/9951a0221a878ba7a917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// If the post has no "content" property and no "summary" property, or if both are empty, then it is a note post | |
if(!$this->get('content') && !$this->get('summary')) { | |
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); | |
if($this->get('content')) { | |
// If the post has a "content" property with a non-empty value, | |
// Then use its first non-empty value as the content | |
$content = $this->get('content'); | |
} else { | |
// Else use the first non-empty "summary" value as the content | |
$content = $this->get('summary'); | |
} | |
// 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