News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Admin Dropdown

Started by Matthew K., January 03, 2010, 10:40:03 AM

Previous topic - Next topic

Matthew K.

Hello everyone!

I made a Forum Cursor Mod, and as suggested by the SMF Customization Team, I am going to be switching to a dropdown instead of text, for multiple reasons.

However, I am unsure on how exactly to call up the input, so guidance would be appreciated.

Code (My CSS) Select
$context['html_headers'] .='<style type="text/css">
body
{
cursor: ' . (!empty($modSettings['forum_cursor']) ? ''. $modSettings['forum_cursor']. '' : 'auto') . ';
}
</style>';

Code (My Array) Select
array('select', 'forum_cursor', array(1 => &$txt['cursor_default'], 2 => &$txt['cursor_crosshair'], 3 => &$txt['cursor_hand'], 4 => &$txt['cursor_pointer'], 5 => &$txt['cursor_move'], 6 => &$txt['cursor_text'], 7 => &$txt['cursor_wait'])),

In the end, I need the value of forum_cursor to be a txt string (one of the cursors) which are defined in Modifications.english.php.

Labradoodle-360

Arantor


$css = array(1 => $txt['cursor_default'], 2 => $txt['cursor_crosshair'], 3 => $txt['cursor_hand'], 4 => $txt['cursor_pointer'], 5 => $txt['cursor_move'], 6 => $txt['cursor_text'], 7 => $txt['cursor_wait']);
$context['html_headers'] .='<style type="text/css">
body
{
cursor: ' . (!empty($modSettings['forum_cursor']) ? ''. $css[$modSettings['forum_cursor']] . '' : 'auto') . ';
}
</style>';


The value you get is a number relating to the array you have, so in your array $txt['cursor_default'] will store 1 in $modSettings['forum_cursor']. Thus you have to look back up what 1 refers to, just like I did in Version Emulate Dropdown.

Matthew K.

#2
After the last PM I received, I figured it was something like that, I just wasn't positive on how to write it and include it.

Thanks Arantor, marking as resolved.
Labradoodle-360

Matthew K.

This isn't working, suggestions?

Arantor

* Arantor really wishes people would read the quote in his signature. Might mean I don't have to make 50% of my posts each day asking the same time-wasting question.

So, anything in the error log?

Matthew K.

Okay Arantor, maybe my post wasn't clear enough, I thought I had stated what I needed done.

No error logs related to the forum_cursor array. What's not working, is that when inputted via Admin panel, nothing is entered to the CSS (or properly entered) meaning the cursor doesn't change.

Arantor

Nothing added at all to the source? That suggests you're putting this in the wrong place.

Where, exactly, is this code?

Matthew K.

It's placed right below Poll Options on Features and Options General, as my mods xml shows.

Arantor

That wasn't what I meant.

Where, exactly, is the OTHER bit of code, the one that process of elimination and logic tells us isn't working?

Matthew K.

The other code, the CSS, is placed in Load.php where I was previously advised to place it.

The placing can't be the problem, because with a text field it works perfectly.
Labradoodle-360

Arantor

In which case, do as I suggested earlier, and verify what exactly is added to the source of the page.

Matthew K.


Matthew K.

Using FireBug, index.php?action=admin;area=featuresettings;sa=basic shows as

body {
}

Arantor

That tells me the code isn't adding to $context['html_headers']. Which means you've put that in the wrong place or there is something else wrong.

Matthew K.

I assume it's something else is wrong, because when it's a text field it works, any further ideas on how to diagnose the problem?

Arantor

I can't see how it can, since the cursor part is missing which suggests the whole thing is broken.

Matthew K.

#16
True, I'll compare it to my context...in the case of a typo. - Compared, and exactly the same except for the top line that defines $css and then adding $css[$modSettings['forum_cursor']].

I honestly don't get what could be wrong, the simple change from text to dropdown disables it...

Code (My code is below this) Select
// Detect the browser. This is separated out because it's also used in attachment downloads
detectBrowser();


I also checked to make sure cursor wasn't being defined in Load.php by another code.

Matthew K.

Maybe it'll help if I post my whole code, I'll post a section or two on either side of both edits so you can see where it's being added to each document.

Code (Load.php) Select

// A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
$context['server']['needs_login_fix'] = $context['server']['is_cgi'] && $context['server']['is_iis'];

// Detect the browser. This is separated out because it's also used in attachment downloads
detectBrowser();


   $cursortext = array(1 => $txt['cursor_default'], 2 => $txt['cursor_crosshair'], 3 => $txt['cursor_hand'], 4 => $txt['cursor_pointer'], 5 => $txt['cursor_move'], 6 => $txt['cursor_text'], 7 => $txt['cursor_wait']);
   $context['html_headers'] .='<style type="text/css">
   body
   {
   cursor: ' . (!empty($modSettings['forum_cursor']) ? ''. $cursortext[$modSettings['forum_cursor']] . '' : 'auto') . ';
   }
   </style>';

Code (ManageSettings.php) Select
function ModifyBasicSettings($return_config = false)
{
global $txt, $scripturl, $context, $settings, $sc, $modSettings;

$config_vars = array(
// Big Options... polls, sticky, bbc....
array('select', 'pollMode', array($txt['disable_polls'], $txt['enable_polls'], $txt['polls_as_topics'])),
'',

array('select', 'forum_cursor', array(1 => &$txt['cursor_default'], 2 => &$txt['cursor_crosshair'], 3 => &$txt['cursor_hand'], 4 => &$txt['cursor_pointer'], 5 => &$txt['cursor_move'], 6 => &$txt['cursor_text'], 7 => &$txt['cursor_wait'])),
    '',

Arantor

And once it's set up, please post the full HTML of the page in question. You cannot get body { } out of that. It's one line of code, and it would contain the cursor declaration.

Matthew K.

You're right, going into the HTML Source, here is what the output of the code in Load.php is<style type="text/css">
   body
   {
   cursor: ;
   }
   </style>

Matthew K.

Meaning, somewhere in the declaration of the empty statement it's not calling up properly, or something to do with the text strings?

Arantor

And no errors in the error log of any kind?

Matthew K.

Ha, there are, but they are undefined errors from a mod I am developing that I've not fully hooked up yet.

Matthew K.

I looked through quite a few, and they all were related to my other unfinished mod, nothing to do with this one.

Arantor

Well, it kind of must be, actually, because right now you're getting an empty answer from an expression that shouldn't be generating a null answer.

Matthew K.

I went through the top 6 error pages with no luck (all from my unfinished mod, which has a ton of arrays.).

So what I'm going to do is remove my unfinished mod and then clear the error logs and see if it comes up.
Labradoodle-360

Matthew K.

Cleared my unfinished mod from Load.php which fixed all Undefined errors, cleared the Error Log and it REMAINS clean.

Arantor

// A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
$context['server']['needs_login_fix'] = $context['server']['is_cgi'] && $context['server']['is_iis'];

// Detect the browser. This is separated out because it's also used in attachment downloads
detectBrowser();


$cursortext = array(1 => $txt['cursor_default'], 2 => $txt['cursor_crosshair'], 3 => $txt['cursor_hand'], 4 => $txt['cursor_pointer'], 5 => $txt['cursor_move'], 6 => $txt['cursor_text'], 7 => $txt['cursor_wait']);
global $txt;
$context['html_headers'] .='<style type="text/css">
body
{
cursor: ' . (!empty($modSettings['forum_cursor']) ? ''. $cursortext[(int) $modSettings['forum_cursor']] . '' : 'auto') . ';
}
</style>';

Matthew K.

Thanks, I'll test it out.

Matthew K.


Arantor

Right... so errors in the error log? Other symptoms?

Matthew K.

I confirmed the problem is with text strands. I tested replacing $txt['cursor_crosshair'] with "crosshair" and selecting crosshair and it worked. So I assume it's the case of moving global $txt; above the $cursortext array correct?

Matthew K.

Doesn't work moving it above, where should I globalize $txt? Or could this be a problem of having the text strands in the wrong place?

Arantor

Bleh, yeah of course it should be there.

I'm curious why no undefined index errors came up.

You DID empty the cache, right?

Matthew K.

Okay, even with global $txt; above the $cursortext array, the output is the same, the text isn't being added.

Cleared cache again just to clarify, and no change in the mod itself, nor the error logs.

Matthew K.

I have also confirmed the text is properly inputted into Modifications.english.php, and it also shows up in the Admin array.

Matthew K.

Anyone have further ideas on this? I'd like to get this finished up shortly.

Labradoodle-360

Arantor

OK so what's in the database for that modSetting?

Matthew K.

What table are the modSettings stored in?

Arantor

smf_settings, contains two columns, left column is the name of the mod setting, right column is its value.

Matthew K.

It's value is 2, which is crosshair

Arantor

// A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
$context['server']['needs_login_fix'] = $context['server']['is_cgi'] && $context['server']['is_iis'];

// Detect the browser. This is separated out because it's also used in attachment downloads
detectBrowser();

global $txt;
$cursortext = array(0 => 'auto', 1 => $txt['cursor_default'], 2 => $txt['cursor_crosshair'], 3 => $txt['cursor_hand'], 4 => $txt['cursor_pointer'], 5 => $txt['cursor_move'], 6 => $txt['cursor_text'], 7 => $txt['cursor_wait']);
$ident = !empty($modSettings['forum_cursor']) ? (int) $modSettings['forum_cursor'] : 0;
if (empty($cursortext[$ident]))
$ident = 0;

$context['html_headers'] .= '<style type="text/css">
body
{
cursor: ' . $cursortext[$ident] . ') . ';
}
</style>';

Matthew K.

Could you explain what the part you added does, so I can understand it?

Thanks,
Labradoodle-360

Arantor

   global $txt;
-> ensures things are in scope

   $cursortext = array(0 => 'auto', 1 => $txt['cursor_default'], 2 => $txt['cursor_crosshair'], 3 => $txt['cursor_hand'], 4 => $txt['cursor_pointer'], 5 => $txt['cursor_move'], 6 => $txt['cursor_text'], 7 => $txt['cursor_wait']);
-> puts all the strings - including auto into the array

   $ident = !empty($modSettings['forum_cursor']) ? (int) $modSettings['forum_cursor'] : 0;
-> checks if modSettings['forum_cursor'] exists. If not, use 0 (which is auto), if it does, force it to be a number (since it won't be otherwise, which will cause the lookup to $cursortext to fail since that relies on numbered keys.

   if (empty($cursortext[$ident]))
      $ident = 0;
-> if there isn't an entry in $cursortext that matches, revert it to 0, i.e. auto

   $context['html_headers'] .= '<style type="text/css">
   body
   {
      cursor: ' . $cursortext[$ident] . ') . ';
   }
   </style>';
-> should be fairly obvious.

Matthew K.

Your code generates an error from
Code (This line) Select
      cursor: ' . $cursortext[$ident] . ') . ';

