[SPLIT] Re: MyStatus Mod (beta) - a social network extension for SMF 2.0

Started by SoLoGHoST, October 16, 2009, 01:30:40 AM

Previous topic - Next topic

SoLoGHoST

lol, I just had to say something in here.  Didn't want you talking to yourself forever :P

Well, on a more serious note, nice concept.  I really don't have the time or energy to devote any coding to it, but you can always ask for help and we will be there :)

Good Luck with your SMF project.  And if it's your first 1, Cheers :)  It's a hell of a 1st SMF project :)

Arantor

It looks like an awesome project, I can't deny that!

And +1 to what SoLoGHoST said, if it's your first SMF mod (though I know you've done some stuff with BoardIndex already) it's going to be an interesting ride. But please, feel free to ask questions here if you have any problems or concerns and we'll see what we can do :)

ElectricSquid

Thanks a lot!!
It's nice to know I have some back-up in case I code myself into a corner :P

Quote from: SoLoGHoST on October 16, 2009, 01:30:40 AM
...  And if it's your first 1, Cheers :)  It's a hell of a 1st SMF project :)
Quote from: Arantor on October 16, 2009, 07:25:26 AM
... if it's your first SMF mod (though I know you've done some stuff with BoardIndex already) it's going to be an interesting ride.

This will be my first official modification.
I plan to take this one all the way to the Mod Site.

I did create (with much help) SSI_NavBar, and I'm still working on the Custom Pages part of all of that, but that was in preparation for this mod. MyStatus Mod is what brings it all together for our BIG upgrade to SMF 2.0 (on my own forum).

Since I'm coding this up for myself, I might as well share it with everyone else.

LOL, and this mod might seem big, but I don't think it's that bad.
SMF already does most of what I need to make this mod work.
I'm just presenting it differently :P

Arantor

Quote from: ∑£ℓ¢†®¡¢ §ợų¡đ on October 16, 2009, 10:03:00 AM
It's nice to know I have some back-up in case I code myself into a corner :P

That's really what this whole board is about, supporting coders.

Quote from: ∑£ℓ¢†®¡¢ §ợų¡đ on October 16, 2009, 10:03:00 AM
This will be my first official modification.
I plan to take this one all the way to the Mod Site.

We do have coding guidelines to follow for approved mods, but nothing particular onerous IMO. When it is submitted, one of the Customizer team will be reviewing it for you and may provide feedback in addition to approval.

Sounds like it's going to be a blast though.

Dragooon

This sounds interesting, although I recommend not to include SSI inside SMF(it is supposed to be includes only outside). Having a separate function that is same as the SSI one inside Status.php is a better idea.

Arantor

Quote from: Dragooon on October 16, 2009, 10:22:52 AM
This sounds interesting, although I recommend not to include SSI inside SMF(it is supposed to be includes only outside). Having a separate function that is same as the SSI one inside Status.php is a better idea.

Indeed, and we would fail it for that. Not to mention that you can likely do it quicker with a dedicated query for your purpose rather than the exact code there which by nature has to be more general purpose.

ElectricSquid

Thanks, noted :)
No SSI inside the forum.
Only provide SSI for external use.

Costa

Quote from: SoLoGHoST on October 16, 2009, 01:30:40 AM
Good Luck with your SMF project.  And if it's your first 1, Cheers :)  It's a hell of a 1st SMF project :)
+1 :)
Hugo "Costa" Fernandes - PT SMF
Todas as MP's a pedir ajuda são sujeitas a radioactividade, microondas, queimadas e atiradas borda fora.

"At least someone appreciates the fact that I am doing and not thinking..."
"Laziness is counter-revolutionary."

ElectricSquid

Arggg!!

For the life of me, I can't figure out how to connect these templates to the a board to get the topics to display.

LOL, I've figured out a lot of ways it won't work, though :P

SoLoGHoST

In the function for the action/subaction call:loadTemplate('NameOfFile');
NameOfFile should be just the name of the file before .template.php.  So, in this example, it would be called, NameOfFile.template.php and be stored within the ./Themes/default directory.

You would define the language file as follows in the main function that gets called for the action, that way all subactions can use it (or if your main function doesn't need the language file, you can throw it in the subaction functions that use it, whichever):if (loadLanguage('NameOfFile') == false)
loadLanguage('NameOfFile', 'english');
  NameOfFile should be the name of the file just before .english.php or .english-utf8.php.  So in the example NameOfFile.english.php and NameOfFile.english-utf8.php should be in the ./Themes/default/languages directory.  An then in this file, you define all of the $txt[] used by the template.  For example:$txt['string1'] = '<strong>Just a string</strong>';Where string1 is the index of $txt, than to call this string, you just have defined global $txt within the function and use echo $txt['string1'];

Note:  Call loadLanguage() function before loadTemplate() that way the $txt[] array of strings get loaded before the template calls upon them.

Cheers :)

ElectricSquid

I'll be referring back to that about 38 more times today, thanks.
But that's not the issue I'm facing.

Basically, I'm trying to tackle the hardest part of this entire mod, first. Which is obtaining the latest 12 topics out of board_id = 1 and displaying them with all their replies.
All I need is the message text, poster (user), and time. None of the other stuff.

I'm still pluggin' away at it.
But I think for now, I need to go take a walk in the yard and take a break.

SoLoGHoST

In the topics table there is id_board which gives you the board of all topics.  id_first_msg gives you all information about the first post of that topic when matching it to the id_msg column from the messages table.  And from the messages table you can get all of this info.

Here's an example site I did for 2 boards:  EXAMPLE of this for Boards 1 and 2 using setInterval to randomly choose a post in all topics from these boards.

And the code I used to do this with in test5.php is, as follows for SMF 2.0 RC 1.2, and should be the same for RC2 (you can sift through the code and use whatever you want from it, Cheers :)):
<?php
include ('SSI.php');
?>

<html>
<head>
<title>TESTING 1 2 3</title>
<?php

// grabbing all topics, posts from board ids 1 and 2!
$boards = array(12);

// get name of boards for output in the bottom area.
$result $smcFunc['db_query']('''
  SELECT name, id_board
  FROM {db_prefix}boards
  WHERE id_board IN ({array_int:id_board})
  ORDER BY NULL'
,
  array(
  
'id_board' => $boards,
  )
);
$entryBoards = array();
while (
$row mysql_fetch_assoc($result)) {
$xRow++;
$entryBoards[$row['id_board']] = '<a target="_blank" href="' $scripturl '?board=' $row['id_board'] . '.0" style="color: pink; text-decoration: none;">' $row['name'] . '</a>';
}

mysql_free_result($result);

$query $smcFunc['db_query']('''
  SELECT id_topic, id_msg, body
  FROM {db_prefix}messages
  WHERE id_board IN ({array_int:id_board})
  ORDER BY NULL'
,
  array(
  
'id_board' => $boards,
  )
);

$entry = array();

while (
$row mysql_fetch_assoc($query)) {
$row['body'] = parse_bbc($row['body']);
  
$entry[] = '<a target="_blank" href="' $scripturl '?topic=' $row['id_topic'] . '.msg' $row['id_msg'] . '#msg' $row['id_msg'] . '" style="text-decoration: none">' $row['body'] . '</a>';

}

mysql_free_result($query);

echo 
'<script language="JavaScript" type="text/javascript">
var daEntries = new Array();
'
;

foreach (
$entry as $key => $value)
echo '
daEntries[' 
$key '] = \'' addslashes($value) . '\';';

echo 
'

// Just a few global variables defined here...
var timer;
var curEntry = -1;
var maxEntries = ' 
. (count($entry)-1) . ';
var minEntries = 0;
var daTimer = 3000;

// Make sure we get a truely random post id that does not match the same as the previous id
function getRandomPost()
{
var randomNum = Math.random()*(maxEntries-minEntries);
randomNum = Math.round(minEntries+randomNum);
// Make sure we get a different post each time...
if (randomNum == curEntry)
getRandomPost();
else
doFunc(randomNum);
}

// Finally, do the actual switch of each post.
function doFunc(randNum)
{
document.getElementById("message").innerHTML = \'\';
document.getElementById("message").innerHTML = daEntries[randNum];
curEntry = randNum;
}

// Onload...
function init()
{
daTimer = document.getElementById("daTime").value * 1000;
getRandomPost();
timer = window.setInterval("getRandomPost()", daTimer);
}

// Stop the timer
function stopIt()
{
clearInterval(timer);
}

// Start the timer
function startIt()
{
daTimer = document.getElementById("daTime").value * 1000;
timer = window.setInterval("getRandomPost()", daTimer);
}

// Used for keydown and keyup events only clearing the interval if start = true (onKeyUp)
function NumOnly(e, start, obj) {
var key;
var keychar;

if (window.event) {
   key = window.event.keyCode;
}
else if (e) {
   key = e.which;
}
else {
   return true;
}
keychar = String.fromCharCode(key);

if ((key==null) || (key==0) ||  (key==9) || (key==13) || (key==27) ) {
   return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
if ((parseInt(obj.value)) == 0) 
{
obj.value = obj.value.replace(obj.value, \'1\');
if (start)
{
stopIt();
startIt();
}
return false;
} else {
if (start)
{
stopIt();
startIt();
}
return true;
}
}
else if ((key==190) || (keychar == ".")) { 
  return false;
}
else if (key==8) {
if (trim(obj.value) == \'\' || parseInt(obj.value) == 0)
obj.value = obj.value.replace(obj.value, \'1\');

if (start) {
stopIt();
startIt();
}
   return true;
   }
   else {
    return false;
   }
}

// fastest way to trim a string in Javascript.  Believe it or not!
function trim(str) {
var str = str.replace(/^\s\s*/, \'\'),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}

// Only return numbers. Just in case user copies and pastes into the textbox
function digitsOnly(obj){
obj.value=obj.value.replace(/[^\d]/g,\'\');
}

</script>
'
;
?>




<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body, td, th, span {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #FFFFFF;
}
body {
background-color: #3c3c3c;
}
-->
</style></head>
<body onLoad="init();">
<div id="outerDiv" style="position: absolute; left: 0px; top: 0px; width: 100%; align: center;">
<div style="position: relative; width: 85%; left: 5%; padding-bottom: 30px; padding-left: 15px; padding-right: 15px; top: 25px; background-color: #990000; border: 1px ridge #C0C0C0; align: center;">
<span style="position:relative; left: 5px; top: 5px; font-size: 0.8em; font-family: verdana, sans-serif;">Time Delay: <input name="daTime" style="position: relative; text-align: right; top: 2px;" type="text" id="daTime" value="3" size="2" maxlength="2" onKeyPress="return NumOnly(event, false, this)" onKeyUp="return NumOnly(event, true, this)" onBlur="digitsOnly(this)"> seconds</span><div id="message" style="position: relative; left: 3%; top: 10px; width: 94%; height: 230px; overflow-y: auto; background-color: #C0C0C0; color: black; border: 1px inset #ffb0b0; padding: 5px 0px 5px 0px;">&nbsp;</div><div style="position: relative; left: 0px; top: 20px; width: 100%; text-align: center; font-size: 14px;">
<?php 
if (!empty($entryBoards))
echo 'An example of grabbing unique, random posts from the following board(s): ';
$xRow 0;
foreach (
$entryBoards as $id => $board) {
$xRow++;
if ($xRow == (count($entryBoards) - 1))
echo $board . (count($entryBoards) >= ' (ID: #' $id '),' ' (ID: #' $id ')') . ' and ';
else
echo $board ' (ID: #' $id ')' . (($xRow < (count($entryBoards) - 1) && (count($entryBoards) > 2)) ? ', ' '');
}
?>

</div>
</div>
</div>

</body>
</html>
Ofcourse this is using SSI.php, so if you aren't using this and are doing it from an action, you can just take this bit out, and the <html> and <body> tags as well, as everything will be done from, both the source and the template files instead of it being done from 1 file using SSI.php.

Well, hopefully this helps you some.  Cheers :)

Arantor


ElectricSquid

#13
Start time.
We won't need any of the last edit stuff, or any of that.

Every status update will remain ordered by when they were created, no matter when a reply was made. That way new stuff is new, and the old falls away.

This really is the big difference between the Status Update and the Forum structure.
Status Updates are all about now, here, look at me and what I'm doing right now.
Forum Topics are more long term.

Arantor

In which case, you are just querying topics table and keeping it in order of id_topic DESC LIMIT 12.

Actually it isn't so far away from what the forum can do now - ssi_boardNews basically has a template for this kind of thing.

The last edit stuff is still recorded, unless you physically remove it, just not displayed unless you want it to be.

ElectricSquid

I was eyeing up ssi_boardNews about 5 hours ago, but for some reason I couldn't get it to show after I extracted it from ssi and ported it over to an action.

Arantor


ElectricSquid

I refresh it at every change.
Usually the normal stuff.

Undefined index
Invalid argument supplied for foreach()

that kinda stuff :P

Arantor

Well, mods should never generate an error (we don't allow mods that do generate errors without good reason, i.e. it's not the mod's fault, but user error that caused it)

ElectricSquid

I was joking when I said the usual stuff :P
The error log should be error free.

I just suck at coding, so I'm working it till it's right.
Gotta learn somewhere ;D

Advertisement: