PHP: SimpleXML + SOAP

Recently after getting into XML parsing with PHP and realising how hard most of the functions were to use, I decided to put it down and that i was going to require PHP5 for all my projects. Great i thought, SOAP, PHP’s got a SOAPClient class!

Personally i didnt like the Soap class, I’m happy to hardcode the values i send to the server,  But i want to read the returned XML easily.

I looked around, and found SimpleXML, And i like it!, It  worked well with all the sniplets of XML i gave it.. Well, Until i actually used it on some live data!

Suddenly SimpleXML refuses to parse the SOAP reply…

Heres a example of XML SimpleXML didnt like:

[sourcecode language="xml"]<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetProviders xmlns="http://hostname/" />
</soap:Body>
</soap:Envelope>[/sourcecode]

See any problem? Looks valid to me!

The cause of it not parsing though? SimpleXML doesnt like any colons(:) in tagnames or attribute names! If its contained within the value of the tag or attribute its ok though.

So, What can i do? A Mass-replace of all colons? That’d potentially destroy my source data..

I came up with this short snipplet of PHP regular expressions to strip out any colons in the tags/attributes:

[sourcecode language="php"]$out = preg_replace(‘|<([/\w]+)(:)|m’,’<$1′,$in);
$out = preg_replace(‘|(\w+)(:)(\w+=\")|m’,’$1$3′,$out);[/sourcecode]

The result after this has been done:

[sourcecode language="xml"]<?xml version="1.0" encoding="utf-8"?>
<soapEnvelope xmlnsxsi="http://www.w3.org/2001/XMLSchema-instance" xmlnsxsd="http://www.w3.org/2001/XMLSchema" xmlnssoap="http://schemas.xmlsoap.org/soap/envelope/">
<soapBody>
<GetProviders xmlns="http://hostname/" />
</soapBody>
</soapEnvelope>
[/sourcecode]

As you can see, the general gyst of the document is there, and its parsable,  just without the colons where simpleXML cant handle them.

Dovecot: ERR No INBOX for user

Did something stupid a few days ago, After Opera 9.5 Alpha did something stupid with my email, I decided to clear out all email on my server..

Not a hard thing to do.. SSH to server, echo > ~/mail/username Check the list with the ‘mail‘ app, Yep all fine.. emails cleared; Then went out for a few days.

Come back today and i have no email? Strange, I send myself a test message, Doesnt turn up in my POP3 inbox.. SSH in, whoa, 92 messages on the server (using the ‘mail‘ command again), Why isnt it coming through POP3 then?

Started investigating, grabed telnet and connected to the mail server, Here’s what i got:

+OK dovecot ready.
USER my_username
+OK
PASS my_super_secret
+OK Logged in.
-ERR No INBOX for user.

Yep.. Somethings screwed on the server, But what? I didnt touch anything!

After a lot of screwing around and re-setting permissions and all that, I found the error, Can you see the error?

Dovecot mail error

No, I’m not supprised if you cant see it, It didnt hit me at first either, Especially when  mail was showing all my mail correctly.

Turned out, Dovecot doesnt like the new line at the start of the file, It bails out thinking its not a valid inbox…. removed the new line and everythings off and running fine again. Shame i bothered the hosts support a few hours ago, But at least i had fixed it before they started pulling their hair out :)

MSN: FailedAuthentication Profile accrual is required

I’m writing a PHP MSN ‘framework’ based on MSNP15 at present, This evening the SSO authentication failed with the following message: (Apologies to not having exact XML)

wsse FailedAuthentication
Failure Code: Profile accrual is required 

The cause? MSN has updated the protocol? Nope, I needed to update the profile for that account, upon logging into MSN messenger with it i was asked to fill out my Birthyear and Country. Upon entering those details in its once again working nicely.

Why blog about this? Well, Why not? Google didnt have any comments for the given failure code, might as well get an explanation out there :)

Week 12 Status update

Firstly i’d like to say, I’ve enjoyed Summer of Code, and thanks to the WP devs who chose to accept my proposal.
Secondly, i’d like to remind any testers that this plugin requires wordpress 2.3(currently in alpha).

