Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * Social profile field define.
  19   *
  20   * @package    profilefield_social
  21   * @copyright  2020 Bas Brands <bas@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  /**
  26   * Class profile_field_social.
  27   *
  28   * @copyright  2020 Bas Brands <bas@moodle.com>
  29   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class profile_field_social extends profile_field_base {
  32  
  33      /**
  34       * Adds elements for this field type to the edit form.
  35       * @param moodleform $mform
  36       */
  37      public function edit_field_add($mform) {
  38          $mform->addElement('text', $this->inputname, $this->field->name, null, null);
  39          if ($this->field->param1 === 'url') {
  40              $mform->setType($this->inputname, PARAM_URL);
  41          } else {
  42              $mform->setType($this->inputname, PARAM_NOTAGS);
  43          }
  44      }
  45  
  46      /**
  47       * alter the fieldname to be fetched from the language file.
  48       *
  49       * @param stdClass $field
  50       */
  51      public function set_field($field) {
  52          $networks = profilefield_social\helper::get_networks();
  53          $field->name = $networks[$field->name];
  54          parent::set_field($field);
  55      }
  56  
  57      /**
  58       * Display the data for this field
  59       * @return string
  60       */
  61      public function display_data() {
  62          $network = $this->field->param1;
  63          $networkurls = profilefield_social\helper::get_network_urls();
  64  
  65          if (array_key_exists($network, $networkurls)) {
  66              $pattern = ['%%ENCODED%%', '%%PLAIN%%'];
  67              $data = [rawurlencode($this->data), $this->data];
  68              return str_replace($pattern, $data, $networkurls[$network]);
  69          }
  70  
  71          return $this->data;
  72      }
  73  
  74      /**
  75       * Return the field type and null properties.
  76       * This will be used for validating the data submitted by a user.
  77       *
  78       * @return array the param type and null property
  79       * @since Moodle 3.2
  80       */
  81      public function get_field_properties() {
  82          return array(PARAM_TEXT, NULL_NOT_ALLOWED);
  83      }
  84  }
  85  
  86