Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

MetaWeblog API in PHP

Implementation of the MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP.

<?php
/**
 * Skeleton file for MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP
 * Requires Keith Deven's XML-RPC Library http://keithdevens.com/software/xmlrpc and store it as xmlrpc.php in the same folder
 * Written by Daniel Lorch, based heavily on Keith Deven's examples on the Blogger API.
 */

require_once dirname(__FILE__) . '/xmlrpc.php';

function metaWeblog_newPost($params) {
  list($blogid, $username, $password, $struct, $publish) = $params;
  $title = $struct['title'];
  $description = $struct['description'];


  // YOUR CODE:
  $post_id = 0; // id of the post you just created


  XMLRPC_response(XMLRPC_prepare((string)$post_id), WEBLOG_XMLRPC_USERAGENT);
}

function metaWeblog_editPost($params) {
  list($postid, $username, $password, $struct, $publish) = $params;


  // YOUR CODE:
  $result = false; // whether or not the action succeeded


  XMLRPC_response(XMLRPC_prepare((boolean)$result), WEBLOG_XMLRPC_USERAGENT);
}

function metaWeblog_getPost($params) {
  list($postid, $username, $password) = $params;
  $post = array();


  // YOUR CODE:
  $post['userId'] = '1';
  $post['dateCreated'] = XMLRPC_convert_timestamp_to_iso8601(time());
  $post['title'] = 'Replace me';
  $post['content'] = 'Replace me, too';
  $post['postid'] = '1';


  XMLRPC_response(XMLRPC_prepare($post), WEBLOG_XMLRPC_USERAGENT);
}

function XMLRPC_method_not_found($methodName) {
  XMLRPC_error("2", "The method you requested, '$methodName', was not found.", WEBLOG_XMLRPC_USERAGENT);
}

$xmlrpc_methods = array(
  'metaWeblog.newPost'  => 'metaWeblog_newPost',
  'metaWeblog.editPost' => 'metaWeblog_editPost',
  'metaWeblog.getPost'  => 'metaWeblog_getPost'
);

$xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);
$methodName = XMLRPC_getMethodName($xmlrpc_request);
$params = XMLRPC_getParams($xmlrpc_request);

if(!isset($xmlrpc_methods[$methodName])) {
  XMLRPC_method_not_found($methodName);
} else {
  $xmlrpc_methods[$methodName]($params);
}
?>

Blogger Archive Menu XHTML Valid

Runs the archives backwards, so that the most recent month is at the top of the menu.

     <ul class="archive-list"><li><select name="archivemenu" id="archivemenu"
style="width:100%;background-color:#000000;color:#006666;font-weight:bold;"
onchange="document.location.href=this.options[this.selectedIndex].value;" >
<option selected="selected" value="archives">archives</option>
</select></li></ul>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
var archives = new Array();

<BloggerArchives>
archives[archives.length] = new Array('<$BlogArchiveURL$>', '<$BlogArchiveName$>');
</BloggerArchives>
var theSel = document.getElementById('archivemenu');
for (var i=archives.length-1;i>=0;i--) {
var newOpt = new Option(archives[i][1], archives[i][0]);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;

}
//--><!]]>
</script>

Blogger Previous Posts Menu XHTML valid

Previous Posts in a drop down menu.

Recent Perversions can be changed to whatever you want to show up as the title of your menu.

<ul><li>
<select name="previouspostsmenu" id="previouspostsmenu"
style="width:100%;background-color:#000000;color:#ffffff;font-weight:bold;"
onchange="document.location.href=this.options[this.selectedIndex].value;" >
        <option selected="selected" value="Recent Perversions">&nbsp;Recent Perversions</option>
               <BloggerPreviousItems>
                     <option value="<$BlogItemPermalinkURL$>"><$BlogPreviousItemTitle$></option>                  
                  </BloggerPreviousItems>
               </select></li></ul>
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS