We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!

Answered Recent posts

    • 38705
    • 101 Posts
    Hi, maybe i am overlooking something but have a question about recent posts.

    Question 1:
    How can i get a short overview of 10 most recent posts on discuss my frontpage (not my main forumpage)?

    Question 2:
    As an alternative I tried it with reading the recent.xml feed but that throws an error.
    If I compare my feed against the modx feed (which produces correct results) i see in the source that row 1 is different.

    On forums.modx.com
    <?xml version="1.0" encoding="UTF-8"?>
    .....

    This produces nice results.

    On my page
    {SPACE}<?xml version="1.0" encoding="UTF-8"?>
    ... etc

    Which produces:
    Warning: MagpieRSS: Failed to parse RSS file. (Reserved XML Name at line 1, column 38) in /home/user/domains/mydomain.nl/public_html/core/model/modx/xmlrss/rssfetch.class.php on line 237


    On my page a space is added before the xml statement, which seem to produce the error.
    Does anyone have a clue where to edit the controller- of template-file on discuss to remove this (whitespace)character?

    *** EDIT: I can confirm that a XML-file without the space produces the correct result. Does anyone have a quickfix? ***

    This question has been answered by multiple community members. See the first response.

    [ed. note: mintnl last edited this post 11 years, 3 months ago.]
      Addict since 2012....
      • 38705
      • 101 Posts
      Made my own snippet to retrieve the latest forumposts (look at http://www.javelin.nl for example).

      Snippet Discuss.Recent
      <?php
      $weghalen = array(",", "/", "?", "<", ">", ";", ":", "[", "]", "{", "}", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "=");
      $vervangen = array(" ", ".");
      
      $c = $modx->newQuery('modUser');
      $c->leftJoin('modUserProfile','Profile');
      $c->sortby('id','ASC'); 
      // add column names that u want to show
      $c->select(array(
          'modUser.*',
          'Profile.fullname',
          'Profile.email',
      ));
       
      $users = $modx->getCollection("modUser",$c);
      $naam[0] = 'Anoniem'; 
      foreach($users as $user){
          $usr = $user->toArray();
      
      $naam[$usr['id']] = $usr['username'];
      $email[$usr['id']] = $usr['email'];
      }
      
      $tpl = $modx->getOption('tpl',$scriptProperties,'Forumposts.Recent');
      
      $package_path = $modx->getOption('core_path').'components/discuss/model/';
      $modx->addPackage('discuss', $package_path);
      $vraag = $modx->newQuery('disPost');
      $vraag->sortby('id','DESC');
      $vraag->where(array(
         'board:!=' => 9,
         'board:!=' => 10,
      ));
      $vraag->limit(6,0);
      
      $regels = $modx->getCollection('disPost',$vraag);
      $output = '';
      
      foreach($regels as $regel){
      $rglArray['post']= $regel->get('id');
      $rglArray['thread']= $regel->get('thread');
      $titel = strtolower($regel->get('title'));
      if(substr($titel, 0,4)=="re: "){$titel = substr($titel,4);}
      $titel= str_replace($vervangen, "-", str_replace($weghalen, "", $titel));
      if(substr($titel,-1)=="-"){$titel = substr($titel,0,-1);}
      $rglArray['threadname'] = $titel;
      //$rglArray['threadname'] = $titel2;
      $rglArray['title']= $regel->get('title');
      $rglArray['message']= $regel->get('message');
      $rglArray['author'] = $naam[$regel->get('author')];
      $rglArray['createdon']= $regel->get('createdon');
      $rglArray['gravatar'] = "http://www.gravatar.com/avatar/".md5(strtolower(trim($email[$regel->get('author')])))."?d=mm&s=50";
      $rglArray['email'] = $email[$regel->get('author')];
      $rglArray['nummer'] =$nummer;
      
      $output .= $modx->getChunk($tpl,$rglArray);
      }
      return $output;


      and the use of a Chunk called Forumposts.Recent:
      <li>  <img src="[[+gravatar]]" class="avatar">
      <em> door [[+author:isnot=`Anoniem`:then=`<a href="/forums/u/[[+author]]">[[+author]]</a>`:else=`[[+author]]`]] » [[+createdon:ago]]</em>
      <h3><a href="/forums/thread/[[+thread]]/[[+threadname]]#dis-post-[[+post]]">[[+title]]</a></h3>
      <p style='margin-top:-15px'>[[+message:strip:stripTags:ellipsis=`50`]]</p> 
      					<div class="clear"></div>
      </li>



      In the page template it is called like:
      [[!Discuss.Recent]]


      In this case the boards 9 & 10 are restricted, so you don't want to show that on the page. Maybe you could integrate an user-id check, but haven't gone that route yet.

      Maybe not the most elegant scripting but it works smiley Hope somebody can use it.
        Addict since 2012....
      • discuss.answer
        • 38705
        • 101 Posts
        To get back on topic: feed error resolved by removing the space before
         <?php 
        from file /core/components/discuss/model/discuss/dispost.class.php


        **edit: This fixes the general RSS, recent.xml still has the problem ** [ed. note: mintnl last edited this post 11 years, 2 months ago.]
          Addict since 2012....
          • 46509
          • 2 Posts
          Thank you very much. Can I display recent threads by dint of this snippet?
            • 46886
            • 1,154 Posts
            Ah this looks fabulous, will try it out soon.
              • 43836
              • 2 Posts
              This is a great little snippet thanks mintl

              Got it on my home page but it seems to be displaying the bb code ie
              [b]Title,[/b]


              Any ideas how I can strip those tags? I could build some jquery thingy to modify those tags but that's a hack. [ed. note: andywade84 last edited this post 9 years, 11 months ago.]
                • 46886
                • 1,154 Posts
                you were able to get it working just by putting it in? Did you have to do any conversion? I am going to try it out next week.
                • discuss.answer
                  • 38705
                  • 101 Posts
                  You can try to add

                  $titel = strtolower(preg_replace('~\[b\](.+?)\[/b\]~is', '\1', $regel->get('title'))); 

                  instead of the "original" line 42 in the earlier post. This should strip the bold tag
                    Addict since 2012....
                    • 46220
                    • 66 Posts
                    Hi mintnl, thanks so much for this, it was one of the things I was looking for. One question though, where it should state the name of the user, it returns the name of the website administrator. I'm sure I am just missing something here, mainly knowledge (sorry, I work in HR and do this as hobby), hope you (or anyone else) can help me out.

                    EDIT: As for now, I just removed it which works fine for me now. [ed. note: gormytorysh last edited this post 9 years, 10 months ago.]