Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Mod Requests => Topic started by: Motorhed on April 22, 2012, 08:46:38 PM

Title: [Paid] News Site SSI
Post by: Motorhed on April 22, 2012, 08:46:38 PM
Hi all.

First, let me state that I am very far from able to pay much for this modification, but I'm hoping it will be simple enough that my offer will not be an insult.

I am offering $15.




The Mod:

When you look at news sites, you'll see that news headlines usually look like this:


[IMAGE] [Title & Short Blurb]

[IMAGE] [Title & Short Blurb]

[IMAGE] [Title & Short Blurb]

[IMAGE] [Title & Short Blurb]


And so on. The idea being that there is an image to grab the reader's eye, and next to that image will be the headline and a short amount of text FROM that story.


For example, imagine the blocks on the left represent ONE big image floating left...

[________] POPE SHOOTS BEAR!
[________] by Motorhed, 01/21/12
[________] The Pope shot a bear today. He was strolling through the
[________] woods when suddenly the bear appeared from nowhere...
[________] Read More | 12 Comments


So essentially what we have is the current SSI board news thing, but here's the catch...

The image floating to the left is the first image attached to that post. In other words, attachment #1 of that post is displayed to the left of the news blurb.


No other attachments would be displayed, ONLY that one floating to the left. This is because other images would clearly break the layout if they appeared in the text.


I would also like an idea of how to add this to a SimplePortal block as well.


For any info, please ask.


Thanks!
Title: Re: [Paid] News Site SSI
Post by: TheListener on April 22, 2012, 10:26:31 PM
Have you considered using the portals RSS block?
Title: Re: [Paid] News Site SSI
Post by: Motorhed on April 22, 2012, 10:34:54 PM
Does that have the first attachment in the post aligned left of the title and blurb while displaying no other images?
Title: Re: [Paid] News Site SSI
Post by: TheListener on April 22, 2012, 10:38:43 PM
If you mean attachment as in image tthen no.

If ya have a look at my Broadstar link look at the Music-News block.


This is an RSS block.
Title: Re: [Paid] News Site SSI
Post by: Motorhed on April 22, 2012, 10:41:28 PM
Ah, okay.

Check out the post again, the attachment thing is the most important part and actually probably the only thing that makes this a mod as opposed to just using the board news SSI.
Title: Re: [Paid] News Site SSI
Post by: Motorhed on April 23, 2012, 08:15:53 PM
I'll figure this out myself. Thanks to anyone who took a look.
Title: Re: [Paid] News Site SSI
Post by: Motorhed on April 24, 2012, 02:27:24 AM
See the "News" and "Articles & Reviews" blocks on my portal to see this in action:

http://herohour.com
Title: Re: [Paid] News Site SSI
Post by: diontoradan on April 25, 2012, 03:20:26 PM
check out my site... is this what you looking for? the portal was made with php, but the content is taken from smf. you need some basic php / mysql knowledge to do this.

www.ravelex.net/articles

to display the news outside the forum i use SSI Topics and Replies mod, its easy, you just need the topic id.

for a simpler solution you can use Thumbnail Topic Mod, to display the first attachment on board index.

cheers...
Title: Re: [Paid] News Site SSI
Post by: Motorhed on April 25, 2012, 09:32:05 PM
Yes, that looks great! If you want to share, just let me know. :)

I have a portal and all set up, it's just that the only way I could figure out how to make this mod work was to "float: left" all images in the post text, then make sure the attachment was included (in-line attachment mod) before the character limit cut it off...


But if yours is displaying the first attachment from a post, regardless of whether it's included in the post text or not, then I'd definitely be up for that if you're so incluned as to let me know how to do it.



When you say all I would need is the Topic ID, do you mean you have to add each post to the main page by hand?
Title: Re: [Paid] News Site SSI
Post by: Motorhed on April 28, 2012, 10:13:14 PM
I'll take that as a 'no' on sharing. Ha ha ha! :) No worries.
Title: Re: [Paid] News Site SSI
Post by: Motorhed on April 29, 2012, 04:27:35 PM
I unmarked this as 'solved' because while I found a solution, it simply floats the first attachment IN the post to the left... meaning the person posting has to attach the image at the top of their post - and if they don't, it doesn't show at all.

Soooo... ugh.
Title: Re: [Paid] News Site SSI
Post by: Motorhed on April 30, 2012, 01:04:44 AM
Got it. Finally managed to dig up the ONE very old post here that noted how to do it. It's in the advanced SSI FAQ thread, IIRC.

Closed.
Title: Re: [Paid] News Site SSI
Post by: mane16 on June 06, 2012, 10:49:20 PM
Hey Motorhed, would you mind sharing a little explanation on how you did it (if you actually managed to do it), I want to do the same thing on simpleportal, but can't really think on how to actually do it, and my knowledge is also a little limited on this field.
Thanks in advance :)
Title: Re: [Paid] News Site SSI
Post by: Motorhed on July 02, 2012, 07:25:13 PM
Sorry for the late reply. I assumed nobody else cared about the feature.

Here is the edited boardNews code. I renamed it and added it in so that I could still have the OLD boardNews in place. It is now called squareNews and must be called by that name when adding the portal block...

You can see it in use here:

http://herohour.com (The front page news area and the header news w/edit to make it horizontal.)
http://incomics.com (The front page news area, this is not a forum portal.)

Put this in SSI.php, near the end but not outside the php code.


// Square news, assembled/stolen by Motorhed from various forum posts.
function ssi_squareNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $smcFunc;

loadLanguage('Stats');

// Must be integers....
if ($limit === null)
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
else
$limit = (int) $limit;

if ($start === null)
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
else
$start = (int) $start;

/*
if ($board !== null)
$board = (int) $board;
elseif (isset($_GET['board']))
$board = (int) $_GET['board'];
*/

if (empty($board))
return;
elseif (!is_array($board))
$board = array($board);

if ($length === null)
$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
else
$length = (int) $length;

$limit = max(0, $limit);
$start = max(0, $start);

/*
// Make sure guests can see this board.
$request = $smcFunc['db_query']('', '
SELECT id_board
FROM {db_prefix}boards
WHERE ' . ($board === null ? '' : 'id_board = {int:current_board}
AND ') . 'FIND_IN_SET(-1, member_groups)
LIMIT 1',
array(
'current_board' => $board,
)
);
if ($smcFunc['db_num_rows']($request) == 0)
{
if ($output_method == 'echo')
die($txt['ssi_no_guests']);
else
return array();
}
list ($board) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
*/

// Load the message icons - the usual suspects.
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

// Find the post ids.
$request = $smcFunc['db_query']('', '
SELECT id_first_msg
FROM {db_prefix}topics
WHERE id_board IN ({array_int:current_board})' . ($modSettings['postmod_active'] ? '
AND approved = {int:is_approved}' : '') . '
ORDER BY id_first_msg DESC
LIMIT ' . $start . ', ' . $limit,
array(
'current_board' => $board,
'is_approved' => 1,
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$posts[] = $row['id_first_msg'];
$smcFunc['db_free_result']($request);

if (empty($posts))
return array();

global $sourcedir, $attachments, $topic;
require_once($sourcedir . '/Display.php');

$attachments = array();
$request = $smcFunc['db_query']('', '
SELECT
a.id_attach, a.id_folder, a.id_msg, a.filename, IFNULL(a.size, 0) AS filesize, a.downloads, a.approved,
a.width, a.height' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ',
IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height') . '
FROM {db_prefix}attachments AS a' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : '
LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)') . '
WHERE a.id_msg IN ({array_int:message_list})
AND a.attachment_type = {int:attachment_type}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
AND a.approved = {int:is_approved}'),
array(
'message_list' => $posts,
'attachment_type' => 0,
'is_approved' => 1,
)
);
$temp = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$temp[$row['id_attach']] = $row;

if (!isset($attachments[$row['id_msg']]))
$attachments[$row['id_msg']] = array();
}
$smcFunc['db_free_result']($request);

