0) {
foreach ($post_items[$material_id] as $item_id) {
$item_materials_array = explode(',', $item['materials']);
if (!in_array($item['id'], $post_items[$material_id])) {
foreach ($item_materials_array as $item_key=>$item_value) {
if ((int)$item_value == (int)$material_id) {
unset($item_materials_array[$item_key]);
}
}
}
else {
$item_materials_array = explode(',', $item['materials']);
if (!in_array($material_id, $item_materials_array)) {
$item_materials_array[]=$material_id;
}
}
}
}
else {
$item_materials_array = explode(',', $item['materials']);
foreach ($item_materials_array as $item_key=>$item_value) {
if ((int)$item_value == (int)$material_id) {
unset($item_materials_array[$item_key]);
}
}
}
$item['materials']=implode(',', array_filter(array_unique($item_materials_array)));
p3dlite_update_option( 'p3dlite_'.$option_name, $item );
}
}
add_action( 'admin_menu', 'register_3dprintlite_menu_page' );
function register_3dprintlite_menu_page() {
//add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null )
add_menu_page( 'Settings', '3DPrint Lite', 'manage_options', '3dprint-lite', 'register_3dprintlite_settings_page_callback' );
add_submenu_page( '3dprint-lite', 'Settings', 'Settings', 'manage_options', 'p3dlite_settings', 'register_3dprintlite_settings_page_callback' );
add_submenu_page( '3dprint-lite', 'Materials', 'Materials', 'manage_options', 'p3dlite_materials', 'register_3dprintlite_materials_page_callback' );
add_submenu_page( '3dprint-lite', 'Printers', 'Printers', 'manage_options', 'p3dlite_printers', 'register_3dprintlite_printers_page_callback' );
add_submenu_page( '3dprint-lite', 'Coatings', 'Coatings', 'manage_options', 'p3dlite_coatings', 'register_3dprintlite_coatings_page_callback' );
add_submenu_page( '3dprint-lite', 'Infills', 'Infills', 'manage_options', 'p3dlite_infills', 'register_3dprintlite_infills_page_callback' );
add_submenu_page( '3dprint-lite', 'Post-Processings', 'Post-Processings', 'manage_options', 'p3dlite_postprocessings', 'register_3dprintlite_postprocessings_page_callback' );
add_submenu_page( '3dprint-lite', 'Price Requests', 'Price Requests', 'manage_options', 'p3dlite_price_requests', 'register_3dprintlite_price_requests_page_callback' );
add_submenu_page( '3dprint-lite', 'Email Templates', 'Email Templates', 'manage_options', 'p3dlite_email_templates', 'register_3dprintlite_email_templates_page_callback' );
add_submenu_page( '3dprint-lite', 'File Manager', 'File Manager', 'manage_options', 'p3dlite_file_manager', 'register_3dprintlite_file_manager_page_callback' );
# add_submenu_page( '3dprint-lite', 'Discounts', 'Discounts', 'manage_options', 'p3dlite_discounts', 'register_3dprintlite_discounts_page_callback' );
}
function register_3dprintlite_settings_page_callback() {
global $wpdb;
if ( $_GET['page'] != '3dprint-lite' && $_GET['page'] != 'p3dlite_settings') return false;
if ( !current_user_can('administrator') ) return false;
$settings=p3dlite_get_option( 'p3dlite_settings' );
if ( isset( $_POST['action'] ) && $_POST['action']=='save_login' ) {
$settings['api_login']=sanitize_text_field($_POST['api_login']);
update_option( 'p3dlite_settings', $settings );
}
if ( isset( $_POST['p3dlite_settings'] ) && !empty( $_POST['p3dlite_settings'] ) ) {
if ( ! isset( $_POST['p3d_settings_update'] ) || ! wp_verify_nonce( $_POST['p3d_settings_update'], 'update' ) ) {
print 'Sorry, your nonce did not verify.';
exit;
}
$settings_update = array_map('sanitize_text_field', $_POST['p3dlite_settings']);
if (isset($_FILES['p3dlite_settings']['tmp_name']['ajax_loader']) && strlen($_FILES['p3dlite_settings']['tmp_name']['ajax_loader'])>0) {
$uploaded_file = p3dlite_upload_file('p3dlite_settings', 'ajax_loader');
$settings_update['ajax_loader']=str_replace('http:','',$uploaded_file['url']);
}
else {
$settings_update['ajax_loader']=$settings['ajax_loader'];
}
/*
if (isset($_FILES['woo3dv_settings']['tmp_name']['view3d_button_image']) && strlen($_FILES['woo3dv_settings']['tmp_name']['view3d_button_image'])>0) {
$uploaded_file = woo3dv_upload_file('woo3dv_settings', 'view3d_button_image');
$settings_update['view3d_button_image']=str_replace('http:','',$uploaded_file['url']);
}
else {
$settings_update['view3d_button_image']=$settings['view3d_button_image'];
}
*/
if (!is_numeric($settings_update['num_decimals'])) $settings_update['num_decimals'] = 2;
if (empty($settings_update['canvas_width'])) $settings_update['canvas_width'] = 1024;
if (empty($settings_update['canvas_height'])) $settings_update['canvas_height'] = 768;
if (empty($settings_update['file_max_size'])) $settings_update['file_max_size'] = 20;
if (empty($settings_update['file_chunk_size'])) $settings_update['file_chunk_size'] = 2;
if (empty($settings_update['items_per_page'])) $settings_update['items_per_page'] = 10;
update_option( 'p3dlite_settings', $settings_update );
}
$settings=p3dlite_get_option( 'p3dlite_settings' );
#var_dump( $settings['ninjaforms_shortcode']);
# $shortcode_atts = shortcode_parse_atts( $settings['ninjaforms_shortcode'] );
# if (isset($shortcode_atts['id']))
# $form_id = (int)$shortcode_atts['id'];
# else
# $form_id = 0;
#p3dlite_clean_uploads();
add_thickbox();
#p3dlite_check_install();
$p3dlite_cache=p3dlite_get_option('p3dlite_cache');
$p3dlite_triangulation_cache=p3dlite_get_option('p3dlite_triangulation_cache');
?>
get_results( "select * from {$wpdb->prefix}p3dlite_printers where status=1", ARRAY_A );
if ($wpdb->num_rows==0) { //should not happen, but let's create a default one, at least one printer is required
$printer_default_data=array( 'name'=>'At least one active printer is required for the plugin to work', 'status'=>1, 'width'=>300, 'length'=>400, 'height'=>300 );
$wpdb->insert( $wpdb->prefix . 'p3dlite_printers', $printer_default_data );
}
if (isset($_POST['p3dlite_printers_description'])) {
update_option('p3dlite_printers_description', wp_kses_post(nl2br(wp_unslash($_POST['p3dlite_printers_description']))));
}
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
$printer_id = (int)$_GET['printer'];
$printer_result = $wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_printers where id='$printer_id'", ARRAY_A );
if (count($printer_result)==0) {
wp_redirect( admin_url( 'admin.php?page=p3dlite_printers' ) );
}
$printer = $printer_result[0];
$materials=p3dlite_get_option( 'p3dlite_materials' );
$infills=p3dlite_get_option( 'p3dlite_infills' );
add_thickbox();
// if (count($_POST)) {
// $printers=p3dlite_get_option( 'p3dlite_printers' );
// foreach ($printers as $key => $printer) {
// wp_set_object_terms( 0, strval($key), 'pa_p3dlite_printer' , false );
// }
// }
include('3dprint-lite-admin-printers-edit.php');
}
elseif (isset($_GET['action']) && $_GET['action'] == 'clone') {
if (!wp_verify_nonce(sanitize_key( $_REQUEST['_wpnonce'] ), 'sp_clone_printer')) {
wp_die('nonce does not match, try to refresh the page');
}
$printer_id = (int)$_GET['printer'];
$printer_result = $wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_printers where id='$printer_id'", ARRAY_A );
if (count($printer_result)==0) {
wp_redirect( admin_url( 'admin.php?page=p3dlite_printers' ) );
}
$clone_data = $printer_result[0];
unset($clone_data['id']);
$wpdb->insert($wpdb->prefix."p3dlite_printers", $clone_data);
wp_redirect( admin_url( 'admin.php?page=p3dlite_printers&action=edit&printer='.(int)$wpdb->insert_id ) );
}
elseif (isset($_GET['action']) && $_GET['action'] == 'add') {
if (!wp_verify_nonce(sanitize_key( $_REQUEST['_wpnonce'] ), 'sp_add_printer')) {
wp_die('nonce does not match, try to refresh the page');
}
$default_printer_data = array(
'status' => '1',
'name' => 'New Printer',
'description' => '',
'photo' => '',
'type' => 'fff',
'full_color' => '1',
'platform_shape' => 'rectangle',
'width' => '300',
'length' => '400',
'height' => '300',
'diameter' => '300',
'min_side' => '1',
'price' => '0',
'price_type' => 'box_volume',
'infills' => '0,10,20,30,40,50,60,70,80,90,100',
'default_infill' => '20',
'materials' => "",
'group_name' => '',
'sort_order' => '0'
);
$wpdb->insert($wpdb->prefix."p3dlite_printers", $default_printer_data);
wp_redirect( admin_url( 'admin.php?page=p3dlite_printers&action=edit&printer='.(int)$wpdb->insert_id ) );
}
else {
include('3dprint-lite-admin-printers.php');
$p3dlitep_instance = p3dliteP_Plugin::get_instance();
$p3dlitep_instance->plugin_settings_page();
}
}
function register_3dprintlite_materials_page_callback() {
global $wpdb;
if ( $_GET['page'] != 'p3dlite_materials') return false;
if ( !current_user_can('administrator') ) return false;
$settings=p3dlite_get_option( 'p3dlite_settings' );
if (isset($_POST['p3dlite_materials_description'])) {
if ( ! isset( $_POST['p3dlite_materials_edit'] ) || ! wp_verify_nonce( sanitize_key(wp_unslash($_POST['p3dlite_materials_edit'])), 'update-options' ) ) {
print 'Sorry, your nonce did not verify. Try to refresh the page.';
exit;
}
update_option('p3dlite_materials_description', wp_kses_post(nl2br(wp_unslash($_POST['p3dlite_materials_description']))));
}
$wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_materials where status=1", ARRAY_A );
if ($wpdb->num_rows==0) { //should not happen, but let's create a default one, at least one material is required
$default_material_data=array(
'status' => '1',
'name' => 'At least one active material is required for the plugin to work',
'description' => '',
'photo' => '',
'type' => 'filament',
'density' => '1.26',
'length' => '330',
'diameter' => '1.75',
'weight' => '1',
'price' => '0.03',
'price_type' => 'gram',
'roll_price' => '20',
'group_name' => 'PLA',
'color' => '#08c101',
'shininess' => 'plastic',
'glow' => '0',
'transparency' => 'opaque'
);
$wpdb->insert( $wpdb->prefix . 'p3dlite_materials', $default_material_data );
}
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
$material_id = (int)$_GET['material'];
$material_result = $wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_materials where id='$material_id'", ARRAY_A );
if (count($material_result)==0) {
wp_redirect( admin_url( 'admin.php?page=p3dlite_materials' ) );
}
$material = $material_result[0];
add_thickbox();
// if (count($_POST)) {
// $materials=p3dlite_get_option( 'p3dlite_materials' );
// foreach ($materials as $key => $material) {
// wp_set_object_terms( 0, strval($key), 'pa_p3dlite_material' , false );
// }
// }
include('3dprint-lite-admin-materials-edit.php');
}
elseif (isset($_GET['action']) && $_GET['action'] == 'clone') {
if (!wp_verify_nonce(sanitize_key( $_REQUEST['_wpnonce'] ), 'sp_clone_material')) {
wp_die('nonce does not match, try to refresh the page');
}
$material_id = (int)$_GET['material'];
$material_result = $wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_materials where id='$material_id'", ARRAY_A );
if (count($material_result)==0) {
wp_redirect( admin_url( 'admin.php?page=p3dlite_materials' ) );
}
$clone_data = $material_result[0];
unset($clone_data['id']);
$wpdb->insert($wpdb->prefix."p3dlite_materials", $clone_data);
$insert_id = $wpdb->insert_id;
$db_printers=p3dlite_get_option( 'p3dlite_printers' );
$db_coatings=p3dlite_get_option( 'p3dlite_coatings' );
foreach ($db_printers as $db_printer) {
$db_printer_materials = explode(',', $db_printer['materials']);
if (in_array($material_id, $db_printer_materials)) {
$db_printer_materials[]=$insert_id;
$db_printer['materials']=implode(',', $db_printer_materials);
p3dlite_update_option( 'p3dlite_printers', $db_printer );
}
}
foreach ($db_coatings as $db_coating) {
$db_coating_materials = explode(',', $db_coating['materials']);
if (in_array($material_id, $db_coating_materials)) {
$db_coating_materials[]=$insert_id;
$db_coating['materials']=implode(',', $db_coating_materials);
p3dlite_update_option( 'p3dlite_coatings', $db_coating );
}
}
wp_redirect( admin_url( 'admin.php?page=p3dlite_materials&action=edit&material='.(int)$insert_id ) );
}
elseif (isset($_GET['action']) && $_GET['action'] == 'add') {
if (!wp_verify_nonce(sanitize_key( $_REQUEST['_wpnonce'] ), 'sp_add_material')) {
wp_die('nonce does not match, try to refresh the page');
}
$default_material_data = array(
'status' => '1',
'name' => 'New Material',
'description' => '',
'photo' => '',
'type' => 'filament',
'density' => '1.26',
'length' => '330',
'diameter' => '1.75',
'weight' => '1',
'price' => '0.03',
'price_type' => 'gram',
'roll_price' => '20',
'group_name' => 'PLA',
'color' => '#08c101',
'shininess' => 'plastic',
'glow' => '0',
'transparency' => 'opaque'
);
$wpdb->insert($wpdb->prefix."p3dlite_materials", $default_material_data);
wp_redirect( admin_url( 'admin.php?page=p3dlite_materials&action=edit&material='.(int)$wpdb->insert_id ) );
}
else {
include('3dprint-lite-admin-materials.php');
$p3dlitem_instance = p3dliteM_Plugin::get_instance();
$p3dlitem_instance->plugin_settings_page();
}
}
function register_3dprintlite_coatings_page_callback() {
global $wpdb;
if ( $_GET['page'] != 'p3dlite_coatings') return false;
if ( !current_user_can('administrator') ) return false;
$settings=p3dlite_get_option( 'p3dlite_settings' );
if (isset($_POST['p3dlite_coatings_description'])) {
if ( ! isset( $_POST['p3dlite_coatings_edit'] ) || ! wp_verify_nonce( sanitize_key(wp_unslash($_POST['p3dlite_coatings_edit'])), 'update-options' ) ) {
print 'Sorry, your nonce did not verify. Try to refresh the page.';
exit;
}
update_option('p3dlite_coatings_description', wp_kses_post(nl2br(wp_unslash($_POST['p3dlite_coatings_description']))));
}
$materials=p3dlite_get_option( 'p3dlite_materials' );
add_thickbox();
// if (count($_POST)) {
// $coatings=p3dlite_get_option( 'p3dlite_coatings' );
// foreach ($coatings as $key => $coating) {
// wp_set_object_terms( 0, strval($key), 'pa_p3dlite_coating' , false );
// }
// }
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
$coating_id = (int)$_GET['coating'];
$coating_result = $wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_coatings where id='$coating_id'", ARRAY_A );
if (count($coating_result)==0) {
wp_redirect( admin_url( 'admin.php?page=p3dlite_coatings' ) );
}
$coating = $coating_result[0];
add_thickbox();
// if (count($_POST)) {
// $coatings=p3dlite_get_option( 'p3dlite_coatings' );
// foreach ($coatings as $key => $coating) {
// wp_set_object_terms( 0, strval($key), 'pa_p3dlite_coating' , false );
// }
// }
include('3dprint-lite-admin-coatings-edit.php');
}
elseif (isset($_GET['action']) && $_GET['action'] == 'clone') {
if (!wp_verify_nonce(sanitize_key( $_REQUEST['_wpnonce'] ), 'sp_clone_coating')) {
wp_die('nonce does not match, try to refresh the page');
}
$coating_id = (int)$_GET['coating'];
$coating_result = $wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_coatings where id='$coating_id'", ARRAY_A );
if (count($coating_result)==0) {
wp_redirect( admin_url( 'admin.php?page=p3dlite_coatings' ) );
}
$clone_data = $coating_result[0];
unset($clone_data['id']);
$wpdb->insert($wpdb->prefix."p3dlite_coatings", $clone_data);
wp_redirect( admin_url( 'admin.php?page=p3dlite_coatings&action=edit&coating='.(int)$wpdb->insert_id ) );
}
elseif (isset($_GET['action']) && $_GET['action'] == 'add') {
if (!wp_verify_nonce(sanitize_key( $_REQUEST['_wpnonce'] ), 'sp_add_coating')) {
wp_die('nonce does not match, try to refresh the page');
}
$default_coating_data = array(
'status' => '1',
'name' => 'New Coating',
'description' => '',
'photo' => '',
'color' => '#08c101',
);
$wpdb->insert($wpdb->prefix."p3dlite_coatings", $default_coating_data);
wp_redirect( admin_url( 'admin.php?page=p3dlite_coatings&action=edit&coating='.(int)$wpdb->insert_id ) );
}
else {
include('3dprint-lite-admin-coatings.php');
$p3dlitec_instance = p3dliteC_Plugin::get_instance();
$p3dlitec_instance->plugin_settings_page();
}
}
function register_3dprintlite_price_requests_page_callback() {
global $wpdb;
if ( $_GET['page'] != 'p3dlite_price_requests') return false;
if ( !current_user_can('administrator') ) return false;
$settings=p3dlite_get_option( 'p3dlite_settings' );
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
$price_request_id = (int)$_GET['price_request'];
if (empty($price_request_id)) {
wp_redirect( admin_url( 'admin.php?page=p3dlite_price_requests' ) );
}
$price_request_result = $wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_price_requests where id='$price_request_id'", ARRAY_A );
$price_request = $price_request_result[0];
include('3dprint-lite-admin-price-requests-edit.php');
}
else {
include('3dprint-lite-admin-price-requests.php');
$p3dlitepr_instance = p3dlitePR_Plugin::get_instance();
$p3dlitepr_instance->plugin_settings_page();
}
# p3dlite_check_install();
}
function register_3dprintlite_email_templates_page_callback() {
global $wpdb;
if ( $_GET['page'] != 'p3dlite_email_templates') return false;
if ( !current_user_can('administrator') ) return false;
$settings=p3dlite_get_option( 'p3dlite_settings' );
if ( isset( $_POST['p3dlite_email_templates'] ) && !empty( $_POST['p3dlite_email_templates'] ) ) {
if ( ! isset( $_POST['p3d_email_templates_edit'] ) || ! wp_verify_nonce( $_POST['p3d_email_templates_edit'], 'update' ) ) {
print 'Sorry, your nonce did not verify.';
exit;
}
$templates_update = p3dlite_sanitize_templates($_POST['p3dlite_email_templates']);
if (isset($templates_update['client_email_preserve_html']) && $templates_update['client_email_preserve_html']=='on') {
$templates_update['client_email_body'] = $templates_update['client_email_body_raw'];
}
else {
$templates_update['client_email_body'] = nl2br($templates_update['client_email_body']);
}
if (isset($templates_update['admin_email_preserve_html']) && $templates_update['admin_email_preserve_html']=='on') {
$templates_update['admin_email_body'] = $templates_update['admin_email_body_raw'];
}
else {
$templates_update['admin_email_body'] = nl2br($templates_update['admin_email_body']);
}
update_option( 'p3dlite_email_templates', $templates_update );
}
$current_templates = get_option( 'p3dlite_email_templates' );
#p3dlite_check_install();
?>
Available in Premium version
Available in Premium version
Requires a subscription!
Screenshot:
$infill) {
// wp_set_object_terms( 0, strval($key), 'pa_p3dlite_infill' , false );
// }
// }
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
$infill_id = (int)$_GET['infill'];
$infill_result = $wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_infills where id='$infill_id'", ARRAY_A );
if (count($infill_result)==0) {
wp_redirect( admin_url( 'admin.php?page=p3dlite_infills' ) );
}
$infill = $infill_result[0];
add_thickbox();
// if (count($_POST)) {
// $infills=p3dlite_get_option( 'p3dlite_infills' );
// foreach ($infills as $key => $infill) {
// wp_set_object_terms( 0, strval($key), 'pa_p3dlite_infill' , false );
// }
// }
include('3dprint-lite-admin-infills-edit.php');
}
elseif (isset($_GET['action']) && $_GET['action'] == 'clone') {
if (!wp_verify_nonce(sanitize_key( $_REQUEST['_wpnonce'] ), 'sp_clone_infill')) {
wp_die('nonce does not match, try to refresh the page');
}
$infill_id = (int)$_GET['infill'];
$infill_result = $wpdb->get_results( "select * from {$wpdb->prefix}p3dlite_infills where id='$infill_id'", ARRAY_A );
if (count($infill_result)==0) {
wp_redirect( admin_url( 'admin.php?page=p3dlite_infills' ) );
}
$clone_data = $infill_result[0];
unset($clone_data['id']);
$wpdb->insert($wpdb->prefix."p3dlite_infills", $clone_data);
wp_redirect( admin_url( 'admin.php?page=p3dlite_infills&action=edit&infill='.(int)$wpdb->insert_id ) );
}
elseif (isset($_GET['action']) && $_GET['action'] == 'add') {
if (!wp_verify_nonce(sanitize_key( $_REQUEST['_wpnonce'] ), 'sp_add_infill')) {
wp_die('nonce does not match, try to refresh the page');
}
$default_infill_data = array(
'status' => '1',
'name' => 'New infill',
'description' => '',
'photo' => '',
);
$wpdb->insert($wpdb->prefix."p3dlite_infills", $default_infill_data);
wp_redirect( admin_url( 'admin.php?page=p3dlite_infills&action=edit&infill='.(int)$wpdb->insert_id ) );
}
else {
include('3dprint-lite-admin-infills.php');
$p3dlitei_instance = p3dliteI_Plugin::get_instance();
$p3dlitei_instance->plugin_settings_page();
}
}
function register_3dprintlite_postprocessings_page_callback() {
global $wpdb;
if ( $_GET['page'] != 'p3dlite_postprocessings') return false;
if ( !current_user_can('administrator') ) return false;
?>
Available in Premium version
Screenshot:
Available in Premium version
Screenshot: