*/ /** * patTemplate-function to display QRCodes * * Usage * [[PROTOCOL]]://[[SERVER]][[SELF]]{URI} * * [[PROTOCOL]]://[[SERVER]][[SELF]]{URI} * * @version 1.1.0 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Qrcode extends patTemplate_Function { /** * Name of Function * * @access private * @var string */ public $_name = 'Qrcode'; /** * Function Type * * Tell that this function has to be executed during runtime * @var string */ public $_type = PATTEMPLATE_FUNCTION_RUNTIME; /** * QR-Code Generator * * @var WBUte_QRCode */ private $qrc; /** * Call the function * * Initialize WBUte_QRCode, set configuration parameter and QRCode-Text and finally * render either for HTML or LaTeX (see: attribute "mode") * * Known parameter * - mode: html (default) or latex * - class: class-attribute name for HTML img-tag * - border: 1 (default) or 0 for no border Usually QRCodes with border are easier to scan * - width: "" (default) for LaTeX includegraphics and HTML * - height: "" (default) for LaTeX includegraphics and HTML * Furthermore all parameters will be passed as configuration parameter to WBUte_QRCode * * @see WBUte_QRCode::configure() * @param array $params parameters of the function (= attributes of the tag) * @param string $content inside tag * @return string content to insert into the template */ public function call($params, $content) { $paramsDef = array( 'mode' => 'html', 'class' => '', 'border' => 1, 'width' => '', 'height' => '' ); $params = array_merge($paramsDef, $params); $this->qrc = WBClass::create('WBUte_QRCode'); $this->qrc->configure($params); $content = WBString::replaceSuperPlaceholders($content); $this->qrc->setText($content); switch (strtolower($params['mode'])) { case 'tex': case 'latex': return $this->get4LaTeX($params); break; default: case 'html': return $this->get4HTML($params); break; } } /** * Get Content for LaTeX Output * * @todo to be implemented * @param array */ private function get4LaTeX($params) { $att = array('keepaspectratio'); $key = array( 'width', 'height' ); foreach ($key as $k) { if (empty($params[$k])) { continue; } $att[] = sprintf('%s=%s', $k, $params[$k]); } $file = $this->qrc->getImage()->realpath(); rename($file, $file . '.png'); $tex = '\includegraphics[%s]{%s}'; return sprintf($tex, implode(',', $att), $file . '.png'); } /** * Get Content for HTML Output * * Convert image file to base64 and render img-tag with inline image data * * @param array */ private function get4HTML($params) { $file = $this->qrc->getImage(); $file = base64_encode(file_get_contents($file->realpath())); $this->qrc->flush(); $att = array(); $key = array( 'class', 'width', 'height' ); foreach ($key as $k) { if (empty($params[$k])) { continue; } $att[] = sprintf('%s=%s', $k, $params[$k]); } $att = implode(' ', $att); return sprintf('', $att, $file); } }