generatedLabelsController = new GeneratedLabelsController();
$this->generalController = new GeneralController();
$this->settingsController = new SettingsController();
$this->dimensions = new Dimensions();
$this->templates = new Templates();
$this->profilesModel = new Profiles();
$this->ajaxRoutes = new AjaxRoutes();
add_action('admin_menu', array($this, 'addMenuPages'), 9);
add_action('admin_enqueue_scripts', array($this, 'adminAllEnqueueScripts'), 9);
add_filter('plugin_row_meta', array($this, 'pluginRowMeta'), 10, 2);
add_action('admin_footer', array($this, 'adminFooter'));
add_action('wp_ajax_' . self::ajax_action('barcodeLabelsConfigs'), array($this, 'handleConfigs'));
$woocommerceModel = new WooCommerceController();
add_action('wp_ajax_' . self::ajax_action(WoocommerceProducts::ACTION_IMPORT), array($woocommerceModel, 'getBarcodes'));
add_action('wp_ajax_' . self::ajax_action(WoocommerceOrders::ACTION_IMPORT), array($woocommerceModel, 'getBarcodesByOrders'));
add_action('wp_ajax_' . self::ajax_action(WoocommerceOrderProducts::ACTION_IMPORT), array($woocommerceModel, 'getBarcodesByOrderProducts'));
add_action('wp_ajax_' . self::ajax_action(WoocommerceOrderItems::ACTION_IMPORT), array($woocommerceModel, 'getBarcodesByOrderItems'));
add_action('wp_ajax_' . self::ajax_action('delete_label'), array($this->generatedLabelsController, 'delete'));
add_action('wp_ajax_' . self::ajax_action('copy_label'), array($this->generatedLabelsController, 'copy'));
add_action('wp_ajax_' . self::ajax_action('sort_labels'), array($this->generatedLabelsController, 'sort'));
add_action('wp_ajax_' . self::ajax_action('recreate_labels'), function(){ uslp_a4bJsonResponse($this->generatedLabelsController->recreate()); });
$postDataController = new PostsDataController();
add_action('wp_ajax_' . self::ajax_action('check_bulk_list'), array($postDataController, 'getIdsBulkList'));
add_action('wp_ajax_' . self::ajax_action('get_product_variations'), array($postDataController, 'getProductVariations'));
add_action('wp_ajax_' . self::ajax_action('integration_button_info'), array($this->generalController, 'integrationButtonInfo'));
add_action('wp_ajax_' . self::ajax_action('barcodeLabelAction'), array($this->ajaxRoutes, "handleRequest"));
add_action('wp_ajax_' . 'barcodeLabelInitAction', array($this->ajaxRoutes, "handleRequest"));
$profilesMetaTable = new ProfilesMetaTable();
add_action('init', array($profilesMetaTable, "register"), 0);
add_action('switch_blog', array($profilesMetaTable, "register"), 0);
add_action('init', array($this->profilesModel, 'copyDefaultProfilesToCurrentUser'));
$barcodeFieldForWcProducts = new BarcodeField();
add_action('init', array($barcodeFieldForWcProducts, 'customFields'));
new PostFilters();
IntegrationButtons::init();
}
public static function ajax_action($action)
{
return self::AJAX_ACTION_PREFIX . $action;
}
public function adminFooter()
{
$actionType = 'products';
$wpAction = esc_attr(Core::ajax_action(WoocommerceProducts::ACTION_IMPORT));
$integration = esc_attr(implode(', ', array(ProductsShortcode::fullIntegrationSlug())));
$buttonSlug = esc_attr(ProductsPageImportProductsBtn::SLUG);
$availableProfiles = esc_attr(implode(',', (new ProfilesPermissions())->getAvailableProfilesIds(ProductsPageImportProductsBtn::SLUG)));
?>
settingsController, 'settingsPage')
);
add_submenu_page(
"",
__('Settings', 'a4-barcode-generator'),
__('Settings', 'a4-barcode-generator'),
'manage_options',
'uslp-label-printing-settings-update',
array($this->settingsController, 'formSubmitted')
);
add_submenu_page(
"",
__('Settings', 'a4-barcode-generator'),
__('Settings', 'a4-barcode-generator'),
'manage_options',
'uslp-label-printing-wizard-reset',
array($this->settingsController, 'wizardReset')
);
add_submenu_page(
'uslp-label-printing-preview',
__('Ask on the Forum', 'a4-barcode-generator'),
__('Ask on the Forum', 'a4-barcode-generator'),
'manage_woocommerce',
'uslp-label-printing-ask-on-the-forum',
array($this, 'emptyPage')
);
add_submenu_page(
'uslp-label-printing-preview',
__('Support', 'a4-barcode-generator'),
'' . __('Support', 'a4-barcode-generator') . '',
'read',
'uslp-barcode-generator-support',
array($this, 'emptyPage')
);
add_submenu_page(
'uslp-label-printing-preview',
__('FAQ', 'a4-barcode-generator'),
'' . __('FAQ', 'a4-barcode-generator') . '',
'read',
'uslp-barcode-generator-faq',
array($this, 'emptyPage')
);
add_submenu_page(
"",
__('Barcode-Generator Page', 'a4-barcode-generator'),
__('Barcode-Generator Page', 'a4-barcode-generator'),
'read',
'uslp-barcode-generator-print',
array($this, 'emptyPage')
);
}
public function pluginRowMeta($links, $file)
{
if (Variables::$A4B_PLUGIN_BASE_NAME == $file) {
}
return (array) $links;
}
public function adminAllEnqueueScripts()
{
global $wp_version;
if (!is_admin()) {
return;
}
wp_register_style('us_barcode_label_printing_4', Variables::$A4B_PLUGIN_BASE_URL . 'src/templates/actions-assets/style.css', false, '4.0.3');
wp_enqueue_style('us_barcode_label_printing_4');
wp_enqueue_script('us_barcode_label_printing_4__assets', Variables::$A4B_PLUGIN_BASE_URL . 'src/templates/actions-assets/script.js');
$path = str_replace('src/Classes/', '', USLP_PLUGIN_BASE_URL);
wp_enqueue_script("us_barcode_label_printing4_loader_print", $path."assets/js/index-4.0.3-1793007717960.js", array("jquery"), 1793007717960, true);
$appJsPath = $path."assets/js/bundle-4.0.3-1793007717960.js";
$vendorJsPath = $path."assets/js/chunk-4.0.3-1793007717960.js";
wp_enqueue_style('us_barcode_label_printing4_style', Variables::$A4B_PLUGIN_BASE_URL . 'assets/css/style.css', array());
wp_enqueue_script("us_barcode_label_printing4_libs_api", Variables::$A4B_PLUGIN_BASE_URL."assets/js/api-4.0.3-1793007717960.js", null, null, true);
$barcodeLoaderScriptSlug = 'us_barcode_label_printing4_loader_print';
$uslpjs = array(
'appJsPath' => $appJsPath,
'vendorJsPath' => $vendorJsPath,
'ajaxUrl' => get_admin_url() . 'admin-ajax.php',
'nonce' => wp_create_nonce('wp_rest'),
'wp_version' => $wp_version,
'wc_version' => defined("WC_VERSION") ? WC_VERSION : 0,
);
wp_localize_script($barcodeLoaderScriptSlug, "uslpjs", $uslpjs);
if (isset($_GET['page']) && $_GET['page'] == 'uslp-label-printing-settings') {
$generalSettings = UserSettings::getGeneral();
wp_localize_script($barcodeLoaderScriptSlug, 'uslpjsGS', $generalSettings);
}
}
public function handleConfigs() {
global $wp_version;
Request::checkNonce();
if (!current_user_can('read')) {
wp_die();
}
$activeDimension = $this->dimensions->getActive();
$allPaperFormats = array();
$barcodeSizes = array();
$importCodes = array();
$papersController = new PapersController();
$allPaperFormats = $papersController->getAll();
$shortcodesOrder = $shortcodesProduct = $shortcodesCustom = array();
$config = require Variables::$A4B_PLUGIN_BASE_PATH . 'src/config/config.php';
$uslpjs = array(
'pluginUrl' => Variables::$A4B_PLUGIN_BASE_URL,
'pluginType' => Variables::$A4B_PLUGIN_TYPE,
'websiteUrl' => get_bloginfo("url"),
'adminUrl' => get_admin_url(),
'pluginVersion' => '4.0.3',
'isWoocommerceActive' => is_plugin_active('woocommerce/woocommerce.php'),
'isCF7Active' => is_plugin_active('contact-form-7/wp-contact-form-7.php'),
'isTieredPriceActive' => (is_plugin_active('tier-pricing-table/tier-pricing-table.php') || is_plugin_active('tier-pricing-table-premium/tier-pricing-table.php')),
'isAtumPoActive' => is_plugin_active('atum-stock-manager-for-woocommerce/atum-stock-manager-for-woocommerce.php'),
'isWcShippingLocalPickupPlusActive' => is_plugin_active('woocommerce-shipping-local-pickup-plus/woocommerce-shipping-local-pickup-plus.php'),
'wt_seq_ordnum' => is_plugin_active('wt-woocommerce-sequential-order-numbers/wt-advanced-order-number.php'),
'autologin_links' => is_plugin_active('autologin-links/autologin-links.php'),
'allPaperFormats' => $allPaperFormats,
'allTemplates' => $this->templates->getAll(),
'shortcodesOrder' => $shortcodesOrder,
'shortcodesProduct' => $shortcodesProduct,
'shortcodesCustom' => $shortcodesCustom,
'rest_root' => esc_url_raw(rest_url()),
'nonce' => wp_create_nonce('wp_rest'),
'activeDimension' => $activeDimension,
'dimensions' => $this->dimensions->get(),
'barcodeTypes' => $config['listAlgorithm'],
'barcodeSizes' => $barcodeSizes,
'uid' => get_current_user_id(),
'wp_version' => $wp_version,
'wc_version' => defined("WC_VERSION") ? WC_VERSION : 0,
'currentPage' => Variables::getCurrentPage(),
'ajaxUrl' => get_admin_url() . 'admin-ajax.php',
'isFront' => 0,
'plugins' => $this->checkExternalPlugins(),
'isCustomSortEnabled' => function_exists('barcodes_products_sort_items_hook'),
'tab' => isset($_GET["tab"]) ? sanitize_text_field($_GET["tab"]) : "",
'bulkListRaw' => get_user_meta(get_current_user_id(), 'uslp_bulk_list_raw', true),
);
$this->shortcodesData = new ShortcodesData();
$shortcodesData = $this->getAllShortcodes();
$response = array(
"uslpjs" => $uslpjs,
"uslpjsATTR" => (new Search())->getAttributes(),
"uslpjsGS" => UserSettings::getGeneral(),
"uslpjsL10n" => array_merge(
require Variables::$A4B_PLUGIN_BASE_PATH . 'src/config/jsL10n.php',
$this->shortcodesData->getDoc($shortcodesData)
),
"uslpjsUS" => UserSettings::get(),
"uslpLabels" => (new GeneratedLabelsData())->get(get_current_user_id()),
'uslpShortcodes' => $shortcodesData,
);
wp_send_json($response);
wp_die();
}
public function emptyPage()
{
}
public function getAllShortcodes()
{
$result = array(
'integrations' => array(),
);
$shortCodes = $this->shortcodesData->getShortcodesInfoArray();
foreach ($shortCodes as $shortCode) {
if (!isset($result['integrations'][$shortCode['integration']])) {
$result['integrations'][$shortCode['integration']] = array(
'name' => $shortCode['integration_name'],
'integration_types' => array(),
);
}
if (!isset($result['integrations'][$shortCode['integration']]['integration_types'][$shortCode['integration_type']])) {
$result['integrations'][$shortCode['integration']]['integration_types'][$shortCode['integration_type']] = array(
'name' => $shortCode['integration_type_name'],
'slug' => $shortCode['integration_type'],
'shortcodes' => array(),
);
}
if (!empty($shortCode['show_in_matching'])) {
$result['integrations'] [$shortCode['integration']] ['integration_types'] [$shortCode['integration_type']] ['shortcodes'] [] = array(
'label' => $shortCode['label'],
'shortcode' => $shortCode['shortcode'],
'show_in_matching' => $shortCode['show_in_matching'],
'show_in_doc' => $shortCode['show_in_doc'],
'have_variants' => $shortCode['have_variants'],
'variants' => $shortCode['variants'],
'order' => $shortCode['order'],
);
}
}
foreach ($result['integrations'] as &$integration) {
foreach ($integration['integration_types'] as &$integration_type) {
usort($integration_type['shortcodes'], function ($a, $b) {
if ($a['order'] < $b['order']) {
return -1;
} elseif ($a['order'] > $b['order']) {
return 1;
}
return 0;
});
}
}
return $result;
}
private function checkExternalPlugins()
{
$alg_wc_ean_title = get_option('alg_wc_ean_title', __('EAN', 'a4-barcode-generator'));
$wpm_pgw_label = get_option('wpm_pgw_label', __('EAN', 'a4-barcode-generator'));
$wpm_pgw_label = $wpm_pgw_label . __(' Code:', 'a4-barcode-generator');
$hwp_gtin_text = get_option('hwp_gtin_text');
$hwp_gtin_text = (!empty($hwp_gtin_text) ? $hwp_gtin_text : 'GTIN');
$plugins = array(
"wc_appointments" => array('status' => is_plugin_active('woocommerce-appointments/woocommerce-appointments.php'), 'label' => 'WooCommerce Appointments'),
"openpos" => array('status' => is_plugin_active('woocommerce-openpos/woocommerce-openpos.php'), 'label' => 'Product Id'),
"atum" => array('status' => is_plugin_active('atum-stock-manager-for-woocommerce/atum-stock-manager-for-woocommerce.php'), 'label' => ''),
"license_manager" => array('status' => is_plugin_active('license-manager-for-woocommerce/license-manager-for-woocommerce.php'), 'label' => ''),
array('key' => '_alg_ean', 'status' => function_exists('alg_wc_ean'), 'label' => 'EAN for WooCommerce', 'fieldLabel' => $alg_wc_ean_title . ' (EAN for WooCommerce)'),
array('key' => '_wpm_gtin_code', 'status' => function_exists('wpm_product_gtin_wc'), 'label' => 'Product GTIN (EAN, UPC, ISBN) for WooCommerce', 'fieldLabel' => $wpm_pgw_label . ' (Product GTIN (EAN, UPC, ISBN))'),
array('key' => 'hwp_product_gtin', 'status' => class_exists('Woo_GTIN'), 'label' => 'WooCommerce UPC, EAN, and ISBN', 'fieldLabel' => $hwp_gtin_text . ' (WooCommerce UPC, EAN, and ISBN)'),
array('key' => '_wepos_barcode', 'status' => is_plugin_active('wepos/wepos.php'), 'label' => 'WePOS', 'fieldLabel' => 'Barcode (WePOS)'),
array('key' => '_ts_gtin', 'status' => is_plugin_active('woocommerce-germanized/woocommerce-germanized.php'), 'label' => 'GTIN - Germanized for WooCommerce', 'fieldLabel' => 'GTIN (Germanized for WooCommerce)'),
array('key' => '_ts_mpn', 'status' => is_plugin_active('woocommerce-germanized/woocommerce-germanized.php'), 'label' => 'MPN - Germanized for WooCommerce', 'fieldLabel' => 'MPN (Germanized for WooCommerce)'),
);
foreach ($plugins as &$plugin) {
if (isset($plugin["fieldLabel"])) {
$plugin["fieldLabel"] = str_replace('', '', $plugin["fieldLabel"]);
}
}
return $plugins;
}
}