getParam(3); $iSize = $categories->arraysize(); $category = ''; for ($i=0;$i<$iSize;$i++) { $struct = $categories->arraymem($i); $bPrimary = $struct->structmem('isPrimary'); if ($bPrimary) $bPrimary = $bPrimary->scalarval(); else if (!$category) $bPrimary = 1; // "Using isPrimary to set the primary category is optional-- // in the absence of this flag, the first struct in the array // will be assigned the primary category for the post." (MT doc) if ($bPrimary) { $category = $struct->structmem('categoryId'); $category = $category->scalarval(); } } return _mt_setPostCategories($itemid, $username, $password, $category); } // mt.getRecentPostTitles $f_mt_getRecentPostTitles_sig = array(array( // return $xmlrpcArray, // array of structs // params $xmlrpcString, // blogid $xmlrpcString, // userid $xmlrpcString, // password, $xmlrpcInt // number of posts )); $f_mt_getRecentPostTitles_doc = 'Returns a bandwidth-friendly list of the most recent posts in the system.'; function f_mt_getRecentPostTitles($m) { $blogid = intval(_getScalar($m, 0)); $username = _getScalar($m, 1); $password = _getScalar($m, 2); $iAmount = intval(_getScalar($m, 3)); return _mt_getRecentPostTitles($blogid, $username, $password, $iAmount); } // mt.getTrackbackPings $f_mt_getTrackbackPings_sig = array(array( // return $xmlrpcArray, // array of structs // params $xmlrpcString // postid )); $f_mt_getTrackbackPings_doc = '(this is currently just a placeholder. It returns an empty array.)'; function f_mt_getTrackbackPings($m) { global $manager; $itemid = intval(_getScalar($m, 0)); $trackbacks = array (); $tbstruct = array (); $manager->notify('RetrieveTrackback', array ('tb_id' => $itemid, 'trackbacks' => & $trackbacks)); while (list(,$v) = each ($trackbacks)) { $tbstruct[] = new xmlrpcval( array( "pingTitle" => new xmlrpcval($v['title'], "string"), "pingURL" => new xmlrpcval($v['url'], "string"), "pingIP" => new xmlrpcval($v['ip'], "string") ) ,'struct'); } return new xmlrpcresp(new xmlrpcval( $tbstruct , "array")); } $functionDefs = array_merge($functionDefs, array( "mt.supportedMethods" => array( "function" => "f_mt_supportedMethods", "signature" => $f_mt_supportedMethods_sig, "docstring" => $f_mt_supportedMethods_doc), "mt.supportedTextFilters" => array( "function" => "f_mt_supportedTextFilters", "signature" => $f_mt_supportedTextFilters_sig, "docstring" => $f_mt_supportedTextFilters_doc), "mt.getCategoryList" => array( "function" => "f_mt_getCategoryList", "signature" => $f_mt_getCategoryList_sig, "docstring" => $f_mt_getCategoryList_doc), "mt.publishPost" => array( "function" => "f_mt_publishPost", "signature" => $f_mt_publishPost_sig, "docstring" => $f_mt_publishPost_doc), "mt.getPostCategories" => array( "function" => "f_mt_getPostCategories", "signature" => $f_mt_getPostCategories_sig, "docstring" => $f_mt_getPostCategories_doc), "mt.setPostCategories" => array( "function" => "f_mt_setPostCategories", "signature" => $f_mt_setPostCategories_sig, "docstring" => $f_mt_setPostCategories_doc), "mt.getRecentPostTitles" => array( "function" => "f_mt_getRecentPostTitles", "signature" => $f_mt_getRecentPostTitles_sig, "docstring" => $f_mt_getRecentPostTitles_doc), "mt.getTrackbackPings" => array( "function" => "f_mt_getTrackbackPings", "signature" => $f_mt_getTrackbackPings_sig, "docstring" => $f_mt_getTrackbackPings_doc) ) ); function _mt_setPostCategories($itemid, $username, $password, $category) { global $manager; // login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in"); // check if item exists if (!$manager->existsItem($itemid,1,1)) return _error(6,"No such item ($itemid)"); $blogid = getBlogIDFromItemID($itemid); $blog = new BLOG($blogid); if (!$mem->canAlterItem($itemid)) return _error(7,"Not allowed to alter item"); $old =& $manager->getItem($itemid,1,1); $catid = $blog->getCategoryIdFromName($category); $publish = 0; if ($old['draft'] && $publish) { $wasdraft = 1; $publish = 1; } else { $wasdraft = 0; } return _edititem($itemid, $username, $password, $catid, $old['title'], $old['body'], $old['more'], $wasdraft, $publish, $old['closed']); } function _mt_getPostCategories($itemid, $username, $password) { global $manager; // login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in"); // check if item exists if (!$manager->existsItem($itemid,1,1)) return _error(6,"No such item ($itemid)"); $blogid = getBlogIDFromItemID($itemid); $blog = new BLOG($blogid); if (!$mem->canAlterItem($itemid)) return _error(7, 'You are not allowed to request this information'); $info =& $manager->getItem($itemid,1,1); $catName = $blog->getCategoryName($info['catid']); $struct = new xmlrpcval( array( 'categoryId' => new xmlrpcval($catName, 'string'), 'categoryName' => new xmlrpcval($catName, 'string'), 'isPrimary' => new xmlrpcval(1, 'boolean') ), 'struct' ); return new xmlrpcresp(new xmlrpcval(array($struct), 'array')); } function _mt_publishPost($itemid, $username, $password) { global $manager; if (!$manager->existsItem($itemid,1,1)) return _error(6,"No such item ($itemid)"); // get item data $blogid = getBlogIDFromItemID($itemid); $blog = new BLOG($blogid); $old =& $manager->getItem($itemid,1,1); return _edititem($itemid, $username, $password, $old['catid'], $old['title'], $old['body'], $old['more'], $old['draft'], 1, $old['closed']); } function _mt_categoryList($blogid, $username, $password) { // 1. login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in"); // check if on team and blog exists if (!BLOG::existsID($blogid)) return _error(2,"No such blog ($blogid)"); if (!$mem->teamRights($blogid)) return _error(3,"Not a team member"); $b = new BLOG($blogid); $categorystruct = array(); $query = "SELECT cname, cdesc, catid" . ' FROM '.sql_table('category') . " WHERE cblog=" . intval($blogid) . " ORDER BY cname"; $r = sql_query($query); while ($obj = sql_fetch_object($r)) { $categorystruct[] = new xmlrpcval( array( "categoryName" => new xmlrpcval($obj->cname,"string"), "categoryId" => new xmlrpcval($obj->cname,"string") ) ,'struct'); } return new xmlrpcresp(new xmlrpcval( $categorystruct , "array")); } function _mt_getRecentPostTitles($blogid, $username, $password, $iAmount) { $blogid = intval($blogid); $iAmount = intval($iAmount); // 1. login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in"); // 2. check if allowed if (!BLOG::existsID($blogid)) return _error(2,"No such blog ($blogid)"); if (!$mem->teamRights($blogid)) return _error(3,"Not a team member"); $iAmount = intval($iAmount); if ($iAmount < 1) return _error(5,"Amount parameter must be positive"); // 3. create and return list of recent items // Struct returned has dateCreated, userid, postid and title $blog = new BLOG($blogid); $structarray = array(); // the array in which the structs will be stored $query = "SELECT inumber, ititle as title, itime, iauthor" .' FROM '.sql_table('item') ." WHERE iblog=$blogid" ." ORDER BY itime DESC" ." LIMIT $iAmount"; $r = sql_query($query); while ($row = sql_fetch_assoc($r)) { $newstruct = new xmlrpcval(array( "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"), "postid" => new xmlrpcval($row['inumber'],"string"), "title" => new xmlrpcval($row['title'],"string"), "userid" => new xmlrpcval($row['iauthor'],"string") ),'struct'); array_push($structarray, $newstruct); } return new xmlrpcresp(new xmlrpcval( $structarray , "array")); } ?>