예제 #1
0
파일: interface.php 프로젝트: zhebiewang/WP
 private function sendMsgBase($fromUsername, $toUsername, $messages)
 {
     if (count($messages) > 0) {
         $headerTpl = "<ToUserName><![CDATA[%s]]></ToUserName>\n      \t\t\t        <FromUserName><![CDATA[%s]]></FromUserName>\n      \t\t\t        <CreateTime>%s</CreateTime>\n      \t\t\t        <MsgType><![CDATA[%s]]></MsgType>\n      \t\t\t        <ArticleCount>%s</ArticleCount>";
         $itemTpl = "<item>\n        \t\t\t\t\t<Title><![CDATA[%s]]></Title> \n        \t\t\t\t\t<Description><![CDATA[%s]]></Description>\n        \t\t\t\t\t<PicUrl><![CDATA[%s]]></PicUrl>\n        \t\t\t\t\t<Url><![CDATA[%s]]></Url>\n        \t\t\t\t\t</item>";
         $itemStr = "";
         $mediaCount = 0;
         $i = 1;
         foreach ($messages as $mediaObject) {
             $src_and_text = $this->getImgsSrcInPost($mediaObject->ID, $mediaObject->post_content, $i, $contentData['type'], $mediaObject->post_excerpt);
             $title = trim_words($mediaObject->post_title, SYNC_TITLE_LIMIT);
             $des = $src_and_text['text'];
             // strip_tags or not
             $media = $this->parseurl($src_and_text['src']);
             if ($contentData['type'] == "attachment") {
                 $url = home_url('/?attachment_id=' . $mediaObject->ID);
             } else {
                 $url = html_entity_decode(get_permalink($mediaObject->ID));
             }
             $itemStr .= sprintf($itemTpl, $title, $des, $media, $url);
             $mediaCount++;
             $i++;
         }
         $msgType = "news";
         $time = time();
         $headerStr = sprintf($headerTpl, $fromUsername, $toUsername, $time, $msgType, $mediaCount);
         $resultStr = "<xml>" . $headerStr . "<Articles>" . $itemStr . "</Articles></xml>";
     } else {
         $textTpl = "<xml>\n        \t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n        \t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n        \t\t\t\t\t<CreateTime>%s</CreateTime>\n        \t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n        \t\t\t\t\t<Content><![CDATA[%s]]></Content>\n        \t\t\t\t\t<FuncFlag>0</FuncFlag>\n        \t\t\t\t\t</xml>";
         $msgType = "text";
         $time = time();
         $no_result = __('Sorry! No result.', 'WPWSL');
         $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $no_result);
     }
     return $resultStr;
 }
예제 #2
0
function prefix_ajax_get_insert_content()
{
    if ($_GET['rtype'] == 'posts') {
        $myrow = get_post($_GET['postid']);
        $post_categories = wp_get_post_categories($myrow->ID);
        $cats = '';
        foreach ($post_categories as $c) {
            $cat = get_category($c);
            $cats .= ',' . $cat->name;
        }
        $cats = substr($cats, 1);
        $text_title = trim_words($myrow->post_title, SYNC_TITLE_LIMIT);
        $text_content = trim_words($myrow->post_content, SYNC_CONTENT_LIMIT);
        $rpost = '#' . $text_title . '#' . $text_content . '[' . get_permalink($myrow->ID) . '][' . $myrow->post_date . ']';
        $r = array('status' => 'success', 'data' => $rpost);
    } else {
        if ($_GET['rtype'] == 'urls') {
            $myrow = get_post($_GET['postid']);
            $r = array('status' => 'success', 'data' => get_permalink($myrow->ID));
        } else {
            if ($_GET['rtype'] == 'phmsg') {
                if (isset($_GET['imagesize']) && $_GET['imagesize'] == 'small') {
                    $imageSize = 'sup_wechat_small';
                } else {
                    $imageSize = 'sup_wechat_big';
                }
                $myrow = get_post($_GET['postid']);
                $myrow->pic = WPWSL_PLUGIN_URL . '/img/' . $imageSize . '.png';
                if (get_the_post_thumbnail($_GET['postid']) != '') {
                    $_tmp_thumb_id = get_post_thumbnail_id($_GET['postid']);
                    $tmp_img_obj = wp_get_attachment_image_src($_tmp_thumb_id, $imageSize);
                    $myrow->pic = $tmp_img_obj[0];
                } else {
                    $attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $_GET['postid'], 'exclude' => get_post_thumbnail_id($_GET['postid'])));
                    if (count($attachments) > 0) {
                        $tmp_img_obj = wp_get_attachment_image_src($attachments[0]->ID, $imageSize);
                        $myrow->pic = $tmp_img_obj[0];
                    }
                }
                $myrow->post_title = trim_words($myrow->post_title, SYNC_TITLE_LIMIT);
                if (trim($myrow->post_excerpt) != '') {
                    $myrow->post_content = trim_words($myrow->post_excerpt, SYNC_EXCERPT_LIMIT);
                } else {
                    $myrow->post_content = trim_words($myrow->post_content, SYNC_EXCERPT_LIMIT);
                }
                $myrow->url = get_permalink($myrow->ID);
                $r = array('status' => 'success', 'data' => $myrow);
            } else {
                $r = array('status' => 'error', 'data' => 'rtype error!');
            }
        }
    }
    print json_encode($r);
    die;
}