We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49469
    • 3 Posts
    Hi all, thank you for the best cms and for a great support community.
    This is my first post and I would like to ask if anyone has succeeded in passing the web user username from modx to yshout.
    Running modx evo 1.0.14

    This should be easy but I can't seem to find a way. I'm looking for the right place to put the username placeholder.

    Two places where it could be are:

    1) yshout.class.php

    	function post($nickname, $message) {
    		global $prefs;
    
    		if ($this->banned(ip()) /* && !$this->admin*/) return false;
    
    		if (!$this->validate($message, $prefs['messageLength'])) return false;
    		if (!$this->validate($nickname, $prefs['nicknameLength'])) return false;
    
    		$message = trim(clean($message));
    		$nickname = trim(clean($nickname));
    		
    		if ($message == '') return false;
    		if ($nickname == '') return false;
    		
    		$timestamp = ts();
    		
    		$message = $this->censor($message);
    		$nickname = $this->censor($nickname);
    		
    		$post = array(
    			'nickname' => $nickname,
    			'message' => $message,
    			'timestamp' => $timestamp,
    			'admin' => $this->admin,
    			'uid' => md5($timestamp . ' ' . $nickname),
    			'adminInfo' => array(
    				'ip' => ip()
    			)
    		);
    
    		$s = $this->storage->open(true);
    
    		$s['posts'][] = $post;
    
    		if (sizeof($s['posts']) > $prefs['history']) 
    			$this->truncate($s['posts']);
    
    		$s['info']['latestTimestamp'] = $post['timestamp'];
    
    		$this->storage->close($s);
    		$this->postProcess($post);
    		return $post;
    	}


    2) preferences.php

    <?
    	// If you want to change the nickname, the line below is the one to modify.
    	// Simply set $overrideNickname to whatever variable you want to appear as the nickname,
    	// or leave it null to use the set nicknames.
    	
    	$overrideNickname = null;
    
    	
    	$storage = 'FileStorage';
    	
    	function loadPrefs() {
    		global $prefs, $storage, $null;
    		$s = new $storage('yshout.prefs');
    		$s->open();
    		$prefs = $s->load();
    		$s->close($null);
    	}
    
    	function savePrefs($newPrefs) {
    		global $prefs, $storage;
    
    		$s = new $storage('yshout.prefs');
    		$s->open(true);
    		$s->close($newPrefs);
    		$prefs = $newPrefs;
    	}
    	
    	function resetPrefs() {
    		$defaultPrefs = array(
    			'password' => '123',								// The password for the CP
    
    			'refresh' => 6000,										// Refresh rate
    
    			'logs' => 5,											// Amount of different log files to allow
    			'history' => 200,										// Shouts to keep in history
    
    			'inverse' => false,										// Inverse shoutbox / form on top
    
    			'truncate' => 15,										// Truncate messages client-side
    			'doTruncate' => true,									// Truncate messages?
    
    			'timestamp' => 12,										// Timestamp format 12- or 24-hour
    
    			'defaultNickname' => 'Nickname',
    			'defaultMessage' => 'Message Text',
    			'defaultSubmit' => 'Shout!',
    			'showSubmit' => true,
    			
    			'nicknameLength' => 25,
    			'messageLength' => 175,
    
    			'nicknameSeparator' => ':',
    			
    			'flood' => true,
    			'floodTimeout' => 5000,
    			'floodMessages' => 4,
    			'floodDisable' => 8000,
    			'floodDelete' => false,
    			
    			'autobanFlood' => 0,									// Autoban people for flooding after X messages
    
    			'censorWords' => 'fuck shit bitch ass',
    			
    			'postFormLink' => 'history',
    
    			'info' => 'inline'
    		);
    
    		savePrefs($defaultPrefs);
    	}
    	
    	// resetPrefs();
    	loadPrefs();
    
    ?>
    


    Thanks in advance! [ed. note: didobb last edited this post 9 years, 5 months ago.]
      • 4041
      • 788 Posts
      No promise but maybe try this:

      $overrideNickname = $_SESSION['webShortname'];
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 49469
        • 3 Posts
        Quote from: breezer at Dec 04, 2014, 04:53 PM
        No promise but maybe try this:

        $overrideNickname = $_SESSION['webShortname'];

        Thank you breezer, I've already tried this but it breaks the plugin and the shoutbox doesn't show up.

        I have this snippet that brings up a web user's username [[username]]:

        <?php
        $short_name  = $_SESSION['webShortname'];
        return $short_name;
        ?>


        Is there a way to embed this snippet inside the yshout php code?
        Because doing this still breaks the plugin:

        $overrideNickname = $_SESSION['webShortname'];
        	return $overrideNickname;
        [ed. note: didobb last edited this post 9 years, 5 months ago.]
          • 4041
          • 788 Posts
          Maybe create a snippet to define a constant would work. Make the following a snippet and call it at the top of your template before any yshout call.

          define( "MODX_WEBUSER", $_SESSION['webShortname'] );


          Then in your yshout script:

          $overrideNickname = MODX_WEBUSER;

            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 49469
            • 3 Posts
            Thanks again breezer but same thing happens, the plugin breaks and is not displayed at all.

            Both above ways should work though, there must be something else breaking it.

            Should I post any more files here to investigate it further?