We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15980
    • 3 Posts
    Hi-ho,

    My first post to the forums, I’ve been using modx for a while and this is the first snippet/module I’ve written that I thought might be of use to someone else. wink

    You can see it in use here: http://www.trash.co.nz it’s on the bottom of most pages.

    I used the site spec arrray from a wordpress plugin, which gives it support for 99 different bookmarking services.

    You can see the full set of them on this page: http://www.trash.co.nz/projects/social-bookmarking.html

    It’s implemented in a single class, so with a little bit of fiddling you could use it anywhere.

    There’s a readme file in the tar file, and hopefully there are enough comments in my code for someone else to follow it. Then again my coding isn’t the greatest on the planet, and this was partially an exercise in learning php Objects rather than bashing out everything procedurally, so the comments might not help! smiley

    My Environment: php5.2.6, apache 2, modx 1.0.3

    Cheers, Chris H.

    note: Source files are linked off the demo page..
      • 26931
      • 2,314 Posts
      Hi Chris,

      thanks for sharing your Snippet! smiley
        • 20413
        • 2,877 Posts
        Cool! cool
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 15980
          • 3 Posts
          OK, updated it to version 0.2 laugh

          Found that some of the definitions I used from the original wordpress plugin gave cruddy HTML.

          http://www.trash.co.nz/projects/social-bookmarking.html now validates using htmltidy and the wc3 validator...

          I also put a link to the tgz file onto that page on my site, and added a simple change log.

          Enjoy...

          Cheers, Chris H.
            • 12379
            • 460 Posts
            Nice one!
              Mostly harmless.
              • 1122
              • 209 Posts
              Hi all,
              this post is my small contribution to development of this nice tool (many thanks, Chris, for sharing).

              While installing and fine-tuning this snippet on my site I noticed that one thing in it might be generalized.

              The easiest way for installing this social bookmarking tool is calling a snippet on page template thus automatically rendering it on all pages (using that specific template). However, from the point of view of page template it is not known whether the actual page is publicly accessible (and therefore may be shared) or is weblogin secured (sharing is pointless). I’ve added at the beginning of the snippet small piece of code that checks the status of a page to be shared -- if it appears that page is not publicly accesible, then execution is terminated with empty output (no links are rendered).

              Added code is marked with #### ... ## The rest of changes is pure cosmetics.
              <?php
              /*
               Social Bookmarking snippet, v. 0.2
               ... author + parameter info ...
              */
              
              #### determine page to be shared
              $pgID = isset($pgID) ? $pgID : $modx->documentObject['id'];
              $pgObj = $modx->getDocument($pgID, 'longtitle,introtext,privateweb');
              if ($pgObj['privateweb']) { // page is not publicly accessible
                  // there is no point to render anything
                  return '';
              }
              ## else -> public page; do what is required...
              
              // include the main class file, create object
              include_once($modx->config['base_path'] . 'assets/snippets/social/class.php');
              $Social_links = new SocialBookmarks;
              
              // settings, just set
              $Social_links->ImagePath = '/assets/snippets/social/images/'; // path to images, trailing slash
              $Social_links->SiteName = $modx->config['site_name']; // site name from config, replace it with a string if you want
              // $Social_links->FeedLink = '/rss.xml'; // path to RSS feed, defaults to /rss.xml
              // $Social_links->DEBUG = TRUE;  // Debug=True puts a bold heading before each icon; defaults to FALSE
              // $Social_links->ExcerptSize = 250; // excerpt size; default is 250 characters
              
              // settings; pick up page info by default, or use parameters...
              $Social_links->PageTitle = isset($pgTitle) ? $pgTitle : $pgObj['longtitle']; // long title used for the description
              $Social_links->PageExcerpt = isset($pgExcerpt) ? $pgExcerpt : $pgObj['introtext']; // page excerpt, used for summary on some services (linkedin for e.g.)
              $Social_links->PageLink = $modx->makeUrl($pgID, '', '', 'full');
              if (isset($TagLine)) {
                  // text that goes above icons; defaults to 'Share'
                  $Social_links->TagLine = $TagLine;
              }
              
              // set up which services get shown, and the order
              // use method $Social_links->ShowServices(); to create the default array, then edit it
              $Services = array(
              	'BarraPunto',
              	// ...
              	// ...
              	// ...
              	'Diggita',
              );
              
              
              return $Social_links->render($Services);
              ?>
              
                • 26931
                • 2,314 Posts
                this post is my small contribution to development of this nice tool
                thanks for sharing! smiley
                  • 15980
                  • 3 Posts
                  Hi-ho,

                  Thanks for that.... I’ve updated the snippet.php in the archive on my site and put a link to the forums in changelog. So we’re now on version 0.3. smiley

                  And, totally unrelated to this I’ve just had a debate with someone about the syntax for if() when there is only one statement after the if....

                  ie:

                  you changed:

                  if(isset($TagLine)) $Social_links->TagLine=$TagLine;  // Text that goes above icons. Defaults to 'Share'


                  to be:

                  if(isset($TagLine)) {
                  	// Text that goes above icons. Defaults to 'Share'
                  	$Social_links->TagLine=$TagLine;
                  }


                  I was fairly certain I preferred single-line for single statement, but now I’m thinking one of the other options is more readable. Hmmm.

                  Maybe:
                  if(isset($TagLine)) 	// Text that goes above icons. Defaults to 'Share'
                  	$Social_links->TagLine=$TagLine;
                  


                  Too many options... grin

                  Cheers, Chris H.
                    • 1122
                    • 209 Posts
                    Syntax for if is an issue of your preference. I am following "old school" (inherited from my masters) -- do braces block even if it includes single statement, it is readable, and ready-to-go in the case you need to include more statement into it.
                      • 20413
                      • 2,877 Posts
                      I do
                      if ($var == 'yes') { $output = 'ABC'; } else { $output = '123'; }
                        @hawproductions | http://mrhaw.com/

                        Infograph: MODX Advanced Install in 7 steps:
                        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower