Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 09-21-2007, 12:34 AM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Issue with attachment.php calling thumbs

I'm using attachment.php to display thumbnails for attachments. This is being used in a custom script which resides within the AdminCP and it's called in the same manner in which it's used in postbit to display thumbs:

http://www.mysite.com/forum/attachme...1&d=1189977330

The thumbnails display properly when any menber views their own attachments, however when they attempt to view another member's attachments, the image is not displayed (i get the box with red X in it).

You can see the result of the query which is called within the script in attached "query.gif"

The issue which i feel might be the problem is that there's no forumid passed into $attachmentinfo and therefore no $forumperms to view the attachment? I think that's the issue, but not sure because when I comment out the following block of code (taken from attachment.php) the image still doesn't show, however when i run the script to call the same exact imageid but while logged in as the user who posted the attachment, it does show.

PHP Code:
if ($attachmentinfo['postid'] == 0)
{    
// Attachment that is in progress but hasn't been finalized
    
if ($vbulletin->userinfo['userid'] != $attachmentinfo['userid'] AND !can_moderate($attachmentinfo['forumid'], 'caneditposts'))
    {    
// Person viewing did not upload it
        
eval(standard_error(fetch_error('invalidid'$idname$vbulletin->options['contactuslink'])));
    }
    
// else allow user to view the attachment (from the attachment manager for example)
}
else
{
    
$forumperms fetch_permissions($attachmentinfo['forumid']);

    
$threadinfo = array('threadid' => $attachmentinfo['threadid']); // used for session.inthread
    
$foruminfo = array('forumid' => $attachmentinfo['forumid']); // used for session.inforum

    # Block attachments belonging to soft deleted posts and threads
    
if (!can_moderate($attachmentinfo['forumid']) AND ($attachmentinfo['post_visible'] == OR $attachmentinfo['thread_visible'] == 2))
    {
        eval(
standard_error(fetch_error('invalidid'$idname$vbulletin->options['contactuslink'])));
    }

    
# Block attachments belonging to moderated posts and threads
    
if (!can_moderate($attachmentinfo['forumid'], 'canmoderateposts') AND ($attachmentinfo['post_visible'] == OR $attachmentinfo['thread_visible'] == 0))
    {
        eval(
standard_error(fetch_error('invalidid'$idname$vbulletin->options['contactuslink'])));
    }

    if (!(
$forumperms $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['cangetattachment'])  OR (!($forumperms $vbulletin->bf_ugp_forumpermissions['canviewothers']) AND ($attachmentinfo['postuserid'] != $vbulletin->userinfo['userid'] OR $vbulletin->userinfo['userid'] == 0)))
    {
        
print_no_permission();
    }

    
// check if there is a forum password and if so, ensure the user has it set
    
verify_forum_password($attachmentinfo['forumid'], $vbulletin->forumcache["$attachmentinfo[forumid]"]['password']);

    if (!
$attachmentinfo['visible'] AND !can_moderate($attachmentinfo['forumid'], 'canmoderateattachments') AND $attachmentinfo['userid'] != $vbulletin->userinfo['userid'])
    {
        eval(
standard_error(fetch_error('invalidid'$idname$vbulletin->options['contactuslink'])));
    }

How can I bypass this issue? I can't seem to narrow down what the problem is really. I even tried editing the attachment.php file and adding the following just before the block above but it didnt work either:

PHP Code:
// assign a forumid in which all users have all permissions assigned
$attachmentinfo['forumid'] = 1
Any ideas? I've been stumped on this for 2 days now.
Attached Images
File Type: jpg query.jpg (14.3 KB, 0 views)
Reply With Quote
  #2  
Old 09-25-2007, 10:39 AM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bump - can anyone help?
Reply With Quote
  #3  
Old 10-18-2007, 09:49 PM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm so sad, this is killing me. Still can't figure this out.
Reply With Quote
  #4  
Old 10-18-2007, 10:08 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It would probably be useful to see what the source code in the page looks like for the img tags. Also, have you tried doing a query in the attachment.php page to find out what forum the attachment is in and using that variable in the rest of the code? At least that way you can find out if the forumid is the problem.
Reply With Quote
  #5  
Old 10-19-2007, 03:02 PM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The code which is creating the thumbnails is as follows:
PHP Code:
    while ($attachment $db->fetch_array($attachments))
    {
        if (!
$attachment['build_thumbnail'])
        {
            
$attachment['hasthumbnail'] = false;
        }
        
$feedback['attachments']["$attachment[attachmentid]"] = $attachment;

        if (
$attachment['hasthumbnail'])
        {
            
$thumbcount++;
            if (
$vbulletin->options['attachrow'] AND $thumbcount >= $vbulletin->options['attachrow'])
            {
                
$thumbcount 0;
                
$show['br'] = true;
            }
            else
            {
                
$show['br'] = false;
            }
            
            
// ... define transparency for attachments with visible = 0
            
if ($attachment['visible'])
            {
                
$transparency '';
            }
            else
            {
                
$transparency '-moz-opacity:0.2; filter:alpha(opacity=20)';
            }
            
            
// ... display each thumbnail
            
$thumbs .= 
                
'<a href="../attachment.php?' $vbulletin->session->vars['sessionurl'] . "attachmentid=$attachment[attachmentid]&amp;stc=1&amp;d=$attachment[thumbnail_dateline]\" target=\"_blank\"><img src=\"../attachment.php?" $vbulletin->session->vars['sessionurl'] . "attachmentid=$attachment[attachmentid]&amp;thumb=1&amp;d=$attachment[dateline]\" border=\"0\" style=\"$transparency\" class=\"thumbnail\" alt=\"Attachment id: $attachment[attachmentid]\" /></a><a href=\"attachment.php" $vbulletin->session->vars['sessionurl'] . "?do=edit&amp;attachmentid=$attachment[attachmentid]\" target=\"_blank\"><img src=\"../images/statusicon/icon_editimage.gif\" border=\"0\" alt=\"Edit Image\" /></a>
                &nbsp;" 
iif($show['br'], "<br /><br />") . "
            "
;
            
$show['thumbnailattachment'] = true;
        }
    
    } 
I don't think that's the issue as it works just fine for generating thumbs for attachments posted by myself, the problem occurrs when viewing thumbs for any other member.

It's probably relevant that these thumbnails for attachments are NOT associated with posts, threads or forums. they are associated with Feedback reports. Therefore the query which gathers the attachment data from the database returns no forumid. (please see attached "query_result_attachment-php.gif" ).

I thought since there's no forumid returned, the following code in attachment.php is unable to generate the $forumperms needed and it's the reason for the error:

PHP Code:
    $forumperms fetch_permissions($attachmentinfo['forumid']);

    
$threadinfo = array('threadid' => $attachmentinfo['threadid']); // used for session.inthread
    
$foruminfo = array('forumid' => $attachmentinfo['forumid']); // used for session.inforum 
But that can't be it, since there's no forum id returned either when viewing my own attachment thumbnail.

If the thumb is clisked on to view the attachment in a full size window, I get a NO PERMISSION error. Now the interesting thing is, the no permission error ( print_no_permission(); ) is only located in the following part of the attachment.php script:

PHP Code:
    if (!($forumperms $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['cangetattachment'])  OR (!($forumperms $vbulletin->bf_ugp_forumpermissions['canviewothers']) AND ($attachmentinfo['postuserid'] != $vbulletin->userinfo['userid'] OR $vbulletin->userinfo['userid'] == 0)))
    {
        
print_no_permission();
    } 
But if i comment that part out in attachment php, the thumbnail still doesn't display, and i still get the nopermission error when opening the full wondow.

It baffles my mind. Please anyone help, i will be eternally grateful.
Attached Images
File Type: jpg query_result_attachment-php.jpg (13.3 KB, 0 views)
Reply With Quote
  #6  
Old 10-19-2007, 04:41 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was actually wondering about what was being printed out in the source code for the page. I always like to see what is actually being parsed from the code. In fact, it sometimes helps to hide variables in there so you can see what is being fed to the page.

When you click on the thumbnail, you get a new window that is supposed to have the large image, correct? It would be useful to see what the source code is for that. Perhaps try to hide some variables in there in order to see what is being passed.

(Sorry I can't be more help specifically, I'm still running vB 3.0 - I'm just throwing out suggestions on how I troubleshoot things like this.)
Reply With Quote
  #7  
Old 10-24-2007, 04:22 PM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Lynne. I actually was able (finally) to solve this by assigning the missing $forumperms within hook location attachment_start.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:55 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04300 seconds
  • Memory Usage 2,297KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (2)postbit_attachment
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete