Ticket #12731: 0001-Remove-changed-some-deprecated-PHP7-functions.patch

File 0001-Remove-changed-some-deprecated-PHP7-functions.patch, 15.3 KB (added by charles.bovy@…, 3 years ago)
  • classes/Database/Query/mysql.php

    From 0cffb7b27d00110d1531da050c6f0380ea70613e Mon Sep 17 00:00:00 2001
    From: Charles Bovy <charles.bovy@gmail.com>
    Date: Mon, 18 Apr 2016 16:17:39 +0200
    Subject: [PATCH] Remove/changed some deprecated PHP7 functions: * split() by
     preg_split() * eregi() by preg_match() * mysql_*() by mysqli_*() * PHP4
     constructors (http://cweiske.de/tagebuch/php4-constructors-php7.htm)
    
    ---
     classes/Database/Query/mysql.php               | 30 +++++++++----------
     classes/Database/mysql.php                     | 14 ++++-----
     classes/vcalendar.php                          | 40 ++++++++++++++++++++------
     includes/sorting.php                           |  2 +-
     modules/music/mp3act_functions.php             | 18 ++++++------
     modules/mythweb/tmpl/default/set_flvplayer.php |  2 +-
     modules/tv/classes/Recording.php               |  5 +++-
     7 files changed, 69 insertions(+), 42 deletions(-)
    
    diff --git a/classes/Database/Query/mysql.php b/classes/Database/Query/mysql.php
    index f05ddc2..b5e2cf1 100644
    a b class Database_Query_mysql extends Database_Query { 
    5454                $arg = array_shift($args);
    5555                $this->last_query .= is_null($arg)
    5656                                        ? 'NULL'
    57                                         : "'".mysql_real_escape_string($arg)."'";
     57                                        : "'".mysqli_real_escape_string($arg)."'";
    5858            }
    5959        }
    6060    // Perform the query
    class Database_Query_mysql extends Database_Query { 
    6363            $this->db->error();
    6464            trigger_error($this->db->error, E_USER_ERROR);
    6565        }
    66         $this->sh = mysql_query($this->last_query, $this->dbh);
     66        $this->sh = mysqli_query($this->last_query, $this->dbh);
    6767
    6868    // Cache these
    6969        if (is_bool($this->sh)) {
    70             $this->insert_id     = mysql_insert_id($this->dbh);
    71             $this->affected_rows = mysql_affected_rows($this->dbh);
     70            $this->insert_id     = mysqli_insert_id($this->dbh);
     71            $this->affected_rows = mysqli_affected_rows($this->dbh);
    7272        }
    7373        else {
    74             $this->num_rows      = mysql_num_rows($this->sh);
     74            $this->num_rows      = mysqli_num_rows($this->sh);
    7575        }
    7676
    7777        if ($this->sh === false) {
    7878            if ($this->db->fatal_errors)
    79                 trigger_error('SQL Error: '.mysql_error($this->dbh).' [#'.mysql_errno($this->dbh).']', E_USER_ERROR);
     79                trigger_error('SQL Error: '.mysqli_error($this->dbh).' [#'.mysqli_errno($this->dbh).']', E_USER_ERROR);
    8080            else
    8181                $this->db->error();
    8282        }
    class Database_Query_mysql extends Database_Query { 
    8787 * php.  The only difference is that the resource handle gets passed-in
    8888 * automatically.  eg.
    8989 *
    90  *      mysql_fetch_row($result);   ->  $sh->fetch_row();
    91  *      mysql_affected_rows($dbh);  ->  $sh->affected_rows();
     90 *      mysqli_fetch_row($result);   ->  $sh->fetch_row();
     91 *      mysqli_affected_rows($dbh);  ->  $sh->affected_rows();
    9292 **/
    9393
    9494/**
    class Database_Query_mysql extends Database_Query { 
    9696 * @return mixed
    9797 **/
    9898    function fetch_col() {
    99         list($return) = mysql_fetch_row($this->sh);
     99        list($return) = mysqli_fetch_row($this->sh);
    100100        return $return;
    101101    }
    102102
    class Database_Query_mysql extends Database_Query { 
    114114 * @return array
    115115 **/
    116116    function fetch_row() {
    117         return mysql_fetch_row($this->sh);
     117        return mysqli_fetch_row($this->sh);
    118118    }
    119119
    120120/**
    class Database_Query_mysql extends Database_Query { 
    124124 * @return assoc
    125125 **/
    126126    function fetch_assoc() {
    127         return mysql_fetch_assoc($this->sh);
     127        return mysqli_fetch_assoc($this->sh);
    128128    }
    129129
    130130/**
    class Database_Query_mysql extends Database_Query { 
    134134 * @return assoc
    135135 **/
    136136    function fetch_array($result_type=MYSQL_BOTH) {
    137         return mysql_fetch_array($this->sh, $result_type);
     137        return mysqli_fetch_array($this->sh, $result_type);
    138138    }
    139139
    140140/**
    class Database_Query_mysql extends Database_Query { 
    144144 * @return object
    145145 **/
    146146    function fetch_object() {
    147         return mysql_fetch_object($this->sh);
     147        return mysqli_fetch_object($this->sh);
    148148    }
    149149
    150150/**
    class Database_Query_mysql extends Database_Query { 
    152152 * @return bool
    153153 **/
    154154    function data_seek($row_number) {
    155         return mysql_data_seek($this->sh, $row_number);
     155        return mysqli_data_seek($this->sh, $row_number);
    156156    }
    157157
    158158/**
    class Database_Query_mysql extends Database_Query { 
    184184 **/
    185185    function finish() {
    186186        if ($this->sh && is_resource($this->sh))
    187             mysql_free_result($this->sh);
     187            mysqli_free_result($this->sh);
    188188        unset($this->sh);
    189189    }
    190190
  • classes/Database/mysql.php

    diff --git a/classes/Database/mysql.php b/classes/Database/mysql.php
    index 6baa795..e0d563f 100644
    a b class Database_mysql extends Database { 
    5252            }
    5353        }
    5454    // Connect to the database
    55         $this->dbh = @mysql_connect($port ? "$server:$port" : $server, $login, $password)
     55        $this->dbh = @mysqli_connect($port ? "$server:$port" : $server, $login, $password)
    5656            or $this->error("Can't connect to the database server.");
    5757        if ($this->dbh) {
    58             @mysql_select_db($db_name, $this->dbh)
     58            @mysqli_select_db($db_name, $this->dbh)
    5959                or $this->error("Can't access the database file.");
    6060        }
    6161    }
    class Database_mysql extends Database { 
    7373        if (is_null($string))
    7474            return 'NULL';
    7575    // Just a string
    76         return str_replace('?', '\\?', "'".mysql_real_escape_string($string, $this->dbh)."'");
     76        return str_replace('?', '\\?', "'".mysqli_real_escape_string($string, $this->dbh)."'");
    7777    }
    7878
    7979/**
    class Database_mysql extends Database { 
    110110 * @return string The most recent error string
    111111 **/
    112112    function _errstr() {
    113         return $this->dbh ? mysql_error($this->dbh) : mysql_error();
     113        return $this->dbh ? mysqli_error($this->dbh) : mysqli_error();
    114114    }
    115115
    116116/**
    117117 * @return int The most recent error number
    118118 **/
    119119    function _errno() {
    120         return $this->dbh ? mysql_errno($this->dbh) : mysql_errno();
     120        return $this->dbh ? mysqli_errno($this->dbh) : mysqli_errno();
    121121    }
    122122
    123123/**
    124124 * @return string Information about the mysql server
    125125 **/
    126126    function server_info() {
    127         return mysql_get_server_info($this->dbh);
     127        return mysqli_get_server_info($this->dbh);
    128128    }
    129129
    130130/**
    131131 * @return bool true on success
    132132 **/
    133133    function close() {
    134         return mysql_close($this->dbh);
     134        return mysqli_close($this->dbh);
    135135    }
    136136
    137137}
  • classes/vcalendar.php

    diff --git a/classes/vcalendar.php b/classes/vcalendar.php
    index 86b7db3..a1b2a7c 100644
    a b class vcalendar { 
    8484 * @since 2.2.13 - 2007-12-30
    8585 * @return void
    8686 */
    87   function vcalendar () {
     87  function __construct () {
    8888    $this->_makeVersion();
    8989    $this->calscale   = null;
    9090    $this->method     = null;
    class vcalendar { 
    107107    $this->components = array();
    108108    $this->setProperty( 'X-WR-TIMEZONE', date('e') );
    109109  }
     110 function vcalendar () {
     111    self::__construct();
     112 }
    110113/*********************************************************************************/
    111114/**
    112115 * Property Name: CALSCALE
    class calendarComponent { 
    17921795 * @author Kjell-Inge Gustafsson <ical@kigkonsult.se>
    17931796 * @since 2.3.1 - 2007-11-19
    17941797 */
    1795   function calendarComponent() {
     1798  function __construct () {
    17961799    $this->objName         = ( isset( $this->timezonetype )) ?
    17971800                          strtolower( $this->timezonetype )  :  get_class ( $this );
    17981801    $this->uid             = array();
    class calendarComponent { 
    18511854
    18521855    $this->_makeDtstamp();
    18531856  }
     1857  function calendarComponent() {
     1858    self::__construct();
     1859  }
    18541860/*********************************************************************************/
    18551861/**
    18561862 * Property Name: ACTION
    class vevent extends calendarComponent { 
    70277033 * @since 0.3.0 - 2006-08-10
    70287034 * @return void
    70297035 */
    7030   function vevent() {
     7036  function __construct() {
    70317037    $this->calendarComponent();
    70327038  }
     7039  function vevent() {
     7040    self::__construct();
     7041  }
    70337042/**
    70347043 * create formatted output for calendar component VEVENT object instance
    70357044 *
    class vtodo extends calendarComponent { 
    71007109 * @since 0.3.0 - 2006-08-10
    71017110 * @return void
    71027111 */
    7103   function vtodo() {
     7112  function __construct() {
    71047113    $this->calendarComponent();
    71057114  }
     7115  function vtodo() {
     7116    self::__construct();
     7117  }
    71067118/**
    71077119 * create formatted output for calendar component VTODO object instance
    71087120 *
    class vjournal extends calendarComponent { 
    71747186 * @since 0.3.0 - 2006-08-10
    71757187 * @return void
    71767188 */
    7177   function vjournal() {
     7189  function __construct() {
    71787190    $this->calendarComponent();
    71797191  }
     7192  function vjournal() {
     7193    self::__construct();
     7194  }
    71807195/**
    71817196 * create formatted output for calendar component VJOURNAL object instance
    71827197 *
    class vfreebusy extends calendarComponent { 
    72377252 * @since 0.7.3 - 2006-09-09
    72387253 * @return void
    72397254 */
    7240   function vfreebusy() {
     7255  function __construct() {
    72417256    $this->calendarComponent();
    72427257  }
     7258  function vfreebusy() {
     7259    self::__construct();
     7260  }
    72437261/**
    72447262 * create formatted output for calendar component VFREEBUSY object instance
    72457263 *
    class valarm extends calendarComponent { 
    72887306 * @since 0.3.0 - 2006-08-10
    72897307 * @return void
    72907308 */
    7291   function valarm() {
     7309  function __construct() {
    72927310    $this->calendarComponent();
    72937311  }
     7312  function valarm() {
     7313    self::__construct();
     7314  }
    72947315/**
    72957316 * create formatted output for calendar component VALARM object instance
    72967317 *
    class vtimezone extends calendarComponent { 
    73377358 * @param string $timezonetype optional, default FALSE ( STANDARD / DAYLIGHT )
    73387359 * @return void
    73397360 */
    7340   function vtimezone( $timezonetype=FALSE ) {
     7361  function __construct( $timezonetype=FALSE ) {
    73417362    if( !$timezonetype )
    73427363      $this->timezonetype = 'VTIMEZONE';
    73437364    else
    73447365      $this->timezonetype = strtoupper( $timezonetype );
    73457366    $this->calendarComponent();
    73467367  }
     7368  function vtimezone($timezonetype=FALSE) {
     7369    self::__construct($timezonetype=FALSE);
     7370  }
    73477371/**
    73487372 * create formatted output for calendar component VTIMEZONE object instance
    73497373 *
  • includes/sorting.php

    diff --git a/includes/sorting.php b/includes/sorting.php
    index 54ceb0b..e307525 100644
    a b  
    8686        // This sortby method is the first element in the sort array, let's reverse it (unless told otherwise)
    8787            if ($_SESSION[$session][0]['field'] == $_GET['sortby']) {
    8888                if (isset($_GET['reverse']))
    89                     $_SESSION[$session][0]['reverse'] = ($_GET['reverse'] > 0 || eregi('^y', $_GET['reverse'])) ? true : false;
     89                    $_SESSION[$session][0]['reverse'] = ($_GET['reverse'] > 0 || preg_match('/^y/i', $_GET['reverse'])) ? true : false;
    9090                else
    9191                    $_SESSION[$session][0]['reverse'] = $_SESSION[$session][0]['reverse'] ? false : true;
    9292            }
  • modules/music/mp3act_functions.php

    diff --git a/modules/music/mp3act_functions.php b/modules/music/mp3act_functions.php
    index b6fc7e0..259d29d 100644
    a b function musicLookup($type, $itemid) 
    835835        'GROUP BY ms.album_id '.
    836836        'ORDER BY playcount DESC '.
    837837        'LIMIT 40';
    838       $result = mysql_query($query);
     838      $result = mysqli_query($query);
    839839      if (!$result)
    840840        break;
    841841
    function musicLookup($type, $itemid) 
    846846          title="'.t('Return to Statistics Page').'">'.t('Back').'</a></div>
    847847        <h2 class="music">'.t('Top Played Albums').'</h2></div>
    848848        <ul class="music">';
    849       while ($row = mysql_fetch_array($result))
     849      while ($row = mysqli_fetch_array($result))
    850850      {
    851851        $output .= getHtmlAlbum($row['album_id'], $row['album_name'],
    852852          $row['artist_name'], '', '', '', $row['playcount']."x");
    853853      }
    854       mysql_free_result($result);
     854      mysqli_free_result($result);
    855855      $output .= '</ul>';
    856856      break;
    857857
    function musicLookup($type, $itemid) 
    864864        'GROUP BY ms.artist_id '.
    865865        'ORDER BY playcount DESC '.
    866866        'LIMIT 40';
    867       $result = mysql_query($query);
     867      $result = mysqli_query($query);
    868868      if (!$result)
    869869        break;
    870870
    function musicLookup($type, $itemid) 
    875875          title="'.t('Return to Statistics Page').'">'.t('Back').'</a></div>
    876876        <h2 class="music">'.t('Top Played Artist').'</h2></div>
    877877        <ul class="music">';
    878       while ($row = mysql_fetch_array($result))
     878      while ($row = mysqli_fetch_array($result))
    879879      {
    880880        $output .= getHtmlArtist($row['artist_id'], $row['artist_name'],
    881881          '', '', '', $row['playcount']."x");
    882882      }
    883       mysql_free_result($result);
     883      mysqli_free_result($result);
    884884      $output .= '</ul>';
    885885      break;
    886886
    function musicLookup($type, $itemid) 
    919919        'GROUP BY ms.album_id '.
    920920        'ORDER BY ms.lastplay DESC '.
    921921        'LIMIT 40';
    922       $result = mysql_query($query);
     922      $result = mysqli_query($query);
    923923      if (!$result)
    924924        break;
    925925
    function musicLookup($type, $itemid) 
    930930          title="'.t('Return to Statistics Page').'">'.t('Back').'</a></div>
    931931        <h2 class="music">'.t('Recently Played Albums').'</h2></div>
    932932        <ul class="music">';
    933       while ($row = mysql_fetch_array($result))
     933      while ($row = mysqli_fetch_array($result))
    934934      {
    935935        $output .= getHtmlAlbum($row['album_id'], $row['album_name'],
    936936          $row['artist_name'], '', '', '', date('m.d.Y', $row['playdate']));
    937937      }
    938       mysql_free_result($result);
     938      mysqli_free_result($result);
    939939      $output .= '</ul>';
    940940      break;
    941941
  • modules/mythweb/tmpl/default/set_flvplayer.php

    diff --git a/modules/mythweb/tmpl/default/set_flvplayer.php b/modules/mythweb/tmpl/default/set_flvplayer.php
    index 4e0b565..f6b9ac0 100644
    a b  
    2323         title="<?php echo t('Enable Flash Video player for recordings.') ?>"
    2424        <?php
    2525            $ffmpeg = '';
    26             foreach (split (':', getenv ('PATH').':/usr/local/bin:/usr/bin') as $path) {
     26            foreach (preg_split ('/:/', getenv ('PATH').':/usr/local/bin:/usr/bin') as $path) {
    2727                if (file_exists ($path."/ffmpeg")) {
    2828                    $ffmpeg = $path."/ffmpeg";
    2929                    break;
  • modules/tv/classes/Recording.php

    diff --git a/modules/tv/classes/Recording.php b/modules/tv/classes/Recording.php
    index c8bc683..9d5608b 100644
    a b class Recording { 
    5656
    5757    var $css_class;         // css class, based on category and/or category_type
    5858
    59     function Recording($recording_data) {
     59    function __construct($recording_data) {
    6060
    6161    // SQL data
    6262        if (is_array($recording_data) && isset($recording_data['recordid'])) {
    class Recording { 
    124124        if ($this->chanid != '')
    125125            $this->css_class = category_class($this);
    126126    }
     127  function Recording($recording_data) {
     128    self::__construct($recording_data);
     129  }
    127130
    128131}