mrhaw
Posts: 5
Comment
new comment
Reply #7 on : Mon July 12, 2010, 09:32:15
Nice! Great site! :)
senica
Posts: 3
Comment
new comment
Reply #6 on : Thu June 24, 2010, 05:29:41
@Jay, The archives has baffled me. I don't know why Wordpress does not allow a way to pull that information. You could probably edit one of the functions in the class, and pass in the url of the xml feed for archives and process that. It should work.
Jay
Posts: 5
Comment
new comment
Reply #5 on : Thu June 03, 2010, 15:46:35
Great set of tools. Is there a way to pull in content from the Archives section of a blog? For example, I'd like to show all the posts from May 2010 in a ModX page. Thank you.
senica
Posts: 3
Comment
new comment
Reply #4 on : Wed May 26, 2010, 10:09:20
@Andrew, Sorry I couldn't reply right away to you. This grabs the wordpress feed and processes it. It does not paginate the blog, as wordpress does not provide a way to do that through xml-rpc. This is a manual process, no fancy modx module built. If someone would like to help out with that, I'll be more than happy to post up here.
Andrew
Posts: 5
Comment
new comment
Reply #3 on : Thu May 13, 2010, 20:44:28
So, just to clarify, this will pull all content out of a WordPress blog and post it into ModX? Will it paginate the posts, or does it make it one long feed in the ModX template?

Also, how is this content styled once in the ModX template? Can you assign a template that controls the content input into Modx like most other snippets?
senica
Posts: 3
Comment
new comment
Reply #2 on : Thu May 13, 2010, 09:30:18
Hey Steve, just to follow up for comments sake...

After helping Steve, it ended up being that DOM had not been configured with PHP.

DOMDocument() is used to parse XML from Wordpress.
steve
Posts: 5
Comment
new comment
Reply #1 on : Tue May 04, 2010, 01:54:02
Hi

I can't get this to work in even it's most basic form (ie all instructions followed up to making any php changes)

The post(s) don't show up

Have tested with a different WP blog

Any tips?

Steve
Allebrum Program Package Download AWP

Title: Allebrum Wordpress Tools for MODx (AWP)
Supports MODx 1.0.2
Package Contains:
Main Class
Example Snippets
Readme
Version: 0.3
This is the first release of the Allebrum Wordpress Tools. Please send us your praise and hatemail.  This was tested on a limited environment, so any feedback you give about your environment will be helpful to others who use this package.

Write a comment


If you have trouble reading the code, click on the code itself to generate a new random code.
 
If you like the Wordpress Tools, buy us a cup of tea.

Allebrum Wordpress Tools for MODx

Thanks for checking out our Wordpress Tools for MODx.  If you are using MODx to manage your site, and you have a Wordpress blog that you want to pull into your site, this tool is for you.  We tried to make this as easy to use as possible, but in the end....well, that didn't exactly happen.  But if you follow along, I'm sure we can get you there.

*Note for international characters: We were recently working with an international client and fan into a problem with the way that DOMXPath for PHP handles UTF-8 encoding. If you get funny characters printed out, you may have to edit some of the functions in the allebrumWordpress class. An example to fix this issue would be to change the line: $elements["title"] = $xpath->query("title", $c)->item(0)->nodeValue); to $elements["title"] = htmlentities($xpath->query("title", $c)->item(0)->nodeValue, ENT_QUOTES, 'UTF-8'); . Places where it is a text() node, just wrap it in utf8_decode.

INSTALLATION

First things first.  Make sure you have downloaded the install files, unzip them, and upload them to your server.  If you do not have a copy of the Allebrum Wordpress Tools Class yet, you can download it from the right side, or go to MODxCMS.com and find it in the Blogging Section of their Extras.  

Once you have downloaded the package, you will need to unzip it and upload the allebrumWordpress.inc.php file to your server in the assets/snippets/allebrumWordpress folder (obviously you will need to create an allebrumWordpress folder).  When you are finished, it should look something like this:

Folder Install

 

Now that that is finished, you will need to login to your MODx Manager, and go to Elements>Manage Elements>Snippets and click on New Snippet.

Give your snippet a name (it is better if there are no spaces), and paste the text from awpNav.snippet.txt into the text area.  On the first several lines of that code, you will see a place where you will need to put in a username and password.  Enter your Wordpress.com username and password accordingly between the double-quotation marks.  You will also need to specify the domain that your wordpress blog resides on.  Next you will have to specify the path to the xmlrpc.php file that came with your wordpress install.  If your wordpress blog is on wordpress.com, then this should be "/xmlrpc.php". Save that.

Now, create a new resource (a new page), give it a name, and type [\[allebrumWordpress]\] in the text area (without the slashes).  *Note that you should replace allebrumWordpress with the name that you gave your snippet.

If your blog is installed on Wordpress.com, then that is all you need to do for the install part.

If you are hosting your Wordpress blog yourself, then you need to do one more step.  Login to your Wordpress blog admin.  On the left-hand side, go to Settings>Writing, and under the Remote Publishing section, place a checkbox next to XML-RPC.

