Просмотр исходного кода

#50 - Get rid of usage of eval PHP function (Settings -> Check)

AntonLV 12 лет назад
Родитель
Сommit
8f099409f2

+ 5 - 4
install/sql/system.sql

@@ -165,7 +165,8 @@ CREATE TABLE `sys_options` (
   `value` mediumtext NOT NULL,
   `type` enum('digit','text','checkbox','select','combobox','file','list') NOT NULL default 'digit',
   `extra` text NOT NULL default '',
-  `check` text NOT NULL,
+  `check` varchar(32) NOT NULL,
+  `check_params` text NOT NULL,
   `check_error` varchar(255) NOT NULL default '',
   `order` int(11) default '0',
   PRIMARY KEY (`id`),
@@ -260,7 +261,7 @@ INSERT INTO `sys_options_categories`(`type_id`, `name`, `caption`, `hidden`, `or
 SET @iCategoryId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
-(@iCategoryId, 'template', '_adm_stg_cpt_option_template', '', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:13:"get_templates";s:5:"class";s:21:"TemplTemplateServices";}', 'bx_import(\'BxDolModuleQuery\'); return (strlen($arg0) > 0 && BxDolModuleQuery::getInstance()->isEnabled($arg0)) ? true : false;', 'Template cannot be empty and must have a valid name.', 1),
+(@iCategoryId, 'template', '_adm_stg_cpt_option_template', '', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:13:"get_templates";s:5:"class";s:21:"TemplTemplateServices";}', 'Template', '_adm_stg_err_option_template', 1),
 (@iCategoryId, 'enable_template', '_adm_stg_cpt_option_enable_template', 'on', 'checkbox', '', '', '', 2),
 
 (@iCategoryId, 'sys_template_page_width_min', '_adm_stg_cpt_option_sys_template_page_width_min', '774', 'digit', '', '', '', 3),
@@ -309,8 +310,8 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_oauth_secret', '_adm_stg_cpt_option_sys_oauth_secret', '', 'digit', '', '', '', 5),
 (@iCategoryId, 'boonexAffID', '_adm_stg_cpt_option_boonex_aff_id', '', 'digit', '', '', '', 6),
 
-(@iCategoryId, 'currency_code', '_adm_stg_cpt_option_currency_code', 'USD', 'select', 'USD,EURO', 'return strlen($arg0) > 0;', 'Cannot be empty.', 7),
-(@iCategoryId, 'currency_sign', '_adm_stg_cpt_option_currency_sign', '$', 'digit', '', 'return strlen($arg0) > 0;', 'Cannot be empty.', 8),
+(@iCategoryId, 'currency_code', '_adm_stg_cpt_option_currency_code', 'USD', 'select', 'USD,EURO', 'Avail', '_adm_stg_err_option_currency_code', 7),
+(@iCategoryId, 'currency_sign', '_adm_stg_cpt_option_currency_sign', '$', 'digit', '', 'Avail', '_adm_stg_err_option_currency_sign', 8),
 
 (@iCategoryId, 'enable_gd', '_adm_stg_cpt_option_enable_gd', 'on', 'checkbox', '', '', '', 9),
 (@iCategoryId, 'useLikeOperator', '_adm_stg_cpt_option_use_like_operator', 'on', 'checkbox', '', '', '', 10);

+ 4 - 0
modules/boonex/english/data/langs/system.xml

@@ -1087,7 +1087,9 @@
 	<string name="_adm_stg_cpt_category_templates"><![CDATA[Templates]]></string>
 	<string name="_adm_stg_cpt_option_boonex_aff_id"><![CDATA[My BoonEx Affiliate ID]]></string>
 	<string name="_adm_stg_cpt_option_currency_code"><![CDATA[Currency code (for checkout system)]]></string>
+	<string name="_adm_stg_err_option_currency_code"><![CDATA[Cannot be empty.]]></string>
 	<string name="_adm_stg_cpt_option_currency_sign"><![CDATA[Currency sign (for display purposes only)]]></string>
+	<string name="_adm_stg_err_option_currency_sign"><![CDATA[Cannot be empty.]]></string>
 	<string name="_adm_stg_cpt_option_enable_gd"><![CDATA[Use GD library for image processing]]></string>
 	<string name="_adm_stg_cpt_option_enable_template"><![CDATA[Show Template Switcher]]></string>
 	<string name="_adm_stg_cpt_option_expire_notification_days"><![CDATA[Number of days before membership expiration to notify members ( -1 = after expiration )]]></string>
@@ -1137,9 +1139,11 @@
 	<string name="_adm_stg_cpt_option_sys_template_page_width_max"><![CDATA[Max page width(in pixels)]]></string>
 	<string name="_adm_stg_cpt_option_sys_template_page_width_min"><![CDATA[Min page width(in pixels)]]></string>
 	<string name="_adm_stg_cpt_option_template"><![CDATA[Default Template]]></string>
+	<string name="_adm_stg_err_option_template"><![CDATA[Template cannot be empty and must have a valid name.]]></string>
 	<string name="_adm_stg_cpt_option_use_like_operator"><![CDATA[Use operator LIKE for search (recommended for small content)]]></string>
 	<string name="_adm_stg_cpt_type_system"><![CDATA[System]]></string>
 	<string name="_adm_stg_scs_save"><![CDATA[Settings were successfully saved]]></string>
+	<string name="_adm_stg_err_save_error_message"><![CDATA[Error in '{0}': {1}]]></string>
 	<string name="_adm_str_cpt_files_file"><![CDATA[File]]></string>
 	<string name="_adm_str_cpt_files_version"><![CDATA[Version]]></string>
 	<string name="_adm_str_err_cannot_connect_to_ftp"><![CDATA[Cannot connect to FTP server. Please check FTP access details in Settings -> Other.]]></string>

+ 4 - 0
modules/boonex/russian/data/langs/system.xml

@@ -1526,6 +1526,7 @@ Please click "Continue" below to navigate to the home page of the site.]]></stri
 	<!-- Settings: Templates -->
 	<string name="_adm_stg_cpt_category_templates"><![CDATA[Templates]]></string>
 	<string name="_adm_stg_cpt_option_template"><![CDATA[Default Template]]></string>
+	<string name="_adm_stg_err_option_template"><![CDATA[Template cannot be empty and must have a valid name.]]></string>
 	<string name="_adm_stg_cpt_option_enable_template"><![CDATA[Show Template Switcher]]></string>
 	<string name="_adm_stg_cpt_option_sys_template_page_width_min"><![CDATA[Min page width(in pixels)]]></string>
 	<string name="_adm_stg_cpt_option_sys_template_page_width_max"><![CDATA[Max page width(in pixels)]]></string>
@@ -1556,7 +1557,9 @@ Please click "Continue" below to navigate to the home page of the site.]]></stri
 	<string name="_adm_stg_cpt_option_sys_oauth_secret"><![CDATA[BoonEx account secret]]></string>
 	<string name="_adm_stg_cpt_option_boonex_aff_id"><![CDATA[My BoonEx Affiliate ID]]></string>
 	<string name="_adm_stg_cpt_option_currency_code"><![CDATA[Currency code (for checkout system)]]></string>
+	<string name="_adm_stg_err_option_currency_code"><![CDATA[Cannot be empty.]]></string>
 	<string name="_adm_stg_cpt_option_currency_sign"><![CDATA[Currency sign (for display purposes only)]]></string>
+	<string name="_adm_stg_err_option_currency_sign"><![CDATA[Cannot be empty.]]></string>
 	<string name="_adm_stg_cpt_option_enable_gd"><![CDATA[Use GD library for image processing]]></string>
 	<string name="_adm_stg_cpt_option_use_like_operator"><![CDATA[Use operator LIKE for search (recommended for small content)]]></string>
 	<string name="_adm_stg_cpt_option_"><![CDATA[]]></string>
@@ -1613,6 +1616,7 @@ Please click "Continue" below to navigate to the home page of the site.]]></stri
 
 	<string name="_adm_stg_err_save"><![CDATA[Cannot save settings]]></string>
 	<string name="_adm_stg_scs_save"><![CDATA[Settings were successfully saved]]></string>
+	<string name="_adm_stg_err_save_error_message"><![CDATA[Error in '{0}': {1}]]></string>
 
 	<!-- Store -->
 	<string name="_adm_page_cpt_store"><![CDATA[Store]]></string>

+ 22 - 0
modules/boonex/timeline/classes/BxTimelineFormCheckerHelper.php

@@ -0,0 +1,22 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ * 
+ * @defgroup    Timeline Timeline
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+bx_import('BxDolStudioForm');
+
+class BxTimelineFormCheckerHelper extends BxDolStudioFormCheckerHelper
+{
+	function checkGreaterThen($sVal, $iLimit)
+    {
+    	return (int)$sVal > (int)$iLimit;
+    }
+}
+
+/** @} */ 

+ 6 - 0
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -469,6 +469,12 @@ class BxTimelineModule extends BxDolModule
 		return $this->serviceGetShareCounter($sType, $sAction, $iObjectId);
     }
 
+    public function serviceGetSettingsCheckerHelper()
+    {
+    	bx_import('FormCheckerHelper', $this->_aModule);
+    	return 'BxTimelineFormCheckerHelper';
+    }
+
     /*
      * COMMON METHODS 
      */

+ 1 - 0
modules/boonex/timeline/install/langs/en.xml

@@ -9,6 +9,7 @@
 	<string name="_bx_timeline_option_rss_length"><![CDATA[The length of RSS feed]]></string>
 	<string name="_bx_timeline_option_events_hide"><![CDATA[Hide events from Timeline]]></string>
 	<string name="_bx_timeline_option_chars_display_max"><![CDATA[Max number of displayed character in text post]]></string>
+	<string name="_bx_timeline_option_err_chars_display_max"><![CDATA[Enter the number which should be greater then 150.]]></string>
 
 	<string name="_bx_timeline_form_post"><![CDATA[Post]]></string>
 	<string name="_bx_timeline_form_post_display_add"><![CDATA[Write Post]]></string>

+ 7 - 7
modules/boonex/timeline/install/sql/enable.sql

@@ -56,13 +56,13 @@ INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)
 VALUES (@iTypeId, 'bx_timeline', '_bx_timeline', 1);
 SET @iCategId = LAST_INSERT_ID();
 
-INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_error`, `extra`, `order`) VALUES
-('bx_timeline_enable_delete', 'on', @iCategId, '_bx_timeline_option_enable_delete', 'checkbox', '', '', '', 1),
-('bx_timeline_events_per_page_profile', '10', @iCategId, '_bx_timeline_option_events_per_page_profile', 'digit', '', '', '', 2),
-('bx_timeline_events_per_page_account', '20', @iCategId, '_bx_timeline_option_events_per_page_account', 'digit', '', '', '', 3),
-('bx_timeline_rss_length', '5', @iCategId, '_bx_timeline_option_rss_length', 'digit', '', '', '', 4),
-('bx_timeline_events_hide', '', @iCategId, '_bx_timeline_option_events_hide', 'list', '', '', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:21:"get_actions_checklist";}', 5),
-('bx_timeline_chars_display_max', '300', @iCategId, '_bx_timeline_option_chars_display_max', 'digit', '', '', '', 6);
+INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_params`, `check_error`, `extra`, `order`) VALUES
+('bx_timeline_enable_delete', 'on', @iCategId, '_bx_timeline_option_enable_delete', 'checkbox', '', '', '', '', 1),
+('bx_timeline_events_per_page_profile', '10', @iCategId, '_bx_timeline_option_events_per_page_profile', 'digit', '', '', '', '', 2),
+('bx_timeline_events_per_page_account', '20', @iCategId, '_bx_timeline_option_events_per_page_account', 'digit', '', '', '', '', 3),
+('bx_timeline_rss_length', '5', @iCategId, '_bx_timeline_option_rss_length', 'digit', '', '', '', '', 4),
+('bx_timeline_events_hide', '', @iCategId, '_bx_timeline_option_events_hide', 'list', '', '', '', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:21:"get_actions_checklist";}', 5),
+('bx_timeline_chars_display_max', '300', @iCategId, '_bx_timeline_option_chars_display_max', 'digit', 'GreaterThen', 'a:1:{s:3:"min";i:150;}', '_bx_timeline_option_err_chars_display_max', '', 6);
 
 
 -- UPLOADERS

+ 8 - 2
studio/classes/BxDolStudioForm.php

@@ -17,7 +17,7 @@ class BxDolStudioForm extends BxBaseFormView {
     function BxDolStudioForm($aInfo, $oTemplate) {
         parent::BxBaseFormView($aInfo, $oTemplate !== false ? $oTemplate : BxDolStudioTemplate::getInstance());
 
-        $this->_sCheckerHelper = isset($this->aParams['checker_helper']) ? $this->aParams['checker_helper'] : 'BxDolStudioCheckerHelper';
+        $this->_sCheckerHelper = isset($this->aParams['checker_helper']) ? $this->aParams['checker_helper'] : 'BxDolStudioFormCheckerHelper';
     }
 
     function initChecker($aValues = array (), $aSpecificValues = array())  {
@@ -139,7 +139,7 @@ class BxDolStudioForm extends BxBaseFormView {
     }
 }
 
-class BxDolStudioCheckerHelper extends BxDolFormCheckerHelper {
+class BxDolStudioFormCheckerHelper extends BxDolFormCheckerHelper {
     function checkAvailTranslatable($sVal, $aName, $sMethod = BX_DOL_STUDIO_METHOD_DEFAULT, $bAll = true) {
         if(empty($sMethod) || empty($aName))
             return false;
@@ -179,5 +179,11 @@ class BxDolStudioCheckerHelper extends BxDolFormCheckerHelper {
 
         return $bAll ? true : false;
     }
+
+    function checkTemplate($sVal)
+    {
+    	bx_import('BxDolModuleQuery'); 
+    	return strlen($sVal) > 0 && BxDolModuleQuery::getInstance()->isEnabled($sVal);
+    }
 }
 /** @} */

+ 18 - 4
studio/classes/BxDolStudioSettings.php

@@ -67,17 +67,31 @@ class BxDolStudioSettings extends BxTemplStudioPage {
 
         foreach ($aCategories as $sCategory) {
             $aOptions = array();
-            $iOptions = $this->oDb->getOptions(array('type' => 'by_category_name', 'value' => $sCategory), $aOptions);
+            $iOptions = $this->oDb->getOptions(array('type' => 'by_category_name_full', 'value' => $sCategory), $aOptions);
 
             $aData = array();
             foreach($aOptions as $aOption) {
                 $aData[$aOption['name']] = $oForm->getCleanValue($aOption['name']);
 
                 if(!empty($aOption['check'])) {
-                    $oFunction = create_function('$arg0', $aOption['check']);
-                    if(!$oFunction($aData[$aOption['name']])) {
+                	$sCheckerHelper = '';
+                	if(!empty($aOption['type_name']) && BxDolRequest::serviceExists($aOption['type_name'], 'get_settings_checker_helper'))
+                		$sCheckerHelper = BxDolService::call($aOption['type_name'], 'get_settings_checker_helper');
+
+                	if($sCheckerHelper == '') {
+                		bx_import('BxDolStudioForm');
+                		$sCheckerHelper = 'BxDolStudioFormCheckerHelper';
+                	}
+
+                	$oChecker = new $sCheckerHelper();
+                	$aCheckFunction = array($oChecker, 'check' . bx_gen_method_name($aOption['check']));
+                	$aCheckFunctionParams = array($aData[$aOption['name']]);
+                	if(!empty($aOption['check_params']))
+                		$aCheckFunctionParams = array_merge($aCheckFunctionParams, unserialize($aOption['check_params']));
+
+                	if(is_callable($aCheckFunction) && !call_user_func_array($aCheckFunction, $aCheckFunctionParams)) {
                         $this->sCategory = $sCategory;
-                        return $this->getJsResult("'" . $aOption['title'] .  "' " . $aOption['check_error'], false);
+                        return $this->getJsResult(_t('_adm_stg_err_save_error_message', _t($aOption['caption']), _t($aOption['check_error'])), false);
                     }
                 }
 

+ 7 - 1
studio/classes/BxDolStudioSettingsQuery.php

@@ -126,6 +126,11 @@ class BxDolStudioSettingsQuery extends BxDolStudioPageQuery {
             case 'by_category_name':
                 $sJoinClause .= "LEFT JOIN `sys_options_categories` AS `tc` ON `to`.`category_id`=`tc`.`id` ";
                 $sWhereClause .= $this->prepare("AND `tc`.`name`=?", $aParams['value']);
+                break;
+			case 'by_category_name_full':
+				$sSelectClause .= ", `tc`.`name` AS `category_name`, `tt`.`name` AS `type_name`";
+				$sJoinClause .= "LEFT JOIN `sys_options_categories` AS `tc` ON `to`.`category_id`=`tc`.`id` LEFT JOIN `sys_options_types` AS `tt` ON `tc`.`type_id`=`tt`.`id` ";
+                $sWhereClause .= $this->prepare("AND `tc`.`name`=?", $aParams['value']);
                 break;
         }
 
@@ -138,8 +143,9 @@ class BxDolStudioSettingsQuery extends BxDolStudioPageQuery {
                 `to`.`type` AS `type`,
                 `to`.`extra` AS `extra`,
                 `to`.`check` AS `check`,
+                `to`.`check_params` AS `check_params`,
                 `to`.`check_error` AS `check_error`,
-                `to`.`order` AS `order` " . $sSelectClause . "
+                `to`.`order` AS `order`" . $sSelectClause . "
             FROM `sys_options` AS `to` " . $sJoinClause . "
             WHERE 1 " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause;
         $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);