Skip to content

Commit

Permalink
Merge pull request techjoomla#36 from techjoomla/feat-privacy-tools
Browse files Browse the repository at this point in the history
Merge `Feat privacy tools` into `Master`
  • Loading branch information
manojLondhe authored Nov 12, 2018
2 parents f6ae838 + 7744180 commit ad269c0
Show file tree
Hide file tree
Showing 16 changed files with 720 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
label="COM_TJNOTIFICATIONS_FIELD_CLIENT_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_CLIENT_DESC"
type="sql"
query="select name from `#__extensions` where type='component' "
query="select LOWER(name) as name from `#__extensions` where type='component' "
key_field="name"
value_field="name"
required="true"
Expand Down
16 changes: 16 additions & 0 deletions src/com_tjnotifications/admin/models/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
*/
class TjnotificationsModelNotification extends JModelAdmin
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @since 3.2
*/
public function __construct($config = array())
{
$config['event_after_save'] = 'tjnOnAfterSaveNotificationTemplate';
parent::__construct($config);
}

/**
* Returns a reference to the a Table object, always creating it.
*
Expand Down Expand Up @@ -182,6 +195,9 @@ public function delete(&$cid)
{
$value[] = 1;
parent::delete($data->id);
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('tjnotification');
$dispatcher->trigger('tjnOnAfterDeleteNotificationTemplate', array($data));
}
}
else
Expand Down
153 changes: 153 additions & 0 deletions src/com_tjnotifications/install.tjnotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
**/
class Com_TjnotificationsInstallerScript
{
/** @var array The list of extra modules and plugins to install */
private $queue = array(
// Plugins => { (folder) => { (element) => (published) }* }*
'plugins' => array(
'actionlog' => array(
'tjnotification' => 1
),
'privacy' => array(
'tjnotification' => 1,
),
),
);

/**
* method to install the component
*
Expand All @@ -26,6 +39,57 @@ public function install($parent)
{
}

/**
* This method is called after a component is uninstalled.
*
* @param \stdClass $parent Parent object calling this method.
*
* @return void
*/
public function uninstall($parent)
{
jimport('joomla.installer.installer');
$db = JFactory::getDBO();
$status = new JObject;
$status->plugins = array();
$src = $parent->getParent()->getPath('source');

// Plugins uninstallation
if (count($this->queue['plugins']))
{
foreach ($this->queue['plugins'] as $folder => $plugins)
{
if (count($plugins))
{
foreach ($plugins as $plugin => $published)
{
$sql = $db->getQuery(true)->select($db->qn('extension_id'))
->from($db->qn('#__extensions'))
->where($db->qn('type') . ' = ' . $db->q('plugin'))
->where($db->qn('element') . ' = ' . $db->q($plugin))
->where($db->qn('folder') . ' = ' . $db->q($folder));
$db->setQuery($sql);

$id = $db->loadResult();

if ($id)
{
$installer = new JInstaller;
$result = $installer->uninstall('plugin', $id);
$status->plugins[] = array(
'name' => 'plg_' . $plugin,
'group' => $folder,
'result' => $result
);
}
}
}
}
}

return $status;
}

/**
* method to update the component
*
Expand All @@ -38,6 +102,7 @@ public function update($parent)
// Install SQL FIles
$this->installSqlFiles($parent);
$this->fix_db_on_update();
$this->fixMenuLinks();
}

/**
Expand All @@ -62,6 +127,71 @@ public function preflight($type, $parent)
*/
public function postflight($type, $parent)
{
$src = $parent->getParent()->getPath('source');
$db = JFactory::getDbo();
$status = new JObject;
$status->plugins = array();

// Plugins installation
if (count($this->queue['plugins']))
{
foreach ($this->queue['plugins'] as $folder => $plugins)
{
if (count($plugins))
{
foreach ($plugins as $plugin => $published)
{
$path = "$src/plugins/$folder/$plugin";

if (!is_dir($path))
{
$path = "$src/plugins/$folder/plg_$plugin";
}

if (!is_dir($path))
{
$path = "$src/plugins/$plugin";
}

if (!is_dir($path))
{
$path = "$src/plugins/plg_$plugin";
}

if (!is_dir($path))
{
continue;
}

// Was the plugin already installed?
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->qn('#__extensions'))
->where($db->qn('element') . ' = ' . $db->q($plugin))
->where($db->qn('folder') . ' = ' . $db->q($folder));
$db->setQuery($query);
$count = $db->loadResult();

$installer = new JInstaller;
$result = $installer->install($path);

$status->plugins[] = array('name' => 'plg_' . $plugin, 'group' => $folder, 'result' => $result);

if ($published && !$count)
{
$query = $db->getQuery(true)
->update($db->qn('#__extensions'))
->set($db->qn('enabled') . ' = ' . $db->q('1'))
->where($db->qn('element') . ' = ' . $db->q($plugin))
->where($db->qn('folder') . ' = ' . $db->q($folder));
$db->setQuery($query);
$db->execute();
}
}
}
}
}

// Install SQL FIles
$this->installSqlFiles($parent);
}
Expand Down Expand Up @@ -212,4 +342,27 @@ public function fix_db_on_update()

$this->fixTemplateTable($db, $dbprefix, $config);
}

/**
* Fix Duplicate menu created for Notification
*
* @return void
*
* @Since 1.1
*/
public function fixMenuLinks()
{
$db = JFactory::getDbo();
$link = 'index.php?option=com_tjnotifications&view=notifications&extension=com_jticketing';
$link1 = 'index.php?option=com_tjnotifications&extension=com_tjvendors';
$allLinks = '"' . $link . '","'. $link1 . '"';

// Delete the mainmenu from menu table
$deleteMenu = $db->getQuery(true);
$deleteMenu->delete($db->quoteName('#__menu'));
$deleteMenu->where($db->quoteName('link') . 'IN (' . $allLinks . ')');
$deleteMenu->where($db->quoteName('level') . " = 1");
$db->setQuery($deleteMenu);
$db->execute();
}
}
2 changes: 1 addition & 1 deletion src/com_tjnotifications/site/controllers/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TJNotificationsControllerPreferences extends JControllerForm
* @since 1.6
*/

public function save()
public function save($key = null, $urlVar = '')
{
$jinput = JFactory::getApplication()->input;
$clientName = $jinput->get('client_name', '');
Expand Down
8 changes: 7 additions & 1 deletion src/com_tjnotifications/site/models/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public function save($data)
if ($data)
{
parent::save($data);
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('tjnotification');
$dispatcher->trigger('tjnOnAfterUnsubscribeNotification', array($data));

return true;
}
Expand All @@ -133,6 +136,9 @@ public function deletePreference(&$data)
{
if ($data)
{
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('tjnotification');
$dispatcher->trigger('tjnOnAfterResubscribeNotification', array($data));
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$conditions = array(
Expand Down Expand Up @@ -281,7 +287,7 @@ public function getUnsubscribedUsers($client,$key)
);
$db->setQuery($query);
$userIds = $db->loadObjectList();
$unsubscribed_users = '';
$unsubscribed_users = array();

foreach ($userIds as $userId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<script src="/jquery.min.js"></script>
<script type="text/javascript">
const tjnBaseurl = "<?php echo JUri::root();?>";
jQuery.noConflict();
jQuery(".btn-group > .btn").click(function(){
jQuery(this).addClass("active").siblings().removeClass("active");
Expand All @@ -24,7 +25,7 @@ function addPreferance(pId,client,provider,key)
jQuery.ajaxSetup({
global: false,
type:'post',
url:'index.php?option=com_tjnotifications&task=preferences.save',
url:tjnBaseurl+'index.php?option=com_tjnotifications&task=preferences.save',
dataType:'json',
beforeSend: function () {
jQuery('#ajax-loader'+pId).show();
Expand Down Expand Up @@ -65,7 +66,7 @@ function removePreferance(pId,client,provider,key)
jQuery.ajaxSetup({
global: false,
type:'post',
url:'index.php?option=com_tjnotifications&task=preferences.delete',
url:tjnBaseurl+'index.php?option=com_tjnotifications&task=preferences.delete',

beforeSend: function () {
jQuery('#ajax-loader'+pId).show();
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/actionlog/tjnotification/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<html><body bgcolor="#FFFFFF"></body></html>

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; @package TJNotifications
; @subpackage Actionlog.tjNotifications
; @copyright Copyright (C) 2009 - 2018 Techjoomla. All rights reserved.
; @license GNU General Public License version 2 or later
; Note: All ini files need to be saved as UTF-8

PLG_ACTIONLOG_TJNOTIFICATION="Action Log - TJNotifications"
PLG_ACTIONLOG_TJNOTIFICATION_XML_DESCRIPTION="Record the actions of users on the site for TJNotifications extension so they can be reviewed if required."

; Config
PLG_ACTIONLOG_TJNOTIFICATION_LOG_ACTION_NOTIFICATION_SUBSCRIPTION="Log action if user unsubscribes/resubscribes for notifications?"
PLG_ACTIONLOG_TJNOTIFICATION_LOG_ACTION_NEW_TEMPLATE="Log action for creation or update notification template?"
PLG_ACTIONLOG_TJNOTIFICATION_LOG_ACTION_DELETE_TEMPLATE="Log action for delete notification template?"
PLG_ACTIONLOG_TJNOTIFICATION_LOG_ACTION_COMMON_DESC="This action will be logged only when you set this to 'Yes'"

; Event
PLG_ACTIONLOG_TJNOTIFICATION_NOTIFICATION_UNSUBSCRIBE="User <a href=\"{accountlink}\">{username}</a> has unsubscribed {client} {type} notification for <a href=\"{keylink}\">{key}."
PLG_ACTIONLOG_TJNOTIFICATION_NOTIFICATION_RESUBSCRIBE="User <a href=\"{accountlink}\">{username}</a> has resubscribed {client} {type} notification for <a href=\"{keylink}\">{key}."
PLG_ACTIONLOG_TJNOTIFICATION_TEMPLATE_ADD="User <a href=\"{accountlink}\">{username}</a> has added the template <a href=\"{keylink}\">{title}</a> for {client}."
PLG_ACTIONLOG_TJNOTIFICATION_TEMPLATE_UPDATE="User <a href=\"{accountlink}\">{username}</a> has updated the template <a href=\"{keylink}\">{title}</a> for {client}."
PLG_ACTIONLOG_TJNOTIFICATION_TEMPLATE_DELETE="User <a href=\"{accountlink}\">{username}</a> has deleted the template {title} for {client}."
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; @package TJ Notifications
; @subpackage Actionlog.tjNotifications
; @copyright Copyright (C) 2009 - 2018 Techjoomla. All rights reserved.
; @license GNU General Public License version 2 or later
; Note: All ini files need to be saved as UTF-8

PLG_ACTIONLOG_TJNOTIFICATION="Action Log - TJ Notifications"
PLG_ACTIONLOG_TJNOTIFICATION_XML_DESCRIPTION="Record the actions of users on the site for TJNotifications extension so they can be reviewed if required."
Loading

0 comments on commit ad269c0

Please sign in to comment.