| Current Path : /home/megadansyp/www/plugins/system/wbreactiv/ |
| Current File : /home/megadansyp/www/plugins/system/wbreactiv/wbreactiv.php |
<?php
/**
* wbReactiv - resend confirmation email
*
* @author Yannick Gaultier - Weeblr.com
* @copyright (c) Yannick Gaultier - Weeblr llc - 2015
* @package wbreactiv
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @version 1.0.7.100
* @date 2016-07-18
*
* build 1.0.7.100
*
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
/**
*/
class plgSystemWbreactiv extends JPlugin
{
protected $autoloadLanguage = true;
/**
* Constructor.
*
* @param object &$subject The object to observe.
* @param array $config An optional associative array of configuration settings.
*
* @since 1.5
*/
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
include_once 'helper.php';
}
/**
* Respond to an ajax request to provide some dynamic data to a fully cached page
* Requests are:
* Session messages: /baseurl/index.php?option=com_ajax&plugin=wbreactiv&method=resend&format=json&user_id=xx
*
*/
public static function onAjaxWbreactiv()
{
// token check from GET var
if (!JSession::checkToken('get'))
{
throw new RuntimeException('Access denied.', 403);
}
$app = JFactory::getApplication();
$app->allowCache(false);
$method = $app->input->get('method');
switch ($method)
{
case'resend':
$response = self::_resendActivationEmail($app->input->getInt('user_id'), $app->input->getCmd('type', 'list'));
break;
default:
$response = array('success' => false, 'message' => JText::_('PLG_SYSTEM_WBREACTIV_INVALID_METHOD'), 'messages' => null, 'data' => null);
return $response;
break;
}
return $response;
}
public static function _resendActivationEmail($userId, $type)
{
if (empty($userId))
{
$response = array('success' => false, 'message' => JText::_('PLG_SYSTEM_WBREACTIV_INVALID_USER_ID'), 'messages' => null, 'data' => null);
return $response;
}
// resend email
$response = PlgSystemWbreactivHelper::reactiv($userId, $type);
return $response;
}
public function onAfterDispatch()
{
$app = JFactory::getApplication();
if (!$app->isAdmin())
{
return;
}
$option = $app->input->getCmd('option');
if ($option !== 'com_users')
{
return;
}
$view = $app->input->getCmd('view');
switch ($view)
{
case 'users':
$this->_insertJs();
break;
case 'user':
$layout = $app->input->getCmd('layout');
$userId = $app->input->getInt('id');// already activated? no button
if ($layout == 'edit' && !empty($userId) && PlgSystemWbreactivHelper::shouldSendActivationEmail($userId))
{
$this->_insertJs($userId);
}
break;
}
}
/**
* @param JForm $form The form to be altered.
* @param array $data The associated data for the form.
*
* @return boolean
*/
protected function _insertJs($userId = 0)
{
// insert our javascript/css
$document = JFactory::getDocument();
$document->addScript(JURI::root() . 'media/plg_wbreactiv/js/wbreactiv.min.js');
$document->addStyleDeclaration(
"
.wb-resend-activation {
display: inline-block;
}
.wb-resend-activation-icon {
display:inline-block;
margin: 0.5em 0 0 0;
}
.wb-resend-activation-button {
display: inline-block;
margin-left: 1em;
min-width: 165px;
}
.wb-resend-activation-status {
margin-left: 1em;
font-size: 0.9em;
color: #555;
}
.wb-resend-activation-status-list {
margin:0;
padding:0;
font-size: 0.9em;
color: #555;
}
");
$document->addScriptDeclaration(
"
window.weeblrApp = window.weeblrApp || {};
window.weeblrApp.resendActivationBase = '" . JUri::root() . "';
window.weeblrApp.resendActivationUrl = '" . JUri::base()
. 'index.php?option=com_ajax&plugin=wbreactiv&method=resend&format=json&user_id={{user_id}}&type={{type}}&'
. JSession::getFormToken() . "=1';
window.weeblrApp.resendActivationText = '" . JText::_('PLG_SYSTEM_WBREACTIV_RESEND_ACTIVATION_EMAIL', true) . "';
window.weeblrApp.confirmResendActivationText = '" . JText::_('PLG_SYSTEM_WBREACTIV_CONFIRM_RESEND', true) . "';
" . (empty($userId) ? '' : 'window.weeblrApp.confirmResendActivationUserId = ' . $userId . ';') . "
"
);
return true;
}
}