Allebrum Wordpress Tools
Thanks for checking out our Wordpress Tools. If you have a website, 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
Please note that this is not the right location if you are using MODx. Please look for the Wordpress Tools for MODx on this site instead.
Allebrum Wordpress Tools is simply one single PHP class file that you interact with. You can obtain this class by downloading the zip file on the right hand side of this page.
Once you have downloaded the package, you will need to unzip it and upload the allebrumWordpress.inc.php file to your server. You can put this file anywhere you like, but you will need to make a note of where you put it because you will need to reference it later. For this installation, we will put it in a folder called wordpress. So I could theoretically access the file by typing in http://localhost/wordpress/allebrumWordpress.inc.php on my particular installation.
If you have your Wordpress blog on Wordpress.com, then that is all you need to do for the installation portion.
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.

Save that.
Congratulations! You are finished installing!
To use the class, here is quick example to get you started. Create a new php file on you server in the root directory. Inside that php file, put the following code.
A few notes on the code:
$domain is the actual domain where your wordpress blog resides. If you are hosting on wordpress.com, then your domain will be something like "allebrum.wordpress.com". If you are hosting on your own computer, it might be "localhost". If you are hosting on your own domain, it might be something like "allebrum.com". If your wordpress blog is at http://localhost/wordpress, then $domain is still just "localhost". Got it? Okay, next...
$username and $password are the actual username and password you use to login to your Wordpress admin to make new posts.
$path is the location of your xmlrpc.php file. Every Wordpress installation has one. If you are hosting on wordpress.com, this can be omitted completely. All others will need to leave this variable and fill it out correctly. Go to your wordpress installation and find the xmlrpc.php file. If you have wordpress installed in a directory called "wordpress", then $path will probably be "/wordpress/xmlrpc.php".
/************** EDIT THESE VARIABLES TO PERTAIN TO YOUR BLOG ******************************************************************************************/$domain = "allebrum.wordpress.com"; //The domain your blog is hosted on.$username = "username"; //The username you use to login at Wordpress.com or into your dashboard if hosted yourself$password = "password"; //The password you use to login at Wordpress.com or into your dashboard if hosted yourself/********************************* END EDITS ****************************************************************************************************************************//*####################################################################################Programmer: Senica GonzalezCompany: AllebrumWebsite: www.allebrum.comVersion 0.1Documentation can be found on Allebrum.comThis work is licensed under the Creative CommonsAttribution-Share Alike 3.0 United States License.To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.######################################################################################*/preg_match("/\/.*?\?id=\d+/", $_SERVER['REQUEST_URI'], $match);$url = "http://".$_SERVER['SERVER_NAME'].$match[0];if(!class_exists('AWP')){include("assets/snippets/allebrumWordpress/allebrumWordpress.inc.php");}$awp = new AWP($domain, $username, $password);$posts = $awp->getList(200);$nav = $awp->getNav($posts);foreach($nav as $v){echo "<h3>".$v["title"]."</h3>";foreach($v["posts"] as $p){echo "<a href=$url&postid=".$p["postid"]." class='more'>". $p["title"]."</a>";}}?><?php
/************** EDIT THESE VARIABLES TO PERTAIN TO YOUR BLOG ****************************/
$domain = "allebrum.wordpress.com"; //The domain your blog is hosted on.
$username = "username"; //The username you use to login at Wordpress.com or into your dashboard if hosted yourself
$password = "password"; //The password you use to login at Wordpress.com or into your dashboard if hosted yourself
$path = "/xmlrpc.php"; //This is the actual path to the xmlrpc.php file. Check the location of your file and fill this out accordingly.
/********************************* END EDITS ********************************/
/*####################################################################################
Programmer: Senica Gonzalez
Company: Allebrum
Website: www.allebrum.com
Version 0.1
Documentation can be found on Allebrum.com
This work is licensed under the Creative Commons
Attribution-Share Alike 3.0 United States License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/
or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
######################################################################################*/
if(!class_exists('AWP')){
include("/wordpress/allebrumWordpress.inc.php");
}
$awp = new AWP($domain, $username, $password, $path);
$posts = $awp->getList(200);
$nav = $awp->getNav($posts);
foreach($nav as $v){
echo "<h3>".$v["title"]."</h3>";
foreach($v["posts"] as $p){
echo "<a href=?postid=".$p["postid"].">". $p["title"]."</a>";
}
}
?>
Save that file, and open that file in your browser. You should now see a list of your Wordpress Categories and Posts Title (if you filled in the domain name, username, password and path correctly.)
The remainder of this documents deals with different calls to class. 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("wordpress/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("wordpress/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("wordpress/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("[", "[", $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("[", "[", $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("wordpress/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"];
}
###The following are for internal use only at this moment.
getPageList()
RETURNS: Array of pages with minimal information.
Params: page_id
page_title
page_parent_id
dateCreated
This concludes the current documentation for the Allebrum Wordpress Tools for MODx.
Posts: 1
Reply #2 on : Thu February 18, 2010, 09:36:11