# share-button/0.9/classes/blocks/style_block.php

Social Share Buttons, version 0.9. 197 lines.

- Page: https://pluginprobe.com/plugins/share-button/0.9/code/classes/blocks/style_block.php
- Raw: https://pluginprobe.com/plugins/share-button/0.9/raw/classes/blocks/style_block.php
- Modified: 2017-11-22T15:53:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/share-button/0.9/code/classes/blocks/style_block.php#L10-L20`.

```php
<?php
namespace MBSocial;
defined('ABSPATH') or die('No direct access permitted');

use \MaxButtons\maxField as maxField;
use \MaxButtons\maxBlocks as maxBlocks;
use \MaxButtons\maxButton as maxButton;

$collectionBlock["style"] = array('class' => "styleBlock",
								  'order' => 30);

class styleBlock extends block
{
	protected $blockname = "style";
	protected $fields = array(
						"style" => array("default" => "0" ),
						'custom_list' => array('default' => array() ),
	);

	public $add_preview_style = false;

//	public $preview_style = false;


	public function set($data)
	{
		parent::set($data);
		$blockdata = $this->data[$this->blockname];


		if (isset($blockdata['style']) && ! empty($blockdata['style']) )
		{
			$styleObj = styles::getStyle($blockdata['style']);
			if ($styleObj)
				$this->collection->setStyle( $styleObj );
		}
		else // default to first style - default option
		{
			$styles = styles::getStyles();

			if (count($styles) > 0)
			{
				$first_ar  = array_shift($styles);
				$style_obj = array_shift($first_ar);
				$data_style = $style_obj->name;
				$style = styles::getStyle($data_style);
				$this->collection->setStyle($style);
			}
		}



	}

	public function parse($itemObj, $args = array() )
	{
		$block_data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();

		$style = $this->collection->getStyle();

		if ($style->has_label)
		{
			$network = $args['network'];

			$anchor = $itemObj->find('.maxbutton-social', 0);
			$label = $network->get('label');
			if ($label)
			{
				$anchor->class .= ' with-label ';
				$label_text = '<span class="mb-label">' . $label . '</span>';
		 		$anchor->innertext .= $label_text;
		 		$itemObj->load($itemObj->save() );
		 	}
		}

		if ($args['preview'] == true && $this->add_preview_style)
		{
			$style = $this->add_preview_style;
		}


		return $itemObj;
	}

	public function ajax_get_all_styles()
	{
		$available_styles = styles::getStyles();

	}

	public function admin()
	{
		wp_enqueue_style('mbsocial-buttons');

		$active_networks = isset($this->data['network']['active']) ? $this->data['network']['active'] : array();

		$admin = mbSocial()->admin();
		$networks = mbSocial()->networks()->get();

		$networks = $admin->get_networks($active_networks);
		if (count($networks['selected']) == 0)
			$networks = $networks['unselected'];
		else
			$networks = $networks['selected'];

 		$blockdata = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();

		$data_style = isset($blockdata['style']) ? $blockdata['style'] : false; //

?>


		<div class='options option-container style' id='styleBlock' data-refresh='styleBlock' >
			<div class='title'><?php _e('Style', 'mbsocial'); ?></div>
			<div class='inside'>

				<?php
				/*  FOR TESTING ALL STYLES
				$styles = styles::getStyles();
				 $args = array('preview' => true,
				 			   'load_type' => 'inline',
				 			   'echo' => true,
				 			   'compile' => true,
				 			  );

				foreach($styles as $order => $style_classes)
				{
					foreach($style_classes as $style_class)
					{
						//echo $style_class->class . "<BR><p>--";

						//$styleBlock = $collection->getBlock('styleBlock');
						$this->add_preview_style = $style_class->class;
						$this->collection->setStyle($style_class);
						$this->collection->display($args);

				//		echo "--</p>";
					}
				}
				*/
		?>


				<?php //foreach ($available_styles as $style):
					//$selected = ($data_style == $style->name ) ? ' checked ' : '';

					 $args = array('preview' => true,
					 			   'load_type' => 'inline',
					 			   'compile' => true,
					 			  );
				 ?>
					<div class='style-row'>
					<input type='hidden' id='style' name='style' value='<?php echo $data_style ?>'>
					<span class='updatables hidden'>#style</span>
					<?php
					$style = $this->collection->getStyle();  // set by the set data set of this block
					$style_name = $style->class;


					?>

						<div  id='style_preview'>
							<?php
								//$this->preview_style = $style->class;
								$this->collection->display($args);
							?>
						</div>


						<p><button name='style_button' type="button" data-modal='modal_styles' class='maxmodal button-primary'><?php _e('Select Style', 'mbsocial'); ?> </button> </p>
					</div>
				<?php //endforeach; // styles ?>
			</div> <!-- inside-->
		</div> <!-- option container -->

<div id='modal_styles' class='maxmodal-data'  data-load='window.maxFoundry.maxSocial.loadStylesPopup'>
		<div class='title'><?php _e('Style Selector - Click on Style to Select or Mouseover to See Effect.', 'mbsocial'); ?></div>
		<div class='content'>

			<div class='style_modal style-row wrapper'>


			</div>

		</div>  <!-- content -->
		<div class='controls'>
			<p>
				<button class='button-primary modal_close'><?php _e('Done','mbsocial'); ?></button>
			</p>
		</div>
	</div> <!-- modal -->
<?php
	} // admin


} // class

```
