Jump to content
horst

ALIF - Admin Links In Frontend

Recommended Posts

ALIF - Admin Links In Frontend
 

This module combines some of the admin links that we want to use on the frontpages sometimes. It is a comfortable and easy way to do so. After you have installed and configured the module, you can inject the links into the frontpage with code like this in a template file:

echo $modules->isInstalled('AdminLinksInFrontend') ? $modules->get('AdminLinksInFrontend')->render() : '';

.

Credits: The comfortable Javascript Color Picker in the Configpage comes from Jan Odvarko (http://jscolor.com). Many thanks for this!

* Toolbar
 
The toolbar can be positioned by css values for top/bottom and left/right. It can expand in vertical or horizontal direction. The buttons are links to the PW admin, for logout, or for editing the page in admin, or informational ones. All settings, including the colors, can be defined in the modules config page. This is available for all PW versions from PW 2.3 up to now.
 
pw_alif_01.jpg
 
Depending on how you configure this part, it can be used for authors and editors too, maybe.
 
 
* Import / Export Settings
 
It has the possibility to export and import its settings via two textarea fields. When importing settings, you get a second screen where you can select which settings you want to import.
 
post-1041-0-93467100-1450162787_thumb.jp
 
* One-click User Account Switcher
 
For PW versions 2.6.8+, there is one really nice function available, that I use when developing / testing sites with different user / roles. A fast User-Account-Switcher that lets you view the same page from different user accounts with only one click. To enter this mode, you need to login as a superuser one time, and the feature needs to be enabled in the module of course. After that, you can log out, login with different user roles, etc. At least the toolbar buttons for the User-Account-Switcher will stay visible for you. :)
 
This is session based. There is also an extra button with a trash can and the text "Session", that helps you to leave this mode once you are finished.

pw_alif_02.jpg
 
As you can see in the screenshot, after clicking "guest",  I was logged out, but a regular login button, a warning for debug mode and my three defined buttons for user accounts are available. When clicking another user button I login with this account. Very handy.
 
ATTENTION!
 
The use of the One-click User Account Switcher is mainly intended for dev sites, not for public sites! You should be aware that there is a huge security risc when using this feature on public reachable sites! We completly leave ProcessWires comfort zone in regard of security, - and the only thing between your site and potentially hackattacks is this module. (Oh mom, - what have I done?)
 
PW 2.6.8+ has a comfortable function for admin tasks, that let us log into different user accounts via API without using passwords. This module uses this function! All data that is needed during a User Account Switcher session is stored in the session data on the server. So, if someone steel your session cookie, there is potentially risc that he can login as a superuser, depending of the user account buttons you have in your admin links collection! To prevent SessionHijacking, the module can be bound to a single IP address, it uses a fingerprint depending of IP(s) and UserAgent string. And you need to define a max time to live in minutes between 2 and 60, a User Account Switcher session may run.
 
A User Account Switcher session only can be initialized by a Superuser who also explicitly has set a permission called 'alif-user-account-switcher', what is defined by the module, when installing it. So, the prefered way to use this module is, to enable and use the User Account Switcher while the site is unpublic, and before it goes public, remove the permission from the superuser role. This way, you can use its menu function, but not the UAS anymore.

On a sidenote, for those rare cases where multiple superusers simultaneous developing on a site and want to use the ALIF, but the UAS should be used only by one, you can leave the 'alif-user-account-switcher' permission removed from the superuser role, but need to assign the role 'alif-superuser' to the single user account. This way, only that single superuser has the permission for UAS, whereas all other superusers doesn't have it.
.
.

* The Configpage

pw_alif_04.jpg
 

 
* Online demo

I have pasted it into this old site and enabled it to be present every time (when the site is in demo mode only!). So, it is an earlier state, but the switcher is functional there: http://pwlaf.biriba.de/dbinfo/
 

* Download

From our modules directory or from github repo

Edited by horst
updated with link to modules directory
  • Like 31

Share this post


Link to post
Share on other sites

It's now on Github: https://github.com/horst-n/AdminLinksInFrontend

After aproval in the modules directory, I will update the post here. :-)

Please, re-read the first post. It is updated with the release announcement and a more detailed explanation of all features.

Edited by horst
  • Like 3

Share this post


Link to post
Share on other sites

Have seen that it was mentioned in last ProcessWire Weekly. (sighh, have hurried up with it)

I have tested it with PW versions 2.3, 2.4, 2.5, 2.6, 2.7 and with PHP 5.3 and 5.4. It works good from PW 2.4+ up! With PW 2.3, the Javascript Color Picker doesn't function. But 2.3 is really old and if someone has maintained a site until now without ALIF, he will do it fine in future too. :lol:

Only thing I want to know is: in wich PW version was "showIf" introduced to show / hide Inputfields in the admin? Would be nice if someone can point me to that.

So, it is ready for the masses now! ;)

Edited by horst
  • Like 5

Share this post


Link to post
Share on other sites

Added another little tool to the box that I sometimes use to detect best breakpoints for mediaqueries. A little Javascriptbox that displays the dimensions of body and a configurable custom container (by ID). What dimensions are shown, offsetWidth, ClientWidth, ScrollWidth, is dynamically configurable in the Top of the JSbox:

 

pw_alif_07.jpgpw_alif_08.jpg

 

To enable / disable it, select or drop the button in the config page, and, optionally, type in the id of a custom container.

  • Like 5

Share this post


Link to post
Share on other sites

One more Button, :) for: OpCache status

pw_alif_opc_01.jpg

pw_alif_opc_02.jpg

If OpCache is enabled on a site, it includes a new button and add an admin page for viewing the opcache status. The script for showing this is taken from, and credits go to: Rasmus Lerdorfs. See github repo: https://github.com/rlerdorf/opcache-status

Share this post


Link to post
Share on other sites

Successfully tested ALIF with PW 3.0 and set the version to 1.0.0 stable now.

  • Like 6

Share this post


Link to post
Share on other sites
Hi,

First time I have installed it, mainly to see what the button "Debugmode" does. It does not do anything: href='javascript:;'

Am I missing something?

Share this post


Link to post
Share on other sites

This is a pure info icon. It (only) recommends you that you have $config->debug set to true! So, maybe not that useful in develoment mode, but later, if you use a small set of admin links for editors too, it is useful to be rmembered to turn out debug mode when finished something on a production site.

Share this post


Link to post
Share on other sites

This morning, I finally had time to install this module. I am blown away to it's usefulness and wish I had made time to look at this a whole lot earlier. Great work, @horst!

  • Like 3

Share this post


Link to post
Share on other sites

hi horst,

i can't seem to get the user switcher working... after some setup problems i finally got the user-buttons to display. but when i click on "guest" i am logged out and don't see the user buttons any more. also the "enable login-button" seems to have no effect.

can you please help me how i can debug this? thanks!

Share this post


Link to post
Share on other sites

This morning, I finally had time to install this module. I am blown away to it's usefulness and wish I had made time to look at this a whole lot earlier. Great work, @horst!

Thanks Charles!

hi horst,

i can't seem to get the user switcher working... after some setup problems i finally got the user-buttons to display. but when i click on "guest" i am logged out and don't see the user buttons any more. also the "enable login-button" seems to have no effect.

can you please help me how i can debug this? thanks!

Bernhard, I'm not sure, but best thing would be, if you can run this locally and use an IDE with debugger. Everything in this regard is Sessionbased. You need to check / debug those functions in the module:

  •     public function hookBeforeProcessLogin(HookEvent $event) {
  •     public function hookBeforeProcessLogout(HookEvent $event) {
  •     public function hookAfterSessionLogout(HookEvent $event) {
  •     public function hookAfterSessionLogin(HookEvent $event) {

Also I don't know what you mean with: "after some setup problems"?

Share this post


Link to post
Share on other sites

hi horst,

i tried it on a fresh install today and got it working. don't know what was the reason but i'm too busy right now to investigate further :(

Also I don't know what you mean with: "after some setup problems"?

i was not sure what all the fields where doing

post-2137-0-30370400-1456420160_thumb.pn

my questions where like this:

"select users"

what is this doing? is this controlling access? will only users selected here see the switcher?

"start UAS session"

what is an UAS session?? ok got it now... user account switcher, but i thought that was a technical word i didn't know. and therefore i didn't know what this checkbox is doing at all.

i think step by step instructions would be good, like:

if you want to show the user switcher proceed as follows:

  • check the box "enable user account switcher
  • select users that should be shown in the switcher-panel
  • check the box to start the user account switcher (UAS) session
  • select the time, how long the UAS should be active (no good english i think)
  • click on "submit" button and go to frontend. the UAS-Panel should show up

edit: i think it would help to change the field label from

Configure and start the fast User Account Switcher

to

Configure and start the fast User Account Switcher (UAS)
 
maybe that sounds too much to you, but it was really not clear for me as i did not know anything about the workflow.
 
edit2: maybe a screencast with licecap would have also solved those questions ;)

Share this post


Link to post
Share on other sites

On module install there's a PHP error:

Trying to get property of non-object in .../ProcessAdminLinksInFrontend.module:52

Share this post


Link to post
Share on other sites

Sorry it's me again, 'Warm up opcache with PW files' throws an error here (Tracy):

Cannot declare class ProcessWire\InputfieldForm, because the name is already in use
5×	
PHP Notice: Undefined index: dirname in .../AdminLinksInFrontend/libs/hn_basic.class.php:1748
21×	
PHP Notice: Use of undefined constant THOUSAND_SEPARATOR - assumed 'THOUSAND_SEPARATOR' in .../site/modules/AdminLinksInFrontend/libs/opcache.php:60
634×	
PHP Notice: Use of undefined constant THOUSAND_SEPARATOR - assumed 'THOUSAND_SEPARATOR' in .../site/modules/AdminLinksInFrontend/libs/opcache.php:249
1×	
PHP Notice: Use of undefined constant THOUSAND_SEPARATOR - assumed 'THOUSAND_SEPARATOR' in .../site/modules/AdminLinksInFrontend/libs/opcache.php:183

Share this post


Link to post
Share on other sites

Hhm, looks like the OPCache class is not ready to use with PW3 namespaces. Unfortunately I have no PW3 installl with OPCache installed where I can test it. :(

To the first error, I can say this sounds a bit weird, because I try to get the Page of Admin -> Setup (what is 22) and than checks if it has a children Page with the name of the OP-Cache Viewer. So this should return A) the page if existing, or B) a NullPage object. Both possible returns are objects. So, without able to test, it looks weird.

What ID does your Admin Setup Page have?

---

I suggest to uninstall the OPCache Viewer and only use the Admin Links In Frontend module until I got solved this. (What may take a while, :( )

Share this post


Link to post
Share on other sites

Ok, thanks. Don't worry about the errors, I use this module only occassionally, and I just took a look on the opcache viewer as there's opcache on the server.

As for issue No1, maybe there's an extra "children('include=hidden')" that doesn't needed?

// original - throws error
$p = $this->pages->get(22)->children('include=hidden')->get('name=' . AdminLinksInFrontend::opcPageName);

// works
$p = $this->pages->get(22)->get('name=' . AdminLinksInFrontend::opcPageName);

// in one go
$p = $this->pages->get('parent=22, name=' . AdminLinksInFrontend::opcPageName);
Admin->Setup has the id of 22 here too. I forgot to mention that it's PW 3.021 here but it seems you figured this out :)
  • Like 1

Share this post


Link to post
Share on other sites

Hi, Horst,

I just tried to install the module, but got 2 error messages right after downloading, regarding:

AdminLinksInFrontend.module, line 153
and
ProcessAdminLinksInFrontend.module, line 45

In both cases I had to remove the [...] part to get it working: 

self::$opcEnabled = opcache_get_status();//['opcache_enabled'];

I am running PW 3.0.23 in this particular case.

 

EDIT: Ok, now PW tells me why: I need to install PHP 5.4 or greater...

Sorry for bothering you!

  • Like 1

Share this post


Link to post
Share on other sites

Have made some updates to ALIF:

  • 1.1.0 fixed a bug in method sanitizeColor()
  • 1.1.1 added detection and a toggle button for TracyDebugger (enable/disable)
  • 1.1.2 more security for User-Switcher, (stays in for cases, where TracyDebugger isn't available)

pw-alif-tracy-toggler.png

http://modules.processwire.com/modules/admin-links-in-frontend/

  • Like 6

Share this post


Link to post
Share on other sites
On 12/10/2015 at 12:35 PM, horst said:

A User Account Switcher session only can be initialized by a Superuser who also explicitly has set a permission called 'alif-user-account-switcher', what is defined by the module, when installing it.

Just an FYI, that a recent change to the core might make this impossible to do via the admin:
https://github.com/processwire/processwire/commit/7943aa1064204db5415d661312037f1dd4199249

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By eelkenet
      Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild.  
       
      What is it?
      The missing range slider Inputfield for Processwire. 
      What does it do?
      This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
      It includes a visible and editable value field, to override/tweak the value if required.  
      Features
      Min/max values Precision (number of decimals) Steps (Read more) Manual override of the selected value (will still adhere to the rules above) Usage
      Clone / zip repo Install FieldtypeFloatRange, this automatically installs the Inputfield Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field. To render the field's value simply echo `$page->field` Demo
      A field with Min=0, Max=1, Step=0.2, Precision=2

      Field with settings Min=0, Max=200, Step=0.25, Precision=2

       
      Todo
      Make the display-field's size configurable (will use the Input Size field setting)  Hopefully become redundant If it's usable for others I'll add it to the Modules list  
      Changelog
      v002
      - Fix issue where setting the step value to an empty value created problem with validation
      - Make the display-field optional 
      v001
      - Initial release
       
      Thanks!
       
       
    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
    • By adrian
      This module allows you to automatically rename file (including image) uploads according to a configurable format
      This module lets you define as many rules as you need to determine how uploaded files will be named and you can have different rules for different pages, templates, fields, and file extensions, or one rule for all uploads. Renaming works for files uploaded via the admin interface and also via the API, including images added from remote URLs.   Github: https://github.com/adrianbj/CustomUploadNames
      Modules Directory: http://modules.processwire.com/modules/process-custom-upload-names/
      Renaming Rules
      The module config allows you to set an unlimited number of Rename Rules. You can define rules to specific fields, templates, pages, and file extensions. If a rule option is left blank, the rule with be applied to all fields/templates/pages/extensions. Leave Filename Format blank to prevent renaming for a specific field/template/page combo, overriding a more general rule. Rules are processed in order, so put more specific rules before more general ones. You can drag to change the order of rules as needed. The following variables can be used in the filename format: $page, $template, $field, and $file. For some of these (eg. $field->description), if they haven't been filled out and saved prior to uploading the image, renaming won't occur on upload, but will happen on page save (could be an issue if image has already been inserted into RTE/HTML field before page save). Some examples: $page->title mysite-{$template->name}-images $field->label $file->description {$page->name}-{$file->filesize}-kb prefix-[Y-m-d_H-i-s]-suffix (anything inside square brackets is is considered to be a PHP date format for the current date/time) randstring[n] (where n is the number of characters you want in the string) ### (custom number mask, eg. 001 if more than one image with same name on a page. This is an enhanced version of the automatic addition of numbers if required) If 'Rename on Save' is checked files will be renamed again each time a page is saved (admin or front-end via API). WARNING: this setting will break any direct links to the old filename, which is particularly relevant for images inserted into RTE/HTML fields. The Filename Format can be defined using plain text and PW $page variable, for example: mysite-{$page->path} You can preserve the uploaded filename for certain rules. This will allow you to set a general renaming rule for your entire site, but then add a rule for a specific page/template/field that does not rename the uploaded file. Just simply build the rule, but leave the Filename Format field empty. You can specify an optional character limit (to nearest whole word) for the length of the filename - useful if you are using $page->path, $path->name etc and have very long page names - eg. news articles, publication titles etc. NOTE - if you are using ProcessWire's webp features, be sure to use the useSrcExt because if you have jpg and png files on the same page and your rename rules result in the same name, you need to maintain the src extension so they are kept as separate files.
      $config->webpOptions = array(     'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp) ); Acknowledgments
      The module config settings make use of code from Pete's EmailToPage module and the renaming function is based on this code from Ryan: http://processwire.com/talk/topic/3299-ability-to-define-convention-for-image-and-file-upload-names/?p=32623 (also see this post for his thoughts on file renaming and why it is the lazy way out - worth a read before deciding to use this module). 
       
       
      NOTE:
      This should not be needed on most sites, but I work with lots of sites that host PDFs and photos/vectors that are available for download and I have always renamed the files on upload because clients will often upload files with horrible meaningless filenames like:
      Final ReportV6 web version for John Feb 23.PDF

×
×
  • Create New...