Changeset 406705
- Timestamp:
- 07/08/2011 11:50:54 AM (15 years ago)
- Location:
- qqpress/trunk
- Files:
-
- 2 edited
-
qqpress.php (modified) (11 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
qqpress/trunk/qqpress.php
r387641 r406705 19 19 add_action('admin_menu', 'qc_options_add_page'); 20 20 add_action('wp_insert_post', 'qqpress_run'); 21 add_option('qqpress_message', '新日志:[title] [permalink] ', '', 'yes');21 add_option('qqpress_message', '新日志:[title] [permalink]##100', '', 'yes'); 22 22 define("MB_RETURN_FORMAT", "json"); 23 23 … … 161 161 //再次确认该日志状态为publish 162 162 if ($post->post_status == "publish") { 163 $message = qqpress_get_message($post ID); //格式化同步内容163 $message = qqpress_get_message($post, $postID); //格式化同步内容 164 164 qqpress_publish_2_qq($message); 165 165 … … 175 175 if(!class_exists('MBOpenTOAuth')) 176 176 include dirname(__FILE__).'/opent.php'; 177 177 178 178 global $qq_consumer_key, $qq_consumer_secret; 179 179 $to = new MBOpenTOAuth($qq_consumer_key, $qq_consumer_secret, $oauth_token, $oauth_token_secret); … … 200 200 //将日志转换为自定义的同步格式 201 201 function 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; 203 205 204 206 $proto = str_replace("[title]", $post->post_title, $proto); … … 206 208 $proto = str_replace("[link]", get_option('home')."?p=".$postID, $proto); 207 209 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 } 209 217 } 210 218 … … 241 249 <script type="text/javascript"> 242 250 function qc_reload(){ 243 var url =location.href;251 var url = location.href; 244 252 var temp = url.split("#"); 245 253 url = temp[0]; … … 251 259 <div class="wrap"> 252 260 <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> 256 262 <p id="qc_connect" class="qc_button"> 257 263 <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;" /> … … 265 271 global $wpdb; 266 272 $table_name = "qqpress"; 267 268 $message = get_option('qqpress_message');269 273 $submitFieldID = 'qqpress_submit_hidden'; 270 274 271 275 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); 273 278 echo '<div class="updated"><p><strong>更新成功</strong></p></div>'; 274 279 } … … 294 299 } 295 300 }); 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 } 297 311 298 312 function disable_button() { 299 313 jQuery("#qqpress_tweet").attr("disabled", "disabled"); 300 314 } 301 315 302 316 function show_message(data) { 303 317 jQuery("#qqpress_result").html("发布成功。<a href='http://t.qq.com/p/t/"+data+"' target='_blank'>查看</a>").css("color", "red"); … … 311 325 <textarea id="qqpress_tweet_content" name="qqpress_tweet_content" rows="2" cols="80" />#半醒WP微博同步#</textarea><br /> 312 326 <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 ?> 314 332 <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()"> 316 334 <input type="hidden" name="qqpress_submit_hidden" value="Y" /> 317 335 <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="保存修改" /> 319 340 </form></p> 320 341 <p>同步内容支持以下格式: … … 383 404 return $onlineip; 384 405 } 406 407 //汉字截断 408 function 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 5 5 Requires at least: 3.0 6 6 Tested up to: 3.1.1 7 Stable tag: 1. 37 Stable tag: 1.4 8 8 9 支持将新日志标题和链接同步到腾讯微博 。9 支持将新日志标题和链接同步到腾讯微博,同时支持自定义文章内容预览长度。 10 10 11 11 == Description == 12 发布日志时同步一条该日志标题和链接到腾讯微博 。12 发布日志时同步一条该日志标题和链接到腾讯微博,并可指定文章内容预览字数。 13 13 支持自定义消息前缀。 14 14 腾讯微博OAuth授权。 … … 26 26 27 27 如果你在腾讯微博应用中取消对该应用的授权,请先登陆后台禁用该插件,然后在重启启用插件并在设置中进行插件配置。 28 或者邮件联系:[email protected] 28 29 29 30 = 出现类似于 Call to undefined function curl_init() in …… = … … 32 33 33 34 == Changelog == 35 = 1.4 = 36 * 2011/07/08 37 * 增加文章内容同步功能,自定义内容预览长度(最长为110)。 38 34 39 = 1.3 = 35 40 * 2011/05/16
Note: See TracChangeset
for help on using the changeset viewer.