css-hero-main.php 41.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
<?php
/* Plugin Name: CSSHero
Plugin URI: csshero.org
Description: Bringing the future of interactive Web design to a WordPress near you. Requires Wp 3.5+
Version: 1.31 A
Author: CssHero.org
Author URI: csshero.org
License: Commercial
*/ 


require_once ("dynamic_css.php");

global $csshero_public_demo_mode;
$csshero_public_demo_mode=FALSE;
 
function wpcss_base64url_encode($data) { 
  return  rawurlencode( base64_encode( $data ) );
}
function wpcss_base64url_decode($data) { 
  return rawbase64_decode( urldecode($data)); 
} 
 

// Place in admin menu a trigger
add_action('admin_bar_menu', 'wpcss_add_toolbar_items', 100);

function wpcss_add_toolbar_items($admin_bar)
{
	 if (!wpcss_check_license() or !current_user_can('edit_theme_options') 	) return;
	$admin_bar->add_menu( array(
								'id'    => 'wpcss-css-hero-go',
								'title' => 'CSS Hero',
								'href'  => (get_bloginfo('wpurl')."?csshero_action=edit_page"),	
								 
							));
}
		
 
function wpcss_current_theme_slug()
{ 	$theme_name = wp_get_theme();
	return sanitize_title($theme_name);
 
}

 

