Skip to main content
Topic: Missing Hooks (Read 1642 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Missing Hooks

For my Addon ElkArte Ajax Chat, missing Hooks for Load.php, SSI.php and BoardIndex.template.php.

Code: (xml) [Select]
<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.elkarte.net/site/modification">
<!--
/**
 * ElkArte Ajax Chat
 *
 * @author  wintstar
 * @license BSD http://opensource.org/licenses/BSD-3-Clause
 * @license Bluimp's AJAX Chat is released under a Modified MIT License (MIT) https://raw.githubusercontent.com/Frug/AJAX-Chat/master/chat/license.txt
 *
 * @version 1.0.1
 */
-->
<modification xmlns="http://www.elkarte.net/site/modification" xmlns:elk="http://www.elkarte.net/">
    <id>wintstar:ElkAjaxChat</id>
    <version>1.0.1</version>

    <file name="BOARDDIR/SSI.php">
        <operation>
            <search position="end" />
            <add><![CDATA[

function ssi_talkInside($output_method = 'echo')
{
    global $scripturl, $txt, $user_info, $modSettings;

    $db = database();

    $users = array();
    $userIDs = talkInsideUsers();
    $users['links'] = array();
    if (count($userIDs) > 0){
        if (count($userIDs) == 1){
            $request = $db->query('', '
                SELECT mem.ID_MEMBER, mem.real_name, mem.ID_GROUP, mg.online_color, mg.ID_GROUP
                    FROM    {db_prefix}members AS mem
                    LEFT JOIN {db_prefix}membergroups AS mg ON
                    (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP)) WHERE mem.ID_MEMBER = {int:the_id}' ,
                array(
                    'the_id' => $userIDs[0],
                    )
                );
            }else{
                $request = $db->query('', '
                    SELECT mem.ID_MEMBER, mem.real_name, mem.ID_GROUP, mg.online_color, mg.ID_GROUP
                        FROM    {db_prefix}members AS mem
                        LEFT JOIN {db_prefix}membergroups AS mg ON
                        (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP)) WHERE mem.ID_MEMBER IN ({array_int:the_ids})',
                    array(
                        'the_ids' => $userIDs,
                    )
                );
            }
            while ($row = $db->fetch_assoc($request))
                {
                $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'];
                if($row['online_color'] != ""){
                    $link.= '" style="color: ' . $row['online_color'];
                }
                $link.= '">' . $row['real_name'] . '</a>';
                array_push($users['links'], $link);
                }
            $db->free_result($request);
    }
    if ($output_method != 'echo')
        return $users;
    else{
        if (count($users['links']) == 0 )
            echo $txt['chat_no_user'];
        elseif (count($users['links']) == 1 )
            echo '1' . $txt['chat_aUser']. ':<br />', implode($users['links']);
        else
            echo count($users['links']). $txt['chat_users']. ':<br />', implode(', ', $users['links']);
        }
}]]></add>
        </operation>
    </file>
    <file name="SOURCEDIR/Load.php">
        <operation>
            <search position="end" />
            <add><![CDATA[
function getShoutBoxContent(){
    global $scripturl, $modSettings;

    // Get the URL to the chat directory:
    if (!defined('AJAX_CHAT_URL')){
            define('AJAX_CHAT_URL', str_replace("index.php", "talk/", $scripturl));
    }

    // Get the real path to the chat directory:
    if (!defined('AJAX_CHAT_PATH')){
            define('AJAX_CHAT_PATH', dirname(dirname(__FILE__)) . '/talk/');
    }

    // Validate the path to the chat:
    if (@is_file(AJAX_CHAT_PATH . 'lib/classes.php')){
        // Include Class libraries:
        require_once(AJAX_CHAT_PATH.'lib/classes.php');

        // Initialize the shoutbox:
        $ajaxChat = new CustomAJAXChatShoutBox();

        // Parse and return the shoutbox template content:
        return $ajaxChat->getShoutBoxContent();
    }
    return null;
}

function talkInsideUsers(){

    $db = database();

    $userIDs = array();
    $request = $db->query('', '
        SELECT userID
            FROM {db_prefix}chat_online    WHERE NOW() <= DATE_ADD(dateTime, interval 2 MINUTE)' ,
        array()
    );
    while ($row = $db->fetch_assoc($request)) {
        array_push($userIDs, $row['userID']);
        }
    $db->free_result($request);
    return array_unique($userIDs);
}]]></add>
        </operation>
    </file>
    <file name="THEMEDIR/BoardIndex.template.php">
        <operation>
            <search position="replace"><![CDATA[function template_boardindex_outer_above()
{
    global $context, $settings, $txt;]]></search>
            <add><![CDATA[function template_boardindex_outer_above()
{
    global $context, $modSettings, $settings, $txt;

    if (!empty($modSettings['talk_chatEnable'])){
        template_inc_talk_aboveIndex();
    }]]></add>
        </operation>
        <operation>
            <search position="replace"><![CDATA[function template_info_center()
{
    global $context, $txt;]]></search>
            <add><![CDATA[function template_info_center()
{
    global $context, $modSettings, $txt;

    if (!empty($modSettings['talk_chatEnable'])){
        template_inc_talk_belowIndex();
    }]]></add>
        </operation>
        <operation>
            <search position="replace"><![CDATA[        if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
            echo '
                <p class="inline membergroups">[' . implode(',&nbsp;', $context['membergroups']) . ']</p>';
    }
    echo '
            </li>';]]></search>
            <add><![CDATA[        if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
            echo '
                <p class="inline membergroups">[' . implode(',&nbsp;', $context['membergroups']) . ']</p>';
    }
    echo '
            </li>';

    if (!empty($modSettings['talk_chatEnable'])){
        template_inc_talk_userInside();
    }]]></add>
        </operation>
    </file>
</modification>

Can it create Hooks for that? It would be easy to use for update with new Forums Version.


Regards Stephan

Re: Missing Hooks

Reply #1

You only need a hook to call a function or change a value. You don't need one to add a function.

Don't add functions to files. There's no point. Just put them in their own file.

Re: Missing Hooks

Reply #2

Very good idea :)  How can I then add these functions as the Hook? Is there then it Hooks?


Regards Stephan