AesopInteractive /
lasso
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * |
||
| 4 | * |
||
| 5 | * @package Editus |
||
| 6 | * @author Hyun Supul <[email protected]>, Nick Haskins <[email protected]> |
||
| 7 | * @link http://edituswp.com |
||
| 8 | * @copyright 2015-2021 Aesopinteractive |
||
| 9 | * |
||
| 10 | * Plugin Name: Editus |
||
| 11 | * Plugin URI: http://edituswp.com |
||
| 12 | * Description: Front-end editor and story builder. |
||
| 13 | * Version: 1.3.7 |
||
| 14 | * Author: Aesopinteractive |
||
| 15 | * Author URI: http://aesopinteractive.com |
||
| 16 | * Text Domain: lasso |
||
| 17 | * Domain Path: /languages |
||
| 18 | */ |
||
| 19 | |||
| 20 | // If this file is called directly, abort. |
||
| 21 | if ( ! defined( 'WPINC' ) ) { |
||
| 22 | die; |
||
| 23 | } |
||
| 24 | |||
| 25 | // Set some constants |
||
| 26 | define( 'LASSO_VERSION', '1.3.7' ); |
||
| 27 | define( 'LASSO_DIR', plugin_dir_path( __FILE__ ) ); |
||
| 28 | define( 'LASSO_URL', plugins_url( '', __FILE__ ) ); |
||
| 29 | define( 'LASSO_FILE', __FILE__ ); |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Load plugin if PHP version is 5.4 or later. |
||
| 33 | */ |
||
| 34 | if ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ) { |
||
| 35 | |||
| 36 | include_once( LASSO_DIR . '/bootstrap.php' ); |
||
| 37 | |||
| 38 | } else { |
||
| 39 | |||
| 40 | add_action('admin_head', 'lasso_fail_notice'); |
||
| 41 | function lasso_fail_notice(){ |
||
| 42 | |||
| 43 | printf('<div class="error"><p>Editus requires PHP 5.4 or higher.</p></div>'); |
||
| 44 | |||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | add_filter('register_post_type_args', 'lasso_show_in_rest', 10, 2); |
||
| 49 | function lasso_show_in_rest($args, $post_type){ |
||
| 50 | |||
| 51 | $allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( ) ); |
||
| 52 | $allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types ); |
||
| 53 | if (in_array( $post_type,$allowed_post_types)) { |
||
| 54 | $args['show_in_rest'] = true; |
||
| 55 | if ($post_type != 'post' && $post_type != 'page') { |
||
| 56 | $args['rest_base'] = $post_type; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | return $args; |
||
| 61 | } |
||
| 62 | |||
| 63 | |||
| 64 | View Code Duplication | function lasso_editor_get_option( $option, $section, $default = '' ) { |
|
| 65 | |||
| 66 | if ( empty( $option ) ) |
||
| 67 | return; |
||
| 68 | |||
| 69 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
||
| 70 | |||
| 71 | $options = get_site_option( $section ); |
||
| 72 | |||
| 73 | } else { |
||
| 74 | |||
| 75 | $options = get_option( $section ); |
||
| 76 | } |
||
| 77 | |||
| 78 | if ( isset( $options[$option] ) ) { |
||
| 79 | return $options[$option]; |
||
| 80 | } |
||
| 81 | |||
| 82 | return $default; |
||
| 83 | } |
||
| 84 | |||
| 85 | register_meta('user', 'lasso_hide_tour', array( |
||
| 86 | "type" => "string", |
||
| 87 | "show_in_rest" => true // this is the key part |
||
| 88 | )); |
||
| 89 | |||
| 90 | // Gutenberg |
||
| 91 | if( function_exists( 'is_gutenberg_page' ) ) { |
||
| 92 | function add_raw_to_post( $response, $post, $request ) { |
||
| 93 | $response_data = $response->get_data(); |
||
| 94 | if ( is_array( $response_data['content'] )) { |
||
| 95 | $response_data['content']['raw'] = $post->post_content ; |
||
| 96 | $response->set_data( $response_data ); |
||
| 97 | } |
||
| 98 | |||
| 99 | return $response; |
||
| 100 | } |
||
| 101 | add_filter( "rest_prepare_post", 'add_raw_to_post', 10, 3 ); |
||
| 102 | } |
||
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | //table codes to be added |
||
| 107 | class editus_table { |
||
| 108 | |||
| 109 | public function __construct(){ |
||
| 110 | $add_table = lasso_editor_get_option('add_table', 'lasso_editor', false); |
||
| 111 | if ($add_table) { |
||
| 112 | add_action('wp_enqueue_scripts', array($this,'scripts')); |
||
| 113 | |||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | function scripts() |
||
| 118 | { |
||
| 119 | add_action('lasso_editor_controls_after_outside', array($this,'editus_table_edit_menu')); |
||
| 120 | add_filter('lasso_components',array($this,'editus_components_add_table'),10,1); |
||
| 121 | add_action( 'lasso_toolbar_components', array($this,'editus_toolbar_components_add_table'), 10 ); |
||
| 122 | wp_enqueue_style( 'editus-table-style', LASSO_URL. '/public/assets/css/editus-table-edit-public.css', LASSO_VERSION, true ); |
||
| 123 | wp_enqueue_script( 'editus_table', LASSO_URL. '/public/assets/js/editus-table-edit-public.js', array( 'jquery' ), LASSO_VERSION, true ); |
||
| 124 | } |
||
| 125 | |||
| 126 | function editus_table_edit_menu() |
||
| 127 | { ?> |
||
| 128 | |||
| 129 | <ul class='editus-table-menu'> |
||
| 130 | <li data-action="insertcol"><?php echo __('Insert Column','lasso')?></li> |
||
| 131 | <li data-action="insertrow"><?php echo __('Insert Row','lasso')?></li> |
||
| 132 | <li data-action="delcol"><?php echo __('Delete Column','lasso')?></li> |
||
| 133 | <li data-action="delrow"><?php echo __('Delete Row','lasso')?></li> |
||
| 134 | <li data-action="deltable"><?php echo __('Delete Table','lasso')?></li |
||
| 135 | </ul> |
||
| 136 | <?php |
||
| 137 | } |
||
| 138 | |||
| 139 | |||
| 140 | function editus_html_table() |
||
| 141 | { |
||
| 142 | return '<figure class="wp-block-table"><table><tr><th>Cell 1</th><th>Cell 2</th></tr><tr><td>Cell 3</td><td>Cell 4</td></tr></table></figure><p><br></p>'; |
||
| 143 | } |
||
| 144 | |||
| 145 | |||
| 146 | View Code Duplication | function editus_components_add_table( $array ){ |
|
|
0 ignored issues
–
show
|
|||
| 147 | $custom = array( |
||
| 148 | 'htmltable' => array( |
||
| 149 | 'name' => __('HTML Table','lasso'), |
||
| 150 | 'content' => self::editus_html_table(), |
||
| 151 | ) |
||
| 152 | ); |
||
| 153 | return array_merge( $array, $custom ); |
||
| 154 | } |
||
| 155 | |||
| 156 | |||
| 157 | function editus_toolbar_components_add_table( ) { |
||
| 158 | ?> |
||
| 159 | <li data-type="htmltable" title="<?php esc_attr_e( 'HTML Table', 'lasso' );?>" class="quote lasso-toolbar--component__htmltable dashicons dashicons-grid-view"></li> |
||
| 160 | <?php |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | |||
| 165 | new editus_table(); |
||
| 166 | |||
| 167 | |||
| 168 | |||
| 169 | //table codes to be added |
||
| 170 | class editus_paragraph { |
||
| 171 | |||
| 172 | public function __construct(){ |
||
| 173 | add_action('wp_enqueue_scripts', array($this,'scripts')); |
||
| 174 | } |
||
| 175 | |||
| 176 | function scripts() |
||
|
0 ignored issues
–
show
|
|||
| 177 | { |
||
| 178 | add_action('lasso_editor_controls_after_outside', array($this,'editus_paragraph_style')); |
||
| 179 | add_filter('lasso_components',array($this,'editus_components_add_paragraph'),10,1); |
||
| 180 | add_action( 'lasso_toolbar_components', array($this,'editus_toolbar_components_add_paragraph'), 10 ); |
||
| 181 | //wp_enqueue_style( 'editus-table-style', LASSO_URL. '/public/assets/css/editus-table-edit-public.css', LASSO_VERSION, true ); |
||
| 182 | //wp_enqueue_script( 'editus_table', LASSO_URL. '/public/assets/js/editus-table-edit-public.js', array( 'jquery' ), LASSO_VERSION, true ); |
||
| 183 | } |
||
| 184 | |||
| 185 | View Code Duplication | function editus_components_add_paragraph( $array ){ |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 186 | $custom = array( |
||
| 187 | 'htmlparagraph' => array( |
||
| 188 | 'name' => __('HTML Paragraph','lasso'), |
||
| 189 | 'content' => self::editus_html_paragraph(), |
||
| 190 | ) |
||
| 191 | ); |
||
| 192 | return array_merge( $array, $custom ); |
||
| 193 | } |
||
| 194 | |||
| 195 | |||
| 196 | function editus_html_paragraph() |
||
|
0 ignored issues
–
show
|
|||
| 197 | { |
||
| 198 | return '<p contenteditable="true"><br></p>'; |
||
| 199 | } |
||
| 200 | |||
| 201 | function editus_paragraph_style() |
||
|
0 ignored issues
–
show
|
|||
| 202 | { ?> |
||
| 203 | <style> |
||
| 204 | #lasso-toolbar--components__list .lasso-toolbar--component__htmlparagraph:before |
||
| 205 | { |
||
| 206 | content: "\f476"; |
||
| 207 | font-family: 'dashicons' !important; |
||
| 208 | } |
||
| 209 | </style> |
||
| 210 | <?php |
||
| 211 | } |
||
| 212 | |||
| 213 | |||
| 214 | function editus_toolbar_components_add_paragraph( ) { |
||
|
0 ignored issues
–
show
|
|||
| 215 | ?> |
||
| 216 | <li data-type="htmlparagraph" title="<?php esc_attr_e( 'HTML Paragraph', 'lasso' );?>" class="quote lasso-toolbar--component__htmlparagraph dashicons dashicons-editor-paragraph"></li> |
||
| 217 | <?php |
||
| 218 | } |
||
| 219 | } |
||
| 220 | |||
| 221 | //Disable it for now |
||
| 222 | //new editus_paragraph(); |
||
| 223 | |||
| 224 | |||
| 225 | |||
| 226 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.