| 1 |
<?php |
| 2 |
defined('ABSPATH') or die('No direct access permitted'); |
| 3 |
$blockClass["responsive"] = "responsiveBlock"; |
| 4 |
$blockOrder[90][] = "responsive"; |
| 5 |
|
| 6 |
class responsiveBlock extends maxBlock |
| 7 |
{ |
| 8 |
protected $blockname = 'responsive'; |
| 9 |
protected $fields = array("options" => '', |
| 10 |
"auto_responsive" => array("default" => 0), |
| 11 |
"media_query" => array("default" => array() |
| 12 |
), |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
); |
| 17 |
// multifields for manual conversion // define +/- the same as normal fields. |
| 18 |
// to find solution in parsing stuff back to button. |
| 19 |
protected $multi_fields = array("mq_button_width" => array("default" => 0, |
| 20 |
"css" => "width", |
| 21 |
"csspseudo" => "responsive", |
| 22 |
|
| 23 |
), |
| 24 |
"mq_button_width_unit" => array("default" => 'px', |
| 25 |
"css" => "width_unit", |
| 26 |
"csspseudo" => "responsive", |
| 27 |
), |
| 28 |
"mq_container_width" => array("default" => 0, |
| 29 |
"css" => "width", |
| 30 |
"csspart" => "mb-container", |
| 31 |
"csspseudo" => "responsive", |
| 32 |
), |
| 33 |
"mq_container_float" => array("default" => "", |
| 34 |
"css" => "float", |
| 35 |
"csspart" => "mb-container", |
| 36 |
"csspseudo" => "responsive", |
| 37 |
), |
| 38 |
"mq_container_width_unit" => array("default" => "px", |
| 39 |
"css" => "width_unit", |
| 40 |
"csspart" => "mb-container", |
| 41 |
), |
| 42 |
"mq_font_size" => array("default" => 90, |
| 43 |
"css" => "font-size", |
| 44 |
"csspart" => "mb-text", |
| 45 |
), |
| 46 |
"mq_font_size_unit" => array("default" => "%", |
| 47 |
"css" => "font-size_unit", |
| 48 |
"csspart" => "mb-text"), |
| 49 |
|
| 50 |
"mq_custom_minwidth" => array("default" => "0", |
| 51 |
"css" => "custom_minwidth"), |
| 52 |
"mq_custom_maxwidth" => array("default" => "0", |
| 53 |
"css" => "custom_maxwidth"), |
| 54 |
"mq_hide" => array("default" => '', |
| 55 |
"css" => "display", |
| 56 |
"csspart" => "mb-container, maxbutton, mb-center", |
| 57 |
|
| 58 |
), |
| 59 |
); |
| 60 |
|
| 61 |
|
| 62 |
public function parse_css($css, $mode = 'normal') |
| 63 |
{ |
| 64 |
if ($mode != 'normal') |
| 65 |
return $css; |
| 66 |
|
| 67 |
if (! isset($this->data[$this->blockname])) |
| 68 |
return $css; |
| 69 |
|
| 70 |
$data = $this->data[$this->blockname]; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
if (isset($data["auto_responsive"]) && $data["auto_responsive"] == 1) |
| 75 |
{ // generate auto_rules for responsive. |
| 76 |
$css["maxbutton"]["responsive"]["phone"][0]["width"] = "90%"; |
| 77 |
$css["mb-container"]["responsive"]["phone"][0]["width"] = "90%"; |
| 78 |
$css["mb-container"]["responsive"]["phone"][0]["float"] = "none"; |
| 79 |
$css["mb-text"]["responsive"]["phone"][0]["font-size"] = "90%"; |
| 80 |
|
| 81 |
|
| 82 |
if ( isset($this->data["text"]["font_size"]) ) |
| 83 |
{ |
| 84 |
$css["mb-text"]["responsive"]["phone"][0]["font-size"] = floor(intval($this->data["text"]["font_size"]) * 0.8) . 'px'; |
| 85 |
} |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
if (! isset($data["media_query"])) |
| 90 |
return $css; |
| 91 |
|
| 92 |
foreach($data["media_query"] as $query => $data ): |
| 93 |
$i = 0; |
| 94 |
|
| 95 |
foreach($data as $index => $fields): |
| 96 |
|
| 97 |
|
| 98 |
foreach($fields as $field => $value) |
| 99 |
{ |
| 100 |
$csspart = (isset($this->multi_fields[$field]["csspart"])) ? explode(",",$this->multi_fields[$field]["csspart"]) : array('maxbutton') ; |
| 101 |
$css_stat = $this->multi_fields[$field]["css"]; |
| 102 |
|
| 103 |
|
| 104 |
if ($value == '' || $value == '0') |
| 105 |
{ } |
| 106 |
elseif ($query != 'custom' && ($field == 'mq_custom_maxwidth' || $field == "mq_custom_minwidth")) |
| 107 |
{ } // skip custom fields on noncustom query |
| 108 |
else |
| 109 |
{ |
| 110 |
foreach($csspart as $j => $part) |
| 111 |
{ |
| 112 |
|
| 113 |
$css[$part]["responsive"][$query][$i][$css_stat] = $value; |
| 114 |
} |
| 115 |
|
| 116 |
/* } |
| 117 |
else |
| 118 |
{ |
| 119 |
|
| 120 |
$css[$csspart]["responsive"][$query][$i][$css_stat] = $value; |
| 121 |
} */ |
| 122 |
} |
| 123 |
|
| 124 |
} |
| 125 |
$i++; |
| 126 |
endforeach; |
| 127 |
|
| 128 |
endforeach; |
| 129 |
|
| 130 |
return $css; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
public function save_fields($data, $post) |
| 135 |
{ |
| 136 |
|
| 137 |
$queries = (isset($post["media_query"])) ? $post["media_query"] : null; |
| 138 |
$media_queries = array(); |
| 139 |
|
| 140 |
if (is_null($queries)) |
| 141 |
return $data; |
| 142 |
|
| 143 |
foreach($queries as $i => $query) |
| 144 |
{ |
| 145 |
|
| 146 |
if ($query != '') |
| 147 |
{ |
| 148 |
//$media_queries[$query] = array(); |
| 149 |
|
| 150 |
// collect the other fields. |
| 151 |
$c = isset($media_queries[$query]) ? count($media_queries[$query]) : 0; |
| 152 |
|
| 153 |
foreach($this->multi_fields as $field => $values) |
| 154 |
{ |
| 155 |
$default = isset($values["default"]) ? $values["default"] : ''; |
| 156 |
|
| 157 |
if (isset($post[$field][$i])) |
| 158 |
{ |
| 159 |
$postval = $post[$field][$i]; |
| 160 |
if (is_numeric($default)) // sanitize. |
| 161 |
{ |
| 162 |
$postval = intval($postval); |
| 163 |
} |
| 164 |
else |
| 165 |
$value = sanitize_text_field($postval); |
| 166 |
|
| 167 |
$media_queries[$query][$c][$field] = $postval; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
$data[$this->blockname]["media_query"] = $media_queries; |
| 175 |
|
| 176 |
$data[$this->blockname]["auto_responsive"] = (isset($post["auto_responsive"])) ? $post["auto_responsive"] : 0; |
| 177 |
|
| 178 |
return $data; |
| 179 |
|
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
public function admin_fields() |
| 184 |
{ |
| 185 |
$data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array(); |
| 186 |
|
| 187 |
$media_names = maxUtils::get_media_query(1); // nicenames |
| 188 |
$media_desc = maxUtils::get_media_query(3); |
| 189 |
$units = array("px" => __("px","maxbuttons"), |
| 190 |
"%" => __("%","maxbuttons") |
| 191 |
); |
| 192 |
$container_floats = array( |
| 193 |
"" => "", |
| 194 |
"none" => __("None","maxbuttons"), |
| 195 |
"left" => __("Left","maxbuttons"), |
| 196 |
"right" => __("Right","maxbuttons"), |
| 197 |
); |
| 198 |
|
| 199 |
foreach($this->fields as $field => $options) |
| 200 |
{ |
| 201 |
$default = (isset($options["default"])) ? $options["default"] : ''; |
| 202 |
$$field = (isset($data[$field])) ? $data[$field] : $default; |
| 203 |
${$field . "_default"} = $default; |
| 204 |
} |
| 205 |
|
| 206 |
// sorting routine via array merge. |
| 207 |
$fk = array_flip(array_keys($media_query)); |
| 208 |
$names_used = array_intersect_key($media_names,$fk); |
| 209 |
$media_query = array_merge($names_used,$media_query); |
| 210 |
|
| 211 |
?> |
| 212 |
<div class="mb_tab option-container"> |
| 213 |
<div class="title"><?php _e('Responsive Settings', 'maxbuttons') ?></div> |
| 214 |
<div class="inside"> |
| 215 |
|
| 216 |
<div class="option-design"> |
| 217 |
<p class="note"><?php _e("Responsive settings let you decide the behavior of the button on different devices and screen sizes. For instance large buttons on small screens.","maxbuttons") ?></p> |
| 218 |
<label for='auto_responsive'><?php _e("Auto Responsive", 'maxbuttons') ?> <?php _e("(Experimental)","maxbuttons") ?></label> |
| 219 |
|
| 220 |
<div class="input checkbox"> |
| 221 |
<input type='checkbox' id='auto_responsive' name='auto_responsive' value='1' <?php checked(1, $auto_responsive); ?> > |
| 222 |
</div> |
| 223 |
|
| 224 |
<div class="clear"></div> |
| 225 |
<p class="note"><strong><?php _e("Note:","maxbuttons"); ?> </strong><?php _e(" Auto responsive settings will take a guess only on small screens. To control your responsive settings uncheck this button. This will show more options.","maxbuttons"); ?></p> |
| 226 |
</div> |
| 227 |
|
| 228 |
|
| 229 |
<div class='option-design media_queries_options'> |
| 230 |
<?php |
| 231 |
$i = 0 ; |
| 232 |
foreach($media_query as $item => $data): |
| 233 |
foreach ($data as $index => $fields): |
| 234 |
|
| 235 |
?> |
| 236 |
<div class='media_query' data-query="<?php echo $item ?>"> |
| 237 |
<span class='removebutton'><img src="<?php echo MB()->get_plugin_url() ?>/assets/icons/remove.png"></span> |
| 238 |
|
| 239 |
<input type="hidden" name="media_query[<?php echo $i ?>]" value="<?php echo $item ?>"> |
| 240 |
<label class='title'><?php echo $media_names[$item] ?></label> |
| 241 |
<p class='description'><?php echo $media_desc[$item] ?></p> |
| 242 |
<?php |
| 243 |
if ($item == "custom") { $custom_class = ''; } else { $custom_class = 'hidden'; } |
| 244 |
|
| 245 |
?> |
| 246 |
<div class="custom" <?php echo $custom_class ?> > |
| 247 |
<div class="label"><?php _e("Min width","maxbuttons") ?></div> |
| 248 |
<div class="input"><input type="text" class="tiny" name="mq_custom_minwidth[<?php echo $i ?>]" value="<?php echo $fields["mq_custom_minwidth"] ?>" />px</div> |
| 249 |
|
| 250 |
<div class="label max"> <?php _e("Max width","maxbuttons"); ?></div> |
| 251 |
<div class="input max"><input type="text" class="tiny" name="mq_custom_maxwidth[<?php echo $i ?>]" value="<?php echo $fields["mq_custom_maxwidth"] ?>" />px</div> |
| 252 |
|
| 253 |
|
| 254 |
</div> |
| 255 |
|
| 256 |
<div class='label'><?php _e("Font size","maxbuttons") ?></div> |
| 257 |
<div class='input'><input type='text' name='mq_font_size[<?php echo $i ?>]' class='tiny' value="<?php echo $fields["mq_font_size"] ?>"> <?php echo maxUtils::selectify("mq_font_size_unit[$i]",$units,$fields["mq_font_size_unit"]) ?> |
| 258 |
</div> |
| 259 |
|
| 260 |
<div class='label'><?php _e("Button width", 'maxbuttons') ?></div> |
| 261 |
|
| 262 |
<div class='input'><input type='text' name="mq_button_width[<?php echo $i ?>]" value="<?php echo $fields["mq_button_width"] ?>" class='tiny'> <?php echo maxUtils::selectify("mq_button_width_unit[$i]",$units,$fields["mq_button_width_unit"]) ?></div> |
| 263 |
|
| 264 |
<div class='label'><?php _e("Container width", 'maxbuttons'); ?></div> |
| 265 |
|
| 266 |
<div class='input'><input type='text' name="mq_container_width[<?php echo $i ?>]" value="<?php echo $fields["mq_container_width"] ?>" class='tiny'> <?php echo maxUtils::selectify("mq_container_width_unit[$i]",$units,$fields["mq_container_width_unit"]); ?> |
| 267 |
</div> |
| 268 |
|
| 269 |
<div class='label'><?php _e("Container float", "maxbuttons"); ?></div> |
| 270 |
<div class="input"><?php echo maxUtils::selectify("mq_container_float[$i]",$container_floats, $fields["mq_container_float"]) ?></div> |
| 271 |
|
| 272 |
<?php $mq_hide = (isset($fields["mq_hide"])) ? $fields["mq_hide"] : ''; ?> |
| 273 |
<div class="label"><?php _e("Hide button on this view","maxbuttons"); ?></div> |
| 274 |
<div class="input"> |
| 275 |
|
| 276 |
<input type="checkbox" name="mq_hide[<?php echo $i ?>]" value="none" <?php checked('none', $mq_hide ) ?> ></div> |
| 277 |
</div> |
| 278 |
|
| 279 |
<?php |
| 280 |
$i++; |
| 281 |
//if ($item != 'custom') |
| 282 |
// unset($media_names[$item]); // remove existing queries from new query selection |
| 283 |
endforeach; |
| 284 |
endforeach; |
| 285 |
|
| 286 |
|
| 287 |
?> |
| 288 |
|
| 289 |
<div class="new_query_space"></div> |
| 290 |
<div class="clear"></div> |
| 291 |
<div class="option-design new-query"> |
| 292 |
<label for='new_query'><?php _e('New Query', 'maxbuttons') ?></label> |
| 293 |
|
| 294 |
<div class="input"> |
| 295 |
<select name="new_query" id="new_query"> |
| 296 |
<?php |
| 297 |
|
| 298 |
foreach ($media_names as $key => $val): |
| 299 |
$disabled = isset($media_query[$key]) && $key !== 'custom' ? ' DISABLED ' : ''; |
| 300 |
?> |
| 301 |
<option value="<?php echo $key ?>" <?php echo $disabled ?> ><?php echo $val ?></option> |
| 302 |
|
| 303 |
|
| 304 |
<?php endforeach; ?> |
| 305 |
</select> |
| 306 |
<?php //echo maxUtils::selectify("new_query",$media_names,'' ); ?> |
| 307 |
<a href='javascript:void(0)' class="button add_media_query"><?php _e("Add","maxbuttons") ?></a> |
| 308 |
</div> |
| 309 |
|
| 310 |
|
| 311 |
<div class="clear"></div> |
| 312 |
</div> |
| 313 |
</div> |
| 314 |
</div> <!-- inside --> |
| 315 |
|
| 316 |
<input type="hidden" name="next_media_index" value="<?php echo $i ?>" > |
| 317 |
<div class='media_option_prot'> |
| 318 |
|
| 319 |
<div class='media_query' data-query=''> |
| 320 |
<span class='removebutton'><img src="<?php echo MB()->get_plugin_url() ?>assets/icons/remove.png"></span> |
| 321 |
|
| 322 |
<input type="hidden" name="media_query[]" value=""> |
| 323 |
<label class='title'></label> |
| 324 |
<p class='description'>Description here</p> |
| 325 |
|
| 326 |
<div class="custom"> |
| 327 |
<div class="label"><?php _e("Min width","maxbuttons") ?></div> |
| 328 |
<div class="input"><input type="text" class="tiny" name="mq_custom_minwidth[]" value="0" />px</div> |
| 329 |
|
| 330 |
<div class="label max"> <?php _e("Max width","maxbuttons"); ?></div> |
| 331 |
<div class="input max"><input type="text" class="tiny" name="mq_custom_maxwidth[]" value="0" />px</div> |
| 332 |
|
| 333 |
|
| 334 |
</div> |
| 335 |
<div class='label'><?php _e("Font size","maxbuttons") ?></div> |
| 336 |
<div class='input'><input type='text' name='mq_font_size[]' class='tiny' value="90"> <?php echo maxUtils::selectify("mq_font_size_unit[]",$units,"%") ?> |
| 337 |
</div> |
| 338 |
|
| 339 |
<div class='label'><?php _e("Button width", "maxbuttons") ?></div> |
| 340 |
<div class='input'><input type='text' name="mq_button_width[]" value="0" class='tiny'> <?php echo maxUtils::selectify("mq_button_width_unit[]",$units,""); ?></div> |
| 341 |
<div class='label'><?php _e("Container width", "maxbuttons"); ?></div> |
| 342 |
<div class='input'> |
| 343 |
<input type='text' name="mq_container_width[]" value="0" class='tiny'> <?php echo maxUtils::selectify("mq_container_width_unit[]",$units,""); ?> |
| 344 |
</div> |
| 345 |
|
| 346 |
<div class='label'><?php _e("Container float", "maxbuttons"); ?></div> |
| 347 |
<div class="input"><?php echo maxUtils::selectify("mq_container_float[]",$container_floats, "") ?></div> |
| 348 |
<div class="label"><?php _e("Hide button on this view","maxbuttons"); ?></div> |
| 349 |
<div class="input"><input type="checkbox" name="mq_hide[]" value="none"> |
| 350 |
</div> |
| 351 |
`</div> |
| 352 |
|
| 353 |
</div> |
| 354 |
<div id="media_desc"> |
| 355 |
<?php foreach($media_desc as $key => $desc) |
| 356 |
{ |
| 357 |
echo "<span id='$key'>$desc</span>"; |
| 358 |
|
| 359 |
} |
| 360 |
?> |
| 361 |
</div> |
| 362 |
|
| 363 |
|
| 364 |
</div> <!-- container --> |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
<?php |
| 370 |
} |
| 371 |
|
| 372 |
} // class |
| 373 |
|
| 374 |
?> |
| 375 |
|