<?php
defined('ABSPATH') or die('No direct access permitted');
$collectionClass["social"] = "socialPROCollection"; 

// Add PRO features to social collection
class socialPROCollection extends socialCollection
{
 
	function editor_getPacks() 
	{	
		$packs = parent::editor_getPacks();

		$path = MB()->get_plugin_path(true) . "assets/packs/"; 
		$packs = array_merge($packs, $this->getSocialPacks($path)); 

		$maxPack = MB()->getClass('pack'); 
		$local_packs = $maxPack->get_local_packs();

		foreach($local_packs as $pack_name => $pack_files)
		{
			$maxPack->load_pack($pack_files); 
			
			$packs[$pack_name]["tab"] = $maxPack->getName();
			$packs[$pack_name]["func"] = array($this, 'editor_getPackButtons'); 
			$packs[$pack_name]["rel"] = ''; //unused here
		
		}
		//$title_pack = array_shift($packs); // this is 'your buttons'  

		ksort($packs);
		//array_unshift($packs, $title_pack);
					
		return $packs; 
		
	}
	
	function editor_getPackButtons($packname, $data = array() )
	{
		$packsClass = MB()->getClass("pack"); 

		$packs = $this->editor_getPacks(); 
		$data = $packs[$packname];  

		$packpath = MAXBUTTONS_PRO_PACKS_DIR . "/" . $packname . "/"; 
		$packurl = MAXBUTTONS_PRO_PACKS_URL . "/" . $packname . "/"; 

		$packdata = array("file" => $packpath . "$packname.xml", 
						    "img" => '', 
						    "dir" => $packurl, 
						    "is_local" => true,
					);
					
	
		$packsClass->setPackPath($packurl);			
		$packsClass->load_pack($packdata);
		$xml = $packsClass->getPackXML(); 



		foreach( $xml->maxbutton as $xmlbutton)
		{
			 
			$button_array =  $packsClass->parse_pack_button($xmlbutton);

			$button = MB()->getClass('button'); 
			$button->clear(); // also ensures all fields are loaded
				
			$meta = array("is_virtual" => true, // not a real button
						  "created_source" => "collection");
			$button_array["meta"]= json_encode($meta);			
 
			$button->setupData($button_array);

 		 
			if (isset($button_array["collection"])) 
			{
				$coldata = $button_array["collection"];
			
				// overloading the class to retrieve collection data later on social-block at adding time.  
				$button->setData("collection", $coldata); 
			
			} 
	 
			$buttons[] =  $button;
			
		}
		return $buttons;
		
 	}
}
