first commit

This commit is contained in:
Ryan Ariana
2024-05-06 11:04:37 +07:00
commit aee061ddba
7322 changed files with 2918816 additions and 0 deletions

View File

@@ -0,0 +1,341 @@
<?php
namespace HtContactForm\Block;
/**
* analytical data store
*/
class Contactform_Block
{
/**
* [$_instance]
* @var null
*/
private static $_instance = null;
/**
* [instance] Initializes a singleton instance
* @return [Actions]
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
self::$_instance->define_constants();
}
return self::$_instance;
}
/**
* The Constructor.
*/
public function __construct() {
add_action( 'enqueue_block_assets', [ $this, 'block_assets' ] );
add_action( 'enqueue_block_editor_assets', [ $this, 'block_editor_assets' ] );
add_action( 'init', [ $this, 'init' ] );
add_action( 'rest_api_init', [ $this, 'register_api' ] );
}
public function init(){
// Return early if this function does not exist.
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
$this->register_block();
}
/**
* Block assets.
*/
public function block_assets() {
$dependencies = require_once( HTCONTACTFORM_BLOCK_PATH . '/build/htcontactform-block.asset.php' );
wp_enqueue_script(
'ht-contactform-blocks',
HTCONTACTFORM_BLOCK_URL . '/build/htcontactform-block.js',
$dependencies['dependencies'],
$dependencies['version'],
true
);
wp_enqueue_style(
'ht-contactform-block-style',
HTCONTACTFORM_BLOCK_URL . '/src/assets/css/style-index.css',
array(),
HTCONTACTFORM_VERSION
);
wp_localize_script(
'ht-contactform-blocks',
'htcontactdata',
[
'pluginDirPath' => plugin_dir_path( __DIR__ ),
'pluginDirUrl' => plugin_dir_url( __DIR__ ),
'security' => wp_create_nonce('htcontactform-nonce'),
]
);
}
/**
* Block editor assets.
*/
public function block_editor_assets() {
wp_enqueue_style( 'ht-contactform-block-editor-style', HTCONTACTFORM_BLOCK_URL . '/src/assets/css/editor-style.css', false, HTCONTACTFORM_VERSION, 'all' );
}
private function register_block(){
ob_start();
include HTCONTACTFORM_BLOCK_PATH . '/src/ht-contactform-block/block.json';
$attributes = json_decode( ob_get_clean(), true );
register_block_type(
'block/ht-contactform', array(
'render_callback' => [ $this, 'render_content' ],
'attributes' => $attributes,
)
);
}
/**
* Define the required plugin constants
*
* @return void
*/
public function define_constants() {
$this->define( 'HTCONTACTFORM_BLOCK_FILE', __FILE__ );
$this->define( 'HTCONTACTFORM_BLOCK_PATH', __DIR__ );
$this->define( 'HTCONTACTFORM_BLOCK_URL', plugins_url( '', HTCONTACTFORM_BLOCK_FILE ) );
}
/**
* Define constant if not already set
*
* @param string $name
* @param string|bool $value
* @return type
*/
private function define( $name, $value ) {
if ( ! defined( $name ) ) {
define( $name, $value );
}
}
public function render_content($attr){
if(isset($attr['formId']) && !empty($attr['formId'])){
$block_uniqueid = '#ht-block-'.$attr['blockUniqId'];
ob_start();
echo '<div id="ht-block-'.$attr['blockUniqId'].'">';
echo do_shortcode( '[contact-form-7 id="'.$attr['formId'].'"]' );
echo "</div>";
?>
<style type="text/css">
<?php echo $block_uniqueid; ?>{
<?php echo $this->dimentation($attr,'areaMargin','','margin'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 input:not([type="checkbox"]):not([type="submit"]),<?php echo $block_uniqueid; ?> .wpcf7 textarea{
<?php echo $this->generate_css($attr,'inputBackground','','background'); ?>
<?php echo $this->generate_css($attr,'inputTextColor','','color'); ?>
<?php echo $this->dimentation($attr,'inputPadding','','padding'); ?>
<?php echo $this->dimentation($attr,'inputMargin','','margin'); ?>
<?php
$border = $attr['borderWidth'] ? $attr['borderWidth'].'px'.' '.$attr['borderType'].' '.$attr['borderColor'] : '';
echo $this->generate_css($attr, $border, '', 'border');
?>
<?php echo $this->dimentation($attr,'inputBorderRadius','','border-radius'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 label{
<?php echo $this->generate_css($attr,'labelColor','','color'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 input[type=submit]{
<?php echo $this->generate_css($attr,'btnBackgroundColor','','background'); ?>
<?php echo $this->dimentation($attr,'btnTextColor','','color'); ?>
<?php
$btn_border = $attr['btnBorderWidth'] ? $attr['btnBorderWidth'].'px'.' '.$attr['btnBorderType'].' '.$attr['btnBorderColor'] : '';
echo $this->generate_css($attr, $btn_border, '', 'border');
?>
<?php echo $this->dimentation($attr,'buttonBorderRadius','','border-radius'); ?>
}
/* Normal desktop*/
@media (min-width: 1300px){
<?php echo $block_uniqueid; ?> .wpcf7 input[type=text],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=email],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=password],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=search],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=tel],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=url],
<?php echo $block_uniqueid; ?> .wpcf7 select{
height: <?php echo $attr['inputHight']['desktop'] ?>px;
}
<?php echo $block_uniqueid; ?> .wpcf7 textarea{
height: <?php echo $attr['textAreaHight']['desktop'];?>px;
}
<?php echo $block_uniqueid; ?> .wpcf7 input:not([type="checkbox"]):not([type="submit"]),<?php echo $block_uniqueid; ?> .wpcf7 textarea{
<?php echo $this->generate_css($attr,'inputTextSize','desktop','font-size'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 label{
<?php echo $this->generate_css($attr,'labelFontSize','desktop','font-size'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 input[type=submit]{
<?php echo $this->generate_css($attr,'btnFontSize','desktop','font-size'); ?>
<?php echo $this->dimentation($attr,'buttonPadding','desktop','padding'); ?>
<?php echo $this->dimentation($attr,'buttonMargin','desktop','margin'); ?>
}
}
/* Normal laptop*/
@media (min-width: 992px) and (max-width: 1299px){
<?php echo $block_uniqueid; ?> .wpcf7 input[type=text],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=email],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=password],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=search],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=tel],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=url],
<?php echo $block_uniqueid; ?> .wpcf7 select{
height: <?php echo $attr['inputHight']['laptop'] ?>px;
}
<?php echo $block_uniqueid; ?> .wpcf7 textarea{
height: <?php echo $attr['textAreaHight']['laptop'];?>px;
}
<?php echo $block_uniqueid; ?> .wpcf7 input:not([type="checkbox"]):not([type="submit"]),<?php echo $block_uniqueid; ?> .wpcf7 textarea{
<?php echo $this->generate_css($attr,'inputTextSize','laptop','font-size'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 label{
<?php echo $this->generate_css($attr,'labelFontSize','laptop','font-size'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 input[type=submit]{
<?php echo $this->generate_css($attr,'btnFontSize','laptop','font-size'); ?>
<?php echo $this->dimentation($attr,'buttonPadding','laptop','padding'); ?>
<?php echo $this->dimentation($attr,'buttonMargin','laptop','margin'); ?>
}
}
/* Normal tablate*/
@media (min-width: 768px) and (max-width: 991px) {
<?php echo $block_uniqueid; ?> .wpcf7 input[type=text],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=email],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=password],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=search],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=tel],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=url],
<?php echo $block_uniqueid; ?> .wpcf7 select{
height: <?php echo $attr['inputHight']['tablet'] ?>px;
}
<?php echo $block_uniqueid; ?> .wpcf7 textarea{
height: <?php echo $attr['textAreaHight']['tablet'];?>px;
}
<?php echo $block_uniqueid; ?> .wpcf7 input:not([type="checkbox"]):not([type="submit"]),<?php echo $block_uniqueid; ?> .wpcf7 textarea{
<?php echo $this->generate_css($attr,'inputTextSize','tablet','font-size'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 label{
<?php echo $this->generate_css($attr,'labelFontSize','tablet','font-size'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 input[type=submit]{
<?php echo $this->generate_css($attr,'btnFontSize','tablet','font-size'); ?>
<?php echo $this->dimentation($attr,'buttonPadding','tablet','padding'); ?>
<?php echo $this->dimentation($attr,'buttonMargin','tablet','margin'); ?>
}
}
/* Normal mobile*/
@media (max-width: 767px) {
<?php echo $block_uniqueid; ?> .wpcf7 input[type=text],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=email],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=password],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=search],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=tel],
<?php echo $block_uniqueid; ?> .wpcf7 input[type=url],
<?php echo $block_uniqueid; ?> .wpcf7 select{
height: <?php echo $attr['inputHight']['mobile'] ?>px;
}
<?php echo $block_uniqueid; ?> .wpcf7 textarea{
height: <?php echo $attr['textAreaHight']['mobile'];?>px;
}
<?php echo $block_uniqueid; ?> .wpcf7 input:not([type="checkbox"]):not([type="submit"]),<?php echo $block_uniqueid; ?> .wpcf7 textarea{
<?php echo $this->generate_css($attr,'inputTextSize','mobile','font-size'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 label{
<?php echo $this->generate_css($attr,'labelFontSize','mobile','font-size'); ?>
}
<?php echo $block_uniqueid; ?> .wpcf7 input[type=submit]{
<?php echo $this->generate_css($attr,'btnFontSize','mobile','font-size'); ?>
<?php echo $this->dimentation($attr,'buttonPadding','mobile','padding'); ?>
<?php echo $this->dimentation($attr,'buttonMargin','mobile','margin'); ?>
}
}
</style>
<?php
return ob_get_clean();
}else{
return '<p class="ht-contactform-initial">'.esc_html__( "Please Select a contact form.", "ht-contactform" ).'</p>';
}
}
private function generate_css($settings, $attribute, $device, $css_attr, $important = ''){
if('' == $device && 'border' != $css_attr ){
$value = !empty( $settings[$attribute] ) ? $settings[$attribute] : '';
}else{
$value = !empty( $settings[$attribute][$device] ) ? $settings[$attribute][$device] : '';
}
if('border' == $css_attr){
$value = $attribute;
}
if( !empty( $value ) && 'NaN' !== $value ){
$css_attr .= ":{$value}";
return $css_attr."{$important};";
}else{
return "";
}
}
private function dimentation($settings, $attribute, $device, $css_attr, $important = ''){
$dimensions = !empty( $settings[$attribute] ) ? $settings[$attribute] : array();
if('' == $device){
if( isset( $dimensions['top'] ) || isset( $dimensions['right'] ) || isset( $dimensions['bottom'] ) || isset( $dimensions['left'] ) ){
$unit = empty( $dimensions['unit'] ) ? 'px' : $dimensions['unit'];
$top = ( $dimensions['top'] !== '' ) ? $dimensions['top'].$unit : null;
$right = ( $dimensions['right'] !== '' ) ? $dimensions['right'].$unit : null;
$bottom = ( $dimensions['bottom'] !== '' ) ? $dimensions['bottom'].$unit : null;
$left = ( $dimensions['left'] !== '' ) ? $dimensions['left'].$unit : null;
$css_dimension = ( ($top != null) || ($right !=null) || ($bottom != null) || ($left != '') ) ? ( $css_attr.":{$top} {$right} {$bottom} {$left}" ) : '';
return $css_dimension."{$important};";
}else{
return "";
}
}else{
if( isset( $dimensions[$device]['top'] ) || isset( $dimensions[$device]['right'] ) || isset( $dimensions[$device]['bottom'] ) || isset( $dimensions[$device]['left'] ) ){
$unit = empty( $dimensions['unit'] ) ? 'px' : $dimensions['unit'];
$top = ( $dimensions[$device]['top'] !== '' ) ? $dimensions[$device]['top'].$unit : null;
$right = ( $dimensions[$device]['right'] !== '' ) ? $dimensions[$device]['right'].$unit : null;
$bottom = ( $dimensions[$device]['bottom'] !== '' ) ? $dimensions[$device]['bottom'].$unit : null;
$left = ( $dimensions[$device]['left'] !== '' ) ? $dimensions[$device]['left'].$unit : null;
$css_dimension = ( ($top != null) || ($right !=null) || ($bottom != null) || ($left != '') ) ? ( $css_attr.":{$top} {$right} {$bottom} {$left}" ) : '';
return $css_dimension."{$important};";
}else{
return "";
}
}
}
public function register_api(){
$api = new Api\Api();
$api->register_routes();
}
}
Contactform_Block::instance();

View File

@@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'ab7ab8c167d159b48fdb');

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,125 @@
/**
* #.# Editor Styles
*
* CSS for just Backend enqueued after style.scss
* which makes it higher in priority.
*/
.wp-block-cgb-block-ht-contactform-block {
}
h2.ht-contactform-blocks-section-title{
margin: 0;
padding: 10px 0 10px 10px;
text-align: center;
font-size: 14px;
text-transform: uppercase;
font-weight: bold;
margin-bottom: 15px;
margin-top: 10px;
background-color: #eee;
}
.wpcf7 p{
margin-top: 0px;
margin-bottom: 1.2em !important;
}
.wpcf7 input[type=text], .wpcf7 textarea,input[type=email], .wpcf7 input[type=password], .wpcf7 input[type=search], .wpcf7 input[type=tel],.wpcf7 input[type=url],.wpcf7 select{
width:100%;
padding: .75em;
height: auto;
border-width: 1px;
border-style: solid;
border-color: #eaeaea;
border-radius: 2px;
box-shadow: none;
box-sizing: border-box;
transition: all .2s linear;
}
.wpcf7 input[type=checkbox]{
margin-right: 10px;
}
.wpcf7 input[type=submit]{
border-radius: 2px;
border-color: #0170B9;
background: #0170B9;
color: #fff;
padding-right: 40px;
padding-bottom: 8px;
}
.wpcf7 label span{
margin-top: 10px;
display: block;
}
.wp-block-selector-ht-contactform-dimensions-control{
margin: 15px 0;
}
.wp-block-selector-ht-contactform-dimensions-control .components-panel__row{
align-items: flex-start;
}
.wp-block-selector-ht-contactform-dimensions-control .ht-contactform-dimensions-btn-group button{
padding: 1px 7px;
height: auto;
}
.wp-block-selector-ht-contactform-dimensions-control button.components-button.has-icon {
height: 100%;
width: auto;
padding: 4px 3px;
border-radius: 0;
border: 1px solid #222;
}
.wp-block-selector-ht-contactform-dimensions-control h3{
margin: 0 0 5px 0;
}
.wp-block-selector-ht-contactform-dimensions-control .components-input-control{
align-items: center;
}
.wp-block-selector-ht-contactform-dimensions-control .components-input-control__backdrop{
border-right: 0 !important;
border-radius: 0 !important;
}
.ht-contactform-panel-row-height-auto {
min-height: inherit;
}
.components-panel__row.ht-contactform-device-row {
justify-content: start;
}
.ht-contactform-device-button button.components-button {
padding: 0 !important;
min-width: inherit;
height: inherit;
box-shadow: none !important;
border: none !important;
color: #222 !important;
background-color: transparent !important;
}
.ht-contactform-device-button button.components-button span.dashicon {
font-size: 13px;
width: inherit;
height: inherit;
}
.ht-contactform-device-button button.components-button.is-primary {
color: #007cba !important;
}
.wp-block-block-ht-contactform p.ht-contactform-initial{
padding: 16px 10px;
background: #eee;
}

