| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Awesome Support/Admin/Functions/Toolbar |
| 4 |
* @author AwesomeSupport <contact@getawesomesupport.com> |
| 5 |
* @license GPL-2.0+ |
| 6 |
* @link https://getawesomesupport.com |
| 7 |
* @copyright 2015-2017 AwesomeSupport |
| 8 |
*/ |
| 9 |
|
| 10 |
// If this file is called directly, abort. |
| 11 |
if ( ! defined( 'WPINC' ) ) { |
| 12 |
die; |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
/** |
| 17 |
* Generate toolbar item markup |
| 18 |
* |
| 19 |
* @param array $args |
| 20 |
* |
| 21 |
* @return string |
| 22 |
*/ |
| 23 |
function wpas_toolbar_item( $args ) { |
| 24 |
|
| 25 |
$defaults = array( |
| 26 |
'id_param' => 'id', |
| 27 |
'id_css' => '', |
| 28 |
'type' => 'button', |
| 29 |
'link' => '#', |
| 30 |
'icon' => '', |
| 31 |
'tool_tip_text' => '', |
| 32 |
'attributes' => '', |
| 33 |
'data' => array(), |
| 34 |
'classes' => '' |
| 35 |
); |
| 36 |
|
| 37 |
$args = wp_parse_args( $args, $defaults ); |
| 38 |
|
| 39 |
|
| 40 |
$id = $args['id']; |
| 41 |
$type = $args['type']; |
| 42 |
$link = $args['link']; |
| 43 |
$icon = $args['icon']; |
| 44 |
$classes = $args['classes']; |
| 45 |
|
| 46 |
$tool_tip_text = $args['tool_tip_text']; |
| 47 |
|
| 48 |
$attributes = $args['attributes']; |
| 49 |
|
| 50 |
if( 'id' === $args['id_param'] ) { |
| 51 |
$attributes = " id=\"{$id}\""; |
| 52 |
} else { |
| 53 |
$classes .= " wpas_toolbar_item_{$id}"; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
$data_params = is_array( $args['data'] ) ? $args['data'] : array(); |
| 58 |
|
| 59 |
foreach( $data_params as $dp_name => $dp_value ) { |
| 60 |
$attributes .= " data-{$dp_name}=\"{$dp_value}\""; |
| 61 |
} |
| 62 |
|
| 63 |
$item = ""; |
| 64 |
|
| 65 |
$wrapper_classes = "hint-bottom hint-anim wpas_toolbar_item"; |
| 66 |
|
| 67 |
if( 'link' === $type ) { |
| 68 |
|
| 69 |
$item = sprintf( '<li data-hint="%s" class="%s"><a href="%s" class="%s" %s><span class="%s"></span></a></li>', $tool_tip_text, $wrapper_classes, $link, $classes, $attributes, "wpas-icon {$icon}" ); |
| 70 |
} else { |
| 71 |
$item = sprintf( '<li data-hint="%s" class="%s"><span class="%s" %s></span></li>', $tool_tip_text, $wrapper_classes, "wpas-icon {$icon} {$classes}", $attributes ); |
| 72 |
} |
| 73 |
|
| 74 |
return $item; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
/** |
| 79 |
* Generate toolbar markup |
| 80 |
* |
| 81 |
* @param string $type unique toolbar name |
| 82 |
* @param array $fun_args |
| 83 |
* |
| 84 |
* @return string |
| 85 |
*/ |
| 86 |
function wpas_toolbar( $type, $fun_args = array() ) { |
| 87 |
|
| 88 |
$id = "wpas_toolbar_{$type}"; |
| 89 |
|
| 90 |
$args = array(); |
| 91 |
|
| 92 |
$args[0] = $id; |
| 93 |
$args[1] = array(); |
| 94 |
|
| 95 |
foreach( $fun_args as $arg ) { |
| 96 |
$args[] = $arg; |
| 97 |
} |
| 98 |
|
| 99 |
$toolbar_items = call_user_func_array( 'apply_filters', $args ); |
| 100 |
|
| 101 |
|
| 102 |
// Stop processing if no toolbar item exist |
| 103 |
if( empty( $toolbar_items ) ) { |
| 104 |
return; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
$items = array(); |
| 109 |
|
| 110 |
foreach ( $toolbar_items as $item_id => $item ) { |
| 111 |
|
| 112 |
$item['id'] = $item_id; |
| 113 |
|
| 114 |
$items[] = wpas_toolbar_item( $item ); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
$items[] = '<li class="clear clearfix"></li>'; |
| 119 |
return '<ul class="wpas-toolbar" id="wpas-toolbar-'.$type.'">' . implode( "\n\r", $items ) . '</ul>'; |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
add_filter( 'wpas_toolbar_ticket', 'wpas_toolbar_ticket_items', 11, 2 ); |
| 125 |
|
| 126 |
|
| 127 |
/** |
| 128 |
* Add items to main ticket toolbar |
| 129 |
* |
| 130 |
* @param array $items |
| 131 |
* @param int $ticket_id |
| 132 |
* |
| 133 |
* @return array |
| 134 |
*/ |
| 135 |
function wpas_toolbar_ticket_items( $items, $ticket_id ) { |
| 136 |
|
| 137 |
$items['wpas-collapse-replies-top'] = array( |
| 138 |
'icon' => 'icon-hide-ticket-replies', |
| 139 |
'tool_tip_text' => __( 'Toggle Replies (Hide All Replies Except The Last 3)', 'awesome-support' ) |
| 140 |
); |
| 141 |
|
| 142 |
|
| 143 |
$items['wpas-toggle-ticket-slug'] = array( |
| 144 |
'icon' => 'icon-hide-ticket-urls', |
| 145 |
'tool_tip_text' => __( 'Show/Hide The Ticket Slug', 'awesome-support' ) |
| 146 |
); |
| 147 |
|
| 148 |
$items['wpas-edit-main-ticket-message'] = array( |
| 149 |
'icon' => 'icon-edit-ticket-replies', |
| 150 |
'tool_tip_text' => __( 'Edit Ticket', 'awesome-support' ), |
| 151 |
'data' => array( |
| 152 |
'ticketid' => $ticket_id |
| 153 |
) |
| 154 |
); |
| 155 |
|
| 156 |
|
| 157 |
$items['wpas-view-edit-main-ticket-message'] = array( |
| 158 |
'icon' => 'icon-due-date', |
| 159 |
'tool_tip_text' => __( 'View History', 'awesome-support' ), |
| 160 |
'data' => array( |
| 161 |
'ticketid' => $ticket_id |
| 162 |
) |
| 163 |
); |
| 164 |
|
| 165 |
|
| 166 |
return $items; |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
/** |
| 172 |
* Print main ticket toolbar |
| 173 |
*/ |
| 174 |
function wpas_ticket_toolbar() { |
| 175 |
|
| 176 |
$tabs_content = wpas_toolbar( 'ticket', func_get_args() ); |
| 177 |
echo wp_kses( is_string($tabs_content) ? $tabs_content : '', get_allowed_html_wp_notifications() ); |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Print toolbar with each reply |
| 183 |
*/ |
| 184 |
function wpas_ticket_reply_toolbar() { |
| 185 |
|
| 186 |
$tabs_content = wpas_toolbar( 'ticket_reply', func_get_args() ); |
| 187 |
echo wp_kses( is_string($tabs_content) ? $tabs_content : '', get_allowed_html_wp_notifications() ); |
| 188 |
|
| 189 |
} |