The final Evaluation code is available in this branch: http://wordpress-soc-2007.googlecode.com/svn/trunk/dd32.crazyman/tags/gsoc-final-evaluation/

Whats happened since the mid week dash update?

Useful Things

This week the most useful resource i came accross was this blog entry: Timing is everything: scheduling in WordPress It outlines on how to use the WP-Cron functionality.

EDIT: Stupid Non-breaking spaces :(

Final Dash

So its the 17th today, GSoC pens down is officially 5am on tuesday(21st).

That means i’ve got this weekend basically to finish off everything. So what needs doing?

  1. Support for FTP other than via the inbuilt FTP Extension. This is semi done, Turns out the PemFTP library which i was relying on working doesnt seem to work at all for me (Strangely enough), but i’ve found another class PHP FTP which seems its going to work for me (Needs a lot of testing though).
  2. Upgrading of Plugins, this has been sitting there waiting to be done for awhile now, its one of the items i should’ve started with a lot earlier, but i kept putting it off to work on other items which it was to rely on.. Probably done 2/3 of that, just need to write the final copying code( It allready knows which files have changed, which have been deleted, whats new/etc, so it shouldnt be too hard)
  3. Bug Fixing.. Theres a lot more bugs surfacing, Mainly due to some functionality not being as streamlined as i wanted.
  4. Testing.. Theres not been too much testing in a variety of platforms, I was intending for this last part of the time to mainly be testing, but it doesnt look that way right now.
  5. Documentation, Luckely quite a lot of it is easy enough to follow in the files(IMHO), but i’m still going to need to write something down.
  6. Caching! Currently i make great use of the WordPress Obejct cache, however, As most people should know, Its not used for a LOT of wordpress installs. I Guess i need to throw some get_option/set_option in there for caching of the main output? (ie. the current status for the plugins(“Latest Installed” || “Update Available”) etc

What could’ve been done better.

This is something that most people will be writing after their evaluation is done, but hey, Its in the open anyway :)

  1. I came into GSoC not knowing much about the XMLRPC code which wordpress uses, In retrospect, i should’ve built the update server into that, and had it making requests via that for default, However thats not a great issue in my mind, Its only a few code changes in an extension file. At the same time i’d have liked to use RSS, but i didnt get time to locate a decent way to work with that(And representing 2d arrays in RSS to be parsed by a reader is impossible.)
  2. Time Management, I’ve never been good at time management, But i’m getting better..

Week 11 status report

Whats been acomplished this week.

  • Fixed Tag searching of WordPress.org
  • Made a lot of changes to the FTP-Ext class, Re-implemented a few functions which i wasnt happy about, added features to existing functions.
  • Made a move to $wp_update instead of $wpupdate to keep with WP coding
  • Made a move to a global $wp_filesystem class to make the coding simpler
  • Created a functionfolder_diff which relies on $wp_filesystem, used to create output such as this:
    dda-options.php (Changed)
    dda_portfolio.php (Changed)
    ddeviantart.php (Changed)
    inc (Changed)
    inc/dCustom.php (Changed)
    readme.txt (New)
    deleted_file (Deleted)
    same_file (unChanged)
  • Some more work on plugin upgrades
  • Many Many more small bugs which appeared during enhancements (And while testing on linux with FTP)

Plans for Next Week

  • Finally get a non-PHP-FTP-Extension FTP class implemented around the PemFTP classes.
  • More bugfixing (Just watch, more will come out of the woodwork)
  • More work on plugin upgrades, only another step or so left in that code i think.

The time left is Dwindling fast, incredibly fast actually, and uni workloads are increasing twice as fast.. I’m honestly supprised i got so much work done this week. (Yet so little with the time spent argueing with bugs)GSoC, WordPress, wp-update

dDeviantArt: Go vote!

dDeviantart was entered into the WordPress Plugin Competition.

You can go view the entries here:http://weblogtoolscollection.com/pluginblog/2007/08/06/2007-wordpress-plugin-competition-prize-list-and-plugins-list/

And vote for dDeviantArt over here: http://weblogtoolscollection.com/pluginblog/ddeviantart-rating-page/

Theres some great entries this time around, And by the look of it, those that win any prizes will both be deserving, and slightly richer contestants :)