View File

@@ -0,0 +1,216 @@
{
"formId": {
"type":"string",
"default":""
},
"inputHight":{
"type": "object",
"default": {
"desktop": 40,
"laptop": 35,
"tablet": 30,
"mobile": 30
}
},
"areaMargin": {
"type": "object",
"default": {
"top":"0",
"right":"0",
"bottom":"0",
"left":"0",
"unit":"px",
"link":"yes"
}
},
"blockUniqId":{
"type": "string",
"default": ""
},
"inputTextColor":{
"type" : "string",
"default" : "#666"
},
"inputTextSize":{
"type": "object",
"default": {
"desktop": "16px",
"laptop": "14px",
"tablet": "14px",
"mobile": "14px"
}
},
"inputBackground":{
"type" : "string",
"default" : "#fafafa"
},
"inputPadding": {
"type": "object",
"default": {
"top":"8",
"right":"8",
"bottom":"8",
"left":"8",
"unit":"px",
"link":"yes"
}
},
"inputMargin": {
"type": "object",
"default": {
"top":"0",
"right":"0",
"bottom":"0",
"left":"0",
"unit":"px",
"link":"yes"
}
},
"inputBorderRadius": {
"type": "object",
"default": {
"top":"5",
"right":"5",
"bottom":"5",
"left":"5",
"unit":"px",
"link":"yes"
}
},
"borderType":{
"type":"string",
"default":"solid"
},
"borderWidth":{
"type":"number",
"default":1
},
"borderColor":{
"type":"string",
"default":"#c8c9cb"
},
"textAreaHight":{
"type": "object",
"default": {
"desktop": 175,
"laptop": 170,
"tablet": 160,
"mobile": 160
}
},
"labelFontSize":{
"type": "object",
"default": {
"desktop": "16px",
"laptop": "14px",
"tablet": "14px",
"mobile": "14px"
}
},
"labelColor":{
"type" : "string",
"default" : "#3a3a3a"
},
"buttonPadding": {
"type": "object",
"default": {
"desktop":{
"top":"10",
"right":"40",
"bottom":"10",
"left":"40"
},
"laptop":{
"top":"0",
"right":"0",
"bottom":"0",
"left":"0"
},
"tablet":{
"top":"0",
"right":"0",
"bottom":"0",
"left":"0"
},
"mobile":{
"top":"0",
"right":"0",
"bottom":"0",
"left":"0"
},
"unit":"px",
"link":"no"
}
},
"buttonMargin": {
"type": "object",
"default": {
"desktop":{
"top":"10",
"right":"0",
"bottom":"10",
"left":"0"
},
"laptop":{
"top":"0",
"right":"0",
"bottom":"0",
"left":"0"
},
"tablet":{
"top":"0",
"right":"0",
"bottom":"0",
"left":"0"
},
"mobile":{
"top":"0",
"right":"0",
"bottom":"0",
"left":"0"
},
"unit":"px",
"link":"no"
}
},
"buttonBorderRadius": {
"type": "object",
"default": {
"top":"5",
"right":"5",
"bottom":"5",
"left":"5",
"unit":"px",
"link":"yes"
}
},
"btnBorderType":{
"type":"string",
"default":"none"
},
"btnBorderWidth":{
"type":"number",
"default":1
},
"btnBorderColor":{
"type":"string",
"default":"#000"
},
"btnBackgroundColor":{
"type":"string",
"default":"#0170B9"
},
"btnTextColor":{
"type":"string",
"default":"#fff"
},
"btnFontSize":{
"type": "object",
"default": {
"desktop": "16px",
"laptop": "14px",
"tablet": "14px",
"mobile": "14px"
}
}
}