Skip to content

Commit

Permalink
added support for php 5.2.x (and less than 5.3.6)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainN committed Nov 14, 2013
1 parent dc03402 commit 66f98aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion OnceFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function default_value() {
return $this->default_value;
}

abstract public function value( $value = NULL );
//abstract public function value( $value = NULL );

public function name() {
return $this->node->getAttribute('name');
Expand Down
21 changes: 19 additions & 2 deletions OnceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,25 @@ class OnceForm

protected $user_validator;

public function __toString() {
return $this->doc->saveHTML( $this->form );
public function __toString()
{
// different versions of php handle this differently
// see: http://us2.php.net/manual/en/domdocument.savehtml.php
if ( version_compare(PHP_VERSION, '5.3.6', '>=')) {
// for current versions, we need to pass a node, to get the fragment HTML
return $this->doc->saveHTML( $this->form );
}
elseif ( version_compare(PHP_VERSION, '5.2.6', '>=')) {
// for php 5.2.6 through 5.3.5 we need to trim this manually
return preg_replace('/^<!DOCTYPE.+?>/', '',
str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''),
preg_replace('/<head\b[^>]*>(.*?)<\/head>/','',$this->doc->saveHTML())
)
);
}
else
// older than 5.2.6 only saves the fragment you pass it
return $this->doc->saveHTML();
}

public function toString() {
Expand Down

0 comments on commit 66f98aa

Please sign in to comment.