Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 108 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 2 |
| zeroBSCRM_TagManagerMetaboxSetup | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
90 | |||
| zeroBS__Metabox_TagList | |
0.00% |
0 / 79 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| html | |
0.00% |
0 / 68 |
|
0.00% |
0 / 1 |
56 | |||
| zeroBS__Metabox_TagAdd | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /* |
| 3 | * Jetpack CRM |
| 4 | * https://jetpackcrm.com |
| 5 | * V3.0 |
| 6 | * |
| 7 | * Copyright 2020 Automattic |
| 8 | * |
| 9 | * Date: 20/02/2019 |
| 10 | */ |
| 11 | |
| 12 | defined( 'ZEROBSCRM_PATH' ) || exit( 0 ); |
| 13 | |
| 14 | /* |
| 15 | ====================================================== |
| 16 | Init Func |
| 17 | ====================================================== */ |
| 18 | |
| 19 | function zeroBSCRM_TagManagerMetaboxSetup() { |
| 20 | |
| 21 | // lazy page switch |
| 22 | $typeInt = -1; |
| 23 | if ( zeroBSCRM_is_customertags_page() ) { |
| 24 | $typeInt = ZBS_TYPE_CONTACT; |
| 25 | } |
| 26 | if ( zeroBSCRM_is_companytags_page() ) { |
| 27 | $typeInt = ZBS_TYPE_COMPANY; |
| 28 | } |
| 29 | if ( zeroBSCRM_is_quotetags_page() ) { |
| 30 | $typeInt = ZBS_TYPE_QUOTE; |
| 31 | } |
| 32 | if ( zeroBSCRM_is_invoicetags_page() ) { |
| 33 | $typeInt = ZBS_TYPE_INVOICE; |
| 34 | } |
| 35 | if ( zeroBSCRM_is_transactiontags_page() ) { |
| 36 | $typeInt = ZBS_TYPE_TRANSACTION; |
| 37 | } |
| 38 | if ( zeroBSCRM_is_formtags_page() ) { |
| 39 | $typeInt = ZBS_TYPE_FORM; |
| 40 | } |
| 41 | if ( zeroBSCRM_is_tasktags_page() ) { |
| 42 | $typeInt = ZBS_TYPE_TASK; |
| 43 | } |
| 44 | |
| 45 | if ( $typeInt > 0 ) { |
| 46 | |
| 47 | // Tag List |
| 48 | $zeroBS__Metabox_TagList = new zeroBS__Metabox_TagList( __FILE__, $typeInt ); |
| 49 | |
| 50 | // Add Tags |
| 51 | $zeroBS__Metabox_TagAdd = new zeroBS__Metabox_TagAdd( __FILE__, $typeInt ); |
| 52 | |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | add_action( 'admin_init', 'zeroBSCRM_TagManagerMetaboxSetup' ); |
| 57 | |
| 58 | /* |
| 59 | ====================================================== |
| 60 | / Init Func |
| 61 | ====================================================== */ |
| 62 | |
| 63 | /* |
| 64 | ====================================================== |
| 65 | Declare Globals |
| 66 | ====================================================== */ |
| 67 | |
| 68 | #} Used throughout |
| 69 | // Don't know who added this, but GLOBALS are out of scope here |
| 70 | // global $zbsCustomerFields,$zbsCustomerQuoteFields,$zbsCustomerInvoiceFields; |
| 71 | |
| 72 | /* |
| 73 | ====================================================== |
| 74 | / Declare Globals |
| 75 | ====================================================== */ |
| 76 | |
| 77 | // PerfTest: zeroBSCRM_performanceTest_startTimer('custmetabox'); |
| 78 | |
| 79 | /* |
| 80 | ====================================================== |
| 81 | Tag List Metabox |
| 82 | ====================================================== */ |
| 83 | |
| 84 | class zeroBS__Metabox_TagList extends zeroBS__Metabox { |
| 85 | |
| 86 | /** |
| 87 | * The legacy object name (e.g. 'zerobs_customer') |
| 88 | * |
| 89 | * @var string |
| 90 | */ |
| 91 | private $postType; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase |
| 92 | |
| 93 | public function __construct( $plugin_file, $typeInt = ZBS_TYPE_CONTACT ) { |
| 94 | |
| 95 | global $zbs; |
| 96 | |
| 97 | // set these |
| 98 | $this->typeInt = $typeInt; |
| 99 | $this->postType = $zbs->DAL->typeCPT( $typeInt ); |
| 100 | $this->metaboxID = 'zerobs-' . $zbs->DAL->objTypeKey( $typeInt ) . '-tags-edit'; |
| 101 | $this->metaboxTitle = __( $zbs->DAL->typeStr( $typeInt ) . ' Tags', 'zero-bs-crm' ); |
| 102 | $this->metaboxScreen = 'zerobs_edit_tags'; // we can use anything here as is now using our func |
| 103 | $this->metaboxArea = 'normal'; |
| 104 | $this->metaboxLocation = 'high'; |
| 105 | $this->saveOrder = 1; |
| 106 | // headless! |
| 107 | $this->headless = true; |
| 108 | |
| 109 | // call this |
| 110 | $this->initMetabox(); |
| 111 | } |
| 112 | |
| 113 | public function html( $contact, $metabox ) { |
| 114 | |
| 115 | global $zbs; |
| 116 | |
| 117 | // Get all tags |
| 118 | $tags = $zbs->DAL->getTagsForObjType( |
| 119 | array( |
| 120 | |
| 121 | 'objtypeid' => $this->typeInt, |
| 122 | 'excludeEmpty' => false, |
| 123 | 'withCount' => true, |
| 124 | 'ignoreowner' => true, |
| 125 | // sort |
| 126 | 'sortByField' => 'tagcount', |
| 127 | 'sortOrder' => 'DESC', |
| 128 | |
| 129 | ) |
| 130 | ); |
| 131 | |
| 132 | // pre-inject some potential js errors :) |
| 133 | ?><div id="zbs-error-prep"> |
| 134 | <?php |
| 135 | |
| 136 | echo zeroBSCRM_UI2_messageHTML( 'info hidden', __( 'Tag Exists', 'zero-bs-crm' ), __( 'Cannot add a tag. A tag already exists with this text', 'zero-bs-crm' ), '', 'zbsTagAlreadyExists' ); |
| 137 | echo zeroBSCRM_UI2_messageHTML( 'info hidden', __( 'Tag Text Empty', 'zero-bs-crm' ), __( 'You cannot add empty tags', 'zero-bs-crm' ), '', 'zbsTagEmpty' ); |
| 138 | |
| 139 | ?> |
| 140 | </div> |
| 141 | <?php |
| 142 | |
| 143 | // long term perhaps we need a list metabox type, for now, hardcoded: |
| 144 | ?> |
| 145 | <table class="ui celled table" id="zbs-tag-manager" style="margin-top:0;"> |
| 146 | <thead> |
| 147 | <tr> |
| 148 | <th><?php esc_html_e( 'Name', 'zero-bs-crm' ); ?></th> |
| 149 | <th><?php esc_html_e( 'Slug', 'zero-bs-crm' ); ?></th> |
| 150 | <?php /* this shows 1 date as DAL2 migration...<th><?php _e('First Used',"zero-bs-crm"); ?></th> */ ?> |
| 151 | <th class="center aligned"><?php esc_html_e( 'Count', 'zero-bs-crm' ); ?></th> |
| 152 | <th class="center aligned"><?php esc_html_e( 'Action', 'zero-bs-crm' ); ?></th> |
| 153 | </tr> |
| 154 | </thead> |
| 155 | <tbody> |
| 156 | <?php |
| 157 | if ( count( $tags ) > 0 ) { |
| 158 | foreach ( $tags as $tag ) { |
| 159 | |
| 160 | $link = jpcrm_esc_link( 'listtagged', -1, $this->postType, -1, $tag['id'] ); |
| 161 | ?> |
| 162 | <tr> |
| 163 | <td> |
| 164 | <?php |
| 165 | if ( isset( $tag['name'] ) ) { |
| 166 | echo '<a href="' . esc_url( $link ) . '" class="ui large label">' . esc_html( $tag['name'] ) . '</a>'; |
| 167 | } |
| 168 | ?> |
| 169 | </td> |
| 170 | <td> |
| 171 | <?php |
| 172 | if ( isset( $tag['slug'] ) ) { |
| 173 | echo esc_html( $tag['slug'] ); |
| 174 | } |
| 175 | ?> |
| 176 | </td> |
| 177 | <?php /* this shows 1 date as DAL2 migration... <td><?php if (isset($tag['created']) && !empty($tag['created']) && $tag['created'] !== -1) echo zeroBSCRM_locale_utsToDate($tag['created']); ?></td> */ ?> |
| 178 | <td class="center aligned"> |
| 179 | <?php |
| 180 | if ( isset( $tag['count'] ) ) { |
| 181 | echo '<a href="' . esc_url( $link ) . '">' . esc_html( zeroBSCRM_prettifyLongInts( $tag['count'] ) ) . '</a>';} |
| 182 | ?> |
| 183 | </td> |
| 184 | <td class="center aligned"> |
| 185 | <button type="button" class="ui mini button black zbs-delete-tag" data-tagid="<?php echo esc_attr( $tag['id'] ); ?>"> |
| 186 | <i class="trash alternate icon"></i> |
| 187 | <?php esc_html_e( 'Delete', 'zero-bs-crm' ); ?> |
| 188 | </button> |
| 189 | </td> |
| 190 | </tr> |
| 191 | <?php |
| 192 | } |
| 193 | } |
| 194 | ?> |
| 195 | </tbody> |
| 196 | </table> |
| 197 | <?php |
| 198 | |
| 199 | if ( count( $tags ) == 0 ) { |
| 200 | echo zeroBSCRM_UI2_messageHTML( 'info', __( 'No Tags Found', 'zero-bs-crm' ), __( 'There are no Tags here, create one using the box to the right.', 'zero-bs-crm' ), 'disabled warning sign', 'zbsNoTagResults' ); |
| 201 | } |
| 202 | |
| 203 | ?> |
| 204 | <script type="text/javascript"> |
| 205 | <?php |
| 206 | #} Nonce for AJAX |
| 207 | echo "var zbscrmjs_secToken = '" . esc_js( wp_create_nonce( 'zbscrmjs-ajax-nonce' ) ) . "';"; |
| 208 | ?> |
| 209 | |
| 210 | var zbsTagListLang = { |
| 211 | |
| 212 | 'delete': '<?php zeroBSCRM_slashOut( __( 'Delete', 'zero-bs-crm' ) ); ?>', |
| 213 | |
| 214 | 'deleteswaltitle': '<?php zeroBSCRM_slashOut( __( 'Are you sure?', 'zero-bs-crm' ) ); ?>', |
| 215 | 'deleteswaltext': '<?php zeroBSCRM_slashOut( __( 'This will delete the tag and remove it from any tagged ' . __( $zbs->DAL->typeStr( $this->typeInt ), 'zero-bs-crm' ) . '. This is irreversable.', 'zero-bs-crm' ) ); ?>', |
| 216 | 'deleteswalconfirm': '<?php zeroBSCRM_slashOut( __( 'Yes, delete the tag!', 'zero-bs-crm' ) ); ?>', |
| 217 | |
| 218 | |
| 219 | 'tagdeleted':'<?php zeroBSCRM_slashOut( __( 'Tag Deleted!', 'zero-bs-crm' ) ); ?>', |
| 220 | 'tagremoved':'<?php zeroBSCRM_slashOut( __( 'Your tag has been removed.', 'zero-bs-crm' ) ); ?>', |
| 221 | 'tagnotdeleted':'<?php zeroBSCRM_slashOut( __( 'Tag Not Deleted!', 'zero-bs-crm' ) ); ?>', |
| 222 | 'tagnotremoved':'<?php zeroBSCRM_slashOut( __( 'Your tag was not removed, please try again.', 'zero-bs-crm' ) ); ?>', |
| 223 | |
| 224 | }; |
| 225 | |
| 226 | |
| 227 | </script> |
| 228 | <?php |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | ====================================================== |
| 234 | / Tag List Metabox |
| 235 | ====================================================== */ |
| 236 | |
| 237 | /* |
| 238 | ====================================================== |
| 239 | Create Tags Box |
| 240 | ====================================================== */ |
| 241 | |
| 242 | class zeroBS__Metabox_TagAdd extends zeroBS__Metabox_Tags { |
| 243 | |
| 244 | /** |
| 245 | * The legacy object name (e.g. 'zerobs_customer') |
| 246 | * |
| 247 | * @var string |
| 248 | */ |
| 249 | private $postType; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase |
| 250 | |
| 251 | public function __construct( $plugin_file, $typeInt = ZBS_TYPE_CONTACT ) { |
| 252 | |
| 253 | global $zbs; |
| 254 | |
| 255 | $this->typeInt = $typeInt; // until db2 ZBS_TYPE_CONTACT; |
| 256 | $this->postType = $zbs->DAL->typeCPT( $typeInt ); |
| 257 | $this->metaboxID = 'zerobs-' . $zbs->DAL->objTypeKey( $typeInt ) . '-tags'; |
| 258 | $this->metaboxTitle = __( 'Add ' . $zbs->DAL->typeStr( $typeInt ) . ' Tags', 'zero-bs-crm' ); |
| 259 | $this->metaboxScreen = 'zerobs_edit_tags'; // we can use anything here as is now using our func |
| 260 | $this->metaboxArea = 'side'; |
| 261 | $this->metaboxLocation = 'high'; |
| 262 | |
| 263 | // call this |
| 264 | $this->initMetabox(); |
| 265 | } |
| 266 | |
| 267 | // html + save dealt with by parent class :) |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | ====================================================== |
| 272 | / Create Tags Box |
| 273 | ====================================================== */ |