Changeset 1482629
- Timestamp:
- 08/24/2016 03:48:42 PM (10 years ago)
- Location:
- sepa-girocode
- Files:
-
- 3 added
- 3 edited
-
assets/girocode.snag (added)
-
trunk/images/girocode.png (added)
-
trunk/includes/phpqrcode/qrimage.php (modified) (1 diff)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/sepa-girocode.php (modified) (7 diffs)
-
trunk/sepa-girocode.php.backup (added)
Legend:
- Unmodified
- Added
- Removed
-
sepa-girocode/trunk/includes/phpqrcode/qrimage.php
r1455698 r1482629 64 64 65 65 //---------------------------------------------------------------------- 66 p rivatestatic function image($frame, $pixelPerPoint = 4, $outerFrame = 4)66 public static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) 67 67 { 68 68 $h = count($frame); -
sepa-girocode/trunk/readme.txt
r1459751 r1482629 3 3 Tags: Girocode, EPC, SEPA, SCT, Überweisung, Mobile Payments 4 4 Requires at least: 4.0 5 Tested up to: 4. 5.35 Tested up to: 4.6.0 6 6 Stable tag: 0.3 7 7 … … 31 31 * purposecode: Standard-Codes for payment purposes, e.g. CHAR for Charity-Payments 32 32 * 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 34 37 35 38 = Come on, show me an example ... = … … 42 45 43 46 = 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 47 http://phpqrcode.sourceforge.net/ 46 48 47 49 == Screenshots == … … 50 52 51 53 == 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 52 61 = 0.3 = 53 62 * Added new parameters (clickable, purposecode, reference) -
sepa-girocode/trunk/sepa-girocode.php
r1459748 r1482629 2 2 3 3 defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); 4 require_once("includes/phpqrcode/qrlib.php"); 4 5 5 6 … … 39 40 $this->data['purpose'] = ""; 40 41 $this->data['amount'] = 0; 41 $this->data['isclickable'] = 0;42 $this->data['isclickable'] = 1; 42 43 $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 44 49 } 45 50 … … 61 66 } 62 67 68 63 69 $value = trim($value); 64 70 … … 86 92 break; 87 93 case "isclickable": 94 $this->data["$property"] = floatval($value); 95 break; 96 case "frame": 88 97 $this->data["$property"] = floatval($value); 89 98 break; … … 135 144 } 136 145 146 public 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 211 public 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 223 public function getTransientKey() { 224 return "sgc_" . md5($this->getQrPayload()); 225 } 226 227 public 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 137 253 } // end class 138 254 … … 157 273 158 274 $sgc = new sepa_girocode_class(); 159 $output = "";160 275 161 276 foreach ($atts as $k => $v) { … … 166 281 } 167 282 } 168 169 //$gurl = $sgc->getGoogleUrl(); 170 $newvalue = $sgc->getQrPayload(); 171 $key = "sgc_" . md5( $newvalue ); 172 283 284 $key = $sgc->getTransientKey(); 285 173 286 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(); 191 294 } 192 295 193 296 194 297 195 298 function sepa_girocode_parse_request($wp) { 196 299 // only process requests with "halli-girocode=show-code" 197 require_once("includes/phpqrcode/qrlib.php");198 300 301 199 302 if (array_key_exists('sepa-girocode', $wp->query_vars) && $wp->query_vars['sepa-girocode'] == 'show-code') { 303 200 304 $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 203 315 204 316 if (array_key_exists('sepa-girocode', $wp->query_vars) && $wp->query_vars['sepa-girocode'] == 'get-codefile') { 205 317 $key = $wp->query_vars['key']; 318 $sgc = get_transient($key); 206 319 header("Content-Type: application/octet-stream"); 207 320 header("Content-Disposition: attachment; filename=\"$key.girocode\""); 208 echo get_transient($key); 321 echo $sgc->getQrPayload(); 322 209 323 exit; 210 324 }
Note: See TracChangeset
for help on using the changeset viewer.