Mys 1.3.5 Site Maintenance Mode Mod

Forum
Last Post
Threads / Messages

GeneticAlpha

Loving Mysidia!
Member
Joined
May 24, 2020
Messages
283
Points
18
Age
30
Location
Tennessee
Mysidian Dollar
13,356
I really love that we have a site turn off feature in 1.3.5 so I wanted to add to it, because as of right now, it only allows you to shut the site off. You can't edit things and see what you're working on onsite during the site being off. So I made a mod that allows admins and mod groups access to the site still but everyone else has no access. I wanted it as a weekly maintenance feature. There probably is a better way to do this I'm sure, but I only know basic HTML, CSS, and a bit of PHP. So this was the best I could come up with lol. This will work for 1.3.4 if the turn site off feature is added before this mod. If I figure that out I'll add a post to this thread with how to install that feature to 1.3.4. The same goes for 1.3.6 I'll try to add that in later if I find out how to add it to that one as well.

Anyway, this mod edit is all within the index.php file and you'll be working in the public function handleRequest(){ area around 15.

You want to find this section here:
public function handleRequest(){
$mysidia = Registry::get("mysidia");
$class = $mysidia->input->get("appcontroller")->capitalize();
$controller = "{$class}Controller";
$action = $mysidia->input->action();

try{
if($mysidia->systems->site != "enabled") throw new NoPermissionException("The admin has turned off the site for maintenance, please come back and visit later.");
$this->appController = new $controller;
$this->appController->setFrontController($this);
$this->appController->$action();
$this->action = $action;
return TRUE;
}
catch(GuestNoaccessException $gne){
$this->setFlags("global_guest_title", $gne->getmessage());
return FALSE;
}
catch(InvalidActionException $iae){
$this->setFlags("global_action_title", $iae->getmessage());
return FALSE;
}
catch(NoPermissionException $npe){
$this->setFlags("global_error", $npe->getmessage());
return FALSE;
}
catch(InvalidIDException $iie){
$this->setFlags("global_id_title", $iie->getmessage());
return FALSE;
}
catch(DuplicateIDException $die){
$this->setFlags("global_id_title", $die->getmessage());
return FALSE;
}
catch(AlreadyLoggedinException $ale){
$this->setFlags("global_login_title", $ale->getmessage());
return FALSE;
}
catch(MemberNotfoundException $mne){
$this->setFlags("global_id_title", $mne->getmessage());
return FALSE;
}
catch(Exception $e){
$error = strtolower(str_replace("Exception", "_error", get_class($e)));
$this->setFlags($error, $e->getmessage());
return FALSE;
}
}

and replace it with this:
public function handleRequest(){
$mysidia = Registry::get("mysidia");
$class = $mysidia->input->get("appcontroller")->capitalize();
$controller = "{$class}Controller";
$action = $mysidia->input->action();
$group = $mysidia->db->select("users", array("usergroup"), "username ='{$mysidia->user->username}'")->fetchColumn();
if($mysidia->systems->site != "disabled"){
try{
$this->appController = new $controller;
$this->appController->setFrontController($this);
$this->appController->$action();
$this->action = $action;
return TRUE;
}
catch(GuestNoaccessException $gne){
$this->setFlags("global_guest_title", $gne->getmessage());
return FALSE;
}
catch(InvalidActionException $iae){
$this->setFlags("global_action_title", $iae->getmessage());
return FALSE;
}
catch(NoPermissionException $npe){
$this->setFlags("global_error", $npe->getmessage());
return FALSE;
}
catch(InvalidIDException $iie){
$this->setFlags("global_id_title", $iie->getmessage());
return FALSE;
}
catch(DuplicateIDException $die){
$this->setFlags("global_id_title", $die->getmessage());
return FALSE;
}
catch(AlreadyLoggedinException $ale){
$this->setFlags("global_login_title", $ale->getmessage());
return FALSE;
}
catch(MemberNotfoundException $mne){
$this->setFlags("global_id_title", $mne->getmessage());
return FALSE;
}
catch(Exception $e){
$error = strtolower(str_replace("Exception", "_error", get_class($e)));
$this->setFlags($error, $e->getmessage());
return FALSE;
}}

if($group <= 2){
try {
if($mysidia->systems->site != "enabled" && ($group <= 2))
$this->appController = new $controller;
$this->appController->setFrontController($this);
$this->appController->$action();
$this->action = $action;
return FALSE;
}
catch(GuestNoaccessException $gne){
$this->setFlags("global_guest_title", $gne->getmessage());
return FALSE;
}
catch(InvalidActionException $iae){
$this->setFlags("global_action_title", $iae->getmessage());
return FALSE;
}
catch(NoPermissionException $npe){
$this->setFlags("global_error", $npe->getmessage());
return FALSE;
}
catch(InvalidIDException $iie){
$this->setFlags("global_id_title", $iie->getmessage());
return FALSE;
}
catch(DuplicateIDException $die){
$this->setFlags("global_id_title", $die->getmessage());
return FALSE;
}
catch(AlreadyLoggedinException $ale){
$this->setFlags("global_login_title", $ale->getmessage());
return FALSE;
}
catch(MemberNotfoundException $mne){
$this->setFlags("global_id_title", $mne->getmessage());
return FALSE;
}
catch(Exception $e){
$error = strtolower(str_replace("Exception", "_error", get_class($e)));
$this->setFlags($error, $e->getmessage());
return FALSE;
}}
else{
try{
if($mysidia->systems->site != "enabled") throw new NoPermissionException("<br><b>The site has been temporarily shut down for routine maintenance.</b>");
$this->appController = new $controller;
$this->appController->setFrontController($this);
$this->appController->$action();
$this->action = $action;
return TRUE;
}
catch(GuestNoaccessException $gne){
$this->setFlags("global_guest_title", $gne->getmessage());
return FALSE;
}
catch(InvalidActionException $iae){
$this->setFlags("global_action_title", $iae->getmessage());
return FALSE;
}
catch(NoPermissionException $npe){
$this->setFlags("global_error", $npe->getmessage());
return FALSE;
}
catch(InvalidIDException $iie){
$this->setFlags("global_id_title", $iie->getmessage());
return FALSE;
}
catch(DuplicateIDException $die){
$this->setFlags("global_id_title", $die->getmessage());
return FALSE;
}
catch(AlreadyLoggedinException $ale){
$this->setFlags("global_login_title", $ale->getmessage());
return FALSE;
}
catch(MemberNotfoundException $mne){
$this->setFlags("global_id_title", $mne->getmessage());
return FALSE;
}
catch(Exception $e){
$error = strtolower(str_replace("Exception", "_error", get_class($e)));
$this->setFlags($error, $e->getmessage());
return FALSE;
}

}
}
Essentially, that first bit of code I said to find is a try and catch statement thing I had to find a way to put it all in an if and else statement. It took me 4 hours to figure out how to get stuff to function without breaking haha. I tested this as different usergroups, and while site was disabled and enabled I got no more errors and things work correctly. Hope I didn't miss anything.

So essentially, this makes it where if a user is usergroup 1 or 2 (admin = 1 | mod = 2) then it will allow you access still to the site if the turn off site is enabled.
If the user is anything other than usergroup 1 or 2 then it switches the site to display the:
"The site has been temporarily shut down for routine maintenance."
Then else if the site turn off is disabled, then nothing happens.

Again, this is for 1.3.5 mod only, because I haven't tested anything yet with 1.3.6 and 1.3.4 needs to have the site turn off feature added before this will work and you may need to make edits, I forgot if usergroup 1 and 2 is mod groups already.
 
Looks nice, I think it should work on Mys v1.3.6 unless you are using more classes than the original code. In this case, the equivalent Mys v1.3.6 code will need to import the class with a use statement at the top of the script file, but it should be simple enough to make it work.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,267
Messages
33,049
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top