OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



[Multibyte support] Exporting articles and issues plugin

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

[Multibyte support] Exporting articles and issues plugin

Postby suzuki@wul » Thu Mar 29, 2007 8:21 pm

Dear all,

Exporting articles and issues plugin could not handle Japanese characters (UTF-8 ).
Then we've revised *XMLNode.inc.php*. It works well at our OJS.

I'm not an programmer, but If you have any comments or suggestions, please let me know.
I'll pass along them to the programmer, Mr Matsuo.

Best regards,
Suzuki
Waseda University Library / JAPAN

The revised code:
=============================================
<?php

/**
* XMLNode.inc.php
*
* Copyright (c) 2003-2006 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @package xml
*
* Default handler for XMLParser returning a simple DOM-style object.
* This handler parses an XML document into a tree structure of XMLNode objects.
*
* $Id: XMLNode.inc.php,v 1.11 2006/06/12 23:25:57 alec Exp $
*/

class XMLNode {

/** @var string the element (tag) name */
var $name;

/** @var XMLNode reference to the parent node (null if this is the root node) */
var $parent;

/** @var array the element's attributes */
var $attributes;

/** @var string the element's value */
var $value;

/** @var array references to the XMLNode children of this node */
var $children;

/**
* Constructor.
* @param $name element/tag name
*/
function XMLNode($name = null) {
$this->name = $name;
$this->parent = null;
$this->attributes = array();
$this->value = null;
$this->children = array();
}

/**
* @return string
*/
function getName() {
return $this->name;
}

/**
* @param $name string
*/
function setName($name) {
$this->name = $name;
}

/**
* @return XMLNode
*/
function &getParent() {
return $this->parent;
}

/**
* @param $parent XMLNode
*/
function setParent(&$parent) {
$this->parent = &$parent;
}

/**
* @return array all attributes
*/
function getAttributes() {
return $this->attributes;
}

/**
* @param $name string attribute name
* @return string attribute value
*/
function getAttribute($name) {
return isset($this->attributes[$name]) ? $this->attributes[$name] : null;
}

/**
* @param $name string attribute name
* @param value string attribute value
*/
function setAttribute($name, &$value) {
$this->attributes[$name] = &$value;
}

/**
* @param $attributes array
*/
function setAttributes($attributes) {
$this->attributes = $attributes;
}

/**
* @return string
*/
function &getValue() {
return $this->value;
}

/**
* @param $value string
*/
function setValue($value) {
$this->value = &$value;
}

/**
* @return array this node's children (XMLNode objects)
*/
function &getChildren() {
return $this->children;
}

/**
* @param $name
* @param $index
* @return XMLNode the ($index+1)th child matching the specified name
*/
function &getChildByName($name, $index = 0) {
foreach ($this->children as $child) {
if ($child->getName() == $name) {
if ($index == 0) {
return $child;
} else {
$index--;
}
}
}
$child = null;
return $child;
}

/**
* @param $node XMLNode the child node to add
*/
function addChild(&$node) {
$this->children[] = &$node;
}

/**
* @param $output file handle to write to, or true for stdout, or null if XML to be returned as string
* @return string
*/
function &toXml($output = null) {
$nullVar = null;
$out = '';

if ($this->parent === null) {
// This is the root node. Output information about the document.
$out .= "<?xml version=\"" . $this->getAttribute('version') . "\" encoding=\"UTF-8\"?>\n";
if ($this->getAttribute('type') != '') {
if ($this->getAttribute('url') != '') {
$out .= "<!DOCTYPE " . $this->getAttribute('type') . " PUBLIC \"" . $this->getAttribute('dtd') . "\" \"" . $this->getAttribute('url') . "\">";
} else {
$out .= "<!DOCTYPE " . $this->getAttribute('type') . " SYSTEM \"" . $this->getAttribute('dtd') . "\">";
}
}
}

if ($this->name !== null) {
$out .= '<' . $this->name;
foreach ($this->attributes as $name => $value) {
$value = XMLNode::xmlentities($value);
$out .= " $name=\"$value\"";
}
$out .= '>';
}
$out .= XMLNode::xmlentities($this->value, ENT_NOQUOTES);
foreach ($this->children as $child) {
if ($output !== null) {
if ($output === true) echo $out;
else fwrite ($output, $out);
$out = '';
}
$out .= $child->toXml($output);
}
if ($this->name !== null) $out .= '</' . $this->name . '>';
if ($output !== null) {
if ($output === true) echo $out;
else fwrite ($output, $out);
return $nullVar;
}
return $out;
}

function xmlentities($string, $quote_style=ENT_QUOTES) {
// from tmp1000 at fastmail dot deleteme dot fm and duke at redump dot de;
// see http://ca3.php.net/htmlentities

// CHG 20070319 H.Matsuo *** from ***
/*static $trans;
if (!isset($trans)) {
$trans = get_html_translation_table(HTML_ENTITIES, $quote_style);
foreach ($trans as $key => $value)
$trans[$key] = '&#'.ord($key).';';
}

return strtr($string, $trans);*/
return htmlentities($string, $quote_style, 'UTF-8');
// CHG 20070319 H.Matsuo *** to ***
}

}

?>
=====================================================
suzuki@wul
 
Posts: 5
Joined: Tue Mar 06, 2007 10:41 pm
Location: Waseda University Library / JAPAN

Postby asmecher » Fri Mar 30, 2007 12:04 am

Hi Suzuki,

Is the only change in question the xmlentities function? If so, the same change has already been made in CVS -- see http://pkp.sfu.ca/cvs/cvsweb.cgi/ojs2/classes/xml/XMLNode.inc.php.diff?r1=1.11;r2=1.12. This will be released with OJS 2.2.

Regards,
Alec Smecher
Open Journal Systems Team
---
Don't miss the First International PKP Scholarly Publishing Conference
July 11 - 13, 2007, Vancouver, BC, Canada
http://ocs.sfu.ca/pkp2007/
asmecher
 
Posts: 8610
Joined: Wed Aug 10, 2005 12:56 pm

Postby suzuki@wul » Fri Mar 30, 2007 12:36 am

Hi Alec,

Yes, that is the only change we made.

Regards,
Suzuki
suzuki@wul
 
Posts: 5
Joined: Tue Mar 06, 2007 10:41 pm
Location: Waseda University Library / JAPAN


Return to OJS Development

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 3 guests