<?php
if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'before_widget' => '<span class="sidebar-top" /><li>',
        'after_widget' => '</li><span class="sidebar_bottom" />',
        'before_title' => '<h2>',
        'after_title' => '</h2>',
    ));

function string_limit_words($string, $word_limit) {
  $words = explode(' ', $string, ($word_limit + 1));
  if(count($words) > $word_limit)
  array_pop($words);
  return implode(' ', $words);
}

// Hook for adding admin menus
add_action('admin_menu', 'mt_add_pages');

// action function for above hook
function mt_add_pages() {

  // Add a new submenu under Manage:
  add_theme_page('Social Media Settings', 'Social Media Settings', 1, 'feed_options', 'mt_manage_page');

}

function mt_manage_page() {

// variables for the field and option names
  $opt_name = 'mt_feedburner_feed';
  $opt2_name = 'mt_subscription_code';
  $hidden_field_name = 'mt_submit_hidden';
  $data_feedburner_feed = 'mt_feedburner_feed';
  $subscription_link_code = 'mt_subscription_code';

  // Read in existing option value from database
  $opt_val = get_option( $opt_name );
  $opt_val2 = get_option( $opt2_name );

  if( $_POST[ $hidden_field_name ] == 'Y' ) {
    // Read their posted value
    $opt_val = $_POST[ $data_feedburner_feed ];
    $opt_val2 = $_POST[ $subscription_link_code ];

    // Save the posted values in the database
    update_option( $opt_name, $opt_val );
    update_option( $opt2_name, $opt_val2 );
    update_option( $opt3_name, $opt_val3 );

    // Put an options updated message on the screen

    ?>

	<?
			if($_POST['blogger']){ update_option('blogger', $_POST['blogger']); }
	        	else{ update_option('blogger', ''); }
			if($_POST['delicious']){ update_option('delicious', $_POST['delicious']); }
	        	else{ update_option('delicious', ''); }
			if($_POST['digg']){ update_option('digg', $_POST['digg']); }
	        	else{ update_option('digg', ''); }
			if($_POST['facebook']){ update_option('facebook', $_POST['facebook']); }
	        	else{ update_option('facebook', ''); }
			if($_POST['feed']){ update_option('feed', $_POST['feed']); }
				else{ update_option('feed', ''); }
			if($_POST['feedburner']){ update_option('feedburner', $_POST['feedburner']); }
				else{ update_option('feedburner', ''); }
			if($_POST['flickr']){ update_option('flickr', $_POST['flickr']); }
				else{ update_option('flickr', ''); }
	        if($_POST['friendfeed']){ update_option('friendfeed', $_POST['friendfeed']); }
	        	else{ update_option('friendfeed', ''); }
			if($_POST['friendster']){ update_option('friendster', $_POST['friendster']); }
	        	else{ update_option('friendster', ''); }
			if($_POST['lastfm']){ update_option('lastfm', $_POST['lastfm']); }
	        	else{ update_option('lastfm', ''); }
			if($_POST['linkedin']){ update_option('linkedin', $_POST['linkedin']); }
	        	else{ update_option('linkedin', ''); }
			if($_POST['livejournal']){ update_option('livejournal', $_POST['livejournal']); }
	        	else{ update_option('livejournal', ''); }
			if($_POST['mixx']){ update_option('mixx', $_POST['mixx']); }
	        	else{ update_option('mixx', ''); }
			if($_POST['myspace']){ update_option('myspace', $_POST['myspace']); }
	        	else{ update_option('myspace', ''); }
			if($_POST['netvibes']){ update_option('netvibes', $_POST['netvibes']); }
	        	else{ update_option('netvibes', ''); }
			if($_POST['newsvine']){ update_option('newsvine', $_POST['newsvine']); }
	        	else{ update_option('newsvine', ''); }
			if($_POST['stumble']){ update_option('stumble', $_POST['stumble']); }
	        	else{ update_option('stumble', ''); }
			if($_POST['technorati']){ update_option('technorati', $_POST['technorati']); }
	        	else{ update_option('technorati', ''); }				
	        if($_POST['twitter']){ update_option('twitter', $_POST['twitter']); }
	        	else{ update_option('twitter', ''); }
			if($_POST['vimeo']){ update_option('vimeo', $_POST['vimeo']); }
				else{ update_option('vimeo', ''); }
			if($_POST['webshots']){ update_option('webshots', $_POST['webshots']); }
				else{ update_option('webshots', ''); }
			if($_POST['yelp']){ update_option('yelp', $_POST['yelp']); }
				else{ update_option('yelp', ''); }
			if($_POST['youtube']){ update_option('youtube', $_POST['youtube']); }
				else{ update_option('youtube', ''); }
			
	?>
	
    <div class="updated"><p><strong><?php _e('Information saved.', 'mt_trans_domain' ); ?></strong></p></div>
    
    <?php }

      // Now display the options editing screen
      echo '<div class="wrap">';

      // header
      echo "<h2>" . __( 'Social Media Configuration', 'mt_trans_domain' ) . "</h2>"
    ?>
		  <h3>How to activate Feeds</h3>

		  <p>
			The theme has been automatically setup to use whatever feed service or social media outlets you'd like. All you need to do is include the feed URL or ID from your account in the fields below and click <em>Update Options</em>, and the feeds will automatically populate in your sidebar.
		  </p>


		<!-- options form -->
		<form name="form1" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>" style="float: left;">
			<input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y">
			
			<table class="form-table" style="margin:0; width:auto">
				<tr>
					<td><label for="blogger"><h3>Blogger:</h3></label></td>
					<td><input type="text" name="blogger" id="blogger" maxlength="60" size="60" value="<?=get_option('blogger');?>" /></td>
					<td>Enter your <strong>Blogger</strong> address. Example: http://(YourBlogName).blogspot.com. YourBlogName is all you need.</td>
				</tr>
                <tr>
					<td><label for="stumble"><h3>Delicious:</h3></label></td>
					<td><input type="text" name="delicious" id="delicious" maxlength="60" size="60" value="<?=get_option('delicious');?>" /></td>
					<td>Enter your <strong>Delicious</strong> search info.  For instance maybe your name.</td>
				</tr>
                <tr>
					<td><label for="digg"><h3>Digg:</h3></label></td>
					<td><input type="text" name="digg" id="digg" maxlength="60" size="60" value="<?=get_option('digg');?>" /></td>
					<td>Enter what you want people to search in <strong>Digg</strong>. Something like maybe you name.</td>
				</tr>
                <tr>
					<td><label for="facebook"><h3>Facebook:</h3></label></td>
					<td><input type="text" name="facebook" id="facebook" maxlength="60" size="60" value="<?=get_option('facebook');?>" /></td>
					<td>Enter the <strong>title</strong> that you would like to use for users to share on Facebook</td>
				</tr>
                <tr>
					<td><label for="feed"><h3>RSS Feed:</h3></label></td>
					<td><input type="text" name="feed" id="feed" maxlength="60" size="60" value="<?=get_option('feed');?>" /></td>
					<td>Enter your RSS <strong>location</strong>. <em>Example: feeds for http://yourdomain/feeds</em></td>
				</tr>
                <tr>
					<td><label for="feedburner"><h3>Feedburner:</h3></label></td>
					<td><input type="text" name="feedburner" id="feedburner" maxlength="60" size="60" value="<?=get_option('feedburner');?>" /></td>
					<td>Enter your Feedburner <strong>URL</strong>. <em>Example: http://feeds.feedburner.com/myFeed</em></td>
				</tr>
				<tr>
					<td><label for="<?=$subscription_link_code;?>"><h3><? _e("Feed ID:", 'mt_trans_domain' ); ?></h3></label></td>
					<td><input type="text" name="<?=$subscription_link_code;?>" size="60" value="<?=stripslashes($opt_val2);?>" /></td>
					<td>If you're using FeedBurner you can take advantage of their Email Subscription capabilities by entering your <strong>FeedID</strong>. This can be grabbed from your feed details page of FeedBurner.</td>
				</tr>
				<tr>
					<td><label for="flickr"><h3>Flickr:</h3></label></td>
					<td><input type="text" name="flickr" id="flickr" maxlength="60" size="60" value="<?=get_option('flickr');?>" /></td>
					<td>Enter your <strong>Flickr Username</strong>.</td>
				</tr>
				<tr>
					<td><label for="friendfeed"><h3>FriendFeed:</h3></label></td>
					<td><input type="text" name="friendfeed" id="friendfeed" maxlength="60" size="60" value="<?=get_option('friendfeed');?>" /></td>
					<td>Enter your <strong>Friendfeed</strong> domain. Example: http://friendfeed.com/(YourDomain). YourDomain is all you need.</td>
				</tr>
                <tr>
					<td><label for="friendster"><h3>FriendSter:</h3></label></td>
					<td><input type="text" name="friendster" id="friendster" maxlength="60" size="60" value="<?=get_option('friendster');?>" /></td>
					<td>Enter your <strong>Friendster</strong> domain. Example: http://friendster.com/(YourDomain). YourDomain is all you need.</td>
				</tr>
                <tr>
					<td><label for="lastfm"><h3>Last.fm:</h3></label></td>
					<td><input type="text" name="lastfm" id="lastfm" maxlength="60" size="60" value="<?=get_option('lastfm');?>" /></td>
					<td>Enter your <strong>Last.fm</strong> account. Example: http://www.last.fm/user/(YourAccount). YourAccount is all you need.</td>
				</tr>
                <tr>
					<td><label for="linkedin"><h3>Linkedin:</h3></label></td>
					<td><input type="text" name="linkedin" id="linkedin" maxlength="60" size="60" value="<?=get_option('linkedin');?>" /></td>
					<td>Enter your <strong>Linkedin</strong> Account. Example: http://www.linkedin.com/li/(YourAccount). YourAccount is all you need (no spaces).</td>
				</tr>
                <tr>
					<td><label for="livejournal"><h3>Live Journal:</h3></label></td>
					<td><input type="text" name="livejournal" id="livejournal" maxlength="60" size="60" value="<?=get_option('livejournal');?>" /></td>
					<td>Enter your <strong>Live Journal</strong> Account. Example: http://(YourDomain).livejournal.com/. YourDomain is all you need.</td>
				</tr>
                <tr>
					<td><label for="mixx"><h3>Mixx:</h3></label></td>
					<td><input type="text" name="mixx" id="mixx" maxlength="60" size="60" value="<?=get_option('mixx');?>" /></td>
					<td>Enter your <strong>Mixx</strong> Account. Example: http://www.mixx.com/users/(YourAccount).  YourAccount is all you need.</td>
				</tr>
                <tr>
					<td><label for="myspace"><h3>MySpace:</h3></label></td>
					<td><input type="text" name="myspace" id="myspace" maxlength="60" size="60" value="<?=get_option('myspace');?>" /></td>
					<td>Enter your <strong>MySpace Username</strong>.</td>
				</tr>
                <tr>
					<td><label for="netvibes"><h3>Netvibes:</h3></label></td>
					<td><input type="text" name="netvibes" id="netvibes" maxlength="60" size="60" value="<?=get_option('netvibes');?>" /></td>
					<td>Enter your <strong>Netvibes</strong> Account. Example: http://www.netvibes.com/(YourAccount). YourAccount is all you need.</td>
				</tr>
                <tr>
					<td><label for="newsvine"><h3>Newsvine:</h3></label></td>
					<td><input type="text" name="newsvine" id="newsvine" maxlength="60" size="60" value="<?=get_option('newsvine');?>" /></td>
					<td>Enter your <strong>Newsvine</strong> Account. Example: http://www.(YourAccount).netvibes.com/. YourAccount is all you need.</td>
				</tr>
                <tr>
					<td><label for="reddit"><h3>Reddit:</h3></label></td>
					<td><input type="text" name="reddit" id="reddit" maxlength="60" size="60" value="<?=get_option('reddit');?>" /></td>
					<td>Enter your <strong>Reddit</strong> Account. Example: http://www.reddit.com/user/(YourAccount). YourAccount is all you need.</td>
				</tr>
                <tr>
					<td><label for="stumble"><h3>StumbleUpon:</h3></label></td>
					<td><input type="text" name="stumble" id="stumble" maxlength="60" size="60" value="<?=get_option('stumble');?>" /></td>
					<td>Enter your <strong>StumbleUpon Profile</strong> for users to find what you stumble.</td>
				</tr>
                <tr>
					<td><label for="technorati"><h3>Technorati:</h3></label></td>
					<td><input type="text" name="technorati" id="technorati" maxlength="60" size="60" value="<?=get_option('technorati');?>" /></td>
					<td>Enter your Blog registered with <strong>Technorati</strong>. Like this www.yoursite.com.</td>
				</tr>
				<tr>
					<td><label for="twitter"><h3>Twitter:</h3></label></td>
					<td><input type="text" name="twitter" id="twitter" maxlength="60" size="60" value="<?=get_option('twitter');?>" /></td>
					<td>Enter your <strong>Twitter</strong> for users to tweet you.</td>
				</tr>
                <tr>
					<td><label for="vimeo"><h3>Vimeo:</h3></label></td>
					<td><input type="text" name="vimeo" id="vimeo" maxlength="60" size="60" value="<?=get_option('vimeo');?>" /></td>
					<td>Enter your <strong>Vimeo</strong> Account. Example: http://www.reddit.com/(YourAccount). YourAccount is all you need.</td>
				</tr>
                <tr>
					<td><label for="webshots"><h3>Webshots:</h3></label></td>
					<td><input type="text" name="webshots" id="webshots" maxlength="60" size="60" value="<?=get_option('webshots');?>" /></td>
					<td>Enter your <strong>Webshots</strong> Account. Example: http://www.webshots.com/(YourAccount). YourAccount is all you need.</td>
				</tr>
                <tr>
					<td><label for="yelp"><h3>Yelp:</h3></label></td>
					<td><input type="text" name="yelp" id="yelp" maxlength="60" size="60" value="<?=get_option('yelp');?>" /></td>
					<td>Enter your <strong>Yelp</strong> User ID. Example: o9NyLXdwEByujD1Fun5lYw.</td>
				</tr>
                <tr>
					<td><label for="youtube"><h3>YouTube:</h3></label></td>
					<td><input type="text" name="youtube" id="youtube" maxlength="60" size="60" value="<?=get_option('youtube');?>" /></td>
					<td>Enter your <strong>YouTube</strong> Account.</td>
				</tr>
                 
			</table>
	
	     	<p class="submit"><input type="submit" name="Submit" value="<? _e('Update Options', 'mt_trans_domain' ) ?>" /></p>
		</form>
    </div>

<?php }

function feed_url() {
	$output = stripslashes(get_option('mt_feedburner_feed'));
	if ( '' != $output )
	echo $output;
}

function feedburner_subscription_link() {
	$output = "http://www.feedburner.com/fb/a/emailverifySubmit?feedId=" . stripslashes(get_option('mt_subscription_code')) . "&amp;loc=en_US";
	if ( '' != $output )
	echo $output;
}

function feedburner_feed_id() {
	$output = stripslashes(get_option('mt_subscription_code'));
	if ( '' != $output )
	echo $output;
}

add_action('feed_url', 'feed_options');
add_action('feedburner_subscription_link', 'feed_options');
add_action('feedburner_feed_id', 'feed_options');

//set initial defaults for feeds
add_option('blogger', '');
add_option('delicious', '');
add_option('digg', '');
add_option('facebook', '');
add_option('feed', '');
add_option('feedburner', '');
add_option('flickr', '');
add_option('friendfeed', '');
add_option('friendster', '');
add_option('lastfm', '');
add_option('linkedin', '');
add_option('livejournal', '');
add_option('mixx', '');
add_option('myspace', '');
add_option('netvibes', '');
add_option('newsvine', '');
add_option('pownce', '');
add_option('reddit', '');
add_option('stumble', '');
add_option('technorati', '');
add_option('twitter', '');
add_option('vimeo', '');
add_option('webshots', '');
add_option('yelp', '');
add_option('youtube', '');
?>