/class/xml/rpc/xmlrpcapi.php

https://gitlab.com/VoyaTrax/vtCMS3 · PHP · 165 lines · 101 code · 20 blank · 44 comment · 15 complexity · 2c38fcad77c8b555be80368d1fc3adbf MD5 · raw file

  1. <?php
  2. /*
  3. You may not change or alter any portion of this comment or credits
  4. of supporting developers from this source code or any supporting source code
  5. which is considered copyrighted (c) material of the original comment or credit authors.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. */
  10. /**
  11. * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
  12. * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
  13. * @package class
  14. * @subpackage xml
  15. * @since 1.0.0
  16. * @author Kazumi Ono (AKA onokazu)
  17. * @version $Id $
  18. */
  19. defined('XOOPS_ROOT_PATH') or die("XOOPS root path not defined");
  20. class XoopsXmlRpcApi
  21. {
  22. // reference to method parameters
  23. var $params;
  24. // reference to xmlrpc document class object
  25. /**
  26. * @var XoopsXmlRpcResponse
  27. */
  28. var $response;
  29. // reference to module class object
  30. /**
  31. * @var XoopsModule
  32. */
  33. var $module;
  34. // map between xoops tags and blogger specific tags
  35. var $xoopsTagMap = array();
  36. // user class object
  37. var $user;
  38. var $isadmin = false;
  39. function XoopsXmlRpcApi(&$params, &$response, &$module)
  40. {
  41. $this->params = $params;
  42. $this->response = $response;
  43. $this->module = $module;
  44. }
  45. function _setUser(&$user, $isadmin = false)
  46. {
  47. if (is_object($user)) {
  48. $this->user = $user;
  49. $this->isadmin = $isadmin;
  50. }
  51. }
  52. function _checkUser($username, $password)
  53. {
  54. $xoops = Xoops::getInstance();
  55. if (isset($this->user)) {
  56. return true;
  57. }
  58. $member_handler = $xoops->getHandlerMember();
  59. $this->user = $member_handler->loginUser(addslashes($username), addslashes($password));
  60. if (!is_object($this->user)) {
  61. unset($this->user);
  62. return false;
  63. }
  64. $moduleperm_handler = $xoops->getHandlerGroupperm();
  65. if (!$moduleperm_handler->checkRight('module_read', $this->module->getVar('mid'), $this->user->getGroups())) {
  66. unset($this->user);
  67. return false;
  68. }
  69. return true;
  70. }
  71. function _checkAdmin()
  72. {
  73. if ($this->isadmin) {
  74. return true;
  75. }
  76. if (!isset($this->user)) {
  77. return false;
  78. }
  79. if (!$this->user->isAdmin($this->module->getVar('mid'))) {
  80. return false;
  81. }
  82. $this->isadmin = true;
  83. return true;
  84. }
  85. function _getPostFields($post_id = null, $blog_id = null)
  86. {
  87. $ret = array();
  88. $ret['title'] = array('required' => true, 'form_type' => 'textbox', 'value_type' => 'text');
  89. $ret['hometext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea');
  90. $ret['moretext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea');
  91. $ret['categories'] = array('required' => false, 'form_type' => 'select_multi', 'data_type' => 'array');
  92. /*
  93. if (!isset($blog_id)) {
  94. if (!isset($post_id)) {
  95. return false;
  96. }
  97. $itemman = $this->mf->get(MANAGER_ITEM);
  98. $item = $itemman->get($post_id);
  99. $blog_id = $item->getVar('sect_id');
  100. }
  101. $sectman = $this->mf->get(MANAGER_SECTION);
  102. $this->section = $sectman->get($blog_id);
  103. $ret = $this->section->getVar('sect_fields');
  104. */
  105. return $ret;
  106. }
  107. function _setXoopsTagMap($xoopstag, $blogtag)
  108. {
  109. if (trim($blogtag) != '') {
  110. $this->xoopsTagMap[$xoopstag] = $blogtag;
  111. }
  112. }
  113. function _getXoopsTagMap($xoopstag)
  114. {
  115. if (isset($this->xoopsTagMap[$xoopstag])) {
  116. return $this->xoopsTagMap[$xoopstag];
  117. }
  118. return $xoopstag;
  119. }
  120. function _getTagCdata(&$text, $tag, $remove = true)
  121. {
  122. $ret = '';
  123. $match = array();
  124. if (preg_match("/\<" . $tag . "\>(.*)\<\/" . $tag . "\>/is", $text, $match)) {
  125. if ($remove) {
  126. $text = str_replace($match[0], '', $text);
  127. }
  128. $ret = $match[1];
  129. }
  130. return $ret;
  131. }
  132. // kind of dirty method to load XOOPS API and create a new object thereof
  133. // returns itself if the calling object is XOOPS API
  134. function _getXoopsApi(&$params)
  135. {
  136. if (strtolower(get_class($this)) != 'xoopsapi') {
  137. require_once(XOOPS_ROOT_PATH . '/class/xml/rpc/xoopsapi.php');
  138. return new XoopsApi($params, $this->response, $this->module);
  139. } else {
  140. return $this;
  141. }
  142. }
  143. }
  144. ?>