| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
use \MaxButtons\maxField as maxField; |
| 6 |
use \MaxButtons\maxBlocks as maxBlocks; |
| 7 |
use \MaxButtons\maxButton as maxButton; |
| 8 |
|
| 9 |
$collectionBlock["style"] = array('class' => "styleBlock", |
| 10 |
'order' => 30); |
| 11 |
|
| 12 |
class styleBlock extends block |
| 13 |
{ |
| 14 |
protected $blockname = "style"; |
| 15 |
protected $fields = array( |
| 16 |
"style" => array("default" => "0" ), |
| 17 |
'custom_list' => array('default' => array() ), |
| 18 |
); |
| 19 |
|
| 20 |
public $add_preview_style = false; |
| 21 |
|
| 22 |
// public $preview_style = false; |
| 23 |
|
| 24 |
|
| 25 |
public function set($data) |
| 26 |
{ |
| 27 |
parent::set($data); |
| 28 |
$blockdata = $this->data[$this->blockname]; |
| 29 |
|
| 30 |
|
| 31 |
if (isset($blockdata['style']) && ! empty($blockdata['style']) ) |
| 32 |
{ |
| 33 |
$styleObj = styles::getStyle($blockdata['style']); |
| 34 |
if ($styleObj) |
| 35 |
$this->collection->setStyle( $styleObj ); |
| 36 |
} |
| 37 |
else // default to first style - default option |
| 38 |
{ |
| 39 |
$styles = styles::getStyles(); |
| 40 |
|
| 41 |
if (count($styles) > 0) |
| 42 |
{ |
| 43 |
$first_ar = array_shift($styles); |
| 44 |
$style_obj = array_shift($first_ar); |
| 45 |
$data_style = $style_obj->name; |
| 46 |
$style = styles::getStyle($data_style); |
| 47 |
$this->collection->setStyle($style); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
public function parse($itemObj, $args = array() ) |
| 56 |
{ |
| 57 |
$block_data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array(); |
| 58 |
|
| 59 |
$style = $this->collection->getStyle(); |
| 60 |
|
| 61 |
if ($style->has_label) |
| 62 |
{ |
| 63 |
$network = $args['network']; |
| 64 |
|
| 65 |
$anchor = $itemObj->find('.maxbutton-social', 0); |
| 66 |
$label = $network->get('label'); |
| 67 |
if ($label) |
| 68 |
{ |
| 69 |
$anchor->class .= ' with-label '; |
| 70 |
$label_text = '<span class="mb-label">' . $label . '</span>'; |
| 71 |
$anchor->innertext .= $label_text; |
| 72 |
$itemObj->load($itemObj->save() ); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
if ($args['preview'] == true && $this->add_preview_style) |
| 77 |
{ |
| 78 |
$style = $this->add_preview_style; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
return $itemObj; |
| 83 |
} |
| 84 |
|
| 85 |
public function ajax_get_all_styles() |
| 86 |
{ |
| 87 |
$available_styles = styles::getStyles(); |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
public function admin() |
| 92 |
{ |
| 93 |
wp_enqueue_style('mbsocial-buttons'); |
| 94 |
|
| 95 |
$active_networks = isset($this->data['network']['active']) ? $this->data['network']['active'] : array(); |
| 96 |
|
| 97 |
$admin = mbSocial()->admin(); |
| 98 |
$networks = mbSocial()->networks()->get(); |
| 99 |
|
| 100 |
$networks = $admin->get_networks($active_networks); |
| 101 |
if (count($networks['selected']) == 0) |
| 102 |
$networks = $networks['unselected']; |
| 103 |
else |
| 104 |
$networks = $networks['selected']; |
| 105 |
|
| 106 |
$blockdata = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array(); |
| 107 |
|
| 108 |
$data_style = isset($blockdata['style']) ? $blockdata['style'] : false; // |
| 109 |
|
| 110 |
?> |
| 111 |
|
| 112 |
|
| 113 |
<div class='options option-container style' id='styleBlock' data-refresh='styleBlock' > |
| 114 |
<div class='title'><?php _e('Style', 'mbsocial'); ?></div> |
| 115 |
<div class='inside'> |
| 116 |
|
| 117 |
<?php |
| 118 |
/* FOR TESTING ALL STYLES |
| 119 |
$styles = styles::getStyles(); |
| 120 |
$args = array('preview' => true, |
| 121 |
'load_type' => 'inline', |
| 122 |
'echo' => true, |
| 123 |
'compile' => true, |
| 124 |
); |
| 125 |
|
| 126 |
foreach($styles as $order => $style_classes) |
| 127 |
{ |
| 128 |
foreach($style_classes as $style_class) |
| 129 |
{ |
| 130 |
//echo $style_class->class . "<BR><p>--"; |
| 131 |
|
| 132 |
//$styleBlock = $collection->getBlock('styleBlock'); |
| 133 |
$this->add_preview_style = $style_class->class; |
| 134 |
$this->collection->setStyle($style_class); |
| 135 |
$this->collection->display($args); |
| 136 |
|
| 137 |
// echo "--</p>"; |
| 138 |
} |
| 139 |
} |
| 140 |
*/ |
| 141 |
?> |
| 142 |
|
| 143 |
|
| 144 |
<?php //foreach ($available_styles as $style): |
| 145 |
//$selected = ($data_style == $style->name ) ? ' checked ' : ''; |
| 146 |
|
| 147 |
$args = array('preview' => true, |
| 148 |
'load_type' => 'inline', |
| 149 |
'compile' => true, |
| 150 |
); |
| 151 |
?> |
| 152 |
<div class='style-row'> |
| 153 |
<input type='hidden' id='style' name='style' value='<?php echo $data_style ?>'> |
| 154 |
<span class='updatables hidden'>#style</span> |
| 155 |
<?php |
| 156 |
$style = $this->collection->getStyle(); // set by the set data set of this block |
| 157 |
$style_name = $style->class; |
| 158 |
|
| 159 |
|
| 160 |
?> |
| 161 |
|
| 162 |
<div id='style_preview'> |
| 163 |
<?php |
| 164 |
//$this->preview_style = $style->class; |
| 165 |
$this->collection->display($args); |
| 166 |
?> |
| 167 |
</div> |
| 168 |
|
| 169 |
|
| 170 |
<p><button name='style_button' type="button" data-modal='modal_styles' class='maxmodal button-primary'><?php _e('Select Style', 'mbsocial'); ?> </button> </p> |
| 171 |
</div> |
| 172 |
<?php //endforeach; // styles ?> |
| 173 |
</div> <!-- inside--> |
| 174 |
</div> <!-- option container --> |
| 175 |
|
| 176 |
<div id='modal_styles' class='maxmodal-data' data-load='window.maxFoundry.maxSocial.loadStylesPopup'> |
| 177 |
<div class='title'><?php _e('Style Selector - Click on Style to Select or Mouseover to See Effect.', 'mbsocial'); ?></div> |
| 178 |
<div class='content'> |
| 179 |
|
| 180 |
<div class='style_modal style-row wrapper'> |
| 181 |
|
| 182 |
|
| 183 |
</div> |
| 184 |
|
| 185 |
</div> <!-- content --> |
| 186 |
<div class='controls'> |
| 187 |
<p> |
| 188 |
<button class='button-primary modal_close'><?php _e('Done','mbsocial'); ?></button> |
| 189 |
</p> |
| 190 |
</div> |
| 191 |
</div> <!-- modal --> |
| 192 |
<?php |
| 193 |
} // admin |
| 194 |
|
| 195 |
|
| 196 |
} // class |
| 197 |
|