遨游死神文章列表

[全新接口]WordPress 新文章带图片同步微博

add_action('publish_post', 'new_post_weibo', 1);
function new_post_weibo($post_ID, $debug = false) {
        global $post;
        if (!wp_is_post_revision($post_ID) && $post->post_status != "publish" || $debug == true){
                if (isset($post) && $post->post_type != "post") return;
                $access_token = "应用密匙";
                $headers = array();
                $headers[] = "Authorization: OAuth2 ".$access_token;
                $url = 'https://api.weibo.com/2/statuses/share.json';
                $status = "我刚刚发布了新文章《".get_the_title($post_ID)."》,快来看看吧。详细内容请点击:".get_permalink($post_ID);
                if (has_post_thumbnail()) {
                        $post_thumbnail_id = get_post_thumbnail_id($post_ID);
                        $img_src = wp_get_attachment_url( $post_thumbnail_id );
                }else{
                        $content = get_post( $post_ID )->post_content;
                        preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
                        $img_src = $strResult[1][0];
                }
                if(!empty($img_src)) {
                        $picfile = str_replace(home_url(),$_SERVER["DOCUMENT_ROOT"],$img_src);
                        if(!empty($picfile)){
                                $filecontent = file_get_contents($picfile);
                        }else{
                                $filecontent = file_get_contents($img_src);
                        }
                        $array = explode('?', basename($img_src));
                        $filename = $array[0];
                        $boundary = uniqid('------------------');
                        $MPboundary = '--'.$boundary;
                        $endMPboundary = $MPboundary. '--';
                        $multipartbody = '';
                        $multipartbody .= $MPboundary . "\r\n";
                        $multipartbody .= 'Content-Disposition: form-data; name="pic"; filename="' . $filename . '"' . "\r\n";
                        $multipartbody .= "Content-Type: image/unknown\r\n\r\n";
                        $multipartbody .= $filecontent. "\r\n";
                        $multipartbody .= $MPboundary . "\r\n";
                        $multipartbody .= 'content-disposition: form-data; name="status' . ""\r\n\r\n";
                        $multipartbody .= urlencode($status)."\r\n";
                        $multipartbody .= $endMPboundary;
                        $headers[] = "Content-Type: multipart/form-data; boundary=" . $boundary;
                        $data = $multipartbody;
                }else{
                        $data = "status=" . urlencode($status);
                }
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                curl_setopt($ch, CURLOPT_POST, TRUE);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $curlResponse = curl_exec($ch);
                curl_close($ch);
                $output = json_decode($curlResponse);
                if($debug){
                        var_dump($output);
                        echo '<hr />';
                        var_dump($data);
                }
        }
}

作者:kn007的个人博客

自己改下代码里的“应用密匙”

Typecho视频插件JWPlayer

我代码稍作了修改解决报错问题
使用方法

<jw>https://doc.172u.top/file/mp4/test.mp4</jw>

播放器载入中...

说明下使用规范在https中无法使用http源,这个是默认都这样。
http可以使用https或者http

JWPlayer.zip修改版 下载

Upload to FTP wordpress远程附件插件

screenshot-1.png

台湾伙伴写的wordpress ftp远程附件
唯一缺点对SSL 略不支持可以先正常保存后通过修改数据库使用。
假如作者不修改,那我有空修改让他支持
upload-to-ftp.1.0.5.zip

必须配合这个一起用

//remove insert images attribute
//add_filter( 'the_content', 'fanly_remove_images_attribute', 99 );
add_filter( 'post_thumbnail_html', 'fanly_remove_images_attribute', 10 );
add_filter( 'image_send_to_editor', 'fanly_remove_images_attribute', 10 );
function fanly_remove_images_attribute( $html ) {
        //$html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
        $html = preg_replace( '/width="(\d*)"\s+height="(\d*)"\s+class="[^"]*"/', "", $html );
        $html = preg_replace( '/  /', "", $html );
        return $html;
}