News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

[README] SSI FAQ's

Started by Tomer, August 09, 2004, 05:30:03 PM

Previous topic - Next topic

mark7144

Anyone know if it's possible to have the 'Send Topic' using SSI?

Oldiesmann

Not directly, but ssi_recentPosts, ssi_recentTopics, ssi_boardNews and ssi_topTopics all return the topic ID as part of the array of info if you choose that output method, so you'd just need to output the link based on that - the URL is index.php?action=sendtopic;topic={topic_id}.
Michael Eshom
Christian Metal Fans

addictedBG

ow could I understand all the command ...I mean such as $news['icon'], '', $news['subject'], '<span class="smaller">', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '', $news['link'], ' | ', $news['new_comment'], '

fwitt

normally from the context, as $news appears lots I assume its something to do with displaying news posts,
$news['icon'] probly holds the info for displaying the icon for the news article
$news['subject'] could this be the variable containing the subject of the news article
'<span class="smaller">' html i assume class="smaller" means that it belong to a css class that shrinks the text size
$news['time'] probly the time the news article was posted
$txt[525] a text string what it is replaced with will be found in the relevant language file so if the code is in news.template.php the $txt variable will probly be in news.yourlanguage.php
$news['poster']['link'] probly a link to the profile of the poster of the news article
$news['link'] a link to the news article itself
$news['new_comment'] could it be a link to the comments about the news article?

as I said look at the context of the code the variables are in and what there names are
if your not sure whats in a variable a simple echo '$variable = ' .  $variable; will show you what the variable contains in a given situation which should give you a clue as to what it does.

Daerchwing

#44
I'm having a problem using SSI on my site.

I've included the file as per instructions, but when I try to use a SSI function such as ssi_recentTopics(); I get the following error:
Fatal error: Call to undefined function db_query() in /pathinfo removed by me/public_html/test/forums/SSI.php on line 244

What do I do to correct this?

I'm running 1.1 RC3 and I include SSI.php from my WordPress header.

Edit: sorry if this isn't the right place to ask this sort of question.

Edit 2: NM, I figured it out.

brianjw

Tomer,
Since you wrote these, I am hoping you will be able to help me with something. But it's a bit long so its in its own topic.

http://www.simplemachines.org/community/index.php?topic=159588.0

Thanks,
Brianjw

PS: im a bit late posting lol :P

321Hosted.com

I am a bit lost here, SSI is not my thing by far! I read the basic FAQ and am still lost!

I have a free web hosting business that offers free forum and cpanel hosting. I use SMF for the forum. The forum is also where users signup for their free account (I have added the custom profile fields mod to collect the needed info).

What I want this to do is display on one page, the members that are using free cpanel hosting, and the members that are using free forum hosting. I have these member groups setup, but I have no idea how to get a page setup so I can view the 2 member groups and the people in them.

Any help would be greatly appreciated!

B Patterson

#47
Well, without having a function called "getMembersByGroup", there's not a whole lot to make this easy.  You could use this though:

function getMembersByGroup($groupname$max=10$output_method='string')
{
    global 
$db_prefix;

    
$request db_query("SELECT mem.memberName, mem.posts
                                  FROM 
{$db_prefix}members AS mem
                                  LEFT JOIN 
{$db_prefix}membergroups AS grp
                                       ON grp.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP)
                                  ORDER BY mem.memberName ASC
                                  LIMIT 0,
{$max}"__FILE____LINE__);

    
$member = array();

    while(
$row mysql_fetch_assoc($result))
    {
        
$member[] = array('name'=>$row['memberName'],
                                  
'posts'=>$row['posts']);
    }

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

    
$string '<table>';
    foreach(
$member as $mem)
    {
        
$string .= '<tr><td>'$mem['name'], '</td><td>'$mem['posts'], '</td></tr>';
    }
    
$string .= '</table>';

    return 
$string;
}

include_once(
'SSI.php');
print_r(getmembersByGroup('FreeForum'10'array'));
echo 
getMembersByGroup('FreeCpanel'5);


Not guaranteed to work, but something like that would be what you want....

vsobral

How can I use ssi functions with mouse events?

An example of what i was trying to do with no success

<td class="windowbg" width="20%" align="left"> <input type="button"  value="Administradores" onclick=';
echo"'";

echo '
document.getElementById("ct").innerHTML = "'ssi_function()'"';

echo "'";
echo '
/>...



This works with variables but not with ssi functions

Thanks

fwitt

quick thing that looks wrong to me is this


echo '
document.getElementById("ct").innerHTML = "'ssi_function()'"';


shouldnt it be


echo '
document.getElementById("ct").innerHTML = "' , ssi_function() , '"';

vsobral

#50
I've forgot to put the comas, but that is'nt the problem.

here is the full code



<?php





if (!defined('SMF'))
die('Hacking attempt...');

// Don't do anything if SMF is already loaded.


require(dirname(__FILE__) . '/../SSI.php');

