";
+ }
- /**
- * Start an individual timer
- * This will pause the running timer and place it on a stack.
- * @param string $name name of the timer
- * @param string optional $desc description of the timer
- */
- public function startTimer($name, $desc="" ){
- $this->trace.="start $name\n";
- $n=array_push( $this->stack, $this->cur_timer );
- $this->__suspendTimer( $this->stack[$n-1] );
- $this->startTime[$name] = $this->getMicroTime();
- $this->cur_timer=$name;
- $this->description[$name] = $desc;
- if (!array_key_exists($name,$this->count))
- $this->count[$name] = 1;
- else
- $this->count[$name]++;
- }
+ /**
+ * Start an individual timer
+ * This will pause the running timer and place it on a stack.
+ * @param string $name name of the timer
+ * @param string optional $desc description of the timer
+ */
+ public function startTimer($name, $desc="" ){
+ $this->trace.="start $name\n";
+ $n=array_push( $this->stack, $this->cur_timer );
+ $this->__suspendTimer( $this->stack[$n-1] );
+ $this->startTime[$name] = $this->getMicroTime();
+ $this->cur_timer=$name;
+ $this->description[$name] = $desc;
+ if (!array_key_exists($name,$this->count))
+ $this->count[$name] = 1;
+ else
+ $this->count[$name]++;
+ }
- /**
- * Stop an individual timer
- * Restart the timer that was running before this one
- * @param string $name name of the timer
- */
- public function stopTimer($name){
- $this->trace.="stop $name\n";
- $this->endTime[$name] = $this->getMicroTime();
- if (!array_key_exists($name, $this->running))
- $this->running[$name] = $this->elapsedTime($name);
- else
- $this->running[$name] += $this->elapsedTime($name);
- $this->cur_timer=array_pop($this->stack);
- $this->__resumeTimer($this->cur_timer);
- }
+ /**
+ * Stop an individual timer
+ * Restart the timer that was running before this one
+ * @param string $name name of the timer
+ */
+ public function stopTimer($name){
+ $this->trace.="stop $name\n";
+ $this->endTime[$name] = $this->getMicroTime();
+ if (!array_key_exists($name, $this->running))
+ $this->running[$name] = $this->elapsedTime($name);
+ else
+ $this->running[$name] += $this->elapsedTime($name);
+ $this->cur_timer=array_pop($this->stack);
+ $this->__resumeTimer($this->cur_timer);
+ }
- /**
- * measure the elapsed time of a timer without stoping the timer if
- * it is still running
- */
- public function elapsedTime($name){
- // This shouldn't happen, but it does once.
- if (!array_key_exists($name,$this->startTime))
- return 0;
+ /**
+ * measure the elapsed time of a timer without stoping the timer if
+ * it is still running
+ */
+ public function elapsedTime($name){
+ // This shouldn't happen, but it does once.
+ if (!array_key_exists($name,$this->startTime))
+ return 0;
- if(array_key_exists($name,$this->endTime)){
- return ($this->endTime[$name] - $this->startTime[$name]);
- } else {
- $now=$this->getMicroTime();
- return ($now - $this->startTime[$name]);
- }
- }//end start_time
+ if(array_key_exists($name,$this->endTime)){
+ return ($this->endTime[$name] - $this->startTime[$name]);
+ } else {
+ $now=$this->getMicroTime();
+ return ($now - $this->startTime[$name]);
+ }
+ }//end start_time
- /**
- * Measure the elapsed time since the profile class was initialised
- *
- */
- public function elapsedOverall(){
- $oaTime = $this->getMicroTime() - $this->initTime;
- return($oaTime);
- }//end start_time
+ /**
+ * Measure the elapsed time since the profile class was initialised
+ *
+ */
+ public function elapsedOverall(){
+ $oaTime = $this->getMicroTime() - $this->initTime;
+ return($oaTime);
+ }//end start_time
- /**
- * print out a log of all the timers that were registered
- *
- */
- public function printTimers($enabled=false)
- {
- if($this->output_enabled||$enabled){
- $TimedTotal = 0;
- $tot_perc = 0;
- ksort($this->description);
- print("
\n");
- $oaTime = $this->getMicroTime() - $this->initTime;
- echo"============================================================================\n";
- echo " PROFILER OUTPUT\n";
- echo"============================================================================\n";
- print( "Calls Time Routine\n");
- echo"-----------------------------------------------------------------------------\n";
- while (list ($key, $val) = each ($this->description)) {
- $t = $this->elapsedTime($key);
- $total = $this->running[$key];
- $count = $this->count[$key];
- $TimedTotal += $total;
- $perc = ($total/$oaTime)*100;
- $tot_perc+=$perc;
- // $perc=sprintf("%3.2f", $perc );
- $lines[ sprintf( "%3d %3.4f ms (%3.2f %%) %s\n", $count, $total*1000, $perc, $key) ] = $total;
- }
+ /**
+ * print out a log of all the timers that were registered
+ *
+ */
+ public function printTimers($enabled=false)
+ {
+ if($this->output_enabled||$enabled){
+ $TimedTotal = 0;
+ $tot_perc = 0;
+ ksort($this->description);
+ print("
$sql";
DB::query($sql);
diff --git a/model/HasManyList.php b/model/HasManyList.php
index 290f8955a..c39efceb4 100644
--- a/model/HasManyList.php
+++ b/model/HasManyList.php
@@ -66,10 +66,10 @@ class HasManyList extends RelationList {
* @param $itemID The ID of the item to be removed
*/
public function removeByID($itemID) {
- $item = $this->byID($itemID);
- return $this->remove($item);
- }
-
+ $item = $this->byID($itemID);
+ return $this->remove($item);
+ }
+
/**
* Remove an item from this relation.
* Doesn't actually remove the item, it just clears the foreign key value.
@@ -77,10 +77,10 @@ class HasManyList extends RelationList {
* @todo Maybe we should delete the object instead?
*/
public function remove($item) {
- if(!($item instanceof $this->dataClass)) {
- throw new InvalidArgumentException("HasManyList::remove() expecting a $this->dataClass object, or ID",
- E_USER_ERROR);
- }
+ if(!($item instanceof $this->dataClass)) {
+ throw new InvalidArgumentException("HasManyList::remove() expecting a $this->dataClass object, or ID",
+ E_USER_ERROR);
+ }
$fk = $this->foreignKey;
$item->$fk = null;
diff --git a/model/Hierarchy.php b/model/Hierarchy.php
index cd9d990f7..4fa8f98d9 100644
--- a/model/Hierarchy.php
+++ b/model/Hierarchy.php
@@ -434,14 +434,14 @@ class Hierarchy extends DataExtension {
public function Children() {
if(!(isset($this->_cache_children) && $this->_cache_children)) {
$result = $this->owner->stageChildren(false);
- if(isset($result)) {
- $this->_cache_children = new ArrayList();
- foreach($result as $child) {
- if($child->canView()) {
- $this->_cache_children->push($child);
- }
- }
- }
+ if(isset($result)) {
+ $this->_cache_children = new ArrayList();
+ foreach($result as $child) {
+ if($child->canView()) {
+ $this->_cache_children->push($child);
+ }
+ }
+ }
}
return $this->_cache_children;
}
@@ -487,10 +487,10 @@ class Hierarchy extends DataExtension {
// Next, go through the live children. Only some of these will be listed
$liveChildren = $this->owner->liveChildren(true, true);
if($liveChildren) {
- $merged = new ArrayList();
- $merged->merge($stageChildren);
- $merged->merge($liveChildren);
- $stageChildren = $merged;
+ $merged = new ArrayList();
+ $merged->merge($stageChildren);
+ $merged->merge($liveChildren);
+ $stageChildren = $merged;
}
}
@@ -526,7 +526,7 @@ class Hierarchy extends DataExtension {
throw new Exception('Hierarchy->AllHistoricalChildren() only works with Versioned extension applied');
}
- return Versioned::get_including_deleted(ClassInfo::baseDataClass($this->owner->class),
+ return Versioned::get_including_deleted(ClassInfo::baseDataClass($this->owner->class),
"\"ParentID\" = " . (int)$this->owner->ID)->count();
}
diff --git a/model/ManyManyList.php b/model/ManyManyList.php
index e3e1a1b27..1cfb5069c 100644
--- a/model/ManyManyList.php
+++ b/model/ManyManyList.php
@@ -117,11 +117,11 @@ class ManyManyList extends RelationList {
* @param $itemID The ID of the item to remove.
*/
public function remove($item) {
- if(!($item instanceof $this->dataClass)) {
- throw new InvalidArgumentException("ManyManyList::remove() expecting a $this->dataClass object");
- }
-
- return $this->removeByID($item->ID);
+ if(!($item instanceof $this->dataClass)) {
+ throw new InvalidArgumentException("ManyManyList::remove() expecting a $this->dataClass object");
+ }
+
+ return $this->removeByID($item->ID);
}
/**
@@ -130,7 +130,7 @@ class ManyManyList extends RelationList {
* @param $itemID The item it
*/
public function removeByID($itemID) {
- if(!is_numeric($itemID)) throw new InvalidArgumentException("ManyManyList::removeById() expecting an ID");
+ if(!is_numeric($itemID)) throw new InvalidArgumentException("ManyManyList::removeById() expecting an ID");
$query = new SQLQuery("*", array("\"$this->joinTable\""));
$query->setDelete(true);
@@ -145,16 +145,16 @@ class ManyManyList extends RelationList {
$query->execute();
}
- /**
- * Remove all items from this many-many join. To remove a subset of items, filter it first.
- */
- public function removeAll() {
+ /**
+ * Remove all items from this many-many join. To remove a subset of items, filter it first.
+ */
+ public function removeAll() {
$query = $this->dataQuery()->query();
$query->setDelete(true);
$query->setSelect(array('*'));
$query->setFrom("\"$this->joinTable\"");
$query->execute();
- }
+ }
/**
* Find the extra field data for a single row of the relationship
diff --git a/model/MySQLDatabase.php b/model/MySQLDatabase.php
index c0069bead..e85f26123 100644
--- a/model/MySQLDatabase.php
+++ b/model/MySQLDatabase.php
@@ -269,8 +269,8 @@ class MySQLDatabase extends SS_Database {
if($alteredIndexes) foreach($alteredIndexes as $k => $v) {
$alterList[] .= "DROP INDEX \"$k\"";
$alterList[] .= "ADD ". $this->getIndexSqlDefinition($k, $v);
- }
-
+ }
+
if($alteredOptions && isset($alteredOptions[get_class($this)])) {
if(!isset($this->indexList[$tableName])) {
$this->indexList[$tableName] = $this->indexList($tableName);
@@ -298,7 +298,7 @@ class MySQLDatabase extends SS_Database {
}
}
- $alterations = implode(",\n", $alterList);
+ $alterations = implode(",\n", $alterList);
$this->query("ALTER TABLE \"$tableName\" $alterations");
}
@@ -467,9 +467,9 @@ class MySQLDatabase extends SS_Database {
$indexSpec = trim($indexSpec);
if($indexSpec[0] != '(') list($indexType, $indexFields) = explode(' ',$indexSpec,2);
- else $indexFields = $indexSpec;
+ else $indexFields = $indexSpec;
- if(!isset($indexType))
+ if(!isset($indexType))
$indexType = "index";
if($indexType=='using')
@@ -499,15 +499,15 @@ class MySQLDatabase extends SS_Database {
$indexSpec=$this->convertIndexSpec($indexSpec);
$indexSpec = trim($indexSpec);
- if($indexSpec[0] != '(') {
- list($indexType, $indexFields) = explode(' ',$indexSpec,2);
- } else {
- $indexFields = $indexSpec;
- }
+ if($indexSpec[0] != '(') {
+ list($indexType, $indexFields) = explode(' ',$indexSpec,2);
+ } else {
+ $indexFields = $indexSpec;
+ }
- if(!$indexType) {
- $indexType = "index";
- }
+ if(!$indexType) {
+ $indexType = "index";
+ }
$this->query("ALTER TABLE \"$tableName\" DROP INDEX \"$indexName\"");
$this->query("ALTER TABLE \"$tableName\" ADD $indexType \"$indexName\" $indexFields");
@@ -822,19 +822,19 @@ class MySQLDatabase extends SS_Database {
if(!class_exists('File')) throw new Exception('MySQLDatabase->searchEngine() requires "File" class');
$fileFilter = '';
- $keywords = Convert::raw2sql($keywords);
+ $keywords = Convert::raw2sql($keywords);
$htmlEntityKeywords = htmlentities($keywords, ENT_NOQUOTES, 'UTF-8');
$extraFilters = array('SiteTree' => '', 'File' => '');
- if($booleanSearch) $boolean = "IN BOOLEAN MODE";
+ if($booleanSearch) $boolean = "IN BOOLEAN MODE";
- if($extraFilter) {
- $extraFilters['SiteTree'] = " AND $extraFilter";
+ if($extraFilter) {
+ $extraFilters['SiteTree'] = " AND $extraFilter";
- if($alternativeFileFilter) $extraFilters['File'] = " AND $alternativeFileFilter";
- else $extraFilters['File'] = $extraFilters['SiteTree'];
- }
+ if($alternativeFileFilter) $extraFilters['File'] = " AND $alternativeFileFilter";
+ else $extraFilters['File'] = $extraFilters['SiteTree'];
+ }
// Always ensure that only pages with ShowInSearch = 1 can be searched
$extraFilters['SiteTree'] .= " AND ShowInSearch <> 0";
@@ -982,7 +982,7 @@ class MySQLDatabase extends SS_Database {
$boolean = $booleanSearch ? "IN BOOLEAN MODE" : "";
$fieldNames = '"' . implode('", "', $fields) . '"';
- $SQL_keywords = Convert::raw2sql($keywords);
+ $SQL_keywords = Convert::raw2sql($keywords);
$SQL_htmlEntityKeywords = Convert::raw2sql(htmlentities($keywords, ENT_NOQUOTES, 'UTF-8'));
return "(MATCH ($fieldNames) AGAINST ('$SQL_keywords' $boolean) + MATCH ($fieldNames)"
@@ -1151,7 +1151,7 @@ class MySQLDatabase extends SS_Database {
* @param string $date2 to be substracted of $date1, can be either 'now', literal datetime like
* '1973-10-14 10:30:00' or field name, e.g. '"SiteTree"."Created"'
* @return string SQL datetime expression to query for the interval between $date1 and $date2 in seconds which
- * is the result of the substraction
+ * is the result of the substraction
*/
public function datetimeDifferenceClause($date1, $date2) {
diff --git a/model/SQLQuery.php b/model/SQLQuery.php
index 5a2a633e3..7981c61d4 100644
--- a/model/SQLQuery.php
+++ b/model/SQLQuery.php
@@ -908,11 +908,11 @@ class SQLQuery {
* @return string
*/
public function __toString() {
- try {
- return $this->sql();
- } catch(Exception $e) {
- return "";
- }
+ try {
+ return $this->sql();
+ } catch(Exception $e) {
+ return "";
+ }
}
/**
diff --git a/model/Transliterator.php b/model/Transliterator.php
index f8753bc3e..4a8a5018f 100644
--- a/model/Transliterator.php
+++ b/model/Transliterator.php
@@ -53,6 +53,6 @@ class SS_Transliterator extends Object {
* Transliteration using iconv()
*/
protected function useIconv($source) {
- return iconv("utf-8", "us-ascii//IGNORE//TRANSLIT", $source);
+ return iconv("utf-8", "us-ascii//IGNORE//TRANSLIT", $source);
}
}
diff --git a/model/Versioned.php b/model/Versioned.php
index ac7140c5b..a74928408 100644
--- a/model/Versioned.php
+++ b/model/Versioned.php
@@ -136,8 +136,8 @@ class Versioned extends DataExtension {
* @todo Should this all go into VersionedDataQuery?
*/
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
- $baseTable = ClassInfo::baseDataClass($dataQuery->dataClass());
-
+ $baseTable = ClassInfo::baseDataClass($dataQuery->dataClass());
+
switch($dataQuery->getQueryParam('Versioned.mode')) {
// Noop
case '':
@@ -266,8 +266,8 @@ class Versioned extends DataExtension {
*/
function augmentLoadLazyFields(SQLQuery &$query, DataQuery &$dataQuery = null, $record) {
$dataClass = $dataQuery->dataClass();
- if (isset($record['Version'])){
- $dataQuery->where("\"$dataClass\".\"RecordID\" = " . $record['ID']);
+ if (isset($record['Version'])){
+ $dataQuery->where("\"$dataClass\".\"RecordID\" = " . $record['ID']);
$dataQuery->where("\"$dataClass\".\"Version\" = " . $record['Version']);
$dataQuery->setQueryParam('Versioned.mode', 'all_versions');
}
diff --git a/model/fieldtypes/Date.php b/model/fieldtypes/Date.php
index 5e3851cd4..f789dd82c 100644
--- a/model/fieldtypes/Date.php
+++ b/model/fieldtypes/Date.php
@@ -330,23 +330,23 @@ class Date extends DBField {
public function days_between($fyear, $fmonth, $fday, $tyear, $tmonth, $tday){
- return abs((mktime ( 0, 0, 0, $fmonth, $fday, $fyear) - mktime ( 0, 0, 0, $tmonth, $tday, $tyear))/(60*60*24));
+ return abs((mktime ( 0, 0, 0, $fmonth, $fday, $fyear) - mktime ( 0, 0, 0, $tmonth, $tday, $tyear))/(60*60*24));
}
public function day_before($fyear, $fmonth, $fday){
- return date ("Y-m-d", mktime (0,0,0,$fmonth,$fday-1,$fyear));
+ return date ("Y-m-d", mktime (0,0,0,$fmonth,$fday-1,$fyear));
}
public function next_day($fyear, $fmonth, $fday){
- return date ("Y-m-d", mktime (0,0,0,$fmonth,$fday+1,$fyear));
+ return date ("Y-m-d", mktime (0,0,0,$fmonth,$fday+1,$fyear));
}
public function weekday($fyear, $fmonth, $fday){ // 0 is a Monday
- return (((mktime ( 0, 0, 0, $fmonth, $fday, $fyear) - mktime ( 0, 0, 0, 7, 17, 2006))/(60*60*24))+700000) % 7;
+ return (((mktime ( 0, 0, 0, $fmonth, $fday, $fyear) - mktime ( 0, 0, 0, 7, 17, 2006))/(60*60*24))+700000) % 7;
}
public function prior_monday($fyear, $fmonth, $fday){
- return date ("Y-m-d", mktime (0,0,0,$fmonth,$fday-$this->weekday($fyear, $fmonth, $fday),$fyear));
+ return date ("Y-m-d", mktime (0,0,0,$fmonth,$fday-$this->weekday($fyear, $fmonth, $fday),$fyear));
}
/**
diff --git a/model/fieldtypes/Text.php b/model/fieldtypes/Text.php
index 822d4a535..f9e778513 100644
--- a/model/fieldtypes/Text.php
+++ b/model/fieldtypes/Text.php
@@ -33,7 +33,7 @@ class Text extends StringField {
'NoHTML' => 'Text',
);
- /**
+ /**
* (non-PHPdoc)
* @see DBField::requireField()
*/
diff --git a/model/fieldtypes/Varchar.php b/model/fieldtypes/Varchar.php
index 6cf02aec8..98f8eba0a 100644
--- a/model/fieldtypes/Varchar.php
+++ b/model/fieldtypes/Varchar.php
@@ -17,8 +17,8 @@ class Varchar extends StringField {
);
protected $size;
-
- /**
+
+ /**
* Construct a new short text field
*
* @param $name string The name of the field
@@ -27,12 +27,12 @@ class Varchar extends StringField {
* See {@link StringField::setOptions()} for information on the available options
* @return unknown_type
*/
- public function __construct($name = null, $size = 50, $options = array()) {
+ public function __construct($name = null, $size = 50, $options = array()) {
$this->size = $size ? $size : 50;
parent::__construct($name, $options);
}
- /**
+ /**
* (non-PHPdoc)
* @see DBField::requireField()
*/
diff --git a/parsers/BBCodeParser.php b/parsers/BBCodeParser.php
index e3352c3ef..72fce426c 100644
--- a/parsers/BBCodeParser.php
+++ b/parsers/BBCodeParser.php
@@ -27,7 +27,7 @@ class BBCodeParser extends TextParser {
* @var Boolean
*/
protected static $allowSimilies = false;
-
+
/**
* Set the location of the smiles folder. By default use the ones in framework
* but this can be overridden by setting BBCodeParser::set_icon_folder('themes/yourtheme/images/');
@@ -165,7 +165,7 @@ class BBCodeParser extends TextParser {
'#(? " ", // :(
'#(? " ", // :-(
'#(? " ", // :p
- '#(? " ", // 8-)
+ '#(? " ", // 8-)
'#(? " " // :^)
);
$this->content = preg_replace(array_keys($smilies), array_values($smilies), $this->content);
diff --git a/parsers/HTML/HTMLBBCodeParser.php b/parsers/HTML/HTMLBBCodeParser.php
index b09ce64e2..e9cfdacf6 100644
--- a/parsers/HTML/HTMLBBCodeParser.php
+++ b/parsers/HTML/HTMLBBCodeParser.php
@@ -55,819 +55,818 @@
*/
class SSHTMLBBCodeParser
{
- /**
- * An array of tags parsed by the engine, should be overwritten by filters
- *
- * @access private
- * @var array
- */
- var $_definedTags = array();
+ /**
+ * An array of tags parsed by the engine, should be overwritten by filters
+ *
+ * @access private
+ * @var array
+ */
+ var $_definedTags = array();
- /**
- * A string containing the input
- *
- * @access private
- * @var string
- */
- var $_text = '';
+ /**
+ * A string containing the input
+ *
+ * @access private
+ * @var string
+ */
+ var $_text = '';
- /**
- * A string containing the preparsed input
- *
- * @access private
- * @var string
- */
- var $_preparsed = '';
+ /**
+ * A string containing the preparsed input
+ *
+ * @access private
+ * @var string
+ */
+ var $_preparsed = '';
- /**
- * An array tags and texts build from the input text
- *
- * @access private
- * @var array
- */
- var $_tagArray = array();
+ /**
+ * An array tags and texts build from the input text
+ *
+ * @access private
+ * @var array
+ */
+ var $_tagArray = array();
- /**
- * A string containing the parsed version of the text
- *
- * @access private
- * @var string
- */
- var $_parsed = '';
+ /**
+ * A string containing the parsed version of the text
+ *
+ * @access private
+ * @var string
+ */
+ var $_parsed = '';
- /**
- * An array of options, filled by an ini file or through the contructor
- *
- * @access private
- * @var array
- */
- var $_options = array(
- 'quotestyle' => 'double',
- 'quotewhat' => 'all',
- 'open' => '[',
- 'close' => ']',
- 'xmlclose' => true,
- 'filters' => 'Basic'
- );
+ /**
+ * An array of options, filled by an ini file or through the contructor
+ *
+ * @access private
+ * @var array
+ */
+ var $_options = array(
+ 'quotestyle' => 'double',
+ 'quotewhat' => 'all',
+ 'open' => '[',
+ 'close' => ']',
+ 'xmlclose' => true,
+ 'filters' => 'Basic'
+ );
- /**
- * An array of filters used for parsing
- *
- * @access private
- * @var array
- */
- var $_filters = array();
+ /**
+ * An array of filters used for parsing
+ *
+ * @access private
+ * @var array
+ */
+ var $_filters = array();
- /**
- * Constructor, initialises the options and filters
- *
- * Sets the private variable _options with base options defined with
- * &PEAR::getStaticProperty(), overwriting them with (if present)
- * the argument to this method.
- * Then it sets the extra options to properly escape the tag
- * characters in preg_replace() etc. The set options are
- * then stored back with &PEAR::getStaticProperty(), so that the filter
- * classes can use them.
- * All the filters in the options are initialised and their defined tags
- * are copied into the private variable _definedTags.
- *
- * @param array options to use, can be left out
- * @return none
- * @access public
- * @author Stijn de Reede
- */
- public function SSHTMLBBCodeParser($options = array())
- {
- // set the already set options
- $baseoptions = &SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
- if (is_array($baseoptions)) {
- foreach ($baseoptions as $k => $v) {
- $this->_options[$k] = $v;
- }
- }
+ /**
+ * Constructor, initialises the options and filters
+ *
+ * Sets the private variable _options with base options defined with
+ * &PEAR::getStaticProperty(), overwriting them with (if present)
+ * the argument to this method.
+ * Then it sets the extra options to properly escape the tag
+ * characters in preg_replace() etc. The set options are
+ * then stored back with &PEAR::getStaticProperty(), so that the filter
+ * classes can use them.
+ * All the filters in the options are initialised and their defined tags
+ * are copied into the private variable _definedTags.
+ *
+ * @param array options to use, can be left out
+ * @return none
+ * @access public
+ * @author Stijn de Reede
+ */
+ public function SSHTMLBBCodeParser($options = array())
+ {
+ // set the already set options
+ $baseoptions = &SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
+ if (is_array($baseoptions)) {
+ foreach ($baseoptions as $k => $v) {
+ $this->_options[$k] = $v;
+ }
+ }
- // set the options passed as an argument
- foreach ($options as $k => $v ) {
- $this->_options[$k] = $v;
- }
+ // set the options passed as an argument
+ foreach ($options as $k => $v ) {
+ $this->_options[$k] = $v;
+ }
- // add escape open and close chars to the options for preg escaping
- $preg_escape = '\^$.[]|()?*+{}';
- if ($this->_options['open'] != '' && strpos($preg_escape, $this->_options['open'])) {
- $this->_options['open_esc'] = "\\".$this->_options['open'];
- } else {
- $this->_options['open_esc'] = $this->_options['open'];
- }
- if ($this->_options['close'] != '' && strpos($preg_escape, $this->_options['close'])) {
- $this->_options['close_esc'] = "\\".$this->_options['close'];
- } else {
- $this->_options['close_esc'] = $this->_options['close'];
- }
+ // add escape open and close chars to the options for preg escaping
+ $preg_escape = '\^$.[]|()?*+{}';
+ if ($this->_options['open'] != '' && strpos($preg_escape, $this->_options['open'])) {
+ $this->_options['open_esc'] = "\\".$this->_options['open'];
+ } else {
+ $this->_options['open_esc'] = $this->_options['open'];
+ }
+ if ($this->_options['close'] != '' && strpos($preg_escape, $this->_options['close'])) {
+ $this->_options['close_esc'] = "\\".$this->_options['close'];
+ } else {
+ $this->_options['close_esc'] = $this->_options['close'];
+ }
- // set the options back so that child classes can use them */
- $baseoptions = $this->_options;
- unset($baseoptions);
+ // set the options back so that child classes can use them */
+ $baseoptions = $this->_options;
+ unset($baseoptions);
- // return if this is a subclass
- if (is_subclass_of($this, 'SSHTMLBBCodeParser_Filter')) {
- return;
- }
+ // return if this is a subclass
+ if (is_subclass_of($this, 'SSHTMLBBCodeParser_Filter')) {
+ return;
+ }
- // extract the definedTags from subclasses */
- $this->addFilters($this->_options['filters']);
- }
-
- static function &getStaticProperty($class, $var)
- {
- static $properties;
- if (!isset($properties[$class])) {
- $properties[$class] = array();
- }
- if (!array_key_exists($var, $properties[$class])) {
- $properties[$class][$var] = null;
- }
- return $properties[$class][$var];
- }
+ // extract the definedTags from subclasses */
+ $this->addFilters($this->_options['filters']);
+ }
+
+ static function &getStaticProperty($class, $var)
+ {
+ static $properties;
+ if (!isset($properties[$class])) {
+ $properties[$class] = array();
+ }
+ if (!array_key_exists($var, $properties[$class])) {
+ $properties[$class][$var] = null;
+ }
+ return $properties[$class][$var];
+ }
- /**
- * Option setter
- *
- * @param string option name
- * @param mixed option value
- * @author Lorenzo Alberton
- */
- public function setOption($name, $value)
- {
- $this->_options[$name] = $value;
- }
+ /**
+ * Option setter
+ *
+ * @param string option name
+ * @param mixed option value
+ * @author Lorenzo Alberton
+ */
+ public function setOption($name, $value)
+ {
+ $this->_options[$name] = $value;
+ }
- /**
- * Add a new filter
- *
- * @param string filter
- * @author Lorenzo Alberton
- */
- public function addFilter($filter)
- {
-
- $filter = ucfirst($filter);
- if (!array_key_exists($filter, $this->_filters)) {
- $class = 'SSHTMLBBCodeParser_Filter_'.$filter;
- if (fopen('BBCodeParser/Filter/'.$filter.'.php','r',true)) {
- include_once 'BBCodeParser/Filter/'.$filter.'.php';
- }
- if (!class_exists($class)) {
+ /**
+ * Add a new filter
+ *
+ * @param string filter
+ * @author Lorenzo Alberton
+ */
+ public function addFilter($filter)
+ {
+ $filter = ucfirst($filter);
+ if (!array_key_exists($filter, $this->_filters)) {
+ $class = 'SSHTMLBBCodeParser_Filter_'.$filter;
+ if (fopen('BBCodeParser/Filter/'.$filter.'.php','r',true)) {
+ include_once 'BBCodeParser/Filter/'.$filter.'.php';
+ }
+ if (!class_exists($class)) {
- //PEAR::raiseError("Failed to load filter $filter", null, PEAR_ERROR_DIE);
- }
+ //PEAR::raiseError("Failed to load filter $filter", null, PEAR_ERROR_DIE);
+ }
else {
$this->_filters[$filter] = new $class;
- $this->_definedTags = array_merge(
- $this->_definedTags,
- $this->_filters[$filter]->_definedTags
- );
+ $this->_definedTags = array_merge(
+ $this->_definedTags,
+ $this->_filters[$filter]->_definedTags
+ );
}
- }
+ }
- }
+ }
- /**
- * Remove an existing filter
- *
- * @param string $filter
- * @author Lorenzo Alberton
- */
- public function removeFilter($filter)
- {
- $filter = ucfirst(trim($filter));
- if (!empty($filter) && array_key_exists($filter, $this->_filters)) {
- unset($this->_filters[$filter]);
- }
- // also remove the related $this->_definedTags for this filter,
- // preserving the others
- $this->_definedTags = array();
- foreach (array_keys($this->_filters) as $filter) {
- $this->_definedTags = array_merge(
- $this->_definedTags,
- $this->_filters[$filter]->_definedTags
- );
- }
- }
+ /**
+ * Remove an existing filter
+ *
+ * @param string $filter
+ * @author Lorenzo Alberton
+ */
+ public function removeFilter($filter)
+ {
+ $filter = ucfirst(trim($filter));
+ if (!empty($filter) && array_key_exists($filter, $this->_filters)) {
+ unset($this->_filters[$filter]);
+ }
+ // also remove the related $this->_definedTags for this filter,
+ // preserving the others
+ $this->_definedTags = array();
+ foreach (array_keys($this->_filters) as $filter) {
+ $this->_definedTags = array_merge(
+ $this->_definedTags,
+ $this->_filters[$filter]->_definedTags
+ );
+ }
+ }
- /**
- * Add new filters
- *
- * @param mixed (array or string)
- * @return boolean true if all ok, false if not.
- * @author Lorenzo Alberton
- */
- public function addFilters($filters)
- {
- if (is_string($filters)) {
- //comma-separated list
- if (strpos($filters, ',') !== false) {
- $filters = explode(',', $filters);
- } else {
- $filters = array($filters);
- }
- }
- if (!is_array($filters)) {
- //invalid format
- return false;
- }
- foreach ($filters as $filter) {
- if (trim($filter)){
- $this->addFilter($filter);
- }
- }
- return true;
- }
+ /**
+ * Add new filters
+ *
+ * @param mixed (array or string)
+ * @return boolean true if all ok, false if not.
+ * @author Lorenzo Alberton
+ */
+ public function addFilters($filters)
+ {
+ if (is_string($filters)) {
+ //comma-separated list
+ if (strpos($filters, ',') !== false) {
+ $filters = explode(',', $filters);
+ } else {
+ $filters = array($filters);
+ }
+ }
+ if (!is_array($filters)) {
+ //invalid format
+ return false;
+ }
+ foreach ($filters as $filter) {
+ if (trim($filter)){
+ $this->addFilter($filter);
+ }
+ }
+ return true;
+ }
- /**
- * Executes statements before the actual array building starts
- *
- * This method should be overwritten in a filter if you want to do
- * something before the parsing process starts. This can be useful to
- * allow certain short alternative tags which then can be converted into
- * proper tags with preg_replace() calls.
- * The main class walks through all the filters and and calls this
- * method. The filters should modify their private $_preparsed
- * variable, with input from $_text.
- *
- * @return none
- * @access private
- * @see $_text
- * @author Stijn de Reede
- */
- public function _preparse()
- {
- // default: assign _text to _preparsed, to be overwritten by filters
- $this->_preparsed = $this->_text;
+ /**
+ * Executes statements before the actual array building starts
+ *
+ * This method should be overwritten in a filter if you want to do
+ * something before the parsing process starts. This can be useful to
+ * allow certain short alternative tags which then can be converted into
+ * proper tags with preg_replace() calls.
+ * The main class walks through all the filters and and calls this
+ * method. The filters should modify their private $_preparsed
+ * variable, with input from $_text.
+ *
+ * @return none
+ * @access private
+ * @see $_text
+ * @author Stijn de Reede
+ */
+ public function _preparse()
+ {
+ // default: assign _text to _preparsed, to be overwritten by filters
+ $this->_preparsed = $this->_text;
- // return if this is a subclass
- if (is_subclass_of($this, 'SSHTMLBBCodeParser')) {
- return;
- }
+ // return if this is a subclass
+ if (is_subclass_of($this, 'SSHTMLBBCodeParser')) {
+ return;
+ }
- // walk through the filters and execute _preparse
- foreach ($this->_filters as $filter) {
- $filter->setText($this->_preparsed);
- $filter->_preparse();
- $this->_preparsed = $filter->getPreparsed();
- }
- }
+ // walk through the filters and execute _preparse
+ foreach ($this->_filters as $filter) {
+ $filter->setText($this->_preparsed);
+ $filter->_preparse();
+ $this->_preparsed = $filter->getPreparsed();
+ }
+ }
- /**
- * Builds the tag array from the input string $_text
- *
- * An array consisting of tag and text elements is contructed from the
- * $_preparsed variable. The method uses _buildTag() to check if a tag is
- * valid and to build the actual tag to be added to the tag array.
- *
- * @todo - rewrite whole method, as this one is old and probably slow
- * - see if a recursive method would be better than an iterative one
- *
- * @return none
- * @access private
- * @see _buildTag()
- * @see $_text
- * @see $_tagArray
- * @author Stijn de Reede
- */
- public function _buildTagArray()
- {
- $this->_tagArray = array();
- $str = $this->_preparsed;
- $strPos = 0;
- $strLength = strlen($str);
+ /**
+ * Builds the tag array from the input string $_text
+ *
+ * An array consisting of tag and text elements is contructed from the
+ * $_preparsed variable. The method uses _buildTag() to check if a tag is
+ * valid and to build the actual tag to be added to the tag array.
+ *
+ * @todo - rewrite whole method, as this one is old and probably slow
+ * - see if a recursive method would be better than an iterative one
+ *
+ * @return none
+ * @access private
+ * @see _buildTag()
+ * @see $_text
+ * @see $_tagArray
+ * @author Stijn de Reede
+ */
+ public function _buildTagArray()
+ {
+ $this->_tagArray = array();
+ $str = $this->_preparsed;
+ $strPos = 0;
+ $strLength = strlen($str);
- while (($strPos < $strLength)) {
- $tag = array();
- $openPos = strpos($str, $this->_options['open'], $strPos);
- if ($openPos === false) {
- $openPos = $strLength;
- $nextOpenPos = $strLength;
- }
- if ($openPos + 1 > $strLength) {
- $nextOpenPos = $strLength;
- } else {
- $nextOpenPos = strpos($str, $this->_options['open'], $openPos + 1);
- if ($nextOpenPos === false) {
- $nextOpenPos = $strLength;
- }
- }
- $closePos = strpos($str, $this->_options['close'], $strPos);
- if ($closePos === false) {
- $closePos = $strLength + 1;
- }
+ while (($strPos < $strLength)) {
+ $tag = array();
+ $openPos = strpos($str, $this->_options['open'], $strPos);
+ if ($openPos === false) {
+ $openPos = $strLength;
+ $nextOpenPos = $strLength;
+ }
+ if ($openPos + 1 > $strLength) {
+ $nextOpenPos = $strLength;
+ } else {
+ $nextOpenPos = strpos($str, $this->_options['open'], $openPos + 1);
+ if ($nextOpenPos === false) {
+ $nextOpenPos = $strLength;
+ }
+ }
+ $closePos = strpos($str, $this->_options['close'], $strPos);
+ if ($closePos === false) {
+ $closePos = $strLength + 1;
+ }
- if ($openPos == $strPos) {
- if (($nextOpenPos < $closePos)) {
- // new open tag before closing tag: treat as text
- $newPos = $nextOpenPos;
- $tag['text'] = substr($str, $strPos, $nextOpenPos - $strPos);
- $tag['type'] = 0;
- } else {
- // possible valid tag
- $newPos = $closePos + 1;
- $newTag = $this->_buildTag(substr($str, $strPos, $closePos - $strPos + 1));
- if (($newTag !== false)) {
- $tag = $newTag;
- } else {
- // no valid tag after all
- $tag['text'] = substr($str, $strPos, $closePos - $strPos + 1);
- $tag['type'] = 0;
- }
- }
- } else {
- // just text
- $newPos = $openPos;
- $tag['text'] = substr($str, $strPos, $openPos - $strPos);
- $tag['type'] = 0;
- }
+ if ($openPos == $strPos) {
+ if (($nextOpenPos < $closePos)) {
+ // new open tag before closing tag: treat as text
+ $newPos = $nextOpenPos;
+ $tag['text'] = substr($str, $strPos, $nextOpenPos - $strPos);
+ $tag['type'] = 0;
+ } else {
+ // possible valid tag
+ $newPos = $closePos + 1;
+ $newTag = $this->_buildTag(substr($str, $strPos, $closePos - $strPos + 1));
+ if (($newTag !== false)) {
+ $tag = $newTag;
+ } else {
+ // no valid tag after all
+ $tag['text'] = substr($str, $strPos, $closePos - $strPos + 1);
+ $tag['type'] = 0;
+ }
+ }
+ } else {
+ // just text
+ $newPos = $openPos;
+ $tag['text'] = substr($str, $strPos, $openPos - $strPos);
+ $tag['type'] = 0;
+ }
- // join 2 following text elements
- if ($tag['type'] === 0 && isset($prev) && $prev['type'] === 0) {
- $tag['text'] = $prev['text'].$tag['text'];
- array_pop($this->_tagArray);
- }
+ // join 2 following text elements
+ if ($tag['type'] === 0 && isset($prev) && $prev['type'] === 0) {
+ $tag['text'] = $prev['text'].$tag['text'];
+ array_pop($this->_tagArray);
+ }
- $this->_tagArray[] = $tag;
- $prev = $tag;
- $strPos = $newPos;
- }
- }
+ $this->_tagArray[] = $tag;
+ $prev = $tag;
+ $strPos = $newPos;
+ }
+ }
- /**
- * Builds a tag from the input string
- *
- * This method builds a tag array based on the string it got as an
- * argument. If the tag is invalid, is returned. The tag
- * attributes are extracted from the string and stored in the tag
- * array as an associative array.
- *
- * @param string string to build tag from
- * @return array tag in array format
- * @access private
- * @see _buildTagArray()
- * @author Stijn de Reede
- */
- public function _buildTag($str)
- {
- $tag = array('text' => $str, 'attributes' => array());
+ /**
+ * Builds a tag from the input string
+ *
+ * This method builds a tag array based on the string it got as an
+ * argument. If the tag is invalid, is returned. The tag
+ * attributes are extracted from the string and stored in the tag
+ * array as an associative array.
+ *
+ * @param string string to build tag from
+ * @return array tag in array format
+ * @access private
+ * @see _buildTagArray()
+ * @author Stijn de Reede
+ */
+ public function _buildTag($str)
+ {
+ $tag = array('text' => $str, 'attributes' => array());
- if (substr($str, 1, 1) == '/') { // closing tag
+ if (substr($str, 1, 1) == '/') { // closing tag
- $tag['tag'] = strtolower(substr($str, 2, strlen($str) - 3));
- if (!in_array($tag['tag'], array_keys($this->_definedTags))) {
- return false; // nope, it's not valid
- } else {
- $tag['type'] = 2;
- return $tag;
- }
- } else { // opening tag
+ $tag['tag'] = strtolower(substr($str, 2, strlen($str) - 3));
+ if (!in_array($tag['tag'], array_keys($this->_definedTags))) {
+ return false; // nope, it's not valid
+ } else {
+ $tag['type'] = 2;
+ return $tag;
+ }
+ } else { // opening tag
- $tag['type'] = 1;
- if (strpos($str, ' ') && (strpos($str, '=') === false)) {
- return false; // nope, it's not valid
- }
+ $tag['type'] = 1;
+ if (strpos($str, ' ') && (strpos($str, '=') === false)) {
+ return false; // nope, it's not valid
+ }
- // tnx to Onno for the regex
- // split the tag with arguments and all
- $oe = $this->_options['open_esc'];
- $ce = $this->_options['close_esc'];
- $tagArray = array();
- if (preg_match("!$oe([a-z0-9]+)[^$ce]*$ce!i", $str, $tagArray) == 0) {
- return false;
- }
- $tag['tag'] = strtolower($tagArray[1]);
- if (!in_array($tag['tag'], array_keys($this->_definedTags))) {
- return false; // nope, it's not valid
- }
+ // tnx to Onno for the regex
+ // split the tag with arguments and all
+ $oe = $this->_options['open_esc'];
+ $ce = $this->_options['close_esc'];
+ $tagArray = array();
+ if (preg_match("!$oe([a-z0-9]+)[^$ce]*$ce!i", $str, $tagArray) == 0) {
+ return false;
+ }
+ $tag['tag'] = strtolower($tagArray[1]);
+ if (!in_array($tag['tag'], array_keys($this->_definedTags))) {
+ return false; // nope, it's not valid
+ }
- // tnx to Onno for the regex
- // validate the arguments
- $attributeArray = array();
- $regex = "![\s$oe]([a-z0-9]+)=(\"[^\s$ce]+\"|[^\s$ce]";
- if ($tag['tag'] != 'url') {
- $regex .= "[^=]";
- }
- $regex .= "+)(?=[\s$ce])!i";
- preg_match_all($regex, $str, $attributeArray, PREG_SET_ORDER);
- foreach ($attributeArray as $attribute) {
- $attNam = strtolower($attribute[1]);
- if (in_array($attNam, array_keys($this->_definedTags[$tag['tag']]['attributes']))) {
- if ($attribute[2][0] == '"' && $attribute[2][strlen($attribute[2])-1] == '"') {
- $tag['attributes'][$attNam] = substr($attribute[2], 1, -1);
- } else {
- $tag['attributes'][$attNam] = $attribute[2];
- }
- }
- }
- return $tag;
- }
- }
+ // tnx to Onno for the regex
+ // validate the arguments
+ $attributeArray = array();
+ $regex = "![\s$oe]([a-z0-9]+)=(\"[^\s$ce]+\"|[^\s$ce]";
+ if ($tag['tag'] != 'url') {
+ $regex .= "[^=]";
+ }
+ $regex .= "+)(?=[\s$ce])!i";
+ preg_match_all($regex, $str, $attributeArray, PREG_SET_ORDER);
+ foreach ($attributeArray as $attribute) {
+ $attNam = strtolower($attribute[1]);
+ if (in_array($attNam, array_keys($this->_definedTags[$tag['tag']]['attributes']))) {
+ if ($attribute[2][0] == '"' && $attribute[2][strlen($attribute[2])-1] == '"') {
+ $tag['attributes'][$attNam] = substr($attribute[2], 1, -1);
+ } else {
+ $tag['attributes'][$attNam] = $attribute[2];
+ }
+ }
+ }
+ return $tag;
+ }
+ }
- /**
- * Validates the tag array, regarding the allowed tags
- *
- * While looping through the tag array, two following text tags are
- * joined, and it is checked that the tag is allowed inside the
- * last opened tag.
- * By remembering what tags have been opened it is checked that
- * there is correct (xml compliant) nesting.
- * In the end all still opened tags are closed.
- *
- * @return none
- * @access private
- * @see _isAllowed()
- * @see $_tagArray
- * @author Stijn de Reede , Seth Price
- */
- public function _validateTagArray()
- {
- $newTagArray = array();
- $openTags = array();
- foreach ($this->_tagArray as $tag) {
- $prevTag = end($newTagArray);
- switch ($tag['type']) {
- case 0:
- if (($child = $this->_childNeeded(end($openTags), 'text')) &&
- $child !== false &&
- /*
- * No idea what to do in this case: A child is needed, but
- * no valid one is returned. We'll ignore it here and live
- * with it until someone reports a valid bug.
- */
- $child !== true )
- {
- if (trim($tag['text']) == '') {
- //just an empty indentation or newline without value?
- continue;
- }
- $newTagArray[] = $child;
- $openTags[] = $child['tag'];
- }
- if ($prevTag['type'] === 0) {
- $tag['text'] = $prevTag['text'].$tag['text'];
- array_pop($newTagArray);
- }
- $newTagArray[] = $tag;
- break;
+ /**
+ * Validates the tag array, regarding the allowed tags
+ *
+ * While looping through the tag array, two following text tags are
+ * joined, and it is checked that the tag is allowed inside the
+ * last opened tag.
+ * By remembering what tags have been opened it is checked that
+ * there is correct (xml compliant) nesting.
+ * In the end all still opened tags are closed.
+ *
+ * @return none
+ * @access private
+ * @see _isAllowed()
+ * @see $_tagArray
+ * @author Stijn de Reede , Seth Price
+ */
+ public function _validateTagArray()
+ {
+ $newTagArray = array();
+ $openTags = array();
+ foreach ($this->_tagArray as $tag) {
+ $prevTag = end($newTagArray);
+ switch ($tag['type']) {
+ case 0:
+ if (($child = $this->_childNeeded(end($openTags), 'text')) &&
+ $child !== false &&
+ /*
+ * No idea what to do in this case: A child is needed, but
+ * no valid one is returned. We'll ignore it here and live
+ * with it until someone reports a valid bug.
+ */
+ $child !== true )
+ {
+ if (trim($tag['text']) == '') {
+ //just an empty indentation or newline without value?
+ continue;
+ }
+ $newTagArray[] = $child;
+ $openTags[] = $child['tag'];
+ }
+ if ($prevTag['type'] === 0) {
+ $tag['text'] = $prevTag['text'].$tag['text'];
+ array_pop($newTagArray);
+ }
+ $newTagArray[] = $tag;
+ break;
- case 1:
- if (!$this->_isAllowed(end($openTags), $tag['tag']) ||
- ($parent = $this->_parentNeeded(end($openTags), $tag['tag'])) === true ||
- ($child = $this->_childNeeded(end($openTags), $tag['tag'])) === true) {
- $tag['type'] = 0;
- if ($prevTag['type'] === 0) {
- $tag['text'] = $prevTag['text'].$tag['text'];
- array_pop($newTagArray);
- }
- } else {
- if ($parent) {
- /*
- * Avoid use of parent if we can help it. If we are
- * trying to insert a new parent, but the current tag is
- * the same as the previous tag, then assume that the
- * previous tag structure is valid, and add this tag as
- * a sibling. To add as a sibling, we need to close the
- * current tag.
- */
- if ($tag['tag'] == end($openTags)){
- $newTagArray[] = $this->_buildTag('[/'.$tag['tag'].']');
- array_pop($openTags);
- } else {
- $newTagArray[] = $parent;
- $openTags[] = $parent['tag'];
- }
- }
- if ($child) {
- $newTagArray[] = $child;
- $openTags[] = $child['tag'];
- }
- $openTags[] = $tag['tag'];
- }
- $newTagArray[] = $tag;
- break;
+ case 1:
+ if (!$this->_isAllowed(end($openTags), $tag['tag']) ||
+ ($parent = $this->_parentNeeded(end($openTags), $tag['tag'])) === true ||
+ ($child = $this->_childNeeded(end($openTags), $tag['tag'])) === true) {
+ $tag['type'] = 0;
+ if ($prevTag['type'] === 0) {
+ $tag['text'] = $prevTag['text'].$tag['text'];
+ array_pop($newTagArray);
+ }
+ } else {
+ if ($parent) {
+ /*
+ * Avoid use of parent if we can help it. If we are
+ * trying to insert a new parent, but the current tag is
+ * the same as the previous tag, then assume that the
+ * previous tag structure is valid, and add this tag as
+ * a sibling. To add as a sibling, we need to close the
+ * current tag.
+ */
+ if ($tag['tag'] == end($openTags)){
+ $newTagArray[] = $this->_buildTag('[/'.$tag['tag'].']');
+ array_pop($openTags);
+ } else {
+ $newTagArray[] = $parent;
+ $openTags[] = $parent['tag'];
+ }
+ }
+ if ($child) {
+ $newTagArray[] = $child;
+ $openTags[] = $child['tag'];
+ }
+ $openTags[] = $tag['tag'];
+ }
+ $newTagArray[] = $tag;
+ break;
- case 2:
- if (($tag['tag'] == end($openTags) || $this->_isAllowed(end($openTags), $tag['tag']))) {
- if (in_array($tag['tag'], $openTags)) {
- $tmpOpenTags = array();
- while (end($openTags) != $tag['tag']) {
- $newTagArray[] = $this->_buildTag('[/'.end($openTags).']');
- $tmpOpenTags[] = end($openTags);
- array_pop($openTags);
- }
- $newTagArray[] = $tag;
- array_pop($openTags);
- /* why is this here? it just seems to break things
- * (nested lists where closing tags need to be
- * generated)
- while (end($tmpOpenTags)) {
- $tmpTag = $this->_buildTag('['.end($tmpOpenTags).']');
- $newTagArray[] = $tmpTag;
- $openTags[] = $tmpTag['tag'];
- array_pop($tmpOpenTags);
- }*/
- }
- } else {
- $tag['type'] = 0;
- if ($prevTag['type'] === 0) {
- $tag['text'] = $prevTag['text'].$tag['text'];
- array_pop($newTagArray);
- }
- $newTagArray[] = $tag;
- }
- break;
- }
- }
- while (end($openTags)) {
- $newTagArray[] = $this->_buildTag('[/'.end($openTags).']');
- array_pop($openTags);
- }
- $this->_tagArray = $newTagArray;
- }
+ case 2:
+ if (($tag['tag'] == end($openTags) || $this->_isAllowed(end($openTags), $tag['tag']))) {
+ if (in_array($tag['tag'], $openTags)) {
+ $tmpOpenTags = array();
+ while (end($openTags) != $tag['tag']) {
+ $newTagArray[] = $this->_buildTag('[/'.end($openTags).']');
+ $tmpOpenTags[] = end($openTags);
+ array_pop($openTags);
+ }
+ $newTagArray[] = $tag;
+ array_pop($openTags);
+ /* why is this here? it just seems to break things
+ * (nested lists where closing tags need to be
+ * generated)
+ while (end($tmpOpenTags)) {
+ $tmpTag = $this->_buildTag('['.end($tmpOpenTags).']');
+ $newTagArray[] = $tmpTag;
+ $openTags[] = $tmpTag['tag'];
+ array_pop($tmpOpenTags);
+ }*/
+ }
+ } else {
+ $tag['type'] = 0;
+ if ($prevTag['type'] === 0) {
+ $tag['text'] = $prevTag['text'].$tag['text'];
+ array_pop($newTagArray);
+ }
+ $newTagArray[] = $tag;
+ }
+ break;
+ }
+ }
+ while (end($openTags)) {
+ $newTagArray[] = $this->_buildTag('[/'.end($openTags).']');
+ array_pop($openTags);
+ }
+ $this->_tagArray = $newTagArray;
+ }
- /**
- * Checks to see if a parent is needed
- *
- * Checks to see if the current $in tag has an appropriate parent. If it
- * does, then it returns false. If a parent is needed, then it returns the
- * first tag in the list to add to the stack.
- *
- * @param array tag that is on the outside
- * @param array tag that is on the inside
- * @return boolean false if not needed, tag if needed, true if out
- * of our minds
- * @access private
- * @see _validateTagArray()
- * @author Seth Price
- */
- public function _parentNeeded($out, $in)
- {
- if (!isset($this->_definedTags[$in]['parent']) ||
- ($this->_definedTags[$in]['parent'] == 'all')
- ) {
- return false;
- }
+ /**
+ * Checks to see if a parent is needed
+ *
+ * Checks to see if the current $in tag has an appropriate parent. If it
+ * does, then it returns false. If a parent is needed, then it returns the
+ * first tag in the list to add to the stack.
+ *
+ * @param array tag that is on the outside
+ * @param array tag that is on the inside
+ * @return boolean false if not needed, tag if needed, true if out
+ * of our minds
+ * @access private
+ * @see _validateTagArray()
+ * @author Seth Price
+ */
+ public function _parentNeeded($out, $in)
+ {
+ if (!isset($this->_definedTags[$in]['parent']) ||
+ ($this->_definedTags[$in]['parent'] == 'all')
+ ) {
+ return false;
+ }
- $ar = explode('^', $this->_definedTags[$in]['parent']);
- $tags = explode(',', $ar[1]);
- if ($ar[0] == 'none'){
- if ($out && in_array($out, $tags)) {
- return false;
- }
- //Create a tag from the first one on the list
- return $this->_buildTag('['.$tags[0].']');
- }
- if ($ar[0] == 'all' && $out && !in_array($out, $tags)) {
- return false;
- }
- // Tag is needed, we don't know which one. We could make something up,
- // but it would be so random, I think that it would be worthless.
- return true;
- }
+ $ar = explode('^', $this->_definedTags[$in]['parent']);
+ $tags = explode(',', $ar[1]);
+ if ($ar[0] == 'none'){
+ if ($out && in_array($out, $tags)) {
+ return false;
+ }
+ //Create a tag from the first one on the list
+ return $this->_buildTag('['.$tags[0].']');
+ }
+ if ($ar[0] == 'all' && $out && !in_array($out, $tags)) {
+ return false;
+ }
+ // Tag is needed, we don't know which one. We could make something up,
+ // but it would be so random, I think that it would be worthless.
+ return true;
+ }
- /**
- * Checks to see if a child is needed
- *
- * Checks to see if the current $out tag has an appropriate child. If it
- * does, then it returns false. If a child is needed, then it returns the
- * first tag in the list to add to the stack.
- *
- * @param array tag that is on the outside
- * @param array tag that is on the inside
- * @return boolean false if not needed, tag if needed, true if out
- * of our minds
- * @access private
- * @see _validateTagArray()
- * @author Seth Price
- */
- public function _childNeeded($out, $in)
- {
- if (!isset($this->_definedTags[$out]['child']) ||
- ($this->_definedTags[$out]['child'] == 'all')
- ) {
- return false;
- }
+ /**
+ * Checks to see if a child is needed
+ *
+ * Checks to see if the current $out tag has an appropriate child. If it
+ * does, then it returns false. If a child is needed, then it returns the
+ * first tag in the list to add to the stack.
+ *
+ * @param array tag that is on the outside
+ * @param array tag that is on the inside
+ * @return boolean false if not needed, tag if needed, true if out
+ * of our minds
+ * @access private
+ * @see _validateTagArray()
+ * @author Seth Price
+ */
+ public function _childNeeded($out, $in)
+ {
+ if (!isset($this->_definedTags[$out]['child']) ||
+ ($this->_definedTags[$out]['child'] == 'all')
+ ) {
+ return false;
+ }
- $ar = explode('^', $this->_definedTags[$out]['child']);
- $tags = explode(',', $ar[1]);
- if ($ar[0] == 'none'){
- if ($in && in_array($in, $tags)) {
- return false;
- }
- //Create a tag from the first one on the list
- return $this->_buildTag('['.$tags[0].']');
- }
- if ($ar[0] == 'all' && $in && !in_array($in, $tags)) {
- return false;
- }
- // Tag is needed, we don't know which one. We could make something up,
- // but it would be so random, I think that it would be worthless.
- return true;
- }
+ $ar = explode('^', $this->_definedTags[$out]['child']);
+ $tags = explode(',', $ar[1]);
+ if ($ar[0] == 'none'){
+ if ($in && in_array($in, $tags)) {
+ return false;
+ }
+ //Create a tag from the first one on the list
+ return $this->_buildTag('['.$tags[0].']');
+ }
+ if ($ar[0] == 'all' && $in && !in_array($in, $tags)) {
+ return false;
+ }
+ // Tag is needed, we don't know which one. We could make something up,
+ // but it would be so random, I think that it would be worthless.
+ return true;
+ }
- /**
- * Checks to see if a tag is allowed inside another tag
- *
- * The allowed tags are extracted from the private _definedTags array.
- *
- * @param array tag that is on the outside
- * @param array tag that is on the inside
- * @return boolean return true if the tag is allowed, false
- * otherwise
- * @access private
- * @see _validateTagArray()
- * @author Stijn de Reede
- */
- public function _isAllowed($out, $in)
- {
- if (!$out || ($this->_definedTags[$out]['allowed'] == 'all')) {
- return true;
- }
- if ($this->_definedTags[$out]['allowed'] == 'none') {
- return false;
- }
+ /**
+ * Checks to see if a tag is allowed inside another tag
+ *
+ * The allowed tags are extracted from the private _definedTags array.
+ *
+ * @param array tag that is on the outside
+ * @param array tag that is on the inside
+ * @return boolean return true if the tag is allowed, false
+ * otherwise
+ * @access private
+ * @see _validateTagArray()
+ * @author Stijn de Reede
+ */
+ public function _isAllowed($out, $in)
+ {
+ if (!$out || ($this->_definedTags[$out]['allowed'] == 'all')) {
+ return true;
+ }
+ if ($this->_definedTags[$out]['allowed'] == 'none') {
+ return false;
+ }
- $ar = explode('^', $this->_definedTags[$out]['allowed']);
- $tags = explode(',', $ar[1]);
- if ($ar[0] == 'none' && in_array($in, $tags)) {
- return true;
- }
- if ($ar[0] == 'all' && in_array($in, $tags)) {
- return false;
- }
- return false;
- }
+ $ar = explode('^', $this->_definedTags[$out]['allowed']);
+ $tags = explode(',', $ar[1]);
+ if ($ar[0] == 'none' && in_array($in, $tags)) {
+ return true;
+ }
+ if ($ar[0] == 'all' && in_array($in, $tags)) {
+ return false;
+ }
+ return false;
+ }
- /**
- * Builds a parsed string based on the tag array
- *
- * The correct html and attribute values are extracted from the private
- * _definedTags array.
- *
- * @return none
- * @access private
- * @see $_tagArray
- * @see $_parsed
- * @author Stijn de Reede
- */
- public function _buildParsedString()
- {
- $this->_parsed = '';
- foreach ($this->_tagArray as $tag) {
- switch ($tag['type']) {
+ /**
+ * Builds a parsed string based on the tag array
+ *
+ * The correct html and attribute values are extracted from the private
+ * _definedTags array.
+ *
+ * @return none
+ * @access private
+ * @see $_tagArray
+ * @see $_parsed
+ * @author Stijn de Reede
+ */
+ public function _buildParsedString()
+ {
+ $this->_parsed = '';
+ foreach ($this->_tagArray as $tag) {
+ switch ($tag['type']) {
- // just text
- case 0:
- $this->_parsed .= $tag['text'];
- break;
+ // just text
+ case 0:
+ $this->_parsed .= $tag['text'];
+ break;
- // opening tag
- case 1:
- $this->_parsed .= '<'.$this->_definedTags[$tag['tag']]['htmlopen'];
- if ($this->_options['quotestyle'] == 'single') $q = "'";
- if ($this->_options['quotestyle'] == 'double') $q = '"';
- foreach ($tag['attributes'] as $a => $v) {
- //prevent XSS attacks. IMHO this is not enough, though...
- //@see http://pear.php.net/bugs/bug.php?id=5609
- $v = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $v);
- $v = htmlspecialchars($v);
- $v = str_replace('&', '&', $v);
+ // opening tag
+ case 1:
+ $this->_parsed .= '<'.$this->_definedTags[$tag['tag']]['htmlopen'];
+ if ($this->_options['quotestyle'] == 'single') $q = "'";
+ if ($this->_options['quotestyle'] == 'double') $q = '"';
+ foreach ($tag['attributes'] as $a => $v) {
+ //prevent XSS attacks. IMHO this is not enough, though...
+ //@see http://pear.php.net/bugs/bug.php?id=5609
+ $v = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $v);
+ $v = htmlspecialchars($v);
+ $v = str_replace('&', '&', $v);
- if (($this->_options['quotewhat'] == 'nothing') ||
- (($this->_options['quotewhat'] == 'strings') && is_numeric($v))
- ) {
- $this->_parsed .= ' '.sprintf($this->_definedTags[$tag['tag']]['attributes'][$a], $v, '');
- } else {
- $this->_parsed .= ' '.sprintf($this->_definedTags[$tag['tag']]['attributes'][$a], $v, $q);
- }
- }
- if ($this->_definedTags[$tag['tag']]['htmlclose'] == '' && $this->_options['xmlclose']) {
- $this->_parsed .= ' /';
- }
- $this->_parsed .= '>';
- break;
+ if (($this->_options['quotewhat'] == 'nothing') ||
+ (($this->_options['quotewhat'] == 'strings') && is_numeric($v))
+ ) {
+ $this->_parsed .= ' '.sprintf($this->_definedTags[$tag['tag']]['attributes'][$a], $v, '');
+ } else {
+ $this->_parsed .= ' '.sprintf($this->_definedTags[$tag['tag']]['attributes'][$a], $v, $q);
+ }
+ }
+ if ($this->_definedTags[$tag['tag']]['htmlclose'] == '' && $this->_options['xmlclose']) {
+ $this->_parsed .= ' /';
+ }
+ $this->_parsed .= '>';
+ break;
- // closing tag
- case 2:
- if ($this->_definedTags[$tag['tag']]['htmlclose'] != '') {
- $this->_parsed .= ''.$this->_definedTags[$tag['tag']]['htmlclose'].'>';
- }
- break;
- }
- }
- }
+ // closing tag
+ case 2:
+ if ($this->_definedTags[$tag['tag']]['htmlclose'] != '') {
+ $this->_parsed .= ''.$this->_definedTags[$tag['tag']]['htmlclose'].'>';
+ }
+ break;
+ }
+ }
+ }
- /**
- * Sets text in the object to be parsed
- *
- * @param string the text to set in the object
- * @return none
- * @access public
- * @see getText()
- * @see $_text
- * @author Stijn de Reede
- */
- public function setText($str)
- {
- $this->_text = $str;
- }
+ /**
+ * Sets text in the object to be parsed
+ *
+ * @param string the text to set in the object
+ * @return none
+ * @access public
+ * @see getText()
+ * @see $_text
+ * @author Stijn de Reede
+ */
+ public function setText($str)
+ {
+ $this->_text = $str;
+ }
- /**
- * Gets the unparsed text from the object
- *
- * @return string the text set in the object
- * @access public
- * @see setText()
- * @see $_text
- * @author Stijn de Reede
- */
- public function getText()
- {
- return $this->_text;
- }
+ /**
+ * Gets the unparsed text from the object
+ *
+ * @return string the text set in the object
+ * @access public
+ * @see setText()
+ * @see $_text
+ * @author Stijn de Reede
+ */
+ public function getText()
+ {
+ return $this->_text;
+ }
- /**
- * Gets the preparsed text from the object
- *
- * @return string the text set in the object
- * @access public
- * @see _preparse()
- * @see $_preparsed
- * @author Stijn de Reede
- */
- public function getPreparsed()
- {
- return $this->_preparsed;
- }
+ /**
+ * Gets the preparsed text from the object
+ *
+ * @return string the text set in the object
+ * @access public
+ * @see _preparse()
+ * @see $_preparsed
+ * @author Stijn de Reede
+ */
+ public function getPreparsed()
+ {
+ return $this->_preparsed;
+ }
- /**
- * Gets the parsed text from the object
- *
- * @return string the parsed text set in the object
- * @access public
- * @see parse()
- * @see $_parsed
- * @author Stijn de Reede
- */
- public function getParsed()
- {
- return $this->_parsed;
- }
+ /**
+ * Gets the parsed text from the object
+ *
+ * @return string the parsed text set in the object
+ * @access public
+ * @see parse()
+ * @see $_parsed
+ * @author Stijn de Reede
+ */
+ public function getParsed()
+ {
+ return $this->_parsed;
+ }
- /**
- * Parses the text set in the object
- *
- * @return none
- * @access public
- * @see _preparse()
- * @see _buildTagArray()
- * @see _validateTagArray()
- * @see _buildParsedString()
- * @author Stijn de Reede
- */
- public function parse()
- {
- $this->_preparse();
- $this->_buildTagArray();
- $this->_validateTagArray();
- $this->_buildParsedString();
- }
+ /**
+ * Parses the text set in the object
+ *
+ * @return none
+ * @access public
+ * @see _preparse()
+ * @see _buildTagArray()
+ * @see _validateTagArray()
+ * @see _buildParsedString()
+ * @author Stijn de Reede
+ */
+ public function parse()
+ {
+ $this->_preparse();
+ $this->_buildTagArray();
+ $this->_validateTagArray();
+ $this->_buildParsedString();
+ }
- /**
- * Quick method to do setText(), parse() and getParsed at once
- *
- * @return none
- * @access public
- * @see parse()
- * @see $_text
- * @author Stijn de Reede
- */
- public function qparse($str)
- {
- $this->_text = $str;
- $this->parse();
- return $this->_parsed;
- }
+ /**
+ * Quick method to do setText(), parse() and getParsed at once
+ *
+ * @return none
+ * @access public
+ * @see parse()
+ * @see $_text
+ * @author Stijn de Reede
+ */
+ public function qparse($str)
+ {
+ $this->_text = $str;
+ $this->parse();
+ return $this->_parsed;
+ }
- /**
- * Quick static method to do setText(), parse() and getParsed at once
- *
- * @return none
- * @access public
- * @see parse()
- * @see $_text
- * @author Stijn de Reede
- */
- public function staticQparse($str)
- {
- $p = new SSHTMLBBCodeParser();
- $str = $p->qparse($str);
- unset($p);
- return $str;
- }
+ /**
+ * Quick static method to do setText(), parse() and getParsed at once
+ *
+ * @return none
+ * @access public
+ * @see parse()
+ * @see $_text
+ * @author Stijn de Reede
+ */
+ public function staticQparse($str)
+ {
+ $p = new SSHTMLBBCodeParser();
+ $str = $p->qparse($str);
+ unset($p);
+ return $str;
+ }
}
diff --git a/search/SearchContext.php b/search/SearchContext.php
index 610974f2b..de34b4086 100644
--- a/search/SearchContext.php
+++ b/search/SearchContext.php
@@ -147,7 +147,7 @@ class SearchContext extends Object {
$searchParamArray = $searchParams;
}
- foreach($searchParamArray as $key => $value) {
+ foreach($searchParamArray as $key => $value) {
$key = str_replace('__', '.', $key);
if($filter = $this->getFilter($key)) {
$filter->setModel($this->modelClass);
@@ -158,9 +158,9 @@ class SearchContext extends Object {
}
}
- if($this->connective != "AND") {
- throw new Exception("SearchContext connective '$this->connective' not supported after ORM-rewrite.");
- }
+ if($this->connective != "AND") {
+ throw new Exception("SearchContext connective '$this->connective' not supported after ORM-rewrite.");
+ }
return $query;
}
diff --git a/security/Authenticator.php b/security/Authenticator.php
index 9d61924a9..75c05ef4d 100644
--- a/security/Authenticator.php
+++ b/security/Authenticator.php
@@ -11,95 +11,95 @@
*/
abstract class Authenticator extends Object {
- /**
- * This variable holds all authenticators that should be used
- *
- * @var array
- */
- private static $authenticators = array('MemberAuthenticator');
-
- /**
- * Used to influence the order of authenticators on the login-screen
- * (default shows first).
- *
- * @var string
- */
- private static $default_authenticator = 'MemberAuthenticator';
+ /**
+ * This variable holds all authenticators that should be used
+ *
+ * @var array
+ */
+ private static $authenticators = array('MemberAuthenticator');
+
+ /**
+ * Used to influence the order of authenticators on the login-screen
+ * (default shows first).
+ *
+ * @var string
+ */
+ private static $default_authenticator = 'MemberAuthenticator';
- /**
- * Method to authenticate an user
- *
- * @param array $RAW_data Raw data to authenticate the user
- * @param Form $form Optional: If passed, better error messages can be
- * produced by using
- * {@link Form::sessionMessage()}
- * @return bool|Member Returns FALSE if authentication fails, otherwise
- * the member object
- */
+ /**
+ * Method to authenticate an user
+ *
+ * @param array $RAW_data Raw data to authenticate the user
+ * @param Form $form Optional: If passed, better error messages can be
+ * produced by using
+ * {@link Form::sessionMessage()}
+ * @return bool|Member Returns FALSE if authentication fails, otherwise
+ * the member object
+ */
public static function authenticate($RAW_data, Form $form = null) {
}
- /**
- * Method that creates the login form for this authentication method
- *
- * @param Controller The parent controller, necessary to create the
- * appropriate form action tag
- * @return Form Returns the login form to use with this authentication
- * method
- */
+ /**
+ * Method that creates the login form for this authentication method
+ *
+ * @param Controller The parent controller, necessary to create the
+ * appropriate form action tag
+ * @return Form Returns the login form to use with this authentication
+ * method
+ */
public static function get_login_form(Controller $controller) {
}
- /**
- * Get the name of the authentication method
- *
- * @return string Returns the name of the authentication method.
- */
+ /**
+ * Get the name of the authentication method
+ *
+ * @return string Returns the name of the authentication method.
+ */
public static function get_name() {
}
- public static function register($authenticator) {
+ public static function register($authenticator) {
self::register_authenticator($authenticator);
- }
+ }
- /**
- * Register a new authenticator
- *
- * The new authenticator has to exist and to be derived from the
- * {@link Authenticator}.
- * Every authenticator can be registered only once.
- *
- * @param string $authenticator Name of the authenticator class to
- * register
- * @return bool Returns TRUE on success, FALSE otherwise.
- */
- public static function register_authenticator($authenticator) {
- $authenticator = trim($authenticator);
+ /**
+ * Register a new authenticator
+ *
+ * The new authenticator has to exist and to be derived from the
+ * {@link Authenticator}.
+ * Every authenticator can be registered only once.
+ *
+ * @param string $authenticator Name of the authenticator class to
+ * register
+ * @return bool Returns TRUE on success, FALSE otherwise.
+ */
+ public static function register_authenticator($authenticator) {
+ $authenticator = trim($authenticator);
- if(class_exists($authenticator) == false)
- return false;
+ if(class_exists($authenticator) == false)
+ return false;
- if(is_subclass_of($authenticator, 'Authenticator') == false)
- return false;
+ if(is_subclass_of($authenticator, 'Authenticator') == false)
+ return false;
- if(in_array($authenticator, self::$authenticators) == false) {
- if(call_user_func(array($authenticator, 'on_register')) === true) {
- array_push(self::$authenticators, $authenticator);
- } else {
- return false;
- }
- }
+ if(in_array($authenticator, self::$authenticators) == false) {
+ if(call_user_func(array($authenticator, 'on_register')) === true) {
+ array_push(self::$authenticators, $authenticator);
+ } else {
+ return false;
+ }
+ }
- return true;
- }
-
- public static function unregister($authenticator) {
- self::unregister_authenticator($authenticator);
- }
-
+ return true;
+ }
+
+ public static function unregister($authenticator) {
+ self::unregister_authenticator($authenticator);
+ }
+
/**
* Remove a previously registered authenticator
*
@@ -108,82 +108,82 @@ abstract class Authenticator extends Object {
*/
public static function unregister_authenticator($authenticator) {
if(call_user_func(array($authenticator, 'on_unregister')) === true) {
- if(in_array($authenticator, self::$authenticators)) {
- unset(self::$authenticators[array_search($authenticator, self::$authenticators)]);
- }
+ if(in_array($authenticator, self::$authenticators)) {
+ unset(self::$authenticators[array_search($authenticator, self::$authenticators)]);
+ }
};
}
- /**
- * Check if a given authenticator is registered
- *
- * @param string $authenticator Name of the authenticator class to check
- * @return bool Returns TRUE if the authenticator is registered, FALSE
- * otherwise.
- */
- public static function is_registered($authenticator) {
- return in_array($authenticator, self::$authenticators);
- }
+ /**
+ * Check if a given authenticator is registered
+ *
+ * @param string $authenticator Name of the authenticator class to check
+ * @return bool Returns TRUE if the authenticator is registered, FALSE
+ * otherwise.
+ */
+ public static function is_registered($authenticator) {
+ return in_array($authenticator, self::$authenticators);
+ }
- /**
- * Get all registered authenticators
- *
- * @return array Returns an array with the class names of all registered
- * authenticators.
- */
- public static function get_authenticators() {
- // put default authenticator first (mainly for tab-order on loginform)
- if($key = array_search(self::$default_authenticator,self::$authenticators)) {
- unset(self::$authenticators[$key]);
- array_unshift(self::$authenticators, self::$default_authenticator);
- }
+ /**
+ * Get all registered authenticators
+ *
+ * @return array Returns an array with the class names of all registered
+ * authenticators.
+ */
+ public static function get_authenticators() {
+ // put default authenticator first (mainly for tab-order on loginform)
+ if($key = array_search(self::$default_authenticator,self::$authenticators)) {
+ unset(self::$authenticators[$key]);
+ array_unshift(self::$authenticators, self::$default_authenticator);
+ }
- return self::$authenticators;
- }
-
- /**
- * Set a default authenticator (shows first in tabs)
- *
- * @param string
- */
- public static function set_default_authenticator($authenticator) {
- self::$default_authenticator = $authenticator;
-
-
- }
-
- /**
- * @return string
- */
- public static function get_default_authenticator() {
- return self::$default_authenticator;
- }
+ return self::$authenticators;
+ }
+
+ /**
+ * Set a default authenticator (shows first in tabs)
+ *
+ * @param string
+ */
+ public static function set_default_authenticator($authenticator) {
+ self::$default_authenticator = $authenticator;
+
+
+ }
+
+ /**
+ * @return string
+ */
+ public static function get_default_authenticator() {
+ return self::$default_authenticator;
+ }
- /**
- * Callback function that is called when the authenticator is registered
- *
- * Use this method for initialization of a newly registered authenticator.
- * Just overload this method and it will be called when the authenticator
- * is registered.
- * If the method returns FALSE, the authenticator won't be
- * registered!
- *
- * @return bool Returns TRUE on success, FALSE otherwise.
- */
- protected static function on_register() {
- return true;
- }
-
- /**
- * Callback function that is called when an authenticator is removed.
- *
- * @return bool
- */
- protected static function on_unregister() {
- return true;
- }
+ /**
+ * Callback function that is called when the authenticator is registered
+ *
+ * Use this method for initialization of a newly registered authenticator.
+ * Just overload this method and it will be called when the authenticator
+ * is registered.
+ * If the method returns FALSE, the authenticator won't be
+ * registered!
+ *
+ * @return bool Returns TRUE on success, FALSE otherwise.
+ */
+ protected static function on_register() {
+ return true;
+ }
+
+ /**
+ * Callback function that is called when an authenticator is removed.
+ *
+ * @return bool
+ */
+ protected static function on_unregister() {
+ return true;
+ }
}
diff --git a/security/Group.php b/security/Group.php
index 772712a21..e70851b87 100755
--- a/security/Group.php
+++ b/security/Group.php
@@ -154,7 +154,7 @@ class Group extends DataObject {
// but tabstrip.js doesn't display tabs when directly adressed through a URL pragma
_t('Group.RolesAddEditLink', 'Manage roles')
) .
- "
"
+ ""
)
);
@@ -315,7 +315,7 @@ class Group extends DataObject {
}
public function getTreeTitle() {
- if($this->hasMethod('alternateTreeTitle')) return $this->alternateTreeTitle();
+ if($this->hasMethod('alternateTreeTitle')) return $this->alternateTreeTitle();
else return htmlspecialchars($this->Title, ENT_QUOTES);
}
@@ -367,7 +367,7 @@ class Group extends DataObject {
$results = $this->extend('canEdit', $member);
if($results && is_array($results)) if(!min($results)) return false;
- if(
+ if(
// either we have an ADMIN
(bool)Permission::checkMember($member, "ADMIN")
|| (
diff --git a/security/Member.php b/security/Member.php
index c6e4fb12f..137a7e2de 100644
--- a/security/Member.php
+++ b/security/Member.php
@@ -561,7 +561,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
* It should return fields that are editable by the admin and the logged-in user.
*
* @return FieldList Returns a {@link FieldList} containing the fields for
- * the member form.
+ * the member form.
*/
public function getMemberFormFields() {
$fields = parent::getFrontendFields();
@@ -658,10 +658,10 @@ class Member extends DataObject implements TemplateGlobalProvider {
return $word . $number;
} else {
- $random = rand();
- $string = md5($random);
- $output = substr($string, 0, 6);
- return $output;
+ $random = rand();
+ $string = md5($random);
+ $output = substr($string, 0, 6);
+ return $output;
}
}
@@ -1149,7 +1149,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
*
* @param array $groupList An array of group code names.
* @param array $memberGroups A component set of groups (if set to NULL,
- * $this->groups() will be used)
+ * $this->groups() will be used)
* @return array Groups in which the member is NOT in.
*/
public function memberNotInGroups($groupList, $memberGroups = null){
@@ -1171,7 +1171,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
* this member.
*
* @return FieldList Return a FieldList of fields that would appropriate for
- * editing this member.
+ * editing this member.
*/
public function getCMSFields() {
require_once('Zend/Date.php');
@@ -1535,14 +1535,14 @@ class Member_GroupSet extends ManyManyList {
* @subpackage security
*/
class Member_ChangePasswordEmail extends Email {
- protected $from = ''; // setting a blank from address uses the site's default administrator email
- protected $subject = '';
- protected $ss_template = 'ChangePasswordEmail';
-
- public function __construct() {
+ protected $from = ''; // setting a blank from address uses the site's default administrator email
+ protected $subject = '';
+ protected $ss_template = 'ChangePasswordEmail';
+
+ public function __construct() {
parent::__construct();
- $this->subject = _t('Member.SUBJECTPASSWORDCHANGED', "Your password has been changed", 'Email subject');
- }
+ $this->subject = _t('Member.SUBJECTPASSWORDCHANGED', "Your password has been changed", 'Email subject');
+ }
}
@@ -1553,14 +1553,14 @@ class Member_ChangePasswordEmail extends Email {
* @subpackage security
*/
class Member_ForgotPasswordEmail extends Email {
- protected $from = ''; // setting a blank from address uses the site's default administrator email
- protected $subject = '';
- protected $ss_template = 'ForgotPasswordEmail';
-
- public function __construct() {
+ protected $from = ''; // setting a blank from address uses the site's default administrator email
+ protected $subject = '';
+ protected $ss_template = 'ForgotPasswordEmail';
+
+ public function __construct() {
parent::__construct();
- $this->subject = _t('Member.SUBJECTPASSWORDRESET', "Your password reset link", 'Email subject');
- }
+ $this->subject = _t('Member.SUBJECTPASSWORDRESET', "Your password reset link", 'Email subject');
+ }
}
/**
diff --git a/security/MemberAuthenticator.php b/security/MemberAuthenticator.php
index 91d7a16fc..7654cca37 100644
--- a/security/MemberAuthenticator.php
+++ b/security/MemberAuthenticator.php
@@ -18,103 +18,103 @@ class MemberAuthenticator extends Authenticator {
'sha1' => 'sha1_v2.4'
);
- /**
- * Method to authenticate an user
- *
- * @param array $RAW_data Raw data to authenticate the user
- * @param Form $form Optional: If passed, better error messages can be
- * produced by using
- * {@link Form::sessionMessage()}
- * @return bool|Member Returns FALSE if authentication fails, otherwise
- * the member object
- * @see Security::setDefaultAdmin()
- */
- public static function authenticate($RAW_data, Form $form = null) {
- if(array_key_exists('Email', $RAW_data) && $RAW_data['Email']){
- $SQL_user = Convert::raw2sql($RAW_data['Email']);
- } else {
- return false;
- }
-
- $isLockedOut = false;
- $result = null;
-
- // Default login (see Security::setDefaultAdmin())
- if(Security::check_default_admin($RAW_data['Email'], $RAW_data['Password'])) {
- $member = Security::findAnAdministrator();
- } else {
- $member = DataObject::get_one(
- "Member",
- "\"" . Member::get_unique_identifier_field() . "\" = '$SQL_user' AND \"Password\" IS NOT NULL"
- );
-
- if($member) {
- $result = $member->checkPassword($RAW_data['Password']);
- } else {
- $result = new ValidationResult(false, _t('Member.ERRORWRONGCRED'));
- }
-
- if($member && !$result->valid()) {
- $member->registerFailedLogin();
- $member = false;
- }
- }
-
- // Optionally record every login attempt as a {@link LoginAttempt} object
/**
- * TODO We could handle this with an extension
+ * Method to authenticate an user
+ *
+ * @param array $RAW_data Raw data to authenticate the user
+ * @param Form $form Optional: If passed, better error messages can be
+ * produced by using
+ * {@link Form::sessionMessage()}
+ * @return bool|Member Returns FALSE if authentication fails, otherwise
+ * the member object
+ * @see Security::setDefaultAdmin()
*/
- if(Security::login_recording()) {
- $attempt = new LoginAttempt();
- if($member) {
- // successful login (member is existing with matching password)
- $attempt->MemberID = $member->ID;
- $attempt->Status = 'Success';
-
- // Audit logging hook
- $member->extend('authenticated');
+ public static function authenticate($RAW_data, Form $form = null) {
+ if(array_key_exists('Email', $RAW_data) && $RAW_data['Email']){
+ $SQL_user = Convert::raw2sql($RAW_data['Email']);
} else {
- // failed login - we're trying to see if a user exists with this email (disregarding wrong passwords)
- $existingMember = DataObject::get_one(
- "Member",
- "\"" . Member::get_unique_identifier_field() . "\" = '$SQL_user'"
- );
- if($existingMember) {
- $attempt->MemberID = $existingMember->ID;
-
- // Audit logging hook
- $existingMember->extend('authenticationFailed');
- } else {
-
- // Audit logging hook
- singleton('Member')->extend('authenticationFailedUnknownUser', $RAW_data);
- }
- $attempt->Status = 'Failure';
- }
- if(is_array($RAW_data['Email'])) {
- user_error("Bad email passed to MemberAuthenticator::authenticate(): $RAW_data[Email]", E_USER_WARNING);
return false;
}
+
+ $isLockedOut = false;
+ $result = null;
+
+ // Default login (see Security::setDefaultAdmin())
+ if(Security::check_default_admin($RAW_data['Email'], $RAW_data['Password'])) {
+ $member = Security::findAnAdministrator();
+ } else {
+ $member = DataObject::get_one(
+ "Member",
+ "\"" . Member::get_unique_identifier_field() . "\" = '$SQL_user' AND \"Password\" IS NOT NULL"
+ );
+
+ if($member) {
+ $result = $member->checkPassword($RAW_data['Password']);
+ } else {
+ $result = new ValidationResult(false, _t('Member.ERRORWRONGCRED'));
+ }
+
+ if($member && !$result->valid()) {
+ $member->registerFailedLogin();
+ $member = false;
+ }
+ }
- $attempt->Email = $RAW_data['Email'];
- $attempt->IP = Controller::curr()->getRequest()->getIP();
- $attempt->write();
- }
-
- // Legacy migration to precision-safe password hashes.
- // A login-event with cleartext passwords is the only time
- // when we can rehash passwords to a different hashing algorithm,
- // bulk-migration doesn't work due to the nature of hashing.
- // See PasswordEncryptor_LegacyPHPHash class.
- if(
- $member // only migrate after successful login
- && self::$migrate_legacy_hashes
- && array_key_exists($member->PasswordEncryption, self::$migrate_legacy_hashes)
- ) {
- $member->Password = $RAW_data['Password'];
- $member->PasswordEncryption = self::$migrate_legacy_hashes[$member->PasswordEncryption];
- $member->write();
- }
+ // Optionally record every login attempt as a {@link LoginAttempt} object
+ /**
+ * TODO We could handle this with an extension
+ */
+ if(Security::login_recording()) {
+ $attempt = new LoginAttempt();
+ if($member) {
+ // successful login (member is existing with matching password)
+ $attempt->MemberID = $member->ID;
+ $attempt->Status = 'Success';
+
+ // Audit logging hook
+ $member->extend('authenticated');
+ } else {
+ // failed login - we're trying to see if a user exists with this email (disregarding wrong passwords)
+ $existingMember = DataObject::get_one(
+ "Member",
+ "\"" . Member::get_unique_identifier_field() . "\" = '$SQL_user'"
+ );
+ if($existingMember) {
+ $attempt->MemberID = $existingMember->ID;
+
+ // Audit logging hook
+ $existingMember->extend('authenticationFailed');
+ } else {
+
+ // Audit logging hook
+ singleton('Member')->extend('authenticationFailedUnknownUser', $RAW_data);
+ }
+ $attempt->Status = 'Failure';
+ }
+ if(is_array($RAW_data['Email'])) {
+ user_error("Bad email passed to MemberAuthenticator::authenticate(): $RAW_data[Email]", E_USER_WARNING);
+ return false;
+ }
+
+ $attempt->Email = $RAW_data['Email'];
+ $attempt->IP = Controller::curr()->getRequest()->getIP();
+ $attempt->write();
+ }
+
+ // Legacy migration to precision-safe password hashes.
+ // A login-event with cleartext passwords is the only time
+ // when we can rehash passwords to a different hashing algorithm,
+ // bulk-migration doesn't work due to the nature of hashing.
+ // See PasswordEncryptor_LegacyPHPHash class.
+ if(
+ $member // only migrate after successful login
+ && self::$migrate_legacy_hashes
+ && array_key_exists($member->PasswordEncryption, self::$migrate_legacy_hashes)
+ ) {
+ $member->Password = $RAW_data['Password'];
+ $member->PasswordEncryption = self::$migrate_legacy_hashes[$member->PasswordEncryption];
+ $member->write();
+ }
if($member) {
Session::clear('BackURL');
@@ -126,25 +126,25 @@ class MemberAuthenticator extends Authenticator {
}
- /**
- * Method that creates the login form for this authentication method
- *
- * @param Controller The parent controller, necessary to create the
- * appropriate form action tag
- * @return Form Returns the login form to use with this authentication
- * method
- */
- public static function get_login_form(Controller $controller) {
- return Object::create("MemberLoginForm", $controller, "LoginForm");
- }
+ /**
+ * Method that creates the login form for this authentication method
+ *
+ * @param Controller The parent controller, necessary to create the
+ * appropriate form action tag
+ * @return Form Returns the login form to use with this authentication
+ * method
+ */
+ public static function get_login_form(Controller $controller) {
+ return Object::create("MemberLoginForm", $controller, "LoginForm");
+ }
- /**
- * Get the name of the authentication method
- *
- * @return string Returns the name of the authentication method.
- */
- public static function get_name() {
+ /**
+ * Get the name of the authentication method
+ *
+ * @return string Returns the name of the authentication method.
+ */
+ public static function get_name() {
return _t('MemberAuthenticator.TITLE', "E-mail & Password");
}
}
diff --git a/security/MemberLoginForm.php b/security/MemberLoginForm.php
index 2e04763f4..5ac7b7d86 100644
--- a/security/MemberLoginForm.php
+++ b/security/MemberLoginForm.php
@@ -33,7 +33,7 @@ class MemberLoginForm extends LoginForm {
* @param string $authenticatorClassName Name of the authenticator class that this form uses.
*/
public function __construct($controller, $name, $fields = null, $actions = null,
- $checkCurrentUser = true) {
+ $checkCurrentUser = true) {
// This is now set on the class directly to make it easier to create subclasses
// $this->authenticator_class = $authenticatorClassName;
@@ -226,13 +226,13 @@ JS
}
- /**
- * Try to authenticate the user
- *
- * @param array Submitted data
- * @return Member Returns the member object on successful authentication
- * or NULL on failure.
- */
+ /**
+ * Try to authenticate the user
+ *
+ * @param array Submitted data
+ * @return Member Returns the member object on successful authentication
+ * or NULL on failure.
+ */
public function performLogin($data) {
$member = call_user_func_array(array($this->authenticator_class, 'authenticate'), array($data, $this));
if($member) {
diff --git a/security/Permission.php b/security/Permission.php
index ea7e194ed..3e7bb12fb 100644
--- a/security/Permission.php
+++ b/security/Permission.php
@@ -6,7 +6,7 @@
*/
class Permission extends DataObject implements TemplateGlobalProvider {
- // the (1) after Type specifies the DB default value which is needed for
+ // the (1) after Type specifies the DB default value which is needed for
// upgrades from older SilverStripe versions
static $db = array(
"Code" => "Varchar",
@@ -55,7 +55,7 @@ class Permission extends DataObject implements TemplateGlobalProvider {
*/
static $declared_permissions = null;
- /**
+ /**
* Linear list of declared permissions in the system.
*
* @var array
diff --git a/security/PermissionCheckboxSetField.php b/security/PermissionCheckboxSetField.php
index c2a98f3b7..059735371 100644
--- a/security/PermissionCheckboxSetField.php
+++ b/security/PermissionCheckboxSetField.php
@@ -157,7 +157,7 @@ class PermissionCheckboxSetField extends FormField {
}
}
}
-
+
$odd = 0;
$options = '';
if($this->source) {
@@ -256,7 +256,7 @@ class PermissionCheckboxSetField extends FormField {
$idList = array();
if($this->value) foreach($this->value as $id => $bool) {
- if($bool) {
+ if($bool) {
$perm = new $managedClass();
$perm->{$this->filterField} = $record->ID;
$perm->Code = $id;
diff --git a/security/Security.php b/security/Security.php
index 908cb13a0..5b3daf07c 100644
--- a/security/Security.php
+++ b/security/Security.php
@@ -7,18 +7,18 @@
class Security extends Controller {
static $allowed_actions = array(
- 'index',
- 'login',
- 'logout',
- 'basicauthlogin',
- 'lostpassword',
- 'passwordsent',
- 'changepassword',
+ 'index',
+ 'login',
+ 'logout',
+ 'basicauthlogin',
+ 'lostpassword',
+ 'passwordsent',
+ 'changepassword',
'ping',
'LoginForm',
'ChangePasswordForm',
'LostPasswordForm',
- );
+ );
/**
* Default user name. Only used in dev-mode by {@link setDefaultAdmin()}
@@ -138,22 +138,22 @@ class Security extends Controller {
* If you don't provide a messageSet, a default will be used.
*
* @param Controller $controller The controller that you were on to cause the permission
- * failure.
+ * failure.
* @param string|array $messageSet The message to show to the user. This
- * can be a string, or a map of different
- * messages for different contexts.
- * If you pass an array, you can use the
- * following keys:
- * - default: The default message
- * - logInAgain: The message to show
- * if the user has just
- * logged out and the
- * - alreadyLoggedIn: The message to
- * show if the user
- * is already logged
- * in and lacks the
- * permission to
- * access the item.
+ * can be a string, or a map of different
+ * messages for different contexts.
+ * If you pass an array, you can use the
+ * following keys:
+ * - default: The default message
+ * - logInAgain: The message to show
+ * if the user has just
+ * logged out and the
+ * - alreadyLoggedIn: The message to
+ * show if the user
+ * is already logged
+ * in and lacks the
+ * permission to
+ * access the item.
*
* The alreadyLoggedIn value can contain a '%s' placeholder that will be replaced with a link
* to log in.
@@ -240,7 +240,7 @@ class Security extends Controller {
}
- /**
+ /**
* Get the login form to process according to the submitted data
*/
protected function LoginForm() {
@@ -262,7 +262,7 @@ class Security extends Controller {
}
- /**
+ /**
* Get the login forms for all available authentication methods
*
* @return array Returns an array of available login forms (array of Form
@@ -276,8 +276,8 @@ class Security extends Controller {
$authenticators = Authenticator::get_authenticators();
foreach($authenticators as $authenticator) {
- array_push($forms,
- call_user_func(array($authenticator, 'get_login_form'),
+ array_push($forms,
+ call_user_func(array($authenticator, 'get_login_form'),
$this));
}
@@ -307,9 +307,9 @@ class Security extends Controller {
* Log the currently logged in user out
*
* @param bool $redirect Redirect the user back to where they came.
- * - If it's false, the code calling logout() is
- * responsible for sending the user where-ever
- * they should go.
+ * - If it's false, the code calling logout() is
+ * responsible for sending the user where-ever
+ * they should go.
*/
public function logout($redirect = true) {
$member = Member::currentUser();
@@ -675,7 +675,7 @@ class Security extends Controller {
}
if ($adminGroup) {
- $member = $adminGroup->Members()->First();
+ $member = $adminGroup->Members()->First();
}
if(!$adminGroup) {
diff --git a/tests/api/RestfulServiceTest.php b/tests/api/RestfulServiceTest.php
index 9cc817bc5..201ea6f3a 100644
--- a/tests/api/RestfulServiceTest.php
+++ b/tests/api/RestfulServiceTest.php
@@ -37,7 +37,7 @@ class RestfulServiceTest extends SapphireTest {
$service->setQueryString($params);
$responseBody = $service->request($url)->getBody();
foreach ($params as $key => $value) {
- $this->assertContains("$value", $responseBody);
+ $this->assertContains("$value", $responseBody);
$this->assertContains("$value", $responseBody);
}
}
@@ -52,7 +52,7 @@ class RestfulServiceTest extends SapphireTest {
$service->setQueryString($params);
$responseBody = $service->request($url)->getBody();
foreach ($params as $key => $value) {
- $this->assertContains("$value", $responseBody);
+ $this->assertContains("$value", $responseBody);
$this->assertContains("$value", $responseBody);
}
}
@@ -67,7 +67,7 @@ class RestfulServiceTest extends SapphireTest {
$url .= '?' . http_build_query($params);
$responseBody = $service->request($url)->getBody();
foreach ($params as $key => $value) {
- $this->assertContains("$value", $responseBody);
+ $this->assertContains("$value", $responseBody);
$this->assertContains("$value", $responseBody);
}
}
diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php
index ea6f10054..a522e8a7c 100644
--- a/tests/behat/features/bootstrap/FeatureContext.php
+++ b/tests/behat/features/bootstrap/FeatureContext.php
@@ -3,10 +3,10 @@
namespace SilverStripe\Framework\Test\Behaviour;
use SilverStripe\BehatExtension\Context\SilverStripeContext,
- SilverStripe\BehatExtension\Context\BasicContext,
- SilverStripe\BehatExtension\Context\LoginContext,
- SilverStripe\Framework\Test\Behaviour\CmsFormsContext,
- SilverStripe\Framework\Test\Behaviour\CmsUiContext;
+ SilverStripe\BehatExtension\Context\BasicContext,
+ SilverStripe\BehatExtension\Context\LoginContext,
+ SilverStripe\Framework\Test\Behaviour\CmsFormsContext,
+ SilverStripe\Framework\Test\Behaviour\CmsUiContext;
// PHPUnit
require_once 'PHPUnit/Autoload.php';
@@ -20,19 +20,19 @@ require_once 'PHPUnit/Framework/Assert/Functions.php';
*/
class FeatureContext extends SilverStripeContext
{
- /**
- * Initializes context.
- * Every scenario gets it's own context object.
- *
- * @param array $parameters context parameters (set them up through behat.yml)
- */
- public function __construct(array $parameters)
- {
- $this->useContext('BasicContext', new BasicContext($parameters));
- $this->useContext('LoginContext', new LoginContext($parameters));
- $this->useContext('CmsFormsContext', new CmsFormsContext($parameters));
- $this->useContext('CmsUiContext', new CmsUiContext($parameters));
+ /**
+ * Initializes context.
+ * Every scenario gets it's own context object.
+ *
+ * @param array $parameters context parameters (set them up through behat.yml)
+ */
+ public function __construct(array $parameters)
+ {
+ $this->useContext('BasicContext', new BasicContext($parameters));
+ $this->useContext('LoginContext', new LoginContext($parameters));
+ $this->useContext('CmsFormsContext', new CmsFormsContext($parameters));
+ $this->useContext('CmsUiContext', new CmsUiContext($parameters));
- parent::__construct($parameters);
- }
+ parent::__construct($parameters);
+ }
}
diff --git a/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsFormsContext.php b/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsFormsContext.php
index 7e3591913..ca7b7baf9 100644
--- a/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsFormsContext.php
+++ b/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsFormsContext.php
@@ -3,12 +3,12 @@
namespace SilverStripe\Framework\Test\Behaviour;
use Behat\Behat\Context\ClosuredContextInterface,
- Behat\Behat\Context\TranslatedContextInterface,
- Behat\Behat\Context\BehatContext,
- Behat\Behat\Context\Step,
- Behat\Behat\Exception\PendingException;
+ Behat\Behat\Context\TranslatedContextInterface,
+ Behat\Behat\Context\BehatContext,
+ Behat\Behat\Context\Step,
+ Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
- Behat\Gherkin\Node\TableNode;
+ Behat\Gherkin\Node\TableNode;
// PHPUnit
require_once 'PHPUnit/Autoload.php';
@@ -21,81 +21,81 @@ require_once 'PHPUnit/Framework/Assert/Functions.php';
*/
class CmsFormsContext extends BehatContext
{
- protected $context;
+ protected $context;
- /**
- * Initializes context.
- * Every scenario gets it's own context object.
- *
- * @param array $parameters context parameters (set them up through behat.yml)
- */
- public function __construct(array $parameters)
- {
- // Initialize your context here
- $this->context = $parameters;
- }
+ /**
+ * Initializes context.
+ * Every scenario gets it's own context object.
+ *
+ * @param array $parameters context parameters (set them up through behat.yml)
+ */
+ public function __construct(array $parameters)
+ {
+ // Initialize your context here
+ $this->context = $parameters;
+ }
- /**
- * Get Mink session from MinkContext
- */
- public function getSession($name = null)
- {
- return $this->getMainContext()->getSession($name);
- }
+ /**
+ * Get Mink session from MinkContext
+ */
+ public function getSession($name = null)
+ {
+ return $this->getMainContext()->getSession($name);
+ }
- /**
- * @Then /^I should see an edit page form$/
- */
- public function stepIShouldSeeAnEditPageForm()
- {
- $page = $this->getSession()->getPage();
+ /**
+ * @Then /^I should see an edit page form$/
+ */
+ public function stepIShouldSeeAnEditPageForm()
+ {
+ $page = $this->getSession()->getPage();
- $form = $page->find('css', '#Form_EditForm');
- assertNotNull($form, 'I should see an edit page form');
- }
+ $form = $page->find('css', '#Form_EditForm');
+ assertNotNull($form, 'I should see an edit page form');
+ }
- /**
- * @When /^I fill in the "(?P([^"]*))" HTML field with "(?P([^"]*))"$/
- * @When /^I fill in "(?P([^"]*))" for the "(?P([^"]*))" HTML field$/
- */
- public function stepIFillInTheHtmlFieldWith($field, $value)
- {
- $page = $this->getSession()->getPage();
- $inputField = $page->findField($field);
- assertNotNull($inputField, sprintf('HTML field "%s" not found', $field));
+ /**
+ * @When /^I fill in the "(?P([^"]*))" HTML field with "(?P([^"]*))"$/
+ * @When /^I fill in "(?P([^"]*))" for the "(?P([^"]*))" HTML field$/
+ */
+ public function stepIFillInTheHtmlFieldWith($field, $value)
+ {
+ $page = $this->getSession()->getPage();
+ $inputField = $page->findField($field);
+ assertNotNull($inputField, sprintf('HTML field "%s" not found', $field));
- $this->getSession()->evaluateScript(sprintf(
- "jQuery('#%s').entwine('ss').getEditor().setContent('%s')",
- $inputField->getAttribute('id'),
- addcslashes($value, "'")
- ));
- }
+ $this->getSession()->evaluateScript(sprintf(
+ "jQuery('#%s').entwine('ss').getEditor().setContent('%s')",
+ $inputField->getAttribute('id'),
+ addcslashes($value, "'")
+ ));
+ }
- /**
- * @When /^I append "(?P([^"]*))" to the "(?P([^"]*))" HTML field$/
- */
- public function stepIAppendTotheHtmlField($field, $value)
- {
- $page = $this->getSession()->getPage();
- $inputField = $page->findField($field);
- assertNotNull($inputField, sprintf('HTML field "%s" not found', $field));
+ /**
+ * @When /^I append "(?P([^"]*))" to the "(?P([^"]*))" HTML field$/
+ */
+ public function stepIAppendTotheHtmlField($field, $value)
+ {
+ $page = $this->getSession()->getPage();
+ $inputField = $page->findField($field);
+ assertNotNull($inputField, sprintf('HTML field "%s" not found', $field));
- $this->getSession()->evaluateScript(sprintf(
- "jQuery('#%s').entwine('ss').getEditor().insertContent('%s')",
- $inputField->getAttribute('id'),
- addcslashes($value, "'")
- ));
- }
+ $this->getSession()->evaluateScript(sprintf(
+ "jQuery('#%s').entwine('ss').getEditor().insertContent('%s')",
+ $inputField->getAttribute('id'),
+ addcslashes($value, "'")
+ ));
+ }
- /**
- * @Then /^the "(?P([^"]*))" HTML field should contain "(?P([^"]*))"$/
- */
- public function theHtmlFieldShouldContain($field, $value)
- {
- $page = $this->getSession()->getPage();
- $inputField = $page->findField($field);
- assertNotNull($inputField, sprintf('HTML field "%s" not found', $field));
+ /**
+ * @Then /^the "(?P([^"]*))" HTML field should contain "(?P([^"]*))"$/
+ */
+ public function theHtmlFieldShouldContain($field, $value)
+ {
+ $page = $this->getSession()->getPage();
+ $inputField = $page->findField($field);
+ assertNotNull($inputField, sprintf('HTML field "%s" not found', $field));
- $this->getMainContext()->assertElementContains('#' . $inputField->getAttribute('id'), $value);
- }
+ $this->getMainContext()->assertElementContains('#' . $inputField->getAttribute('id'), $value);
+ }
}
diff --git a/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php b/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php
index 42d2b2e73..0cbcb4ed2 100644
--- a/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php
+++ b/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php
@@ -3,13 +3,13 @@
namespace SilverStripe\Framework\Test\Behaviour;
use Behat\Behat\Context\ClosuredContextInterface,
- Behat\Behat\Context\TranslatedContextInterface,
- Behat\Behat\Context\BehatContext,
- Behat\Behat\Context\Step,
- Behat\Behat\Exception\PendingException,
- Behat\Mink\Exception\ElementNotFoundException;
+ Behat\Behat\Context\TranslatedContextInterface,
+ Behat\Behat\Context\BehatContext,
+ Behat\Behat\Context\Step,
+ Behat\Behat\Exception\PendingException,
+ Behat\Mink\Exception\ElementNotFoundException;
use Behat\Gherkin\Node\PyStringNode,
- Behat\Gherkin\Node\TableNode;
+ Behat\Gherkin\Node\TableNode;
// PHPUnit
@@ -23,376 +23,376 @@ require_once 'PHPUnit/Framework/Assert/Functions.php';
*/
class CmsUiContext extends BehatContext
{
- protected $context;
+ protected $context;
- /**
- * Initializes context.
- * Every scenario gets it's own context object.
- *
- * @param array $parameters context parameters (set them up through behat.yml)
- */
- public function __construct(array $parameters)
- {
- // Initialize your context here
- $this->context = $parameters;
- }
+ /**
+ * Initializes context.
+ * Every scenario gets it's own context object.
+ *
+ * @param array $parameters context parameters (set them up through behat.yml)
+ */
+ public function __construct(array $parameters)
+ {
+ // Initialize your context here
+ $this->context = $parameters;
+ }
- /**
- * Get Mink session from MinkContext
- */
- public function getSession($name = null)
- {
- return $this->getMainContext()->getSession($name);
- }
+ /**
+ * Get Mink session from MinkContext
+ */
+ public function getSession($name = null)
+ {
+ return $this->getMainContext()->getSession($name);
+ }
- /**
- * @Then /^I should see the CMS$/
- */
- public function iShouldSeeTheCms()
- {
- $page = $this->getSession()->getPage();
- $cms_element = $page->find('css', '.cms');
- assertNotNull($cms_element, 'CMS not found');
- }
+ /**
+ * @Then /^I should see the CMS$/
+ */
+ public function iShouldSeeTheCms()
+ {
+ $page = $this->getSession()->getPage();
+ $cms_element = $page->find('css', '.cms');
+ assertNotNull($cms_element, 'CMS not found');
+ }
- /**
- * @Then /^I should see a "([^"]*)" notice$/
- */
- public function iShouldSeeANotice($notice)
- {
- $this->getMainContext()->assertElementContains('.notice-wrap', $notice);
- }
+ /**
+ * @Then /^I should see a "([^"]*)" notice$/
+ */
+ public function iShouldSeeANotice($notice)
+ {
+ $this->getMainContext()->assertElementContains('.notice-wrap', $notice);
+ }
- /**
- * @Then /^I should see a "([^"]*)" message$/
- */
- public function iShouldSeeAMessage($message)
- {
- $this->getMainContext()->assertElementContains('.message', $message);
- }
+ /**
+ * @Then /^I should see a "([^"]*)" message$/
+ */
+ public function iShouldSeeAMessage($message)
+ {
+ $this->getMainContext()->assertElementContains('.message', $message);
+ }
- protected function getCmsTabsElement()
- {
- $this->getSession()->wait(5000, "window.jQuery('.cms-content-header-tabs').size() > 0");
+ protected function getCmsTabsElement()
+ {
+ $this->getSession()->wait(5000, "window.jQuery('.cms-content-header-tabs').size() > 0");
- $page = $this->getSession()->getPage();
- $cms_content_header_tabs = $page->find('css', '.cms-content-header-tabs');
- assertNotNull($cms_content_header_tabs, 'CMS tabs not found');
+ $page = $this->getSession()->getPage();
+ $cms_content_header_tabs = $page->find('css', '.cms-content-header-tabs');
+ assertNotNull($cms_content_header_tabs, 'CMS tabs not found');
- return $cms_content_header_tabs;
- }
+ return $cms_content_header_tabs;
+ }
- protected function getCmsContentToolbarElement()
- {
- $this->getSession()->wait(
- 5000,
- "window.jQuery('.cms-content-toolbar').size() > 0 "
- . "&& window.jQuery('.cms-content-toolbar').children().size() > 0"
- );
+ protected function getCmsContentToolbarElement()
+ {
+ $this->getSession()->wait(
+ 5000,
+ "window.jQuery('.cms-content-toolbar').size() > 0 "
+ . "&& window.jQuery('.cms-content-toolbar').children().size() > 0"
+ );
- $page = $this->getSession()->getPage();
- $cms_content_toolbar_element = $page->find('css', '.cms-content-toolbar');
- assertNotNull($cms_content_toolbar_element, 'CMS content toolbar not found');
+ $page = $this->getSession()->getPage();
+ $cms_content_toolbar_element = $page->find('css', '.cms-content-toolbar');
+ assertNotNull($cms_content_toolbar_element, 'CMS content toolbar not found');
- return $cms_content_toolbar_element;
- }
+ return $cms_content_toolbar_element;
+ }
- protected function getCmsTreeElement()
- {
- $this->getSession()->wait(5000, "window.jQuery('.cms-tree').size() > 0");
+ protected function getCmsTreeElement()
+ {
+ $this->getSession()->wait(5000, "window.jQuery('.cms-tree').size() > 0");
- $page = $this->getSession()->getPage();
- $cms_tree_element = $page->find('css', '.cms-tree');
- assertNotNull($cms_tree_element, 'CMS tree not found');
+ $page = $this->getSession()->getPage();
+ $cms_tree_element = $page->find('css', '.cms-tree');
+ assertNotNull($cms_tree_element, 'CMS tree not found');
- return $cms_tree_element;
- }
+ return $cms_tree_element;
+ }
- protected function getGridfieldTable($title)
- {
- $page = $this->getSession()->getPage();
- $table_elements = $page->findAll('css', '.ss-gridfield-table');
- assertNotNull($table_elements, 'Table elements not found');
+ protected function getGridfieldTable($title)
+ {
+ $page = $this->getSession()->getPage();
+ $table_elements = $page->findAll('css', '.ss-gridfield-table');
+ assertNotNull($table_elements, 'Table elements not found');
- $table_element = null;
- foreach ($table_elements as $table) {
- $table_title_element = $table->find('css', '.title');
- if ($table_title_element->getText() === $title) {
- $table_element = $table;
- break;
- }
- }
- assertNotNull($table_element, sprintf('Table `%s` not found', $title));
+ $table_element = null;
+ foreach ($table_elements as $table) {
+ $table_title_element = $table->find('css', '.title');
+ if ($table_title_element->getText() === $title) {
+ $table_element = $table;
+ break;
+ }
+ }
+ assertNotNull($table_element, sprintf('Table `%s` not found', $title));
- return $table_element;
- }
+ return $table_element;
+ }
- /**
- * @Given /^I should see a "([^"]*)" button in CMS Content Toolbar$/
- */
- public function iShouldSeeAButtonInCmsContentToolbar($text)
- {
- $cms_content_toolbar_element = $this->getCmsContentToolbarElement();
+ /**
+ * @Given /^I should see a "([^"]*)" button in CMS Content Toolbar$/
+ */
+ public function iShouldSeeAButtonInCmsContentToolbar($text)
+ {
+ $cms_content_toolbar_element = $this->getCmsContentToolbarElement();
- $element = $cms_content_toolbar_element->find('named', array('link_or_button', "'$text'"));
- assertNotNull($element, sprintf('%s button not found', $text));
- }
+ $element = $cms_content_toolbar_element->find('named', array('link_or_button', "'$text'"));
+ assertNotNull($element, sprintf('%s button not found', $text));
+ }
- /**
- * @When /^I should see "([^"]*)" in CMS Tree$/
- */
- public function stepIShouldSeeInCmsTree($text)
- {
- $cms_tree_element = $this->getCmsTreeElement();
+ /**
+ * @When /^I should see "([^"]*)" in CMS Tree$/
+ */
+ public function stepIShouldSeeInCmsTree($text)
+ {
+ $cms_tree_element = $this->getCmsTreeElement();
- $element = $cms_tree_element->find('named', array('content', "'$text'"));
- assertNotNull($element, sprintf('%s not found', $text));
- }
+ $element = $cms_tree_element->find('named', array('content', "'$text'"));
+ assertNotNull($element, sprintf('%s not found', $text));
+ }
- /**
- * @When /^I should not see "([^"]*)" in CMS Tree$/
- */
- public function stepIShouldNotSeeInCmsTree($text)
- {
- $cms_tree_element = $this->getCmsTreeElement();
+ /**
+ * @When /^I should not see "([^"]*)" in CMS Tree$/
+ */
+ public function stepIShouldNotSeeInCmsTree($text)
+ {
+ $cms_tree_element = $this->getCmsTreeElement();
- $element = $cms_tree_element->find('named', array('content', "'$text'"));
- assertNull($element, sprintf('%s found', $text));
- }
+ $element = $cms_tree_element->find('named', array('content', "'$text'"));
+ assertNull($element, sprintf('%s found', $text));
+ }
- /**
- * @When /^I expand the "([^"]*)" CMS Panel$/
- */
- public function iExpandTheCmsPanel()
- {
- // TODO Make dynamic, currently hardcoded to first panel
- $page = $this->getSession()->getPage();
+ /**
+ * @When /^I expand the "([^"]*)" CMS Panel$/
+ */
+ public function iExpandTheCmsPanel()
+ {
+ // TODO Make dynamic, currently hardcoded to first panel
+ $page = $this->getSession()->getPage();
- $panel_toggle_element = $page->find('css', '.cms-content > .cms-panel > .cms-panel-toggle > .toggle-expand');
- assertNotNull($panel_toggle_element, 'Panel toggle not found');
+ $panel_toggle_element = $page->find('css', '.cms-content > .cms-panel > .cms-panel-toggle > .toggle-expand');
+ assertNotNull($panel_toggle_element, 'Panel toggle not found');
- if ($panel_toggle_element->isVisible()) {
- $panel_toggle_element->click();
- }
- }
+ if ($panel_toggle_element->isVisible()) {
+ $panel_toggle_element->click();
+ }
+ }
- /**
- * @When /^I click the "([^"]*)" CMS tab$/
- */
- public function iClickTheCmsTab($tab)
- {
- $this->getSession()->wait(5000, "window.jQuery('.ui-tabs-nav').size() > 0");
+ /**
+ * @When /^I click the "([^"]*)" CMS tab$/
+ */
+ public function iClickTheCmsTab($tab)
+ {
+ $this->getSession()->wait(5000, "window.jQuery('.ui-tabs-nav').size() > 0");
- $page = $this->getSession()->getPage();
- $tabsets = $page->findAll('css', '.ui-tabs-nav');
- assertNotNull($tabsets, 'CMS tabs not found');
+ $page = $this->getSession()->getPage();
+ $tabsets = $page->findAll('css', '.ui-tabs-nav');
+ assertNotNull($tabsets, 'CMS tabs not found');
- $tab_element = null;
- foreach($tabsets as $tabset) {
- if($tab_element) continue;
- $tab_element = $tabset->find('named', array('link_or_button', "'$tab'"));
- }
- assertNotNull($tab_element, sprintf('%s tab not found', $tab));
+ $tab_element = null;
+ foreach($tabsets as $tabset) {
+ if($tab_element) continue;
+ $tab_element = $tabset->find('named', array('link_or_button', "'$tab'"));
+ }
+ assertNotNull($tab_element, sprintf('%s tab not found', $tab));
- $tab_element->click();
- }
+ $tab_element->click();
+ }
- /**
- * @Then /^the "([^"]*)" table should contain "([^"]*)"$/
- */
- public function theTableShouldContain($table, $text)
- {
- $table_element = $this->getGridfieldTable($table);
+ /**
+ * @Then /^the "([^"]*)" table should contain "([^"]*)"$/
+ */
+ public function theTableShouldContain($table, $text)
+ {
+ $table_element = $this->getGridfieldTable($table);
- $element = $table_element->find('named', array('content', "'$text'"));
- assertNotNull($element, sprintf('Element containing `%s` not found in `%s` table', $text, $table));
- }
+ $element = $table_element->find('named', array('content', "'$text'"));
+ assertNotNull($element, sprintf('Element containing `%s` not found in `%s` table', $text, $table));
+ }
- /**
- * @Then /^the "([^"]*)" table should not contain "([^"]*)"$/
- */
- public function theTableShouldNotContain($table, $text)
- {
- $table_element = $this->getGridfieldTable($table);
+ /**
+ * @Then /^the "([^"]*)" table should not contain "([^"]*)"$/
+ */
+ public function theTableShouldNotContain($table, $text)
+ {
+ $table_element = $this->getGridfieldTable($table);
- $element = $table_element->find('named', array('content', "'$text'"));
- assertNull($element, sprintf('Element containing `%s` not found in `%s` table', $text, $table));
- }
+ $element = $table_element->find('named', array('content', "'$text'"));
+ assertNull($element, sprintf('Element containing `%s` not found in `%s` table', $text, $table));
+ }
- /**
- * @Given /^I click on "([^"]*)" in the "([^"]*)" table$/
- */
- public function iClickOnInTheTable($text, $table)
- {
- $table_element = $this->getGridfieldTable($table);
+ /**
+ * @Given /^I click on "([^"]*)" in the "([^"]*)" table$/
+ */
+ public function iClickOnInTheTable($text, $table)
+ {
+ $table_element = $this->getGridfieldTable($table);
- $element = $table_element->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text));
- assertNotNull($element, sprintf('Element containing `%s` not found', $text));
- $element->click();
- }
+ $element = $table_element->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text));
+ assertNotNull($element, sprintf('Element containing `%s` not found', $text));
+ $element->click();
+ }
- /**
- * @Then /^I can see the preview panel$/
- */
- public function iCanSeeThePreviewPanel()
- {
- $this->getMainContext()->assertElementOnPage('.cms-preview');
- }
+ /**
+ * @Then /^I can see the preview panel$/
+ */
+ public function iCanSeeThePreviewPanel()
+ {
+ $this->getMainContext()->assertElementOnPage('.cms-preview');
+ }
- /**
- * @Given /^the preview contains "([^"]*)"$/
- */
- public function thePreviewContains($content)
- {
- $driver = $this->getSession()->getDriver();
- $driver->switchToIFrame('cms-preview-iframe');
+ /**
+ * @Given /^the preview contains "([^"]*)"$/
+ */
+ public function thePreviewContains($content)
+ {
+ $driver = $this->getSession()->getDriver();
+ $driver->switchToIFrame('cms-preview-iframe');
- $this->getMainContext()->assertPageContainsText($content);
- $driver->switchToWindow();
- }
+ $this->getMainContext()->assertPageContainsText($content);
+ $driver->switchToWindow();
+ }
- /**
- * @Given /^I set the CMS mode to "([^"]*)"$/
- */
- public function iSetTheCmsToMode($mode)
- {
- return array(
- new Step\When(sprintf('I fill in the "Change view mode" dropdown with "%s"', $mode)),
- new Step\When('I wait for 1 second') // wait for CMS layout to redraw
- );
- }
+ /**
+ * @Given /^I set the CMS mode to "([^"]*)"$/
+ */
+ public function iSetTheCmsToMode($mode)
+ {
+ return array(
+ new Step\When(sprintf('I fill in the "Change view mode" dropdown with "%s"', $mode)),
+ new Step\When('I wait for 1 second') // wait for CMS layout to redraw
+ );
+ }
- /**
- * @Given /^I wait for the preview to load$/
- */
- public function iWaitForThePreviewToLoad()
- {
- $driver = $this->getSession()->getDriver();
- $driver->switchToIFrame('cms-preview-iframe');
-
- $this->getSession()->wait(
- 5000,
- "!jQuery('iframe[name=cms-preview-iframe]').hasClass('loading')"
- );
+ /**
+ * @Given /^I wait for the preview to load$/
+ */
+ public function iWaitForThePreviewToLoad()
+ {
+ $driver = $this->getSession()->getDriver();
+ $driver->switchToIFrame('cms-preview-iframe');
+
+ $this->getSession()->wait(
+ 5000,
+ "!jQuery('iframe[name=cms-preview-iframe]').hasClass('loading')"
+ );
- $driver->switchToWindow();
- }
+ $driver->switchToWindow();
+ }
- /**
- * @Given /^I switch the preview to "([^"]*)"$/
- */
- public function iSwitchThePreviewToMode($mode)
- {
- $controls = $this->getSession()->getPage()->find('css', '.cms-preview-controls');
- assertNotNull($controls, 'Preview controls not found');
+ /**
+ * @Given /^I switch the preview to "([^"]*)"$/
+ */
+ public function iSwitchThePreviewToMode($mode)
+ {
+ $controls = $this->getSession()->getPage()->find('css', '.cms-preview-controls');
+ assertNotNull($controls, 'Preview controls not found');
- $label = $controls->find('xpath', sprintf(
- './/label[(@for="%s")]',
- $mode
- ));
- assertNotNull($label, 'Preview mode switch not found');
+ $label = $controls->find('xpath', sprintf(
+ './/label[(@for="%s")]',
+ $mode
+ ));
+ assertNotNull($label, 'Preview mode switch not found');
- $label->click();
+ $label->click();
- return new Step\When('I wait for the preview to load');
- }
+ return new Step\When('I wait for the preview to load');
+ }
- /**
- * @Given /^the preview does not contain "([^"]*)"$/
- */
- public function thePreviewDoesNotContain($content)
- {
- $driver = $this->getSession()->getDriver();
- $driver->switchToIFrame('cms-preview-iframe');
+ /**
+ * @Given /^the preview does not contain "([^"]*)"$/
+ */
+ public function thePreviewDoesNotContain($content)
+ {
+ $driver = $this->getSession()->getDriver();
+ $driver->switchToIFrame('cms-preview-iframe');
- $this->getMainContext()->assertPageNotContainsText($content);
- $driver->switchToWindow();
- }
+ $this->getMainContext()->assertPageNotContainsText($content);
+ $driver->switchToWindow();
+ }
- /**
- * Workaround for chosen.js dropdowns which hide the original dropdown field.
- *
- * @When /^(?:|I )fill in the "(?P(?:[^"]|\\")*)" dropdown with "(?P(?:[^"]|\\")*)"$/
- * @When /^(?:|I )fill in "(?P(?:[^"]|\\")*)" for the "(?P(?:[^"]|\\")*)" dropdown$/
- */
- public function theIFillInTheDropdownWith($field, $value)
- {
- $field = $this->fixStepArgument($field);
- $value = $this->fixStepArgument($value);
+ /**
+ * Workaround for chosen.js dropdowns which hide the original dropdown field.
+ *
+ * @When /^(?:|I )fill in the "(?P(?:[^"]|\\")*)" dropdown with "(?P(?:[^"]|\\")*)"$/
+ * @When /^(?:|I )fill in "(?P(?:[^"]|\\")*)" for the "(?P(?:[^"]|\\")*)" dropdown$/
+ */
+ public function theIFillInTheDropdownWith($field, $value)
+ {
+ $field = $this->fixStepArgument($field);
+ $value = $this->fixStepArgument($value);
- // Given the fuzzy matching, we might get more than one matching field.
- $formFields = array();
+ // Given the fuzzy matching, we might get more than one matching field.
+ $formFields = array();
- // Find by label
- $formField = $this->getSession()->getPage()->findField($field);
- if($formField) $formFields[] = $formField;
+ // Find by label
+ $formField = $this->getSession()->getPage()->findField($field);
+ if($formField) $formFields[] = $formField;
- // Fall back to finding by title (for dropdowns without a label)
- if(!$formFields) {
- $formFields = $this->getSession()->getPage()->findAll(
- 'xpath',
- sprintf(
- '//*[self::select][(./@title="%s")]',
- $field
- )
- );
- }
+ // Fall back to finding by title (for dropdowns without a label)
+ if(!$formFields) {
+ $formFields = $this->getSession()->getPage()->findAll(
+ 'xpath',
+ sprintf(
+ '//*[self::select][(./@title="%s")]',
+ $field
+ )
+ );
+ }
- assertGreaterThan(0, count($formFields), sprintf(
- 'Chosen.js dropdown named "%s" not found',
- $field
- ));
+ assertGreaterThan(0, count($formFields), sprintf(
+ 'Chosen.js dropdown named "%s" not found',
+ $field
+ ));
- $containers = array();
- foreach($formFields as $formField) {
- // Traverse up to field holder
- $containerCandidate = $formField;
- do {
- $containerCandidate = $containerCandidate->getParent();
- } while($containerCandidate && !preg_match('/field/', $containerCandidate->getAttribute('class')));
+ $containers = array();
+ foreach($formFields as $formField) {
+ // Traverse up to field holder
+ $containerCandidate = $formField;
+ do {
+ $containerCandidate = $containerCandidate->getParent();
+ } while($containerCandidate && !preg_match('/field/', $containerCandidate->getAttribute('class')));
- if(
- $containerCandidate
- && $containerCandidate->isVisible()
- && preg_match('/field/', $containerCandidate->getAttribute('class'))
- ) {
- $containers[] = $containerCandidate;
- }
- }
-
- assertGreaterThan(0, count($containers), 'Chosen.js field container not found');
+ if(
+ $containerCandidate
+ && $containerCandidate->isVisible()
+ && preg_match('/field/', $containerCandidate->getAttribute('class'))
+ ) {
+ $containers[] = $containerCandidate;
+ }
+ }
+
+ assertGreaterThan(0, count($containers), 'Chosen.js field container not found');
- // Default to first visible container
- $container = $containers[0];
-
- // Click on newly expanded list element, indirectly setting the dropdown value
- $linkEl = $container->find('xpath', './/a[./@href]');
- assertNotNull($linkEl, 'Chosen.js link element not found');
- $this->getSession()->wait(100); // wait for dropdown overlay to appear
- $linkEl->click();
+ // Default to first visible container
+ $container = $containers[0];
+
+ // Click on newly expanded list element, indirectly setting the dropdown value
+ $linkEl = $container->find('xpath', './/a[./@href]');
+ assertNotNull($linkEl, 'Chosen.js link element not found');
+ $this->getSession()->wait(100); // wait for dropdown overlay to appear
+ $linkEl->click();
- $listEl = $container->find('xpath', sprintf('.//li[contains(normalize-space(string(.)), \'%s\')]', $value));
- assertNotNull($listEl, sprintf(
- 'Chosen.js list element with title "%s" not found',
- $value
- ));
+ $listEl = $container->find('xpath', sprintf('.//li[contains(normalize-space(string(.)), \'%s\')]', $value));
+ assertNotNull($listEl, sprintf(
+ 'Chosen.js list element with title "%s" not found',
+ $value
+ ));
- // Dropdown flyout might be animated
- // $this->getSession()->wait(1000, 'jQuery(":animated").length == 0');
- $this->getSession()->wait(300);
+ // Dropdown flyout might be animated
+ // $this->getSession()->wait(1000, 'jQuery(":animated").length == 0');
+ $this->getSession()->wait(300);
- $listEl->click();
- }
+ $listEl->click();
+ }
- /**
- * Returns fixed step argument (with \\" replaced back to ").
- *
- * @param string $argument
- *
- * @return string
- */
- protected function fixStepArgument($argument)
- {
- return str_replace('\\"', '"', $argument);
- }
+ /**
+ * Returns fixed step argument (with \\" replaced back to ").
+ *
+ * @param string $argument
+ *
+ * @return string
+ */
+ protected function fixStepArgument($argument)
+ {
+ return str_replace('\\"', '"', $argument);
+ }
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 1904a068f..8e4da445d 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -27,18 +27,18 @@ if(!defined('BASE_PATH')) define('BASE_PATH', dirname($frameworkPath));
// Copied from cli-script.php, to enable same behaviour through phpunit runner.
if(isset($_SERVER['argv'][2])) {
- $args = array_slice($_SERVER['argv'],2);
- if(!isset($_GET)) $_GET = array();
- if(!isset($_REQUEST)) $_REQUEST = array();
- foreach($args as $arg) {
- if(strpos($arg,'=') == false) {
- $_GET['args'][] = $arg;
- } else {
- $newItems = array();
- parse_str( (substr($arg,0,2) == '--') ? substr($arg,2) : $arg, $newItems );
- $_GET = array_merge($_GET, $newItems);
- }
- }
+ $args = array_slice($_SERVER['argv'],2);
+ if(!isset($_GET)) $_GET = array();
+ if(!isset($_REQUEST)) $_REQUEST = array();
+ foreach($args as $arg) {
+ if(strpos($arg,'=') == false) {
+ $_GET['args'][] = $arg;
+ } else {
+ $newItems = array();
+ parse_str( (substr($arg,0,2) == '--') ? substr($arg,2) : $arg, $newItems );
+ $_GET = array_merge($_GET, $newItems);
+ }
+ }
$_REQUEST = array_merge($_REQUEST, $_GET);
}
@@ -70,4 +70,4 @@ if(!isset($_GET['flush']) || !$_GET['flush']) {
"Add flush=1 as an argument to discover new classes or files.\n",
false
);
-}
\ No newline at end of file
+}
diff --git a/tests/control/HTTPTest.php b/tests/control/HTTPTest.php
index 654b824cb..5379c7ae9 100644
--- a/tests/control/HTTPTest.php
+++ b/tests/control/HTTPTest.php
@@ -10,8 +10,8 @@ class HTTPTest extends SapphireTest {
/**
* Tests {@link HTTP::getLinksIn()}
*/
- public function testGetLinksIn() {
- $content = '
+ public function testGetLinksIn() {
+ $content = '