随遇而安

2009年1月5日 抱歉,此文章并无中文版本。

归类于: 网站纪事与消息 — ghorse@16:15

2008年9月13日 在Nextgen Gallery加入photo2post功能

归类于: 网站纪事与消息 — ghorse@15:59

photo2post是在nextgen gallery的图集->管理图集->编辑的版面增加了“Photo to Post”。意思是对选中的图片自动转为独立的帖子,并张Nextgen gallery图片资料自动转到帖子上,转移的资料包括:标题,描述,标签。帖子会安排在12小时后开始每12小时发报一个。这样对做图博很方便。修改的地方都在Nexggen gallery下的manage.php档如下:

在nggallery_admin_manage_gallery()加入下列源码:
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\’} )” >点击观看EXIF数据。’;
// 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;

在nggallery_manage_gallery_main()加入下列源码:
<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>

文件要以UTF-8来存储,这样中文字符才有效。

以上资料只供参考,改动你网站的源码前请三思,一切后果和风险自负。

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.

Live and Relax Copyright gHorse