Skip to content

Commit

Permalink
Ticket unacms#2745
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed May 6, 2020
1 parent 5b3d151 commit 7bd6e6d
Show file tree
Hide file tree
Showing 15 changed files with 565 additions and 11 deletions.
29 changes: 29 additions & 0 deletions form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaCore UNA Core
* @{
*/

require_once('./inc/header.inc.php');
require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
require_once(BX_DIRECTORY_PATH_INC . "utils.inc.php");

bx_import('BxDolLanguages');

$sObject = bx_process_input(bx_get('o'));
$sDisplay = bx_process_input(bx_get('d'));
$sAction = bx_process_input(bx_get('a'));
if(!empty($sAction))
$sAction = 'performAction' . bx_gen_method_name($sAction);

// try to create form object and call its method
if(!empty($sObject) && !empty($sDisplay) && !empty($sAction)) {
$oForm = BxTemplFormView::getObjectInstance($sObject, $sDisplay);
if($oForm && method_exists($oForm, $sAction))
$oForm->$sAction();
}

/** @} */
57 changes: 57 additions & 0 deletions inc/classes/BxDolForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,12 @@ class BxDolForm extends BxDol implements iBxDolReplaceable

protected $_aFieldsCheckForSpam = array(); ///< additional fields names to check for spam(profanity filter), now only fields with 'textarea' and 'text' are checked for spam, 'textarea' fields are checked for spam and filter for profanity, while 'text' fields are filtetered for profanity only


protected $_iAuthorId;
protected $_sAuthorKey; ///< array key to get author ID from Values array provided in BxDolForm::initChecker.
protected $_sPrivacyObjectView;
protected $_sPrivacyGroupDefault;

public function __construct ($aInfo, $oTemplate)
{
parent::__construct();
Expand All @@ -758,6 +764,10 @@ public function __construct ($aInfo, $oTemplate)

$this->_sChecker = isset($this->aParams['checker']) ? $this->aParams['checker'] : 'BxDolFormChecker';
$this->_sCheckerHelper = isset($this->aParams['checker_helper']) ? $this->aParams['checker_helper'] : '';

$this->_sAuthorKey = 'author';
$this->_sPrivacyObjectView = 'sys_form_inputs_allow_view_to';
$this->_sPrivacyGroupDefault = BX_DOL_PG_ALL;
}

/**
Expand Down Expand Up @@ -825,6 +835,11 @@ function initChecker ($aValues = array (), $aSpecificValues = array())
if ($aValues)
$oChecker->fillWithValues($this->aInputs, $aValues);

// init author from provided values if it's available

if (isset($aValues[$this->_sAuthorKey]))
$this->_iAuthorId = (int)$aValues[$this->_sAuthorKey];


if ($this->isSubmitted ()) {

Expand Down Expand Up @@ -951,6 +966,17 @@ function getSpecificValues()
return $this->_aSpecificValues;
}

function getAuthorId()
{
return $this->_iAuthorId;
}

function setAuthorId($iAuthorId)
{
$this->_iAuthorId = (int)$iAuthorId;
$this->aParams['params']['author_id'] = $this->_iAuthorId;
}

public static function getSubmittedValue($sKey, $sMethod, &$aSpecificValues = false)
{
$aData = array();
Expand Down Expand Up @@ -1127,6 +1153,37 @@ public function getFormErrors ()
}
return $s;
}

protected function _getPrivacyIcon($mixedPrivacy)
{
switch($mixedPrivacy) {
case BX_DOL_PG_MEONLY:
$sResult = 'lock';
break;

case BX_DOL_PG_ALL:
$sResult = 'globe';
break;

default:
$sResult = 'user';
break;
}

return $sResult;
}

protected function _getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId = false)
{
if(!$iAuthorId)
$iAuthorId = bx_get_logged_profile_id();

$mixedPrivacyGroup = BxDolFormQuery::getInputPrivacy($iInputId, $iAuthorId, BxDolPrivacy::getFieldName($sPrivacyObject));
if(empty($mixedPrivacyGroup))
$mixedPrivacyGroup = $this->_sPrivacyGroupDefault;

return $mixedPrivacyGroup;
}
}

class BxDolFormChecker
Expand Down
51 changes: 50 additions & 1 deletion inc/classes/BxDolFormQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ static public function getFormArray ($sObject, $sDisplayName)
'uri' => $aObject['uri'],
'uri_title' => $aObject['uri_title'],
),
'view_mode' => $aDisplay['view_mode'],
'object' => $sObject,
'display' => $sDisplayName,
'view_mode' => $aDisplay['view_mode'],
);

$aForm['params'] = array_merge_recursive($aDefaultsFormParams, !empty($aAddFormParams) && is_array($aAddFormParams) ? $aAddFormParams : array());
Expand All @@ -99,6 +100,7 @@ static public function getFormArray ($sObject, $sDisplayName)

// main attributes
$aInput = array (
'id' => $a['id'],
'type' => $a['type'],
'name' => $a['name'],
'caption_system_src' => $a['caption_system'],
Expand All @@ -109,6 +111,7 @@ static public function getFormArray ($sObject, $sDisplayName)
'required' => $a['required'] ? true : false,
'unique' => $a['unique'] ? true : false,
'collapsed' => $a['collapsed'] ? true : false,
'privacy' => $a['privacy'] ? true : false,
'html' => $a['html'],
'attrs' => $a['attrs'] ? unserialize($a['attrs']) : false,
'tr_attrs' => $a['attrs_tr'] ? unserialize($a['attrs_tr']) : false,
Expand Down Expand Up @@ -216,6 +219,52 @@ static public function fieldGetValue($sTable, $sField, $sFieldKey, $sFieldKeyVal
));
}

static public function getInputByName($sObject, $sName)
{
return BxDolDb::getInstance()->getRow("SELECT * FROM `sys_form_inputs` WHERE `object`=:object AND `name`=:name LIMIT 1", array(
'object' => $sObject,
'name' => $sName
));
}

static public function getInputPrivacy($iInputId, $iAuthorId, $sPrivacyField = '')
{
$sMethod = 'getRow';
$sSelectClause = '*';

if(!empty($sPrivacyField)) {
$sMethod = 'getOne';
$sSelectClause = '`' . $sPrivacyField . '`';
}

return BxDolDb::getInstance()->$sMethod("SELECT " . $sSelectClause . " FROM `sys_form_inputs_privacy` WHERE `input_id`=:input_id AND `author_id`=:author_id LIMIT 1", array(
'input_id' => $iInputId,
'author_id' => $iAuthorId,
));
}

static public function setInputPrivacy($iInputId, $iAuthorId, $sPrivacyField, $sPrivacyValue)
{
$oDb = BxDolDb::getInstance();

$sTable = 'sys_form_inputs_privacy';
$aBindingsSet = array(
$sPrivacyField => $sPrivacyValue
);
$aBindingsWhere = array(
'input_id' => $iInputId,
'author_id' => $iAuthorId,
);

$bResult = false;
if((int)$oDb->getOne("SELECT `id` FROM `" . $sTable . "` WHERE `input_id`=:input_id AND `author_id`=:author_id LIMIT 1", $aBindingsWhere) != 0)
$bResult = $oDb->query("UPDATE `" . $sTable . "` SET " . $oDb->arrayToSQL($aBindingsSet) . " WHERE " . $oDb->arrayToSQL($aBindingsWhere, ' AND ')) !== false;
else
$bResult = (int)$oDb->query("INSERT `" . $sTable . "` SET " . $oDb->arrayToSQL(array_merge($aBindingsSet, $aBindingsWhere))) > 0;

return $bResult;
}

public function getFormInputs()
{
$sQuery = $this->prepare("SELECT * FROM `sys_form_inputs` WHERE `object` = ? ORDER BY `order` ASC", $this->_aObject['object']);
Expand Down
60 changes: 60 additions & 0 deletions inc/js/classes/BxDolForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaCore UNA Core
* @{
*/

function BxDolForm(oOptions)
{
if(typeof oOptions === 'undefined')
return;

this._sObjName = oOptions.sObjName === undefined ? 'oForm' : oOptions.sObjName; // javascript object name, to run current object instance from onTimer
this._sObject = oOptions.sObject; // form object
this._sDisplay = oOptions.sDisplay; // form display

this._sActionsUri = 'form.php';
this._sActionsUrl = oOptions.sRootUrl + this._sActionsUri; // actions url address

this._sAnimationEffect = 'fade';
this._iAnimationSpeed = 'slow';
this._aHtmlIds = oOptions.aHtmlIds;
}

BxDolForm.prototype.pgcTogglePopup = function(oLink, iInputId, sPrivacyObject)
{
var oData = this._getDefaultParams();
oData['a'] = 'get_privacy_group_chooser';
oData['input_id'] = iInputId;
oData['privacy_object'] = sPrivacyObject;

$(oLink).dolPopupAjax({
id: this._aHtmlIds['pgc_popup'] + iInputId,
url: bx_append_url_params(this._sActionsUri, oData),
closeOnOuterClick: false,
removeOnClose: true,
});
};

BxDolForm.prototype.pgcOnSelectGroup = function(oData)
{
if(oData && parseInt(oData.code) != 0)
return;

if(oData.form_id && oData.chooser_id && oData.icon)
$('#' + oData.form_id + ' #' + oData.chooser_id + ' .bx-form-input-pgc-current .sys-icon').removeClass().addClass('sys-icon ' + oData.icon);
};

BxDolForm.prototype._getDefaultParams = function()
{
var oDate = new Date();
return {
o: this._sObject,
d: this._sDisplay,
_t: oDate.getTime()
};
};

/** @} */
27 changes: 26 additions & 1 deletion install/sql/system.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-- --------------------------------------------------------

DROP TABLE IF EXISTS `sys_keys`, `sys_objects_editor`, `sys_objects_player`, `sys_objects_embeds`, `sys_objects_file_handlers`, `sys_objects_captcha`, `sys_objects_cmts`, `sys_cmts_images`, `sys_cmts_images_preview`, `sys_cmts_images2entries`, `sys_cmts_ids`, `sys_cmts_meta_keywords`, `sys_cmts_meta_mentions`, `sys_cmts_votes`, `sys_cmts_votes_track`, `sys_cmts_reactions`, `sys_cmts_reactions_track`, `sys_cmts_reports`, `sys_cmts_reports_track`, `sys_cmts_scores`, `sys_cmts_scores_track`, `sys_email_templates`, `sys_queue_push`, `sys_queue_email`, `sys_options`, sys_options_types, `sys_options_categories`, `sys_options_mixes`, `sys_options_mixes2options`, `sys_localization_categories`, `sys_localization_keys`, `sys_localization_languages`, `sys_localization_strings`, `sys_acl_actions`, `sys_acl_actions_track`, `sys_acl_matrix`, `sys_acl_levels`, `sys_sessions`, `sys_acl_levels_members`, `sys_objects_rss`, `sys_objects_search`, `sys_objects_search_extended`, `sys_search_extended_fields`, `sys_statistics`, `sys_audit`, `sys_alerts`, `sys_alerts_handlers`, `sys_injections`, `sys_injections_admin`, `sys_modules`, `sys_modules_file_tracks`, `sys_modules_relations`, `sys_permalinks`, `sys_objects_privacy`, `sys_privacy_defaults`, `sys_privacy_groups`, `sys_privacy_groups_custom`, `sys_privacy_groups_custom_members`, `sys_objects_auths`, `sys_objects_score`, `sys_objects_vote`, `sys_objects_report`, `sys_objects_view`, `sys_objects_favorite`, `sys_objects_feature`, `sys_objects_chart`, `sys_objects_content_info`, `sys_content_info_grids`, `sys_cron_jobs`, `sys_objects_storage`, `sys_objects_uploader`, `sys_storage_user_quotas`, `sys_storage_tokens`, `sys_storage_ghosts`, `sys_storage_deletions`, `sys_storage_mime_types`, `sys_objects_transcoder`, `sys_transcoder_images_files`, `sys_transcoder_videos_files`, `sys_transcoder_audio_files`, `sys_transcoder_filters`, `sys_transcoder_queue`, `sys_transcoder_queue_files`, `sys_accounts`, `sys_profiles`, `sys_objects_form`, `sys_form_displays`, `sys_form_inputs`, `sys_form_display_inputs`, `sys_form_pre_lists`, `sys_form_pre_values`, `sys_menu_templates`, `sys_objects_menu`, `sys_menu_sets`, `sys_menu_items`, `sys_objects_grid`, `sys_grid_fields`, `sys_grid_actions`, `sys_objects_connection`, `sys_profiles_conn_relations`, `sys_profiles_conn_subscriptions`, `sys_profiles_conn_friends`, `sys_objects_page`, `sys_pages_types`, `sys_pages_layouts`, `sys_pages_design_boxes`, `sys_pages_blocks`, `sys_labels`, `sys_objects_metatags`, `sys_objects_category`, `sys_objects_live_updates`, `sys_objects_payments`, `sys_files`, `sys_images`, `sys_images_custom`, `sys_images_resized`, `sys_rewrite_rules`, `sys_preloader`, `sys_std_pages`, `sys_std_widgets`, `sys_std_pages_widgets`, `sys_categories`, `sys_categories2objects`, `sys_objects_wiki`, `sys_pages_wiki_blocks`, `sys_badges`, `sys_badges2objects`;
DROP TABLE IF EXISTS `sys_keys`, `sys_objects_editor`, `sys_objects_player`, `sys_objects_embeds`, `sys_objects_file_handlers`, `sys_objects_captcha`, `sys_objects_cmts`, `sys_cmts_images`, `sys_cmts_images_preview`, `sys_cmts_images2entries`, `sys_cmts_ids`, `sys_cmts_meta_keywords`, `sys_cmts_meta_mentions`, `sys_cmts_votes`, `sys_cmts_votes_track`, `sys_cmts_reactions`, `sys_cmts_reactions_track`, `sys_cmts_reports`, `sys_cmts_reports_track`, `sys_cmts_scores`, `sys_cmts_scores_track`, `sys_email_templates`, `sys_queue_push`, `sys_queue_email`, `sys_options`, sys_options_types, `sys_options_categories`, `sys_options_mixes`, `sys_options_mixes2options`, `sys_localization_categories`, `sys_localization_keys`, `sys_localization_languages`, `sys_localization_strings`, `sys_acl_actions`, `sys_acl_actions_track`, `sys_acl_matrix`, `sys_acl_levels`, `sys_sessions`, `sys_acl_levels_members`, `sys_objects_rss`, `sys_objects_search`, `sys_objects_search_extended`, `sys_search_extended_fields`, `sys_statistics`, `sys_audit`, `sys_alerts`, `sys_alerts_handlers`, `sys_injections`, `sys_injections_admin`, `sys_modules`, `sys_modules_file_tracks`, `sys_modules_relations`, `sys_permalinks`, `sys_objects_privacy`, `sys_privacy_defaults`, `sys_privacy_groups`, `sys_privacy_groups_custom`, `sys_privacy_groups_custom_members`, `sys_objects_auths`, `sys_objects_score`, `sys_objects_vote`, `sys_objects_report`, `sys_objects_view`, `sys_objects_favorite`, `sys_objects_feature`, `sys_objects_chart`, `sys_objects_content_info`, `sys_content_info_grids`, `sys_cron_jobs`, `sys_objects_storage`, `sys_objects_uploader`, `sys_storage_user_quotas`, `sys_storage_tokens`, `sys_storage_ghosts`, `sys_storage_deletions`, `sys_storage_mime_types`, `sys_objects_transcoder`, `sys_transcoder_images_files`, `sys_transcoder_videos_files`, `sys_transcoder_audio_files`, `sys_transcoder_filters`, `sys_transcoder_queue`, `sys_transcoder_queue_files`, `sys_accounts`, `sys_profiles`, `sys_objects_form`, `sys_form_displays`, `sys_form_inputs`, `sys_form_inputs_privacy`, `sys_form_display_inputs`, `sys_form_pre_lists`, `sys_form_pre_values`, `sys_menu_templates`, `sys_objects_menu`, `sys_menu_sets`, `sys_menu_items`, `sys_objects_grid`, `sys_grid_fields`, `sys_grid_actions`, `sys_objects_connection`, `sys_profiles_conn_relations`, `sys_profiles_conn_subscriptions`, `sys_profiles_conn_friends`, `sys_objects_page`, `sys_pages_types`, `sys_pages_layouts`, `sys_pages_design_boxes`, `sys_pages_blocks`, `sys_labels`, `sys_objects_metatags`, `sys_objects_category`, `sys_objects_live_updates`, `sys_objects_payments`, `sys_files`, `sys_images`, `sys_images_custom`, `sys_images_resized`, `sys_rewrite_rules`, `sys_preloader`, `sys_std_pages`, `sys_std_widgets`, `sys_std_pages_widgets`, `sys_categories`, `sys_categories2objects`, `sys_objects_wiki`, `sys_pages_wiki_blocks`, `sys_badges`, `sys_badges2objects`;

ALTER DATABASE DEFAULT CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
Expand Down Expand Up @@ -758,6 +758,10 @@ INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`,
('system', 'set acl as privacy', NULL, '_sys_acl_action_set_acl_as_privacy', '_sys_acl_action_set_acl_as_privacy_desc', 0, 3);
SET @iIdActionSetAclAsPrivacy = LAST_INSERT_ID();

INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
('system', 'set form fields privacy', NULL, '_sys_acl_action_set_form_fields_privacy', '_sys_acl_action_set_form_fields_privacy_desc', 0, 3);
SET @iIdActionSetFormFieldsPrivacy = LAST_INSERT_ID();

INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
('system', 'chart view', NULL, '_sys_acl_action_chart_view', '_sys_acl_action_chart_view_desc', 0, 3);
SET @iIdActionChartView = LAST_INSERT_ID();
Expand Down Expand Up @@ -961,6 +965,15 @@ INSERT INTO `sys_acl_matrix` (`IDLevel`, `IDAction`) VALUES
-- set acl as privacy
(@iAdministrator, @iIdActionSetAclAsPrivacy),

-- set form fields privacy
(@iAccount, @iIdActionSetFormFieldsPrivacy),
(@iStandard, @iIdActionSetFormFieldsPrivacy),
(@iUnconfirmed, @iIdActionSetFormFieldsPrivacy),
(@iPending, @iIdActionSetFormFieldsPrivacy),
(@iModerator, @iIdActionSetFormFieldsPrivacy),
(@iAdministrator, @iIdActionSetFormFieldsPrivacy),
(@iPremium, @iIdActionSetFormFieldsPrivacy),

-- view charts
(@iAdministrator, @iIdActionChartView),

Expand Down Expand Up @@ -1850,6 +1863,9 @@ CREATE TABLE `sys_objects_privacy` (
UNIQUE KEY `action` (`module`(64), `action`(127))
);

INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
('sys_form_inputs_allow_view_to', 'system', 'view', '_sys_privacy_forms_input_allow_view_to', '3', 'sys_form_inputs_privacy', 'id', 'author_id', '', '');

CREATE TABLE `sys_privacy_defaults` (
`owner_id` int(11) NOT NULL default '0',
`action_id` int(11) NOT NULL default '0',
Expand Down Expand Up @@ -3140,6 +3156,7 @@ CREATE TABLE IF NOT EXISTS `sys_form_inputs` (
`unique` tinyint(4) NOT NULL DEFAULT '0',
`collapsed` tinyint(4) NOT NULL DEFAULT '0',
`html` tinyint(4) NOT NULL DEFAULT '0',
`privacy` tinyint(4) NOT NULL DEFAULT '0',
`attrs` text NOT NULL,
`attrs_tr` text NOT NULL,
`attrs_wrapper` text NOT NULL,
Expand Down Expand Up @@ -3249,6 +3266,14 @@ INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `c
('sys_wiki', 'system', 'close', '_sys_close', '', 0, 'reset', '_sys_form_wiki_input_caption_close', '', '', 0, 0, 0, 'a:2:{s:7:\"onclick\";s:46:\"$(\'.bx-popup-applied:visible\').dolPopupHide();\";s:5:\"class\";s:22:\"bx-def-margin-sec-left\";}', '', '', '', '', '', '', '', 1, 0),
('sys_wiki', 'system', 'buttons', '', 'do_submit,close', 0, 'input_set', '_sys_form_wiki_buttons', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0);

CREATE TABLE IF NOT EXISTS `sys_form_inputs_privacy` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`input_id` int(11) unsigned NOT NULL default '0',
`author_id` int(11) unsigned NOT NULL default '0',
`allow_view_to` varchar(16) NOT NULL DEFAULT '3',
PRIMARY KEY (`id`),
UNIQUE KEY `input` (`input_id`,`author_id`)
);

