We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21056
    • 327 Posts
    This is an auto-generated support/comment thread for vCard.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    This snippet is to create vCards from within Modx. It is useful for either a single vCard for an entire organisation, or it can take it’s values from template variables (TVs) in order to be used in staff directories.
      Author: ManagerManager plugin - customise your ModX manager interface

      Rckt - web development, Sheffield, UK
      • 4385
      • 372 Posts
      I had problems getting the template variables from the parent, and had to modify lines 99 and 100.

      	// if we have requested a parent TV value by prefixing the tv name with parent.
      		if (substr($input[$f], 1, 7) == 'parent.') {
      			$tvname = substr($input[$f], 8, -1);
      			$parent = $modx->getTemplateVar('parent', '*', $id);
      			$parent = $parent['value'];
      			$doc_id  = $parent;
      		}
      
        DropboxUploader -- Upload files to a Dropbox account.
        DIG -- Dynamic Image Generator
        gus -- Google URL Shortener
        makeQR -- Uses google chart api to make QR codes.
        MODxTweeter -- Update your twitter status on publish.
        • 18174
        • 116 Posts
        Nice snippet, but doesn’t work with modx modified to utf-8 database character set.
        Around line 90 I had to change
        foreach ($fields as $f) {
        	$input[$f] = isset($$f) ? $$f : '';

        into
        foreach ($fields as $f) {
        	$input[$f] = isset($$f) ? utf8_decode($$f) : '';

        I’m not sure if this is the ultimate solution, but it works for me.
        regards
        manu
          • 19986
          • 90 Posts
          Hi. Many thanks for the snippet, it looks like it’ll prove very useful.

          I’ve made a couple of very minor changes, necessary to allow me to use TVs on the current document without having to specify the doc ID.

          Currently, your code A) sets the id to false if a non numerical urlParam is provided and B) requires the id in order to look for the * characters that indicate a TV is to be sourced.

          There’s no need for B because MODx will default to using the current document id if it’s false and I think the preventing A results in behaviour that’s least surprising (in that one bad param won’t alter another good one).

          Changes made to repo-1498.txt.

          diff --git a/HEAD^:vCard.snippet.php b/HEAD:vCard.snippet.php
          index 34b1250..ff321be 100644
          --- a/HEAD^:vCard.snippet.php
          +++ b/HEAD:vCard.snippet.php
          @@ -77,8 +77,6 @@ $id = isset($id) ? $id : false;
           $urlParam = isset($urlParam) ? $urlParam : 'id';
           if (isset($_GET[$urlParam]) && is_numeric($_GET[$urlParam])) {
                  $id = $_GET[$urlParam];
          -} else {
          -       $id = false;
           }
           
           
          @@ -92,7 +90,7 @@ foreach ($fields as $f) {
                  $input[$f] = isset($$f) ? $$f : '';
                  // If the value supplied is surrounded by *, e,g, *staffemail*, assume we are being told to use not a literal value here, 
                  // but the value of a template variable
          -       if ($id && substr($input[$f], 0, 1) == '*' && substr($input[$f], -1, 1) == '*') {
          +       if (substr($input[$f], 0, 1) == '*' && substr($input[$f], -1, 1) == '*') {
                          $tvname = substr($input[$f], 1, strlen($input[$f])-2);  // remove the asterisk from each end
                          $doc_id = $id;
                          // if we have requested a parent TV value by prefixing the tv name with parent.
          @@ -316,4 +314,4 @@ class vCard {
                          return $this->filename;
                  }
           }
          -?>
          \ No newline at end of file
          +?>


          Thanks again.

          Stephan
            • 21056
            • 327 Posts
            Thanks for the feedback; I’ve amended the file slightly (v 0.3) with the feedback from this thread. I’ve taken a slightly different approach from your diff, removing the $id check, but adding in a line so if no ID is supplied, then the current doc ID is used (although this could be achieved by using [*id*] as the ID parameter to the snippet).

            While it’s awaiting approval in the repository, I’ve attached it here.
              Author: ManagerManager plugin - customise your ModX manager interface

              Rckt - web development, Sheffield, UK
              • 19986
              • 90 Posts
              Hi. I’ve found a bug whereby the wrong variable is used when parent TV specified. Diff on 0.3 below:

              97,98c97,98
              < 		if (substr($input[$f], 0, 7) == 'parent.') {
              < 			$tvname = substr($input[$f], 7);
              ---
              > 		if (substr($tvname, 0, 7) == 'parent.') {
              > 			$tvname = substr($tvname, 7);
              

                • 21056
                • 327 Posts
                Thanks Steph - have updated it in v0.4 and submitted it to the repository.
                  Author: ManagerManager plugin - customise your ModX manager interface

                  Rckt - web development, Sheffield, UK
                  • 34108
                  • 66 Posts
                  Thanks for this very useful snippet ncrossland grin Much appreciated!

                  I am currently trying to use it for a new MODx (Evolution) site, and while it generates the vCard fine it’s not filling the fields with the template variables I’ve assigned.

                  I’ve created a new page in the menu structure called ’vCard template’ which contains the following code:
                  [[vCard? &name=`*full-name*` &email=`*contact*` &organisation=`Camerons Accountants and Advisors` &address_street=`` &address_region=`Tasmania` &address_city=`*office*` &postcode=`` &url=`http://www.camerons-ca.com.au/` &urlParam=`person` ]]
                  


                  Then on each staff profile page I’ve included a link to this page ID. When clicked it generates an eCard in Outlook but none of the dynamic fields are populated (only those which are hard-coded, e.g. the url, show up).

                  I thought this may have something to do with the &urlParam=`person` value? I tried to figure this out by reading the documentation, specifically "...tell the snippet which member of staff we wanted a vCard for by supplying their doc ID as a URL paramater called "person".", but couldn’t work it out sorry.

                  Any help you can give me would be very gratefully received! And thanks again for providing this snippet smiley

                  Thanks
                  Harmony
                    • 21056
                    • 327 Posts
                    Are you linking to the page containing the vCard snippet with the ID of the person whose card you want to display?

                    e.g.

                    /path/to/vcard?person=5

                      Author: ManagerManager plugin - customise your ModX manager interface

                      Rckt - web development, Sheffield, UK
                      • 34108
                      • 66 Posts
                      Quote from: ncrossland at Jun 24, 2010, 07:57 AM

                      Are you linking to the page containing the vCard snippet with the ID of the person whose card you want to display?
                      e.g.
                      /path/to/vcard?person=5

                      Thanks for replying so quickly smiley! I’m just linking to the vcard from a template:

                      <a href="[~60~]">Download vCard</a></li>


                      Do I need to attach ?person= to this, e.g. <a href="[~60~]?person=10">Download vCard</a></li> ? (I tried this but got a 404 error but my syntax may be incorrect).