We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27751
    • 45 Posts
    Thanks brezzer! That absolutely did the trick.

    Thanks everyone for trying to help. Some notes that are worth mentioning because I, as a newbie, went through some circles here. First, if you ask in the install instructions to use the Snippet name "Personalize" don’t in the Example Usage call it as "LoggedOrNot":

    [[LoggedOrNot? &yesChunk=`Link` &noChunk=`Register` &ph=`name`]]

    I know that seems silly to you and that I should know that LoggedOrNot is the call to the Snippet and so the Snippet name must be the same, but a little help PLEASE. Things you take for granted are not so obvious to a newbie.

    You might also stay consistent on the forum with the variable names. Notice &ph=`name` in the example but &ph=`username` was used as an example on the forum. I feel like a prick pointing this out, and I am in no way trying to insult anyone (actually it is my own ignorance exposed), but it would make it easier for newbies to catch on if it were consistent.
      Dedicated CENTOS 5.5 x86_64 standard WHM 11.28.64
      Apache/2.2.17 | PHP/5.2.15
      MySQL Version 5.0.91 | MODx Revolution
      • 32645
      • 377 Posts
      How do I prevent Personalise 2.0 from redirecting?

      I put this call onto my ’private page’, but it keeps redirecting!

      [[LoggedOrNot? &yesChunk=`chk.yesLoggedIn` &noChunk=`chk.notLoggedin`]]
      


      I don’t want it to redirect, I want it to show my messsage/chunk instead.
        • 25046
        • 194 Posts
        I would like to automatically display a "Log Out" link for the yesChunk when a user is logged in. Is there any standard code that will work for me for this? Thanks!
          • 33014 ☆ A M B ☆
          • 1,231 Posts
          I have improved personalizing snippet.

          //<?php
          /**
           * Personalize
           * 
           * Personalize snippet
           *
           * @category 	snippet
           * @version 	2.1
           * @license 	http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
           * @internal	@properties 
           * @internal	@modx_category Login
           * @author  	Created By Ryan Thrash ([email protected])
           * @author  	powered up by kudo ([email protected])
           * @author  	powered up by yama([email protected])
           */
          
          #::::::::::::::::::::::::::::::::::::::::
          # Created By:Ryan Thrash ([email protected]), 
          #	and then powered up by kudo ([email protected])
          #
          # Date: Aug 03, 2006
          #
          # Changelog: 
          # Dec 01, 05 -- initial release
          # Jun 19, 06 -- updated description
          # Jul 19, 06 -- hacked by kudo to output chunks
          # Aug 03, 06 -- added placeholder for username
          # Aug 27, 10 -- powered up all code
          #
          #::::::::::::::::::::::::::::::::::::::::
          # Description: 	
          #	Checks to see if webusers are logged in and displays yesChunk if the user
          #	is logged or noChunk if user is not logged. Insert only the chunk name as
          #	param, without {{}}. Can use a placeholder to output the username.
          #	TESTED: can be used more than once per page.
          #	TESTED: chunks can contain snippets.
          #	
          #	
          # Params:
          #	&yesChunk [string] (optional)
          #		Output for LOGGED users
          #
          #	&noChunk [string] (optional)
          #		Output for NOT logged users
          #
          #	&ph [string] (optional) 
          #		Placeholder for placing the username
          #		ATTENTION!: place this ph only in yesChunk!
          #	
          #	&context [string] (optional) 
          #		web|mgr
          #
          #	&yesTV [string] (optional)
          #		Output for LOGGED users
          #
          #	&noTV [string] (optional)
          #		Output for NOT logged users
          #
          # Example Usage:
          #
          #	[[Personalize? &yesChunk=`Link` &noChunk=`Register` &ph=`name`]]
          #
          #	Having Chunks named {{Link}} and another {{Register}}, the first will be
          #	published to registered user, the second to non-registered users.
          #
          #::::::::::::::::::::::::::::::::::::::::
          
          # prepare params and variables
          
          if     ($this->isFrontend() && isset ($_SESSION['webValidated'])) $current_context = 'web';
          elseif ($this->isBackend()  && isset ($_SESSION['mgrValidated'])) $current_context = 'mgr';
          
          $output = '';
          $yesChunk = (isset($yesChunk))? $yesChunk : '';
          $noChunk  = (isset($noChunk)) ? $noChunk  : '';
          $ph       = (isset($ph))      ? $ph       : 'username';
          $context  = (isset($context)) ? $context     : $current_context;
          $yesTV    = (isset($yesTV))   ? $yesTV : '';
          $noTV     = (isset($noTV))    ? $noTV  : '';
          
          /*
          $referer = htmlspecialchars($_SERVER['HTTP_REFERER'], ENT_QUOTES);
          $ua =      htmlspecialchars($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES);
          $ip =      htmlspecialchars($_SERVER['REMOTE_ADDR'], ENT_QUOTES);
          $host =    htmlspecialchars($_SERVER['REMOTE_HOST'], ENT_QUOTES);
          
          $ua_strtolower = strtolower($_SERVER['HTTP_USER_AGENT']);
          if    (strpos($ua_strtolower, 'firefox') !== false)     $browser = 'firefox';
          elseif(strpos($ua_strtolower, 'trident/4.0') !== false) $browser = 'internet explorer 8';
          elseif(strpos($ua_strtolower, 'msie') !== false)        $browser = 'internet explorer';
          elseif(strpos($ua_strtolower, 'chrome') !== false)      $browser = 'chrome';
          elseif(strpos($ua_strtolower, 'safari') !== false)      $browser = 'safari';
          elseif(strpos($ua_strtolower, 'opera') !== false)       $browser = 'opera';
          else $browser = 'other';
          
          $modx->setPlaceholder('referer', $referer);
          $modx->setPlaceholder('ua',      $ua);
          $modx->setPlaceholder('browser', $browser);
          $modx->setPlaceholder('ip',      $ip);
          $modx->setPlaceholder('host',    $host);
          */
          
          switch($context)
          {
              case 'web':
                  $short_name = $_SESSION['webShortname'];
                  $full_name  = $_SESSION['webFullname'];
                  $email      = $_SESSION['webEmail'];
                  $last_login = $_SESSION['webLastlogin'];
                  break;
              case 'mgr':
              case 'manager':
                  $short_name = $_SESSION['mgrShortname'];
                  $full_name  = $_SESSION['mgrFullname'];
                  $email      = $_SESSION['mgrEmail'];
                  $last_login = $_SESSION['mgrLastlogin'];
                  break;
              default:
                  $short_name = '';
          }
          if (!empty($context))
          {
              if($yesTV !== '')
              {
                  $pre_output = $modx->documentObject[$yesTV];
                  if(is_array($pre_output))
                  {
                      $output = $pre_output[1];
                  }
                  else
                  {
                      $output = $pre_output;
                  }
              }
              elseif($yesChunk !== '')
              {
                  $output = $modx->getChunk($yesChunk);
              }
              else
              {
                  $output = 'username : ' . $short_name;
              }
              
              if(empty($last_login)) $last_login_text = 'first login';
              else                   $last_login_text = $modx->toDateFormat($last_login);
              
              $modx->setPlaceholder($ph,$short_name);
              $modx->setPlaceholder('short_name',  $short_name);
              $modx->setPlaceholder('full_name',   $full_name);
              $modx->setPlaceholder('email',       $email);
              $modx->setPlaceholder('last_login', $last_login_text);
          }
          else
          {
              if($noTV !== '')
              {
                  $pre_output = $modx->documentObject[$noTV];
                  if(is_array($pre_output))
                  {
                      $output = $pre_output[1];
                  }
                  else
                  {
                      $output = $pre_output;
                  }
              }
              elseif($noChunk!=='')
              {
                  $output = $modx->getChunk($noChunk);
              }
              else
              {
                  $output = 'guest';
              }
          }
          return $output;
          


          [+username+]
          [+short_name+]
          [+full_name+]
          [+email+]
          [+last_login+]