CREATE TABLE IF NOT EXISTS `sys_form_display_inputs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand Down
12 changes: 10 additions & 2 deletions modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public function getObjectFormDelete ($sDisplay = false)

public function viewDataEntry ($iContentId)
{
$CNF = &$this->_oModule->_oConfig->CNF;

// get content data and profile info
list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
if (!$aContentInfo)
Expand All @@ -144,6 +146,12 @@ public function viewDataEntry ($iContentId)
if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
return MsgBox($sMsg);

$oForm = $this->getObjectFormView();
$oForm->initChecker($aContentInfo);

if(!empty($CNF['FIELD_TEXT']) && !$oForm->isInputVisible($CNF['FIELD_TEXT']))
return '';

return $this->_oModule->_oTemplate->entryText($aContentInfo);
}

Expand Down Expand Up @@ -439,11 +447,11 @@ public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null
if ($sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile))
return $sResult;

// create an alert
// create an alert
bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']], false, array(
'content' => &$aContentInfo
));

return '';
}

Expand Down
2 changes: 2 additions & 0 deletions modules/base/profile/classes/BxBaseModProfileFormEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function __construct($aInfo, $oTemplate = false)
{
parent::__construct($aInfo, $oTemplate);

$this->_sAuthorKey = 'profile_id';

$CNF = &$this->_oModule->_oConfig->CNF;

if (!empty($CNF['FIELD_PICTURE']) && isset($this->aInputs[$CNF['FIELD_PICTURE']])) {
Expand Down
Loading

0 comments on commit 7bd6e6d

Please sign in to comment.