WordPress.org

Ready to get started?Download WordPress

Forums

Front end posting with extra tables MySQL (1 post)

  1. GrundeLL
    Member
    Posted 2 years ago #

    Hello,

    So what im working on is a front end posting for a Facebook app. The problem I'm having is that i have to tie the facebook id and accesstoken to the post so i can retrive it later. I've managed to get the access_token and the user_id. The problem I'm having is that it seams like it doesn't want to post it to my database.

    This is what my code looks like.

    <?php
    /*
    Template Name: Febuary Love
    */
    
    if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {
    
    	// Do some minor form validation to make sure there is content
    	if (isset ($_POST['title'])) {
    		$title =  $_POST['title'];
    	} else {
    		echo 'Please enter the Poem name';
    	}
    	if (isset ($_POST['description'])) {
    		$description = $_POST['description'];
    	} else {
    		echo 'Please enter some notes';
    	}
    
    	$tags = $_POST['post_tags'];
    
    	// ADD THE FORM INPUT TO $new_post ARRAY
    	$new_post = array(
    	'post_title'	=>	$title,
    	'post_content'	=>	$description,
    	'post_category'	=>	array($_POST['cat']),  // Usable for custom taxonomies too
    	'tags_input'	=>	array($tags),
    	'post_status'	=>	'draft',           // Choose: publish, preview, future, draft, etc.
    	'post_type'	=>	'post',  //'post',page' or use a custom post type if you want to
    	'post_author' => $user,
    	'access_token' => $access_token,
    	);
    
    	//SAVE THE POST
    	$pid = wp_insert_post($new_post);
    
        //SET OUR TAGS UP PROPERLY
    	wp_set_post_tags($pid, $_POST['post_tags']);
    
    	//REDIRECT TO THE NEW POST ON SAVE
    	$link = get_permalink( $pid );
    	wp_redirect( $link );
    
    } // END THE IF STATEMENT THAT STARTED THE WHOLE FORM
    
    //POST THE POST YO
    do_action('wp_insert_post', 'wp_insert_post');
    
    get_header(); ?> 
    
    <?php
    	add_filter('fb_php_sdk_load','your_filter');
    	function your_filter($array)
    	{
    	    $array[] = '2.1.2'; //exact version number you need
    	    return $array;
    	}
    
    	$facebook = new Facebook(array(
    		'appId' => '$app_id',
    		'secret' => '$app_secret',
    		'cookie' => true,  
    
    	));
    
    	$session = $facebook->getUser();
    
    	if (!empty($session))
    		{
    			try{
    				$user = $facebook->getUser();
    				$user = $facebook->api('/me');
    				print_r($user);
    
    			}
    			catch (Exception $e){
    			}
    
    		if (!empty($user))
    		{
    	 		echo "hello";
    		}
    		else
    			die ("An error occured");
    	}
    	else{
    		$loginUrl = $facebook->getLoginUrl(array(
    		    'canvas' => 1,
    		    'fbconnect' => 0,
    		    'scope' => 'offline_access, publish_stream'
    		));
    			echo "<a href='".$loginUrl."'>Click </a> to add the Copypanther Facebook application";
    		}
    ?>
    
    <?php
    $user = $facebook->getUser();
    if($user){
        $access_token = $facebook->getAccessToken();
    	print_r($access_token);
    
    }
    ?>
    
            <div id="container">
                <div id="content" role="main"> 
    
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> 
    
                    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <?php if ( is_front_page() ) { ?>
                            <h2 class="entry-title"><?php the_title(); ?></h2>
                        <?php } else { ?>
                            <h1 class="entry-title"><?php the_title(); ?></h1>
                        <?php } ?> 
    
                        <div class="form-content">
                            <?php the_content(); ?>
    
    						<!-- WINE RATING FORM -->
    
    						<div class="wpcf7">
    						<form id="new_post" name="new_post" method="post" action="" class="wpcf7-form" enctype="multipart/form-data">
    							<!-- post name -->
    							<fieldset name="name">
    								<label for="title">Love poem name:</label>
    								<input type="text" id="title" value="" tabindex="5" name="title" />
    							</fieldset>
    
    							<!-- post Category -->
    							<fieldset class="category">
    								<label for="cat">Translate to:</label>
    								<?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0' ); ?>
    							</fieldset>
    
    							<!-- post Content -->
    							<fieldset class="content">
    								<label for="description">Love poem:</label>
    								<textarea id="description" tabindex="15" name="description" cols="80" rows="10"></textarea>
    							</fieldset>
    
    							<!-- post tags -->
    							<fieldset class="tags">
    								<label for="post_tags">Keywords (comma separated):</label>
    								<input type="text" value="" tabindex="35" name="post_tags" id="post_tags" />
    							</fieldset>
    
    							<fieldset class="submit">
    								<input type="submit" value="Send" tabindex="40" id="submit" name="submit" />
    							</fieldset>
    
    							<input type="hidden" name="action" value="new_post" />
    							<?php wp_nonce_field( 'new-post' ); ?>
    						</form>
    						</div> <!-- END WPCF7 -->
    
                            <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
                            <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
                        </div><!-- .entry-content -->
                    </div><!-- #post-## --> 
    
    <?php endwhile; // end of the loop. ?> 
    
                </div><!-- #content -->
            </div><!-- #container -->
    <?php get_footer(); ?>

    What i need to post is the $access_token and $user. They look like this:

    $user:

    Array ( [id] => xxxxxxx [name] => xxx xxxxx [first_name] => xxxxxx [last_name] => xxxxxx [link] => http://www.facebook.com/xxxxxxxusername => xxxxxxxx [hometown] => Array ( [id] => xxxxxxxxx [name] => xxxxxxxx, xxxxxx ) [location] => Array ( [id] => xxxxxxxxx [name] => xxxxxxxx, xxxxxxxx ) [bio] => Lost like always! [work] => Array ( [0] => Array ( [employer] => Array ( [id] => xxxxxx [name] => NGee ) [location] => Array ( [id] => xxxxxxxxxxx [name] => xxxxxxxx, xxxxxxxx ) [position] => Array ( [id] => xxxxxxxxx [name] => Owner, CEO ) [start_date] => 2010-01 ) ) [education] => Array ( [0] => Array ( [school] => Array ( [id] => 111487752200798 [name] => xxxxxxxxxxx) [year] => Array ( [id] => xxxxxxx [name] => xxxxxxx ) [type] => xxxxxxxxx ) [1] => Array ( [school] => Array ( [id] => 124099044279792 [name] => xxxxxxxx ) [year] => Array ( [id] => xxxxxxx [name] => 2010 ) [type] => College ) ) [gender] => male [timezone] => 1 [locale] => en_US [verified] => 1 [updated_time] => 2011-12-06T11:35:49+0000 ) hello

    and the $access_token:
    AAAEEh9vZCO3MBAHdRlbkZBCvMHbFy05oyc8E29LhEk5QBJWCavpz68IC4A7gZCGrR6mICXkn4SZA81ZACXaasXZtfeEtBePEg8b7iWZB1bquZCwZDZD

    The thing is that as I understand it I need to save it in wp_post to tie it the the post.

    So question is simple.

    How to i post this information to DB / MySQL table wp_post?

    Thanks for taking time to look at this.

    Best Regards
    GrundeLL

Topic Closed

This topic has been closed to new replies.

About this Topic