Code_Manager.php
1 year ago
Code_Manager_Dashboard.php
1 year ago
Code_Manager_Export.php
1 year ago
Code_Manager_Form.php
1 year ago
Code_Manager_Import.php
1 year ago
Code_Manager_Import_File.php
1 year ago
Code_Manager_List.php
1 year ago
Code_Manager_List_View.php
1 year ago
Code_Manager_Model.php
1 year ago
Code_Manager_Preview.php
1 year ago
Code_Manager_Settings.php
1 year ago
Code_Manager_Tabs.php
1 year ago
Message_Box.php
1 year ago
WP_List_Table.php
1 year ago
Code_Manager_Tabs.php
198 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Code Manager tab mode |
| 5 | * |
| 6 | * @package Code_Manager |
| 7 | */ |
| 8 | namespace Code_Manager; |
| 9 | |
| 10 | /** |
| 11 | * Class Code_Manager_Tabs |
| 12 | * |
| 13 | * Builds the Code Manager tab mode IDE |
| 14 | * |
| 15 | * @author Peter Schulz |
| 16 | * @since 1.0.0 |
| 17 | */ |
| 18 | class Code_Manager_Tabs { |
| 19 | /** |
| 20 | * Nonce using user login |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | protected $wpnonce; |
| 25 | |
| 26 | /** |
| 27 | * Nonce used to get code from user login |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | protected $wpnonce_get_code; |
| 32 | |
| 33 | /** |
| 34 | * Code_Manager_Tabs constructor |
| 35 | * |
| 36 | * Creates a number of wpnonces needed to authorize ajax calls |
| 37 | * |
| 38 | * @since 1.0.0 |
| 39 | */ |
| 40 | public function __construct() { |
| 41 | $this->wpnonce = wp_create_nonce( 'code-manager-' . Code_manager::get_current_user_login() ); |
| 42 | $this->wpnonce_get_code = wp_create_nonce( 'code-manager-get-code' . Code_manager::get_current_user_login() ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Shows the tab mode IDE |
| 47 | * |
| 48 | * JavaScript depending on server variables not available in the browser are added here. Generic JavaScript |
| 49 | * code is added as a script file. |
| 50 | * |
| 51 | * @since 1.0.0 |
| 52 | */ |
| 53 | public function show() { |
| 54 | $cm_message = Code_Manager::get_cm_message(); |
| 55 | ?> |
| 56 | <script type="text/javascript"> |
| 57 | var wpnonce = '<?php |
| 58 | echo esc_attr( $this->wpnonce ); |
| 59 | ?>'; |
| 60 | var wpnonce_get_code = '<?php |
| 61 | echo esc_attr( $this->wpnonce_get_code ); |
| 62 | ?>'; |
| 63 | var code_manager_code_groups = []; |
| 64 | <?php |
| 65 | $code_manager_tab = new Code_Manager_Tabs(); |
| 66 | $code_types = $code_manager_tab->get_code_types(); |
| 67 | foreach ( $code_types as $code_type_group => $value ) { |
| 68 | echo 'code_manager_code_group = [];'; |
| 69 | foreach ( $value as $code_type => $code_type_label ) { |
| 70 | echo "code_manager_code_group['" . esc_attr( $code_type ) . "'] = '" . esc_attr( $code_type_label ) . "';"; |
| 71 | } |
| 72 | echo "code_manager_code_groups['" . esc_attr( $code_type_group ) . "'] = code_manager_code_group;"; |
| 73 | } |
| 74 | ?> |
| 75 | function filter_code_list() { |
| 76 | jQuery("#code_manager_code_list > option").each(function() { |
| 77 | showCode = true; |
| 78 | if (jQuery("#code_manager_filter_code_type").val()!=="") { |
| 79 | if (jQuery("#code_manager_filter_code_type").val()!==jQuery(this).data("type")) { |
| 80 | jQuery(this).hide(); |
| 81 | showCode = false; |
| 82 | } |
| 83 | } |
| 84 | if (showCode && jQuery("#code_manager_filter_code_name").val()!=="") { |
| 85 | if (!jQuery(this).data("name").toLowerCase().includes(jQuery("#code_manager_filter_code_name").val().toLowerCase())) { |
| 86 | jQuery(this).hide(); |
| 87 | showCode = false; |
| 88 | } |
| 89 | } |
| 90 | if (showCode) { |
| 91 | jQuery(this).show(); |
| 92 | } |
| 93 | }); |
| 94 | } |
| 95 | <?php |
| 96 | if ( 'hide' !== $cm_message ) { |
| 97 | ?> |
| 98 | jQuery(function() { |
| 99 | cm_warning(); |
| 100 | }); |
| 101 | <?php |
| 102 | } |
| 103 | ?> |
| 104 | </script> |
| 105 | <div class="wrap"> |
| 106 | <table cellspacing="0" cellpadding="0" border="0" width="100%"> |
| 107 | <tr> |
| 108 | <td> |
| 109 | <h1 class="wp-heading-inline"> |
| 110 | <?php |
| 111 | echo 'Code Manager'; |
| 112 | echo ' - tab mode'; |
| 113 | ?> |
| 114 | </h1> |
| 115 | </td> |
| 116 | <td style="text-align:right;padding-right:10px;padding-top:4px"> |
| 117 | <a id="disable_preview" |
| 118 | href="javascript:void(0)" |
| 119 | class="fas fa-eye-slash cm_menu_title" |
| 120 | style="line-height: 30px; text-decoration: none" |
| 121 | title="Turn of preview mode for all code IDs" |
| 122 | ></a> |
| 123 | </td> |
| 124 | </tr> |
| 125 | </table> |
| 126 | <style> |
| 127 | #code_manager_code_list { |
| 128 | background-image: none; |
| 129 | min-width: 100%; |
| 130 | width: 100%; |
| 131 | max-width: 100%; |
| 132 | font-family: monospace; |
| 133 | font-size: 90%; |
| 134 | } |
| 135 | #code_manager_code_list option { |
| 136 | width: 100%; |
| 137 | } |
| 138 | </style> |
| 139 | <div id="code_manager_open_frame" style="display: none; background-color: transparent;"> |
| 140 | <p style="margin-top:0">Hold ctrl key to select multiple code blocks, double click to select single code block</p> |
| 141 | <div style="margin-right:-2px"> |
| 142 | <span> |
| 143 | <input type="text" placeholder="Filter code name" id="code_manager_filter_code_name" onkeyup="filter_code_list()" autocomplete="off"/> |
| 144 | </span> |
| 145 | <span style="float: right"> |
| 146 | <select id="code_manager_filter_code_type" onchange="filter_code_list()"></select> |
| 147 | </span> |
| 148 | </div> |
| 149 | <div> |
| 150 | <select id="code_manager_code_list" size="14" multiple="multiple"> |
| 151 | <option>Loading data...</option> |
| 152 | </select> |
| 153 | </div> |
| 154 | </div> |
| 155 | <div id="code_manager_taskbar_tabmode" class="nav-tab-wrapper"></div> |
| 156 | <div id="code_manager_workspace_tabmode"></div> |
| 157 | <div class="cm_tab_mode_intro"> |
| 158 | <p> |
| 159 | <i class="fas fa-hand-point-right"></i> |
| 160 | Press the "add new code" icon in the toolbar to start writing new code |
| 161 | </p> |
| 162 | <p> |
| 163 | <i class="fas fa-hand-point-right"></i> |
| 164 | Press the "open existing code" icon in the toolbar to change existing code |
| 165 | </p> |
| 166 | <div class="cm_tab_mode_intro_close"> |
| 167 | <a href="#" onclick="javascript:jQuery('.cm_tab_mode_intro').remove()"> |
| 168 | <i class="fas fa-times-circle"></i> |
| 169 | </a> |
| 170 | </div> |
| 171 | </div> |
| 172 | </div> |
| 173 | <?php |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Get code types |
| 178 | * |
| 179 | * Code types are organized in group to allow grouping in list boxes. |
| 180 | * |
| 181 | * @since 1.0.0 |
| 182 | * |
| 183 | * @return string[][] |
| 184 | */ |
| 185 | public function get_code_types() { |
| 186 | $code_types = array( |
| 187 | 'Shortcodes' => array( |
| 188 | 'php shortcode' => 'PHP Shortcode', |
| 189 | 'javascript shortcode' => 'JavaScript Shortcode', |
| 190 | 'css shortcode' => 'CSS Shortcode', |
| 191 | 'html shortcode' => 'HTML Shortcode', |
| 192 | ), |
| 193 | ); |
| 194 | return $code_types; |
| 195 | } |
| 196 | |
| 197 | } |
| 198 |