ksort($temp);

foreach ($temp as $row)
$attachments[$row['id_msg']][] = $row;

// Find the posts.
$request = $smcFunc['db_query']('', '
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.num_views, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, t.id_last_msg
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT ' . count($posts),
array(
'post_list' => $posts,
)
);
$return = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// If we want to limit the length of the post.
if (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $length);

// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

if ($cutoff !== false)
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);

$topic = $row['id_topic'];
$return[] = array(
'attachments' => loadAttachmentContext($row['id_msg']),
'id' => $row['id_topic'],
'views' => $row['num_views'],
'message_id' => $row['id_msg'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" alt="' . $row['icon'] . '" />',
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>',
'replies' => $row['num_replies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';last_msg=' . $row['id_last_msg'],
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';last_msg=' . $row['id_last_msg'] . '">' . $txt['ssi_write_comment'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
),
'locked' => !empty($row['locked']),
'is_last' => false
);
}
$smcFunc['db_free_result']($request);

if (empty($return))
return $return;

$return[count($return) - 1]['is_last'] = true;

if ($output_method != 'echo')
return $return;

foreach ($return as $news)
{
$attachment = array();
if (!empty($news['attachments'][0]))
{
$attachment = $news['attachments'][0];

if ($attachment['is_image'])
{
if ($attachment['thumbnail']['has_thumb'])
echo '
<div class="floatsquare"><a href="', $news['href'], '"><img src="', $attachment['thumbnail']['href'], '" alt="' . $news['subject'] . '" border="0" /></a><br /></div>';
else
echo '
<div class="floatsquare"><a href="', $news['href'], '"><img src="' . $attachment['href'] . ';image" alt="' . $news['subject'] . '" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" border="0" /></a><br /></div>';
}
}
else
echo '
<div class="floatsquare"> &nbsp; </div>';

echo '
<div class="newsblock">
<div class="headline"><a href="', $news['href'], '">', $news['subject'], '</a></div>
<div class="details"><span style="display: none;">', $news['time'], '</span>', $txt['by'], ' ', $news['poster']['link'], ' | <i>' , $news['views'], ' views</i></div>
<div class="text">', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '</div>

</div>';

if (!$news['is_last'])
echo '
<hr />';
}
}


Note I removed some things you might want and that I call images and CSS that I made myself. You'll have to be clever and either remove those bits or make your own CSS entries to fit what I put, etc.

I cannot possibly properly credit all the code I used to make this - it came from multiple people in multiple places... so instead I have to credit "The SMF Community" for everything here that I didn't do myself.

Here is the CSS I used for some of this:



.headline {
display: block;
font-family: book antiqua;
font-style: italic;
font-size: 18px;
}

.headline a:link, .headline a:visited {
font-weight: bold;
text-decoration: none;
color: red;
}

.headline a:hover {
color: #CD0000;
}

.text, .text a:link, .text a:visited {
color: #888;
font-size: 12px;
line-height: 12px;
}

.text a:hover {
text-decoration: underline;
}

.text img {
display: none;
}

.text hr {
color: #eee;
}

.details, .details a:link, .details a:visited, .details a:hover {
font-size: 11px;
color: #bbb;
margin-bottom: 4px;
}

.floatsquare {
float: left;
width: 100px;
height: 100px;
display: block;
overflow: hidden;
border: 1px solid #eee;
background: #fff url(../images/off.png) no-repeat center center;
}

.floatsquare img {
width: 100px;
max-width: 100px;
min-height: 100px;
min-width: 100px;
}

.newsblock {
margin-left: 110px;
height: 102px;
display: block;
overflow: hidden;
}



Forgive all the mess!

I'm not a programmer, so needless to say I cannot supply support.