i want to make this plugin admin only

https://community.elgg.org/plugins/879242 i want to make this plugin's action admin only so i make change in start.php file as below its take all right from non admin user but that start chat,add member link still visiblle to non admin how can hide that??? changed code is highlighted in BOld ,please help me

<?php
/**
 * Chat
 *
 * @package Chat
 */

/**
 * Initialize the plugin.
 */
function chat_init() {
    global $CONFIG;

    $actionspath = $CONFIG->pluginspath . "chat/actions/chat";
    elgg_register_action("chat/save", "$actionspath/save.php",'admin');
    elgg_register_action("chat/addmembers", "$actionspath/addmembers.php",'admin');
    elgg_register_action("chat/leave", "$actionspath/leave.php");
    elgg_register_action("chat/delete", "$actionspath/delete.php",'admin');
    elgg_register_action("chat/message/save", "$actionspath/message/save.php");
    elgg_register_action("chat/message/delete", "$actionspath/message/delete.php");
    elgg_register_action("chat/usersettings/save", "$actionspath/usersettings/save.php",'admin');

    $libpath = elgg_get_plugins_path() . 'chat/lib/chat.php';
    elgg_register_library('chat', $libpath);

    elgg_require_js('chat/chat');

    // Add custom CSS
    elgg_extend_view('css', 'chat/css');

    // Register on low priority so it's possible to remove items added by other plugins
    elgg_register_plugin_hook_handler('register', 'menu:entity', 'chat_entity_menu_setup', 600);
    // Register on low priority so it's possible to remove items added by other plugins
    elgg_register_plugin_hook_handler('register', 'menu:entity', 'chat_message_menu_setup', 600);
    elgg_register_plugin_hook_handler('permissions_check', 'object', 'chat_permissions_override');
    elgg_register_plugin_hook_handler('entity:url', 'object', 'chat_url_handler');

    elgg_register_event_handler('pagesetup', 'system', 'chat_notifier');

    elgg_register_page_handler('chat', 'chat_page_handler');
}

/**
 * Dispatche chat pages.
 *
 * @param array $page
 * @return bool
 */
function chat_page_handler ($page) {
    elgg_load_library('chat');

    if (!isset($page[0])) {
        elgg_push_breadcrumb(elgg_echo('chat'));
        $page[0] = 'all';
    } else {
        elgg_push_breadcrumb(elgg_echo('chat'), 'chat/all');
    }

    switch ($page[0]) {
        case 'messages':
            include(__DIR__ . '/messages.php');
            return true;
        case 'notifier':
            include(__DIR__ . '/notifier.php');
            return true;
        case 'owner':
            $user = get_user_by_username($page[1]);
            $params = chat_all($user->guid);
            break;
        case 'friends':
            $user = get_user_by_username($page[1]);
            $params = chat_friends($user->guid);
            break;
        case 'add':
            gatekeeper();
            $params = chat_edit();
            break;
        case 'edit':
            gatekeeper();
            $params = chat_edit($page[1]);
            break;
        case 'view':
            $params = chat_view($page[1]);
            break;
        case 'members':
            gatekeeper();
            $params = chat_add_members($page[1]);
            break;
        case 'all':
        default:
            $params = chat_all();
            break;
        }

    $body = elgg_view_layout('content', $params);
    echo elgg_view_page('test', $body);
    return true;
}

/**
 * Format and return the URL for chats.
 *
 * @param string $hook   'entity:url'
 * @param string $type   'object'
 * @param string $url    The current URL
 * @param array  $params Array('entity' => ElggObject)
 * @return string URL of the chat
 */
function chat_url_handler($hook, $type, $url, $params) {
    $entity = elgg_extract('entity', $params);

    if (!$entity instanceof ElggChat) {
        return $url;
    }

    $title = elgg_get_friendly_title($entity->title);

    return "chat/view/{$entity->guid}/$title";
}

/**
 * Add title button for adding more people to a chat.
 *
 * All members of the chat are allowed to add people.
 *
 * @todo Is it possible to use userpicker through lightbox?
 *
 * @param obj $entity ElggChat object
 */
function chat_register_addusers_button($entity) {
    if (elgg_is_logged_in()) {
        $user = elgg_get_logged_in_user_entity();

        if ($user && $entity->isMember()) {
            $guid = $entity->getGUID();
            elgg_register_menu_item('title', array(
                'name' => 'chat_members',
                'href' => "chat/members/$guid",
                'text' => elgg_echo('chat:members:add'),
                'link_class' => 'elgg-button elgg-button-action', // elgg-lightbox
            ));
        }

        /*
        elgg_load_js('lightbox');
        elgg_load_css('lightbox');

        elgg_load_js('elgg.userpicker');
        */
    }
}

/**
 * Set up the entity menu for chat entities.
 */
function chat_entity_menu_setup ($hook, $type, $return, $params) {
    if (elgg_in_context('widgets')) {
        return $return;
    }

    $entity = $params['entity'];
    $handler = elgg_extract('handler', $params, false);
    if ($handler != 'chat') {
        return $return;
    }

    $num_messages = $entity->getUnreadMessagesCount();
    if ($num_messages) {
        if ($num_messages == 1) {
            $string = 'chat:unread_message'; // Singular
        } else {
            $string = 'chat:unread_messages'; // Plural
        }

        $text = elgg_echo($string, array($num_messages));

        $options = array(
            'name' => 'unread_mesages',
            'text' => $text,
            'href' => false,
            'priority' => 150,
        );
        $return[] = ElggMenuItem::factory($options);
    }

    // Use white list to prevent unwanted menu items
    $allow = array('unread_mesages');
    if (!elgg_in_context('chat_preview')) {
        $allow[] = 'edit';
        $allow[] = 'delete';
    }

    // Remove unwanted menu items
    foreach ($return as $index => $item) {
        if (!in_array($item->getName(), $allow)) {
            unset($return[$index]);
        }
    }

    return $return;
}

/**
 * Set up the entity menu for chat messages.
 */
function chat_message_menu_setup ($hook, $type, $return, $params) {
    if (elgg_in_context('widgets')) {
        return $return;
    }

    $entity = $params['entity'];

    if ($entity->getSubtype() !== 'chat_message') {
        return $return;
    }

    // We don't want other plugins to add new menu items so we use a white list
    $allow = array('likes');

    $user = elgg_get_logged_in_user_entity();

    if ($entity->getOwnerGUID() == $user->getGUID() || $user->isAdmin()) {
        $guid = $entity->getGUID();

        $options = array(
            'name' => 'edit',
            'text' => elgg_echo('edit'),
            'href' => "#chat-edit-message-$guid",
            'priority' => 100,
            'rel' => 'toggle',
        );
        $return[] = ElggMenuItem::factory($options);

        $options = array(
            'name' => 'delete',
            'text' => elgg_view_icon('delete'),
            'href' => "action/chat/message/delete?guid=$guid",
            'priority' => 150,
            'is_action' => true,
        );
        $return[] = ElggMenuItem::factory($options);

        $allow[] = 'edit';
        $allow[] = 'delete';
    }

    // Remove unwanted menu items
    foreach ($return as $index => $item) {
        if (!in_array($item->getName(), $allow)) {
            unset($return[$index]);
        }
    }

    return $return;
}

/**
 * Display notification of new chat messages in topbar
 */
function chat_notifier() {
    if (elgg_is_logged_in()) {
        // Add hidden popup module to topbar
        elgg_extend_view('page/elements/topbar', 'chat/preview');

        $text = elgg_view_icon('speech-bubble-alt');

        $count = chat_count_unread_messages();
        if ($count) {
            $text .= "<span id=\"chat-messages-new\">$count</span>";
        } else {
            // Add a hidden element so value can be added using XHR
            $text .= "<span id=\"chat-messages-new\" class=\"hidden\"></span>";
        }

        // This link opens the popup module
        elgg_register_menu_item('topbar', array(
            'name' => 'chat-notifier',
            'href' => '#chat-messages-preview',
            'text' => $text,
            'priority' => 600,
            'title' => elgg_echo("chat:messages"),
            'rel' => 'popup',
            'id' => 'chat-preview-link',
        ));
    }
}

/**
 * Get all chats with unread messages.
 *
 * @param array $options See elgg_get_entities_from_annotations().
 */
function chat_get_unread_chats($options = array()) {
    $user = elgg_get_logged_in_user_entity();

    $defaults = array(
        'type' => 'object',
        'subtype' => 'chat',
        'annotation_names' => 'unread_messages',
        'annotation_owner_guids' => $user->getGUID(),
        'count' => false,
    );

    $options = array_merge($defaults, $options);

    return elgg_get_entities_from_annotations($options);
}

/**
 * Get the number of all unread chat messages.
 *
 * @return mixed False on error, int if success.
 */
function chat_count_unread_messages() {
    $user_guid = elgg_get_logged_in_user_guid();

    return elgg_get_entities_from_relationship(array(
        'type' => 'object',
        'subtype' => 'chat_message',
        'count' => true,
        'relationship' => 'unread',
        'relationship_guid' => $user_guid,
        'inverse_relationship' => true,
    ));
}

/**
 * Allow chat members to add messages to chat.
 */
function chat_permissions_override($hook, $type, $return, $params) {
    $entity = $params['entity'];
    $user = $params['user'];

    if (elgg_instanceof($entity, 'object', 'chat')) {
        // Allow full access to administrators
        if ($user->isAdmin()) {
            return true;
        }

        // Allow chat members to add messages to chat
        if ($entity->isMember($user) && elgg_in_context('chat_message')) {
            return true;
        }
    }

    return $return;
}

elgg_register_event_handler('init', 'system', 'chat_init');

  • ionly what im try to do with this plugin is make it as chatroom for whole website i want to join user automatically in chat when they register ,and i found your plugin groupAutosubcribe which allow same functionality for the group i try with chat but it's give blank page when  new user register can you give me some guidance regarding this so i  can use auto join for chat same as group :) 

  • Possibly works with a plugin hook callback function like this:

    function autosubscribechat_join($event, $object_type, $object) {

        if (($object instanceof ElggUser) && ($event == 'create') && ($object_type == 'user')) {
            //auto submit relationships between user & chat
            //retrieve chat ids from plugin
            $chats = elgg_get_plugin_setting('systemchats', 'autosubscribechat');
            $chats = split(',', $chats);

            $ia = elgg_set_ignore_access(true);

            foreach($chats as $chatID) {
                $chatEnt = get_entity($chatID);

                if ($chatEnt) {
                    $entity->addMember($object->getGUID());
                }
            }
            elgg_set_ignore_access($ia);
        }
    }

    You would have to adjust the rest of the Autosubscribegroup plugin accordingly to be able to define the chat ids a user should be auto-joined via plugin settings.

    I've not tested the code and I don't know much details about the Chat plugin to be able to judge if it's really a good idea to create a site-wide chat like this. I imagine it could get problematic if many users are sharing a chat session with regards to server load. I also don't know about leaving / re-joining options: can a user leave a chat session if not interested and is it possible for a user to join a chat session again later - without being invited?

  • where i have to place above code?? in start.php of aurisubcribe gorup??if yes then do i need to remove all other function from start.php????

  • I imagine it could get problematic if many users are sharing a chat session with regards to server load. I also don't know about leaving / re-joining options: can a user leave a chat session if not interested and is it possible for a user to join a chat session again later - without being invited?

    i dont think that it will load on server because its a same as posting blog and get comment from user ,you just need to create chat and invite freinds they can comment simple :) yes they can leave if they are not intrested ,but if they want to join again they have to request admin for it :) actually   i made wesite for reunion we had freind group on one wesite which is shutdown and i found elgg which is similar to that website (which is shutdown) so i think this is best way to get my freinds back only thing i need is chatroom and i find this plugin which is same as chatroom :)

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking