SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: goten22 on September 01, 2015, 02:15:50 PM

Title: SP articles more functions
Post by: goten22 on September 01, 2015, 02:15:50 PM
Simpleportal has its own articles system where you can select specific topics to display on homepage. But the output is very minimalistic. I would like to see topic attachment as image or number of comments. Is this possible?

This is default output:
(http://i.imgur.com/3qEZwPg.jpg)
Title: Re: SP articles more functions
Post by: ccbtimewiz on September 01, 2015, 07:15:21 PM
It can be adjusted to show the first attachment (if its an image) as a thumbnail aligned to the right pretty easily.

Though, what is it exactly you're looking for with the feature?
Title: Re: SP articles more functions
Post by: goten22 on September 02, 2015, 02:06:05 AM
How can I do this?

I'm looking for a way to display it in a bit another way not through css but by php code itself. I want to have custom php block that will display latest articles.
Title: Re: SP articles more functions
Post by: goten22 on September 03, 2015, 04:17:24 PM
@Sayaka, anyone, please?
Title: Re: SP articles more functions
Post by: goten22 on September 04, 2015, 07:58:22 PM
If I do echo $context['topic_is_article']; it shows me some random number so if I could somehow display all topics that have "['topic_is_article']!=0"?
Title: Re: SP articles more functions
Post by: ataru on September 09, 2015, 08:55:12 AM
I did some stuff in www.biancocelesti.org site:

the block "Notizie dal mondo Lazio" is made with a custom php block

I took an old discussion with @AngelinaBelle (http://simpleportal.net/index.php?topic=4734) and customized it adding nivo-slider jquery plugin taking 1st image in post this way:
http://simpleportal.net/index.php?topic=13798.msg68983#msg68983

here's my code:
Code: [Select]
<?php
global $smcFunc$modSettings$scripturl$user_info$txt$color_profile$smcFunc$context$settings;

$limit 15// numero totale degli articoli
$type 0// 0 = ultimi; 1 = casuale
$image 2// 0 = Nessuno; 1 = Avatar dell'utente; 2 = Categoria d'immagine
$category 0// 0 = (Tutte le Categorie)</option>; 1 = Notizie dal Campo; 2 = Notizie dalla Società; 3 = Notizie dalle Giovanili; 4 = Calciomercato; 5 = Interviste; 6 = Arbitri e moviole; 7 = Commento; 8 = Statistiche; 9 = Cronaca
$displaymessage True// False = Solo titolo; True = Titolo e testo dell'articolo
$hidebbcode False// False = Mostra; True = Nascondi
$hideauthor True// False = Mostra; True = Nascondi
$hideprnt True// False = Mostra; True = Nascondi
$shortafter 6//Mostra in maniera compatta gli articoli dopo il numero n:
$showfirstcomplete False// 
$truncate 10//
$truncatefirst 300//

$sql_qry='
SELECT
m.id_topic, m.subject, m.poster_name, m.poster_time, m.icon, c.picture, c.name, 
. (!$displaymessage '' 'm.id_msg, m.body, m.smileys_enabled, 
'
) . 'mem.id_member, mem.real_name, mem.avatar,
at.id_attach, at.attachment_type, at.filename, t.num_views
FROM {db_prefix}sp_articles AS a
INNER JOIN {db_prefix}sp_categories AS c ON (c.id_category = a.id_category)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_message)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS at ON (at.id_member = mem.id_member)
LEFT JOIN {db_prefix}topics AS t ON (m.id_msg = t.id_first_msg)
WHERE {query_see_board}
AND a.approved = {int:approved}' 
.  
(!empty($category
'
AND a.id_category = {int:category}' 
''
) . '
ORDER BY {raw:type}
LIMIT {int:limit}'
;

$sql_params = array(
'approved' => 1,
'type' => $type 'RAND()' 'm.poster_time DESC',
'limit' => $limit
);
if (!empty($category)) $sql_params['category'] = $category;

$request $smcFunc['db_query'](''$sql_qry$sql_params);

$articles = array();
$colorids = array();
while ($row $smcFunc['db_fetch_assoc']($request))
{
if (!empty($row['ID_MEMBER']))
$colorids[$row['ID_MEMBER']] = $row['ID_MEMBER'];

if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' $modSettings['avatar_max_width_external'] . '"' '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' $modSettings['avatar_max_height_external'] . '"' '';
}
else
{
$avatar_width '';
$avatar_height '';
}

censorText($row['subject']);

$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' $row['icon'] . '.gif') ? 'images_url' 'default_images_url';


$articles[] = array(
'id' => $row['id_topic'],
'name' => $row['subject'],
'icon' => '<img src="' $settings[$icon_sources[$row['icon']]] . '/post/' $row['icon'] . '.gif" align="middle" alt="' $row['icon'] . '" border="0" />',
'msg' => ( !$displaymessage NULL
array(
'id' => $row['id_msg'],
'body' => $row['body'],
'nviews' => $row['num_views'],
'smileys_enabled' => $row['smileys_enabled'
)
),
'href' => $scripturl '?topic=' $row['id_topic'] . '.0',
'link' => '<a href="' $scripturl '?topic=' $row['id_topic'] . '.0">' $row['subject'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl '?action=profile;u=' $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' $scripturl '?action=profile;u=' $row['id_member'] . '">' $row['real_name'] . '</a>',
'time' => timeformat($row['poster_time']),
'timestamp' => forum_time(true$row['poster_time']),
'timeyear' => timeformat($row['poster_time'], '%d %b %y'),
'timeday' => timeformat($row['poster_time'], '%H:%M:%S'),
),
'image' => array(
'href' => $row['picture'],
'image' => '<img src="' $row['picture'] . '" alt="' $row['name'] . '" />',
),
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > '<img src="' . (empty($row['attachment_type']) ? $scripturl '?action=dlattach;attach=' $row['id_attach'] . ';type=avatar' $modSettings['custom_avatar_url'] . '/' $row['filename']) . '" alt="" class="avatar" border="0" />' '') : (stristr($row['avatar'], 'http://') ? '<img src="' $row['avatar'] . '" alt="" class="avatar" border="0" />' '<img src="' $modSettings['avatar_url'] . '/' htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > ? (empty($row['attachment_type']) ? $scripturl '?action=dlattach;attach=' $row['id_attach'] . ';type=avatar' $modSettings['custom_avatar_url'] . '/' $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' $row['avatar']),
'url' => $row['avatar'] == '' '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' $row['avatar']),
),
);

}

$smcFunc['db_free_result']($request);


$parse_tags FALSE;

$enableaeva=True;
if (array_key_exists('aeva_disable',$context))
{
$realaeva=$context['aeva_disable'];
$context['aeva_disable'] = ($enableaeva null 1);

}
elseif (array_key_exists('aeva_enable',$modSettings))
{
$realaeva=$modSettings['aeva_enable'];
$modSettings['aeva_enable'] = ($enableaeva NULL);
}

if ($displaymessage)
{

$artn=1;
foreach ($articles as $k => $article)
{
$nobbcode preg_replace('/[\ ]+/',' ',preg_replace('/<br[^>]*>/',' ',$article['msg']['body']));
$nobbcode str_replace("[img]","<",str_replace("[/img]",">",$nobbcode));
$nobbcode strip_tags(str_replace("[""<"str_replace("]"">"$nobbcode)));

$corpodellarticolo $article['msg']['body'];
$pattern "/\[img(.*?)]([^\[]+)\[\/img]/i";
preg_match_all($pattern$article['msg']['body'], $matchesPREG_SET_ORDER);
foreach ($matches as $val) {
$imgs[] = $val[2];
$corpodellarticolo str_replace($val[0],"",$corpodellarticolo);
}

$pattern "/\[url(.*?)]([^\[]+)\[\/url]/i"
preg_match_all($pattern$article['msg']['body'], $matchesPREG_SET_ORDER);
foreach ($matches as $val) {
$urls[] = $val[2];
$urlspar[] = $val[1];
$corpodellarticolo str_replace($val[0],"",$corpodellarticolo);
}
for ($spazi 0$spazi 10$spazi++) {
$corpodellarticolo str_replace("<br /><br />","<br />"$corpodellarticolo);
}
$article['msg']['body'] = $corpodellarticolo;

if ($hidebbcode && $artn $shortafter)
{
$article['msg']['body'] = $nobbcode;
}

if ($artn $shortafter)
$truncart $truncate;
else
$truncart $truncatefirst;
if (($cutoff $smcFunc['strpos']($article['msg']['body'], '')) !== false)
$putdots 
  (
   (
     $cutoff 
      ($smcFunc['strlen']($article['msg']['body']) - $smcFunc['strlen'](''
      )
    )
  ? TRUE
  : FALSE 
  );
elseif (!empty($truncart) && $smcFunc['strlen']($nobbcode) > $truncart )
{
$cutoff $truncart $smcFunc['strlen']($article['msg']['body']) - $smcFunc['strlen']($nobbcode);
$putdots TRUE;
}
else 
{
$cutoff FALSE;
$putdots FALSE;
}

if ( $cutoff !== FALSE )
{
$cut_string=substr($article['msg']['body'], 0,$cutoff);
$last_space=strrpos($cut_string," ");
$article['msg']['body']=substr($cut_string0,$last_space);
}

if ( isset($imgs) ) {
$ImgsSlide[$artn] = $imgs[0];
unset($imgs);
} else {
$ImgsSlide[$artn] = "/images/immagineNews.jpg";
}
if ( isset($urls) ) {
$UrlsSlide[$artn] = '<a href="' substr($urlspar[0], 1) . '" target="_blank">' $urls[0] . '</a>';
unset($urls);
} else {
$UrlsSlide[$artn] = "";
}
for ($spazi 0$spazi 10$spazi++) {
$article['msg']['body'] = str_replace("<br /><br />","<br />"$article['msg']['body']);
}
$article['msg']['body'] = parse_bbc($article['msg']['body'], $article['msg']['smileys_enabled'], $article['msg']['id'], $parse_tags);

if ($putdots
$article['msg']['body'] .= ' (<a href="'.$article['href'].'">...</a>)';


if ($modSettings['sp_resize_images'])
$article['msg']['body'] = preg_replace('~class="bbc_img"~i''class="bbc_img sp_article"'$article['msg']['body']);

$articles[$k]['msg']['body'] = $article['msg']['body'];
$artn++;
}

if (array_key_exists('aeva_disable',$context))
{
$context['aeva_disable'] = $realaeva;
}
elseif (array_key_exists('aeva_enable',$modSettings))
{
$modSettings['aeva_enable'] = $realaeva;
}


}

if (empty($articles))
{
echo '
'
$txt['error_sp_no_articles_found'];
return;
}
else
$articles[count($articles) - 1]['is_last']=True;

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($articles as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$articles[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

echo '
<table class="sp_fullwidth sp_articles">'
;
$artn=1;
foreach ($articles as $article)
{
if ($artn $shortafter)
{
echo '
<tr><td>
'
;

if (empty($image)) {}
else 
{
if (!empty($article['avatar']['href']) && $image == 1)
$img_guts $article['avatar']['href'] .  '" alt="' .  $article['poster']['name'];
elseif (!empty($article['image']['href']) && $image == 2)
$img_guts $article['image']['href'] . '" alt="' .  $article['name'];

if ( isset($img_guts) && !empty($img_guts) )
echo '<img class="sp_articles_icon" src="'$img_guts'" width="40" /></td>';
}
echo '<td>';

echo  $article['link'] ;

if ( empty($article['is_last'])) echo '
<hr />'
;
echo '</td></tr>' "\n";
}
elseif (!$showfirstcomplete)
{
if ($artn == 1)
echo'
<link rel="stylesheet" href="/jquery/nivoslider/themes/bar/bar.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/jquery/nivoslider/nivo-slider.css" type="text/css" media="screen" />
<tr><td colspan="2">
<div class="slider-wrapper theme-bar">
<div id="slider" class="nivoSlider">'
;

$htmlcaption $htmlcaption '
<div id="htmlcaption' 
$artn '" class="nivo-html-caption">
<table style="width:100%">
<tr><td style="width:70px;background-image: url(' 
$article['image']['href'] . ');background-size:64px;background-repeat:no-repeat;"></td>
<td style="color:#fff"><strong><a href="' 
$article['href'] . '" style="font-size: 200%;">' $article['name'] . '</a></strong><br />
$UrlsSlide[$artn] . '
$article['msg']['body'] . '</td></tr>
</table>
</div>'
;
echo'
<img src="' 
$ImgsSlide[$artn] , '" data-thumb="' $ImgsSlide[$artn] , '" alt="" title="#htmlcaption' $artn '" />';
if ($artn == $shortafter)
echo'
</div>' 
$htmlcaption '
</div>
<script type="text/javascript" src="/jquery/1.11.2.min.js"></script>
<script type="text/javascript" src="/jquery/nivoslider/jquery.nivo.slider.pack.js"></script>
<script type="text/javascript">
$(window).load(function() {
$("#slider").nivoSlider({
effect: "fold",                 // Specify sets like: "fold,fade,sliceDown"
//slices: 15,                     // For slice animations
//boxCols: 8,                     // For box animations
//boxRows: 4,                     // For box animations
animSpeed: 500,                 // Slide transition speed
pauseTime: 8000,                 // How long each slide will show
startSlide: 0,                     // Set starting Slide (0 index)
directionNav: true,             // Next & Prev navigation
controlNav: true,                 // 1,2,3... navigation
controlNavThumbs: false,         // Use thumbnails for Control Nav
pauseOnHover: true,             // Stop animation while hovering
manualAdvance: false,             // Force manual transitions
prevText: "Prec.",                 // Prev directionNav text
nextText: "Succ.",                 // Next directionNav text
randomStart: false//,             // Start on a random slide
//beforeChange: function(){},     // Triggers before a slide transition
//afterChange: function(){},         // Triggers after a slide transition
//slideshowEnd: function(){},     // Triggers after all slides have been shown
//lastSlide: function(){},         // Triggers when last slide is shown
//afterLoad: function(){}         // Triggers when slider has loaded
});
});
</script>
</tr></td>'
;

}
$artn++;
}
echo "</table>\n";
if ($modSettings['sp_resize_images'])
{
echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var cssNode = document.createElement("link");
cssNode.type = "text/css";
cssNode.rel = "stylesheet";
cssNode.href = "'
$settings['default_theme_url'], '/css/portal_resize.css";
cssNode.media = "screen";
cssNode.title = "dynamicLoadedSheet";
document.getElementsByTagName("head")[0].appendChild(cssNode); 
// ]]></script>'
;
}
?>

Title: Re: SP articles more functions
Post by: goten22 on September 09, 2015, 09:45:51 AM
Thanks, but it doesn't work for me. I've got only two broken img tags in block. In logs I have " Undefined variable: htmlcaption". Should I modify something to make it work?
Title: Re: SP articles more functions
Post by: ataru on September 09, 2015, 10:04:37 AM
try saving a php file in your webspace with that code, ant then call it in a php block with

Code: [Select]
include('homepagenews.php');

for me it's working also in custom php without including it.

try adding
Code: [Select]
$htmlcaption = "";
after
Code: [Select]
$truncatefirst = 300; //
Title: Re: SP articles more functions
Post by: goten22 on September 09, 2015, 04:51:30 PM
Still doesn't work. Does it work with clean smf and SP (2.3.6) installation? Maybe I should modify some core files?

first is this code and second default block called "articles"
(http://i.imgur.com/RtaKIAA.jpg)
Title: Re: SP articles more functions
Post by: ataru on September 11, 2015, 10:35:50 AM
Still doesn't work. Does it work with clean smf and SP (2.3.6) installation? Maybe I should modify some core files?

first is this code and second default block called "articles"
(http://i.imgur.com/RtaKIAA.jpg)

did you put nivoslider and jquery in a jquery folder on the root of your webspace?

look at that code:

Code: [Select]
<link rel="stylesheet" href="/jquery/nivoslider/themes/bar/bar.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/jquery/nivoslider/nivo-slider.css" type="text/css" media="screen" />

[...]
<script type="text/javascript" src="/jquery/1.11.2.min.js"></script>
<script type="text/javascript" src="/jquery/nivoslider/jquery.nivo.slider.pack.js"></script>
Title: Re: SP articles more functions
Post by: goten22 on September 12, 2015, 12:56:40 AM
I tried but still no output. Maybe if you could simplify a bit this block just to show link to the topic maybe then it will work. The number of the articles is correct but there's no link and no img.
Title: Re: SP articles more functions
Post by: ataru on September 12, 2015, 04:05:48 AM
What's the output html?
Title: Re: SP articles more functions
Post by: goten22 on September 12, 2015, 08:54:41 AM
This:
http://i.imgur.com/WBpeSPh.jpg
Title: Re: SP articles more functions
Post by: Cyberkid on September 12, 2015, 07:01:03 PM
This:
http://i.imgur.com/WBpeSPh.jpg
no output here too
Title: Re: SP articles more functions
Post by: ataru on September 13, 2015, 03:42:32 AM
Ok there is no images in articles shown, so my code tries to put /images/imagineNews.jpg as default image.

Try to put a ImagineNews.jpg file in /Images/ folder


Which version of php are you running?  Need to know why captions are not created.

Articles are empty? Try to put in articles more than 10 words
Title: Re: SP articles more functions
Post by: goten22 on September 13, 2015, 04:26:11 AM
Ok there is no images in articles shown, so my code tries to put /images/imagineNews.jpg as default image.

Try to put a ImagineNews.jpg file in /Images/ folder
...
Articles are empty? Try to put in articles more than 10 words
No changes.

Quote
Which version of php are you running?  Need to know why captions are not created.
5.3
Title: Re: SP articles more functions
Post by: Cyberkid on September 13, 2015, 08:22:21 AM
nothing appearing here, are you sure the code is right????????
Title: Re: SP articles more functions
Post by: ataru on September 13, 2015, 10:32:23 AM
It's working for me. Got also Htmlcaption undefined error in log , going to fix it

Ok got why Htmlcaption is not generated

Try adding more articles or setting $shortafter lower or equal to total number of articles

I've got hundreds of articles so I never figured how to code for test forums

Other thing. My script takes images from img tags not from attachments
Title: Re: SP articles more functions
Post by: goten22 on September 13, 2015, 10:51:33 AM
Yep lowering $shortafter helps. Thank you for help.
Title: Re: SP articles more functions
Post by: Cyberkid on September 13, 2015, 02:28:55 PM
It's working for me. Got also Htmlcaption undefined error in log , going to fix it

Ok got why Htmlcaption is not generated

Try adding more articles or setting $shortafter lower or equal to total number of articles

I've got hundreds of articles so I never figured how to code for test forums

Other thing. My script takes images from img tags not from attachments
Thanks, any way to make it both attached/image tags??? any that comes first
Title: Re: SP articles more functions
Post by: ataru on September 13, 2015, 05:59:12 PM
Thanks, any way to make it both attached/image tags??? any that comes first
Sure it can be done. But I don't know how to get attachments from db. I never used to check it. Sorry
Title: Re: SP articles more functions
Post by: Cyberkid on September 13, 2015, 06:07:28 PM
 :'(
Title: Re: SP articles more functions
Post by: goten22 on September 14, 2015, 09:06:23 AM
An one more question. How can I display number of comments?
Title: Re: SP articles more functions
Post by: ataru on September 14, 2015, 11:17:13 AM
to add number of replies you have to get them in sql query adding num_replies (and eventually num_views) values from topics tab:

Code: [Select]
<?php
$sql_qry='
SELECT
m.id_topic, m.subject, m.poster_name, m.poster_time, m.icon, c.picture, c.name, 
. (!$displaymessage '' 'm.id_msg, m.body, m.smileys_enabled,
'
) . 'mem.id_member, mem.real_name, mem.avatar,
/*adding line*/
t.num_replies, t.num_views, 
/*end of added line*/
at.id_attach, at.attachment_type, at.filename, t.num_views
FROM {db_prefix}sp_articles AS a
INNER JOIN {db_prefix}sp_categories AS c ON (c.id_category = a.id_category)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_message)
/*adding line*/
INNER JOIN {db_prefix}topics AS t ON (t.id_first_msg = a.id_message)
/*end of added line*/
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS at ON (at.id_member = mem.id_member)
LEFT JOIN {db_prefix}topics AS t ON (m.id_msg = t.id_first_msg)
WHERE {query_see_board}
AND a.approved = {int:approved}' 
.  
(!empty($category
'
AND a.id_category = {int:category}' 
''
) . '
ORDER BY {raw:type}
LIMIT {int:limit}'
;
?>


and put them into $articles array:

Code: [Select]
<?php
$articles[] = array(
'id' => $row['id_topic'],
'name' => $row['subject'],
/*adding lines*/
'replies' => $row['num_replies']
'views' => $row['num_views']
/*end of added lines*/
'icon' => '<img src="' $settings[$icon_sources[$row['icon']]] . '/post/' $row['icon'] . '.gif" align="middle" alt="' $row['icon'] . '" border="0" />',
'msg' => ( !$displaymessage NULL
array(
'id' => $row['id_msg'],
'body' => $row['body'],
'nviews' => $row['num_views'],
'smileys_enabled' => $row['smileys_enabled'
)
),
'href' => $scripturl '?topic=' $row['id_topic'] . '.0',
'link' => '<a href="' $scripturl '?topic=' $row['id_topic'] . '.0">' $row['subject'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl '?action=profile;u=' $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' $scripturl '?action=profile;u=' $row['id_member'] . '">' $row['real_name'] . '</a>',
'time' => timeformat($row['poster_time']),
'timestamp' => forum_time(true$row['poster_time']),
'timeyear' => timeformat($row['poster_time'], '%d %b %y'),
'timeday' => timeformat($row['poster_time'], '%H:%M:%S'),
),
'image' => array(
'href' => $row['picture'],
'image' => '<img src="' $row['picture'] . '" alt="' $row['name'] . '" />',
),
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > '<img src="' . (empty($row['attachment_type']) ? $scripturl '?action=dlattach;attach=' $row['id_attach'] . ';type=avatar' $modSettings['custom_avatar_url'] . '/' $row['filename']) . '" alt="" class="avatar" border="0" />' '') : (stristr($row['avatar'], 'http://') ? '<img src="' $row['avatar'] . '" alt="" class="avatar" border="0" />' '<img src="' $modSettings['avatar_url'] . '/' htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > ? (empty($row['attachment_type']) ? $scripturl '?action=dlattach;attach=' $row['id_attach'] . ';type=avatar' $modSettings['custom_avatar_url'] . '/' $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' $row['avatar']),
'url' => $row['avatar'] == '' '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' $row['avatar']),
),
);
?>


and then you will find number of views and replies using variables:
Code: [Select]
$article['replies']
$article['views']

double check everything, I didn't test it, and remove '/*adding line*/' and '/*end of added line*/' from code
Title: Re: SP articles more functions
Post by: ataru on September 14, 2015, 11:36:47 AM
:'(

you should take advantage from that mod:

http://custom.simplemachines.org/mods/index.php?mod=1151

using:

Code: [Select]
, IFNULL(big.id_attach, 0) AS big_id, big.filename AS big_filename, big.width AS big_width, big.height AS big_height,
IFNULL(thn.id_attach, 0) AS thn_id, thn.filename AS thn_filename, thn.width AS thn_width, thn.height AS thn_height

Code: [Select]
LEFT JOIN {db_prefix}attachments AS big ON (big.id_msg = mf.id_msg AND big.attachment_type = 0)
LEFT JOIN {db_prefix}attachments AS thn ON (thn.id_attach = big.id_thumb)

on sql query to get images and thumbnails from database

and then cycle them to get first attachment image.
Title: Re: SP articles more functions
Post by: Cyberkid on September 14, 2015, 01:17:59 PM
Am loving this site
Title: Re: SP articles more functions
Post by: goten22 on September 15, 2015, 06:06:06 AM
I've got error "Not unique table/alias: 't'"

EDIT: Got it. Sad that I still don't know much how to deal with this sql, array etc.

Code: [Select]
SELECT
m.id_topic, m.subject, m.poster_name, m.poster_time, ///add t.num_replies///, m.icon, c.picture, c.name,

Code: [Select]
$articles[] = array(
'id' => $row['id_topic'],
'name' => $row['subject'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
///add 'replies' => $row['num_replies'],////
'msg' => ( !$displaymessage ? NULL:

and then just $article['replies']
Title: Re: SP articles more functions
Post by: Cyberkid on September 21, 2015, 10:12:46 AM
:'(
you should take advantage from that mod:
http://custom.simplemachines.org/mods/index.php?mod=1151
using:
Code: [Select]
, IFNULL(big.id_attach, 0) AS big_id, big.filename AS big_filename, big.width AS big_width, big.height AS big_height,
IFNULL(thn.id_attach, 0) AS thn_id, thn.filename AS thn_filename, thn.width AS thn_width, thn.height AS thn_height
Code: [Select]
LEFT JOIN {db_prefix}attachments AS big ON (big.id_msg = mf.id_msg AND big.attachment_type = 0)
LEFT JOIN {db_prefix}attachments AS thn ON (thn.id_attach = big.id_thumb)
on sql query to get images and thumbnails from database
and then cycle them to get first attachment image.
Can this your code be done for recent post?? I mean detecting thumbnail via  [IMG] tag
Title: Re: SP articles more functions
Post by: Cyberkid on December 04, 2016, 05:48:55 PM
Thanks, any way to make it both attached/image tags??? any that comes first
Sure it can be done. But I don't know how to get attachments from db. I never used to check it. Sorry
hi bro, i had to look for my way down here again, was still thinking if this can be done, using this mod Post and PM Inline Attachments link here http://custom.simplemachines.org/mods/index.php?mod=3770 since it uses custom bbc tags, don't know if the url of the attachment can be extracted and echo out as img tag, please help out
Title: Re: SP articles more functions
Post by: emanuele on December 05, 2016, 03:03:15 PM
Thanks, any way to make it both attached/image tags??? any that comes first
Attachments never come "first", they are always at the end of the message.
What if there is more than one attachment? Just pick the first?
I guess you'd want the attachment only if it is an image, and the thumbnail should served (not the full size image).

Work with attachments is a bit tricky TBH, I may try to put something together, but I do not assure you anything.
Title: Re: SP articles more functions
Post by: Cyberkid on December 05, 2016, 06:10:51 PM
Thanks, any way to make it both attached/image tags??? any that comes first
Attachments never come "first", they are always at the end of the message.
What if there is more than one attachment? Just pick the first?
I guess you'd want the attachment only if it is an image, and the thumbnail should served (not the full size image).

Work with attachments is a bit tricky TBH, I may try to put something together, but I do not assure you anything.
okay thanks bro
Title: Re: SP articles more functions
Post by: emanuele on December 08, 2016, 08:45:23 AM
And the answers to my questions are...? ;)
SimplePortal 2.3.8 © 2008-2024, SimplePortal