# share-button/0.9/classes/class-collection.php

Social Share Buttons, version 0.9. 1,101 lines.

- Page: https://pluginprobe.com/plugins/share-button/0.9/code/classes/class-collection.php
- Raw: https://pluginprobe.com/plugins/share-button/0.9/raw/classes/class-collection.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/class-collection.php#L10-L20`.

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

use \maxbuttons\maxUtils as maxUtils;
use \maxbuttons\maxCSSParser as maxCSSParser;
use \simple_html_dom as simple_html_dom;
use \MaxButtons\maxBlocks as maxBlocks;

class collection
{
	protected $blocks = array(); // array of objects
	protected $buttons = array();
	protected $data;  // data of the collection
	protected $meta_data;  // data stored specific to posts / pages etc

	protected $collection_id = 0;
	protected $collection_type = 'social_share';
	protected $styleObj = null;

	// layout functions
	protected $cssParser;

	// save hook currently active
	protected $doingHook;


  public $is_showable = true; // keeps state of hidden options
	public $is_static = false;
	public $is_post = false; // embedded in a post situation
	public $is_mobile = false;
	public $is_tablet = false;
	public $orientation = 'horizontal';
	public $display_mode = 'hidden';
	public $post_id;


	/* Constructor
	   Sets the blocks used in this collection. These are mostly derived from subclasses of the specific collection types.
	*/
	public function __construct($collection_id = 0)
	{
		collections::checkExpireTrans();

		$blocks = collections::getBlocks();

		$default_data = array();


		foreach($blocks as $block_name)
		{
			$block = collections::getBlock($block_name);
			if ($block)
			{
				$block->setCollection($this);
				$default_data = $block->save_fields($default_data, null ); // force the fields to set a default pos.

				$this->blocks[$block_name] = $block;

			}
			maxBlocks::add($block);
		}

		// then load the default as data
		maxBlocks::setData($default_data);
		$this->data = $default_data;

		foreach($this->blocks as $block)
		{
			if ($block)
			{
				$block->set($default_data);
			}

		}

		if ($collection_id > 0)
			$this->set($collection_id);

	}
	/* Get all buttons that are currently loaded */
	/*public function getLoadedButtons()
	{
		return $this->buttons;
	} */




	/* Get a certain block class by name */
	public function getBlock($blockname)
	{

		if (isset($this->blocks[$blockname]))
			return $this->blocks[$blockname];
		else
			return false;
	}

	/* Get the type of the collection */
	/*public function getType()
	{
		return $this->collection_type;
	} */

	/* Get the ID of the collection */
	public function getID()
	{
		return $this->collection_id;
	}

	/** Get the MaxCSSParser classes which handles SCSS. This function is derived from the one in Button class */
	public function getCSSParser()
	{
		if (! $this->cssParser)
		{	$this->cssParser = new maxCSSParser();
			$this->cssParser->anchor_class = '.maxbutton-social';
		}
		return $this->cssParser;
	}

	/** Set the collection by ID
	* @param $collection_id ID of the collection stored in database
	*/
	public function set($collection_id)
	{
		$this->collection_id = $collection_id;

		// make every block set it's stuff.
		$data = $this->get_meta($collection_id);

		foreach($this->blocks as $name => $block)
		{
			// run every blocks setter
			$block->set($data);
		}

		$this->data = $data;
	}

	public function setData($data)
	{
		$this->data = $data;
	}

	public function setHook($hook)
	{
		$this->doingHook = $hook;
		$this->setEnv();
	}

	// sets the style object to a collection. This is important for styling CSS
	public function setStyle($style)
	{
		if (! is_object($style))
			return false;
			
		$this->styleObj = $style;
		$style->setActive();
	}

	public function getStyle()
	{
		return $this->styleObj;

	}

	public function getHook()
	{
		if (is_null($this->doingHook))
			return false;
		else
			return $this->doingHook;
	}

	public function setEnv() // load orientations and specifics about the current collections. After data has loaded and all that.
	{
		$data = $this->data;

		$hook = $this->doingHook;
		$display = isset($this->data[$hook]) ? $this->data[$hook] : 'hidden';
		$this->display_mode = $display;

		if (! is_admin() )
		{
			global $post;
			$this->post_id = $post->ID;
		}
		else
			$this->post_id = 0;


		if ($display == 'static')
		{
			$this->is_static = true;
		}
		elseif ($display == 'after' || $display == 'before' || $display == 'after-before')
			$this->is_post = true;

		// check if on some mobile
		$mobileDetect = new Mobile_Detect;
		$this->is_mobile = $mobileDetect->isMobile();
		$this->is_tablet = $mobileDetect->isTablet();

		$options = isset($data['display'][$hook . '_options']) ? $data['display'][$hook . '_options'] : array();

		$orientation = isset($options['orientation']) ? $options['orientation'] : 'auto';
		$static = isset($options['static']) ? $options['static'] : 'auto';

		if ($orientation == 'auto' && $display == 'static')
			{
				switch($static) // auto align on basis of placement on screen
				{
					 case "left":  // vertical items
					 case "right":
					 case "auto":
					 	$orientation = "vertical";
					break;
					case "top":  // horizontal
					case "bottom":
					default:
						$orientation = "horizontal";
					break;
			}
		}
		elseif ($orientation == 'auto')
		{
			$orientation = 'horizontal';
		}

		$this->orientation = $orientation;

		// Check if any hidden variables are given.
		$active = isset($this->data['general']['active']) ? $this->data['general']['active'] : true;

		if ($active === 0)
		{
			$this->is_showable = false;
		}

		if ($this->post_id > 0)
		{
			$meta = $this->get_metadata($this->post_id);
			$is_active = (isset($meta['general']['active'])) ? $meta['general']['active'] : true;
			if ($is_active === 0)
				$this->is_showable = false;
		}

	}

	/** Interface for handling AJAX requests to communicate with the seperate blocks.
	*	@param $result The initial (default) result to JSON back
	*	@param $block_name The name of the block in question
	*	@param $action The name of the block function to call
	*	@param $data Data specified by JS to use for this function
	*	@return $result - Standardized result block including error, body
	*/
	public function doBlockAJAX($result, $block_name, $action, $data)
	{
		// core class is being called.
		if ($block_name == 'collection')
		{
			$result = $this->$action($result, $data);
			return $result;
		}

		if (isset($this->blocks[$block_name]))
		{
			$block= $this->blocks[$block_name];
			$result = $block->$action($result, $data);
			return $result;

		}

		$result["error"] = true;
		$result["title"] = __("Error : Block was not there","maxbuttons");
		return $result;
	}

	/** Save the collection data to the database. This will invoke the save functions of the blocks itself to gather, verify and manipulate data */
	public function save($post)
	{
		$data = array();

		// Collection id needed to save meta data and others.
		if ($this->collection_id == 0) // assume new
		{
			$collection_id = $this->getNewCollectionID();

			$this->collection_id = $collection_id;
		}

		// run this by each block and collect data
	 	foreach($this->blocks as $block_name => $block)
	 	{

	 		$data = $block->save_fields($data, $post);
	 	}

	 	// clean what was not set
	 	$this->clean_meta($data);

	 	// write data as a per block per key value into the database
	 	foreach($data as $blockname => $blockdata)
	 	{
	 		// seems dangerous
	 		$meta_id = $this->update_meta($this->collection_id, $blockname, $blockdata);
		}

		// insert collection type
		$this->update_meta($this->collection_id, 'collection_type', 'social_share') ;

	 	return $this->collection_id;

	}

	// remove post meta not in data post.
	public function clean_meta($data)
	{
		$data_blocks = array_keys($data);

		$meta = $this->get_meta($this->collection_id);

		foreach($meta as $meta_key => $values)
		{
			if (! in_array($meta_key, $data_blocks))
			{
				$this->delete_meta($this->collection_id, $meta_key);
			}
		}

	}

	protected function update_meta($collection_id, $collection_key, $collection_value)
	{
		global $wpdb;
		$table = maxUtils::get_collection_table_name();

		if ($collection_value == '') return; // no data no database entry
		if (is_array($collection_value) && count($collection_value) == 0) return; // same for empty arrays

		if (is_array($collection_value))
			$collection_value = json_encode($collection_value);

		if ($collection_id == 0) // assume new
		{
			$collection_id = $this->getNewCollectionID();

			$this->collection_id = $collection_id;
		}

		$sql = "SELECT meta_id from $table where collection_id = %d and collection_key = %s ";
		$sql = $wpdb->prepare($sql, $collection_id, $collection_key);

		$results = $wpdb->get_results($sql, ARRAY_A);

		if (count($results) == 1)
		{
			$meta_id = $results[0]["meta_id"];
			$data = array("collection_value" => $collection_value);  // what's being updated
			$where = array("meta_id" => $meta_id);

			$wpdb->update($table, $data, $where);
			return $meta_id;
		}
		if (count($results) == 0)
		{
			$data = array("collection_value" => $collection_value,
						"collection_key" => $collection_key,
						"collection_id" => $collection_id,
					);

			$meta_id = $wpdb->insert($table, $data);

			return $meta_id;
		}
		else
		{
			MB()->add_notice("error", __("Update Collection meta has multiple rows, this should not be possible.","maxbuttons"));

		}
		return false;
	}


	/** Determine the next ID for collection */
	protected function getNewCollectionID()
	{
		global $wpdb;
		$table = maxUtils::get_collection_table_name();

		$sql = "SELECT max(collection_id) as max from $table";

		$max = intval($wpdb->get_var($sql));

		$max = $max + 1;
		return $max;
	}

	protected function delete_meta($collection_id, $collection_key)
	{
		if (intval($collection_id) > 0 && $collection_key != "")
		{
			global $wpdb;
		//	delete_post_meta($collection_id, $collection_key);
			$table = maxUtils::get_collection_table_name();
			$where = array("collection_id" => $collection_id,
						   "collection_key" => $collection_key
						  );
			$where_format = array("%d", "%s");
			$wpdb->delete($table, $where, $format);

		}
	}


	/** Delete the collection. This is done via AJAX request */
	/*public function delete($result, $data)
	{
		global $wpdb;
		if(! $this->collection_id > 0)
			return false;

		$picker = $this->getBlock("picker");
		$picker_data = $picker->get();
		$buttons = $picker_data["selection"];
		$button = MB()->getClass("button");

		$buttons_removed = 0;

		foreach($buttons as $button_id)
		{
			$deleted = $this->maybe_delete_button($button_id);
			if ($deleted)
				$buttons_removed++;

		}

		$table = maxUtils::get_collection_table_name();
		$where = array("collection_id" => $this->collection_id);
		$where_format = array("%d");
		$wpdb->delete($table, $where, $where_format);

 		$result["data"]["body"] = __("The collection is removed","maxbuttons");
 		$result["data"]["title"] = __("Removed","maxbuttons");
 		$result["data"]["buttons_removed"] = $buttons_removed;
 		$result["data"]["collection_id"] = $this->collection_id;
 		return $result;


	} */

	/** On deletion of a collection check for each button if this is an auto-generated button just made for this collection * and if
	* no changes where made to this button. If both conditions are true, remove the button */
	/*function maybe_delete_button($button_id)
	{
			$button = MB()->getClass("button");

			$button->set($button_id);
			$button_data = $button->get();

			$collection_id= $this->collection_id;

			// remove unedited buttons created for this collection - use with care.
			if (isset($button_data["meta"]["user_edited"]))
			{
				$created_source = (isset($button_data["meta"]["created_source"])) ? $button_data["meta"]["created_source"] : '';
				if ($button_data["meta"]["user_edited"] === false && $created_source == 'collection')
				{
					$in_collections = $button_data["meta"]["in_collections"];

					$key = array_search($collection_id, $in_collections);

					if ($key !== false)
					{
						unset($button_data["meta"]["in_collections"][$key]);

						if (count($button_data["meta"]["in_collections"]) == 0)
						{	$button->delete($button_id);
							return true;
						}
						else
						{
							if ($button_id > 0) // safety.
							$button->update($button_data);
						}
					}
				}


			}
		return false;
	} */

	function get_meta ($collection_id, $collection_key = '')
	{
		global $wpdb;
		$table = maxUtils::get_collection_table_name();

		$prepare = array($collection_id);

		$sql = "SELECT * from $table where collection_id = %d ";
		if ($collection_key != '')
		{
			$sql .= " and collection_key = %s ";
			array_push($prepare, $collection_key);

		}

		$sql = $wpdb->prepare($sql, $prepare);

		$results = $wpdb->get_results($sql, ARRAY_A);

		$result_array = array(); // format array by field name = values to feed blocks and others.
		if (! is_null($results))
		{
			$nr = array();
			foreach($results as $row)
			{
				$key = $row["collection_key"];
				/* A field can be either plain text or JSON */
				if(json_decode($row["collection_value"]))
					$value = json_decode($row["collection_value"], true);
				else
					$value = $row["collection_value"];
				$result_array[$key] = $value;

				//$row["collection_value"] = unserialize($row["collection_value"]);
			}

			return $result_array;
		}
		else
		{
			return false;
		}
	}

	function display($args = array())
	{
		if (! $this->is_showable)
			return;

		wp_enqueue_style('mbsocial-buttons'); // load the general button style
		wp_enqueue_script('mbsocial_front');

		maxUtils::startTime('collection-display');
		$defaults = array(
				"preview" => false,
				"echo" => true,
				"style_tag" => false,
				"compile" => false,
				"js_tag" => true,
				"load_type" => "footer",
		);

		$args = wp_parse_args($args, $defaults);

		//$cache = MaxCollections::checkCachedCollection($this->collection_id);
		$cache = false;

		if (! $cache)
		{
			$cssParser = $this->getCSSParser();
			$domObj = $this->parse($args);

			$css 	= $this->parseCSS($args);

			$js = $this->parseJS($args);

			$output = $domObj->save();

			unset($domObj);


		// CSS & JS output control
		$output .= $this->displayCSS($css, $args);
		$output .= $this->displayJS($js, $args);
		}
		else
			$output = $cache;

		//collections::addCachedCollection($this->collection_id, $output);

		maxUtils::endTime('collection-display');


		if ($args["echo"])
		{
			echo $output;
		}
		else
		{
			return $output;
		}

	}

	public function displayCSS($css, $args = array() ) // $echo = true, $style_tag = true)
	{

		$default = array(
			"echo" => true,
			"style_tag" => true,
			"load_type" => "footer",
		);
		$args = wp_parse_args($args, $default);
		if ($args['load_type'] == 'inline')
			$args['style_tag'] =true;

		$output = '';

		if ($args["style_tag"])
			$output .=  "<style type='text/css'>";

			$output .= $css;

		if ($args["style_tag"])
			$output .= "</style>";


 		if ($args["load_type"] == 'footer')
 		{

 			do_action('mb-footer','collection-' . $this->collection_id, $output);
 		}
 		elseif ($args["load_type"] == 'inline')
 		{
 			if ($args["echo"]) echo $output;
 			else return $output;

 		}

	}

	public function displayJS($js, $args = array() ) // $echo = true, $style_tag = true)
	{
		$default = array(
			"echo" => true,
			"js_tag" => true,
			"load_type" => "footer",
			"preview" => false,
		);


		$args = wp_parse_args($args, $default);

		if ($args["preview"])
			return; // no js on previews.

		$output = '';

		if (count($js) == 0)
			return; // no output, holiday

		if ($args["js_tag"])
		{
			$output .= "<script type='text/javascript'> ";
//			$output .= " if (typeof MBcollection" . $this->collection_id . " == 'undefined') { ";
//			$output .= " function MBcollection" . $this->collection_id . "() { ";


		}

		foreach($js as $index => $code)
		{
			$output .= $code;
		}

		if ($args["js_tag"])
		{
			$output .= " // }
					//	}
			//	window.onload = MBcollection" . $this->collection_id . "();
				</script>		";
		}


 		if ($args["load_type"] == 'footer')
 		{

 			do_action('mb-footer','collection-' . $this->collection_id, $output, "js");
 		}
 		elseif ($args["load_type"] == 'inline')
 		{
 			if ($args["echo"]) echo $output;
 			else return $output;

 		}
	}

	/* Parses the collection, via the blocks */
	function parse($args)
	{
		$admin = mbSocial()->admin();
		//$this->setEnv(); // sets the relevant data for the block (orientation etc)
		$this->buttons = array(); // reset the buttons - needed for preview

		$preview = isset($args["preview"]) ? $args["preview"] : false;

		$collectionObj = new simple_html_dom();
		$collection_id = $this->collection_id;

		$styleObj = $this->styleObj;
		$style_class = $styleObj->class;
		$style_class .= ' ' . $this->orientation;

		$node = "<div class='maxcollection maxcollection-" . $collection_id . " $style_class ' data-collection='" . $collection_id . "'>
					   </div>";
		$node = apply_filters("maxbuttons/social/basic-container",$node);
		$collectionObj->load($node);

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

		if (count($active) == 0 && $args['preview'] == true)
		{
			$networks = $admin->get_default_networks();
			$use_networks = $networks['unselected'];
		}
		elseif (count($active) == 0)
			return $collectionObj; // no networks no collection
		else
		{
			$networks = $admin->get_networks($active);
			$use_networks = $networks['selected'];
		}

		maxUtils::startTime('collection-parse-parsebuttons');
		foreach($use_networks as $network)
		{
			//$style = $this->data['style']['style'];

			$args = array('link' => $network->get('share_url'),
						  'name' => $network->get('network'),
						//  'classes' => $style,
						  'network' => $network,
						  'preview' => $preview,

					);

			$args = apply_filters('mbsocial/parsebutton/args', $args);

			maxUtils::endTime('collection-parse-parsebuttons');

			$button = $this->createButton($args);

			maxUtils::startTime('collection-parse-blockparse');


			foreach($this->blocks as $block)
			{
				$block->setPreview($preview);
				$button = $block->parse($button, $args);
			}

			if ($button)
			{
				$this->buttons[] = array('item_class' => $args['name'],
										 'obj' => $button);
			}
		} // network loop.

		// general parsing

	 	maxUtils::endTime('collection-parse-blockparse');

	 	$button_output = '';

	 	foreach($this->buttons as $button_item)
	 	{
	 		$buttonDom = $button_item['obj'];
	 		$button_output .=  $buttonDom->save() ;

	 	}

	 	$this->createTotal($collectionObj);

	 	$collectionObj->find('.maxcollection', 0)->innertext  .= $button_output;


	 	$collectionObj->load($collectionObj->save());

	 	$cssParser = $this->getCSSParser();
	 	//$collectionObj->load($collectionObj->save() );

	 	// save DOM structure to parser
		$cssParser->loadDom($collectionObj);

		return $collectionObj;
	}

	// create a block for total shares
	public function createTotal($collectionObj, $args = array() )
	{

	 	$count_block = $this->blocks['countBlock'];

	 	if (! $count_block->showTotal() )
	 		return ;

	 	$total = $count_block->get_total();
	 	$total_label = maxBlocks::getValue('total_count_label'); //$count_block->get_total_label();

		$total_html = '<div class="collection-item total">
				<div class="maxbutton-social-total">
					<div class="mb-icon-total"><i class="mb-icon-total-icon dashicons dashicons-share"></i></div>
				    <div class="mb-totals">
					<div class="mb-count-total">' . $total . '</div>
					<div class="mb-label-total">' . $total_label .'</div>
				   </div>
				</div>
			</div>';

		$collectionObj->find('.maxcollection',0)->innertext = $total_html;
	}

	public function createButton($args)
	{
		$defaults = array(
						'link' => 'javascript:void(0)',
						'classes' => array(),
						'item_classes' => array(),
						'name' => '',
					//	'show_share_count' => false,
					//	'share_count' => 0,
		);

		$args = wp_parse_args($args, $defaults);

		$item_classes = array_merge ($args['item_classes'], array($args['name']) );

		$icon_output = $this->styleObj->renderIcon($args['network']);


		$html = "<span class='collection-item " . implode(' ', $item_classes) . "'><a href='" . $args['link'] . "' class='maxbutton-social '>
								<span class='mb-icon-wrapper'>
									 " . $icon_output . " </span>	";

		//if ($args['show_share_count'])
		//	$html .= "<span class='share-count'>" . $args['share_count'] . "</span>";

		$html .= "</a></span>";


 		$button = str_get_html($html);
		return $button;
	}

	function parseCSS($args)
	{
		$css = array();
		if (! is_null($this->styleObj))
		{
			$prep_args = array(
					'orientation' => $this->orientation,
					'is_static' => $this->is_static,
					'is_mobile' => $this->is_mobile,
					'is_tablet' => $this->is_tablet,
					'is_post' => $this->is_post);

		   $this->styleObj->prepareCSS($prep_args);
			 $css = $this->styleObj->getCSS();
		}

		foreach($this->blocks as $block)
		{
			// This needs changes to accomodate to parse the defined SCSS stylesheet instead of using CSSParser which will not work here.
			// It will not work because CSSparse expects a very precise class definition and not a general broad definition of the items.
			$css = $block->parseCSS($css, $args);

		}

		// before the parse let have style have one more go
		$css = $this->styleObj->preParse($css);

		$css = $this->getCSSParser()->parse($css);

		return $css;
	}

	function parseJS($args)
	{
		$js = array();

		$defaults = array("preview" => false,
		);

		$args = wp_parse_args($args, $defaults);

		if ($args["preview"])
			return false; // no js on previews

		foreach($this->blocks as $block)
		{
			$js = $block->parseJS($js, $args);

		}

		return $js;
	}


	public function shortcode($atts, $content = null)
	{

		// ugly -need to rework logic here.
		//$collection = maxCollections::getCollection('social');
		$display_args = shortcode_atts(array(
					"echo" => false,
					"mode" => "normal",
					"nocache" => false,
					"style" => 'footer',
				),

		$atts);

		$collection_id = $this->collection_id;

		//$this->set($collection_id);
		$display_args["compile"] = $display_args["nocache"];
		$display_args['load_type'] = $display_args['style'];
		unset($display_args['style']);
		unset($display_args["nocache"]);

		$output = $this->display($display_args);

		return $output;
	}

	/** Metadata functions **/

	public function get_metadata($post_id)
	{
		if ( ! is_array($this->meta_data) || count ($this->meta_data) == 0)
		{
			$data = get_post_meta($post_id, 'mbsocial_data', true);
			$this->meta_data = $data;
		}

		return $this->meta_data;
	}

	public function do_meta_boxes($post_type, $post)
	{
		$content_blocks = array();

		foreach($this->blocks as $block)
		{
			$content_blocks = $block->do_meta_boxes($content_blocks, $post);
		}

		return $content_blocks;
	}

	/** @param $post_id Saving post_id
		@param $post  Post Array of submitted values
	**/
	public function save_meta_boxes($post_id, $post)
	{
		$post_meta = array();

		foreach($this->blocks as $block)
		{
			$post_meta = $block->save_meta_boxes($post_meta, $post_id, $post);

		}

		if (count($post_meta) > 0)
			update_post_meta($post_id, 'mbsocial_data', $post_meta);
	}


	// Get the pack definition that are present in the system.
	/*function editor_getPacks()
	{
		//$pack_paths = apply_filters('mb-col-pack-paths',  array(MB()->get_plugin_path() . "/") );
		$packs["maxbuttons"]["func"] = array($this, 'editor_getButtons');
		$packs["maxbuttons"]["tab"] = __("Your MaxButtons","maxbuttons");
		return $packs;

	} */

	/* public function ajax_getButtons($result, $data)
	{
		$packs = $this->editor_getPacks();
		$req_pack= $data["pack"];

		foreach($packs as $index => $pack_data)
		{
			if ($req_pack == $index)
			{
				$buttons = call_user_func($pack_data["func"], $index, $data);

			}
		}
		$output = '';


		$page_args = array();
		if (isset($data["paged"]))
		{
			$page_args["paged"] = $data["paged"];
		}

		if ($req_pack == 'maxbuttons')
		{
			$page_args["limit"] = 18;
			ob_start();
			do_action("mb-display-meta");
			do_action("mb-display-pagination", $page_args);
			$pagination = "<div class='tablenav top'>" .ob_get_contents() . "</div>";
			ob_end_clean();

		$output .= $pagination;
 		}

		foreach($buttons as $button)
		{
			$button_data = $button->get();

			$button_id = $button->getID();
			$name = $button->getName();

			$meta = isset($button_data["meta"]) ? $button_data["meta"] : array();
			do_action('mb-data-load',$button_data); // weakness of the bubbling filter model

			$output .= "<div class='item shortcode-container' data-id='$button_id'> ";
			$output .= $button->display(array("mode" => "preview", 'echo' => false, 'load_css' => 'inline') ); //"mode" => "preview", "compile" => true,
			$output .= "<span class='button_data'>" .  base64_encode(json_encode($button_data)) . "</span>";
			$output .= "<span class='button_name'>" . $name . "</span>";
			$output .= "</div>";

		}

		if ($req_pack == 'maxbuttons')
		{
			$output .= $pagination;
		}

		$result["body"] = $output;
		return $result;

	}
	*/

	// show the available buttons
	/* function editor_getButtons($pack, $data)
	{
		$button_array = array();

		$admin = MB()->getClass("admin");
		$button = MB()->getClass("button");

		$paged = (isset($data["paged"])) ? $data["paged"] : 1;

		$buttons = $admin->getButtons(array(
				"orderby" => "id",
				"order" => "DESC",
				"paged" => $paged,
				"limit" => 18,
		));


		foreach($buttons as $btn)
		{
			$id = $btn["id"];
			$b = MB()->getClass('button');
			$b->clear();
			$b->set($id);
			$button_data = $b->get();
			// exclude auto-generated non-user edited buttons.
			if ( ! isset($button_data["meta"]["user_edited"]) || ($button_data["meta"]["user_edited"] == true || $button_data["meta"]["created_source"] != "collection"))
				$button_array[]  = $b; // the object
		}
		return $button_array;
	} */


	function showBlocks()
	{
		maxBlocks::setData($this->data);
		foreach($this->blocks as $block)
		{
			echo $block->admin();
		}

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

		if ( is_array($active) && count($active) > 0)
		{


			foreach($active as $network_name)
			{
				$network = MbSocial()->networks()->get($network_name);
				echo $network->admin($this->data);
			}
		}
	}
} //class

```
