Skip to content

Commit

Permalink
feat: add comments settings
Browse files Browse the repository at this point in the history
  • Loading branch information
cristian-ungureanu committed May 25, 2021
1 parent a35ce12 commit 8d83bcc
Show file tree
Hide file tree
Showing 13 changed files with 592 additions and 426 deletions.
4 changes: 0 additions & 4 deletions assets/scss/elements/blog/_comments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@
float: right;
}
}

input[type=submit] {
@extend %nv-button-secondary;
}
}

.comment-form {
Expand Down
5 changes: 5 additions & 0 deletions assets/scss/elements/blog/_single-new.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
}
}

.nv-comments-wrap.is-boxed .nv-comments-list {
padding: 0;
}


.mobile-top {
align-self: flex-start;
}
Expand Down
46 changes: 46 additions & 0 deletions globals/sanitize-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,49 @@ function sanitize_meta_ordering( $value ) {

return $value;
}

/**
* Sanitize blend mode option.
*
* @param string $input Control input.
*
* @return string
*/
function sanitize_blend_mode( $input ) {
$blend_mode_options = [ 'normal', 'multiply', 'screen', 'overlay', 'darken', 'lighten', 'color-dodge', 'saturation', 'color', 'difference', 'exclusion', 'hue', 'luminosity' ];
if ( ! in_array( $input, $blend_mode_options, true ) ) {
return 'normal';
}
return $input;
}

/**
* Sanitize the container layout value
*
* @param string $value value from the control.
*
* @return bool
*/
function sanitize_container_layout( $value ) {
$allowed_values = array( 'contained', 'full-width' );
if ( ! in_array( $value, $allowed_values, true ) ) {
return 'contained';
}

return esc_html( $value );
}

/**
* Sanitize Button Type option.
*
* @param string $value the control value.
*
* @return string
*/
function sanitize_button_type( $value ) {
if ( ! in_array( $value, [ 'primary', 'secondary' ], true ) ) {
return 'primary';
}

return $value;
}
4 changes: 3 additions & 1 deletion inc/admin/metabox/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Neve\Core\Settings\Config;
use Neve\Core\Settings\Mods;
use Neve\Customizer\Defaults\Single_Post;
use Neve\Customizer\Options\Layout_Single_Post;
use Neve\Views\Post_Layout;

