Plugin Directory

Changeset 1482629


Ignore:
Timestamp:
08/24/2016 03:48:42 PM (10 years ago)
Author:
mhallmann
Message:

Update auf 0.4

Location:
sepa-girocode
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • sepa-girocode/trunk/includes/phpqrcode/qrimage.php

    r1455698 r1482629  
    6464   
    6565        //----------------------------------------------------------------------
    66         private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
     66        public static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
    6767        {
    6868            $h = count($frame);
  • sepa-girocode/trunk/readme.txt

    r1459751 r1482629  
    33Tags: Girocode, EPC, SEPA, SCT, Überweisung, Mobile Payments
    44Requires at least: 4.0
    5 Tested up to: 4.5.3
     5Tested up to: 4.6.0
    66Stable tag: 0.3
    77
     
    3131* purposecode: Standard-Codes for payment purposes, e.g. CHAR for Charity-Payments
    3232* reference: Alternative to unstructured purpose description, use of reference overrules purpose-field
    33 * clickable: With this field set to 1 the QR-Code can be downloaded als .girocode file
     33* isclickable: With this field set to 1 (standard) the QR-Code can be downloaded als .girocode file
     34* frame: With this field set to 0 (standard = 1), the girocode-frame will be supressed
     35* dimension: Width (and also height) of the code in pixels (standard = 150)
     36* divclass: Optional CSS-class for wrapping <div>-element
    3437
    3538= Come on, show me an example ... =
     
    4245
    4346= Which tool do you use to create the QR-Code? =
    44 This plugin uses google charts api for initial rendering. Once the QR-Code has been rendered, it is cached in the Wordpress-database. Any change of the shortcode triggers a new request to google charts api.
    45 
     47http://phpqrcode.sourceforge.net/
    4648
    4749== Screenshots ==
     
    5052
    5153== Changelog ==
     54= 0.4 (2016-08-24) =
     55* Added girocode-frame
     56* Added frame-parameter
     57* Added dimension-parameter
     58* Added optional div-class-parameter
     59* Code refactor
     60
    5261= 0.3 =
    5362* Added new parameters (clickable, purposecode, reference)
  • sepa-girocode/trunk/sepa-girocode.php

    r1459748 r1482629  
    22
    33defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
     4require_once("includes/phpqrcode/qrlib.php");
    45
    56
     
    3940    $this->data['purpose'] = "";
    4041    $this->data['amount'] = 0;
    41     $this->data['isclickable'] = 0;
     42    $this->data['isclickable'] = 1;
    4243    $this->data['purposecode'] = '';
    43     $this->data['reference'] = '';
     44    $this->data['reference'] = "";
     45    $this->data['dimension'] = 150;
     46    $this->data['frame'] = 1;
     47    $this->data['divclass'] = "";
     48
    4449}
    4550
     
    6166    }
    6267
     68   
    6369    $value = trim($value);
    6470
     
    8692            break;
    8793        case "isclickable":
     94            $this->data["$property"] = floatval($value);
     95            break;
     96        case "frame":
    8897            $this->data["$property"] = floatval($value);
    8998            break;
     
    135144}
    136145
     146public function renderQrCode() {
     147
     148    $payload = $this->getQrPayload();
     149    $outerFrame = 1;
     150    $pixelPerPoint = 8;
     151   
     152    // render Image without Girocode frame
     153    if ($this->frame == 0) {
     154        ob_start ( );
     155        QRcode::png ($payload, false, QR_ECLEVEL_M, $pixelPerPoint, $outerFrame, false);
     156        $tmp = ob_get_contents ( );
     157        ob_end_clean ( );
     158        return $tmp;
     159        die();
     160    }
     161
     162   
     163   
     164    // generating frame
     165   
     166    $frame = QRcode::text($payload, false, QR_ECLEVEL_M);
     167     
     168    // rendering frame with GD2 (that should be function by real impl.!!!)
     169    $h = count($frame);
     170    $w = strlen($frame[0]);
     171    $imgW = $w + 2*$outerFrame;
     172    $imgH = $h + 2*$outerFrame;
     173     
     174    $base_image = imagecreate($imgW, $imgH);
     175     
     176    $col[0] = imagecolorallocate($base_image,255,255,255); // BG, white 
     177    $col[1] = imagecolorallocate($base_image,0,0,0);     // FG, black
     178   
     179    imagefill($base_image, 0, 0, $col[0]);
     180
     181    for($y=0; $y<$h; $y++) {
     182        for($x=0; $x<$w; $x++) {
     183            if ($frame[$y][$x] == '1') {
     184                imagesetpixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); 
     185            }
     186        }
     187    }
     188
     189    $target_image = imagecreatefrompng(plugin_dir_path( __FILE__ ) . "images/girocode.png");
     190
     191    imagecopyresized(
     192        $target_image, 
     193        $base_image, 
     194        25, 25, 0, 0,
     195        350, 350, $imgW, $imgH
     196    );
     197   
     198    imagedestroy($base_image);
     199   
     200    ob_start ( );
     201    imagepng ( $target_image );
     202    $tmp = ob_get_contents ( );
     203    ob_end_clean ( );
     204   
     205    imagedestroy($target_image);
     206   
     207    return $tmp;
     208}
     209
     210
     211public function QrPngWithHeader() {
     212       
     213           
     214        $image = imagecreatefromstring($this->renderQrCode());
     215        if (! $image)  die("Fehler in getQrPng");
     216        header('Content-Type: image/png');
     217        imagepng($image);
     218        imagedestroy($image); 
     219        return true;
     220        exit;
     221}
     222
     223public function getTransientKey() {
     224    return "sgc_" . md5($this->getQrPayload());
     225}
     226
     227public function getQrDiv() {
     228    $key = $this->getTransientKey();
     229    $img_src = "index.php?sepa-girocode=show-code&key=" . $key;
     230    $click_url = "index.php?sepa-girocode=get-codefile&key=" . $key;
     231    $width_height = $this->dimension;
     232    $output = "";
     233    $a = "";
     234    $ae = "";
     235   
     236    if ($this->isclickable == 1) {
     237        $a = "<a href='$click_url' target='_blank'>";
     238        $ae = "</a>";
     239    }
     240   
     241   
     242    if (strlen($this->divclass) == 0) {
     243        $output .= "<div>";
     244    } else {
     245        $output .= "<div class='" . $this->divclass . "'>";
     246    }
     247   
     248    $output .= "$a<img src='$img_src' width='$width_height' height='$width_height'></img>$ae</div>";
     249
     250    return $output;
     251}
     252
    137253}  // end class
    138254
     
    157273   
    158274    $sgc = new sepa_girocode_class();
    159     $output = "";
    160275       
    161276    foreach ($atts as $k => $v) {
     
    166281        }
    167282    }
    168    
    169     //$gurl =  $sgc->getGoogleUrl();
    170     $newvalue =  $sgc->getQrPayload();
    171     $key =  "sgc_" . md5( $newvalue );
    172    
     283
     284    $key =  $sgc->getTransientKey();
     285
    173286    if ( false === ( $value = get_transient($key) ) ) {
    174         set_transient($key, $newvalue, YEAR_IN_SECONDS);
    175     }
    176 
    177     $img_src = "index.php?sepa-girocode=show-code&key=" . $key;
    178     $click_url = "index.php?sepa-girocode=get-codefile&key=" . $key;
    179    
    180     if ($sgc->isclickable == 1) {
    181         $output .= "<div><a href='$click_url' target='_blank'><img src='$img_src'></a></img></div>";
    182     } else {
    183         $output .= "<div><img src='$img_src'></img></div>";
    184     }
    185    
    186      
    187      
    188    
    189      
    190     return $output;
     287        $tmp = set_transient($key,
     288                      $sgc,
     289                      MINUTE_IN_SECONDS);
     290        if (!$tmp) die ("Konnte Transient nicht setzen! KEY = " . $key);
     291    }
     292
     293    return $sgc->getQrDiv();
    191294}   
    192    
     295
    193296
    194297
    195298function sepa_girocode_parse_request($wp) {
    196299    // only process requests with "halli-girocode=show-code"
    197     require_once("includes/phpqrcode/qrlib.php");
    198    
     300   
     301
    199302    if (array_key_exists('sepa-girocode', $wp->query_vars) && $wp->query_vars['sepa-girocode'] == 'show-code') {
     303       
    200304        $key = $wp->query_vars['key'];
    201         QRcode::png( get_transient($key, $level=QR_ECLEVEL_M) );
    202     }
     305        if ( false === ( $sgc = get_transient($key) ) ) {
     306            die("Kein Transient gefunden!");
     307        }
     308       
     309        $sgc->QrPngWithHeader();
     310        exit;
     311
     312    }
     313   
     314
    203315   
    204316    if (array_key_exists('sepa-girocode', $wp->query_vars) && $wp->query_vars['sepa-girocode'] == 'get-codefile') {
    205317        $key = $wp->query_vars['key'];
     318        $sgc = get_transient($key);
    206319        header("Content-Type: application/octet-stream");
    207320        header("Content-Disposition: attachment; filename=\"$key.girocode\"");
    208         echo get_transient($key);
     321        echo $sgc->getQrPayload();
     322       
    209323        exit;
    210324    }
Note: See TracChangeset for help on using the changeset viewer.