GetSimple Support Forum

Full Version: looking for a solution to manage global custom fields
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Howdy
I'm wondering if there's a solution (script/plugin/function/droplet etc.) to have something like global custom fields (long/short text inputs), usable across whole website.
I'd need this to store some vars, words or sentences in an easy to manage way, and output them across whole website in various places.

I - of course - know about plugins like custom fields or default component functionality, but none of them solves the problem, is easy to use and fast to manage.
Custom fields are page dependant, and all fields show in page's option.
There's no easy way to hide those fields in page's options.
Using components is too risky, and managing at least 20-30 changeable values using them would be a total misunderstanding.

There are more reasons but you get the point: easiest possible way to add a new input, echo its content in for example footer. Let it be even a phone number, which have to be changed in couple places at once.
As for now I'm using some kind of translation file, where values might be changed by editing one of template files, but this is a usability destroyer, and a disaster for non-techie person.

Developing a plugin for it is the only way I see, but maybe somebody already invented something like this and forgot/would like to share ?
you could try my Matrix plugin, unreleased to extend as I haven't had time to do some decent docs for it. but I use it on all my recent sites without issues.

Just setup a table called 'settings' or whatever, then add your fields that you need.
Now add a single record, edit the fields as required.
Then output them on your page using the following code:

**edit** wrong way round above, fixed now

Code:
// query the settings table
$myquery = "select * from settings where id = 1";  
// return the setting into the $result array
$result=DM_query($myquery,DM_SINGLE);

then just echo $result['setting']; // echo whatever field you want.

Let me know if you need any more info.

its available from github to download and use:

https://github.com/n00dles/DM_Matrix
Sounds great ! Smile
Even for multilanguage fields.

ps. I've been wondering what for was that "matrix plugin" something mentioned long time ago, but after a quick search I did not find a clickable linky.
Matrix
Or just get DM_getRecord() for simple fetches.
Thanx for info Shawn, great hint.

One more question about DM. Am I only able to fetch data on a template level, or are there also some kind of short codes, to use inside textarea while editing page ?

edit: I mean builtin' DM function; dynpages afair interfered with one of the plugins I use.
edit2: Mike's shortcodes plugin could fulfill such task ?
mmmm,tons of plugins...
@shawn, thanks , You'd think I'd know my own plugins ...

@yojoe, you can use my other plugin GS_Shortcodes plugin.
Create a file shortcodes.php in your theme folder and add the following code

Code:
function getSetting($atts){
  extract(shortcode_atts(array(
    "name" => ''
  ), $atts));  
// change this line to your table and record number.
  $records=DM_getRecord('settings', '0');
  return $records[$name];
}
add_shortcode('setting','getSetting', '[setting name=""  /]');

you can then use the shortcode

Code:
[setting name="" /]


When editing pages.

WHen setting up a settings table I usually set it to a max records of 1.
Add all the fields and then just edit that 1 record.
(2013-02-07, 20:04:29)n00dles101 Wrote: [ -> ]@shawn, thanks , You'd think I'd know my own plugins ...

@yojoe, you can use my other plugin GS_Shortcodes plugin.
Create a file shortcodes.php in your theme folder and add the following code

WHen setting up a settings table I usually set it to a max records of 1.
Add all the fields and then just edit that 1 record.

Thx Mike, provided shortcode function looks nice.
I just need a small edit to check frontend language var, and add it automatically.

I'm still testing the DM possibilities, and I'm looking towards the way you mentioned: all fields in one row.
Since every row is saved in a standalone file, one-liner containing all variables should fetch, and display faster.

Btw. DM_getRecord function is dead simple, but it still isn't a one-line command. Still needs to be bind to a variable, to display fetched array value (or am I wrong?).
Slight change to add 3rd parameter, and echo the fetched value should simplify the usage.
Or you already thought about that ? Smile
Just make our own wrapper function in
Your theme.
Yeah, I was going to port DM_getRecord function to functions.php

Right after I find why the files get 604 and dirs 705 rights, and instead of editing field values, a new field is created.
I hope it's not a fault of 3.2B downloaded from GS website :\
@yojoe, did you figure this out?
(2013-02-08, 21:18:06)n00dles101 Wrote: [ -> ]@yojoe, did you figure this out?

I think yes. I firstly chmod'ed manually earlier created dirs, and changed their rights to 755. But I didn't get the possibility to delete created databases. After looking into DM_Matrix.php I found out that it calls mkdir() funct without sufficient access rights.
A quick edit seemed to work fine and newly created dbases started to be deletable.

Check line 50 in mentioned file, and add 0755 rights for created dbases with:
Code:
mkdir(GSSCHEMAPATH, 0755);
I didn't test this by adding new fields types yet, as I have focused on messing with already created dbases, but I think GS installation file also calls mkdir and it's working.

One thing I need to say, that this plugin is FANTASTIC !
DM provides so wide spectrum of possibilities for GS, that I can't even count.

I still need to check your droplet code, as I hadn't have enough time to test shortcodes.

once again: DM is awesome!