PDA

View Full Version : injecting into admincp settings?


Dr.CustUmz
05-04-2016, 02:03 AM
im trying to include a stylesheet in my settings page, i managed to get it to load in but not in a good way. It adds the code to the very end of the page.

</body>
</html><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">

the plugin I created:
<plugin active="1" executionorder="1" product="vbulletin">
<title>font awesome in settings</title>
<hookname>admin_complete</hookname>
<phpcode><![CDATA[if ($vbulletin->options['drc_fa_adm']){
echo('<link rel="stylesheet" href="'.$vbulletin->options['drc_fa_prov'].'">');
}]]></phpcode>
</plugin>

https://vborg.vbsupport.ru/external/2016/05/28.png


even though this works, I would like to know... is there anyway i can properly inject stylesheets and/or scripts into the settings page?

squidsk
05-05-2016, 02:49 PM
Here install this mod and then create a setting where the option code is:
css:my_custom_css_file.css

Replace the red part with the path to your custom css file. Other than the variable name, the only other value that matters when creating the setting is the title.

Dr.CustUmz
05-05-2016, 03:42 PM
thanks squid, this is the hook I ended up using already =) but that hook, some option pages like turn site on off don't have that hook, and one of my products (didnt check every default settings page) actually has that hook 2ce so the stylesheet loads 2ce.

I tried using some js in the admin complete hook
$drcjQ = "<link ref=\"stylesheet\" href=\"style.css\">";

echo "<script>var headHTML = document.getElementsByTagName('head')[0].innerHTML;
headHTML += '" . $drcjQ . "';
document.getElementsByTagName('head')[0].innerHTML = headHTML;</script>";

and even though it adds it to the head, it doesnt work =/

side note* I am out of iframes when im testing this, i open the options in a new tab and go to the settings of the product I'm working on.
example: yoursite.com/admincp/options.php?do=options&dogroup=onoff

so its the full page and no nav on the left or bar at the top

--------------- Added 1462470531 at 1462470531 ---------------

this is what I have currently working btw I'd just like to be able to get it working in the HEAD
<hookname>admin_options_print</hookname>
<phpcode><![CDATA[if ($vbulletin->options['drc_fa_adm']){
echo '<link rel="stylesheet" href="'.$vbulletin->options['drc_fa_prov'].'">';
}]]></phpcode>

squidsk
05-05-2016, 04:27 PM
thanks squid, this is the hook I ended up using already =) but that hook, some option pages like turn site on off don't have that hook, and one of my products (didnt check every default settings page) actually has that hook 2ce so the stylesheet loads 2ce.

I tried using some js in the admin complete hook
$drcjQ = "<link ref=\"stylesheet\" href=\"style.css\">";

echo "<script>var headHTML = document.getElementsByTagName('head')[0].innerHTML;
headHTML += '" . $drcjQ . "';
document.getElementsByTagName('head')[0].innerHTML = headHTML;</script>";

and even though it adds it to the head, it doesnt work =/

side note* I am out of iframes when im testing this, i open the options in a new tab and go to the settings of the product I'm working on.
example: yoursite.com/admincp/options.php?do=options&dogroup=onoff

so its the full page and no nav on the left or bar at the top

--------------- Added 1462470531 at 1462470531 ---------------

this is what I have currently working btw I'd just like to be able to get it working in the HEAD
<hookname>admin_options_print</hookname>
<phpcode><![CDATA[if ($vbulletin->options['drc_fa_adm']){
echo '<link rel="stylesheet" href="'.$vbulletin->options['drc_fa_prov'].'">';
}]]></phpcode>
I think your misunderstanding how to use the product. On your product page (i.e. yoursite.com/admincp/options.php?do=options&dogroup=my_product_page) add a new setting with option code:
css:style.css As long as you don't define multiple css settings for a particular option page you won't have multiple instances of the css being loaded.

For any settings page that you want custom css to be applied to, add a new settings with css:... as the option code.

EDIT: To clarify, this will only add your custom css to those settings pages where you add a setting that has the specified option code. The product will not add it to all settings group pages.

squidsk
05-05-2016, 04:40 PM
Here's what I mean, the first image is a new setting I create within any settings group.
https://vborg.vbsupport.ru/attachment.php?attachmentid=154942&stc=1&d=1462473526

Here's viewing the actual settings page. The style.css file has a single entry .alt1{background-color:red;}

https://vborg.vbsupport.ru/attachment.php?attachmentid=154943&stc=1&d=1462473614

Dr.CustUmz
05-05-2016, 05:56 PM
thats actually pretty cool, but it's not what im going for. Im going to have a core product that must be installed for my addons, and in that product is where i apply the style sheet for its (and all my other products) settings. That way i can use jquery and stylesheets and theyre all loaded from the core product, so in a new products settings i can just call the classes and what not.

its hard to explain not having released it yet, but i hope you get it =/

--------------- Added 1462489633 at 1462489633 ---------------

i tried this @admin_options_print just to test

$alreadyLoaded = array('one' => false, 'two' => false);
if (!$alreadyLoaded['one']) {
echo 'ECHO';
$alreadyLoaded['one'] = true;
}

and it still echo's twice... now I have lost all faith in humanity lol.

whats going on =/

this is my settings page
https://vborg.vbsupport.ru/external/2016/05/27.png