vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Way to get attachment url in header? (https://vborg.vbsupport.ru/showthread.php?t=278687)

tpearl5 02-16-2012 11:14 PM

Way to get attachment url in header?
 
I'm looking for a way to say....

If first attachment is an image, url

...in the headerinclude template.

Any ideas?

Lynne 02-17-2012 01:09 AM

I'm not sure I understand. How do you define the first attachment? Do you mean the first one used in the post? If so, you'd have to search for "[attach]" or "[attach=config]" in there and find the attachment id and then find out it's extension.

tpearl5 02-17-2012 01:13 AM

I guess it would be 'if an attachment in first post is an image'

Lynne 02-17-2012 01:23 AM

That is going to require a query done right off the bat since attachments aren't looked at at the time the header is rendered. You have the threadid at that point, but that is all. So, you'd need to do a query on the thread table to get the first postid and join with the filedata (maybe attachment - I'm not looking at a database right now) table and then take a look at the extension.

tpearl5 02-17-2012 01:52 AM

hrm, so it would be something like this?

SELECT attachmentid FROM attachment WHERE postid = $post[postid] ORDER BY attachmentid LIMIT 1

Lynne 02-17-2012 04:45 PM

There is no postid field in the attachment table. It would need to be something more like:

SELECT attachmentid FROM attachment WHERE contenttypeid=1 AND contentid= $post[postid] ORDER BY attachmentid LIMIT 1

(not tested at all)

tpearl5 02-18-2012 05:46 PM

oh okay - so then it would just be a matter of writing something to cache that in a database table so a query isn't run every time a page is loaded.

Lynne 02-18-2012 05:59 PM

I guess if I were going to do this, I would maybe add another field to the thread table. If that field is empty, then you run that query and then run another one to enter the attachmentid into the new field. That way, the two queries only get run the first time someone accesses the thread. You may need to do something for when someone edits the thread and changes attachments though.

tpearl5 02-19-2012 05:00 PM

Thanks for the tips Lynne. Btw, this is the reason I'm trying to figure out how to do this:
https://vborg.vbsupport.ru/showthread.php?t=275236

It doesn't make sense that the image for facebook is static.

Anatoliy2 05-31-2012 02:41 PM

Quote:

Originally Posted by Lynne (Post 2300569)
SELECT attachmentid FROM attachment WHERE contenttypeid=1 AND contentid= $post[postid] ORDER BY attachmentid LIMIT 1

So when my php scrypt got an attachmentid (in my case it's 24561) what the path to the image would be (so the script would display the image)? I see 'filename' - 1.jpg (the original name of the picture). What is the path to it?


All times are GMT. The time now is 12:06 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01089 seconds
  • Memory Usage 1,729KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete