Plugin Directory

Changeset 406705


Ignore:
Timestamp:
07/08/2011 11:50:54 AM (15 years ago)
Author:
cooiky
Message:

post preview

Location:
qqpress/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • qqpress/trunk/qqpress.php

    r387641 r406705  
    1919add_action('admin_menu', 'qc_options_add_page');
    2020add_action('wp_insert_post', 'qqpress_run');
    21 add_option('qqpress_message', '新日志:[title] [permalink]', '', 'yes');
     21add_option('qqpress_message', '新日志:[title] [permalink]##100', '', 'yes');
    2222define("MB_RETURN_FORMAT", "json");
    2323
     
    161161    //再次确认该日志状态为publish
    162162    if ($post->post_status == "publish") {
    163         $message = qqpress_get_message($postID); //格式化同步内容
     163        $message = qqpress_get_message($post, $postID); //格式化同步内容
    164164        qqpress_publish_2_qq($message);
    165165       
     
    175175            if(!class_exists('MBOpenTOAuth'))
    176176                include dirname(__FILE__).'/opent.php';
    177 
     177           
    178178            global $qq_consumer_key, $qq_consumer_secret;
    179179            $to = new MBOpenTOAuth($qq_consumer_key, $qq_consumer_secret, $oauth_token, $oauth_token_secret);
     
    200200//将日志转换为自定义的同步格式
    201201function qqpress_get_message($post, $postID) {
    202     $proto = get_option('qqpress_message');
     202    $message = get_option('qqpress_message');
     203    list($proto, $length) = explode("##", $message);
     204    $length = $length == 0 ? 100 : $length;
    203205
    204206    $proto = str_replace("[title]", $post->post_title, $proto);
     
    206208    $proto = str_replace("[link]", get_option('home')."?p=".$postID, $proto);
    207209
    208     return $proto;
     210    if (0 == $length)
     211        return $proto;
     212    else {
     213        $length = $length > 110 ? 100 : $length;
     214        $content = getstr($post->post_content, $length, $encoding  = 'utf-8'); //文章内容预览
     215        return $proto.$content."...";
     216    }
    209217}
    210218
     
    241249    <script type="text/javascript">
    242250    function qc_reload(){
    243        var url=location.href;
     251       var url = location.href;
    244252       var temp = url.split("#");
    245253       url = temp[0];
     
    251259    <div class="wrap">
    252260        <h2>腾讯微博同步授权</h2>
    253         <style type="text/css">
    254             .qc_button img{border:none;}
    255         </style>
     261        <style type="text/css">.qc_button img{border:none;}</style>
    256262        <p id="qc_connect" class="qc_button">
    257263        <img onclick='window.open("<?php echo $qc_url; ?>/qq-start.php","","width=800,height=600,left=150,top=100,qcrollbar=no,resize=no");return false;' src="<?php echo $qc_url; ?>/qq_button.png" alt="使用腾讯微博登陆" style="cursor: pointer; margin-right: 20px;" />
     
    265271    global $wpdb;
    266272    $table_name = "qqpress";
    267 
    268     $message = get_option('qqpress_message');
    269273    $submitFieldID = 'qqpress_submit_hidden';
    270274   
    271275    if ($_POST[$submitFieldID] == 'Y') {
    272         update_option('qqpress_message', $_POST['qqpress_form_message']);
     276        $message = $_POST['qqpress_form_message']."##".$_POST['qqpress_form_content'];
     277        update_option('qqpress_message', $message);
    273278        echo '<div class="updated"><p><strong>更新成功</strong></p></div>';
    274279    }
     
    294299            }
    295300        });
    296     })
     301    });
     302
     303    function checkForm() {
     304        var length = jQuery.trim(jQuery("#qqpress_form_content").val());
     305        if (!/^[0-9]{1,3}$/.test(length)) {
     306            alert("长度别太长哦");
     307            return false;
     308        }
     309        return true;
     310    }
    297311   
    298312    function disable_button() {
    299313        jQuery("#qqpress_tweet").attr("disabled", "disabled");
    300314    }
    301 
     315   
    302316    function show_message(data) {
    303317        jQuery("#qqpress_result").html("发布成功。<a href='http://t.qq.com/p/t/"+data+"' target='_blank'>查看</a>").css("color", "red");
     
    311325            <textarea id="qqpress_tweet_content" name="qqpress_tweet_content" rows="2" cols="80" />#半醒WP微博同步#</textarea><br />
    312326            <input type="button" id="qqpress_tweet" name="qqpress_tweet_button" value=" 广 播 " class="button" /><span id="qqpress_result"></span><br /><br />
    313            
     327            <?php
     328                $data = get_option('qqpress_message');
     329                list($message, $length) = explode("##", $data);
     330                $length = $length!="" ? $length : 0;
     331            ?>
    314332            <h3>腾讯微博同步格式</h3>
    315             <p><form name="qqpress_form" method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
     333            <p><form name="qqpress_form" method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>" onsubmit="return checkForm()">
    316334                <input type="hidden" name="qqpress_submit_hidden" value="Y" />
    317335                <label for="qqpress_form_message">同步内容格式:</label>
    318                 <input type="text" size="64" class="regular-text" id="qqpress_form_message" name="qqpress_form_message" value="<?php echo (get_option('qqpress_message')); ?>" /><input type="submit" name="Submit" class="button" value="保存修改" />
     336                <input type="text" size="64" class="regular-text" id="qqpress_form_message" name="qqpress_form_message" value="<?php echo $message; ?>" />
     337                <label for="qqpress_form_content">文章预览长度:</label>
     338                <input type="text" size="64" maxlength="3" class="regular-text" id="qqpress_form_content" name="qqpress_form_content" value="<?php echo $length; ?>" />
     339                <input type="submit" name="Submit" class="button" value="保存修改" />
    319340            </form></p>
    320341            <p>同步内容支持以下格式:
     
    383404    return $onlineip;
    384405}
     406
     407//汉字截断
     408function getstr($string, $length, $encoding  = 'utf-8') {
     409    $string = trim($string);
     410   
     411    if ($length && strlen($string) > $length) {
     412        //截断字符   
     413        $wordscut = '';   
     414        if (strtolower($encoding) == 'utf-8') {
     415            //utf8编码   
     416            $n = 0;
     417            $tn = 0;
     418            $noc = 0;
     419            while ($n < strlen($string)) {
     420                $t = ord($string[$n]);
     421                if ($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
     422                    $tn = 1;
     423                    $n++;
     424                    $noc++;
     425                } elseif (194 <= $t && $t <= 223) {
     426                    $tn = 2;
     427                    $n += 2;
     428                    $noc += 2;
     429                } elseif (224 <= $t && $t < 239) {
     430                    $tn = 3;
     431                    $n += 3;
     432                    $noc += 2;
     433                } elseif (240 <= $t && $t <= 247) {
     434                    $tn = 4;
     435                    $n += 4;
     436                    $noc += 2;
     437                } elseif (248 <= $t && $t <= 251) {
     438                    $tn = 5;
     439                    $n += 5;
     440                    $noc += 2;
     441                } elseif ($t == 252 || $t == 253) {
     442                    $tn = 6;
     443                    $n += 6;
     444                    $noc += 2;
     445                } else
     446                    $n++;
     447               
     448                if ($noc >= $length)
     449                    break;
     450            }
     451
     452            if ($noc > $length)
     453                $n -= $tn;
     454           
     455            $wordscut = substr($string, 0, $n);
     456        } else {
     457            for($i = 0; $i < $length - 1; $i++) {
     458                if (ord($string[$i]) > 127) {
     459                    $wordscut .= $string[$i].$string[$i + 1];
     460                    $i++;
     461                } else
     462                    $wordscut .= $string[$i];
     463            }
     464        }
     465        $string = $wordscut;
     466    }
     467    return trim($string);
     468}
  • qqpress/trunk/readme.txt

    r385435 r406705  
    55Requires at least: 3.0
    66Tested up to: 3.1.1
    7 Stable tag: 1.3
     7Stable tag: 1.4
    88
    9 支持将新日志标题和链接同步到腾讯微博
     9支持将新日志标题和链接同步到腾讯微博,同时支持自定义文章内容预览长度
    1010
    1111== Description ==
    12 发布日志时同步一条该日志标题和链接到腾讯微博
     12发布日志时同步一条该日志标题和链接到腾讯微博,并可指定文章内容预览字数
    1313支持自定义消息前缀。
    1414腾讯微博OAuth授权。
     
    2626
    2727如果你在腾讯微博应用中取消对该应用的授权,请先登陆后台禁用该插件,然后在重启启用插件并在设置中进行插件配置。
     28或者邮件联系:[email protected]
    2829
    2930= 出现类似于 Call to undefined function curl_init() in …… =
     
    3233
    3334== Changelog ==
     35= 1.4 =
     36* 2011/07/08
     37* 增加文章内容同步功能,自定义内容预览长度(最长为110)。
     38
    3439= 1.3 =
    3540* 2011/05/16
Note: See TracChangeset for help on using the changeset viewer.