Search moodle.org's
Developer Documentation


Long Term Support Release

  • Bug fixes for general core bugs in 3.1.x ended 8 May 2017 (12 months).
  • Bug fixes for security issues in 3.1.x ended 13 May 2019 (36 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x , 5.5.x or 5.6.x on Windows - http://windows.php.net/download/). PHP 7.0.x is supported but has some engine limitations. PHP 7.1.x is not supported.
  • Differences Between: [Versions 31 and 32] [Versions 31 and 33] [Versions 31 and 34] [Versions 31 and 35] [Versions 31 and 36] [Versions 31 and 37] [Versions 31 and 38]

       1  <?php
       2  // This file is part of Moodle - http://moodle.org/
       3  //
       4  // Moodle is free software: you can redistribute it and/or modify
       5  // it under the terms of the GNU General Public License as published by
       6  // the Free Software Foundation, either version 3 of the License, or
       7  // (at your option) any later version.
       8  //
       9  // Moodle is distributed in the hope that it will be useful,
      10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12  // GNU General Public License for more details.
      13  //
      14  // You should have received a copy of the GNU General Public License
      15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
      16  
      17  
      18  /**
      19   * List of external blogs for current user.
      20   *
      21   * @package    moodlecore
      22   * @subpackage blog
      23   * @copyright  2009 Nicolas Connault
      24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      25   */
      26  
      27  require_once('../config.php');
      28  require_once ('lib.php');
      29  
      30  require_login();
      31  $context = context_system::instance();
      32  $PAGE->set_context(context_user::instance($USER->id));
      33  $PAGE->set_url(new moodle_url('/blog/external_blogs.php'));
      34  require_capability('moodle/blog:manageexternal', $context);
      35  
      36  $delete = optional_param('delete', null, PARAM_INT);
      37  
      38  $strexternalblogs = get_string('externalblogs', 'blog');
      39  $straddnewexternalblog = get_string('addnewexternalblog', 'blog');
      40  $strblogs = get_string('blogs', 'blog');
      41  $message = null;
      42  
      43  if ($delete && confirm_sesskey()) {
      44      $externalbloguserid = $DB->get_field('blog_external', 'userid', array('id' => $delete));
      45      if ($externalbloguserid == $USER->id) {
      46          // Delete the external blog.
      47          $DB->delete_records('blog_external', array('id' => $delete));
      48  
      49          // Delete the external blog's posts.
      50          $deletewhere = 'module = :module
      51                              AND userid = :userid
      52                              AND ' . $DB->sql_isnotempty('post', 'uniquehash', false, false) . '
      53                              AND ' . $DB->sql_compare_text('content') . ' = ' . $DB->sql_compare_text(':delete');
      54          $DB->delete_records_select('post', $deletewhere, array('module' => 'blog_external',
      55                                                                 'userid' => $USER->id,
      56                                                                 'delete' => $delete));
      57  
      58          $message = get_string('externalblogdeleted', 'blog');
      59      }
      60  }
      61  
      62  $blogs = $DB->get_records('blog_external', array('userid' => $USER->id));
      63  
      64  $PAGE->set_heading(fullname($USER));
      65  $PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
      66  $PAGE->set_pagelayout('standard');
      67  
      68  echo $OUTPUT->header();
      69  echo $OUTPUT->heading($strexternalblogs, 2);
      70  
      71  if (!empty($message)) {
      72      echo $OUTPUT->notification($message);
      73  }
      74  
      75  echo $OUTPUT->box_start('generalbox boxaligncenter');
      76  
      77  if (!empty($blogs)) {
      78      $table = new html_table();
      79      $table->cellpadding = 4;
      80      $table->attributes['class'] = 'generaltable boxaligncenter';
      81      $table->head = array(get_string('name'),
      82                           get_string('url', 'blog'),
      83                           get_string('timefetched', 'blog'),
      84                           get_string('valid', 'blog'),
      85                           get_string('actions'));
      86  
      87      foreach ($blogs as $blog) {
      88          if ($blog->failedlastsync) {
      89              $validicon = $OUTPUT->pix_icon('i/invalid', get_string('feedisinvalid', 'blog'));
      90          } else {
      91              $validicon = $OUTPUT->pix_icon('i/valid', get_string('feedisvalid', 'blog'));
      92          }
      93  
      94          $editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id));
      95          $editicon = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('editexternalblog', 'blog')));
      96  
      97          $deletelink = new moodle_url('/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey' => sesskey()));
      98          $action = new confirm_action(get_string('externalblogdeleteconfirm', 'blog'));
      99          $deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog')),
     100                                             $action);
     101  
     102          $table->data[] = new html_table_row(array($blog->name,
     103                                                    $blog->url,
     104                                                    userdate($blog->timefetched),
     105                                                    $validicon,
     106                                                    $editicon . $deleteicon));
     107      }
     108      echo html_writer::table($table);
     109  }
     110  
     111  $newexternalurl = new moodle_url('/blog/external_blog_edit.php');
     112  echo html_writer::link($newexternalurl, $straddnewexternalblog);
     113  echo $OUTPUT->box_end();
     114  echo $OUTPUT->footer();
    

    Search This Site: