Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
20 posts Page 2 of 2
@Blutbaden,
am I right in understanding that what you want is this -
suppose the sidebar has several groups (i.e. collapsible regions) with several templates below each group.
Now if it so happens that for a certain admin *all* the templates below a particular group are hidden, what we are left with is the empty group.
You'd like that if there are no templates below a group, that group should also not show.

Please let me know if that is correct. Thanks.
Yes, correct. :)

Automatically or there could be config options for groups like there is for templates.
Would something like this be possible in 2.0?
@Blutbaden,

We can do that in v2.0 by overriding the theme snippet that renders the sidebar with our own version that first checks if a group has any children before displaying it.

The concept of theme overriding has been discussed at viewtopic.php?f=5&t=10241 (under 'Theming' heading) so if you need more info please take a look at that post.

Here is how we'll use it for your problem.
First of all, we'll signal to Couch that we have our own custom theme that can override GUI items of the admin-panel.
To do that, find the following line in couch/config.php file.and uncomment it (i.e. remove the two leading slashes) -
// 26.
// If the admin-panel uses a custom theme, set the following to the folder-name of the theme.
// Theme folder is expected to be within the 'couch/theme' folder. No leading or trailing slashes please.
//define( 'K_ADMIN_THEME', 'sample' );

This is the sample theme that ships with Couch and you can its folder at 'couch/theme/sample'.

As explained in the v2.0 post I mentioned, once the theme is activated, all snippets placed in this folder will be used by Couch in place of the system theme snippets (found in 'couch/theme/_system' folder) that it normally uses.

We are interested only in overriding the snippet used for the sidebar. That happens to be 'sidebar.html'.

I am attaching a modified version of the system sidebar.html. Please extract it from the zip and place it in the 'sample' folder mentioned above.

And that should be it.
The sidebar should now only show the headers that have atleast one child beneath them.

Hope it helps. Do let me know.

Attachments

All this is very useful KK, thank you very much :D
Testing this 6 years later on current version, and it's working just fine. That's great!

@KK, is there a way to set the access to a specific user_acess_level instead to a specific user_name? Let's suppose I have some level 7, level 8 and level 9 admins (tweaking auth/auth.php file and couch_levels db table). How could I give, in an example, access to a specific template only to level 9 and above? Is it possible using this addon?
File config.php of the addon takes a list of users, which is not necessarily a static typed list. Do you see my point?

Usual version of configuration —
Code: Select all
$t['blog.php'] = 'admin';


Your version would be like —

Code: Select all
<-- query a list of users with level 9 — -->

$my_level9users = $DB->select( ... );


<-- feed the "|"-separated list of users to the Blog setting — -->

$t['blog.php'] = $my_level9users;


All of this can be done via AdminPanel with a version of my paid custom addon (github addons » advanced access control) but it is not coded with access levels yet, so may take a day or two (if anyone's interested). Addon is more inclined to restrict file access to never allow certain people to delete files from server.

Anyway, with a few PHP lines and an SQL query, code can automatically feed the names of level-9 users to config and voila, it works :lol:


AmaralSites wrote: Testing this 6 years later on current version, and it's working just fine. That's great!

@KK, is there a way to set the access to a specific user_acess_level instead to a specific user_name? Let's suppose I have some level 7, level 8 and level 9 admins (tweaking auth/auth.php file and couch_levels db table). How could I give, in an example, access to a specific template only to level 9 and above? Is it possible using this addon?

Attachments

@AmaralSites, as an alternative to @trendoman's suggestions you may try the following quick-n-dirty solution -

Edit simple-access-control.php file and find function access_control() in it.
Modify the following line in the function from -
Code: Select all
if( in_array($AUTH->user->name, $users) ){

to this -
Code: Select all
if( in_array($AUTH->user->access_level, $users) ){

And now the addon expects a pipe-separated set of explicit values in config that represent the 'access level' (1 to 10) instead of names e.g.
Code: Select all
$t['blog.php'] = '10';
$t['news.php'] = '4 | 7 | 10';
$t['test.php'] = '';

As I mentioned, this is not a very elegant solution but has the benefit of requiring minimal changes in existing code to work as you wish.

Hope it helps.
This is awesome, @KK. Thanks a lot!
You are welcome :)
20 posts Page 2 of 2
cron