Files
@ c7d7e38b2269
Branch filter:
Location: hot67beta/plugins/xmlrpc/blogger.php
c7d7e38b2269
18.7 KiB
text/x-php
Initial import of the site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | <?php
/**
* @version $Id: blogger.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgXMLRPCBlogger extends JPlugin
{
function plgXMLRPCBlogger(&$subject, $config)
{
parent::__construct($subject, $config);
$this->loadLanguage( '', JPATH_ADMINISTRATOR );
}
/**
* @return array An array of associative arrays defining the available methods
*/
function onGetWebServices()
{
global $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
return array
(
'blogger.getUsersBlogs' => array(
'function' => 'plgXMLRPCBloggerServices::getUserBlogs',
'docstring' => JText::_('Returns a list of weblogs to which an author has posting privileges.'),
'signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString ))
),
'blogger.getUserInfo' => array(
'function' => 'plgXMLRPCBloggerServices::getUserInfo',
'docstring' => JText::_('Returns information about an author in the system.'),
'signature' => array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString))
),
'blogger.getPost' => array(
'function' => 'plgXMLRPCBloggerServices::getPost',
'docstring' => JText::_('Returns information about a specific post.'),
'signature' => array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString))
),
'blogger.getRecentPosts' => array(
'function' => 'plgXMLRPCBloggerServices::getRecentPosts',
'docstring' => JText::_('Returns a list of the most recent posts in the system.'),
'signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcInt))
),
'blogger.getTemplate' => array(
'function' => 'plgXMLRPCBloggerServices::getTemplate',
'docstring' => '',
'signature' => array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString))
),
'blogger.setTemplate' => array(
'function' => 'plgXMLRPCBloggerServices::setTemplate',
'docstring' => '',
'signature' => array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString))
),
'blogger.newPost' => array(
'function' => 'plgXMLRPCBloggerServices::newPost',
'docstring' => JText::_('Creates a new post, and optionally publishes it.'),
'signature' => array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean))
),
'blogger.deletePost' => array(
'function' => 'plgXMLRPCBloggerServices::deletePost',
'docstring' => JText::_('Deletes a post.'),
'signature' => array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean))
),
'blogger.editPost' => array(
'function' => 'plgXMLRPCBloggerServices::editPost',
'docstring' => JText::_('Updates the information about an existing post.'),
'signature' => array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean))
)
);
}
}
class plgXMLRPCBloggerServices
{
/*
* Note : blogger.getUsersBlogs will make more sense once we support multiple blogs
*/
function getUserBlogs($appkey, $username, $password)
{
global $mainframe, $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
if(!plgXMLRPCBloggerHelper::authenticateUser($username, $password)) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_("Login Failed"));
}
$user =& JFactory::getUser($username);
plgXMLRPCBloggerHelper::getUserAid( $user );
// Handle the access permissions part of the main database query
if ($user->authorize('com_content', 'edit', 'content', 'all')) {
$xwhere = '';
} else {
$xwhere = ' AND a.published = 1 AND b.published = 1';
}
$gid = $user->get('aid', 0);
$access_check = ' AND a.access <= '.(int) $gid .
' AND b.access <= '.(int) $gid;
// Query of categories within section
$query = 'SELECT a.id, a.title, a.section, ' .
' CONCAT_WS(\'/\', a.title, b.title) AS catName' .
' FROM #__categories AS a' .
' LEFT JOIN #__sections AS b ON a.section = b.id' .
$xwhere.
$access_check;
$db = &JFactory::getDBO();
$db->setQuery( $query );
$categories = $db->loadObjectList();
$structarray = array();
foreach( $categories AS $category ) {
if (intval($category->section) > 0) {
$blog = new xmlrpcval(array(
'url' => new xmlrpcval(JURI::base(), $xmlrpcString),
'blogid' => new xmlrpcval($category->id, $xmlrpcString),
'blogName' => new xmlrpcval($category->catName, $xmlrpcString)
), 'struct');
array_push($structarray, $blog);
}
}
return new xmlrpcresp(new xmlrpcval( $structarray , $xmlrpcArray));
}
function getUserInfo($appkey, $username, $password)
{
global $xmlrpcerruser, $xmlrpcStruct;
if(!plgXMLRPCBloggerHelper::authenticateUser($username, $password)) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_("Login Failed"));
}
$user =& JFactory::getUser($username);
plgXMLRPCBloggerHelper::getUserAid( $user );
$struct = new xmlrpcval(
array(
'nickname' => new xmlrpcval($user->get('username')),
'userid' => new xmlrpcval($user->get('id')),
'url' => new xmlrpcval(''),
'email' => new xmlrpcval($user->get('email')),
'lastname' => new xmlrpcval($user->get('name')),
'firstname' => new xmlrpcval($user->get('name'))
), $xmlrpcStruct);
return new xmlrpcresp($struct);
}
function getPost($appkey, $postid, $username, $password)
{
global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
if(!plgXMLRPCBloggerHelper::authenticateUser($username, $password)) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_("Login Failed"));
}
$user =& JFactory::getUser($username);
plgXMLRPCBloggerHelper::getUserAid( $user );
$db = &JFactory::getDBO();
$where = 'a.id = ' . (int) $postid;
$canReadUnpublished = $user->authorize('com_content', 'edit', 'content', 'all');
if ($canReadUnpublished) {
$publishedWhere = '';
} else {
$publishedWhere = ' AND u.published = 1 AND b.published = 1';
}
$nullDate = $db->getNullDate();
$date =& JFactory::getDate();
$now = $date->toMySQL();
$query = 'SELECT a.title AS title,'
. ' a.created AS created,'
. ' a.introtext AS introtext,'
. ' a.fulltext AS ftext,'
. ' a.id AS id,'
. ' a.created_by AS created_by'
. ' FROM #__content AS a'
. ' INNER JOIN #__categories AS b ON b.id=a.catid'
. ' INNER JOIN #__sections AS u ON u.id = a.sectionid'
. ' WHERE '.$where
. $publishedWhere
. ' AND a.access <= '.(int) $user->get( 'aid' )
. ' AND b.access <= '.(int) $user->get( 'aid' )
. ' AND u.access <= '.(int) $user->get( 'aid' )
. ' AND ( a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' )'
. ' AND ( a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )'
;
$db->setQuery( $query );
$item = $db->loadObject();
if ($item === null) {
return new xmlrpcresp(0, $xmlrpcerruser+2, JText::_("Access Denied"));
}
$content = '<title>'.$item->title.'</title>';
$content .= $item->introtext.'<more_text>'.$item->ftext.'</more_text>';
$struct = new xmlrpcval(
array(
'userid' => new xmlrpcval($item->created_by),
'dateCreated' => new xmlrpcval($item->created),
'content' => new xmlrpcval($content),
'postid' => new xmlrpcval($item->id)
), $xmlrpcStruct);
return new xmlrpcresp($struct);
}
function newPost($appkey, $blogid, $username, $password, $content, $publish)
{
global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
if(!plgXMLRPCBloggerHelper::authenticateUser($username, $password)) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_("Login Failed"));
}
$user =& JFactory::getUser($username);
plgXMLRPCBloggerHelper::getUserAid( $user );
if ($user->get('gid') < 19) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('ALERTNOTAUTH'));
}
// Create a user access object for the user
$access = new stdClass();
$access->canEdit = $user->authorize('com_content', 'edit', 'content', 'all');
$access->canEditOwn = $user->authorize('com_content', 'edit', 'content', 'own');
$access->canPublish = $user->authorize('com_content', 'publish', 'content', 'all');
if (!($access->canEdit || $access->canEditOwn)) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('ALERTNOTAUTH'));
}
$db =& JFactory::getDBO();
// load plugin params info
$plugin =& JPluginHelper::getPlugin('xmlrpc','blogger');
$params = new JParameter( $plugin->params );
$blogid = (int) $blogid;
// load the category
$cat =& JTable::getInstance('category');
$cat->load($blogid);
// create a new content item
$item =& JTable::getInstance('content');
$item->title = plgXMLRPCBloggerHelper::getPostTitle($content);
$item->introtext = plgXMLRPCBloggerHelper::getPostIntroText($content);
$item->fulltext = plgXMLRPCBloggerHelper::getPostFullText($content);
$item->catid = $blogid;
$item->sectionid = $cat->section;
$date =& JFactory::getDate();
$item->created = $date->toMySQL();
$item->created_by = $user->get('id');
$item->publish_up = $date->toMySQL();
$item->publish_down = $db->getNullDate();
$item->state = ($publish && $access->canPublish) ? 1 : 0;
if (!$item->check()) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Post check failed') );
}
$item->version++;
if (!$item->store()) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Post store failed') );
}
return new xmlrpcresp(new xmlrpcval($item->id, $xmlrpcString));
}
function editPost($appkey, $postid, $username, $password, $content, $publish)
{
global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
if(!plgXMLRPCBloggerHelper::authenticateUser($username, $password)) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_("Login Failed"));
}
$user =& JFactory::getUser($username);
plgXMLRPCBloggerHelper::getUserAid( $user );
// Create a user access object for the user
$access = new stdClass();
$access->canEdit = $user->authorize('com_content', 'edit', 'content', 'all');
$access->canEditOwn = $user->authorize('com_content', 'edit', 'content', 'own');
$access->canPublish = $user->authorize('com_content', 'publish', 'content', 'all');
if (!($access->canEdit || $access->canEditOwn)) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('ALERTNOTAUTH'));
}
// load the row from the db table
$item =& JTable::getInstance('content');
if(!$item->load( $postid )) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Sorry, no such post') );
}
if($item->isCheckedOut($user->get('id'))) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Sorry, post is already being edited') );
}
//lock the item
$item->checkout($user->id);
$item->title = plgXMLRPCBloggerHelper::getPostTitle($content);
$item->introtext = plgXMLRPCBloggerHelper::getPostIntroText($content);
$item->fulltext = plgXMLRPCBloggerHelper::getPostFullText($content);
if (!$item->check()) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Post check failed') );
}
$item->version++;
if (!$item->store()) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Post store failed') );
}
$item->state = ($publish && $access->canPublish) ? 1 : 0;
//lock the item
$item->checkout();
return new xmlrpcresp(new xmlrpcval('true', $xmlrpcBoolean));
}
function deletePost($appkey, $postid, $username, $password, $publish)
{
global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
if(!plgXMLRPCBloggerHelper::authenticateUser($username, $password)) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_("Login Failed"));
}
$user =& JFactory::getUser($username);
plgXMLRPCBloggerHelper::getUserAid( $user );
if ($user->get('gid') < 23) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('ALERTNOTAUTH'));
}
// load the row from the db table
$item =& JTable::getInstance('content');
if(!$item->load( $postid )) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Sorry, no such post') );
}
if($item->isCheckedOut($user->get('id'))) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Sorry, post is already being edited') );
}
//lock the item
$item->checkout();
$item->state = -2;
$item->ordering = 0;
if (!$item->store()) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Post delete failed') );
}
return new xmlrpcresp(new xmlrpcval('true', $xmlrpcBoolean));
}
/**
* Blogger API - blogger.getRecentPosts
*
* @param xmlrpcmessage XML-RPC message passed to the method
* @return xmlrpcresp XML-RPC response
*/
function getRecentPosts($appkey, $blogid, $username, $password, $numposts)
{
global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
if(!plgXMLRPCBloggerHelper::authenticateUser($username, $password)) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_("Login Failed"));
}
$user =& JFactory::getUser($username);
plgXMLRPCBloggerHelper::getUserAid( $user );
// load plugin params info
$plugin =& JPluginHelper::getPlugin('xmlrpc','blogger');
$params = new JParameter( $plugin->params );
$db =& JFactory::getDBO();
$nullDate = $db->getNullDate();
$date =& JFactory::getDate();
$now = $date->toMySQL();
$blogid = (int) $blogid;
$canReadUnpublished = $user->authorize('com_content', 'edit', 'content', 'all');
if ($canReadUnpublished) {
$publishedWhere = '';
$publishTimeWhere = '';
} else {
$publishedWhere = ' AND u.published = 1 AND b.published = 1';
$publishTimeWhere = ' AND ( a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' )'
. ' AND ( a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )';
}
$query = 'SELECT a.title AS title,'
. ' a.created AS created,'
. ' a.introtext AS introtext,'
. ' a.fulltext AS ftext,'
. ' a.id AS id,'
. ' a.created_by AS created_by'
. ' FROM #__content AS a'
. ' INNER JOIN #__categories AS b ON b.id=a.catid'
. ' INNER JOIN #__sections AS u ON u.id = a.sectionid'
. ' WHERE a.catid = '. $blogid
. $publishedWhere
. ' AND a.access <= '.(int) $user->get( 'aid' )
. ' AND b.access <= '.(int) $user->get( 'aid' )
. ' AND u.access <= '.(int) $user->get( 'aid' )
. $publishTimeWhere
;
$db->setQuery($query, 0, $numposts);
$items = $db->loadObjectList();
if ($items === null) {
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('No posts available, or an error has occured.') );
}
$structArray = array();
foreach ($items as $item)
{
$content = '<title>'.$item->title.'</title>';
$content .= $item->introtext.'<more_text>'.$item->ftext.'</more_text>';
$structArray[] = new xmlrpcval(array(
'userid' => new xmlrpcval($item->created_by),
'dateCreated' => new xmlrpcval($item->created),
'content' => new xmlrpcval($content),
'postid' => new xmlrpcval($item->id)
), 'struct');
}
return new xmlrpcresp(new xmlrpcval( $structArray , $xmlrpcArray));
}
function getTemplate($appkey, $blogid, $username, $password, $templateType)
{
global $xmlrpcerruser;
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Method not implemented') );
}
function setTemplate($appkey, $blogid, $username, $password, $template, $templateType)
{
global $xmlrpcerruser;
return new xmlrpcresp(0, $xmlrpcerruser+1, JText::_('Method not implemented') );
}
}
class plgXMLRPCBloggerHelper
{
function getUserAid( &$user ) {
$acl = &JFactory::getACL();
//Get the user group from the ACL
$grp = $acl->getAroGroup($user->get('id'));
// Mark the user as logged in
$user->set('guest', 0);
$user->set('aid', 1);
// Fudge Authors, Editors, Publishers and Super Administrators into the special access group
if ($acl->is_group_child_of($grp->name, 'Registered') ||
$acl->is_group_child_of($grp->name, 'Public Backend')) {
$user->set('aid', 2);
}
}
function authenticateUser($username, $password)
{
// Get the global JAuthentication object
jimport( 'joomla.user.authentication');
$auth = & JAuthentication::getInstance();
$credentials = array( 'username' => $username, 'password' => $password );
$options = array();
$response = $auth->authenticate($credentials, $options);
return $response->status === JAUTHENTICATE_STATUS_SUCCESS;
}
function getPostTitle($content)
{
$title = '';
if ( preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle) )
{
$title = $matchtitle[0];
$title = preg_replace('/<title>/si', '', $title);
$title = preg_replace('/<\/title>/si', '', $title);
}
if (empty( $title )) {
$title = substr( $content, 0, 20 );
}
return $title;
}
function getPostCategory($content)
{
$category = 0;
$match = array();
if ( preg_match('/<category>(.+?)<\/category>/is', $content, $match) )
{
$category = trim($match[1], ',');
$category = explode(',', $category);
}
return $category;
}
function getPostIntroText($content)
{
return plgXMLRPCBloggerHelper::removePostData($content); //substr($string, 0, strpos($string, '<more_text>'));
}
function getPostFullText($content)
{
$match = array();
if ( preg_match('/<more_text>(.+?)<\/more_text>/is', $content, $match) )
{
$fulltext = $match[0];
$fulltext = preg_replace('/<more_text>/si', '', $fulltext);
$fulltext = preg_replace('/<\/more_text>/si', '', $fulltext);
}
return $fulltext;
}
function removePostData($content)
{
$content = preg_replace('/<title>(.+?)<\/title>/si', '', $content);
$content = preg_replace('/<category>(.+?)<\/category>/si', '', $content);
$content = preg_replace('/<more_text>(.+?)<\/more_text>/si', '', $content);
$content = trim($content);
return $content;
}
}
|