Tworzenie wtyczki - definicja hook'a

Założony przez  aeroflash.

Mam takie pytanie przy tworzeniu wtyczki do forum definiuje się hook, który realizuje zadane wyświetlania czegoś w danym miejscu. np. ten kod poniżej wyświetla coś na stronie głównej forum, ale jak zdefiniować hook, aby wyświetlał to samo jeszcze w działach i tematach czyli też w innych częściach forum?
$plugins->add_hook("index_start","pluginmybb"); 

Próbowałem inne hooki wpisać, ale nic to nie daje więc czy gdzieś jeszcze należy się do nich odwołać czy jak.
Dodawałem coś takiego, ale nic to nie dało, dany element tylko wyświetlał mi się na stronie głównej.

$plugins->add_hook("index_start","pluginmybb");
$plugins->add_hook("forumdisplay_start""pluginmybb");
$plugins->add_hook("forumdisplay_thread""pluginmybb");
$plugins->add_hook("showthread_start""pluginmybb");
$plugins->add_hook("portal_start""pluginmybb"); 
Sepowaty napisał 13.06.2013, 20:37:
Przenoszę do odpowiedniego działu.
Zalezy jak wyglada Twoj plugin i co robi. Jezeli potrzebuje zmiennej to ja dodawales rowniez w inne miejsca, tam gdzie definjujesz podpiecie hooka


Wysłane z mojego LG-P500 za pomocą Tapatalk 2
Na razie to testuję i wziąłem jakiś taki zwykły, który wyświetla ostatnie tematy na forum, ale robi to na stronie tylko głównej więc chcę się dowiedzieć jak realizuje to na reszcie podstron, np. w działach i tematach.

<?php

//Recent Threads Sidebar Mod by Borbole

//Trying to access directly the file, are we :D

if(!defined("IN_MYBB"))
{
    die(
"Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

//Hooking into index_start with our function

$plugins->add_hook("index_end""sidebarthreads");

//Show some info about our mod
function sidebarthreads_info()
{
    return array(
        
"name"            => "Recent Threads Sidebar",
        
"description"    => "It shows the recent posts on the sidebar.",
        
"website"        => "http://www.forumservices.eu/mybb",
        
"version"        => "1.0",
        
"author"        => "borbole",
        
"authorsite"    => "http://www.forumservices.eu/mybb",
        
"compatibility"  => "16*",
        
'guid'        => '99c9a5bd8f5ae93cfe6d5fad258df89d'
    
);
}

//Activate it
function sidebarthreads_activate()
{
    global 
$db;

    
//Insert the mod settings in the portal settinggroup
    
$query $db->simple_select("settinggroups""gid""name='portal'");
    
$gid $db->fetch_field($query"gid");

    
$setting = array(
        
'name' => 'sidebar_enable',
        
'title' => 'Lates Threads Sidebar',
        
'description' => 'Do you wish to show the Lates Threads in the sidebar as well?',
        
'optionscode' => 'yesno',
        
'value' => '1',
        
'disporder' => '90',
        
'gid' => intval($gid)
    );
    
$db->insert_query('settings',$setting);

    
$setting = array(
        
"sid" => "NULL",
        
"name" => "sidebar_position",
        
"title" => "Position",
        
"description" => "On which side do you wish to show the Lates Threads in the sidebar?",
        
"optionscode" => "select
         1= Right Side
         2= Left Side"
,
        
"value" => "2",
        
"disporder" => "91",
        
"gid" => intval($gid),
        );
    
$db->insert_query("settings"$setting);


    
$template = array(
        
"tid"        => NULL,
        
"title"        => 'thread_sidebar',
        
"template"    => '{$showrecentthreads}',
        
"sid"        => "-1",
        
"version"    => "1.0",
        
"dateline"    => time(),
    );

    
$db->insert_query("templates"$template);

    
rebuild_settings();
}

//Don't want to use it anymore? Let 's deactivate it then and drop the settings and the custom var as well
function sidebarthreads_deactivate()
{
    global 
$db$mybb;

    
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='sidebar_enable'");    
    
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='sidebar_position'");
    
    
$db->delete_query("templates","title = 'thread_sidebar'");

    
rebuild_settings();
}


//Insert our function 
function sidebarthreads()
{
   global 
$db$mybb$forums$templates;

   
//Get the recent threads settings from the portal
   
if($mybb->settings['portal_showdiscussions'] != && $mybb->settings['portal_showdiscussionsnum'])
   {
       
$showrecentthreads showrecentthreads();
   }
    
//Show the recent threads on the sidebar on board index
   
if($mybb->settings['sidebar_enable'] == 1)
   {
      
      
//Get the template
      
eval("\$sidebarposition = \"".$templates->get("thread_sidebar")."\";");

      
//Display it on the right side
      
if ($mybb->settings['sidebar_position'] == "2"
      {
          
$forums ='<table border="0" width="100%">
          <tr>
              <td width="200" valign="top">'
$sidebarposition'</td>
              <td valign="top">'
$forums'</td>
         </tr>
         </table>'
;
      }
      
       
//Display it on the left side
     
if ($mybb->settings['sidebar_position'] == "1"
     {
        
$forums ='<table border="0" width="100%">
        <tr>
            <td valign="top">'
$forums'</td>
            <td width="200" valign="top">'
$sidebarposition'</td>
        </tr>
       </table>'
;
     }
  }
}


//Get the recent threads from the portal to show them on the sidebar in forum index
function showrecentthreads()
{
    global 
$db$mybb$templates$latestthreads$lang$theme$forum_cache;
    
    
// Load global language phrases
    
$lang->load("portal");

    
// Latest forum discussions
    
$altbg alt_trow();
    
$threadlist '';
    
$query $db->query("
        SELECT t.*, u.username
        FROM "
.TABLE_PREFIX."threads t
        LEFT JOIN "
.TABLE_PREFIX."users u ON (u.uid=t.uid)
        WHERE 1=1 
$unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
        ORDER BY t.lastpost DESC 
        LIMIT 0, "
.$mybb->settings['portal_showdiscussionsnum']
    );
    while(
$thread $db->fetch_array($query))
    {
        
$forumpermissions[$thread['fid']] = forum_permissions($thread['fid']);

        
// Make sure we can view this thread
        
if($forumpermissions[$thread['fid']]['canview'] == || $forumpermissions[$thread['fid']]['canviewthreads'] == || $forumpermissions[$thread['fid']]['canonlyviewownthreads'] == && $thread['uid'] != $mybb->user['uid'])
        {
            continue;
        }

        
$lastpostdate my_date($mybb->settings['dateformat'], $thread['lastpost']);
        
$lastposttime my_date($mybb->settings['timeformat'], $thread['lastpost']);
        
// Don't link to guest's profiles (they have no profile).
        
if($thread['lastposteruid'] == 0)
        {
            
$lastposterlink $thread['lastposter'];
        }
        else
        {
            
$lastposterlink build_profile_link($thread['lastposter'], $thread['lastposteruid']);
        }
        if(
my_strlen($thread['subject']) > 25)
        {
            
$thread['subject'] = my_substr($thread['subject'], 025) . "...";
        }
        
$thread['subject'] = htmlspecialchars_uni($thread['subject']);
        
$thread['threadlink'] = get_thread_link($thread['tid']);
        
$thread['lastpostlink'] = get_thread_link($thread['tid'], 0"lastpost");
        eval(
"\$threadlist .= \"".$templates->get("portal_latestthreads_thread")."\";");
        
$altbg alt_trow();
    }
    if(
$threadlist)
    { 
        
// Show the table only if there are threads
        
eval("\$latestthreads = \"".$templates->get("portal_latestthreads")."\";");
    }

    return 
$latestthreads;
}

?>
Przede wszystkim, głównym zadaniem hookow nie jest wyświetlanie czegokolwiek. One odpadają funkcje które są do nich przypisane w miejscach gdzie występują. A co robią te funkcje, to już inna sprawa.
A więc przeglądałem w wolnym czasie różne wtyczki, którą można przerobić, aby dodawała boczny pasek po prawej stronie, który będzie się wyświetlał na prawie każdej stronie forum.

Jest forum.
[Obrazek: di-5ICA.jpg]

Chciałbym uzyskać taki sidebar na forum.
[Obrazek: di-P4OZ.jpg]

Standardowe wtyczki jak dodają sidebar to jest on wyświetlany równo z częścią pierwszego działu.
[Obrazek: di-14LT.jpg]

Jest możliwe w MyBB, aby taki sidebar wyświetlał się od samej góry forum? Większość dodaje boczny panel od początku pierwszego działu. Po wejściu w dział gdzie jest przycisk Nowy temat trochę dziwnie wygląda ten sidebar wtedy.
Chociaż i to jest do przyjęcia, ale interesuje mnie w 1 kolejności czy od góry da się to zrobić. Wtedy i reklama na środku by się dobrze środkowała.
[Obrazek: di-HXJ4.jpg]


Także lukas taki sidebar, aby wyświetlał się od samego początku da się zrobić. Jesteś w stanie przerobić ten sidebra? W zasadzie chodzi tylko o to, aby zmodyfikować go, aby wyświetlał się nie tylko na stronie głównej, ale i w działach, w tematach. No i aby właśnie najlepiej, aby rozpoczynał się od samej góry. Co będzie wyświetlał to już nie problem, bo wystarczy tylko dodać kod HTML, który ma się na nim wyświetlać.

Brałeś się wcześniej za to zlecenie więc w zasięgu są takie rzeczy dla Ciebie? Bo wracam od tego tematu i chcę, aby ktoś dobrze to opracował oczywiście na ze free.

To jest kod wtyczki Sidebarmybb, ale są też inne które można przerobić do działania, które chciałbym uzyskać.

<?php
/* This plugin is made by sunjava1 
 * Sidebarmybb for MyBB 1.6.x
 * Copyright © 2011 Sunjava1, All Rights Reserved!
 
 * Website: http://www.vubscs.tk
 * License: 
 * "This plugin is offered "as is" with no guarantees.
 * You may redistribute it provided the code and credits 
 * remain intact with no changes. This is not distributed
 * under GPL, so you may NOT re-use the code in any other
 * module, plugin, or program.
  
 * Free for non-commercial purposes!"
 * Thank you, for your understanding!!
 */

if(!defined("IN_MYBB"))
{
die (
"Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("index_start","sidebarmybb");

function 
sidebarmybb_info()
        {
return array(
        
        
"name"=> "Side bar for mybb",
        
"description"=> "This plugin will add a side bar in your index page",
        
"website"=> "http://www.vubscs.tk",
        
"author"=> "sunjava1",
        
"authorsite"=> "http://www.facebook.com/sunjava1",
        
"version"=> "1.0",
        
"guid" => "9ca49b02c1045d7d1b658624bde22a5b",
            );
        }
        
function 
sidebarmybb_activate(){
global 
$db$mybb$sidebarmybb_template;
    
    
$sidebarmybb_group = array(
        
"name" => "sidebarmybb",
        
"title" => "Side bar on index",
        
"description" => "Display side bar on index page .",
        
"disporder" => "401",
        
"isdefault" => "no",
        );
    
$group['gid'] = $db->insert_query("settinggroups"$sidebarmybb_group);
    
$gid $db->insert_id();
    
    
    
$sidebarmybb_set = array(
        
"name" => "sidebarmybb_numb",
        
"title" => "Number of Sidebars",
        
"description" => "Select the number of sidebars you want",
        
"optionscode" => "select \n30=1 Sidebar\n20=2 Sidebars",
        
"value" => "30",
        
"disporder" => "1",
        
"gid" => intval($gid),
        );
    
$db->insert_query("settings"$sidebarmybb_set);
    
    
    
    
$sidebarmybb_table_title_1 = array(
        
"name" => "sidebarmybb_title_1",
        
"title" => "Title (First Sidebar)",
        
"description" => "Add the title of first sidebar",
        
"optionscode" => "text",
        
"value" => "my first sidebar title",
        
"disporder" => "2",
        
"gid" => intval($gid),
        );
    
$db->insert_query("settings"$sidebarmybb_table_title_1);
    
    
    
    
    
$sidebarmybb_table_messege_1 = array(
        
"name" => "sidebarmybb_messege_1",
        
"title" => "Content (First Sidebar)",
        
"description" => "Add the first sidebar content i.e. your adds, facebook badges etc",
        
"optionscode" => "textarea",
        
"value" => "this is my first side bar default content",
        
"disporder" => "3",
        
"gid" => intval($gid),
        );
    
$db->insert_query("settings"$sidebarmybb_table_messege_1);
    
    
    
    
$sidebarmybb_table_title_2 = array(
        
"name" => "sidebarmybb_title_2",
        
"title" => "Title (second sidebar)",
        
"description" => "Add the title of second sidebar (NOTE Leave this blank if you have not select 2 sidebars from first option)",
        
"optionscode" => "text",
        
"value" => "",
        
"disporder" => "4",
        
"gid" => intval($gid),
        );
    
$db->insert_query("settings"$sidebarmybb_table_title_2);
    
    
    
    
    
$sidebarmybb_table_messege_2 = array(
        
"name" => "sidebarmybb_messege_2",
        
"title" => "Content (Second sidebar)",
        
"description" => "Add the content of second sidebar. (NOTE Leave this blank if you have not select 2 sidebars from first option)",
        
"optionscode" => "textarea",
        
"value" => "",
        
"disporder" => "5",
        
"gid" => intval($gid),
        );
    
$db->insert_query("settings"$sidebarmybb_table_messege_2);
    
    
    
    require 
MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("index""#".preg_quote('{$forums}')."#i"'<table width=\'100%\'><tr><td valign=\'top\'>{$forums}</td>{$sidebarmybb}'); 
         


 
    
rebuild_settings();
}        

function 
sidebarmybb_deactivate(){
global 
$db;
    
    
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='sidebarmybb'");
    
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='sidebarmybb_title_1'");
    
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='sidebarmybb_numb'");
    
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='sidebarmybb_messege_1'");
    
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='sidebarmybb_title_2'");
    
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='sidebarmybb_messege_2'");
    
  require 
MYBB_ROOT."/inc/adminfunctions_templates.php";
    
find_replace_templatesets("index""#".preg_quote('<table width=\'100%\'><tr><td valign=\'top\'>{$forums}</td>{$sidebarmybb}')."#i"'{$forums}'); 

    
// Rebuilding settings
    
    
rebuild_settings();
    }

function 
sidebarmybb(){
global 
$sidebarmybb$mybb;

if (
$mybb->settings['sidebarmybb_numb']==20)
{

$sidebarmybb='<td valign="top" align="right">
<script src="jscripts/sidebarmybb.js"></script>
<table><tr><td>
<table class="tborder" ><tr><th align="right" class="thead">
<a href="#" onclick="sidebarmybb_container();" id="sidebarmybb_toggle"> <img src="images/minus.png"></a></th>
<tr><td style="background:#fff;">     
<div id="sidebarmybb_content" style="display:block">
        <table class="tborder">
                <tr class="tcat"><td><strong> '
$mybb->settings['sidebarmybb_title_1'] .' </strong> <span style="float:right;">  <a id="sidebarmybb_toggle_1" href="#" onclick="sidebarmybb_func_1();"> <img src="images/minus.png"></a></span></tr>
                <tr ><td colspan="2" style="background:#fff;">  
                        <div id="sidebarmybb_1" style="display:block">    '
$mybb->settings['sidebarmybb_messege_1'] .' </div>  
                </td></tr>
        </table> 
        <br>
        <table class="tborder">
                <tr class="tcat"><td > <strong> '
$mybb->settings['sidebarmybb_title_2'] .'  </strong><span style="float:right">  <a id="sidebarmybb_toggle_2" href="#" onclick="sidebarmybb_func_2();"> <img src="images/minus.png"></a></span></td></tr>
                <tr ><td colspan="2" style="background:#fff;">  
                        <div id="sidebarmybb_2" style="display:block">    '
$mybb->settings['sidebarmybb_messege_2'] .' </div>  
                </td></tr>
        </table> 
 </div>
</td></tr>

</table>

</td></tr></table>

</td></tr></table>'
;    


}

else 
{

    
$sidebarmybb='<td valign="top" align="right">
<script src="jscripts/sidebarmybb.js"></script>
<table><tr><td>
<table class="tborder"  ><tr><th align="right" class="thead">
<a href="#" onclick="sidebarmybb_container();" id="sidebarmybb_toggle"> <img src="images/minus.png"></a></th>
<tr><td style="background:#fff;">     
<div id="sidebarmybb_content" style="display:block">
        <table class="tborder">
                <tr class="tcat"><td > <strong> '
$mybb->settings['sidebarmybb_title_1'] .' </strong> <span style="float:right">  <a id="sidebarmybb_toggle_1" href="#" onclick="sidebarmybb_func_1();"> <img src="images/minus.png"></a></span></td></tr>
                <tr ><td colspan="2" style="background:#fff;">   <div id="sidebarmybb_1" style="display:block">    '
$mybb->settings['sidebarmybb_messege_1'] .' </div>  
                </td></tr>
        </table> 
 </div>
</td></tr>

</table>

</td></tr></table>

</td></tr></table>'
;    


}



    }

?>
Kwestia od kiedy zaczyna się sidebar to kwestia kodu w szablonie index, więc dobrze by było jak byś go przytoczył :).

Zaś edytować kod, aby spełniał Twoje funkcjonalności to jednak trochę roboty, więc szybciej jest zmienić hook w pluginie i pozmieniać kod w szablonach ręcznie, ale o tym później.



Użytkownicy przeglądający ten wątek:

1 gości