PluginProbe
Services Section Block – present your services in clean grids and columns / 1.1.3
Services Section Block – present your services in clean grids and columns v1.1.3
1.4.6 1.4.5 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 trunk 1.0 1.1 1.1.1 All 33 releases
services-section / plugin.php

plugin.php in Services Section Block – present your services in clean grids and columns 1.1.3, at plugin.php

181 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Services Section
4 * Description: Use Services Section Block to provide services of your business to clients with customizable settings.
5 * Version: 1.1.3
6 * Author: bPlugins LLC
7 * Author URI: http://bplugins.com
8 * License: GPLv3
9 * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
10 * Text Domain: services-section
11 */
12
13 // ABS PATH
14 if ( !defined( 'ABSPATH' ) ) { exit; }
15
16 // Constant
17 define( 'SSB_PLUGIN_VERSION', '1.1.3' );
18 define( 'SSB_ASSETS_DIR', plugin_dir_url( __FILE__ ) . 'assets/' );
19
20 // Generate Styles
21 class SSBStyleGenerator {
22 public static $styles = [];
23 public static function addStyle($selector, $styles){
24 if(array_key_exists($selector, self::$styles)){
25 self::$styles[$selector] = wp_parse_args(self::$styles[$selector], $styles);
26 }else { self::$styles[$selector] = $styles; }
27 }
28 public static function renderStyle(){
29 $output = '';
30 foreach(self::$styles as $selector => $style){
31 $new = '';
32 foreach($style as $property => $value){
33 if($value == ''){ $new .= $property; }else { $new .= " $property: $value;"; }
34 }
35 $output .= "$selector { $new }";
36 }
37 return $output;
38 }
39 }
40
41 // Services Section Block
42 class ServicesSectionBlock{
43 protected static $_instance = null;
44
45 function __construct(){
46 add_action( 'enqueue_block_assets', [$this, 'enqueue_block_assets'] );
47 add_action( 'init', [$this, 'register'] );
48 }
49
50 public static function instance(){
51 if(self::$_instance === null){
52 self::$_instance = new self();
53 }
54 return self::$_instance;
55 }
56
57 function enqueue_block_assets(){ wp_enqueue_script( 'font-awesome-kit', SSB_ASSETS_DIR . 'js/font-awesome-kit.js', array(), SSB_PLUGIN_VERSION, true ); }
58
59 function register_script( $block, $options = array() ){
60 register_block_type( 'services-section/' . $block, array_merge( array(
61 'editor_script' => 'ssb_editor_script',
62 'editor_style' => 'ssb_editor_style',
63 'script' => 'ssb_script',
64 'style' => 'ssb_style',
65 ), $options ) );
66 } // Register Script
67
68 function register(){
69 wp_register_script( 'ssb_editor_script', plugins_url( 'dist/editor.js', __FILE__ ), array( 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-rich-text' ), SSB_PLUGIN_VERSION, false ); // Backend Script
70 wp_register_style( 'ssb_editor_style', plugins_url( 'dist/editor.css', __FILE__ ), array( 'wp-edit-blocks' ), SSB_PLUGIN_VERSION ); // Backend Style
71 wp_register_script( 'ssb_script', plugins_url( 'dist/script.js', __FILE__ ), array( 'jquery' ), SSB_PLUGIN_VERSION, true ); // Frontend Script
72 wp_register_style( 'ssb_style', plugins_url( 'dist/style.css', __FILE__ ), array( 'wp-editor' ), SSB_PLUGIN_VERSION ); // Frontend Style
73
74 $this->register_script( 'services', array( 'render_callback' => [$this, 'render_services'] ) );
75 $this->register_script( 'service', array( 'render_callback' => [$this, 'render_service'] ) );
76
77 wp_set_script_translations( 'ssb_editor_script', 'services-section', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate
78 } // Register
79
80 function render_services( $attributes, $content ){
81 extract( $attributes );
82 $align = $align ?? 'wide';
83 $cId = $cId ?? '';
84 $layout = $layout ?? 'default';
85 $columns = $columns ?? array( 'desktop' => 3, 'tablet' => 2, 'mobile' => 1 );
86 $columnGap = $columnGap ?? '30px';
87 $rowGap = $rowGap ?? '30px';
88 $background = $background ?? '#0000';
89 $textAlign = $textAlign ?? 'left';
90 $itemHeight = $itemHeight ?? '375px';
91 $itemPadding = $itemPadding ?? array('top' => '50px', 'right' => '30px', 'bottom' => '50px', 'left' => '50px');
92 $itemShadow = $itemShadow ?? array('blur' => '20px', 'color' => '#0000001a');
93 $itemBorder = $itemBorder ?? array('radius' => '15px');
94 $iconPadding = $iconPadding ?? array('bottom' => '10px');
95 $iconMargin = $iconMargin ?? array('bottom' => '20px');
96 $titleTypo = $titleTypo ?? array('fontSize' => 23);
97 $titleMargin = $titleMargin ?? array('bottom' => '30px');
98 $descTypo = $descTypo ?? array('fontSize' => 16);
99
100 $servicesStyle = new SSBStyleGenerator(); // Generate Styles
101 $servicesStyle::addStyle("#ssbServices-$cId .ssbServices", array( 'grid-gap' => "$rowGap $columnGap", $background['styles'] ?? 'background-color: #0000;' => '' ));
102 $servicesStyle::addStyle("#ssbServices-$cId .ssbServices .ssbService", array(
103 'text-align' => $textAlign,
104 'min-height' => $itemHeight,
105 'padding' => $itemPadding['styles'] ?? '50px 30px 50px 50px',
106 'box-shadow' => $itemShadow['styles'] ?? '0 0 20px 0 #0000001a',
107 $itemBorder['styles'] ?? 'border-radius: 15px;' => ''
108 ));
109 $servicesStyle::addStyle("#ssbServices-$cId .ssbServices .ssbService .bgLayer", array( 'border-radius' => $itemBorder['radius'] ?? '15px' ));
110 $servicesStyle::addStyle("#ssbServices-$cId .ssbServices .ssbService .icon", array( 'padding' => $iconPadding['styles'] ?? '0 0 10px 0', 'margin' => $iconMargin['styles'] ?? '0 0 20px 0' ));
111 $servicesStyle::addStyle("#ssbServices-$cId .ssbServices .ssbService .title", array( $titleTypo['styles'] ?? 'font-size: 23px' => '', 'margin' => $titleMargin['styles'] ?? '0 0 30px 0' ));
112 $servicesStyle::addStyle("#ssbServices-$cId .ssbServices .ssbService .description", array( $descTypo['styles'] ?? 'font-size: 16px' => '' ));
113
114 $titleFontLink = $titleTypo['googleFontLink'] ?? '';
115 $descFontLink = $descTypo['googleFontLink'] ?? '';
116
117 $alignClass = isset($align) ? 'align' . $align : '';
118
119 return "<div class='wp-block-services-section-services ". esc_attr($alignClass) ."' id='ssbServices-$cId'>
120 <style>@import url($titleFontLink); @import url($descFontLink);". $servicesStyle::renderStyle() ."</style>
121
122 <div class='ssbServices $layout columns-". $columns['desktop'] ." columns-tablet-". $columns['tablet'] ." columns-mobile-". $columns['mobile'] ."'> $content </div>
123 </div>";
124 $servicesStyle::$styles = array(); // Empty styles
125 } // Render Services
126
127 function render_service( $attributes ){
128 extract( $attributes );
129 $cId = $cId ?? '';
130 $background = $background ?? array('type' => 'image', 'image' => array('url' => plugins_url( 'dist/src/img/service-pattern.png', __FILE__ )), 'overlayColor' => '#0000', 'position' => 'bottom left', 'size' => 'auto');
131 $isIcon = $isIcon ?? true;
132 $isUpIcon = $isUpIcon ?? false;
133 $icon = $icon ?? array('class' => 'fa fa-wordpress', 'fontSize' => 70);
134 $upIcon = $upIcon ?? array('id' => NULL, 'url' => '', 'alt' => '', 'title' => '');
135 $iconWidth = $iconWidth ?? '70px';
136 $iconBorder = $iconBorder ?? array();
137 $isTitle = $isTitle ?? true;
138 $title = $title ?? 'Service title';
139 $titleColor = $titleColor ?? '#222';
140 $isDesc = $isDesc ?? true;
141 $desc = $desc ?? 'Lorem ipsum dolor sit, amet consectetur adipisicing elit. Accusamus, fuga.';
142 $descColor = $descColor ?? '#333';
143 $isLink = $isLink ?? true;
144 $link = $link ?? '#';
145 $linkIn = $linkIn ?? 'button';
146 $linkIconColor = $linkIconColor ?? '#fff';
147 $linkBGColor = $linkBGColor ?? '#d2d2d2';
148 $linkBGHovColor = $linkBGHovColor ?? '#fe6601';
149
150 $serviceStyle = new SSBStyleGenerator(); // Generate Styles
151 $serviceStyle::addStyle("#ssbService-$cId .ssbService .bgLayer", array( $background['styles'] ?? 'background-image: url('. plugins_url( 'dist/src/img/service-pattern.png', __FILE__ ) .'); background-position: bottom left; background-size: auto; background-repeat: no-repeat; background-color: #0000;' => '' ));
152 $serviceStyle::addStyle("#ssbService-$cId .ssbService .icon", array( $iconBorder['styles'] ?? '' => '' ));
153 $serviceStyle::addStyle("#ssbService-$cId .ssbService .icon i", array( $icon['styles'] ?? 'font-size: 70px;' => '' ));
154 $serviceStyle::addStyle("#ssbService-$cId .ssbService .icon img", array( 'width' => $iconWidth ));
155 $serviceStyle::addStyle("#ssbService-$cId .ssbService .title", array( 'color' => $titleColor ));
156 $serviceStyle::addStyle("#ssbService-$cId .ssbService .description", array( 'color' => $descColor ));
157 $serviceStyle::addStyle("#ssbService-$cId .ssbService .link a", array( 'background-color' => $linkBGColor ));
158 $serviceStyle::addStyle("#ssbService-$cId:hover .ssbService .link a", array( 'background-color' => $linkBGHovColor ));
159 $serviceStyle::addStyle("#ssbService-$cId .ssbService .link a svg", array( 'fill' => $linkIconColor ));
160
161 ob_start(); ?>
162 <div class='wp-block-services-section-service' id='ssbService-<?php echo esc_attr($cId); ?>'>
163 <style><?php echo wp_kses($serviceStyle::renderStyle(), []); ?></style>
164 <div class='ssbService'>
165 <div class='bgLayer'></div>
166 <div class='icon'><?php echo $isUpIcon ? (isset($upIcon['url']) ? "<img src='". esc_url($upIcon['url']) ."' alt='". esc_attr($upIcon['alt']) ."' />" : '') : (isset($icon['class']) ? "<i class='". esc_attr($icon['class']) ."'></i>" : ''); ?></div>
167
168 <?php echo $isTitle ? ('title' === $linkIn ? "<a href='". esc_url($link) ."'><h3 class='title'>". esc_html($title) ."</h3></a>" : "<h3 class='title'>". esc_html($title) ."</h3>") : ''; ?>
169
170 <?php echo $isDesc ? "<p class='description'>". esc_html( $desc ) ."</p>" : ''; ?>
171
172 <?php echo $isLink && 'button' === $linkIn ? "<div class='link'><a href='". esc_url($link) ."'>
173 <svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 493.356 493.356'><path d='M490.498,239.278l-109.632-99.929c-3.046-2.474-6.376-2.95-9.993-1.427c-3.613,1.525-5.427,4.283-5.427,8.282v63.954H9.136 c-2.666,0-4.856,0.855-6.567,2.568C0.859,214.438,0,216.628,0,219.292v54.816c0,2.663,0.855,4.853,2.568,6.563 c1.715,1.712,3.905,2.567,6.567,2.567h356.313v63.953c0,3.812,1.817,6.57,5.428,8.278c3.62,1.529,6.95,0.951,9.996-1.708 l109.632-101.077c1.903-1.902,2.852-4.182,2.852-6.849C493.356,243.367,492.401,241.181,490.498,239.278z' /></svg>
174 </a></div>" : ''; ?>
175 </div>
176 </div>
177 <?php $serviceStyle::$styles = array(); // Empty styles
178 return ob_get_clean();
179 } // Render Service
180 }
181 ServicesSectionBlock::instance();