function wpcss_handle_actions()
{		global $csshero_public_demo_mode;
		
		//trigger possible actions for NORMAL users, not logged in
		
		//Dynamic CSS
		if (isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='show_css')  {
		  
					if (is_user_logged_in()):     
						 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
						 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
						 endif;
						 
					header("Content-type: text/css");
					echo  wpcss_get_dynamic_css();
					die;
					}
		
		if ($csshero_public_demo_mode):
			   //new nano   loading for demo
			   if (isset($_GET['csshero_action']) && $_GET['csshero_action']=='edit_page')  {require_once('edit-page.php'); exit;}
					   
		endif;
		
		
		
		//history or preset list ajax loading result
		if (  (  current_user_can('edit_theme_options') or   function_exists('chpr_roller_is_allowed_to_all') ) && isset($_GET['csshero_action']) && $_GET['csshero_action']=='list_saved_snapshots' && isset($_GET['snapshot_type']) ) 
		
		{						  					$printed_elements=0;
														$wpcss_history_steps_array=get_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug());
															//print_r($wpcss_history_steps_array); 
															if ($wpcss_history_steps_array):
																				?><ul><?php
																					   $wpcss_history_steps_array=array_reverse($wpcss_history_steps_array);
																											foreach($wpcss_history_steps_array as $history_element):
																																									   if ($history_element['snapshot_type']!=$_GET['snapshot_type'])  continue;
																																										
																																											//print_r(get_option('wpcss_theme_settings_snapshot_array_'.wpcss_current_theme_slug().'-'.$step_id));
																																										
																																											if (get_option('wpcss_snapshots_active_step_id_'.wpcss_current_theme_slug())==$history_element['step_id'] ) { $activeflag="csshero-active-history-element";     } else {$activeflag="csshero-non-active-history-element";}
																																											
																																											$printed_elements++;
																																											?>
																																											<li class="<?php echo $activeflag; ?>" id="csshero-step-id-<?php echo $history_element['step_id'] ?>">
																																											
																																											
																																											<a class="preview-saved-step-trigger" href='?csshero_action=preview_step&step_id=<?php echo $history_element['step_id'] ?>'></a>
																																											
			<p><?php echo $history_element['snapshot_name'] ?></p>			
			<a target="_blank" class="delete-saved-step-trigger" href='?csshero_action=delete_snapshot&step_id=<?php echo $history_element['step_id'] ?>'>Delete</a>																								<a class="activate-saved-step-trigger" href='?csshero_action=activate_snapshot&step_id=<?php echo $history_element['step_id'] ?>'>Activate</a>
																						
																																											</li>
																																											
																																											<?php
																																								 
																																										
																													
																											endforeach;
																						?></ul><?php 					
																	endif;
																	if ($printed_elements==0)   echo "<p style='padding:10px';>None yet.</p>";
																	die;
		}
		
		
		
		
		
		//Following actions for site admin only
		if(!current_user_can('edit_theme_options')  ) return; //quit function if user cannot edit site
		 
		
		//check if product activated
		if ( is_admin()  && !wpcss_check_license()) {add_action( 'admin_notices', 'wpcss_hero_admin_notice' ); return;}
		
		//setcookie('csshero_is_on', 1, time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false);
		if ( is_admin() && isset($_COOKIE['csshero_is_on']) && $_COOKIE['csshero_is_on']==1  ) setcookie('csshero_is_on', 0, time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false);
		
		//LICENSING   ACTIVATION																				
		if (!isset($_POST['wpcss_submit_form']) && isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='activation' && is_user_logged_in()&& current_user_can('install_plugins'))
							
							{ //license request
							  wpcss_update_option('wpcss_accept_license','yes');
							  $data=array( 'url' => get_bloginfo('wpurl'), 'email' => get_bloginfo('admin_email'),'product'=>'CSSHERO');
							  wp_redirect('http://csshero.org/request-license/?v=2&data='.wpcss_base64url_encode(serialize($data)));
								die;  
								}
		
							
		//GET REMOTE LICENSE
		
		if (!isset($_POST['wpcss_submit_form'])  && isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='get_license'&& get_option('wpcss_accept_license')=='yes' && is_user_logged_in()&& current_user_can('install_plugins'))
					{ 
									wpcss_update_option('csshero-license',$_GET['license_key']);
			
										delete_option('wpcss_accept_license');
															
									$license=wpcss_check_license();
									if ($license!=FALSE) {
														$redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
														
														$redirect_url_array=explode('?',$redirect_url);
														$redirect_url=$redirect_url_array[0];
													  ?>
													  <body style="padding: 0; margin: 0; background: #f0f4f3;">
													  <div style="margin: 0; padding:100px; ">	 
																		<div style="margin: 0px auto; position: relative; background: transparent url(http://www.csshero.org/production/activation-img/remote_welcome.png) no-repeat center; width: 220px; height: 475px">					
																		<a style="display: block; position: absolute; width:176px; height:37px; background:transparent url(http://www.csshero.org/production/activation-img/remote_ok.png) no-repeat center; top: 329px; left: 22px;" href="<?php echo $redirect_url ?>"></a>
																		</div>			
													  </div>
													</body>	
														<?php die;
							}
									
									else {
												$redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
												$redirect_url_array=explode('?',$redirect_url);
												$redirect_url=$redirect_url_array[0];
												wp_redirect($redirect_url.'/?wpcss_message=activation_invalid');
												}
									
										die;
										
					}
									
		 
									
		//DELETE LICENSE
		if (!isset($_POST['wpcss_submit_form']) && isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='delete_license' && is_user_logged_in()&& current_user_can('install_plugins')) {delete_option('csshero-license');wp_redirect(admin_url()); }
		
		
		
		//CHECK LICENSE DEBUG
		if (!isset($_POST['wpcss_submit_form']) && isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='check_license' && is_user_logged_in()&& current_user_can('install_plugins') && is_user_logged_in()&& current_user_can('install_plugins'))
		{
		echo wpcss_check_license(); die;
		}
		
		///END LICENSING ACTIONS
		
		
		
		
		//HIDE / SHOW TRIGGER
		if (!isset($_POST['wpcss_submit_form']) && isset($_GET['wpcss_hidetrigger']) && is_numeric($_GET['wpcss_hidetrigger']) && is_user_logged_in()&& current_user_can('install_plugins')) {wpcss_update_option('wpcss_hidetrigger',$_GET['wpcss_hidetrigger']); die('done'); }
		 	
		//THEME RESET
		if (isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='reset')  {
																			wpcss_update_option('wpcss_current_settings_array_'.wpcss_current_theme_slug(),'');
		
																			//Save which is the active current history step 
																			//	wpcss_update_option('wpcss_snapshots_active_step_id_'.wpcss_current_theme_slug(),$id_of_new_step);
																				
																			
																		   //cache the CSS
																		   if (get_option('csshero_css_caching')==1) wpcss_generate_static_css();
																			   
																		    include('assets/mini-redirect.php');
																			  }
		//RESET QUICK CONFIG
		if (isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='reset_quick_config')  {delete_option('wpcss_quick_config_settings_'.wpcss_current_theme_slug()); include('assets/mini-redirect.php');}
						 
		
		
		
		if (isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='delete_theme_config')  {delete_option('wpcss_current_theme_options_array_'.wpcss_current_theme_slug());echo "Done!"; exit;}
														
		if (isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='share_preset')  { wpcss_share_current_preset(); }
		
		
																		
		//SAVE CSSHERO DATA																		
		if (current_user_can('edit_theme_options') && isset($_POST['wpcss_submit_form'])  && $_POST['wpcss_submit_form']==1  &&  isset($_POST['csshero-livearray-saving-field'])) { 
											
												
													if ( empty($_POST)  or  !wp_verify_nonce($_POST['csshero_saving_nonce_field'],'csshero_saving_nonce') )
															{
																		print '<h1>Sorry, your nonce did not verify.</h1>'; //('','csshero_save_nonce'
																		exit;
															}		
														
													   $field= stripslashes( ($_POST['csshero-livearray-saving-field'])); 	//	echo $field;
														$wpcss_current_settings_array= json_decode($field); // print_r($wpcss_current_settings_array);
		
													//UPDATE CURRENT MAIN THEME SETTINGS !!!
													wpcss_update_option('wpcss_current_settings_array_'.wpcss_current_theme_slug(),serialize($wpcss_current_settings_array));
												//	print_r($wpcss_current_settings_array);
												
													//save history NEW
												$wpcss_history_steps_array=get_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug()); //print_r($wpcss_history_steps_array);
													if (!$wpcss_history_steps_array) $wpcss_history_steps_array=array();
											
													//find maximum step value
															
													$id_of_new_step=0;
													foreach($wpcss_history_steps_array as $history_element):
													if ($history_element['step_id']>$id_of_new_step) $id_of_new_step=$history_element['step_id'];
													endforeach;
											
												 $id_of_new_step++;
																			
													 //add element to history array
												 $wpcss_history_steps_array[]=array(
																				'step_id' => $id_of_new_step,
																				'snapshot_name' =>   date(' h:i:s a m/d/Y', time()),
																				'snapshot_type' => 'history',
																				'key' => mt_rand(),
																				);
													
													
													//save setting as history step
													 $wpcss_new_stored_configuration_value=serialize($wpcss_current_settings_array);
												wpcss_update_option('wpcss_theme_settings_snapshot_array_'.wpcss_current_theme_slug().'-'.$id_of_new_step,$wpcss_new_stored_configuration_value);
													
													//Save history steps definition list
													 wpcss_update_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug(),$wpcss_history_steps_array);
													
													
													//Save which is the active current history step 
													 wpcss_update_option('wpcss_snapshots_active_step_id_'.wpcss_current_theme_slug(),$id_of_new_step);
													
													
													//cache the CSS
													if (get_option('csshero_css_caching')==1) wpcss_generate_static_css();
													
													
												  die("Saved");
										
									}
									
									
		//SAVE QUICK CONFIG  				
		if (isset($_POST['wpcss_submit_quick_config_form']) && $_POST['wpcss_submit_quick_config_form']==1) {
														if ( empty($_POST)  or !wp_verify_nonce($_POST['csshero_saving_nonce_field'],'csshero_saving_nonce') )
															{
																		print '<h1>Sorry, your nonce did not verify.</h1>'; //('','csshero_save_nonce'
																		exit;
															}	
													
													$wpcss_new_quick_config=addslashes($_POST['wp-css-config-quick-editor-textarea']);
										 
													//aggiungere sanitizzazione
													
													wpcss_update_option('wpcss_quick_config_settings_'.wpcss_current_theme_slug(),$wpcss_new_quick_config);
													
												echo "Config Saved";die;
													}
		
		
		
		
		
		//GET REMOTE PRESETS & Store in CSSHERO																	
		if (isset($_GET['wpcss_remote_get_preset'])  ) {//print_r($_POST);
															
													   $wpcss_current_settings_array=( base64_decode($_POST['preset_data']));
													    
												  //  SICUREZZA		
													  if ( empty($_POST)  or  !wp_verify_nonce($_POST['csshero_saving_nonce_field'],'csshero_saving_nonce') )
															{
																		print '<h1>Sorry, your nonce did not verify.</h1>'; //('','csshero_save_nonce'
																		exit;
															}		
														
											 	 
		
													//UPDATE CURRENT MAIN THEME SETTINGS !!!
													wpcss_update_option('wpcss_current_settings_array_'.wpcss_current_theme_slug(), ($wpcss_current_settings_array));
												 //	print_r($wpcss_current_settings_array); 
												
													//save history NEW
												$wpcss_history_steps_array=get_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug()); //print_r($wpcss_history_steps_array);
													if (!$wpcss_history_steps_array) $wpcss_history_steps_array=array();
											
													//find maximum step value
															
													$id_of_new_step=0;
													foreach($wpcss_history_steps_array as $history_element):
													if ($history_element['step_id']>$id_of_new_step) $id_of_new_step=$history_element['step_id'];
													endforeach;
											
												 $id_of_new_step++;
																			
													 //add element to history array
												 $wpcss_history_steps_array[]=array(
																				'step_id' => $id_of_new_step,
																				'snapshot_name' =>   $_POST['preset_name'],
																				'snapshot_type' => 'preset',
																				'key' => mt_rand(),
																				);
													
													
													//save setting as history step
													 $wpcss_new_stored_configuration_value=($wpcss_current_settings_array);
												wpcss_update_option('wpcss_theme_settings_snapshot_array_'.wpcss_current_theme_slug().'-'.$id_of_new_step,$wpcss_new_stored_configuration_value);
													
													//Save history steps definition list
													 wpcss_update_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug(),$wpcss_history_steps_array);
													
													
													//Save which is the active current history step 
													 wpcss_update_option('wpcss_snapshots_active_step_id_'.wpcss_current_theme_slug(),$id_of_new_step);
													  ?> <script>  parent.window.location.href = "<?php echo get_bloginfo('url') ?>";  </script><?php
														die("<h1>Activating preset... </h1>");
										
									} //FINE GET REMORE PRESETS
									
		//attiva preset locali
		if (!isset($_POST['wpcss_submit_form']) && isset($_GET['csshero_action']) && $_GET['csshero_action']=='activate_snapshot') {
		
		
		
															//global $wpcss_current_settings_array; //sara letto dopo dal ciclo dei font della header percio va settato bene
															$step_id=$_GET['step_id'];
															if (!is_numeric($step_id)) die ("<h1>Invalid step id, not numeric!");
															$wpcss_settings_history_step=get_option('wpcss_theme_settings_snapshot_array_'.wpcss_current_theme_slug().'-'.$step_id);
																
															wpcss_update_option('wpcss_current_settings_array_'.wpcss_current_theme_slug(),$wpcss_settings_history_step);
																
															//Save which is the active current history step 
															wpcss_update_option('wpcss_snapshots_active_step_id_'.wpcss_current_theme_slug(),$step_id);
															
															//cache the CSS
															if (get_option('csshero_css_caching')==1) wpcss_generate_static_css();
													
		
															include('assets/mini-redirect.php');
																
																}
																
		//delete local preset
		if (!isset($_POST['wpcss_submit_form']) && isset($_GET['csshero_action']) && $_GET['csshero_action']=='delete_snapshot') {
		
		
		
															//global $wpcss_current_settings_array; //sara letto dopo dal ciclo dei font della header percio va settato bene
															 
															if (!is_numeric($_GET['step_id'])) die ("<h1>Invalid step id, not numeric!");
															 
															$wpcss_history_steps_array=get_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug());
															$new_wpcss_history_steps_array=array();
														 
																						
																foreach($wpcss_history_steps_array as $history_element):
																	
																		
																	 if ($_GET['step_id']!=$history_element['step_id'])
																							
																				 { $new_wpcss_history_steps_array[]=$history_element; //keep
																				 }
																							
																				 else  delete_option('wpcss_theme_settings_snapshot_array_'.wpcss_current_theme_slug().'-'.$history_element['step_id']);
																																										 
		
																endforeach;
																
														 wpcss_update_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug(),$new_wpcss_history_steps_array);   
													 
															
															  
																	
															die("Snapshot  deleted.");
															
																
																}
		
		if (!isset($_POST['wpcss_submit_form']) && isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='delete_history_snapshots') {
		
		
													$current_step_id=	get_option('wpcss_snapshots_active_step_id_'.wpcss_current_theme_slug());
															$wpcss_history_steps_array=get_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug());
															$new_wpcss_history_steps_array=array();
														 
																						
																foreach($wpcss_history_steps_array as $history_element):
																	
																		
																							if ($history_element['snapshot_type']=='preset' or $current_step_id==$history_element['step_id'])
																							
																														{ $new_wpcss_history_steps_array[]=$history_element; //si tenne
																																}
																							
																																 else  delete_option('wpcss_theme_settings_snapshot_array_'.wpcss_current_theme_slug().'-'.$history_element['step_id']);
																																										 
		
																endforeach;
																
														 wpcss_update_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug(),$new_wpcss_history_steps_array);   
													 
															
															  
																	
															die("History Snapshots deleted.");
																
														}
		
		if (!isset($_POST['wpcss_submit_form']) && isset($_GET['wpcss_action']) && $_GET['wpcss_action']=='rename_snapshot') {
		
															//save history NEW
																					$wpcss_history_steps_array=get_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug());
																					if (!$wpcss_history_steps_array) $wpcss_history_steps_array=array();
																							
																							
																							
																							
																					  $current_step_id=get_option('wpcss_snapshots_active_step_id_'.wpcss_current_theme_slug());
																							
																							
																							
																					 foreach($wpcss_history_steps_array as &$history_element):
																														  
																																		 if ($history_element['step_id']!=$current_step_id) continue;
																																						$history_element['snapshot_type']= "preset";
																																	 $history_element['snapshot_name']= $_GET['newname'];
																					
																			endforeach;
																			
																			
																			 
																						  
																					//Save history steps definition list
																					wpcss_update_option('wpcss_snapshots_index_array_'.wpcss_current_theme_slug(),$wpcss_history_steps_array);
																						
																					//end save history new
																						die("Preset Saved.");
															//include('assets/mini-redirect.php');
															
															}
															
		
		//new nano   loading
		if (isset($_GET['csshero_action']) && $_GET['csshero_action']=='edit_page')  {require_once('edit-page.php'); exit;}
						
		//CSSHERO SHUTDOWN			
		if (isset($_GET['csshero_action']) && $_GET['csshero_action'] =="shutdown" && current_user_can("edit_theme_options") )  {setcookie('csshero_is_on', 0, time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false);
		wp_redirect(add_query_arg( array('csshero_action' => false ) ));die;
			}
		
		//WHEN CSSHERO IS ON ELIMINATE WP ADMIN BAR WHEN PERFORMING EDITING ACTIONS
		if (isset($_COOKIE['csshero_is_on']) && $_COOKIE['csshero_is_on']==1 && current_user_can("edit_theme_options")
			&& (!isset($_GET['csshero_action']) OR  $_GET['csshero_action'] !="shutdown")
			)  {add_filter('show_admin_bar', '__return_false');add_filter( 'edit_post_link', '__return_false' );}
		
					
		
		
		
		
		
		


     }
add_action ('wp_loaded','wpcss_handle_actions');
 
 
   

function wpcss_hero_admin_notice() {
    ?>
    <div class="updated">
	<h2> Welcome to CSSHero.</h2>
	<p> Let's activate your product. It's fast and easy! Click the button and let's go.</p>
	<a class="button button-primary button-hero " href="<?php BLOGINFO('wpurl'); ?>?wpcss_action=activation">Get my key now!</a></p>
    </div>
    <?php
}


 
 
 
 
 
add_action('wp_head', 'wpcss_add_header_stuff');  //adds stuff to theme header for adding custom dynamic css and used fonts
 
function wpcss_add_header_stuff()

{
								//global $_GET; if (isset($_GET['wpcss_disable_all']) && $_GET['wpcss_disable_all']=1) return;
       
	?><!-- Start CSSHero.org Dynamic CSS & Fonts Loading -->
	 <link rel="stylesheet" type="text/css" media="all" href="<?php wp_css_print_style_url() ?>" data-apply-prefixfree />
	 <?php 	$used_fonts_array=csshero_get_used_google_fonts_array();
	 if ($used_fonts_array)
				 { ?><link href='//fonts.googleapis.com/css?family=<?php foreach($used_fonts_array as $font):  echo str_replace(' ','+',$font)."%7C";  endforeach; ?>' rel='stylesheet' type='text/css'> 	<?php } // end if
							 ?> <!-- End CSSHero.org Dynamic CSS & Fonts Loading -->    
										<?php   
}
function wp_css_print_style_url()

     {	//cached
		  if (!current_user_can('edit_theme_options') && (get_option('csshero_css_caching')==1))  //is caching flag on
		  {
			    $old_uploaded=get_option('wpcss_static_css_data');
			   if (is_array($old_uploaded) && isset($old_uploaded['file']) ) { echo ($old_uploaded['url']);  }
        
		  }
		  
		  else
		  {
		  
		  //standard
		 echo  get_bloginfo('url')."/?wpcss_action=show_css";
		 if (   (  current_user_can('edit_theme_options') or   function_exists('chpr_roller_is_allowed_to_all') ) && isset($_GET['csshero_action']) && $_GET['csshero_action']=='preview_step' && isset($_GET['step_id']) ) echo "&amp;step_id=".$_GET['step_id'];
		 if (   (  current_user_can('edit_theme_options') or   function_exists('chpr_roller_is_allowed_to_all') )) echo "&amp;rnd=".rand(0,1024);
	 
		  } //end else
	 }
     
      

function wpcss_addscripts() {//INCLUDE JS LIBRARIES AND STUFF 
 
 
		 wp_enqueue_script('prefixfree', plugins_url('/assets/js/prefixfree.min.js', __FILE__)); //prefix free. Thanks Lea, you're a star!
 
 
}    
 
add_action('wp_enqueue_scripts', 'wpcss_addscripts');  



 

function wpcss_share_current_preset()
{
	$the_data=(base64_encode( (get_option('wpcss_current_settings_array_'.wpcss_current_theme_slug()))));
	
	$args = array(
	'body' => array( 'site_url' => get_bloginfo('url'), 'preset_data' => $the_data, 'preset_name' => $_GET['preset_name'],'user_id' => $_GET['user_id'],  'theme_slug'=>wpcss_current_theme_slug()),
	'user-agent' => 'Css Hero'
	);
	
	$resp = wp_remote_post( 'http://csshero.org/share-preset', $args );
	print_r($resp[body]);
	die();//"Your preset has been saved."
}




  
function wpcss_check_license()
{
  $license= get_option('csshero-license');
   if ($license !=FALSE && strlen($license)>10)
			{ return $license; 	}
		else return FALSE;
 
}

     

function wpcss_get_property_value_from_slug($slug)
{
    $wpcss_current_settings_array=csshero_get_configuration_array();
    return $wpcss_current_settings_array[$slug]['property_value'];
}



 

function csshero_get_configuration_array($step_id="default")
{
     if ($step_id=="default")
     {
          $wpcss_current_settings_array=unserialize(get_option('wpcss_current_settings_array_'.wpcss_current_theme_slug()));
     }
     
     else {
             	if (!is_numeric($_GET['step_id'])) die ("<h1>Invalid step id, not numeric!");
                $wpcss_current_settings_array=unserialize(get_option('wpcss_theme_settings_snapshot_array_'.wpcss_current_theme_slug().'-'.$_GET['step_id']));
           
          }
          
      return $wpcss_current_settings_array;  
}

 

 



function csshero_get_used_google_fonts_array()
{
            if (   (  current_user_can('edit_theme_options') or   function_exists('chpr_roller_is_allowed_to_all') ) && isset($_GET['csshero_action']) && $_GET['csshero_action']=='preview_step' && isset($_GET['step_id']) )
												
												$wpcss_current_settings_array=csshero_get_configuration_array($_GET['step_id']);
												else
												$wpcss_current_settings_array=csshero_get_configuration_array();
            
            
            //print_r($wpcss_current_settings_array);die;
            
            
            $used_fonts_array=array(); 
          //  echo "<pre>";print_r($wpcss_current_settings_array);
     
            if (($wpcss_current_settings_array))
					foreach ($wpcss_current_settings_array as $option_slug=>$new_css_row):
                      
                     if (  $new_css_row->property_name =='font-family' && isset($new_css_row->font_source) && $new_css_row->font_source =='google'   &&  strlen( $new_css_row->property_value)>2 )
						 $used_fonts_array[]=$new_css_row->property_value; //take all properties with slug containing font-family like header-font-family
                        
                 
					 endforeach;
			 
		 
            return array_unique($used_fonts_array);
}







 
function csshero_add_footer_trigger() {
	
						if (!wpcss_check_license() or !current_user_can('edit_theme_options') or  get_option('wpcss_hidetrigger')==1	) return;
						
						// if  (!isset($_GET['csshero_action']) OR  $_GET['csshero_action'] !="shutdown")  return;
	 
				?><div id="csshero-very-first-trigger"   ><a href="<?php echo add_query_arg( 'csshero_action', 'edit_page' )  ?>"></a></div>
				<style>
					/* NEW STARTUP BUTTON */
						#csshero-very-first-trigger{position:fixed;top:40px;right:40px;z-index: 999999999;background: #448cdd; width: 48px; height: 48px; -webkit-transition: width .5s ease-in-out;-moz-transition: width .5s ease-in-out;-o-transition: width .5s ease-in-out;transition: width .5s ease-in-out;-webkit-border-radius: 3px;-moz-border-radius: 3px;border-radius: 3px;overflow: hidden;}
						
						#csshero-very-first-trigger:hover{width: 98px; animation: cssherobganim 7s linear infinite; background: transparent url(//www.csshero.org/production/assets-startup-button/startup.png?v737473) no-repeat 0px -48px;}
						#csshero-very-first-trigger a{width: 198px; height: 48px; display: block; background: transparent url(//www.csshero.org/production/assets-startup-button/startup.png?v73747) no-repeat 0 0; cursor: pointer;-webkit-transition: margin-left .3s ease-in-out;-moz-transition: margin-left .3s ease-in-out;-o-transition: margin-left .3s ease-in-out;transition: margin-left .3s ease-in-out; max-width: inherit;}
						#csshero-very-first-trigger a:hover{margin-left: -50px;}
						@keyframes cssherobganim{from { background-position: 0 -48px; } to { background-position: 100% -48px; }}
				</style>
				
				<?php
}
add_action('wp_footer', 'csshero_add_footer_trigger');





// THIS GIVES US SOME OPTIONS FOR STYLING THE upload ADMIN AREA
function csshero_custom_upload_style() {
	
	
      echo '<style type="text/css">
       							.ml-submit, .theme-layouts-post-layout, tr.post_title , tr.align , tr.image_alt, tr.post_excerpt, tr.post_content ,tr.url{display:none}
						  		
						  		
						  		td.savesend{text-align: right;}
						  		tr.submit .savesend input:hover,
						  		tr.submit .savesend input {background: url(//www.csshero.org/csshero-nano-service/assets/img/esprit.png?v6) no-repeat 0px -862px; height: 70px !important; z-index:999;border: 0px;padding:0px;width: 208px;border-radius: 0px;-moz-border-radius: 0px;-webkit-border-radius: 0px; text-indent: -9999px;}
						  		#media-upload a.del-link:active,
						  		tr.submit .savesend input:active{position: relative; top: 1px;}
								
								#media-upload a.del-link:hover,
								#media-upload a.del-link{height: 70px; width: 101px; background: url(//www.csshero.org/csshero-nano-service/assets/img/esprit.png?v6) no-repeat -208px -862px; display: inline-block; float: right; margin: 0px 2px 0px 10px; text-indent: 999px;}
								
								
								tr.submit{border-top: 1px solid #dfdfdf;}
								tr.submit .savesend{padding-top: 15px;}
								
								div#media-upload-header{padding: 0px; border: 0px; background: #222; position: fixed; top: 0px; left: 0px; width: 100%; height: 48px; z-index: 9999;}
								#sidemenu a.current {padding-left: 20px; padding-right: 20px; font-weight: normal; text-decoration: none; background: #3e7cff; color: white;-webkit-border-top-left-radius: 0px;-webkit-border-top-right-radius: 0px;border-top-left-radius: 0px;border-top-right-radius: 0px;border-width: 0px;}
								#sidemenu a{padding: 10px 20px; border: 0px; background: transparent; color: white; font-size: 10px; text-transform: uppercase;}
								body#media-upload{padding-top: 50px; background: #f5f5f5; height: 100%;}
								body#media-upload ul#sidemenu{bottom: 0; margin: 0px; padding: 0px;}
								#sidemenu a:hover{background:#222;}
								h3.media-title{font-family: sans-serif; font-size: 10px; font-weight: bold; text-transform: uppercase;}
								h3.media-title,.upload-flash-bypass,.max-upload-size{display: block;text-align: center;}
								.upload-flash-bypass{margin-top: 20px;}
								.max-upload-size{margin-bottom: 20px;}
								#sidemenu li#tab-type_url,
								#sidemenu li#tab-grabber{display: none;}
								
								
         </style>';
}

if (isset($_GET['csshero_upload']) && $_GET['csshero_upload']==1) add_action('admin_head', 'csshero_custom_upload_style');

function wpcss_active_site_plugins() {
	$out="";
  $the_plugs = get_option('active_plugins'); 
	
    if ($the_plugs) foreach($the_plugs as $key => $value) {
        $string = explode('/',$value); // Folder name will be displayed
        $out.=$string[0] .',';
    }
	
	 $the_network_plugs=get_site_option('active_sitewide_plugins');
 
	 if ($the_network_plugs)  foreach($the_network_plugs as $key => $value) {
        $string = explode('/',$key); // Folder name will be displayed
        $out.=$string[0] .',';
    }
    return $out;
}

 
function wpcss_update_option($option_name,$new_value)
{
 

		  if ( get_option( $option_name ) !== false ) {
		  
			  // The option already exists, so we just update it.
			  update_option( $option_name, $new_value );
		  
		  } else {
		  
			  // The option hasn't been added yet. We'll add it with $autoload set to 'no'.
			  $deprecated = null;
			  $autoload = 'no';
			  add_option( $option_name, $new_value, $deprecated, $autoload );
		  }
}

///////SAVING AND EXPORTING



add_action('admin_menu', 'CSSHero_export_plugin_setup_menu');
 add_action('init', 'csshero_export_check_url_actions');
 function csshero_export_check_url_actions()
 
 {
	 
	 
	 
	 if (isset($_POST['csshero_set_cache_button']))
		  {
			 
			  wpcss_update_option('csshero_css_caching',$_POST['csshero_css_caching']);
			  
			  if ($_POST['csshero_css_caching']==1)  {
			  global $csshero_global_cache_settings_message;
			  
			   $csshero_global_cache_settings_message= "<h1 style='text-align:center'>CSS Caching Enabled.</h1>";
			   
			    wpcss_generate_static_css();
			   
			 
			 }
			   
			   
			   
			  
		  }
 
	 
	 
	 
	//ACTION DOWNLOAD SETTINGS TO FILE
	if (current_user_can('install_plugins') && isset($_POST['csshero_export_current_settings_to_file']))
		{  
		  header("Cache-Control: public");
		  header("Content-Description: File Transfer");
		  header("Content-Disposition: attachment; filename= current_csshero_settings.txt");
		  header("Content-Transfer-Encoding: binary");
		  $the_data=(base64_encode( (get_option('wpcss_current_settings_array_'.wpcss_current_theme_slug()))));
		 echo 	$the_data;
		 die;
		}
	
	//ACTION SAVE
	if (
            current_user_can('install_plugins') &&
            isset($_POST['csshero_import_current_settings_button']) &&
            isset($_POST['csshero_accept_conditions']) &&
          //  $_FILES['csshero_current_settings']['name']=='current_csshero_settings.txt' &&
            $_FILES['csshero_current_settings']['type']=='text/plain' &&
            $_FILES['csshero_current_settings']['error']==0
            )
		{
                        //echo $_POST['csshero_current_settings'];
			$the_data=(base64_decode(file_get_contents($_FILES['csshero_current_settings']['tmp_name'])));
		 	//UPDATE CURRENT MAIN THEME SETTINGS !!!
			wpcss_update_option('wpcss_current_settings_array_'.wpcss_current_theme_slug(),$the_data);
			 //	print_r($wpcss_current_settings_array);
			global $csshero_global_saving_import_message;									
			$csshero_global_saving_import_message="<h1>Success!</h1><p>go to your homepage and enjoy :)</p>";
		}
	
	
	
	
	
 }
 
 
function CSSHero_export_plugin_setup_menu(){
        add_submenu_page( 'options-general.php','CSSHero  Plugin Settings', 'CSS Hero', 'edit_theme_options', 'csshero_settings', 'CSSHero_settingspage_init' );
}
 
function CSSHero_settingspage_init(){
		
		global $csshero_global_saving_import_message;
		if ( isset( $csshero_global_saving_import_message)	):
			echo '<div id="message" class="updated fade"><p>'.$csshero_global_saving_import_message.'</p></div>';
			die;
		endif;
		 
		 global $csshero_global_cache_settings_message;
		if ( isset( $csshero_global_cache_settings_message)	):
			echo '<div id="message" class="updated fade"><p>'.$csshero_global_cache_settings_message.'</p></div>';
			 
		endif;
		 
		 
		 
		 
        ?>
		<div class="csshero-settings-wrap wrap">
		<h1>CSS Hero Static CSS</h1>
		<h3>Will serve to unlogged users a static CSS file for best performance. Cache will automatically be updated upon saving.</h3>
	 
		<table class="form-table">
			<!-- <tr>
				<th scope="row">Build a static CSS version of your current edits</th>
				<td>
					<a target="_blank" class="thickbox button button-hero" href="<?php  echo  get_bloginfo('url');?>/ ">Build and View Static CSS</a>
					<p class="description">Will open in a new window</p>
				</td>
			</tr> -->
			<tr>
				<th scope="row">Enable the cache now</th>
				<td>
					<form method="post">
						<input type="radio" name="csshero_css_caching" value="0" <?php if (get_option('csshero_css_caching')!=1) echo "checked"; ?>>OFF<br>
						<input type="radio" name="csshero_css_caching" value="1" <?php if (get_option('csshero_css_caching')==1) echo "checked"; ?>>ON<br>
						<br /><br />
						<input type="submit" class="button button-primary" name="csshero_set_cache_button" value="Update">
					</form>
				</td>
			</tr>
		</table>
		<hr>
		<br />
		<h1>CSS Hero Export / Import Tool</h1>
		
		<p>This tool allows you to export current site personalizations to a file in order to make easy your work of migrating your work to another domain.</p>
		<h3>Download active settings</h3>
		<p>This keeps your active settings, eg site personalizations, colors, etc. (without your editing history)</p>
		<form method="post">
			<br />
			<input type="submit" class="button" name="csshero_export_current_settings_to_file" value="Download Site Personalizations File">
			<br /><br />
		</form>
		
		<hr>
		<h3>Upload a current_csshero_settings.txt file and replace current state</h3>
		 
		<form method="post" enctype="multipart/form-data">
                        <?php 
                        if ( isset($_POST['csshero_import_current_settings_button'])  && $_FILES['csshero_current_settings']['type']!='text/plain') echo '<div id="message" class="updated fade"><p>You need to upload only text file</p></div>';
                        elseif ( isset($_POST['csshero_import_current_settings_button'])  && $_FILES['csshero_current_settings']['error']!=0) echo '<div id="message" class="updated fade"><p>Upload error</p></div>';
                        ?>
                        <input type="file" name="csshero_current_settings" />
			<h3>Warning - read well before submitting</h3>
			<?php if ( isset($_POST['csshero_import_current_settings_button'])  && !isset($_POST['csshero_accept_conditions'])) echo '<div id="message" class="updated fade"><p>You need to accept the conditions - read the warning</p></div>'; ?>
			<input type="checkbox" name="csshero_accept_conditions"> I understand that this will destroy any current live personalization of current site.
			<p>
			<input type="submit" class="button button-primary" name="csshero_import_current_settings_button" value="Activate">
			</p>
		</form>
		</div>
		<?php
}
 

  
  
  
  


///////RSS FEED UPDATES BOX ///////////////////

function rc_mdm_register_widgets() {
	global $wp_meta_boxes;
	
	wp_add_dashboard_widget('widget_cssheronews', __('From  the  CSS Hero world', 'rc_mdm'), 'rc_mdm_create_my_rss_box');
}
add_action('wp_dashboard_setup', 'rc_mdm_register_widgets');


function rc_mdm_create_my_rss_box() {
	
	// Get RSS Feed(s)
	include_once(ABSPATH . WPINC . '/feed.php');
	
	// My feeds list (add your own RSS feeds urls)
	$my_feeds = array( 
				'http://www.csshero.org/feed/?x=y' 
				);
	
	// Loop through Feeds
	foreach ( $my_feeds as $feed) :
	
		// Get a SimplePie feed object from the specified feed source.
		$rss = fetch_feed( $feed );
		if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly 
		    // Figure out how many total items there are, and choose a limit 
		    $maxitems = $rss->get_item_quantity( 3 ); 
		
		    // Build an array of all the items, starting with element 0 (first element).
		    $rss_items = $rss->get_items( 0, $maxitems ); 
	
		    // Get RSS title
		    $rss_title = '<a href="'.$rss->get_permalink().'" target="_blank">'.strtoupper( $rss->get_title() ).'</a>'; 
		endif;
	
		// Display the container
		?>
		<style>
		#csshero-blog-feed img { margin: 0 auto;display: block}
		#csshero-blog-feed li {border-bottom: 1px solid #ccc}
		#csshero-blog-feed li p:nth-of-type(2) {display: none}
		</style>
		<?php 
		echo '<div class="rss-widget" id="csshero-blog-feed">';
		//echo '<strong>'.$rss_title.'</strong>';
		echo "<img style='float:left; margin:0 5px' src='https://www.csshero.org/wp-content/uploads/2015/05/diamond.jpg' width='64' height='64' /> <strong>Start earning now! Become a CSS Hero affiliate</strong><br />
		Earn 40% on each sale right now.
		Spread the CSS Hero word and share the wealth with us! </p>
		<a target='_blank' href='http://www.csshero.org/affiliate/' style='float:right' class='button button-primary'>Start Earning</a>
		<div style='clear:both'></div>"; 
			 
		echo '<hr style="border: 0; background-color: #DFDFDF; height: 1px;">';
		echo "<strong>Latest News</strong>"; 
		// Starts items listing within <ul> tag
		
		echo '<ul>';
		
		// Check items
		if ( $maxitems == 0 ) {
			echo '<li>'.__( 'No item', 'rc_mdm').'.</li>';
		} else {
			// Loop through each feed item and display each item as a hyperlink.
			foreach ( $rss_items as $item ) :
				// Uncomment line below to display non human date
				//$item_date = $item->get_date( get_option('date_format').' @ '.get_option('time_format') );
				
				// Get human date (comment if you want to use non human date)
				$item_date = human_time_diff( $item->get_date('U'), current_time('timestamp')).' '.__( 'ago', 'rc_mdm' );
				
				// Start displaying item content within a <li> tag
				echo '<li>';
				// create item link
				echo '<a href="'.esc_url( $item->get_permalink() ).'" title="'.$item_date.'">';
				// Get item title
				echo esc_html( $item->get_title() );
				echo '</a>';
				// Display date
				echo ' <span class="rss-date">'.$item_date.'</span><br />';
				// Get item content
				$content = $item->get_content();
				// Shorten content
				//$content = wp_html_excerpt($content, 240) . ' [...]';
				// Display content
				echo $content;
				// End <li> tag
				echo '</li>';
			endforeach;
		}
		// End <ul> tag
		echo '</ul> </div>';

	endforeach; // End foreach feed
}

  
//end main csshero file, never close php :)