Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
1.4k views
in Q2A Core by
Hi. As the title of my question describes what i want to do is to create a custom page that will be displayed to the users when they are  loging out of my web site. The goal is to say a "thank you" to those users and display some links/graphics so my site will be a little more user friendly.

PS I dont mind if i have to hack the core files cause i really need to build that page so any answers are welcome.

Thanks in advance for your help
Q2A version: 1.7

2 Answers

+3 votes
by
selected by
 
Best answer

You will need to create an event plugin. You can achieve desired processing by fetching the "u_logout" event in your plugin.

Implementation procedure:

1. Create new page

Go to "Admin" > "Pages" > "Add Page".

Example of settings:

  • Name of page: "Logout message"
  • Position: "No link"
  • Visible for: "Anybody"
  • Heading to display at top of page: "Thank you!"
  • Content: Enter arbitrary HTML codes

2. Create event plugin.

2.1 Create "my-event-handler" folder under qa-plugin/.

2.2 Make plugin files under my-event-handler folder.

metadata.json​


"name": "My Event Handler", 
"description": "Custom event handling", 
"version": "1.0", 
"date": "2017-04-14", 
"author": "PowerQA", 
"author_uri": "http://www.powerqa.org", 
"license": "GPLv2", 
"min_q2a": "1.5" 
}

qa-plugin.php​

<?php 
/* 
Question2Answer by Gideon Greenspan and contributors 
http://www.question2answer.org/
File: qa-plugin/my-event-handler/qa-plugin.php 
Description: Initiates My Event Handler plugin

This program is free software; you can redistribute it and/or 
modify it under the terms of the GNU General Public License 
as published by the Free Software Foundation; either version 2 
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php 
*/
/* 
Plugin Name: My Event Handler 
Plugin URI: 
Plugin Description: Custom event handling 
Plugin Version: 1.0 
Plugin Date: 2017-04-14 
Plugin Author: PowerQA 
Plugin Author URI: http://www.powerqa.org/ 
Plugin License: GPLv2 
Plugin Minimum Question2Answer Version: 1.5 
Plugin Update Check URI: 
*/

if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser 
header('Location: ../../'); 
exit; 
}
qa_register_plugin_module('event', 'qa-my-event-handler.php', 'qa_my_event_handler', 'My Event Handler');

qa-my-event-handler.php

<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/

File: qa-plugin/my-event-handler/qa-event-logger.php
Description: Event module class for my event handler plugin

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

More about this license: http://www.question2answer.org/license.php
*/

class qa_my_event_handler {
public function admin_form(&$qa_content) {
    $saved=false;
    if (qa_clicked('meh_save_button')) {
        qa_opt('meh_redirect_url_when_logout', qa_post_text('meh_redirect_url_when_logout_field'));
        $saved=true;
    }
    $url=qa_opt('meh_redirect_url_when_logout');
    $error=null;
    //if (!strlen($url))
    //    $error='Please set relative or absolute URL.';

    return array(
        'ok' => ($saved && !isset($error)) ? 'Event handler settings saved' : null,
        'fields' => array(
            array(
                'id' => 'meh_redirect_url_when_logout',
                'label' => 'When users logout, they will be redirected to this page - Relative or absolute URL:',
                'value' => qa_html($url),
                'tags' => 'name="meh_redirect_url_when_logout_field"',
                'error' => qa_html($error),
            ),
        ),
        'buttons' => array(
            array(
                'label' => 'Save Changes',
                'tags' => 'name="meh_save_button"',
            ),
        ),
    );
}
public function process_event($event, $userid, $handle, $cookieid, $params) {
    switch($event) {
    case 'u_logout':
        $this->u_logout($event, $userid, $handle, $cookieid, $params);
        break;
    default:
        break;
    }
}
private function u_logout($event, $userid, $handle, $cookieid, $params) {
    $redirectpath = qa_opt('meh_redirect_url_when_logout');
    if(!empty($redirectpath))
        qa_redirect_raw($redirectpath);
}
}

3. Settings

  1. Go to "Admin" > "Plugins" > "My Event Handler" > "Settings"
  2. Set "Redirect path" option. It is OK either relative or absolute URL.

Note

Redirected page does not have to be pages in Q2A. It is OK at other sites (domains).
by
Wow Sama excellent answer!!!. Big Thanks man !!
by
edited by
Ok! just tested and works fine. Awesome plugin and i think you should upload this to Github as many people will find it very usefull !

PS: As a User Experience & User Interface Designer i have a lot of good ideas that will help Q2A be more user friendly. If you or anyone in here needs some Designing help or advice don't hesitate to drop me a message. Once again Thanks !
0 votes
by
Not working in my website... Admin area getting blank.
by
What do you mean? What version of Q2A are u running ? Could you provide more details. I applied it on my site and it works fine !
by
Version 1.7.4
I cannot get logged in. As soon as I hit login button I am getting blank page with nothing on it. Everything worked perfectly fine once i removed the plugin.
Could u please download the plugin from your server and provide me the link.
by
Try to check 4 basic things.
1. Did you edit PHP source with text editor that supports UTF?
     I recommend Notepad++ (https://notepad-plus-plus.org/).
2. Did you save source files with UTF-8 (no BOM).
    https://en.wikipedia.org/wiki/Byte_order_mark
3. Is there unnecessary character OR line before start tag ("<?php")?
4. End tag ("?>") of source files is unnecessary.
...