2013-02-11, 07:05:05
Trying to talk to NM from P&C, I used a function which returns an NM post slug. If it's not just me who thinks it's handy, maybe something as follows (based on nm_post_title) could be added to site.php?:
BTW - I used basename in the example above, because I couldn't understand why code:
returned an empty string. Why do "->date", "->title" extract the expected string from posts.xml, but not "->slug"?
PHP Code:
function nm_post_slug($echo=true) {
global $NMPAGEURL;
$slug = false;
if (isset($_GET['post']) && strval(get_page_slug(false)) == $NMPAGEURL) {
$file = NMPOSTPATH . $_GET['post'] . '.xml';
if (dirname(realpath($file)) == realpath(NMPOSTPATH)) { // no path traversal
$post = @getXML($file);
if (!empty($post) && $post->private != 'Y') {
$slug = basename($file, '.xml');
if ($echo) echo $slug;
}
}
}
return $slug;
}
BTW - I used basename in the example above, because I couldn't understand why code:
PHP Code:
$slug = $post->slug;
returned an empty string. Why do "->date", "->title" extract the expected string from posts.xml, but not "->slug"?