Error: unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING
I tried escaping [$ident] .') to no avail.

Arantor

// A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
$context['server']['needs_login_fix'] = $context['server']['is_cgi'] && $context['server']['is_iis'];

// Detect the browser. This is separated out because it's also used in attachment downloads
detectBrowser();

global $txt;
$cursortext = array(0 => 'auto', 1 => $txt['cursor_default'], 2 => $txt['cursor_crosshair'], 3 => $txt['cursor_hand'], 4 => $txt['cursor_pointer'], 5 => $txt['cursor_move'], 6 => $txt['cursor_text'], 7 => $txt['cursor_wait']);
$ident = !empty($modSettings['forum_cursor']) ? (int) $modSettings['forum_cursor'] : 0;
if (empty($cursortext[$ident]))
$ident = 0;

$context['html_headers'] .= '<style type="text/css">
body
{
cursor: ' . $cursortext[$ident] . ';
}
</style>';


That's what I get for trying to clean up.

Matthew K.

Cursor stays default, after changing the admin input.

The page source shows:<style type="text/css">
   body
   {
      cursor: auto;
   }
   </style>

Matthew K.

Would it be smarter just to put the text directly in load for the $cursortext? That does work.

Arantor

I don't get why it does though.

It's on the fence though; strictly all language strings should be $txt strings because they're translatable that way however these aren't exactly just language strings...

Hmmm, not sure what our view as a team on this is; I'm personally inclined to allow it though.

Matthew K.

Yep, definitely. I understand that.

But I've already put a lot more time into just this section than really it's worth.
I could see if it was a fairly easy fix, but I've spent a long time on it, and you've also spent a while on it.

I'll submit it using plain text rather than strings and if the SMF Customization Team wants to correct me, I'll let them show me how and I'll gladly change it.

Arantor

Well, since I'm probably going to be the one who reviews it...

Matthew K.

haha true.

Should the code be left as:

   global $txt;
   $cursortext = array(0 => 'auto', 1 => 'default', 2 => 'crosshair', 3 => 'hand', 4 => 'pointer;cursor;hand', 5 => 'move', 6 => 'text', 7 => 'wait');
   $ident = !empty($modSettings['forum_cursor']) ? (int) $modSettings['forum_cursor'] : 0;
   if (empty($cursortext[$ident]))
      $ident = 0;

   $context['html_headers'] .= '<style type="text/css">
   body
   {
      cursor: ' . $cursortext[$ident] . ';
   }
   </style>';


Or should things be removed? (Obviously global $txt; correct?)

Anything else?

Advertisement: