<?php 
$_opt = getCO();

if ( (defined('MULTISITE')) && (MULTISITE == true) ) {
	global $blog_id, $current_site;
	$site_url = get_blogaddress_by_id(1);
	
	$site_url = str_replace( home_url().'/',$site_url, get_bloginfo('template_directory')).'/';
	
}else{
	$site_url = TMP_URL.'/';
}


if (isset($_GET['reset'])) {
	$nonce = $_GET["nonce"];
	check_admin_referer();
	
	if (wp_create_nonce('cloudfw') == $nonce) {

	cloudfw_reset_options();
	wp_redirect(admin_url(CLOUD_PAGE.'&m=9000'));
	
	}
}



if (isset($_GET['clearcache'])) {
	$nonce = $_GET["nonce"];
	check_admin_referer();
	
	if (wp_create_nonce('cloudfw') !== $nonce) wp_redirect(admin_url(CLOUD_PAGE.'&m=2010')); else {

		remove_old_cache_files();
		
		wp_redirect(admin_url(CLOUD_PAGE.'&m=9001'));		
		
	}
}

if (isset($_GET['createBlog'])) {
	$nonce = $_GET["nonce"];
	check_admin_referer();
	global $_opt;
	
	if (wp_create_nonce('cloudfw') !== $nonce) wp_redirect(admin_url(CLOUD_PAGE.'&m=2010')); else {

	$sys_page_1_init['post_title'] = 'Blog';
	$sys_page_1_init['post_content'] = '';
	$sys_page_1_init['post_status'] = 'publish';
	$sys_page_1_init['post_author'] = 1;
	$sys_page_1_init['post_type'] = 'page';

	$sys_page_1 = cloudfw_create_a_page( $sys_page_1_init, array('template' => 'page-blog.php') );


	if ($sys_page_1 !== false){
		update_option('page_for_posts', $sys_page_1['id'] );
		wp_redirect(admin_url(CLOUD_PAGE.'&m=8001'));		
		}else{
		wp_redirect(admin_url(CLOUD_PAGE.'&m=2001'));	
		}
	}
}


if (isset($_GET['createHomepage'])) {
	$nonce = $_GET["nonce"];
	check_admin_referer();
	$sys_page_1_init['ID'] = '';
	$sliderID = $_REQUEST["sliderID"];

	global $_opt;
	
	if (wp_create_nonce('cloudfw') !== $nonce) wp_redirect(admin_url(CLOUD_PAGE.'&m=2010')); else {
	$_opt = getCO();
	$cid = cloudfw_get_page_id($_opt[PFIX.'_sourcepage']);	
	

	if ($sliderID)
		$sys_page_1_init['post_content'] .= '[slider id="'.$sliderID.'"] [slice]';
		
	
	$sys_page_1_init['ID'] = $cid;
	$sys_page_1_init['post_title'] = '[Homepage]';
	$sys_page_1_init['post_status'] = 'publish';
	$sys_page_1_init['post_author'] = 1;
	$sys_page_1_init['post_type'] = 'page';
	$sys_page_1_init['post_content'] .= '
[1of3]
[frame]<img class="size-full" src="'.$site_url.'lib/samples/placeholder_250x220.gif" alt="" width="240" />[/frame]

[stitle]Phasellus lacinia[/stitle]
Cras aliquet, velit sed egestas rutrum, augue dui posuere metus

[list type="check"]
[li]Phasellus lacinia[/li]
[li]Cras eu lectus urna, a egestas libero[/li]
[li]Aliquam vitae felis (nam, purus elit)[/li]

[/list]

[/1of3]
[1of3]

[frame]<img class="size-full" src="'.$site_url.'lib/samples/placeholder_250x220.gif" alt="" width="240" />[/frame]
[stitle]Aliquam vitae felis[/stitle]
Cras aliquet, velit sed egestas rutrum, augue dui posuere metus

[list type="check"]
[li]Augue dui posuere metus[/li]
[li]Egestas rutrum[/li]
[/list]
[list type="cancel"]
[li]Cras aliquet[/li]
[/list]

[/1of3]
[1of3_last]

[frame]<img class="size-full" src="'.$site_url.'lib/samples/placeholder_250x220.gif" alt="" width="240" />[/frame]
[stitle]Aliquam vitae felis[/stitle]
Cras aliquet, velit sed egestas rutrum, augue dui posuere metus

[list type="check"]
[li]Augue dui posuere metus[/li]
[li]Egestas rutrum[/li]
[/list]
[list type="cancel"]
[li]Cras aliquet[/li]
[/list]

[/1of3_last]

[slice]

[portfolio from="a category" id="%PORTFOLIO_CATEGORY_ID%" title="Portfolio" subtitle="Cras aliquet, velit sed egestas rutrum, augue dui posuere metus" columns="4" limit="-1" carousel="1" height="350"]

[slice]

[1of3]
<h3>From The Blog</h3>
 
[blog  columns="1" limit="3" style="1"] 

[/1of3]

[1of3]
<h3>Follow Us</h3>
[twitter username="envato" count="4" columns="1"] [/1of3]


[1of3_last]
<h3>Offices</h3>

[tabs_simple tabs="Melbourne|Australia"]
[tab] [gmap address="Little Lonsdale St, Melbourne" html="Envato" zoom="15" height="250"] [/tab]
[tab] [gmap address="Victoria 8011 Australia" html="Victoria 8011 Australia" zoom="10" height="250"] [/tab]
[/tabs_simple]

[/1of3_last]
[divider_line]

<p style="text-align: center; background: none repeat scroll 0pt 0pt rgb(249, 249, 249); padding: 20px;" class="global-radius">
Lorem ipsum dolor sit amet, <strong>consectetur</strong> adipiscing elit. Mauris aliquam suscipit faucibus. [button size="normal" color="sky" style="margin-left:10px;" link="#"]Velit sed egestas rutrum[/button]</p>';

	$sys_page_1 = cloudfw_create_a_page( $sys_page_1_init, array('update' => true) );

	if ($sys_page_1 !== false){
		update_option(PFIX.'_homepage_sample', true );
		update_option('show_on_front', 'page' );
		update_option('page_on_front', $sys_page_1['id'] );
		update_option(PFIX.'_homepage_sample', true );
		wp_redirect(admin_url(CLOUD_PAGE.'&m=8003'));		
		}else{
		wp_redirect(admin_url(CLOUD_PAGE.'&m=2001'));	
		}
	}
}





if (isset($_GET['sliderCreateSample'])) {
	$nonce = $_GET["nonce"];
	check_admin_referer();
	global $_opt;
	
	if (wp_create_nonce('cloudfw') !== $nonce) wp_redirect(admin_url(CLOUD_PAGE.'&m=2010')); else {

/* CU3ER SLIDER */
$piecemaker_main = array (
  'foldername' => '3D_Piecemaker_Slider',
  'title' => '[Sample] 3D Homepage Slider',
  'width' => '860',
  'height' => '400',
  'pausetime' => '10',
  'autoplay' => '1',
  'dropShadowAlpha' => '0.7',
  'dropShadowScale' => '0.9',
  'controlBg' => 'FFFFFF',
  'controlText' => '000000',
  'controlAlpha' => '0.7',
  'controlAlphaOver' => '0.95',
  'fieldOfView' => '70',
  'id' => 'piecemakerSample',
  'type' => 'piecemaker_slider',
);

$piecemaker_data = array (
      0 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400.gif',
        'slider_type' => 'image',
        'slider_source' => '',
        'slider_url' => '',
        'slider_url_target' => '_self',
        'slider_title' => '',
        'transition_effect' => '',
        'slider_name' => 'Item #1',
        'slider_caption' => '',
        'slider_pieces' => '9',
        'slider_time' => '1.2',
        'slider_delay' => '0.1',
        'slider_depth_offset' => '300',
        'slider_cube_distance' => '30',
      ),
      1 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400_secondary.gif',
        'slider_type' => 'image',
        'slider_source' => '',
        'slider_url' => '',
        'slider_url_target' => '_self',
        'slider_title' => '',
        'transition_effect' => '',
        'slider_name' => 'Item #2',
        'slider_caption' => '',
        'slider_pieces' => '16',
        'slider_time' => '1.2',
        'slider_delay' => '0.1',
        'slider_depth_offset' => '300',
        'slider_cube_distance' => '30',
      ),
      2 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400.gif',
        'slider_type' => 'image',
        'slider_source' => '',
        'slider_url' => '',
        'slider_url_target' => '_self',
        'slider_title' => '',
        'transition_effect' => '',
        'slider_name' => 'Item #3',
        'slider_caption' => '',
        'slider_pieces' => '1',
        'slider_time' => '1.2',
        'slider_delay' => '0.1',
        'slider_depth_offset' => '300',
        'slider_cube_distance' => '30',
      ),
      3 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400_secondary.gif',
        'slider_type' => 'image',
        'slider_source' => '',
        'slider_url' => 'http://google.com/',
        'slider_url_target' => '_self',
        'slider_title' => '',
        'transition_effect' => '',
        'slider_name' => 'Item #4',
        'slider_caption' => '',
        'slider_pieces' => '3',
        'slider_time' => '1.2',
        'slider_delay' => '0.2',
        'slider_depth_offset' => '300',
        'slider_cube_distance' => '30',
      )
);


if ($piecemaker_slider_id = cloudfw_create_slider($piecemaker_main)) 
    update_option($piecemaker_slider_id, $piecemaker_data);



/* NIVO SLIDER */
$nivo_main = array (
	'source' => 'manual',
	'id'   => 'nivoSample',
	'title' => '[Sample] Nivo Slider',
	'width' => '860',
	'height' => '400',
	'effect' => 'boxRain',
	'effect_speed' => '3000',
	'autorotation_speed' => '5000',
	'slices' => '8',
	'pagination' => '1',
	'next_prev' => true,
	'type' => 'nivo_slider',
	'foldername' => 'Nivo_Slider'
);

$nivo_data = array (
      0 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400.gif',
        'slider_url' => '',
        'slider_video' => '',
        'slider_title' => '',
        'slider_name' => 'Item #1',
        'slider_caption' => 'Sample Caption',
      ),
      1 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400_secondary.gif',
        'slider_url' => '',
        'slider_video' => '',
        'slider_title' => '',
        'slider_name' => 'Item #2',
        'slider_caption' => '',
      ),
      2 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400.gif',
        'slider_url' => '',
        'slider_video' => '',
        'slider_title' => '',
        'slider_name' => 'Item #3',
        'slider_caption' => '',
      )
);


if ($nivo_slider_id = cloudfw_create_slider($nivo_main)) 
    update_option($nivo_slider_id, $nivo_data);


/* INLINE SLIDER */
$inline_main = array (
	'foldername' => 'Inline_Slider',
	'id'   => 'inlineSample',
	'title' => '[Sample] Inline Slider',
	'width' => '860',
	'height' => '400',
	'effect' => 'slide',
	'effect_speed' => '500',
	'autorotation_speed' => '5',
	'pagination' => '1',
	'autorotation' => '1',
	'next_prev' => '1',
	'type' => 'inpage_slider',
);

$inline_data = array (
      0 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400.gif',
        'slider_url' => '',
        'slider_video' => '',
        'slider_title' => '',
        'slider_name' => 'Item #1',
      ),
      1 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400_secondary.gif',
        'slider_url' => '',
        'slider_video' => '',
        'slider_title' => '',
        'slider_name' => 'Item #2',
        'slider_caption' => '',
      ),
      2 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400.gif',
        'slider_url' => '',
        'slider_video' => '',
        'slider_title' => '',
        'slider_name' => 'Item #3',
        'slider_caption' => '',
      )
);

if ($inline_id = cloudfw_create_slider($inline_main)) 
    update_option($inline_id, $inline_data);


/* GALLERIA SLIDER */
$galleria_main = array (
      'foldername' => 'Galleria',
	    'id'   => 'galleriaSample',
      'source' => 'manual',
      'title' => '[Sample] Galleria',
      'width' => '860',
      'height' => '400',
      'pausetime' => '5',
      'effect' => 'fade',
      'effect_speed' => '400',
      'imageCrop' => '1',
      'thumbnails' => '1',
      'type' => 'galleria'
);

$galleria_data = array (
      0 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400.gif',
        'slider_url' => '',
        'slider_video' => '',
        'slider_title' => '',
        'slider_name' => 'Item #1',
      ),
      1 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400_secondary.gif',
        'slider_url' => '',
        'slider_video' => '',
        'slider_title' => '',
        'slider_name' => 'Item #2',
        'slider_caption' => '',
      ),
      2 => 
      array (
        'slider_image' => $site_url.'lib/samples/placeholder_860x400.gif',
        'slider_url' => '',
        'slider_video' => '',
        'slider_title' => '',
        'slider_name' => 'Item #3',
        'slider_caption' => '',
      )
);


if ($galleria_id = cloudfw_create_slider($galleria_main)) 
    update_option($galleria_id, $galleria_data);


		wp_redirect(admin_url(CLOUD_PAGE.'&m=8004'));		
		
	}
	
}



if (isset($_GET['duplicateSkin'])) {
			$id = $_GET["id"];
			cloudfw_manage_skin_ID($id,'duplicate');
			wp_redirect(admin_url(CLOUD_PAGE.'&tab=skins&jump=0&m=7006'));		
}

if (isset($_GET['deleteSkin'])) {
			$id = $_GET["id"];
			cloudfw_manage_skin_ID($id,'delete');
			wp_redirect(admin_url(CLOUD_PAGE.'&tab=skins&jump=0&m=7003'));
}

if (isset($_GET['clvf'])) {
	$nonce = $_POST["nonce"];
	
	if (wp_create_nonce('cloudfw') !== $nonce) wp_redirect(admin_url(CLOUD_PAGE.'&m=2010')); else {
		
		$tf_id = $_POST["tf_id"];
		$tf_k = $_POST["tf_k"];
		
		if (isset($tf_id) && isset($tf_k)){
		
		update_option('api_id', cloudfw__sc99($tf_id));
		update_option('api_key', cloudfw__sc99($tf_k));
		
		}
		
	}
	


}