phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Topic Calendar 1.2.2 php7.x constructors


 
Search this topic... | Search MOD Writing... | Search Box
Register or Login to Post    Index » MOD Writing  Previous TopicPrint TopicNext Topic
Author Message
s1eelra1
Board Member



Joined: 08 Apr 2015

Posts: 6



PostPosted: Wed Nov 18, 2020 2:34 pm 
Post subject: Topic Calendar 1.2.2 php7.x constructors

Let me start by saying I have a working 2.0.24 board, on php7.4.x and it works just fine. The host switched us to php7.x in spring so there was a scramble to make the php7 adjustments.

I'm now working through the updating of the "notice/deprecated/warning", so hopefully there will be more time, and less to fix the next time the host requires a php upgrade.

The current problem is the class/function/constructors for the topic calendar mod. I've been doing searches via google, stackoverflow, here etc. Unfortunately, I've only been able to replace some of class/functions. At one point I had the calendar page it self stop reporting errors, but also had the portions of the page stop working.

Here's one of the original sections of code:

Code:

   function calendar_api()
   {
      $this->days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      $this->elapsed_days = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365);
      $this->monthes_list = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
      $this->days_list = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');

      $this->format_short = '';
      $this->format_medium = '';
      $this->format_long = '';
      $this->timezone = 0;
      $this->set = false;
   }




Which I've been able to hack into this:

Code:


/*
//-- php7.2/7.4 fixes
//-- phpbb 2.0.25
//-- code replace   
   function calendar_api()
*/

   function __construct()

//-- fin replace


   {
      $this->days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      $this->elapsed_days = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365);
      $this->monthes_list = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
      $this->days_list = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');

      $this->format_short = '';
      $this->format_medium = '';
      $this->format_long = '';
      $this->timezone = 0;
      $this->set = false;
   }

/*
//-- php7.2/7.4 fixes
//-- phpbb 2.0.25
//-- code add to pair with the replace in the function name   
*/   
function calendar_api()
{
   self::__construct();
}


And it seems to work. But I've found more trouble when I do similar changes to function -> that has extends parent::. Also there's at least one file which has 3 classes in it. I'm not sure if that then means it needs to be a multi constructor format or not.

Does anybody have some good examples of "how" to do a better constructor format?

I've attached the original mod download, just in case it's helpful. Currently I'm having the most trouble with the class_calendar_handler.php.

TIA



TC122p0.zip
 Description:
topic calendar 1.2.2 build version

Download
 Filename:  TC122p0.zip
 Filesize:  83.48 KB
 Downloaded:  11 Time(s)

Back to top
StarWolf3000
Board Member



Joined: 10 Jun 2010

Posts: 160
Location: Germany


flag
PostPosted: Thu Nov 26, 2020 10:19 am 
Post subject: Re: Topic Calendar 1.2.2 php7.x constructors

There should be no need to use classic-style constructors in recent PHP versions, so this snippet is obsolete (it might even be ignored by PHP by now):
Code:
/*
//-- php7.2/7.4 fixes
//-- phpbb 2.0.25
//-- code add to pair with the replace in the function name
*/
function calendar_api()
{
   self::__construct();
}

For classes that extend from a parent class, you have to replace the constructor of both the parent and inheriting class(es).

Example:
Code:
class Mysqli {
  function Mysqli(...) {
  }
}

Code:
class sql_db extends Mysqli {
  function sql_db(...) {
    parent::Mysqli(...);
  }
}

Change the parent constructor:
Code:
class Mysqli {
  function __construct(...) {
  }
}

Change the inheriting class constructor:
Code:
class sql_db extends Mysqli {
  function __construct(...) {
    parent::__construct(...);
  }
}

Quote:
Currently I'm having the most trouble with the class_calendar_handler.php.

Replace:
Code:
   function calendar_root($requester='', $parms='')
   {
      $this->requester = $requester;
      $this->parms = empty($parms) ? array() : $parms;
      $this->id_prefix = 'item_';
   }

with:
Code:
   function __construct($requester='', $parms='')
   {
      $this->requester = $requester;
      $this->parms = empty($parms) ? array() : $parms;
      $this->id_prefix = 'item_';
   }

Replace:
Code:
   function calendar_event($requester, $parms, &$handler, $module_id)
   {
      parent::calendar_root($requester, $parms);
      $this->handler = &$handler;
      $this->module_id = $module_id;
      $this->data = array();
   }

with:
Code:
   function __construct($requester, $parms, &$handler, $module_id)
   {
      parent::__construct($requester, $parms);
      $this->handler = &$handler; // <- I'm unsure if the & is needed here, might throw a Fatal Error
      $this->module_id = $module_id;
      $this->data = array();
   }

Replace:
Code:
   function calendar_handler($requester='', $parms='')
   {
      global $calendar_api, $calendar_modules;

      parent::calendar_root($requester, $parms);
      $this->queues = array();
      $this->map = array();
      $this->modules = &$calendar_modules;
      $this->txt_overview = array();
      $this->selection_form = array();

      $this->settings = $this->retrieve_settings();
      $this->selection_def();

      $calendar_api->set();
   }

with:
Code:
   function __construct($requester='', $parms='')
   {
      global $calendar_api, $calendar_modules;

      parent::__construct($requester, $parms);
      $this->queues = array();
      $this->map = array();
      $this->modules = &$calendar_modules; // <- I'm unsure if the & is needed here, might throw a Fatal Error
      $this->txt_overview = array();
      $this->selection_form = array();

      $this->settings = $this->retrieve_settings();
      $this->selection_def();

      $calendar_api->set();
   }
Back to top
s1eelra1
Board Member



Joined: 08 Apr 2015

Posts: 6



PostPosted: Thu Nov 26, 2020 2:47 pm 
Post subject: Re: Topic Calendar 1.2.2 php7.x constructors

thank you sir. I'll give it a whirl.

So far I made progress with the __construct, and a call to "self::old function name", but it did break one thing on the calendar page.

I also found that quite possibly I did a blanket removal of &$ variables for php5.4 possibly. For most of the pages from the original phpbb code, they got re-added. Once I realized that, I've been going through older backup revisions to see if I can find where else I stupidly removed $&. With the full download of the original topic calendar, I have put all those back in already.
Back to top
Display posts from previous:   
Register or Login to Post    Index » MOD Writing  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0282 seconds using 17 queries. (SQL 0.0021 Parse 0.0023 Other 0.0238)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo