1: <?php
2: /**
3: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @package Wicked
9: */
10:
11: /**
12: * @author Duck <duck@obala.net>
13: * @package Wicked
14: */
15: class Wicked_Sync_Wicked extends Wicked_Sync
16: {
17: /**
18: *
19: * @var Horde_Http_Client
20: */
21: protected $_client;
22:
23: public function __construct(array $params = array())
24: {
25: parent::__construct($params);
26: $this->_client = $GLOBALS['injector']->
27: getInstance('Horde_Core_Factory_HttpClient')->
28: create(array('request.username' => $this->_params['user'],
29: 'request.password' => $this->_params['password'])
30: );
31: }
32:
33: /**
34: * Returns a list of available pages.
35: *
36: * @return array An array of all available pages.
37: */
38: public function listPages()
39: {
40: return $this->_getData('list');
41: }
42:
43: /**
44: * Get the wiki source of a page specified by its name.
45: *
46: * @param string $name The name of the page to fetch
47: *
48: * @return string Page data.
49: * @throws Wicked_Exception
50: */
51: public function getPageSource($pageName)
52: {
53: return $this->_getData('getPageSource', array($pageName));
54: }
55:
56: /**
57: * Return basic page information.
58: *
59: * @param string $pageName Page name
60: *
61: * @return array Page data.
62: * @throws Wicked_Exception
63: */
64: public function getPageInfo($pageName)
65: {
66: return $this->_getData('getPageInfo', array($pageName));
67: }
68:
69: /**
70: * Return basic pages information.
71: *
72: * @param array $pages Page names to get info for
73: *
74: * @return array Pages data.
75: * @throws Wicked_Exception
76: */
77: public function getMultiplePageInfo($pages = array())
78: {
79: return $this->_getData('getMultiplePageInfo', array($pages));
80: }
81:
82: /**
83: * Return page history.
84: *
85: * @param string $pagename Page name
86: *
87: * @return array An array of page parameters.
88: */
89: public function getPageHistory($pagename)
90: {
91: return $this->_getData('getPageHistory', array($pagename));
92: }
93:
94: /**
95: * Updates content of a wiki page. If the page does not exist it is
96: * created.
97: *
98: * @param string $pagename Page to edit
99: * @param string $text Page content
100: * @param string $changelog Description of the change
101: *
102: * @throws Wicked_Exception
103: */
104: public function editPage($pagename, $text, $changelog = '')
105: {
106: $this->_getData('edit', array($pagename, $text, $changelog));
107: }
108:
109: /**
110: * Process remote call
111: *
112: * @param string $method Method name to call
113: * @param array $params Array of parameters
114: *
115: * @return mixed
116: * @throws Wicked_Exception
117: */
118: protected function _getData($method, array $params = array())
119: {
120: try {
121: return Horde_Rpc::request(
122: 'xmlrpc',
123: $this->_params['url'],
124: $this->_params['prefix'] . '.' . $method,
125: $this->_client,
126: $params);
127: } catch (Horde_Http_Client_Exception $e) {
128: throw new Wicked_Exception($e);
129: }
130: }
131:
132: }
133: