PageRenderTime 29ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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