e107help.org Q&A
0 like 0 dislike

Hey guys,

i need help about my old shortcode for forum. In e107 v1 used all time the shortcode {FORUM_WHOISONLINE}. How this work in e107 v2.x?

——————

// file forum_whoisonline.sc

if( !defined('e_TRACKING_DISABLED') && e_PAGE == 'forum_viewtopic.php')

{

    global $listuserson, $post_info;

    if (is_array($post_info))

    {

        if(varset($listuserson[$post_info['user_id'].'.'.$post_info['user_name']]))

        {

            return '<img src="https://xxx.de/themes/xxx/images/online-button.png" width="150" height="29" />';

        }

        else

        {

            return '<img src="https://xxx.de/themes/xxx/images/offline-button.png" width="150" height="29" />';

        }

    }

}

e107 version Latest from Github
asked in Plugins by (12 points) 1 2 5

4 Answers

0 like 0 dislike
Since code base has changed a lot from the time of v1 it would be a good idea to go through the e107_plugins/forum/forum_class.php and the forum shortcodes to get an idea of a workable solution. On a quick scan I think '$post_info' might not work anymore.

After you have worked out a logic you may put it in your 'e107_themes/your_theme/theme_shortcodes.php' class as a custom shortcode method to be rendered in 'forum_viewtopic_template.php' template, if that's your intention.
answered by (51 points) 1 1 6
work, but the code is outdated, can anyone rewrite it for me? sorry, but my experience is not sufficient here in the field of coding.
0 like 0 dislike
This here are not work, any ideas?
Thanks for help! :)

- Killer0561

<?php
/*
 * e107 website system
 *
 * Copyright (C) 2008-2013 e107 Inc (e107.org)
 * Released under the terms and conditions of the
 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
 *
 * e107 Dragonhead Theme Shortcodes.
 *
*/
class theme_shortcodes extends e_shortcode
{
    function sc_forum_whoisonline()
    {
        if( !defined('e_TRACKING_DISABLED') && e_PAGE == 'forum_viewtopic.php')
        {
            global $listuserson, $post_info;
            if (is_array($post_info))
            {
                if(varset($listuserson[$post_info['user_id'].'.'.$post_info['user_name']]))
                {
                    return '<img src="https://xxx.de/themes/xxx/images/online-button.png" width="150" height="29" />';
                }
                else
                {
                    return '<img src="https://xxx.de/themes/xxx/images/offline-button.png" width="150" height="29" />';
                }
            }
        }
    }
}

?>
answered by (12 points) 1 2 5
edited by
As I mentioned in my original reply I don't think the variable $post_info is available any longer in the global scope. Try to find a variable that's associated with forums in the scope of 'e_shortcode' object to essentially swap with '$post_info' to sort out this particular logic. For that I think  'e107_plugins/forum/shortcodes/forum_shortcodes.php' is a good place to start looking at.
hm, its not easy for me. my experience about coding is not good :) - need here help ;)
0 like 0 dislike
I'm currently using these two in my theme_shortcode file:

function sc_info()
    {

        if (ANON == TRUE)
        {
            $text = LAN_FORUM_0049.'<br />'.LAN_FORUM_0050." <a href='".e_SIGNUP."'>".LAN_FORUM_0051."</a> ".LAN_FORUM_0052;
        }
        elseif(USER == FALSE)
        {
            $text = LAN_FORUM_0049.'<br />'.LAN_FORUM_0053." <a href='".e_SIGNUP."'>".LAN_FORUM_0054."</a> ".LAN_FORUM_0055;
        }

        if (USER == TRUE)
        {
            $total_new_threads = e107::getDb()->count('forum_thread', '(*)', "WHERE thread_datestamp>'".USERLV."' ");
                $total_read_threads = 0;
            if (USERVIEWED != "")
            {
                $tmp = explode(".", USERVIEWED); // List of numbers, separated by single period
                $total_read_threads = count($tmp);
            }

            $text = LAN_FORUM_0018." ".USERNAME."<br />";
            $lastvisit_datestamp = e107::getParser()->toDate(USERLV, 'long'); //FIXME Use e107::getParser()->toDate();
            $datestamp = e107::getParser()->toDate(time(), "long");

            $text .= (!$total_new_threads?LAN_FORUM_0019." ":($total_new_threads == 1?LAN_FORUM_0020:LAN_FORUM_0021." ".$total_new_threads." ".LAN_FORUM_0022." ")).LAN_FORUM_0023;

            if ($total_new_threads != 0 && $total_read_threads >= $total_new_threads)
            {
                $text .= LAN_FORUM_0029;
                $allread = TRUE;
            }
            elseif($total_read_threads != 0)
            {
                $text .= " (".LAN_FORUM_0027." ".$total_read_threads." ".LAN_FORUM_0028.")";
            }

            $text .= "<br />
            ".LAN_FORUM_0024." ".$lastvisit_datestamp."<br />
            ".LAN_FORUM_0025." ".$datestamp;
        }

        return $text;

    }

 

function sc_forumlink()
    {
    $data = e107::getScBatch('forum', true)->var;

        return e107::url('forum', 'forum', $data);

    }
answered by (296 points) 11 43 48
I need a shortcode, where under the avatar in the forum in a forum post a graphic is displayed, whether this user is currently online or offline.

SInce i've got something similar in my under development shortcode, just try this (untested...):

function sc_forum_whoisonline()
    {
        if( !defined('e_TRACKING_DISABLED') && e_PAGE == 'forum_viewtopic.php')
        {
$data = e107::getScBatch('forum', true)->var;

$post_info = $data->postInfo;

     if (is_array($post_info))
            {
                $on_name = "".$post_info['post_user'].".".$post_info['user_name']."";

                $check = $this->sql-> db_Count("online","(*)","WHERE online_user_id='".$on_name."'");
               return (( $check > 0 )?'<img src="https://xxx.de/themes/xxx/images/online-button.png" width="150" height="29" />':'<img src="https://xxx.de/themes/xxx/images/offline-button.png" width="150" height="29" />');

}

}

    }

0 like 0 dislike
[Sat Apr 14 17:53:13.544856 2018] [:error] [pid 21382] [client 94.114.171.243:52050] PHP Fatal error:  Uncaught Error: Call to undefined function forum_rules() in /var/www/_[EGU]_Seiten/homepage/plugins/forum/shortcodes/batch/forum_shortcodes.php:19\nStack trace:\n#0 /var/www/_[EGU]_Seiten/homepage/handlers/shortcode_handler.php(458): forum_shortcodes->__construct()\n#1 /var/www/_[EGU]_Seiten/homepage/handlers/e107_class.php(1327): e_parse_shortcode->getScObject('forum_shortcode...', 'forum', NULL)\n#2 /var/www/_[EGU]_Seiten/homepage/themes/dragonhead/theme_shortcodes.php(33): e107::getScBatch('forum', true)\n#3 /var/www/_[EGU]_Seiten/homepage/handlers/shortcode_handler.php(262): theme_shortcodes->sc_forum_onlinestatus_test(Array, '')\n#4 /var/www/_[EGU]_Seiten/homepage/handlers/shortcode_handler.php(1184): e_parse_shortcode->callScFuncA('theme_shortcode...', 'sc_forum_online...', Array)\n#5 [internal function]: e_parse_shortcode->doCode(Array)\n#6 /var/www/_[EGU]_Seiten/homepage/handlers/shortcode_handler.php(968): preg_replace_callback('#\\\\{([A-Z][^\\\\x02...', Array, '\\n        <hr st...')\n#7 /var/www/_[EGU]_Seiten/h in /var/www/_[EGU]_Seiten/homepage/plugins/forum/shortcodes/batch/forum_shortcodes.php on line 19
answered by (12 points) 1 2 5
This is the correct one. Tested it and it's running:

function sc_forumuseronline()
    {

    $data = e107::getScBatch('view', 'forum');
    $post_info = $data->postInfo;

      if (is_array($post_info))
        {
                $on_name = "".$post_info['post_user'].".".$post_info['user_name']."";

                $check = e107::getDb()->count("online","(*)","WHERE online_user_id='".$on_name."'");
               return (( $check > 0 )?'<img src="https://xxx.de/themes/xxx/images/online-button.png" width="150" height="29" />':'<img src="https://xxx.de/themes/xxx/images/offline-button.png" width="150" height="29" />');

        }
    }

 

There could be also another option, if the USERCOMBO shortcode could be templated, but unfortunatelly it can't.... yet...
Thank you very much!

Work perfect!
Welcome to e107 Q&A, where you can ask questions and receive answers from other members of the e107 community.
747 questions
1,157 answers
1,968 comments
1,242 users