Calling group forum posts in to PHP block

in 7.0.9 I used the following code to call group forum posts in to a php block ... I cannot seem to make it work in 7.1

can anyone help with this please ?

$groupuri = str_replace( '/m/groups/view/', '', $_SERVER['REQUEST_URI'] ); return ' <div class="RSSAggrCont" rssid="groupforum" rssnum="5" member="0" groupuri="'.$groupuri.'">  <div class="loading_rss">  <img src="' . getTemplateImage('loading.gif') . '" alt="'._t('_loading ...').'" />  </div>  </div> ';

DedicatedServer4You.com -- BIGGEST Range of Dedicated Servers at the Lowest Price!
Quote · 21 Dec 2012

bump.

DedicatedServer4You.com -- BIGGEST Range of Dedicated Servers at the Lowest Price!
Quote · 21 Dec 2012

Dont know but let me know if you get it to work on 7.1!

I had this enabled on 7.0.9 but not yet on 7.1...

 

Quote · 21 Dec 2012

I do not have a answer which is the reason i did not post a response.

I don't have any groups or much of anything else setup on my 7.1 site to test with right now.

https://www.deanbassett.com
Quote · 22 Dec 2012

bump for fix / solution

DedicatedServer4You.com -- BIGGEST Range of Dedicated Servers at the Lowest Price!
Quote · 22 Dec 2012

Bump... We REALLY need to know this plz help us....  Innocent

Quote · 20 Jan 2013

I am stepping into this forum post.  I see there is an RSS feed for group forums.  Clicking on the RSS link does show only the group forum posts.  Therefore, I would assume that I could pull the group forum topics into an RSS block like the Home Page block for the regular forum and place it on the group home page so that when you visit the group you can see new forum topics.  However, I can not seem to get it to work.  How should the URL be formed?

Geeks, making the world a better place
Quote · 10 Feb 2013

@detective - on what page are you wanting to put your block on so i can see if i can help

caredesign.net
Quote · 10 Feb 2013

@geek_girl - check out mytherapysession.com/m/groups and let me know if that is what you are talking about - in this case i created a new rss and used this for the url field:

{SiteUrl}forum/?action=rss_all

that shows all of the forum posts, I am guessing you just want to show forums related to a specific group?

caredesign.net
Quote · 10 Feb 2013

OK - I took a lil time to try and figure out how to accomplish what you are looking for. I have a quick demo to see if it is correct at http://www.mytherapysession.com/m/groups/view/test-2 - check it out and let me know if this is close to what you want. i didnt do the profile pic though, just the basic data to see if i could do it.

caredesign.net
Quote · 10 Feb 2013

ok, this is what i have put together in order to somewhat accomplish what you are looking for (I hope):

First - I created a php block on the Groups View Page

In that php block, I put the following:

?>

[EDIT]

<link type="text/css" rel="stylesheet" href="http://www.your-domain.com/gzip_loader.php?file=bx_templ_css_71919003a98e29d8456c6c6366ade493.css">
<?php
$groupid = $this->aDataEntry['id'];
$groupuri = $this->aDataEntry['uri'];
// $groupid = 2;
// $groupuri = "test-2";
 $db=mysql_connect  ('localhost', 'user',  'password') or die ('I cannot connect to the database  because: ' . mysql_error());
      //-select  the database to use
      $mydb=mysql_select_db('database');
     
       if (!(isset($pagenum)))
 {
 $pagenum = 1;
 }
 
echo "<div class='bx-def-bc-padding'><table class='forum_table_list'><tbody>";
// Perform an statndard SQL query:
$sql= mysql_query("SELECT t.topic_title, t.topic_uri, t.first_post_user, t.first_post_when, t.last_post_user, t.last_post_when, t.topic_posts, p.post_text FROM bx_groups_forum_topic AS t INNER JOIN bx_groups_forum_post AS p ON t.topic_id = p.topic_id WHERE t.forum_id = $groupid") or die (mysql_error());
// We are going to use the "$row" method for this query. This is just my preference.
$nr = mysql_num_rows($sql); // Get total of Num rows from the database query
if (isset($_GET['pn'])) { // Get pn from URL vars if it is present
    $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new)
    //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated)
} else { // If the pn URL variable is not present force it to be value of page number 1
    $pn = 1;
}
//This is where we set how many database items to show on each page
$itemsPerPage = 1;
// Get the value of the last page in the pagination result set
$lastPage = ceil($nr / $itemsPerPage);
// Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage
if ($pn < 1) { // If it is less than 1
    $pn = 1; // force if to be 1
} else if ($pn > $lastPage) { // if it is greater than $lastpage
    $pn = $lastPage; // force it to be $lastpage's value
}
// This creates the numbers to click in between the next and back buttons
// This section is explained well in the video that accompanies this script
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
} else if ($pn == $lastPage) {
    $centerPages .= '&nbsp; <a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '&nbsp; <a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;';
} else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '&nbsp; <a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
}
// This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
// Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax
// $sql2 is what we will use to fuel our while loop statement below

 
 $sql2= mysql_query("SELECT t.topic_title, t.topic_uri, t.first_post_user, t.first_post_when, t.last_post_user, t.last_post_when, t.topic_posts, p.post_text FROM bx_groups_forum_topic AS t INNER JOIN bx_groups_forum_post AS p ON t.topic_id = p.topic_id WHERE t.forum_id = $groupid $limit") or die (mysql_error());
// We are going to use the "$row" method for this query. This is just my preference.
 $paginationDisplay = ""; // Initialize the pagination output variable
// This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
if ($lastPage != "1"){
    // This shows the user what page they are on, and the total number of pages
//    $paginationDisplay .= 'Page ' . $pn . ' of ' . $lastPage. '&nbsp;  &nbsp;  &nbsp; ';
    // If we are not on page 1 we can place the Back button
    if ($pn > 3) {
        $first = 1;
        $paginationDisplay .=  '<a onclick="return document.f.selectGroupTopics ("0")" href="m/groups/view/' . $groupuri . '?pn=' . $first . '" title="First page">
<i class="sys-icon step-backward"> </i>';
    }
    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .=  '<a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $previous . '" title="Previous page">
<i class="sys-icon backward"> </i>';
    }
   
   
    // Lay in the clickable numbers display here between the Back and Next links
    $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
    // If we are not on the very last page we can place the Next button
    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '<a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $nextPage . '" title="Next page">
<i class="sys-icon forward"> </i></a>';
    }
    if ($pn != $lastPage && $pn != $first) {
       
        $paginationDisplay .=  '<a onclick="return document.f.selectGroupTopics ("10")" href="m/groups/view/' . $groupuri . '?pn=' . $lastPage . '" title="Last page">
<i class="sys-icon step-forward"> </i></a>';
    }
}
// Build the Output Section Here
$outputList = '';
 while ($row = mysql_fetch_array($sql2)) {
$post_text = $row["post_text"];
$topic_uri = $row["topic_uri"];
$topic_title = $row["topic_title"];
$first_post_user = $row["first_post_user"];
$first_post_when = $row["first_post_when"];
$last_post_user = $row["last_post_user"];
$last_post_when = $row["last_post_when"];
$topic_posts = $row["topic_posts"];

    // Echo your table row and table data that you want to be looped over and over here.
echo "<tr><td colspan='2'><div class='bx-def-hr bx-def-margin-sec-top bx-def-margin-sec-bottom'></div></td></tr><tr><td class='forum_table_column_first forum_table_fixed_height'><div class='forum_icon_title_desc'><img class='forum_user_icon bx-def-round-corners' src='http://www.your-domain.com/modules/boonex/avatar/data/images/1i.jpg'><a class='forum_topic_title bx-def-font-h2' href='http://www.your-domain.com/forum/groups/topic/" . $topic_uri . ".htm' onclick='return f.selectTopic('" . $topic_uri . "');'>" . $topic_title . "</a><span class='bx-def-font-small bx-def-font-grayed'><span class='forum_stat'>created by " . $first_post_user . " $first_post_when · last reply by $last_post_user $last_post_when</span></span><span class='forum_topic_ext_info'>" . $post_text . "</span></div></td><td class='forum_table_column_stat bx-def-font-large'>$topic_posts posts</td></tr>";
                       
                       
    // Add 1 to the row count
    $row_count++;
    }

echo "</tbody></table></div><div class='paginate bx-def-padding-right bx-def-padding-left'><div class='per_page_section'><div class='info'>$nr Topics for this Group</div></div><div class='pages_section'><div class='active_page'>$paginationDisplay</div></div></div>";

Remember to change the items in red to match your settings.

Now - I did not do the pictures, those are just placeholders for now. And the xx Topics for this group is not correct either. But its a start. I also can not guarantee that it will work for you. This is what I did and it does work for me, you can check it out at the url i posted earlier. I really hope it works for you and others as well. Or at least if someone can come in and post a better way.

[edit] - bx_templ_css_71919003a98e29d8456c6c6366ade493.css => I think this comes from the cache, I will have to fix this part right quick

caredesign.net
Quote · 10 Feb 2013

 

@geek_girl - check out mytherapysession.com/m/groups and let me know if that is what you are talking about - in this case i created a new rss and used this for the url field:

{SiteUrl}forum/?action=rss_all

that shows all of the forum posts, I am guessing you just want to show forums related to a specific group?

Yes, the block would be on all groups; on the main page of the group, showing recent forum topics for that group only.  Each group forum has it own RSS feed so I did not think it would be that difficult to do.

Geeks, making the world a better place
Quote · 10 Feb 2013

Yes, working to an extend.  I am using a group module by a third party.  When clicking the pagination:


Warning: Cannot modify header information - headers already sent by (output started at /public_html/inc/design.inc.php(117) : runtime-created function:28) in /[the module script]

However,  I don't want the pagination; I just want to list x number of recent posts; which I should be able to do on my own.  They can see all the forum topics by clicking on the forum link in the group.  It is just so they can see quickly when they come into the group page that there is new forum content.

Geeks, making the world a better place
Quote · 10 Feb 2013

I increased the number of posts and removed the pagination and it is working nicely.  I need to change the unix timestamp to a date but that is easy enough.

Thanks for your work on this.

Geeks, making the world a better place
Quote · 10 Feb 2013

Wow - I must say I was a lil worried when i went  to bed last night that it may not work or be a big disaster. I am glad it is working for you. DOnt forget the user pics have to be done also. I hadnt done those.

caredesign.net
Quote · 10 Feb 2013

 

DOnt forget the user pics have to be done also. I hadnt done those.

 Really?  They showed up for me and I did not change that bit.  I am assuming you mean the small avatar to the left of the forum topic.

Geeks, making the world a better place
Quote · 10 Feb 2013

yes - the small avatar to the left - i just used what i have as a placeholder until either i get to it or someone manages to find a simpler more efficient way to do what you want. I just put that together last night to see if i could. I am not that good with php coding, and trying to learn as i go.

but hmmm - this would be a nice default action for dolphin though. hopefully someday it can be implemented.

caredesign.net
Quote · 11 Feb 2013

any idea why my original code won't work ?

DedicatedServer4You.com -- BIGGEST Range of Dedicated Servers at the Lowest Price!
Quote · 11 Feb 2013

the first thing i was looking for was your variable $groupuri. - when i use the code ii only get the circling loading icon. so I first looked for your variable in my files and couldnt find it. I havent done groups before and the variable that i could find was $this->aDataEntry['uri'], I even tried to replace your variable and it still did not work. So thats why i just did a full script.

caredesign.net
Quote · 11 Feb 2013

 

yes - the small avatar to the left - i just used what i have as a placeholder until either i get to it or someone manages to find a simpler more efficient way to do what you want. I just put that together last night to see if i could. I am not that good with php coding, and trying to learn as i go.

but hmmm - this would be a nice default action for dolphin though. hopefully someday it can be implemented.

 It is pulling out the avatar; so that is working; at least for me.

Geeks, making the world a better place
Quote · 11 Feb 2013

So you are telling me that it is pulling in the proper avatar pic for the person posting the topic? Holy Smokes!!! I did not see that one coming. Roflmfaop.

caredesign.net
Quote · 11 Feb 2013

I knew it was too good to be true - lol. I just created a new post under a different account - and in my case it used the same avatar as the admin - which is the account i was under when I looked at the code to begin with.

caredesign.net
Quote · 11 Feb 2013

after further review - I noticed that the url for the image is set to display the 1i.jpg. So here is the edited portion  to provide the proper avatar image (section in blue is the additional code for the avatar):

$topic_posts = $row["topic_posts"];

    // Echo your table row and table data that you want to be looped over and over here.
 $poster = mysql_query("SELECT ID FROM Profiles WHERE NickName = '$first_post_user'") or die (mysql_error());
  while ($row = mysql_fetch_array($poster)) {
$user_id = $row["ID"];
  }
  $avatar = mysql_query("SELECT id FROM bx_avatar_images WHERE author_id = '$user_id' LIMIT 1") or die (mysql_error());
  while ($row = mysql_fetch_array($avatar)) {

$avatar_id = $row['id'];
 }
echo "<tr><td colspan='2'><div class='bx-def-hr bx-def-margin-sec-top bx-def-margin-sec-bottom'></div></td>

 ...

And this also needs to be changed from:

.../boonex/avatar/data/images/1i.jpg'>

to:

....../boonex/avatar/data/images/" . $avatar_id . "i.jpg'>

 

Also - this is for the stylesheet at the top of the code:

<link type="text/css" rel="stylesheet" href="http://your-domain.com/modules/boonex/forum/layout/base/css/main.css">

I edited this from my original post as I had posted the wrong thing

caredesign.net
Quote · 11 Feb 2013

OK, for the topic count it is counting the number replies as well as the topic; I guess it is counting the posts instead of topics;  first post is the creation of the topic, then when you reply, it is counted as well.  so the topic count is wrong.

 

Plus, need to convert the timestamp to a date; which I did.

Geeks, making the world a better place
Quote · 11 Feb 2013

it was late last night when i was doing it - so another reason I am surprised it actually worked as much as it has. Please check out my last post. I made an edit while you were posting I think. Also - in the essence of saving time, could you post what you have for the time code change from unix please.

caredesign.net
Quote · 11 Feb 2013

This is not working on my production site.  It pulls out one topic and then repeats the next topic three times; I have it set to display four.

Plus, I want a latest forum topic block; the newest forum topic listed first.  It is listing the forum topics as they were created; reads in the first row of the table and so on.

Geeks, making the world a better place
Quote · 11 Feb 2013

Yes, I thank you for your work on this.  It is appreciated.

Geeks, making the world a better place
Quote · 11 Feb 2013

I know you can convert the timestamp as you read the value in from the table but I just added two variables;

$last_post_date = date("d.m.Y H-i",$last_post_when);
$topic_created_date = date("d.m.Y H-i",$first_post_when);

 

$last_post_user = date("d.m.Y H-i",$row["last_post_user"]);

Would that work?

Geeks, making the world a better place
Quote · 11 Feb 2013

as for the order - you could add ORDER BY topic_id DESC in the two join sql statements

 and $last_post_user is the name of the person who posted the last post - not actually the date

caredesign.net
Quote · 11 Feb 2013

 

This is not working on my production site.  It pulls out one topic and then repeats the next topic three times; I have it set to display four.

 I will have to check on this tomorrow - when i first put the script together, I had exactly what you are getting - duplicating entries. It took me an hour or so to finally get it straightened out - but thats the bad part. I know how it works for me and based on any changes I have made to my site. I know you mentioned using a 3rd party groups module, so i dont know how it will react with that. By the way. what is the custom groups module, and is it a free one. If it is I will install and see what happens for me and If i can figure it out for you. Or I may just buy it if it is one to be purchased.

Please keep in mind that my coding skills are very limited, and I know that this could be accomplished with a few functions and probably 6 to 8 lines of code - lol. I am just not that good to know how yet.

caredesign.net
Quote · 11 Feb 2013

heres a quick edit to hopefully resolve the wrong number of topics for the group:

$topics_number = mysql_query("SELECT * FROM bx_groups_forum_topic WHERE forum_id = '$groupid'") or die (mysql_error());
 $t_number = mysql_num_rows($topics_number);
 
echo "</tbody></table></div><div class='paginate bx-def-padding-right bx-def-padding-left'><div class='per_page_section'><div class='info'>$t_number Topics for this Group</div></div><div class='pages_section'><div class='active_page'>$paginationDisplay</div></div></div>";

caredesign.net
Quote · 11 Feb 2013

Thanks for the updates, I will work on this some more later.

Geeks, making the world a better place
Quote · 11 Feb 2013
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.