ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์CMS & Free Scriptใช้ plugin wp post to smf แล้วใน smf ขึ้น ????? ครับ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ใช้ plugin wp post to smf แล้วใน smf ขึ้น ????? ครับ  (อ่าน 1580 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
bubbleball
Administrator
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 444
ออฟไลน์ ออฟไลน์

กระทู้: 5,695



ดูรายละเอียด
« เมื่อ: 29 ตุลาคม 2010, 15:15:41 »

ใช้ plugin ชื่อ Post to SimpleMachines Forum SMF  โพสต์ไปบอร์ด smf แล้วภาษาไทยมันขึ้น ??   Tongue

ลองใส่ header ("Content-type: text/html; charset=utf-8");  ก็ยังไม่สำเร็จ  
บอร์ดผมใช้ smf 1.1.11 ภาษาไทย utf-8

ใครพอทราบสาเหตุขอแนวทางหน่อยครับ  ขอบคุณครับผม

โค๊ด:
<?php
/*
Plugin Name: Post to SimpleMachines Forum SMF 
Plugin URI: http://www.zonca.org/wordpress-post-to-smf
Description: Automatically posts each new wordpress post to a SMF board 
Version: 1.5
Author: Zonca Webdesign
Author URI: http://www.zonca.org
*/
// paths to forum

$post_to_smf_db_version "1.0";

function 
post_to_smf_install () {
   global 
$wpdb;
   global 
$post_to_smf_db_version;

   
$table_name $wpdb->prefix "post_to_smf";
   if(
$wpdb->get_var("show tables like &#39;$table_name&#39;") != $table_name) {
      
      
$sql "CREATE TABLE " $table_name " (
      id mediumint(9) NOT NULL AUTO_INCREMENT,
      wp_id bigint(11) NOT NULL,
      smf_topic_id bigint(11) NOT NULL,
      smf_msg_id bigint(11) NOT NULL,
      UNIQUE KEY id (id)
    );"
;
     require_once(
ABSPATH . &#39;wp-admin/includes/upgrade.php&#39;);
      
dbDelta($sql);


      
add_option("post_to_smf_db_version"$post_to_smf_db_version);

   }
}

function 
post_to_smf_catexcluded($postid) {
   
$postcats get_the_category($postid);
   
$excludedcats explode(",",get_option( &#39;post_to_smf_excludecats&#39; )); 
   
foreach($postcats as $category) {     
    
$catid=$category->cat_ID;
     if (
in_array($catid,$excludedcats)) return true;
   } 
 return 
false;
 }

function 
post_to_smf($post_ID) {
    global 
$wpdb;
$smfpath get_option(&#39;post_to_smf_smfpath&#39;);
    
$post get_post($post_ID); 
  if (!
file_exists($smfpath . &#39;/SSI.php&#39;)) {return $post->post_content;}

  
$props get_post_custom($id);

    require_once(
"$smfpath/SSI.php");
    require_once(
"$smfpath/Sources/Subs-Post.php");
    
$table_name $wpdb->prefix "post_to_smf";
    if (
get_option(&#39;post_to_smf_excerpt_length&#39;)==&#39;&#39;) {
        
$max_length 0;
    } else {
        
$max_length get_option(&#39;post_to_smf_excerpt_length&#39;);
    
}

  
$ID_BOARD=$props[&#39;forum&#39;][0];
  
if ($ID_BOARD == &#39;&#39;) {
    
$ID_BOARD get_option(&#39;post_to_smf_defforum&#39;); // id of the board to post to
  
}
  if ((
$ID_BOARD)&&($ID_BOARD!=&#39;0&#39;)&&($post->post_status==&#39;publish&#39;)&& (!post_to_smf_catexcluded($post_ID))) {

    
$subject $wpdb->escape($post->post_title);

 if (empty(
$post->post_excerpt)) {
     if (
$max_length>0){
        
$excerpt $post->post_content;
        
$excerpt trim(strip_tags($excerpt));
        
str_replace("—""-"$excerpt);

        
$words preg_split("/(?<=(\.|!|\?)+)\s/"$excerpt, -1PREG_SPLIT_NO_EMPTY);

        foreach ( 
$words as $word )
        {
            
$new_text $text substr($excerpt0strpos($excerpt$word) + strlen($word));
            
$excerpt substr($excerptstrpos($excerpt$word) + strlen($word), strlen($excerpt));

            if ( ( 
strlen($text) != ) && ( strlen($new_text) > $max_length ) )
            {
                break;
            }

            
$text $new_text;
        }
        
$post->post_excerpt $text;
     } else {
        
$post->post_excerpt $post->post_content;
     }
 }
    
    
$output $wpdb->escape($post->post_excerpt "<br /><a href=\"" .  get_permalink($post->ID) . "\">" get_option(&#39;post_to_smf_msgtext&#39;) . "</a>");
    
$ID_MEMBER get_option(&#39;post_to_smf_username&#39;); // id of the user
    // Collect all necessary parameters for the creation of the post.
    
$msgOptions = array(
       &
#39;id&#39; =>  0,
       
&#39;subject&#39; => $subject,
       
&#39;body&#39; => $output,
       
&#39;smileys_enabled&#39; => true,
    
);
    
    
$topicOptions = array(
       &
#39;id&#39; => 0,
       
&#39;board&#39; => $ID_BOARD,
       
&#39;mark_as_read&#39; => true,
    
);
    
    
$posterOptions = array(
       &
#39;id&#39; => $ID_MEMBER,
    
);
    
    
// check if post already exists
    
if ($wpdb->get_row("SELECT * FROM $table_name WHERE wp_id = $post_ID")) {

        
//exist, update post
        
$row $wpdb->get_row("SELECT * FROM $table_name WHERE wp_id = $post_ID");

        
$topicOptions[&#39;id&#39;] = $row->smf_topic_id;
        
$msgOptions[&#39;id&#39;] = $row->smf_msg_id;

        
modifyPost($msgOptions$topicOptions$posterOptions);

    } else { 
//doesn&#39;t exist create a new post

      
createPost($msgOptions$topicOptions$posterOptions);

      
$insert "INSERT INTO " $table_name .
              
" (wp_id, smf_topic_id, smf_msg_id) " .
              
"VALUES (&#39;" $post_ID "&#39;,&#39;" $topicOptions[&#39;id&#39;] . "&#39;,&#39;" . $msgOptions[&#39;id&#39;] . "&#39;)";
      
$results $wpdb->query$insert );
   
    }
    }

    return 
$post_ID;

}

function 
post_to_smf_link($link_text) {
    global 
$post;
    global 
$wpdb;
    
$post_ID $post->ID;
    
$table_name $wpdb->prefix "post_to_smf";
    if (
$wpdb->get_row("SELECT * FROM $table_name WHERE wp_id = $post_ID")) {
        
//exist, update post
        
$row $wpdb->get_row("SELECT * FROM $table_name WHERE wp_id = $post_ID");
        
$topic $row->smf_topic_id;
        
$forumurl get_option(&#39;post_to_smf_smfurl&#39;);

        
echo "<a href=\"$forumurl/index.php?topic=$topic.0\">$link_text</a>";
    }
    return 
true;
}
    
add_action(&#39;publish_post&#39;, &#39;post_to_smf&#39;);
register_activation_hook(__FILE__,&#39;post_to_smf_install&#39;);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ADMIN PAGE

 
function post_to_smf_admin() {
   
add_options_page(&#39;post_to_smf Configuration&#39;, &#39;post_to_smf&#39;, 8, &#39;post_to_smf.php&#39;, &#39;post_to_smf_options&#39;);
 
}

 function 
post_to_smf_options() {

  
// variables for the field and option names 

  
$hidden_field_name = &#39;mt_submit_hidden&#39;;

  
$opt_smfpath = &#39;post_to_smf_smfpath&#39;;
  
$opt_smfurl = &#39;post_to_smf_smfurl&#39;;
  
$opt_defforum  = &#39;post_to_smf_defforum&#39;;
  
$opt_username= &#39;post_to_smf_username&#39;;
  
$opt_msgtext  = &#39;post_to_smf_msgtext&#39;;
  
$opt_comments0 = &#39;post_to_smf_comments0&#39;;
  
$opt_comments1 = &#39;post_to_smf_comments1&#39;;
  
$opt_commentsx = &#39;post_to_smf_commentsx&#39;;
  
$opt_reply  = &#39;post_to_smf_reply&#39;;
  
$opt_onthefly = &#39;post_to_smf_onthefly&#39;;
  
$opt_excludecats = &#39;post_to_smf_excludecats&#39; ;
  
$opt_excerpt_length = &#39;post_to_smf_excerpt_length&#39; ;

  // Read in existing option value from database

  
$opt_smfpath_val get_option$opt_smfpath );
  
$opt_smfurl_val     get_option$opt_smfurl);
  
$opt_defforum_val  get_option$opt_defforum );
  
$opt_username_val get_option$opt_username );
  
$opt_msgtext_val get_option$opt_msgtext);
  
$opt_comments0_val get_option$opt_comments0);
  
$opt_comments1_val get_option$opt_comments1);
  
$opt_commentsx_val get_option$opt_commentsx);
  
$opt_reply_val get_option$opt_reply);
  
$opt_onthefly_val get_option$opt_onthefly);
  
$opt_excludecats_val get_option$opt_excludecats);
  
$opt_excerpt_length_val get_option$opt_excerpt_length);

  if( 
$_POST$hidden_field_name ] == &#39;Y&#39; ) {

    
$opt_smfpath_val $_POST$opt_smfpath];
    
$opt_smfurl_val     $_POST$opt_smfurl];
    
$opt_defforum_val  $_POST$opt_defforum];
    
$opt_username_val $_POST$opt_username];
    
$opt_msgtext_val $_POST$opt_msgtext];
    
$opt_comments0_val $_POST$opt_comments0];
    
$opt_comments1_val $_POST$opt_comments1];
    
$opt_commentsx_val $_POST$opt_commentsx];
    
$opt_reply_val $_POST$opt_reply];
    
$opt_onthefly_val $_POST$opt_onthefly];
    
$opt_excludecats_val $_POST$opt_excludecats];
    
$opt_excerpt_length_val $_POST$opt_excerpt_length];

    
$opt_msgtext_val str_replace(&#39;\"&#39;,&#39;"&#39;,$opt_msgtext_val);
    
$opt_msgtext_val str_replace("\&#39;","&#39;",$opt_msgtext_val);
    
$opt_msgtext_val str_replace(&#39;\\\\&#39;,&#39;\\&#39;,$opt_msgtext_val);

    
$opt_comments0_val str_replace(&#39;\"&#39;,&#39;"&#39;,$opt_comments0_val);
    
$opt_comments0_val str_replace("\&#39;","&#39;",$opt_comments0_val);
    
$opt_comments0_val str_replace(&#39;\\\\&#39;,&#39;\\&#39;,$opt_comments0_val);

    
$opt_comments1_val str_replace(&#39;\"&#39;,&#39;"&#39;,$opt_comments1_val);
    
$opt_comments1_val str_replace("\&#39;","&#39;",$opt_comments1_val);
    
$opt_comments1_val str_replace(&#39;\\\\&#39;,&#39;\\&#39;,$opt_comments1_val);

    
$opt_commentsx_val str_replace(&#39;\"&#39;,&#39;"&#39;,$opt_commentsx_val);
    
$opt_commentsx_val str_replace("\&#39;","&#39;",$opt_commentsx_val);
    
$opt_commentsx_val str_replace(&#39;\\\\&#39;,&#39;\\&#39;,$opt_commentsx_val);

    
$opt_reply_val str_replace(&#39;\"&#39;,&#39;"&#39;,$opt_reply_val);
    
$opt_reply_val str_replace("\&#39;","&#39;",$opt_reply_val);
    
$opt_reply_val str_replace(&#39;\\\\&#39;,&#39;\\&#39;,$opt_reply_val);

    
update_option$opt_smfpath$opt_smfpath_val );
    
update_option$opt_smfurl$opt_smfurl_val );
    
update_option$opt_defforum$opt_defforum_val );
    
update_option$opt_username$opt_username_val );
    
update_option$opt_msgtext$opt_msgtext_val );
    
update_option$opt_comments0$opt_comments0_val );
    
update_option$opt_comments1$opt_comments1_val );
    
update_option$opt_commentsx$opt_commentsx_val );
    
update_option$opt_reply$opt_reply_val );
    
update_option$opt_onthefly$opt_onthefly_val );
    
update_option$opt_excludecats$opt_excludecats_val );
    
update_option$opt_excerpt_length$opt_excerpt_length_val );

  
?>


  <div class="updated"><p><strong><?php _e(&#39;Options saved.&#39;, &#39;mt_trans_domain&#39; ); ?></strong></p></div>
  <?php }
     echo &
#39;<div class="wrap">&#39;;    
     
echo "<h2>" __( &#39;post_to_smf Plugin Options&#39;, &#39;mt_trans_domain&#39; ) . "</h2>";
     
echo &#39;<a href="http://www.zonca.org/wp-post-to-smf">post_to_smf</a> by <a href="http://www.zonca.org">Zonca Webdesign</a>&#39;;

    
if (!file_exists($opt_smfpath_val . &#39;/SSI.php&#39;)) {
      
echo &#39;<div style="border:5px solid #aa0000; background:#feeeee; margin:0px;margin-top:10px; padding:4px;clear:both;"><p>&#39;;
      
echo &#39;&nbsp;&nbsp;<b>smf not found!</b> Please set smf local path before creating or updating posts</p></div>&#39;;
    
}

  
?>


  <!-- Here is the form -->    
  <form name="form1" method="post"
   action="<?php echo str_replace( &#39;%7E&#39;, &#39;~&#39;, $_SERVER[&#39;REQUEST_URI&#39;]); ?>">
  <input type="hidden" name="<?php echo $hidden_field_name?>" value="Y">

  <table class="form-table">

  <tr valign="top">
    <th scope="row"><label><?php _e("smf local path:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><input type="text" name="post_to_smf_smfpath" value="<?php echo $opt_smfpath_val?>" size="60">
    <?php 
        
if (file_exists($opt_smfpath_val . &#39;/SSI.php&#39;)) echo (&#39;<br/>smf found&#39;); 
        
else echo (&#39;<br><strong>smf NOT FOUND!</strong>&#39;);
     
?>

    </td>
    <td>Local path of your smf installation<br/>(probably <?php
          $wpl
=substr(__FILE__,0,stripos(__FILE__, &#39;/wp-content&#39;));
          
$bblsubstr($wpl,0,stripos($wpl,strrchr($wpl,&#39;/&#39;))) . &#39;<em>/myforum</em>&#39;;
          
echo (&#39;<strong>&#39; . $bbl . &#39;</strong>&#39;); 
         
?>
)</td>
  </tr>

  <tr valign="top">
    <th scope="row"><label><?php _e("smf forum URL:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><input type="text" name="post_to_smf_smfurl" value="<?php echo $opt_smfurl_val?>" size="60"></td>
    <td>Public URL of your forum<br/>(i.e. "http://www.mydomain.com/myforum")</td>
  </tr>

  <tr valign="top">
    <th scope="row"><label><?php _e("Default forum for posts:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><input type="text" name="post_to_smf_defforum" value="<?php echo $opt_defforum_val?>" size="60"></td>
    <td>Numeric ID of the smf forum where topics for new posts will be created (if none specified in the 'forum' custom field of the WP post). If blank, no topics will be created unless 'forum' custom field of the post is set</td>
  </tr>

<!--  <tr valign="top">
    <th scope="row"><label><?php _e("Exclude categories", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><input type="text" name="post_to_smf_excludecats" value="<?php echo $opt_excludecats_val;?>" size="60"></td>
    <td>Comma separated list of Wordpress categories ID's to be excluded. Any post in this categories will not have correspondent messages in the forum</td>
  </tr>
  --!>

  <tr valign="top">
    <th scope="row"><label><?php _e("Forum user ID:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><input type="text" name="post_to_smf_username" value="<?php echo $opt_username_val;?>" size="60"></td>
    <td>ID of the smf existing user used for creating new topics (i.e. 1 should be your admin account)</td>
  </tr>

  <tr valign="top">
    <th scope="row"><label><?php _e("Topic message text for posts:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><textarea id="details" name="post_to_smf_msgtext" rows="5" cols="60"><?php echo $opt_msgtext_val;?></textarea></td>
    <td>Message text for the link at the end of the forum post which links to the wordpress post, it should be something like "Read the full article"</td>
  </tr>

  <tr valign="top">
    <th scope="row"><label><?php _e("Maximum number of characters in the forum post:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><input type="text" name="post_to_smf_excerpt_length" value="<?php echo $opt_excerpt_length_val;?>" size="60"></td>
    <td>Maximum number of characters used in the forum post (using the {$post} variable, leave blank to have the full wordpress post in the forum. The plugin tries automatically to stop after a full sentence.</td>
  </tr>

<!--  <tr valign="top">
    <th scope="row"><label><?php _e("&#39;0 messages in the forum&#39; text:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><textarea id="comments0" name="post_to_smf_comments0" rows="3" cols="60"><?php echo $opt_comments0_val;?></textarea></td>
    <td>Text displayed when there are no comments in the forum for the post</tr>

  <tr valign="top">
    <th scope="row"><label><?php _e("&#39;1 message in the forum&#39; text:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><textarea id="comments1" name="post_to_smf_comments1" rows="3" cols="60"><?php echo $opt_comments1_val;?></textarea></td>
    <td>Text displayed when there is 1 comment in the forum for the post</tr>

  <tr valign="top">
    <th scope="row"><label><?php _e("&#39;x messages in the forum&#39; text:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><textarea id="commentsx" name="post_to_smf_commentsx" rows="3" cols="60"><?php echo $opt_commentsx_val;?></textarea></td>
    <td>Text displayed when there is more than 1 comments in the forum for the post<br/>
     Some text replacement keywords can be used:<br/>
    {$x} Actual number of messages in the forum</tr>
--!>
<!--
  <tr valign="top">
    <th scope="row"><label><?php _e("&#39;Add a message in the forum&#39; text:", &#39;mt_trans_domain&#39; ); ?></label></th>
    <td><textarea id="textreply" name="post_to_smf_reply" rows="3" cols="60"><?php echo $opt_reply_val;?></textarea></td>
    <td>Text displayed in the 'add a reply in the forum' quick link</tr>
--!>


  </table>

  <p class="submit">
    <input type="submit" name="Submit" value="<?php _e(&#39;Update Options&#39;, &#39;mt_trans_domain&#39; ); ?>" />
  </p>

  </form>
  </div>

<?php 


 
add_action(&#39;admin_menu&#39;,   &#39;post_to_smf_admin&#39;);

?>

« แก้ไขครั้งสุดท้าย: 29 ตุลาคม 2010, 15:16:20 โดย bubbleball » บันทึกการเข้า

กลุ่มซื้อขายบริการเกี่ยวกับ SEO อื่นๆ โดยตรง
SEO MARKET THAILAND

สงสัยติดต่ออะไรไปทักหาที่ Fair Thailand (ไม่ค่อยอ่านกล่องข้อความที่นี่)

Fair Market Thailand   กลุ่มค้าขายรวมอื่นๆ ในภายหลัง


ปลาทอง
ลายเซนต์สูงไม่เกิน 250px
kisschy
ก๊วนเสียว
*

พลังน้ำใจ: 36
ออฟไลน์ ออฟไลน์

กระทู้: 407



ดูรายละเอียด
« ตอบ #1 เมื่อ: 30 ตุลาคม 2010, 11:22:29 »


ปัญหามันเป็นเรื่องของ Encoding แหละครับผมว่า
ลองดูตารางและฟิลด์ที่เกี่ยวข้องกับหัวข้อเช่นตาราง messages, topic พวกนี้ว่า encoding มันเป็น UTF8 แล้วหรือยัง
แล้วก็ลองตรวจสอบดูฝั่งของ WP ด้วยครับ
บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์