$normal_dashboard['woo_tumblog_dashboard_widget']);
unset($normal_dashboard['woo_tumblog_dashboard_widget']);
// Merge the two arrays together so tumblog widget is at the beginning
$sorted_dashboard = array_merge($woo_tumblog_widget_backup, $normal_dashboard);
// Save the sorted array back into the original metaboxes
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
}
//Loads Tumblog javascript and php js functions
function woo_load_tumblog_libraries() {
wp_enqueue_script( 'newscript', get_template_directory_uri() . '/functions/js/tumblog-ajax.js', array( 'jquery', 'jquery-form'));
wp_enqueue_script( 'nicedit', get_template_directory_uri() . '/functions/js/nicEdit.js' );
wp_enqueue_script( 'phpjs', get_template_directory_uri() . '/functions/js/php.js' );
wp_enqueue_script( 'datepicker', get_template_directory_uri() . '/functions/js/ui.datepicker.js',array( 'jquery'));
}
//Load Tumblog CSS
function woo_load_tumblog_css($hook) {
if ($hook == 'post.php' OR $hook == 'post-new.php' OR $hook == 'page-new.php' OR $hook == 'page.php') {
}
else {
echo "";
echo "";
}
}
/*-----------------------------------------------------------------------------------*/
/* AJAX Callback Functions
/*-----------------------------------------------------------------------------------*/
//Handles AJAX Form Post from Woo QuickPress
function woo_tumblog_ajax_post() {
//Publish Article
if ($_POST['tumblog-type'] == 'article')
{
$data = $_POST;
$type = 'note';
woo_tumblog_publish($type, $data);
die ( 'OK' );
}
//Publish Video
elseif ($_POST['tumblog-type'] == 'video')
{
$data = $_POST;
$type = 'video';
woo_tumblog_publish($type, $data);
die ( 'OK' );
}
//Publish Image
elseif ($_POST['tumblog-type'] == 'image')
{
$data = $_POST;
$type = 'image';
woo_tumblog_publish($type, $data);
die ( 'OK' );
}
//Publish Link
elseif ($_POST['tumblog-type'] == 'link')
{
$data = $_POST;
$type = 'link';
woo_tumblog_publish($type, $data);
die ( 'OK' );
}
//Publish Quote
elseif ($_POST['tumblog-type'] == 'quote')
{
$data = $_POST;
$type = 'quote';
woo_tumblog_publish($type, $data);
die ( 'OK' );
}
//Publish Audio
elseif ($_POST['tumblog-type'] == 'audio')
{
$data = $_POST;
$type = 'audio';
woo_tumblog_publish($type, $data);
die ( 'OK' );
}
//Default
else {
die ( 'OK' );
}
}
//Publishes the Tumblog Item
function woo_tumblog_publish($type, $data) {
global $current_user;
//Gets the current user's info
get_currentuserinfo();
$content_method = get_option( 'woo_tumblog_content_method' );
//Set custom fields
$tumblog_custom_fields = array( 'video-embed' => 'video-embed',
'quote-copy' => 'quote-copy',
'quote-author' => 'quote-author',
'quote-url' => 'quote-url',
'link-url' => 'link-url',
'image-url' => 'image',
'audio-url' => 'audio'
);
//get term ids
$tumblog_items = array( 'articles' => get_option( 'woo_articles_term_id'),
'images' => get_option( 'woo_images_term_id'),
'audio' => get_option( 'woo_audio_term_id'),
'video' => get_option( 'woo_video_term_id'),
'quotes' => get_option( 'woo_quotes_term_id'),
'links' => get_option( 'woo_links_term_id')
);
//Set date formatting
$php_formatting = "Y-m-d H:i:s";
//default post settings
$tumbl_note = array();
$tumbl_note['post_status'] = 'publish';
$browser = $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$safari_check = substr_count( strtolower( $browser ) , strtolower( 'safari' ) );
if ($safari_check > 0) {
$data['tumblog-content'] = str_ireplace(array( '
','
'),array( '','
'),$data['tumblog-content']);
$data['tumblog-content'] = str_ireplace(array( '
'),array( '
'),$data['tumblog-content']);
$data['tumblog-content'] = str_ireplace(array( ' '), array( ' '),$data['tumblog-content']);
}
//Handle Tumblog Types
switch ($type)
{
case 'note':
//Create post object
$tumbl_note['post_title'] = $data['note-title'];
$tumbl_note['post_content'] = $data['tumblog-content'];
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($data['tumblog-status'] != '') {
$tumbl_note['post_status'] = $data['tumblog-status'];
}
//Hours and Mins
$original_hours = (int)$data['original-tumblog-hours'];
$original_mins = (int)$data['original-tumblog-mins'];
$original_date = strtotime($data['original-tumblog-date']);
$posted_date = strtotime($data['tumblog-date']);
$note_hours = (int)$data['tumblog-hours'];
if ($note_hours == 0) { $note_hours = 12; }
elseif ($note_hours >= 24) { $note_hours = 0; }
$note_mins = (int)$data['tumblog-mins'];
if ($note_mins == 0) { $note_mins = 0; }
elseif ($note_mins >= 60) { $note_mins = 0; }
//Convert to Y-m-d H:i:s
//if everything is unchanged
if ( ($note_hours == $original_hours) && ($note_mins == $original_mins) && ($posted_date == $original_date) ) {
$time_now_hours = date_i18n( "H" );
$time_now_mins = date_i18n( "i" );
$date_raw = date( "Y").'-'.date( "m").'-'.date( "d").' '.$time_now_hours.':'.$time_now_mins.':00';
} else {
$date_raw = date( "Y",strtotime($data['tumblog-date'])).'-'.date( "m",strtotime($data['tumblog-date'])).'-'.date( "d",strtotime($data['tumblog-date'])).' '.$note_hours.':'.$note_mins.':00';
}
$date_formatted = date($php_formatting, strtotime($date_raw));
$tumbl_note['post_date'] = $date_formatted;
// DEPRECATED
// }
$tumbl_note['post_author'] = $current_user->ID;
$tumbl_note['tags_input'] = $data['tumblog-tags'];
// DEPRECATED
// Get Category from Theme Options
/*
if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
$category_id = get_cat_ID( get_option( 'woo_articles_category') );
$categories = array($category_id);
} else {
$categories = array();
}
*/
$categories = array();
$post_cat_array = $data['post_category'];
if(empty($post_cat_array))
{
//Do nothing
} else {
$N = count($post_cat_array);
for($i=0; $i < $N; $i++) {
array_push($categories, $post_cat_array[$i]);
}
}
$tumbl_note['post_category'] = $categories;
//Insert the note into the database
$post_id = wp_insert_post($tumbl_note);
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($content_method == 'post_format') {
set_post_format( $post_id, 'aside' );
} else {
//update posts taxonomies
$taxonomy_data = $data['tax_input'];
if ( !empty($taxonomy_data) ) {
foreach ( $taxonomy_data as $taxonomy => $tags ) {
$taxonomy_obj = get_taxonomy($taxonomy);
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
$tags = array_filter($tags);
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
array_push($tags, $tumblog_items['articles']);
}
} else {
$tags[0] = $tumblog_items['articles'];
}
wp_set_post_terms( $post_id, $tags, 'tumblog' );
}
// DEPRECATED
// }
break;
case 'video':
//Create post object
$tumbl_note['post_title'] = $data['video-title'];
$tumbl_note['post_content'] = $data['tumblog-content'];
// DEPRECATED
//if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($data['tumblog-status'] != '') {
$tumbl_note['post_status'] = $data['tumblog-status'];
}
//Hours and Mins
$original_hours = (int)$data['original-tumblog-hours'];
$original_mins = (int)$data['original-tumblog-mins'];
$original_date = strtotime($data['original-tumblog-date']);
$posted_date = strtotime($data['tumblog-date']);
$note_hours = (int)$data['tumblog-hours'];
if ($note_hours == 0) { $note_hours = 12; }
elseif ($note_hours >= 24) { $note_hours = 0; }
$note_mins = (int)$data['tumblog-mins'];
if ($note_mins == 0) { $note_mins = 0; }
elseif ($note_mins >= 60) { $note_mins = 0; }
//Convert to Y-m-d H:i:s
//if everything is unchanged
if ( ($note_hours == $original_hours) && ($note_mins == $original_mins) && ($posted_date == $original_date) ) {
$time_now_hours = date_i18n( "H" );
$time_now_mins = date_i18n( "i" );
$date_raw = date( "Y").'-'.date( "m").'-'.date( "d").' '.$time_now_hours.':'.$time_now_mins.':00';
} else {
$date_raw = date( "Y",strtotime($data['tumblog-date'])).'-'.date( "m",strtotime($data['tumblog-date'])).'-'.date( "d",strtotime($data['tumblog-date'])).' '.$note_hours.':'.$note_mins.':00';
}
$date_formatted = date($php_formatting, strtotime($date_raw));
$tumbl_note['post_date'] = $date_formatted;
// DEPRECATED
// }
$tumbl_note['post_author'] = $current_user->ID;
$tumbl_note['tags_input'] = $data['tumblog-tags'];
// DEPRECATED
//Get Category from Theme Options
/*
if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
$category_id = get_cat_ID( get_option( 'woo_videos_category') );
$categories = array($category_id);
} else {
$categories = array();
}
*/
$categories = array();
$post_cat_array = $data['post_category'];
if(empty($post_cat_array))
{
//Do nothing
} else {
$N = count($post_cat_array);
for($i=0; $i < $N; $i++) {
array_push($categories, $post_cat_array[$i]);
}
}
$tumbl_note['post_category'] = $categories;
//Insert the note into the database
$post_id = wp_insert_post($tumbl_note);
//Add Custom Field Data to the Post
add_post_meta($post_id, $tumblog_custom_fields['video-embed'], $data['video-embed'], true);
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($content_method == 'post_format') {
set_post_format( $post_id, 'video' );
} else {
//update posts taxonomies
$taxonomy_data = $data['tax_input'];
if ( !empty($taxonomy_data) ) {
foreach ( $taxonomy_data as $taxonomy => $tags ) {
$taxonomy_obj = get_taxonomy($taxonomy);
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
$tags = array_filter($tags);
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
array_push($tags, $tumblog_items['video']);
}
} else {
$tags[0] = $tumblog_items['video'];
}
wp_set_post_terms( $post_id, $tags, 'tumblog' );
}
// DEPRECATED
// }
break;
case 'image':
//Create post object
$tumbl_note['post_title'] = $data['image-title'];
$tumbl_note['post_content'] = $data['tumblog-content'];
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($data['tumblog-status'] != '') {
$tumbl_note['post_status'] = $data['tumblog-status'];
}
//Hours and Mins
$original_hours = (int)$data['original-tumblog-hours'];
$original_mins = (int)$data['original-tumblog-mins'];
$original_date = strtotime($data['original-tumblog-date']);
$posted_date = strtotime($data['tumblog-date']);
$note_hours = (int)$data['tumblog-hours'];
if ($note_hours == 0) { $note_hours = 12; }
elseif ($note_hours >= 24) { $note_hours = 0; }
$note_mins = (int)$data['tumblog-mins'];
if ($note_mins == 0) { $note_mins = 0; }
elseif ($note_mins >= 60) { $note_mins = 0; }
//Convert to Y-m-d H:i:s
//if everything is unchanged
if ( ($note_hours == $original_hours) && ($note_mins == $original_mins) && ($posted_date == $original_date) ) {
$time_now_hours = date_i18n( "H" );
$time_now_mins = date_i18n( "i" );
$date_raw = date( "Y").'-'.date( "m").'-'.date( "d").' '.$time_now_hours.':'.$time_now_mins.':00';
} else {
$date_raw = date( "Y",strtotime($data['tumblog-date'])).'-'.date( "m",strtotime($data['tumblog-date'])).'-'.date( "d",strtotime($data['tumblog-date'])).' '.$note_hours.':'.$note_mins.':00';
}
$date_formatted = date($php_formatting, strtotime($date_raw));
$tumbl_note['post_date'] = $date_formatted;
// DEPRECATED
// }
$tumbl_note['post_author'] = $current_user->ID;
$tumbl_note['tags_input'] = $data['tumblog-tags'];
// DEPRECATED
//Get Category from Theme Options
/*
if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
$category_id = get_cat_ID( get_option( 'woo_images_category') );
$categories = array($category_id);
} else {
$categories = array();
}
*/
$categories = array();
$post_cat_array = $data['post_category'];
if(empty($post_cat_array))
{
//Do nothing
} else {
$N = count($post_cat_array);
for($i=0; $i < $N; $i++) {
array_push($categories, $post_cat_array[$i]);
}
}
$tumbl_note['post_category'] = $categories;
//Insert the note into the database
$post_id = wp_insert_post($tumbl_note);
//Add Custom Field Data to the Post
if ($data['image-id'] > 0) {
$my_post = array();
$my_post['ID'] = $data['image-id'];
$my_post['post_parent'] = $post_id;
//Update the post into the database
wp_update_post( $my_post );
add_post_meta($post_id, $tumblog_custom_fields['image-url'], $data['image-upload'], true);
}
else {
add_post_meta($post_id, $tumblog_custom_fields['image-url'], $data['image-url'], true);
}
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($content_method == 'post_format') {
set_post_format( $post_id, 'image' );
} else {
//update posts taxonomies
$taxonomy_data = $data['tax_input'];
if ( !empty($taxonomy_data) ) {
foreach ( $taxonomy_data as $taxonomy => $tags ) {
$taxonomy_obj = get_taxonomy($taxonomy);
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
$tags = array_filter($tags);
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
array_push($tags, $tumblog_items['images']);
}
} else {
$tags[0] = $tumblog_items['images'];
}
wp_set_post_terms( $post_id, $tags, 'tumblog' );
}
// DEPRECATED
// }
break;
case 'link':
//Create post object
$tumbl_note['post_title'] = $data['link-title'];
$tumbl_note['post_content'] = $data['tumblog-content'];
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($data['tumblog-status'] != '') {
$tumbl_note['post_status'] = $data['tumblog-status'];
}
//Hours and Mins
$original_hours = (int)$data['original-tumblog-hours'];
$original_mins = (int)$data['original-tumblog-mins'];
$original_date = strtotime($data['original-tumblog-date']);
$posted_date = strtotime($data['tumblog-date']);
$note_hours = (int)$data['tumblog-hours'];
if ($note_hours == 0) { $note_hours = 12; }
elseif ($note_hours >= 24) { $note_hours = 0; }
$note_mins = (int)$data['tumblog-mins'];
if ($note_mins == 0) { $note_mins = 0; }
elseif ($note_mins >= 60) { $note_mins = 0; }
//Convert to Y-m-d H:i:s
//if everything is unchanged
if ( ($note_hours == $original_hours) && ($note_mins == $original_mins) && ($posted_date == $original_date) ) {
$time_now_hours = date_i18n( "H" );
$time_now_mins = date_i18n( "i" );
$date_raw = date( "Y").'-'.date( "m").'-'.date( "d").' '.$time_now_hours.':'.$time_now_mins.':00';
} else {
$date_raw = date( "Y",strtotime($data['tumblog-date'])).'-'.date( "m",strtotime($data['tumblog-date'])).'-'.date( "d",strtotime($data['tumblog-date'])).' '.$note_hours.':'.$note_mins.':00';
}
$date_formatted = date($php_formatting, strtotime($date_raw));
$tumbl_note['post_date'] = $date_formatted;
// DEPRECATED
// }
$tumbl_note['post_author'] = $current_user->ID;
$tumbl_note['tags_input'] = $data['tumblog-tags'];
// DEPRECATED
//Get Category from Theme Options
/*
if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
$category_id = get_cat_ID( get_option( 'woo_links_category') );
$categories = array($category_id);
} else {
$categories = array();
}
*/
$categories = array();
$post_cat_array = $data['post_category'];
if(empty($post_cat_array))
{
//Do nothing
} else {
$N = count($post_cat_array);
for($i=0; $i < $N; $i++) {
array_push($categories, $post_cat_array[$i]);
}
}
$tumbl_note['post_category'] = $categories;
//Insert the note into the database
$post_id = wp_insert_post($tumbl_note);
//Add Custom Field Data to the Post
add_post_meta($post_id, $tumblog_custom_fields['link-url'], $data['link-url'], true);
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($content_method == 'post_format') {
set_post_format( $post_id, 'link' );
} else {
//update posts taxonomies
$taxonomy_data = $data['tax_input'];
if ( !empty($taxonomy_data) ) {
foreach ( $taxonomy_data as $taxonomy => $tags ) {
$taxonomy_obj = get_taxonomy($taxonomy);
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
$tags = array_filter($tags);
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
array_push($tags, $tumblog_items['links']);
}
} else {
$tags[0] = $tumblog_items['links'];
}
wp_set_post_terms( $post_id, $tags, 'tumblog' );
}
// DEPRECATED
// }
break;
case 'quote':
//Create post object
$tumbl_note['post_title'] = $data['quote-title'];
$tumbl_note['post_content'] = $data['tumblog-content'];
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($data['tumblog-status'] != '') {
$tumbl_note['post_status'] = $data['tumblog-status'];
}
//Hours and Mins
$original_hours = (int)$data['original-tumblog-hours'];
$original_mins = (int)$data['original-tumblog-mins'];
$original_date = strtotime($data['original-tumblog-date']);
$posted_date = strtotime($data['tumblog-date']);
$note_hours = (int)$data['tumblog-hours'];
if ($note_hours == 0) { $note_hours = 12; }
elseif ($note_hours >= 24) { $note_hours = 0; }
$note_mins = (int)$data['tumblog-mins'];
if ($note_mins == 0) { $note_mins = 0; }
elseif ($note_mins >= 60) { $note_mins = 0; }
//Convert to Y-m-d H:i:s
//if everything is unchanged
if ( ($note_hours == $original_hours) && ($note_mins == $original_mins) && ($posted_date == $original_date) ) {
$time_now_hours = date_i18n( "H" );
$time_now_mins = date_i18n( "i" );
$date_raw = date( "Y").'-'.date( "m").'-'.date( "d").' '.$time_now_hours.':'.$time_now_mins.':00';
} else {
$date_raw = date( "Y",strtotime($data['tumblog-date'])).'-'.date( "m",strtotime($data['tumblog-date'])).'-'.date( "d",strtotime($data['tumblog-date'])).' '.$note_hours.':'.$note_mins.':00';
}
$date_formatted = date($php_formatting, strtotime($date_raw));
$tumbl_note['post_date'] = $date_formatted;
// DEPRECATED
// }
$tumbl_note['post_author'] = $current_user->ID;
$tumbl_note['tags_input'] = $data['tumblog-tags'];
// DEPRECATED
//Get Category from Theme Options
/*
if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
$category_id = get_cat_ID( get_option( 'woo_quotes_category') );
$categories = array($category_id);
} else {
$categories = array();
}
*/
$categories = array();
$post_cat_array = $data['post_category'];
if(empty($post_cat_array))
{
//Do nothing
} else {
$N = count($post_cat_array);
for($i=0; $i < $N; $i++) {
array_push($categories, $post_cat_array[$i]);
}
}
$tumbl_note['post_category'] = $categories;
//Insert the note into the database
$post_id = wp_insert_post($tumbl_note);
//Add Custom Field Data to the Post
add_post_meta($post_id, $tumblog_custom_fields['quote-copy'], $data['quote-copy'], true);
add_post_meta($post_id, $tumblog_custom_fields['quote-author'], $data['quote-author'], true);
add_post_meta($post_id, $tumblog_custom_fields['quote-url'], $data['quote-url'], true);
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($content_method == 'post_format') {
set_post_format( $post_id, 'quote' );
} else {
//update posts taxonomies
$taxonomy_data = $data['tax_input'];
if ( !empty($taxonomy_data) ) {
foreach ( $taxonomy_data as $taxonomy => $tags ) {
$taxonomy_obj = get_taxonomy($taxonomy);
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
$tags = array_filter($tags);
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
array_push($tags, $tumblog_items['quotes']);
}
} else {
$tags[0] = $tumblog_items['quotes'];
}
wp_set_post_terms( $post_id, $tags, 'tumblog' );
}
// DEPRECATED
// }
break;
case 'audio':
//Create post object
$tumbl_note['post_title'] = $data['audio-title'];
$tumbl_note['post_content'] = $data['tumblog-content'];
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($data['tumblog-status'] != '') {
$tumbl_note['post_status'] = $data['tumblog-status'];
}
//Hours and Mins
$original_hours = (int)$data['original-tumblog-hours'];
$original_mins = (int)$data['original-tumblog-mins'];
$original_date = strtotime($data['original-tumblog-date']);
$posted_date = strtotime($data['tumblog-date']);
$note_hours = (int)$data['tumblog-hours'];
if ($note_hours == 0) { $note_hours = 12; }
elseif ($note_hours >= 24) { $note_hours = 0; }
$note_mins = (int)$data['tumblog-mins'];
if ($note_mins == 0) { $note_mins = 0; }
elseif ($note_mins >= 60) { $note_mins = 0; }
//Convert to Y-m-d H:i:s
//if everything is unchanged
if ( ($note_hours == $original_hours) && ($note_mins == $original_mins) && ($posted_date == $original_date) ) {
$time_now_hours = date_i18n( "H" );
$time_now_mins = date_i18n( "i" );
$date_raw = date( "Y").'-'.date( "m").'-'.date( "d").' '.$time_now_hours.':'.$time_now_mins.':00';
} else {
$date_raw = date( "Y",strtotime($data['tumblog-date'])).'-'.date( "m",strtotime($data['tumblog-date'])).'-'.date( "d",strtotime($data['tumblog-date'])).' '.$note_hours.':'.$note_mins.':00';
}
$date_formatted = date($php_formatting, strtotime($date_raw));
$tumbl_note['post_date'] = $date_formatted;
// DEPRECATED
// }
$tumbl_note['post_author'] = $current_user->ID;
$tumbl_note['tags_input'] = $data['tumblog-tags'];
// DEPRECATED
//Get Category from Theme Options
/*
if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
$category_id = get_cat_ID( get_option( 'woo_audio_category') );
$categories = array($category_id);
} else {
$categories = array();
}
*/
$categories = array();
$post_cat_array = $data['post_category'];
if(empty($post_cat_array))
{
//Do nothing
} else {
$N = count($post_cat_array);
for($i=0; $i < $N; $i++) {
array_push($categories, $post_cat_array[$i]);
}
}
$tumbl_note['post_category'] = $categories;
//Insert the note into the database
$post_id = wp_insert_post($tumbl_note);
//Add Custom Field Data to the Post
if ($data['audio-id'] > 0) {
$my_post = array();
$my_post['ID'] = $data['audio-id'];
$my_post['post_parent'] = $post_id;
//Update the post into the database
wp_update_post( $my_post );
add_post_meta($post_id, $tumblog_custom_fields['audio-url'], $data['audio-upload'], true);
}
else {
add_post_meta($post_id, $tumblog_custom_fields['audio-url'], $data['audio-url'], true);
}
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($content_method == 'post_format') {
set_post_format( $post_id, 'audio' );
} else {
//update posts taxonomies
$taxonomy_data = $data['tax_input'];
if ( !empty($taxonomy_data) ) {
foreach ( $taxonomy_data as $taxonomy => $tags ) {
$taxonomy_obj = get_taxonomy($taxonomy);
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
$tags = array_filter($tags);
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
array_push($tags, $tumblog_items['audio']);
}
} else {
$tags[0] = $tumblog_items['audio'];
}
wp_set_post_terms( $post_id, $tags, 'tumblog' );
}
// DEPRECATED
// }
break;
default:
break;
}
}
//Handles AJAX Post
function woo_tumblog_file_upload() {
global $wpdb;
//Upload overrides
$filename = $_FILES['userfile']; // [name] [tmp_name]
$override['test_form'] = false;
$override['action'] = 'wp_handle_upload';
//Handle Uploaded File
$uploaded_file = wp_handle_upload($filename, $override); // [file] [url] [type]
//Create Attachment Object
$attachment['post_title'] = $filename['name']; //post_title, post_content (the value for this key should be the empty string), post_status and post_mime_type
$attachment['post_content'] = '';
$attachment['post_status'] = 'inherit';
$attachment['post_mime_type'] = $uploaded_file['type'];
$attachment['guid'] = $uploaded_file['url'];
//Prepare file attachment
$wud = wp_upload_dir(); // [path] [url] [subdir] [basedir] [baseurl] [error]
$filename_attach = $wud['basedir'].$uploaded_file['file'];
//Insert Attachment
$attach_id = wp_insert_attachment( $attachment, $filename_attach, 0 );
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename_attach );
wp_update_attachment_metadata( $attach_id, $attach_data );
//Handle Errors and Response
if(!empty($uploaded_file['error'])) {echo 'Upload Error: ' . $uploaded_file['error']; }
else { echo $uploaded_file['url'].'|'.$attach_id.'|'; } // Is the Response
}
/*-----------------------------------------------------------------------------------*/
/* Dashboard Widget
/*-----------------------------------------------------------------------------------*/
// Tumblog Dashboard Widget Output
function woo_tumblog_dashboard_widget_output() {
//security check
if (current_user_can( 'publish_posts')) {
$tumblog_items = array( 'articles' => get_option( 'woo_articles_term_id'),
'images' => get_option( 'woo_images_term_id'),
'audio' => get_option( 'woo_audio_term_id'),
'video' => get_option( 'woo_video_term_id'),
'quotes' => get_option( 'woo_quotes_term_id'),
'links' => get_option( 'woo_links_term_id')
);
?>