Pyrometric /
UIX
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * UIX Control |
||
| 4 | * |
||
| 5 | * @package controls |
||
| 6 | * @author David Cramer |
||
| 7 | * @license GPL-2.0+ |
||
| 8 | * @link |
||
| 9 | * @copyright 2016 David Cramer |
||
| 10 | */ |
||
| 11 | namespace uix\ui\control; |
||
| 12 | |||
| 13 | use uix\ui\modal; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Layout Grid Editor |
||
| 17 | * |
||
| 18 | * @since 1.0.0 |
||
| 19 | */ |
||
| 20 | class layout extends \uix\ui\control { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The type of object |
||
| 24 | * |
||
| 25 | * @since 1.0.0 |
||
| 26 | * @access public |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | public $type = 'layout'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * The component modals |
||
| 33 | * |
||
| 34 | * @since 1.0.0 |
||
| 35 | * @access public |
||
| 36 | * @var array |
||
| 37 | */ |
||
| 38 | public $modals = array(); |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Autoload Children - Checks structure for nested structures |
||
| 42 | * |
||
| 43 | * @since 1.0.0 |
||
| 44 | * @access public |
||
| 45 | */ |
||
| 46 | 1 | public function setup() { |
|
| 47 | |||
| 48 | // create components |
||
| 49 | 1 | if ( ! empty( $this->struct['component'] ) ) { |
|
| 50 | $this->register_components(); |
||
| 51 | } |
||
| 52 | |||
| 53 | 1 | foreach ( $this->modals as $modal ) { |
|
| 54 | |||
| 55 | if ( $modal->is_submitted() ) { |
||
| 56 | wp_send_json_success( $modal->get_value() ); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | 1 | parent::setup(); |
|
| 61 | 1 | } |
|
| 62 | |||
| 63 | |||
| 64 | /** |
||
| 65 | * register components for layout |
||
| 66 | * |
||
| 67 | * @since 1.0.0 |
||
| 68 | * @access public |
||
| 69 | */ |
||
| 70 | public function register_components() { |
||
| 71 | |||
| 72 | foreach ( $this->struct['component'] as $component_id => $component_struct ) { |
||
| 73 | |||
| 74 | if ( ! empty( $component_struct['id'] ) ) { |
||
| 75 | $component_id = $component_struct['id']; |
||
| 76 | } |
||
| 77 | |||
| 78 | $component_struct += array( |
||
| 79 | 'attributes' => array( |
||
| 80 | 'data-master' => true, |
||
| 81 | 'style' => 'margin:6px 0 0 6px;', |
||
| 82 | ), |
||
| 83 | 'footer' => array( |
||
| 84 | 'id' => $component_id . '_foot', |
||
| 85 | 'control' => array( |
||
| 86 | 'set_component' => array( |
||
| 87 | 'label' => 'Send to Layout', |
||
| 88 | 'type' => 'button', |
||
| 89 | 'attributes' => array( |
||
| 90 | 'type' => 'submit', |
||
| 91 | ), |
||
| 92 | ), |
||
| 93 | ), |
||
| 94 | ), |
||
| 95 | ); |
||
| 96 | |||
| 97 | if ( ! empty( $component_struct['setup'] ) ) { |
||
| 98 | $component_struct['section'] = $component_struct['setup']; |
||
| 99 | unset( $component_struct['setup'] ); |
||
| 100 | } |
||
| 101 | |||
| 102 | $this->modals[] = $this->modal( $component_id, $component_struct ); |
||
|
0 ignored issues
–
show
|
|||
| 103 | } |
||
| 104 | |||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Define core UIX scripts - override to register core ( common scripts for uix type ) |
||
| 109 | * |
||
| 110 | * @since 1.0.0 |
||
| 111 | * @access public |
||
| 112 | */ |
||
| 113 | 1 | public function set_assets() { |
|
| 114 | |||
| 115 | // set style |
||
| 116 | 1 | $this->assets['style']['layout'] = $this->url . 'assets/controls/layout/css/layout' . UIX_ASSET_DEBUG . '.css'; |
|
| 117 | 1 | $this->assets['style']['layout-grid'] = $this->url . 'assets/controls/layout/css/layout-grid' . UIX_ASSET_DEBUG . '.css'; |
|
| 118 | |||
| 119 | // push to register script |
||
| 120 | 1 | $this->assets['script']['layout'] = array( |
|
| 121 | 1 | 'src' => $this->url . 'assets/controls/layout/js/layout' . UIX_ASSET_DEBUG . '.js', |
|
| 122 | 'deps' => array( |
||
| 123 | 'jquery-ui-draggable', |
||
| 124 | 'jquery-ui-droppable', |
||
| 125 | 'jquery-ui-sortable', |
||
| 126 | ), |
||
| 127 | 'in_footer' => true, |
||
| 128 | ); |
||
| 129 | 1 | $this->assets['script']['handlebars'] = array( |
|
| 130 | 1 | 'src' => $this->url . 'assets/js/handlebars-latest' . UIX_ASSET_DEBUG . '.js', |
|
| 131 | ); |
||
| 132 | 1 | $this->assets['script']['baldrick-handlebars'] = array( |
|
| 133 | 1 | 'src' => $this->url . 'assets/js/handlebars.baldrick' . UIX_ASSET_DEBUG . '.js', |
|
| 134 | 'deps' => array( 'baldrick' ), |
||
| 135 | ); |
||
| 136 | |||
| 137 | // modals |
||
| 138 | 1 | $this->assets['script']['modals'] = array( |
|
| 139 | 1 | 'src' => $this->url . 'assets/js/modals' . UIX_ASSET_DEBUG . '.js', |
|
| 140 | 'deps' => array( 'baldrick' ), |
||
| 141 | ); |
||
| 142 | 1 | $this->assets['style']['modals'] = $this->url . 'assets/css/modals' . UIX_ASSET_DEBUG . '.css'; |
|
| 143 | |||
| 144 | |||
| 145 | 1 | parent::set_assets(); |
|
| 146 | 1 | } |
|
| 147 | |||
| 148 | /** |
||
| 149 | * Gets the attributes for the control. |
||
| 150 | * |
||
| 151 | * @since 1.0.0 |
||
| 152 | * @access public |
||
| 153 | */ |
||
| 154 | 1 | public function set_attributes() { |
|
| 155 | |||
| 156 | 1 | parent::set_attributes(); |
|
| 157 | 1 | $this->attributes['class'] = 'hidden'; |
|
| 158 | |||
| 159 | 1 | } |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Render the Control |
||
| 163 | * |
||
| 164 | * @since 1.0.0 |
||
| 165 | * @see \uix\ui\uix |
||
| 166 | * @access public |
||
| 167 | * @return string HTML of rendered control |
||
| 168 | */ |
||
| 169 | 1 | public function render() { |
|
| 170 | |||
| 171 | 1 | $output = '<div id="' . esc_attr( $this->id() ) . '" data-color="' . esc_attr( $this->base_color() ) . '" data-for="' . esc_attr( $this->id() ) . '-control" class="uix-control uix-control-' . esc_attr( $this->type ) . ' ' . esc_attr( $this->id() ) . '"></div>'; |
|
| 172 | 1 | $output .= $this->label(); |
|
| 173 | 1 | $output .= $this->input(); |
|
| 174 | |||
| 175 | 1 | $output .= $this->component_templates(); |
|
| 176 | |||
| 177 | 1 | $output .= $this->modal_template(); |
|
| 178 | |||
| 179 | 1 | return $output; |
|
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Returns the label for the control |
||
| 184 | * |
||
| 185 | * @since 1.0.0 |
||
| 186 | * @access public |
||
| 187 | * @return string label of control |
||
| 188 | */ |
||
| 189 | 1 | View Code Duplication | public function label() { |
|
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...
|
|||
| 190 | 1 | $output = null; |
|
| 191 | 1 | if ( isset( $this->struct['label'] ) ) { |
|
| 192 | 1 | $output .= '<label for="' . esc_attr( $this->id() ) . '-control" class="uix-add-row"><span class="uix-control-label">' . esc_html( $this->struct['label'] ) . '</span></label>'; |
|
| 193 | } |
||
| 194 | |||
| 195 | 1 | return $output; |
|
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Returns the main input field for rendering |
||
| 200 | * |
||
| 201 | * @since 1.0.0 |
||
| 202 | * @see \uix\ui\uix |
||
| 203 | * @access public |
||
| 204 | * @return string Input field HTML striung |
||
| 205 | */ |
||
| 206 | 1 | public function input() { |
|
| 207 | 1 | return '<input type="hidden" value="' . esc_attr( $this->get_value() ) . '" ' . $this->build_attributes() . '>'; |
|
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Render component templates |
||
| 212 | * |
||
| 213 | * @since 1.0.0 |
||
| 214 | * @see \uix\ui\uix |
||
| 215 | * @access public |
||
| 216 | * @return string HTML of templates for components |
||
| 217 | */ |
||
| 218 | 1 | public function component_templates() { |
|
| 219 | 1 | $output = null; |
|
| 220 | 1 | foreach ( $this->modals as $modal ) { |
|
| 221 | |||
| 222 | $width = 'data-width="950"'; |
||
| 223 | $height = 'data-height="550"'; |
||
| 224 | |||
| 225 | $output .= '<script type="text/html" ' . $width . ' ' . $height . ' id="' . esc_attr( $this->id() ) . '-' . esc_attr( $modal->slug ) . '">'; |
||
| 226 | if ( isset( $modal->struct['preview'] ) ) { |
||
| 227 | $template = uix()->add( 'control', $modal->slug, array( |
||
| 228 | 'type' => 'template', |
||
| 229 | 'template' => $modal->struct['preview'], |
||
| 230 | ) ); |
||
| 231 | |||
| 232 | $output .= $template->render(); |
||
| 233 | } else { |
||
| 234 | $output .= '<div>' . $modal->struct['label'] . '</div>'; |
||
| 235 | } |
||
| 236 | $output .= '</script>'; |
||
| 237 | |||
| 238 | } |
||
| 239 | |||
| 240 | 1 | return $output; |
|
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Render the modal template |
||
| 245 | * |
||
| 246 | * @since 1.0.0 |
||
| 247 | * @see \uix\ui\uix |
||
| 248 | * @access public |
||
| 249 | * @return string HTML of modals templates |
||
| 250 | */ |
||
| 251 | 1 | public function modal_template() { |
|
| 252 | |||
| 253 | 1 | $output = '<script type="text/html" id="' . esc_attr( $this->id() ) . '-components">'; |
|
| 254 | 1 | foreach ( $this->modals as $modal ) { |
|
| 255 | |||
| 256 | $label = $modal->struct['label']; |
||
| 257 | $data = $modal->get_data(); |
||
| 258 | $data_template = $this->drill_in( $data[ $modal->slug ], '{{@root' ); |
||
| 259 | $modal->set_data( array( $modal->slug => $data_template ) ); |
||
| 260 | |||
| 261 | $modal->render(); |
||
| 262 | |||
| 263 | $setup = null; |
||
| 264 | if ( count( $modal->child ) > 1 ) { |
||
| 265 | $setup = ' data-setup="true" '; |
||
| 266 | } |
||
| 267 | |||
| 268 | $output .= '<button type="button" class="button uix-component-trigger" style="margin:12px 0 0 12px;" data-label="' . esc_attr( $modal->attributes['data-title'] ) . '" data-type="' . $modal->slug . '" ' . $setup . ' data-id="' . esc_attr( $modal->id() ) . '">' . $label . '</button> '; |
||
| 269 | |||
| 270 | } |
||
| 271 | 1 | $output .= '</script>'; |
|
| 272 | |||
| 273 | 1 | return $output; |
|
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * builds the handlebars based structure for template render |
||
| 278 | * |
||
| 279 | * @param array $array the dat astructure to drill into |
||
| 280 | * @param string $tag the final tag to replace the data with. |
||
| 281 | * @since 1.0.0 |
||
| 282 | * @access public |
||
| 283 | * @return array array of the data structure |
||
| 284 | */ |
||
| 285 | View Code Duplication | public function drill_in( $array, $tag = null ) { |
|
|
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...
|
|||
| 286 | $back = array(); |
||
| 287 | foreach ( $array as $key => $value ) { |
||
| 288 | if ( is_array( $value ) && ! empty( $value ) ) { |
||
| 289 | $back[ $key ] = $this->drill_in( $value, $tag . '.' . $key ); |
||
| 290 | } else { |
||
| 291 | $back[ $key ] = $tag . '.' . $key . '}}'; |
||
| 292 | } |
||
| 293 | } |
||
| 294 | |||
| 295 | return $back; |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Sets styling colors |
||
| 300 | * |
||
| 301 | * @since 1.0.0 |
||
| 302 | * @access protected |
||
| 303 | */ |
||
| 304 | protected function set_active_styles() { |
||
| 305 | |||
| 306 | $style = '.' . $this->id() . ' .dashicons.dashicons-plus-alt{ color: ' . $this->base_color() . ' !important;}'; |
||
| 307 | $style .= '.' . $this->id() . ' .column-handle{background-color: ' . $this->base_color() . ' !important;}'; |
||
| 308 | $style .= '.' . $this->id() . ' .uix-component-toolbar{background-color: ' . $this->base_color() . ' !important;}'; |
||
| 309 | |||
| 310 | uix_share()->set_active_styles( $style ); |
||
| 311 | } |
||
| 312 | } |
||
| 313 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: