mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-19676 Replaced magpie with simplepie
This commit is contained in:
parent
af804e3e0f
commit
e14de6f979
3 changed files with 28 additions and 28 deletions
|
@ -28,7 +28,7 @@
|
||||||
require_once('../config.php');
|
require_once('../config.php');
|
||||||
require_once('lib.php');
|
require_once('lib.php');
|
||||||
require_once('external_form.php');
|
require_once('external_form.php');
|
||||||
require_once($CFG->libdir . '/magpie/rss_fetch.inc');
|
require_once($CFG->libdir . '/simplepie/moodle_simplepie.php');
|
||||||
require_once($CFG->dirroot.'/tag/lib.php');
|
require_once($CFG->dirroot.'/tag/lib.php');
|
||||||
|
|
||||||
require_login();
|
require_login();
|
||||||
|
@ -63,10 +63,11 @@ if ($externalblogform->is_cancelled()){
|
||||||
//save stuff in db
|
//save stuff in db
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'add':
|
case 'add':
|
||||||
$rss = fetch_rss($data->url);
|
$rss = new moodle_simplepie($data->url);
|
||||||
|
|
||||||
$new_external = new stdClass();
|
$new_external = new stdClass();
|
||||||
$new_external->name = (empty($data->name)) ? $rss->channel['title'] : $data->name;
|
$new_external->name = (empty($data->name)) ? $rss->get_title() : $data->name;
|
||||||
$new_external->description = (empty($data->description)) ? $rss->channel['description'] : $data->description;
|
$new_external->description = (empty($data->description)) ? $rss->get_description() : $data->description;
|
||||||
$new_external->userid = $user->id;
|
$new_external->userid = $user->id;
|
||||||
$new_external->url = $data->url;
|
$new_external->url = $data->url;
|
||||||
$new_external->timemodified = mktime();
|
$new_external->timemodified = mktime();
|
||||||
|
@ -83,10 +84,11 @@ if ($externalblogform->is_cancelled()){
|
||||||
case 'edit':
|
case 'edit':
|
||||||
if ($data->id && $DB->record_exists('blog_external', array('id' => $data->id))) {
|
if ($data->id && $DB->record_exists('blog_external', array('id' => $data->id))) {
|
||||||
|
|
||||||
$rss = fetch_rss($data->url);
|
$rss = new moodle_simplepie($data->url);
|
||||||
|
|
||||||
$external->id = $data->id;
|
$external->id = $data->id;
|
||||||
$external->name = (empty($data->name)) ? $rss->channel['title'] : $data->name;
|
$external->name = (empty($data->name)) ? $rss->get_title() : $data->name;
|
||||||
$external->description = (empty($data->description)) ? $rss->channel['description'] : $data->description;
|
$external->description = (empty($data->description)) ? $rss->get_description() : $data->description;
|
||||||
$external->userid = $user->id;
|
$external->userid = $user->id;
|
||||||
$external->url = $data->url;
|
$external->url = $data->url;
|
||||||
$external->timemodified = mktime();
|
$external->timemodified = mktime();
|
||||||
|
|
|
@ -70,8 +70,8 @@ class blog_edit_external_form extends moodleform {
|
||||||
if (!blog_is_valid_url($data['url'])) {
|
if (!blog_is_valid_url($data['url'])) {
|
||||||
$errors['url'] = get_string('invalidurl', 'blog');
|
$errors['url'] = get_string('invalidurl', 'blog');
|
||||||
} else {
|
} else {
|
||||||
$rss = fetch_rss($data['url']);
|
$rss = new moodle_simplepie($data['url']);
|
||||||
if (empty($rss->channel)) {
|
if (!$rss->init()) {
|
||||||
$errors['url'] = get_string('emptyrssfeed', 'blog');
|
$errors['url'] = get_string('emptyrssfeed', 'blog');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,14 +89,14 @@ class blog_edit_external_form extends moodleform {
|
||||||
$url = $mform->getElementValue('url');
|
$url = $mform->getElementValue('url');
|
||||||
|
|
||||||
if (empty($name) || empty($description)) {
|
if (empty($name) || empty($description)) {
|
||||||
$rss = fetch_rss($url);
|
$rss = new moodle_simplepie($url);
|
||||||
|
|
||||||
if (empty($name) && !empty($rss->channel['title'])) {
|
if (empty($name) && $rss->get_title()) {
|
||||||
$mform->setDefault('name', $rss->channel['title']);
|
$mform->setDefault('name', $rss->get_title());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($description) && !empty($rss->channel['description'])) {
|
if (empty($description) && $rss->get_description()) {
|
||||||
$mform->setDefault('description', $rss->channel['description']);
|
$mform->setDefault('description', $rss->get_description());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
blog/lib.php
22
blog/lib.php
|
@ -403,32 +403,30 @@ function blog_print_entry($blogEntry, $viewtype='full', $filtertype='', $filters
|
||||||
*/
|
*/
|
||||||
function blog_fetch_external_entries($external_blog) {
|
function blog_fetch_external_entries($external_blog) {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
require_once($CFG->libdir . '/magpie/rss_fetch.inc');
|
require_once($CFG->libdir . '/simplepie/moodle_simplepie.php');
|
||||||
|
|
||||||
if (!blog_is_valid_url($external_blog->url)) {
|
if (!blog_is_valid_url($external_blog->url)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$rss = fetch_rss($external_blog->url)) {
|
$rss = new moodle_simplepie($external_blog->url);
|
||||||
|
|
||||||
|
if (empty($rss->data)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($rss->channel) || empty($rss->items)) {
|
foreach ($rss->get_items() as $entry) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($rss->items as $entry) {
|
|
||||||
$params = array('userid' => $external_blog->userid,
|
$params = array('userid' => $external_blog->userid,
|
||||||
'module' => 'blog',
|
'module' => 'blog',
|
||||||
'uniquehash' => $entry['link'],
|
'uniquehash' => $entry->get_permalink(),
|
||||||
'publishstate' => 'site',
|
'publishstate' => 'site',
|
||||||
'format' => FORMAT_HTML);
|
'format' => FORMAT_HTML);
|
||||||
|
|
||||||
if (!$DB->record_exists('post', $params)) {
|
if (!$DB->record_exists('post', $params)) {
|
||||||
$params['subject'] = $entry['title'];
|
$params['subject'] = $entry->get_title();
|
||||||
$params['summary'] = $entry['description'];
|
$params['summary'] = $entry->get_description();
|
||||||
$params['created'] = $entry['date_timestamp'];
|
$params['created'] = $entry->get_date('U');
|
||||||
$params['lastmodified'] = $entry['date_timestamp'];
|
$params['lastmodified'] = $entry->get_date('U');
|
||||||
|
|
||||||
$id = $DB->insert_record('post', $params);
|
$id = $DB->insert_record('post', $params);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue