General plugin question: replacing core files?

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
Tagirijus
Posts: 33
Joined: 05 Dec 2017, 10:19
Contact:

General plugin question: replacing core files?

Post by Tagirijus »

Hey there,

I did a dark theme for mantis and a user in this forum told me that I could write a plugin instead of replacing the original files. Sounds clever to me, while I would not have to replace each file manually, if I move to a newer version of mantis (if these files will still work, of course). Now I wanted to start to understand the plugin development principle of mantisbt. Unfortunately this seems a bit too high for me and I think I need some help understanding things. Yes, I read the docs and looked through the example plugins.

These are my questions:
  • 1. Is it possible to let a plugin replace a whole core file of mantis and Mantis will use the new file instead of the original. Maybe something like the manage_proj_page.php or ...
  • 2. ... several css files (or any file!?).
  • 3. If yes: how?
  • 4a. If not: how would a plugin e.g. change the project list table on the manage_proj_page.php site or ...
  • 4b. ... change the css files?
With 1 I want to accomplish to have a plugin for this issue and with 2 I want to accomplish what this user wrote (writing a plugin for theming mantis).

Thanks for the help, people! :)

Best,
Manu
Starbuck
Posts: 219
Joined: 14 Feb 2006, 02:53
Location: USA
Contact:

Re: General plugin question: replacing core files?

Post by Starbuck »

Rather than replacing entire files, I believe you want to make use of the Event system. See chapter 5 in the docs for specific events, and chapter 4 for how to hook into them.
Similarly, rather than replacing CSS, the whole point of CSS is that user sheets can overload/supercede whatever comes before it. So I suggest perhaps copying whatever CSS file you want and then just changing it. Then with your plugin, use the info in chapter 4 (I believe) to insert your CSS into pages, where it should be added after others and thus override whatever is set by them.

If this PHP is beyond your skills, consider a barter for services. What languages do your work with? What can you offer someone who will write some code for you? While I do a lot with PHP, my skills are not such that I would presume to offer detailed help here. But perhaps someone else (who uses Mantis or not) could be enticed by some reward to write this code for you.

HTH
Tagirijus
Posts: 33
Joined: 05 Dec 2017, 10:19
Contact:

Re: General plugin question: replacing core files?

Post by Tagirijus »

Hey there,

firts of all: thanks for the reply! :)
Starbuck wrote:Rather than replacing entire files, I believe you want to make use of the Event system. See chapter 5 in the docs for specific events, and chapter 4 for how to hook into them.
I did browser quickly over these chapters already before I posted. I will surely dig deeper as good as I can. My thread and my questions are mainly meant to save me time learning the wrong things. Since this event hooking thing is something I still have to understand a bit better, I mainly wanted to ask, if it is a common plugin-thing to just replace files.

But probably you are right and the best way is to understand the event and hooking thing.

Starbuck wrote: Similarly, rather than replacing CSS, the whole point of CSS is that user sheets can overload/supercede whatever comes before it. So I suggest perhaps copying whatever CSS file you want and then just changing it. Then with your plugin, use the info in chapter 4 (I believe) to insert your CSS into pages, where it should be added after others and thus override whatever is set by them.
Hopefully I will dig this as well ... if at all, haha. :D ... will try, for sure!

Starbuck wrote: If this PHP is beyond your skills, consider a barter for services. What languages do your work with? What can you offer someone who will write some code for you? While I do a lot with PHP, my skills are not such that I would presume to offer detailed help here. But perhaps someone else (who uses Mantis or not) could be enticed by some reward to write this code for you.

HTH
Thanks for this interesting tip. My PHP skills are ... I do not even knoww. I would say "not detailed" but not "totally bloody noobish". I coded my website on my own lately. The old site had even more interesting PHP code. The actual site could be done in HTML only, I know. Not a very good showcase for my PHP skills. But I would say that my PHP skills are ... "ok" maybe? :D

It's still a difference to code its own website with probably bad coding, which still works somehow and using a rather more professinal API from other people, I know. as I already wrote: my questions are mainly be meant for me to avoid learning the wrong path from the beginning, when trying to understand the MantisBT plugin API.

Still looking forward to good tips though. :)
Tagirijus
Posts: 33
Joined: 05 Dec 2017, 10:19
Contact:

Re: General plugin question: replacing core files?

Post by Tagirijus »

Well there it comes, the first problem. I might understand now how the plugin hooking and event thing is working. So I tried to write a plugin, which add a dark theme - the same I did with replacing and adding CSS etc. Unfortunately the plugin does not replace the old CSS files, while they still have many "!important" rules. Even with loading the same tweaked CSS after the original ones were loaded did not work.

I did it with hooking to the EVENT_LAYOUT_RESOURCES and my function just adds

Code: Select all

<link rel="stylesheet" type="text/css" href="' . plugin_file('ace.min.css') . '" />' . "/n";
<link rel="stylesheet" type="text/css" href="' . plugin_file('DarkTheme.css') . '" />' . "/n";
For example. Where in ace.min.css I basically deleted all the !important rules and in DarkTheme I re-colored them with !important. I guess that the first loaded CSS with !important rules get still higher priority, right? So how could one change these CSS files with a plugin if not with replacing them?


Edit:
I uploaded the work-in-progress plugin on github: https://github.com/Tagirijus/MantisBTDarkTheme


Edit 2:
Also I could not find an event for the manage_proj_page.php table creation or similar. First I thought it would be EVENT_MANAGE_PROJECT_PAGE ... but this is just for the editing page of a project. I searched the docs multiple times and I even tried to look into the APIs and the code, but could not find a event_signal() function, calling an event while / before / after creating the table.

Another reason why I started this thread: to ask if my tasks and my goals are even possible with plugin developement! :)
Starbuck
Posts: 219
Joined: 14 Feb 2006, 02:53
Location: USA
Contact:

Re: General plugin question: replacing core files?

Post by Starbuck »

Not to bore anyone but just to explain why I jumped in here:

I've been a developer for about 40 years. While not a PHP pro in a long list of language skills, I do a lot of noodling with modern FOSS, and that requires frequent excursions with PHP. For websites I use WordPress extensively (highly recommended) which has a plugin and event/hook model that's similar to MantisBT. I use Mantis for client projects and am learning the API because I see a lot of need for plugins for this fine software, for myself and others who ask questions in this forum.

As a part of my research, and with a bit of pay-forward/back for FOSS, I'm making doc changes in my GitHub repo and will soon submit pull requests. So while making suggestions to you here, I'm also looking for notes on doc difficulties and errors so that I can enhance the docs for all of us.

Similarly, I'm elated that you've posted code and notes on specific events. My goal with referring you to chapter 5 was specifically so that you could do that. If you do create a solution and document it here, we've all won a great victory. Posting your code to GH is great, TYVM. If we cannot solve this problem with the existing events, and it turns out that we cannot do what you want with the existing API, I'm hoping this thread will translate into a tracker report for enhancements for new events in key locations (before/after importing CSS/JS) and/or bug fixes for the same ... in which case we all still win. Of course I will add related notes to the doc as this evolves.

So while I'm personally not able to help with this specific task, I'm hoping you and we all benefit from your process - with as little unnecessary effort as possible as you've said.

As to motivating others to help, I hope I wasn't being condescending - and it looks like you took that in the intended spirit. You see here that my contribution to FOSS is in trying to improve docs, get issue reports for improvements, and helping someone else to use this fine software. If you (and others!) follow a similar plan, and thus achieve your own goals, again, we all win.

HTH
Starbuck
Posts: 219
Joined: 14 Feb 2006, 02:53
Location: USA
Contact:

Re: General plugin question: replacing core files?

Post by Starbuck »

On looking at your GH code, and this is why it's great to code share, I see your code is doing an echo of the desired header markup. But the doc says the Return Value of the function gets inserted into the doc being built. So I recommend you change echo to return to see if that results in an override of the defaults. If it does not, check a page to see if your markup is in the header. That will help to differentiate "code is there but not working" from "code is not inserted into the page".

Looking at the docs, there does not seem to be an event to substitute the default CSS. Personally I think that would be a good feature so that we don't need to completely load all CSS and then override it all, just bloating the page with redundant bytes and processing.
Starbuck
Posts: 219
Joined: 14 Feb 2006, 02:53
Location: USA
Contact:

Re: General plugin question: replacing core files?

Post by Starbuck »

While perhaps not important, you're setting MantisCore to a minimum of 2.5.1. That's a very specific version. I have no idea if this area where you're working has been changed in recent releases, but if you're not running v2.8 or v2.9 then I suggest you get the latest version. Otherwise you could be struggling with old issues.

Then to be safe, change your 'requires' MantisCore value to 2.8 or whatever you're actually running. This way, we know that it works with that version, and that there are no guarantees that it will work with a prior version, so older versions won't load your plugin. That will eliminate some "why doesn't this work?" enquiries.
Tagirijus
Posts: 33
Joined: 05 Dec 2017, 10:19
Contact:

Re: General plugin question: replacing core files?

Post by Tagirijus »

Hey Starbuck,

thanks for your reply. Of course FOSS is a great thing and I also think that people can learn from this more than proprietary software. As you already might noticed, I like to publish my little scripts and programms on github. Glad you like that I published this attempt as well. Still: for me as a hobby coder it's not that clever to put too much time into coding things, while not knowing, if things are even possible, while a dev, who e.g. wrote the API, could tell me in a simple yes / no answer, if my task is even possible in the first place! ;)

Regarding "echo -> return": this did not help.

Regarding movign to 2.8: I will try it. I looked into the source on github and I could not find additional EVENTS there, though. I did change the rquirement to 2.5.1 since this is the version I am working with at the moment.

Edit:
Just a little update: Upgrading to 2.9 did not help either.
Starbuck
Posts: 219
Joined: 14 Feb 2006, 02:53
Location: USA
Contact:

Re: General plugin question: replacing core files?

Post by Starbuck »

Gotcha. Time to bring in the cavalry. Good luck!
Tagirijus
Posts: 33
Joined: 05 Dec 2017, 10:19
Contact:

Re: General plugin question: replacing core files?

Post by Tagirijus »

I found out that in CSS you have to assign a rule to exactly the same class. Like ".skin-3 .nav-list {blabla}" instead of just ".nav-list {blabla}". With these new learned things I might have managed to make the Dark Theme work!? I updated the github code.
Starbuck
Posts: 219
Joined: 14 Feb 2006, 02:53
Location: USA
Contact:

Re: General plugin question: replacing core files?

Post by Starbuck »

I just submitted this related request. Let's see what happens.
Tagirijus
Posts: 33
Joined: 05 Dec 2017, 10:19
Contact:

Re: General plugin question: replacing core files?

Post by Tagirijus »

Thanks. One of the devs already contacted me some days ago and we are going to talk about theming, I guess. :)
Post Reply