<?php
/**
* Delete all tags for a given content object
*/

//allow only the app owner to delete tags from any object
if (! XN_Profile::current()->isOwner()) {
$signInUrl = XN_Request::signInUrl();
echo 'Not allowed <a href="'.$signInUrl.'" >Sign in</a> if you are the owner of this app.';
die();
}
?>
<form action="" method="POST">
Object Id:<input type="text" name="object_id"/>
<input type="submit" value="Delete All Tags"/>
</form>
<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$content = XN_Content::load($_REQUEST['object_id']);
$tagQuery = XN_Query::create('Tag');
$tagQuery->filter('content','=', $content);
$tagsQueryResults = $tagQuery->execute();
$tags = array();
foreach($tagsQueryResults as $tag){
//add quotes tothe tags to ensure the full value is considered
$tags[] = '"'.$tag->value.'"';;
}
$tagString = implode(', ',$tags);
echo '<p>Content '.$content->id.' had the following tags: '.htmlentities($tagString).'</p>';
XN_Tag::deleteTags( $content , $tagString);
echo "<p>They are history.</p>";
}

?>