Enable XMLRPC on Wordpress

Save that.

Congratulations!  You are finished!

You should now be able to browse to the resource (or page) that you created and see a navigation list of your Wordpress posts.

The remainder of this documents deals with modifying the snippet to fit your particular website.  Hopefully it is straightforward for those of you that know PHP....for those that don't, follow along and learn something!

Documenting the AWP class (Allebrum WordPress)

constructor

To use the AWP class, you will need to include it.  We first check to see if the class already exists. If it doesn't, then we include our class file.

if(!class_exists('AWP')){

include("assets/snippets/allebrumWordpress/allebrumWordpress.inc.php");

}

Next you will need to specify your username, password, domain, and a path for the xmlrpc.php file.

The username and password is the actual username and password that you use to login to make new posts on your Wordpress blog.

The domain is the place where your blog resides.  Some example of this are:

If your Wordpress blog is installed at http://localhost/wordpress/, then your domain is "localhost".

If your Wordpress blog is installed at http://allebrum.wordpress.com, then your domain is "allebrum.wordpress.com".

If your Wordpress blog is installed at http://www.bobsportapottys.com/wp/myblog/, then your domain is "bobsportapottys.com".

The path is the location of your xmlrpc.php file.  Every Wordpress install has one...somewhere.

If you could access the xmlrpc.php file by typing http://localhost/wordpress/xmlrpc.php into your browser (it wouldn't show you anything, but for argument sakes), then the path would be "/wordpress/xmlrpc.php", and your domain would be "localhost".

Since we have our blog installed on wordpress.com, we will set our path to "/xmlrpc.php".  Alternatively, we can completely omit the $path line since we are hosting on wordpress.com.  $path is set to "/xmlrpc.php" by default.

$user = "username"; //where username is your actual username

$pass = "password"; //where password is your actual password.

$domain = "allebrum.wordpress.com";

$path = "/xmlrpc.php";

Now we need to make a new instance of the AWP class:

$blog = new AWP($domain, $user, $pass, $path);

That sums that up.  At this point your file should look something like this:

<?php

 

if(!class_exists('AWP')){

include("assets/snippets/allebrumWordpress/allebrumWordpress.inc.php");

}

 

$user = "username"; //where username is your actual username

$pass = "password"; //where password is your actual password.

$domain = "allebrum.wordpress.com";

$path = "/xmlrpc.php";

$blog = new AWP($domain, $user, $pass, $path);

?>

Now we can use the class to get information from Wordpress....and you thought we were already doing something.

After making a new call to the constructor, the following parameters become available for your use:

echo $blog->blogName;

echo $blog->blogId;

echo $blog->blogUrl;

getBlogs()

RETURNS: Array of all blogs of username.

Params: url

blogid

blogName

USAGE:

$blogs = $blog->getBlogs();

foreach($blogs as $v){

echo $v["url"]."-";

echo $v["blogid"]."-";

echo $v["blogName"]."-<br>";

}

getCategories()

RETURNS: Array of categories with an array of properties.

Params: categoryId

parentId

description

categoryDescription

categoryName

htmlUrl

rssUrl

USAGE:

$categories = $blog->getCategories();

foreach($categories as $v){

echo $v["categoryId"];

echo $v["categoryName"];

}

getPostsInCategory(string categoryFeedUrl) DEPRECATED

*NOTICE: Due to excessive bandwidth overhead, this function is now deprecated. Please do not use this function.  It is in the documentation for support on older systems.  Please use getNav() instead.

RETURNS: An array of posts within the category (specified by category Feed)

Params: title

link

commentFeed

pubDate

description

content

id

USAGE:

$categories = $blog->getCategories();

foreach($categories as $v){

echo $v["categoryName"]."<br>";

$posts = $blog->getPostsInCategory($v["rssUrl"]);

foreach($posts as $p){

echo "<a href='".$p["link"]."'>".$p["title"]."</a><br>";

}

}

getList(int numberOfPosts)

RETURNS: Array of posts with minimal information.

Params: userid

postid

title

numberOfPosts is the number of most recent posts to return.  This value is required.  There is no way to get all posts from Wordpress other than to increase this number to value larger than the total posts you have.  

USAGE:

$posts = $blog->getList(1000);

foreach($posts as $p){

echo $p["postid"]."-".$p["title"];

}

getNav(object getList)

RETURNS: Array of Categories along with each post title belonging to that category.

Params: title

id

posts Array(

userid

postid

title)

USAGE:

$posts = $blog->getList(200);

$nav = $blog->getNav($posts);

foreach($nav as $n){

echo "<h3>".$n["title"]."</h3>"; //Category Name

echo "<h3>".$n["id"]."</h3>"; //Category Id

foreach($n["posts"] as $p){

echo "<a href='".$p["postid"]."' class='more'>"

echo $p["title"]."</a><br>";

}

}

While we stopped using getPostInCategory in an attempt to cut down on bandwidth, there really isn't a friendly way to get a Category>Post list from Wordpress.  They pack everything backwards from this functionality.  So there is still quite a bit a of bandwidth used as we have to make a call for each post, to find out what category it belongs to, and then process that information.  If you are experiencing a long load time, try lowering the number of posts you are requesting, or take this out completely and see if that helps.  If it does, you know where your problem lies.

getPost(int postid)

RETURNS: Array of Post information relative to postid.

Params: dateCreated

userid

postid

description - This is the main content...may need to be formatted to your liking

title

link

permaLink

categories

mt_keywords

mt_allow_comments

mt_excerpt

mt_text_more

wp_slug

wp_author_id

wp_author_display_name

date_created_gmt

post_status

custom_fields

USAGE:

If you script is located at http://www.allebrum.com/blog.php, then enter the following in your address bar:

http://www.allebrum.com/blog.php?postid=9

Your script at blog.php should look something like this:

 

<?php

 

if(!class_exists('AWP')){

include("assets/snippets/allebrumWordpress/allebrumWordpress.inc.php");

}

 

$user = "username"; //where username is your actual username

$pass = "password"; //where password is your actual password.

$domain = "allebrum.wordpress.com";

$path = "/xmlrpc.php";

 

 

$blog = new AWP($domain, $user, $pass, $path);

$id = $_GET["postid"];

$post = $blog->getPost($id);

echo "<h2>".$post["title"]."</h2>";

$p = $post["description"];

$p = str_replace("[code]", "<blockquote>", $p);

$p = str_replace("[/code]", "</blockquote>", $p);

$breaks   = array("\r\n", "\n", "\r");

$p = str_replace("\n", '<br />', $p);

$p = str_replace("[", "&#91;", $p);

echo $p;

?>

getRecentPosts(int numberOfPosts)

RETURNS: Array of Posts up to the numberOfPosts

Params: Array(same as getPost())

USAGE:

 

$list = $blog->getRecentPosts(2);

foreach($list as $v){

echo "<h2>".$v["title"]."</h2>";

$p = $v["description"];

$p = str_replace("[code]", "<blockquote>", $p);

$p = str_replace("[/code]", "</blockquote>", $p);

$breaks   = array("\r\n", "\n", "\r");

$p = str_replace("\n", '<br />', $p);

$p = str_replace("[", "&#91;", $p);

echo $p;

}

newComment(int postid, string comment, string author, string author_website, string author_email)

RETURNS: If successful, returns the new comment id.

Due to some uncanny "security" restrictions on Wordpress.com, newComment will post the comment with the name of the person that is logged in, and not the specified author.  I have gone round and round with them about this issue. You can view the thread here. I also posted on the mailing lists and support website to no avail.  In order to correct this, you will need to call the editComment() function right after the newComment is made. I have provided an example below.

USAGE:

$postid = $_GET['postid']; //assuming that you passed the postid in the url

$comment = "This rocks!!";

$author = "Senica";

$web = "www.allebrum.com";

$email = "senica@allebrum.com";

$commentid = $blog->newComment($postid, $comment, $author, $web, $email);

REAL LIFE EXAMLE:

<?php

 

if(!class_exists('AWP')){

include("assets/snippets/allebrumWordpress/allebrumWordpress.inc.php");

}

 

$user = "username"; //where username is your actual username

$pass = "password"; //where password is your actual password.

$domain = "allebrum.wordpress.com";

$path = "/xmlrpc.php";

 

 

$awp = new AWP($domain, $user, $pass, $path);

$commentid = $awp->newComment($contact["postid"], $contact["comment"], $contact["name"], $contact["web"], $contact["email"]);

if($commentid > 0){

$editid = $awp->editComment($commentid, $contact["comment"], $contact["name"], $contact["web"], $contact["email"]);

if($editid == 1){

echo "Post successfully made and edited";

}else{

echo "Not Today";

}

}else{

echo "Failed on making Comment";

}

?>

editComment(int commentid, string comment, string author, string author_website, string author_email)

RETURNS: 1 if successful, 0 or null if it fails.

USAGE:

 

$commentid = $_GET['commentid']; //assuming that you passed the commentid in the url

$comment = "This rocks!!";

$author = "Senica";

$web = "www.allebrum.com";

$email = "senica@allebrum.com";

$commentid = $blog->newComment($commentid, $comment, $author, $web, $email);

getTags()

RETURNS: Array of all tags within current blog.

USAGE: 

$tags = $blog->getTags();

foreach($tags as $t){

echo $t;

}

getComments(int postid, [int number], [int offset])

RETURNS: Array of comments up to number specified, for the specified postid, starting at offset.

Params:

date_created_gmt

user_id

comment_id

parent

status

content

link

post_id

post_title

author

author_url

author_email

author_ip

type

number and offset are both optional. number is the number of posts to return.  If you only want to display 5 posts, set number to 5. 

offset is where to start.  If you don't want the first 3 comments, set offset to 4.  This is useful if you are paginating your comments.

USAGE:

$comments = $blog->getComments("20"); //Could optionally be getComments("20", "5", "4");

foreach($comments as $c){

echo $c["author"].$c["content"];

}

 

This concludes the current documentation for the Allebrum Wordpress Tools for MODx.

 

© Allebrum, LLC 2010