Переглянути джерело

replace markers refactoring

Alex Trofimov 13 роки тому
батько
коміт
4a1993ea06

+ 1 - 12
inc/classes/BxDolCmts.php

@@ -877,18 +877,7 @@ class BxDolCmts extends BxDol
      * @return string where all occured markers are replaced
      */ 
     protected function _replaceMarkers ($mixed) {
-        if (empty($this->_aMarkers))
-            return $mixed;
-
-        if (is_array($mixed)) {
-            foreach ($mixed as $sKey => $sValue)
-                $mixed[$sKey] = $this->_replaceMarkers ($sValue);
-        } else {
-            foreach ($this->_aMarkers as $sKey => $sValue)
-                $mixed = str_replace('{' . $sKey . '}', $sValue, $mixed);
-        }
-
-        return $mixed;
+        return bx_replace_markers($mixed, $this->_aMarkers);
     }
 
     protected function _getUserChoice()

+ 1 - 5
inc/classes/BxDolEditor.php

@@ -147,11 +147,7 @@ class BxDolEditor extends BxDol implements iBxDolFactoryObject {
     protected function _replaceMarkers ($s, $a) {
         if (empty($s) || empty($a) || !is_array($a))
             return $s;
-
-        foreach ($a as $sKey => $sValue)
-            $s = str_replace('{' . $sKey . '}', $sValue, $s);
-
-        return $s;
+        return bx_replace_markers($s, $a);
     }
 
 }

+ 2 - 4
inc/classes/BxDolMenu.php

@@ -215,10 +215,8 @@ class BxDolMenu extends BxDol implements iBxDolFactoryObject {
             return $a;
         $aReplacebleFields = array ('title', 'link', 'onclick');
         foreach ($aReplacebleFields as $sField)
-        	if(isset($a[$sField]))
-            	foreach ($this->_aMarkers as $sKey => $sValue)
-                	$a[$sField] = str_replace('{' . $sKey . '}', $sValue, $a[$sField]);
-
+        	if (isset($a[$sField]))
+                $a[$sField] = bx_replace_markers($a[$sField], $this->_aMarkers);
         return $a;
     }
 

+ 1 - 12
inc/classes/BxDolPage.php

@@ -194,18 +194,7 @@ class BxDolPage extends BxDol implements iBxDolFactoryObject {
      * @return string where all occured markers are replaced
      */ 
     protected function _replaceMarkers ($mixed) {
-        if (empty($this->_aMarkers))
-            return $mixed;
-
-        if (is_array($mixed)) {
-            foreach ($mixed as $sKey => $sValue)
-                $mixed[$sKey] = $this->_replaceMarkers ($sValue);
-        } else {
-            foreach ($this->_aMarkers as $sKey => $sValue)
-                $mixed = str_replace('{' . $sKey . '}', $sValue, $mixed);
-        }
-
-        return $mixed;
+        return bx_replace_markers($mixed, $this->_aMarkers);
     }
 
     /**

+ 1 - 12
inc/classes/BxDolProfileForms.php

@@ -36,18 +36,7 @@ class BxDolProfileForms extends BxDol {
      * @return string where all markers are replaced
      */ 
     protected function _replaceMarkers ($mixed, $aMarkers) {
-        if (empty($aMarkers))
-            return $mixed;
-
-        if (is_array($mixed)) {
-            foreach ($mixed as $sKey => $sValue)
-                $mixed[$sKey] = $this->_replaceMarkers ($sValue);
-        } else {
-            foreach ($aMarkers as $sKey => $sValue)
-                $mixed = str_replace('{' . $sKey . '}', $sValue, $mixed);
-        }
-
-        return $mixed;
+        return bx_replace_markers($mixed, $aMarkers);
     }
 
 }

+ 1 - 12
inc/classes/BxDolSearch.php

@@ -745,18 +745,7 @@ class BxDolSearchResult {
      * @return string where all occured markers are replaced
      */ 
     protected function _replaceMarkers ($mixed) {
-        if (empty($this->_aMarkers))
-            return $mixed;
-
-        if (is_array($mixed)) {
-            foreach ($mixed as $sKey => $sValue)
-                $mixed[$sKey] = $this->_replaceMarkers ($sValue);
-        } else {
-            foreach ($this->_aMarkers as $sKey => $sValue)
-                $mixed = str_replace('{' . $sKey . '}', $sValue, $mixed);
-        }
-
-        return $mixed;
+        return bx_replace_markers($mixed, $this->_aMarkers);
     }
 }
 

+ 1 - 11
inc/classes/BxDolSocialSharing.php

@@ -82,17 +82,7 @@ class BxDolSocialSharing extends BxDol implements iBxDolSingleton
     protected function _replaceMarkers ($mixed, $aMarkers) {
         if (empty($mixed) || empty($aMarkers) || !is_array($aMarkers))
             return $s;
-
-
-        if (is_array($mixed)) {
-            foreach ($mixed as $sKey => $sValue)
-                $mixed[$sKey] = $this->_replaceMarkers ($sValue, $aMarkers);
-        } else {
-            foreach ($aMarkers as $sKey => $sValue)
-                $mixed = str_replace('{' . $sKey . '}', $sValue, $mixed);
-        }
-        
-        return $mixed;
+        return bx_replace_markers($mixed, $aMarkers);
     }
 
     /**

+ 14 - 0
inc/utils.inc.php

@@ -1437,6 +1437,20 @@ function getSitesArray ($sLink) {
     return $aSites;
 }
 
+function bx_replace_markers($mixed, $aMarkers) {
+    if (empty($aMarkers))
+        return $mixed;
+
+    if (is_array($mixed)) {
+        foreach ($mixed as $sKey => $sValue)
+            $mixed[$sKey] = bx_replace_markers ($sValue, $aMarkers);
+    } else {
+        foreach ($aMarkers as $sKey => $sValue)
+            $mixed = str_replace('{' . $sKey . '}', $sValue, $mixed);
+    }
+
+    return $mixed;
+}
 
 /** @} */