Expand All @@ -18,6 +19,7 @@
* @package Neve\Admin\Metabox
*/
final class Manager {
use Single_Post;

/**
* Control instances.
Expand Down Expand Up @@ -412,7 +414,7 @@ public function meta_sidebar_script_enqueue() {
* @return string
*/
private function get_post_elements_default_order() {
$default_order = Layout_Single_Post::ordering_default();
$default_order = $this->post_ordering();

$content_order = get_theme_mod( 'neve_layout_single_post_elements_order', wp_json_encode( $default_order ) );
if ( ! is_string( $content_order ) ) {
Expand Down
11 changes: 9 additions & 2 deletions inc/core/settings/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,15 @@ class Config {
const MODS_POST_COVER_OVERLAY_OPACITY = 'neve_post_cover_overlay_opacity';
const MODS_POST_COVER_TEXT_COLOR = 'neve_post_cover_text_color';
const MODS_POST_COVER_BLEND_MODE = 'neve_post_cover_blend_mode';
const MODS_POST_COVER_BOXED_TITLE_PADDING = 'neve_post_cover_boxed_title_padding';
const MODS_POST_COVER_BOXED_TITLE_BACKGROUND = 'neve_post_cover_boxed_title_background';
const MODS_POST_COVER_BOXED_TITLE_PADDING = 'neve_post_cover_title_boxed_padding';
const MODS_POST_COVER_BOXED_TITLE_BACKGROUND = 'neve_post_cover_title_boxed_background';

const MODS_POST_COMMENTS_PADDING = 'neve_comments_boxed_padding';
const MODS_POST_COMMENTS_BACKGROUND_COLOR = 'neve_comments_boxed_background_color';
const MODS_POST_COMMENTS_TEXT_COLOR = 'neve_comments_boxed_text_color';
const MODS_POST_COMMENTS_FORM_PADDING = 'neve_comments_form_boxed_padding';
const MODS_POST_COMMENTS_FORM_BACKGROUND_COLOR = 'neve_comments_form_boxed_background_color';
const MODS_POST_COMMENTS_FORM_TEXT_COLOR = 'neve_comments_form_boxed_text_color';

const CSS_PROP_BORDER_COLOR = 'border-color';
const CSS_PROP_BACKGROUND_COLOR = 'background-color';
Expand Down
66 changes: 57 additions & 9 deletions inc/core/styles/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Neve\Core\Settings\Config;
use Neve\Core\Settings\Mods;
use Neve\Customizer\Defaults\Single_Post;
use Neve\Customizer\Options\Layout_Single_Post;

/**
Expand All @@ -17,6 +18,8 @@
* @package Neve\Core\Styles
*/
class Frontend extends Generator {
use Single_Post;

/**
* Generator constructor.
*/
Expand Down Expand Up @@ -764,8 +767,8 @@ private function setup_form_fields_style() {
*/
private function setup_single_post_style() {

$cover_padding_default = Layout_Single_Post::cover_padding_default();
$this->_subscribers['body.single-post .nv-post-cover'] = [
$cover_padding_default = $this->padding_default( 'cover' );
$this->_subscribers['.nv-post-cover'] = [
Config::CSS_PROP_MIN_HEIGHT => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COVER_HEIGHT,
Dynamic_Selector::META_IS_RESPONSIVE => true,
Expand All @@ -779,7 +782,7 @@ private function setup_single_post_style() {
],
];

$this->_subscribers['body.single-post .nv-post-cover .nv-overlay'] = [
$this->_subscribers['.nv-post-cover .nv-overlay'] = [
Config::CSS_PROP_BACKGROUND_COLOR => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COVER_BACKGROUND_COLOR,
Dynamic_Selector::META_DEFAULT => 'var(--nv-dark-bg)',
Expand All @@ -796,7 +799,7 @@ private function setup_single_post_style() {
];


$this->_subscribers['body.single-post .nv-post-cover .nv-meta-list li, body.single-post .nv-post-cover .nv-meta-list a'] = [
$this->_subscribers['.nv-post-cover .nv-meta-list li, .nv-post-cover .nv-meta-list a'] = [
Config::CSS_PROP_COLOR => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COVER_TEXT_COLOR,
Dynamic_Selector::META_DEFAULT => 'var(--nv-text-dark-bg)',
Expand All @@ -808,22 +811,67 @@ private function setup_single_post_style() {
Dynamic_Selector::META_KEY => Config::MODS_POST_COVER_BOXED_TITLE_PADDING,
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_SUFFIX => 'responsive_unit',
Dynamic_Selector::META_DEFAULT => $cover_padding_default,
Dynamic_Selector::META_DEFAULT => $this->padding_default( 'cover' ),
],
Config::CSS_PROP_BACKGROUND_COLOR => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COVER_BOXED_TITLE_BACKGROUND,
Dynamic_Selector::META_DEFAULT => 'var(--nv-dark-bg)',
],
];

$this->_subscribers['body.single-post .nv-post-cover .nv-cover-container'] = [
$this->_subscribers['.nv-post-cover .nv-cover-container'] = [
Config::CSS_PROP_PADDING => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COVER_PADDING,
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_SUFFIX => 'responsive_unit',
Dynamic_Selector::META_DEFAULT => $cover_padding_default,
Dynamic_Selector::META_DEFAULT => $this->padding_default( 'cover' ),
],
];

$this->_subscribers['.nv-comments-wrap.is-boxed'] = [
Config::CSS_PROP_PADDING => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_PADDING,
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_SUFFIX => 'responsive_unit',
Dynamic_Selector::META_DEFAULT => $this->padding_default(),
],
Config::CSS_PROP_BACKGROUND_COLOR => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_BACKGROUND_COLOR,
Dynamic_Selector::META_DEFAULT => 'var(--nv-dark-bg)',
],
];

$this->_subscribers['.nv-comments-wrap.is-boxed, .nv-comments-wrap.is-boxed a'] = [
Config::CSS_PROP_COLOR => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_TEXT_COLOR,
Dynamic_Selector::META_DEFAULT => 'var(--nv-text-dark-bg)',
],
];




$this->_subscribers['.comment-respond.is-boxed'] = [
Config::CSS_PROP_PADDING => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_PADDING,
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_SUFFIX => 'responsive_unit',
Dynamic_Selector::META_DEFAULT => $this->padding_default(),
],
Config::CSS_PROP_BACKGROUND_COLOR => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_BACKGROUND_COLOR,
Dynamic_Selector::META_DEFAULT => 'var(--nv-dark-bg)',
],
];

$this->_subscribers['.comment-respond.is-boxed, .comment-respond.is-boxed a'] = [
Config::CSS_PROP_COLOR => [
Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_TEXT_COLOR,
Dynamic_Selector::META_DEFAULT => 'var(--nv-text-dark-bg)',
],
];


}

/**
Expand All @@ -834,7 +882,7 @@ private function setup_single_post_style() {
* @return string
*/
public function add_form_buttons( $selector ) {
return ( $selector . ', form input[type="submit"], form button[type="submit"], #comments input[type="submit"]' );
return ( $selector . ', form input[type="submit"], form button[type="submit"]' );
}

/**
Expand All @@ -845,6 +893,6 @@ public function add_form_buttons( $selector ) {
* @return string
*/
public function add_form_buttons_hover( $selector ) {
return ( $selector . ', form input[type="submit"]:hover, form button[type="submit"]:hover, #comments input[type="submit"]:hover' );
return ( $selector . ', form input[type="submit"]:hover, form button[type="submit"]:hover' );
}
}
108 changes: 108 additions & 0 deletions inc/customizer/defaults/Single_Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
/**
* Default settings traits, shared with other classes.
*
* @package Neve\Customizer\Defaults
*/

namespace Neve\Customizer\Defaults;

/**
* Trait Single_Post_Defaults
*
* @package Neve\Customizer\Defaults
*/
trait Single_Post {

/**
* Get default values for cover padding.
*
* @return array
*/
public function padding_default( $param = '' ) {

$m_t = $m_r = $m_b = $m_l = $t_t = $t_r = $t_b = $t_l = $d_t = $d_r = $d_b = $d_l = 15; //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found

if ( $param === 'cover' ) {
$m_t = $m_b = 40; //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
$m_r = $m_l = $d_r = $d_l = $t_r = $t_l = 15; //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
$t_t = $t_b = $d_t = $d_b = 60; //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
}

return [
'mobile' => [
'top' => $m_t,
'right' => $m_r,
'bottom' => $m_b,
'left' => $m_l,
],
'tablet' => [
'top' => $t_t,
'right' => $t_r,
'bottom' => $t_b,
'left' => $t_l,
],
'desktop' => [
'top' => $d_t,
'right' => $d_r,
'bottom' => $d_b,
'left' => $d_l,
],
'mobile-unit' => 'px',
'tablet-unit' => 'px',
'desktop-unit' => 'px',
];
}

/**
* Get the default value for title alignment.
*
* @return array
*/
public static function post_title_alignment() {
$default_position = is_rtl() ? 'right' : 'left';
return [
'mobile' => $default_position,
'tablet' => $default_position,
'desktop' => $default_position,
];
}

/**
* Get the default value for title vertical position.
*
* @return array
*/
public function post_title_position() {
return [
'mobile' => 'bottom',
'tablet' => 'bottom',
'desktop' => 'bottom',
];
}

/**
* Get default values for ordering control
*
* @return array
*/
public function post_ordering() {
$default_components = [
'title-meta',
'thumbnail',
'content',
'tags',
'comments',
];

if ( get_theme_mod( 'neve_post_header_layout' ) === 'cover' ) {
$default_components = [
'content',
'tags',
'comments',
];
}

return apply_filters( 'neve_single_post_elements_default_order', $default_components );
}
}
17 changes: 1 addition & 16 deletions inc/customizer/options/form_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private function add_button_controls() {
new Control(
'neve_form_button_type',
[
'sanitize_callback' => [ $this, 'sanitize_button_type' ],
'sanitize_callback' => 'sanitize_button_type',
'default' => 'primary',
],
[
Expand All @@ -606,19 +606,4 @@ private function add_button_controls() {
)
);
}

/**
* Sanitize Button Type option.
*
* @param string $value the control value.
*
* @return string
*/
public function sanitize_button_type( $value ) {
if ( ! in_array( $value, [ 'primary', 'secondary' ], true ) ) {
return 'primary';
}

return $value;
}
}
Loading

0 comments on commit 8d83bcc

Please sign in to comment.