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 Robin S
      A community member raised a question and I thought a new sanitizer method for the purpose would be useful, hence...
      Sanitizer Transliterate
      Adds a transliterate method to $sanitizer that performs character replacements as defined in the module config. The default character replacements are based on the defaults from InputfieldPageName, but with uppercase characters included too.
      Usage
      Install the Sanitizer Transliterate module.
      Customise the character replacements in the module config as needed.
      Use the sanitizer on strings like so:
      $transliterated_string = $sanitizer->transliterate($string);
       
      https://github.com/Toutouwai/SanitizerTransliterate
      https://modules.processwire.com/modules/sanitizer-transliterate/
       
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version to 2.10, add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By thomasaull
      I created a little helper module to trigger a CI pipeline when your website has been changed. It's quite simple and works like this: As soon as you save a page the module sets a Boolean via a pages save after hook. Once a day via LazyCron the module checks if the Boolean is set and sends a POST Request to a configurable Webhook URL.
      Some ideas to extend this:
      make request type configurable (GET, POST) make the module trigger at a specified time (probably only possible with a server cronjob) trigger manually Anything else? If there's interest, I might put in some more functionality. Let me know what you're interested in. Until then, maybe it is useful for a couple of people 🙂
      Github Repo: https://github.com/thomasaull/CiTrigger
    • By Robin S
      I created this module a while ago and never got around to publicising it, but it has been outed in the latest PW Weekly so here goes the support thread...
      Unique Image Variations
      Ensures that all ImageSizer options and focus settings affect image variation filenames.

      Background
      When using methods that produce image variations such as Pageimage::size(), ProcessWire includes some of the ImageSizer settings (height, width, cropping location, etc) in the variation filename. This is useful so that if you change these settings in your size() call a new variation is generated and you see this variation on the front-end.
      However, ProcessWire does not include several of the other ImageSizer settings in the variation filename:
      upscaling cropping, when set to false or a blank string interlace sharpening quality hidpi quality focus (whether any saved focus area for an image should affect cropping) focus data (the top/left/zoom data for the focus area) This means that if you change any of these settings, either in $config->imageSizerOptions or in an $options array passed to a method like size(), and you already have variations at the requested size/crop, then ProcessWire will not create new variations and will continue to serve the old variations. In other words you won't see the effect of your changed ImageSizer options on the front-end until you delete the old variations.
      Features
      The Unique Image Variations module ensures that any changes to ImageSizer options and any changes to the focus area made in Page Edit are reflected in the variation filename, so new variations will always be generated and displayed on the front-end.
      Installation
      Install the Unique Image Variations module.
      In the module config, set the ImageSizer options that you want to include in image variation filenames.
      Warnings
      Installing the module (and keeping one or more of the options selected in the module config) will cause all existing image variations to be regenerated the next time they are requested. If you have an existing website with a large number of images you may not want the performance impact of that. The module is perhaps best suited to new sites where image variations have not yet been generated.
      Similarly, if you change the module config settings on an existing site then all image variations will be regenerated the next time they are requested.
      If you think you might want to change an ImageSizer option in the future (I'm thinking here primarily of options such as interlace that are typically set in $config->imageSizerOptions) and would not want that change to cause existing image variations to be regenerated then best to not include that option in the module config after you first install the module.
       
      https://github.com/Toutouwai/UniqueImageVariations
      https://modules.processwire.com/modules/unique-image-variations/
    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      ProcessWire-Module: http://modules.processwire.com/modules/page-access-releasetime/
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
×
×
  • Create New...