Skip to content

Commit

Permalink
Filtering improvements and work toward comments
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmj authored and boonebgorges committed Oct 25, 2011
1 parent 751c12e commit 3c412b8
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 17 deletions.
99 changes: 82 additions & 17 deletions includes/class-tei-dom.php
Expand Up @@ -129,15 +129,13 @@ public function buildProjectData() {
foreach($libraryItemObjectsArray as $libraryItemObject) {

$origPostData = get_post_meta($libraryItemObject->ID, 'anthologize_meta', true );

$libraryItemObject->original_post_id = isset( $origPostData['original_post_id'] ) ? $origPostData['original_post_id'] : false;

$newItem = $this->newItem($libraryItemObject);
$newItem->setAttribute('xml:id', "body-$partNumber-$itemNumber");
if($this->includeStructuredSubjects) {
$this->addStructuredSubjects($libraryItemObject->original_post_id);
}

$newItem->setAttribute('n', $itemNumber);
$newPart->appendChild($newItem);
$itemNumber++;
Expand Down Expand Up @@ -304,15 +302,76 @@ public function sanitizeImages() {

}

public function addStructuredPerson($wpUserObj) {

$newPerson = $this->newStructuredPerson($wpUserObj);
public function addStructuredPerson($personObj, $type = 'user') {

switch($type) {
case 'user':
$newPerson = $this->newStructuredPerson($personObj);
break;

case 'commenter':
$newPerson = $this->newStructuredCommenter($personObj);

break;
}

if($newPerson) {
$this->structuredPersonList->appendChild($newPerson);
}

}

public function newStructuredCommenter($commenterObj) {
$id = $commenterObj->comment_author_email;

if( array_key_exists($id, $this->knowenPersons)) {
$this->knownPersons[$id] = $this->knownPersons[$id] + 1;

//since the node is added to the TEI at 1st occurance, update the node already in the TEI
$personCountNode = $this->xpath->query("//tei:person[@xml:id = '$id']/tei:persName/tei:num")->item(0);
$personCountNode->nodeValue = $this->knownPersons[$id];
return false;
}
$this->knownPersons[$id] = 1;

$person = $this->dom->createElementNS(TEI, 'person');
$person->setAttribute('xml:id', $id );
$persName = $this->dom->createElementNS(TEI, 'persName');
$name = $this->dom->createElementNS(TEI, 'name');
$name->appendChild($this->sanitizeString($commenterObj->comment_author));

$email = $this->dom->createElementNS(TEI, 'email');
$email->appendChild($this->sanitizeString($commenterObj->comment_author_email));

$grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $commenterObj->comment_author_email ) ) ) ;

//building it myself rather using WP's function so I build a node in the right document
$grav = $this->dom->createElementNS(HTML, 'img');
$src = $grav->setAttribute('src', $grav_url);

//adding the nodes to the TEI as I build them because otherwise funky and wrong xmlns:defaults are added

$figure = $this->dom->createElementNS(TEI, 'figure');
$person->appendChild($figure);
$graphic = $this->dom->createElementNS(TEI, 'graphic');
$graphic->setAttribute('type', 'gravatar');
$graphic->setAttribute('url', $grav_url);
$figure->appendChild($graphic);
$graphic->appendChild($grav);


$persName->appendChild($name);
$link = $this->dom->createElementNS(TEI, 'link');
$link->setAttribute('type', 'webpage');
$link->appendChild($this->dom->createTextNode(rtrim($commenterObj->comment_author_url, '/')));
$persName->appendChild($link);

$person->appendChild($persName);

return $person;

}

public function newStructuredPerson($wpUserObj) {

$id = $wpUserObj->user_login;
Expand Down Expand Up @@ -340,7 +399,6 @@ public function newStructuredPerson($wpUserObj) {
$count->setAttribute('type', 'count');
$count->appendChild($this->dom->createTextNode('1'));


$desc = $this->dom->createElementNS(TEI, 'note');
$desc->setAttribute('type', 'description');
$desc->appendChild($this->sanitizeString($wpUserObj->description, true));
Expand Down Expand Up @@ -451,11 +509,16 @@ public function newSubjectRefString($subject) {
public function newNote($commentObj) {
$note = $this->dom->createElementNS(TEI, 'note');
$bibl = $this->dom->createElementNS(TEI, 'bibl');
$commentAuthor = $this->dom->createElementNS(TEI, 'author');
$commentAuthor->setAttribute('ref', $commentObj->comment_author_email);
$commentAuthor->setAttribute('type', 'commenter');
$this->addStructuredPerson($commentObj, 'commenter');
$note->appendChild($bibl);
//TODO: figure out commenter data structures
$commenterObj = new StdClass();
$bibl->appendChild($this->newCommenter($commenterObj));
//$commenterObj = new StdClass();
//$bibl->appendChild($this->newCommenter($commenterObj));
$note->appendChild($this->sanitizeString($commentObj->comment_content, true));
return $note;
}


Expand Down Expand Up @@ -537,10 +600,15 @@ public function newItem($libraryItemObject) {
if($this->includeComments) {
$commentsDiv = $this->dom->createElementNS(TEI, 'div');
$commentsDiv->setAttribute('type', 'comments');
$comments = array(); //for me and boone to figure out
$args = array(
'post_id' => $libraryItemObject->original_post_id,
'status' => 'approve'
);
$comments = get_comments($args);
foreach($comments as $comment) {
$commentsDiv->appendChild($this->newNote($comment));
}
$newItem->appendChild($commentsDiv);
}

return $newItem;
Expand Down Expand Up @@ -624,15 +692,14 @@ public function newHead($postObject) {
}

public function sanitizeString($content, $isMultiline = false) {

$content = $this->sanitizeEntities($content);
$content = $this->sanitizeEntities($content);

if ($isMultiline) {
//TODO: check if this is redundant now that I'm using apply_filters()'
//$content = wpautop($content);
//$content = $this->sanitizeShortCodes($content);

$content = apply_filters('the_content', $content);
$content = apply_filters('the_content', $content);
$content = wpautop($content);

if($this->tidy) {
$this->tidy->parseString($content, array(), 'utf8');
$this->tidy->cleanRepair();
Expand All @@ -652,9 +719,7 @@ public function sanitizeString($content, $isMultiline = false) {

//using loadHTML because it is more forgiving than loadXML
$tmpHTML = new DOMDocument('1.0', 'UTF-8');
//conceal the Warning about bad html with @
//loadHTML adds head and body tags silently
@$tmpHTML->loadHTML("<?xml version='1.0' encoding='UTF-8' ?><$element xmlns='http://www.w3.org/1999/xhtml'>$content</$element>" );
@$tmpHTML->loadHTML("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body><$element xmlns='http://www.w3.org/1999/xhtml'>$content</$element></body></html>" );
if($this->checkImgSrcs) {
$this->checkImageSources($tmpHTML);
}
Expand Down
1 change: 1 addition & 0 deletions templates/tei/base.php
Expand Up @@ -10,6 +10,7 @@
'includeStructuredCreatorData' => true, //include structured data about creators
'includeOriginalPostData' => true, //include data about the original post (true to use tags and categories)
'checkImgSrcs' => false, //whether to check availability of image sources
'includeComments' => true,
'linkToEmbeddedObjects' => false,
'indexSubjects' => true,
'indexCategories' => true,
Expand Down

0 comments on commit 3c412b8

Please sign in to comment.