Commits

Doug Stewart committed d7082ac

Mucho change-o.

  • Participants
  • Parent commits 4fef8cf

Comments (0)

Files changed (7)

File include/css/lbcb-core.css

 	width: 38px;
 	background: transparent url('../images/ku_36pxBugOnly.png') no-repeat;
 }
+
+.kuler-saved {
+	background-color: #F8FAFC;
+}

File include/js/lbcb-ajax.js

 		$.post(the_ajax_script.ajaxurl, data, function(response) {
 			alert(response);
 		});
+		$(this).closest('tr').addClass('kuler-saved');
 		return false;
 	});
 });

File include/lbcb-ajax.php

  * Process the Kulers sent in the back-end
  */
 function lbcb_ajax_process_kulers(){
+	global $wpdb;
+
+	// Set up some query arguments
+	$lbcb_args = array(
+		'order'				=> 'DESC',
+		'post_type'			=> 'colorbox',
+	);
+	
+	// Check $_POST to make sure we got sent legit data
 	if( isset($_POST['kuler'])){
 		parse_str($_POST['kuler']);
-		$response = $kuler;
-		echo $response;
+
+		// Grab the Kuler transient for the current screen
+		$kuler_trans = get_transient( 'lbcb_' . $kuler_type . '_kulers' );
+		
+		$kuler_urls = wp_list_pluck( $kuler_trans, 'url' );
+		
+		if(in_array($kuler,$kuler_urls)){
+			$k_index = array_search( $kuler, $kuler_urls);
+			$k_full = $kuler_trans[$k_index];
+			
+			//print_r($k_full);
+		}else{
+			echo "Whoops. You shouldn't ever see this message.";
+		}
+		$lbcb_args['meta_query'] = array( 
+										array(	'key'	=> '_lbcb_type',
+												'value'	=> 'kuler'
+										),
+										array(	'key'	=> '_lbcb_link',
+												'value'	=> $kuler
+										)
+									);
+		$kuler_query = new WP_Query( $lbcb_args );
+		
+		if( 0 == $kuler_query->post_count){
+			$k_full['type'] = 'kuler';
+			lbcb_insert_colorbox( $k_full );
+			echo "Kuler added.";
+		}else{
+			echo "Kuler already present.";
+		}
 		die();
 		
 	}else{

File include/lbcb-cpt.php

 	
 	$cb_types = array( 'original', 'colourlover', 'studiopress', 'kuler', 'colllor', 'other' );
 	
-	if( in_array( $colorbox['type'], $types) ){
+	if( in_array( $colorbox['type'], $cb_types) ){
 		$lbcb_type = $colorbox['type'];
 	}else{
 		$lbcb_type = 'other';
 	if( $cb_ID != 0 ){
 		add_post_meta( $cb_ID, '_lbcb_type', $lbcb_type, true );
 		add_post_meta( $cb_ID, '_lbcb_author', $colorbox['author'], true );
-		add_post_meta( $cb_ID, '_lbcb_url', $colorbox['url'], true );
+		add_post_meta( $cb_ID, '_lbcb_link', $colorbox['url'], true );
 		add_post_meta( $cb_ID, '_lbcb_color1', $colorbox['color1'], true );
 		add_post_meta( $cb_ID, '_lbcb_color2', $colorbox['color2'], true );
 		add_post_meta( $cb_ID, '_lbcb_color3', $colorbox['color3'], true );

File include/lbcb-list-table.php

  * @since 		LB-Colorbox 0.5
  */
 class LBCB_Kuler_List_Table extends WP_List_Table {
+	
+	protected $kuler_type;
+	
 	/**
 	 * Constructor
 	 */
 	 */
 	function column_title( $item ){
 		$actions = array(
-			'save'	=> sprintf('<a href="?page=%s&post_type=colorbox&action=%s&kuler=%s">Save</a>',$_REQUEST['page'],'savekuler',urlencode($item['url'])),
+			'save'	=> sprintf('<a href="?page=%s&post_type=colorbox&action=%s&kuler=%s&kuler_type=%s">Save</a>',
+								$_REQUEST['page'],
+								'savekuler',
+								urlencode($item['url']),
+								$this->kuler_type)
 		);
 		
 		return sprintf('%1$s %2$s',
 			'total_pages' => ceil($total_items/$per_page)   //WE have to calculate the total number of pages
 		) );
 	}
+	
+	/**
+	 * Accessor function to set Kuler type
+	 *
+	 * @param string $k_type The type of kuler we're currently dealing with
+	 */
+	function set_kuler_type( $k_type ){
+		$this->kuler_type = $k_type;
+	}
 }

File include/lbcb-options.php

 function lbcb_rating_kulers_page() {
 	$kulersListTable = new LBCB_Kuler_List_Table();
 	
+	$kulersListTable->set_kuler_type( 'rating' );
 	$kulersListTable->prepare_items( 'rating' );
 ?>
 	<div class="wrap">
 function lbcb_popular_kulers_page() {
 	$kulersListTable = new LBCB_Kuler_List_Table();
 	
+	$kulersListTable->set_kuler_type( 'popular' );
 	$kulersListTable->prepare_items( 'popular' );
 ?>
 	<div class="wrap">
  */
 function lbcb_recent_kulers_page() {
 	$kulersListTable = new LBCB_Kuler_List_Table();
-	
+
+	$kulersListTable->set_kuler_type( 'recent' );	
 	$kulersListTable->prepare_items( 'recent' );
 ?>
 	<div class="wrap">
 function lbcb_random_kulers_page() {
 	$kulersListTable = new LBCB_Kuler_List_Table();
 	
+	$kulersListTable->set_kuler_type( 'random' );
 	$kulersListTable->prepare_items( 'random' );
 ?>
 	<div class="wrap">
 
 Under Settings->ColorBox
 
-= What about foo bar? =
-
-Answer to foo bar dilemma.
-
 == Screenshots ==
 
 1. Create your own swatches and save them as Custom Post Types