home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / xml / rpc / xmlrpcapi.php < prev    next >
Encoding:
PHP Script  |  2005-11-03  |  6.2 KB  |  167 lines

  1. <?php
  2. // $Id: xmlrpcapi.php 2 2005-11-02 18:23:29Z skalpa $
  3. //  ------------------------------------------------------------------------ //
  4. //                XOOPS - PHP Content Management System                      //
  5. //                    Copyright (c) 2000 XOOPS.org                           //
  6. //                       <http://www.xoops.org/>                             //
  7. //  ------------------------------------------------------------------------ //
  8. //  This program is free software; you can redistribute it and/or modify     //
  9. //  it under the terms of the GNU General Public License as published by     //
  10. //  the Free Software Foundation; either version 2 of the License, or        //
  11. //  (at your option) any later version.                                      //
  12. //                                                                           //
  13. //  You may not change or alter any portion of this comment or credits       //
  14. //  of supporting developers from this source code or any supporting         //
  15. //  source code which is considered copyrighted (c) material of the          //
  16. //  original comment or credit authors.                                      //
  17. //                                                                           //
  18. //  This program is distributed in the hope that it will be useful,          //
  19. //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
  20. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
  21. //  GNU General Public License for more details.                             //
  22. //                                                                           //
  23. //  You should have received a copy of the GNU General Public License        //
  24. //  along with this program; if not, write to the Free Software              //
  25. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
  26. //  ------------------------------------------------------------------------ //
  27. // Author: Kazumi Ono (AKA onokazu)                                          //
  28. // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
  29. // Project: The XOOPS Project                                                //
  30. // ------------------------------------------------------------------------- //
  31.  
  32.  
  33. class XoopsXmlRpcApi
  34. {
  35.  
  36.     // reference to method parameters 
  37.     var $params;
  38.  
  39.     // reference to xmlrpc document class object
  40.     var $response;
  41.  
  42.     // reference to module class object
  43.     var $module;
  44.  
  45.     // map between xoops tags and blogger specific tags
  46.     var $xoopsTagMap = array();
  47.  
  48.     // user class object
  49.     var $user;
  50.     
  51.     var $isadmin = false;
  52.  
  53.  
  54.  
  55.     function XoopsXmlRpcApi(&$params, &$response, &$module)
  56.     {
  57.         $this->params =& $params;
  58.         $this->response =& $response;
  59.         $this->module =& $module;
  60.     }
  61.  
  62.     function _setUser(&$user, $isadmin = false) 
  63.     {
  64.         if (is_object($user)) {
  65.             $this->user =& $user;
  66.             $this->isadmin = $isadmin;
  67.         }
  68.     }
  69.  
  70.     function _checkUser($username, $password)
  71.     {
  72.         if (isset($this->user)) {
  73.             return true;
  74.         }
  75.         $member_handler =& xoops_gethandler('member');
  76.         $this->user =& $member_handler->loginUser(addslashes($username), addslashes($password));
  77.         if (!is_object($this->user)) {
  78.             unset($this->user);
  79.             return false;
  80.         }
  81.         $moduleperm_handler =& xoops_gethandler('groupperm');
  82.         if (!$moduleperm_handler->checkRight('module_read', $this->module->getVar('mid'), $this->user->getGroups())) {
  83.             unset($this->user);
  84.             return false;
  85.         }
  86.         return true;
  87.     }
  88.  
  89.     function _checkAdmin()
  90.     {
  91.         if ($this->isadmin) {
  92.             return true;
  93.         }
  94.         if (!isset($this->user)) {
  95.             return false;
  96.         }
  97.         if (!$this->user->isAdmin($this->module->getVar('mid'))) {
  98.             return false;
  99.         }
  100.         $this->isadmin = true;
  101.         return true;
  102.     }
  103.  
  104.     function &_getPostFields($post_id = null, $blog_id = null)
  105.     {
  106.         $ret = array();
  107.         $ret['title'] = array('required' => true, 'form_type' => 'textbox', 'value_type' => 'text');
  108.         $ret['hometext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea');
  109.         $ret['moretext'] = array('required' => false, 'form_type' => 'textarea', 'data_type' => 'textarea');
  110.         $ret['categories'] = array('required' => false, 'form_type' => 'select_multi', 'data_type' => 'array');
  111.         /*
  112.         if (!isset($blog_id)) {
  113.             if (!isset($post_id)) {
  114.                 return false;
  115.             }
  116.             $itemman =& $this->mf->get(MANAGER_ITEM);
  117.             $item =& $itemman->get($post_id);
  118.             $blog_id = $item->getVar('sect_id');
  119.         }
  120.         $sectman =& $this->mf->get(MANAGER_SECTION);
  121.         $this->section =& $sectman->get($blog_id);
  122.         $ret =& $this->section->getVar('sect_fields');
  123.         */
  124.         return $ret;
  125.     }
  126.  
  127.     function _setXoopsTagMap($xoopstag, $blogtag)
  128.     {
  129.         if (trim($blogtag) != '') {
  130.             $this->xoopsTagMap[$xoopstag] = $blogtag;
  131.         }
  132.     }
  133.  
  134.     function _getXoopsTagMap($xoopstag)
  135.     {
  136.         if (isset($this->xoopsTagMap[$xoopstag])) {
  137.             return $this->xoopsTagMap[$xoopstag];
  138.         }
  139.         return $xoopstag;
  140.     }
  141.  
  142.     function _getTagCdata(&$text, $tag, $remove = true)
  143.     {
  144.         $ret = '';
  145.         $match = array();
  146.         if (preg_match("/\<".$tag."\>(.*)\<\/".$tag."\>/is", $text, $match)) {
  147.             if ($remove) {
  148.                 $text = str_replace($match[0], '', $text);
  149.             }
  150.             $ret = $match[1];
  151.         }
  152.         return $ret;
  153.     }
  154.  
  155.     // kind of dirty method to load XOOPS API and create a new object thereof
  156.     // returns itself if the calling object is XOOPS API 
  157.     function &_getXoopsApi(&$params)
  158.     {
  159.         if (strtolower(get_class($this)) != 'xoopsapi') {
  160.             require_once(XOOPS_ROOT_PATH.'/class/xml/rpc/xoopsapi.php');
  161.             return new XoopsApi($params, $this->response, $this->module);
  162.         } else {
  163.             return $this;
  164.         }
  165.     }
  166. }
  167. ?>