Skip to content

Commit

Permalink
[E] Improvement to checkboxes #2357
Browse files Browse the repository at this point in the history
  • Loading branch information
lianglee committed Mar 3, 2024
1 parent 3baca59 commit bc17ada
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 72 deletions.
63 changes: 45 additions & 18 deletions system/plugins/default/input/checkbox.php
Expand Up @@ -8,29 +8,56 @@
* @license Open Source Social Network License (OSSN LICENSE) http://www.opensource-socialnetwork.org/licence
* @link https://www.opensource-socialnetwork.org/
*/

$class = 'ossn-checkbox-input';
if(isset($params['class'])){
//[B] strangeness of class extending in input modules #1635
$params['class'] = $class .' '. $params['class'];
if(isset($params['class'])) {
//[B] strangeness of class extending in input modules #1635
$params['class'] = $class . ' ' . $params['class'];
}
$value = (isset($params['value'])) ? $params['value'] : '';
$value = isset($params['value']) ? $params['value'] : '';
//[B] input/checkbox not getting any label #1849
$label = (isset($params['label'])) ? $params['label'] : '';
//this label is not the forum label but the checkbox title example [ ] Label not form <label>...
$label = isset($params['label']) ? $params['label'] : '';
$options = isset($params['options']) ? $params['options'] : false;

$vars = array();
//old checkbox
if(!$options) {
$options = array(
"{$params['name']}" => $label,
);
}
$vars = array();

$defaults = array(
'disabled' => false,
'class' => $class,
'type' => 'checkbox',
'disabled' => false,
'class' => $class,
'type' => 'checkbox',
);

$params = array_merge($defaults, $params);
unset($params['value']);
$attributes = ossn_args($params);
if(!empty($value) && $value == true){
$vars['checked'] = 'checked';
}
$vars = ossn_args($vars);
echo "<div class='checkbox-block'><input {$attributes} {$vars} /><span>{$label}</span></div>";
if(!empty($options)) {
$options_count = count($options);
//explode user option value later used for checking/unchecking box
if($options_count > 0 && !empty($value) && !is_array($value)){
$value = explode(',', $value);
$value = array_map('trim', $value);
}
foreach ($options as $key => $option_label) {
$args = array_merge($defaults, $params);

unset($args['value']);
unset($args['options']);
unset($args['label']);

$args['value'] = $key;
//if more than 1 options then name is array[]
if($options_count > 1) {
$args['name'] = "{$args['name']}[]";
}

if((!empty($value) && is_array($value) && in_array($key, $value)) || ($options_count == 1 && $value === true)) {
$args['checked'] = 'checked';
}

$attributes = ossn_args($args);
echo "<div class='checkbox-block'><input {$attributes} /><span>{$option_label}</span></div>";
}
}
122 changes: 69 additions & 53 deletions system/plugins/default/user/fields/item.php
Expand Up @@ -9,96 +9,112 @@
* @link https://www.opensource-socialnetwork.org/
*/
if(isset($params['items'])) {
foreach($params['items'] as $fields) {
foreach ($params['items'] as $fields) {
if(isset($fields['text'])) {
foreach($fields['text'] as $item) {
if(!isset($item['params'])){
$item['params'] = array();
foreach ($fields['text'] as $item) {
if(!isset($item['params'])) {
$item['params'] = array();
}
$args = array();
$args['name'] = $item['name'];
$args['value'] = '';
if(isset($item['value'])){
$args['value'] = $item['value'];
$args = array();
$args['name'] = $item['name'];
$args['value'] = '';
if(isset($item['value'])) {
$args['value'] = $item['value'];
}
$args['placeholder'] = ossn_print("{$item['name']}");
if(isset($item['class'])){
$args['class'] = 'form-control '.$item['class'];
if(isset($item['class'])) {
$args['class'] = 'form-control ' . $item['class'];
} else {
$args['class'] = 'form-control ';
}
$vars = array_merge($args, $item['params']);
$args['class'] = 'form-control ';
}
$vars = array_merge($args, $item['params']);
echo "<div class='text'>";
//[E]make the label arg assigned to any label of user/field #1646
if(isset($item['label']) && !is_bool($item['label'])){
echo "<label>".$item['label']."</label>";
} elseif((isset($item['label']) && $item['label'] === true) || (isset($params['label']) && $params['label'] === true)){
echo "<label>".ossn_print("{$item['name']}")."</label>";
if(isset($item['label']) && !is_bool($item['label'])) {
echo '<label>' . $item['label'] . '</label>';
} elseif((isset($item['label']) && $item['label'] === true) || (isset($params['label']) && $params['label'] === true)) {
echo '<label>' . ossn_print("{$item['name']}") . '</label>';
}
echo ossn_plugin_view('input/text', $vars);
echo "</div>";
echo '</div>';
}
}
if(isset($fields['textarea'])) {
foreach($fields['textarea'] as $item) {
if(!isset($item['params'])){
$item['params'] = array();
foreach ($fields['textarea'] as $item) {
if(!isset($item['params'])) {
$item['params'] = array();
}
$args = array();
$args['name'] = $item['name'];
$args['value'] = '';
if(isset($item['value'])) {
$args['value'] = $item['value'];
}
$args = array();
$args['name'] = $item['name'];
$args['value'] = '';
if(isset($item['value'])){
$args['value'] = $item['value'];
}
$args['placeholder'] = ossn_print("{$item['name']}");
if(isset($item['class'])){
$args['class'] = 'form-control '.$item['class'];
if(isset($item['class'])) {
$args['class'] = 'form-control ' . $item['class'];
} else {
$args['class'] = 'form-control ';
}
$vars = array_merge($args, $item['params']);
$args['class'] = 'form-control ';
}
$vars = array_merge($args, $item['params']);
echo "<div class='text'>";
//[E]make the label arg assigned to any label of user/field #1646
if(isset($item['label']) && !is_bool($item['label'])){
echo "<label>".$item['label']."</label>";
} elseif((isset($item['label']) && $item['label'] === true) || (isset($params['label']) && $params['label'] === true)){
echo "<label>".ossn_print("{$item['name']}")."</label>";
if(isset($item['label']) && !is_bool($item['label'])) {
echo '<label>' . $item['label'] . '</label>';
} elseif((isset($item['label']) && $item['label'] === true) || (isset($params['label']) && $params['label'] === true)) {
echo '<label>' . ossn_print("{$item['name']}") . '</label>';
}
echo ossn_plugin_view('input/textarea', $vars);
echo "</div>";
echo '</div>';
}
}
if(isset($fields['dropdown'])) {
foreach($fields['dropdown'] as $item) {
foreach ($fields['dropdown'] as $item) {
$vars = array();
$vars['name'] = $item['name'];
$args = array_merge($vars, $item);
echo "<div class='dropdown-block'>";
//[E]make the label arg assigned to any label of user/field #1646
if(isset($item['label']) && !is_bool($item['label'])){
echo "<label>".$item['label']."</label>";
} elseif((isset($item['label']) && $item['label'] === true) || (isset($params['label']) && $params['label'] === true)){
echo "<label>".ossn_print("{$item['name']}")."</label>";
if(isset($item['label']) && !is_bool($item['label'])) {
echo '<label>' . $item['label'] . '</label>';
} elseif((isset($item['label']) && $item['label'] === true) || (isset($params['label']) && $params['label'] === true)) {
echo '<label>' . ossn_print("{$item['name']}") . '</label>';
}
echo ossn_plugin_view('input/dropdown', $args);
echo "</div>";
echo '</div>';
}
}
}
if(isset($fields['radio'])) {
foreach($fields['radio'] as $item) {
foreach ($fields['radio'] as $item) {
$vars = array();
$vars['name'] = $item['name'];
$args = array_merge($vars, $item);
echo "<div class='radio-block-container'>";
//[E]make the label arg assigned to any label of user/field #1646
if(isset($item['label']) && !is_bool($item['label'])){
echo "<label>".$item['label']."</label>";
} elseif((isset($item['label']) && $item['label'] === true) || (isset($params['label']) && $params['label'] === true)){
echo "<label>".ossn_print("{$item['name']}")."</label>";
if(isset($item['label']) && !is_bool($item['label'])) {
echo '<label>' . $item['label'] . '</label>';
} elseif((isset($item['label']) && $item['label'] === true) || (isset($params['label']) && $params['label'] === true)) {
echo '<label>' . ossn_print("{$item['name']}") . '</label>';
}
echo ossn_plugin_view('input/radio', $args);
echo "</div>";
echo '</div>';
}
}
if(isset($fields['checkbox'])) {
foreach ($fields['checkbox'] as $item) {
echo "<div class='checkbox-block-container'>";
$vars = array();
$vars['name'] = $item['name'];
$args = array_merge($vars, $item);
//[E]make the label arg assigned to any label of user/field #1646
if(isset($item['label']) && !is_bool($item['label'])) {
echo '<label>' . $item['label'] . '</label>';
} elseif((isset($item['label']) && $item['label'] === true) || (isset($params['label']) && $params['label'] === true)) {
echo '<label>' . ossn_print("{$item['name']}") . '</label>';
}
echo ossn_plugin_view('input/checkbox', $args);
echo '</div>';
}
}
}
}
}
}
9 changes: 8 additions & 1 deletion themes/goblue/plugins/default/css/core/default.php
Expand Up @@ -2280,7 +2280,14 @@
.checkbox-block span {
margin-top:6px;
}

.checkbox-block-container {
margin-bottom: 20px;
}
#ossn-home-signup .checkbox-block,
.ossn-profile-bottom .ossn-edit-form .checkbox-block {
margin-top: 0;
margin-bottom: 0;
}
/*******************************
Ossn Blocked
*********************************/
Expand Down

0 comments on commit bc17ada

Please sign in to comment.