Hallo, Gast! (Registrieren)

Letzte Ankündigung: MyBB 1.8.37 veröffentlicht (04.11.23)


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste
Portal erweitern - Frage zu Plugin
#1
Hallo,

derzeit arbeite ich an einer Erweiterung des Portals um dort mehr Infos und außerdem eine bessere Sortierung zu erreichen. Aus diesem Grund habe ich derzeit die Portal.php sowie die entsprechenden Templates angepasst bzw. neue erstellt.

Im Moment wird am Anfang die ersten 2 Announcements aus dem Forum oben in voller Breite dargestellt.

Darunter sind zwei neue Tabellen (links & rechts) die jeweils nur 50% breit sind. Das ganze klappt auch soweit ganz gut. Nur würde ich gerne die Portal.php unberührt lassen und den zusätzlichen Code in eine Plugin auslagern. Leider hören hier dann meine Plugin-Kenntnisse langsam auf und es mag einfach nicht funktionieren. Vermutlich bin ich einfach noch nicht so ganz hinter das System "Plugin" gestiegen.

Derzeit habe ich in der portal.php folgendes unter dem portal_end Hook eingefügt (im endeffekt zwei angepasste Announcment-Versionen)
PHP-Code:
//reviewsection-test
// Get latest news reviews
// First validate review fids:
$reviewsfids "4";
if(
is_array($reviewsfids))
{
    foreach(
$reviewsfids as $fid)
    {
        
$fid_array[] = intval($fid);
    }
    
$reviewsfids implode(','$fid_array);
}
// And get them!
$query $db->simple_select("forums""*""fid IN (".$reviewsfids.")");
while(
$forumrow $db->fetch_array($query))
{
    
$forum[$forumrow['fid']] = $forumrow;
}

$numreviews intval(5);
$numreviews $numreviews 5;
if(!
$numreviews)
{
    
$numreviews 10// Default back to 10
}

$pids '';
$tids '';
$comma '';
$query $db->query("
    SELECT p.pid, p.message, p.tid, p.smilieoff
    FROM "
.TABLE_PREFIX."posts p
    LEFT JOIN "
.TABLE_PREFIX."threads t ON (t.tid=p.tid)
    WHERE t.fid IN ("
.$reviewsfids.") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
    ORDER BY t.dateline DESC 
    LIMIT 4, 
{$numreviews}"
);
while(
$getid $db->fetch_array($query))
{
    
$pids .= ",'{$getid['pid']}'";
    
$tids .= ",'{$getid['tid']}'";
    
$posts[$getid['tid']] = $getid;
}
$pids "pid IN(0{$pids})";
// Now lets fetch all of the attachments for these posts
$query $db->simple_select("attachments""*"$pids);
while(
$attachment $db->fetch_array($query))
{
    
$attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
}

if(
is_array($forum))
{
    foreach(
$forum as $fid => $forumrow)
    {
        
$forumpermissions[$fid] = forum_permissions($fid);
    }
}

$icon_cache $cache->read("posticons");

$reviews '';
$query $db->query("
    SELECT t.*, t.username AS threadusername, u.username, u.avatar, u.avatardimensions
    FROM "
.TABLE_PREFIX."threads t
    LEFT JOIN "
.TABLE_PREFIX."users u ON (u.uid = t.uid)
    WHERE t.fid IN ("
.$reviewsfids.") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
    ORDER BY t.dateline DESC
    LIMIT 0, 
{$numreviews}"
);
while(
$review $db->fetch_array($query))
{
    
// Make sure we can view this review
    
if($forumpermissions[$review['fid']]['canview'] == || $forumpermissions[$review['fid']]['canviewthreads'] == || $forumpermissions[$review['fid']]['canonlyviewownthreads'] == && $review['uid'] != $mybb->user['uid'])
    {
        continue;
    }

    
$review['message'] = $posts[$review['tid']]['message'];
    
$review['pid'] = $posts[$review['tid']]['pid'];
    
$review['smilieoff'] = $posts[$review['tid']]['smilieoff'];
    
$review['threadlink'] = get_thread_link($review['tid']);

    
    if(
$review['uid'] == 0)
    {
        
$profilelink htmlspecialchars_uni($review['threadusername']);
    }
    else
    {
        
$profilelink build_profile_link($review['username'], $review['uid']);
    }
    
    if(!
$review['username'])
    {
        
$review['username'] = $review['threadusername'];
    }
    
$review['subject'] = htmlspecialchars_uni($parser->parse_badwords($review['subject']));
    if(
$review['icon'] > && $icon_cache[$review['icon']])
    {
        
$icon $icon_cache[$review['icon']];
        
$icon "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
    }
    else
    {
        
$icon "&nbsp;";
    }
    if(
$review['avatar'] != '')
    {
        
$avatar_dimensions explode("|"$review['avatardimensions']);
        if(
$avatar_dimensions[0] && $avatar_dimensions[1])
        {
            
$avatar_width_height "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\"";
        }
        if (!
stristr($review['avatar'], 'http://'))
        {
            
$review['avatar'] = $mybb->settings['bburl'] . '/' $review['avatar'];
        }        
        
$avatar "<td class=\"trow1\" width=\"1\" align=\"center\" valign=\"top\"><img src=\"{$review['avatar']}\" alt=\"\" {$avatar_width_height} /></td>";
    }
    else
    {
        
$avatar '';
    }
    
$anndate my_date($mybb->settings['dateformat'], $review['dateline']);
    
$anntime my_date($mybb->settings['timeformat'], $review['dateline']);

    if(
$review['replies'])
    {
        eval(
"\$numcomments = \"".$templates->get("portal_review_numcomments")."\";");
    }
    else
    {
        eval(
"\$numcomments = \"".$templates->get("portal_review_numcomments_no")."\";");
        
$lastcomment '';
    }
    
    
$plugins->run_hooks("portal_review");

    
$parser_options = array(
        
"allow_html" => $forum[$review['fid']]['allowhtml'],
        
"allow_mycode" => $forum[$review['fid']]['allowmycode'],
        
"allow_smilies" => $forum[$review['fid']]['allowsmilies'],
        
"allow_imgcode" => $forum[$review['fid']]['allowimgcode'],
        
"allow_videocode" => $forum[$review['fid']]['allowvideocode'],
        
"filter_badwords" => 1
    
);
    if(
$review['smilieoff'] == 1)
    {
        
$parser_options['allow_smilies'] = 0;
    }

    
$message2 $parser->parse_message($review['message'], $parser_options);
    
$message2 strip_tags($message2'<img>');
    
//$excerpt = substr ($message2, 0, 500);
$excerpt substr($message2.' ' 501);
$excerpt substr($excerpt strrpos ($excerpt ' '));    
    if(
is_array($attachcache[$review['pid']]))
    { 
// This post has 1 or more attachments
        
$validationcount 0;
        
$id $review['pid'];
        foreach(
$attachcache[$id] as $aid => $attachment)
        {
            if(
$attachment['visible'])
            { 
// There is an attachment thats visible!
                
$attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
                
$attachment['filesize'] = get_friendly_size($attachment['filesize']);
                
$ext get_extension($attachment['filename']);
                if(
$ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg")
                {
                    
$isimage true;
                }
                else
                {
                    
$isimage false;
                }
                
$attachment['icon'] = get_attachment_icon($ext);
                
// Support for [attachment=id] code
                
if(stripos($message"[attachment=".$attachment['aid']."]") !== false)
                {
                    if(
$attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
                    { 
// We have a thumbnail to show (and its not the "SMALL" enough image
                        
eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
                    }
                    elseif(
$attachment['thumbnail'] == "SMALL" && $forumpermissions[$review['fid']]['candlattachments'] == 1)
                    {
                        
// Image is small enough to show - no thumbnail
                        
eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";");
                    }
                    else
                    {
                        
// Show standard link to attachment
                        
eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";");
                    }
                    
$message preg_replace("#\[attachment=".$attachment['aid']."]#si"$attbit$message);
                }
                else
                {
                    if(
$attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
                    { 
// We have a thumbnail to show
                        
eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
                        if(
$tcount == 5)
                        {
                            
$thumblist .= "<br />";
                            
$tcount 0;
                        }
                        ++
$tcount;
                    }
                    elseif(
$attachment['thumbnail'] == "SMALL" && $forumpermissions[$review['fid']]['candlattachments'] == 1)
                    {
                        
// Image is small enough to show - no thumbnail
                        
eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";");
                    }
                    else
                    {
                        eval(
"\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";");
                    }
                }
            }
            else
            {
                
$validationcount++;
            }
        }
        if(
$post['thumblist'])
        {
            eval(
"\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";");
        }
        if(
$post['imagelist'])
        {
            eval(
"\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";");
        }
        if(
$post['attachmentlist'] || $post['thumblist'] || $post['imagelist'])
        {
            eval(
"\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";");
        }
    }

    eval(
"\$reviews .= \"".$templates->get("portal_review")."\";");
    unset(
$post);
}

//review 2 Block 
// First validate review2 fids:
$reviews2fids "6";
if(
is_array($reviews2fids))
{
    foreach(
$reviews2fids as $fid)
    {
        
$fid_array[] = intval($fid);
    }
    
$reviews2fids implode(','$fid_array);
}
// And get them!
$query $db->simple_select("forums""*""fid IN (".$reviews2fids.")");
while(
$forumrow $db->fetch_array($query))
{
    
$forum[$forumrow['fid']] = $forumrow;
}

$numreviews2 intval(5);
if(!
$numreviews2)
{
    
$numreviews2 10// Default back to 10
}

$pids '';
$tids '';
$comma '';
$query $db->query("
    SELECT p.pid, p.message, p.tid, p.smilieoff
    FROM "
.TABLE_PREFIX."posts p
    LEFT JOIN "
.TABLE_PREFIX."threads t ON (t.tid=p.tid)
    WHERE t.fid IN ("
.$reviews2fids.") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
    ORDER BY t.dateline DESC 
    LIMIT 1, 
{$numreviews2}"
);
while(
$getid $db->fetch_array($query))
{
    
$pids .= ",'{$getid['pid']}'";
    
$tids .= ",'{$getid['tid']}'";
    
$posts[$getid['tid']] = $getid;
}
$pids "pid IN(0{$pids})";
// Now lets fetch all of the attachments for these posts
$query $db->simple_select("attachments""*"$pids);
while(
$attachment $db->fetch_array($query))
{
    
$attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
}

if(
is_array($forum))
{
    foreach(
$forum as $fid => $forumrow)
    {
        
$forumpermissions[$fid] = forum_permissions($fid);
    }
}

$icon_cache $cache->read("posticons");

$reviews2 '';
$query $db->query("
    SELECT t.*, t.username AS threadusername, u.username, u.avatar, u.avatardimensions
    FROM "
.TABLE_PREFIX."threads t
    LEFT JOIN "
.TABLE_PREFIX."users u ON (u.uid = t.uid)
    WHERE t.fid IN ("
.$reviews2fids.") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
    ORDER BY t.dateline DESC
    LIMIT 0, 
{$numreviews2}"
);
while(
$review2 $db->fetch_array($query))
{
    
// Make sure we can view this review2
    
if($forumpermissions[$review2['fid']]['canview'] == || $forumpermissions[$review2['fid']]['canviewthreads'] == || $forumpermissions[$review2['fid']]['canonlyviewownthreads'] == && $review2['uid'] != $mybb->user['uid'])
    {
        continue;
    }

    
$review2['message'] = $posts[$review2['tid']]['message'];
    
$review2['pid'] = $posts[$review2['tid']]['pid'];
    
$review2['smilieoff'] = $posts[$review2['tid']]['smilieoff'];
    
$review2['threadlink'] = get_thread_link($review2['tid']);

    
    if(
$review2['uid'] == 0)
    {
        
$profilelink htmlspecialchars_uni($review2['threadusername']);
    }
    else
    {
        
$profilelink build_profile_link($review2['username'], $review2['uid']);
    }
    
    if(!
$review2['username'])
    {
        
$review2['username'] = $review2['threadusername'];
    }
    
$review2['subject'] = htmlspecialchars_uni($parser->parse_badwords($review2['subject']));
    if(
$review2['icon'] > && $icon_cache[$review2['icon']])
    {
        
$icon $icon_cache[$review2['icon']];
        
$icon "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
    }
    else
    {
        
$icon "&nbsp;";
    }
    if(
$review2['avatar'] != '')
    {
        
$avatar_dimensions explode("|"$review2['avatardimensions']);
        if(
$avatar_dimensions[0] && $avatar_dimensions[1])
        {
            
$avatar_width_height "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\"";
        }
        if (!
stristr($review2['avatar'], 'http://'))
        {
            
$review2['avatar'] = $mybb->settings['bburl'] . '/' $review2['avatar'];
        }        
        
$avatar "<td class=\"trow1\" width=\"1\" align=\"center\" valign=\"top\"><img src=\"{$review2['avatar']}\" alt=\"\" {$avatar_width_height} /></td>";
    }
    else
    {
        
$avatar '';
    }
    
$anndate my_date($mybb->settings['dateformat'], $review2['dateline']);
    
$anntime my_date($mybb->settings['timeformat'], $review2['dateline']);

    if(
$review2['replies'])
    {
        eval(
"\$numcomments = \"".$templates->get("portal_review_numcomments")."\";");
    }
    else
    {
        eval(
"\$numcomments = \"".$templates->get("portal_review_numcomments_no")."\";");
        
$lastcomment '';
    }
    
    
$parser_options = array(
        
"allow_html" => $forum[$review2['fid']]['allowhtml'],
        
"allow_mycode" => $forum[$review2['fid']]['allowmycode'],
        
"allow_smilies" => $forum[$review2['fid']]['allowsmilies'],
        
"allow_imgcode" => $forum[$review2['fid']]['allowimgcode'],
        
"allow_videocode" => $forum[$review2['fid']]['allowvideocode'],
        
"filter_badwords" => 1
    
);
    if(
$review2['smilieoff'] == 1)
    {
        
$parser_options['allow_smilies'] = 0;
    }

    
$message2 $parser->parse_message($review2['message'], $parser_options);
    
$message2 strip_tags($message2'<img>');
//    $excerpt = substr ($message2, 0, 500);    
$excerpt substr($message2.' ' 501);
$excerpt substr($excerpt strrpos ($excerpt ' '));
    if(
is_array($attachcache[$review2['pid']]))
    { 
// This post has 1 or more attachments
        
$validationcount 0;
        
$id $review2['pid'];
        foreach(
$attachcache[$id] as $aid => $attachment)
        {
            if(
$attachment['visible'])
            { 
// There is an attachment thats visible!
                
$attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
                
$attachment['filesize'] = get_friendly_size($attachment['filesize']);
                
$ext get_extension($attachment['filename']);
                if(
$ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg")
                {
                    
$isimage true;
                }
                else
                {
                    
$isimage false;
                }
                
$attachment['icon'] = get_attachment_icon($ext);
                
// Support for [attachment=id] code
                
if(stripos($message"[attachment=".$attachment['aid']."]") !== false)
                {
                    if(
$attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
                    { 
// We have a thumbnail to show (and its not the "SMALL" enough image
                        
eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
                    }
                    elseif(
$attachment['thumbnail'] == "SMALL" && $forumpermissions[$review2['fid']]['candlattachments'] == 1)
                    {
                        
// Image is small enough to show - no thumbnail
                        
eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";");
                    }
                    else
                    {
                        
// Show standard link to attachment
                        
eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";");
                    }
                    
$message preg_replace("#\[attachment=".$attachment['aid']."]#si"$attbit$message);
                    
$excerpt substr($message0500);
                }
                else
                {
                    if(
$attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
                    { 
// We have a thumbnail to show
                        
eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
                        if(
$tcount == 5)
                        {
                            
$thumblist .= "<br />";
                            
$tcount 0;
                        }
                        ++
$tcount;
                    }
                    elseif(
$attachment['thumbnail'] == "SMALL" && $forumpermissions[$review2['fid']]['candlattachments'] == 1)
                    {
                        
// Image is small enough to show - no thumbnail
                        
eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";");
                    }
                    else
                    {
                        eval(
"\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";");
                    }
                }
            }
            else
            {
                
$validationcount++;
            }
        }
        if(
$post['thumblist'])
        {
            eval(
"\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";");
        }
        if(
$post['imagelist'])
        {
            eval(
"\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";");
        }
        if(
$post['attachmentlist'] || $post['thumblist'] || $post['imagelist'])
        {
            eval(
"\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";");
        }
    }

    eval(
"\$reviews2 .= \"".$templates->get("portal_review_right")."\";");
    unset(
$post);


Diese Zeilen würde ich nun gern in das Plugin bringen und dann über den portal_end hook einbinden. Leider führen alle derzeitigen Versuche zu einer weißen Seite im Board.
Im Plugin habe ich derzeit folgendes angegeben
Code:
global $lang, $db, $mybb, $templates, $post, $forumpermissions;
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";

Vermutlich habe ich hier einen typischen Anfängerfehler da ich das Plugin-System noch nicht durchdrungen habe. Vielleicht kann mir ja jemand einen Ansatzpunkt geben was ich beachten muss bzw. wo mein Denkfehler liegt.

Es soll am ende so aussehen wie hier: http://theandroidblog.de/portal.php
Zitieren
#2
Weiße Seiten erscheinen, wenn die Fehlerbearbeitung von PHP aus ist. Dann ist es selbst für eine Profi praktisch unmöglich den Fehler zu finden.
[Bild: banner.png]

Bitte die Foren-Regeln beachten und im Profil die verwendete MyBB-Version angeben.
Zitieren
#3
Danke, dass hat mir schon sehr weiter geholfen. Konnte die Fehlerbearbeitung per htaccess aktivieren und damit die Störenfriede ausschalten. Mittlerweile geht das Plugin zu 50% und die erste "Halbe" Tabelle wird schon mal angezeigt. Die Zweite macht noch Problem und wird nicht angezeigt. Da muss ich noch nacharbeiten

Edit: hat sich auch erledigt. Hatte eine $games Variable nicht global definiert.
Zitieren