Skip to content

Commit

Permalink
Merge branch '3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Jul 11, 2016
2 parents 327ddb2 + 3906228 commit 5776a03
Show file tree
Hide file tree
Showing 24 changed files with 349 additions and 78 deletions.
2 changes: 1 addition & 1 deletion ORM/Connect/MySQLiConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function connect($parameters, $selectDB = false) {
}

public function __destruct() {
if ($this->dbConn) {
if (is_resource($this->dbConn)) {
mysqli_close($this->dbConn);
$this->dbConn = null;
}
Expand Down
16 changes: 8 additions & 8 deletions ORM/FieldType/DBField.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,43 +256,43 @@ public function forTemplate() {
}

public function HTMLATT() {
return Convert::raw2htmlatt($this->value);
return Convert::raw2htmlatt($this->RAW());
}

public function URLATT() {
return urlencode($this->value);
return urlencode($this->RAW());
}

public function RAWURLATT() {
return rawurlencode($this->value);
return rawurlencode($this->RAW());
}

public function ATT() {
return Convert::raw2att($this->value);
return Convert::raw2att($this->RAW());
}

public function RAW() {
return $this->value;
}

public function JS() {
return Convert::raw2js($this->value);
return Convert::raw2js($this->RAW());
}

/**
* Return JSON encoded value
* @return string
*/
public function JSON() {
return Convert::raw2json($this->value);
return Convert::raw2json($this->RAW());
}

public function HTML(){
return Convert::raw2xml($this->value);
return Convert::raw2xml($this->RAW());
}

public function XML(){
return Convert::raw2xml($this->value);
return Convert::raw2xml($this->RAW());
}

/**
Expand Down
24 changes: 15 additions & 9 deletions ORM/FieldType/DBHTMLText.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function Summary($maxWords = 50, $flex = 15, $add = '...') {
// Catch warnings thrown by loadHTML and turn them into a failure boolean rather than a SilverStripe error
set_error_handler(create_function('$no, $str', 'throw new Exception("HTML Parse Error: ".$str);'), E_ALL);
// Nonbreaking spaces get converted into weird characters, so strip them
$value = str_replace(' ', ' ', $this->value);
$value = str_replace(' ', ' ', $this->RAW());
try {
$res = $doc->loadHTML('<meta content="text/html; charset=utf-8" http-equiv="Content-type"/>' . $value);
}
Expand Down Expand Up @@ -186,6 +186,15 @@ public function FirstSentence() {
return $this->Summary();
}

public function RAW() {
if ($this->processShortcodes) {
return ShortcodeParser::get_active()->parse($this->value);
}
else {
return $this->value;
}
}

/**
* Return the value of the field with relative links converted to absolute urls (with placeholders parsed).
* @return string
Expand All @@ -195,12 +204,7 @@ public function AbsoluteLinks() {
}

public function forTemplate() {
if ($this->processShortcodes) {
return ShortcodeParser::get_active()->parse($this->value);
}
else {
return $this->value;
}
return $this->RAW();
}

public function prepValueForDB($value) {
Expand Down Expand Up @@ -248,14 +252,16 @@ public function exists() {
return false;
}

$value = $this->RAW();

// If it's got a content tag
if(preg_match('/<(img|embed|object|iframe|meta|source|link)[^>]*>/i', $this->value)) {
if(preg_match('/<(img|embed|object|iframe|meta|source|link)[^>]*>/i', $value)) {
return true;
}

// If it's just one or two tags on its own (and not the above) it's empty.
// This might be <p></p> or <h1></h1> or whatever.
if(preg_match('/^[\\s]*(<[^>]+>[\\s]*){1,2}$/', $this->value)) {
if(preg_match('/^[\\s]*(<[^>]+>[\\s]*){1,2}$/', $value)) {
return false;
}

Expand Down
7 changes: 6 additions & 1 deletion ORM/FieldType/DBHTMLVarchar.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ public function setOptions(array $options = array()) {
}

public function forTemplate() {
return $this->RAW();
}

public function RAW() {
if ($this->processShortcodes) {
return ShortcodeParser::get_active()->parse($this->value);
}
else {
return $this->value;
}

}

public function exists() {
return parent::exists() && $this->value != '<p></p>';
return parent::exists() && $this->RAW() != '<p></p>';
}

public function scaffoldFormField($title = null, $params = null) {
Expand Down
27 changes: 14 additions & 13 deletions ORM/FieldType/DBString.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public function getNullifyEmpty() {
* @see core/model/fieldtypes/DBField#exists()
*/
public function exists() {
return $this->getValue() // All truthy values exist
|| (is_string($this->getValue()) && strlen($this->getValue())) // non-empty strings exist ('0' but not (int)0)
|| (!$this->getNullifyEmpty() && $this->getValue() === ''); // Remove this stupid exemption in 4.0
$value = $this->RAW();
return $value // All truthy values exist
|| (is_string($value) && strlen($value)) // non-empty strings exist ('0' but not (int)0)
|| (!$this->getNullifyEmpty() && $value === ''); // Remove this stupid exemption in 4.0
}

/**
Expand Down Expand Up @@ -122,7 +123,7 @@ public function forTemplate() {
* @return string
*/
public function LimitCharacters($limit = 20, $add = '...') {
$value = trim($this->value);
$value = trim($this->RAW());
if($this->stat('escape_type') == 'xml') {
$value = strip_tags($value);
$value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');
Expand All @@ -146,13 +147,13 @@ public function LimitCharacters($limit = 20, $add = '...') {
*/
public function LimitCharactersToClosestWord($limit = 20, $add = '...') {
// Strip HTML tags if they exist in the field
$this->value = strip_tags($this->value);
$value = strip_tags($this->RAW());

// Determine if value exceeds limit before limiting characters
$exceedsLimit = mb_strlen($this->value) > $limit;
$exceedsLimit = mb_strlen($value) > $limit;

// Limit to character limit
$value = $this->LimitCharacters($limit, '');
$value = DBField::create_field(get_class($this), $value)->LimitCharacters($limit, '');

// If value exceeds limit, strip punctuation off the end to the last space and apply ellipsis
if($exceedsLimit) {
Expand All @@ -178,11 +179,11 @@ public function LimitCharactersToClosestWord($limit = 20, $add = '...') {
* @return string
*/
public function LimitWordCount($numWords = 26, $add = '...') {
$this->value = trim(Convert::xml2raw($this->value));
$ret = explode(' ', $this->value, $numWords + 1);
$value = trim(Convert::xml2raw($this->RAW()));
$ret = explode(' ', $value, $numWords + 1);

if(count($ret) <= $numWords - 1) {
$ret = $this->value;
$ret = $value;
} else {
array_pop($ret);
$ret = implode(' ', $ret) . $add;
Expand Down Expand Up @@ -213,15 +214,15 @@ public function LimitWordCountXML($numWords = 26, $add = '...') {
* @return string
*/
public function LowerCase() {
return mb_strtolower($this->value);
return mb_strtolower($this->RAW());
}

/**
* Converts the current value for this StringField to uppercase.
* @return string
*/
public function UpperCase() {
return mb_strtoupper($this->value);
return mb_strtoupper($this->RAW());
}

/**
Expand All @@ -230,6 +231,6 @@ public function UpperCase() {
* @return string
*/
public function NoHTML() {
return strip_tags($this->value);
return strip_tags($this->RAW());
}
}
29 changes: 15 additions & 14 deletions ORM/FieldType/DBText.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function requireField() {
* @return string
*/
public function AbsoluteLinks() {
return HTTP::absoluteURLs($this->value);
return HTTP::absoluteURLs($this->RAW());
}

/**
Expand All @@ -86,7 +86,7 @@ public function LimitSentences($sentCount = 2) {
}

$output = array();
$data = trim(Convert::xml2raw($this->value));
$data = trim(Convert::xml2raw($this->RAW()));
$sentences = explode('.', $data);

if ($sentCount == 0) return '';
Expand All @@ -106,7 +106,7 @@ public function LimitSentences($sentCount = 2) {
* Caution: Not XML/HTML-safe - does not respect closing tags.
*/
public function FirstSentence() {
$paragraph = Convert::xml2raw( $this->value );
$paragraph = Convert::xml2raw( $this->RAW() );
if( !$paragraph ) return "";

$words = preg_split('/\s+/', $paragraph);
Expand All @@ -127,7 +127,7 @@ public function FirstSentence() {
public function Summary($maxWords = 50) {
// get first sentence?
// this needs to be more robust
$value = Convert::xml2raw( $this->value /*, true*/ );
$value = Convert::xml2raw( $this->RAW() /*, true*/ );
if(!$value) return '';

// grab the first paragraph, or, failing that, the whole content
Expand Down Expand Up @@ -169,7 +169,7 @@ public function BigSummary($maxWords = 50, $plain = true) {

// get first sentence?
// this needs to be more robust
$data = $plain ? Convert::xml2raw($this->value, true) : $this->value;
$data = $plain ? Convert::xml2raw($this->RAW(), true) : $this->RAW();

if(!$data) return '';

Expand Down Expand Up @@ -209,8 +209,9 @@ public function BigSummary($maxWords = 50, $plain = true) {
public function FirstParagraph($plain = 1) {
// get first sentence?
// this needs to be more robust
$value = $this->RAW();
if($plain && $plain != 'html') {
$data = Convert::xml2raw($this->value);
$data = Convert::xml2raw($value);
if(!$data) return "";

// grab the first paragraph, or, failing that, the whole content
Expand All @@ -219,12 +220,12 @@ public function FirstParagraph($plain = 1) {

return $data;
} else {
if(strpos($this->value, "</p>") === false) return $this->value;
if(strpos($value, "</p>") === false) return $value;

$data = substr($this->value, 0, strpos($this->value, "</p>") + 4);
$data = substr($value, 0, strpos($value, "</p>") + 4);

if(strlen($data) < 20 && strpos($this->value, "</p>", strlen($data))) {
$data = substr($this->value, 0, strpos( $this->value, "</p>", strlen($data)) + 4 );
if(strlen($data) < 20 && strpos($value, "</p>", strlen($data))) {
$data = substr($value, 0, strpos( $value, "</p>", strlen($data)) + 4 );
}

return $data;
Expand Down Expand Up @@ -253,7 +254,7 @@ public function ContextSummary($characters = 500, $string = false, $striphtml =
}

// Remove HTML tags so we don't have to deal with matching tags
$text = $striphtml ? $this->NoHTML() : $this->value;
$text = $striphtml ? $this->NoHTML() : $this->RAW();

// Find the search string
$position = (int) stripos($text, $string);
Expand Down Expand Up @@ -285,7 +286,7 @@ public function ContextSummary($characters = 500, $string = false, $striphtml =
$summary = trim($summary);

if($position > 0) $summary = $prefix . $summary;
if(strlen($this->value) > ($characters + $position)) $summary = $summary . $suffix;
if(strlen($this->RAW()) > ($characters + $position)) $summary = $summary . $suffix;

return $summary;
}
Expand All @@ -299,14 +300,14 @@ public function ContextSummary($characters = 500, $string = false, $striphtml =
*/
public function Parse($parser = "TextParser") {
if($parser == "TextParser" || is_subclass_of($parser, "TextParser")) {
$obj = new $parser($this->value);
$obj = new $parser($this->RAW());
return $obj->parse();
} else {
// Fallback to using raw2xml and show a warning
// TODO Don't kill script execution, we can continue without losing complete control of the app
user_error("Couldn't find an appropriate TextParser sub-class to create (Looked for '$parser')."
. "Make sure it sub-classes TextParser and that you've done ?flush=1.", E_USER_WARNING);
return Convert::raw2xml($this->value);
return Convert::raw2xml($this->RAW());
}
}

Expand Down
12 changes: 8 additions & 4 deletions ORM/FieldType/DBVarchar.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,27 @@ public function requireField() {
* Return the first letter of the string followed by a .
*/
public function Initial() {
if($this->exists()) return $this->value[0] . '.';
if($this->exists()) {
$value = $this->RAW();
return $value[0] . '.';
}
}

/**
* Ensure that the given value is an absolute URL.
*/
public function URL() {
if(preg_match('#^[a-zA-Z]+://#', $this->value)) return $this->value;
else return "http://" . $this->value;
$value = $this->RAW();
if(preg_match('#^[a-zA-Z]+://#', $value)) return $value;
else return "http://" . $value;
}

/**
* Return the value of the field in rich text format
* @return string
*/
public function RTF() {
return str_replace("\n", '\par ', $this->value);
return str_replace("\n", '\par ', $this->RAW());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Security/MemberLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function __construct($controller, $name, $fields = null, $actions = null,
FormAction::create('dologin', _t('Member.BUTTONLOGIN', "Log in")),
LiteralField::create(
'forgotPassword',
'<p id="ForgotPassword"><a href="Security/lostpassword">'
'<p id="ForgotPassword"><a href="' . Security::lost_password_url() . '">'
. _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
)
);
Expand Down
3 changes: 1 addition & 2 deletions Security/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,9 @@ public static function checkMember($member, $code, $arg = "any", $strict = true)
}
}
}
elseif (substr($permCode, 0, 11) === 'CMS_ACCESS_') {
elseif (substr($permCode, 0, 11) === 'CMS_ACCESS_' && !in_array('CMS_ACCESS_LeftAndMain', $code)) {
//cms_access_leftandmain means access to all CMS areas
$code[] = 'CMS_ACCESS_LeftAndMain';
break;
}
}

Expand Down
Loading

0 comments on commit 5776a03

Please sign in to comment.