<?php
class plugin_rhc_czpf_shortcode {

	function __construct(){
		if(!is_admin()){
			add_action( 'plugins_loaded', array(&$this,'init') );
		}
	}

	function init(){
		add_shortcode('rhc_profile', array(&$this,'shorcode_profil'));
		add_shortcode('rhc_members', array(&$this,'shorcode_members'));  
		add_shortcode('rhc_groups', array(&$this,'shorcode_groups'));
	}
	
	function shorcode_members(){
		global $czpf_plugin;
		require_once(RHCCZPF_PATH.'inc/class.object_controler.php');	
		$czpf_class_object_controler = new czpf_class_object_controler(RHCCZPF_URL);
		echo '<div id="cz_member_tmp" style="display:none;">';
		
		
		if(empty($czpf_plugin->czpf_advancede['hide_member_menu'])){
			$czpf_plugin->czpf_advancede['hide_member_menu'] = '';
		}
		
		echo ' <div class="mbl pbm" '.($czpf_plugin->czpf_advancede['hide_member_menu'] != '' ? 'style="display:none"'  : '').'><ul id="memebersprofil_buttons" class="nav nav-pills">';
		$tmp_sort_arrrays = array('mostpost'=>'Most posts','mostratings'=>'Most ratings','mostrsvppastevents'=>'Most Past Events','mostrsvpupcoming'=>'Most Upcoming Events','alphabetical'=>'Alphabetical');
		 
		$defult_sort = 'mostpost'; 
		if(!empty($czpf_plugin->czpf_advancede['members_sortby'])){
			$defult_sort = $czpf_plugin->czpf_advancede['members_sortby']; 
		} 
		
		if(!class_exists('plugin_rhc_rating')){
			unset($tmp_sort_arrrays['mostratings']);
			
			if($defult_sort == 'mostratings'){
				$defult_sort = 'alphabetical';
			}
		}
		
		if(!class_exists('plugin_rhc_rsvp')){
			unset($tmp_sort_arrrays['mostrsvppastevents']);
			unset($tmp_sort_arrrays['mostrsvpupcoming']);
			if($defult_sort == 'mostrsvppastevents' || $defult_sort == 'mostrsvpupcoming' ){
				$defult_sort = 'alphabetical';
			}
		}
	
		foreach($tmp_sort_arrrays as $tmp_sort_key => $tmp_sort_data){
			echo '<li';
			
			if($defult_sort == $tmp_sort_key){
				echo ' class="active" ';
			}
			
			echo '><a data_text="'.$tmp_sort_key.'" href="#">'.$tmp_sort_data.'</a></li>';
		}
	
	    echo '</ul>
	      </div>';
	      
	    echo $czpf_class_object_controler->generate_memebers_count($czpf_plugin->czpf_advancede);
	      
	      
	    echo '<div id="comdata">';
		echo 		$czpf_class_object_controler->generate_memebers('list',$defult_sort);
		echo '</div>';
		echo 		'<div onclick="czpf_fn_scroll_fadingeffect_members()" class="more_items_div_profile" style="display: none;"><div class="more_items czpficon-arrow-down"></div></div>';
		echo '</div>';
		return '<div id="cz_members" class="div_czpf" style="display:none;"></div>';
	}
	
	function shorcode_groups(){
		global $czpf_plugin;
		require_once(RHCCZPF_PATH.'inc/class.object_controler.php');	
		$czpf_class_object_controler = new czpf_class_object_controler(RHCCZPF_URL);
		echo '<div id="cz_groups_tmp" style="display:none;">';
		
		
		
		$show_content = false;
		if(isset($_REQUEST['ID']) and is_numeric($_REQUEST['ID'])){
			
			$content_post = get_post($_REQUEST['ID']);
			
			if(!empty($content_post) && $content_post->post_status == 'publish' and $content_post->post_type == 'groupsteams'){
				$show_content = true;
			}
			
			
		}
		
		
		if(isset($_REQUEST['ID']) and !empty($content_post) and $show_content ){
			$current_user_id = get_current_user_id();
			$post_img = '';
				
							if(has_post_thumbnail( $content_post->ID )){
								
								$post_img = wp_get_attachment_image_src(get_post_thumbnail_id($content_post->ID),  'large-feature');
								$post_img = $post_img[0];
								
							}

			if(empty($post_img)){
				$post_img = RHCCZPF_URL . 'images/group_default.jpg';
			}
			
			$post_img = '<div class="czpf_group_img" style="background-image:url(\''.$post_img.'\');"></div>';
			
			$title = '<div class="czpf_title ob_s_c  czpf_editble " data-obj="title"><div id="user_show">'.$content_post->post_title.'</div>';
			if($content_post->post_author == $current_user_id){
				$title .= '<div class="czpf_edit_box" id="czpf_edit_box"><input value="'.$content_post->post_title.'" id="user_edit"></div><span class="editble czpficon-pencil" onclick="czpf_fn_edit_object_groups(this,\'post_title\',\''.$_REQUEST['ID'].'\')"></span>';
			}
			$title .= '</div>';
			
			
			echo '<div class="grouprowobject">';
			echo $post_img.'<div class="boxyclass"><h2>'.$title.'</h2></div>';
			echo '</div>';

			echo '<div class="grouprowobject">';
				echo '<div class="czpf_description ob_s_c  czpf_editble " data-obj="description">';
					echo '<div id="user_show">'.$content_post->post_content.'</div>';
					
					if($content_post->post_author == $current_user_id){
						echo '<div class="czpf_edit_box" id="czpf_edit_box">';
							echo '<div onclick="czpf_replace_textarea(this);" class="toolbar_item bold czpficon-bold"></div>';
							echo '<div onclick="czpf_replace_textarea(this);" class="toolbar_item italic czpficon-italic"></div>';
							echo '<div onclick="czpf_replace_textarea(this);" class="toolbar_item link czpficon-link2"></div>';
							echo '<div onclick="czpf_replace_textarea(this);" class="toolbar_item em czpficon-font-size"></div>';
							echo '<div onclick="czpf_replace_textarea(this);" class="toolbar_item sub czpficon-subscript"></div>';
							echo '<div onclick="czpf_replace_textarea(this);" class="toolbar_item sup czpficon-superscript"></div>';
							echo '<textarea id="user_edit">'.$content_post->post_content.'</textarea>';
						echo '</div>';
						echo '<span class="editble czpficon-pencil" onclick="czpf_fn_edit_object_groups(this,\'post_content\',\''.$_REQUEST['ID'].'\')"></span>';
					}
				echo '</div>';			
			echo '</div>';
			
			echo '<div class="grouprowobject">';
			
			echo $czpf_class_object_controler->generate_group_friends($_REQUEST['ID'],$content_post->post_author);
			
			echo '</div>';		








		} else {
		
			if(empty($czpf_plugin->czpf_advancede['hide_groups_sort_menu'])){
				$czpf_plugin->czpf_advancede['hide_groups_sort_menu'] = '';
			}
			$groups_create_roles = array();
			if(!empty($czpf_plugin->czpf_advancede['groups_create_roles'])){
				$groups_create_roles = explode('|', $czpf_plugin->czpf_advancede['groups_create_roles']);
			}			
			
			$current_user = wp_get_current_user();
			
			if((empty($czpf_plugin->czpf_advancede['hide_groups_add'])) && is_user_logged_in() && ( empty($czpf_plugin->czpf_advancede['groups_create_roles']) || (!empty($current_user->roles[0]) && in_array($current_user->roles[0], $groups_create_roles) ))){
				echo ' <div class="rhc_createnew"><a data_text="new" onclick="czpf_fn_show_groups_register();return false;" href="#">'.__('Create','rhc').'</a>';
		        echo '</div>';	
			}
		
			echo '<div class="rhc_groups_bg">';
				echo '<div class="rhc_groups_inner">';
					echo '<div class="rhc_groups_inner2">';
						echo '<div id="loading" style="text-align: center; bottom: 0px; padding-left: 50%; position: absolute; top: 50%; width: 100%; z-index: 200;"><div class="bigsize loading"></div></div>';
						echo '<div class="rhc_groups_main">';
							echo '<div class="rhc_groups_title">'.__('Create','rhcrsvp').'</div>';
							echo '<div class="rhc_groups_close czpficon-uniE2C2" onClick="czpf_fn_hide_groups_register();"></div>';
							echo '<lable>Title</lable>';
							echo '<div class="rhc_groups_main_data_title">';
								echo '<input type="text" value="" id="sub" class="sub">';
							echo '</div>';
							echo '<lable>Description</lable>';
							echo '<div class="rhc_groups_main_data_textarea">';
								echo '<div onclick="czpf_replace_textarea(this);" class="toolbar_item bold czpficon-bold"></div><div onclick="czpf_replace_textarea(this);" class="toolbar_item italic czpficon-italic"></div><div onclick="czpf_replace_textarea(this);" class="toolbar_item link czpficon-link2"></div><div onclick="czpf_replace_textarea(this);" class="toolbar_item em czpficon-font-size"></div><div onclick="czpf_replace_textarea(this);" class="toolbar_item sub czpficon-subscript"></div><div onclick="czpf_replace_textarea(this);" class="toolbar_item sup czpficon-superscript"></div>';
								echo '<textarea id="content" class="content"></textarea> ';
							echo '</div>';
							echo '<div class="rhc_groups_main_data_submitall">';
								echo '<input type="checkbox" value="1" id="submitall" class="submitall"> '.__('Allow anyone to join','rhc');
							echo '</div>';
							echo '<div class="rhc_groups_main_data_upload_thumbnail">';
								echo __('Upload image','rhc');
								echo '<div id="groupfileuploader"></div><div class="ajax-file-upload-progress-fake" style=""></div>';
								echo '<input type="hidden" value="" id="images_check">';
							echo '</div>';
							echo '<div class="rhc_groups_main_data_upload_save">';
								echo '<button onclick="czpf_fn_save_groups_register();return false;" class="btn btn-block btn-primary">'.__('Create','rhcrsvp').'</button>';
							echo '</div>';
							
							
						echo '</div>';
					echo '</div>';
				echo '</div>';
			echo '</div>';
	          
			echo ' <div class="mbl pbm" '.($czpf_plugin->czpf_advancede['hide_groups_sort_menu'] != '' ? 'style="display:none"'  : '').'><ul id="memebersprofil_buttons" class="nav nav-pills">';
			$tmp_sort_arrrays = array('alphabetical'=>__('Alphabetical','rhc'),'mostusers'=>__('Most Members','rhc'));
			 
			$defult_sort = 'alphabetical';
			 
			if(!empty($czpf_plugin->czpf_advancede['group_sortby'])){
				$defult_sort = $czpf_plugin->czpf_advancede['group_sortby']; 
			} 
	 
			foreach($tmp_sort_arrrays as $tmp_sort_key => $tmp_sort_data){
				echo '<li';
				
				if($defult_sort == $tmp_sort_key){
					echo ' class="active" ';
				}
				
				echo '><a data_text="'.$tmp_sort_key.'" href="#">'.$tmp_sort_data.'</a></li>';
			}
	
	        echo '</ul></div>';
	        echo $czpf_class_object_controler->generate_groups_count($czpf_plugin->czpf_advancede);
	        echo '<div id="comdata">';
			echo 	$czpf_class_object_controler->generate_groups('list',$defult_sort);
			echo '</div>';
			echo '<div onclick="czpf_fn_scroll_fadingeffect_members()" class="more_items_div_profile" style="display: none;"><div class="more_items czpficon-arrow-down"></div></div>';
		
		}
		
		echo '</div>';
		return '<div id="cz_groups" class="div_czpf" style="display:none;"></div>';	
	}
	
