News:

Wondering if this will always be free?  See why free is better.

Main Menu

HELP:News integration for my website.

Started by mpglivecarlo, October 23, 2009, 06:20:58 PM

Previous topic - Next topic

mpglivecarlo

i got the attachments issue resolved, but now i need syntax for query to get the first attachment for a specific topic so i can diplay it on a diferent template.

been trying some code i found on the forums but i get a fatal error Call to undefined function db_query() :S

Arantor

db_query is for SMF 1.1 only. The equivalent in SMF 2 is $smcFunc['db_query'].

Is the attachment in the first message of that topic?

mpglivecarlo

yes attachment is in first msg of the topic.

tried the way you worte but still gave an error, i think the syntax is wrong. cause it was using db_query

Arantor

Yes, it probably was because db_query is quite different to $smcFunc['db_query'].

What code, exactly, do you have right now?

mpglivecarlo

this was the code i found and was thinking on using since they said it would get the first attachment image for display from a topic.

$topic_id = $news['id'];
// get the details of the attachment
if($topic_id > 0) {
  $query = db_query('
  SELECT ID_ATTACH, width, height
  FROM topics t INNER JOIN attachments a ON
  (t.ID_FIRST_MSG = a.ID_MSG) WHERE a.ID_THUMB = 0
  AND t.ID_TOPIC = ' . $topic_id . ' ORDER BY a.ID_ATTACH ASC LIMIT 1
   ', __FILE__, __LINE__);
}

// display the attachment - link back to SMF to do so to track hits
if($row = mysql_fetch_assoc($query)) {
  echo '<img src="index.php?action=dlattach;topic=', $topic_id , '.0;attach=', $row['ID_ATTACH'], '" width="', $row['width'], '" height="', $row['height'], '">';
}


the $news['id']; I added since its how i can send the topic id to the code.

Arantor

Yes, it'll do that. Needs a few little tweaks for 2.0, but nothing earth shattering.

$topic_id = (int) $news['id'];
// get the details of the attachment
if($topic_id > 0) {
  $query = $smcFunc['db_query']('', '
  SELECT id_attach, width, height
  FROM {db_prefix}topics t INNER JOIN {db_prefix}attachments a ON
  (t.id_first_msg = a.id_msg) WHERE a.id_thumb = 0
  AND t.id_topic = {int:topic} ORDER BY a.id_attach ASC LIMIT 1
   ',
    array(
      'topic' => $topic_id
    )
  );

  // display the attachment - link back to SMF to do so to track hits
  if($row = $smcFunc['db_fetch_assoc']($query)) {
    echo '<img src="index.php?action=dlattach;topic=', $topic_id , '.0;attach=', $row['ID_ATTACH'], '" width="', $row['width'], '" height="', $row['height'], '">';
  $smcFunc['db_free_result']($query);
}

mpglivecarlo

#26
query is not working right cause the link is missing the id_attach.

im using the ssi_boardnews to get the topic and first message from topic, seems query for attachment is missing something. posting the code from ssi_boardnews.

<?php

$news1 
ssi_boardNews(385null500'array');
       foreach (
$news1 as $news)
             echo
'<h3><a href="'$news['href'], '">''</a> '$news['subject'], '</h3>
<span>'
$news['time'], ' '$txt['by'], ' <strong> '$news['poster']['link'], '</strong></span>

'
$news['body'], '<div class="comenta"><div class="ver_mas">'$news['link'], $news['locked'] ? '' '</div><div class="comentario">' $news['comment_link']. '</div></div><br><br>';
?>



Another thing it seems that the code is going to display the thumbnail, but i want is the full size image.

Arantor

:facepalm:

Should have been $row['id_attach'] instead of $row['ID_ATTACH'].

mpglivecarlo

now it shows id_attach in link, but still no image just a blank square; another thing, is it possible to show the full size image and not the thumb?

thx

Arantor

Is the board where the attachment is visible to guests?

mpglivecarlo

#30
hi, back from my trip, yes guest are allowed to view attachments (but even tho im testing it logged in), but all it displays is a blank square with the attachment link correct i think but no image.

But i cant seem to make both codes work, im using the ssiboardnews to get the latest 5 posts from board 38 in array mode, thats working right, but since the ssiBoardNews does not include attachment images that's why I needed the code to get the topics first attachment, now i have a blank square that is the image url but it only "shows" (as I stated it only show a blank white square) from the last board news item the first four topics are only showing the text and title from the post.

im putting the whole code here:

$news1 = ssi_boardNews(38, 5, null, 300, 'array');
       foreach ($news1 as $news)
             echo
         '<h3><a href="', $news['href'], '">', $news['subject'], '</a></h3>
            <span>', $news['time'], ' ', $txt['by'], ' <strong> ', $news['poster']['link'], '</strong></span>

            ', $news['body'], '<div class="comenta"><div class="ver_mas">', $news['link'], $news['locked'] ? '' : '</div><div class="comentario">' . $news['comment_link']. '</div></div><br><br>';

$topic_id = (int) $news['id'];
// get the details of the attachment
if($topic_id > 0) {
  $query = $smcFunc['db_query']('', '
  SELECT id_attach, width, height
  FROM {db_prefix}topics t INNER JOIN {db_prefix}attachments a ON
  (t.id_first_msg = a.id_msg) WHERE a.id_thumb = 0
  AND t.id_topic = {int:topic} ORDER BY a.id_attach ASC LIMIT 1
   ',
    array(
      'topic' => $topic_id
    )
  );

  // display the attachment - link back to SMF to do so to track hits
  if($row = $smcFunc['db_fetch_assoc']($query)) {
    echo '<img src="index.php?action=dlattach;topic=', $topic_id , '.0;attach=', $row['id_attach'], '" width="', $row['width'], '" height="', $row['height'], '">';
  $smcFunc['db_free_result']($query);
}
}


I want the code to get the last 5 topics from the board and show the first attachment from each topic as a main full size image and a small part of the news.

Arantor

You might be better waiting a little bit for my mod to come along, ssi_multiBoardNews that will drastically simplify this process.

mpglivecarlo

Quote from: Arantor on November 24, 2009, 02:25:25 PM
You might be better waiting a little bit for my mod to come along, ssi_multiBoardNews that will drastically simplify this process.

not to sound too eager, but any ETA on the date? :P

Arantor

When the Customizer team approve it. Since it's my mod, I can't approve it.

It has the option to actually get attachments for you; then it's just a matter of display rather than anything else.

mpglivecarlo

Quote from: Arantor on November 24, 2009, 03:49:49 PM
When the Customizer team approve it. Since it's my mod, I can't approve it.

It has the option to actually get attachments for you; then it's just a matter of display rather than anything else.

nice mate thx a lot, when it comes out ill be the first to download and test, even bother you with questions :P

mpglivecarlo

ok, while we wait until your mod is online, can you help me on how to make a custom permission rule?

i want guests to see the attachments but not to be able to download them. is it possible?

ATM my website shows downloads to all users registered or unregistered, but when they try to download them a php file checks if user is logued in to give them the direct link for the download; and for "download theft" when a user posts the direct link of the download location the hosting will send them a forbiden access to the folder so they cant download it unless they get the link thru the website.

since the hotlink option on the server needs a file extension then i cant apply it to the atachments since the file itself does not have an extension.

Arantor

If they are image downloads, it gets incredibly complex to do (in theory separating image from thumbnail is doable, though images too small to have thumbnails will fail). It would be possible to list non image downloads and have them be visible without being downloadable. Thinking about it, the mod should do it like that.

mpglivecarlo

Quote from: Arantor on November 26, 2009, 05:20:30 PM
If they are image downloads, it gets incredibly complex to do (in theory separating image from thumbnail is doable, though images too small to have thumbnails will fail). It would be possible to list non image downloads and have them be visible without being downloadable. Thinking about it, the mod should do it like that.

srry forgot to specify, downlaos i mean are .RAR, zip, EXE and that sort of files, images i don really need this for, website hostes patches for some games and the video broadcasts of several latin tournaments, they are compressed in rar and zip

Arantor

Yeah, in which case the mod should work; it doesn't perform a permissions check on the list of attachments (since that's implied by the admin setting options in the code anyway), but the attachment system will check prior to downloading.

Once the mod is approved I'll go over how it needs to be used here.

mpglivecarlo

Quote from: Arantor on November 26, 2009, 05:34:02 PM
Yeah, in which case the mod should work; it doesn't perform a permissions check on the list of attachments (since that's implied by the admin setting options in the code anyway), but the attachment system will check prior to downloading.

Once the mod is approved I'll go over how it needs to be used here.

thx mate....

Advertisement: