SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 37 of 37
  1. #26
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Okay, to get you started, you need to put the filename of your php script in the action="" of your HTML form (like so, I also removed the duplicate name attributes you had on several fields)
    HTML Code:
    <style>
    #form {width: 360px; background-color: #ccc;
    border: 1px dotted #333; padding: 5px;
    margin: 0px auto;}
    div.row {
    clear: both;
    padding-top: 5px;
    }
    
    div.row span.label {
    float: left;
    width: 100px;
    text-align: right;
    }
    
    div.row span.formw {
    float: right;
    width: 235px;
    text-align: left;
    } 
    </style>
    
    <div id="form">
    <form name="wordressposter" action="myphpscript.php" method="post">
    <div class="row">
    <span class="label">Title: </span><span
    class="formw"><input name="title" type="text" size="25" /></span>
    </div>
    <div class="row">
    <span class="label">Comments: </span><span class="formw">
    <textarea cols="25" rows="8" name="article"></textarea>
    </span>
    </div>
    <div class="row">
    <span class="label">Tags: </span><span
    class="formw"><input type="text" size="25" name="keywords"/></span>
    </div>
    <div class="row">
    <span class="label">Categories: (separate with commas)</span><span
    class="formw"><input type="text" size="25" name="categories"/></span>
    </div>
    
    <div class="spacer">
    </div>
    </form>
    </div>
    Then you need to update your PHP script to use the form elements
    PHP Code:
    <?php  
    include("./wp-includes/class-IXR.php");  
    $client = new IXR_Client('http://MYSITE.org/xmlrpc.php');  

    if (!
    $client->query('wp.getCategories','''WHERE-I-PUT-MY-WORDPRESS-USERNAME','WHERE-I-PUT-MY-WORDPRESS-PASSWORD')) {  
    echo(
    'An error occurred calling wp.getCategories - '.$client->getErrorCode().":".$client->getErrorMessage());  
    }  
    $response $client->getResponse();  




    $content = array(  
    'title'=>$_POST['title'],  
    'description'=>$_POST['article'],  
    'mt_allow_comments'=>'1',  
    'mt_allow_pings'=>'1',  
    'post_type'=>'post',  
    'mt_keywords'=>$_POST['keywords'],  
    'categories'=>split(','$_POST['categories'])
    );  

    var_dump($content); // paste the output of this back to the forum for us to review.

    if (!$client->query('metaWeblog.newPost','''WHERE-I-PUT-MY-WORDPRESS-USERNAME','WHERE-I-PUT-MY-WORDPRESS-PASSWORD'$contentfalse)) {  
    echo(
    'An error occurred calling metaWeblog.newPost - '.$client->getErrorCode().":".$client->getErrorMessage());  
    }  
    echo 
    $client->getResponse(); //with Wordpress, will report the ID of the new post  
    ?>
    Now I am making a few assumptions, 1) I am assuming the WordPress API will sanitize the data because the examples found on http://life.mysiteonline.org/archive...d-XML-RPC.html do not tell me that I need to sanitize the data. 2) I am assuming allow_comments and allow_pings are a true/false field and since the form doesn't specifically ask, I hard coded them to true.

  2. #27
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi cpradio, thanks I get this array:

    array(7) {
    ["title"]=>
    string(3) "new"
    ["description"]=>
    string(3) "new"
    ["mt_allow_comments"]=>
    string(1) "1"
    ["mt_allow_pings"]=>
    string(1) "1"
    ["post_type"]=>
    string(4) "post"
    ["mt_keywords"]=>
    string(3) "new"
    ["categories"]=>
    array(1) {
    [0]=>
    string(10) "category name"
    }
    }
    548

  3. #28
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bayliss Trevor View Post
    Hi cpradio, thanks I get this array:

    array(7) {
    ["title"]=>
    string(3) "new"
    ["description"]=>
    string(3) "new"
    ["mt_allow_comments"]=>
    string(1) "1"
    ["mt_allow_pings"]=>
    string(1) "1"
    ["post_type"]=>
    string(4) "post"
    ["mt_keywords"]=>
    string(3) "new"
    ["categories"]=>
    array(1) {
    [0]=>
    string(10) "category name"
    }
    }
    548
    And no error? So it seems you should have a new post in your WordPress installation with a title of new and a article/description of new.

    With that said, you can remove the var_dump line, and you can remove your echo $client->getResponse(); (unless you want to know the post ID that was created)

  4. #29
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I couldn't see it published so I just checked the wp admin, and it's there but as a draft not a published post. I'll check out the wordpress documentation and see why it isn't being published. Thanks for all the help cpradio really appreciated

  5. #30
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    http://codex.wordpress.org/XML-RPC_MetaWeblog_API

    You can set a publish indicator to 1 to force it to publish when you call newPost like so:
    PHP Code:
    $content = array(   
    'title'=>$_POST['title'],   
    'description'=>$_POST['article'],   
    'mt_allow_comments'=>'1',   
    'mt_allow_pings'=>'1',   
    'post_type'=>'post',    
    'publish'=>'1',   
    'mt_keywords'=>$_POST['keywords'],   
    'categories'=>split(','$_POST['categories']) 
    ); 

  6. #31
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    I do want to point out 1 more thing, that you should take very seriously.

    Since your PHP script contains your WordPress username and password, anyone that posts information to that script with title, article, keywords, and categories will be able to post an entry to your blog.

    One way to protect against this is to have your username and password as fields on your form that must be filled out. If this concerns you, I'll be glad to help you sort that out, or if you rather take a different approach, I can help provide those as well.

  7. #32
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi doesn't work, it maybe something to do with my other plugins, I'm going to do some tests, cheers

  8. #33
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes that is a concern, that is exactly what is needed, that the username and passoword are forms that must be filled out please

  9. #34
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Form that has username and password

    HTML Code:
    <style>
    #form {width: 360px; background-color: #ccc;
    border: 1px dotted #333; padding: 5px;
    margin: 0px auto;}
    div.row {
    clear: both;
    padding-top: 5px;
    }
    
    div.row span.label {
    float: left;
    width: 100px;
    text-align: right;
    }
    
    div.row span.formw {
    float: right;
    width: 235px;
    text-align: left;
    } 
    </style>
    
    <div id="form">
    <form name="wordressposter" action="myphpscript.php" method="post">
    <div class="row">
    <span class="label">Username: </span><span
    class="formw"><input name="username" type="text" size="25" /></span>
    </div>
    <div class="row">
    <span class="label">Password: </span><span
    class="formw"><input name="password" type="password" size="25" /></span>
    </div>
    <div class="row">
    <span class="label">Title: </span><span
    class="formw"><input name="title" type="text" size="25" /></span>
    </div>
    <div class="row">
    <span class="label">Comments: </span><span class="formw">
    <textarea cols="25" rows="8" name="article"></textarea>
    </span>
    </div>
    <div class="row">
    <span class="label">Tags: </span><span
    class="formw"><input type="text" size="25" name="keywords"/></span>
    </div>
    <div class="row">
    <span class="label">Categories: (separate with commas)</span><span
    class="formw"><input type="text" size="25" name="categories"/></span>
    </div>
    
    <div class="spacer">
    </div>
    </form>
    </div>
    New set of code that accepts username and password from the form

    PHP Code:
    <?php   
    include("./wp-includes/class-IXR.php");   
    $client = new IXR_Client('http://MYSITE.org/xmlrpc.php');   

    if (!
    $client->query('wp.getCategories',''$_POST['username'],$_POST['password'])) {   
    echo(
    'An error occurred calling wp.getCategories - '.$client->getErrorCode().":".$client->getErrorMessage());   
    }   
    $response $client->getResponse();   




    $content = array(   
    'title'=>$_POST['title'],   
    'description'=>$_POST['article'],   
    'mt_allow_comments'=>'1',   
    'mt_allow_pings'=>'1',   
    'publish'=>true,   // try true instead of '1'
    'post_type'=>'post',   
    'mt_keywords'=>$_POST['keywords'],   
    'categories'=>split(','$_POST['categories']) 
    );   

    //var_dump($content); // paste the output of this back to the forum for us to review. 

    if (!$client->query('metaWeblog.newPost',''$_POST['username'],$_POST['password'], $contentfalse)) {   
    echo(
    'An error occurred calling metaWeblog.newPost - '.$client->getErrorCode().":".$client->getErrorMessage());   
    }   
    echo 
    $client->getResponse(); //with Wordpress, will report the ID of the new post   
    ?>
    I also changed the 'publish' line to use true instead of '1', maybe that will make a difference.

  10. #35
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    From the http://codex.wordpress.org/XML-RPC_MetaWeblog_API

    You can also try setting 'post_status' => 'publish' like so
    PHP Code:
    $content = array(   
    'title'=>$_POST['title'],   
    'description'=>$_POST['article'],   
    'mt_allow_comments'=>'1',   
    'mt_allow_pings'=>'1',   
    'publish'=>true,   // try true instead of '1'
    'post_status'=>'publish',
    'post_type'=>'post',   
    'mt_keywords'=>$_POST['keywords'],   
    'categories'=>split(','$_POST['categories']) 
    ); 

  11. #36
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi cpradio I found the solution!
    In class-wp-xmlrpc-server.php, find this line

    Code:

    'publish' : 'draft';

    Replace that with

    Code:

    ‘draft’ : ‘publish

  12. #37
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Good to know


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •