Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

Add custom input field into admin panel

Aloittaja MarkoKg, marraskuu 02, 2013, 02:26:00 IP

« edellinen - seuraava »

MarkoKg

Hello there,

I'm in a need for 3 custom input fields that I would like to have placed somewhere in admin panel. That would be just text fields where admins can place links to specific images. Then I would like those images (from the field) to be able to use on my portal (Simple Portal).
So I guess that I should edit ./Sources/Admin.php in order to add fields somewhere to admin panel, right?
Any help with this please?

Regards,
Marko

Arantor

What version of SMF? (It should not be Admin.php but the file and the ease of doing this relates to the SMF version)
Holder of controversial views, all of which my own.


MarkoKg

Oh, sorry, version is 2.0.6.
I thought that I could use this mod as help while doing this:
http://custom.simplemachines.org/mods/index.php?action=parse;mod=2966;attach=214076;smf_version=2.0.4
I just won't do any changes to index.template, so I should be able to use this thing on portal, right?
I actually tried it on my test forum, I added a html block on portal with:
<a title="' . $modSettings['fmenu_title1'] . '" href="' . $modSettings['fmenu_url1'] . '">' . $modSettings['fmenu_title1'] . '</a>
Before that I added modSettings to globals in portal standalone file:
global $sp_standalone, $modSettings;

But that all results with a broken link that looks like:
http://forum.com/' . $modSettings['fmenu_url1'] . '
I guess that I didnt put globals on the right place or something, can I put it inside html block somehow?
Sorry for bothering about this, maybe it was a better to put the "clean code" rather than using this mod?

Arantor

Well, you can't just $modSettings in an HTML block, it would have to be a PHP block... but that still doesn't help you actually *define* those $modSettings entries.

The quickest way of doing that would be to add them to the Modification Settings page in ManageSettings.php, in this chunk of code:

function ModifyGeneralModSettings($return_config = false)
{
global $txt, $scripturl, $context, $settings, $sc, $modSettings;

$config_vars = array(
// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
);


You can add simple settings to $config_vars there, in your case:

function ModifyGeneralModSettings($return_config = false)
{
global $txt, $scripturl, $context, $settings, $sc, $modSettings;

$config_vars = array(
// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
array('text', 'fmenu_url1'),
array('text', 'fmenu_url2'),
);


You will need to declare $txt['fmenu_url1'] and $txt['fmenu_url2'] in the language strings (I suggest ManageSettings.language.php)

But then you still need to use a PHP block with an echo statement to output the strings in question.
Holder of controversial views, all of which my own.


MarkoKg

Thanks, that seems to be working now :)
I just had to use php block and to add $modSettings in globals.

One more question, as I'm not sure if this is even possible or now, so please sorry if the question is too dumb.

Is it possible to use input from one of that text fields, for example fmenu_url1 inside CSS, for example I currently have something like this in CSS file (using that on portal):
#blog1 { background: url('images/blog/1.png') center center;}
So is it anyhow possible to have that background url value pulled from fmenu_url1? Sorry once again if this is dump question, but I don't know much about php and stuff.

Thanks once again! :)

Arantor

Not in the CSS file itself but you could modify index.template.php to output it in a <style> inside the <head> area.
Holder of controversial views, all of which my own.


MarkoKg

Ok, so if I put something like:
#blog1 { background: url('' . $modSettings['fmenu_url1'] . '') center center;}
Into Index.template style tag, it should work, right? Or I need some additinal settings?

Arantor

No, that's pretty much hat I had in mind, provided it's a style tag inside the <head>. Except not for the pairs of single quotes, which is invalid.

#blog1 { background: url("' . $modSettings['fmenu_url1'] . '") center center;}
Holder of controversial views, all of which my own.


MarkoKg

Sorry for bumping old thread, but i just wanted to ask something related to my last question here.
Is it possible to use data from some locally stored txt file instead of $modSettings['fmenu_url1'] in CSS?
I want for example line 5 from txt file (which is basically a url for image) to be in:
#blog1 { background: url("LINE 5 HERE") center center;}

I know that I can use something like this normally, but I don't know how to apply it for CSS...
$lines = file('file.txt');
echo $lines[4];

Arantor

I wouldn't normally recommend it - there's all kinds of ways that can go wrong! - the quickest way to do it would be:

#blog1 { background: url("' . file_get_contents('file.txt') . '") center center;}
Holder of controversial views, all of which my own.


MarkoKg

Thanks, but is there a way to just have content of specific line, for example line 5 as I said above?

Would something like that cause some security problems or something? I would need to display just specific line from txt file, don't know how else can I do that as I'm really a beginner with php and stuff.

Thanks for your quick answer, I really appreciate it! :)

Arantor

o.O I didn't see that part.

I don't understand why you're deliberately making this more complex than it needs to be - why do you need this?
Holder of controversial views, all of which my own.


MarkoKg

I have custom made boxes on portal (SP) where I have to manually add title, description, url for background image and link for every blog entry, and all of that for every of total 12 boxes that I have. I used custom fileds which I added into admin panel for this, but now i figured that it's too big job, because whenever I want to add new blog entry I need to move every of current items to next place in order to leave first one empty and then add new blog item there. So the easier would be to just have one txt file where I'll have content in lines, 4 lines for every blog item. Then I'll be able to just add new content on top, and all will be automatically moved like it should.
I already made titles, description and link to work, and I just need this background image to be applied to CSS in order to have everything done.

Don't know if that makes sense to you, English is not my native language so I'm not sure if I'm understandable enough, sorry.

Arantor

If you're doing that, it's already preset so you might as well just add it directly to your CSS file rather than splicing bits and pieces out of another file, right?
Holder of controversial views, all of which my own.


MarkoKg

Yeah, but I don't know what is the correct way to add for example line 5 to the css background atribute here:
#blog1 { background: url("LINE 5 HERE") center center;} 
Should I use something like:
#blog1 { background: url("echo $lines[4]; ") center center;} 

Arantor

Why do you need to do that though?

Unless they all have ids of blog1 for some insane reason (which they shouldn't), use whatever their id is and just put that information directly into the CSS file. Makes it run faster, amongst other things.
Holder of controversial views, all of which my own.


MarkoKg

As you can see in attached picture above, every box have different background image, and I will change them occasionally in that txt file. So I need every blog to have different class with different background image.

Arantor

So every box has a different background picture. That's fine. Give them some unique identifier and set that in the CSS like it's supposed to be done!
Holder of controversial views, all of which my own.


MarkoKg

But if I'm going to change those pictures every now and then, for example in every two days, it would be a much of a work to change links to those images in CSS every time. That's why I'm trying to use specific lines from txt file which I'll be changing.

Arantor

*shrug* You really are making this more complicated than it needs to be.
Holder of controversial views, all of which my own.


Advertisement: