<?php
/**
Plugin Name: SCO Pinterest
Plugin URI: http://white-label-login.righthere.com
Description: Integration Pinterest to the social connection module.
Version: 1.0.0
Author: Maxim Levikov (RightHere LLC)
Author URI: http://white-label-login.righthere.com
 **/

if( !defined('SPSCOPINTEREST_PATH')): //only load the code if not loaded by another plugins addon.

if(defined('SPL_ADDON_PATH')){
	define('SPSCOPINTEREST_PATH', trailingslashit(SPL_ADDON_PATH . dirname($addon)) ); 
	define("SPSCOPINTEREST_URL", trailingslashit(SPL_ADDON_URL . dirname($addon)) );
}else{
	define('SPSCOPINTEREST_PATH', plugin_dir_path(__FILE__) ); 
	define("SPSCOPINTEREST_URL", plugin_dir_url(__FILE__) );
}

class plugin_sco_pinterest {
	var $id;
	var $name;
	var $option;
	function plugin_sco_pinterest( $args=array() ){
		//------------
		$defaults = array(
			'id'				=> 'pinterest',
			'plugin_id'			=> 'rhsco',
			'name'				=> 'Pinterest',
			'option'			=> 'pinterest_enable'
		);
		foreach($defaults as $property => $default){
			$this->$property = isset($args[$property])?$args[$property]:$default;
		}
		//-----------	
		//filter from social-connection/map_network_names.php
		//description:  this filter tells the main plugin the new network id, name, and the option that enables it.
		add_filter( 'get_sco_installed_networks', array( &$this, 'get_sco_installed_networks' ), 10, 1 );
		//filter from social-connection/class.sco_options.php
		//description:  this filter adds options to the social connection options panel 
		add_filter( 'sco_options', array( &$this, 'sco_options' ), 10, 3 );
		//filter from social-connection/class.sco_ajax.php
		//description, the main plugin loooks for files with the form login_wit_NETWORKID.php,
		//this filter just tells the main plugin the right path to the addon network.
		add_filter( 'sco_social_connect_filename', array( &$this, 'sco_social_connect_filename' ), 10, 2 );
	}
	
	function sco_social_connect_filename( $filename ){
		if( 'login_with_pinterest.php'==$filename ){
			return SPSCOPINTEREST_PATH.'/'.$filename;
		}
		return $filename;
	}
	
	function sco_options( $t, $i, $o ){
		$i = count($t);

		//-- this network -----------------------	
		$description =  __('For more information on setting up the OAuth API credentials, please visit our <a href="https://righthere.zendesk.com" target="_blank">Help Center</a>.<br><br>
			<b>Redirect URIs:</b><br>'
			.site_url('', 'https').'/wp-admin/admin-ajax.php?action=sco_social_connect&network='.$this->id.'&window_close=1', 'rhsco');

		$t[$i]=(object)array();
		$t[$i]->id 			= 'rhcsco-pinterest'; 
		$t[$i]->open 		= false; 
		$t[$i]->label 		= __('Pinterest','rhsco');
		$t[$i]->right_label	= __('Pinterest','rhsco');
		$t[$i]->page_title	= __('Pinterest','rhsco');
		$t[$i]->theme_option = true;
		$t[$i]->plugin_option = true;		
		$t[$i]->options = array();	
	
		$t[$i]->options[]=(object)array(
				'type'	=> 'subtitle',
				'label'	=> __('Pinterest','rhsco')
			);
						
		$t[$i]->options[] =	(object)array(
				'id'			=> 'pinterest_enable',
				'label'			=> __('Enable Pinterest','rhsco'),
				'type'			=> 'onoff',
				'default'		=> '0',
				'hidegroup'		=> '#pinterest_group',
				'el_properties'	=> array(),
				'save_option'	=>true,
				'load_option'	=>true
			);
		
		$t[$i]->options[]=(object)array(
				'id'	=> 'pinterest_group',
				'type'	=> 'div_start'
			);
						
		$t[$i]->options[] =	(object)array(
				'id'			=> 'pinterest_app_id',
				'label'			=> __('App ID','rhsco'),
				'description'	=> $description,
				'type'			=> 'text',
				'el_properties'	=> array('class'=>'widefat'),
				'save_option'	=>true,
				'load_option'	=>true
			);
						
		$t[$i]->options[] =	(object)array(
				'id'			=> 'pinterest_app_secret',
				'label'			=> __('App secret','rhsco'),
				//'description'	=> __('Specify a maximun number of taxonomies that a user can create by default.','rhsco'),
				'type'			=> 'text',
				'el_properties'	=> array('class'=>'widefat'),
				'save_option'	=>true,
				'load_option'	=>true
			);	
			
		$t[$i]->options[] =	(object)array(
				'id'			=> 'pinterest_login_label',
				'label'			=> __('Login label','rhsco'),
				'type'			=> 'text',
				'el_properties'	=> array('class'=>'widefat'),
				'save_option'	=>true,
				'load_option'	=>true
			);	
		
		$t[$i]->options[]=(object)array(
				'type'	=> 'div_end'
			);
		
		$t[$i]->options[]=(object)array(
				'type'=>'clear'
			);
		
		$t[$i]->options[]=(object)array(
				'type'	=> 'submit',
				'label'	=> __('Save','rhcs'),
				'class' => 'button-primary'
			);		

		return $t;
	}
	
	function get_sco_installed_networks( $sco_installed_networks ){
		$sco_installed_networks[ $this->id ] = (object)array(
			'name' 		=> $this->name,
			'option'	=> $this->option
		);
		return $sco_installed_networks;
	}
}

new plugin_sco_pinterest();

endif;
?>