Recent Topics

1 Sep 20, 2008 18:37    

My b2evolution Version: 2.x

Hi everyone,
I have a little problem with XMLRPC. I have this code. It works fine, but I can't save my tags. Can someone help me with this?

<?php
include("xmlrpc.inc");

    $ee_api_path = "http://www.mydomain.com/blogs/xmlsrv/xmlrpc.php";
    $ee_username = "user";
    $ee_password = "password";

    $c = new xmlrpc_client($ee_api_path);
    //$c->debug = true;

    $content['title'] = "XMLRPC Post Example";
    $content['description'] = "This is my post content.[teaserbreak][video:youtube:YOUTUBEID]";
    $content['categories'] = array("Category 1", "Category 2");

    $content['tags'] = "videos,youtube,external";

    $x = new xmlrpcmsg("metaWeblog.newPost",
        array(php_xmlrpc_encode("2"),
        php_xmlrpc_encode($ee_username),
        php_xmlrpc_encode($ee_password),
        php_xmlrpc_encode($content),
    $c->return_type = 'phpvals';
    $r = $c->send($x);

    if ($r->errno == "0") {
        echo "Successfully Posted";
    } else {
        echo "There are some error";
        print_r($r);
    }
?>

2 Sep 22, 2008 16:35

Hi Everyone,
I do a little modification. Now I can handle tags, too! I don't know if I made these chances on the correct files, but it working now! Just in case these are my diff:

--- inc/xmlrpc/apis/_metaweblog.api.php.orig    Thu Sep 18 00:07:06 2008
+++ inc/xmlrpc/apis/_metaweblog.api.php Mon Sep 22 07:43:38 2008
@@ -388,7 +388,7 @@
        $content = $contentstruct['description'];

        // COMPLETE VALIDATION & INSERT:
-       return xmlrpcs_new_item( $post_title, $content, $post_date, $main_cat, $cat_IDs, $status );
+       return xmlrpcs_new_item( $post_title, $content, $post_date, $main_cat, $cat_IDs, $status, $contentstruct );
 }

--- inc/xmlrpc/model/_xmlrpcs.funcs.php.orig     Mon Sep 22 08:26:27 2008
+++ inc/xmlrpc/model/_xmlrpcs.funcs.php  Mon Sep 22 08:16:35 2008
@@ -329,7 +329,7 @@
  * @param string status
  * @return xmlrpcmsg
  */
-function xmlrpcs_new_item( $post_title, $content, $post_date, $main_cat, $cat_IDs, $status )
+function xmlrpcs_new_item( $post_title, $content, $post_date, $main_cat, $cat_IDs, $status, $contentStruct = array() )
 {
   /**
         * @var User
@@ -339,6 +339,9 @@
        global $Messages;
        global $DB;

+
+       $structKeys = array('tags');
+
        // CHECK HTML SANITY:
        if( ($post_title = check_html_sanity( $post_title, 'xmlrpc_posting' )) === false )
        {
@@ -349,6 +352,17 @@
                return xmlrpcs_resperror( 22, $Messages->get_string( 'Invalid post contents, please correct these errors:'."\n", '', NULL, "  //  \n", 'xmlrpc' ) );
        }

+       foreach ($contentStruct as $key => $value) {
+               $key = strtolower($key);
+               if (in_array($key, $structKeys)) {
+                       if (($value = check_html_sanity($value, 'xmlrpc_posting')) === false) {
+                               return xmlrpcs_resperror( 22, $Messages->get_string( 'Invalid extra info, please correct these errors:'."\n", '', NULL, "  //  \n", 'xmlrpc' ) );
+                       } else {
+                               $extraInfo[$key] = $value;
+                       }
+               }
+       }
+
        // INSERT NEW POST INTO DB:
        load_class( 'items/model/_item.class.php' );
        $edited_Item = & new Item();
@@ -360,6 +374,16 @@
        $edited_Item->set( 'status', $status);
        $edited_Item->set( 'locale', $current_User->locale );
        $edited_Item->set_creator_User( $current_User );
+
+       // SET EXTRA INFO FROM STRUCTCONTENT
+       foreach ($extraInfo as $key => $value) {
+               if ($key === 'tags') {
+                       $edited_Item->set_tags_from_string($value);
+               } else {
+                       $edited_Item->set($key, $value);
+               }
+       }
+
        $edited_Item->dbinsert();
        if( empty($edited_Item->ID) )
        { // DB error

3 Sep 26, 2008 16:30

Hi Wildduck (I think you've fixed your problem) Well done.

It seems you're using the XMLRPC function to add a blog (Atleast someone worked it out). Could you please provide me with a few hints as to how I can do this? I didnt consider actually just using the functions, I was looking for an actual RPC method to do post inserts.

Please show me a more clean version if you have the time.

Thanks!

4 Sep 26, 2008 16:39

Hi Adam,
This is my little test. I hope this can help you!


<?php
include("xmlrpc.inc");

    $ee_api_path = "http://www.yoursite.com/blogs/xmlsrv/xmlrpc.php";
    $ee_username = "nickname";
    $ee_password = "password";

    $c = new xmlrpc_client($ee_api_path);
    $c->debug = true;


    $content['title'] = "This is an auto-post";
    $content['description'] = "This is the breaf<!--more-->More text with rendering objects [video:youtube:youtubeid]";
    $content['categories'] = array("Category I", "Category II");
    $content['tags'] = "tag1,tag2,tag3";

    $x = new xmlrpcmsg("metaWeblog.newPost",
        array(php_xmlrpc_encode("2"),
        php_xmlrpc_encode($ee_username),
        php_xmlrpc_encode($ee_password),
        php_xmlrpc_encode($content),
        php_xmlrpc_encode(true)));
    $c->return_type = 'phpvals';
    $r = $c->send($x);

    if ($r->errno == "0") {
        echo "Successfully Posted";
    } else {
        echo "There are some error";
        print_r($r);
    }
?>

5 Sep 26, 2008 16:52

Oh man... THANK YOU SO MUCH!

My cURL way of doing things was so wrong. MUCH THANKS!

Have fun with your future projects!

6 Sep 26, 2008 22:47

I hope this can help you a lot! :lol:


Form is loading...