text:
IBM offers concessions to settle EU antitrust probe
1 min read . Updated: 20 Sep 2011, 03:33 PM IST Foo Yun Chee/Reuters
IBMEUAntitrustProbeMainframeHardwareInvestigationInternational NewsEurope
Brussels: International Business Machines Corp (IBM) has offered concessions to settle a year-long investigation by EU antitrust regulators into its business practices, which could see it ward off a possible fine.
The European Commission opened a probe into IBM in July last year after competing suppliers of mainframe maintenance services accused the US-based company of discriminatory behaviour.
A preliminary finding showed IBM's practices "may amount to a constructive refusal to supply these inputs (required for the maintenance of IBM mainframe hardware and software)", the commission said in a statement on Tuesday.
"IBM does not agree with the commission's preliminary assessment. It has nevertheless offered commitments... to meet the commission's competition concerns," the EU's executive commission said.
IBM offered to provide certain spare parts and technical information to other companies which maintain its mainframe hardware and software under reasonable and non-discriminatory terms and conditions, said the commission, which acts as competition regulator in the 27-member EU.
The company proposed appointing a manager to handle dealings with other firms. The concessions would last for five years.
EU regulators said third parties now had a month to comment on the proposals. If the proposals were accepted, IBM would not be fined. Penalties for breaking the rules allow for fines of up to 10% of global revenues.
The commission also closed a separate investigation into IBM after three small rivals withdrew their complaints that the firm had tied its mainframe hardware with its operating system.
IBM had said at the time of the allegations that Microsoft and other competitors had inspired the actions by emulator software vendor T3 Technologies Inc. and France's TurboHercules.
The third complainant was Texas-based Neon Enterprise Software.
IBM welcomed the Commission's decision on both issues.
"IBM has put in place certain ... parts ordering procedures, and we look forward to that providing the basis for the final resolution," the company said in a statement.


text:
You are here: >Home Page >Biological Sciences >Ecology, Evolution, Organismal, and Behavioral Biology > Ecology (Intro) > The Ecology of Plants
Request Examination Copy
Buy Ebook from VitalSource
Buy Print Edition
The Ecology of Plants
Jessica Gurevitch, Samuel M. Scheiner, and Gordon A. Fox
Publication Date - July 2020
8 1/2 x 11 inches
Retail Price to Students: $154.99
A comprehensive and engaging university textbook in plant ecology
The Ecology of Plants provides comprehensive, contemporary coverage of plant ecology. Now in its third edition, the text incorporates current scientific developments and includes hundreds of stunning photographs, insightful illustrations, and references. It also features a clean, modern design that makes the material accessible and appealing. The book covers a range of current and historical ecological topics, presented in an evolutionary context, with the focus on the interactions between plants and their environments over a range of scales. Some of the subjects covered are unique to plants, such as photosynthesis and the ecology of plant-soil interactions; other topics, such as resource and mate acquisition, emphasize the distinctive ways plants (in contrast to animals) deal with their environments. The book uniquely emphasizes the importance of evolutionary and other historical ecological processes as well as human environmental influences. While the book is written for an undergraduate course in plant ecology, the engaging style, thorough coverage of the field, and contemporary perspective make it accessible and useful to others as well, including graduate students in conservation biology, evolutionary biologists and resource managers.
Includes new developments and ideas, as well as new evaluations of older work
An enlivened art program provides new, updated, and redrawn illustrations and photos
A redesigned layout with a clean, modern design makes the material accessible and appealing
Materials have been reorganized, consolidated, and developed in certain sections to include a fuller treatment: the section on how to think about and quantify diversity has been updated and consolidated into a single chapter, and the explanations of Earth's climate and climate change have been integrated, sharpened, and made clearer
Jessica Gurevitch is Distinguished Professor in the Department of Ecology and Evolution at Stony Brook University.
Samuel M. Scheiner is a researcher in ecology and evolution.
Gordon A. Fox is Adjunct Professor of Biology at the University of New Mexico, and Emeritus Professor of Integrative Biology at the University of South Florida.
Chapter 1. The Science of Plant Ecology
Part 1: Individuals and Their Environment
Chapter 2. Photosynthesis and Light
Chapter 3. Water Relations and Thermal Energy Balance
Chapter 4. Soil and Terrestrial Plant Life
Chapter 5. Ecosystem Processes
Part 2: From Individuals to Populations
Chapter 6. Individual Growth and Reproduction
Chapter 7. Plant Life Histories
Chapter 8. Population Structure, Growth, and Decline
Chapter 9. Evolution: Processes and Change
Part 3: Population Interactions and Communities
Chapter 10. Competition and Other Plant Interactions
Chapter 11. Herbivory and other Trophic Interactions
Chapter 12. Community diversity and structure
Chapter 13. Community dynamics and succession
Chapter 14. Local Abundance, Diversity, and Rarity
Part 4: From Landscapes to Planet Earth
Chapter 15. Landscapes: Pattern and Scale
Chapter 16. Climate, Plants, and Climate Change
Chapter 17. Paleoecology
Chapter 18. Biomes and Physiognomy
Chapter 19. Global Biodiversity Patterns, Loss, and Conservation
William D. Bowman and Sally D. Hacker
William D. Bowman, Sally D. Hacker, and Michael L. Cain
Plants, Genes, and Agriculture: Sustainability through Biotechnology
Maarten J. Chrispeels and Paul Gepts
Ecology: Evolution, Application, Integration
David T. Krohne
Anne Goodenough and Adam Hart
An Introduction to Molecular Ecology
Graham Rowe, Michael Sweet, and Trevor Beebee
A Primer of Ecological Statistics
Nicholas J. Gotelli and Aaron M. Ellison
A Primer of Ecology
Nicholas J. Gotelli
First Ecology: Ecological Principles and Enviromental Issues
Alan Beeby and Anne-Marie Brennan
Readings in Ecology
Stanley I. Dodson, Timothy F. H. Allen, Stephen R. Carpenter...
A Primer of Population Biology
Edward O. Wilson and William H. Bossert

redpajama_set_name: RedPajamaCommonCrawl


John M. Cogswell is not a widely recognized name within the Article V movement. The 79-year-old Cogswell is an attorney living in Buena Vista, Colorado. He is a graduate of Yale University and Georgetown Law Center, who has appeared before the US Court of Appeals for the District of Columbia, US District Courts in Colorado, Kansas and the District of Columbia, and the Supreme Courts of Colorado and Kansas.Cogswell has been practicing law for 48 years. He has been civically and politically active, and in 2011 he formed a group known as Campaign Constitution, focusing on the citizen powers locked up in the fifth Article of the US Constitution.During this past year, at the request of the new American Constitution Foundation (ACF), Cogswell invested more than 250 hours reading and carefully studying state applications for a convention to propose amendments as listed by the Article V Library (a feat very few other legal minds have attempted).He also studied the extensive research and writings of respected constitutional scholars Michael Stokes Paulsen and Robert G. Natelson… and related works by James Kenneth Rogers, Charles L. Black, Jr., Thomas M. Durbin, David C. Huckabee, and Yale constitutional law professor Akhil Amar.His objective was to analyze a recently completed study done by ACF that concluded that there currently are 37 valid applications for an Article V convention for proposing amendments. He compared the ACF study to a recent report by Natelson that concluded there are at least 33 existing applications that could be aggregated to justify the calling of a BBA-focused Article V convention.
In 2011 Paulson issued an opinion that at the time there was 33 valid current applications. Cogswell then used Paulsen's model (basis for counting aggregable state applications) and concluded that recent additions (after deducting rescissions) bring that number to at least 36… toward the 34 needed to trigger a Congressional Call for a plenary Article V convention to propose amendments.
Cogswell recently issued his legal opinion that a willing Congress could easily find sufficient state applications to justify an immediate Call for a convention of states under the terms of Article V. His 39-page (plus numerous pages of appendix documentation) opinion is not exactly bedtime reading, but should be read and studied by every state legislator, Article V activist, and member of Congress. Download and read Cogwell's opinion HERE, and his documentation Appendix HERE.
He also notes that "The made-up incorporation doctrine has been the chief mechanism through which a one-size-fits-all form of government, with all rights and powers emanating from Washington, D.C., has arisen. It has been the springboard from which our Constitutional Republic has been systematically dismantled." Read his piece HERE.
During December, Jurist (a publication self-described as "Legal News and Research – A collaboration with the University of Pittsburgh") carried a guest column entitled A Progressive Call for a Constitutional Convention by Roy Ulrich, of the University of California, Berkeley.
The piece includes some inaccurate facts and a questionable understanding of the foundation of Article V… but at least it reflects some perspective that so-called Progressives have about the potential bi-partisan benefits of an Article V convention. It can be read HERE.
Roman Buhler is an attorney and the Director of a group he calls The Madison Coalition. He has attended many Article V-related events over the past several years, although he is not really part of any of the groups seeking to use the second option in Article V. Buhler works mostly on efforts to get Congress to propose certain constitutional amendments.
Mr. Buhler's current primary focus is on getting Congress to propose the Regulation Freedom Amendment, a provision that would require that major new federal regulations be approved by Congress. He recently announced that US Senator David Perdue has endorsed his proposal.
Rather than using the states' "convention to propose amendments" provision in Article V, Buhler travels from state to state lobbying legislators to adopt resolutions "urging" Congress to adopt (propose) the amendment. He reports that some two dozen states have adopted his requested resolution. More details are available HERE.
Congress proposed the Equal Rights Amendment (ERA) in 1972. By the proposal's self-imposed deadline in 1977 only 35 states out of the needed 38 had ratified the proposed constitutional amendment. Congress then purported to extend the ratification deadline by another five years. During that time no other states ratified it.
In 2017 the Nevada legislature adopted a measure to ratify the proposed constitutional amendment. In 2018 the Illinois legislature also purported to ratify the ERA. The two states consider those to be the 36th and 37th ratifications (although since 1977 four or five states have taken actions to rescind their earlier ratifications).
Now comes Missouri. According to the Joplin Globe a group calling itself ERA38 has formed in an attempt to get the 2019 session of the Missouri legislature to belatedly adopt a ERA ratification resolution. The measure was actually approved in 1975 by the Missouri House, but the Senate has consistently declined to ratify the ERA.
This coming session the newly organized ERA38 plans to work closely with Senator Schupp. Read the detailed Joplin Globe article HERE.
Readers who are interested in this topic should also read "Let's not waste time reviving the zombie Equal Rights Amendment" by constitutional historian Rob Natelson. It was published in The Hill on November 6, 2017 and can be found HERE.
The Law of Article V is a newly released book by Professor Robert G. Natelson. Described as "primarily a work for attorneys", it is a book that will answer most of the questions American citizens and legislators have about the fifth Article of the US Constitution.
Natelson, described as "America's leading active scholar on the constitutional amendment process" uses his new book to demonstrate how Americans can fix the broken federal government by using the constitutional provision the Founders provided. The 136-page paperback book can be purchased HERE.
Harvard Professor Lawrence Lessig is considered an expert on constitutional law and has often opined on Article V issues, but his newest book is much broader. His new book, America, Compromised discusses what he describes as the increased levels of corruption permeating the fabric of America.
While the book is not entirely government-focused, Lessig clearly believes Congress is corrupt, even as he expresses his opinion that the overwhelming majority of members of Congress are not. Buy his book HERE.
Rep Murphy was the first Democrat to introduce a balanced budget amendment during the 115th Congress. Her bill was endorsed by the Blue Dog Coalition. Read more about her HERE.
During December the Associated Press produced an article about Dennis Daugaard the retiring governor of South Dakota. Daugaard was credited with orchestrating a massive cut in state spending to erase a budget deficit early in his first term and then championed less popular tax hikes in his second term.
He was also credited for successfully urging voters to adopt a balanced budget amendment to the state's constitution, an action which helped the state achieve an AAA credit rating. Although the article did not mention it, during Daugaard's leadership the South Dakota legislature adopted one of the 28 existing applications for a BBA-focused Article V convention.
Interestingly the Daugaard story was carried in the Idaho Statesman where their legislature has twice defeated efforts to adopt an application for an Article V convention that could lead to fiscal restraints at the federal level. If the article is still posted, read the Statesman article HERE.
A month before Mick Mulvaney was appointed as President Trump's Acting Chief of Staff he was a guest speaker at the 2018 ALEC States and Nation Policy Summit in Washington DC.
He went on to say, "Spending is not going to solve itself," and then he stressed that every time a state legislature adopts a balanced budget amendment to its own state constitution it sets an example for the federal government. "The more you folks (at the state level) put those fiscally responsible principles to work, the more influence you can have over (the federal government)." See and hear Mulvaney's presentation HERE.
The young writer concluded by saying, "A Balanced Budget Amendment is necessary to place a constraint on our elected officials – to reinforce that one of their primary responsibilities is to spend taxpayer money appropriately, without putting the country's future further into an almost insurmountable debt." Read the article HERE.
Earlier in the year that same student publication carried a piece entitled Up to Us Campaign Takes on National Debt. It detailed efforts by a relatively unknown group of college-age Americans operating under the name Up to Us. The organization is co-sponsored by the Peter G. Peterson Foundation, Net Impact, and the Clinton Global Initiative University.
Up to Us is described as "a rapidly growing, nonpartisan movement of young people who are passionate about raising awareness on the debt. Since its inception … Up to Us has engaged nearly 150,000 people through over 400 college teams." Read this article HERE.
Other college students are working on such things as limiting the terms of political leaders. That's one of the topics, hosted by US Term Limits, that will be addressed at LibertyCon, a conference of students from around the world, operated by a group called Students for Liberty January 17-19, 2019 at the Marriott Marquis Hotel in Washington, DC.
Blogger Rodney Dodsworth has just released a reminder of James Madison's words in 1787 when he wrote what became known as the 14th Federalist Paper. They are words that every legislator (state and federal) and every Article V activist should read and consider.
Madison writes about the question as to whether liberty can be preserved across a continent. He challenges readers to not listen to naysayers, and to consider the blessings of America's special kind of republic.
Dodsworth says, "As pundits and patriots today wonder if resolution of the centrifugal forces that threaten the American Union is possible, perhaps we can find solace in the words of James Madison." Politics involves compromise. Hopefully both political leaders and the leaders of Article V movements can benefit from Madison's words to look beyond the shrill voices of disunity and find compromise where needed. Read Madison's words HERE.
for members of the United States Congress.


Everyone at a CPS community forum in the spring of 2009 opposed the closing of Gladstone elementary with 300 students. Mike Milkie crosses a picket line at Gladstone Elementary. Photo by David VanceNoble officials crossed the student picket line, including former CEO of Noble, Mike Milkie. Gladstone elementary, 1231 S Damen Ave., was closed in 2009, despite widespread opposition, and the building given to Noble charter.After 100 years of education history, Gladstone is gone. Another public building given to a private operator.
School community members, from more than 50 Chicago public schools, opposed the board of eduction's closures and charter school replacements in the 2000s. Gladstone protested in 2009 as Noble took over. There are now 56 charter elementary schools and 65 charter high schools in Chicago.
The outgoing head of Chicago's largest and top-performing charter school network is being investigated following allegations of inappropriate behavior toward young female alumnae, WBEZ has learned.
In a statement, Mike Milkie acknowledged he "acted inappropriately toward adult women affiliated with Noble." He said that is why he announced his retirement last week as CEO of Noble Network of Charter Schools.
"This is why I am rightly no longer CEO," Milkie said. " I am very sorry and apologize first to those impacted by my inappropriate interactions. I also apologize to my family and to my friends. I let you down. Finally, I apologize to the students, alumni, families, and supporters of Noble. I let you down, too." Noble runs 17 charter high schools and one middle school that serve more than 12,000 students. Many Noble campuses are high performing and viewed as models of success. The charter network is also a darling of the city's rich and powerful, with campuses bearing such names as Rauner, Pritzker and Chicago Bulls.
On Tuesday, Noble Board President Allan Muchin confirmed to WBEZ that the board was investigating Milkie, 57. The board has hired an outside law firm to conduct the investigation of Milkie.
The board was notified after two top Noble leaders, then-president and now CEO Constance Jones, and Head of Schools Ellen Metz, confronted Milkie in October. They cited "a pattern of inappropriate behavior across several incidents, including hand holding and slow dancing with an alumna," according to a statement released by the charter network. The two leaders said they lacked confidence in Milkie's leadership.
When faced with this information, Milkie chose to retire, the statement said.
"At no point did Noble leadership have knowledge of allegations that required mandated reporting, nor that were criminal in nature," Noble said in the statement. Noble also said the outside law firm will review the charter network's reporting processes for allegations of inappropriate behavior.
Gladstone community signs in 2009. WBEZ interviewed one alumna who said Milkie used his powerful position several years ago to put her in a terrible situation. She was in her early 20s, and just out of college, when she was asked to chaperone a college trip Milkie was taking with a handful of current Noble students. After having dinner with students, he took her into the college town and they went to a bar.
She said he pushed her to drink, despite several refusals. She said she then left to go back to the hotel and, on the way back, he held her hand.
She was so afraid of Milkie that she barricaded herself in her room and called her boyfriend to pick her up.
The young woman had plans to become a teacher, working under Milkie at one of the Noble campuses.
Once back in Chicago, she said Milkie called and texted her incessantly until she finally answered and told him to stop.
The Noble graduate said she shared her harrowing story with the Noble staffer who hired her to chaperone the college visit. She doesn't know what, if anything, came of her complaint.
A senior Noble staff member told WBEZ about allegations against Milkie as well. When this staffer was principal at a Noble campus, female students told a teacher Milkie made them feel uncomfortable, she said. The students said Milkie paid girls more attention than boys and took a personal interest in their lives. The principal looked into the allegations and concluded they didn't rise to a level that further action was required. This Noble staffer also requested anonymity by WBEZ.
A third woman connected to Noble — another recent graduate — described to WBEZ efforts by Milkie to forge a relationship with her when she was a student. He never crossed a line, the 2015 graduate said, but his repeated efforts to seek her out at lunchtime, to take her on college trips, to babysit his children, made her feel targeted and uncomfortable.
Muchin said it was important for the board to take action.
"When you have someone running schools, you have to take these situations seriously," he said.
Muchin did not want to discuss what steps the board may take if the investigation turns up serious wrongdoing.
WBEZ reporter Linda Lutton contributed to this story.
Unfortunately, these pedophiles lurk around our children. Imagine -- inviting your prey to babysit your kids while your wife's away -- thats sick. Amazed this man isn't in prison. Most people defend themselves. This guy is so guilty of the things yet to be revealed he went into hiding.
Coach Sandusky is doing 30-60 years for this kind of behavior. I'm sure more victims will need to come out into the open to put this kind of person away. The fact he blatantly admitted to fact and went into hiding should ring some serious alarm bells here.


A former Key Executive Officer of an estate agent, Nicholas Kok Chiew Leong, was convicted and sentenced in April 2014 for handling transaction monies. Kok was fined $2,500 for handling an option exercise fee of $4,000 for his clients. Another charge of a similar breach was taken into consideration for sentencing.
A couple engaged Kok to purchase a unit in Clementi. They made an offer for the unit after the second viewing. Two days after making the offer, Kok's clients handed him $1,000 in cash, the proposed option fee and they signed the resale checklist and Option to Purchase. Two weeks later, they handed Kok the option exercise fee of $4,000, which he subsequently passed to the sellers.
CEA advises consumers not to hand transaction monies to salespersons. Salespersons are not allowed to handle transaction monies in order to protect the clients' interest and to minimise the risk involved in loss of sales proceeds. Consumers are asked not to request their salespersons to handle transaction monies as the latter would end up committing an offence.
This entry was posted in CEA and tagged CEA, Council for Estate Agencies, KEO, Nicholas Kok Chiew Leong, transaction monies. Bookmark the permalink.


Profitability is a preeminent thought about when you play on the web. As a territory, you ought to in all regards likely find, how the on-line online club. you pick will no doubt give sufficient security for any exchanges you make on the web and is set up to arrangement with any sort of good conditions material confirmation exigencies. This makes it key to set aside a few minutes, how in truth comprehended, astonishing and safe the singled out the web betting establishment is. Despite reality that it is troublesome, everything considered staggering, to get any kind of affirmation, you could review the related while meanwhile picking a web wagering club. If the right answer was genuinely, around then it might recommend that the electronic wagering club is especially related and obvious. Article judgment deals with this conspicuously flawed web wagering club that may be does not give fulfilling best quality and flourishing appraisals would stop being seen and coordinated high on any web searcher. This really cannot abstain from being truly not an over any shortcoming chance structure yet you can utilize the SERP redirection course of action to waitlist the pompous web wagering clubs.
There's nothing at all perfect over have bal' decree. Pick web wagering clubs that can go to a stunning degree endorsed by amigos and accomplices. In the a long way from condition they may have played on-line or in case they understand a person who has performed on the web and sent back having a without inquiry issue, odds are, the online wagering club they have frequented is palatable confirmed. Scan for after for thriving and security related contacts that give a few information about SSL or computerized record encryption update used, and quality lodgings separated for after on the site. A web subordinate online club which gives out key information concerning the consistency, brands demonstrated the veracity of invigorates from confided in resources like Wager Performs, Small PC excitements, Partech, Crypto structure for considering and plans its statement sorts is most obviously totally veritable to be considered as a choice.
View decisions like burst betting establishments. Since you do not need to get and show anything or association, the likelihood of imperiling the security of your own Laptop or PC is effectively sensible. Take a gander at spaces that give information and organizing on web club. You may need to isolate down respect any on the web wagering club that may be all around successfully misused. Endeavor to discover experiences concerning advancements utilized in web club and the dimension of affirmation they offer 안전놀이터. It bodes enough to contribute power and exertion to settle on illuminating confirmation before beginning as a choice as opposed to lamenting later on.


text:
Gordon Brand may refer to:

Gordon Brand Jnr (1958–2019), Scottish golfer
Gordon J. Brand (1955–2020), English golfer

redpajama_set_name: RedPajamaWikipedia


Buying into the high life isn't frivolous—it's an investment!
How to do it: If you don't have the pockets for a Picasso, try exploring contemporary art by young or emerging artists, suggests Michael Plummer, principal and cofounder of Artvest Partners. He often points new collectors toward unique works on paper, such as drawings or watercolors.
Remember this: Global sales of art surpassed $64 billion in 2011, triple the 2002 total; in fact, art has even outperformed the S&P 500 over the past 10 years. And as with any investment, diversifying your art casts a wider net for future earnings. Jump in now and hold tight.
And don't forget: Fancy paintings may impress her, but even that Renoir won't matter if one place isn't up to her standards. Find out What Your Bathroom Is Telling Her.
How to do it: "Vintage and producer mean everything," says 20-year collector Keith Williams. Buy high-quality cases that are in limited supply and watch values rise. "I bought a 1982 Chateau Lafite-Rothschild at $150 and recently sold the bottle for $4,000." That's a 2,567 percent jump.
Remember this: As the Chinese market booms, standard French bottles continue to reign at auction, especially the top-tier brands, categorized Grand Cru. For value, Williams researches the best names (such as Chateau Lafon-Rochet) four or five classifications below top quality.
Can't swing high-end vino? No problem—these 16 Wines for Under $15 will do just fine.
How to do it: Find a racing outfit that offers general or limited partnerships, which allow several investors to share ownership. Brokers with racetrack know-how can advise you, or you can find a source through the Thoroughbred Owners and Breeders Association.
Remember this: Wins and pedigree drive value. Even modest-stakes winners with fine pedigrees can turn a profit breeding, says Cot Campbell, president of Dogwood Stable in South Carolina. "We might buy a yearling for $100,000 and sell him for a multimillion stallion career 3 years later."
How to do it: Buy quality. Commit these timepiece brands to memory: Patek Philippe, Rolex, Audemars Piguet, A. Lange & Sohne, and Vacheron Constantin. "Watches hold value over the long term," says Doug Escribano, a specialist in the watch department at Christie's.
Remember this: Returns vary widely depending on the brand, period, and scarcity of the timepiece. (Last year, a 1965 open-face Patek Philippe sold for $962,500.) Condition is extremely important, Escribano says, and can double the auction value. So wear it with care.
Of course, a great watch doesn't need to run you as much as a used car. Sign up for the Men's Health Style Siren newsletter for more affordable (but just as stylish) picks.
How to do it: Smarten up by joining a car club. Then shop at auctions (including eBay). Motorpool.com CEO Morgan Murphy suggests looking for "fringe" cars in popular genres. For example, a '63 Buick Riviera (a "muscle car in disguise") can cost a fraction of the price of a '65 Shelby GT350.
Remember this:Murphy's bought 43 classic cars and hasn't lost a nickel. In fact, he says he's seen double annual returns in some cases. "But I'm prepared to hold a car 5 years," he adds. Going forward, Murphy says, "I'm looking to the 1980s, especially Jeep Grand Wagoneers and BMW 3 Series."
How do I break it to my bro that I don't want to invest in his pub?


text:
<?php
/**
 * Custom Meta Box Class
 *
 * The Meta Box Class is used by including it in your plugin files and using its methods to
 * create custom meta boxes for custom post types. It is meant to be very simple and
 * straightforward. For name spacing purposes, All Types metabox ( meaning you can do anything with it )
 * is used.
 *
 * This class is derived from Ohad Raz (email: admin@bainternet.info) and Meta Box script by Rilwis<rilwis@gmail.com> version 3.2.
 * which later was forked by Cory Crowley (email: cory.ivan@gmail.com) The purpose of this class is not to rewrite the script but to
 * modify and change small things and adding a few field types that i needed to my personal preference.
 * The original author did a great job in writing this class, so all props goes to him.
 *
 * @category CyberChimps Framework
 * @package  Framework
 * @since    1.0
 * @author   CyberChimps
 * @license  http://www.opensource.org/licenses/gpl-license.php GPL v3.0 (or later)
 * @link     http://www.cyberchimps.com/
 */

// TODO CyberChimps have changed the markup of this class don't just update by copying over it

if( !class_exists( 'AT_Meta_Box' ) ) :

	/**
	 * All Types Meta Box class.
	 *
	 * @package All Types Meta Box
	 * @since 1.0
	 *
	 * @todo Nothing.
	 */
	class AT_Meta_Box {

		/**
		 * Holds meta box object
		 *
		 * @var object
		 * @access protected
		 */
		protected $_meta_box;

		/**
		 * Holds meta box fields.
		 *
		 * @var array
		 * @access protected
		 */
		protected $_prefix;

		/**
		 * Holds Prefix for meta box fields.
		 *
		 * @var array
		 * @access protected
		 */
		protected $_fields;

		/**
		 * Use local images.
		 *
		 * @var bool
		 * @access protected
		 */
		protected $_Local_images;

		/**
		 * SelfPath to allow themes as well as plugins.
		 *
		 * @var string
		 * @access protected
		 * @since 1.6
		 */
		protected $SelfPath;

		/**
		 * $field_types  holds used field types
		 * @var array
		 * @access public
		 * @since 2.9.7
		 */
		public $field_types = array();

		/**
		 * $inGroup  holds groupping boolean
		 * @var boolean
		 * @access public
		 * @since 2.9.8
		 */
		public $inGroup = false;

		/**
		 * Constructor
		 *
		 * @since 1.0
		 * @access public
		 *
		 * @param array $meta_box
		 */
		public function __construct( $meta_box ) {

			// If we are not in admin area exit.
			if( !is_admin() ) {
				return;
			}

			//load translation
			add_filter( 'init', array( $this, 'load_textdomain' ) );

			// Assign meta box values to local variables and add it's missed values.
			$this->_meta_box     = $meta_box;
			$this->_prefix       = ( isset( $meta_box['prefix'] ) ) ? $meta_box['prefix'] : '';
			$this->_fields       = $this->_meta_box['fields'];
			$this->_Local_images = ( isset( $meta_box['local_images'] ) ) ? true : false;
			$this->add_missed_values();

			if( isset( $meta_box['use_with_theme'] ) ) {
				if( $meta_box['use_with_theme'] === true ) {
					$this->SelfPath = get_stylesheet_directory_uri() . '/cyberchimps/options/meta-box-class';
				}
				elseif( $meta_box['use_with_theme'] === false ) {
					$this->SelfPath = plugins_url( 'meta-box-class', plugin_basename( dirname( __FILE__ ) ) );
				}
				else {
					$this->SelfPath = $meta_box['use_with_theme'];
				}
			}
			else {
				$this->SelfPath = plugins_url( 'meta-box-class', plugin_basename( dirname( __FILE__ ) ) );
			}

			// Add metaboxes
			add_action( 'add_meta_boxes', array( $this, 'add' ) );
			//add_action( 'wp_insert_post', array( $this, 'save' ) );
			add_action( 'pre_post_update', array( $this, 'save' ) );
			// Load common js, css files
			// Must enqueue for all pages as we need js for the media upload, too.
			add_action( 'admin_print_styles', array( $this, 'load_scripts_styles' ) );
			//limit File type at upload
			add_filter( 'wp_handle_upload_prefilter', array( $this, 'Validate_upload_file_type' ) );

		}

		/**
		 * Load all Javascript and CSS
		 *
		 * @since 1.0
		 * @access public
		 */
		public function load_scripts_styles() {

			// Get Plugin Path
			$plugin_path = $this->SelfPath;

			// Set template directory uri
			$directory_uri = get_template_directory_uri();
			$metabox_uri = $directory_uri . '/cyberchimps/options/meta-box-class';

			//only load styles and js when needed
			/*
	 * since 1.8
	 */
			global $typenow;
			if( in_array( $typenow, $this->_meta_box['pages'] ) && $this->is_edit_page() ) {
				// Enqueue Meta Box Style
				wp_enqueue_style( 'at-meta-box', $metabox_uri . '/css/meta-box.css' );

				// Load color picker
				wp_enqueue_style( 'color-picker', $directory_uri . '/cyberchimps/options/lib/css/colorpicker.css' );
				wp_enqueue_script( 'color-picker-js', $directory_uri . '/cyberchimps/options/lib/js/colorpicker.min.js', array( 'jquery' ), '', true );

				// Enqueue Meta Box Scripts
				wp_enqueue_script( 'at-meta-box', $metabox_uri . '/js/meta-box.min.js', array( 'jquery' ), null, true );
				// Enqueue Cyberchimps Scripts
				wp_enqueue_script( 'meta-boxes-js', $metabox_uri . '/js/metabox-tabs.min.js', array( 'jquery' ), null, true );
				// Enqueue Media uploader for single images TODO look into removing this and use this classes image uploader that saves images as an array. Will need to change all elements to be
//              TODO able to work with this
				wp_enqueue_script( 'cc-media-uploader-js', get_template_directory_uri() . '/cyberchimps/lib/js/media-uploader-new.min.js', array( 'jquery' ), null, true );

				// Make upload feature work event when custom post type doesn't support 'editor'
				if( $this->has_field( 'image' ) || $this->has_field( 'file' ) ) {
					wp_enqueue_script( 'media-upload' );
					add_thickbox();
					wp_enqueue_script( 'jquery-ui-core' );
					wp_enqueue_script( 'jquery-ui-sortable' );
				}
				// Check for special fields and add needed actions for them.

				//this replaces the ugly check fields methods calls
				foreach( array( 'upload', 'color', 'date', 'time', 'select' ) as $type ) {
					call_user_func( array( $this, 'check_field_' . $type ) );
				}
			}

		}

		/**
		 * Check the Field select, Add needed Actions
		 *
		 * @since 2.9.8
		 * @access public
		 */
		public function check_field_select() {

			// Check if the field is an image or file. If not, return.
			if( !$this->has_field( 'select' ) ) {
				return;
			}
			$plugin_path = $this->SelfPath;
			// Enqueu JQuery UI, use proper version.

			// Enqueu JQuery select2 library, use proper version.
//            wp_enqueue_style( 'at-multiselect-select2-css', $plugin_path . '/js/select2/select2.css', array(), null );
//            wp_enqueue_script( 'at-multiselect-select2-js', $plugin_path . '/js/select2/select2.js', array( 'jquery' ), false, true );
		}

		/**
		 * Check the Field Upload, Add needed Actions
		 *
		 * @since 1.0
		 * @access public
		 */
		public function check_field_upload() {

			// Check if the field is an image or file. If not, return.
			if( !$this->has_field( 'image' ) && !$this->has_field( 'file' ) ) {
				return;
			}

			// Add data encoding type for file uploading.
			add_action( 'post_edit_form_tag', array( $this, 'add_enctype' ) );

		}

		/**
		 * Add data encoding type for file uploading
		 *
		 * @since 1.0
		 * @access public
		 */
		public function add_enctype() {
			printf( ' enctype="multipart/form-data" encoding="multipart/form-data" ' );
		}

		/**
		 * Check Field Color
		 *
		 * @since 1.0
		 * @access public
		 */
		public function check_field_color() {

			if( $this->has_field( 'color' ) && $this->is_edit_page() ) {
				wp_enqueue_style( 'wp-color-picker' );
				wp_enqueue_script( 'wp-color-picker' );
			}
		}

		/**
		 * Check Field Date
		 *
		 * @since 1.0
		 * @access public
		 */
		public function check_field_date() {

			if( $this->has_field( 'date' ) && $this->is_edit_page() ) {
				// Enqueu JQuery UI, use proper version.
				$plugin_path = $this->SelfPath;
				wp_enqueue_style( 'at-jquery-ui-css', $plugin_path . '/js/jquery-ui/jquery-ui.css' );
				wp_enqueue_script( 'jquery-ui' );
				wp_enqueue_script( 'jquery-ui-datepicker' );
			}
		}

		/**
		 * Check Field Time
		 *
		 * @since 1.0
		 * @access public
		 */
		public function check_field_time() {

			if( $this->has_field( 'time' ) && $this->is_edit_page() ) {
				$plugin_path = $this->SelfPath;
				// Enqueu JQuery UI, use proper version.
				wp_enqueue_style( 'at-jquery-ui-css', $plugin_path . '/js/jquery-ui/jquery-ui.css' );
				wp_enqueue_script( 'jquery-ui' );
				wp_enqueue_script( 'at-timepicker', $plugin_path . '/js/jquery-ui/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-slider', 'jquery-ui-datepicker' ), false, true );
			}
		}

		/**
		 * Add Meta Box for multiple post types.
		 *
		 * @since 1.0
		 * @access public
		 */
		public function add( $postType ) {
			if( in_array( $postType, $this->_meta_box['pages'] ) ) {
				add_meta_box( $this->_meta_box['id'], $this->_meta_box['title'], array( $this, 'show' ), $postType, $this->_meta_box['context'], $this->_meta_box['priority'] );
			}
		}

		/**
		 * Callback function to show fields in meta box.
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show() {
			$this->inGroup = false;
			global $post;

			wp_nonce_field( basename( __FILE__ ), 'at_meta_box_nonce' );
			echo '
';

			foreach( $this->_fields as $field ) {
				$field['multiple'] = isset( $field['multiple'] ) ? $field['multiple'] : false;
				$meta              = get_post_meta( $post->ID, $field['id'], !$field['multiple'] );
				$meta              = ( $meta !== '' ) ? $meta : @$field['std'];

				if( !in_array( $field['type'], array( 'image', 'repeater', 'file' ) ) ) {
					$meta = is_array( $meta ) ? array_map( 'esc_attr', $meta ) : esc_attr( $meta );
				}

				$class = ( ( $field['class'] != '' ) ) ? ' class="' . $field['class'] . '-container"' : '';
				if( $this->inGroup !== true ) {
					echo '
';
				}

				if( isset( $field['group'] ) && $field['group'] == 'start' ) {
					$this->inGroup = true;
					echo '

';
				}

				// Call Separated methods for displaying each type of field.
				call_user_func( array( $this, 'show_field_' . $field['type'] ), $field, $meta );

				if( $this->inGroup === true ) {
					if( isset( $field['group'] ) && $field['group'] == 'end' ) {
						echo '

';
						$this->inGroup = false;
					}
				}
				else {
					echo '
';
				}
			}
			echo '
';
		}

		/**
		 * Show Repeater Fields.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_repeater( $field, $meta ) {
			global $post;
			// Get Plugin Path
			$plugin_path = $this->SelfPath;
			$this->show_field_begin( $field, $meta );
			$class = '';
			if( $field['sortable'] ) {
				$class = " repeater-sortable";
			}
			echo "
";

			$c    = 0;
			$meta = get_post_meta( $post->ID, $field['id'], true );

			if( count( $meta ) > 0 && is_array( $meta ) ) {
				foreach( $meta as $me ) {
					//for labling toggles
					$mmm = isset( $me[$field['fields'][0]['id']] ) ? $me[$field['fields'][0]['id']] : "";
					if( in_array( $field['fields'][0]['type'], array( 'image', 'file' ) ) ) {
						$mmm = $c + 1;
					}
					echo '
' . $mmm . '

';
					if( $field['inline'] ) {
						echo '
';
					}
					foreach( $field['fields'] as $f ) {
						//reset var $id for repeater
						$id = '';
						$id = $field['id'] . '[' . $c . '][' . $f['id'] . ']';
						$m  = isset( $me[$f['id']] ) ? $me[$f['id']] : '';
						$m  = ( $m !== '' ) ? $m : $f['std'];
						if( 'image' != $f['type'] && $f['type'] != 'repeater' ) {
							$m = is_array( $m ) ? array_map( 'esc_attr', $m ) : esc_attr( $m );
						}
						//set new id for field in array format
						$f['id'] = $id;
						if( !$field['inline'] ) {
							echo '
';
						}
						call_user_func( array( $this, 'show_field_' . $f['type'] ), $f, $m );
						if( !$field['inline'] ) {
							echo '
';
						}
					}
					if( $field['inline'] ) {
						echo '
';
					}
					echo '
';
					if( $field['sortable'] ) {
						echo '';
					}

					echo '

';
					$c = $c + 1;
				}
			}

			echo '_Local_images ) {
				echo $plugin_path . '/images/add.png';
			}
			else {
				echo 'http://i.imgur.com/w5Tuc.png';
			}
			echo '" alt="' . __( 'Add', 'cyberchimps_core' ) . '" title="' . __( 'Add', 'cyberchimps_core' ) . '" id="add-' . $field['id'] . '">

';

			//create all fields once more for js function and catch with object buffer
			ob_start();
			echo '

';
			if( $field['inline'] ) {
				echo '
';
			}
			foreach( $field['fields'] as $f ) {
				//reset var $id for repeater
				$id      = '';
				$id      = $field['id'] . '[CurrentCounter][' . $f['id'] . ']';
				$f['id'] = $id;
				if( !$field['inline'] ) {
					echo '
';
				}
				if( $f['type'] != 'editor' ) {
					call_user_func( array( $this, 'show_field_' . $f['type'] ), $f, '' );
				}
				else {
					call_user_func( array( $this, 'show_field_' . $f['type'] ), $f, '', true );
				}
				if( !$field['inline'] ) {
					echo '
';
				}
			}
			if( $field['inline'] ) {
				echo '
';
			}
			echo '

';
			$counter = 'countadd_' . $field['id'];
			$js_code = ob_get_clean();
			$js_code = str_replace( "\n", "", $js_code );
			$js_code = str_replace( "\r", "", $js_code );
			$js_code = str_replace( "'", "\"", $js_code );
			$js_code = str_replace( "CurrentCounter", "' + " . $counter . " + '", $js_code );
			echo '';
			echo '
';
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Begin Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_begin( $field, $meta ) {
			echo "inGroup === true ) ? " valign='top'" : "" ) . ">";
			if( $field['name'] != '' || $field['name'] != false ) {
				echo "
";
				echo "{$field['name']}";
				echo "
";
			}
		}

		/**
		 * End Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_end( $field, $meta = null, $group = false ) {
			//print description
			if( isset( $field['desc'] ) && $field['desc'] != '' ) {
				echo "
{$field['desc']}
";
			}
			echo "	";
		}

		/**
		 * Show Field Text.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_text( $field, $meta ) {
			$this->show_field_begin( $field, $meta );
			echo "<input type='text' class='at-text" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' id='{$field['id']}' value='{$meta}' size='30' " . ( isset( $field['style'] ) ? "style='{$field['style']}'" : '' ) . "/>";
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Field number.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_number( $field, $meta ) {
			$this->show_field_begin( $field, $meta );
			$step = ( isset( $field['step'] ) || $field['step'] != '1' ) ? "step='" . $field['step'] . "' " : '';
			$min  = isset( $field['min'] ) ? "min='" . $field['min'] . "' " : '';
			$max  = isset( $field['max'] ) ? "max='" . $field['max'] . "' " : '';
			echo "<input type='number' class='at-number" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' id='{$field['id']}' value='{$meta}' size='30' " . $step . $min . $max . ( isset( $field['style'] ) ? "style='{$field['style']}'" : '' ) . "/>";
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Field hidden.
		 *
		 * @param string $field
		 * @param string|mixed $meta
		 *
		 * @since 0.1.3
		 * @access public
		 */
		public function show_field_hidden( $field, $meta ) {
			//$this->show_field_begin( $field, $meta );
			echo "<input type='hidden' " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . "class='at-text" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' id='{$field['id']}' value='{$meta}'/>";
			//$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Field Paragraph.
		 *
		 * @param string $field
		 *
		 * @since 0.1.3
		 * @access public
		 */
		public function show_field_paragraph( $field ) {
			//$this->show_field_begin( $field, $meta );
			echo '
' . $field['value'] . '
';
			//$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Field Textarea.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_textarea( $field, $meta ) {
			$this->show_field_begin( $field, $meta );
			echo "<textarea class='at-textarea large-text" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' id='{$field['id']}' " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " cols='60' rows='10'>{$meta}</textarea>";
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Field Unfiltered Textarea.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_unfiltered_textarea( $field, $meta ) {
			$this->show_field_begin( $field, $meta );
			echo "<textarea class='at-textarea large-text" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' id='{$field['id']}' " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " cols='60' rows='10'>{$meta}</textarea>";
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Field Select.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_select( $field, $meta ) {

			if( !is_array( $meta ) ) {
				$meta = (array)$meta;
			}

			$this->show_field_begin( $field, $meta );
			echo "<select " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " class='at-select" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}" . ( $field['multiple'] ? "[]' id='{$field['id']}' multiple='multiple'" : "'" ) . ">";
			foreach( $field['options'] as $key => $value ) {
				echo "<option value='{$key}'" . selected( in_array( $key, $meta ), true, false ) . ">{$value}</option>";
			}
			echo "</select>";
			$this->show_field_end( $field, $meta );

		}

		/**
		 * Show Radio Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_radio( $field, $meta ) {

			if( !is_array( $meta ) ) {
				$meta = (array)$meta;
			}

			$this->show_field_begin( $field, $meta );
			foreach( $field['options'] as $key => $value ) {
				echo "<input type='radio' " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " class='at-radio" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' value='{$key}'" . checked( in_array( $key, $meta ), true, false ) . " /> {$value}";
			}
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Checkbox Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_checkbox( $field, $meta ) {

			$this->show_field_begin( $field, $meta );
			echo "<input type='checkbox' " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " class='rw-checkbox" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' id='{$field['id']}'" . checked( !empty( $meta ), true, false ) . " />";
			$this->show_field_end( $field, $meta );

		}

		/**
		 * Show editor Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_editor( $field, $meta, $in_repeater = false ) {
			$this->show_field_begin( $field, $meta );

			if( $in_repeater ) {
				echo "<textarea class='at-editor theEditor large-text" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' id='{$field['id']}' cols='60' rows='10'>{$meta}</textarea>";
			}
			else {
				$default_settings = array( 'media_buttons' => false );

				// Use new wp_editor() since WP 3.3
				$settings                 = ( isset( $field['settings'] ) && is_array( $field['settings'] ) ? $field['settings'] : $default_settings );
				$settings['editor_class'] = 'at-editor' . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' );
				$id                       = str_replace( "_", "", $this->stripNumeric( strtolower( $field['id'] ) ) );
				wp_editor( html_entity_decode( $meta ), $id, $settings );
			}
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show File Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_file( $field, $meta ) {
			wp_enqueue_media();
			$this->show_field_begin( $field, $meta );

			$std      = isset( $field['std'] ) ? $field['std'] : array( 'id' => '', 'url' => '' );
			$multiple = isset( $field['multiple'] ) ? $field['multiple'] : false;
			$multiple = ( $multiple ) ? "multiFile '" : "";
			$name     = esc_attr( $field['id'] );
			$value    = isset( $meta['id'] ) ? $meta : $std;
			$has_file = ( empty( $value['url'] ) ) ? false : true;
			$type     = isset( $field['mime_type'] ) ? $field['mime_type'] : '';
			$ext      = isset( $field['ext'] ) ? $field['ext'] : '';
			$type     = ( is_array( $type ) ? implode( "|", $type ) : $type );
			$ext      = ( is_array( $ext ) ? implode( "|", $ext ) : $ext );
			$id       = $field['id'];
			$li       = ( $has_file ) ? "
{$value['url']}
" : "";

			echo "
{$li}
";
			echo "<input type='hidden' name='{$name}[id]' value='{$value['id']}'/>";
			echo "<input type='hidden' name='{$name}[url]' value='{$value['url']}'/>";
			if( $has_file ) {
				echo "<input type='button' class='{$multiple} button simplePanelfileUploadclear' id='{$id}' value='Remove File' data-mime_type='{$type}' data-ext='{$ext}'/>";
			}
			else {
				echo "<input type='button' class='{$multiple} button simplePanelfileUpload' id='{$id}' value='Upload File' data-mime_type='{$type}' data-ext='{$ext}'/>";
			}

			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Image Field.
		 *
		 * @param array $field
		 * @param array $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_image( $field, $meta ) {
			wp_enqueue_media();

			$this->show_field_begin( $field, $meta );

			$std   = isset( $field['std'] ) ? $field['std'] : array( 'id' => '', 'url' => '' );
			$name  = esc_attr( $field['id'] );
			$value = isset( $meta['id'] ) ? $meta : $std;

			$value['url'] = isset( $meta['src'] ) ? $meta['src'] : $value['url']; //backwords capability
			$has_image    = empty( $value['url'] ) ? false : true;
			$w            = isset( $field['width'] ) ? $field['width'] : 'auto';
			$h            = isset( $field['height'] ) ? $field['height'] : 'auto';
			$PreviewStyle = "style='width: $w; height: $h;" . ( ( !$has_image ) ? "display: none;'" : "'" );
			$id           = $field['id'];
			$multiple     = isset( $field['multiple'] ) ? $field['multiple'] : false;
			$multiple     = ( $multiple ) ? "multiFile " : "";

			echo "
";
			echo "<input type='hidden' name='{$name}[id]' value='{$value['id']}'/>";
			echo "<input type='hidden' name='{$name}[url]' value='{$value['url']}'/>";
			if( $has_image ) {
				echo "<input class='{$multiple} button  simplePanelimageUploadclear' id='{$id}' value='Remove Image' type='button'/>";
			}
			else {
				echo "<input class='{$multiple} button simplePanelimageUpload' id='{$id}' value='Upload Image' type='button'/>";
			}
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Color Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_color( $field, $meta ) {

			if( empty( $meta ) ) {
				$meta = '#';
			}

			$this->show_field_begin( $field, $meta );
			echo '
<input class="of-color" name="' . $field['id'] . '" id="' . $field['id'] . '" type="text" value="' . $meta . '" />';
			echo '

';

			$this->show_field_end( $field, $meta );

		}

		/**
		 * Show Checkbox List Field
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_checkbox_list( $field, $meta ) {

			if( !is_array( $meta ) ) {
				$meta = (array)$meta;
			}

			$this->show_field_begin( $field, $meta );

			$html = array();

			foreach( $field['options'] as $key => $value ) {
				$html[] = "<input type='checkbox' " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . "  class='at-checkbox_list" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}[]' value='{$key}'" . checked( in_array( $key, $meta ), true, false ) . " /> {$value}";
			}

			echo implode( '
', $html );

			$this->show_field_end( $field, $meta );

		}

		/**
		 * Show Date Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_date( $field, $meta ) {
			$this->show_field_begin( $field, $meta );
			echo "<input type='text'  " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " class='at-date" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' id='{$field['id']}' rel='{$field['format']}' value='{$meta}' size='30' />";
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show time field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_time( $field, $meta ) {
			$this->show_field_begin( $field, $meta );
			$ampm = ( $field['ampm'] ) ? 'true' : 'false';
			echo "<input type='text'  " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " class='at-time" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}' id='{$field['id']}' data-ampm='{$ampm}' rel='{$field['format']}' value='{$meta}' size='30' />";
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Posts field.
		 * used creating a posts/pages/custom types checkboxlist or a select dropdown
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_posts( $field, $meta ) {
			global $post;

			if( !is_array( $meta ) ) {
				$meta = (array)$meta;
			}
			$this->show_field_begin( $field, $meta );
			$options = $field['options'];
			$posts   = get_posts( $options['args'] );
			// checkbox_list
			if( 'checkbox_list' == $options['type'] ) {
				foreach( $posts as $p ) {
					echo "<input type='checkbox' " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " class='at-posts-checkbox" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}[]' value='$p->ID'" . checked( in_array( $p->ID, $meta ), true, false ) . " /> $p->post_title
";
				}
			}
			// select
			else {
				echo "<select " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " class='at-posts-select" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}" . ( $field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'" ) . ">";
				foreach( $posts as $p ) {
					echo "<option value='$p->ID'" . selected( in_array( $p->ID, $meta ), true, false ) . ">$p->post_title</option>";
				}
				echo "</select>";
			}

			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Taxonomy field.
		 * used creating a category/tags/custom taxonomy checkboxlist or a select dropdown
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 *
		 * @uses get_terms()
		 */
		public function show_field_taxonomy( $field, $meta ) {
			global $post;

			if( !is_array( $meta ) ) {
				$meta = (array)$meta;
			}
			$this->show_field_begin( $field, $meta );
			$options = $field['options'];
			$terms   = get_terms( $options['taxonomy'], $options['args'] );

			// checkbox_list
			if( 'checkbox_list' == $options['type'] ) {
				foreach( $terms as $term ) {
					echo "<input type='checkbox' " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " class='at-tax-checkbox" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}[]' value='$term->slug'" . checked( in_array( $term->slug, $meta ), true, false ) . " /> $term->name
";
				}
			}
			// select
			else {
				echo "<select " . ( isset( $field['style'] ) ? "style='{$field['style']}' " : '' ) . " class='at-tax-select" . ( isset( $field['class'] ) ? ' ' . $field['class'] : '' ) . "' name='{$field['id']}" . ( $field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'" ) . ">";
				foreach( $terms as $term ) {
					echo "<option value='$term->slug'" . selected( in_array( $term->slug, $meta ), true, false ) . ">$term->name</option>";
				}
				echo "</select>";
			}

			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show conditinal Checkbox Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 2.9.9
		 * @access public
		 */
		public function show_field_cond( $field, $meta ) {

			$this->show_field_begin( $field, $meta );
			$checked = false;
			if( is_array( $meta ) && isset( $meta['enabled'] ) && $meta['enabled'] == 'on' ) {
				$checked = true;
			}
			echo "<input type='checkbox' class='conditinal_control' name='{$field['id']}[enabled]' id='{$field['id']}'" . checked( $checked, true, false ) . " />";
			//start showing the fields
			$display = ( $checked ) ? '' : ' style="display: none;"';

			echo '

';
			foreach( (array)$field['fields'] as $f ) {
				//reset var $id for cond
				$id = '';
				$id = $field['id'] . '[' . $f['id'] . ']';
				$m  = '';
				$m  = ( isset( $meta[$f['id']] ) ) ? $meta[$f['id']] : '';
				$m  = ( $m !== '' ) ? $m : ( isset( $f['std'] ) ? $f['std'] : '' );
				if( 'image' != $f['type'] && $f['type'] != 'repeater' ) {
					$m = is_array( $m ) ? array_map( 'esc_attr', $m ) : esc_attr( $m );
				}
				//set new id for field in array format
				$f['id'] = $id;
				echo '
';
				call_user_func( array( $this, 'show_field_' . $f['type'] ), $f, $m );
				echo '
';
			}
			echo '

';
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Show Help Field.
		 *
		 * @param string $field
		 * @param string $meta
		 *
		 * @since 1.0
		 * @access public
		 */
		public function show_field_help( $field, $meta ) {

			$this->show_field_begin( $field, $meta );
			echo '' . $field['help_text'] . '';
			$this->show_field_end( $field, $meta );
		}

		/**
		 * Save Data from Metabox
		 *
		 * @param string $post_id
		 *
		 * @since 1.0
		 * @access public
		 */
		public function save( $post_id ) {

			global $post_type;

			$post_type_object = get_post_type_object( $post_type );

			if( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) // Check Autosave
				|| ( !isset( $_POST['post_ID'] ) || $post_id != $_POST['post_ID'] ) // Check Revision
				|| ( !in_array( $post_type, $this->_meta_box['pages'] ) ) // Check if current post type is supported.
				|| ( !check_admin_referer( basename( __FILE__ ), 'at_meta_box_nonce' ) ) // Check nonce - Security
				|| ( !current_user_can( $post_type_object->cap->edit_post, $post_id ) )
			) // Check permission
			{
				return $post_id;
			}

			foreach( $this->_fields as $field ) {

				$name = $field['id'];
				$type = $field['type'];
				$old  = get_post_meta( $post_id, $name, !$field['multiple'] );
				$new  = ( isset( $_POST[$name] ) ) ? $_POST[$name] : ( ( $field['multiple'] ) ? array() : '' );

				// Validate meta value
				if( class_exists( 'at_Meta_Box_Validate' ) && method_exists( 'at_Meta_Box_Validate', $field['validate_func'] ) ) {
					$new = call_user_func( array( 'at_Meta_Box_Validate', $field['validate_func'] ), $new );
				}

				//skip on Paragraph field
				if( $type != "paragraph" ) {

					// Call defined method to sanitize meta value
					$sanitize_func = 'sanitize_field_' . $type;

					if( method_exists( $this, $sanitize_func ) ) {
						$new = call_user_func( array( $this, $sanitize_func ), $new, $old );
					}

					// Call defined method to save meta value, if there's no methods, call common one.
					$save_func = 'save_field_' . $type;
					if( method_exists( $this, $save_func ) ) {
						call_user_func( array( $this, $save_func ), $post_id, $field, $old, $new );
					}
					else {
						$this->save_field( $post_id, $field, $old, $new );
					}
				}

			} // End foreach
		}

		/**
		 * Common function for saving fields.
		 *
		 * @param string $post_id
		 * @param string $field
		 * @param string $old
		 * @param string|mixed $new
		 *
		 * @since 1.0
		 * @access public
		 */
		public function save_field( $post_id, $field, $old, $new ) {

			$name = $field['id'];
			delete_post_meta( $post_id, $name );
			if( $new === '' || $new === array() ) {
				return;
			}
			if( $field['multiple'] ) {
				foreach( $new as $add_new ) {
					add_post_meta( $post_id, $name, $add_new, false );
				}
			}
			else {
				update_post_meta( $post_id, $name, $new );
			}
		}

		/**
		 * function for saving image field.
		 *
		 * @param string $post_id
		 * @param string $field
		 * @param string $old
		 * @param string|mixed $new
		 *
		 * @since 1.7
		 * @access public
		 */
		public function save_field_image( $post_id, $field, $old, $new ) {
			$name = $field['id'];
			delete_post_meta( $post_id, $name );
			if( $new === '' || $new === array() || $new['id'] == '' || $new['url'] == '' ) {
				return;
			}

			update_post_meta( $post_id, $name, $new );
		}

		/*
   * Save Editor Field.
   *
   * @param string $post_id
   * @param string $field
   * @param string $old
   * @param string $new
   * @since 1.0
   * @access public
   */
		public function save_field_editor( $post_id, $field, $old, $new ) {
			$id  = str_replace( "_", "", $this->stripNumeric( strtolower( $field['id'] ) ) );
			$new = ( isset( $_POST[$id] ) ) ? $_POST[$id] : ( ( $field['multiple'] ) ? array() : '' );
			$this->save_field( $post_id, $field, $old, $new );
		}

		/**
		 * Save repeater Fields.
		 *
		 * @param string $post_id
		 * @param string $field
		 * @param string|mixed $old
		 * @param string|mixed $new
		 *
		 * @since 1.0
		 * @access public
		 */
		public function save_field_repeater( $post_id, $field, $old, $new ) {
			if( is_array( $new ) && count( $new ) > 0 ) {
				foreach( $new as $n ) {
					foreach( $field['fields'] as $f ) {
						$type = $f['type'];
						switch( $type ) {
							case 'editor':
								$n[$f['id']] = wpautop( $n[$f['id']] );
								break;
							default:
								break;
						}
					}
					if( !$this->is_array_empty( $n ) ) {
						$temp[] = $n;
					}
				}
				if( isset( $temp ) && count( $temp ) > 0 && !$this->is_array_empty( $temp ) ) {
					update_post_meta( $post_id, $field['id'], $temp );
				}
				else {
					//  remove old meta if exists
					delete_post_meta( $post_id, $field['id'] );
				}
			}
			else {
				//  remove old meta if exists
				delete_post_meta( $post_id, $field['id'] );
			}
		}

		/**
		 * Save File Field.
		 *
		 * @param string $post_id
		 * @param string $field
		 * @param string $old
		 * @param string $new
		 *
		 * @since 1.0
		 * @access public
		 */
		public function save_field_file( $post_id, $field, $old, $new ) {

			$name = $field['id'];
			delete_post_meta( $post_id, $name );
			if( $new === '' || $new === array() || $new['id'] == '' || $new['url'] == '' ) {
				return;
			}

			update_post_meta( $post_id, $name, $new );
		}

		/**
		 * Save repeater File Field.
		 *
		 * @param string $post_id
		 * @param string $field
		 * @param string $old
		 * @param string $new
		 *
		 * @since 1.0
		 * @access public
		 * @deprecated 3.0.7
		 */
		public function save_field_file_repeater( $post_id, $field, $old, $new ) {
		}

		/**
		 * Save Checkbox Field.
		 *
		 * @param string $post_id
		 * @param string $field
		 * @param string $old
		 * @param string $new
		 *
		 * @since 1.0
		 * @access public
		 */
		function save_field_checkbox( $post_id, $field, $old, $new ) {
			$new = $new ? "1" : "0";
			update_post_meta( $post_id, $field['id'], $new );
		}

		/**
		 * Add missed values for meta box.
		 *
		 * @since 1.0
		 * @access public
		 */
		public function add_missed_values() {

			// Default values for meta box
			$this->_meta_box = array_merge( array( 'context' => 'normal', 'priority' => 'high', 'pages' => array( 'post' ) ), (array)$this->_meta_box );

			// Default values for fields
			foreach( $this->_fields as &$field ) {

				$multiple = in_array( $field['type'], array( 'checkbox_list', 'file', 'image' ) );
				$std      = $multiple ? array() : '';
				$format   = 'date' == $field['type'] ? 'yy-mm-dd' : ( 'time' == $field['type'] ? 'hh:mm' : '' );

				$field = array_merge( array( 'multiple' => $multiple, 'std' => $std, 'desc' => '', 'format' => $format, 'validate_func' => '' ), $field );

			} // End foreach

		}

		/**
		 * Check if field with $type exists.
		 *
		 * @param string $type
		 *
		 * @since 1.0
		 * @access public
		 */
		public function has_field( $type ) {
			//faster search in single dimention array.
			if( count( $this->field_types ) > 0 ) {
				return in_array( $type, $this->field_types );
			}

			//run once over all fields and store the types in a local array
			$temp = array();
			foreach( $this->_fields as $field ) {
				$temp[] = $field['type'];
				if( 'repeater' == $field['type'] || 'cond' == $field['type'] ) {
					foreach( (array)$field["fields"] as $repeater_field ) {
						$temp[] = $repeater_field["type"];
					}
				}
			}

			//remove duplicates
			$this->field_types = array_unique( $temp );

			//call this function one more time now that we have an array of field types
			return $this->has_field( $type );
		}

		/**
		 * Check if current page is edit page.
		 *
		 * @since 1.0
		 * @access public
		 */
		public function is_edit_page() {
			global $pagenow;

			return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
		}

		/**
		 * Fixes the odd indexing of multiple file uploads.
		 *
		 * Goes from the format:
		 * $_FILES['field']['key']['index']
		 * to
		 * The More standard and appropriate:
		 * $_FILES['field']['index']['key']
		 *
		 * @param string $files
		 *
		 * @since 1.0
		 * @access public
		 */
		public function fix_file_array( &$files ) {

			$output = array();

			foreach( $files as $key => $list ) {
				foreach( $list as $index => $value ) {
					$output[$index][$key] = $value;
				}
			}

			return $output;

		}

		/**
		 * Get proper JQuery UI version.
		 *
		 * Used in order to not conflict with WP Admin Scripts.
		 *
		 * @since 1.0
		 * @access public
		 */
		public function get_jqueryui_ver() {

			global $wp_version;

			if( version_compare( $wp_version, '3.1', '>=' ) ) {
				return '1.8.10';
			}

			return '1.7.3';

		}

		/**
		 *  Add Field to meta box (generic function)
		 * @author Ohad Raz
		 * @since 1.2
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 */
		public function addField( $id, $args ) {
			$new_field       = array( 'id' => $id, 'std' => '', 'desc' => '', 'style' => '' );
			$new_field       = array_merge( $new_field, $args );
			$this->_fields[] = $new_field;
		}

		/**
		 *  Add Text Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'style' =>   // custom style for field, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addText( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'text', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => 'Text Field' );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Number Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'style' =>   // custom style for field, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addNumber( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'number', 'id' => $id, 'std' => '0', 'desc' => '', 'style' => '', 'name' => 'Number Field', 'step' => '1', 'min' => '0' );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Hidden Field to meta box
		 * @author Ohad Raz
		 * @since 0.1.3
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'style' =>   // custom style for field, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addHidden( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'hidden', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => 'Text Field' );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Paragraph to meta box
		 * @author Ohad Raz
		 * @since 0.1.3
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $value  paragraph html
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addParagraph( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'paragraph', 'id' => $id, 'value' => '' );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Checkbox Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addCheckbox( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'checkbox', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => 'Checkbox Field' );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add CheckboxList Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $options (array)  array of key => value pairs for select options
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 *
		 * @return : remember to call: $checkbox_list = get_post_meta(get_the_ID(), 'meta_name', false);
		 *   which means the last param as false to get the values in an array
		 */
		public function addCheckboxList( $id, $options, $args, $repeater = false ) {
			$new_field = array( 'type' => 'checkbox_list', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => 'Checkbox List Field', 'options' => $options, 'multiple' => true, );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Textarea Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'style' =>   // custom style for field, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addTextarea( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'textarea', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => 'Textarea Field' );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Select Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string field id, i.e. the meta key
		 * @param $options (array)  array of key => value pairs for select options
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, (array) optional
		 *    'multiple' => // select multiple values, optional. Default is false.
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addSelect( $id, $options, $args, $repeater = false ) {
			$new_field = array( 'type' => 'select', 'id' => $id, 'std' => array(), 'desc' => '', 'style' => '', 'name' => 'Select Field', 'multiple' => false, 'options' => $options );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Radio Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string field id, i.e. the meta key
		 * @param $options (array)  array of key => value pairs for radio options
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addRadio( $id, $options, $args, $repeater = false ) {
			$new_field = array( 'type' => 'radio', 'id' => $id, 'std' => array(), 'desc' => '', 'style' => '', 'name' => 'Radio Field', 'options' => $options );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Date Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'validate_func' => // validate function, string optional
		 *    'format' => // date format, default yy-mm-dd. Optional. Default "'d MM, yy'"  See more formats here: http://goo.gl/Wcwxn
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addDate( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'date', 'id' => $id, 'std' => '', 'desc' => '', 'format' => 'd MM, yy', 'name' => 'Date Field' );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Time Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string- field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'validate_func' => // validate function, string optional
		 *    'format' => // time format, default hh:mm. Optional. See more formats here: http://goo.gl/83woX
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addTime( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'time', 'id' => $id, 'std' => '', 'desc' => '', 'format' => 'hh:mm', 'name' => 'Time Field', 'ampm' => false );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Color Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addColor( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'color', 'id' => $id, 'std' => '', 'desc' => '', 'name' => 'ColorPicker Field' );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Image Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addImage( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'image', 'id' => $id, 'desc' => '', 'name' => 'Image Field', 'std' => array( 'id' => '', 'url' => '' ), 'multiple' => false );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add File Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addFile( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'file', 'id' => $id, 'desc' => '', 'name' => 'File Field', 'multiple' => false, 'std' => array( 'id' => '', 'url' => '' ) );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Editor Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'style' =>   // custom style for field, string optional Default 'width: 300px; height: 400px'
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addEditor( $id, $args, $repeater = false ) {
			$new_field = array( 'type' => 'editor', 'id' => $id, 'std' => '', 'desc' => '', 'style' => 'width: 300px; height: 400px', 'name' => 'Editor Editor Field' );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add Taxonomy Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $options mixed|array options of taxonomy field
		 *    'taxonomy' =>    // taxonomy name can be category,post_tag or any custom taxonomy default is category
		 *    'type' =>  // how to show taxonomy? 'select' (default) or 'checkbox_list'
		 *    'args' =>  // arguments to query taxonomy, see http://goo.gl/uAANN default ('hide_empty' => false)
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addTaxonomy( $id, $options, $args, $repeater = false ) {
			$temp      = array(
				'args' => array( 'hide_empty' => 0 ),
				'tax'  => 'category',
				'type' => 'select'
			);
			$options   = array_merge( $temp, $options );
			$new_field = array( 'type' => 'taxonomy', 'id' => $id, 'desc' => '', 'name' => 'Taxonomy Field', 'options' => $options );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add posts Field to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $options mixed|array options of taxonomy field
		 *    'post_type' =>    // post type name, 'post' (default) 'page' or any custom post type
		 *    'type' =>  // how to show posts? 'select' (default) or 'checkbox_list'
		 *    'args' =>  // arguments to query posts, see http://goo.gl/is0yK default ('posts_per_page' => -1)
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'validate_func' => // validate function, string optional
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addPosts( $id, $options, $args, $repeater = false ) {
			$post_type = isset( $options['post_type'] ) ? $options['post_type'] : ( isset( $args['post_type'] ) ? $args['post_type'] : 'post' );
			$type      = isset( $options['type'] ) ? $options['type'] : 'select';
			$q         = array( 'posts_per_page' => -1, 'post_type' => $post_type );
			if( isset( $options['args'] ) ) {
				$q = array_merge( $q, (array)$options['args'] );
			}
			$options   = array( 'post_type' => $post_type, 'type' => $type, 'args' => $q );
			$new_field = array( 'type' => 'posts', 'id' => $id, 'desc' => '', 'name' => 'Posts Field', 'options' => $options, 'multiple' => false );
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 *  Add repeater Field Block to meta box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 *
		 * @param $id string  field id, i.e. the meta key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'style' =>   // custom style for field, string optional
		 *    'validate_func' => // validate function, string optional
		 *    'fields' => //fields to repeater
		 */
		public function addRepeaterBlock( $id, $args ) {
			$new_field       = array(
				'type'     => 'repeater',
				'id'       => $id,
				'name'     => 'Reapeater Field',
				'fields'   => array(),
				'inline'   => false,
				'sortable' => false
			);
			$new_field       = array_merge( $new_field, $args );
			$this->_fields[] = $new_field;
		}

		/**
		 *  Add Checkbox conditional Field to Page
		 * @author Ohad Raz
		 * @since 2.9.9
		 * @access public
		 *
		 * @param $id string  field id, i.e. the key
		 * @param $args mixed|array
		 *    'name' => // field name/label string optional
		 *    'desc' => // field description, string optional
		 *    'std' => // default value, string optional
		 *    'validate_func' => // validate function, string optional
		 *    'fields' => list of fields to show conditionally.
		 * @param $repeater bool  is this a field inside a repeatr? true|false(default)
		 */
		public function addCondition( $id, $args, $repeater = false ) {
			$new_field = array(
				'type'   => 'cond',
				'id'     => $id,
				'std'    => '',
				'desc'   => '',
				'style'  => '',
				'name'   => 'Conditional Field',
				'fields' => array()
			);
			$new_field = array_merge( $new_field, $args );
			if( false === $repeater ) {
				$this->_fields[] = $new_field;
			}
			else {
				return $new_field;
			}
		}

		/**
		 * Finish Declaration of Meta Box
		 * @author Ohad Raz
		 * @since 1.0
		 * @access public
		 */
		public function Finish() {
			$this->add_missed_values();
		}

		/**
		 * Helper function to check for empty arrays
		 * @author Ohad Raz
		 * @since 1.5
		 * @access public
		 *
		 * @param $args mixed|array
		 */
		public function is_array_empty( $array ) {
			if( !is_array( $array ) ) {
				return true;
			}

			foreach( $array as $a ) {
				if( is_array( $a ) ) {
					foreach( $a as $sub_a ) {
						if( !empty( $sub_a ) && $sub_a != '' ) {
							return false;
						}
					}
				}
				else {
					if( !empty( $a ) && $a != '' ) {
						return false;
					}
				}
			}

			return true;
		}

		/**
		 * Validate_upload_file_type
		 *
		 * Checks if the uploaded file is of the expected format
		 *
		 * @author Ohad Raz <admin@bainternet.info>
		 * @since 3.0.7
		 * @access public
		 * @uses get_allowed_mime_types() to check allowed types
		 *
		 * @param array $file uploaded file
		 *
		 * @return array file with error on mismatch
		 */
		function Validate_upload_file_type( $file ) {
			if( isset( $_POST['uploadeType'] ) && !empty( $_POST['uploadeType'] ) && isset( $_POST['uploadeType'] ) && $_POST['uploadeType'] == 'my_meta_box' ) {
				$allowed = explode( "|", $_POST['uploadeType'] );
				$ext     = substr( strrchr( $file['name'], '.' ), 1 );

				if( !in_array( $ext, (array)$allowed ) ) {
					$file['error'] = __( 'Sorry, you cannot upload this file type for this field.', 'cyberchimps_core' );

					return $file;
				}

				foreach( get_allowed_mime_types() as $key => $value ) {
					if( strpos( $key, $ext ) || $key == $ext ) {
						return $file;
					}
				}
				$file['error'] = __( 'Sorry, you cannot upload this file type for this field.', 'cyberchimps_core' );
			}

			return $file;
		}

		/**
		 * function to sanitize field id
		 *
		 * @author Ohad Raz <admin@bainternet.info>
		 * @since 3.0.7
		 * @access public
		 *
		 * @param  string $str string to sanitize
		 *
		 * @return string      sanitized string
		 */
		public function idfy( $str ) {
			return str_replace( " ", "_", $str );

		}

		/**
		 * stripNumeric Strip number form string
		 *
		 * @author Ohad Raz <admin@bainternet.info>
		 * @since 3.0.7
		 * @access public
		 *
		 * @param  string $str
		 *
		 * @return string number less string
		 */
		public function stripNumeric( $str ) {
			return trim( str_replace( range( 0, 9 ), '', $str ) );
		}

		/**
		 * load_textdomain
		 * @author Ohad Raz
		 * @since 2.9.4
		 * @return void
		 */
		public function load_textdomain() {
			//In themes/plugins/mu-plugins directory
			load_textdomain( 'cyberchimps_core', dirname( __FILE__ ) . '/lang/' . get_locale() . 'mo' );
		}
	} // End Class
endif; // End Check Class Exists

class CyberChimps_Meta_Box extends AT_Meta_Box {

	public function show_field_image_select( $field, $meta ) {

		$this->show_field_begin( $field, $meta );
		echo "
";
		foreach( $field['options'] as $key => $option ) {
			echo "";
		}
		echo "<input type='hidden' name='{$field['id']}' />";
		echo "
";
		$this->show_field_end( $field, $meta );
	}

	public function show_field_section_order( $field, $meta ) {
		//Define image path
		$image_path = get_template_directory_uri() . "/cyberchimps/lib/images/";

		$this->show_field_begin( $field, $meta );

		echo "
";
		echo "
";
		echo "
Inactive Elements
";
		echo "
";
		foreach( $field['options'] as $key => $option ) {
			if( is_array( $meta ) ) {
				if( in_array( $key, $meta ) ) {
					continue;
				}
			}
			echo "
";
			echo '';
			echo "{$option}";
			echo "
";
		}
		echo "
";
		echo "
";
		echo '

';
		echo "
";
		echo "
Active Elements
";
		echo "
";
		if( is_array( $meta ) ) {
			foreach( $meta as $key => $option ) {
				if( !array_key_exists( $option, $field['options'] ) ) {
					continue;
				}
				echo "
";
				echo '';
				echo '' . $field['options'][$option] . '';
				echo "
";
			}
		}
		echo "
";
		echo "
";
		echo "<input class='section-order-tracker' type='hidden' id={$field['id']} name={$field['id']} />";
		echo '

';
		echo "
";

		$this->show_field_end( $field, $meta );
	}

	/**
	 * Creates re-order field prompt to download plugin
	 *
	 * @param $field
	 * @param $meta
	 */
	public function show_field_reorder( $field, $meta ) {
		$this->show_field_begin( $field, $meta );
		echo "Install the Post Types Order Plugin to control the order of your custom slides.	";

		$this->show_field_end( $field, $meta );
	}

	/**
	 * Show Image Field. Overwrites original as images have been saved under [0] rather than source
	 *
	 * @param array $field
	 * @param array $meta
	 *
	 * @since 1.0
	 * @access public
	 */
	public function show_field_single_image( $field, $meta ) {
		wp_enqueue_media();

		$this->show_field_begin( $field, $meta );

		if( $meta ) {
			echo "
";
		}

		echo "<input type='button' class='upload-image-button' value='" . __( 'Upload', 'cyberchimps_core' ) . "' />";
		echo "
" . __( 'or enter URL', 'cyberchimps_core' ) . "
";
		echo "<input class='upload-image-field' type='text' size='50' name='{$field['id']}' value='{$meta}'/>";

		$this->show_field_end( $field, $meta );
	}

	/****************************** Sanitization Functions Starts *************************************/

	/**
	 * Sanitize editor Field.
	 *
	 * @param string $input
	 *
	 * @returns string $output
	 *
	 * @access public
	 */
	public function sanitize_field_editor( $input ) {
		if( current_user_can( 'unfiltered_html' ) ) {
			$output = $input;
		}
		else {
			global $allowedtags;
			$output = wpautop( wp_kses( $input, $allowedtags ) );
		}

		return $output;
	}

	/**
	 * Sanitize text Field.
	 *
	 * @param string $input
	 *
	 * @returns string $output
	 *
	 * @access public
	 */
	public function sanitize_field_text( $input ) {
		$output = wp_kses_post( $input );

		return $output;
	}

	/**
	 * Sanitize textarea Field.
	 *
	 * @param string $input
	 *
	 * @returns string $output
	 *
	 * @access public
	 */
	public function sanitize_field_textarea( $input ) {
		global $allowedposttags;
		$output = wp_kses( $input, $allowedposttags );

		return $output;
	}

	/**
	 * Sanitize unfiltered_textarea Field.
	 *
	 * @param string $input
	 *
	 * @returns string $output
	 *
	 * @access public
	 */
	public function sanitize_field_unfiltered_textarea( $input, $old ) {
		if( current_user_can( 'unfiltered_html' ) ) {
			return $input;
		}
		else {
			return $old;
		}
	}
}

redpajama_set_name: RedPajamaGithub