Skip to content

Commit d4fefd9

Browse files
committed
version 2.0.0
1 parent a3fd873 commit d4fefd9

File tree

18 files changed

+576
-419
lines changed

18 files changed

+576
-419
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Print.App
22

3-
## Version 2 plugin
3+
## Version 2.0.0 plugin
44
PrintApp is a platform that allows your customers to personalize their Print orders on any web store.
55
It provides customers, an easy to use WYSIWYG (What you see is what you get) "Do It Yourself" interface for creating artworks for Print.
66

assets/icon.svg

Lines changed: 0 additions & 11 deletions
This file was deleted.

assets/images/icon.svg

Lines changed: 11 additions & 0 deletions
Loading

functions/admin/actions.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace printapp\functions\admin;
4+
5+
function actions() {
6+
global $print_app;
7+
8+
add_menu_page(
9+
'PrintApp Settings',
10+
'PrintApp',
11+
'manage_options',
12+
'printapp',
13+
'printapp\\functions\\admin\\admin_page',
14+
$print_app->plugin_url() . '/assets/images/icon.svg'
15+
);
16+
}
17+
18+
function admin_page() {
19+
if (!class_exists('WooCommerce')) {
20+
echo ('<h3>This plugin depends on WooCommerce plugin. Kindly install <a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce here!</a></h3>');
21+
exit();
22+
}
23+
settings_errors();
24+
25+
echo '<form method="post" action="options.php"><div class="wrap">';
26+
27+
settings_fields('print_app');
28+
do_settings_sections('print_app');
29+
submit_button();
30+
31+
echo '</div></form>';
32+
}

functions/admin/designs.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace printapp\functions\admin;
4+
5+
// show design selection form
6+
function assign_design_form() {
7+
global $post;
8+
$printapp_domain_key = get_option('print_app_domain_key');
9+
10+
echo '<div id="print_app_tab" style="padding:1rem" class="panel woocommerce_options_panel hidden"></div>';
11+
12+
wp_enqueue_script('print_app_design_tree', PRINT_APP_DESIGN_SELECT_JS);
13+
wp_localize_script('print_app_design_tree', 'pa_admin_values', array(
14+
'domain_key' => $printapp_domain_key,
15+
'product_id' => $post->ID,
16+
'product_title' => $post->post_title,
17+
));
18+
}
19+
20+
// add design selection tab
21+
function add_design_selection_tab($default_tabs) {
22+
$default_tabs['print_app_tab'] = array(
23+
'label' => __('PrintApp Design', 'domain'),
24+
'target' => 'print_app_tab',
25+
'priority' => 60,
26+
'class' => array()
27+
);
28+
return $default_tabs;
29+
}

functions/admin/orders.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace printapp\functions\admin;
4+
5+
function format_print_app_order_key($display_value, $meta, $order_item) {
6+
7+
if ($meta->key === 'preview' || $meta->key === '_pda_w2p_set_option') return 'PrintApp Customization';
8+
return $display_value;
9+
10+
}
11+
12+
function format_print_app_order_value($formatted_meta, $order_item) {
13+
14+
foreach ($formatted_meta as $meta) {
15+
if ($meta->key === PRINT_APP_CUSTOMIZATION_PREVIEWS_KEY) {
16+
17+
$item_meta_data = $order_item->get_meta_data();
18+
if (empty($item_meta_data)) return $formatted_meta;
19+
20+
foreach ($item_meta_data as $item_meta) {
21+
if ($item_meta->key === PRINT_APP_CUSTOMIZATION_KEY) {
22+
$print_app_customization = $item_meta->value;
23+
24+
$post_fix = $print_app_customization['projectId'];
25+
$previews = '';
26+
foreach ($print_app_customization['previews'] as $preview) {
27+
$previews .= '<img src="' . $preview['url'] . '" width="180px; margin-right:10px;"/>';
28+
}
29+
30+
$display = '
31+
<div class="print_app_order_meta" style="display: flex;">
32+
<div data-project-id="' . $print_app_customization["projectId"] . '" class="pda_show_preview" style="display:flex; flex-wrap: wrap;">
33+
' . $previews . '
34+
</div>
35+
<div>
36+
<a target="_blank" href="https://pdf.print.app/'. $post_fix .'">• Download PDF</a><br/>
37+
<a target="_blank" href="https://png.print.app/'. $post_fix .'">• Download PNG</a><br/>
38+
<a target="_blank" href="https://jpg.print.app/'. $post_fix .'">• Download JPEG</a><br/>
39+
<a target="_blank" href="https://tiff.print.app/'. $post_fix .'">• Download TIFF</a><br/>
40+
<a target="_blank" href="https://admin.print.app/projects/'. $post_fix .'">• Modify Project</a>
41+
</div>
42+
</div>';
43+
44+
$meta->display_value = $display;
45+
break;
46+
}
47+
}
48+
49+
break;
50+
}
51+
}
52+
53+
return $formatted_meta;
54+
}
55+
56+
// this is for backward compatibility v1, to display old orders pre-installing this version
57+
function print_app_filter_wc_order_item_display_meta_value( $display_value, $meta ) {
58+
if ( $meta->key === '_pda_w2p_set_option' ) {
59+
$pda_data = json_decode($display_value, true);
60+
61+
$auth_key = get_option('print_app_secret_key');
62+
63+
if (!empty($pda_data['projectId'])) {
64+
$hash = md5( $pda_data['projectId'] . $auth_key );
65+
$post_fix = $pda_data['projectId'] . '!' . $hash;
66+
67+
return '
68+
<div class="print_app_order_meta" style="display: flex;">
69+
<div onclick="pda_show_preview(this)" data-project-id="' . $pda_data["projectId"] . '" class="pda_show_preview" style="margin-right: 10px;">
70+
<img src="' . $pda_data['previews'][0]['url'] . '" width="180px"/>
71+
<div>
72+
<svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-search" width="22px" height="22px" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" data-v-09078359=""> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <circle cx="10" cy="10" r="7"></circle> <line x1="21" y1="21" x2="15" y2="15"></line> </svg>
73+
</div>
74+
</div>
75+
<div>
76+
<a target="_blank" href="https://pdf.print.app/'. $post_fix .'">Download PDF</a><br/>
77+
<a target="_blank" href="https://png.print.app/'. $post_fix .'">Download PNG</a><br/>
78+
<a target="_blank" href="https://jpg.print.app/'. $post_fix .'">Download JPEG</a><br/>
79+
<a target="_blank" href="https://tiff.print.app/'. $post_fix .'">Download TIFF</a><br/>
80+
<a target="_blank" href="https://admin.print.app/projects/'. $pda_data['projectId'] .'">Modify Project</a>
81+
</div>
82+
</div>';
83+
} else if (!empty($pda_data['form'])) {
84+
print_r($pda_data);
85+
}
86+
}
87+
return $display_value;
88+
}

functions/admin/settings.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace printapp\functions\admin;
4+
5+
function print_app_create_settings() {
6+
echo '<p>' . __("You can generate your DomainKey and AuthKey from the <a target=\"_blank\" href=\"https://admin.print.app/domains\">Print.App Dashboard</a>", "printapp") . '</p>';
7+
}
8+
9+
function settings_api_init() {
10+
add_settings_section('print_app_settings_section', 'PrintApp Settings', 'printapp\\functions\\admin\\print_app_create_settings', 'print_app');
11+
add_settings_field('print_app_domain_key', 'Domain Key', 'printapp\\functions\\admin\\print_app_domain_key', 'print_app', 'print_app_settings_section', array());
12+
add_settings_field('print_app_secret_key', 'Auth Key', 'printapp\\functions\\admin\\print_app_secret_key', 'print_app', 'print_app_settings_section', array());
13+
register_setting('print_app', 'print_app_domain_key');
14+
register_setting('print_app', 'print_app_secret_key');
15+
}
16+
17+
// input for capturing the PrintApp Domain Key
18+
function print_app_domain_key() {
19+
echo '<input class="regular-text" id="print_app_domain_key" name="print_app_domain_key" type="text" value="' . esc_html( get_option('print_app_domain_key') ) . '" />';
20+
}
21+
22+
// input for capturing the PrintApp Auth Key
23+
function print_app_secret_key() {
24+
echo '<input class="regular-text" id="print_app_secret_key" name="print_app_secret_key" type="text" value="' . esc_html( get_option('print_app_secret_key') ) . '" />';
25+
}
26+
27+
// creates the PrintApp settings link in admin
28+
function add_settings_link($links) {
29+
$settings_link = array(
30+
'<a href="/wp-admin/admin.php?page=printapp" rel="noopener">Settings</a>',
31+
);
32+
$actions = array_merge( $links, $settings_link );
33+
return $actions;
34+
}

functions/front/carts.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace printapp\functions\front;
4+
5+
function add_cart_item_data($cart_item_data, $product_id, $variation_id, $qty) {
6+
if (!session_id()) session_start();
7+
8+
$session_key = PRINT_APP_SESSION_PREFIX . $product_id;
9+
10+
if (isset($_SESSION[$session_key])) {
11+
$cart_item_data[PRINT_APP_CUSTOMIZATION_KEY] = $_SESSION[$session_key];
12+
unset($_SESSION[$session_key]);
13+
}
14+
15+
return $cart_item_data;
16+
}
17+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace printapp\functions\front;
4+
5+
function customize_button() {
6+
global $post;
7+
$printapp_domain_key = get_option('print_app_domain_key');
8+
9+
// load the client-class script...
10+
$lang_code = substr(get_bloginfo('language'), 0, 2);
11+
if (!$lang_code) $lang_code = 'en';
12+
$run_url = PRINT_APP_RUN_BASE_URL . $printapp_domain_key . '/' . $post->ID . '/wp?lang=' . $lang_code;
13+
wp_enqueue_script('print_app_class', $run_url, '', '', true);
14+
15+
// get user data
16+
$user_data = get_user_data();
17+
18+
if (!session_id()) session_start();
19+
20+
// get project data
21+
if (session_id()) {
22+
$session_key = PRINT_APP_SESSION_PREFIX . $post->ID;
23+
if (isset($_SESSION[$session_key])) $project_data = $_SESSION[$session_key];
24+
}
25+
26+
// initialize the data to pass to print_app_class
27+
$pa_project_id = '';
28+
$pa_previews = '';
29+
$pa_mode = 'new-project';
30+
$pa_user_id = (get_current_user_id() === 0) ? 'guest' : get_current_user_id();
31+
32+
if (isset($project_data)) {
33+
$pa_project_id = $project_data['projectId'];
34+
$pa_mode = isset($project_data['mode']) ? $project_data['mode'] : 'edit-project';
35+
$pa_previews = isset($project_data['previews']) ? json_encode($project_data['previews']) : '';
36+
}
37+
38+
wp_localize_script('print_app_class', 'printAppParams', array(
39+
'mode' => $pa_mode,
40+
'langCode' => $lang_code,
41+
'previews' => $pa_previews,
42+
'projectId' => $pa_project_id,
43+
'pluginRoot' => site_url() . '/print_app',
44+
'product' => array(
45+
'id' => $post->ID,
46+
'name' => $post->post_name
47+
),
48+
'userId' => $pa_user_id,
49+
'launchData' => $user_data,
50+
'wp_ajax_url' => admin_url('admin-ajax.php'),
51+
));
52+
53+
echo '<div id="pa-buttons"></div>';
54+
}
55+
56+
function get_user_data() {
57+
if (!is_user_logged_in()) return 'null';
58+
59+
$customer = WC()->customer;
60+
$current_user = wp_get_current_user();
61+
62+
$fname = esc_js($customer->get_billing_first_name());
63+
$lname = esc_js($customer->get_billing_last_name());
64+
65+
$address = $customer->get_billing_address_1() . "<br>";
66+
if ( !empty($customer->get_billing_address_2()) ) {
67+
$address .= $customer->get_billing_address_2() . "<br>";
68+
}
69+
$address .= $customer->get_billing_city() . " " . $customer->get_billing_postcode() . "<br>";
70+
if ( !empty($customer->get_billing_state()) ) {
71+
$address .= $customer->get_billing_state() . "<br>";
72+
}
73+
$address .= $customer->get_billing_country();
74+
$address = esc_js($address);
75+
76+
return "{
77+
email: '" . esc_js($current_user->user_email) . "',
78+
name: '{$fname} {$lname}',
79+
firstname: '{$fname}',
80+
lastname: '{$lname}',
81+
phone: '" . esc_js($customer->get_billing_phone()) . "',
82+
address: '{$address}'.split('<br>').join('\\n')
83+
}";
84+
}

functions/front/orders.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace printapp\functions\front;
4+
5+
function add_order_item_meta($order_item, $cart_item_key) {
6+
$cart_item = WC()->cart->get_cart_item( $cart_item_key );
7+
8+
if (empty($cart_item) || empty($cart_item[PRINT_APP_CUSTOMIZATION_KEY])) return;
9+
10+
$order_item->add_meta_data(PRINT_APP_CUSTOMIZATION_KEY, $cart_item[PRINT_APP_CUSTOMIZATION_KEY], true);
11+
12+
$url = $cart_item[PRINT_APP_CUSTOMIZATION_KEY]['previews'][0]['url'];
13+
if (empty($url)) return;
14+
15+
$preview = '<img class="pa-preview-image" style="width:120px; margin-left: 5px; margin-right:5px" src="' . $url . '">';
16+
$order_item->add_meta_data(PRINT_APP_CUSTOMIZATION_PREVIEWS_KEY, $preview, true);
17+
18+
}

0 commit comments

Comments
 (0)