Oree Eyo
|
Tuesday 02 August 2005 11:33:08 pm
Hi All I wrote this upload handler to insert article and i'm having troubles with unicode.
When I upload a file using the browser using /content/upload everything works fine.the new article is created and the charset is ok. but when I use webdav upload , the unicode characters are lost and I get odd characters instead.
my site is configured to utf-8 and works fine using the browser.
I've tried 3 webdav clients and I get the same result. ( konqueror, DAVexplorer, msie)
<i>
This problem has nothing to do with the file itself since I don't even try to open the file or read it...the unicode text is inside the code..
</i> I spent 3 days working on this problem and I don't have a clue why this is happening. eZ crew? Anyone??
function handleFile( &$upload, &$result,
$filePath, $originalFilename, $mimeInfo,
$location, $existingNode )
{
$ini =& eZINI::instance( 'i18n.ini' );
$i18nSettings = array();
$i18nSettings['internal-charset'] = $ini->variable( 'CharacterSettings', 'Charset' );
$i18nSettings['http-charset'] = $ini->variable( 'CharacterSettings', 'HTTPCharset' );
$i18nSettings['mbstring-extension'] = $ini->variable( 'CharacterSettings', 'MBStringExtension' ) == 'enabled';
eZTextCodec::updateSettings( $i18nSettings );
$charset = eZTextCodec::internalCharset(); // returns utf-8
$hcharset = eZTextCodec::httpCharset(); // returns utf-8
//place the new article
$tree = & eZContentObjectTreeNode::fetch(2);
$node = $tree->childrenByName(CONTAINER_NODE);
$nodeID = & $node[0]->MainNodeID;
// we want an article
$class = eZContentClass::fetchByIdentifier( 'article' );
$creatorID = 14; // 14 == admin
$parentNodeID = $nodeID;
$contentObject =& $class->instantiate( $creatorID, 1 );
$nodeAssignment =& eZNodeAssignment::create( array(
'contentobject_id' => $contentObject->attribute( 'id' ),
'contentobject_version' => $contentObject->attribute( 'current_version' ),
'parent_node' => $parentNodeID,
'is_main' => 1
)
);
$nodeAssignment->store();
$version =& $contentObject->version( 1 );
$version->setAttribute( 'modified', eZDateTime::currentTimeStamp() );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();
$contentObjectID = $contentObject->attribute( 'id' );
$dataMap =& $contentObject->dataMap();
{
$titleAttribute = 'title';
$bodyAttribute = 'body';
//This is a simple xml to store.
$xmlTextBody = '<?xml version="1.0" encoding="utf-8"?>
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">
<paragraph>ENTER NON ENGLISH TEXT HERE אבגה</paragraph>
</section>';
$objectName = $title;
$dataMap['intro']->setAttribute( 'data_text', 'intro' );
$dataMap['intro']->store();
$dataMap[$titleAttribute]->setAttribute( 'data_text', 'test article' );
$dataMap[$titleAttribute]->store();
$dataMap[$bodyAttribute]->setAttribute( 'data_text' $xmlTextBody);
$dataMap[$bodyAttribute]->store();
}
require_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute( 'content', 'publish',
array( 'object_id' => $contentObjectID, 'version' => 1 ) );
}
|
Xavier Dutoit
|
Wednesday 03 August 2005 1:42:02 am
Could you please clarify where you're adding the upload handler and what is you ez version ? Also, I quite don't get where is the problem: when you're adding the content or when you're trying to see it ? There is a bug in the webdav (brower part): when it contains accentued chars, it doesn't display them (error message). I sent a patch to ez, don't know if they have fixed it yet. Might be related ? X+
http://www.sydesy.com
|
Oree Eyo
|
Wednesday 03 August 2005 2:25:51 am
xavier.
First. Thanks for the webdav patch. I have it applied and It solved the problem of non-english file (object) names. Maybe you can tell if it has something to do with my problem. Alltough this is not the browser part of the webdav.
This upload handler is reffered by upload.ini and called by ezp after detecting text/html mime upload this way :
[upload.ini] MimeUploadHandlerMap[text/html]=myhandler
The idea is to create an article from the uploaded file.
This upload hanlder is called whenever I upload html document no matter if it's via webdav or via http://localhost/corporate_admin/content/upload/ But, as I mentioned above. unicode isn't stored correctly when I upload via webdav.
I think that there's no problem when I upload the content. I mean. The upload is fine and a new object is created, but when I view it in the admin interface ( and also in the database using phpmyadmin) I see odd characters instead of my unicode text ( again. only if it was a webdav upload).
My ezp Version: 3.7.0rc1 (3.7.0rc1) SVN revision: 12701
|
Xavier Dutoit
|
Friday 05 August 2005 1:26:48 am
Don't know, What is the encoding using for the webdav trafic vs. the regular one (have a look at the http headers with something like "live http headers" on firefox) ? I'd guess that's different encodings, hence the pb, but that's a wild guess. X+ P.S. If you post a bug report, please remind them about the patch I sent them, it seems to have been forgotten.
http://www.sydesy.com
|
Oree Eyo
|
Friday 05 August 2005 2:39:22 am
I'll give it a try but I'm not sure that "Sniffing" http traffic would say something, The problem is somewhere inside the informathion proccess. The following pice of code won't store data as unicode if webdav is calling it, regardless of what you upload.
$utf8text = "NON ENGLISH UNICODE TEXT";
$dataMap[$bodyAttribute]->setAttribute( 'data_text' $utf8text);
$dataMap[$bodyAttribute]->store();
As you can see, the unicode text is inside the code. HTTPCharset is set to utf-8 in i18n.ini
[CharacterSettings]
Charset=utf-8
HTTPCharset=utf-8
MBStringExtension=enabled
Maybe it doesn't apply to webdav.
I wonder if there's a "WEBDAVCharset=xyz". all tough webdav is on-top http so it should be the same. gonna do that bug-report later on. regards.
|