Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blog/external_blog_edit.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 
00028 require_once('../config.php');
00029 require_once('lib.php');
00030 require_once('external_blog_edit_form.php');
00031 require_once($CFG->libdir . '/simplepie/moodle_simplepie.php');
00032 require_once($CFG->dirroot.'/tag/lib.php');
00033 
00034 require_login();
00035 $context = get_context_instance(CONTEXT_SYSTEM);
00036 require_capability('moodle/blog:manageexternal', $context);
00037 
00038 // TODO redirect if $CFG->useexternalblogs is off, $CFG->maxexternalblogsperuser == 0, or if user doesn't have caps to manage external blogs
00039 
00040 $id = optional_param('id', null, PARAM_INT);
00041 $url = new moodle_url('/blog/external_blog_edit.php');
00042 if ($id !== null) {
00043     $url->param('id', $id);
00044 }
00045 $PAGE->set_url($url);
00046 $PAGE->set_context($context);
00047 $PAGE->set_pagelayout('standard');
00048 
00049 $returnurl = new moodle_url('/blog/external_blogs.php');
00050 
00051 $action = (empty($id)) ? 'add' : 'edit';
00052 
00053 $external = new stdClass();
00054 
00055 // Check that this id exists
00056 if (!empty($id) && !$DB->record_exists('blog_external', array('id' => $id))) {
00057     print_error('wrongexternalid', 'blog');
00058 } elseif (!empty($id)) {
00059     $external = $DB->get_record('blog_external', array('id' => $id));
00060 }
00061 
00062 $strformheading = ($action == 'edit') ? get_string('editexternalblog', 'blog') : get_string('addnewexternalblog', 'blog');
00063 $strexternalblogs = get_string('externalblogs','blog');
00064 $strblogs = get_string('blogs','blog');
00065 
00066 $externalblogform = new blog_edit_external_form();
00067 
00068 if ($externalblogform->is_cancelled()){
00069     redirect($returnurl);
00070 
00071 } else if ($data = $externalblogform->get_data()) {
00072     //save stuff in db
00073     switch ($action) {
00074         case 'add':
00075             $rss = new moodle_simplepie($data->url);
00076 
00077             $newexternal = new stdClass();
00078             $newexternal->name = (empty($data->name)) ? $rss->get_title() : $data->name;
00079             $newexternal->description = (empty($data->description)) ? $rss->get_description() : $data->description;
00080             $newexternal->userid = $USER->id;
00081             $newexternal->url = $data->url;
00082             $newexternal->filtertags = $data->filtertags;
00083             $newexternal->timemodified = mktime();
00084 
00085             $newexternal->id = $DB->insert_record('blog_external', $newexternal);
00086             blog_sync_external_entries($newexternal);
00087             tag_set('blog_external', $newexternal->id, explode(',', $data->autotags));
00088 
00089             break;
00090 
00091         case 'edit':
00092             if ($data->id && $DB->record_exists('blog_external', array('id' => $data->id))) {
00093 
00094                 $rss = new moodle_simplepie($data->url);
00095 
00096                 $external->id = $data->id;
00097                 $external->name = (empty($data->name)) ? $rss->get_title() : $data->name;
00098                 $external->description = (empty($data->description)) ? $rss->get_description() : $data->description;
00099                 $external->userid = $USER->id;
00100                 $external->url = $data->url;
00101                 $external->filtertags = $data->filtertags;
00102                 $external->timemodified = mktime();
00103 
00104                 $DB->update_record('blog_external', $external);
00105                 tag_set('blog_external', $external->id, explode(',', $data->autotags));
00106 
00107             } else {
00108                 print_error('wrongexternalid', 'blog');
00109             }
00110 
00111             break;
00112 
00113         default :
00114             print_error('invalidaction');
00115     }
00116 
00117     redirect($returnurl);
00118 }
00119 
00120 $PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname);
00121 $PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
00122 
00123 echo $OUTPUT->header();
00124 echo $OUTPUT->heading($strformheading, 2);
00125 
00126 $externalblogform->set_data($external);
00127 $externalblogform->display();
00128 
00129 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations