Dotclear

source: plugins/importExport/inc/class.dc.import.feed.php @ 2566:9bf417837888

Revision 2566:9bf417837888, 2.5 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Add some people in CREDITS, remove trailing spaces and tabs.

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
[840]4# This file is part of importExport, a plugin for DotClear2.
[0]5#
[840]6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear
[0]7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14class dcImportFeed extends dcIeModule
15{
16     protected $status = false;
17     protected $feed_url = '';
[2566]18
[0]19     public function setInfo()
20     {
[840]21          $this->type = 'import';
[1559]22          $this->name = __('RSS or Atom feed import');
23          $this->description = __('Add a feed content to the blog.');
[0]24     }
[2566]25
[0]26     public function process($do)
27     {
28          if ($do == 'ok') {
29               $this->status = true;
30               return;
31          }
[2566]32
[0]33          if (empty($_POST['feed_url'])) {
34               return;
35          }
[2566]36
[0]37          $this->feed_url = $_POST['feed_url'];
[2566]38
[0]39          $feed = feedReader::quickParse($this->feed_url);
40          if ($feed === false) {
41               throw new Exception(__('Cannot retrieve feed URL.'));
42          }
43          if (count($feed->items) == 0) {
44               throw new Exception(__('No items in feed.'));
45          }
[2566]46
[0]47          $cur = $this->core->con->openCursor($this->core->prefix.'post');
48          $this->core->con->begin();
49          foreach ($feed->items as $item)
50          {
51               $cur->clean();
52               $cur->user_id = $this->core->auth->userID();
53               $cur->post_content = $item->content ? $item->content : $item->description;
54               $cur->post_title = $item->title ? $item->title : text::cutString(html::clean($cur->post_content),60);
55               $cur->post_format = 'xhtml';
56               $cur->post_status = -2;
57               $cur->post_dt = strftime('%Y-%m-%d %H:%M:%S',$item->TS);
[2566]58
[0]59               try {
60                    $post_id = $this->core->blog->addPost($cur);
61               } catch (Exception $e) {
62                    $this->core->con->rollback();
63                    throw $e;
64               }
[2566]65
[0]66               foreach ($item->subject as $subject) {
67                    $this->core->meta->setPostMeta($post_id,'tag',dcMeta::sanitizeMetaID($subject));
68               }
69          }
[2566]70
[0]71          $this->core->con->commit();
72          http::redirect($this->getURL().'&do=ok');
[2566]73
[0]74     }
[2566]75
[0]76     public function gui()
77     {
78          if ($this->status) {
[1553]79               dcPage::success(__('Content successfully imported.'));
[0]80          }
[2566]81
[0]82          echo
83          '<form action="'.$this->getURL(true).'" method="post">'.
[1559]84          '<p>'.sprintf(__('Add a feed content to the current blog: <strong>%s</strong>.'),html::escapeHTML($this->core->blog->name)).'</p>'.
[2566]85
[840]86          '<p><label for="feed_url">'.__('Feed URL:').'</label>'.
87          form::field('feed_url',50,300,html::escapeHTML($this->feed_url)).'</p>'.
[2566]88
[840]89          '<p>'.
[0]90          $this->core->formNonce().
91          form::hidden(array('do'),1).
[840]92          '<input type="submit" value="'.__('Import').'" /></p>'.
[2566]93
[0]94          '</form>';
95     }
96}
Note: See TracBrowser for help on using the repository browser.

Sites map