caa49320 by Marty Penner

Clean up a few files and translate a few strings

1 parent 67e5f6dc
......@@ -23,12 +23,24 @@ call_user_func(
}
);
/**
* @param $a
* @param $subkey
* @param $sort
*
* @return array
*/
function subval_sort($a, $subkey, $sort)
{
$b = [];
$c = [];
foreach ($a as $k => $v) {
$b[$k] = strtolower($v[$subkey]);
}
$sort($b);
foreach ($b as $key => $val) {
$c[] = $a[$key];
}
......@@ -36,6 +48,9 @@ function subval_sort($a, $subkey, $sort)
return $c;
}
/**
* @param $uid
*/
function get_user_notices($uid)
{
$notices = get_user_meta($uid, 'notices', true);
......@@ -45,6 +60,9 @@ function get_user_notices($uid)
}
}
/**
* @param bool $showOnlyUnread
*/
function print_user_notices($showOnlyUnread = false)
{
$user = new User\CurrentAccount();
......@@ -65,7 +83,15 @@ function print_user_notices($showOnlyUnread = false)
if (isset($notice['args']) && count($notice['args']) > 0) {
foreach ($notice['args'] as $key => $val) {
if (filter_var($val, FILTER_VALIDATE_URL) !== false) {
$content = str_replace('{'.$key.'}', "<a href='".$val."'>Click here</a>", $content);
$content = str_replace(
'{'.$key.'}',
"<a href='"
.$val
."'>"
.__('Click here', CBV_DOMAIN)
.'</a>',
$content
);
} else {
$content = str_replace('{'.$key.'}', $val, $content);
}
......@@ -75,7 +101,7 @@ function print_user_notices($showOnlyUnread = false)
$rows .= '<tr class="notice-row" id="'.$index.'">';
$rows .= '<td width="12" style="padding: 0 0 0 10px; vertical-align: middle;"><a href="javascript:;" class="notice '
.(($notice['status'] == 'read') ? 'read' : 'unread')
.'"><img src="assets/images/blank.gif" width="12" height="12"></a></td>';
.'"><img src="/wp-content/themes/cbv/assets/images/blank.gif" style="width: 12px; height: 12px;"></a></td>';
if ($system['system_message_type'] == 'none') {
$system['system_message_type'] = 'notice';
......@@ -84,8 +110,9 @@ function print_user_notices($showOnlyUnread = false)
$rows .= '<td width="80" style="vertical-align:middle;"><span>'
.ucfirst(str_replace('_', '&nbsp;', $system['system_message_type']))
.'</span></td>';
$rows .= '<td style="vertical-align:middle;">'.nl2br($content).'<br /><span class="legal">Sent: '
.date('M j, Y @ h:ia', $notice['sent_date']).'</span></td>';
$rows .= '<td style="vertical-align:middle;">'.nl2br($content).'<br /><span class="legal">'
.__('Sent:', CBV_DOMAIN)
.CBV\tz_display('notice_sent_date', $notice['sent_date']).'</span></td>';
$rows .= '</tr>';
}
......@@ -96,6 +123,11 @@ function print_user_notices($showOnlyUnread = false)
}
}
/**
* @param $trigger
*
* @return bool
*/
function get_notification_by_trigger($trigger)
{
$args = [
......@@ -119,8 +151,9 @@ function get_notification_by_trigger($trigger)
}
/**
* GET NUMBER OF NEW NOTICES
* @returns (Int)
* Get number of new notices
*
* @return int
*/
function get_num_notices()
{
......@@ -166,11 +199,21 @@ function markNotice($notification_id = -1, $status = NOTIFICATION_STATUS_READ)
/**
* Send Notifications
*
* @trigger = notification unique slug name
*
* @param int $uid
* @param string $trigger
* @param array $args
*
* @throws \Exception
*/
function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = [], $send_override = false)
function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = [])
{
/** @var \wpdb $wpdb */
global $wpdb;
/** @var \StdClass $notification */
$notification = get_notification_by_trigger($trigger);
if ($notification) {
......@@ -181,13 +224,13 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
$system = get_post_meta($nid, 'system', true);
$notification->trigger = $details['trigger'];
$notification->status = isset($details['status']) ? $details['status'] : "active";
$notification->status = isset($details['status']) ? $details['status'] : 'active';
$notification->type = $details['type'];
$notification->sendto = @$details['sendto'];
$notification->is_email = (($email['text'] != "" || $email['html'] != "") && $email['subject'] != "")
$notification->is_email = (($email['text'] != '' || $email['html'] != '') && $email['subject'] != '')
? true
: false;
$notification->is_system = (isset($system['message']) && $system['message'] != "") ? true : false;
$notification->is_system = (isset($system['message']) && $system['message'] != '') ? true : false;
// if is_system ==========================================
if ($notification->is_system && $uid != 0) {
......@@ -311,15 +354,20 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
);
}
}
// if the system notification has set current user than get current user otherwise loop through the users needed.
}
/**
* @param int $grpID
*
* @return array
*/
function getGroups($grpID = 0)
{
global $userAccessManager;
$groups = [];
if ($grpID > 0) {
/** @var \UamUserGroup $userGroups */
$userGroups = $userAccessManager
->getAccessHandler()
->getUserGroups($grpID);
......@@ -330,6 +378,8 @@ function getGroups($grpID = 0)
->getAccessHandler()
->getUserGroups();
}
/** @var \UamUserGroup $group */
foreach ($userGroups as $group) {
$groups[$group->getId()] = $group->getGroupName();
}
......@@ -337,22 +387,30 @@ function getGroups($grpID = 0)
return $groups;
}
/**
* @param $var
*
* @return mixed
*/
function get_field_lookup($var)
{
return isset(Vars::$field_lookup[$var]) ? Vars::$field_lookup[$var] : $var;
}
/**
* @return string
*/
function current_url()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
if ($_SERVER['HTTPS'] == 'on') {
$pageURL .= 's';
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
$pageURL .= '://';
if ($_SERVER['SERVER_PORT'] != '80') {
$pageURL .= $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
}
return $pageURL;
......
<?php
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools\Notifications\Settings;
use Tz\WordPress\Tools;
/*
print "<pre>";
print_r($notifications);
print "</pre>";
*/
?>
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" />
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery.-1.4.2.min.js', __FILE__)?>"></script>
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery.qtip-1.0.0-rc3.js', __FILE__)?>"></script>
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/>
<script src="<?php echo Tools\url('assets/scripts/jquery.qtip-1.0.0-rc3.js', __FILE__) ?>"></script>
<div id="" class="wrap">
......@@ -34,32 +24,35 @@ print "</pre>";
</tr>
</thead>
<tbody>
<?php foreach($notifications['scheduled'] as $entry):
<?php foreach ($notifications['scheduled'] as $entry):
$sendto = $entry->sendto;
if(is_numeric($sendto)) {
$sendto = Notifications\getGroups($sendto) . " Group";
if (is_numeric($sendto)) {
$sendto = Notifications\getGroups($sendto)." Group";
} else {
$sendto = Notifications\get_field_lookup($sendto);
}
?>
<tr>
<td><?php echo $entry->post_title; ?></td>
<td><?php echo date("M j, Y @ h:i A",strtotime($entry->execute_date)); ?></td>
<td><?php echo date("M j, Y @ h:i A", strtotime($entry->execute_date)); ?></td>
<td><?php echo ucwords($sendto); ?></td>
<td><?php if ($entry->is_email): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
<td><?php if ($entry->is_system): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
<td><?php if ($entry->is_email): ?><img
src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif;?></td>
<td><?php if ($entry->is_system): ?><img
src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif;?></td>
<td>
<?php
if (strtotime($entry->execute_date) > current_time('timestamp')):?>
<a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a>
| <a href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>" onclick="return confirm('Are you sure?');">delete</a></td>
| <a
href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>"
onclick="return confirm('Are you sure?');">delete</a></td>
<?php else: ?>
<a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> | <em>In progress....</em>
<a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> |
<em>In progress....</em>
<?php endif; ?>
</tr>
<?php endforeach; ?>
......@@ -82,19 +75,23 @@ print "</pre>";
</tr>
</thead>
<tbody>
<?php foreach($notifications['triggered'] as $entry):?>
<?php foreach ($notifications['triggered'] as $entry): ?>
<tr>
<td><?php echo $entry->post_title; ?></td>
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
<td><?php echo $entry->trigger; ?></td>
<?php endif; ?>
<td><?php if ($entry->is_email): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
<td><?php if ($entry->is_system): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
<td><?php if ($entry->is_email): ?><img
src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif; ?></td>
<td><?php if ($entry->is_system): ?><img
src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif; ?></td>
<td><a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a>
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
| <a href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>" onclick="return confirm('Are you sure?');">delete</a>
| <a
href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>"
onclick="return confirm('Are you sure?');">delete</a>
<?php endif; ?>
</td>
</tr>
......
......@@ -6,7 +6,7 @@ use Tz\WordPress\Tools\Notifications\Settings;
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/>
<div id="" class="wrap">
<div class="wrap">
<h2>Notifications - Edit</h2>
<?php if (isset($flash) && $flash != ''): ?>
......