mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +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('lib.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_login();
|
||||
|
@ -63,10 +63,11 @@ if ($externalblogform->is_cancelled()){
|
|||
//save stuff in db
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
$rss = fetch_rss($data->url);
|
||||
$rss = new moodle_simplepie($data->url);
|
||||
|
||||
$new_external = new stdClass();
|
||||
$new_external->name = (empty($data->name)) ? $rss->channel['title'] : $data->name;
|
||||
$new_external->description = (empty($data->description)) ? $rss->channel['description'] : $data->description;
|
||||
$new_external->name = (empty($data->name)) ? $rss->get_title() : $data->name;
|
||||
$new_external->description = (empty($data->description)) ? $rss->get_description() : $data->description;
|
||||
$new_external->userid = $user->id;
|
||||
$new_external->url = $data->url;
|
||||
$new_external->timemodified = mktime();
|
||||
|
@ -83,10 +84,11 @@ if ($externalblogform->is_cancelled()){
|
|||
case 'edit':
|
||||
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->name = (empty($data->name)) ? $rss->channel['title'] : $data->name;
|
||||
$external->description = (empty($data->description)) ? $rss->channel['description'] : $data->description;
|
||||
$external->name = (empty($data->name)) ? $rss->get_title() : $data->name;
|
||||
$external->description = (empty($data->description)) ? $rss->get_description() : $data->description;
|
||||
$external->userid = $user->id;
|
||||
$external->url = $data->url;
|
||||
$external->timemodified = mktime();
|
||||
|
|
|
@ -70,8 +70,8 @@ class blog_edit_external_form extends moodleform {
|
|||
if (!blog_is_valid_url($data['url'])) {
|
||||
$errors['url'] = get_string('invalidurl', 'blog');
|
||||
} else {
|
||||
$rss = fetch_rss($data['url']);
|
||||
if (empty($rss->channel)) {
|
||||
$rss = new moodle_simplepie($data['url']);
|
||||
if (!$rss->init()) {
|
||||
$errors['url'] = get_string('emptyrssfeed', 'blog');
|
||||
}
|
||||
}
|
||||
|
@ -89,14 +89,14 @@ class blog_edit_external_form extends moodleform {
|
|||
$url = $mform->getElementValue('url');
|
||||
|
||||
if (empty($name) || empty($description)) {
|
||||
$rss = fetch_rss($url);
|
||||
$rss = new moodle_simplepie($url);
|
||||
|
||||
if (empty($name) && !empty($rss->channel['title'])) {
|
||||
$mform->setDefault('name', $rss->channel['title']);
|
||||
if (empty($name) && $rss->get_title()) {
|
||||
$mform->setDefault('name', $rss->get_title());
|
||||
}
|
||||
|
||||
if (empty($description) && !empty($rss->channel['description'])) {
|
||||
$mform->setDefault('description', $rss->channel['description']);
|
||||
if (empty($description) && $rss->get_description()) {
|
||||
$mform->setDefault('description', $rss->get_description());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
26
blog/lib.php
26
blog/lib.php
|
@ -403,32 +403,30 @@ function blog_print_entry($blogEntry, $viewtype='full', $filtertype='', $filters
|
|||
*/
|
||||
function blog_fetch_external_entries($external_blog) {
|
||||
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)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$rss = fetch_rss($external_blog->url)) {
|
||||
$rss = new moodle_simplepie($external_blog->url);
|
||||
|
||||
if (empty($rss->data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($rss->channel) || empty($rss->items)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($rss->items as $entry) {
|
||||
foreach ($rss->get_items() as $entry) {
|
||||
$params = array('userid' => $external_blog->userid,
|
||||
'module' => 'blog',
|
||||
'uniquehash' => $entry['link'],
|
||||
'uniquehash' => $entry->get_permalink(),
|
||||
'publishstate' => 'site',
|
||||
'format' => FORMAT_HTML);
|
||||
|
||||
if (!$DB->record_exists('post', $params)) {
|
||||
$params['subject'] = $entry['title'];
|
||||
$params['summary'] = $entry['description'];
|
||||
$params['created'] = $entry['date_timestamp'];
|
||||
$params['lastmodified'] = $entry['date_timestamp'];
|
||||
$params['subject'] = $entry->get_title();
|
||||
$params['summary'] = $entry->get_description();
|
||||
$params['created'] = $entry->get_date('U');
|
||||
$params['lastmodified'] = $entry->get_date('U');
|
||||
|
||||
$id = $DB->insert_record('post', $params);
|
||||
|
||||
|
@ -571,7 +569,7 @@ function blog_get_headers() {
|
|||
} else {
|
||||
$courseid = $site->id;
|
||||
}
|
||||
|
||||
|
||||
$PAGE->navbar->add($strparticipants, "$CFG->wwwroot/user/index.php?id=$courseid");
|
||||
$PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id");
|
||||
$PAGE->navbar->add($strblogentries, $blog_url->out());
|
||||
|
@ -647,7 +645,7 @@ function blog_get_headers() {
|
|||
// Heading: Blog entries by [group name] about [course fullname]
|
||||
if (!empty($groupid) && empty($modid)) {
|
||||
$blog_url->param('courseid', $course->id);
|
||||
|
||||
|
||||
$PAGE->navbar->add($strblogentries, $blog_url->out());
|
||||
$blog_url->remove_params(array('courseid'));
|
||||
$blog_url->param('groupid', $groupid);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue