Welcome to Geeklog, Anonymous Friday, November 08 2024 @ 09:06 pm EST

Geeklog Forums

Forum plugin centerblock autotag


Status: offline

ivy

Forum User
Full Member
Registered: 11/25/04
Posts: 314
Location:Tokyo Japan
are there centerblock autotag?

like this.
Text Formatted Code
line:10


I want to set forum centerblock item in any place.

Geeklog Japan https://www.geeklog.jp
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Hi Ivy,

You can easily do this with autotag plugin by calling a php function (see CUSTOM_centerblock_forum below).

Text Formatted Code
/**
* Display latest forum posts in the center block.
*
* @param   where   int      where the block will be displayed (0..2)
* @param   page    int      page number
* @param   topic   string   topic ID
* @return          string   HTML for the center blcok (can be empty)
*/
function CUSTOM_centerblock_forum ($limit='')
{
   global $_CONF, $_USER, $_TABLES, $LANG_GF01, $CONF_FORUM;
    global $LANG_GF02, $mode, $order;

    //$TIMER = new timerobject();
    //$TIMER->startTimer();
    //$exectime = $TIMER->stopTimer();

    if ($CONF_FORUM['installed_version'] < 2.6) {
        return;
    }

    if ($CONF_FORUM['registration_required'] && $_USER['uid'] < 2) {
        return;
    }

    $retval = '';

    $cb_enable = $CONF_FORUM['show_centerblock'];
    $cb_where  = $CONF_FORUM['centerblock_where'];

    // If enabled only for homepage and this is not page 1 or a topic page,
    // then set disable flag
    if ($CONF_FORUM['centerblock_homepage'] == 1 AND ($page > 1 OR !empty ($topic))) {
        $cb_enable = 0;
    } elseif ($CONF_FORUM['centerblock_homepage'] == 0 and $page > 1) {
        $cb_where = 1;      // Top of Page
    }

    // Check if there are no featured articles in this topic
    // and if so then place it at the top of the page
    if (!empty ($topic)) {
        $wheresql = "WHERE tid='$topic' AND featured > 0";
    } else {
        $wheresql = 'WHERE featured = 1';
    }
    $query = DB_query ("SELECT COUNT(*) AS count FROM {$_TABLES['stories']} $wheresql");
    $result = DB_fetchArray ($query);
    if ($result['count'] == 0 and $cb_where == 2) {
        $cb_where = 1;
    }

    $block = new Template ($_CONF['path'] . 'system/custom/forum');
    $block->set_file (array ('block' => 'centerblock.thtml','record' => 'centerblock_displayline.thtml'));
    $block->set_var ('xhtml', XHTML);
    $block->set_var ('phpself', $_CONF['site_url'] .'/index.php');
    $block->set_var ('startblock', COM_startBlock($LANG_GF02['msg170']));
    $block->set_var ('endblock', COM_endBlock());
    $block->set_var ('site_url', $_CONF['site_url']);
    $block->set_var ('layout_url', $CONF_FORUM['layout_url']);
    $block->set_var ('LANG_title', $LANG_GF02['msg170']);
    $block->set_var ('LANG_FORUM', $LANG_GF01['FORUM']);
    $block->set_var ('LANG_TOPIC', $LANG_GF01['TOPIC']);
    $block->set_var ('LANG_LASTPOST', $LANG_GF01['LASTPOST']);
    $block->set_var ('LANG_viewlastpost', $LANG_GF02['msg160']);
    $block->set_var ('LANG_forumjump', $LANG_GF02['msg195']);

    $groups = array ();
    $usergroups = SEC_getUserGroups();
    foreach ($usergroups as $group) {
        $groups[] = $group;
    }
    $grouplist = implode(',',$groups);
       
    if ($limit != '') $CONF_FORUM['centerblock_numposts'] = $limit;
   
        $sql  = "SELECT a.id, a.forum, a.name, a.date, a.lastupdated, a.last_reply_rec, a.subject, ";
    $sql .= "a.comment, a.uid, a.name, a.pid, a.replies, a.views, b.forum_name  ";
    $sql .= "FROM {$_TABLES['forum_topic']} a ";
    $sql .= "LEFT JOIN {$_TABLES['forum_forums']} b ON a.forum=b.forum_id ";
    $sql .= "WHERE pid=0 AND b.grp_id IN ($grouplist) AND b.no_newposts = 0 ";
    $sql .= "ORDER BY lastupdated DESC LIMIT {$CONF_FORUM['centerblock_numposts']}";
    $result = DB_query ($sql);

    if (DB_numRows($result) == 0) {
        return;
    }

    $f_tooltip = function_exists('COM_getTooltip');
    $cssid = 0;
    while ($A = DB_fetchArray ($result)) {
        $fullsubject = "{$A['subject']}\n{$LANG_GF01['POSTEDBY']}:{$A['name']}{$LANG_GF01['VIEWS']}:{$A['views']}, {$LANG_GF01['REPLIES']}:{$A['replies']}";
        if (strlen ($A['subject']) > $CONF_FORUM['cb_subject_size']) {
            $A['subject'] = COM_truncate($A['subject'], $CONF_FORUM['cb_subject_size'], '...');
        }

        if ($CONF_FORUM['allow_user_dateformat']) {
            $firstdate = COM_getUserDateTimeFormat ($A['date']);
            $firstdate = $firstdate[0];
            $lastdate = COM_getUserDateTimeFormat ($A['lastupdated']);
            $lastdate = $lastdate[0];
        } else {
            $firstdate = strftime($CONF_FORUM['default_Datetime_format'], $A['date']);
            $lastdate = strftime($CONF_FORUM['default_Datetime_format'], $A['lastupdated']);
        }
        if ($A['uid'] > 1) {
            $topicinfo = "{$A['subject']}<br" . XHTML . ">{$LANG_GF01['STARTEDBY']} " . COM_getDisplayName($A['uid']) . ', ';                  
            //$topicinfo .= sprintf($LANG_GF01['LASTREPLYBY'],COM_getDisplayName($A['uid']));                    
        } else {
            $topicinfo = "{$A['subject']}<br" . XHTML . ">{$LANG_GF01['STARTEDBY']},{$A['name']},";
        }

        $topicinfo .= "{$firstdate}<br" . XHTML . ">{$LANG_GF01['VIEWS']}:{$A['views']}, {$LANG_GF01['REPLIES']}:{$A['replies']}<br" . XHTML . ">";

        if (empty ($A['last_reply_rec']) OR $A['last_reply_rec'] < 1) {
            $lastid = $A['id'];
            $lastcomment = $A['comment'];
        } else {
            $qlreply = DB_query("SELECT id,uid,name,comment FROM {$_TABLES['forum_topic']} WHERE id={$A['last_reply_rec']}");
            $B = DB_fetchArray($qlreply);
            $lastid = $B['id'];
            $lastcomment = $B['comment'];
            if ($B['uid'] > 1) {
                $topicinfo .= sprintf($LANG_GF01['LASTREPLYBY'],COM_getDisplayName($B['uid']));                    
            } else {
                $topicinfo .= sprintf($LANG_GF01['LASTREPLYBY'],$B['name']);
            }
        }
        $lastpostinfo = strip_tags(COM_truncate($lastcomment, $CONF_FORUM['contentinfo_numchars'], '...'));
        $lastpostinfo = str_replace(LB, "<br" . XHTML . ">", forum_mb_wordwrap($lastpostinfo, $CONF_FORUM['linkinfo_width'], LB));

        $cssid = ($cssid == 1) ? 2 : 1;

        if ($f_tooltip) {
            $lastpostlink = "{$_CONF['site_url']}/forum/viewtopic.php?showtopic={$A['id']}&amp;lastpost=true#{$lastid}";
            $block->set_var ('tooltip_date', $lastdate);
            $topiclink = "{$_CONF['site_url']}/forum/viewtopic.php?showtopic={$A['id']}";
            $block->set_var ('tooltip_topic_subject', $A['subject']);
        } else {
            $block->set_var ('lastpostinfo', $lastpostinfo);
            $block->set_var ('topicinfo', $topicinfo);
            $block->set_var ('date', $lastdate);
            $block->set_var ('topic_subject', $A['subject']);
        }
        $block->set_var ('lastpostid', $lastid);
        $block->set_var ('cssid', $cssid);
        $block->set_var ('img_dir', $CONF_FORUM['imgset']);
        $block->set_var ('forum_id', $A['forum']);
        $block->set_var ('forum_name', $A['forum_name']);
        $block->set_var ('topic_id', $A['id']);
        $block->set_var ('fullsubject', $fullsubject);
        $block->set_var ('views', $A['views']);
        $block->set_var ('replies', $A['replies']);
        $block->set_var ('lastpostby',$A['name']);
        $block->parse ('block_records', 'record',true);
    }

    $block->parse ('output', 'block');
    $retval .= $block->finish ($block->get_var ('output'));

    //$exectime = $TIMER->stopTimer();
    //COM_errorLog("Centerblock Execution Time: $exectime seconds");

    return $retval;
}


You will also need to add 2 files in system/custom/forum folder

centerblock.thtml

Text Formatted Code
<!-- start centerblock.thtml -->
<!-- startblock -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border: 1px solid #CCC; margin-bottom:10px;">
    <tr style="vertical-align:middle;">
        <td class="pluginTitle alignleft" style="padding:4px; width:40%;"><b>{LANG_FORUM}</b></td>
        <td class="pluginTitle alignleft" style="padding:4px; width:40%;"><b>{LANG_TOPIC}</b></td>
        <td class="pluginTitle aligncenter" style="padding:4px; width:20%;"><b>{LANG_LASTPOST}</b></td>
    </tr>
        {block_records}
</table>
<!-- endblock -->
<!-- end centerblock.thtml -->


centerblock_displayline.thtml

Text Formatted Code

<!-- start centerblock_displayline.thtml -->
    <tr class="pluginRow{cssid}" onmouseover="className='pluginRollOver';" onmouseout="className='pluginRow{cssid} pluginLinks';">        
        <td class="pluginLinks" onclick="window.location.href='{site_url}/forum/index.php?forum={forum_id}'" onmouseover="this.style.cursor='pointer';" style="padding-left:6px; height:20px; width:25%" title="{LANG_forumjump}">{forum_name}</td>
        <td class="pluginLinks" onclick="window.location.href='{site_url}/forum/viewtopic.php?showtopic={topic_id}'" onmouseover="this.style.cursor='pointer';"  style="width:65%">
            {tooltip_topic_subject}
        </td>
        <td class="pluginLinks" onclick="window.location.href='{site_url}/forum/viewtopic.php?showtopic={topic_id}&amp;lastpost=true#{lastpostid}'" onmouseover="this.style.cursor='pointer';" style="padding-right:6px; white-space:nowrap;">
            {tooltip_date}
        </td>
    </tr>
<!-- end centerblock_displayline.thtml -->
 

I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

ivy

Forum User
Full Member
Registered: 11/25/04
Posts: 314
Location:Tokyo Japan
Thanks!

I chenged little for UIkit
http://www.geeklog.jp/staticpages/index.php/forum

custom_centerblock_forum.php
Text Formatted Code
<?php
/**
* Display latest forum posts in the center block.
*
* @param   where   int      where the block will be displayed (0..2)
* @param   page    int      page number
* @param   topic   string   topic ID
* @return          string   HTML for the center blcok (can be empty)
*/
function CUSTOM_centerblock_forum ($limit='')
{
    global $_CONF, $_USER, $_TABLES, $LANG_GF01, $CONF_FORUM;
    global $LANG_GF02, $mode, $order;

    //$TIMER = new timerobject();
    //$TIMER->startTimer();
    //$exectime = $TIMER->stopTimer();

    if ($CONF_FORUM['installed_version'] < 2.6) {
        return;
    }

    if ($CONF_FORUM['registration_required'] && $_USER['uid'] < 2) {
        return;
    }

    $retval = '';

    $cb_enable = $CONF_FORUM['show_centerblock'];
    $cb_where  = $CONF_FORUM['centerblock_where'];

    // If enabled only for homepage and this is not page 1 or a topic page,
    // then set disable flag
    if ($CONF_FORUM['centerblock_homepage'] == 1 AND ($page > 1 OR !empty ($topic))) {
        $cb_enable = 0;
    } elseif ($CONF_FORUM['centerblock_homepage'] == 0 and $page > 1) {
        $cb_where = 1;      // Top of Page
    }

    // Check if there are no featured articles in this topic
    // and if so then place it at the top of the page
    if (!empty ($topic)) {
        $fromsql = ", {$_TABLES['topic_assignments']} ta";
        $wheresql = "WHERE ta.id = sid AND ta.tid='$topic' AND featured > 0";
    } else {
        $fromsql = '';
        $wheresql = 'WHERE featured = 1';
    }
    $query = DB_query ("SELECT COUNT(*) AS count FROM {$_TABLES['stories']} $fromsql $wheresql");
    $result = DB_fetchArray ($query);
    if ($result['count'] == 0 and $cb_where == 2) {
        $cb_where = 1;
    }

     $block = new Template ($_CONF['path'] . 'system/custom/forum');



    $block->set_file (array ('block' => 'centerblock.thtml','record' => 'centerblock_displayline.thtml'));
    $block->set_var ('xhtml', XHTML);
    $block->set_var ('phpself', $_CONF['site_url'] .'/index.php');
    $block->set_var ('startblock', COM_startBlock($LANG_GF02['msg170']));
    $block->set_var ('endblock', COM_endBlock());
    $block->set_var ('site_url', $_CONF['site_url']);
    $block->set_var ('layout_url', $CONF_FORUM['layout_url']);
    $block->set_var ('LANG_title', $LANG_GF02['msg170']);
    $block->set_var ('LANG_FORUM', $LANG_GF01['FORUM']);
    $block->set_var ('LANG_TOPIC', $LANG_GF01['TOPIC']);
    $block->set_var ('LANG_LASTPOST', $LANG_GF01['LASTPOST']);
    $block->set_var ('LANG_viewlastpost', $LANG_GF02['msg160']);
    $block->set_var ('LANG_forumjump', $LANG_GF02['msg195']);

    $groups = array ();
    $usergroups = SEC_getUserGroups();
    foreach ($usergroups as $group) {
        $groups[] = $group;
    }
    $grouplist = implode(',',$groups);

    if ($limit != '') $CONF_FORUM['centerblock_numposts'] = $limit;
   
        $sql  = "SELECT a.id, a.forum, a.name, a.date, a.lastupdated, a.last_reply_rec, a.subject, ";

    $sql .= "a.comment, a.uid, a.name, a.pid, a.replies, a.views, b.forum_name  ";
    $sql .= "FROM {$_TABLES['forum_topic']} a ";
    $sql .= "LEFT JOIN {$_TABLES['forum_forums']} b ON a.forum=b.forum_id ";
    $sql .= "WHERE pid=0 AND b.grp_id IN ($grouplist) AND b.no_newposts = 0 ";
    $sql .= "ORDER BY lastupdated DESC LIMIT {$CONF_FORUM['centerblock_numposts']}";
    $result = DB_query ($sql);

    if (DB_numRows($result) == 0) {
        return;
    }

    $f_tooltip = function_exists('COM_getTooltip');
    $cssid = 0;
    while ($A = DB_fetchArray ($result)) {
//        $fullsubject = "{$A['subject']}\n{$LANG_GF01['POSTEDBY']}:{$A['name']}{$LANG_GF01['VIEWS']}:{$A['views']}, {$LANG_GF01['REPLIES']}:{$A['replies']}";

        $fullsubject = "{$LANG_GF01['POSTEDBY']}:{$A['name']}{$LANG_GF01['VIEWS']}:{$A['views']}";

        if (strlen ($A['subject']) > $CONF_FORUM['cb_subject_size']) {
            $A['subject'] = COM_truncate($A['subject'], $CONF_FORUM['cb_subject_size'], '...');
        }

        if ($CONF_FORUM['allow_user_dateformat']) {
            $firstdate = COM_getUserDateTimeFormat ($A['date']);
            $firstdate = $firstdate[0];
            $lastdate = COM_getUserDateTimeFormat ($A['lastupdated']);
            $lastdate = $lastdate[0];
        } else {
            $firstdate = strftime($CONF_FORUM['default_Datetime_format'], $A['date']);
            $lastdate = strftime($CONF_FORUM['default_Datetime_format'], $A['lastupdated']);
        }
        if ($A['uid'] > 1) {
            $topicinfo = COM_getDisplayName($A['uid']) ;
            //$topicinfo .= sprintf($LANG_GF01['LASTREPLYBY'],COM_getDisplayName($A['uid']));
        } else {
            $topicinfo = "{$A['name']}";
        }

//        $topicinfo .= "{$firstdate} " . " {$LANG_GF01['VIEWS']}:{$A['views']}, {$LANG_GF01['REPLIES']}:{$A['replies']}</span>";
//        $topicinfo .= "{$firstdate} " . " {$LANG_GF01['VIEWS']}:{$A['views']}"."</span>";

        if (empty ($A['last_reply_rec']) OR $A['last_reply_rec'] < 1) {
            $lastid = $A['id'];
            $lastcomment = $A['comment'];
        } else {
            $qlreply = DB_query("SELECT id,uid,name,comment FROM {$_TABLES['forum_topic']} WHERE id={$A['last_reply_rec']}");
            $B = DB_fetchArray($qlreply);
            $lastid = $B['id'];
            $lastcomment = $B['comment'];
            if ($B['uid'] > 1) {
                  $lastpostuser = sprintf("%s",COM_getDisplayName($B['uid']));
            } else {
                  $lastpostuser = sprintf("%s",$B['name']);
            }
        }
        $lastpostinfo = strip_tags(COM_truncate($lastcomment, $CONF_FORUM['contentinfo_numchars'], '...'));
        $lastpostinfo = str_replace(LB, "<br" . XHTML . ">", forum_mb_wordwrap($lastpostinfo, $CONF_FORUM['linkinfo_width'], LB));

        $cssid = ($cssid == 1) ? 2 : 1;
$f_tooltip=0;
        if ($f_tooltip) {
            $lastpostlink = "{$_CONF['site_url']}/forum/viewtopic.php?showtopic={$A['id']}&amp;lastpost=true#{$lastid}";
            $block->set_var ('tooltip_date', COM_getTooltip($lastdate, $lastpostinfo, $lastpostlink));
            $topiclink = "{$_CONF['site_url']}/forum/viewtopic.php?showtopic={$A['id']}";
            $block->set_var ('tooltip_topic_subject', COM_getTooltip($A['subject'], $topicinfo, $topiclink));
        } else {
            $block->set_var ('lastpostinfo', $lastpostinfo);
            $block->set_var ('topicinfo', $topicinfo);
            $block->set_var ('date', $firstdate);
            $block->set_var ('lastdate', $lastdate);
            $block->set_var ('topic_subject', $A['subject']);
        }

        $block->set_var ('lastpostuser', $lastpostuser);



        $block->set_var ('lastpostid', $lastid);
        $block->set_var ('cssid', $cssid);
        $block->set_var ('img_dir', $CONF_FORUM['imgset']);
        $block->set_var ('forum_id', $A['forum']);
        $block->set_var ('forum_name', $A['forum_name']);
        $block->set_var ('topic_id', $A['id']);
        $block->set_var ('fullsubject', $fullsubject);
        $block->set_var ('views', $A['views']);
        $block->set_var ('replies', $A['replies']);
        $block->set_var ('posts', $A['replies']+1);
        $block->set_var ('lastpostby',$A['name']);
        $block->parse ('block_records', 'record',true);
    }

    $block->parse ('output', 'block');
    $retval .= $block->finish ($block->get_var ('output'));

    //$exectime = $TIMER->stopTimer();
    //COM_errorLog("Centerblock Execution Time: $exectime seconds");

    return $retval;
}
 


centerblock.thtml:
Text Formatted Code
<!-- start centerblock.thtml -->
<!-- startblock -->
<h2>FORUM</h2>
<div class="uk-grid" style="margin:0">

<table class="uk-table-striped uk-width-1-1" style="max-width:100%">
<thead>
<tr class="uk-text-muted"><th>Topic</th><th>Category</th><th>Users</th><th>Posts</th><th>Views</th><th>Activity</th></tr>
</thead>
<tbody>
        {block_records}
</tbody>
</table>

</div>

<!-- endblock -->
<!-- end centerblock.thtml -->
 


centerblock_displayline.thtml
Text Formatted Code
<!-- start centerblock_displayline.thtml -->

<tr>
  <td class="uk-text-truncate" style="max-width:320px">
     <a href="{site_url}/forum/viewtopic.php?showtopic={topic_id}"><i class="uk-icon-arrow-circle-right"></i> <span class="uk-text-nowrap uk-text-truncate">{topic_subject}</a></a><br /
  </td>
  <td class="uk-text-truncate" style="max-width:180px">
     <span class="uk-text-truncate"><a href="{site_url}/forum/index.php?forum={forum_id}" class="uk-text-truncate uk-text-success uk-text-bold" style="max-width:100px"><i class="uk-icon-folder-o"></i> {forum_name}</a></span>
  </td>
  <td class="uk-text-truncate" style="max-width:120px">
{topicinfo}{!if replies}...{lastpostuser}{!endif}
  </td>
  <td class="uk-text-truncate">
    {posts}
  </td>
  <td class="uk-text-truncate">
        {views}
  </td>
  <td class="uk-text-truncate">
        <a href="{site_url}/forum/viewtopic.php?showtopic={topic_id}&amp;lastpost=true#{lastpostid}">{date}</a>
  </td>
</tr>

<!-- end centerblock_displayline.thtml -->
 


Static pageFrownPHP mode)
Text Formatted Code
echo CUSTOM_centerblock_forum ($limit='30');


How can I use autotag?


Geeklog Japan https://www.geeklog.jp
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
You must set the Allow PHP configuration setting to true in the Geeklog Configuration panel (Autotag plugin configuration) and be in a group with the autotags.PHP feature in order to modify autotags that call a function to translate the tag.

Check the PHP checkbox: Replace with PHP?

Add to the "Replace With:" textarea
Text Formatted Code
       
CUSTOM_centerblock_forum ($p1)
 


and use it like this in your staticpage:

Text Formatted Code
[forumcenterblock:10]

I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

ivy

Forum User
Full Member
Registered: 11/25/04
Posts: 314
Location:Tokyo Japan
Sorry, autotag error...

Text Formatted Code
Parse error: syntax error, unexpected end of file in /xxx/plugins/autotags/functions.inc(400) : eval()'d code on line 1


Geeklog Japan https://www.geeklog.jp
 Quote

Status: offline

ivy

Forum User
Full Member
Registered: 11/25/04
Posts: 314
Location:Tokyo Japan
Autotag admin
text area:

Text Formatted Code
return CUSTOM_centerblock_forum ($p1);


did it!
thanks!


Geeklog Japan https://www.geeklog.jp
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
+1 Big Grin
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

All times are EST. The time is now 09:06 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content