Support » Plugin: Event Rocket » QR code integration?

  • Resolved dorearendil

    (@dorearendil)


    Hi Barry,
    Sorry to bring in codes from other developers into the mix, but alas my PHP coding abilities are failing me here…

    I’m currently using your great plugin on pages such as this one: http://meridianonline.staging.wpengine.com/events-program/
    Basically, each of these pages displays an array of event post excerpts that can then be printed out as posters.
    The problem with paper posters, of course, is that they make it difficult for people to click hyperlinks!

    So my aim would be to automatically integrate a QR code corresponding to each event post next to the post excerpt, so that people can learn more about it by scanning said code and reading the entire post on their mobile.
    Being rather disappointed with the only available WP QR Code plugin I can find on the WP repo, I’m now experimenting with the method presented there: http://www.sitepoint.com/add-qr-codes-wordpress-posts/
    (I’ll paste the code below for extra clarity)

    Thanks to that script, I’m able to generate QR Codes that are automatically posted at the end of every single post and page on my site. Naturally, that’s not particularly desirable.
    Do you think there would be a convenient way to restrict QR code generation only to the items currently created by Events Rocket on pages like the one linked to above, instead?

    (I guess I need to edit my current Events Rocket “shortcode.embeds.php” file to get there, but I’m still probbing around without much success)

    Thanks in advance 🙂

    =====
    For reference, here’s the plugin code:

    <?php
    /*
    Plugin Name: Awesome QR Code
    Plugin URI: http://sitepoint.com/
    */
    
    include("qrcode.php");
    
    function qr_code($content)
    {
        $url = get_permalink();
    
        $qr = new qrcode();
        $qr->text($url);
    
        $html = "<p><b>QR Code:</b></p><p><img src='".$qr->get_link()."' border='0'/></p>";
        $content .= $html;
    
        return $content;
    }
    
    add_filter("the_content", "qr_code");
    
    ?>

    and the actual qrcode.php script:

    <?php
    /*************************************************************
     * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com
     **************************************************************/
    class qrcode
    {
        private $data;  
    
        //creating code with link mtadata
        public function link($url){
            if (preg_match('/^http:\/\//', $url) || preg_match('/^https:\/\//', $url))
            {
                $this->data = $url;
            }
            else
            {
                $this->data = "http://".$url;
            }
        }  
    
        //...more options//
    
        //getting image
        public function get_image($size = 150, $EC_level = 'L', $margin = '0'){
            $ch = curl_init();
            $this->data = urlencode($this->data);
            curl_setopt($ch, CURLOPT_URL, 'http://chart.apis.google.com/chart');
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, 'chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);  
    
            $response = curl_exec($ch);
            curl_close($ch);
            return $response;
        }  
    
        //getting link for image
        public function get_link($size = 150, $EC_level = 'L', $margin = '0'){
            $this->data = urlencode($this->data);
            return 'http://chart.apis.google.com/chart?chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data;
        }  
    
        //forcing image download
        public function download_image($file){
            header('Content-Disposition: attachment; filename=QRcode.png');
            header('Content-Type: image/png');
            echo $file;
        } 
    
    	//save image to server
        public function save_image($file, $path = "./QRcode.png"){
            file_put_contents($path, $file);
        }
    }
    ?>

    https://wordpress.org/plugins/event-rocket/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Barry

    (@barryhughes-1)

    Hi!

    Right now it’s being applied to all posts because you’ve hooked it up using the the_content filter:

    add_filter("the_content", "qr_code");

    If your goal is to only target the output of the [event_embed] shortcode, what if you change that to eventrocket_embed_post_single_output instead?

    add_filter( 'eventrocket_embed_post_single_output', 'qr_code' );

    Thanks Barry!
    This indeeds helps me get a post-specific QR code at the end of each item in the list generated by Events Rocket, which is awesome.

    Now how would you recommend I proceed if I prefer having the QR code directly integrated within the HTML of each item, instead? So as to avoid fiddling around with relative positioning (and other unseemly tricks)…
    Could part of the plugin code be written directly into my Events Rocket template?

    Plugin Author Barry

    (@barryhughes-1)

    I don’t see why not: you can specify a custom PHP template for [event_embed] to use, like this:

    [event_embed template="custom-embed-tpl.php"]

    This will then look for your-theme/tribe-events/custom-embed-tpl.php which you could initially base on the default template found in the plugin folder:

    event-rocket/templates/embedded-events.php

    Looking at the other code you shared, it seems you could embed the QR code simply by making a call like this:

    echo qr_code( '' );

    I hope that helps!

    Barry, you rock. Thanks again for taking the time to help out a PHP illiterate like me! It all works like a charm.

    In case some people wonder, I of course needed to change the content of the “add_filter” function in the plugin file to make it become:
    add_filter( '', 'qr_code' );

    Plugin Author Barry

    (@barryhughes-1)

    Happy to help 🙂

    Re that line in the plugin file, at this point you could probably simply remove it (or comment it out if you prefer to ‘keep a record’ for possible restoration later), ie:

    // add_filter("the_content", "qr_code");

    Great, thanks!
    I still have so much to learn about the way WordPress works…

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘QR code integration?’ is closed to new replies.