PageRenderTime 57ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/system/expressionengine/modules/metaweblog_api/mod.metaweblog_api.php

https://bitbucket.org/studiobreakfast/sync
PHP | 1942 lines | 1203 code | 375 blank | 364 comment | 235 complexity | cdd14e2bf9594b1f883309875af46d9e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://expressionengine.com/user_guide/license.html
  9. * @link http://expressionengine.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Metaweblog API Module
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Modules
  19. * @category Modules
  20. * @author EllisLab Dev Team
  21. * @link http://expressionengine.com
  22. */
  23. class Metaweblog_api {
  24. var $return_data = ''; // Bah!
  25. var $LB = "\r\n"; // Line Break for Entry Output
  26. var $status = ''; // Retrieving
  27. var $channel = '';
  28. var $fields = array();
  29. var $userdata = array();
  30. var $title = 'MetaWeblog API Entry'; // Default Title
  31. var $channel_id = '1'; // Default Channel ID
  32. var $site_id = '1'; // Default Site ID
  33. var $channel_url = ''; // Channel URL for Permalink
  34. var $comment_url = ''; // Comment URL for Permalink
  35. var $deft_category = ''; // Default Category for Channel
  36. var $excerpt_field = '1'; // Default Except Field ID
  37. var $content_field = '2'; // Default Content Field ID
  38. var $more_field = '3'; // Default More Field ID
  39. var $keywords_field = '0'; // Default Keywords Field ID
  40. var $upload_dir = ''; // Upload Directory for Media Files
  41. var $field_name = 'body'; // Default Field Name
  42. var $entry_status = 'null'; // Entry Status from Configuration
  43. var $field_data = array(); // Array of Field Data
  44. var $field_format = array(); // Array of Field Formats
  45. var $categories = array(); // Categories (new/edit/get entry)
  46. var $assign_parents = TRUE; // Assign cat parents to post
  47. var $cat_parents = array(); // Parent categories of new/edited entry
  48. var $parse_type = FALSE; // Use Typography class when sending entry?
  49. var $html_format = 'none'; // Channel's HTML Formatting Preferences
  50. /**
  51. * Constructor
  52. *
  53. * @access public
  54. */
  55. function Metaweblog_api()
  56. {
  57. // Make a local reference to the ExpressionEngine super object
  58. $this->EE =& get_instance();
  59. $this->EE->lang->loadfile('metaweblog_api');
  60. $id = ( isset($_GET['id']) && is_numeric($_GET['id'])) ? $_GET['id'] : '1';
  61. $this->assign_parents = ($this->EE->config->item('auto_assign_cat_parents') == 'n') ? FALSE : TRUE;
  62. /** ----------------------------------------
  63. /** Configuration Options
  64. /** ----------------------------------------*/
  65. $query = $this->EE->db->get_where('metaweblog_api', array('metaweblog_id' => $id));
  66. if ($query->num_rows() > 0)
  67. {
  68. foreach($query->row_array() as $name => $pref)
  69. {
  70. $name = str_replace('metaweblog_', '', $name);
  71. $name = str_replace('_id', '', $name);
  72. if ($pref == 'y' OR $pref == 'n')
  73. {
  74. $this->{$name} = ($pref == 'y') ? TRUE : FALSE;
  75. }
  76. else
  77. {
  78. $this->{$name} = $pref;
  79. }
  80. }
  81. }
  82. }
  83. // --------------------------------------------------------------------
  84. /**
  85. * Incoming MetaWeblog API Requests
  86. *
  87. * @access public
  88. * @return void
  89. */
  90. function incoming()
  91. {
  92. /** ---------------------------------
  93. /** Load the XML-RPC Files
  94. /** ---------------------------------*/
  95. $this->EE->load->library('xmlrpc');
  96. $this->EE->load->library('xmlrpcs');
  97. /* ---------------------------------
  98. /* Specify Functions
  99. /* Normally, we would add a signature and docstring to the array for
  100. /* each function, but since these are widespread and well known
  101. /* functions I just skipped it.
  102. /* ---------------------------------*/
  103. $functions = array( 'metaWeblog.newPost' => array('function' => 'Metaweblog_api.newPost'),
  104. 'metaWeblog.editPost' => array('function' => 'Metaweblog_api.editPost'),
  105. 'metaWeblog.getPost' => array('function' => 'Metaweblog_api.getPost'),
  106. 'metaWeblog.getCategories' => array('function' => 'Metaweblog_api.getCategories'),
  107. 'metaWeblog.getRecentPosts' => array('function' => 'Metaweblog_api.getRecentPosts'),
  108. 'metaWeblog.deletePost' => array('function' => 'Metaweblog_api.deletePost'),
  109. 'metaWeblog.getUsersBlogs' => array('function' => 'Metaweblog_api.getUsersBlogs'),
  110. 'metaWeblog.newMediaObject' => array('function' => 'Metaweblog_api.newMediaObject'),
  111. 'blogger.getUserInfo' => array('function' => 'Metaweblog_api.getUserInfo'),
  112. 'blogger.getUsersBlogs' => array('function' => 'Metaweblog_api.getUsersBlogs'),
  113. 'blogger.deletePost' => array('function' => 'Metaweblog_api.deletePost'),
  114. 'mt.getCategoryList' => array('function' => 'Metaweblog_api.getCategoryList'),
  115. 'mt.get_postCategories' => array('function' => 'Metaweblog_api.get_postCategories'),
  116. 'mt.getPostCategories' => array('function' => 'Metaweblog_api.get_postCategories'),
  117. 'mt.publishPost' => array('function' => 'Metaweblog_api.publishPost'),
  118. 'mt.getRecentPostTitles' => array('function' => 'Metaweblog_api.getRecentPostTitles'),
  119. 'mt.setPostCategories' => array('function' => 'Metaweblog_api.setPostCategories'),
  120. 'mt.supportedMethods' => array('function' => 'this.listMethods'),
  121. 'mt.supportedTextFilters' => array('function' => 'Metaweblog_api.supportedTextFilters')
  122. );
  123. /** ---------------------------------
  124. /** Instantiate the Server Class
  125. /** ---------------------------------*/
  126. $this->EE->xmlrpcs->initialize(array('functions' => $functions, 'object' => $this, 'xss_clean' => FALSE));
  127. $this->EE->xmlrpcs->serve();
  128. }
  129. // --------------------------------------------------------------------
  130. /**
  131. * Submit New Post
  132. *
  133. * @access public
  134. * @param parameter list
  135. * @return void
  136. */
  137. function newPost($plist)
  138. {
  139. $parameters = $plist->output_parameters();
  140. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  141. {
  142. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  143. }
  144. /** ---------------------------------------
  145. /** Parse Out Channel Information
  146. /** ---------------------------------------*/
  147. $this->parse_channel($parameters['0']);
  148. if ($this->entry_status != '' && $this->entry_status != 'null')
  149. {
  150. $this->status = $this->entry_status;
  151. }
  152. else
  153. {
  154. $this->status = ($parameters['4'] == '0') ? 'closed' : 'open';
  155. }
  156. /** ---------------------------------------
  157. /** Default Channel Data for channel_id
  158. /** ---------------------------------------*/
  159. $this->EE->db->select('deft_comments, cat_group, deft_category, channel_title, channel_url,
  160. channel_notify_emails, channel_notify, comment_url');
  161. $this->EE->db->where('channel_id', $this->channel_id);
  162. $query = $this->EE->db->get('channels');
  163. if ($query->num_rows() == 0)
  164. {
  165. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_channel'));
  166. }
  167. foreach($query->row_array() as $key => $value)
  168. {
  169. ${$key} = $value;
  170. }
  171. $notify_address = ($query->row('channel_notify') == 'y' AND $query->row('channel_notify_emails') != '') ? $query->row('channel_notify_emails') : '';
  172. // Get channel field Settings
  173. $this->get_settings($this->channel_id, 'new');
  174. /** ---------------------------------------
  175. /** Parse Data Struct
  176. /** ---------------------------------------*/
  177. $this->title = $parameters['3']['title'];
  178. $ping_urls = ( ! isset($parameters['3']['mt_tb_ping_urls'])) ? '' : implode("\n",$parameters['3']['mt_tb_ping_urls']);
  179. $this->field_data['excerpt'] = ( ! isset($parameters['3']['mt_excerpt'])) ? '' : $parameters['3']['mt_excerpt'];
  180. $this->field_data['content'] = ( ! isset($parameters['3']['description'])) ? '' : $parameters['3']['description'];
  181. $this->field_data['more'] = ( ! isset($parameters['3']['mt_text_more'])) ? '' : $parameters['3']['mt_text_more'];
  182. $this->field_data['keywords'] = ( ! isset($parameters['3']['mt_keywords'])) ? '' : $parameters['3']['mt_keywords'];
  183. if (isset($parameters['3']['mt_allow_comments']))
  184. {
  185. $deft_comments = ($parameters['3']['mt_allow_comments'] == 1) ? 'y' : 'n';
  186. }
  187. if (isset($parameters['3']['categories']) && count($parameters['3']['categories']) > 0)
  188. {
  189. $cats = array();
  190. foreach($parameters['3']['categories'] as $cat)
  191. {
  192. if (trim($cat) != '')
  193. {
  194. $cats[] = $cat;
  195. }
  196. }
  197. if (count($cats) == 0 && ! empty($deft_category))
  198. {
  199. $cats = array($deft_category);
  200. }
  201. if (count($cats) > 0)
  202. {
  203. $this->check_categories(array_unique($cats));
  204. }
  205. }
  206. elseif( ! empty($deft_category))
  207. {
  208. $this->check_categories(array($deft_category));
  209. }
  210. if ( ! empty($parameters['3']['dateCreated']))
  211. {
  212. $entry_date = $this->iso8601_decode($parameters['3']['dateCreated']);
  213. }
  214. else
  215. {
  216. $entry_date = $this->EE->localize->now;
  217. }
  218. /** ---------------------------------
  219. /** Build our query string
  220. /** --------------------------------*/
  221. $metadata = array(
  222. 'channel_id' => $this->channel_id,
  223. 'author_id' => $this->userdata['member_id'],
  224. 'title' => $this->title,
  225. 'ip_address' => $this->EE->input->ip_address(),
  226. 'entry_date' => $entry_date,
  227. 'edit_date' => gmdate("YmdHis", $entry_date),
  228. 'year' => gmdate('Y', $entry_date),
  229. 'month' => gmdate('m', $entry_date),
  230. 'day' => gmdate('d', $entry_date),
  231. 'status' => $this->status,
  232. 'allow_comments' => $deft_comments,
  233. 'ping_servers' => array()
  234. );
  235. /** ---------------------------------------
  236. /** Parse Channel Field Data
  237. /** ---------------------------------------*/
  238. $entry_data = array('channel_id' => $this->channel_id);
  239. // Default formatting for all of the channel's fields...
  240. foreach($this->fields as $field_id => $field_data)
  241. {
  242. $entry_data['field_ft_'.$field_id] = $field_data['1'];
  243. }
  244. $convert_breaks = ( ! isset($parameters['3']['mt_convert_breaks'])) ? '' : $parameters['3']['mt_convert_breaks'];
  245. if ($convert_breaks === '0')
  246. {
  247. // MarsEdit sends '0' as synonymous with 'none'
  248. $convert_breaks = 'none';
  249. }
  250. elseif ($convert_breaks != '')
  251. {
  252. $plugins = $this->fetch_plugins();
  253. if ( ! in_array($convert_breaks, $plugins))
  254. {
  255. $convert_breaks = '';
  256. }
  257. }
  258. if (isset($this->fields[$this->excerpt_field]))
  259. {
  260. if (isset($entry_data['field_id_'.$this->excerpt_field]))
  261. {
  262. $entry_data['field_id_'.$this->excerpt_field] .= $this->field_data['excerpt'];
  263. }
  264. else
  265. {
  266. $entry_data['field_id_'.$this->excerpt_field] = $this->field_data['excerpt'];
  267. }
  268. $entry_data['field_ft_'.$this->excerpt_field] = ($convert_breaks != '') ? $convert_breaks : $this->fields[$this->excerpt_field]['1'];
  269. }
  270. if (isset($this->fields[$this->content_field]))
  271. {
  272. if (isset($entry_data['field_id_'.$this->content_field]))
  273. {
  274. $entry_data['field_id_'.$this->content_field] .= $this->field_data['content'];
  275. }
  276. else
  277. {
  278. $entry_data['field_id_'.$this->content_field] = $this->field_data['content'];
  279. }
  280. $entry_data['field_ft_'.$this->content_field] = ($convert_breaks != '') ? $convert_breaks : $this->fields[$this->content_field]['1'];
  281. }
  282. if (isset($this->fields[$this->more_field]))
  283. {
  284. if (isset($entry_data['field_id_'.$this->more_field]))
  285. {
  286. $entry_data['field_id_'.$this->more_field] .= $this->field_data['more'];
  287. }
  288. else
  289. {
  290. $entry_data['field_id_'.$this->more_field] = $this->field_data['more'];
  291. }
  292. $entry_data['field_ft_'.$this->more_field] = ($convert_breaks != '') ? $convert_breaks : $this->fields[$this->more_field]['1'];
  293. }
  294. if (isset($this->fields[$this->keywords_field]))
  295. {
  296. if (isset($entry_data['field_id_'.$this->keywords_field]))
  297. {
  298. $entry_data['field_id_'.$this->keywords_field] .= $this->field_data['keywords'];
  299. }
  300. else
  301. {
  302. $entry_data['field_id_'.$this->keywords_field] = $this->field_data['keywords'];
  303. }
  304. $entry_data['field_ft_'.$this->keywords_field] = ($convert_breaks != '') ? $convert_breaks : $this->fields[$this->keywords_field]['1'];
  305. }
  306. /** ---------------------------------
  307. /** Insert the entry data
  308. /** ---------------------------------*/
  309. $entry_data['site_id'] = $this->site_id;
  310. $entry_data['versioning_enabled'] = 'n';
  311. $data = array_merge($metadata, $entry_data);
  312. if (count($this->categories) > 0)
  313. {
  314. foreach($this->categories as $cat_id => $cat_name)
  315. {
  316. $data['category'][] = $cat_id;
  317. }
  318. }
  319. $this->EE->session->userdata = array_merge(
  320. $this->EE->session->userdata,
  321. array(
  322. 'group_id' => $this->userdata['group_id'],
  323. 'member_id' => $this->userdata['member_id'],
  324. 'assigned_channels' => $this->userdata['assigned_channels']
  325. )
  326. );
  327. $this->EE->load->library('api');
  328. $this->EE->api->instantiate('channel_entries');
  329. $this->EE->api->instantiate('channel_fields');
  330. $this->EE->api_channel_fields->setup_entry_settings($this->channel_id, $data);
  331. if ( ! $this->EE->api_channel_entries->submit_new_entry($this->channel_id, $data))
  332. {
  333. $errors = $this->EE->api_channel_entries->get_errors();
  334. $response = array(
  335. 'errors' => array($errors, 'array')
  336. );
  337. return $this->EE->xmlrpc->send_response($response);
  338. }
  339. //Return Entry ID of new entry - defaults to string, so nothing fancy
  340. $response = $this->EE->api_channel_entries->entry_id;
  341. return $this->EE->xmlrpc->send_response($response);
  342. }
  343. // --------------------------------------------------------------------
  344. /**
  345. * Edit Post
  346. *
  347. * @access public
  348. * @param parameter list
  349. * @return void
  350. */
  351. function editPost($plist)
  352. {
  353. $parameters = $plist->output_parameters();
  354. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  355. {
  356. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  357. }
  358. if ( ! $this->userdata['can_access_content'] && $this->userdata['group_id'] != '1')
  359. {
  360. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_access'));
  361. }
  362. if ( ! $this->userdata['can_edit_other_entries'] && $this->userdata['group_id'] != '1')
  363. {
  364. // If there aren't any channels assigned to the user, bail out
  365. if (count($this->userdata['assigned_channels']) == 0)
  366. {
  367. return $this->EE->xmlrpc->send_error_message('804', $this->EE->lang->line('invalid_access'));
  368. }
  369. }
  370. /** ---------------------------------------
  371. /** Retrieve Entry Information
  372. /** ---------------------------------------*/
  373. $entry_id = $parameters['0'];
  374. $sql = "SELECT wt.channel_id, wt.author_id, wt.title, wt.url_title,
  375. wb.channel_title, wb.channel_url
  376. FROM (exp_channel_titles wt, exp_channels wb)
  377. WHERE wt.channel_id = wb.channel_id
  378. AND wt.entry_id = '".$this->EE->db->escape_str($entry_id)."' ";
  379. $query = $this->EE->db->query($sql);
  380. if ($query->num_rows() == 0)
  381. {
  382. return $this->EE->xmlrpc->send_error_message('805', $this->EE->lang->line('no_entry_found'));
  383. }
  384. if ( ! $this->userdata['can_edit_other_entries'] && $this->userdata['group_id'] != '1')
  385. {
  386. if ($query->row('author_id') != $this->userdata['member_id'])
  387. {
  388. return $this->EE->xmlrpc->send_error_message('806', $this->EE->lang->line('entry_uneditable'));
  389. }
  390. }
  391. $this->channel_id = $query->row('channel_id');
  392. $this->title = $query->row('title');
  393. $this->parse_channel($this->channel_id);
  394. if ($this->entry_status != '' && $this->entry_status != 'null')
  395. {
  396. $this->status = $this->entry_status;
  397. }
  398. else
  399. {
  400. $this->status = ($parameters['4'] == '0') ? 'closed' : 'open';
  401. }
  402. /** ---------------------------------------
  403. /** Parse Channel Meta-Information
  404. /** ---------------------------------------*/
  405. $this->title = $parameters['3']['title'];
  406. $ping_urls = ( ! isset($parameters['3']['mt_tb_ping_urls'])) ? '' : implode("\n",$parameters['3']['mt_tb_ping_urls']);
  407. $this->field_data['excerpt'] = ( ! isset($parameters['3']['mt_excerpt'])) ? '' : $parameters['3']['mt_excerpt'];
  408. $this->field_data['content'] = ( ! isset($parameters['3']['description'])) ? '' : $parameters['3']['description'];
  409. $this->field_data['more'] = ( ! isset($parameters['3']['mt_text_more'])) ? '' : $parameters['3']['mt_text_more'];
  410. $this->field_data['keywords'] = ( ! isset($parameters['3']['mt_keywords'])) ? '' : $parameters['3']['mt_keywords'];
  411. /** ---------------------------------
  412. /** Build our query string
  413. /** ---------------------------------*/
  414. $metadata = array(
  415. 'entry_id' => $entry_id,
  416. 'title' => $this->title,
  417. 'ip_address' => $this->EE->input->ip_address(),
  418. 'status' => $this->status
  419. );
  420. if (isset($parameters['3']['mt_allow_comments']))
  421. {
  422. $metadata['allow_comments'] = ($parameters['3']['mt_allow_comments'] == 1) ? 'y' : 'n';
  423. }
  424. if ( ! empty($parameters['3']['dateCreated']))
  425. {
  426. $metadata['entry_date'] = $this->iso8601_decode($parameters['3']['dateCreated']);
  427. }
  428. $metadata['edit_date'] = date("YmdHis");
  429. /** ---------------------------------------
  430. /** Parse Channel Field Data
  431. /** ---------------------------------------*/
  432. $entry_data = array('channel_id' => $this->channel_id);
  433. $convert_breaks = ( ! isset($parameters['3']['mt_convert_breaks'])) ? '' : $parameters['3']['mt_convert_breaks'];
  434. if ($convert_breaks === '0')
  435. {
  436. // MarsEdit sends '0' as synonymous with 'none'
  437. $convert_breaks = 'none';
  438. }
  439. elseif ($convert_breaks != '')
  440. {
  441. $plugins = $this->fetch_plugins();
  442. if ( ! in_array($convert_breaks, $plugins))
  443. {
  444. $convert_breaks = '';
  445. }
  446. }
  447. if (isset($this->fields[$this->excerpt_field]))
  448. {
  449. if (isset($entry_data['field_id_'.$this->excerpt_field]))
  450. {
  451. $entry_data['field_id_'.$this->excerpt_field] .= $this->field_data['excerpt'];
  452. }
  453. else
  454. {
  455. $entry_data['field_id_'.$this->excerpt_field] = $this->field_data['excerpt'];
  456. }
  457. $entry_data['field_ft_'.$this->excerpt_field] = ($convert_breaks != '') ? $convert_breaks : $this->fields[$this->excerpt_field]['1'];
  458. }
  459. if (isset($this->fields[$this->content_field]))
  460. {
  461. if (isset($entry_data['field_id_'.$this->content_field]))
  462. {
  463. $entry_data['field_id_'.$this->content_field] .= $this->field_data['content'];
  464. }
  465. else
  466. {
  467. $entry_data['field_id_'.$this->content_field] = $this->field_data['content'];
  468. }
  469. $entry_data['field_ft_'.$this->content_field] = ($convert_breaks != '') ? $convert_breaks : $this->fields[$this->content_field]['1'];
  470. }
  471. if (isset($this->fields[$this->more_field]))
  472. {
  473. if (isset($entry_data['field_id_'.$this->more_field]))
  474. {
  475. $entry_data['field_id_'.$this->more_field] .= $this->field_data['more'];
  476. }
  477. else
  478. {
  479. $entry_data['field_id_'.$this->more_field] = $this->field_data['more'];
  480. }
  481. $entry_data['field_ft_'.$this->more_field] = ($convert_breaks != '') ? $convert_breaks : $this->fields[$this->more_field]['1'];
  482. }
  483. if (isset($this->fields[$this->keywords_field]))
  484. {
  485. if (isset($entry_data['field_id_'.$this->keywords_field]))
  486. {
  487. $entry_data['field_id_'.$this->keywords_field] .= $this->field_data['keywords'];
  488. }
  489. else
  490. {
  491. $entry_data['field_id_'.$this->keywords_field] = $this->field_data['keywords'];
  492. }
  493. $entry_data['field_ft_'.$this->keywords_field] = ($convert_breaks != '') ? $convert_breaks : $this->fields[$this->keywords_field]['1'];
  494. }
  495. /** ---------------------------------
  496. /** Update the entry data
  497. /** ---------------------------------*/
  498. $this->EE->db->query($this->EE->db->update_string('exp_channel_titles', $metadata, "entry_id = '$entry_id'"));
  499. $this->EE->db->query($this->EE->db->update_string('exp_channel_data', $entry_data, "entry_id = '$entry_id'"));
  500. /** ---------------------------------
  501. /** Insert Categories, if any
  502. /** ---------------------------------*/
  503. if ( ! empty($parameters['3']['categories']) && count($parameters['3']['categories']) > 0)
  504. {
  505. $this->check_categories($parameters['3']['categories']);
  506. }
  507. if (count($this->categories) > 0)
  508. {
  509. $this->EE->db->query("DELETE FROM exp_category_posts WHERE entry_id = '$entry_id'");
  510. foreach($this->categories as $cat_id => $cat_name)
  511. {
  512. $this->EE->db->query("INSERT INTO exp_category_posts
  513. (entry_id, cat_id)
  514. VALUES
  515. ('".$entry_id."', '$cat_id')");
  516. }
  517. }
  518. /** ---------------------------------
  519. /** Clear caches if needed
  520. /** ---------------------------------*/
  521. if ($this->EE->config->item('new_posts_clear_caches') == 'y')
  522. {
  523. $this->EE->functions->clear_caching('all');
  524. }
  525. else
  526. {
  527. $this->EE->functions->clear_caching('sql');
  528. }
  529. /** ---------------------------------
  530. /** Count your chickens after they've hatched
  531. /** ---------------------------------*/
  532. $this->EE->stats->update_channel_stats($this->channel_id);
  533. /** ---------------------------------
  534. /** Return Boolean TRUE
  535. /** ---------------------------------*/
  536. return $this->EE->xmlrpc->send_response(array(1,'boolean'));
  537. }
  538. // --------------------------------------------------------------------
  539. /**
  540. * MT API: Publish Post
  541. *
  542. * @access public
  543. * @param parameter list
  544. * @return void
  545. */
  546. function publishPost($plist)
  547. {
  548. /** ---------------------------------
  549. /** Clear caches
  550. /** ---------------------------------*/
  551. if ($this->EE->config->item('new_posts_clear_caches') == 'y')
  552. {
  553. $this->EE->functions->clear_caching('all');
  554. }
  555. else
  556. {
  557. $this->EE->functions->clear_caching('sql');
  558. }
  559. /** ---------------------------------
  560. /** Return Boolean TRUE
  561. /** ---------------------------------*/
  562. return $this->EE->xmlrpc->send_response(array(1,'boolean'));
  563. }
  564. // --------------------------------------------------------------------
  565. /**
  566. * Get a single post
  567. *
  568. * @access public
  569. * @param parameter list
  570. * @return void
  571. */
  572. function getPost($plist)
  573. {
  574. $parameters = $plist->output_parameters();
  575. return $this->getRecentPosts($plist, $parameters['0']);
  576. }
  577. // --------------------------------------------------------------------
  578. /**
  579. * Get recent posts
  580. *
  581. * @access public
  582. * @param parameter list
  583. * @return void
  584. */
  585. function getRecentPosts($plist, $entry_id = '')
  586. {
  587. $parameters = $plist->output_parameters();
  588. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  589. {
  590. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  591. }
  592. if ( ! $this->userdata['can_access_content'] && $this->userdata['group_id'] != '1')
  593. {
  594. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_access'));
  595. }
  596. /** ---------------------------------------
  597. /** Parse Out Channel Information
  598. /** ---------------------------------------*/
  599. if ($entry_id == '')
  600. {
  601. $this->parse_channel($parameters['0']);
  602. $limit = ( ! empty($parameters['3']) && is_numeric($parameters['3'])) ? $parameters['3'] : '10';
  603. }
  604. /** ---------------------------------------
  605. /** Perform Query
  606. /** ---------------------------------------*/
  607. $sql = "SELECT DISTINCT(wt.entry_id), wt.title, wt.url_title, wt.channel_id,
  608. wt.author_id, wt.entry_date, wt.allow_comments,
  609. exp_channel_data.*
  610. FROM exp_channel_titles wt, exp_channel_data
  611. WHERE wt.entry_id = exp_channel_data.entry_id ";
  612. if ($this->userdata['group_id'] != '1' && ! $this->userdata['can_edit_other_entries'])
  613. {
  614. $sql .= "AND wt.author_id = '".$this->userdata['member_id']."' ";
  615. }
  616. if ($entry_id != '')
  617. {
  618. $sql .= "AND wt.entry_id = '{$entry_id}' ";
  619. }
  620. else
  621. {
  622. $sql .= str_replace('exp_channels.channel_id','wt.channel_id', $this->channel_sql)." ";
  623. }
  624. if ($entry_id == '')
  625. {
  626. $sql .= "ORDER BY entry_date desc LIMIT 0, {$limit}";
  627. }
  628. $query = $this->EE->db->query($sql);
  629. if ($query->num_rows() == 0)
  630. {
  631. return $this->EE->xmlrpc->send_error_message('805', $this->EE->lang->line('no_entries_found'));
  632. }
  633. if ($entry_id != '')
  634. {
  635. $this->parse_channel($query->row('channel_id') );
  636. }
  637. /** ----------------------------------------
  638. /** Instantiate Typography class
  639. /** ----------------------------------------*/
  640. if ($this->parse_type === TRUE)
  641. {
  642. $this->EE->load->library('typography');
  643. $this->EE->typography->initialize(array(
  644. 'encode_email' => FALSE)
  645. );
  646. $this->EE->config->set_item('enable_emoticons', 'n');
  647. }
  648. /** ---------------------------------------
  649. /** Process Output
  650. /** ---------------------------------------*/
  651. $settings = array();
  652. $settings['html_format'] = $this->html_format;
  653. $settings['auto_links'] = 'n';
  654. $settings['allow_img_url'] = 'y';
  655. $response = array();
  656. foreach($query->result_array() as $row)
  657. {
  658. $convert_breaks = 'none';
  659. $link = $this->EE->functions->remove_double_slashes($this->comment_url.'/'.$query->row('url_title') .'/');
  660. // Fields: Textarea and Text Input Only
  661. $this->field_data = array('excerpt' => '', 'content' => '', 'more' => '', 'keywords' => '');
  662. if (isset($this->fields[$this->excerpt_field]))
  663. {
  664. if ($this->parse_type === TRUE)
  665. {
  666. $settings['text_format'] = $row['field_ft_'.$this->excerpt_field];
  667. $this->field_data['excerpt'] = $this->EE->typography->parse_type($row['field_id_'.$this->excerpt_field], $settings);
  668. }
  669. else
  670. {
  671. $this->field_data['excerpt'] .= $row['field_id_'.$this->excerpt_field];
  672. }
  673. }
  674. if (isset($this->fields[$this->content_field]))
  675. {
  676. $convert_breaks = $row['field_ft_'.$this->content_field];
  677. if ($this->parse_type === TRUE)
  678. {
  679. $settings['text_format'] = $row['field_ft_'.$this->content_field];
  680. $this->field_data['content'] = $this->EE->typography->parse_type($row['field_id_'.$this->content_field], $settings);
  681. }
  682. else
  683. {
  684. $this->field_data['content'] .= $row['field_id_'.$this->content_field];
  685. }
  686. }
  687. if (isset($this->fields[$this->more_field]))
  688. {
  689. if ($this->parse_type === TRUE)
  690. {
  691. $settings['text_format'] = $row['field_ft_'.$this->more_field];
  692. $this->field_data['more'] = $this->EE->typography->parse_type($row['field_id_'.$this->more_field], $settings);
  693. }
  694. else
  695. {
  696. $this->field_data['more'] .= $row['field_id_'.$this->more_field];
  697. }
  698. }
  699. if (isset($this->fields[$this->keywords_field]))
  700. {
  701. if ($this->parse_type === TRUE)
  702. {
  703. $settings['text_format'] = $row['field_ft_'.$this->keywords_field];
  704. $this->field_data['keywords'] = $this->EE->typography->parse_type($row['field_id_'.$this->keywords_field], $settings);
  705. }
  706. else
  707. {
  708. $this->field_data['keywords'] .= $row['field_id_'.$this->keywords_field];
  709. }
  710. }
  711. // Categories
  712. $cat_array = array();
  713. $sql = "SELECT exp_categories.cat_id, exp_categories.cat_name
  714. FROM exp_category_posts, exp_categories
  715. WHERE exp_category_posts.cat_id = exp_categories.cat_id
  716. AND exp_category_posts.entry_id = '".$row['entry_id']."'
  717. ORDER BY cat_id";
  718. $results = $this->EE->db->query($sql);
  719. if ($results->num_rows() > 0)
  720. {
  721. foreach($results->result_array() as $rrow)
  722. {
  723. $cat_array[] = array($rrow['cat_name'], 'string');
  724. //$cat_array[] = array($rrow['cat_id'], 'string');
  725. }
  726. }
  727. // Entry Data to XML-RPC form
  728. $pings = array();
  729. $entry_data = array(array(
  730. 'userid' =>
  731. array($row['author_id'],'string'),
  732. 'dateCreated' =>
  733. array(date('Ymd\TH:i:s',$row['entry_date']).'Z','dateTime.iso8601'),
  734. 'blogid' =>
  735. array($row['channel_id'],'string'),
  736. 'title' =>
  737. array($row['title'], 'string'),
  738. 'mt_excerpt' =>
  739. array($this->field_data['excerpt'],'string'),
  740. 'description' =>
  741. array($this->field_data['content'],'string'),
  742. 'mt_text_more' =>
  743. array($this->field_data['more'],'string'),
  744. 'mt_keywords' =>
  745. array($this->field_data['keywords'],'string'),
  746. 'mt_convert_breaks' =>
  747. array($convert_breaks,'string'),
  748. 'postid' =>
  749. array($row['entry_id'],'string'),
  750. 'link' =>
  751. array($link,'string'),
  752. 'permaLink' =>
  753. array($link,'string'),
  754. 'categories' =>
  755. array($cat_array,'array'),
  756. 'mt_allow_comments' =>
  757. array(($row['allow_comments'] == 'y') ? 1 : 0,'int'),
  758. 'mt_tb_ping_urls' =>
  759. array($pings,'array')
  760. ),
  761. 'struct');
  762. array_push($response, $entry_data);
  763. }
  764. if ($entry_id != '')
  765. {
  766. return $this->EE->xmlrpc->send_response($entry_data);
  767. }
  768. else
  769. {
  770. return $this->EE->xmlrpc->send_response(array($response, 'array'));
  771. }
  772. }
  773. // --------------------------------------------------------------------
  774. /**
  775. * MT API: get recent post title
  776. *
  777. * @access public
  778. * @param parameter list
  779. * @return void
  780. */
  781. function getRecentPostTitles($plist)
  782. {
  783. $parameters = $plist->output_parameters();
  784. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  785. {
  786. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  787. }
  788. if ( ! $this->userdata['can_access_content'] && $this->userdata['group_id'] != '1')
  789. {
  790. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_access'));
  791. }
  792. /** ---------------------------------------
  793. /** Parse Out Channel Information
  794. /** ---------------------------------------*/
  795. $this->parse_channel($parameters['0']);
  796. $limit = ( ! empty($parameters['3']) && is_numeric($parameters['3'])) ? $parameters['3'] : '10';
  797. /** ---------------------------------------
  798. /** Perform Query
  799. /** ---------------------------------------*/
  800. $sql = "SELECT DISTINCT(wt.entry_id), wt.title, wt.channel_id,
  801. wt.author_id, wt.entry_date
  802. FROM exp_channel_titles wt, exp_channel_data
  803. WHERE wt.entry_id = exp_channel_data.entry_id ";
  804. if ($this->userdata['group_id'] != '1' && ! $this->userdata['can_edit_other_entries'])
  805. {
  806. $sql .= "AND wt.author_id = '".$this->userdata['member_id']."' ";
  807. }
  808. $sql .= str_replace('exp_channels.channel_id','wt.channel_id', $this->channel_sql)." ";
  809. $sql .= "ORDER BY entry_date desc LIMIT 0, {$limit}";
  810. $query = $this->EE->db->query($sql);
  811. if ($query->num_rows() == 0)
  812. {
  813. return $this->EE->xmlrpc->send_error_message('805', $this->EE->lang->line('no_entries_found'));
  814. }
  815. /** ---------------------------------------
  816. /** Process Output
  817. /** ---------------------------------------*/
  818. $response = array();
  819. foreach($query->result_array() as $row)
  820. {
  821. // Entry Data to XML-RPC form
  822. $entry_data = array(array(
  823. 'userid' =>
  824. array($row['author_id'],'string'),
  825. 'dateCreated' =>
  826. array(date('Ymd\TH:i:s',$row['entry_date']).'Z','dateTime.iso8601'),
  827. 'title' =>
  828. array($row['title'], 'string'),
  829. 'postid' =>
  830. array($row['entry_id'],'string'),
  831. ),
  832. 'struct');
  833. array_push($response, $entry_data);
  834. }
  835. return $this->EE->xmlrpc->send_response(array($response, 'array'));
  836. }
  837. // --------------------------------------------------------------------
  838. /**
  839. * MT API: get post categories
  840. *
  841. * @access public
  842. * @param parameter list
  843. * @return void
  844. */
  845. function get_postCategories($plist)
  846. {
  847. $parameters = $plist->output_parameters();
  848. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  849. {
  850. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  851. }
  852. $query = $this->EE->db->query("SELECT channel_id FROM exp_channel_titles
  853. WHERE entry_id = '".$this->EE->db->escape_str($parameters['0'])."'");
  854. if ($query->num_rows() == 0)
  855. {
  856. return $this->EE->xmlrpc->send_error_message('804', $this->EE->lang->line('invalid_channel'));
  857. }
  858. if ($this->userdata['group_id'] != '1' && ! in_array($query->row('channel_id') , $this->userdata['assigned_channels']))
  859. {
  860. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_access'));
  861. }
  862. $cats = array();
  863. $sql = "SELECT exp_categories.cat_id, exp_categories.cat_name
  864. FROM exp_category_posts, exp_categories
  865. WHERE exp_category_posts.cat_id = exp_categories.cat_id
  866. AND exp_category_posts.entry_id = '".$this->EE->db->escape_str($parameters['0'])."'
  867. ORDER BY cat_id";
  868. $query = $this->EE->db->query($sql);
  869. if ($query->num_rows() > 0)
  870. {
  871. foreach($query->result_array() as $row)
  872. {
  873. $cat = array();
  874. $cat['categoryId'] = array($row['cat_id'],'string');
  875. $cat['categoryName'] = array($row['cat_name'],'string');
  876. array_push($cats, array($cat, 'struct'));
  877. }
  878. }
  879. return $this->EE->xmlrpc->send_response(array($cats, 'array'));
  880. }
  881. // --------------------------------------------------------------------
  882. /**
  883. * MT API: set post categories
  884. *
  885. * @access public
  886. * @param parameter list
  887. * @return void
  888. */
  889. function setPostCategories($plist)
  890. {
  891. $parameters = $plist->output_parameters();
  892. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  893. {
  894. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  895. }
  896. if ( ! $this->userdata['can_access_content'] && $this->userdata['group_id'] != '1')
  897. {
  898. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_access'));
  899. }
  900. if ( ! $this->userdata['can_edit_other_entries'] && $this->userdata['group_id'] != '1')
  901. {
  902. // If there aren't any channels assigned to the user, bail out
  903. if (count($this->userdata['assigned_channels']) == 0)
  904. {
  905. return $this->EE->xmlrpc->send_error_message('804', $this->EE->lang->line('invalid_access'));
  906. }
  907. }
  908. /** ---------------------------------------
  909. /** Details from Parameters
  910. /** ---------------------------------------*/
  911. $entry_id = $parameters['0'];
  912. /** ---------------------------------------
  913. /** Retrieve Entry Information
  914. /** ---------------------------------------*/
  915. $sql = "SELECT channel_id, author_id
  916. FROM exp_channel_titles
  917. WHERE entry_id = '".$entry_id."' ";
  918. $query = $this->EE->db->query($sql);
  919. if ($query->num_rows() == 0)
  920. {
  921. return $this->EE->xmlrpc->send_error_message('805', $this->EE->lang->line('no_entry_found'));
  922. }
  923. if ( ! $this->userdata['can_edit_other_entries'] && $this->userdata['group_id'] != '1')
  924. {
  925. if ($query->row('author_id') != $this->userdata['member_id'])
  926. {
  927. return $this->EE->xmlrpc->send_error_message('806', $this->EE->lang->line('entry_uneditable'));
  928. }
  929. }
  930. $this->channel_id = $query->row('channel_id') ;
  931. $this->parse_channel($this->channel_id);
  932. /** ---------------------------------------
  933. /** Parse Categories
  934. /** ---------------------------------------*/
  935. if ( ! empty($parameters['3']) && count($parameters['3']) > 0)
  936. {
  937. $cats = array();
  938. foreach($parameters['3'] as $cat_data)
  939. {
  940. $cats[] = $cat_data['categoryId'];
  941. }
  942. if (count($cats) == 0 && ! empty($this->deft_category))
  943. {
  944. $cats = array($this->deft_category);
  945. }
  946. if (count($cats) > 0)
  947. {
  948. $this->check_categories($cats);
  949. }
  950. }
  951. else
  952. {
  953. return $this->EE->xmlrpc->send_response(array(1,'boolean'));
  954. //return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('entry_uneditable'));
  955. }
  956. /** ---------------------------------
  957. /** Insert Categories, if any
  958. /** ---------------------------------*/
  959. $this->EE->db->query("DELETE FROM exp_category_posts WHERE entry_id = '$entry_id'");
  960. if (count($this->categories) > 0)
  961. {
  962. foreach($this->categories as $cat_id => $cat_name)
  963. {
  964. $this->EE->db->query("INSERT INTO exp_category_posts
  965. (entry_id, cat_id)
  966. VALUES
  967. ('".$entry_id."', '$cat_id')");
  968. }
  969. }
  970. /** ---------------------------------
  971. /** Clear caches if needed
  972. /** ---------------------------------*/
  973. if ($this->EE->config->item('new_posts_clear_caches') == 'y')
  974. {
  975. $this->EE->functions->clear_caching('all');
  976. }
  977. else
  978. {
  979. $this->EE->functions->clear_caching('sql');
  980. }
  981. /** ---------------------------------
  982. /** Return Boolean TRUE
  983. /** ---------------------------------*/
  984. return $this->EE->xmlrpc->send_response(array(1,'boolean'));
  985. }
  986. // --------------------------------------------------------------------
  987. /**
  988. * Fetch member data
  989. *
  990. * @access public
  991. * @param parameter list
  992. * @return void
  993. */
  994. function fetch_member_data($username, $password)
  995. {
  996. $this->EE->load->library('auth');
  997. if (FALSE == ($auth = $this->EE->auth->authenticate_username($username, $password)))
  998. {
  999. return FALSE;
  1000. }
  1001. // load userdata from Auth object, a few fields from the members table, but most from the group
  1002. foreach (array('screen_name', 'member_id', 'email', 'url', 'group_id') as $member_item)
  1003. {
  1004. $this->userdata[$member_item] = $auth->member($member_item);
  1005. }
  1006. foreach ($this->EE->db->list_fields('member_groups') as $field)
  1007. {
  1008. $this->userdata[$field] = $auth->group($field);
  1009. }
  1010. /** -------------------------------------------------
  1011. /** Find Assigned Channels
  1012. /** -------------------------------------------------*/
  1013. $assigned_channels = array();
  1014. if ($this->userdata['group_id'] == 1)
  1015. {
  1016. $result = $this->EE->db->query("SELECT channel_id FROM exp_channels");
  1017. }
  1018. else
  1019. {
  1020. $result = $this->EE->db->query("SELECT channel_id FROM exp_channel_member_groups WHERE group_id = '".$this->userdata['group_id']."'");
  1021. }
  1022. if ($result->num_rows() > 0)
  1023. {
  1024. foreach ($result->result_array() as $row)
  1025. {
  1026. $assigned_channels[] = $row['channel_id'];
  1027. }
  1028. }
  1029. else
  1030. {
  1031. return FALSE; // Nowhere to Post!!
  1032. }
  1033. $this->userdata['assigned_channels'] = $assigned_channels;
  1034. $this->EE->session->userdata = array_merge(
  1035. $this->EE->session->userdata,
  1036. $this->userdata
  1037. );
  1038. return TRUE;
  1039. }
  1040. // --------------------------------------------------------------------
  1041. /**
  1042. * METAWEBLOG API: get categories
  1043. *
  1044. * @access public
  1045. * @param parameter list
  1046. * @return void
  1047. */
  1048. function getCategories($plist)
  1049. {
  1050. $parameters = $plist->output_parameters();
  1051. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  1052. {
  1053. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  1054. }
  1055. if ($this->userdata['group_id'] != '1' && ! in_array($parameters['0'], $this->userdata['assigned_channels']))
  1056. {
  1057. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_channel'));
  1058. }
  1059. $this->parse_channel($parameters['0']);
  1060. $cats = array();
  1061. $sql = "SELECT exp_categories.cat_id, exp_categories.cat_name, exp_categories.cat_description
  1062. FROM exp_categories, exp_channels
  1063. WHERE FIND_IN_SET(exp_categories.group_id, REPLACE(exp_channels.cat_group, '|', ','))
  1064. AND exp_channels.channel_id = '{$this->channel_id}'";
  1065. $query = $this->EE->db->query($sql);
  1066. if ($query->num_rows() > 0)
  1067. {
  1068. foreach($query->result_array() as $row)
  1069. {
  1070. $cat = array();
  1071. $link = $this->EE->functions->remove_double_slashes($this->channel_url.'/C'.$row['cat_id'].'/');
  1072. $cat['categoryId'] = array($row['cat_id'],'string');
  1073. $cat['description'] = array(($row['cat_description'] == '') ? $row['cat_name'] : $row['cat_description'],'string');
  1074. $cat['categoryName'] = array($row['cat_name'],'string');
  1075. $cat['htmlUrl'] = array($link,'string');
  1076. $cat['rssUrl'] = array($link,'string'); // No RSS URL for Categories
  1077. array_push($cats, array($cat, 'struct'));
  1078. }
  1079. }
  1080. return $this->EE->xmlrpc->send_response(array($cats, 'array'));
  1081. }
  1082. // --------------------------------------------------------------------
  1083. /**
  1084. * MT API: get category list
  1085. *
  1086. * @access public
  1087. * @param parameter list
  1088. * @return void
  1089. */
  1090. function getCategoryList($plist)
  1091. {
  1092. $parameters = $plist->output_parameters();
  1093. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  1094. {
  1095. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  1096. }
  1097. if ($this->userdata['group_id'] != '1' && ! in_array($parameters['0'], $this->userdata['assigned_channels']))
  1098. {
  1099. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_channel'));
  1100. }
  1101. $this->parse_channel($parameters['0']);
  1102. $cats = array();
  1103. $sql = "SELECT exp_categories.cat_id, exp_categories.cat_name
  1104. FROM exp_categories, exp_channels
  1105. WHERE FIND_IN_SET(exp_categories.group_id, REPLACE(exp_channels.cat_group, '|', ','))
  1106. AND exp_channels.channel_id = '{$this->channel_id}'";
  1107. $query = $this->EE->db->query($sql);
  1108. if ($query->num_rows() > 0)
  1109. {
  1110. foreach($query->result_array() as $row)
  1111. {
  1112. $cat = array();
  1113. $cat['categoryId'] = array($row['cat_id'],'string');
  1114. $cat['categoryName'] = array($row['cat_name'],'string');
  1115. array_push($cats, array($cat, 'struct'));
  1116. }
  1117. }
  1118. return $this->EE->xmlrpc->send_response(array($cats, 'array'));
  1119. }
  1120. // --------------------------------------------------------------------
  1121. /**
  1122. * Parses out received channel parameters
  1123. *
  1124. * @access public
  1125. * @param int
  1126. * @return void
  1127. */
  1128. function parse_channel($channel_id)
  1129. {
  1130. $channel_id = trim($channel_id);
  1131. $this->status = 'open';
  1132. $sql = "SELECT channel_id, channel_url, comment_url, deft_category, channel_html_formatting, site_id FROM exp_channels WHERE ";
  1133. $this->channel_sql = $this->EE->functions->sql_andor_string($channel_id, 'exp_channels.channel_id');
  1134. $sql = (substr($this->channel_sql, 0, 3) == 'AND') ? $sql.substr($this->channel_sql, 3) : $sql.$this->channel_sql;
  1135. $query = $this->EE->db->query($sql);
  1136. if ($query->num_rows() == 0)
  1137. {
  1138. return $this->EE->xmlrpc->send_error_message('804', $this->EE->lang->line('invalid_channel'));
  1139. }
  1140. $this->channel_id = $query->row('channel_id');
  1141. $this->channel_url = $query->row('channel_url');
  1142. $this->comment_url = $query->row('comment_url');
  1143. $this->deft_category = $query->row('deft_category');
  1144. $this->html_format = $query->row('channel_html_formatting');
  1145. $this->site_id = $query->row('site_id');
  1146. if ($this->site_id != $this->EE->config->item('site_id'))
  1147. {
  1148. $this->EE->config->site_prefs('', $this->site_id);
  1149. $this->assign_parents = ($this->EE->config->item('auto_assign_cat_parents') == 'n') ? FALSE : TRUE;
  1150. }
  1151. foreach ($query->result_array() as $row)
  1152. {
  1153. if ( ! in_array($row['channel_id'], $this->userdata['assigned_channels']) && $this->userdata['group_id'] != '1')
  1154. {
  1155. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_channel'));
  1156. }
  1157. }
  1158. /** ---------------------------------------
  1159. /** Find Fields
  1160. /** ---------------------------------------*/
  1161. $query = $this->EE->db->query("SELECT field_name, field_id, field_type, field_fmt FROM exp_channel_fields, exp_channels
  1162. WHERE exp_channels.field_group = exp_channel_fields.group_id
  1163. {$this->channel_sql}
  1164. ORDER BY field_order");
  1165. foreach($query->result_array() as $row)
  1166. {
  1167. $this->fields[$row['field_id']] = array($row['field_name'], $row['field_fmt']);
  1168. }
  1169. }
  1170. // --------------------------------------------------------------------
  1171. /**
  1172. * Check validity of categories
  1173. *
  1174. * @access public
  1175. * @param array
  1176. * @return void
  1177. */
  1178. function check_categories($array, $debug = '0')
  1179. {
  1180. $this->categories = array_unique($array);
  1181. $sql = "SELECT exp_categories.cat_id, exp_categories.cat_name, exp_categories.parent_id
  1182. FROM exp_categories, exp_channels
  1183. WHERE FIND_IN_SET(exp_categories.group_id, REPLACE(exp_channels.cat_group, '|', ','))
  1184. AND exp_channels.channel_id = '{$this->channel_id}'";
  1185. $query = $this->EE->db->query($sql);
  1186. if ($query->num_rows() == 0)
  1187. {
  1188. return $this->EE->xmlrpc->send_error_message('807', $this->EE->lang->line('invalid_categories'));
  1189. }
  1190. $good = 0;
  1191. $all_cats = array();
  1192. foreach($query->result_array() as $row)
  1193. {
  1194. $all_cats[$row['cat_id']] = $row['cat_name'];
  1195. if (in_array($row['cat_id'], $this->categories) OR in_array($row['cat_name'], $this->categories))
  1196. {
  1197. $good++;
  1198. $cat_names[$row['cat_id']] = $row['cat_name'];
  1199. if ($this->assign_parents == TRUE && $row['parent_id'] != '0')
  1200. {
  1201. $this->cat_parents[$row['parent_id']] = 'Parent';
  1202. }
  1203. }
  1204. }
  1205. if ($good < count($this->categories))
  1206. {
  1207. return $this->EE->xmlrpc->send_error_message('807', $this->EE->lang->line('invalid_categories'));
  1208. }
  1209. else
  1210. {
  1211. $this->categories = $cat_names;
  1212. if ($this->assign_parents == TRUE && count($this->cat_parents) > 0)
  1213. {
  1214. foreach($this->cat_parents as $kitty => $galore)
  1215. {
  1216. $this->categories[$kitty] = $all_cats[$kitty];
  1217. }
  1218. }
  1219. }
  1220. }
  1221. // --------------------------------------------------------------------
  1222. /**
  1223. * Delete Post
  1224. *
  1225. * @access public
  1226. * @param parameter list
  1227. * @return void
  1228. */
  1229. function deletePost($plist)
  1230. {
  1231. $parameters = $plist->output_parameters();
  1232. if ( ! $this->fetch_member_data($parameters['2'], $parameters['3']))
  1233. {
  1234. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  1235. }
  1236. if ( $this->userdata['group_id'] != '1' AND
  1237. ! $this->userdata['can_delete_self_entries'] AND
  1238. ! $this->userdata['can_delete_all_entries'])
  1239. {
  1240. return $this->EE->xmlrpc->send_error_message('808', $this->EE->lang->line('invalid_access'));
  1241. }
  1242. $this->EE->session->userdata = array_merge(
  1243. $this->EE->session->userdata,
  1244. array(
  1245. 'group_id' => $this->userdata['group_id'],
  1246. 'member_id' => $this->userdata['member_id'],
  1247. 'assigned_channels' => $this->userdata['assigned_channels']
  1248. )
  1249. );
  1250. // Delete the entry
  1251. $this->EE->load->library('api');
  1252. $this->EE->api->instantiate('channel_entries');
  1253. $r = $this->EE->api_channel_entries->delete_entry($parameters['1']);
  1254. if ( ! $r)
  1255. {
  1256. $errors = implode(', ', $this->EE->api_channel_entries->get_errors());
  1257. return $this->EE->xmlrpc->send_error_message('809', $errors);
  1258. }
  1259. else
  1260. {
  1261. return $this->EE->xmlrpc->send_response(array(1,'boolean'));
  1262. }
  1263. }
  1264. // --------------------------------------------------------------------
  1265. /**
  1266. * METAWEBLOG API: new media object
  1267. *
  1268. * XSS Cleaning is bypassed when uploading a file through MetaWeblog API
  1269. *
  1270. * @access public
  1271. * @param parameter list
  1272. * @return void
  1273. */
  1274. function newMediaObject($plist)
  1275. {
  1276. $parameters = $plist->output_parameters();
  1277. if ($this->upload_dir == '')
  1278. {
  1279. return $this->EE->xmlrpc->send_error_message('801', $this->EE->lang->line('invalid_access'));
  1280. }
  1281. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  1282. {
  1283. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  1284. }
  1285. if ($this->userdata['group_id'] != '1' && ! in_array($parameters['0'], $this->userdata['assigned_channels']))
  1286. {
  1287. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_channel'));
  1288. }
  1289. if ($this->userdata['group_id'] != '1')
  1290. {
  1291. $this->EE->db->where('upload_id', $this->upload_dir);
  1292. $this->EE->db->where('member_group', $this->userdata['group_id']);
  1293. if ($this->EE->db->count_all_results('upload_no_access') != 0)
  1294. {
  1295. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_access'));
  1296. }
  1297. }
  1298. $this->EE->db->select('server_path, url');
  1299. $query = $this->EE->db->get_where('upload_prefs', array('id' => $this->upload_dir));
  1300. if ($query->num_rows() == 0)
  1301. {
  1302. return $this->EE->xmlrpc->send_error_message('803', $this->EE->lang->line('invalid_access'));
  1303. }
  1304. /** -------------------------------------
  1305. /** upload the image
  1306. /** -------------------------------------*/
  1307. $this->EE->load->library('filemanager');
  1308. // Disable XSS Filtering
  1309. $this->EE->filemanager->xss_clean_off();
  1310. // Figure out the FULL file path
  1311. $file_path = $this->EE->filemanager->clean_filename(
  1312. $parameters['3']['name'],
  1313. $this->upload_dir,
  1314. array('ignore_dupes' => FALSE)
  1315. );
  1316. $filename = basename($file_path);
  1317. // Check to see if we're dealing with relative paths
  1318. if (strncmp($file_path, '..', 2) == 0)
  1319. {
  1320. $directory = dirname($file_path);
  1321. $file_path = realpath(substr($directory, 1)).'/'.$filename;
  1322. }
  1323. // Upload the file and check for errors
  1324. if (file_put_contents($file_path, $parameters['3']['bits']) === FALSE)
  1325. {
  1326. return $this->EE->xmlrpc->send_error_message(
  1327. '810',
  1328. $this->EE->lang->line('unable_to_upload')
  1329. );
  1330. }
  1331. // Send the file
  1332. $result = $this->EE->filemanager->save_file(
  1333. $file_path,
  1334. $this->upload_dir,
  1335. array(
  1336. 'title' => $filename,
  1337. 'path' => dirname($file_path),
  1338. 'file_name' => $filename
  1339. )
  1340. );
  1341. // Check to see the result
  1342. if ($result['status'] === FALSE)
  1343. {
  1344. $this->EE->xmlrpc->send_error_message(
  1345. '810',
  1346. $result['message']
  1347. );
  1348. }
  1349. // Build XMLRPC response
  1350. $response = array(
  1351. array(
  1352. 'url' => array(
  1353. $query->row('url').$filename,
  1354. 'string'
  1355. ),
  1356. ),
  1357. 'struct'
  1358. );
  1359. return $this->EE->xmlrpc->send_response($response);
  1360. }
  1361. // --------------------------------------------------------------------
  1362. /**
  1363. * BLOGGER API: send user information
  1364. *
  1365. * @access public
  1366. * @param parameter list
  1367. * @return void
  1368. */
  1369. function getUserInfo($plist)
  1370. {
  1371. $parameters = $plist->output_parameters();
  1372. if ( ! $this->fetch_member_data($parameters['1'], $parameters['2']))
  1373. {
  1374. return $this->EE->xmlrpc->send_error_message('802', $this->EE->lang->line('invalid_access'));
  1375. }
  1376. $response = array(array(
  1377. 'nickname' =>
  1378. array($this->userdata['screen_name'],'string'),
  1379. 'userid' =>
  1380. array($this->userdata['member_id'],'string'),
  1381. 'url' =>
  1382. array($this->userdata['url'],'string'),
  1383. 'email' =>
  1384. array($this->userdata['email'],'string'),
  1385. 'lastname' =>
  1386. array('','string'),
  1387. 'fi…

Large files files are truncated, but you can click here to view the full file