Plugin php colors

Założony przez  MEXXIO.

Chciałem napisać plugin w którym możemy zmienić kolorowanie składni, pisałem na podstawie:
https://webboard.pl/thread-53369.html
i mam coś takiego:
<?php

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("global_start", "phpcolors");
$plugins->add_hook("showthread_start", "phpcolors");
function phpcolors_info()
{
    global $lang, $db;
    $lang->load('phpcolors');

        $query = $db->simple_select('settinggroups', '*', "name='phpcolors'");
        if (count($db->fetch_array($query)))
        $settings_link = '(<a href="index.php?module=config&action=change&search=phpcolors" style="color:#FF1493;font-weight:bold;">'.'Ustawienia'.'</a>)';

    return array(
        "name"            => $lang->phpcolors_name,
        "description"    => $lang->phpcolors_desc . $settings_link,
        "website"        => "http://mybbsecurity.net/",
        "author"        => "Nathan Malcolm",
        "authorsite"    => "http://mybbsecurity.net/",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "*"
    );
}

function phpcolors_activate()
{
    require MYBB_ROOT."inc/adminfunctions_templates.php";
    global $db;
    $result = $db->simple_select('settinggroups', 'MAX(disporder) AS max_disporder');
    $max_disporder = $db->fetch_field($result, 'max_disporder');
    $disporter = 1;

    $insertarray = array(
        'gid' => 'NULL',
        'name' => 'phpcolors',
        'title' => 'Zmień kolory kodu PHP',
        'description' => 'Ten plugin pomoże zmienić kolory kodu PHP.',
        'disporder' => $max_disporder + 1,
        'isdefault' => 'no'
    );
    $db->insert_query("settinggroups", $insertarray);
    $group['gid'] = $db->insert_id();


    $settings = array(
                    'name'            => 'phpcolors',
                    'title'            => 'Zmień kolory kodu PHP',
                    'description'    => 'Chcesz włączyć?',
                    'optionscode'    => 'yesno',
                    'value'            => 'yes',
                    'disporder'        => $disporter++,
                    'gid'            => $group['gid'],
    );

    $db->insert_query('settings', $settings);

    $settings1 = array(
                    'name'            => 'highlight.string',
                    'title'           => 'Kolor string',
                    'description'     => 'Tu podaj kolor HEX',
                    'optionscode'     => 'text',
                    'value'           => '#C0FF21',
                    'disporder'       => $disporter++,
                    'gid'             => $group['gid'],
    );

    $db->insert_query('settings', $settings1);

    $settings2 = array(
                    'name'            => 'highlight.comment',
                    'title'           => 'Kolor comment',
                    'description'     => 'Tu podaj kolor HEX',
                    'optionscode'     => 'text',
                    'value'           => '#1E90FF',
                    'disporder'       => $disporter++,
                    'gid'             => $group['gid'],
    );

    $db->insert_query('settings', $settings2);

    $settings3 = array(
                    'name'            => 'highlight.keyword',
                    'title'           => 'Kolor keyword',
                    'description'     => 'Tu podaj kolor HEX',
                    'optionscode'     => 'text',
                    'value'           => '#FFC0CB',
                    'disporder'       => $disporter++,
                    'gid'             => $group['gid'],
    );

    $db->insert_query('settings', $settings3);

    $settings4 = array(
                    'name'            => 'highlight.default',
                    'title'           => 'Kolor default',
                    'description'     => 'Tu podaj kolor HEX',
                    'optionscode'     => 'text',
                    'value'           => '#cecece',
                    'disporder'       => $disporter++,
                    'gid'             => $group['gid'],
    );

    $db->insert_query('settings', $settings4);
}

function phpcolors_deactivate(){
    global $db;
    $db->delete_query("settings", "name='phpcolors'");
    $db->delete_query("settings", "name='highlight.string'");
    $db->delete_query("settings", "name='highlight.comment'");
    $db->delete_query("settings", "name='highlight.keyword'");
    $db->delete_query("settings", "name='highlight.default'");
    $db->delete_query("settinggroups", "name='phpcolors'");
}

function phpcolors_insert(){
    global $mybb;
    if(intval($mybb->settings['phpcolors']) == 1){
    ini_set('highlight.string', ''.$mybb->settings['highlight.string'].'');
    ini_set('highlight.comment', ''.$mybb->settings['highlight.comment'].'');
    ini_set('highlight.keyword', ''.$mybb->settings['highlight.keyword'].'');
    ini_set('highlight.default', ''.$mybb->settings['highlight.default'].'');
}}
?>
i problem mam taki iż nie wiem jak umieścić to w showthread coś robię na bank źle wiec piszę do was z proźbą o pomoc. Piszę to z myślą aby było łatwiej zmienić kolorowanie bez konieczności edytowania plików silnika.
napisz co ma robić plugin, zmieniać kolory składni php? Kolorowanie skladni php juz mamy w tagach [.php][./php] bez kropek
No tak zmieniać kolory, które można sobie dowolnie ustawić przez PA.
Bo na sztywno można dać tak do showthread.php:

ini_set('highlight.string''#C0FF21');
ini_set('highlight.comment''#1E90FF');
ini_set('highlight.keyword''#FFC0CB');
ini_set('highlight.default''#cecece'); 
http://docs.mybb.com/MyBB_Plugin_Hooks.html

i używasz hooka pod którym dodałeś kod skoro tak na sztywno Ci działa

chociaz mi to bardziej pod post perser podchodzi
Mam niby dodane takie:
$plugins->add_hook("global_start""phpcolors");
$plugins->add_hook("showthread_start""phpcolors"); 

ale po aktywacji pluginu i przejsciu na stronę główną mam białą stronkę.
A w ostatnim poście mi chodziło o to że mogę dodać to:
ini_set('highlight.string''#C0FF21');
ini_set('highlight.comment''#1E90FF');
ini_set('highlight.keyword''#FFC0CB');
ini_set('highlight.default''#cecece'); 
bezpośrednio do pliku showthread bez jakiegokolwiek pluginu.
dodaj tu caly plugin w zalaczniku
Załącznik skasowałem.
function favicon_activate() ?
function favicon_deactivate(){ ?
function favicon_insert(){ ?

0 związku z tym o czym piszesz
Pisałem że robię to na podstawie poprzedniego wątku, wieć zwróciłem się z pomocą.

(06.07.2014, 10:05)Supryk napisał(a): function favicon_activate() ?
function favicon_deactivate(){ ?
function favicon_insert(){ ?

0 związku z tym o czym piszesz

sorry zaraz dam nowy załącznik...
function nazwatwojegopluginu_activate() - phpcolors i tak z resta funkcji

zobacz różnice

<?php

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("showthread_start""phpcolors_start");
function 
phpcolors_info()
{
    global 
$lang$db;
    
$lang->load('phpcolors');

    
$lang->phpcolors_desc '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:right;">' .
        
'<input type="hidden" name="cmd" value="_s-xclick">' 
        
'<input type="hidden" name="hosted_button_id" value="FCDVZ8BPAQTKU">' .
        
'<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">' .
        
'<img alt="" border="0" src="https://www.paypalobjects.com/pl_PL/i/scr/pixel.gif" width="1" height="1">' .
        
'</form>' $lang->phpcolors_desc;

        
$query $db->simple_select('settinggroups''*'"name='phpcolors'");
        if (
count($db->fetch_array($query)))
        
$settings_link '(<a href="index.php?module=config&action=change&search=phpcolors" style="color:#FF1493;font-weight:bold;">'.'Ustawienia'.'</a>)';

    return array(
        
"name"            => $lang->phpcolors_name,
        
"description"    => $lang->phpcolors $settings_link,
        
"website"        => "http://mybbsecurity.net/",
        
"author"        => "Nathan Malcolm",
        
"authorsite"    => "http://mybbsecurity.net/",
        
"version"        => "1.0",
        
"guid"             => "",
        
"compatibility" => "*"
    
);
}

function 
phpcolors_activate()
{
    require 
MYBB_ROOT."inc/adminfunctions_templates.php";
    global 
$db;
    
$result $db->simple_select('settinggroups''MAX(disporder) AS max_disporder');
    
$max_disporder $db->fetch_field($result'max_disporder');
    
$disporter 1;

    
$insertarray = array(
        
'gid' => 'NULL',
        
'name' => 'phpcolors',
        
'title' => 'Zmień kolory kodu PHP',
        
'description' => 'Ten plugin pomoże zmienić kolory kodu PHP.',
        
'disporder' => $max_disporder 1,
        
'isdefault' => 'no'
    
);
    
$db->insert_query("settinggroups"$insertarray);
    
$group['gid'] = $db->insert_id();


    
$settings = array(
                    
'name'            => 'phpcolors',
                    
'title'            => 'Zmień kolory kodu PHP',
                    
'description'    => 'Chcesz włączyć?',
                    
'optionscode'    => 'yesno',
                    
'value'            => 'yes',
                    
'disporder'        => $disporter++,
                    
'gid'            => $group['gid'],
    );

    
$db->insert_query('settings'$settings);

    
$settings1 = array(
                    
'name'            => 'highlight.string',
                    
'title'           => 'Kolor string',
                    
'description'     => 'Tu podaj kolor HEX',
                    
'optionscode'     => 'text',
                    
'value'           => '#C0FF21',
                    
'disporder'       => $disporter++,
                    
'gid'             => $group['gid'],
    );

    
$db->insert_query('settings'$settings1);

    
$settings2 = array(
                    
'name'            => 'highlight.comment',
                    
'title'           => 'Kolor comment',
                    
'description'     => 'Tu podaj kolor HEX',
                    
'optionscode'     => 'text',
                    
'value'           => '#1E90FF',
                    
'disporder'       => $disporter++,
                    
'gid'             => $group['gid'],
    );

    
$db->insert_query('settings'$settings2);

    
$settings3 = array(
                    
'name'            => 'highlight.keyword',
                    
'title'           => 'Kolor keyword',
                    
'description'     => 'Tu podaj kolor HEX',
                    
'optionscode'     => 'text',
                    
'value'           => '#FFC0CB',
                    
'disporder'       => $disporter++,
                    
'gid'             => $group['gid'],
    );

    
$db->insert_query('settings'$settings3);

    
$settings4 = array(
                    
'name'            => 'highlight.default',
                    
'title'           => 'Kolor default',
                    
'description'     => 'Tu podaj kolor HEX',
                    
'optionscode'     => 'text',
                    
'value'           => '#cecece',
                    
'disporder'       => $disporter++,
                    
'gid'             => $group['gid'],
    );

    
$db->insert_query('settings'$settings4);
    
rebuild_settings();
}

function 
phpcolors_deactivate(){
    global 
$db;
    
$db->delete_query("settings""name='phpcolors'");
    
$db->delete_query("settings""name='highlight.string'");
    
$db->delete_query("settings""name='highlight.comment'");
    
$db->delete_query("settings""name='highlight.keyword'");
    
$db->delete_query("settings""name='highlight.default'");
    
$db->delete_query("settinggroups""name='phpcolors'");
    
rebuild_settings();
}

function 
phpcolors_start(){
    global 
$mybb;
// tu kod wlasciwy
}
?>
Od dzięki, działa ;) A czy możesz mi wyjaśnić działanie phpcolors_start() i rebuild_settings(); i czemu tylko w tych dwóch miejscach?
phpcolors_start()

Twoja funkcja wywolana hookiem show thread_start

rebuild_settings()

Przebudowuje Twoje ustawienia w pliku settings,php czyli dodaje usuwa je z tego pliku

Wysłane z mojego LG-P700 przy użyciu Tapatalka



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

1 gości