Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Username to another application

edited September 2006 in Vanilla 1.0 Help
Sorry to bug all of you with this, but I've spent 15 hours trying to get this to work to no avail.

I'm trying to use an application called yshout to create a shoutbox in the panel.

I've got everything the way it should be but, but I can't get the friggin nickname to be populated by the Vanilla username.

This is the code (I think) in yshout that sets the username:

<? class YShout { function YShout($path, $admin = false) { global $storage; // Redo to check for folders or just not break, because nonextant files should be allowed. // if (!file_exists($path)) error('That file does not exist.'); $this->storage = new $storage($path, true); $this->admin = $admin; } function posts() { global $null; $this->storage->open(); $s = $this->storage->load(); $this->storage->close($null); if ($s) return $s['posts']; } function info() { global $null; $s = $this->storage->open(true); $this->storage->close($null); if ($s) return $s['info']; } function postsAfter($ts) { $allPosts = $this->posts(); $posts = array(); /* for ($i = sizeof($allPosts) - 1; $i > -1; $i--) { $post = $allPosts[$i]; if ($post['timestamp'] > $ts) $posts[] = $post; } */ foreach($allPosts as $post) { if ($post['timestamp'] > $ts) $posts[] = $post; } $this->postProcess($posts); return $posts; } function latestPosts($num) { $allPosts = $this->posts(); $posts = array_slice($allPosts, -$num, $num); $this->postProcess($posts); return array_values($posts); } function hasPostsAfter($ts) { $info = $this->info(); $timestamp = $info['latestTimestamp']; return $timestamp > $ts; } 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 = clean($message); $nickname = clean($nickname); $post = array( 'nickname' => $nickname, 'message' => $message, 'timestamp' => ts(), 'admin' => $this->admin, '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; } function truncate(&$array) { global $prefs; $array = array_slice($array, -$prefs['history']); $array = array_values($array); } function clear() { global $null; $this->storage->open(true); $this->storage->resetArray(); $this->storage->close($nulls); } function bans() { global $storage, $null; $s = new $storage('yshout.bans'); $s->open(); $bans = $s->load(); $s->close($null); return $bans; } function ban($ip, $reason = '') { global $storage; $s = new $storage('yshout.bans'); $bans = $s->open(true); $bans[] = array( 'ip' => $ip, 'reason' => $reason, 'timestamp' => ts() ); $s->close($bans); } function banned($ip) { global $storage, $null; $s = new $storage('yshout.bans'); $bans = $s->open(true); $s->close($null); foreach($bans as $ban) if ($ban['ip'] == $ip) return true; return false; } function unban($ip) { global $storage; $s = new $storage('yshout.bans'); $bans = $s->open(true); foreach($bans as $key=>$value) if ($value['ip'] == $ip) { unset($bans[$key]); } $bans = array_values($bans); $s->close($bans); } function unbanAll() { global $storage, $null; $s = new $storage('yshout.bans'); $s->open(true); $s->resetArray(); $s->close($null); } function validate($str, $maxLen) { return len($str) <= $maxLen; } function postProcess(&$post) { if (isset($post['message'])) { if ($this->banned($post['adminInfo']['ip'])) $post['banned'] = true; if (!$this->admin) unset($post['adminInfo']); } else { foreach($post as $key=>$value) { if ($this->banned($value['adminInfo']['ip'])) $post[$key]['banned'] = true; if (!$this->admin) unset($post[$key]['adminInfo']); } } } } ?>

I've tried to include

include('../appg/settings.php'); include('../appg/init_ajax.php');

both within the function and before the class, then use

$name = $Context->Session->User->Name;

to call the name and put it into the post function to assign the nick

$nickname = $Context->Session->User->Name;

But everytime I try to include anything, it breaks the application. I'm phpilliterate so I have no idea what's going on. It seems like because it's a class, the call is breaking the function and/or the class.

If anyone has any ideas, or can help in any way-- I'd much appreciate it.




  • Options
    I just downloaded it to see if I could help. I have it installed locally and I can get into the admin. Did you add the js script code from their site to the header file?
  • Options
    Yeah... I have the chat all up and functioning. It looks and works like I want, except for the Username part. All's I need is to get the username [$Context->Session->User->Name;] to automatically insert itself into the Nickname box in the chat.

    In other words, I just need it so that people that are logged in have their names already in the Nickname part of the chat so if they post in the shoutbox their name is already there. I have taken out the Nickname input box... I don't want people abusing it and using other peoples names.

    Thanks for trying to help... it's appreciated :)
  • Options
    OK, still no luck.

    I'm wondering if it'd be easier to just have Vanilla set the cookie that the chat reads when people log in?

    I've looked and searched, but I can't seem to find where Vanilla does it's cookie setting.

    Is this possible? Does anyone have any pointers or hints as to where to look?

  • Options
    edited September 2006
    You have to add $Context to the class property:
    class YShout { var $Context; function YShout($context, $path, $admin = false) { global $storage; // Redo to check for folders or just not break, because nonextant files should be allowed. // if (!file_exists($path)) error('That file does not exist.'); $this->storage = new $storage($path, true); $this->admin = $admin; $this->Context = $Context; }...
    And then use $this->Context->Session->User->Name;
  • Options
    OK (again), I think I've got it...

    I created an extension that calls the javascript that loads the yshout box into the panel... I just needed to add a setcookie in there to set the cookie to be used by yshout.

    $nick = $Context->Session->User->Name; setcookie ("yNickname", $nick, time()+604800); $Head->AddScript("yshout/js/jquery.js"); $Head->AddScript("yshout/js/yshout.js"); $Head->AddStyleSheet("yshout/css/yshout.css"); $Head->AddScript("js/yshout.js"); ?>

    Hope this helps someone in the future.

  • Options

    Thanks Dinoboff, much appreciated. Though, it does seem to be working with the cookie, and I've been on this for ~20 hours (n00b), so right now I'm going to very gently close my ftp program, text editor, and go have a smoke or 10.

    Thanks again.

  • Options
    Smoking is not good for your health. Have a glass of wine or 2 or 3, instead.

    When you make your extension for this, I'd be happy to test it.
  • Options
    edited September 2006
    No problem ;-)
  • Options
    @jimw added it to the addons. Good luck getting it to work ;)

    Seriously. Good luck.
  • Options
    I just downloaded and followed all the steps. They were very clear. Unfortunately, I see the Shout Title and the History button, but nothing else. What did I miss?
  • Options
    That was buggerin me too when I tested it...

    Make sure that you put the yshout.js that is in the root of the zip in the vanilla/js folder.
  • Options
    Yep, it's there. Does the path in it have to change?
  • Options
    it's really buggy.. try refreshing a few times and give it a second to load.

    I'll work on it a bit more when I get home from work.

    sometimes it stays shrunk, but then pops open after a second...
  • Options
    also... make sure to chmod the logs folder and all of the contents individually. just had that cause the error you're describing.

    though, it still seems to be acting funny. from time to time it won't load for some reason, and just sits there with the title and link...

    too bad I have no idea what I'm doing :(
This discussion has been closed.