1

I'm new to writing Joomla plugins so bear with me.

I wanted to create a poke like feature for the Joomla 1.5 Community Builder. When I click on the poke-button of a user, I want this user and only this user to get a notification (or being able to see that he has been poked). How do I do that?

This is the plugin I did so far: cb_poke.php

<script language="javascript" type="text/javascript">
    function pokeMe() 
    {
        var div = document.getElementById("dom-target");
        var myData = div.textContent;

        alert(myData+' poked!');

        return false;
    }
</script>

<div id="dom-target" style="display: none;">
    <?php 
        $user = JFactory::getUser();
        $theUserName='test user';

        if (!$user->guest) {
          $theUserName= $user->username;
        }

        echo htmlspecialchars($theUserName);
    ?>
</div>

<?php

// No direct access allowed to this file
defined( '_JEXEC' ) or die( 'Restricted access' );

// Import Joomla! Plugin library file
jimport('joomla.plugin.plugin');


class getTab extends cbTabHandler 
{

    function getTab() 
    {
        $this->cbTabHandler();
    }

    function getDisplayTab($tab,$user,$ui) 
    {

        $return = null;

        $params = $this->params; // get parameters (plugin and related tab)

        $is_plug_enabled = $params->get('hwPlugEnabled', "1");
        $tab_message = $params->get('hwTabMessage', "Hi there! :)");

        if ($is_plug_enabled != "0") 
        {
            if($tab->description != null) 
            {
                $return .= "\t\t<div class=\"tab_Description\">"
                    . $tab->description // html content is allowed in descriptions
                    . "</div>\n";
            }
            $return .= "\t\t<div>\n"
                . "<p>"
                . htmlspecialchars($tab_message) // make all other output html-safe
                . "</p>"
                . "</div>\n"
                . "<form><input type='Button' value='Poke' id='pokeButton' onclick='pokeMe()'></input></form>";
        }

        return $return;
    } 
} 
?>

When I click on the poke button it returns an alert saying: "[username] poked!". [username] is the user who clicked on the poke button. So far this works. Now I want this message to be passed to the user profile I just poked.

I tried with JFactory::getApplication()->enqueueMessage('Poke message'); but that only means I get notified not the other user.

  • Something like this would either require an Ajax request and additional database table, OR a websocket but I've never used websocket before :/ – Lodder Dec 23 '14 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.