photo2post is to automatically post the selected pictures in a gallery to wordpress posts. Each picture will corresponding to 1 post using [SinglePic not found] and post tile will be picture title, picture description will be post content before the [SinglePic not found], picture tags will become post tags and post category will be in photoblog. The post date will be scheduled at 12hours between sucessive posts and starts from 12 hours from this fuction is performed. This would make regular bi-daily posting of image from the Nextgen gallery much easier. I could treat the Nextgen gallery as the center for entering all information and this could be transfered to by post automaticaly.
Modification to manage.php:
Inside the function nggallery_admin_manage_gallery(), add the follow lines of code to add the “Photo to Post” functionality:
case 9:
// refer to begining of file for reference of $post
$post_status = ‘open’;
$post_author = 1;
$post_category = array(6); //check and adjust for the post category ID for post created
$post_content = ”;
$post_status = ‘publish’;
$post_title = ”;
$post_type = ‘post’;
$tags_input = array(‘x1′,’x2′);
$nggTags = new ngg_Tags();
$time_difference = get_option(‘gmt_offset’) * 3600;
if ( is_array($_POST['doaction']) ) {
$post_count = 1;
foreach ( $_POST['doaction'] as $imageID ) {
$post_title = $wpdb->get_var(“SELECT alttext FROM $wpdb->nggpictures WHERE pid = ‘$imageID’ “);
$post_content = $wpdb->get_var(“SELECT description FROM $wpdb->nggpictures WHERE pid = ‘$imageID’ “);
$picture_tags = $nggTags->get_tags_from_image($imageID);
$tags_input = explode(“,”, $picture_tags);
$post_content .= ‘<p>[SinglePic not found]</p><a class=”highslide” href=”http://ghorse.org/wordpress/wp-content/plugins/nextgen-gallery/admin/showmeta.php?id=’.$imageID.’” onclick=”return hs.htmlExpand(this, {objectType: \’iframe\’, wrapperClassName: \’exif\’} )” >Click here to view EXIF data.’;
// copied from wp-mail.php/
$ddate_U = time(); //get current unit time stamp add by KF
$ddate_U = $ddate_U + ($post_count*12*3600); //set post 12 hours apart starting 12 hours from now
$post_count = $post_count+1;
$post_date = gmdate(‘Y-m-d H:i:s’, $ddate_U + $time_difference);
$post_date_gmt = gmdate(‘Y-m-d H:i:s’, $ddate_U);
// copied from wp-mail.php/
$p2post = compact(‘post_content’,'post_title’,'post_date’,'post_date_gmt’,'post_author’,'post_category’,'post_status’,'post_type’,'tags_input’);
$post_ID = wp_insert_post($p2post);
if ( is_wp_error( $post_ID ) ) echo “\n” . $post_ID->get_error_message();
}
}
nggallery::show_message(__(‘Photo to Post finished’,”nggallery”));
break;
Inside the function nggallery_manage_gallery_main(), add the option to do “Photo to Post”:
<option value=”1″ ><?php _e(“Set watermark”,’nggallery’)?></option>
<option value=”2″ ><?php _e(“Create new thumbnails”,’nggallery’)?></option>
<option value=”3″ ><?php _e(“Resize images”,’nggallery’)?></option>
<option value=”4″ ><?php _e(“Delete images”,’nggallery’)?></option>
<option value=”8″ ><?php _e(“Import metadata”,’nggallery’)?></option>
<option value=”9″ ><?php _e(“Photo to Post”,’nggallery’)?></option>
Notes : For chinese character to word, the manage.php file need to be save in UTF-8 code instead of ANSI code.
Disclaimer: I post out the code here for reference only. If you follow the information here to do any changes to you wordpress and nextgen gallery code, you are on you own and own risk. Make backup to all you database and website. Perform your test on a seperately website than your normal working website.
Sep 11 Some information for my own reference:
nextgen gallery mysql information:
wp_ngg_pictures -> pid, description, alttext
wp_ngg_pic2tags-> picid, tagid
wp_ngg_tags-> id, name, slug
pid=picid, tagid=id, alttext is title
wordpress already have a comprehesive structure to insert a post so there should be no need to dig into the wp database structure:
$post_ID = wp_insert_post($post_data);
$post = array(
‘comment_status’ => [ 'closed' | 'open' ] // ‘closed’ means no comments.
‘ID’ => [ <post id> ] //Are you updating an existing post?
‘menu_order’ => [ <order> ] //If new post is a page, sets the order should it appear in the tabs.
‘page_template => [ <template file> ] //Sets the template for the page.
‘post_author’ => [ <user ID> ] //The user ID number of the author.
‘post_category => [ array(<category id>, <...>) ] //Add some categories.
‘post_content’ => [ <the text of the post> ] //The full text of the post.
‘post_date’ => [ Y-m-d H:i:s ] //The time post was made.
‘post_date_gmt’ => [ Y-m-d H:i:s ] //The time post was made, in GMT.
‘post_excerpt’ => [ <an excerpt> ] //For all your post excerpt needs.
‘post_status’ => [ 'draft' | 'publish' | 'pending' ] //Set the status of the new post.
‘post_title’ => [ <the title> ] //The title of your post.
‘post_type’ => [ 'post' | 'page' ] //Sometimes you want to post a page.
‘tags_input’ => [ '<tag>, <tag>, <...>' ] //For tags.
‘post_parent’ => [ <post ID> ] //Sets the parent of the new post.
‘post_password’ => [ ? ] //password for post?
‘to_ping’ => [ ? ] //?
‘ping_status’ => [ ? ] //Ping status?
‘pinged’ => [ ? ] //?
);
Nextgen gallery ./admin/wp25 is where is file actually used with wp26. The manage.php is the file I need to modify so that photo2post can be added.