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 / xoopsapi.php < prev   
Encoding:
PHP Script  |  2005-11-03  |  16.9 KB  |  349 lines

  1. <?php
  2. // $Id: xoopsapi.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. if (!defined('XOOPS_ROOT_PATH')) {
  32.     die("XOOPS root path not defined");
  33. }
  34. require_once XOOPS_ROOT_PATH.'/class/xml/rpc/xmlrpcapi.php';
  35.  
  36. class XoopsApi extends XoopsXmlRpcApi
  37. {
  38.  
  39.     function XoopsApi(&$params, &$response, &$module)
  40.     {
  41.         $this->XoopsXmlRpcApi($params, $response, $module);
  42.     }
  43.  
  44.     function newPost()
  45.     {
  46.         if (!$this->_checkUser($this->params[1], $this->params[2])) {
  47.             $this->response->add(new XoopsXmlRpcFault(104));
  48.         } else {
  49.             if (!$fields =& $this->_getPostFields(null, $this->params[0])) {
  50.                 $this->response->add(new XoopsXmlRpcFault(106));
  51.             } else {
  52.                 $missing = array();
  53.                 foreach ($fields as $tag => $detail) {
  54.                     if (!isset($this->params[3][$tag])) {
  55.                         $data = $this->_getTagCdata($this->params[3]['xoops_text'], $tag, true);
  56.                         if (trim($data) == ''){
  57.                             if ($detail['required']) {
  58.                                 $missing[] = $tag;
  59.                             }
  60.                         } else {
  61.                             $post[$tag] =& $data;
  62.                         }
  63.                     } else {
  64.                         $post[$tag] =& $this->params[3][$tag];
  65.                     }
  66.                 }
  67.                 if (count($missing) > 0) {
  68.                     $msg = '';
  69.                     foreach ($missing as $m) {
  70.                         $msg .= '<'.$m.'> ';
  71.                     }
  72.                     $this->response->add(new XoopsXmlRpcFault(109, $msg));
  73.                 } else {
  74.                     // will be removed... don't worry if this looks bad
  75.                     include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newsstory.php';
  76.                     $story = new NewsStory();
  77.                     $error = false;
  78.                     if (intval($this->params[4]) > 0) {
  79.                         if (!$this->_checkAdmin()) {
  80.                             // non admin users cannot publish
  81.                             $error = true;
  82.                             $this->response->add(new XoopsXmlRpcFault(111));
  83.                         } else {
  84.                             $story->setType('admin');
  85.                             $story->setApproved(true);
  86.                             $story->setPublished(time());
  87.                         }
  88.                     } else {
  89.                         if (!$this->_checkAdmin()) {
  90.                             $story->setType('user');
  91.                         } else {
  92.                             $story->setType('admin');
  93.                         }
  94.                     }
  95.                     if (!$error) {
  96.                         if (isset($post['categories']) && !empty($post['categories'][0])) {
  97.                             $story->setTopicId(intval($post['categories'][0]['categoryId']));
  98.                         } else {
  99.                             $story->setTopicId(1);
  100.                         }
  101.                         $story->setTitle(addslashes(trim($post['title'])));
  102.                         if (isset($post['moretext'])) {
  103.                             $story->setBodytext(addslashes(trim($post['moretext'])));
  104.                         }
  105.                         if (!isset($post['hometext'])) {
  106.                             $story->setHometext(addslashes(trim($this->params[3]['xoops_text'])));
  107.                         } else {
  108.                             $story->setHometext(addslashes(trim($post['hometext'])));
  109.                         }
  110.                         $story->setUid($this->user->getVar('uid'));
  111.                         $story->setHostname($_SERVER['REMOTE_ADDR']);
  112.                         if (!$this->_checkAdmin()) {
  113.                             $story->setNohtml(1);
  114.                         } else {
  115.                             $story->setNohtml(0);
  116.                         }
  117.                         $story->setNosmiley(0);
  118.                         $story->setNotifyPub(1);
  119.                         $story->setTopicalign('R');
  120.                         $ret = $story->store();
  121.                         if (!$ret) {
  122.                             $this->response->add(new XoopsXmlRpcFault(106));
  123.                         } else {
  124.                             $this->response->add(new XoopsXmlRpcString($ret));
  125.                         }
  126.                     }
  127.                 }
  128.             }
  129.         }
  130.     }
  131.  
  132.     function editPost()
  133.     {
  134.         if (!$this->_checkUser($this->params[1], $this->params[2])) {
  135.             $this->response->add(new XoopsXmlRpcFault(104));
  136.         } else {
  137.             if (!$fields =& $this->_getPostFields($this->params[0])) {
  138.             } else {
  139.                 $missing = array();
  140.                 foreach ($fields as $tag => $detail) {
  141.                     if (!isset($this->params[3][$tag])) {
  142.                         $data = $this->_getTagCdata($this->params[3]['xoops_text'], $tag, true);
  143.                         if (trim($data) == ''){
  144.                             if ($detail['required']) {
  145.                                 $missing[] = $tag;
  146.                             }
  147.                         } else {
  148.                             $post[$tag] = $data;
  149.                         }
  150.                     } else {
  151.                         $post[$tag] = $this->params[3][$tag];
  152.                     }
  153.                 }
  154.                 if (count($missing) > 0) {
  155.                     $msg = '';
  156.                     foreach ($missing as $m) {
  157.                         $msg .= '<'.$m.'> ';
  158.                     }
  159.                     $this->response->add(new XoopsXmlRpcFault(109, $msg));
  160.                 } else {
  161.                     // will be removed... don't worry if this looks bad
  162.                     include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newsstory.php';
  163.                     $story = new NewsStory($this->params[0]);
  164.                     $storyid = $story->storyid();
  165.                     if (empty($storyid)) {
  166.                         $this->response->add(new XoopsXmlRpcFault(106));
  167.                     } elseif (!$this->_checkAdmin()) {
  168.                         $this->response->add(new XoopsXmlRpcFault(111));
  169.                     } else {
  170.                         $story->setTitle(addslashes(trim($post['title'])));
  171.                         if (isset($post['moretext'])) {
  172.                             $story->setBodytext(addslashes(trim($post['moretext'])));
  173.                         }
  174.                         if (!isset($post['hometext'])) {
  175.                             $story->setHometext(addslashes(trim($this->params[3]['xoops_text'])));
  176.                         } else {
  177.                             $story->setHometext(addslashes(trim($post['hometext'])));
  178.                         }
  179.                         if ($this->params[4]) {
  180.                             $story->setApproved(true);
  181.                             $story->setPublished(time());
  182.                         }
  183.                         $story->setTopicalign('R');
  184.                         if (!$story->store()) {
  185.                             $this->response->add(new XoopsXmlRpcFault(106));
  186.                         } else {
  187.                             $this->response->add(new XoopsXmlRpcBoolean(true));
  188.                         }
  189.                     }
  190.                 }
  191.             }
  192.         }
  193.     }
  194.  
  195.     function deletePost()
  196.     {
  197.         if (!$this->_checkUser($this->params[1], $this->params[2])) {
  198.             $this->response->add(new XoopsXmlRpcFault(104));
  199.         } else {
  200.             if (!$this->_checkAdmin()) {
  201.                 $this->response->add(new XoopsXmlRpcFault(111));
  202.             } else {
  203.                 // will be removed... don't worry if this looks bad
  204.                 include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newsstory.php';
  205.                 $story = new NewsStory($this->params[0]);
  206.                 if (!$story->delete()) {
  207.                     $this->response->add(new XoopsXmlRpcFault(106));
  208.                 } else {
  209.                     $this->response->add(new XoopsXmlRpcBoolean(true));
  210.                 }
  211.             }
  212.         }
  213.     }
  214.  
  215.     // currently returns the same struct as in metaWeblogApi
  216.     function &getPost($respond=true)
  217.     {
  218.         if (!$this->_checkUser($this->params[1], $this->params[2])) {
  219.             $this->response->add(new XoopsXmlRpcFault(104));
  220.         } else {
  221.             // will be removed... don't worry if this looks bad
  222.             include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newsstory.php';
  223.             $story = new NewsStory($this->params[0]);
  224.             $ret = array('uid' => $story->uid(), 'published' => $story->published(), 'storyid' => $story->storyId(), 'title' => $story->title('Edit'), 'hometext' => $story->hometext('Edit'), 'moretext' => $story->bodytext('Edit'));
  225.             if (!$respond) {
  226.                 return $ret;
  227.             } else {
  228.                 if (!$ret) {
  229.                     $this->response->add(new XoopsXmlRpcFault(106));
  230.                 } else {
  231.                     $struct = new XoopsXmlRpcStruct();
  232.                     $content = '';
  233.                     foreach ($ret as $key => $value) {
  234.                         switch($key) {
  235.                         case 'uid':
  236.                             $struct->add('userid', new XoopsXmlRpcString($value));
  237.                             break;
  238.                         case 'published':
  239.                             $struct->add('dateCreated', new XoopsXmlRpcDatetime($value));
  240.                             break;
  241.                         case 'storyid':
  242.                             $struct->add('postid', new XoopsXmlRpcString($value));
  243.                             $struct->add('link', new XoopsXmlRpcString(XOOPS_URL.'/modules/news/article.php?item_id='.$value));
  244.                             $struct->add('permaLink', new XoopsXmlRpcString(XOOPS_URL.'/modules/news/article.php?item_id='.$value));
  245.                             break;
  246.                         case 'title':
  247.                             $struct->add('title', new XoopsXmlRpcString($value));
  248.                             break;
  249.                         default :
  250.                             $content .= '<'.$key.'>'.trim($value).'</'.$key.'>';
  251.                             break;
  252.                         }
  253.                     }
  254.                     $struct->add('description', new XoopsXmlRpcString($content));
  255.                     $this->response->add($struct);
  256.                 }
  257.             }
  258.         }
  259.     }
  260.  
  261.     function &getRecentPosts($respond=true)
  262.     {
  263.         if (!$this->_checkUser($this->params[1], $this->params[2])) {
  264.             $this->response->add(new XoopsXmlRpcFault(104));
  265.         } else {
  266.             include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newsstory.php';
  267.             if (isset($this->params[4]) && intval($this->params[4]) > 0) {
  268.                 $stories =& NewsStory::getAllPublished(intval($this->params[3]), 0, $this->params[4]);
  269.             } else {
  270.                 $stories =& NewsStory::getAllPublished(intval($this->params[3]));
  271.             }
  272.             $scount = count($stories);
  273.             $ret = array();
  274.             for ($i = 0; $i < $scount; $i++) {
  275.                 $ret[] = array('uid' => $stories[$i]->uid(), 'published' => $stories[$i]->published(), 'storyid' => $stories[$i]->storyId(), 'title' => $stories[$i]->title('Edit'), 'hometext' => $stories[$i]->hometext('Edit'), 'moretext' => $stories[$i]->bodytext('Edit'));
  276.             }
  277.             if (!$respond) {
  278.                 return $ret;
  279.             } else {
  280.                 if (count($ret) == 0) {
  281.                     $this->response->add(new XoopsXmlRpcFault(106, 'Found 0 Entries'));
  282.                 } else {
  283.                     $arr = new XoopsXmlRpcArray();
  284.                     $count = count($ret);
  285.                     for ($i = 0; $i < $count; $i++) {
  286.                         $struct = new XoopsXmlRpcStruct();
  287.                         $content = '';
  288.                         foreach($ret[$i] as $key => $value) {
  289.                             switch($key) {
  290.                             case 'uid':
  291.                                 $struct->add('userid', new XoopsXmlRpcString($value));
  292.                                 break;
  293.                             case 'published':
  294.                                 $struct->add('dateCreated', new XoopsXmlRpcDatetime($value));
  295.                                 break;
  296.                             case 'storyid':
  297.                                 $struct->add('postid', new XoopsXmlRpcString($value));
  298.                                 $struct->add('link', new XoopsXmlRpcString(XOOPS_URL.'/modules/news/article.php?item_id='.$value));
  299.                                 $struct->add('permaLink', new XoopsXmlRpcString(XOOPS_URL.'/modules/news/article.php?item_id='.$value));
  300.                                 break;
  301.                             case 'title':
  302.                                 $struct->add('title', new XoopsXmlRpcString($value));
  303.                                 break;
  304.                             default :
  305.                                 $content .= '<'.$key.'>'.trim($value).'</'.$key.'>';
  306.                                 break;
  307.                             }
  308.                         }
  309.                         $struct->add('description', new XoopsXmlRpcString($content));
  310.                         $arr->add($struct);
  311.                         unset($struct);
  312.                     }
  313.                     $this->response->add($arr);
  314.                 }
  315.             }
  316.         }
  317.     }
  318.  
  319.     function &getCategories($respond=true)
  320.     {
  321.         if (!$this->_checkUser($this->params[1], $this->params[2])) {
  322.             $this->response->add(new XoopsXmlRpcFault(104));
  323.         } else {
  324.             include_once XOOPS_ROOT_PATH.'/class/xoopstopic.php';
  325.             $db =& Database::getInstance();
  326.             $xt = new XoopsTopic($db->prefix('topics'));
  327.             $ret = $xt->getTopicsList();
  328.             if (!$respond) {
  329.                 return $ret;
  330.             } else {
  331.                 if (count($ret) == 0) {
  332.                     $this->response->add(new XoopsXmlRpcFault(106, 'Found 0 Entries'));
  333.                 } else {
  334.                     $arr = new XoopsXmlRpcArray();
  335.                     foreach ($ret as $topic_id => $topic_vars) {
  336.                         $struct = new XoopsXmlRpcStruct();
  337.                         $struct->add('categoryId', new XoopsXmlRpcString($topic_id));
  338.                         $struct->add('categoryName', new XoopsXmlRpcString($topic_vars['title']));
  339.                         $struct->add('categoryPid', new XoopsXmlRpcString($topic_vars['pid']));
  340.                         $arr->add($struct);
  341.                         unset($struct);
  342.                     }
  343.                     $this->response->add($arr);
  344.                 }
  345.             }
  346.         }
  347.     }
  348. }
  349. ?>