<?php

/* ========================================================================
 * $Id: qrcode.php 1191 2019-12-29 13:10:11Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onezphp.com
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
class onezphp_qrcode extends onezphp{
  var $attr=array();
  function __construct(){
    
  }
  function decode_url($url){
    $data=@file_get_contents($url);
    include_once(dirname(__FILE__).'/lib/QrReader.php');
    $qrcode = new QrReader($data,QrReader::SOURCE_TYPE_BLOB);
    return $qrcode->text();
  }
  function decode($file){
    include_once(dirname(__FILE__).'/lib/QrReader.php');
    $qrcode = new QrReader($file);
    return $qrcode->text();
  }
  function show($text=false){
    include_once(dirname(__FILE__).'/phpqrcode/phpqrcode.php');
    $text===false && $text=onez()->gp('text');
    #QRcode::png($text,false,QR_ECLEVEL_M,8,1);
    QRcode::png($text,false,QR_ECLEVEL_H,8,1);
    exit();
  }
  function pic($text){
    return $this->url($text).'"'.$myattr.' alt="';
  }
  function url($text){
    $get=array();
    $myattr='';
    
    $width=$this->get('width');
    if($width){
      $myattr.=' width="'.$width.'"';
      $get['width']=$width;
    }
    $size=$this->get('size');
    if($size){
      $get['size']=$size;
    }
    
    $get['text']=$text;
    return $this->view('show&'.http_build_query($get));
  }
}