type = 'import'; $this->name = __('RSS or Atom feed import'); $this->description = __('Add a feed content to the blog.'); } public function process($do) { if ($do == 'ok') { $this->status = true; return; } if (empty($_POST['feed_url'])) { return; } $this->feed_url = $_POST['feed_url']; $feed = feedReader::quickParse($this->feed_url); if ($feed === false) { throw new Exception(__('Cannot retrieve feed URL.')); } if (count($feed->items) == 0) { throw new Exception(__('No items in feed.')); } $cur = $this->core->con->openCursor($this->core->prefix.'post'); $this->core->con->begin(); foreach ($feed->items as $item) { $cur->clean(); $cur->user_id = $this->core->auth->userID(); $cur->post_content = $item->content ? $item->content : $item->description; $cur->post_title = $item->title ? $item->title : text::cutString(html::clean($cur->post_content),60); $cur->post_format = 'xhtml'; $cur->post_status = -2; $cur->post_dt = strftime('%Y-%m-%d %H:%M:%S',$item->TS); try { $post_id = $this->core->blog->addPost($cur); } catch (Exception $e) { $this->core->con->rollback(); throw $e; } foreach ($item->subject as $subject) { $this->core->meta->setPostMeta($post_id,'tag',dcMeta::sanitizeMetaID($subject)); } } $this->core->con->commit(); http::redirect($this->getURL().'&do=ok'); } public function gui() { if ($this->status) { dcPage::success(__('Content successfully imported.')); } echo '
'. '

'.sprintf(__('Add a feed content to the current blog: %s.'),html::escapeHTML($this->core->blog->name)).'

'. '

'. form::field('feed_url',50,300,html::escapeHTML($this->feed_url)).'

'. '

'. $this->core->formNonce(). form::hidden(array('do'),1). '

'. '
'; } }