# maxbuttons/7.1.1/classes/pack.php

MaxButtons – Create buttons, version 7.1.1. 169 lines.

- Page: https://pluginprobe.com/plugins/maxbuttons/7.1.1/code/classes/pack.php
- Raw: https://pluginprobe.com/plugins/maxbuttons/7.1.1/raw/classes/pack.php
- Modified: 2018-04-25T12:02: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/maxbuttons/7.1.1/code/classes/pack.php#L10-L20`.

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

// basic pack reading functionality for social buttons
class maxPack
{
	protected $default_img_url = '';

	protected $pack_path = ''; // path of the pack with trailing slash
	protected $pack_dir = '';  // the name of the packs directory without path.
	protected $pack_xml = '';
	protected $pack_url = '';


	protected $img = '';
	protected $name = '';
	protected $author = '';
	protected $author_url = '';
	protected $description = '';
	protected $is_local = true;


	public function setPackPath($path)
	{
		$this->pack_path = $path;
	}

	public function getName()
	{
		return $this->name;
	}

	public function getAuthor()
	{
		return $this->author;
	}

	public function getDescription()
	{
		return $this->description;
	}


	public function load_pack($packdata)
	{
		$pack_file = $packdata["file"];
		$pack_img = $packdata["img"];
		$this->pack_dir = $packdata["dir"];

		$xml = simplexml_load_file($pack_file,null,  LIBXML_NOCDATA);

		if (! $xml)
		{
			MB()->add_notice('error', __( sprintf('Pack file could not be loaded', $pack_file), 'maxbuttons'));
			return false;
		}
		$this->pack_xml = $xml;

		$pack = $xml->pack[0];
		$packset = current($pack->attributes());
		$packset["image"] = $pack_img;
		$packset["is_local"] = $packdata["is_local"];

		$this->set_pack($packset);
		return true; // success
	}

	/* Return the full XML of the pack */
	public function getPackXML()
	{
		return $this->pack_xml;
	}

	/* Set all the pack attributes */
	function set_pack($pack)
	{
		$this->img = (isset($pack["image"])) ? $pack["image"] : '';
		$this->name = (isset($pack["name"])) ? $pack["name"] : '';
		$this->author = (isset($pack["author"])) ? $pack["author"] : '';
		$this->authorurl = (isset($pack["author_url"])) ? $pack["author_url"] : '';
		$this->description = (isset($pack["description"])) ? $pack["description"] : '';
		$this->is_local = $pack["is_local"];
		if (isset($pack["pack_dir"]))
			$this->pack_dir = $pack["pack_dir"];
		if (isset($pack["pack_url"]))
			$this->pack_url = $pack["pack_url"];

	}


	/* Parses old format and current format pack XML into a button_array which button setupdata understands */
	public function parse_pack_button($xmlbutton)
	{
		$button = MB()->getClass("button");
		if ( count($xmlbutton->attributes()) > 0)  // old button
				{

					$attrs = current($xmlbutton->attributes());

					$data = MB()->getClass("install")->convertOldFields($attrs);

					$button_array = array();
					$button_array["status"] = $data["status"];

					$data = $button->save($data,false); // convert from post var to block struct without dbase save


					foreach($data as $block => $values)
					{
						if (is_array($values))
							$button_array[$block] = json_encode($values);
						else
							$button_array[$block] = $values;
					}

				}
				else // new button
				{
					//$button = MB()->getClass("button");

					$button_array = json_decode(json_encode( (array)$xmlbutton), TRUE);

				//	$data = $button->save($button_array, false);
				}
				$temp_id = floor(rand(100000,990000));
				$button_array["id"] =  $temp_id; // fingers crossed

				// for some reason on json_decode when value is empty it created an empty array instead of string.
				foreach($button_array as $name => $values)
				{
					if (is_array($values) && count($values) == 0)
						$button_array[$name] = '';
				}


				// icons from pack
				$icon_array = array();

				if (isset($button_array["icon"]))
				{
					$icon_array = maybe_unserialize($button_array["icon"]);
					if (! is_array($icon_array))  // moving to json_encode
						$icon_array = json_decode($button_array["icon"], true);

						if (isset($icon_array["icon_url"]) && $icon_array["icon_url"] != '') {
							$path =  str_replace(array('http:','https:'), '', $this->pack_path); // allow for SSL / HTTP
							$icon_array["icon_url"] =  $path . $icon_array["icon_url"];  // pack path to allow for remote images
						}
						if (isset($icon_array['fa_icon_value']) && strlen($icon_array['fa_icon_value']) > 0)
						{
							$conversion_path = MB()->get_plugin_path() . '/assets/libraries/font-awesome-5/shims.json';
							$conversion_array = json_decode(file_get_contents($conversion_path), ARRAY_A);
							$old_value = $icon_array['fa_icon_value'];
							$old_value = str_replace('fa-','', $old_value);
							$icon_array['fa_icon_value'] = maxInstall::searchNewFA($old_value, $conversion_array);

						}

						$button_array['icon'] = json_encode($icon_array);
				}

		return $button_array;
	}



} // class

```
