| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Post_Comment_Count { |
| 7 |
public function __construct() { |
| 8 |
add_action('init', array($this, 'register')); |
| 9 |
} |
| 10 |
public function get_attributes($default = false) { |
| 11 |
|
| 12 |
$attributes = array( |
| 13 |
'blockId' => [ |
| 14 |
'type' => 'string', |
| 15 |
'default' => '', |
| 16 |
], |
| 17 |
|
| 18 |
|
| 19 |
/*============================ |
| 20 |
Post Comment Count Settings |
| 21 |
============================*/ |
| 22 |
'commentLabel' => [ |
| 23 |
'type' => 'boolean', |
| 24 |
'default' => true, |
| 25 |
], |
| 26 |
'commentIconShow' => [ |
| 27 |
'type' => 'boolean', |
| 28 |
'default' => true, |
| 29 |
], |
| 30 |
'commentColor' => [ |
| 31 |
'type' => 'string', |
| 32 |
'default' => '', |
| 33 |
'style' => [ |
| 34 |
(object)[ |
| 35 |
'selector'=>'{{ULTP}} .ultp-comment-count { color:{{commentColor}} }' |
| 36 |
], |
| 37 |
], |
| 38 |
], |
| 39 |
'commentTypo' => [ |
| 40 |
'type' => 'object', |
| 41 |
'default' => (object)['openTypography' => 0,'size' => (object)['lg' => '', 'unit' =>'px']], |
| 42 |
'style' => [ |
| 43 |
(object)[ |
| 44 |
'selector'=>'{{ULTP}} .ultp-comment-count' |
| 45 |
], |
| 46 |
], |
| 47 |
], |
| 48 |
'commentCountAlign' => [ |
| 49 |
'type' => 'object', |
| 50 |
'default' => [], |
| 51 |
'style' => [ |
| 52 |
(object)[ |
| 53 |
'selector'=>'{{ULTP}} .ultp-comment-count { justify-content: {{commentCountAlign}};}' |
| 54 |
], |
| 55 |
], |
| 56 |
], |
| 57 |
|
| 58 |
|
| 59 |
/*============================ |
| 60 |
Comment Count Label Settings |
| 61 |
============================*/ |
| 62 |
'commentLabelText' => [ |
| 63 |
'type' => 'string', |
| 64 |
'default' => 'comment ', |
| 65 |
'style' => [ |
| 66 |
(object)[ |
| 67 |
'depends' => [ |
| 68 |
(object)['key'=>'commentLabel','condition'=>'==','value'=> true], |
| 69 |
], |
| 70 |
], |
| 71 |
], |
| 72 |
], |
| 73 |
"commentLabelAlign" => [ |
| 74 |
"type" => "string", |
| 75 |
"default" => "after", |
| 76 |
'style' => [ |
| 77 |
(object)[ |
| 78 |
'depends' => [ |
| 79 |
(object)['key'=>'commentLabelAlign','condition'=>'==','value'=> "before"], |
| 80 |
(object)['key'=>'commentLabel','condition'=>'==','value'=> true], |
| 81 |
], |
| 82 |
'selector'=>'{{ULTP}} .ultp-comment-count .ultp-comment-label {order: -1;margin-right: 5px;}' |
| 83 |
], |
| 84 |
(object)[ |
| 85 |
'depends' => [ |
| 86 |
(object)['key'=>'commentLabelAlign','condition'=>'==','value'=> "after"], |
| 87 |
(object)['key'=>'commentLabel','condition'=>'==','value'=> true], |
| 88 |
], |
| 89 |
'selector'=>'{{ULTP}} .ultp-comment-count .ultp-comment-label {order: unset; margin-left: 5px;}' |
| 90 |
], |
| 91 |
], |
| 92 |
], |
| 93 |
|
| 94 |
/*============================ |
| 95 |
Comment Count Icon Settings |
| 96 |
============================*/ |
| 97 |
'iconColor' => [ |
| 98 |
'type' => 'string', |
| 99 |
'default' => '#656565', |
| 100 |
'style' => [ |
| 101 |
(object)[ |
| 102 |
'depends' => [ |
| 103 |
(object)['key'=>'commentIconShow','condition'=>'==','value'=> true], |
| 104 |
], |
| 105 |
'selector'=>'{{ULTP}} .ultp-comment-count > svg { fill:{{iconColor}}; stroke:{{iconColor}};}' |
| 106 |
], |
| 107 |
], |
| 108 |
], |
| 109 |
'commentIconStyle' => [ |
| 110 |
'type' => 'string', |
| 111 |
'default' => 'commentCount1', |
| 112 |
'style' => [ |
| 113 |
(object)[ |
| 114 |
'depends' => [ |
| 115 |
(object)['key'=>'commentIconShow','condition'=>'==','value'=> true], |
| 116 |
], |
| 117 |
], |
| 118 |
], |
| 119 |
], |
| 120 |
'commentIconSize' => [ |
| 121 |
'type' => 'object', |
| 122 |
'default' => (object)['lg' =>'15', 'unit' =>'px'], |
| 123 |
'style' => [ |
| 124 |
(object)[ |
| 125 |
'depends' => [ |
| 126 |
(object)['key'=>'commentIconShow','condition'=>'==','value'=> true], |
| 127 |
], |
| 128 |
'selector'=>'{{ULTP}} .ultp-comment-count svg{ width:{{commentIconSize}}; height:{{commentIconSize}} }' |
| 129 |
], |
| 130 |
], |
| 131 |
], |
| 132 |
'commentSpace' => [ |
| 133 |
'type' => 'object', |
| 134 |
'default' => (object)['lg' =>'8', 'unit' =>'px'], |
| 135 |
'style' => [ |
| 136 |
(object)[ |
| 137 |
'depends' => [ |
| 138 |
(object)['key'=>'commentIconShow','condition'=>'==','value'=> true], |
| 139 |
], |
| 140 |
'selector'=>'{{ULTP}} .ultp-comment-count > svg { margin-right: {{commentSpace}} }' |
| 141 |
], |
| 142 |
(object)[ |
| 143 |
'depends' => [ |
| 144 |
(object)['key'=>'commentIconShow','condition'=>'==','value'=> true], |
| 145 |
(object)['key'=>'commentLabelAlign','condition'=>'==','value'=> "before"], |
| 146 |
], |
| 147 |
'selector'=>'{{ULTP}} .ultp-comment-count > svg { margin: {{commentSpace}} } {{ULTP}} .ultp-comment-count .ultp-comment-label {margin: 0px !important;}' |
| 148 |
], |
| 149 |
], |
| 150 |
], |
| 151 |
|
| 152 |
//-------------------------- |
| 153 |
// Advanced Settings |
| 154 |
//-------------------------- |
| 155 |
'wrapBg' => [ |
| 156 |
'type' => 'object', |
| 157 |
'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#f5f5f5'], |
| 158 |
'style' => [ |
| 159 |
(object)[ |
| 160 |
'selector'=>'{{ULTP}} .ultp-block-wrapper' |
| 161 |
], |
| 162 |
], |
| 163 |
], |
| 164 |
'wrapBorder' => [ |
| 165 |
'type' => 'object', |
| 166 |
'default' => (object)['openBorder'=>0, 'width' =>(object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'], |
| 167 |
'style' => [ |
| 168 |
(object)[ |
| 169 |
'selector'=>'{{ULTP}} .ultp-block-wrapper' |
| 170 |
], |
| 171 |
], |
| 172 |
], |
| 173 |
'wrapShadow' => [ |
| 174 |
'type' => 'object', |
| 175 |
'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 176 |
'style' => [ |
| 177 |
(object)[ |
| 178 |
'selector'=>'{{ULTP}} .ultp-block-wrapper' |
| 179 |
], |
| 180 |
], |
| 181 |
], |
| 182 |
'wrapRadius' => [ |
| 183 |
'type' => 'object', |
| 184 |
'default' => (object)['lg' =>'', 'unit' =>'px'], |
| 185 |
'style' => [ |
| 186 |
(object)[ |
| 187 |
'selector'=>'{{ULTP}} .ultp-block-wrapper { border-radius:{{wrapRadius}}; }' |
| 188 |
], |
| 189 |
], |
| 190 |
], |
| 191 |
'wrapHoverBackground' => [ |
| 192 |
'type' => 'object', |
| 193 |
'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#037fff'], |
| 194 |
'style' => [ |
| 195 |
(object)[ |
| 196 |
'selector'=>'{{ULTP}} .ultp-block-wrapper:hover' |
| 197 |
], |
| 198 |
], |
| 199 |
], |
| 200 |
'wrapHoverBorder' => [ |
| 201 |
'type' => 'object', |
| 202 |
'default' => (object)['openBorder'=>0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'], |
| 203 |
'style' => [ |
| 204 |
(object)[ |
| 205 |
'selector'=>'{{ULTP}} .ultp-block-wrapper:hover' |
| 206 |
], |
| 207 |
], |
| 208 |
], |
| 209 |
'wrapHoverRadius' => [ |
| 210 |
'type' => 'object', |
| 211 |
'default' => (object)['lg' =>'', 'unit' =>'px'], |
| 212 |
'style' => [ |
| 213 |
(object)[ |
| 214 |
'selector'=>'{{ULTP}} .ultp-block-wrapper:hover { border-radius:{{wrapHoverRadius}}; }' |
| 215 |
], |
| 216 |
], |
| 217 |
], |
| 218 |
'wrapHoverShadow' => [ |
| 219 |
'type' => 'object', |
| 220 |
'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 221 |
'style' => [ |
| 222 |
(object)[ |
| 223 |
'selector'=>'{{ULTP}} .ultp-block-wrapper:hover' |
| 224 |
], |
| 225 |
], |
| 226 |
], |
| 227 |
'wrapMargin' => [ |
| 228 |
'type' => 'object', |
| 229 |
'default' => (object)['lg' =>(object)['top' => '','bottom' => '', 'unit' =>'px']], |
| 230 |
'style' => [ |
| 231 |
(object)[ |
| 232 |
'selector'=>'{{ULTP}} .ultp-block-wrapper { margin:{{wrapMargin}}; }' |
| 233 |
], |
| 234 |
], |
| 235 |
], |
| 236 |
'wrapOuterPadding' => [ |
| 237 |
'type' => 'object', |
| 238 |
'default' => (object)['lg' =>(object)['top' => '','bottom' => '','left' => '', 'right' => '', 'unit' =>'px']], |
| 239 |
'style' => [ |
| 240 |
(object)[ |
| 241 |
'selector'=>'{{ULTP}} .ultp-block-wrapper { padding:{{wrapOuterPadding}}; }' |
| 242 |
], |
| 243 |
], |
| 244 |
], |
| 245 |
|
| 246 |
|
| 247 |
//-------------------------- |
| 248 |
// Advanced Settings |
| 249 |
//-------------------------- |
| 250 |
'advanceId' => [ |
| 251 |
'type' => 'string', |
| 252 |
'default' => '', |
| 253 |
], |
| 254 |
'advanceZindex' => [ |
| 255 |
'type' => 'number', |
| 256 |
'default' => '', |
| 257 |
'style' => [ |
| 258 |
(object)[ |
| 259 |
'selector' => '{{ULTP}} {z-index:{{advanceZindex}};}' |
| 260 |
], |
| 261 |
], |
| 262 |
], |
| 263 |
'wrapMargin' => [ |
| 264 |
'type' => 'object', |
| 265 |
'default' => (object)['lg' =>(object)['top' => '','bottom' => '', 'unit' =>'px']], |
| 266 |
'style' => [ |
| 267 |
(object)[ |
| 268 |
'selector'=>'{{ULTP}} .ultp-block-wrapper { margin:{{wrapMargin}}; }' |
| 269 |
], |
| 270 |
], |
| 271 |
], |
| 272 |
'wrapOuterPadding' => [ |
| 273 |
'type' => 'object', |
| 274 |
'default' => (object)['lg' =>(object)['top' => '','bottom' => '','left' => '', 'right' => '', 'unit' =>'px']], |
| 275 |
'style' => [ |
| 276 |
(object)[ |
| 277 |
'selector'=>'{{ULTP}} .ultp-block-wrapper { padding:{{wrapOuterPadding}}; }' |
| 278 |
], |
| 279 |
], |
| 280 |
], |
| 281 |
'wrapBg' => [ |
| 282 |
'type' => 'object', |
| 283 |
'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#f5f5f5'], |
| 284 |
'style' => [ |
| 285 |
(object)[ |
| 286 |
'selector'=>'{{ULTP}} .ultp-block-wrapper' |
| 287 |
], |
| 288 |
], |
| 289 |
], |
| 290 |
'wrapBorder' => [ |
| 291 |
'type' => 'object', |
| 292 |
'default' => (object)['openBorder'=>0, 'width' =>(object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'], |
| 293 |
'style' => [ |
| 294 |
(object)[ |
| 295 |
'selector'=>'{{ULTP}} .ultp-block-wrapper' |
| 296 |
], |
| 297 |
], |
| 298 |
], |
| 299 |
'wrapShadow' => [ |
| 300 |
'type' => 'object', |
| 301 |
'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 302 |
'style' => [ |
| 303 |
(object)[ |
| 304 |
'selector'=>'{{ULTP}} .ultp-block-wrapper' |
| 305 |
], |
| 306 |
], |
| 307 |
], |
| 308 |
'wrapRadius' => [ |
| 309 |
'type' => 'object', |
| 310 |
'default' => (object)['lg' =>'', 'unit' =>'px'], |
| 311 |
'style' => [ |
| 312 |
(object)[ |
| 313 |
'selector'=>'{{ULTP}} .ultp-block-wrapper { border-radius:{{wrapRadius}}; }' |
| 314 |
], |
| 315 |
], |
| 316 |
], |
| 317 |
'wrapHoverBackground' => [ |
| 318 |
'type' => 'object', |
| 319 |
'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#037fff'], |
| 320 |
'style' => [ |
| 321 |
(object)[ |
| 322 |
'selector'=>'{{ULTP}} .ultp-block-wrapper:hover' |
| 323 |
], |
| 324 |
], |
| 325 |
], |
| 326 |
'wrapHoverBorder' => [ |
| 327 |
'type' => 'object', |
| 328 |
'default' => (object)['openBorder'=>0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'], |
| 329 |
'style' => [ |
| 330 |
(object)[ |
| 331 |
'selector'=>'{{ULTP}} .ultp-block-wrapper:hover' |
| 332 |
], |
| 333 |
], |
| 334 |
], |
| 335 |
'wrapHoverRadius' => [ |
| 336 |
'type' => 'object', |
| 337 |
'default' => (object)['lg' =>'', 'unit' =>'px'], |
| 338 |
'style' => [ |
| 339 |
(object)[ |
| 340 |
'selector'=>'{{ULTP}} .ultp-block-wrapper:hover { border-radius:{{wrapHoverRadius}}; }' |
| 341 |
], |
| 342 |
], |
| 343 |
], |
| 344 |
'wrapHoverShadow' => [ |
| 345 |
'type' => 'object', |
| 346 |
'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 347 |
'style' => [ |
| 348 |
(object)[ |
| 349 |
'selector'=>'{{ULTP}} .ultp-block-wrapper:hover' |
| 350 |
], |
| 351 |
], |
| 352 |
], |
| 353 |
'hideExtraLarge' => [ |
| 354 |
'type' => 'boolean', |
| 355 |
'default' => false, |
| 356 |
'style' => [ |
| 357 |
(object)[ |
| 358 |
'selector' => '{{ULTP}} {display:none;}' |
| 359 |
], |
| 360 |
], |
| 361 |
], |
| 362 |
'hideDesktop' => [ |
| 363 |
'type' => 'boolean', |
| 364 |
'default' => false, |
| 365 |
'style' => [ |
| 366 |
(object)[ |
| 367 |
'selector' => '{{ULTP}} {display:none;}' |
| 368 |
], |
| 369 |
], |
| 370 |
], |
| 371 |
'hideTablet' => [ |
| 372 |
'type' => 'boolean', |
| 373 |
'default' => false, |
| 374 |
'style' => [ |
| 375 |
(object)[ |
| 376 |
'selector' => '{{ULTP}} {display:none;}' |
| 377 |
], |
| 378 |
], |
| 379 |
], |
| 380 |
'hideMobile' => [ |
| 381 |
'type' => 'boolean', |
| 382 |
'default' => false, |
| 383 |
'style' => [ |
| 384 |
(object)[ |
| 385 |
'selector' => '{{ULTP}} {display:none;}' |
| 386 |
], |
| 387 |
], |
| 388 |
], |
| 389 |
'advanceCss' => [ |
| 390 |
'type' => 'string', |
| 391 |
'default' => '', |
| 392 |
'style' => [ |
| 393 |
(object)[ |
| 394 |
'selector' => '{{ULTP}} {display:none;}' |
| 395 |
], |
| 396 |
], |
| 397 |
], |
| 398 |
); |
| 399 |
|
| 400 |
if ($default) { |
| 401 |
$temp = array(); |
| 402 |
foreach ($attributes as $key => $value) { |
| 403 |
if (isset($value['default'])) { |
| 404 |
$temp[$key] = $value['default']; |
| 405 |
} |
| 406 |
} |
| 407 |
return $temp; |
| 408 |
} else { |
| 409 |
return $attributes; |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
public function register() { |
| 414 |
register_block_type( 'ultimate-post/post-comment-count', |
| 415 |
array( |
| 416 |
'editor_script' => 'ultp-blocks-editor-script', |
| 417 |
'editor_style' => 'ultp-blocks-editor-css', |
| 418 |
'attributes' => $this->get_attributes(), |
| 419 |
'render_callback' => array($this, 'content') |
| 420 |
) |
| 421 |
); |
| 422 |
} |
| 423 |
|
| 424 |
public function content($attr, $noAjax) { |
| 425 |
$block_name = 'post-comment-count'; |
| 426 |
$wrapper_before = $wrapper_after = $content = ''; |
| 427 |
|
| 428 |
$comment_count = get_post_meta( get_the_ID(), 'post_comments_count', true ); |
| 429 |
$wrapper_before .= '<div '.($attr['advanceId']?'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].(isset($attr["className"])?' '.$attr["className"]:'').''.(isset($attr["align"])? ' align' .$attr["align"]:'').'">'; |
| 430 |
$wrapper_before .= '<div class="ultp-block-wrapper">'; |
| 431 |
$content .= '<span class="ultp-comment-count">'; |
| 432 |
if ($attr["commentIconShow"] && ($attr["commentIconStyle"] != '')) { |
| 433 |
$content .= ultimate_post()->svg_icon($attr["commentIconStyle"]); |
| 434 |
} |
| 435 |
$content .= '<span>'.($comment_count ? $comment_count : 0).'</span>'; |
| 436 |
if ($attr["commentLabel"]) { |
| 437 |
$content .= '<span class="ultp-comment-label">'.$attr["commentLabelText"].'</span>'; |
| 438 |
} |
| 439 |
$content .= '</span>'; |
| 440 |
$wrapper_after .= '</div>'; |
| 441 |
$wrapper_after .= '</div>'; |
| 442 |
|
| 443 |
return $wrapper_before.$content.$wrapper_after; |
| 444 |
} |
| 445 |
} |