@@ -465,6 +465,28 @@ protected function allValues($oElement, &$aResult, $sSearchString = null) {
465
465
}
466
466
}
467
467
}
468
+
469
+ /**
470
+ * Does the same thing as $this->allRuleSets except it creates
471
+ * an associative array with the selector as the keys. If there
472
+ * are multiple selectors in the rule set, then each one will
473
+ * have their own array element.
474
+ *
475
+ * @param array $aResult
476
+ *
477
+ * @author dschaefer 12/23/2010
478
+ */
479
+ protected function allUniqueRuleSets (&$ aResult ){
480
+ foreach ($ this ->aContents as $ mContent ) {
481
+ if ($ mContent instanceof CSSRuleSet) {
482
+ foreach ($ mContent ->getSelector () as $ aSelector ){
483
+ $ aResult [$ aSelector ] = $ mContent ;
484
+ }
485
+ } else if ($ mContent instanceof CSSList) {
486
+ $ mContent ->allRuleSets ($ aResult );
487
+ }
488
+ }
489
+ }
468
490
}
469
491
470
492
class CSSDocument extends CSSList {
@@ -492,6 +514,44 @@ public function getAllValues($mElement = null) {
492
514
$ this ->allValues ($ mElement , $ aResult , $ sSearchString );
493
515
return $ aResult ;
494
516
}
517
+
518
+ /**
519
+ * Does the same thing as $this->getAllRuleSets except it uses
520
+ * CSSList->allUniqueRuleSets. This will generate an associative
521
+ * array of rule sets with the selector as the key.
522
+ *
523
+ * @return array
524
+ */
525
+ public function getAllUniqueRuleSets (){
526
+ $ aResult = array ();
527
+ $ this ->allUniqueRuleSets ($ aResult );
528
+ return $ aResult ;
529
+ }
530
+
531
+ /**
532
+ * Gets just the style, not the entire rule set of the given
533
+ * selector
534
+ * @param string $sSelector
535
+ * @return string
536
+ */
537
+ public function getStyle ($ sSelector ="" ){
538
+ $ sResult = "" ;
539
+ if ($ sSelector ){
540
+ $ aRuleSets = $ this ->getAllUniqueRuleSets ();
541
+ $ aSelectors = explode (", " , $ sSelector );
542
+ foreach ($ aSelectors as $ sSelector ){
543
+ $ sSelector = trim ($ sSelector );
544
+ if (isset ($ aRuleSets [$ sSelector ])){
545
+ $ oRuleSet = $ aRuleSets [$ sSelector ];
546
+ $ aRules = $ oRuleSet ->getRules ();
547
+ foreach ($ aRules as $ oRule ){
548
+ $ sResult .= $ oRule ->__toString ()." " ;
549
+ }
550
+ }
551
+ }
552
+ }
553
+ return $ sResult ;
554
+ }
495
555
}
496
556
497
557
class CSSMediaQuery extends CSSList {
@@ -704,11 +764,24 @@ public function getIsImportant() {
704
764
public function __toString () {
705
765
$ sResult = "{$ this ->sRule }: " ;
706
766
foreach ($ this ->aValues as $ aValues ) {
707
- $ sResult .= implode (', ' , $ aValues ).' ' ;
767
+ //Rewrote to account for CSSSize and CSSColor- dschaefer 12/22/2010
768
+ reset ($ aValues );
769
+ while ($ mValue = current ($ aValues )){
770
+ if (gettype ($ mValue ) != 'object ' && gettype ($ mValue ) != 'array ' ){
771
+ $ sResult .= $ mValue ." " ;
772
+ }else if (gettype ($ mValue ) == 'object ' ){
773
+ $ sResult .= $ mValue ->__toString ()." " ;
774
+ }
775
+ if (next ($ aValues )){
776
+ $ sResult .= ', ' ;
777
+ }
778
+ }
779
+ //$sResult .= implode(', ', $aValues).' ';
708
780
}
709
781
if ($ this ->bIsImportant ) {
710
782
$ sResult .= '!important ' ;
711
783
} else {
784
+ //What does this accomplish? Should this remove any semi-colons instead of removing the last character?
712
785
$ sResult = substr ($ sResult , 0 , -1 );
713
786
}
714
787
$ sResult .= '; ' ;
@@ -780,7 +853,22 @@ public function getColorDescription() {
780
853
}
781
854
782
855
public function __toString () {
783
- return $ this ->getColorDescription ().'( ' .implode (', ' , $ this ->aColor ).') ' ;
856
+ //Rewrote to account for CSSSize - dschaefer 12/22/2010
857
+ $ sResult = $ this ->getColorDescription ().'( ' ;
858
+ reset ($ this ->aColor );
859
+ while ($ mColor = current ($ this ->aColor )){
860
+ if (gettype ($ mColor ) != "object " ){
861
+ $ sResult .= $ mColor ;
862
+ }else {
863
+ $ sResult .= $ mColor ->__toString ();
864
+ }
865
+ if (next ($ this ->aColor )){
866
+ $ sResult .= ', ' ;
867
+ }
868
+ }
869
+ $ sResult .= ') ' ;
870
+ return $ sResult ;
871
+ //return $this->getColorDescription().'('.implode(', ', $this->aColor).')';
784
872
}
785
873
}
786
874
0 commit comments