	function shorcode_profil(){
		global $czpf_plugin;
		require_once(RHCCZPF_PATH.'inc/class.object_controler.php');	
		
		$czpf_class_object_controler = new czpf_class_object_controler(RHCCZPF_URL);

		echo '<div class="div_czpf backscreenblack" style="display:none;">';
		echo '<div class="socail_alert alert alert-success" data-text="'.__('Please link your [social] account to your Member Profile. It will require that you enter your account information. Please notice that we are not saving any account information, but only verifying your ownership of the social network account.','rhc').'"><div class="div_loading_box" ><div class="bigsize loading inside"></div></div>
            <button class="close fui-cross" type="button" onclick="czpf_fn_social_hidebox();"></button>
            <h3>'.__('Social Link','rhc').'</h3>
            <p>'.__('This will only allow other usere to get your link to the social place on it will not retrive any userdata from you ','rhc').'</p>
            <a class="btn btn-huge btn-embossed btn-primary btn-danger removeclick"  onclick="czpf_connect_remove();return false;" href="#">'.__('Unlink Account','rhc').'</a>
            <a class="btn btn-huge btn-embossed btn-primary sociallink" href="#" onclick="czpf_connect();return false;">'.__('Link Account','rhc').'</a>
            <a class="btn btn-huge btn-embossed btn-primary socialseelink" href="#" onclick="czpf_fn_social_link_me();return false;">'.__('View Link','rhc').'</a>
          </div>';
         echo '</div>';
          
          
          
		
		echo '<div id="cz_profile_tmp" style="display:none;">';
		$status = get_user_meta($czpf_class_object_controler->check_up_user_id, 'status_show', true);
		
		if(!empty($status) && $status == 'private' && $czpf_class_object_controler->check_up_user_id != $czpf_class_object_controler->user_id){
			echo __('This member does not have a public profile.','rhc');
		} else if(empty($czpf_class_object_controler->check_up_user_id)){
			echo do_shortcode('[social_login]');
		} else {
			echo 		$czpf_class_object_controler->generate_list('czpf_container',false);
			if($czpf_class_object_controler->bottomcontainer_check($czpf_plugin->czpf_advancede)){
				echo 	'<div class="rowobject bottomcontainer">';
		 		echo 		$czpf_class_object_controler->generate_list_bottomcontainer($czpf_plugin->czpf_advancede,false);
		 		echo        '<div class="more_items_div" onclick="czpf_fn_scroll_fadingeffect()"><div class="more_items czpficon-arrow-down"></div></div>';
				echo 	'</div>';
			}	
		}	
		echo '</div>';
		return '<div id="cz_profile" class="div_czpf" style="display:none;"></div>';
		
	}
}
global $plugin_rhc_czpf_shortcode;
$plugin_rhc_czpf_shortcode = new plugin_rhc_czpf_shortcode();
?>