| 1 |
<?php |
| 2 |
|
| 3 |
namespace MasterAddons\Addons; |
| 4 |
|
| 5 |
/** |
| 6 |
* Author Name: Liton Arefin |
| 7 |
* Author URL : https: //jeweltheme.com |
| 8 |
*/ |
| 9 |
|
| 10 |
use MasterAddons\Inc\Classes\Base\Master_Widget; |
| 11 |
use \Elementor\Controls_Manager; |
| 12 |
use \Elementor\Group_Control_Background; |
| 13 |
use \Elementor\Repeater; |
| 14 |
|
| 15 |
use MasterAddons\Inc\Admin\Config; |
| 16 |
|
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit; // Exit if accessed directly. |
| 19 |
} |
| 20 |
|
| 21 |
class Code_Highlighter extends Master_Widget { |
| 22 |
use \MasterAddons\Inc\Traits\Widget_Notice; |
| 23 |
use \MasterAddons\Inc\Traits\Widget_Assets_Trait; |
| 24 |
|
| 25 |
public function get_name() { |
| 26 |
return 'jtlma-code-highlighter'; |
| 27 |
} |
| 28 |
|
| 29 |
public function get_title() { |
| 30 |
return __( 'Code Highlighter', 'master-addons' ); |
| 31 |
} |
| 32 |
|
| 33 |
public function get_icon() { |
| 34 |
return 'jltma-icon ' . Config::get_addon_icon($this->get_name()); |
| 35 |
} |
| 36 |
|
| 37 |
public function get_keywords() { |
| 38 |
return [ 'code' ]; |
| 39 |
} |
| 40 |
protected function register_controls() { |
| 41 |
|
| 42 |
$this->start_controls_section( |
| 43 |
'general_section', |
| 44 |
[ |
| 45 |
'label' => __( 'General', 'master-addons' ), |
| 46 |
] |
| 47 |
); |
| 48 |
|
| 49 |
// https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+aspnet+bash+c+csharp+cpp+git+go+haskell+http+java+json+kotlin+less+markup-templating+objectivec+perl+php+python+r+jsx+tsx+ruby+sass+scss+sql+swift+typescript+visual-basic+xml-doc |
| 50 |
$languages = [ |
| 51 |
'markup' => 'Markup', |
| 52 |
'html' => 'HTML', |
| 53 |
'css' => 'CSS', |
| 54 |
'sass' => 'Sass (Sass)', |
| 55 |
'scss' => 'Sass (Scss)', |
| 56 |
'less' => 'Less', |
| 57 |
'javascript' => 'JavaScript', |
| 58 |
'typescript' => 'TypeScript', |
| 59 |
'jsx' => 'React JSX', |
| 60 |
'tsx' => 'React TSX', |
| 61 |
'php' => 'PHP', |
| 62 |
'ruby' => 'Ruby', |
| 63 |
'json' => 'JSON + Web App Manifest', |
| 64 |
'http' => 'HTTP', |
| 65 |
'xml' => 'XML', |
| 66 |
'svg' => 'SVG', |
| 67 |
'csharp' => 'C#', |
| 68 |
'git' => 'Git', |
| 69 |
'java' => 'Java', |
| 70 |
'sql' => 'SQL', |
| 71 |
'go' => 'Go', |
| 72 |
'kotlin' => 'Kotlin + Kotlin Script', |
| 73 |
'python' => 'Python', |
| 74 |
'swift' => 'Swift', |
| 75 |
'bash' => 'Bash + Shell', |
| 76 |
'haskell' => 'Haskell', |
| 77 |
'perl' => 'Perl', |
| 78 |
'objectivec' => 'Objective-C', |
| 79 |
'visual-basic,' => 'Visual Basic + VBA', |
| 80 |
'r' => 'R', |
| 81 |
'c' => 'C', |
| 82 |
'cpp' => 'C++', |
| 83 |
'aspnet' => 'ASP.NET (C#)', |
| 84 |
]; |
| 85 |
|
| 86 |
$this->add_control( |
| 87 |
'language', |
| 88 |
[ |
| 89 |
'label' => esc_html__( 'Language', 'master-addons' ), |
| 90 |
'type' => Controls_Manager::SELECT2, |
| 91 |
'multiple' => false, |
| 92 |
'options' => $languages, |
| 93 |
'default' => 'javascript', |
| 94 |
] |
| 95 |
); |
| 96 |
|
| 97 |
$this->add_control( |
| 98 |
'code', |
| 99 |
[ |
| 100 |
'label' => esc_html__( 'Code', 'master-addons' ), |
| 101 |
'type' => Controls_Manager::CODE, |
| 102 |
'default' => '<h1>I am a title!</h1>', |
| 103 |
'dynamic' => [ |
| 104 |
'active' => true, |
| 105 |
], |
| 106 |
] |
| 107 |
); |
| 108 |
|
| 109 |
$this->add_control( |
| 110 |
'theme', |
| 111 |
[ |
| 112 |
'label' => esc_html__( 'Theme', 'master-addons' ), |
| 113 |
'type' => Controls_Manager::SELECT, |
| 114 |
'default' => 'default', |
| 115 |
'options' => [ |
| 116 |
'default' => 'Default', |
| 117 |
'okaidia' => 'Okaidia', |
| 118 |
'tomorrow' => 'Tomorrow Night', |
| 119 |
], |
| 120 |
'separator' => 'before', |
| 121 |
] |
| 122 |
); |
| 123 |
|
| 124 |
$this->add_control( |
| 125 |
'line_numbers', |
| 126 |
[ |
| 127 |
'label' => esc_html__( 'Line Numbers', 'master-addons' ), |
| 128 |
'type' => Controls_Manager::SWITCHER, |
| 129 |
'return_value' => 'line-numbers', |
| 130 |
'default' => 'line-numbers', |
| 131 |
] |
| 132 |
); |
| 133 |
|
| 134 |
$this->add_control( |
| 135 |
'line_highlight', |
| 136 |
[ |
| 137 |
'label' => esc_html__( 'Line Highlight', 'master-addons' ), |
| 138 |
'type' => Controls_Manager::TEXT, |
| 139 |
'default' => '', |
| 140 |
'placeholder' => '1, 4-6', |
| 141 |
'dynamic' => [ |
| 142 |
'active' => true, |
| 143 |
], |
| 144 |
'ai' => [ |
| 145 |
'active' => false, |
| 146 |
] |
| 147 |
] |
| 148 |
); |
| 149 |
|
| 150 |
$this->end_controls_section(); |
| 151 |
|
| 152 |
if ( class_exists( '\LQD_Elementor_Helper' ) ) { |
| 153 |
\LQD_Elementor_Helper::add_style_controls( |
| 154 |
$this, |
| 155 |
'code', |
| 156 |
[ |
| 157 |
'content' => [ |
| 158 |
'controls' => [ |
| 159 |
[ |
| 160 |
'type' => 'typography', |
| 161 |
'selector' => '.lqd-code-highlighter, {{WRAPPER}} .lqd-code-highlighter code, {{WRAPPER}} .lqd-code-highlighter .line-numbers .line-numbers-rows' |
| 162 |
], |
| 163 |
[ |
| 164 |
'type' => 'margin', |
| 165 |
'selector' => '.lqd-code-highlighter' |
| 166 |
], |
| 167 |
[ |
| 168 |
'type' => 'padding', |
| 169 |
'selector' => '.lqd-code-highlighter' |
| 170 |
], |
| 171 |
[ |
| 172 |
'type' => 'liquid_background_css', |
| 173 |
'selector' => '.lqd-code-highlighter' |
| 174 |
], |
| 175 |
[ |
| 176 |
'type' => 'border', |
| 177 |
'selector' => '.lqd-code-highlighter' |
| 178 |
], |
| 179 |
[ |
| 180 |
'type' => 'border_radius', |
| 181 |
'selector' => '.lqd-code-highlighter' |
| 182 |
], |
| 183 |
[ |
| 184 |
'type' => 'box_shadow', |
| 185 |
'selector' => '.lqd-code-highlighter' |
| 186 |
], |
| 187 |
[ |
| 188 |
'type' => 'text_shadow', |
| 189 |
'selector' => '.lqd-code-highlighter code' |
| 190 |
], |
| 191 |
], |
| 192 |
'plural_heading' => false, |
| 193 |
'state_tabs' => [ 'normal', 'hover' ], |
| 194 |
'state_selectors_before' => [ 'hover' => '{{WRAPPER}}' ] |
| 195 |
], |
| 196 |
], |
| 197 |
); |
| 198 |
} |
| 199 |
|
| 200 |
} |
| 201 |
|
| 202 |
protected function render() { |
| 203 |
|
| 204 |
$settings = $this->get_settings_for_display(); |
| 205 |
extract( $settings ); |
| 206 |
|
| 207 |
$this->add_render_attribute( 'div_wrapper', 'class', 'theme-' . $settings['theme'] ); |
| 208 |
|
| 209 |
$this->add_render_attribute( 'code_wrapper', 'class', 'language-' . $settings['language'] ); |
| 210 |
if ( $line_numbers ) $this->add_render_attribute( 'code_wrapper', 'class', $line_numbers ); |
| 211 |
|
| 212 |
$this->add_render_attribute( 'pre_wrapper', 'class', 'lqd-code-highlighter' ); |
| 213 |
//if ( $copy_to_clipboard ) $this->add_render_attribute( 'pre_wrapper', 'class', $copy_to_clipboard ); |
| 214 |
if ( $line_highlight ) $this->add_render_attribute( 'pre_wrapper', 'data-line', $line_highlight ); |
| 215 |
|
| 216 |
?> |
| 217 |
<div <?php $this->print_render_attribute_string( 'div_wrapper' ); ?>> |
| 218 |
<pre <?php $this->print_render_attribute_string( 'pre_wrapper' ); ?>><code <?php $this->print_render_attribute_string( 'code_wrapper' ); ?>><?php echo esc_html( $settings['code'] ); ?></code></pre> |
| 219 |
</div> |
| 220 |
<?php |
| 221 |
|
| 222 |
} |
| 223 |
|
| 224 |
} |
| 225 |
\Elementor\Plugin::instance()->widgets_manager->register( new Code_Highlighter() ); |
| 226 |
|