Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  /**
   3   * Copyright 2015-2017 Horde LLC (http://www.horde.org/)
   4   *
   5   * See the enclosed file LICENSE for license information (LGPL). If you
   6   * did not receive this file, see http://www.horde.org/licenses/lgpl21.
   7   *
   8   * @category  Horde
   9   * @copyright 2015-2017 Horde LLC
  10   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11   * @package   Mime
  12   */
  13  
  14  /**
  15   * Upgrade V1 of MIME serialized data to V2.
  16   *
  17   * @author    Michael Slusarz <slusarz@horde.org>
  18   * @category  Horde
  19   * @copyright 2015-2017 Horde LLC
  20   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  21   * @package   Mime
  22   * @since     2.8.0
  23   */
  24  class Horde_Mime_Part_Upgrade_V1
  25  {
  26      /**
  27       * Converted data.
  28       *
  29       * @var array
  30       */
  31      public $data = null;
  32  
  33      /**
  34       * Constructor.
  35       *
  36       * @param array $data  V1 data.
  37       */
  38      public function __construct($data)
  39      {
  40          // Version number
  41          array_shift($data);
  42  
  43          $d = array();
  44  
  45          $type = array_shift($data);
  46          $subtype = array_shift($data);
  47  
  48          $ct = Horde_Mime_Headers_ContentParam_ContentType::create();
  49          $d[4] = new Horde_Mime_Headers();
  50          $d[4]->addHeaderOb($ct);
  51          $ct->setContentParamValue($type . '/' . $subtype);
  52  
  53          $d[9] = array_shift($data);
  54  
  55          if ($lang = array_shift($data)) {
  56              $d[4]->addHeaderOb(
  57                  new Horde_Mime_Headers_ContentLanguage('', $lang)
  58              );
  59          }
  60  
  61          if ($cd = array_shift($data)) {
  62              $hdr = new Horde_Mime_Headers_ContentDescription(null, '');
  63              $d[4]->addHeaderOb($hdr);
  64              $hdr->setValue($cd);
  65          }
  66  
  67          $cd = new Horde_Mime_Headers_ContentParam_ContentDisposition(null, '');
  68          $d[4]->addHeaderOb($cd);
  69          $cd->setContentParamValue(array_shift($data));
  70  
  71          foreach (array_shift($data) as $key => $val) {
  72              $cd[$key] = $val;
  73          }
  74  
  75          foreach (array_shift($data) as $key => $val) {
  76              $ct[$key] = $val;
  77          }
  78  
  79          $d[7] = array_shift($data);
  80          $d[6] = array_shift($data);
  81          $d[2] = array_shift($data);
  82          $d[5] = array_shift($data);
  83  
  84          if ($boundary = array_shift($data)) {
  85              $ct['boundary'] = $boundary;
  86          }
  87  
  88          $d[1] = array_shift($data);
  89  
  90          if ($cid = array_shift($data)) {
  91              $hdr = new Horde_Mime_Headers_ContentId(null, $cid);
  92              $d[4]->addHeaderOb($hdr);
  93          }
  94  
  95          if ($cd = array_shift($data)) {
  96              $hdr = new Horde_Mime_Headers_Element_Single('Content-Duration', '');
  97              $d[4]->addHeaderOb($hdr);
  98              $hdr->setValue($cd);
  99          }
 100  
 101          $d[8] = 0;
 102          if (array_shift($data)) {
 103              $d[8] |= STATUS_REINDEX;
 104          }
 105          if (array_shift($data)) {
 106              $d[8] |= STATUS_BASEPART;
 107          }
 108  
 109          $d[3] = array_shift($data);
 110  
 111          if (count($data)) {
 112              $d[10] = reset($data);
 113          }
 114  
 115          $this->data = $d;
 116      }
 117  
 118  }