function 
template_main()
{
global 
$context$settings$options$txt$scripturl;

echo 
'


<table width="100%" border="0" cellspacing="0" cellpadding="3" >
<tr>
<td>'
theme_linktree(), '</td>
</tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center" class="tborder">
<tr class="titlebg" >
<td align="center" width="100%">Staff do P@P</td>
</tr></table>
<table width="20%" border="0" cellspacing="0" cellpadding="4" align="left" class="tborder">

<tr>




<td class="windowbg" width="20%" align="left"> <input type="button"  value="Administradores" onclick='
;
echo
"'";

echo 
'
document.getElementById("ct").innerHTML = "' 
ssi_recentTopics()  , '"';

echo 
"'";
echo 
'
 /> <br />
  </td>  </tr></table>
  
  
  <table width="40%" border="0" cellspacing="0" cellpadding="4" align="center">
  
  <tr> 
  '
;
 


echo 
'
</tr>
</table>

<div id="ct">oláaaaaaaaaaaa</div>
'
;





Thanks for the help



vsobral


otectom

is it possible to use SSI to add calendar events to another page of your site?

fwitt

ssi_todaysEvents and ssi_todaysCalender both display Calender events.

I personally have a page on my website that lists the next years Calender events in order of start date using ssi.

otectom


otectom

Ok, ive seen the examples for today's events and recent evente, but what about upcoming events like everything for the next month/months maybe similar to how events show up on the bottom of the forum

fwitt

I have a customSSI.php which has modified versions of some of the SSI.php functions that fit my needs.
you need to require_once both this file and SSI.php in the file you wish to use it.

To show the calender events the user can see this function is called by the line.


ssi_ListEvents($max_events = 100, $output_method = 'echo', $dateFrom = date("Y-m-d"), $dateTo = (date("Y")+1) . '-' . date("m") . '-' .  date("d"));


Which output the first 100 calender events for the next year that the user can see.

following is the code of the function itself


// Show events between $dateFrom and $dateTo.
function ssi_ListEvents($max_events = 7, $output_method = 'echo', $dateFrom = '0001-01-01', $dateTo = '0001-01-01')
{
global $db_prefix, $user_info, $scripturl, $modSettings, $txt, $sc, $ID_MEMBER;

// Find all events which are happening in the near future that the member can see.
$request = db_query("
SELECT
cal.ID_EVENT, cal.startDate, cal.endDate, cal.title, cal.ID_MEMBER, cal.ID_TOPIC,
cal.ID_BOARD, t.ID_FIRST_MSG
FROM {$db_prefix}calendar AS cal
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = cal.ID_BOARD)
LEFT JOIN {$db_prefix}topics AS t ON (t.ID_TOPIC = cal.ID_TOPIC)
WHERE cal.startDate <= '" . $dateTo . "'
AND cal.startDate >= '" . $dateFrom . "'
AND (cal.ID_BOARD = 0 OR $user_info[query_see_board])
ORDER BY cal.startDate ASC
LIMIT $max_events", __FILE__, __LINE__);
$return = array();
$duplicates = array();
while ($row = mysql_fetch_assoc($request))
{
// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
/*if (!empty($duplicates[$row['title'] . $row['ID_TOPIC']]))
continue; */

// Censor the title.
censorText($row['title']);

/*if ($row['startDate'] < strftime('%Y-%m-%d', forum_time(false)))
$date = strftime('%Y-%m-%d', forum_time(false));
else*/
$date = $row['startDate'];

$return[$date][] = array(
'id' => $row['ID_EVENT'],
'title' => $row['title'],
'can_edit' => allowedTo('calendar_edit_any') || ($row['ID_MEMBER'] == $ID_MEMBER && allowedTo('calendar_edit_own')),
'modify_href' => $scripturl . '?action=' . ($row['ID_BOARD'] == 0 ? 'calendar;sa=post;' : 'post;msg=' . $row['ID_FIRST_MSG'] . ';topic=' . $row['ID_TOPIC'] . '.0;calendar;') . 'eventid=' . $row['ID_EVENT'] . ';sesc=' . $sc,
'href' => $row['ID_BOARD'] == 0 ? '' : $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => $row['ID_BOARD'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['title'] . '</a>',
'start_date' => $row['startDate'],
'end_date' => $row['endDate'],
'is_last' => false
);

// Let's not show this one again, huh?
$duplicates[$row['title'] . $row['ID_TOPIC']] = true;
}
mysql_free_result($request);

foreach ($return as $mday => $array)
$return[$mday][count($array) - 1]['is_last'] = true;

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

// Well the output method is echo.
$tempyear = 0001;
        $tempmonth = 'bob';
foreach ($return as $mday => $array)
foreach ($array as $event)
{
if (strftime("%Y",strtotime($event['start_date'])) != $tempyear)
{
                          $tempyear = strftime("%Y",strtotime($event['start_date']));
                          echo '<h3>' . $tempyear . '</h3>';
                        }
                        if (strftime("%B",strtotime($event['start_date'])) != $tempmonth)
{
                          $tempmonth = strftime("%B",strtotime($event['start_date']));
                          echo '<h3>' . $tempmonth . '</h3>';
                        }
                        if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';

echo '
' . date("jS",strtotime($event['start_date']));
                        if ($event['start_date'] != $event['end_date'])
                          echo '-' . date("jS",strtotime($event['end_date']));
                        echo ' ' . $event['link'] . '<br/>';
}
}

otectom

fwitt, thank you, this is exactly what I am looking for to add to my site, I understand how to place the function on the page where I want to display the events, however I am unsure what to do with the other hunk of code there.  Does that need to be added to my ssi.php file?  if so where?

fwitt

dont add it to your SSI.php (it would work but you would have to do it every time you updated SMF) put it into a new file called CustomSSI.php and include this to your file in the same way as you would SSI.php.

so copy and paste this code to a file called CustomSSI.php and upload it to your forums root.


<?php
require_once("SSI.php");

// Show events between $dateFrom and $dateTo.
function ssi_ListEvents($max_events 7$output_method 'echo'$dateFrom '0001-01-01'$dateTo '0001-01-01')
{
global $db_prefix$user_info$scripturl$modSettings$txt$sc$ID_MEMBER;

// Find all events which are happening in the near future that the member can see.
$request db_query("
SELECT
cal.ID_EVENT, cal.startDate, cal.endDate, cal.title, cal.ID_MEMBER, cal.ID_TOPIC,
cal.ID_BOARD, t.ID_FIRST_MSG
FROM 
{$db_prefix}calendar AS cal
LEFT JOIN 
{$db_prefix}boards AS b ON (b.ID_BOARD = cal.ID_BOARD)
LEFT JOIN 
{$db_prefix}topics AS t ON (t.ID_TOPIC = cal.ID_TOPIC)
WHERE cal.startDate <= '" 
$dateTo "'
AND cal.startDate >= '" 
$dateFrom "'
AND (cal.ID_BOARD = 0 OR 
$user_info[query_see_board])
ORDER BY cal.startDate ASC
LIMIT 
$max_events"__FILE____LINE__);
$return = array();
$duplicates = array();
while ($row mysql_fetch_assoc($request))
{
// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
/*if (!empty($duplicates[$row['title'] . $row['ID_TOPIC']]))
continue; */

// Censor the title.
censorText($row['title']);

/*if ($row['startDate'] < strftime('%Y-%m-%d', forum_time(false)))
$date = strftime('%Y-%m-%d', forum_time(false));
else*/
$date $row['startDate'];

$return[$date][] = array(
'id' => $row['ID_EVENT'],
'title' => $row['title'],
'can_edit' => allowedTo('calendar_edit_any') || ($row['ID_MEMBER'] == $ID_MEMBER && allowedTo('calendar_edit_own')),
'modify_href' => $scripturl '?action=' . ($row['ID_BOARD'] == 'calendar;sa=post;' 'post;msg=' $row['ID_FIRST_MSG'] . ';topic=' $row['ID_TOPIC'] . '.0;calendar;') . 'eventid=' $row['ID_EVENT'] . ';sesc=' $sc,
'href' => $row['ID_BOARD'] == '' $scripturl '?topic=' $row['ID_TOPIC'] . '.0',
'link' => $row['ID_BOARD'] == $row['title'] : '<a href="' $scripturl '?topic=' $row['ID_TOPIC'] . '.0">' $row['title'] . '</a>',
'start_date' => $row['startDate'],
'end_date' => $row['endDate'],
'is_last' => false
);

// Let's not show this one again, huh?
$duplicates[$row['title'] . $row['ID_TOPIC']] = true;
}
mysql_free_result($request);

foreach ($return as $mday => $array)
$return[$mday][count($array) - 1]['is_last'] = true;

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

// Well the output method is echo.
$tempyear 0001;
        
$tempmonth 'bob';
foreach ($return as $mday => $array)
foreach ($array as $event)
{
if (strftime("%Y",strtotime($event['start_date'])) != $tempyear)
{
                          
$tempyear strftime("%Y",strtotime($event['start_date']));
                          echo 
'<h3>' $tempyear '</h3>';
                        }
                        if (
strftime("%B",strtotime($event['start_date'])) != $tempmonth)
{
                          
$tempmonth strftime("%B",strtotime($event['start_date']));
                          echo 
'<h3>' $tempmonth '</h3>';
                        }
                        if (
$event['can_edit'])
echo '
<a href="' 
$event['modify_href'] . '" style="color: #FF0000;">*</a> ';

echo '
date("jS",strtotime($event['start_date']));
                        if (
$event['start_date'] != $event['end_date'])
                          echo 
'-' date("jS",strtotime($event['end_date']));
                        echo 
' ' $event['link'] . '<br/>';
}
}
?>



Then at the top of the php file you want to call it from add the line


require_once("smf/CustomSSI.php");


directly underneath the <?php

then when you wish the info to appear call the function


ssi_ListEvents($max_events = 100, $output_method = 'echo', $dateFrom = date("Y-m-d"), $dateTo = (date("Y")+1) . '-' . date("m") . '-' .  date("d"));

otectom

fwitt, thank you very much.  I followed your instructions and it worked perfectly.  I also slightly modified your code to look the way I wanted to.  I've been wanting to learn php coding for some time now, and this is honestly the first thing i've tried. 

Advertisement: