| 1 |
<?php |
| 2 |
namespace MaxButtons; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
$blockClass["advanced"] = "advancedBlock"; |
| 5 |
$blockOrder[80][] = "advanced"; |
| 6 |
|
| 7 |
|
| 8 |
class advancedBlock extends maxBlock |
| 9 |
{ |
| 10 |
protected $blockname = "advanced"; |
| 11 |
protected $fields = array("important_css" => array("default" => "0"), |
| 12 |
"custom_rel" => array('default' => ''), |
| 13 |
"extra_classes" => array('default' => ''), |
| 14 |
"external_css" => array("default" => "0"), |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
); |
| 19 |
|
| 20 |
public function __construct() |
| 21 |
{ |
| 22 |
parent::__construct(); |
| 23 |
add_filter('mb/button/rawcss', array($this, 'parse_css_advanced'), 1001, 2); // run once |
| 24 |
//add_filter('mb-css-blocks', array($this, 'preview_external_css'), 100 ) |
| 25 |
} |
| 26 |
|
| 27 |
public function parse_css($css, $mode = 'normal') |
| 28 |
{ |
| 29 |
$css = parent::parse_css($css); |
| 30 |
$data = $this->data[$this->blockname]; |
| 31 |
|
| 32 |
if (isset($data["important_css"]) && $data["important_css"] == 1) |
| 33 |
{ |
| 34 |
$css["settings"]["important"] = 1; |
| 35 |
} |
| 36 |
|
| 37 |
return $css; |
| 38 |
} |
| 39 |
|
| 40 |
public function parse_css_advanced($css, $mode) |
| 41 |
{ |
| 42 |
$data = $this->data[$this->blockname]; |
| 43 |
|
| 44 |
if (isset($data["external_css"]) && $data["external_css"] == 1 && $mode == 'normal') |
| 45 |
{ |
| 46 |
|
| 47 |
return array( |
| 48 |
"normal" => array(), |
| 49 |
"hover" => array()); |
| 50 |
} |
| 51 |
|
| 52 |
return $css; |
| 53 |
} |
| 54 |
|
| 55 |
public function parse_button($domObj, $mode = 'normal') |
| 56 |
{ |
| 57 |
|
| 58 |
$data = $this->data[$this->blockname]; |
| 59 |
|
| 60 |
$button_id = $this->data["id"]; |
| 61 |
|
| 62 |
$anchor = $domObj->find("a",0); |
| 63 |
|
| 64 |
if (isset($data["custom_rel"]) && trim($data["custom_rel"]) != '') |
| 65 |
{ |
| 66 |
$rel = ''; |
| 67 |
$custom_rel = trim($data["custom_rel"]); |
| 68 |
if (isset($anchor->rel) && $anchor->rel != '') |
| 69 |
{ |
| 70 |
$anchor->rel .= ' '; |
| 71 |
} |
| 72 |
|
| 73 |
$anchor->rel .= $custom_rel; |
| 74 |
} |
| 75 |
|
| 76 |
if (isset($data["extra_classes"]) && trim($data["extra_classes"]) != '') |
| 77 |
{ |
| 78 |
$extra = trim($data["extra_classes"]); |
| 79 |
$anchor->class .= ' ' . $extra; |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
if (isset($data["external_css"]) && $data["external_css"] == 1) |
| 84 |
{ |
| 85 |
$anchor->class .= ' external-css ' ; |
| 86 |
} |
| 87 |
|
| 88 |
return $domObj; |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
public function admin_fields() |
| 93 |
{ |
| 94 |
$data = $this->data[$this->blockname]; |
| 95 |
$admin = MB()->getClass('admin'); |
| 96 |
|
| 97 |
foreach($this->fields as $field => $options) |
| 98 |
{ |
| 99 |
$default = (isset($options["default"])) ? $options["default"] : ''; |
| 100 |
$$field = (isset($data[$field])) ? $data[$field] : $default; |
| 101 |
${$field . "_default"} = $default; |
| 102 |
|
| 103 |
global $maxbuttons_container_alignments; |
| 104 |
} |
| 105 |
?> |
| 106 |
|
| 107 |
<div class="option-container mb_tab"> |
| 108 |
<div class="title"><?php _e('Advanced', 'maxbuttons') ?></div> |
| 109 |
<div class="inside advanced"> |
| 110 |
|
| 111 |
<?php |
| 112 |
|
| 113 |
$imp = new maxField('switch'); |
| 114 |
$imp->note = __('Adding !important to the button styles can help avoid potential conflicts with your theme styles.', 'maxbuttons') ; |
| 115 |
$imp->id = 'important_css'; |
| 116 |
$imp->name = $imp->id; |
| 117 |
$imp->value = 1; |
| 118 |
$imp->label = __('Use !Important', 'maxbuttons'); |
| 119 |
$imp->checked = checked(maxBlocks::getValue('important_css'), 1, false); |
| 120 |
//$imp->value = maxBlocks::getValue('important_css'); |
| 121 |
//$imp->output('start','end'); |
| 122 |
|
| 123 |
$admin->addField($imp, 'start', 'end'); |
| 124 |
|
| 125 |
$class = new maxField(); |
| 126 |
$class->id = 'extra_classes'; |
| 127 |
$class->name = $class->id; |
| 128 |
$class->label = __("Extra classes","maxbuttons"); |
| 129 |
$class->value = maxBlocks::getValue($class->id); |
| 130 |
$class->note = __("Useful for custom code or other plugins who target classes", "maxbuttons"); |
| 131 |
//$class->output('start','end'); |
| 132 |
|
| 133 |
$admin->addField($class, 'start', 'end'); |
| 134 |
|
| 135 |
$rel = new maxField(); |
| 136 |
$rel->id = 'custom_rel'; |
| 137 |
$rel->name = $rel->id; |
| 138 |
$rel->label = __("Custom Rel Tag","maxbuttons"); |
| 139 |
$rel->value = maxBlocks::getValue($rel->id); |
| 140 |
$rel->note = __("Useful when button is targeting lightbox and/or popup plugins that use this method", "maxbuttons"); |
| 141 |
//$rel->output('start','end'); |
| 142 |
|
| 143 |
$admin->addField($rel, 'start', 'end'); |
| 144 |
|
| 145 |
// do_action('mb-after-advanced'); |
| 146 |
|
| 147 |
$admin->display_fields(); |
| 148 |
|
| 149 |
$nocss = new maxField('switch'); |
| 150 |
$nocss->note = __('By default, the CSS styles for the button are rendered within a <style> block in the HTML body. Enabling the "Use External CSS" option allows you to put the CSS code for the button into your theme stylesheet instead.', 'maxbuttons'); |
| 151 |
$nocss->label = __('Use External CSS', 'maxbuttons'); |
| 152 |
$nocss->id = 'external_css'; |
| 153 |
$nocss->value = 1; |
| 154 |
$nocss->name = $nocss->id; |
| 155 |
$nocss->checked = checked($external_css, 1, false); |
| 156 |
$nocss->output('start',''); |
| 157 |
|
| 158 |
$nospace = new maxField('spacer'); |
| 159 |
$nospace->content = __("Warning: This will remove all styling of the buttons!","maxbuttons"); |
| 160 |
$nospace->output('','end'); |
| 161 |
?> |
| 162 |
|
| 163 |
<div class="option-design"> |
| 164 |
<div class="label"> </div> |
| 165 |
<div class="input"><a id="view_css_modal" name="view_css" href="javascript:void(0)" class="button maxmodal" data-modal="view-css"><?php _e('View CSS', 'maxbuttons') ?></a></div> |
| 166 |
<div class="clear"></div> |
| 167 |
|
| 168 |
<div id="view-css" class="maxmodal-data" > |
| 169 |
<h3 class="title"><?php _e("External CSS","maxbuttons"); ?></h3> |
| 170 |
<div class="content"> |
| 171 |
<p><?php _e('If the "Use External CSS" option is enabled for this button, copy and paste the CSS code below into your theme stylesheet.', 'maxbuttons') ?></p> |
| 172 |
|
| 173 |
<textarea id="maxbutton-css" readonly="readonly"> |
| 174 |
<?php |
| 175 |
if (isset($this->data["id"]) && $this->data['id'] > 0) |
| 176 |
{ |
| 177 |
$id = $this->data["id"]; |
| 178 |
$b = MB()->getClass('button'); |
| 179 |
|
| 180 |
$b->set($id); |
| 181 |
$b->parse_button(); |
| 182 |
$b->parse_css("preview"); |
| 183 |
|
| 184 |
echo $b->getparsedCSS(); |
| 185 |
|
| 186 |
} |
| 187 |
else |
| 188 |
{ _e("Please save the button first","maxbuttons"); } |
| 189 |
|
| 190 |
?></textarea> |
| 191 |
</div> |
| 192 |
<div class='controls'> |
| 193 |
<p><a class='button-primary modal_close' href='javascript:void(0);'><?php _e("Close","maxbuttons"); ?></a> |
| 194 |
</p> |
| 195 |
</div> |
| 196 |
</div> |
| 197 |
|
| 198 |
</div> |
| 199 |
</div> |
| 200 |
</div> |
| 201 |
|
| 202 |
<?php |
| 203 |
} // admin_fields |
| 204 |
|
| 205 |
} // class |
| 206 |
|
| 207 |
?> |
| 208 |
|