-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathscanner.php
More file actions
78 lines (71 loc) · 2.13 KB
/
scanner.php
File metadata and controls
78 lines (71 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
Plugin Name: QR Code Scanner
Plugin URI: http://emanager.nyc
Description: QR code scanner for Wordpress
Author: Matthew M. Emma
Version: 0.4
Author URI: http://www.emanager.nyc
*/
/*-------------------------------------------------------*/
/* Enqueue scripts
/*-------------------------------------------------------*/
$WPQRScanner = new QRScanner();
class QRScanner {
protected $mwidth;
protected $mheight;
public function __construct() {
add_action( 'wp_enqueue_scripts', array($this, 'qrscan_scripts'), 10, 0 );
add_action( 'wp_footer', array($this, 'qrscan_fscript'));
add_shortcode('qrscan', array($this, 'qrscan_shortcode'));
}
public function qrscan_scripts() {
wp_register_script('html5_qrcode', plugins_url('html5-qrcode.min.js', __FILE__), array( 'jquery'),null);
wp_enqueue_script('html5_qrcode');
}
public function strLength($str,$len){
$length = strlen($str);
if($length > $len){
return substr($str,0,$len).'...';
}else{
return $str;
}
}
public function qrscan_shortcode( $atts ) {
extract( shortcode_atts( array(
'width' => '400px',
'height' => '400px'
), $atts, 'qrscan' ) );
$this->mwidth = $width;
$this->mheight = $height;
$v = '<center><div id="reader" style="width:'.$width.';height:'.$height.'"></div>
<h6 class="center">Result</h6>
<span id="read" class="center"></span>
<br>
<h6 class="center">Read Error (Debug only)</h6>
<span class="center">Will constantly show a message, can be ignored</span>
<span id="read_error" class="center"></span>
<br>
<h6 class="center">Video Error</h6>
<span id="vid_error" class="center"></span>
</center>';
return $v;
}
public function qrscan_fscript() {
?>
<script id="qrscanner">
jQuery(document).ready(function($){
$('#reader').html5_qrcode(function(data){
$('#read').html(data);
},
function(error){
$('#read_error').html(error);
}, function(videoError){
$('#vid_error').html(videoError);
}
);
});
</script>
<?php
}
}