Sfoglia il codice sorgente

- iBxDolReplaceable interafce
- make use of bx_gen_method_name function

Alex Trofimov 12 anni fa
parent
commit
7d1c6bfaec

+ 1 - 1
grid.php

@@ -23,7 +23,7 @@ if (!$oGrid) {
     exit;
 }
 
-$sAction = 'performAction' . str_replace(' ', '', ucwords(str_replace('_' , ' ', bx_process_input(bx_get('a')))));
+$sAction = 'performAction' . bx_gen_method_name(bx_process_input(bx_get('a')));
 if (method_exists($oGrid, $sAction)) {
     $oGrid->$sAction();
 } 

+ 7 - 0
inc/classes/BxDol.php

@@ -37,6 +37,13 @@ interface iBxDolFactoryObject {
     static public function getObjectInstance($sObject);
 }
 
+/**
+ * Replacable interface, class has an ability to replace markers somewhere
+ */
+interface iBxDolReplaceable {
+    public function addMarkers ($a);
+}
+
 /**
  * Profile interface, class must implement basic profile methods to be compliant with Profile interface
  */

+ 1 - 1
inc/classes/BxDolCmts.php

@@ -129,7 +129,7 @@ define('BX_CMT_RATE_VALUE_MINUS', -1);
  *      - $aExtra['rate'] - comment rate 1 or -1
  *
  */
-class BxDolCmts extends BxDol
+class BxDolCmts extends BxDol implements iBxDolReplaceable
 {
 	protected $_oQuery = null;
 

+ 1 - 1
inc/classes/BxDolConfig.php

@@ -110,7 +110,7 @@ class BxDolConfig extends BxDol implements iBxDolSingleton {
     }
 
     private function getVarName($sVar) {
-        return 'a' . str_replace(' ', '', ucwords(str_replace('_', ' ', $sVar)));
+        return 'a' . bx_gen_method_name($sVar);
     }
 
     private function getDefineName() {

+ 2 - 1
inc/classes/BxDolForm.php

@@ -716,7 +716,8 @@ define('BX_DATA_VALUES_ADDITIONAL', 'LKey2'); ///< Use additional values for dat
  * @endcode
  *
  */
-class BxDolForm extends BxDol {
+class BxDolForm extends BxDol implements iBxDolReplaceable
+{
 
     static $TYPES_CHECKBOX = array('checkbox' => 1, 'switcher' => 1);
     static $TYPES_TEXT = array('text' => 1, 'textarea' => 1);

+ 1 - 1
inc/classes/BxDolGrid.php

@@ -507,7 +507,7 @@ class BxDolGrid extends BxDol implements iBxDolFactoryObject {
     }
 
     protected function _genMethodName ($s) {
-        return str_replace(' ', '', ucwords(str_replace('_' , ' ', $s)));
+        return bx_gen_method_name($s);
     }
 
     protected function _isVisibleGrid ($a) {

+ 2 - 2
inc/classes/BxDolMenu.php

@@ -85,8 +85,8 @@ bx_import('BxDolPermalinks');
  * menu objects are integrated into pages - there is special 'menu' page block type for it.
  * 
  */
-class BxDolMenu extends BxDol implements iBxDolFactoryObject {
-
+class BxDolMenu extends BxDol implements iBxDolFactoryObject, iBxDolReplaceable
+{
     protected static $SEL_MODULE = '';
     protected static $SEL_NAME = '';
 

+ 1 - 1
inc/classes/BxDolPage.php

@@ -118,7 +118,7 @@ bx_import('BxDolPageQuery');
  * @endcode
  *
  */
-class BxDolPage extends BxDol implements iBxDolFactoryObject {
+class BxDolPage extends BxDol implements iBxDolFactoryObject, iBxDolReplaceable {
 
     protected $_sObject;
     protected $_aObject;

+ 1 - 1
inc/classes/BxDolPrivacy.php

@@ -281,7 +281,7 @@ class BxDolPrivacy extends BxDol implements iBxDolFactoryObject
     	if(substr($s, 0, 1) != '@')
     		return false;
 
-		return str_replace(' ', '', ucwords(str_replace('_', ' ', str_replace('@', 'check_', $s))));
+		return bx_gen_method_name(str_replace('@', 'check_', $s));
     }
 
     /**

+ 4 - 5
inc/classes/BxDolRequest.php

@@ -29,8 +29,8 @@ class BxDolRequest extends BxDol {
         }
     }
     public static function processAsAction($aModule, &$aRequest, $sClass = "Module") {
-        $sAction = empty($aRequest) || (isset($aRequest[0]) && empty($aRequest[0])) ? 'Home' : array_shift($aRequest);
-        $sMethod = 'action' . str_replace(' ', '', ucwords(str_replace('_', ' ', $sAction)));
+        $sAction = empty($aRequest) || (isset($aRequest[0]) && empty($aRequest[0])) ? 'Home' : array_shift($aRequest);                              
+        $sMethod = 'action' . bx_gen_method_name($sAction);
 
         if(isset($GLOBALS['bx_profiler']))
             $GLOBALS['bx_profiler']->beginModule('action', ($sPrHash = uniqid(rand())), $aModule, $sClass, $sMethod);
@@ -45,8 +45,7 @@ class BxDolRequest extends BxDol {
     public static function processAsService($aModule, $sMethod, $aParams, $sClass = "Module") {
         if (isset($aModule['name']) && 'system' == $aModule['name'] && 'Module' == $sClass) 
             $sClass = 'BaseServices';
-
-        $sMethod = 'service' . str_replace(' ', '', ucwords(str_replace('_', ' ', $sMethod)));
+        $sMethod = 'service' . bx_gen_method_name($sMethod);
 
         if(isset($GLOBALS['bx_profiler']))
             $GLOBALS['bx_profiler']->beginModule('service', ($sPrHash = uniqid(rand())), $aModule, $sClass, $sMethod);
@@ -125,7 +124,7 @@ class BxDolRequest extends BxDol {
         if(($oModule = BxDolRequest::_require($aModule, $sClass)) === false)
             return false;
 
-        $sMethod = $sMethodType . str_replace(' ', '', ucwords(str_replace('_', ' ', $sMethodName)));
+        $sMethod = $sMethodType . bx_gen_method_name($sMethodName);
         return method_exists($oModule, $sMethod);
     }
     protected static function _error($sType, $sParam1 = '', $sParam2 = '') {

+ 2 - 1
inc/classes/BxDolSearch.php

@@ -204,7 +204,8 @@ class BxDolSearch extends BxDol {
  *
  */
 
-class BxDolSearchResult {
+class BxDolSearchResult implements iBxDolReplaceable
+{
     var $aCurrent;
     var $aPseud;
     var $id;

+ 2 - 2
inc/utils.inc.php

@@ -1033,8 +1033,8 @@ function bx_site_hash($sSalt = '', $isSkipVersion = false) {
  * @param string where words are separated with underscore
  * @return string where every word begins with capital letter
  */
-function bx_gen_method_name ($s) {
-    return str_replace(' ', '', ucwords(str_replace('_' , ' ', $s)));
+function bx_gen_method_name ($s, $sWordsDelimiter = '_') {
+    return str_replace(' ', '', ucwords(str_replace($sWordsDelimiter, ' ', $s)));
 }
 
 /** @} */ 

+ 1 - 1
install/classes/BxDolInstallController.php

@@ -19,7 +19,7 @@ class BxDolInstallController
 
     function run ($sAction = '') 
     {
-        $sMethod = 'action' . str_replace(' ', '', ucwords(str_replace('_', ' ', $sAction)));
+        $sMethod = 'action' . bx_gen_method_name($sAction);
         if ($sAction && method_exists($this, $sMethod))
             $this->$sMethod ();
         else

+ 1 - 1
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -827,7 +827,7 @@ class BxTimelineTemplate extends BxDolModuleTemplate
 		$mixedResult = array();
         $aHandler = $this->_oConfig->getHandlers($sHandler);
         if(empty($aHandler['module_uri']) && empty($aHandler['module_class']) && empty($aHandler['module_method'])) {
-            $sMethod = 'display' . str_replace(' ', '', ucwords(str_replace('_', ' ', $aHandler['alert_unit'] . '_' . $aHandler['alert_action'])));
+            $sMethod = 'display' . bx_gen_method_name($aHandler['alert_unit'] . '_' . $aHandler['alert_action']);
             if(!method_exists($this, $sMethod))
                 return '';
 

+ 2 - 2
studio/classes/BxDolStudioForms.php

@@ -63,7 +63,7 @@ class BxDolStudioForms extends BxTemplStudioPage {
     }
 
     protected function getClassName($sValue) {
-        return str_replace(' ', '', ucwords(str_replace('_', ' ', $sValue)));
+        return bx_gen_method_name($sValue);
     }
 }
-/** @} */
+/** @} */

+ 1 - 1
studio/classes/BxDolStudioInstaller.php

@@ -451,7 +451,7 @@ class BxDolStudioInstaller extends BxDolInstallerUtils {
 
         $sMessage = '';
         foreach($this->_aConfig[$sOperationName] as $sAction => $iEnabled) {
-            $sMethod = 'action' . str_replace (' ', '', ucwords(str_replace ('_', ' ', $sAction)));
+            $sMethod = 'action' . bx_gen_method_name($sAction);
             if($iEnabled == 0 || !method_exists($this, $sMethod))
                 continue;
 

+ 2 - 2
studio/classes/BxDolStudioUtils.php

@@ -26,7 +26,7 @@ class BxDolStudioUtils extends BxDol {
     }
 
     public static function getClassName($sValue) {
-        return str_replace(' ', '', ucwords(str_replace('_', ' ', $sValue)));
+        return bx_gen_method_name($sValue);
     }
 
     public static function getModuleIcon($sName, $sType = 'menu') {
@@ -155,4 +155,4 @@ class BxDolStudioUtils extends BxDol {
         return $aOutput;
     }
 }
-/** @} */
+/** @} */

+ 1 - 1
template/scripts/BxBaseCmts.php

@@ -22,7 +22,7 @@ class BxBaseCmts extends BxDolCmts {
         if(empty($sSystem))
             return;
 
-        $this->_sJsObjName = 'oCmts' . str_replace(' ', '', ucwords(str_replace(array('_' , '-'), array(' ', ' '), $sSystem))) . $iId;
+        $this->_sJsObjName = 'oCmts' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
         $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
 
         BxDolTemplate::getInstance()->addJsTranslation('_sys_txt_cmt_loading');

+ 1 - 1
template/scripts/BxBaseVote.php

@@ -30,7 +30,7 @@ class BxBaseVote extends BxDolVote
     {
         parent::__construct($sSystem, $iId, $iInit);
 
-		$this->_sJsObjName = 'oVote' . str_replace(' ', '', ucwords(str_replace(array('_' , '-'), array(' ', ' '), $sSystem))) . $iId;
+		$this->_sJsObjName = 'oVote' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
         $this->_sStylePrefix = 'bx-vote';
 
         $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;